Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/oxc_parser/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use oxc_allocator::Vec;
use oxc_ast::ast::{BindingRestElement, RegExpFlags};
use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{GetSpan, Span};
use oxc_span::{GetSpan, Ident, Span};

use crate::{
Context, ParserImpl, diagnostics,
Expand Down Expand Up @@ -74,6 +74,12 @@ impl<'a> ParserImpl<'a> {
self.lexer.get_string(self.token)
}

/// Get current identifier with precomputed hash
#[inline]
pub(crate) fn cur_ident(&self) -> Ident<'a> {
self.lexer.get_ident(self.token)
}

/// Get current template string
pub(crate) fn cur_template_string(&self) -> Option<&'a str> {
self.lexer.get_template_string(self.token.start())
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_parser/src/js/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use oxc_allocator::{Box, TakeIn, Vec};
use oxc_ast::ast::*;
#[cfg(feature = "regular_expression")]
use oxc_regular_expression::ast::Pattern;
use oxc_span::{Atom, GetSpan, Span};
use oxc_span::{GetSpan, Ident, Span};
use oxc_syntax::{
number::{BigintBase, NumberBase},
precedence::Precedence,
Expand Down Expand Up @@ -117,11 +117,11 @@ impl<'a> ParserImpl<'a> {
}

#[inline]
pub(crate) fn parse_identifier_kind(&mut self, kind: Kind) -> (Span, Atom<'a>) {
pub(crate) fn parse_identifier_kind(&mut self, kind: Kind) -> (Span, Ident<'a>) {
let span = self.cur_token().span();
let name = self.cur_string();
let ident = self.cur_ident();
self.bump_remap(kind);
(span, Atom::from(name))
(span, ident)
}

pub(crate) fn check_identifier(&mut self, kind: Kind, ctx: Context) {
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_parser/src/lexer/string.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cmp::max;

use oxc_allocator::StringBuilder;
use oxc_span::Ident;

use crate::diagnostics;

Expand Down Expand Up @@ -272,4 +273,10 @@ impl<'a> Lexer<'a> {
}
&source_text[start..end]
}

/// Get the current identifier with precomputed hash.
#[inline]
pub(crate) fn get_ident(&self, token: Token) -> Ident<'a> {
Ident::new(self.get_string(token))
}
}
Loading