don't inline classes and functions when they're in different scopes in the utility.deadCodeElimination transformer
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class A {
|
||||
constructor() { this.value = 12345; }
|
||||
}
|
||||
|
||||
export default new A();
|
||||
|
||||
@@ -3,12 +3,9 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var A = function A() {
|
||||
exports["default"] = new function A() {
|
||||
babelHelpers.classCallCheck(this, A);
|
||||
this.value = 12345;
|
||||
};
|
||||
|
||||
exports["default"] = new A();
|
||||
}();
|
||||
module.exports = exports["default"];
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var A = (function () {
|
||||
var a = new ((function () {
|
||||
function A() {
|
||||
babelHelpers.classCallCheck(this, A);
|
||||
}
|
||||
@@ -12,6 +12,4 @@ var A = (function () {
|
||||
}
|
||||
}]);
|
||||
return A;
|
||||
})();
|
||||
|
||||
var a = new A();
|
||||
})())();
|
||||
|
||||
Reference in New Issue
Block a user