-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
25 lines (22 loc) · 998 Bytes
/
index.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
// eslint-disable-next-line node/no-unsupported-features/es-syntax
import privateClassElements from "acorn-private-class-elements"
// eslint-disable-next-line node/no-unsupported-features/es-syntax
export default function privateMethods(Parser) {
const ExtendedParser = privateClassElements(Parser)
return class extends ExtendedParser {
// Parse private methods
parseClassElement(_constructorAllowsSuper) {
const oldInClassMemberName = this._inClassMemberName
this._inClassMemberName = true
const result = super.parseClassElement.apply(this, arguments)
this._inClassMemberName = oldInClassMemberName
return result
}
parsePropertyName(prop) {
const isPrivate = this.options.ecmaVersion >= 8 && this._inClassMemberName && this.type == this.privateIdentifierToken && !prop.static
this._inClassMemberName = false
if (!isPrivate) return super.parsePropertyName(prop)
return this.parsePrivateClassElementName(prop)
}
}
}