Lexical variables in the outermost lexical scope don’t get mangled
See original GitHub issueLexical variables in the outermost lexical scope don’t get mangled, i.e. they appear to be incorrectly treated as global variables.
To Reproduce
Minimal code to reproduce the bug:
// foo.mjs
const foo = 42;
const bar = 64;
$ minify foo.mjs
Actual Output
const foo=42,bar=64;
Expected Output
const a=42,b=64;
I’m using the babel-minify
CLI, v0.4.3, with no additional configuration.
As a workaround, I have to wrap my source code in a block: { … }
. That way, babel-plugin-minify-mangle-names seems to kick in correctly.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Is Mathematica's lexical scoping broken?
With is a scoping construct that implements read-only lexical variables. With replaces symbols in expr only when they do not occur as local ......
Read more >Lexical Scope in JavaScript – What Exactly Is Scope in JS?
Scope refers to the area where an item (such as a function or variable) is visible and accessible to other code. Note: Scope...
Read more >What is lexical scope? - javascript - Stack Overflow
Lexical scope means that in a nested group of functions, the inner functions have access to the variables and other resources of their...
Read more >You-Don-t-Know-JS-Scope-Closures.pdf - Pepa
To define it somewhat circularly, lexical scope is scope that is defined at lexing time. In other words, lexical scope is based on...
Read more >Don't use named lexical subroutines – The Effective Perler
Remember how lexical variables work. You can have package (global) variables and lexical variables with the same name and they do not affect ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To clarify what I mean:
--mangle.topLevel
for.mjs
files (as @boopathi suggested) solves the problem for modules. It would be great to do this!--mangle.topLevelLexical
would enable this functionality for non-modules too.@mathiasbynens, for what it’s worth, I would be very surprised if those names were changed without
--mangle.topLevel
. I expect the default behavior to be that compiled programs have the same observable semantics as the input, moduloFunction.prototype.toString
and function names (and also stack traces and other non-spec things). And the names in the top-level lexical scope are very much part of the observable semantics of a program, just like names in the global scope.