Skip to content

Commit

Permalink
fix(es/codegen): Emit space after div if rhs has leading comment (#9631)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #9630
  • Loading branch information
Austaras authored Oct 11, 2024
1 parent aa3bb87 commit f2be26e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/neat-ties-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_ecma_codegen: patch
swc_core: patch
---

fix(es/codegen): Emit space after div if rhs has leading comment
7 changes: 7 additions & 0 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,13 @@ where
let need_post_space = if self.cfg.minify {
if is_kwd_op {
node.right.starts_with_alpha_num()
} else if node.op == op!("/") {
let span = node.right.span();

span.is_pure()
|| self
.comments
.map_or(false, |comments| comments.has_leading(node.right.span().lo))
} else {
require_space_before_rhs(&node.right, &node.op)
}
Expand Down
13 changes: 13 additions & 0 deletions crates/swc_ecma_codegen/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,19 @@ fn issue_8491_2() {
);
}

#[test]
fn issue_9630() {
test_from_to_custom_config(
"console.log(1 / /* @__PURE__ */ something())",
"console.log(1/ /* @__PURE__ */something())",
Config {
minify: true,
..Default::default()
},
Default::default(),
);
}

#[testing::fixture("tests/str-lits/**/*.txt")]
fn test_str_lit(input: PathBuf) {
test_str_lit_inner(input)
Expand Down

0 comments on commit f2be26e

Please sign in to comment.