Skip to content

Commit 9d34909

Browse files
committed
add fallback binding rename
certain cases might exist that the plugin doesn't handle yet and could cause issues with regards to `undefined` variable errors, this would reduce the chances of that happening
1 parent 3c19ede commit 9d34909

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

source/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function transformToStateByScope(path: any, toMod: ToModifyVariableI[]) {
4444
}
4545
},
4646
VariableDeclaration({node}: {node: t.VariableDeclaration}) {
47-
transformReactiveDeclarations(node, toMod)
47+
transformReactiveDeclarations(node, toMod, path)
4848
},
4949
ExpressionStatement({node}: {node: t.ExpressionStatement}) {
5050
transformAssignmentExpression(node, toMod)
@@ -54,7 +54,8 @@ function transformToStateByScope(path: any, toMod: ToModifyVariableI[]) {
5454

5555
function transformReactiveDeclarations(
5656
node: t.VariableDeclaration,
57-
toMod: ToModifyVariableI[]
57+
toMod: ToModifyVariableI[],
58+
path: any
5859
) {
5960
for (let i = 0; i < node.declarations.length; i += 1) {
6061
const declaration = node.declarations[i]
@@ -82,6 +83,9 @@ function transformReactiveDeclarations(
8283
declaration.init ? [declaration.init] : []
8384
)
8485
)
86+
87+
// fallback to replace missed instances of the variable
88+
path.scope.rename(declaration.id.name, normName)
8589
}
8690
}
8791

0 commit comments

Comments
 (0)