build method

dynamic build(
  1. NodeBuilder builder, [
  2. dynamic output = null
])

Implementation

build(NodeBuilder builder, [output = null]) {
  var hash = this.getHash(builder);
  var sharedNode = builder.getNodeFromHash(hash);

  if (sharedNode != undefined && this != sharedNode) {
    return sharedNode.build(builder, output);
  }

  builder.addNode(this);
  builder.addStack(this);

  // generate 函数的参数长度?
  // dart不支持
  var isGenerateOnce = (this.generateLength == 1);

  var snippet = null;

  if (isGenerateOnce) {
    var type = this.getNodeType(builder);
    var nodeData = builder.getDataFromNode(this);

    snippet = nodeData["snippet"];

    if (snippet == undefined) {
      snippet = this.generate(builder) ?? '';

      nodeData["snippet"] = snippet;
    }

    snippet = builder.format(snippet, type, output);
  } else {
    snippet = this.generate(builder, output) ?? '';
  }

  builder.removeStack(this);

  return snippet;
}