[Pkg-javascript-commits] [node-acorn-jsx] 215/484: Added computed properties support.
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:31 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 19696af6662391d4a9de593ca1a456bf9c847557
Author: Ingvar Stepanyan <me at rreverser.com>
Date: Thu Jul 24 18:53:54 2014 +0300
Added computed properties support.
---
README.md | 2 ++
acorn.js | 22 +++++++++++++++-------
test/tests-harmony.js | 30 +++++++++++++++---------------
3 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/README.md b/README.md
index a56e755..e50d98e 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
# Acorn
+[![Build Status](https://travis-ci.org/RReverser/acorn.svg?branch=master)](https://travis-ci.org/RReverser/acorn)
+
A tiny, fast JavaScript parser, written completely in JavaScript.
## Installation
diff --git a/acorn.js b/acorn.js
index aa7b519..50a18dd 100644
--- a/acorn.js
+++ b/acorn.js
@@ -1783,12 +1783,11 @@
} else first = false;
var prop = startNode(), kind;
- prop.key = parsePropertyName();
if (options.ecmaVersion >= 6) {
prop.method = false;
prop.shorthand = false;
- prop.computed = false;
}
+ parsePropertyName(prop);
if (eat(_colon)) {
prop.value = parseExpression(true);
kind = prop.kind = "init";
@@ -1798,11 +1797,11 @@
kind = prop.kind = "init";
prop.method = true;
prop.value = func;
- } else if (options.ecmaVersion >= 5 && prop.key.type === "Identifier" &&
+ } else if (options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set")) {
sawGetSet = true;
kind = prop.kind = prop.key.name;
- prop.key = parsePropertyName();
+ parsePropertyName(prop);
if (tokType !== _parenL) unexpected();
var func = parseFunction(startNode(), false, options.ecmaVersion >= 6);
if (func.body.type !== "BlockStatement") {
@@ -1837,9 +1836,18 @@
props.push(current);
}
- function parsePropertyName() {
- if (tokType === _num || tokType === _string) return parseExprAtom();
- return parseIdent(true);
+ function parsePropertyName(prop) {
+ if (options.ecmaVersion >= 6) {
+ if (eat(_bracketL)) {
+ prop.computed = true;
+ prop.key = parseExpression();
+ expect(_bracketR);
+ return;
+ } else {
+ prop.computed = false;
+ }
+ }
+ prop.key = (tokType === _num || tokType === _string) ? parseExprAtom() : parseIdent(true);
}
// Initialize empty function node with given name.
diff --git a/test/tests-harmony.js b/test/tests-harmony.js
index e18edad..1bec7b7 100644
--- a/test/tests-harmony.js
+++ b/test/tests-harmony.js
@@ -10521,10 +10521,10 @@ test("({[x]: 10})", {
end: {line: 1, column: 9}
}
}],
- range: [1, 10],
+ range: [0, 11],
loc: {
- start: {line: 1, column: 1},
- end: {line: 1, column: 10}
+ start: {line: 1, column: 0},
+ end: {line: 1, column: 11}
}
},
range: [0, 11],
@@ -10601,10 +10601,10 @@ test("({[\"x\" + \"y\"]: 10})", {
end: {line: 1, column: 17}
}
}],
- range: [1, 18],
+ range: [0, 19],
loc: {
- start: {line: 1, column: 1},
- end: {line: 1, column: 18}
+ start: {line: 1, column: 0},
+ end: {line: 1, column: 19}
}
},
range: [0, 19],
@@ -10674,10 +10674,10 @@ test("({[x]: function() {}})", {
end: {line: 1, column: 20}
}
}],
- range: [1, 21],
+ range: [0, 22],
loc: {
- start: {line: 1, column: 1},
- end: {line: 1, column: 21}
+ start: {line: 1, column: 0},
+ end: {line: 1, column: 22}
}
},
range: [0, 22],
@@ -10767,10 +10767,10 @@ test("({[x]: 10, y: 20})", {
}
}
],
- range: [1, 17],
+ range: [0, 18],
loc: {
- start: {line: 1, column: 1},
- end: {line: 1, column: 17}
+ start: {line: 1, column: 0},
+ end: {line: 1, column: 18}
}
},
range: [0, 18],
@@ -10967,10 +10967,10 @@ test("({[x]() {}})", {
end: {line: 1, column: 10}
}
}],
- range: [1, 11],
+ range: [0, 12],
loc: {
- start: {line: 1, column: 1},
- end: {line: 1, column: 11}
+ start: {line: 1, column: 0},
+ end: {line: 1, column: 12}
}
},
range: [0, 12],
--
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