Bones/node_modules/acorn-object-spread/inject.js
SOUTHERNCO\x2mjbyrn 7efe7605b8 Template Upload
2017-05-17 13:45:25 -04:00

51 lines
1.6 KiB
JavaScript

'use strict';
module.exports = function(acorn) {
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, 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"
node.properties.push(prop)
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)
this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors)
this.checkPropClash(prop, propHash)
node.properties.push(this.finishNode(prop, "Property"))
}
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
}
acorn.plugins.objectSpread = function objectSpreadPlugin(instance) {
pp.parseObj = parseObj;
};
return acorn;
};