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
5 changes: 2 additions & 3 deletions crates/oxc_parser/src/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Code related to navigating `Token`s from the lexer

use oxc_allocator::Vec;
use oxc_allocator::{TakeIn, Vec};
use oxc_ast::ast::{Decorator, RegExpFlags};
use oxc_diagnostics::Result;
use oxc_span::{GetSpan, Span};
Expand Down Expand Up @@ -327,8 +327,7 @@ impl<'a> ParserImpl<'a> {
}

pub(crate) fn consume_decorators(&mut self) -> Vec<'a, Decorator<'a>> {
let decorators = std::mem::take(&mut self.state.decorators);
self.ast.vec_from_iter(decorators)
self.state.decorators.take_in(self.ast.allocator)
}

pub(crate) fn parse_normal_list<F, T>(
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ impl<'a> ParserImpl<'a> {
errors: vec![],
token: Token::default(),
prev_token_end: 0,
state: ParserState::default(),
state: ParserState::new(allocator),
ctx: Self::default_context(source_type, options),
ast: AstBuilder::new(allocator),
module_record_builder: ModuleRecordBuilder::new(allocator),
Expand Down
15 changes: 13 additions & 2 deletions crates/oxc_parser/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use rustc_hash::{FxHashMap, FxHashSet};

use oxc_allocator::{Allocator, Vec as ArenaVec};
use oxc_ast::ast::{AssignmentExpression, Decorator};
use oxc_span::Span;

#[derive(Default)]
pub struct ParserState<'a> {
pub not_parenthesized_arrow: FxHashSet<u32>,

pub decorators: Vec<Decorator<'a>>,
pub decorators: ArenaVec<'a, Decorator<'a>>,

/// Temporary storage for `CoverInitializedName` `({ foo = bar })`.
/// Keyed by `ObjectProperty`'s span.start.
Expand All @@ -19,3 +19,14 @@ pub struct ParserState<'a> {
/// Valued by position of the trailing_comma.
pub trailing_commas: FxHashMap<u32, Span>,
}

impl<'a> ParserState<'a> {
pub fn new(allocator: &'a Allocator) -> Self {
Self {
not_parenthesized_arrow: FxHashSet::default(),
decorators: ArenaVec::new_in(allocator),
cover_initialized_name: FxHashMap::default(),
trailing_commas: FxHashMap::default(),
}
}
}
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/ts/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl<'a> ParserImpl<'a> {
return Ok(());
}

let mut decorators = vec![];
let mut decorators = self.ast.vec();
while self.at(Kind::At) {
let decorator = self.parse_decorator()?;
decorators.push(decorator);
Expand Down
Loading