我想创建全局变量并确保它们不会与现有的全局变量名称冲突。
替换所有数组声明的示例:
let arrayDeclarations
const customPlugin = () => {
return {
visitor: {
Program(path) {
arrayDeclarations = []
path.node.body.unshift(t.variableDeclaration('const', arrayDeclarations))
},
ArrayExpression(path) {
const newUniqueName = // TODO
const arrayIdentifier = t.identifier(newUniqueName)
arrayDeclarations.push(t.variableDeclarator(arrayIdentifier, path.node))
path.replaceWith(arrayIdentifier)
}
}
}
}