mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
fix(es/fixer): Handle async
in the left of for of
(#5625)
This commit is contained in:
parent
d538b72002
commit
eb3b0e96e5
@ -1,6 +1,6 @@
|
||||
// @target: esnext
|
||||
var async;
|
||||
for (async of [
|
||||
for ((async) of [
|
||||
1,
|
||||
2
|
||||
]);
|
||||
|
@ -1,5 +1,5 @@
|
||||
var async;
|
||||
for (async of [
|
||||
for ((async) of [
|
||||
1,
|
||||
2
|
||||
]);
|
||||
|
@ -1,3 +1,4 @@
|
||||
use swc_atoms::js_word;
|
||||
use swc_common::{collections::AHashMap, comments::Comments, util::take::Take, Span, Spanned};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
@ -461,6 +462,31 @@ impl VisitMut for Fixer<'_> {
|
||||
fn visit_mut_for_of_stmt(&mut self, s: &mut ForOfStmt) {
|
||||
s.visit_mut_children_with(self);
|
||||
|
||||
if s.await_token.is_none() {
|
||||
if let VarDeclOrPat::Pat(Pat::Ident(BindingIdent {
|
||||
id:
|
||||
id @ Ident {
|
||||
sym: js_word!("async"),
|
||||
..
|
||||
},
|
||||
..
|
||||
})) = &mut s.left
|
||||
{
|
||||
let expr = Expr::Ident(id.take());
|
||||
s.left = VarDeclOrPat::Pat(Pat::Expr(Box::new(expr)));
|
||||
}
|
||||
|
||||
if let VarDeclOrPat::Pat(Pat::Expr(expr)) = &mut s.left {
|
||||
if let Expr::Ident(Ident {
|
||||
sym: js_word!("async"),
|
||||
..
|
||||
}) = &**expr
|
||||
{
|
||||
self.wrap(&mut *expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Expr::Seq(..) | Expr::Await(..) = &*s.right {
|
||||
self.wrap(&mut s.right)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user