-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
clean up negate_iife
#1451
clean up negate_iife
#1451
Conversation
Please add the comments above explaining the clean up into the commit description itself. Because this PR is a rather invasive change to achieve the same functionality as before (albeit in a more efficient way) it would give reviewers more confidence if as little of the tests are changed as possible. Do not move or reorder tests, change formatting, add or remove semicolons or change names of tests - even if inconsistent. You may add new tests (preferably to the bottom of test files), but do not alter existing tests unless there is a mistake in the test itself. In general in this code base when changing object literals such as options try to prefer adding a trailing comma. That way new items added to the end of object literals will produce a smaller diff. Never remove trailing commas in existing code. |
lib/compress.js
Outdated
@@ -2292,7 +2266,18 @@ merge(Compressor.prototype, { | |||
} | |||
} | |||
} | |||
return self.evaluate(compressor)[0]; | |||
function is_iife_call(node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to improve readability please move is_iife_call function declaration below the return at the end of the function.
7b61644
to
94477c9
Compare
Just had a scan through https://github.com/mishoo/UglifyJS2/issues?utf8=%E2%9C%93&q=negate_iife and couldn't find more cases to fix/chase for now. Currently this PR only strips out |
Your changes seem reasonable, but there are a lot of moving parts. What does the new argument |
708ef1b
to
124a829
Compare
Previously there is no tracking of whether an expression under test is first in the statement, e.g. |
I was actually trying to remove Spotted an opportunity to insert new logic into There is an information loss during optimisations by With this PR statement_to_expression() consolidates those sites of interest so further work can be done. |
Thanks for the detailed explanation.
Yeah, once in sequence form a number of transforms are no longer possible. It would mostly impact suboptimal previously minified expression sequences. But that's beyond the scope of this PR. LGTM |
- remove extra tree scanning phase for `negate_iife` - `negate_iife` now only deals with the narrowest form, i.e. IIFE sitting directly under `AST_SimpleStatement` - `booleans`, `conditionals` etc. will now take care the rest via more accurate accounting - `a(); void b();` => `a(); b();` fixes mishoo#1288
124a829
to
1fd8caa
Compare
@kzc I guess you might know about this already, but I just noticed that for test cases with the same name, only the last one will run. So only the second |
I didn't know that, but it stands to reason because each test is just JS code in the end:
I would never have looked at the test names for duplication in a review. When you fix the unintentional duplicate names, do all the tests run correctly? |
I only saw this one while doing this PR, and it stuck in my head like a sore thumb so eventually I tested to see if my hypothesis can be proven. I can do a scan through the tests for duplicate names once I've got this |
Test names are AST_LabeledStatements.
As I mentioned in a few PRs, test coverage is lacking for older Uglify functionality. |
You have to admit the Uglify test framework is pretty darn clever in its use of JS syntax and its ease of use. The tests don't look like JS, yet they are. You can even run them through |
I come to appreciate the beauty of JavaScript as I work on this project, that's for sure 😜 |
Oh, and I looked at |
I learned a lot about JavaScript techniques and the language itself from reading Uglify source code. You don't truly understand any language until you have to minify it. ;-) |
- remove extra tree scanning phase for `negate_iife` - `negate_iife` now only deals with the narrowest form, i.e. IIFE sitting directly under `AST_SimpleStatement` - `booleans`, `conditionals` etc. will now take care the rest via more accurate accounting - `a(); void b();` => `a(); b();` fixes mishoo#1288 closes mishoo#1451
negate_iife
negate_iife
now only deals with the narrowest form, i.e. IIFE sitting directly underAST_SimpleStatement
booleans
,conditionals
etc. will now take care the rest via more accurate accountingIIRC there was a previous issue raised about some corner cases of
negate_iife
which the only workaround was to turn the flag off. If anybody remembers what it is I'd like to add it to test cases, since my aim is to improve the correctness of this feature.Reading material: #640, #1288, #1293