oxc/crates/oxc_parser/src/state.rs
Shannon Rothe 6647752e03
refactor(ast): change Option<Vec> to Vec for decorators (#84)
* remove `Option<Vec>` from `FormalParameter`

* `unwrap` -> `unwrap_or_else`

* prefer `AstBuilder` helper

* implement `consume_decorators`
2023-03-02 15:52:46 +08:00

26 lines
642 B
Rust

use std::collections::HashSet;
use oxc_allocator::{Allocator, Vec};
use oxc_ast::ast::Decorator;
pub struct ParserState<'a> {
allocator: &'a Allocator,
pub not_parenthesized_arrow: HashSet<u32>,
pub decorators: Vec<'a, Decorator<'a>>,
}
impl<'a> ParserState<'a> {
pub fn new(allocator: &'a Allocator) -> Self {
Self {
allocator,
not_parenthesized_arrow: HashSet::new(),
decorators: Vec::new_in(allocator),
}
}
pub fn consume_decorators(&mut self) -> Vec<'a, Decorator<'a>> {
std::mem::replace(&mut self.decorators, Vec::new_in(self.allocator))
}
}