Skip to content

Commit 65dec90

Browse files
authoredDec 22, 2023
fix(es/codegen): Fix codegen of type-only export declarations (#8447)
**Description:** This fixes the emit for `export type { } from "..."` and `export { type A } from "..."`.
1 parent a9f25b2 commit 65dec90

File tree

10 files changed

+38
-2
lines changed

10 files changed

+38
-2
lines changed
 

‎crates/swc_ecma_codegen/src/lib.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ where
415415

416416
srcmap!(node, true);
417417

418+
if node.is_type_only {
419+
keyword!("type");
420+
space!();
421+
}
422+
418423
if let Some(exported) = &node.exported {
419424
emit!(node.orig);
420425
space!();
@@ -470,7 +475,12 @@ where
470475

471476
keyword!("export");
472477

478+
if node.type_only {
479+
space!();
480+
keyword!("type");
481+
}
473482
formatting_space!();
483+
474484
if let Some(spec) = namespace_spec {
475485
emit!(spec);
476486
if has_named_specs {
@@ -521,7 +531,15 @@ where
521531
srcmap!(node, true);
522532

523533
keyword!("export");
524-
formatting_space!();
534+
535+
if node.type_only {
536+
space!();
537+
keyword!("type");
538+
space!();
539+
} else {
540+
formatting_space!();
541+
}
542+
525543
punct!("*");
526544
formatting_space!();
527545
keyword!("from");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type * as test from "./a.ts";
2+
export type { a } from "./a.ts";
3+
export { b, type b2 } from "./b.ts";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type * as test from "./a.ts";
2+
export type { a } from "./a.ts";
3+
export { b, type b2 } from "./b.ts";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type*as test from"./a.ts";export type{a}from"./a.ts";export{b,type b2}from"./b.ts";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type test from "./a.ts";
2+
import type { a } from "./a.ts";
3+
import type * as name from "./a.ts";
4+
import { b, type c } from "./a.ts";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type test from "./a.ts";
2+
import type { a } from "./a.ts";
3+
import type * as name from "./a.ts";
4+
import { b, type c } from "./a.ts";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import type test from"./a.ts";import type{a}from"./a.ts";import type*as name from"./a.ts";import{b,type c}from"./a.ts";
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import Test1 = MyNamespace.Test1;
22
import Test2 = Test1;
3+
export import Test3 = Test1;
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import Test1 = MyNamespace.Test1;
22
import Test2 = Test1;
3+
export import Test3 = Test1;
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import Test1=MyNamespace.Test1;import Test2=Test1;
1+
import Test1=MyNamespace.Test1;import Test2=Test1;export import Test3=Test1;

0 commit comments

Comments
 (0)
Please sign in to comment.