Skip to content

Commit 0e7f305

Browse files
committed
feat: support type-only named import and export specifiers
1 parent 03b36e5 commit 0e7f305

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ dprint-core = { version = "0.46.4", features = ["formatting"] }
2929
rustc-hash = "1.1.0"
3030
serde = { version = "1.0.118", features = ["derive"] }
3131
serde_json = { version = "1.0", optional = true }
32-
swc_ast_view = { version = "0.36.0", package = "dprint-swc-ecma-ast-view" }
33-
swc_common = "0.12.2"
34-
swc_ecmascript = { version = "0.64.0", features = ["parser"] }
32+
swc_ast_view = { version = "0.37.0", package = "dprint-swc-ecma-ast-view" }
33+
swc_common = "0.13.1"
34+
swc_ecmascript = { version = "0.68.0", features = ["parser"] }
3535

3636
[dev-dependencies]
3737
debug-here = "0.2"

src/parsing/parser.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,6 +2656,10 @@ fn parse_yield_expr<'a>(node: &'a YieldExpr, context: &mut Context<'a>) -> Print
26562656
fn parse_export_named_specifier<'a>(node: &'a ExportNamedSpecifier, context: &mut Context<'a>) -> PrintItems {
26572657
let mut items = PrintItems::new();
26582658

2659+
if node.is_type_only() && !node.parent().type_only() {
2660+
items.push_str("type ");
2661+
}
2662+
26592663
items.extend(parse_node(node.orig.into(), context));
26602664
if let Some(exported) = node.exported {
26612665
items.push_signal(Signal::SpaceOrNewLine);
@@ -2682,6 +2686,10 @@ fn parse_namespace_export_specifier<'a>(node: &'a ExportNamespaceSpecifier, cont
26822686
fn parse_import_named_specifier<'a>(node: &'a ImportNamedSpecifier, context: &mut Context<'a>) -> PrintItems {
26832687
let mut items = PrintItems::new();
26842688

2689+
if node.is_type_only() && !node.parent().type_only() {
2690+
items.push_str("type ");
2691+
}
2692+
26852693
if let Some(imported) = node.imported {
26862694
items.extend(parse_node(imported.into(), context));
26872695
items.push_signal(Signal::SpaceOrNewLine);

tests/specs/declarations/export/ExportNamedDeclaration_All.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ export type { test };
2525
[expect]
2626
export type { test };
2727

28+
== should format a type only export specifiers ==
29+
export { type n1 };
30+
export type{ type n1 };
31+
32+
[expect]
33+
export { type n1 };
34+
export type { n1 };
35+
2836
== should format when has zero named exports ==
2937
export {} from "test";
3038

tests/specs/declarations/import/ImportDeclaration_All.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ import type { n1 } from "test";
4848
[expect]
4949
import type { n1 } from "test";
5050

51+
== should format a type only import specifiers ==
52+
import { type n1 } from "test";
53+
import type{ type n1 } from "test";
54+
55+
[expect]
56+
import { type n1 } from "test";
57+
import type { n1 } from "test";
58+
5159
== should format when has zero named imports ==
5260
import {} from "test";
5361

0 commit comments

Comments
 (0)