From 3e3bacfbb27f836aa0aad07a89a5666f4b892777 Mon Sep 17 00:00:00 2001 From: Toshit Chawda Date: Sun, 27 Oct 2024 13:37:03 -0700 Subject: [PATCH] nuke oxc crates --- rewriter/Cargo.lock | 86 +++++++++++++++++++---------------------- rewriter/Cargo.toml | 7 +--- rewriter/src/lib.rs | 2 +- rewriter/src/rewrite.rs | 62 +++++++++++++++-------------- 4 files changed, 76 insertions(+), 81 deletions(-) diff --git a/rewriter/Cargo.lock b/rewriter/Cargo.lock index 2b78e65..9ac6b26 100644 --- a/rewriter/Cargo.lock +++ b/rewriter/Cargo.lock @@ -43,9 +43,6 @@ name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -dependencies = [ - "serde", -] [[package]] name = "boa_ast" @@ -246,7 +243,6 @@ dependencies = [ "itoa", "rustversion", "ryu", - "serde", "static_assertions", ] @@ -716,21 +712,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb37767f6569cd834a413442455e0f066d0d522de8630436e2a1761d9726ba56" [[package]] -name = "oxc_allocator" -version = "0.32.0" +name = "oxc" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40baa80a3e4ae7cea94c1e04dc8820162b934f5f5cbca8a96e80a0b85a2815f4" +checksum = "7e6f17bb1b7da4e269e7f89153b0ea5b928856bde083b05de34f8a073a5ceb6f" +dependencies = [ + "oxc_allocator", + "oxc_ast", + "oxc_diagnostics", + "oxc_index", + "oxc_parser", + "oxc_regular_expression", + "oxc_span", + "oxc_syntax", +] + +[[package]] +name = "oxc_allocator" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5c86018e4c158687698514494cb02b48b0367fd63e463c7b3846e565df53f46" dependencies = [ "allocator-api2", "bumpalo", - "serde", ] [[package]] name = "oxc_ast" -version = "0.32.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7eb50a1c3485609b4b2051bd23352c1e6a8743b9e345dd6def70b3470948429" +checksum = "761ab257d19f07de7f91bab40fd7b232e6e0c68164b9086434f416e960f28149" dependencies = [ "bitflags", "num-bigint", @@ -740,16 +751,13 @@ dependencies = [ "oxc_regular_expression", "oxc_span", "oxc_syntax", - "serde", - "serde_json", - "wasm-bindgen", ] [[package]] name = "oxc_ast_macros" -version = "0.32.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4b29106d9f2bbcca4f5ee7a9325c99844ff9721d10103625cd5278795507fe" +checksum = "a58d52ec144ec10c6c890a5356f7859510aa37e3e2839abd91e419969628302e" dependencies = [ "proc-macro2", "quote", @@ -758,9 +766,9 @@ dependencies = [ [[package]] name = "oxc_diagnostics" -version = "0.32.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2e7c7ff14a1a80cb229593d9fcfae6660c7b2cda8707caa4a89cb489656d156" +checksum = "980c673834c9b2fa15eb2692d418df45c84294771fd364ab53f9abdf4d3e874b" dependencies = [ "miette", "owo-colors", @@ -771,9 +779,9 @@ dependencies = [ [[package]] name = "oxc_ecmascript" -version = "0.32.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17d5cf1710748afcda1269998d2003af79df1fef7c5b4183054aeb1b2a803ff6" +checksum = "20243d6de6301a5265c85d9d8007bf3044be5311906ba1686570de67743904a3" dependencies = [ "num-bigint", "num-traits", @@ -784,24 +792,21 @@ dependencies = [ [[package]] name = "oxc_estree" -version = "0.32.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "befa5f762524cdd768fee0321c4f19ee24e13e7340ca2a64629183a37875ba71" +checksum = "7c30428989d3af8c8d868ec5fdd3e227865bbf7bc875e47785de368968282234" [[package]] name = "oxc_index" -version = "0.32.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a576b0f0a1ef9112504880a3ba82fa895c4cceb52cdc37825180c43b01336f" -dependencies = [ - "serde", -] +checksum = "2c33b9c780ed9ea47548248450b04da65b1e4e8023157403c37407a3210b675a" [[package]] name = "oxc_parser" -version = "0.32.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43e722cd698a1ac383b645ddf6283757d4977b56f6dc278038b9ea74867a508" +checksum = "22251ed2d64a743481450f64e5d279193165b637dc3dce6f5eaa3eeb494d470b" dependencies = [ "assert-unchecked", "bitflags", @@ -822,9 +827,9 @@ dependencies = [ [[package]] name = "oxc_regular_expression" -version = "0.32.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "231ed7fd6173c41270e019c4d1b2cd4bfa463a8abba32e0107bed6a7e9ceca93" +checksum = "fbd944dbd4a2b479bda4e29472e1489bb3abd9efbf8a84397fbe3259944b39b4" dependencies = [ "oxc_allocator", "oxc_ast_macros", @@ -833,31 +838,27 @@ dependencies = [ "oxc_span", "phf", "rustc-hash", - "serde", "unicode-id-start", - "wasm-bindgen", ] [[package]] name = "oxc_span" -version = "0.32.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "734602328c49aa8c31840e72662196ca1b0d7bf3585eca1f9ddbef127172112f" +checksum = "74ea8734bdf818608fe5b92322ef1ad56c56896d83052b5d477f0197d09e7f15" dependencies = [ "compact_str", "miette", "oxc_allocator", "oxc_ast_macros", "oxc_estree", - "serde", - "wasm-bindgen", ] [[package]] name = "oxc_syntax" -version = "0.32.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a56d62a59f4ace25365c1d056d7ce3129ca3fb20e9337b19a0efe62d6bc84cb" +checksum = "14ecf5a5134b738088f1a56fbae78aa4e478b07f27b5f4db3c07734e0c9e005a" dependencies = [ "assert-unchecked", "bitflags", @@ -871,9 +872,7 @@ dependencies = [ "phf", "rustc-hash", "ryu-js", - "serde", "unicode-id-start", - "wasm-bindgen", ] [[package]] @@ -1056,12 +1055,7 @@ dependencies = [ "instant", "js-sys", "obfstr", - "oxc_allocator", - "oxc_ast", - "oxc_diagnostics", - "oxc_parser", - "oxc_span", - "oxc_syntax", + "oxc", "rand", "serde", "serde-wasm-bindgen", diff --git a/rewriter/Cargo.toml b/rewriter/Cargo.toml index 75ade9e..b824c8d 100644 --- a/rewriter/Cargo.toml +++ b/rewriter/Cargo.toml @@ -28,12 +28,7 @@ getrandom = { version = "0.2.15", features = ["js"] } instant = { version = "0.1.13", features = ["wasm-bindgen"] } js-sys = "0.3.69" obfstr = "0.4.3" -oxc_allocator = "0.32.0" -oxc_ast = { version = "0.32.0", features = ["serialize"]} -oxc_diagnostics = "0.32.0" -oxc_parser = "0.32.0" -oxc_span = "0.32.0" -oxc_syntax = "0.32.0" +oxc = "0.34.0" rand = "0.8.5" serde = "1.0.204" serde-wasm-bindgen = "0.6.5" diff --git a/rewriter/src/lib.rs b/rewriter/src/lib.rs index da833ec..e617bc5 100644 --- a/rewriter/src/lib.rs +++ b/rewriter/src/lib.rs @@ -6,7 +6,7 @@ use std::{panic, str::FromStr, sync::Arc, time::Duration}; use error::{Result, RewriterError}; use instant::Instant; use js_sys::{Function, Object, Reflect}; -use oxc_diagnostics::{NamedSource, OxcDiagnostic}; +use oxc::diagnostics::{NamedSource, OxcDiagnostic}; use rewrite::{rewrite, Config, EncodeFn}; use url::Url; use wasm_bindgen::prelude::*; diff --git a/rewriter/src/rewrite.rs b/rewriter/src/rewrite.rs index d32288d..92d817a 100644 --- a/rewriter/src/rewrite.rs +++ b/rewriter/src/rewrite.rs @@ -1,18 +1,24 @@ use core::str; use std::str::from_utf8; -use oxc_allocator::Allocator; -use oxc_ast::{ +use oxc::{ + allocator::Allocator, ast::{ - AssignmentTarget, Expression, IdentifierReference, MemberExpression, ObjectPropertyKind, + ast::{ + AssignmentExpression, AssignmentTarget, CallExpression, DebuggerStatement, + ExportAllDeclaration, ExportNamedDeclaration, Expression, ForInStatement, + ForOfStatement, FunctionBody, IdentifierReference, ImportDeclaration, ImportExpression, + MemberExpression, MetaProperty, NewExpression, ObjectExpression, ObjectPropertyKind, + ReturnStatement, ThisExpression, UnaryExpression, UpdateExpression, + }, + visit::walk, + Visit, }, - visit::walk, - Visit, + diagnostics::OxcDiagnostic, + parser::Parser, + span::{Atom, GetSpan, SourceType, Span}, + syntax::operator::{AssignmentOperator, UnaryOperator}, }; -use oxc_diagnostics::OxcDiagnostic; -use oxc_parser::Parser; -use oxc_span::{Atom, GetSpan, SourceType, Span}; -use oxc_syntax::operator::{AssignmentOperator, UnaryOperator}; use url::Url; use crate::error::{Result, RewriterError}; @@ -116,11 +122,11 @@ impl<'a> Visit<'a> for Rewriter { } // we need to rewrite `new Something` to `new (wrapfn(Something))` instead of `new wrapfn(Something)`, that's why there's weird extra code here - fn visit_new_expression(&mut self, it: &oxc_ast::ast::NewExpression<'a>) { + fn visit_new_expression(&mut self, it: &NewExpression<'a>) { self.walk_member_expression(&it.callee); walk::walk_arguments(self, &it.arguments); } - fn visit_member_expression(&mut self, it: &oxc_ast::ast::MemberExpression<'a>) { + fn visit_member_expression(&mut self, it: &MemberExpression<'a>) { match it { MemberExpression::StaticMemberExpression(s) => { if s.property.name == "postMessage" { @@ -170,14 +176,14 @@ impl<'a> Visit<'a> for Rewriter { walk::walk_member_expression(self, it); } - fn visit_this_expression(&mut self, it: &oxc_ast::ast::ThisExpression) { + fn visit_this_expression(&mut self, it: &ThisExpression) { self.jschanges.push(JsChange::GenericChange { span: it.span, text: format!("{}(this)", self.config.wrapthisfn), }); } - fn visit_debugger_statement(&mut self, it: &oxc_ast::ast::DebuggerStatement) { + fn visit_debugger_statement(&mut self, it: &DebuggerStatement) { // delete debugger statements entirely. some sites will spam debugger as an anti-debugging measure, and we don't want that! self.jschanges.push(JsChange::GenericChange { span: it.span, @@ -187,7 +193,7 @@ impl<'a> Visit<'a> for Rewriter { // we can't overwrite window.eval in the normal way because that would make everything an // indirect eval, which could break things. we handle that edge case here - fn visit_call_expression(&mut self, it: &oxc_ast::ast::CallExpression<'a>) { + fn visit_call_expression(&mut self, it: &CallExpression<'a>) { if let Expression::Identifier(s) = &it.callee { // if it's optional that actually makes it an indirect eval which is handled separately if s.name == "eval" && !it.optional { @@ -219,7 +225,7 @@ impl<'a> Visit<'a> for Rewriter { walk::walk_call_expression(self, it); } - fn visit_import_declaration(&mut self, it: &oxc_ast::ast::ImportDeclaration<'a>) { + fn visit_import_declaration(&mut self, it: &ImportDeclaration<'a>) { let name = it.source.value.to_string(); let text = self.rewrite_url(name); self.jschanges.push(JsChange::GenericChange { @@ -228,7 +234,7 @@ impl<'a> Visit<'a> for Rewriter { }); walk::walk_import_declaration(self, it); } - fn visit_import_expression(&mut self, it: &oxc_ast::ast::ImportExpression<'a>) { + fn visit_import_expression(&mut self, it: &ImportExpression<'a>) { self.jschanges.push(JsChange::GenericChange { span: Span::new(it.span.start, it.span.start + 6), text: format!("({}(\"{}\"))", self.config.importfn, self.base), @@ -236,7 +242,7 @@ impl<'a> Visit<'a> for Rewriter { walk::walk_import_expression(self, it); } - fn visit_export_all_declaration(&mut self, it: &oxc_ast::ast::ExportAllDeclaration<'a>) { + fn visit_export_all_declaration(&mut self, it: &ExportAllDeclaration<'a>) { let name = it.source.value.to_string(); let text = self.rewrite_url(name); self.jschanges.push(JsChange::GenericChange { @@ -245,7 +251,7 @@ impl<'a> Visit<'a> for Rewriter { }); } - fn visit_export_named_declaration(&mut self, it: &oxc_ast::ast::ExportNamedDeclaration<'a>) { + fn visit_export_named_declaration(&mut self, it: &ExportNamedDeclaration<'a>) { if let Some(source) = &it.source { let name = source.value.to_string(); let text = self.rewrite_url(name); @@ -258,7 +264,7 @@ impl<'a> Visit<'a> for Rewriter { } #[cfg(feature = "debug")] - fn visit_try_statement(&mut self, it: &oxc_ast::ast::TryStatement<'a>) { + fn visit_try_statement(&mut self, it: &oxc::ast::ast::TryStatement<'a>) { // for debugging we need to know what the error was if self.config.capture_errors { @@ -276,7 +282,7 @@ impl<'a> Visit<'a> for Rewriter { walk::walk_try_statement(self, it); } - fn visit_object_expression(&mut self, it: &oxc_ast::ast::ObjectExpression<'a>) { + fn visit_object_expression(&mut self, it: &ObjectExpression<'a>) { for prop in &it.properties { #[allow(clippy::single_match)] match prop { @@ -299,7 +305,7 @@ impl<'a> Visit<'a> for Rewriter { walk::walk_object_expression(self, it); } - fn visit_function_body(&mut self, it: &oxc_ast::ast::FunctionBody<'a>) { + fn visit_function_body(&mut self, it: &FunctionBody<'a>) { // tag function for use in sourcemaps if self.config.do_sourcemaps { self.jschanges.push(JsChange::SourceTag { @@ -309,7 +315,7 @@ impl<'a> Visit<'a> for Rewriter { walk::walk_function_body(self, it); } - fn visit_return_statement(&mut self, it: &oxc_ast::ast::ReturnStatement<'a>) { + fn visit_return_statement(&mut self, it: &ReturnStatement<'a>) { // if let Some(arg) = &it.argument { // self.jschanges.push(JsChange::GenericChange { // span: Span::new(it.span.start + 6, it.span.start + 6), @@ -323,7 +329,7 @@ impl<'a> Visit<'a> for Rewriter { walk::walk_return_statement(self, it); } - fn visit_unary_expression(&mut self, it: &oxc_ast::ast::UnaryExpression<'a>) { + fn visit_unary_expression(&mut self, it: &UnaryExpression<'a>) { if matches!(it.operator, UnaryOperator::Typeof) { // don't walk to identifier rewrites since it won't matter return; @@ -332,18 +338,18 @@ impl<'a> Visit<'a> for Rewriter { } // we don't want to rewrite the identifiers here because of a very specific edge case - fn visit_for_in_statement(&mut self, it: &oxc_ast::ast::ForInStatement<'a>) { + fn visit_for_in_statement(&mut self, it: &ForInStatement<'a>) { walk::walk_statement(self, &it.body); } - fn visit_for_of_statement(&mut self, it: &oxc_ast::ast::ForOfStatement<'a>) { + fn visit_for_of_statement(&mut self, it: &ForOfStatement<'a>) { walk::walk_statement(self, &it.body); } - fn visit_update_expression(&mut self, _it: &oxc_ast::ast::UpdateExpression<'a>) { + fn visit_update_expression(&mut self, _it: &UpdateExpression<'a>) { // then no, don't walk it, we don't care } - fn visit_meta_property(&mut self, it: &oxc_ast::ast::MetaProperty<'a>) { + fn visit_meta_property(&mut self, it: &MetaProperty<'a>) { if it.meta.name == "import" { self.jschanges.push(JsChange::GenericChange { span: it.span, @@ -352,7 +358,7 @@ impl<'a> Visit<'a> for Rewriter { } } - fn visit_assignment_expression(&mut self, it: &oxc_ast::ast::AssignmentExpression<'a>) { + fn visit_assignment_expression(&mut self, it: &AssignmentExpression<'a>) { #[allow(clippy::single_match)] match &it.left { AssignmentTarget::AssignmentTargetIdentifier(s) => {