Fix IIFE optimization removing const/let declarations causing undefined variable errors#10855
Fix IIFE optimization removing const/let declarations causing undefined variable errors#10855
Conversation
|
|
|
Co-authored-by: kdy1 <29931815+kdy1@users.noreply.github.com>
CodSpeed Performance ReportMerging #10855 will not alter performanceComparing Summary
|
Co-authored-by: kdy1 <29931815+kdy1@users.noreply.github.com>
|
@copilot Fix CI |
|
Copilot does not work well |
The IIFE (Immediately Invoked Function Expression) optimization was incorrectly handling
constandletdeclarations, causing undefined variable errors in the minified output.Issue
When minifying code with IIFE containing
constorletdeclarations, the optimizer would:prepend_stmtsconst obj;(not allowed in JavaScript)Example input:
Before fix (invalid output):
Fix
Modified the
inline_fn_likefunction incrates/swc_ecma_minifier/src/compress/optimize/iife.rsto only addvardeclarations toprepend_stmts, since:vardeclarations can exist without initializers:var obj;✓constandletdeclarations cannot:const obj;✗After fix (valid output):
Testing
Added comprehensive test case in
tests/fixture/iife_const_bug/that verifies:Fixes #10849.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.