Skip to content

Commit

Permalink
Extract parseProperty from parseObj
Browse files Browse the repository at this point in the history
This should make implementing something like acorn-object-spread much easier
and the result more robust.
  • Loading branch information
adrianheine authored and marijnh committed Oct 29, 2017
1 parent 62444e4 commit 4747645
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/expression.js
Expand Up @@ -556,31 +556,36 @@ pp.parseObj = function(isPattern, refDestructuringErrors) {
if (this.afterTrailingComma(tt.braceR)) break
} else first = false

let prop = this.startNode(), isGenerator, isAsync, startPos, startLoc
if (this.options.ecmaVersion >= 6) {
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)
const prop = this.parseProperty(isPattern, refDestructuringErrors)
this.checkPropClash(prop, propHash)
node.properties.push(this.finishNode(prop, "Property"))
node.properties.push(prop)
}
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
}

pp.parseProperty = function(isPattern, refDestructuringErrors) {
let prop = this.startNode(), isGenerator, isAsync, startPos, startLoc
if (this.options.ecmaVersion >= 6) {
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)
return this.finishNode(prop, "Property")
}

pp.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
if ((isGenerator || isAsync) && this.type === tt.colon)
this.unexpected()
Expand Down

0 comments on commit 4747645

Please sign in to comment.