Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(traverse)!: remove unsound APIs #7514

Merged
merged 1 commit into from
Nov 28, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use oxc_allocator::Vec;
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};
use oxc_traverse::{traverse_mut_with_ctx, ReusableTraverseCtx, Traverse, TraverseCtx};

use crate::CompressorPass;

Expand All @@ -17,9 +17,9 @@ impl<'a> CompressorPass<'a> for CollapseVariableDeclarations {
self.changed
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
self.changed = false;
oxc_traverse::walk_program(self, program, ctx);
traverse_mut_with_ctx(self, program, ctx);
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_minifier/src/ast_passes/exploit_assigns.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};
use oxc_traverse::{traverse_mut_with_ctx, ReusableTraverseCtx, Traverse};

use crate::CompressorPass;

Expand All @@ -15,9 +15,9 @@ impl<'a> CompressorPass<'a> for ExploitAssigns {
self.changed
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
self.changed = false;
oxc_traverse::walk_program(self, program, ctx);
traverse_mut_with_ctx(self, program, ctx);
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/oxc_minifier/src/ast_passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ pub use statement_fusion::StatementFusion;

use oxc_allocator::Vec;
use oxc_ast::ast::*;
use oxc_traverse::{Traverse, TraverseCtx};
use oxc_traverse::{traverse_mut_with_ctx, ReusableTraverseCtx, Traverse, TraverseCtx};

pub trait CompressorPass<'a>: Traverse<'a> {
fn changed(&self) -> bool;

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>);
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>);
}

// See `latePeepholeOptimizations`
Expand Down Expand Up @@ -61,9 +61,9 @@ impl<'a> CompressorPass<'a> for EarlyPass {
self.changed
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
self.changed = false;
oxc_traverse::walk_program(self, program, ctx);
traverse_mut_with_ctx(self, program, ctx);
self.changed = self.x0_statement_fusion.changed()
|| self.x1_peephole_remove_dead_code.changed()
|| self.x2_peephole_minimize_conditions.changed()
Expand Down Expand Up @@ -167,9 +167,9 @@ impl<'a> CompressorPass<'a> for LatePass {
self.changed
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
self.changed = false;
oxc_traverse::walk_program(self, program, ctx);
traverse_mut_with_ctx(self, program, ctx);
self.changed = self.x0_exploit_assigns.changed()
|| self.x0_exploit_assigns.changed()
|| self.x1_collapse_variable_declarations.changed()
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use oxc_syntax::{
number::{NumberBase, ToJsString},
operator::{BinaryOperator, LogicalOperator},
};
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};
use oxc_traverse::{traverse_mut_with_ctx, Ancestor, ReusableTraverseCtx, Traverse, TraverseCtx};

use crate::{node_util::Ctx, CompressorPass};

Expand All @@ -24,9 +24,9 @@ impl<'a> CompressorPass<'a> for PeepholeFoldConstants {
self.changed
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
self.changed = false;
oxc_traverse::walk_program(self, program, ctx);
traverse_mut_with_ctx(self, program, ctx);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use oxc_ast::ast::*;
use oxc_ecmascript::ToBoolean;
use oxc_span::SPAN;
use oxc_traverse::{Traverse, TraverseCtx};
use oxc_traverse::{traverse_mut_with_ctx, ReusableTraverseCtx, Traverse, TraverseCtx};

use crate::CompressorPass;

Expand All @@ -21,9 +21,9 @@ impl<'a> CompressorPass<'a> for PeepholeMinimizeConditions {
self.changed
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
self.changed = false;
oxc_traverse::walk_program(self, program, ctx);
traverse_mut_with_ctx(self, program, ctx);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use oxc_allocator::Vec;
use oxc_ast::{ast::*, Visit};
use oxc_ecmascript::constant_evaluation::{ConstantEvaluation, IsLiteralValue};
use oxc_span::SPAN;
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};
use oxc_traverse::{traverse_mut_with_ctx, Ancestor, ReusableTraverseCtx, Traverse, TraverseCtx};

use crate::node_util::Ctx;
use crate::{keep_var::KeepVar, CompressorPass};
Expand All @@ -22,9 +22,9 @@ impl<'a> CompressorPass<'a> for PeepholeRemoveDeadCode {
self.changed
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
self.changed = false;
oxc_traverse::walk_program(self, program, ctx);
traverse_mut_with_ctx(self, program, ctx);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use oxc_ecmascript::{
constant_evaluation::ConstantEvaluation, StringCharAt, StringCharCodeAt, StringIndexOf,
StringLastIndexOf, StringSubstring,
};
use oxc_traverse::{Traverse, TraverseCtx};
use oxc_traverse::{traverse_mut_with_ctx, ReusableTraverseCtx, Traverse, TraverseCtx};

use crate::{node_util::Ctx, CompressorPass};

Expand All @@ -19,9 +19,9 @@ impl<'a> CompressorPass<'a> for PeepholeReplaceKnownMethods {
self.changed
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
self.changed = false;
oxc_traverse::walk_program(self, program, ctx);
traverse_mut_with_ctx(self, program, ctx);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_syntax::{
number::NumberBase,
operator::{BinaryOperator, UnaryOperator},
};
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};
use oxc_traverse::{traverse_mut_with_ctx, Ancestor, ReusableTraverseCtx, Traverse, TraverseCtx};

use crate::{node_util::Ctx, CompressorPass};

Expand All @@ -32,9 +32,9 @@ impl<'a> CompressorPass<'a> for PeepholeSubstituteAlternateSyntax {
self.changed
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
self.changed = false;
oxc_traverse::walk_program(self, program, ctx);
traverse_mut_with_ctx(self, program, ctx);
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_minifier/src/ast_passes/remove_syntax.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use oxc_allocator::Vec;
use oxc_ast::ast::*;
use oxc_span::GetSpan;
use oxc_traverse::{Traverse, TraverseCtx};
use oxc_traverse::{traverse_mut_with_ctx, ReusableTraverseCtx, Traverse, TraverseCtx};

use crate::{CompressOptions, CompressorPass};

Expand All @@ -19,8 +19,8 @@ impl<'a> CompressorPass<'a> for RemoveSyntax {
false
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
oxc_traverse::walk_program(self, program, ctx);
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
traverse_mut_with_ctx(self, program, ctx);
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_minifier/src/ast_passes/statement_fusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use oxc_allocator::Vec;
use oxc_ast::ast::*;
use oxc_ecmascript::side_effects::MayHaveSideEffects;
use oxc_span::SPAN;
use oxc_traverse::{Traverse, TraverseCtx};
use oxc_traverse::{traverse_mut_with_ctx, ReusableTraverseCtx, Traverse, TraverseCtx};

use crate::CompressorPass;

Expand All @@ -20,9 +20,9 @@ impl<'a> CompressorPass<'a> for StatementFusion {
self.changed
}

fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
self.changed = false;
oxc_traverse::walk_program(self, program, ctx);
traverse_mut_with_ctx(self, program, ctx);
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_minifier/src/compressor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use oxc_allocator::Allocator;
use oxc_ast::ast::*;
use oxc_semantic::{ScopeTree, SemanticBuilder, SymbolTable};
use oxc_traverse::TraverseCtx;
use oxc_traverse::ReusableTraverseCtx;

use crate::{
ast_passes::{
Expand Down Expand Up @@ -33,7 +33,7 @@ impl<'a> Compressor<'a> {
scopes: ScopeTree,
program: &mut Program<'a>,
) {
let mut ctx = TraverseCtx::new(scopes, symbols, self.allocator);
let mut ctx = ReusableTraverseCtx::new(scopes, symbols, self.allocator);
RemoveSyntax::new(self.options).build(program, &mut ctx);

if self.options.dead_code_elimination {
Expand Down Expand Up @@ -62,7 +62,7 @@ impl<'a> Compressor<'a> {
LatePass::new().build(program, &mut ctx);
}

fn dead_code_elimination(program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
fn dead_code_elimination(program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
PeepholeFoldConstants::new().build(program, ctx);
PeepholeMinimizeConditions::new().build(program, ctx);
PeepholeRemoveDeadCode::new().build(program, ctx);
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_minifier/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
use oxc_traverse::TraverseCtx;
use oxc_traverse::ReusableTraverseCtx;

use crate::{ast_passes::CompressorPass, ast_passes::RemoveSyntax, CompressOptions};

Expand Down Expand Up @@ -40,7 +40,7 @@ fn run<'a, P: CompressorPass<'a>>(
if let Some(pass) = pass {
let (symbols, scopes) =
SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree();
let mut ctx = TraverseCtx::new(scopes, symbols, allocator);
let mut ctx = ReusableTraverseCtx::new(scopes, symbols, allocator);
RemoveSyntax::new(CompressOptions::all_false()).build(&mut program, &mut ctx);
pass.build(&mut program, &mut ctx);
}
Expand Down
Loading
Loading