Skip to content

Commit

Permalink
fix(es/parser): Fix span for unterminated block comments (#9361)
Browse files Browse the repository at this point in the history
**Related issue:**

 - wooorm/mdxjs-rs#49
  • Loading branch information
kdy1 committed Aug 1, 2024
1 parent 9cd51ce commit dc1b87e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/large-glasses-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_common: patch
swc_ecma_parser: patch
---

fix(es/parser): Fix span for unterminated block comments
8 changes: 8 additions & 0 deletions crates/swc_common/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ impl<'a> StringInput<'a> {
self.reset_to(self.last_pos + BytePos(n as u32));
}
}

pub fn start_pos(&self) -> BytePos {
self.orig_start
}

pub fn end_pos(&self) -> BytePos {
self.last_pos
}
}

/// Creates an [Input] from [SourceFile]. This is an alias for
Expand Down
3 changes: 2 additions & 1 deletion crates/swc_ecma_parser/src/lexer/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ impl<'a> Lexer<'a> {
self.bump();
}

self.emit_error(start, SyntaxError::UnterminatedBlockComment)
let span = Span::new(start, self.input.end_pos());
self.emit_error_span(span, SyntaxError::UnterminatedBlockComment)
}

#[inline(never)]
Expand Down

0 comments on commit dc1b87e

Please sign in to comment.