in packages/path/src/parser.ts [150:193]
parseIdentifier() {
const node: IdentifierNode = {
type: 'Identifier',
value: this.state.value,
}
const hasNotInDestructor =
!this.includesContext(destructorContext) &&
!this.isMatchPattern &&
!this.isWildMatchPattern
this.next()
if (this.includesContext(bracketArrayContext)) {
if (this.state.type !== bracketRTok) {
throw this.unexpect()
} else {
this.state.context.pop()
this.next()
}
} else if (hasNotInDestructor) {
this.pushSegments(node.value)
}
if (this.state.type === bracketLTok) {
this.next()
if (this.state.type !== nameTok) {
throw this.unexpect()
}
this.state.context.push(bracketArrayContext)
let isNumberKey = false
if (/^\d+$/.test(this.state.value)) {
isNumberKey = true
}
const value = this.state.value
this.pushSegments(isNumberKey ? Number(value) : value)
const after = this.parseAtom(this.state.type) as IdentifierNode
if (isNumberKey) {
after.arrayIndex = true
}
this.append(node, after)
} else {
this.append(node, this.parseAtom(this.state.type))
}
return node
}