Skip to content

Commit a010fd7

Browse files
committed
put acorn-private-class-elements directly in lib/
1 parent b5dfa00 commit a010fd7

File tree

4 files changed

+144
-5
lines changed

4 files changed

+144
-5
lines changed

build.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ function compile (name, output, fix) {
1818
fs.writeFileSync(path.join(__dirname, output), HEADER + result.code, 'utf8')
1919
}
2020

21+
function privateClassElements (str) {
22+
return str.replace('acorn-private-class-elements', '../acorn-private-class-elements')
23+
}
24+
2125
compile('acorn-bigint', './lib/bigint/index.js')
2226
compile('acorn-import-meta', './lib/import-meta/index.js')
23-
compile('acorn-class-fields', './lib/class-fields/index.js')
24-
compile('acorn-static-class-features', './lib/static-class-features/index.js')
25-
compile('acorn-private-class-elements', './lib/node_modules/acorn-private-class-elements/index.js', function (str) {
27+
compile('acorn-class-fields', './lib/class-fields/index.js', privateClassElements)
28+
compile('acorn-static-class-features', './lib/static-class-features/index.js', privateClassElements)
29+
compile('acorn-private-class-elements', './lib/acorn-private-class-elements/index.js', function (str) {
2630
return str.replace('class extends Parser', 'class Parser_ extends Parser')
2731
})
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/* Generated by `npm run build`, do not edit! */
2+
3+
"use strict"
4+
5+
var acorn = require("acorn")
6+
if (acorn.version.indexOf("6.") != 0 || acorn.version.indexOf("6.0.") == 0) {
7+
throw new Error(("acorn-private-class-elements requires acorn@^6.1.0, not " + (acorn.version)))
8+
}
9+
var tt = acorn.tokTypes
10+
var TokenType = acorn.TokenType
11+
12+
module.exports = function(Parser) {
13+
// Only load this plugin once.
14+
if (Parser.prototype.parsePrivateName) {
15+
return Parser
16+
}
17+
18+
// Make sure `Parser` comes from the same acorn as our `tt`,
19+
// otherwise the comparisons fail.
20+
var cur = Parser
21+
while (cur && cur !== acorn.Parser) {
22+
cur = cur.__proto__
23+
}
24+
if (cur !== acorn.Parser) {
25+
throw new Error("acorn-private-class-elements does not support mixing different acorn copies")
26+
}
27+
28+
Parser = /*@__PURE__*/(function (Parser) {
29+
function Parser_ () {
30+
Parser.apply(this, arguments);
31+
}
32+
33+
if ( Parser ) Parser_.__proto__ = Parser;
34+
Parser_.prototype = Object.create( Parser && Parser.prototype );
35+
Parser_.prototype.constructor = Parser_;
36+
37+
Parser_.prototype._branch = function _branch () {
38+
this.__branch = this.__branch || new Parser({ecmaVersion: this.options.ecmaVersion}, this.input)
39+
this.__branch.end = this.end
40+
this.__branch.pos = this.pos
41+
this.__branch.type = this.type
42+
this.__branch.value = this.value
43+
this.__branch.containsEsc = this.containsEsc
44+
return this.__branch
45+
};
46+
47+
Parser_.prototype.parsePrivateClassElementName = function parsePrivateClassElementName (element) {
48+
element.computed = false
49+
element.key = this.parsePrivateName()
50+
if (element.key.name == "constructor") { this.raise(element.key.start, "Classes may not have a private element named constructor") }
51+
var accept = {get: "set", set: "get"}[element.kind]
52+
var privateBoundNames = this._privateBoundNamesStack[this._privateBoundNamesStack.length - 1]
53+
if (Object.prototype.hasOwnProperty.call(privateBoundNames, element.key.name) && privateBoundNames[element.key.name] !== accept) {
54+
this.raise(element.start, "Duplicate private element")
55+
}
56+
privateBoundNames[element.key.name] = element.kind || true
57+
delete this._unresolvedPrivateNamesStack[this._unresolvedPrivateNamesStack.length - 1][element.key.name]
58+
return element.key
59+
};
60+
61+
Parser_.prototype.parsePrivateName = function parsePrivateName () {
62+
var node = this.startNode()
63+
node.name = this.value
64+
this.next()
65+
this.finishNode(node, "PrivateName")
66+
if (this.options.allowReserved == "never") { this.checkUnreserved(node) }
67+
return node
68+
};
69+
70+
// Parse # token
71+
Parser_.prototype.getTokenFromCode = function getTokenFromCode (code) {
72+
if (code === 35) {
73+
++this.pos
74+
var word = this.readWord1()
75+
return this.finishToken(this.privateNameToken, word)
76+
}
77+
return Parser.prototype.getTokenFromCode.call(this, code)
78+
};
79+
80+
// Manage stacks and check for undeclared private names
81+
Parser_.prototype.parseClass = function parseClass (node, isStatement) {
82+
this._privateBoundNamesStack = this._privateBoundNamesStack || []
83+
var privateBoundNames = Object.create(this._privateBoundNamesStack[this._privateBoundNamesStack.length - 1] || null)
84+
this._privateBoundNamesStack.push(privateBoundNames)
85+
this._unresolvedPrivateNamesStack = this._unresolvedPrivateNamesStack || []
86+
var unresolvedPrivateNames = Object.create(null)
87+
this._unresolvedPrivateNamesStack.push(unresolvedPrivateNames)
88+
var _return = Parser.prototype.parseClass.call(this, node, isStatement)
89+
this._privateBoundNamesStack.pop()
90+
this._unresolvedPrivateNamesStack.pop()
91+
if (!this._unresolvedPrivateNamesStack.length) {
92+
var names = Object.keys(unresolvedPrivateNames)
93+
if (names.length) {
94+
names.sort(function (n1, n2) { return unresolvedPrivateNames[n1] - unresolvedPrivateNames[n2]; })
95+
this.raise(unresolvedPrivateNames[names[0]], "Usage of undeclared private name")
96+
}
97+
} else { Object.assign(this._unresolvedPrivateNamesStack[this._unresolvedPrivateNamesStack.length - 1], unresolvedPrivateNames) }
98+
return _return
99+
};
100+
101+
// Parse private element access
102+
Parser_.prototype.parseSubscript = function parseSubscript (base, startPos, startLoc, noCalls, maybeAsyncArrow) {
103+
if (!this.eat(tt.dot)) {
104+
return Parser.prototype.parseSubscript.call(this, base, startPos, startLoc, noCalls, maybeAsyncArrow)
105+
}
106+
var node = this.startNodeAt(startPos, startLoc)
107+
node.object = base
108+
node.computed = false
109+
if (this.type == this.privateNameToken) {
110+
node.property = this.parsePrivateName()
111+
if (!this._privateBoundNamesStack.length || !this._privateBoundNamesStack[this._privateBoundNamesStack.length - 1][node.property.name]) {
112+
this._unresolvedPrivateNamesStack[this._unresolvedPrivateNamesStack.length - 1][node.property.name] = node.property.start
113+
}
114+
} else {
115+
node.property = this.parseIdent(true)
116+
}
117+
return this.finishNode(node, "MemberExpression")
118+
};
119+
120+
// Prohibit delete of private class elements
121+
Parser_.prototype.parseMaybeUnary = function parseMaybeUnary (refDestructuringErrors, sawUnary) {
122+
var _return = Parser.prototype.parseMaybeUnary.call(this, refDestructuringErrors, sawUnary)
123+
if (_return.operator == "delete") {
124+
if (_return.argument.type == "MemberExpression" && _return.argument.property.type == "PrivateName") {
125+
this.raise(_return.start, "Private elements may not be deleted")
126+
}
127+
}
128+
return _return
129+
};
130+
131+
return Parser_;
132+
}(Parser))
133+
Parser.prototype.privateNameToken = new TokenType("privateName")
134+
return Parser
135+
}

lib/class-fields/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
var acorn = require("acorn")
66
var tt = acorn.tokTypes
7-
var privateClassElements = require("acorn-private-class-elements")
7+
var privateClassElements = require("../acorn-private-class-elements")
88

99
function maybeParseFieldValue(field) {
1010
if (this.eat(tt.eq)) {

lib/static-class-features/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function maybeParseFieldValue(field) {
1616
} else { field.value = null }
1717
}
1818

19-
var privateClassElements = require("acorn-private-class-elements")
19+
var privateClassElements = require("../acorn-private-class-elements")
2020

2121
module.exports = function(Parser) {
2222
var ExtendedParser = privateClassElements(Parser)

0 commit comments

Comments
 (0)