Fix computed getters + cleanup AST

This commit is contained in:
Anthony Van de Gejuchte
2016-07-21 18:02:32 +02:00
parent 88384cf351
commit 3f8fc3a316
3 changed files with 17 additions and 33 deletions

View File

@@ -449,7 +449,7 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments is_generator",
$documentation: "Base class for functions", $documentation: "Base class for functions",
$propdoc: { $propdoc: {
is_generator: "is generatorFn or not", is_generator: "is generatorFn or not",
name: "[AST_SymbolDeclaration?] the name of this function", name: "[AST_SymbolDeclaration?|AST_Node] the name of this function or computed expression",
argnames: "[AST_SymbolFunarg|AST_Destructuring|AST_Expansion*] array of function arguments, destructurings, or expanding arguments", argnames: "[AST_SymbolFunarg|AST_Destructuring|AST_Expansion*] array of function arguments, destructurings, or expanding arguments",
uses_arguments: "[boolean/S] tells whether this function accesses the arguments array" uses_arguments: "[boolean/S] tells whether this function accesses the arguments array"
}, },
@@ -996,7 +996,7 @@ var AST_Object = DEFNODE("Object", "properties", {
var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", { var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
$documentation: "Base class for literal object properties", $documentation: "Base class for literal object properties",
$propdoc: { $propdoc: {
key: "[string] the property name converted to a string for ObjectKeyVal. For setters and getters this is an arbitrary AST_Node.", key: "[string|AST_Node] the property name converted to a string for ObjectKeyVal. For setters and getters this is an arbitrary AST_Node.",
value: "[AST_Node] property value. For setters and getters this is an AST_Function." value: "[AST_Node] property value. For setters and getters this is an AST_Function."
}, },
_walk: function(visitor) { _walk: function(visitor) {

View File

@@ -1457,7 +1457,13 @@ function OutputStream(options) {
} }
output.print("set"); output.print("set");
output.space(); output.space();
self.key.print(output); if (self.key instanceof AST_SymbolMethod) {
self.key.print(output);
} else {
output.with_square(function() {
self.key.print(output);
});
}
self.value._do_print(output, true); self.value._do_print(output, true);
}); });
DEFPRINT(AST_ObjectGetter, function(self, output){ DEFPRINT(AST_ObjectGetter, function(self, output){
@@ -1467,7 +1473,13 @@ function OutputStream(options) {
} }
output.print("get"); output.print("get");
output.space(); output.space();
self.key.print(output); if (self.key instanceof AST_SymbolMethod) {
self.key.print(output);
} else {
output.with_square(function() {
self.key.print(output);
});
}
self.value._do_print(output, true); self.value._do_print(output, true);
}); });
DEFPRINT(AST_ObjectComputedKeyVal, function(self, output) { DEFPRINT(AST_ObjectComputedKeyVal, function(self, output) {
@@ -1493,15 +1505,6 @@ function OutputStream(options) {
self.default.print(output) self.default.print(output)
} }
}); });
DEFPRINT(AST_SymbolMethod, function(self, output) {
if (self.name instanceof AST_Node) {
output.with_square(function() {
self.name.print(output);
});
} else {
self._do_print(output);
}
});
DEFPRINT(AST_Undefined, function(self, output){ DEFPRINT(AST_Undefined, function(self, output){
output.print("void 0"); output.print("void 0");
}); });

View File

@@ -240,24 +240,5 @@ getter_setter_with_computed_value: {
} }
} }
} }
expect: { expect_exact: 'class C{get["a"](){return"A"}set["a"](value){do_something(a)}}var x={get[a.b](){return 42}};class MyArray extends Array{get[Symbol.species](){return Array}}'
class C {
get ['a']() {
return 'A';
}
set ['a'](value) {
do_something(a);
}
}
var x = {
get [a.b]() {
return 42;
}
};
class MyArray extends Array {
get [Symbol.species]() {
return Array;
}
}
}
} }