Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: oxc-project/oxc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b5e1fb0e0feb8b5af0992180d76fa9f29098c4ff
Choose a base ref
..
head repository: oxc-project/oxc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 934c75c7f06312aa7a8f23cb9d2da9043b56f402
Choose a head ref
Showing with 94 additions and 6 deletions.
  1. +5 −2 crates/oxc_minifier/src/ast_passes/peephole_minimize_conditions.rs
  2. +85 −0 tasks/coverage/src/tools/esbuild.rs
  3. +4 −4 tasks/minsize/minsize.snap
Original file line number Diff line number Diff line change
@@ -233,6 +233,7 @@ impl<'a> PeepholeMinimizeConditions {

if next_node.as_ref().is_some_and(|s| matches!(s, Statement::IfStatement(_)))
&& else_branch.is_none()
&& Self::statement_must_exit_parent(then_branch)
{
let next_node = next_node.unwrap();
// `if (x) return; if (y) return;` -> `if (x || y) return;`
@@ -1004,8 +1005,10 @@ mod test {
#[test]
#[ignore]
fn test_combine_ifs2() {
// combinable but not yet done
fold_same("function f() {if (x) throw 1; if (y) throw 1}");
fold(
"function f() {if (x) throw 1; if (y) throw 1}",
"function f() {if (x || y) throw 1;}",
);
// Can't combine, side-effect
fold("function f(){ if (x) g(); if (y) g() }", "function f(){ x&&g(); y&&g() }");
fold("function f(){ if (x) g?.(); if (y) g?.() }", "function f(){ x&&g?.(); y&&g?.() }");
85 changes: 85 additions & 0 deletions tasks/coverage/src/tools/esbuild.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use std::path::{Path, PathBuf};
use std::process::Command;

use oxc::span::SourceType;
use similar_asserts::SimpleDiff;

use crate::workspace_root;
use crate::{
suite::{Case, TestResult},
test262::{Test262Case, TestFlag},
Driver,
};

pub struct EsbuildTest262Case {
base: Test262Case,
workspace_root: PathBuf,
}

impl Case for EsbuildTest262Case {
fn new(path: PathBuf, code: String) -> Self {
Self { base: Test262Case::new(path, code), workspace_root: workspace_root() }
}

fn code(&self) -> &str {
self.base.code()
}

fn path(&self) -> &Path {
self.base.path()
}

fn test_result(&self) -> &TestResult {
self.base.test_result()
}

fn skip_test_case(&self) -> bool {
self.base.should_fail() || self.base.skip_test_case()
}

fn run(&mut self) {
let source_text = self.base.code();
let is_module = self.base.meta().flags.contains(&TestFlag::Module);
let source_type = SourceType::default().with_module(is_module);

let mut driver =
Driver { compress: true, codegen: true, remove_whitespace: true, ..Driver::default() };
driver.run(source_text, source_type);
let oxc = driver.printed;

if oxc.is_empty() {
self.base.set_result(TestResult::Passed);
return;
}

let path = self.workspace_root.join(self.path());
let esbuild = Command::new("esbuild")
.arg("--minify-whitespace=true")
.arg("--minify-syntax=true")
.arg("--keep-names")
.arg(&path)
.output()
.unwrap();

if !esbuild.stderr.is_empty() {
self.base.set_result(TestResult::Passed);
return;
}
let esbuild = String::from_utf8(esbuild.stdout).unwrap();

let esbuild_len = esbuild.len();
let oxc_len = oxc.len();

if esbuild_len >= oxc_len {
self.base.set_result(TestResult::Passed);
return;
}

let diff = oxc_len - esbuild_len;

println!("\n{} {diff}\n", self.base.path().to_string_lossy());
println!("\n{}\n", SimpleDiff::from_str(&oxc, &esbuild, "oxc", "esbuild"));

self.base.set_result(TestResult::GenericError(">> ", format!("{diff}")));
}
}
8 changes: 4 additions & 4 deletions tasks/minsize/minsize.snap
Original file line number Diff line number Diff line change
@@ -11,17 +11,17 @@ Original | minified | minified | gzip | gzip | Fixture

544.10 kB | 71.76 kB | 72.48 kB | 26.15 kB | 26.20 kB | lodash.js

555.77 kB | 273.13 kB | 270.13 kB | 90.91 kB | 90.80 kB | d3.js
555.77 kB | 273.14 kB | 270.13 kB | 90.91 kB | 90.80 kB | d3.js

1.01 MB | 459.56 kB | 458.89 kB | 126.74 kB | 126.71 kB | bundle.min.js
1.01 MB | 459.65 kB | 458.89 kB | 126.75 kB | 126.71 kB | bundle.min.js

1.25 MB | 652.73 kB | 646.76 kB | 163.55 kB | 163.73 kB | three.js

2.14 MB | 725.59 kB | 724.14 kB | 180.09 kB | 181.07 kB | victory.js
2.14 MB | 725.66 kB | 724.14 kB | 180.08 kB | 181.07 kB | victory.js

3.20 MB | 1.01 MB | 1.01 MB | 331.78 kB | 331.56 kB | echarts.js

6.69 MB | 2.32 MB | 2.31 MB | 492.62 kB | 488.28 kB | antd.js
6.69 MB | 2.32 MB | 2.31 MB | 492.61 kB | 488.28 kB | antd.js

10.95 MB | 3.49 MB | 3.49 MB | 907.29 kB | 915.50 kB | typescript.js