mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(parser): compact cover initialized name storage (#28495)
Store only the initializer and diagnostic span for cover initialized names, avoiding the unused assignment-target node. Based on #28493. Validated parser conformance, bindings, and allocations. AI-assisted.
This commit is contained in:
1 parent
b3b5444712
commit
691be5c4f5
4 files changed
+19
-21
No files matched your search
@@ -224,7 +224,11 @@ impl<'a, C: Config> CoverGrammar<'a, ObjectProperty<'a>, C> for AssignmentTarget
|
||||
_ => return p.unexpected(),
|
||||
};
|
||||
// convert `CoverInitializedName`
|
||||
let init = p.state.cover_initialized_name.remove(&property.span.start).map(|e| e.right);
|
||||
let init = p
|
||||
.state
|
||||
.cover_initialized_name
|
||||
.remove(&property.span.start)
|
||||
.map(|cover| cover.initializer);
|
||||
AssignmentTargetProperty::new_assignment_target_property_identifier(
|
||||
property.span,
|
||||
binding,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use oxc_allocator::ArenaBox;
|
||||
use oxc_ast::ast::*;
|
||||
use oxc_syntax::operator::AssignmentOperator;
|
||||
|
||||
use crate::{
|
||||
Context, ParserConfig as Config, ParserImpl, diagnostics,
|
||||
lexer::Kind,
|
||||
modifiers::{ModifierKind, ModifierKinds, Modifiers},
|
||||
state::CoverInitializedName,
|
||||
};
|
||||
|
||||
use super::FunctionKind;
|
||||
@@ -108,20 +108,9 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
};
|
||||
// CoverInitializedName ({ foo = bar })
|
||||
if self.eat(Kind::Eq) {
|
||||
let right = self.parse_assignment_expression_or_higher();
|
||||
let left = AssignmentTarget::new_assignment_target_identifier(
|
||||
identifier_name.span,
|
||||
identifier_name.name,
|
||||
self,
|
||||
);
|
||||
let expr = AssignmentExpression::new(
|
||||
self.end_span(start),
|
||||
AssignmentOperator::Assign,
|
||||
left,
|
||||
right,
|
||||
self,
|
||||
);
|
||||
self.state.cover_initialized_name.insert(start, expr);
|
||||
let initializer = self.parse_assignment_expression_or_higher();
|
||||
let cover = CoverInitializedName { span: self.end_span(start), initializer };
|
||||
self.state.cover_initialized_name.insert(start, cover);
|
||||
}
|
||||
Expression::new_identifier(identifier_name.span, identifier_name.name, self)
|
||||
} else {
|
||||
|
||||
@@ -996,11 +996,10 @@ impl<'a, C: ParserConfig> ParserImpl<'a, C> {
|
||||
}
|
||||
|
||||
fn check_unfinished_errors(&mut self) {
|
||||
use oxc_span::GetSpan;
|
||||
// PropertyDefinition : cover_initialized_name
|
||||
// It is a Syntax Error if any source text is matched by this production.
|
||||
for expr in self.state.cover_initialized_name.values() {
|
||||
self.errors.push(diagnostics::cover_initialized_name(expr.span()));
|
||||
for cover in self.state.cover_initialized_name.values() {
|
||||
self.errors.push(diagnostics::cover_initialized_name(cover.span));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
use oxc_ast::ast::AssignmentExpression;
|
||||
use oxc_ast::ast::Expression;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::cursor::ParserCheckpoint;
|
||||
|
||||
/// The initializer and diagnostic span of a shorthand property awaiting cover validation.
|
||||
pub struct CoverInitializedName<'a> {
|
||||
pub span: Span,
|
||||
pub initializer: Expression<'a>,
|
||||
}
|
||||
|
||||
pub struct ParserState<'a> {
|
||||
pub not_parenthesized_arrow: FxHashSet<u32>,
|
||||
|
||||
/// Temporary storage for `CoverInitializedName` `({ foo = bar })`.
|
||||
/// Keyed by `ObjectProperty`'s span.start.
|
||||
pub cover_initialized_name: FxHashMap<u32, AssignmentExpression<'a>>,
|
||||
pub cover_initialized_name: FxHashMap<u32, CoverInitializedName<'a>>,
|
||||
|
||||
/// Trailing comma spans for `ArrayExpression` and `ObjectExpression` ending in a spread.
|
||||
/// Used for error reporting when covering a rest assignment target.
|
||||
|
||||
Reference in new issue
Block a user