template()

in lib/parser.js [1268:1315]


  template() {
    var elements = [];
    var loc = {
      start: this.look.loc.start,
    };
    elements.push({
      type: 'element',
      value: this.look
    });

    var last = this.look;
    this.move();
    if (last.tag === Tag.TEMPLATE && last.tail === true) {
      loc.end = last.loc.end;
      return {
        type: 'template_string',
        elements: elements,
        loc
      };
    }

    for (; ;) {
      if (this.look.tag === Tag.TEMPLATE) {
        var current = this.look;
        elements.push({
          type: 'element',
          value: this.look
        });
        this.move();
        if (current.tail === true) {
          loc.end = current.loc.end;
          break;
        }
      } else {
        var expr = this.expr();
        elements.push({
          type: 'expr',
          expr: expr
        });
      }
    }

    return {
      type: 'template_string',
      elements: elements,
      loc
    };
  }