diff --git a/crates/swc_ecma_parser/src/lexer/util.rs b/crates/swc_ecma_parser/src/lexer/util.rs index 7f6e6cc42f42..464ba459fd62 100644 --- a/crates/swc_ecma_parser/src/lexer/util.rs +++ b/crates/swc_ecma_parser/src/lexer/util.rs @@ -9,7 +9,6 @@ use swc_common::{ BytePos, Span, }; use swc_ecma_ast::Ident; -use swc_ecma_raw_lexer::RawToken; use tracing::warn; use super::{comments_buffer::BufferedComment, Char, LexResult, Lexer}; @@ -20,8 +19,8 @@ use crate::{ }; impl Lexer<'_> { - pub(super) fn span(&self, start: BytePos) -> Span { - let end = self.input.cur_pos(); + pub(super) fn span(&mut self, start: BytePos) -> Span { + let end = self.input.cur_hi(); if cfg!(debug_assertions) && start > end { unreachable!( "assertion failed: (span.start <= span.end). diff --git a/crates/swc_ecma_raw_lexer/src/lib.rs b/crates/swc_ecma_raw_lexer/src/lib.rs index a7d794dc2bd4..38653278d231 100644 --- a/crates/swc_ecma_raw_lexer/src/lib.rs +++ b/crates/swc_ecma_raw_lexer/src/lib.rs @@ -65,6 +65,13 @@ impl<'a> RawLexer<'a> { self.pos } + pub fn cur_hi(&mut self) -> BytePos { + let span = self.lexer.peek().map(|v| v.1.clone()).unwrap_or_default(); + + // +1 because hi is exclusive + self.pos + BytePos(span.len() as u32 + 1) + } + pub fn update_cur_pos(&mut self) -> BytePos { let span = self.lexer.peek().map(|v| v.1.clone()).unwrap_or_default(); self.pos = self.base_pos + BytePos(span.start as u32);