-
Notifications
You must be signed in to change notification settings - Fork 156
build-optimizer: "logical OR" property assignment is removed #388
Comments
When running an Angular application in production mode with the build optimizer and the Angular CLI, the code part, that sets the default color for round buttons, is removed accidentally. This seems to be an issue, that's caused by the build optimizer: angular/devkit#388. Fixes angular#9360
When running an Angular application in production mode with the build optimizer and the Angular CLI, the code part, that sets the default color for round buttons, is removed accidentally. This seems to be an issue, that's caused by the build optimizer: angular/devkit#388. Fixes angular#9360
I'm looking into this problem and I think the current behaviour, although not very intuitive, is correct. This is a situation similar to #364, of which the most important bit is:
In this case, the original code
will be modified to
A couple of things are happening here:
The less obvious effect of this is that UglifyJS (with However, looking a bit more into what being side effect free means, this makes sense. Consider this snippet:
One would expect it to print But if you run it through uglify (
And here you see it does not set the property anymore. We say This is the second problema related to side effects we've had in the last week and I think there will only be more in the future unless an automated way to detect these is implemented. I'm not sure that's even possible, but maybe some linting rules (e.g. don't mutate arguments or call void functions) will go a long way. |
Really this should be catchable by running the unit tests for the library code on the "purified" code, right? For the future (in this case), would it be possible to parse the code and look for mutations to passed in parameters; and so not mark as PURE? |
I think running unit tests on purified code is really smart and should work. We can setup our own pipeline for that, but it makes me think tooling should be able to do this sort of thing in the future. I think it's possible to detect these things, and UglifyJS does it, but in this case we specifically set the |
I don't understand several things. Sorry for stupid questions:
|
When running an Angular application in production mode with the build optimizer and the Angular CLI, the code part, that sets the default color for round buttons, is removed accidentally. This seems to be an issue, that's caused by the build optimizer: angular/devkit#388. Fixes #9360
@IgorMinar this is how the original code looks like: https://github.com/angular/material2/blob/45235566588805ebb06f59f9b7826b865429ec3e/src/lib/button/button.ts#L77-L83 @devversion has a PR to change this logic (angular/components#9376). Regarding
And varying the
It might also be the interaction of It's also relevant to notice that changing If I had to bet, the expression inside parentheses causes UglifyJS to consider the left hand expression as a getter instead of a setter. This might be a UglifyJS bug/limitation (/cc @kzc). But even if that's the case, having a function that alters one of the arguments and returns nothing seems like a side effect to me. Retaining the function call would be a limitation of side-effect detection in UglifyJS. The bug should still be fixed because it's unintended behaviour for the option though. |
@filipesilva Please report this to the uglify project as an ES5 bug. Keep in mind that |
It appears to be a regression from |
@kzc opened as mishoo/UglifyJS#2838 👍 |
The UglifyJS bug bit of this issue was fixed in mishoo/UglifyJS#2839 and should be out on the next release. |
…#9376) When running an Angular application in production mode with the build optimizer and the Angular CLI, the code part, that sets the default color for round buttons, is removed accidentally. This seems to be an issue, that's caused by the build optimizer: angular/devkit#388. Fixes #9360
Awesome! That makes so much more sense because I kept on looking at the code and wondering why the assignment was getting stripped. Sanity restored. I do have to say that this code, particularly the constructor with non-local side-effect, is very odd looking and while it doesn't break our optimizations it should raise some eyebrows. |
…angular#9376) When running an Angular application in production mode with the build optimizer and the Angular CLI, the code part, that sets the default color for round buttons, is removed accidentally. This seems to be an issue, that's caused by the build optimizer: angular/devkit#388. Fixes angular#9360
Closing as the devkit issue is sorted, as far as I can tell. |
Bug Report or Feature Request (mark with an
x
)Area
Versions
Repro steps
Clone this reproduction repository and run the app in two different ways:
-prod --aot
)-prod --aot --build-optimizer=false
)The highlighted code snippet here (picture from the ESM 5 file button.js file) is being removed when running with the build optimizer. If you add a
console.log
before, theconsole.log
stays, just the specific code snippet is being removed.Switching to a ternary, or simple if-else will fix the issue.
with build-optimizer disabled
_with build-optimizer enabled
Mention any other details that might be useful
Related to Angular Material. angular/components#9360
cc. @filipesilva
The text was updated successfully, but these errors were encountered: