💻
How are you using Babel?
Repl
Input code
https://babeljs.io/repl#?config_lz=N4IgZglgNgpgdgQwLYxALhAJxgBygOgCsBnADxABoQdtiYAXY9AbWZHgDdLR6FMBzBkwwA-AAz4xARgCkFAARwA9vXkQY8qVIXLV6gPpIlAI01TKIIwBMArrGEgAxkqRG4JC8Zv9IpGMPpMGxgAXwBdCjZsBEd6biwbOHoIFHQQBBt6FwRkxxBwyJBiXkEAWgAmeKsYZ0wcpUxiADUYRoglODTysXKAZlKtCxwIHBgoCDgYAAVMJRwlYgQoNIALGIBrfLCIoqUbTEcYABUAT1G06ztUEKA&code_lz=JYWwDg9gTgLgBAbwK4GcCmAZAhgTwkmAUQDNi0BjeLFOAOwF85ioIQ4AiKNLS9gbgBQA4klqVgEWnADSwABTAANHQCUiAXDhcYSKFPnUcYuHLUBeAHzrNmkWJgSptU4noa49ZbRV84Aej84ABUAC2AafRoYELQ4SVjmVjho2NkmUXFJLwh4RLYUuFBIWDgUGCwYNBA0WhgBeiA&lineWrap=true&version=7.28.4
Current and expected behavior
In the linked REPL, the n on line 6 should resolve to the n from the Ki function signature on line 3. However at the very bottom of the transpiled output, the n is turned into _react.useLayoutEffect which is incorrect. The function-scoped n should shadow the module-scoped n
Environment
See repl link
Targets >0.01%, not ie 11, not ie_mob 11
Modules commonjs
The rest left as default (v7.28.4)
Possible solution
The function n() {} on line 5 is necessary for this bug to happen. So it seems like that line is somehow confusing babel about the scope of the final n
This also only happens when modules is set to commonjs and targets is >0.01%
Additional context
We experienced this in the wild when testing our pre-minified library in codesandbox and narrowed it down to the code you see in the linked repl
💻
How are you using Babel?
Repl
Input code
https://babeljs.io/repl#?config_lz=N4IgZglgNgpgdgQwLYxALhAJxgBygOgCsBnADxABoQdtiYAXY9AbWZHgDdLR6FMBzBkwwA-AAz4xARgCkFAARwA9vXkQY8qVIXLV6gPpIlAI01TKIIwBMArrGEgAxkqRG4JC8Zv9IpGMPpMGxgAXwBdCjZsBEd6biwbOHoIFHQQBBt6FwRkxxBwyJBiXkEAWgAmeKsYZ0wcpUxiADUYRoglODTysXKAZlKtCxwIHBgoCDgYAAVMJRwlYgQoNIALGIBrfLCIoqUbTEcYABUAT1G06ztUEKA&code_lz=JYWwDg9gTgLgBAbwK4GcCmAZAhgTwkmAUQDNi0BjeLFOAOwF85ioIQ4AiKNLS9gbgBQA4klqVgEWnADSwABTAANHQCUiAXDhcYSKFPnUcYuHLUBeAHzrNmkWJgSptU4noa49ZbRV84Aej84ABUAC2AafRoYELQ4SVjmVjho2NkmUXFJLwh4RLYUuFBIWDgUGCwYNBA0WhgBeiA&lineWrap=true&version=7.28.4
Current and expected behavior
In the linked REPL, the
non line 6 should resolve to thenfrom theKifunction signature on line 3. However at the very bottom of the transpiled output, thenis turned into_react.useLayoutEffectwhich is incorrect. The function-scopednshould shadow the module-scopednEnvironment
See repl link
Targets
>0.01%, not ie 11, not ie_mob 11Modules
commonjsThe rest left as default (v7.28.4)
Possible solution
The
function n() {}on line 5 is necessary for this bug to happen. So it seems like that line is somehow confusing babel about the scope of the finalnThis also only happens when
modulesis set tocommonjsandtargetsis>0.01%Additional context
We experienced this in the wild when testing our pre-minified library in codesandbox and narrowed it down to the code you see in the linked repl