Skip to content

Commit f2be26e

Browse files
authoredOct 11, 2024··
fix(es/codegen): Emit space after div if rhs has leading comment (#9631)
**Related issue:** - Closes #9630
1 parent aa3bb87 commit f2be26e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
 

‎.changeset/neat-ties-smoke.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_ecma_codegen: patch
3+
swc_core: patch
4+
---
5+
6+
fix(es/codegen): Emit space after div if rhs has leading comment

‎crates/swc_ecma_codegen/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,13 @@ where
12671267
let need_post_space = if self.cfg.minify {
12681268
if is_kwd_op {
12691269
node.right.starts_with_alpha_num()
1270+
} else if node.op == op!("/") {
1271+
let span = node.right.span();
1272+
1273+
span.is_pure()
1274+
|| self
1275+
.comments
1276+
.map_or(false, |comments| comments.has_leading(node.right.span().lo))
12701277
} else {
12711278
require_space_before_rhs(&node.right, &node.op)
12721279
}

‎crates/swc_ecma_codegen/src/tests.rs

+13
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,19 @@ fn issue_8491_2() {
962962
);
963963
}
964964

965+
#[test]
966+
fn issue_9630() {
967+
test_from_to_custom_config(
968+
"console.log(1 / /* @__PURE__ */ something())",
969+
"console.log(1/ /* @__PURE__ */something())",
970+
Config {
971+
minify: true,
972+
..Default::default()
973+
},
974+
Default::default(),
975+
);
976+
}
977+
965978
#[testing::fixture("tests/str-lits/**/*.txt")]
966979
fn test_str_lit(input: PathBuf) {
967980
test_str_lit_inner(input)

0 commit comments

Comments
 (0)
Please sign in to comment.