refactor(codegen): use Stack for binary_expr_stack (#8663)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
This commit is contained in:
Boshen 2025-01-23 10:08:21 +08:00 committed by GitHub
parent 1e9f3857ab
commit db863a35bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 2 deletions

1
Cargo.lock generated
View file

@ -1635,6 +1635,7 @@ dependencies = [
"nonmax",
"oxc_allocator",
"oxc_ast",
"oxc_data_structures",
"oxc_index",
"oxc_mangler",
"oxc_parser",

View file

@ -22,6 +22,7 @@ doctest = false
[dependencies]
oxc_allocator = { workspace = true }
oxc_ast = { workspace = true }
oxc_data_structures = { workspace = true }
oxc_index = { workspace = true }
oxc_mangler = { workspace = true }
oxc_sourcemap = { workspace = true }

View file

@ -18,6 +18,7 @@ use std::borrow::Cow;
use oxc_ast::ast::{
BindingIdentifier, BlockStatement, Comment, Expression, IdentifierReference, Program, Statement,
};
use oxc_data_structures::stack::Stack;
use oxc_mangler::Mangler;
use oxc_span::{GetSpan, Span, SPAN};
use oxc_syntax::{
@ -88,7 +89,7 @@ pub struct Codegen<'a> {
prev_reg_exp_end: usize,
need_space_before_dot: usize,
print_next_indent_as_space: bool,
binary_expr_stack: Vec<BinaryExpressionVisitor<'a>>,
binary_expr_stack: Stack<BinaryExpressionVisitor<'a>>,
/// Indicates the output is JSX type, it is set in [`Program::gen`] and the result
/// is obtained by [`oxc_span::SourceType::is_jsx`]
is_jsx: bool,
@ -166,7 +167,7 @@ impl<'a> Codegen<'a> {
needs_semicolon: false,
need_space_before_dot: 0,
print_next_indent_as_space: false,
binary_expr_stack: Vec::with_capacity(5),
binary_expr_stack: Stack::with_capacity(12),
prev_op_end: 0,
prev_reg_exp_end: 0,
prev_op: None,