From 3779b44164c7d11daf1f0da3a9e833f7c5bcf39f Mon Sep 17 00:00:00 2001 From: Robert Krahn Date: Fri, 21 Oct 2016 20:23:42 -0700 Subject: [PATCH 1/4] compatibility with acorn@4 --- inject.js | 17 +++++++++++++---- package.json | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/inject.js b/inject.js index 424305c..61a9fff 100644 --- a/inject.js +++ b/inject.js @@ -14,9 +14,10 @@ module.exports = function(acorn) { this.expect(tt.comma) if (this.afterTrailingComma(tt.braceR)) break } else first = false - - let prop = this.startNode(), isGenerator, startPos, startLoc + + 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 = this.parseSpread() @@ -24,7 +25,7 @@ module.exports = function(acorn) { node.properties.push(prop) continue } - + prop.method = false prop.shorthand = false if (isPattern || refDestructuringErrors) { @@ -35,7 +36,15 @@ module.exports = function(acorn) { isGenerator = this.eat(tt.star) } this.parsePropertyName(prop) - this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors) + if (!isPattern && this.options.ecmaVersion >= 8 && !isGenerator && !prop.computed && + prop.key.type === "Identifier" && prop.key.name === "async" && this.type !== tt.parenL && + this.type !== tt.colon && !this.canInsertSemicolon()) { + isAsync = true + this.parsePropertyName(prop, refDestructuringErrors) + } else { + isAsync = false + } + this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) this.checkPropClash(prop, propHash) node.properties.push(this.finishNode(prop, "Property")) } diff --git a/package.json b/package.json index a3bac7e..4ac2fdd 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,11 @@ "test": "node test/run.js" }, "dependencies": { - "acorn": "^3.1.0" + "acorn": "^4.0.3" }, "devDependencies": { "chai": "^3.0.0", "mocha": "^2.2.5" }, - "version": "1.0.0" + "version": "2.0.0" } From e38d8f4c88bf084c72deec130d08889c558dfa8f Mon Sep 17 00:00:00 2001 From: Robert Krahn Date: Fri, 21 Oct 2016 20:28:25 -0700 Subject: [PATCH 2/4] fix for node 0.10 --- inject.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inject.js b/inject.js index 61a9fff..df73846 100644 --- a/inject.js +++ b/inject.js @@ -6,7 +6,7 @@ module.exports = function(acorn) { // this is the same parseObj that acorn has with... function parseObj(isPattern, refDestructuringErrors) { - let node = this.startNode(), first = true, propHash = {} + var node = this.startNode(), first = true, propHash = {} node.properties = [] this.next() while (!this.eat(tt.braceR)) { @@ -15,7 +15,7 @@ module.exports = function(acorn) { if (this.afterTrailingComma(tt.braceR)) break } else first = false - let prop = this.startNode(), isGenerator, isAsync, startPos, startLoc + var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc if (this.options.ecmaVersion >= 6) { // ...the spread logic borrowed from babylon :) From 0da45682c3b3d5409730c5f49b2d6b390603f4ed Mon Sep 17 00:00:00 2001 From: Robert Krahn Date: Tue, 14 Feb 2017 21:21:18 -0800 Subject: [PATCH 3/4] SpreadProperty => SpreadElement --- inject.js | 2 +- test/tests-object-spread.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/inject.js b/inject.js index df73846..5880719 100644 --- a/inject.js +++ b/inject.js @@ -21,7 +21,7 @@ module.exports = function(acorn) { // ...the spread logic borrowed from babylon :) if (this.type === tt.ellipsis) { prop = this.parseSpread() - prop.type = isPattern ? "RestProperty" : "SpreadProperty" + prop.type = isPattern ? "RestElement" : "SpreadElement" node.properties.push(prop) continue } diff --git a/test/tests-object-spread.js b/test/tests-object-spread.js index 541cf13..b6864d1 100644 --- a/test/tests-object-spread.js +++ b/test/tests-object-spread.js @@ -64,7 +64,7 @@ var fbTestFixture = { }, "properties": [ { - "type": "SpreadProperty", + "type": "SpreadElement", "start": 9, "end": 13, "loc": { @@ -211,7 +211,7 @@ var fbTestFixture = { } }, { - "type": "SpreadProperty", + "type": "SpreadElement", "start": 8, "end": 12, "loc": { @@ -325,7 +325,7 @@ var fbTestFixture = { } }, { - "type": "SpreadProperty", + "type": "SpreadElement", "start": 5, "end": 9, "loc": { @@ -406,7 +406,7 @@ var fbTestFixture = { } }, { - "type": "SpreadProperty", + "type": "SpreadElement", "start": 14, "end": 18, "loc": { From f39f3108e9bacff63c90f7145b74413b73f77167 Mon Sep 17 00:00:00 2001 From: John Boehr Date: Fri, 21 Apr 2017 15:38:27 -0700 Subject: [PATCH 4/4] Revert "SpreadProperty => SpreadElement" This reverts commit 0da45682c3b3d5409730c5f49b2d6b390603f4ed. --- inject.js | 2 +- test/tests-object-spread.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/inject.js b/inject.js index 5880719..df73846 100644 --- a/inject.js +++ b/inject.js @@ -21,7 +21,7 @@ module.exports = function(acorn) { // ...the spread logic borrowed from babylon :) if (this.type === tt.ellipsis) { prop = this.parseSpread() - prop.type = isPattern ? "RestElement" : "SpreadElement" + prop.type = isPattern ? "RestProperty" : "SpreadProperty" node.properties.push(prop) continue } diff --git a/test/tests-object-spread.js b/test/tests-object-spread.js index b6864d1..541cf13 100644 --- a/test/tests-object-spread.js +++ b/test/tests-object-spread.js @@ -64,7 +64,7 @@ var fbTestFixture = { }, "properties": [ { - "type": "SpreadElement", + "type": "SpreadProperty", "start": 9, "end": 13, "loc": { @@ -211,7 +211,7 @@ var fbTestFixture = { } }, { - "type": "SpreadElement", + "type": "SpreadProperty", "start": 8, "end": 12, "loc": { @@ -325,7 +325,7 @@ var fbTestFixture = { } }, { - "type": "SpreadElement", + "type": "SpreadProperty", "start": 5, "end": 9, "loc": { @@ -406,7 +406,7 @@ var fbTestFixture = { } }, { - "type": "SpreadElement", + "type": "SpreadProperty", "start": 14, "end": 18, "loc": {