-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring JS breaks variable scope #357
Comments
If you change Const to Var does it still happen? What about Let? |
Changing the variable to Running the same test without all this code inside an event handler works correctly, eg: const body = document.querySelector("body");
if (!body) {
return;
}
var foo = 'bar'
doIt();
function doIt() {
console.log(foo);
} Generates function doIt(){console.log(foo)}const body=document.querySelector("body");if(!body)return;var foo="bar";doIt() The guard-clause hasn't been inverted: Also it no longer renames variables/functions. |
The non-renaming is expected as they are in global scope (and be theoretically be used elsewhere) Otherwise it does seem like a bug then |
@trullock , any update on this? This is causing some odd issues that our team needs to constantly work around |
Sorry, I don't get any time on this. PRs welcome and I'll merge them |
Tested using 1.20.6
Describe the bug
NUglify refactors JS code, and moves variables inside block scope, breaking functions that reference that variable.
To Reproduce
This example uses C#11 raw string literals
Minified output or stack trace
The minified code:
You can clearly see (once formatted), that the variable
t
is no longer accessible by the functioni
:Excepted output code
Variable declaration should not be moved inside the
if
block.The text was updated successfully, but these errors were encountered: