diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index a2fc951d4..7d8617e45 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -32,8 +32,12 @@ use oxc_span::SourceType; use oxc_traverse::{traverse_mut, Traverse, TraverseCtx}; pub use crate::{ - compiler_assumptions::CompilerAssumptions, env::EnvOptions, es2015::ES2015Options, - options::BabelOptions, options::TransformOptions, react::ReactOptions, + compiler_assumptions::CompilerAssumptions, + env::EnvOptions, + es2015::{ArrowFunctionsOptions, ES2015Options}, + options::BabelOptions, + options::TransformOptions, + react::ReactOptions, typescript::TypeScriptOptions, }; diff --git a/tasks/coverage/src/suite.rs b/tasks/coverage/src/suite.rs index fd3824a8d..0acd209bb 100644 --- a/tasks/coverage/src/suite.rs +++ b/tasks/coverage/src/suite.rs @@ -371,6 +371,9 @@ pub trait Case: Sized + Sync + Send + UnwindSafe { writer.write_all(error.as_bytes())?; } TestResult::Mismatch(ast_string, expected_ast_string) => { + writer.write_all( + format!("Mismatch: {:?}\n", normalize_path(self.path())).as_bytes(), + )?; if args.diff { self.print_diff(writer, ast_string.as_str(), expected_ast_string.as_str())?; println!("Mismatch: {:?}", normalize_path(self.path())); diff --git a/tasks/coverage/src/transformer.rs b/tasks/coverage/src/transformer.rs index 029983e57..b9fb4c19d 100644 --- a/tasks/coverage/src/transformer.rs +++ b/tasks/coverage/src/transformer.rs @@ -1,9 +1,13 @@ use std::path::{Path, PathBuf}; use oxc_allocator::Allocator; +use oxc_codegen::{Codegen, CodegenOptions}; use oxc_parser::Parser; use oxc_span::SourceType; -use oxc_transformer::{TransformOptions, Transformer}; +use oxc_transformer::{ + ArrowFunctionsOptions, ES2015Options, ReactOptions, TransformOptions, Transformer, + TypeScriptOptions, +}; use crate::{ babel::BabelCase, @@ -14,16 +18,62 @@ use crate::{ }; /// Runs the transformer and make sure it doesn't crash. -/// TODO: add codegen to turn on idempotency test. fn get_result(source_text: &str, source_type: SourceType, source_path: &Path) -> TestResult { let allocator = Allocator::default(); - let ret = Parser::new(&allocator, source_text, source_type).parse(); - let mut program = ret.program; - let options = TransformOptions::default(); - let _ = - Transformer::new(&allocator, source_path, source_type, source_text, &ret.trivias, options) - .build(&mut program); - TestResult::Passed + let filename = source_path.file_name().unwrap().to_string_lossy(); + let options = TransformOptions { + typescript: TypeScriptOptions::default(), + es2015: ES2015Options { arrow_function: Some(ArrowFunctionsOptions::default()) }, + react: ReactOptions { + jsx_plugin: true, + jsx_self_plugin: true, + jsx_source_plugin: true, + ..Default::default() + }, + ..Default::default() + }; + let parse_result1 = Parser::new(&allocator, source_text, source_type).parse(); + let mut program = parse_result1.program; + let _ = Transformer::new( + &allocator, + source_path, + source_type, + source_text, + &parse_result1.trivias, + options.clone(), + ) + .build(&mut program); + + let source_text1 = + Codegen::::new(&filename, source_text, CodegenOptions::default(), None) + .build(&program) + .source_text; + + let parse_result2 = Parser::new(&allocator, &source_text1, source_type).parse(); + let mut program = parse_result2.program; + + let _ = Transformer::new( + &allocator, + source_path, + source_type, + &source_text1, + &parse_result2.trivias, + options, + ) + .build(&mut program); + + let source_text2 = + Codegen::::new(&filename, &source_text1, CodegenOptions::default(), None) + .build(&program) + .source_text; + + let result = source_text1 == source_text2; + + if result { + TestResult::Passed + } else { + TestResult::Mismatch(source_text1.clone(), source_text2) + } } pub struct TransformerTest262Case { diff --git a/tasks/coverage/transformer_typescript.snap b/tasks/coverage/transformer_typescript.snap index 2e813fa37..12d5fdd93 100644 --- a/tasks/coverage/transformer_typescript.snap +++ b/tasks/coverage/transformer_typescript.snap @@ -2,4 +2,14 @@ commit: 64d2eeea transformer_typescript Summary: AST Parsed : 5243/5243 (100.00%) -Positive Passed: 5243/5243 (100.00%) +Positive Passed: 5233/5243 (99.81%) +Mismatch: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts" +Mismatch: "compiler/jsxComplexSignatureHasApplicabilityError.tsx" +Mismatch: "compiler/jsxEmptyExpressionNotCountedAsChild.tsx" +Mismatch: "compiler/sourceMapValidationClasses.ts" +Mismatch: "compiler/styledComponentsInstantiaionLimitNotReached.ts" +Mismatch: "compiler/tsxReactPropsInferenceSucceedsOnIntersections.tsx" +Mismatch: "compiler/typeAliasDeclarationEmit3.ts" +Mismatch: "conformance/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCall.ts" +Mismatch: "conformance/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCallWithDefineFields.ts" +Mismatch: "conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.11.ts"