[Pkg-javascript-commits] [node-acorn-jsx] 383/484: Allow `static` as method name in class (fixes #192).
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:59 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit bc2e01aa03ef33d25bf866605cdeb5e88ffe0b5f
Author: Ingvar Stepanyan <me at rreverser.com>
Date: Fri Jan 9 15:31:01 2015 +0200
Allow `static` as method name in class (fixes #192).
Add uncommitted tests for #191.
---
acorn.js | 11 ++--
acorn_loose.js | 14 ++++-
test/tests-harmony.js | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 176 insertions(+), 6 deletions(-)
diff --git a/acorn.js b/acorn.js
index 2a7c89e..90eee06 100644
--- a/acorn.js
+++ b/acorn.js
@@ -2510,14 +2510,17 @@
expect(_braceL);
while (!eat(_braceR)) {
var method = startNode();
- if (tokType === _name && tokVal === "static") {
- next();
+ var isGenerator = eat(_star);
+ parsePropertyName(method);
+ if (tokType !== _parenL && !method.computed && method.key.type === "Identifier" &&
+ method.key.name === "static") {
+ if (isGenerator) unexpected();
method['static'] = true;
+ isGenerator = eat(_star);
+ parsePropertyName(method);
} else {
method['static'] = false;
}
- var isGenerator = eat(_star);
- parsePropertyName(method);
if (tokType !== _parenL && !method.computed && method.key.type === "Identifier" &&
(method.key.name === "get" || method.key.name === "set")) {
if (isGenerator) unexpected();
diff --git a/acorn_loose.js b/acorn_loose.js
index 33a3cfe..010a2d7 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -862,7 +862,7 @@
var prop = startNode(), isGenerator;
if (options.ecmaVersion >= 6) {
if (isClass) {
- if (prop['static'] = (token.type === tt.name && token.value === "static")) next();
+ prop['static'] = false;
} else {
prop.method = false;
prop.shorthand = false;
@@ -871,6 +871,16 @@
}
parsePropertyName(prop);
if (isDummy(prop.key)) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
+ if (isClass) {
+ if (prop.key.type === "Identifier" && !prop.computed && prop.key.name === "static" &&
+ (token.type != tt.parenL && token.type != tt.braceL)) {
+ prop['static'] = true;
+ isGenerator = eat(tt.star);
+ parsePropertyName(prop);
+ } else {
+ prop['static'] = false;
+ }
+ }
if (!isClass && eat(tt.colon)) {
prop.kind = "init";
prop.value = parseExpression(true);
@@ -883,7 +893,7 @@
}
prop.value = parseMethod(isGenerator);
} else if (options.ecmaVersion >= 5 && prop.key.type === "Identifier" &&
- (prop.key.name === "get" || prop.key.name === "set") &&
+ !prop.computed && (prop.key.name === "get" || prop.key.name === "set") &&
(token.type != tt.comma && token.type != tt.braceR)) {
prop.kind = prop.key.name;
parsePropertyName(prop);
diff --git a/test/tests-harmony.js b/test/tests-harmony.js
index bb84065..e382754 100644
--- a/test/tests-harmony.js
+++ b/test/tests-harmony.js
@@ -14598,3 +14598,160 @@ test("var [localVar = defaultValue] = obj", {
locations: true,
loose: false
});
+
+// https://github.com/marijnh/acorn/issues/191
+
+test("try {} catch ({message}) {}", {
+ type: "Program",
+ range: [0, 27],
+ body: [{
+ type: "TryStatement",
+ range: [0, 27],
+ block: {
+ type: "BlockStatement",
+ range: [4, 6],
+ body: []
+ },
+ handler: {
+ type: "CatchClause",
+ range: [7, 27],
+ param: {
+ type: "ObjectPattern",
+ range: [14, 23],
+ properties: [{
+ type: "Property",
+ range: [15, 22],
+ method: false,
+ shorthand: true,
+ computed: false,
+ key: {
+ type: "Identifier",
+ range: [15, 22],
+ name: "message"
+ },
+ kind: "init",
+ value: {
+ type: "Identifier",
+ range: [15, 22],
+ name: "message"
+ }
+ }]
+ },
+ guard: null,
+ body: {
+ type: "BlockStatement",
+ range: [25, 27],
+ body: []
+ }
+ },
+ guardedHandlers: [],
+ finalizer: null
+ }]
+}, {
+ ecmaVersion: 6,
+ ranges: true,
+ locations: true,
+ loose: false
+});
+
+// https://github.com/marijnh/acorn/issues/192
+
+test("class A { static() {} }", {
+ type: "Program",
+ range: [0, 23],
+ body: [{
+ type: "ClassDeclaration",
+ range: [0, 23],
+ id: {
+ type: "Identifier",
+ range: [6, 7],
+ name: "A"
+ },
+ superClass: null,
+ body: {
+ type: "ClassBody",
+ range: [8, 23],
+ body: [{
+ type: "MethodDefinition",
+ range: [10, 21],
+ computed: false,
+ key: {
+ type: "Identifier",
+ range: [10, 16],
+ name: "static"
+ },
+ static: false,
+ kind: "",
+ value: {
+ type: "FunctionExpression",
+ range: [16, 21],
+ id: null,
+ params: [],
+ defaults: [],
+ rest: null,
+ generator: false,
+ body: {
+ type: "BlockStatement",
+ range: [19, 21],
+ body: []
+ },
+ expression: false
+ }
+ }]
+ }
+ }]
+}, {
+ ecmaVersion: 6,
+ ranges: true,
+ locations: true
+});
+
+test("class A { *static() {} }", {
+ type: "Program",
+ range: [0, 24],
+ body: [{
+ type: "ClassDeclaration",
+ range: [0, 24],
+ id: {
+ type: "Identifier",
+ range: [6, 7],
+ name: "A"
+ },
+ superClass: null,
+ body: {
+ type: "ClassBody",
+ range: [8, 24],
+ body: [{
+ type: "MethodDefinition",
+ range: [10, 22],
+ computed: false,
+ key: {
+ type: "Identifier",
+ range: [11, 17],
+ name: "static"
+ },
+ static: false,
+ kind: "",
+ value: {
+ type: "FunctionExpression",
+ range: [17, 22],
+ id: null,
+ params: [],
+ defaults: [],
+ rest: null,
+ generator: true,
+ body: {
+ type: "BlockStatement",
+ range: [20, 22],
+ body: []
+ },
+ expression: false
+ }
+ }]
+ }
+ }]
+}, {
+ ecmaVersion: 6,
+ ranges: true,
+ locations: true
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list