This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinject.js
50 lines (44 loc) · 1.56 KB
/
inject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'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;
};