Commit be3b5b7c authored by Joe Haddad's avatar Joe Haddad Committed by JJ Kasper

Register Created Bindings (#9864)

parent 2f5b3e0d
...@@ -51,6 +51,7 @@ export default function({ ...@@ -51,6 +51,7 @@ export default function({
// if the React binding came from a require('react'), // if the React binding came from a require('react'),
// make sure that our usage comes after it. // make sure that our usage comes after it.
let newPath
if ( if (
existingBinding && existingBinding &&
t.isVariableDeclarator(existingBinding.path.node) && t.isVariableDeclarator(existingBinding.path.node) &&
...@@ -58,10 +59,16 @@ export default function({ ...@@ -58,10 +59,16 @@ export default function({
t.isIdentifier(existingBinding.path.node.init.callee) && t.isIdentifier(existingBinding.path.node.init.callee) &&
existingBinding.path.node.init.callee.name === 'require' existingBinding.path.node.init.callee.name === 'require'
) { ) {
existingBinding.path.parentPath.insertAfter(mapping) ;[newPath] = existingBinding.path.parentPath.insertAfter(
mapping
)
} else { } else {
// @ts-ignore // @ts-ignore
path.unshiftContainer('body', mapping) ;[newPath] = path.unshiftContainer('body', mapping)
}
for (const declar of newPath.get('declarations')) {
path.scope.registerBinding(newPath.node.kind, declar)
} }
} }
...@@ -83,7 +90,10 @@ export default function({ ...@@ -83,7 +90,10 @@ export default function({
) )
// @ts-ignore // @ts-ignore
path.unshiftContainer('body', importSpecifier) const [newPath] = path.unshiftContainer('body', importSpecifier)
for (const specifier of newPath.get('specifiers')) {
path.scope.registerBinding('module', specifier)
}
} }
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment