aboutsummaryrefslogtreecommitdiff
path: root/lib/ast.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-11-08 15:38:32 +0000
committerGitHub <noreply@github.com>2020-11-08 23:38:32 +0800
commit91fc1c82b56986df51ad1450c18718bc585deca9 (patch)
treea534652eea79949356bee8a877b71a49a5b18e82 /lib/ast.js
parent810cd40356f6fa1ddbc9c97a0df95bd1d94a2720 (diff)
downloadtracifyjs-91fc1c82b56986df51ad1450c18718bc585deca9.tar.gz
tracifyjs-91fc1c82b56986df51ad1450c18718bc585deca9.zip
support computed property name in object literal (#4268)
Diffstat (limited to 'lib/ast.js')
-rw-r--r--lib/ast.js26
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/ast.js b/lib/ast.js
index ad58ec21..02a38b9e 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -1015,24 +1015,28 @@ var AST_Object = DEFNODE("Object", "properties", {
var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
$documentation: "Base class for literal object properties",
$propdoc: {
- key: "[string|AST_SymbolAccessor] property name. For ObjectKeyVal this is a string. For getters and setters this is an AST_SymbolAccessor.",
- value: "[AST_Node] property value. For getters and setters this is an AST_Accessor."
+ key: "[string|AST_Node] property name. For computed property this is an AST_Node.",
+ value: "[AST_Node] property value. For getters and setters this is an AST_Accessor.",
},
walk: function(visitor) {
var node = this;
visitor.visit(node, function() {
+ if (node.key instanceof AST_Node) node.key.walk(visitor);
node.value.walk(visitor);
});
- }
+ },
+ _validate: function() {
+ if (typeof this.key != "string") {
+ if (!(this.key instanceof AST_Node)) throw new Error("key must be string or AST_Node");
+ must_be_expression(this, "key");
+ }
+ if (!(this.value instanceof AST_Node)) throw new Error("value must be AST_Node");
+ },
});
-var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", {
+var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", null, {
$documentation: "A key: value object property",
- $propdoc: {
- quote: "[string] the original quote character"
- },
_validate: function() {
- if (typeof this.key != "string") throw new Error("key must be string");
must_be_expression(this, "value");
},
}, AST_ObjectProperty);
@@ -1040,7 +1044,6 @@ var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", {
var AST_ObjectSetter = DEFNODE("ObjectSetter", null, {
$documentation: "An object setter property",
_validate: function() {
- if (!(this.key instanceof AST_SymbolAccessor)) throw new Error("key must be AST_SymbolAccessor");
if (!(this.value instanceof AST_Accessor)) throw new Error("value must be AST_Accessor");
},
}, AST_ObjectProperty);
@@ -1048,7 +1051,6 @@ var AST_ObjectSetter = DEFNODE("ObjectSetter", null, {
var AST_ObjectGetter = DEFNODE("ObjectGetter", null, {
$documentation: "An object getter property",
_validate: function() {
- if (!(this.key instanceof AST_SymbolAccessor)) throw new Error("key must be AST_SymbolAccessor");
if (!(this.value instanceof AST_Accessor)) throw new Error("value must be AST_Accessor");
},
}, AST_ObjectProperty);
@@ -1065,10 +1067,6 @@ var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
},
});
-var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, {
- $documentation: "The name of a property accessor (setter/getter function)"
-}, AST_Symbol);
-
var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
$documentation: "A declaration symbol (symbol in var, function name or argument, symbol in catch)",
}, AST_Symbol);