Register Created Bindings (#9864)

This commit is contained in:
Joe Haddad 2019-12-28 17:01:01 -05:00 committed by JJ Kasper
parent 2f5b3e0d42
commit be3b5b7c5f

View file

@ -51,6 +51,7 @@ export default function({
// if the React binding came from a require('react'),
// make sure that our usage comes after it.
let newPath
if (
existingBinding &&
t.isVariableDeclarator(existingBinding.path.node) &&
@ -58,10 +59,16 @@ export default function({
t.isIdentifier(existingBinding.path.node.init.callee) &&
existingBinding.path.node.init.callee.name === 'require'
) {
existingBinding.path.parentPath.insertAfter(mapping)
;[newPath] = existingBinding.path.parentPath.insertAfter(
mapping
)
} else {
// @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({
)
// @ts-ignore
path.unshiftContainer('body', importSpecifier)
const [newPath] = path.unshiftContainer('body', importSpecifier)
for (const specifier of newPath.get('specifiers')) {
path.scope.registerBinding('module', specifier)
}
}
}
},