From 3f8fc3a316a60b67acf09b2b2cf887f0209c7d71 Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Thu, 21 Jul 2016 18:02:32 +0200 Subject: [PATCH] Fix computed getters + cleanup AST --- lib/ast.js | 4 ++-- lib/output.js | 25 ++++++++++++++----------- test/compress/object.js | 21 +-------------------- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index c08e6222..4a9e20e4 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -449,7 +449,7 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments is_generator", $documentation: "Base class for functions", $propdoc: { 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", 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", { $documentation: "Base class for literal object properties", $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." }, _walk: function(visitor) { diff --git a/lib/output.js b/lib/output.js index 53c9a4ce..2046fc92 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1457,7 +1457,13 @@ function OutputStream(options) { } output.print("set"); 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); }); DEFPRINT(AST_ObjectGetter, function(self, output){ @@ -1467,7 +1473,13 @@ function OutputStream(options) { } output.print("get"); 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); }); DEFPRINT(AST_ObjectComputedKeyVal, function(self, output) { @@ -1493,15 +1505,6 @@ function OutputStream(options) { 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){ output.print("void 0"); }); diff --git a/test/compress/object.js b/test/compress/object.js index ede3ea0f..2e7d37a3 100644 --- a/test/compress/object.js +++ b/test/compress/object.js @@ -240,24 +240,5 @@ getter_setter_with_computed_value: { } } } - expect: { - 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; - } - } - } + 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}}' }