Skip to content

Commit

Permalink
feat(coverage): second transformer build does not print typescript (#…
Browse files Browse the repository at this point in the history
…3561)

Currently, we lack a test to check if the TS AST has been completely deleted. I have thought of a way to test it. Let's have our idempotency test print the TypeScript code the first time and the second time print the JavaScript code only. If the two results do not match, it means that there are still undeleted TS ASTs or other bugs. Since ideally the TS ASTs are completely deleted, the two results should be the same.
  • Loading branch information
Dunqing committed Jun 6, 2024
1 parent cd4ae5a commit 7ed6080
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
3 changes: 1 addition & 2 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2405,8 +2405,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for MethodDefinition<'a> {
}
if let Some(body) = &self.value.body {
body.gen(p, ctx);
}
if p.options.enable_typescript {
} else if p.options.enable_typescript {
p.print_semicolon_after_statement();
}
}
Expand Down
42 changes: 27 additions & 15 deletions tasks/coverage/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn get_result(
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(
let transform_result1 = Transformer::new(
&allocator,
source_path,
source_type,
Expand All @@ -53,7 +53,7 @@ fn get_result(
)
.build(&mut program);

let source_text1 = Codegen::<false>::new(
let ts_source_text1 = Codegen::<false>::new(
&filename,
source_text,
CodegenOptions::default().with_typescript(true),
Expand All @@ -62,10 +62,19 @@ fn get_result(
.build(&program)
.source_text;

let parse_result2 = Parser::new(&allocator, &source_text1, source_type).parse();
let source_text1 =
Codegen::<false>::new(&filename, source_text, CodegenOptions::default(), None)
.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 _ = Transformer::new(
let transform_result2 = Transformer::new(
&allocator,
source_path,
source_type,
Expand All @@ -75,19 +84,22 @@ fn get_result(
)
.build(&mut program);

let source_text2 = Codegen::<false>::new(
&filename,
&source_text1,
CodegenOptions::default().with_typescript(true),
None,
)
.build(&program)
.source_text;

let result = source_text1 == source_text2;
let source_text2 =
Codegen::<false>::new(&filename, &source_text1, CodegenOptions::default(), None)
.build(&program)
.source_text;

if result {
if source_text1 == source_text2 {
TestResult::Passed
} else if 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::<Vec<_>>().join("\n"))
.is_err_and(|err_message| {
err.iter().map(ToString::to_string).collect::<Vec<_>>().join("\n") == err_message
})
}) {
return TestResult::Passed;
} else {
TestResult::Mismatch(source_text1.clone(), source_text2)
}
Expand Down
4 changes: 3 additions & 1 deletion tasks/coverage/transformer_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ commit: 4bd1b2c2

transformer_babel Summary:
AST Parsed : 2099/2099 (100.00%)
Positive Passed: 2099/2099 (100.00%)
Positive Passed: 2097/2099 (99.90%)
Mismatch: "typescript/class/parameter-properties/input.ts"
Mismatch: "typescript/export/as-namespace/input.ts"
34 changes: 33 additions & 1 deletion tasks/coverage/transformer_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,37 @@ commit: 64d2eeea

transformer_typescript Summary:
AST Parsed : 5243/5243 (100.00%)
Positive Passed: 5242/5243 (99.98%)
Positive Passed: 5210/5243 (99.37%)
Mismatch: "compiler/amdModuleName1.ts"
Mismatch: "compiler/avoidCycleWithVoidExpressionReturnedFromArrow.ts"
Mismatch: "compiler/clinterfaces.ts"
Mismatch: "compiler/collectionPatternNoError.ts"
Mismatch: "compiler/comparabilityTypeParametersRelatedByUnion.ts"
Mismatch: "compiler/constEnumMergingWithValues1.ts"
Mismatch: "compiler/constEnumMergingWithValues2.ts"
Mismatch: "compiler/constEnumMergingWithValues3.ts"
Mismatch: "compiler/constEnumMergingWithValues4.ts"
Mismatch: "compiler/constEnumMergingWithValues5.ts"
Mismatch: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts"
Mismatch: "compiler/es5-umd4.ts"
Mismatch: "compiler/exportAssignValueAndType.ts"
Mismatch: "compiler/exportAssignmentWithPrivacyError.ts"
Mismatch: "compiler/exportAssignmentWithoutIdentifier1.ts"
Mismatch: "compiler/exportEqualNamespaces.ts"
Mismatch: "compiler/exportEqualsAmd.ts"
Mismatch: "compiler/exportEqualsClassNoRedeclarationError.ts"
Mismatch: "compiler/exportEqualsCommonJs.ts"
Mismatch: "compiler/exportEqualsUmd.ts"
Mismatch: "compiler/module_augmentUninstantiatedModule2.ts"
Mismatch: "compiler/noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts"
Mismatch: "compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.ts"
Mismatch: "compiler/recursiveFieldSetting.ts"
Mismatch: "compiler/sourceMapValidationExportAssignment.ts"
Mismatch: "compiler/sourceMapValidationExportAssignmentCommonjs.ts"
Mismatch: "compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts"
Mismatch: "compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts"
Mismatch: "conformance/classes/members/privateNames/privateNameFieldParenthesisLeftAssignment.ts"
Mismatch: "conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts"
Mismatch: "conformance/classes/propertyMemberDeclarations/instanceMemberInitialization.ts"
Mismatch: "conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter5.ts"
Mismatch: "conformance/statements/VariableStatements/usingDeclarations/usingDeclarationsTopLevelOfModule.2.ts"

0 comments on commit 7ed6080

Please sign in to comment.