diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index aaa3ef94b..8739f6397 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -654,6 +654,9 @@ impl<'a, const MINIFY: bool> Gen for ImportDeclaration<'a> { p.print(b'\''); p.print_str(self.source.value.as_bytes()); p.print(b'\''); + if self.with_clause.is_some() { + p.print_hard_space(); + } self.with_clause.gen(p, ctx); p.print_semicolon_after_statement(); return; @@ -718,6 +721,9 @@ impl<'a, const MINIFY: bool> Gen for ImportDeclaration<'a> { p.print_str(b" from "); } self.source.gen(p, ctx); + if self.with_clause.is_some() { + p.print_hard_space(); + } self.with_clause.gen(p, ctx); p.print_semicolon_after_statement(); } @@ -734,6 +740,7 @@ impl<'a, const MINIFY: bool> Gen for Option> { impl<'a, const MINIFY: bool> Gen for WithClause<'a> { fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) { self.attributes_keyword.gen(p, ctx); + p.print_soft_space(); p.print_block(&self.with_entries, Separator::Comma, ctx); } } @@ -815,6 +822,9 @@ impl<'a, const MINIFY: bool> Gen for ExportAllDeclaration<'a> { p.print_str(b" from "); self.source.gen(p, ctx); + if self.with_clause.is_some() { + p.print_hard_space(); + } self.with_clause.gen(p, ctx); p.print_semicolon_after_statement(); diff --git a/crates/oxc_codegen/tests/mod.rs b/crates/oxc_codegen/tests/mod.rs index 2a0d356dc..1d3bb3900 100644 --- a/crates/oxc_codegen/tests/mod.rs +++ b/crates/oxc_codegen/tests/mod.rs @@ -104,4 +104,7 @@ fn template() { #[test] fn module_decl() { test("export * as foo from 'foo'", "export * as foo from 'foo';\n"); + test("import x from './foo.js' with {}", "import x from './foo.js' with {\n};\n"); + test("import {} from './foo.js' with {}", "import './foo.js' with {\n};\n"); + test("export * from './foo.js' with {}", "export * from './foo.js' with {\n};\n"); }