[Pkg-javascript-commits] [node-acorn-object-spread] 01/02: New upstream version 3.1.0
Julien Puydt
julien.puydt at laposte.net
Fri Nov 3 19:07:32 UTC 2017
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-acorn-object-spread.
commit d48b36d32dd2b07590c99c4a9c7982edee142eae
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Fri Nov 3 14:29:29 2017 +0100
New upstream version 3.1.0
---
.editorconfig | 7 +
.gitattributes | 1 +
.gitignore | 1 +
.npmignore | 2 +
.travis.yml | 2 +
CHANGELOG.md | 14 +
LICENSE | 19 +
README.md | 49 +++
index.js | 3 +
inject.js | 108 ++++++
package.json | 21 ++
test/driver.js | 102 ++++++
test/run.js | 70 ++++
test/tests-object-spread.js | 855 ++++++++++++++++++++++++++++++++++++++++++++
14 files changed, 1254 insertions(+)
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..c14d5c6
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,7 @@
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+end_of_line = lf
+insert_final_newline = true
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..fcadb2c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text eol=lf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..07e6e47
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/node_modules
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..2c630f1
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,2 @@
+test
+.*
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..ffb9f71
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,2 @@
+language: node_js
+node_js: '0.10'
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..9e14cba
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,14 @@
+# acorn5-object-spread changelog
+
+## 3.1.0
+
+* Support complex rest properties like `{...{a = 5, ...as}}`
+* Support rest properties in arrow function arguments
+* Fail if rest property is not last property or has a trailing comma
+* Detect duplicate exports with rest properties
+* Don't complain about duplicate property names in patterns
+
+## 3.0.0
+
+* Support rest properties
+* Emit `SpreadElement` instead of `SpreadProperty` nodes
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..e2742a4
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (C) 2016 by UXtemple
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f8e9777
--- /dev/null
+++ b/README.md
@@ -0,0 +1,49 @@
+# Spread and rest properties support in acorn 5
+
+[![NPM version](https://img.shields.io/npm/v/acorn5-object-spread.svg)](https://www.npmjs.org/package/acorn5-object-spread)
+
+This is plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript.
+
+It implements support for spread and rest properties as defined in the stage 3 proposal [Object Rest/Spread Properties for ECMAScript](https://github.com/tc39/proposal-object-rest-spread).
+
+## Usage
+
+You can use this module directly in order to get an Acorn instance with the plugin installed:
+
+```javascript
+var acorn = require('acorn5-object-spread');
+```
+
+Or you can use `inject.js` for injecting the plugin into your own version of Acorn like this:
+
+```javascript
+var acorn = require('acorn5-object-spread/inject')(require('./custom-acorn'));
+```
+
+Then, use the `plugins` option whenever you need to support object spread or rest while parsing:
+
+```javascript
+var ast = acorn.parse(code, {
+ plugins: { objectSpread: true }
+});
+```
+
+## Differences to acorn-object-rest-spread
+
+[acorn-object-rest-spread](https://github.com/victor-homyakov/acorn-object-rest-spread)
+is another acorn plugin implementing the same spec. There are some differences, though:
+
+* acorn-object-rest-spread overwrites acorn`s `parseObj` with a modified copy from acorn 4,
+ so that an acorn instance with that plugin cannot for example parse `({async, foo})`
+* acorn-object-rest-spread emits `SpreadElement`s with a
+ [non-standard](https://github.com/estree/estree/blob/master/es2015.md#expressions)
+ `value` property
+* acorn-object-rest-spread emits `SpreadElement`s in arrow function argument patterns
+ and nested object patterns were it should emit `RestElement`s
+* acorn-object-rest-spread doesn't check for invalid trailing commas in rest properties
+
+## License
+
+This plugin is issued under the [MIT license](./LICENSE).
+
+With <3 by UXtemple.
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..58c8677
--- /dev/null
+++ b/index.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = require('./inject')(require('acorn'));
diff --git a/inject.js b/inject.js
new file mode 100644
index 0000000..5b6abcc
--- /dev/null
+++ b/inject.js
@@ -0,0 +1,108 @@
+'use strict';
+
+module.exports = function(acorn) {
+ if (acorn.version.substr(0, 1) !== "5") {
+ throw new Error("Unsupported acorn version " + acorn.version + ", please use acorn 5");
+ }
+ var tt = acorn.tokTypes;
+ var pp = acorn.Parser.prototype;
+
+ // this is the same parseObj that acorn has with...
+ function parseObj(isPattern, refDestructuringErrors) {
+ let node = this.startNode(), first = true, propHash = {}
+ node.properties = []
+ this.next()
+ while (!this.eat(tt.braceR)) {
+ if (!first) {
+ this.expect(tt.comma)
+ if (this.afterTrailingComma(tt.braceR)) break
+ } else first = false
+
+ let prop = this.startNode(), isGenerator, isAsync, startPos, startLoc
+ if (this.options.ecmaVersion >= 6) {
+ // ...the spread logic borrowed from babylon :)
+ if (this.type === tt.ellipsis) {
+ prop = isPattern ? this.parseRestBinding() : this.parseSpread(refDestructuringErrors)
+ node.properties.push(prop)
+ if (this.type === tt.comma) {
+ if (isPattern) {
+ this.raise(this.start, "Comma is not permitted after the rest element")
+ } else if (refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
+ refDestructuringErrors.trailingComma = this.start
+ }
+ }
+ continue
+ }
+
+ prop.method = false
+ prop.shorthand = false
+ if (isPattern || refDestructuringErrors) {
+ startPos = this.start
+ startLoc = this.startLoc
+ }
+ if (!isPattern)
+ isGenerator = this.eat(tt.star)
+ }
+ this.parsePropertyName(prop)
+ if (!isPattern && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
+ isAsync = true
+ this.parsePropertyName(prop, refDestructuringErrors)
+ } else {
+ isAsync = false
+ }
+ this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors)
+ if (!isPattern) this.checkPropClash(prop, propHash)
+ node.properties.push(this.finishNode(prop, "Property"))
+ }
+ return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
+ }
+
+ const getCheckLVal = origCheckLVal => function (expr, bindingType, checkClashes) {
+ if (expr.type == "ObjectPattern") {
+ for (let prop of expr.properties)
+ this.checkLVal(prop, bindingType, checkClashes)
+ return
+ } else if (expr.type === "Property") {
+ // AssignmentProperty has type == "Property"
+ return this.checkLVal(expr.value, bindingType, checkClashes)
+ }
+ return origCheckLVal.apply(this, arguments)
+ }
+
+ acorn.plugins.objectSpread = function objectSpreadPlugin(instance) {
+ pp.parseObj = parseObj;
+ instance.extend("checkLVal", getCheckLVal)
+ instance.extend("toAssignable", nextMethod => function(node, isBinding) {
+ if (this.options.ecmaVersion >= 6 && node) {
+ if (node.type == "ObjectExpression") {
+ node.type = "ObjectPattern"
+ for (let prop of node.properties)
+ this.toAssignable(prop, isBinding)
+ return node
+ } else if (node.type === "Property") {
+ // AssignmentProperty has type == "Property"
+ if (node.kind !== "init") this.raise(node.key.start, "Object pattern can't contain getter or setter")
+ return this.toAssignable(node.value, isBinding)
+ } else if (node.type === "SpreadElement") {
+ node.type = "RestElement"
+ return this.toAssignable(node.argument, isBinding)
+ }
+ }
+ return nextMethod.apply(this, arguments)
+ })
+ instance.extend("checkPatternExport", nextMethod => function(exports, pat) {
+ if (pat.type == "ObjectPattern") {
+ for (let prop of pat.properties)
+ this.checkPatternExport(exports, prop)
+ return
+ } else if (pat.type === "Property") {
+ return this.checkPatternExport(exports, pat.value)
+ } else if (pat.type === "RestElement") {
+ return this.checkPatternExport(exports, pat.argument)
+ }
+ nextMethod.apply(this, arguments)
+ })
+ };
+
+ return acorn;
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..ec81139
--- /dev/null
+++ b/package.json
@@ -0,0 +1,21 @@
+{
+ "name": "acorn5-object-spread",
+ "description": "Support for rest and spread properties in acorn 5",
+ "homepage": "https://github.com/adrianheine/acorn5-object-spread",
+ "contributors": [
+ "Darío Javier Cravero <dario at uxtemple.com>",
+ "Adrian Heine <mail at adrianheine.de>"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/adrianheine/acorn5-object-spread"
+ },
+ "license": "MIT",
+ "scripts": {
+ "test": "node test/run.js"
+ },
+ "dependencies": {
+ "acorn": "^5.1.2"
+ },
+ "version": "3.1.0"
+}
diff --git a/test/driver.js b/test/driver.js
new file mode 100644
index 0000000..49d7c5d
--- /dev/null
+++ b/test/driver.js
@@ -0,0 +1,102 @@
+var tests = [];
+
+exports.test = function(code, ast, options) {
+ tests.push({code: code, ast: ast, options: options});
+};
+exports.testFail = function(code, message, options) {
+ tests.push({code: code, error: message, options: options});
+};
+exports.testAssert = function(code, assert, options) {
+ tests.push({code: code, assert: assert, options: options});
+};
+
+exports.runTests = function(config, callback) {
+ var parse = config.parse;
+
+ for (var i = 0; i < tests.length; ++i) {
+ var test = tests[i];
+ if (config.filter && !config.filter(test)) continue;
+ try {
+ var testOpts = test.options || {locations: true};
+ var expected = {};
+ if (expected.onComment = testOpts.onComment) {
+ testOpts.onComment = []
+ }
+ if (expected.onToken = testOpts.onToken) {
+ testOpts.onToken = [];
+ }
+ testOpts.plugins = testOpts.plugins || { objectSpread: true };
+ var ast = parse(test.code, testOpts);
+
+ if (test.error) {
+ if (config.loose) {
+ callback("ok", test.code);
+ } else {
+ callback("fail", test.code, "Expected error message: " + test.error + "\nBut parsing succeeded.");
+ }
+ }
+ else if (test.assert) {
+ var error = test.assert(ast);
+ if (error) callback("fail", test.code,
+ "\n Assertion failed:\n " + error);
+ else callback("ok", test.code);
+ } else {
+ var mis = misMatch(test.ast, ast);
+ for (var name in expected) {
+ if (mis) break;
+ if (expected[name]) {
+ mis = misMatch(expected[name], testOpts[name]);
+ testOpts[name] = expected[name];
+ }
+ }
+ if (mis) callback("fail", test.code, mis);
+ else callback("ok", test.code);
+ }
+ } catch(e) {
+ if (!(e instanceof SyntaxError)) {
+ throw e;
+ }
+ if (test.error) {
+ if (e.message == test.error) callback("ok", test.code);
+ else callback("fail", test.code,
+ "Expected error message: " + test.error + "\nGot error message: " + e.message);
+ } else {
+ callback("error", test.code, e.stack || e.toString());
+ }
+ }
+ }
+};
+
+function ppJSON(v) { return v instanceof RegExp ? v.toString() : JSON.stringify(v, null, 2); }
+function addPath(str, pt) {
+ if (str.charAt(str.length-1) == ")")
+ return str.slice(0, str.length-1) + "/" + pt + ")";
+ return str + " (" + pt + ")";
+}
+
+var misMatch = exports.misMatch = function(exp, act) {
+ if (!exp || !act || (typeof exp != "object") || (typeof act != "object")) {
+ if (exp !== act) return ppJSON(exp) + " !== " + ppJSON(act);
+ } else if (exp instanceof RegExp || act instanceof RegExp) {
+ var left = ppJSON(exp), right = ppJSON(act);
+ if (left !== right) return left + " !== " + right;
+ } else if (exp.splice) {
+ if (!act.slice) return ppJSON(exp) + " != " + ppJSON(act);
+ if (act.length != exp.length) return "array length mismatch " + exp.length + " != " + act.length;
+ for (var i = 0; i < act.length; ++i) {
+ var mis = misMatch(exp[i], act[i]);
+ if (mis) return addPath(mis, i);
+ }
+ } else {
+ for (var prop in exp) {
+ var mis = misMatch(exp[prop], act[prop]);
+ if (mis) return addPath(mis, prop);
+ }
+ for (var prop in act) {
+ if (!(prop in exp)) {
+ var mis = misMatch(exp[prop], act[prop]);
+ if (mis) return addPath(mis, prop);
+ }
+ }
+ }
+};
diff --git a/test/run.js b/test/run.js
new file mode 100644
index 0000000..cf1151f
--- /dev/null
+++ b/test/run.js
@@ -0,0 +1,70 @@
+var driver = require("./driver.js");
+require("./tests-object-spread.js");
+
+function group(name) {
+ if (typeof console === "object" && console.group) {
+ console.group(name);
+ }
+}
+
+function groupEnd() {
+ if (typeof console === "object" && console.groupEnd) {
+ console.groupEnd(name);
+ }
+}
+
+function log(title, message) {
+ if (typeof console === "object") console.log(title, message);
+}
+
+var stats, modes = {
+ Normal: {
+ config: {
+ parse: require("..").parse
+ }
+ }
+};
+
+function report(state, code, message) {
+ if (state != "ok") {++stats.failed; log(code, message);}
+ ++stats.testsRun;
+}
+
+group("Errors");
+
+for (var name in modes) {
+ group(name);
+ var mode = modes[name];
+ stats = mode.stats = {testsRun: 0, failed: 0};
+ var t0 = +new Date;
+ driver.runTests(mode.config, report);
+ mode.stats.duration = +new Date - t0;
+ groupEnd();
+}
+
+groupEnd();
+
+function outputStats(name, stats) {
+ log(name + ":", stats.testsRun + " tests run in " + stats.duration + "ms; " +
+ (stats.failed ? stats.failed + " failures." : "all passed."));
+}
+
+var total = {testsRun: 0, failed: 0, duration: 0};
+
+group("Stats");
+
+for (var name in modes) {
+ var stats = modes[name].stats;
+ outputStats(name + " parser", stats);
+ for (var key in stats) total[key] += stats[key];
+}
+
+outputStats("Total", total);
+
+groupEnd();
+
+if (total.failed && typeof process === "object") {
+ process.stdout.write("", function() {
+ process.exit(1);
+ });
+}
diff --git a/test/tests-object-spread.js b/test/tests-object-spread.js
new file mode 100644
index 0000000..8096156
--- /dev/null
+++ b/test/tests-object-spread.js
@@ -0,0 +1,855 @@
+// ObjectSpread tests
+
+var fbTestFixture = {
+ // Taken and adapted from babylon's tests.
+ parseObj: {
+ "function fn({__proto__: a, __proto__: b}) {}": {
+ "type": "FunctionDeclaration",
+ "start": 0,
+ "end": 44,
+ "id": {
+ "type": "Identifier",
+ "start": 9,
+ "end": 11,
+ "name": "fn"
+ },
+ "generator": false,
+ "expression": false,
+ "params": [
+ {
+ "type": "ObjectPattern",
+ "start": 12,
+ "end": 40,
+ "properties": [
+ {
+ "type": "Property",
+ "start": 13,
+ "end": 25,
+ "method": false,
+ "shorthand": false,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 13,
+ "end": 22,
+ "name": "__proto__"
+ },
+ "value": {
+ "type": "Identifier",
+ "start": 24,
+ "end": 25,
+ "name": "a"
+ },
+ "kind": "init"
+ },
+ {
+ "type": "Property",
+ "start": 27,
+ "end": 39,
+ "method": false,
+ "shorthand": false,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 27,
+ "end": 36,
+ "name": "__proto__"
+ },
+ "value": {
+ "type": "Identifier",
+ "start": 38,
+ "end": 39,
+ "name": "b"
+ },
+ "kind": "init"
+ }
+ ]
+ }
+ ],
+ "body": {
+ "type": "BlockStatement",
+ "start": 42,
+ "end": 44,
+ "body": []
+ }
+ },
+ 'obj = { then: 1, catch: 2 }': {
+ type: "ExpressionStatement",
+ start: 0,
+ end: 27,
+ expression: {
+ "type": "AssignmentExpression",
+ "start": 0,
+ "end": 27,
+ "operator": "=",
+ "left": {
+ "type": "Identifier",
+ "start": 0,
+ "end": 3,
+ "name": "obj"
+ },
+ "right": {
+ "type": "ObjectExpression",
+ "start": 6,
+ "end": 27,
+ "properties": [
+ {
+ "type": "Property",
+ "start": 8,
+ "end": 15,
+ "method": false,
+ "shorthand": false,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 8,
+ "end": 12,
+ "name": "then"
+ },
+ "value": {
+ "type": "Literal",
+ "start": 14,
+ "end": 15,
+ "value": 1,
+ "raw": "1"
+ },
+ "kind": "init"
+ },
+ {
+ "type": "Property",
+ "start": 17,
+ "end": 25,
+ "method": false,
+ "shorthand": false,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 17,
+ "end": 22,
+ "name": "catch"
+ },
+ "value": {
+ "type": "Literal",
+ "start": 24,
+ "end": 25,
+ "value": 2,
+ "raw": "2"
+ },
+ "kind": "init"
+ }
+ ]
+ }
+ }
+ }
+ },
+ 'ObjectSpread': {
+ 'let z = {...x}': {
+ "type": "VariableDeclaration",
+ "start": 0,
+ "end": 14,
+ "declarations": [
+ {
+ "type": "VariableDeclarator",
+ "start": 4,
+ "end": 14,
+ "id": {
+ "type": "Identifier",
+ "start": 4,
+ "end": 5,
+ "name": "z"
+ },
+ "init": {
+ "type": "ObjectExpression",
+ "start": 8,
+ "end": 14,
+ "properties": [
+ {
+ "type": "SpreadElement",
+ "start": 9,
+ "end": 13,
+ "argument": {
+ "type": "Identifier",
+ "start": 12,
+ "end": 13,
+ "name": "x"
+ }
+ }
+ ]
+ }
+ }
+ ],
+ "kind": "let"
+ },
+ 'z = {x, ...y}': {
+ "type": "ExpressionStatement",
+ "start": 0,
+ "end": 13,
+ "expression": {
+ "type": "AssignmentExpression",
+ "start": 0,
+ "end": 13,
+ "operator": "=",
+ "left": {
+ "type": "Identifier",
+ "start": 0,
+ "end": 1,
+ "name": "z"
+ },
+ "right": {
+ "type": "ObjectExpression",
+ "start": 4,
+ "end": 13,
+ "properties": [
+ {
+ "type": "Property",
+ "start": 5,
+ "end": 6,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 5,
+ "end": 6,
+ "name": "x"
+ },
+ "value": {
+ "type": "Identifier",
+ "start": 5,
+ "end": 6,
+ "name": "x"
+ },
+ "kind": "init"
+ },
+ {
+ "type": "SpreadElement",
+ "start": 8,
+ "end": 12,
+ "argument": {
+ "type": "Identifier",
+ "start": 11,
+ "end": 12,
+ "name": "y"
+ }
+ }
+ ]
+ }
+ }
+ },
+ '({x, ...y, a, ...b, c})': {
+ "type": "ExpressionStatement",
+ "start": 0,
+ "end": 23,
+ "expression": {
+ "type": "ObjectExpression",
+ "start": 1,
+ "end": 22,
+ "properties": [
+ {
+ "type": "Property",
+ "start": 2,
+ "end": 3,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 2,
+ "end": 3,
+ "name": "x"
+ },
+ "value": {
+ "type": "Identifier",
+ "start": 2,
+ "end": 3,
+ "name": "x"
+ },
+ "kind": "init"
+ },
+ {
+ "type": "SpreadElement",
+ "start": 5,
+ "end": 9,
+ "argument": {
+ "type": "Identifier",
+ "start": 8,
+ "end": 9,
+ "name": "y"
+ }
+ },
+ {
+ "type": "Property",
+ "start": 11,
+ "end": 12,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 11,
+ "end": 12,
+ "name": "a"
+ },
+ "value": {
+ "type": "Identifier",
+ "start": 11,
+ "end": 12,
+ "name": "a"
+ },
+ "kind": "init"
+ },
+ {
+ "type": "SpreadElement",
+ "start": 14,
+ "end": 18,
+ "argument": {
+ "type": "Identifier",
+ "start": 17,
+ "end": 18,
+ "name": "b"
+ }
+ },
+ {
+ "type": "Property",
+ "start": 20,
+ "end": 21,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 20,
+ "end": 21,
+ "name": "c"
+ },
+ "value": {
+ "type": "Identifier",
+ "start": 20,
+ "end": 21,
+ "name": "c"
+ },
+ "kind": "init"
+ }
+ ]
+ }
+ },
+ "var someObject = { someKey: { ...mapGetters([ 'some_val_1', 'some_val_2' ]) } }": {
+ "type": "VariableDeclaration",
+ "start": 0,
+ "end": 79,
+ "declarations": [
+ {
+ "type": "VariableDeclarator",
+ "start": 4,
+ "end": 79,
+ "id": {
+ "type": "Identifier",
+ "start": 4,
+ "end": 14,
+ "name": "someObject"
+ },
+ "init": {
+ "type": "ObjectExpression",
+ "start": 17,
+ "end": 79,
+ "properties": [
+ {
+ "type": "Property",
+ "start": 19,
+ "end": 77,
+ "method": false,
+ "shorthand": false,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 19,
+ "end": 26,
+ "name": "someKey"
+ },
+ "value": {
+ "type": "ObjectExpression",
+ "start": 28,
+ "end": 77,
+ "properties": [
+ {
+ "type": "SpreadElement",
+ "start": 30,
+ "end": 75,
+ "argument": {
+ "type": "CallExpression",
+ "start": 33,
+ "end": 75,
+ "callee": {
+ "type": "Identifier",
+ "start": 33,
+ "end": 43,
+ "name": "mapGetters"
+ },
+ "arguments": [
+ {
+ "type": "ArrayExpression",
+ "start": 44,
+ "end": 74,
+ "elements": [
+ {
+ "type": "Literal",
+ "start": 46,
+ "end": 58,
+ "value": "some_val_1",
+ "raw": "'some_val_1'"
+ },
+ {
+ "type": "Literal",
+ "start": 60,
+ "end": 72,
+ "value": "some_val_2",
+ "raw": "'some_val_2'"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "kind": "init"
+ }
+ ]
+ }
+ }
+ ],
+ "kind": "var"
+ }
+ },
+ 'ObjectRest': {
+ 'let {x, ...y} = v': {
+ "type": "VariableDeclaration",
+ "start": 0,
+ "end": 17,
+ "declarations": [
+ {
+ "type": "VariableDeclarator",
+ "start": 4,
+ "end": 17,
+ "id": {
+ "type": "ObjectPattern",
+ "start": 4,
+ "end": 13,
+ "properties": [
+ {
+ "type": "Property",
+ "start": 5,
+ "end": 6,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 5,
+ "end": 6,
+ "name": "x"
+ },
+ "kind": "init",
+ "value": {
+ "type": "Identifier",
+ "start": 5,
+ "end": 6,
+ "name": "x"
+ }
+ },
+ {
+ "type": "RestElement",
+ "start": 8,
+ "end": 12,
+ "argument": {
+ "type": "Identifier",
+ "start": 11,
+ "end": 12,
+ "name": "y"
+ }
+ }
+ ]
+ },
+ "init": {
+ "type": "Identifier",
+ "start": 16,
+ "end": 17,
+ "name": "v"
+ }
+ }
+ ],
+ "kind": "let"
+ },
+ '(function({x, ...y}) {})': {
+ "type": "ExpressionStatement",
+ "start": 0,
+ "end": 24,
+ "expression": {
+ "type": "FunctionExpression",
+ "start": 1,
+ "end": 23,
+ "id": null,
+ "generator": false,
+ "expression": false,
+ "params": [
+ {
+ "type": "ObjectPattern",
+ "start": 10,
+ "end": 19,
+ "properties": [
+ {
+ "type": "Property",
+ "start": 11,
+ "end": 12,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 11,
+ "end": 12,
+ "name": "x"
+ },
+ "kind": "init",
+ "value": {
+ "type": "Identifier",
+ "start": 11,
+ "end": 12,
+ "name": "x"
+ }
+ },
+ {
+ "type": "RestElement",
+ "start": 14,
+ "end": 18,
+ "argument": {
+ "type": "Identifier",
+ "start": 17,
+ "end": 18,
+ "name": "y"
+ }
+ }
+ ]
+ }
+ ],
+ "body": {
+ "type": "BlockStatement",
+ "start": 21,
+ "end": 23,
+ "body": []
+ }
+ }
+ },
+ 'let {...{x, y}} = {}': {
+ "type": "VariableDeclaration",
+ "start": 0,
+ "end": 20,
+ "declarations": [
+ {
+ "type": "VariableDeclarator",
+ "start": 4,
+ "end": 20,
+ "id": {
+ "type": "ObjectPattern",
+ "start": 4,
+ "end": 15,
+ "properties": [
+ {
+ "type": "RestElement",
+ "start": 5,
+ "end": 14,
+ "argument": {
+ "type": "ObjectPattern",
+ "start": 8,
+ "end": 14,
+ "properties": [
+ {
+ "type": "Property",
+ "start": 9,
+ "end": 10,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 9,
+ "end": 10,
+ "name": "x"
+ },
+ "kind": "init",
+ "value": {
+ "type": "Identifier",
+ "start": 9,
+ "end": 10,
+ "name": "x"
+ }
+ },
+ {
+ "type": "Property",
+ "start": 12,
+ "end": 13,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 12,
+ "end": 13,
+ "name": "y"
+ },
+ "kind": "init",
+ "value": {
+ "type": "Identifier",
+ "start": 12,
+ "end": 13,
+ "name": "y"
+ }
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "init": {
+ "type": "ObjectExpression",
+ "start": 18,
+ "end": 20,
+ "properties": []
+ }
+ }
+ ],
+ "kind": "let"
+ },
+ 'let {...{...{x, y}}} = {}': {
+ "type": "VariableDeclaration",
+ "start": 0,
+ "end": 25,
+ "declarations": [
+ {
+ "type": "VariableDeclarator",
+ "start": 4,
+ "end": 25,
+ "id": {
+ "type": "ObjectPattern",
+ "start": 4,
+ "end": 20,
+ "properties": [
+ {
+ "type": "RestElement",
+ "start": 5,
+ "end": 19,
+ "argument": {
+ "type": "ObjectPattern",
+ "start": 8,
+ "end": 19,
+ "properties": [
+ {
+ "type": "RestElement",
+ "start": 9,
+ "end": 18,
+ "argument": {
+ "type": "ObjectPattern",
+ "start": 12,
+ "end": 18,
+ "properties": [
+ {
+ "type": "Property",
+ "start": 13,
+ "end": 14,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 13,
+ "end": 14,
+ "name": "x"
+ },
+ "kind": "init",
+ "value": {
+ "type": "Identifier",
+ "start": 13,
+ "end": 14,
+ "name": "x"
+ }
+ },
+ {
+ "type": "Property",
+ "start": 16,
+ "end": 17,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 16,
+ "end": 17,
+ "name": "y"
+ },
+ "kind": "init",
+ "value": {
+ "type": "Identifier",
+ "start": 16,
+ "end": 17,
+ "name": "y"
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "init": {
+ "type": "ObjectExpression",
+ "start": 23,
+ "end": 25,
+ "properties": []
+ }
+ }
+ ],
+ "kind": "let"
+ },
+ 'const fn = ({text = "default", ...props}) => text + props.children': {
+ "type": "VariableDeclaration",
+ "start": 0,
+ "end": 66,
+ "declarations": [
+ {
+ "type": "VariableDeclarator",
+ "start": 6,
+ "end": 66,
+ "id": {
+ "type": "Identifier",
+ "start": 6,
+ "end": 8,
+ "name": "fn"
+ },
+ "init": {
+ "type": "ArrowFunctionExpression",
+ "start": 11,
+ "end": 66,
+ "id": null,
+ "generator": false,
+ "expression": true,
+ "params": [
+ {
+ "type": "ObjectPattern",
+ "start": 12,
+ "end": 40,
+ "properties": [
+ {
+ "type": "Property",
+ "start": 13,
+ "end": 29,
+ "method": false,
+ "shorthand": true,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 13,
+ "end": 17,
+ "name": "text"
+ },
+ "kind": "init",
+ "value": {
+ "type": "AssignmentPattern",
+ "start": 13,
+ "end": 29,
+ "left": {
+ "type": "Identifier",
+ "start": 13,
+ "end": 17,
+ "name": "text"
+ },
+ "right": {
+ "type": "Literal",
+ "start": 20,
+ "end": 29,
+ "value": "default",
+ "raw": "\"default\""
+ }
+ }
+ },
+ {
+ "type": "RestElement",
+ "start": 31,
+ "end": 39,
+ "argument": {
+ "type": "Identifier",
+ "start": 34,
+ "end": 39,
+ "name": "props"
+ }
+ }
+ ]
+ }
+ ],
+ "body": {
+ "type": "BinaryExpression",
+ "start": 45,
+ "end": 66,
+ "left": {
+ "type": "Identifier",
+ "start": 45,
+ "end": 49,
+ "name": "text"
+ },
+ "operator": "+",
+ "right": {
+ "type": "MemberExpression",
+ "start": 52,
+ "end": 66,
+ "object": {
+ "type": "Identifier",
+ "start": 52,
+ "end": 57,
+ "name": "props"
+ },
+ "property": {
+ "type": "Identifier",
+ "start": 58,
+ "end": 66,
+ "name": "children"
+ },
+ "computed": false
+ }
+ }
+ }
+ }
+ ],
+ "kind": "const"
+ }
+ }
+};
+
+if (typeof exports !== "undefined") {
+ var test = require("./driver.js").test;
+ var testFail = require("./driver.js").testFail;
+ var tokTypes = require("../").tokTypes;
+}
+
+testFail("({get x() {}}) => {}", "Object pattern can't contain getter or setter (1:6)")
+testFail("let {...x, ...y} = {}", "Comma is not permitted after the rest element (1:9)")
+testFail("({...x,}) => z", "Comma is not permitted after the rest element (1:6)")
+testFail("({...{...x,}}) => z", "Comma is not permitted after the rest element (1:10)")
+testFail("export const { foo, ...bar } = baz;\nexport const bar = 1;\n", "Identifier 'bar' has already been declared (2:13)", {
+ sourceType: "module"
+})
+
+for (var ns in fbTestFixture) {
+ ns = fbTestFixture[ns];
+ for (var code in ns) {
+ test(code, {
+ type: 'Program',
+ body: [ns[code]],
+ start: 0,
+ end: code.length,
+ sourceType: "script"
+ }, {
+ ecmaVersion: 7
+ });
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-object-spread.git
More information about the Pkg-javascript-commits
mailing list