Skip to content

Commit

Permalink
Fix Lexer.span
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jan 7, 2025
1 parent cd9fe06 commit c862038
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions crates/swc_ecma_parser/src/lexer/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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).
Expand Down
7 changes: 7 additions & 0 deletions crates/swc_ecma_raw_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c862038

Please sign in to comment.