-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(es/minifier): respect ecma for iife temp vars #11873
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| swc: patch | ||
| swc_core: patch | ||
| swc_ecma_minifier: patch | ||
| --- | ||
|
|
||
| fix(es/minifier): respect ecma when emitting IIFE temp vars |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| let a;v=(a=r,b=>a.map(t=>{if(t)return t.foo})); | ||
| var a;v=(a=r,b=>a.map(t=>{if(t)return t.foo})); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -686,7 +686,11 @@ impl Optimizer<'_> { | |
| self.prepend_stmts.push( | ||
| VarDecl { | ||
| span: DUMMY_SP, | ||
| kind: VarDeclKind::Let, | ||
| kind: if self.options.ecma >= EsVersion::Es2015 { | ||
| VarDeclKind::Let | ||
| } else { | ||
| VarDeclKind::Var | ||
| }, | ||
|
Comment on lines
+689
to
+693
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Using Useful? React with 👍 / 👎.
Comment on lines
+689
to
+693
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Lowering these synthesized temporaries to function-scoped Useful? React with 👍 / 👎. |
||
| declare: Default::default(), | ||
| decls: vars, | ||
| ..Default::default() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "defaults": true, | ||
| "ecma": 5, | ||
| "toplevel": false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function run() { | ||
| return ((value) => value + value)(Math.random()); | ||
| } | ||
|
|
||
| console.log(run()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function run() { | ||
| var value; | ||
| return (value = Math.random()) + value; | ||
| } | ||
| console.log(run()); |
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.
Switching synthesized temp declarations from
lettovarininvoke_iifebreaks closure semantics for arrow-IIFE inlining inside loops whencompress.ecma < 2015. In patterns likefor (const k in obj) { out[k] = ((k)=>()=>k)(k) }, the extracted temp now becomes a function-scopedvar, so all generated closures share one binding and observe the last iteration’s value instead of each iteration’s value. This is a runtime behavior regression (not just formatting) and is visible in the updated 8246 fixture shape where the captured temp is nowvarinside the loop body.Useful? React with 👍 / 👎.