[Pkg-javascript-commits] [node-acorn-jsx] 253/484: Allow computed class method names (as per ariya/esprima#271).
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:40 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 ff9c3550a4d5159139f0689765b6fec04789d79a
Author: Ingvar Stepanyan <me at rreverser.com>
Date: Sun Jul 27 04:46:06 2014 +0300
Allow computed class method names (as per ariya/esprima#271).
---
acorn.js | 8 ++--
test/tests-harmony.js | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 133 insertions(+), 3 deletions(-)
diff --git a/acorn.js b/acorn.js
index fcb3776..4dda5b6 100644
--- a/acorn.js
+++ b/acorn.js
@@ -1291,6 +1291,7 @@
// strict mode, init properties are also not allowed to be repeated.
function checkPropClash(prop, propHash) {
+ if (prop.computed) return;
var key = prop.key, name;
switch (key.type) {
case "Identifier": name = key.name; break;
@@ -2234,11 +2235,12 @@
method.static = false;
}
var isGenerator = eat(_star);
- method.key = parseIdent(true);
- if ((method.key.name === "get" || method.key.name === "set") && tokType === _name) {
+ parsePropertyName(method);
+ if (tokType === _name && !method.computed && method.key.type === "Identifier" &&
+ (method.key.name === "get" || method.key.name === "set")) {
if (isGenerator) unexpected();
method.kind = method.key.name;
- method.key = parseIdent(true);
+ parsePropertyName(method);
} else {
method.kind = "";
}
diff --git a/test/tests-harmony.js b/test/tests-harmony.js
index a6ec0f2..5bfba14 100644
--- a/test/tests-harmony.js
+++ b/test/tests-harmony.js
@@ -7111,6 +7111,7 @@ test("class A {get() {}}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "get",
@@ -7192,6 +7193,7 @@ test("class A { static get() {}}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "get",
@@ -7281,6 +7283,7 @@ test("class A extends B {get foo() {}}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -7370,6 +7373,7 @@ test("class A extends B { static get foo() {}}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -7451,6 +7455,7 @@ test("class A {set a(v) {}}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "a",
@@ -7540,6 +7545,7 @@ test("class A { static set a(v) {}}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "a",
@@ -7629,6 +7635,7 @@ test("class A {set(v) {};}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "set",
@@ -7718,6 +7725,7 @@ test("class A { static set(v) {};}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "set",
@@ -7807,6 +7815,7 @@ test("class A {*gen(v) { yield v; }}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "gen",
@@ -7921,6 +7930,7 @@ test("class A { static *gen(v) { yield v; }}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "gen",
@@ -8056,6 +8066,7 @@ test("\"use strict\"; (class A {constructor() { super() }})", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "constructor",
@@ -8169,6 +8180,7 @@ test("class A {static foo() {}}", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -8251,6 +8263,7 @@ test("class A {foo() {} static bar() {}}", {
body: [
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -8293,6 +8306,7 @@ test("class A {foo() {} static bar() {}}", {
},
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "bar",
@@ -8396,6 +8410,7 @@ test("\"use strict\"; (class A { static constructor() { super() }})", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "constructor",
@@ -8510,6 +8525,7 @@ test("class A { foo() {} bar() {}}", {
body: [
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -8552,6 +8568,7 @@ test("class A { foo() {} bar() {}}", {
},
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "bar",
@@ -8635,6 +8652,7 @@ test("class A { get foo() {} set foo(v) {}}", {
body: [
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -8677,6 +8695,7 @@ test("class A { get foo() {} set foo(v) {}}", {
},
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -8768,6 +8787,7 @@ test("class A { static get foo() {} get foo() {}}", {
body: [
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -8810,6 +8830,7 @@ test("class A { static get foo() {} get foo() {}}", {
},
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -8893,6 +8914,7 @@ test("class A { static get foo() {} static get bar() {} }", {
body: [
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -8935,6 +8957,7 @@ test("class A { static get foo() {} static get bar() {} }", {
},
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "bar",
@@ -9018,6 +9041,7 @@ test("class A { static get foo() {} static set foo(v) {} get foo() {} set foo(v)
body: [
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -9060,6 +9084,7 @@ test("class A { static get foo() {} static set foo(v) {} get foo() {} set foo(v)
},
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -9110,6 +9135,7 @@ test("class A { static get foo() {} static set foo(v) {} get foo() {} set foo(v)
},
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -9152,6 +9178,7 @@ test("class A { static get foo() {} static set foo(v) {} get foo() {} set foo(v)
},
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -9243,6 +9270,7 @@ test("class A { set foo(v) {} get foo() {} }", {
body: [
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -9293,6 +9321,7 @@ test("class A { set foo(v) {} get foo() {} }", {
},
{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "foo",
@@ -10180,6 +10209,104 @@ test("var x = {*[test]() { yield *v; }}", {
locations: true
});
+test("class A {[x]() {}}", {
+ type: "Program",
+ start: 0,
+ end: 18,
+ loc: {
+ start: {line: 1, column: 0},
+ end: {line: 1, column: 18}
+ },
+ range: [0, 18],
+ body: [{
+ type: "ClassDeclaration",
+ start: 0,
+ end: 18,
+ loc: {
+ start: {line: 1, column: 0},
+ end: {line: 1, column: 18}
+ },
+ range: [0, 18],
+ id: {
+ type: "Identifier",
+ start: 6,
+ end: 7,
+ loc: {
+ start: {line: 1, column: 6},
+ end: {line: 1, column: 7}
+ },
+ range: [6, 7],
+ name: "A"
+ },
+ superClass: null,
+ body: {
+ type: "ClassBody",
+ start: 8,
+ end: 18,
+ loc: {
+ start: {line: 1, column: 8},
+ end: {line: 1, column: 18}
+ },
+ range: [8, 18],
+ body: [{
+ type: "MethodDefinition",
+ start: 9,
+ end: 17,
+ loc: {
+ start: {line: 1, column: 9},
+ end: {line: 1, column: 17}
+ },
+ range: [9, 17],
+ static: false,
+ computed: true,
+ key: {
+ type: "Identifier",
+ start: 10,
+ end: 11,
+ loc: {
+ start: {line: 1, column: 10},
+ end: {line: 1, column: 11}
+ },
+ range: [10, 11],
+ name: "x"
+ },
+ kind: "",
+ value: {
+ type: "FunctionExpression",
+ start: 12,
+ end: 17,
+ loc: {
+ start: {line: 1, column: 12},
+ end: {line: 1, column: 17}
+ },
+ range: [12, 17],
+ id: null,
+ params: [],
+ defaults: [],
+ rest: null,
+ generator: false,
+ body: {
+ type: "BlockStatement",
+ start: 15,
+ end: 17,
+ loc: {
+ start: {line: 1, column: 15},
+ end: {line: 1, column: 17}
+ },
+ range: [15, 17],
+ body: []
+ },
+ expression: false
+ }
+ }]
+ }
+ }]
+}, {
+ ecmaVersion: 6,
+ ranges: true,
+ locations: true
+});
+
testFail("({[x]})", "Unexpected token (1:5)", {ecmaVersion: 6});
// ES6: Default parameters
@@ -10824,6 +10951,7 @@ test("(class {f({x} = {x: 10}) {}})", {
type: "ClassBody",
body: [{
type: "MethodDefinition",
+ computed: false,
key: {
type: "Identifier",
name: "f",
--
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