Skip to content
This repository was archived by the owner on Jun 12, 2020. It is now read-only.

compatibility with acorn@4 #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions inject.js
Original file line number Diff line number Diff line change
@@ -6,25 +6,26 @@ 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)) {
if (!first) {
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"))
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
8 changes: 4 additions & 4 deletions test/tests-object-spread.js
Original file line number Diff line number Diff line change
@@ -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": {