From 0084ac14ae807f3f796474e2af65c0d1a94f91b7 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Tue, 30 Dec 2014 13:42:06 +0200 Subject: [PATCH 1/2] Fixed #186. --- acorn.js | 3 ++- acorn_loose.js | 3 ++- test/tests-harmony.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/acorn.js b/acorn.js index 3f15583c13..1208b8775d 100644 --- a/acorn.js +++ b/acorn.js @@ -2223,7 +2223,8 @@ prop.method = true; prop.value = parseMethod(isGenerator); } else if (options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && - (prop.key.name === "get" || prop.key.name === "set")) { + (prop.key.name === "get" || prop.key.name === "set") && + (tokType != _comma && tokType != _braceR)) { if (isGenerator) unexpected(); prop.kind = prop.key.name; parsePropertyName(prop); diff --git a/acorn_loose.js b/acorn_loose.js index 6262162382..a0d822a8a5 100644 --- a/acorn_loose.js +++ b/acorn_loose.js @@ -882,7 +882,8 @@ } prop.value = parseMethod(isGenerator); } else if (options.ecmaVersion >= 5 && prop.key.type === "Identifier" && - (prop.key.name === "get" || prop.key.name === "set")) { + (prop.key.name === "get" || prop.key.name === "set") && + (token.type != tt.comma && token.type != tt.braceR)) { prop.kind = prop.key.name; parsePropertyName(prop); prop.value = parseMethod(false); diff --git a/test/tests-harmony.js b/test/tests-harmony.js index fbe33bee07..1dbbefff68 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -14405,3 +14405,37 @@ test("`{${x}}`, `}`", { } }] }, {ecmaVersion: 6}); + +// https://github.com/marijnh/acorn/issues/186 +test('var {get} = obj;', { + type: "Program", + body: [{ + type: "VariableDeclaration", + declarations: [{ + type: "VariableDeclarator", + id: { + type: "ObjectPattern", + properties: [{ + type: "Property", + method: false, + shorthand: true, + computed: false, + key: { + type: "Identifier", + name: "get" + }, + kind: "init", + value: { + type: "Identifier", + name: "get" + } + }] + }, + init: { + type: "Identifier", + name: "obj" + } + }], + kind: "var" + }] +}, {ecmaVersion: 6}); From 0b59fc198baf2cd970091ee96fe5dd0f90034692 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 30 Dec 2014 12:53:58 +0100 Subject: [PATCH 2/2] Require superclass expressions to be lvals And remove a test that violates this. Closes #185 --- acorn.js | 1 + test/tests-harmony.js | 66 ------------------------------------------- 2 files changed, 1 insertion(+), 66 deletions(-) diff --git a/acorn.js b/acorn.js index 1208b8775d..1d33a45194 100644 --- a/acorn.js +++ b/acorn.js @@ -2406,6 +2406,7 @@ next(); node.id = tokType === _name ? parseIdent() : isStatement ? unexpected() : null; node.superClass = eat(_extends) ? parseExpression() : null; + if (node.superClass) checkLVal(node.superClass); var classBody = startNode(); classBody.body = []; expect(_braceL); diff --git a/test/tests-harmony.js b/test/tests-harmony.js index 1dbbefff68..c7cd8ea072 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -6465,72 +6465,6 @@ test("var A = class extends B {}", { locations: true }); -test("class A extends class B extends C {} {}", { - type: "Program", - body: [{ - type: "ClassDeclaration", - id: { - type: "Identifier", - name: "A", - loc: { - start: {line: 1, column: 6}, - end: {line: 1, column: 7} - } - }, - superClass: { - type: "ClassExpression", - id: { - type: "Identifier", - name: "B", - loc: { - start: {line: 1, column: 22}, - end: {line: 1, column: 23} - } - }, - superClass: { - type: "Identifier", - name: "C", - loc: { - start: {line: 1, column: 32}, - end: {line: 1, column: 33} - } - }, - body: { - type: "ClassBody", - body: [], - loc: { - start: {line: 1, column: 34}, - end: {line: 1, column: 36} - } - }, - loc: { - start: {line: 1, column: 16}, - end: {line: 1, column: 36} - } - }, - body: { - type: "ClassBody", - body: [], - loc: { - start: {line: 1, column: 37}, - end: {line: 1, column: 39} - } - }, - loc: { - start: {line: 1, column: 0}, - end: {line: 1, column: 39} - } - }], - loc: { - start: {line: 1, column: 0}, - end: {line: 1, column: 39} - } -}, { - ecmaVersion: 6, - ranges: true, - locations: true -}); - test("class A {get() {}}", { type: "Program", body: [{