diff --git a/inject.js b/inject.js index 424305c..5880719 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)) { @@ -14,17 +14,18 @@ module.exports = function(acorn) { this.expect(tt.comma) if (this.afterTrailingComma(tt.braceR)) break } else first = false - - let prop = this.startNode(), isGenerator, startPos, startLoc + + var 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() - prop.type = isPattern ? "RestProperty" : "SpreadProperty" + prop.type = isPattern ? "RestElement" : "SpreadElement" 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" } 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": {