Skip to content

Commit 3ebf220

Browse files
committed
fix(codegen): generate missing type in export type {} from 'mod' (#10539)
fixes #10465
1 parent 1d2154e commit 3ebf220

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

crates/oxc_codegen/src/gen.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,10 @@ impl Gen for ExportNamedDeclaration<'_> {
10381038
p.needs_semicolon = false;
10391039
}
10401040
} else {
1041+
if self.export_kind.is_type() {
1042+
p.print_hard_space();
1043+
p.print_str("type");
1044+
}
10411045
p.print_soft_space();
10421046
p.print_ascii_byte(b'{');
10431047
if !self.specifiers.is_empty() {

crates/oxc_codegen/tests/integration/tester.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use oxc_span::SourceType;
77
pub fn test_with_parse_options(source_text: &str, expected: &str, parse_options: ParseOptions) {
88
let allocator = Allocator::default();
99
let ret =
10-
Parser::new(&allocator, source_text, SourceType::jsx()).with_options(parse_options).parse();
10+
Parser::new(&allocator, source_text, SourceType::tsx()).with_options(parse_options).parse();
1111
let result = CodeGenerator::new().build(&ret.program).code;
1212
assert_eq!(result, expected, "\nfor source: {source_text}");
1313
}
@@ -24,7 +24,7 @@ pub fn test_same(source_text: &str) {
2424

2525
#[track_caller]
2626
pub fn test_options(source_text: &str, expected: &str, options: CodegenOptions) {
27-
test_options_with_source_type(source_text, expected, SourceType::jsx(), options);
27+
test_options_with_source_type(source_text, expected, SourceType::tsx(), options);
2828
}
2929

3030
#[track_caller]

crates/oxc_codegen/tests/integration/unit.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ fn module_decl() {
2525
);
2626
}
2727

28+
#[test]
29+
fn export_type() {
30+
test_same("export type {} from \"mod\";\n");
31+
test_same("export type { Foo } from \"mod\";\n");
32+
test_same("export { type Foo, type Bar } from \"mod\";\n");
33+
}
34+
2835
#[test]
2936
fn expr() {
3037
test("new (foo()).bar();", "new (foo()).bar();\n");

0 commit comments

Comments
 (0)