support template literals (#4601)
This commit is contained in:
28
lib/ast.js
28
lib/ast.js
@@ -1418,6 +1418,34 @@ var AST_This = DEFNODE("This", null, {
|
||||
},
|
||||
}, AST_Symbol);
|
||||
|
||||
var AST_Template = DEFNODE("Template", "expressions strings tag", {
|
||||
$documentation: "A template literal, i.e. tag`str1${expr1}...strN${exprN}strN+1`",
|
||||
$propdoc: {
|
||||
expressions: "[AST_Node*] the placeholder expressions",
|
||||
strings: "[string*] the interpolating text segments",
|
||||
tag: "[AST_Node] tag function, or null if absent",
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
if (node.tag) node.tag.walk(visitor);
|
||||
node.expressions.forEach(function(expr) {
|
||||
expr.walk(visitor);
|
||||
});
|
||||
});
|
||||
},
|
||||
_validate: function() {
|
||||
if (this.expressions.length + 1 != this.strings.length) {
|
||||
throw new Error("malformed template with " + this.expressions.length + " placeholder(s) but " + this.strings.length + " text segment(s)");
|
||||
}
|
||||
must_be_expressions(this, "expressions");
|
||||
this.strings.forEach(function(string) {
|
||||
if (typeof string != "string") throw new Error("strings must contain string");
|
||||
});
|
||||
if (this.tag != null) must_be_expression(this, "tag");
|
||||
},
|
||||
});
|
||||
|
||||
var AST_Constant = DEFNODE("Constant", null, {
|
||||
$documentation: "Base class for all constants",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user