Skip to content

Commit

Permalink
chore(coverage, transformer_conformance): print all AST whether or no…
Browse files Browse the repository at this point in the history
…t they are Typecript AST (#3556)

We have a conclusion that codegen will print whatever is in the AST,
instead of having an option to enable printing TypeScript syntax. I plan
to remove codegen's `enable_typescript` option after we strip out all
typescript AST in the transformer typescript plugin.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
  • Loading branch information
Dunqing and Boshen authored Jun 6, 2024
1 parent 6db4d7d commit 0007ee4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
24 changes: 16 additions & 8 deletions tasks/coverage/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ fn get_result(
)
.build(&mut program);

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

let parse_result2 = Parser::new(&allocator, &source_text1, source_type).parse();
let mut program = parse_result2.program;
Expand All @@ -71,10 +75,14 @@ fn get_result(
)
.build(&mut program);

let source_text2 =
Codegen::<false>::new(&filename, &source_text1, CodegenOptions::default(), None)
.build(&program)
.source_text;
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;

Expand Down
13 changes: 11 additions & 2 deletions tasks/transform_conformance/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 4bd1b2c2

Passed: 478/926
Passed: 469/926

# All Passed:
* babel-preset-react
Expand Down Expand Up @@ -445,11 +445,20 @@ Passed: 478/926
* opts/optimizeConstEnums/input.ts
* opts/rewriteImportExtensions/input.ts

# babel-plugin-transform-typescript (134/150)
# babel-plugin-transform-typescript (125/150)
* cast/multiple-assert-and-assign/input.ts
* class/accessor-allowDeclareFields-false/input.ts
* class/accessor-allowDeclareFields-true/input.ts
* class/methods/input.ts
* class/private-method-override/input.ts
* enum/mix-references/input.ts
* enum/ts5.0-const-foldable/input.ts
* exports/declared-types/input.ts
* exports/default-function/input.ts
* exports/interface/input.ts
* imports/type-only-export-specifier-2/input.ts
* lvalues/as-expression/input.ts
* lvalues/type-assertion/input.ts
* optimize-const-enums/custom-values/input.ts
* optimize-const-enums/custom-values-exported/input.ts
* optimize-const-enums/declare/input.ts
Expand Down
24 changes: 17 additions & 7 deletions tasks/transform_conformance/src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,14 @@ pub trait TestCase {
.build(&mut program);

result.map(|()| {
Codegen::<false>::new("", &source_text, CodegenOptions::default(), None)
.build(&program)
.source_text
Codegen::<false>::new(
"",
&source_text,
CodegenOptions::default().with_typescript(true),
None,
)
.build(&program)
.source_text
})
}
}
Expand Down Expand Up @@ -251,7 +256,7 @@ impl TestCase for ConformanceTestCase {
println!("output_path: {output_path:?}");
}

let codegen_options = CodegenOptions::default();
let codegen_options = CodegenOptions::default().with_typescript(true);
let mut transformed_code = String::new();
let mut actual_errors = String::new();

Expand Down Expand Up @@ -382,9 +387,14 @@ impl ExecTestCase {
let source_type = SourceType::from_path(&target_path).unwrap();
let transformed_program =
Parser::new(&allocator, &source_text, source_type).parse().program;
let result = Codegen::<false>::new("", &source_text, CodegenOptions::default(), None)
.build(&transformed_program)
.source_text;
let result = Codegen::<false>::new(
"",
&source_text,
CodegenOptions::default().with_typescript(true),
None,
)
.build(&transformed_program)
.source_text;

fs::write(&target_path, result).unwrap();

Expand Down

0 comments on commit 0007ee4

Please sign in to comment.