fix: Don't hoist JSX elements referencing mutable variables (#13054)
issue-13051 Co-authored-by: Clint Goodman <clintgoodman@workfront.com>
This commit is contained in:
@@ -64,13 +64,17 @@ export default declare((api, options) => {
|
||||
// Ignore identifiers & JSX expressions.
|
||||
if (
|
||||
path.isJSXIdentifier() ||
|
||||
path.isIdentifier() ||
|
||||
path.isJSXMemberExpression() ||
|
||||
path.isJSXNamespacedName()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (path.isIdentifier()) {
|
||||
const binding = path.scope.getBinding(path.node.name);
|
||||
if (binding && binding.constant) return;
|
||||
}
|
||||
|
||||
if (!path.isImmutable()) {
|
||||
// If it's not immutable, it may still be a pure expression, such as string concatenation.
|
||||
// It is still safe to hoist that, so long as its result is immutable.
|
||||
|
||||
Reference in New Issue
Block a user