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
fix(es/base): Use seperate mark for FnExpr Ident #5959
Conversation
(function f(f) { | ||
f = b; | ||
f[b] = 0; | ||
(function f(f1) { |
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.
Don't know why this is renamed -- Could you help @kdy1 ?
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.
Because function name (f
) and the parameter (f1
) is now in a different scope
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.
Previously those were treated as identical to each other
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.
As there's (
in front of function, this is fn expr, not fn decl
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.
But why do other colliding ident not got renamed?
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.
At where? We reuse variable names in the name mangler, and we only rename declared identifiers in normal var renamer
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.
function foo(foo) {}
would remain the same after renamer.
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.
We are using same analyer for minifier and normal var renamer, and the analyzer knows that you can't refer foo
(function) from in foo
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.
Hmm... you are right I'm not sure why is this renamed.
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 think
swc/crates/swc_ecma_transforms_base/src/rename/analyzer/mod.rs
Lines 155 to 171 in 3d393dd
fn visit_fn_decl(&mut self, f: &FnDecl) { | |
self.add_decl(f.ident.to_id()); | |
self.with_scope(|v| { | |
f.function.visit_with(v); | |
}) | |
} | |
fn visit_fn_expr(&mut self, f: &FnExpr) { | |
self.with_scope(|v| { | |
if let Some(id) = &f.ident { | |
v.add_decl(id.to_id()); | |
} | |
f.function.visit_with(v); | |
}) | |
} |
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.
Thanks, although I think you need to update more tests.
swc-bump:
- swc_ecma_transforms_base
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 think there are room for improvement, but let's split PR.
(function f(f) { | ||
f = b; | ||
f[b] = 0; | ||
(function f(f1) { |
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.
We are using same analyer for minifier and normal var renamer, and the analyzer knows that you can't refer foo
(function) from in foo
(function f(f) { | ||
f = b; | ||
f[b] = 0; | ||
(function f(f1) { |
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.
Hmm... you are right I'm not sure why is this renamed.
(function f(f) { | ||
f = b; | ||
f[b] = 0; | ||
(function f(f1) { |
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 think
swc/crates/swc_ecma_transforms_base/src/rename/analyzer/mod.rs
Lines 155 to 171 in 3d393dd
fn visit_fn_decl(&mut self, f: &FnDecl) { | |
self.add_decl(f.ident.to_id()); | |
self.with_scope(|v| { | |
f.function.visit_with(v); | |
}) | |
} | |
fn visit_fn_expr(&mut self, f: &FnExpr) { | |
self.with_scope(|v| { | |
if let Some(id) = &f.ident { | |
v.add_decl(id.to_id()); | |
} | |
f.function.visit_with(v); | |
}) | |
} |
Description:
BREAKING CHANGE:
Related issue (if exists):