fix: handle nested scope identifiers
This commit is contained in:
parent
88e5e96a3e
commit
e09e887219
@ -50,7 +50,7 @@ export interface TransformOptions {
|
|||||||
export interface TransformContext extends Required<TransformOptions> {
|
export interface TransformContext extends Required<TransformOptions> {
|
||||||
imports: Set<string>
|
imports: Set<string>
|
||||||
statements: string[]
|
statements: string[]
|
||||||
identifiers: { [name: string]: true }
|
identifiers: { [name: string]: number | undefined }
|
||||||
parent: ParentNode
|
parent: ParentNode
|
||||||
ancestors: ParentNode[]
|
ancestors: ParentNode[]
|
||||||
childIndex: number
|
childIndex: number
|
||||||
@ -113,11 +113,15 @@ function createTransformContext(
|
|||||||
context.parent.children.splice(removalIndex, 1)
|
context.parent.children.splice(removalIndex, 1)
|
||||||
},
|
},
|
||||||
onNodeRemoved: () => {},
|
onNodeRemoved: () => {},
|
||||||
addIdentifier(exp) {
|
addIdentifier({ content }) {
|
||||||
context.identifiers[exp.content] = true
|
const { identifiers } = context
|
||||||
|
if (identifiers[content] === undefined) {
|
||||||
|
identifiers[content] = 0
|
||||||
|
}
|
||||||
|
;(identifiers[content] as number)++
|
||||||
},
|
},
|
||||||
removeIdentifier(exp) {
|
removeIdentifier({ content }) {
|
||||||
delete context.identifiers[exp.content]
|
;(context.identifiers[content] as number)--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return context
|
return context
|
||||||
|
Loading…
x
Reference in New Issue
Block a user