aboutsummaryrefslogtreecommitdiff
path: root/lib/ast.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ast.js')
-rw-r--r--lib/ast.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/ast.js b/lib/ast.js
index 1a09d4de..5bfe7be1 100644
--- a/lib/ast.js
+++ b/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",
});