acorn5-object-spread
Advanced tools
Comparing version 4.0.0 to 5.0.0
'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"); | ||
let acornVersion = acorn.version.match(/^5\.(\d+)\./) | ||
if (!acornVersion || Number(acornVersion[1]) < 2) { | ||
throw new Error("Unsupported acorn version " + acorn.version + ", please use acorn 5 >= 5.2"); | ||
} | ||
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) { | ||
if (isPattern) { | ||
this.next() | ||
prop.argument = this.parseIdent() | ||
this.finishNode(prop, "RestElement") | ||
} else { | ||
prop = 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) { | ||
@@ -79,3 +23,29 @@ if (expr.type == "ObjectPattern") { | ||
acorn.plugins.objectSpread = function objectSpreadPlugin(instance) { | ||
pp.parseObj = parseObj; | ||
instance.extend("parseProperty", nextMethod => function (isPattern, refDestructuringErrors) { | ||
if (this.options.ecmaVersion >= 6 && this.type === tt.ellipsis) { | ||
let prop | ||
if (isPattern) { | ||
prop = this.startNode() | ||
this.next() | ||
prop.argument = this.parseIdent() | ||
this.finishNode(prop, "RestElement") | ||
} else { | ||
prop = this.parseSpread(refDestructuringErrors) | ||
} | ||
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 | ||
} | ||
} | ||
return prop | ||
} | ||
return nextMethod.apply(this, arguments) | ||
}) | ||
instance.extend("checkPropClash", nextMethod => function(prop, propHash) { | ||
if (prop.type == "SpreadElement" || prop.type == "RestElement") return | ||
return nextMethod.apply(this, arguments) | ||
}) | ||
instance.extend("checkLVal", getCheckLVal) | ||
@@ -82,0 +52,0 @@ instance.extend("toAssignable", nextMethod => function(node, isBinding) { |
@@ -18,5 +18,5 @@ { | ||
"dependencies": { | ||
"acorn": "^5.1.2" | ||
"acorn": "^5.2.1" | ||
}, | ||
"version": "4.0.0" | ||
"version": "5.0.0" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7537
81
Updatedacorn@^5.2.1