fix renaming

This commit is contained in:
Ivan Kopeykin 2022-02-22 13:37:58 +03:00
parent 261a73e18e
commit 82a0f2add6
2 changed files with 11 additions and 7 deletions

View File

@ -69,13 +69,16 @@ class NodeStuffPlugin {
);
}
});
parser.hooks.canRename.for("global").tap(
{
name: "NodeStuffPlugin",
stage: -10
},
() => false
);
parser.hooks.rename.for("global").tap("NodeStuffPlugin", expr => {
const dep = new ConstDependency(
RuntimeGlobals.global,
expr.range,
[RuntimeGlobals.global]
);
dep.loc = expr.loc;
parser.state.module.addPresentationalDependency(dep);
return false;
});
}
const setModuleConstant = (expressionName, fn, warning) => {

View File

@ -4,5 +4,6 @@ it("should disallow rename global", () => {
var method = shouldBeGlobal[String.fromCharCode(40, 40, 40)];
method && method();
eval("expect(shouldBeGlobal.value1).toBe('value1')");
expect(shouldBeGlobal.test).toBe("test");
expect(global.test).toBe("test");
});