mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +03:00
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 "..."`.
This commit is contained in:
parent
a9f25b2fb6
commit
65dec905c0
@ -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!();
|
||||
@ -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 {
|
||||
@ -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");
|
||||
|
@ -0,0 +1,3 @@
|
||||
export type * as test from "./a.ts";
|
||||
export type { a } from "./a.ts";
|
||||
export { b, type b2 } from "./b.ts";
|
@ -0,0 +1,3 @@
|
||||
export type * as test from "./a.ts";
|
||||
export type { a } from "./a.ts";
|
||||
export { b, type b2 } from "./b.ts";
|
1
crates/swc_ecma_codegen/tests/fixture/typescript/exports/output.min.js
vendored
Normal file
1
crates/swc_ecma_codegen/tests/fixture/typescript/exports/output.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
export type*as test from"./a.ts";export type{a}from"./a.ts";export{b,type b2}from"./b.ts";
|
@ -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";
|
@ -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";
|
1
crates/swc_ecma_codegen/tests/fixture/typescript/imports/output.min.js
vendored
Normal file
1
crates/swc_ecma_codegen/tests/fixture/typescript/imports/output.min.js
vendored
Normal file
@ -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";
|
@ -1,2 +1,3 @@
|
||||
import Test1 = MyNamespace.Test1;
|
||||
import Test2 = Test1;
|
||||
export import Test3 = Test1;
|
||||
|
@ -1,2 +1,3 @@
|
||||
import Test1 = MyNamespace.Test1;
|
||||
import Test2 = Test1;
|
||||
export import Test3 = Test1;
|
||||
|
@ -1 +1 @@
|
||||
import Test1=MyNamespace.Test1;import Test2=Test1;
|
||||
import Test1=MyNamespace.Test1;import Test2=Test1;export import Test3=Test1;
|
||||
|
Loading…
Reference in New Issue
Block a user