Skip to content

Commit

Permalink
chore(tasks/coverage): do not run minifier in script mode (#8213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jan 1, 2025
1 parent 05be1fc commit cd349a3
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 22 deletions.
18 changes: 12 additions & 6 deletions tasks/coverage/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use oxc_tasks_common::agent;

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

Expand Down Expand Up @@ -153,6 +153,12 @@ impl Case for Test262RuntimeCase {
return;
}

// Unable to minify `script`, which may contain syntaxes that the minifier do not support (e.g. `with`).
if !self.base.is_module() {
self.base.set_result(TestResult::Passed);
return;
}

let code = self.get_code(false, true);
let result = self.run_test_code("minify", code).await;
self.base.set_result(result);
Expand All @@ -162,8 +168,8 @@ impl Case for Test262RuntimeCase {
impl Test262RuntimeCase {
fn get_code(&self, transform: bool, minify: bool) -> String {
let source_text = self.base.code();
let is_module = self.base.meta().flags.contains(&TestFlag::Module);
let is_only_strict = self.base.meta().flags.contains(&TestFlag::OnlyStrict);
let is_module = self.base.is_module();
let is_only_strict = self.base.is_only_strict();
let source_type = SourceType::cjs().with_module(is_module);
let allocator = Allocator::default();
let mut program = Parser::new(&allocator, source_text, source_type).parse().program;
Expand Down Expand Up @@ -205,9 +211,9 @@ impl Test262RuntimeCase {
}

async fn run_test_code(&self, case: &'static str, code: String) -> TestResult {
let is_async = self.base.meta().flags.contains(&TestFlag::Async);
let is_module = self.base.meta().flags.contains(&TestFlag::Module);
let is_raw = self.base.meta().flags.contains(&TestFlag::Raw);
let is_async = self.base.is_async();
let is_module = self.base.is_module();
let is_raw = self.base.is_raw();
let import_dir =
self.test_root.join(self.base.path().parent().unwrap()).to_string_lossy().to_string();

Expand Down
28 changes: 22 additions & 6 deletions tasks/coverage/src/test262/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,39 @@ pub struct Test262Case {
}

impl Test262Case {
pub fn meta(&self) -> &MetaData {
&self.meta
}

/// # Panics
pub fn read_metadata(code: &str) -> MetaData {
let (start, end) = (code.find("/*---").unwrap(), code.find("---*/").unwrap());
let s = &code[start + 5..end].replace('\r', "\n");
MetaData::from_str(s)
}

fn compute_should_fail(meta: &MetaData) -> bool {
meta.negative.as_ref().filter(|n| n.phase == Phase::Parse).is_some()
}

pub fn set_result(&mut self, result: TestResult) {
self.result = result;
}

fn compute_should_fail(meta: &MetaData) -> bool {
meta.negative.as_ref().filter(|n| n.phase == Phase::Parse).is_some()
pub fn meta(&self) -> &MetaData {
&self.meta
}

pub fn is_module(&self) -> bool {
self.meta.flags.contains(&TestFlag::Module)
}

pub fn is_only_strict(&self) -> bool {
self.meta.flags.contains(&TestFlag::OnlyStrict)
}

pub fn is_raw(&self) -> bool {
self.meta.flags.contains(&TestFlag::Raw)
}

pub fn is_async(&self) -> bool {
self.meta.flags.contains(&TestFlag::Async)
}
}

Expand Down
4 changes: 2 additions & 2 deletions tasks/coverage/src/tools/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
babel::BabelCase,
misc::MiscCase,
suite::{Case, TestResult},
test262::{Test262Case, TestFlag},
test262::Test262Case,
typescript::TypeScriptCase,
Driver,
};
Expand Down Expand Up @@ -58,7 +58,7 @@ impl Case for CodegenTest262Case {

fn run(&mut self) {
let source_text = self.base.code();
let is_module = self.base.meta().flags.contains(&TestFlag::Module);
let is_module = self.base.is_module();
let source_type = SourceType::default().with_module(is_module);
let result = get_result(source_text, source_type);
self.base.set_result(result);
Expand Down
9 changes: 7 additions & 2 deletions tasks/coverage/src/tools/minifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use oxc::span::SourceType;
use crate::{
babel::BabelCase,
suite::{Case, TestResult},
test262::{Test262Case, TestFlag},
test262::Test262Case,
Driver,
};

Expand Down Expand Up @@ -45,8 +45,13 @@ impl Case for MinifierTest262Case {

fn run(&mut self) {
let source_text = self.base.code();
let is_module = self.base.meta().flags.contains(&TestFlag::Module);
let is_module = self.base.is_module();
let source_type = SourceType::default().with_module(is_module);
// Unable to minify `script`, which may contain syntaxes that the minifier do not support (e.g. `with`).
if source_type.is_script() {
self.base.set_result(TestResult::Passed);
return;
}
let result = get_result(source_text, source_type);
self.base.set_result(result);
}
Expand Down
4 changes: 2 additions & 2 deletions tasks/coverage/src/tools/prettier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
babel::BabelCase,
misc::MiscCase,
suite::{Case, TestResult},
test262::{Test262Case, TestFlag},
test262::Test262Case,
typescript::TypeScriptCase,
};

Expand Down Expand Up @@ -64,7 +64,7 @@ impl Case for PrettierTest262Case {

fn run(&mut self) {
let source_text = self.base.code();
let is_module = self.base.meta().flags.contains(&TestFlag::Module);
let is_module = self.base.is_module();
let source_type = SourceType::default().with_module(is_module);
let result = get_result(source_text, source_type);
self.base.set_result(result);
Expand Down
4 changes: 2 additions & 2 deletions tasks/coverage/src/tools/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
driver::Driver,
misc::MiscCase,
suite::{Case, TestResult},
test262::{Test262Case, TestFlag},
test262::Test262Case,
typescript::TypeScriptCase,
};

Expand Down Expand Up @@ -77,7 +77,7 @@ impl Case for SemanticTest262Case {

fn run(&mut self) {
let source_text = self.base.code();
let is_module = self.base.meta().flags.contains(&TestFlag::Module);
let is_module = self.base.is_module();
let source_type = SourceType::default().with_module(is_module);
let result = get_result(source_text, source_type, self.path(), None);
self.base.set_result(result);
Expand Down
4 changes: 2 additions & 2 deletions tasks/coverage/src/tools/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
driver::Driver,
misc::MiscCase,
suite::{Case, TestResult},
test262::{Test262Case, TestFlag},
test262::Test262Case,
typescript::TypeScriptCase,
};

Expand Down Expand Up @@ -82,7 +82,7 @@ impl Case for TransformerTest262Case {

fn run(&mut self) {
let source_text = self.base.code();
let is_module = self.base.meta().flags.contains(&TestFlag::Module);
let is_module = self.base.is_module();
let source_type = SourceType::default().with_module(is_module);
let result = get_result(source_text, source_type, self.path(), None);
self.base.set_result(result);
Expand Down

0 comments on commit cd349a3

Please sign in to comment.