-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(es/minifier): Invoke IIFE into block #10220
Conversation
🦋 Changeset detectedLatest commit: 39e6480 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
CodSpeed Performance ReportMerging #10220 will degrade performances by 2.08%Comparing Summary
Benchmarks breakdown
|
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.
I'll review this very carefully with some time. Sorry for the delay, but this is a quite advanced optimization.
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.
Pull Request Overview
This PR implements changes to invoke IIFE blocks into a new block structure for various module outputs and async/await helper functions. The key changes include:
- Updating snapshot test outputs for library sizes.
- Rewriting module export patterns (AMD, CommonJS, UMD) to use a variable assignment with an "all" object and a for‑in loop.
- Modifying async/await helper output by removing IIFE wrappers.
Reviewed Changes
Copilot reviewed 160 out of 160 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
crates/swc/tests/libs-size.snapshot.md | Updated size snapshot values for various libraries. |
crates/swc/tests/tsc-references/contextuallyTypedStringLiteralsInJsxAttributes02.2.minified.js | Reordered export definitions with new function declarations. |
crates/swc/tests/tsc-references/exportAsNamespace3(module=amd).2.minified.js | Changed export pattern to use an "all" object and for‑in loop. |
crates/swc/tests/tsc-references/exportAsNamespace2(module=amd).2.minified.js | Changed export pattern to use an "all" object and for‑in loop. |
crates/swc/tests/tsc-references/asyncAwaitIsolatedModules_es6.2.minified.js | Removed IIFE wrapper in async/await helper function assignment. |
crates/swc/tests/tsc-references/asyncAwaitIsolatedModules_es5.2.minified.js | Removed IIFE wrapper in async/await helper function assignment. |
crates/swc/tests/tsc-references/asyncAwait_es6.2.minified.js | Removed IIFE wrapper in async/await helper function assignment. |
crates/swc/tests/tsc-references/asyncAwait_es5.2.minified.js | Removed IIFE wrapper in async/await helper function assignment. |
crates/swc/tests/tsc-references/exportAsNamespace2(module=umd).2.minified.js | Changed export pattern to use an "all" object and for‑in loop. |
crates/swc/tests/tsc-references/exportAsNamespace2(module=commonjs).2.minified.js | Changed export pattern to use an "all" object and for‑in loop. |
crates/swc/tests/tsc-references/exportAsNamespace3(module=commonjs).2.minified.js | Changed export pattern to use an "all" object and for‑in loop. |
crates/swc/tests/tsc-references/exportAsNamespace3(module=umd).2.minified.js | Changed export pattern to use an "all" object and for‑in loop. |
crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression.2.minified.js | Changed export pattern; removal of a redundant variable declaration. |
crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression.2.minified.js | Changed export pattern; removal of redundant declaration ordering. |
crates/swc/tests/tsc-references/declarationEmitThisPredicates01.2.minified.js | Changed export pattern to use variable assignment and "all" object. |
crates/swc/tests/tsc-references/assignmentCompatWithDiscriminatedUnion.2.minified.js | Updated call ordering within expression chains. |
crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES6.2.minified.js | Modified scope and declaration patterns in for‑of loops. |
crates/swc/tests/tsc-references/exportAsNamespace1(module=amd).2.minified.js | Changed export pattern to use an "all" object and for‑in loop. |
crates/swc/tests/tsc-references/exportAsNamespace1(module=commonjs).2.minified.js | Changed export pattern to use an "all" object and for‑in loop. |
crates/swc/tests/tsc-references/exportAsNamespace1(module=umd).2.minified.js | Changed export pattern to use an "all" object and for‑in loop. |
Comments suppressed due to low confidence (2)
crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression.2.minified.js:14
- The function for property 'E1' returns 'E11', which is not defined. This may cause a runtime error.
E1: function() { return E11; }
crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression.2.minified.js:10
- The function for property 'E1' returns 'E11', which is not defined. This may cause a runtime error.
E1: function() { return E11; }
crates/swc_ecma_minifier/tests/fixture/next/styled-components/1/output.js
Outdated
Show resolved
Hide resolved
@@ -1,8 +1,6 @@ | |||
//// [assignmentCompatWithDiscriminatedUnion.ts] |
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.
Note from copilot:
The initialization order of the variables (Example1, Example2, Example3, Example4, Example5, GH14865, GH30170, GH12052, GH18421, GH15907, GH20889, and GH39357) remains the same before and after the changes. The primary difference is the movement of the getAxisType function call and the removal of a few lines, which does not affect the order of variable initialization.
|
||
has_default && has_non_empty_terminates | ||
} | ||
Stmt::Try(t) => { |
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.
What about the finally block?
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.
finally block, despite run after every throw, would not change control flow, following code would not be executed if there's no catch
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.
Pull Request Overview
This PR implements a new feature in the ES minifier to invoke IIFEs into blocks, addressing missing scope support compared to gcc. The changes include refactoring how IIFEs and export objects are wrapped across various module formats (AMD, CommonJS, UMD) and updating snapshot files to reflect the new minified output.
- Export object definitions are refactored to use a local “all” variable with an iteration to define properties.
- The IIFE invocation for functions (e.g. for f1) is updated to use block scoping via immediate object assignment.
- Snapshot files are updated to reflect minor size changes.
Reviewed Changes
Copilot reviewed 164 out of 164 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
crates/swc/tests/libs-size.snapshot.md | Updated snapshot output values for compressed and gzipped sizes. |
crates/swc/tests/tsc-references/contextuallyTypedStringLiteralsInJsxAttributes02.2.minified.js | Reordered export definitions and function declarations for clarity. |
crates/swc/tests/fixture/issues-4xxx/4953/output/index.js | Wrapped the export assignment of “vr” in an IIFE to enforce strict mode. |
Multiple files under crates/swc/tests/tsc-references/ | Standardized export object creation across AMD, CommonJS, and UMD modules; updated async/await patterns accordingly. |
crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES6.2.minified.js | Adjusted loop binding declarations (using const over let) in destructuring loops. |
Comments suppressed due to low confidence (1)
crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression.2.minified.js:15
- The getter for E1 returns E11, which appears to be undefined; please verify whether it should return E1 instead.
return E11;
Description:
This is maybe the biggest missing feature of terser as compared to gcc because its lack of proper scope support. But we have.
Further development:
if (() => {} ())
Related issue:
es/minifier
: deep inline functions with statements #10054