Skip to content

Commit

Permalink
fix(es/codegen): Fix codegen of type-only export declarations (#8447)
Browse files Browse the repository at this point in the history
**Description:**

This fixes the emit for `export type { } from "..."` and `export { type A } from "..."`.
  • Loading branch information
dsherret committed Dec 22, 2023
1 parent a9f25b2 commit 65dec90
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 2 deletions.
20 changes: 19 additions & 1 deletion crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ where

srcmap!(node, true);

if node.is_type_only {
keyword!("type");
space!();
}

if let Some(exported) = &node.exported {
emit!(node.orig);
space!();
Expand Down Expand Up @@ -470,7 +475,12 @@ where

keyword!("export");

if node.type_only {
space!();
keyword!("type");
}
formatting_space!();

if let Some(spec) = namespace_spec {
emit!(spec);
if has_named_specs {
Expand Down Expand Up @@ -521,7 +531,15 @@ where
srcmap!(node, true);

keyword!("export");
formatting_space!();

if node.type_only {
space!();
keyword!("type");
space!();
} else {
formatting_space!();
}

punct!("*");
formatting_space!();
keyword!("from");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type * as test from "./a.ts";
export type { a } from "./a.ts";
export { b, type b2 } from "./b.ts";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type * as test from "./a.ts";
export type { a } from "./a.ts";
export { b, type b2 } from "./b.ts";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type*as test from"./a.ts";export type{a}from"./a.ts";export{b,type b2}from"./b.ts";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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 number Diff line number Diff line change
@@ -0,0 +1,4 @@
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 number Diff line number Diff line change
@@ -0,0 +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 number Diff line number Diff line change
@@ -1,2 +1,3 @@
import Test1 = MyNamespace.Test1;
import Test2 = Test1;
export import Test3 = Test1;
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import Test1 = MyNamespace.Test1;
import Test2 = Test1;
export import Test3 = Test1;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import Test1=MyNamespace.Test1;import Test2=Test1;
import Test1=MyNamespace.Test1;import Test2=Test1;export import Test3=Test1;

0 comments on commit 65dec90

Please sign in to comment.