You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Compiler.print() is called with an AST consisting of an empty IIFE, the function doesn't wrap function(){} in parenthesis, causing invalid javascript to be returned.
Input code
use swc::Compiler;use swc_ecma_ast::{CallExpr,Callee,Expr,ExprStmt,FnExpr,Function,Module,ModuleItem,Program,Stmt};pubfnmain(){
let c=Compiler::new(Default::default());println!("{}",c.print(&Program::Module(Module{body: vec![ModuleItem::Stmt(Stmt::Expr(ExprStmt{expr: Box::new(Expr::Call(CallExpr{callee: Callee::Expr(Box::new(Expr::Fn(FnExpr{function: Box::new(Function{body: Some(Default::default()),..Default::default()}),..Default::default()}))),..Default::default()})),..Default::default()}))],..Default::default()}),Default::default()).unwrap().code);}
Config
Playground link (or link to the minimal reproduction)
maxicode2
changed the title
codegen: missing parenthesis around IIFE results in invalid output
swc_ecma_codegen: missing parenthesis around IIFE results in invalid output
Jan 20, 2025
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Describe the bug
When
Compiler.print()
is called with an AST consisting of an empty IIFE, the function doesn't wrapfunction(){}
in parenthesis, causing invalid javascript to be returned.Input code
Config
Playground link (or link to the minimal reproduction)
https://gist.github.com/maxicode2/35a93dcac5984fa7333af7ab491bb380
SWC Info output
No response
Expected behavior
The AST is printed as
(function(){})()
and node.js returns no errorActual behavior
The AST is printed as
function() {}()
and node.js returns an error:Version
swc@10.0.0, swc_ecma_ast@5.0.3, swc_ecma_codegen@5.1.0
Additional context
No response
The text was updated successfully, but these errors were encountered: