diff --git a/tasks/coverage/src/runtime/mod.rs b/tasks/coverage/src/runtime/mod.rs index 222485a2f1351..66a3ef969dd40 100644 --- a/tasks/coverage/src/runtime/mod.rs +++ b/tasks/coverage/src/runtime/mod.rs @@ -18,7 +18,7 @@ use oxc_tasks_common::agent; use crate::{ suite::{Case, TestResult}, - test262::{Test262Case, TestFlag}, + test262::Test262Case, workspace_root, }; @@ -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); @@ -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; @@ -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(); diff --git a/tasks/coverage/src/test262/mod.rs b/tasks/coverage/src/test262/mod.rs index 584a2c78e4677..134912507fa0b 100644 --- a/tasks/coverage/src/test262/mod.rs +++ b/tasks/coverage/src/test262/mod.rs @@ -57,10 +57,6 @@ 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()); @@ -68,12 +64,32 @@ impl Test262Case { 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) } } diff --git a/tasks/coverage/src/tools/codegen.rs b/tasks/coverage/src/tools/codegen.rs index 580653ff61d23..09401e9f0ba77 100644 --- a/tasks/coverage/src/tools/codegen.rs +++ b/tasks/coverage/src/tools/codegen.rs @@ -6,7 +6,7 @@ use crate::{ babel::BabelCase, misc::MiscCase, suite::{Case, TestResult}, - test262::{Test262Case, TestFlag}, + test262::Test262Case, typescript::TypeScriptCase, Driver, }; @@ -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); diff --git a/tasks/coverage/src/tools/minifier.rs b/tasks/coverage/src/tools/minifier.rs index ccdb43fc35f77..0fb4c7624b3cf 100644 --- a/tasks/coverage/src/tools/minifier.rs +++ b/tasks/coverage/src/tools/minifier.rs @@ -5,7 +5,7 @@ use oxc::span::SourceType; use crate::{ babel::BabelCase, suite::{Case, TestResult}, - test262::{Test262Case, TestFlag}, + test262::Test262Case, Driver, }; @@ -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); } diff --git a/tasks/coverage/src/tools/prettier.rs b/tasks/coverage/src/tools/prettier.rs index 36f7ad2f20404..aaf9f1750728c 100644 --- a/tasks/coverage/src/tools/prettier.rs +++ b/tasks/coverage/src/tools/prettier.rs @@ -11,7 +11,7 @@ use crate::{ babel::BabelCase, misc::MiscCase, suite::{Case, TestResult}, - test262::{Test262Case, TestFlag}, + test262::Test262Case, typescript::TypeScriptCase, }; @@ -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); diff --git a/tasks/coverage/src/tools/semantic.rs b/tasks/coverage/src/tools/semantic.rs index 162bfddc88f9c..8ad756ef49305 100644 --- a/tasks/coverage/src/tools/semantic.rs +++ b/tasks/coverage/src/tools/semantic.rs @@ -10,7 +10,7 @@ use crate::{ driver::Driver, misc::MiscCase, suite::{Case, TestResult}, - test262::{Test262Case, TestFlag}, + test262::Test262Case, typescript::TypeScriptCase, }; @@ -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); diff --git a/tasks/coverage/src/tools/transformer.rs b/tasks/coverage/src/tools/transformer.rs index 840f24694083f..ee188bf97408c 100644 --- a/tasks/coverage/src/tools/transformer.rs +++ b/tasks/coverage/src/tools/transformer.rs @@ -10,7 +10,7 @@ use crate::{ driver::Driver, misc::MiscCase, suite::{Case, TestResult}, - test262::{Test262Case, TestFlag}, + test262::Test262Case, typescript::TypeScriptCase, }; @@ -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);