-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Certain function inlining not maintaining a function reference #481
Comments
Thank you very much for this detailed report! Not everyone finds the time to do some research on the bug before posting an issue :) |
@mileszim please provide the actual code when reporting bugs, it helps a lot! If you were reproducing an error, you wouldn't like to type every character in a screenshot :) |
@molily I can't reproduce this anymore, with the following code:
The code that's generated is correct:
If I run the code in the browser (injecting an initialState span with Can you try running with the latest Terser version? (4.3.9) I might've fixed this issue while fixing something else. |
Thanks a lot for your efforts! Minifying the example file that only renders 'hi' now works. However, minifying my full app build still produces the same error. Here are the full files: https://molily.de/assets/full-bundle-before-terser.js The reference to for (i in n) i in t || C(e, i, null, n[i], r);
for (i in t) o && "function" != typeof t[i] || "value" === i || "checked" === i || n[i] === t[i] || C(e, i, t[i], n[i], r); where the wrong function j(e, t, n, r, o, u, a, c, s, l) {
var d, v, y, m, g, w, O, P, T, E, C = t.type; The correct function that should be called is now called function E(e, t, n, r, o) {
var i, u, a, c, s; By the way, the source code is here if you like to test with it: https://github.com/molily/universal-progressive-todos/tree/preact-no-minification (branch Let me know if I can help! |
After a couple of hours deleting code, I managed to reduce your pre-terser file to this test case:
If the function order is different, this does not happen, which I find interesting. |
v4.6.2 should come out tomorrow with this fix. Sorry it took so long but it was harder than it seems to fix :) |
Thank you very much, it works like a charm! :) |
Super cool! |
Bug report or Feature request?
Bug
Version (complete output of
terser -V
or specific git commit)4.3.4
Complete CLI command or
minify()
options used--compress --mangle
terser
inputSee https://molily.de/assets/bundle-before-terser.js
terser
output or errorSee https://molily.de/assets/bundle-after-terser.js
This is the bundle of a project with Preact, compiled with Webpack. The production build is minified with Terser.
bundle-before-terser.js contains the pre-minified code of Preact in line 1042.
Excerpt (prettified):
TL;DR:
N
,preact_module_C
,z
, and$
.preact_module_C
is called only once, that is inz
. So Terser inlinespreact_module_C
intoz
.z
is called only once, that is in$
. So Terser inlinesz
into$
.preact_module_C
callsN
. So Terser needs to maintain that reference.$
has a local variable namedN
which shadows theN
function in the outer scope.After the minification by Terser, the inlined
preact_module_C
code looks like this:The call to
N
is now a call toC
.Meanwhile,
N
has been renamed toE
:So the reference is broken.
It is worth noting that, in fact, there is a
C
in the scope. But it’s a variable in the functionj
, formerly known as$
, the new parent after the inlining.C
was formerly known asN
. Maybe that is what confuses Terser: “Oh, there is an N already in the new scope chain, so I’ll update the reference to its new name”.C
is a string here, not a function. So the code produces aTypeError
during runtime.I think this confusion is a result of several function inlining operations.
I really tried to boil this down to a minimal test case for you, but if I take anything away, Terser correctly maintains the reference to the function originally called
N
.Also, if I make a minimal setup with four functions like above, everything works fine:
Output:
o
could be inlined again (and it is with another Terser run), but the code it correct.Thanks for bearing with me. Let me know if you have questions or tips how I can make this any more helpful for you.
The text was updated successfully, but these errors were encountered: