Skip to content

Commit 16e204d

Browse files
authored
fix(es/codegen): Don't call cmt.get_leading for dummy span (#10568)
This was the only place where `Comments` were queried for dummy spans (`BytePos(0)`)
1 parent 81fcd01 commit 16e204d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

.changeset/sixty-pans-help.md

Lines changed: 6 additions & 0 deletions
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+
Don't call `cmt.get_leading` for dummy span

crates/swc_ecma_codegen/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,10 @@ fn is_empty_comments(span: &Span, comments: &Option<&dyn Comments>) -> bool {
13821382
fn span_has_leading_comment(cmt: &dyn Comments, span: Span) -> bool {
13831383
let lo = span.lo;
13841384

1385+
if lo.is_dummy() {
1386+
return false;
1387+
}
1388+
13851389
// see #415
13861390
if let Some(cmt) = cmt.get_leading(lo) {
13871391
if cmt.iter().any(|cmt| {

0 commit comments

Comments
 (0)