don't inline classes and functions when they're in different scopes in the utility.deadCodeElimination transformer

This commit is contained in:
Sebastian McKenzie
2015-05-25 03:33:12 +01:00
parent 8e2b743f7e
commit 73ada57a17
4 changed files with 15 additions and 9 deletions

View File

@@ -33,6 +33,16 @@ export function ReferencedIdentifier(node, parent, scope) {
}
if (!replacement) return;
// ensure it's a "pure" type
if (!scope.isPure(replacement)) return;
if (t.isClass(replacement) || t.isFunction(replacement)) {
// don't change this if it's in a different scope, this can be bad
// for performance since it may be inside a loop or deeply nested in
// hot code
if (!binding.path.scope.parent.is(scope)) return;
}
if (this.findParent((node) => node === replacement)) {
return;
}