mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(coverage): second transformer build does not print typescript (#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.
This commit is contained in:
parent
e8a20f8d50
commit
5c8e16c976
4 changed files with 64 additions and 19 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -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),
|
||||
|
|
@ -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,
|
||||
|
|
@ -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 source_text2 =
|
||||
Codegen::<false>::new(&filename, &source_text1, CodegenOptions::default(), None)
|
||||
.build(&program)
|
||||
.source_text;
|
||||
|
||||
let result = source_text1 == source_text2;
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue