Skip to content

Commit

Permalink
fix(es/transforms/compat): apply regenerator transform for default expr
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Nov 9, 2021
1 parent 502962e commit 85a4373
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ecmascript/transforms/compat/src/es2017/async_to_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,35 @@ impl Fold for Actual {
}
}

fn fold_module_item(&mut self, item: ModuleItem) -> ModuleItem {
match item {
// if fn is ExportDefaultDecl, fn is not FnDecl but FnExpr
ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(export_default)) => {
if let DefaultDecl::Fn(expr) = export_default.decl {
let expr = if !expr.function.is_async {
expr
} else {
let function = self.fold_fn(expr.ident.clone(), expr.function, true);
FnExpr {
ident: expr.ident,
function,
}
};

ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl {
decl: expr.into(),
..export_default
}))
} else {
let item =
ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(export_default));
item.fold_children_with(self)
}
}
_ => item.fold_children_with(self),
}
}

fn fold_method_prop(&mut self, prop: MethodProp) -> MethodProp {
let prop = prop.fold_children_with(self);

Expand Down

0 comments on commit 85a4373

Please sign in to comment.