You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unreachable code in jquery_event_deprecation #17550
In Firefox with Ember v3.7.0 I'm seeing the following warning on the console in production:
unreachable code after return statement (jquery_event_deprecation.js:10)
It looks like the minifier is not doing its thing here. We should try to find a way to restructure that code so that terser is dropping the dead code correctly.
The first iteration of this did not work as expected, so I played around a bit, to see what's happening, and found something weird.
Given the following code excerpt:
console.log(DEBUG);
if (JQUERY_INTEGRATION && DEBUG && HAS_NATIVE_PROXY) {
let boundFunctions = new Map();
ember.prod.js looks like this:
console.log(false
/* DEBUG */
);
if (_deprecatedFeatures.JQUERY_INTEGRATION && false
/* DEBUG */
&& _utils.HAS_NATIVE_PROXY) {
let boundFunctions = new Map();
which is fine, so DEBUG has been replaced with false, and thus the if expression will always evaluate to false as well. So you would expect terser to completely remove that if block. But this is what ember.min.js will look like instead:
Not only did it not remove the if block, it removed false (from DEBUG) from the expression. Which is semantically totally wrong! Would have been ok if it was true. 😱
Note that it does work when DEBUG is the first item in the if expression, as is the case in the PR!
Anyone can explain this, other than this being a bug in terser?
Hm, probably terser is not able to reduce the expression to a simple true or false, because a getter for i.JQUERY_INTEGRATIONcould have a side effect, so the safe bet would be to keep it. And if the whole expression cannot be reduced to a simple static boolean, it is maybe not smart enough to remove the whole if block, even if effectively the expression will always evaluate to the same value!?
Just speculating, but it would explain why changing the order makes a difference: when DEBUG/false is the first operand, it is safe to skip evaluating the other properties, as that's what would happen at runtime as well.
I agree that the import could have side effects but in any case it knows that the body of the if could never be executed and it should therefore be stripped....
Activity
simonihmig commentedon Feb 3, 2019
I'll try to fix this!
[BUGFIX beta] remove jQuery deprecation code from production builds
[BUGFIX beta] remove jQuery deprecation code from production builds
simonihmig commentedon Feb 3, 2019
Here's a PR that fixes this: #17555
The first iteration of this did not work as expected, so I played around a bit, to see what's happening, and found something weird.
Given the following code excerpt:
ember.prod.jslooks like this:which is fine, so
DEBUGhas been replaced withfalse, and thus theifexpression will always evaluate tofalseas well. So you would expectterserto completely remove that if block. But this is whatember.min.jswill look like instead:Not only did it not remove the
ifblock, it removedfalse(fromDEBUG) from the expression. Which is semantically totally wrong! Would have been ok if it wastrue. 😱Note that it does work when
DEBUGis the first item in the if expression, as is the case in the PR!Anyone can explain this, other than this being a bug in
terser?rwjblue commentedon Feb 3, 2019
We should probably report over there I think...
Turbo87 commentedon Feb 3, 2019
you missed the
,0part.(i.JQUERY_INTEGRATION,0)will evaluate the property and then return0because it's a comma expression.simonihmig commentedon Feb 3, 2019
Ah, indeed! So it's semantically not wrong, but could have still figured out this to be always false, and thus removed the if block...
rwjblue commentedon Feb 3, 2019
Right. It’s still a bug IMHO.
simonihmig commentedon Feb 3, 2019
Hm, probably
terseris not able to reduce the expression to a simpletrueorfalse, because a getter fori.JQUERY_INTEGRATIONcould have a side effect, so the safe bet would be to keep it. And if the whole expression cannot be reduced to a simple static boolean, it is maybe not smart enough to remove the whole if block, even if effectively the expression will always evaluate to the same value!?Just speculating, but it would explain why changing the order makes a difference: when
DEBUG/falseis the first operand, it is safe to skip evaluating the other properties, as that's what would happen at runtime as well.Turbo87 commentedon Feb 3, 2019
@simonihmig yep, that is what I would expect to be the reason too.
it could remove the
&&n.HAS_NATIVE_PROXYpart as the first part is already falsy, but apparently it's not quite clever enough for that 😉rwjblue commentedon Feb 3, 2019
I agree that the import could have side effects but in any case it knows that the body of the if could never be executed and it should therefore be stripped....