From a18f3d10037c4adba0f0de8b16472ee5feeb9524 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 4 Nov 2014 11:40:49 +1100 Subject: [PATCH] Add support for computed static mutator class methods --- acorn.js | 2 +- test/tests-harmony.js | 153 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 1 deletion(-) diff --git a/acorn.js b/acorn.js index 401b9421c8..d94aee2fc3 100644 --- a/acorn.js +++ b/acorn.js @@ -2402,7 +2402,7 @@ } var isGenerator = eat(_star); parsePropertyName(method); - if (tokType === _name && !method.computed && method.key.type === "Identifier" && + if (tokType !== _parenL && !method.computed && method.key.type === "Identifier" && (method.key.name === "get" || method.key.name === "set")) { if (isGenerator) unexpected(); method.kind = method.key.name; diff --git a/test/tests-harmony.js b/test/tests-harmony.js index 539418f870..2302f58f60 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -8304,6 +8304,159 @@ test("class A { static get foo() {} static set foo(v) {} get foo() {} set foo(v) locations: true }); + +test("class A { static [foo]() {} }", { + type: "Program", + loc: { + start: {line: 1, column: 0}, + end: {line: 1, column: 29} + }, + body: [{ + type: "ClassDeclaration", + loc: { + start: {line: 1, column: 0}, + end: {line: 1, column: 29} + }, + id: { + type: "Identifier", + loc: { + start: {line: 1, column: 6}, + end: {line: 1, column: 7} + }, + name: "A" + }, + superClass: null, + body: { + type: "ClassBody", + loc: { + start: {line: 1, column: 8}, + end: {line: 1, column: 29} + }, + body: [{ + type: "MethodDefinition", + loc: { + start: {line: 1, column: 10}, + end: {line: 1, column: 27} + }, + static: true, + computed: true, + key: { + type: "Identifier", + loc: { + start: {line: 1, column: 18}, + end: {line: 1, column: 21} + }, + name: "foo" + }, + kind: "", + value: { + type: "FunctionExpression", + loc: { + start: {line: 1, column: 22}, + end: {line: 1, column: 27} + }, + id: null, + params: [], + defaults: [], + rest: null, + generator: false, + body: { + type: "BlockStatement", + loc: { + start: {line: 1, column: 25}, + end: {line: 1, column: 27} + }, + body: [] + }, + expression: false + } + }] + } + }] +}, { + ecmaVersion: 6, + ranges: true, + locations: true +}); + +test("class A { static get [foo]() {} }", { + type: "Program", + loc: { + start: {line: 1, column: 0}, + end: {line: 1, column: 33} + }, + body: [{ + type: "ClassDeclaration", + loc: { + start: {line: 1, column: 0}, + end: {line: 1, column: 33} + }, + id: { + type: "Identifier", + loc: { + start: {line: 1, column: 6}, + end: {line: 1, column: 7} + }, + range: [ + 6, + 7 + ], + name: "A" + }, + superClass: null, + body: { + type: "ClassBody", + loc: { + start: {line: 1, column: 8}, + end: {line: 1, column: 33} + }, + body: [{ + type: "MethodDefinition", + loc: { + start: {line: 1, column: 10}, + end: {line: 1, column: 31} + }, + static: true, + computed: true, + key: { + type: "Identifier", + loc: { + start: {line: 1, column: 22}, + end: {line: 1, column: 25} + }, + name: "foo" + }, + kind: "get", + value: { + type: "FunctionExpression", + loc: { + start: {line: 1, column: 26}, + end: {line: 1, column: 31} + }, + id: null, + params: [], + defaults: [], + rest: null, + generator: false, + body: { + type: "BlockStatement", + loc: { + start: {line: 1, column: 29}, + end: {line: 1, column: 31} + }, + body: [] + }, + expression: false + } + }] + } + }] +}, { + ecmaVersion: 6, + ranges: true, + locations: true +}); + test("class A { set foo(v) {} get foo() {} }", { type: "Program", body: [{