Skip to content
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
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub use crate::{
es2015::{ArrowFunctionsOptions, ES2015Options},
options::BabelOptions,
options::TransformOptions,
react::ReactOptions,
react::{ReactJsxRuntime, ReactOptions},
typescript::TypeScriptOptions,
};

Expand Down
6 changes: 5 additions & 1 deletion crates/oxc_transformer/src/react/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ use oxc_traverse::TraverseCtx;

use crate::context::Ctx;

pub use self::{display_name::ReactDisplayName, jsx::ReactJsx, options::ReactOptions};
pub use self::{
display_name::ReactDisplayName,
jsx::ReactJsx,
options::{ReactJsxRuntime, ReactOptions},
};

/// [Preset React](https://babel.dev/docs/babel-preset-react)
///
Expand Down
40 changes: 28 additions & 12 deletions tasks/coverage/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use oxc_codegen::{Codegen, CodegenOptions};
use oxc_parser::Parser;
use oxc_span::SourceType;
use oxc_transformer::{
ArrowFunctionsOptions, ES2015Options, ReactOptions, TransformOptions, Transformer,
TypeScriptOptions,
ArrowFunctionsOptions, ES2015Options, ReactJsxRuntime, ReactOptions, TransformOptions,
Transformer, TypeScriptOptions,
};

use crate::{
Expand All @@ -17,11 +17,8 @@ use crate::{
typescript::TypeScriptCase,
};

/// Runs the transformer and make sure it doesn't crash.
fn get_result(source_text: &str, source_type: SourceType, source_path: &Path) -> TestResult {
let allocator = Allocator::default();
let filename = source_path.file_name().unwrap().to_string_lossy();
let options = TransformOptions {
fn get_default_transformer_options() -> TransformOptions {
TransformOptions {
typescript: TypeScriptOptions::default(),
es2015: ES2015Options { arrow_function: Some(ArrowFunctionsOptions::default()) },
react: ReactOptions {
Expand All @@ -31,7 +28,19 @@ fn get_result(source_text: &str, source_type: SourceType, source_path: &Path) ->
..Default::default()
},
..Default::default()
};
}
}

/// Runs the transformer and make sure it doesn't crash.
fn get_result(
source_text: &str,
source_type: SourceType,
source_path: &Path,
options: Option<TransformOptions>,
) -> TestResult {
let allocator = Allocator::default();
let filename = source_path.file_name().unwrap().to_string_lossy();
let options = options.unwrap_or_else(get_default_transformer_options);
let parse_result1 = Parser::new(&allocator, source_text, source_type).parse();
let mut program = parse_result1.program;
let _ = Transformer::new(
Expand Down Expand Up @@ -105,7 +114,7 @@ impl Case for TransformerTest262Case {
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 result = get_result(source_text, source_type, self.path());
let result = get_result(source_text, source_type, self.path(), None);
self.base.set_result(result);
}
}
Expand Down Expand Up @@ -138,7 +147,7 @@ impl Case for TransformerBabelCase {
fn run(&mut self) {
let source_text = self.base.code();
let source_type = self.base.source_type();
let result = get_result(source_text, source_type, self.path());
let result = get_result(source_text, source_type, self.path(), None);
self.base.set_result(result);
}
}
Expand Down Expand Up @@ -169,7 +178,14 @@ impl Case for TransformerTypeScriptCase {
}

fn run(&mut self) {
let result = get_result(self.base.code(), self.base.source_type(), self.path());
let mut options = get_default_transformer_options();
let mut source_type = self.base.source_type();
// handle @jsx: react, `react` of behavior is match babel following options
if self.base.meta().options.jsx.last().is_some_and(|jsx| jsx == "react") {
source_type = source_type.with_module(true);
options.react.runtime = ReactJsxRuntime::Classic;
}
let result = get_result(self.base.code(), source_type, self.path(), Some(options));
self.base.set_result(result);
}
}
Expand Down Expand Up @@ -200,7 +216,7 @@ impl Case for TransformerMiscCase {
}

fn run(&mut self) {
let result = get_result(self.base.code(), self.base.source_type(), self.path());
let result = get_result(self.base.code(), self.base.source_type(), self.path(), None);
self.base.set_result(result);
}
}
10 changes: 7 additions & 3 deletions tasks/coverage/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl TypeScriptCase {
pub fn set_result(&mut self, result: TestResult) {
self.result = result;
}

pub fn meta(&self) -> &TypeScriptTestMeta {
&self.meta
}
}

impl Case for TypeScriptCase {
Expand Down Expand Up @@ -133,8 +137,8 @@ impl Case for TypeScriptCase {
}
}

struct TypeScriptTestMeta {
pub tests: Vec<TestUnitData>,
pub struct TypeScriptTestMeta {
pub(self) tests: Vec<TestUnitData>,
pub options: CompilerOptions,
error_files: Vec<String>,
}
Expand Down Expand Up @@ -224,7 +228,7 @@ struct TestUnitData {

#[derive(Debug)]
#[allow(unused)]
struct CompilerOptions {
pub struct CompilerOptions {
pub modules: Vec<String>,
pub targets: Vec<String>,
pub strict: bool,
Expand Down
4 changes: 1 addition & 3 deletions tasks/coverage/transformer_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ commit: 64d2eeea

transformer_typescript Summary:
AST Parsed : 5243/5243 (100.00%)
Positive Passed: 5240/5243 (99.94%)
Positive Passed: 5242/5243 (99.98%)
Mismatch: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts"
Mismatch: "compiler/jsxComplexSignatureHasApplicabilityError.tsx"
Mismatch: "compiler/tsxReactPropsInferenceSucceedsOnIntersections.tsx"