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
refactor(es/minifier): Don't create invalid nodes #6191
Conversation
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.
swc-bump:
- swc_ecma_transforms_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.
swc-bump:
- swc_ecma_transforms_optimization
@@ -1,5 +1,6 @@ | |||
//// [ES5For-of16.ts] | |||
for(var _i = 0, _iter = []; _i < _iter.length; _i++){ | |||
_iter[_i]; | |||
for(var _i1 = 0, _iter1 = []; _i1 < _iter1.length; _i1++)_iter1[_i1]; | |||
for(var _i1 = 0, _iter1 = []; _i1 < _iter1.length; _i1++); |
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.
These tests changes are bugfix
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 we generated foo = Expr::Seq(seq)
so logic expecting identifier in foo
didn't work correctly.
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.
Now we generate foo = seq.0
so it's analyzed/processed correctly
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 believe this output is actually incorrect for the input. The following line should be inside the inner for loop, not after.
@@ -1,5 +1,6 @@ | |||
//// [ES5For-of16.ts] | |||
for(var _i = 0, _iter = []; _i < _iter.length; _i++){ | |||
_iter[_i]; | |||
for(var _i1 = 0, _iter1 = []; _i1 < _iter1.length; _i1++)_iter1[_i1]; | |||
for(var _i1 = 0, _iter1 = []; _i1 < _iter1.length; _i1++); |
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 believe this output is actually incorrect for the input. The following line should be inside the inner for loop, not after.
@@ -986,7 +982,9 @@ where | |||
}; | |||
self.merge_sequences_in_seq_expr(&mut e); | |||
|
|||
return Some(Expr::Seq(e)); | |||
let mut e = Expr::Seq(e); |
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.
Do we know exprs
has more than 1 element?
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 normalize instead of verifying, at the line below.
I think we can improve this in the future
@@ -1008,7 +1006,9 @@ where | |||
}; | |||
self.merge_sequences_in_seq_expr(&mut e); | |||
|
|||
Some(Expr::Seq(e)) | |||
let mut e = Expr::Seq(e); |
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.
Ditto.
match s { | ||
Stmt::Decl(Decl::Var(v)) if v.decls.is_empty() => { | ||
s.take(); | ||
if self.prepend_stmts.is_empty() && self.append_stmts.is_empty() { |
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.
This is the fix for wrong appending
|
||
if seq.exprs.len() == 1 { | ||
*e = *seq.exprs.take().into_iter().next().unwrap(); | ||
self.normalize_expr(e); |
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.
Nit: isn't this already normalized from the above for e in seq.exprs
? Can extracting it out of the sequence expression change the normalization?
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.
Oh I think you are right
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.
Actually it had an effect beause for e
does not handle len() == 1
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.
Automated review comment generated by auto-rebase script
Description:
Related issue: