Skip to content
Merged
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
13 changes: 6 additions & 7 deletions crates/oxc_parser/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ pub struct ParserCheckpoint<'a> {

impl<'a> ParserImpl<'a> {
#[inline]
pub(crate) fn start_span(&self) -> Span {
let token = self.cur_token();
Span::new(token.start, 0)
pub(crate) fn start_span(&self) -> u32 {
self.token.start
}

#[inline]
pub(crate) fn end_span(&self, mut span: Span) -> Span {
span.end = self.prev_token_end;
debug_assert!(span.end >= span.start);
span
pub(crate) fn end_span(&self, start: u32) -> Span {
let end = self.prev_token_end;
debug_assert!(end >= start);
Span::new(start, end)
}

/// Get current token
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_parser/src/js/arrow.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use oxc_allocator::Box;
use oxc_ast::{NONE, ast::*};
use oxc_diagnostics::Result;
use oxc_span::{GetSpan, Span};
use oxc_span::GetSpan;
use oxc_syntax::precedence::Precedence;

use super::Tristate;
Expand All @@ -12,7 +12,7 @@ struct ArrowFunctionHead<'a> {
params: Box<'a, FormalParameters<'a>>,
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
r#async: bool,
span: Span,
span: u32,
has_return_colon: bool,
}

Expand Down Expand Up @@ -213,7 +213,7 @@ impl<'a> ParserImpl<'a> {

pub(crate) fn parse_simple_arrow_function_expression(
&mut self,
span: Span,
span: u32,
ident: Expression<'a>,
r#async: bool,
allow_return_type_in_arrow_function: bool,
Expand All @@ -229,7 +229,7 @@ impl<'a> ParserImpl<'a> {
}
_ => unreachable!(),
};
let params_span = self.end_span(ident.span);
let params_span = self.end_span(ident.span.start);
let ident = BindingPatternKind::BindingIdentifier(ident);
let pattern = self.ast.binding_pattern(ident, NONE, false);
let formal_parameter = self.ast.plain_formal_parameter(params_span, pattern);
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_parser/src/js/binding.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use oxc_ast::{NONE, ast::*};
use oxc_diagnostics::Result;
use oxc_span::{GetSpan, Span};
use oxc_span::GetSpan;

use crate::{Context, ParserImpl, diagnostics, lexer::Kind};

Expand Down Expand Up @@ -165,7 +165,7 @@ impl<'a> ParserImpl<'a> {
/// = `AssignmentExpression`[?In, ?Yield, ?Await]
fn parse_initializer(
&mut self,
span: Span,
span: u32,
left: BindingPattern<'a>,
) -> Result<BindingPattern<'a>> {
if self.eat(Kind::Eq) {
Expand Down
16 changes: 8 additions & 8 deletions crates/oxc_parser/src/js/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<'a> ParserImpl<'a> {
pub(crate) fn parse_class_statement(
&mut self,
stmt_ctx: StatementContext,
start_span: Span,
start_span: u32,
) -> Result<Statement<'a>> {
let modifiers = self.parse_modifiers(
/* allow_decorators */ true, /* permit_const_as_modifier */ false,
Expand All @@ -40,7 +40,7 @@ impl<'a> ParserImpl<'a> {
/// Section 15.7 Class Definitions
pub(crate) fn parse_class_declaration(
&mut self,
start_span: Span,
start_span: u32,
modifiers: &Modifiers<'a>,
) -> Result<Box<'a, Class<'a>>> {
self.parse_class(start_span, ClassType::ClassDeclaration, modifiers)
Expand All @@ -57,14 +57,14 @@ impl<'a> ParserImpl<'a> {

fn parse_class(
&mut self,
start_span: Span,
start_span: u32,
r#type: ClassType,
modifiers: &Modifiers<'a>,
) -> Result<Box<'a, Class<'a>>> {
self.bump_any(); // advance `class`

let decorators = self.consume_decorators();
let start_span = decorators.iter().next().map_or(start_span, |d| d.span);
let start_span = decorators.iter().next().map_or(start_span, |d| d.span.start);

let id = if self.cur_kind().is_binding_identifier() && !self.at(Kind::Implements) {
Some(self.parse_binding_identifier()?)
Expand Down Expand Up @@ -391,7 +391,7 @@ impl<'a> ParserImpl<'a> {

fn parse_class_method_definition(
&mut self,
span: Span,
span: u32,
kind: MethodDefinitionKind,
key: PropertyKey<'a>,
computed: bool,
Expand Down Expand Up @@ -455,7 +455,7 @@ impl<'a> ParserImpl<'a> {
/// `FieldDefinition`[?Yield, ?Await] ;
fn parse_class_property_definition(
&mut self,
span: Span,
span: u32,
key: PropertyKey<'a>,
computed: bool,
r#static: bool,
Expand Down Expand Up @@ -497,7 +497,7 @@ impl<'a> ParserImpl<'a> {

/// `ClassStaticBlockStatementList` :
/// `StatementList`[~Yield, +Await, ~Return]
fn parse_class_static_block(&mut self, span: Span) -> Result<ClassElement<'a>> {
fn parse_class_static_block(&mut self, span: u32) -> Result<ClassElement<'a>> {
let block =
self.context(Context::Await, Context::Yield | Context::Return, Self::parse_block)?;
Ok(self.ast.class_element_static_block(self.end_span(span), block.unbox().body))
Expand All @@ -506,7 +506,7 @@ impl<'a> ParserImpl<'a> {
/// <https://github.com/tc39/proposal-decorators>
fn parse_class_accessor_property(
&mut self,
span: Span,
span: u32,
key: PropertyKey<'a>,
computed: bool,
r#static: bool,
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_parser/src/js/declaration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use oxc_allocator::Box;
use oxc_ast::{NONE, ast::*};
use oxc_diagnostics::Result;
use oxc_span::{GetSpan, Span};
use oxc_span::GetSpan;

use super::VariableDeclarationParent;
use crate::{
Expand Down Expand Up @@ -36,13 +36,13 @@ impl<'a> ParserImpl<'a> {
pub(crate) fn parse_using_statement(&mut self) -> Result<Statement<'a>> {
let mut decl = self.parse_using_declaration(StatementContext::StatementList)?;
self.asi()?;
decl.span = self.end_span(decl.span);
decl.span = self.end_span(decl.span.start);
Ok(Statement::VariableDeclaration(self.alloc(decl)))
}

pub(crate) fn parse_variable_declaration(
&mut self,
start_span: Span,
start_span: u32,
decl_parent: VariableDeclarationParent,
modifiers: &Modifiers<'a>,
) -> Result<Box<'a, VariableDeclaration<'a>>> {
Expand Down
32 changes: 16 additions & 16 deletions crates/oxc_parser/src/js/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<'a> ParserImpl<'a> {
}
}

fn parse_parenthesized_expression(&mut self, span: Span) -> Result<Expression<'a>> {
fn parse_parenthesized_expression(&mut self, span: u32) -> Result<Expression<'a>> {
self.expect(Kind::LParen)?;
let expr_span = self.start_span();
let mut expressions = self.context(Context::In, Context::Decorator, |p| {
Expand Down Expand Up @@ -436,7 +436,7 @@ impl<'a> ParserImpl<'a> {
if self.at(Kind::Comma) {
let comma_span = self.start_span();
self.bump_any();
self.state.trailing_commas.insert(span.start, self.end_span(comma_span));
self.state.trailing_commas.insert(span, self.end_span(comma_span));
}
self.expect(Kind::RBrack)?;
Ok(self.ast.expression_array(self.end_span(span), elements))
Expand Down Expand Up @@ -510,7 +510,7 @@ impl<'a> ParserImpl<'a> {

fn parse_tagged_template(
&mut self,
span: Span,
span: u32,
lhs: Expression<'a>,
in_optional_chain: bool,
type_parameters: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
Expand Down Expand Up @@ -708,7 +708,7 @@ impl<'a> ParserImpl<'a> {
/// parse rhs of a member expression, starting from lhs
fn parse_member_expression_rest(
&mut self,
lhs_span: Span,
lhs_span: u32,
lhs: Expression<'a>,
in_optional_chain: &mut bool,
) -> Result<Expression<'a>> {
Expand Down Expand Up @@ -784,7 +784,7 @@ impl<'a> ParserImpl<'a> {
/// static member `a.b`
fn parse_static_member_expression(
&mut self,
lhs_span: Span,
lhs_span: u32,
lhs: Expression<'a>,
optional: bool,
) -> Result<Expression<'a>> {
Expand All @@ -809,7 +809,7 @@ impl<'a> ParserImpl<'a> {
/// `MemberExpression`[?Yield, ?Await] [ Expression[+In, ?Yield, ?Await] ]
fn parse_computed_member_expression(
&mut self,
lhs_span: Span,
lhs_span: u32,
lhs: Expression<'a>,
optional: bool,
) -> Result<Expression<'a>> {
Expand Down Expand Up @@ -882,7 +882,7 @@ impl<'a> ParserImpl<'a> {
/// Section 13.3 Call Expression
fn parse_call_expression_rest(
&mut self,
lhs_span: Span,
lhs_span: u32,
lhs: Expression<'a>,
in_optional_chain: &mut bool,
) -> Result<Expression<'a>> {
Expand Down Expand Up @@ -923,7 +923,7 @@ impl<'a> ParserImpl<'a> {

fn parse_call_arguments(
&mut self,
lhs_span: Span,
lhs_span: u32,
lhs: Expression<'a>,
optional: bool,
type_parameters: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
Expand Down Expand Up @@ -958,7 +958,7 @@ impl<'a> ParserImpl<'a> {
}

/// Section 13.4 Update Expression
fn parse_update_expression(&mut self, lhs_span: Span) -> Result<Expression<'a>> {
fn parse_update_expression(&mut self, lhs_span: u32) -> Result<Expression<'a>> {
let kind = self.cur_kind();
// ++ -- prefix update expressions
if kind.is_update_operator() {
Expand Down Expand Up @@ -996,7 +996,7 @@ impl<'a> ParserImpl<'a> {
/// Section 13.5 Unary Expression
pub(crate) fn parse_unary_expression_or_higher(
&mut self,
lhs_span: Span,
lhs_span: u32,
) -> Result<Expression<'a>> {
// ++ -- prefix update expressions
if self.is_update_expression() {
Expand All @@ -1007,7 +1007,7 @@ impl<'a> ParserImpl<'a> {

pub(crate) fn parse_simple_unary_expression(
&mut self,
lhs_span: Span,
lhs_span: u32,
) -> Result<Expression<'a>> {
match self.cur_kind() {
kind if kind.is_unary_operator() => self.parse_unary_expression(),
Expand Down Expand Up @@ -1066,7 +1066,7 @@ impl<'a> ParserImpl<'a> {
/// Section 13.6 - 13.13 Binary Expression
fn parse_binary_expression_rest(
&mut self,
lhs_span: Span,
lhs_span: u32,
lhs: Expression<'a>,
min_precedence: Precedence,
) -> Result<Expression<'a>> {
Expand Down Expand Up @@ -1143,7 +1143,7 @@ impl<'a> ParserImpl<'a> {
/// `ShortCircuitExpression`[?In, ?Yield, ?Await] ? `AssignmentExpression`[+In, ?Yield, ?Await] : `AssignmentExpression`[?In, ?Yield, ?Await]
fn parse_conditional_expression_rest(
&mut self,
lhs_span: Span,
lhs_span: u32,
lhs: Expression<'a>,
allow_return_type_in_arrow_function: bool,
) -> Result<Expression<'a>> {
Expand Down Expand Up @@ -1284,7 +1284,7 @@ impl<'a> ParserImpl<'a> {

fn parse_assignment_expression_recursive(
&mut self,
span: Span,
span: u32,
lhs: Expression<'a>,
allow_return_type_in_arrow_function: bool,
) -> Result<Expression<'a>> {
Expand All @@ -1305,7 +1305,7 @@ impl<'a> ParserImpl<'a> {
/// Section 13.16 Sequence Expression
fn parse_sequence_expression(
&mut self,
span: Span,
span: u32,
first_expression: Expression<'a>,
) -> Result<Expression<'a>> {
let mut expressions = self.ast.vec1(first_expression);
Expand All @@ -1318,7 +1318,7 @@ impl<'a> ParserImpl<'a> {

/// ``AwaitExpression`[Yield]` :
/// await `UnaryExpression`[?Yield, +Await]
fn parse_await_expression(&mut self, lhs_span: Span) -> Result<Expression<'a>> {
fn parse_await_expression(&mut self, lhs_span: u32) -> Result<Expression<'a>> {
let span = self.start_span();
if !self.ctx.has_await() {
self.error(diagnostics::await_expression(self.cur_token().span()));
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_parser/src/js/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'a> ParserImpl<'a> {

pub(crate) fn parse_function(
&mut self,
span: Span,
span: u32,
id: Option<BindingIdentifier<'a>>,
r#async: bool,
generator: bool,
Expand Down Expand Up @@ -232,7 +232,7 @@ impl<'a> ParserImpl<'a> {
/// at `function`
pub(crate) fn parse_ts_function_impl(
&mut self,
start_span: Span,
start_span: u32,
func_kind: FunctionKind,
modifiers: &Modifiers<'a>,
) -> Result<Box<'a, Function<'a>>> {
Expand All @@ -254,7 +254,7 @@ impl<'a> ParserImpl<'a> {
/// [Function Expression](https://tc39.es/ecma262/#prod-FunctionExpression)
pub(crate) fn parse_function_expression(
&mut self,
span: Span,
span: u32,
r#async: bool,
) -> Result<Expression<'a>> {
let func_kind = FunctionKind::Expression;
Expand Down Expand Up @@ -309,7 +309,7 @@ impl<'a> ParserImpl<'a> {

let has_yield = self.ctx.has_yield();
if !has_yield {
self.error(diagnostics::yield_expression(Span::new(span.start, span.start + 5)));
self.error(diagnostics::yield_expression(Span::new(span, span + 5)));
}

let mut delegate = false;
Expand Down
Loading
Loading