diff --git a/crates/oxc_transformer/examples/transformer.rs b/crates/oxc_transformer/examples/transformer.rs index 0412ff0260498..13126ff2ccb62 100644 --- a/crates/oxc_transformer/examples/transformer.rs +++ b/crates/oxc_transformer/examples/transformer.rs @@ -24,11 +24,11 @@ fn main() { let ret = Parser::new(&allocator, &source_text, source_type).parse(); if !ret.errors.is_empty() { + println!("Parser Errors:"); for error in ret.errors { let error = error.with_source_code(source_text.clone()); println!("{error:?}"); } - return; } println!("Original:\n"); @@ -46,7 +46,7 @@ fn main() { }, ..Default::default() }; - Transformer::new( + let _ = Transformer::new( &allocator, path, source_type, @@ -54,8 +54,7 @@ fn main() { ret.trivias.clone(), transform_options, ) - .build(&mut program) - .unwrap(); + .build(&mut program); let printed = Codegen::::new("", &source_text, ret.trivias, CodegenOptions::default()) .build(&program) diff --git a/tasks/coverage/src/transformer.rs b/tasks/coverage/src/transformer.rs index fdb76b19f0fd7..b5c97d58583b9 100644 --- a/tasks/coverage/src/transformer.rs +++ b/tasks/coverage/src/transformer.rs @@ -17,7 +17,7 @@ use crate::{ typescript::TypeScriptCase, }; -/// Runs the transformer and make sure it doesn't crash. +/// Idempotency test fn get_result( source_text: &str, source_type: SourceType, @@ -27,76 +27,51 @@ fn get_result( 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 transform_result1 = Transformer::new( - &allocator, - source_path, - source_type, - source_text, - parse_result1.trivias.clone(), - options.clone(), - ) - .build(&mut program); - - let ts_source_text1 = Codegen::::new( - &filename, - source_text, - parse_result1.trivias.clone(), - CodegenOptions::default(), - ) - .build(&program) - .source_text; - - let source_text1 = Codegen::::new( - &filename, - source_text, - parse_result1.trivias.clone(), - CodegenOptions::default(), - ) - .build(&program) - .source_text; - - if transform_result1.is_ok() && ts_source_text1 != source_text1 { - return TestResult::Mismatch(ts_source_text1.clone(), source_text1.clone()); - } - - let parse_result2 = Parser::new(&allocator, &ts_source_text1, source_type).parse(); - let mut program = parse_result2.program; - - let transform_result2 = Transformer::new( - &allocator, - source_path, - source_type, - &source_text1, - parse_result2.trivias.clone(), - options, - ) - .build(&mut program); - - let source_text2 = Codegen::::new( - &filename, - &source_text1, - parse_result2.trivias, - CodegenOptions::default(), - ) - .build(&program) - .source_text; - - if source_text1 == source_text2 - || transform_result1.is_err_and(|err| { - // If error messages are the same, we consider it as a pass. - transform_result2 - .map_err(|err| err.iter().map(ToString::to_string).collect::>().join("\n")) - .is_err_and(|err_message| { - err.iter().map(ToString::to_string).collect::>().join("\n") - == err_message - }) - }) - { + + // First pass + let transformed1 = { + let mut ret1 = Parser::new(&allocator, source_text, source_type).parse(); + let _ = Transformer::new( + &allocator, + source_path, + source_type, + source_text, + ret1.trivias.clone(), + options.clone(), + ) + .build(&mut ret1.program); + Codegen::::new( + &filename, + source_text, + ret1.trivias.clone(), + CodegenOptions::default(), + ) + .build(&ret1.program) + .source_text + }; + + // Second pass with only JavaScript parsing + let transformed2 = { + let source_type = SourceType::default().with_module(source_type.is_module()); + let mut ret2 = Parser::new(&allocator, &transformed1, source_type).parse(); + let _ = Transformer::new( + &allocator, + source_path, + source_type, + &transformed1, + ret2.trivias.clone(), + options, + ) + .build(&mut ret2.program); + Codegen::::new(&filename, source_text, ret2.trivias, CodegenOptions::default()) + .build(&ret2.program) + .source_text + }; + + if transformed1 == transformed2 { TestResult::Passed } else { - TestResult::Mismatch(source_text1.clone(), source_text2) + TestResult::Mismatch(transformed1, transformed2) } } diff --git a/tasks/coverage/transformer_babel.snap b/tasks/coverage/transformer_babel.snap index cc33537346a44..6ddf3e86ec88c 100644 --- a/tasks/coverage/transformer_babel.snap +++ b/tasks/coverage/transformer_babel.snap @@ -2,4 +2,5 @@ commit: 12619ffe transformer_babel Summary: AST Parsed : 2101/2101 (100.00%) -Positive Passed: 2101/2101 (100.00%) +Positive Passed: 2100/2101 (99.95%) +Mismatch: "typescript/class/accessor/input.ts" diff --git a/tasks/coverage/transformer_typescript.snap b/tasks/coverage/transformer_typescript.snap index 1854ec204b948..268234062061b 100644 --- a/tasks/coverage/transformer_typescript.snap +++ b/tasks/coverage/transformer_typescript.snap @@ -2,5 +2,19 @@ commit: d8086f14 transformer_typescript Summary: AST Parsed : 5283/5283 (100.00%) -Positive Passed: 5282/5283 (99.98%) +Positive Passed: 5268/5283 (99.72%) Mismatch: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts" +Mismatch: "compiler/esDecoratorsClassFieldsCrash.ts" +Mismatch: "compiler/useBeforeDeclaration_classDecorators.2.ts" +Mismatch: "conformance/classes/propertyMemberDeclarations/autoAccessor10.ts" +Mismatch: "conformance/classes/propertyMemberDeclarations/autoAccessor2.ts" +Mismatch: "conformance/classes/propertyMemberDeclarations/autoAccessor9.ts" +Mismatch: "conformance/classes/propertyMemberDeclarations/autoAccessorAllowedModifiers.ts" +Mismatch: "conformance/classes/propertyMemberDeclarations/staticAutoAccessors.ts" +Mismatch: "conformance/classes/propertyMemberDeclarations/staticAutoAccessorsWithDecorators.ts" +Mismatch: "conformance/decorators/legacyDecorators-contextualTypes.ts" +Mismatch: "conformance/esDecorators/classDeclaration/classThisReference/esDecorators-classDeclaration-classThisReference.ts" +Mismatch: "conformance/esDecorators/classDeclaration/fields/esDecorators-classDeclaration-fields-staticAccessor.ts" +Mismatch: "conformance/esDecorators/classDeclaration/fields/esDecorators-classDeclaration-fields-staticPrivateAccessor.ts" +Mismatch: "conformance/esDecorators/classExpression/esDecorators-classExpression-commentPreservation.ts" +Mismatch: "conformance/esDecorators/esDecorators-contextualTypes.ts"