mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
feat(tasks/coverage): turn on idempotency testing for transformer (#3470)
This commit is contained in:
parent
350cd9158a
commit
574629e5de
4 changed files with 79 additions and 12 deletions
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
|
|
|
|||
|
|
@ -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::<false>::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::<false>::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 {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue