Skip to content

Commit

Permalink
fix(codegen): print space before with clause in import (#2278)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryven committed Feb 2, 2024
1 parent 3569e42 commit 0c225a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> 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;
Expand Down Expand Up @@ -718,6 +721,9 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> 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();
}
Expand All @@ -734,6 +740,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for Option<WithClause<'a>> {
impl<'a, const MINIFY: bool> Gen<MINIFY> 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);
}
}
Expand Down Expand Up @@ -815,6 +822,9 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> 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();
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_codegen/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 0c225a4

Please sign in to comment.