Skip to content

Commit f9321a9

Browse files
committed
handle export type
1 parent 528edb9 commit f9321a9

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

src/languages/ts.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,13 @@ export default (options = {}) => {
747747
},
748748

749749
ExportAllDeclaration(node, context) {
750-
context.write('export * ');
750+
context.write(node.exportKind === 'type' ? 'export type * ' : 'export * ');
751+
751752
if (node.exported) {
752753
context.write('as ');
753754
context.visit(node.exported);
754755
}
756+
755757
context.write(' from ');
756758
context.visit(node.source);
757759
context.write(';');
@@ -770,6 +772,10 @@ export default (options = {}) => {
770772
ExportNamedDeclaration(node, context) {
771773
context.write('export ');
772774

775+
if (node.exportKind === 'type') {
776+
context.write('type ');
777+
}
778+
773779
if (node.declaration) {
774780
context.visit(node.declaration);
775781
return;
@@ -788,6 +794,10 @@ export default (options = {}) => {
788794
},
789795

790796
ExportSpecifier(node, context) {
797+
if (node.exportKind === 'type') {
798+
context.write('type ');
799+
}
800+
791801
context.visit(node.local);
792802

793803
if (node.local.name !== node.exported.name) {

test/samples/ts-export/expected.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// TODO i think these are currently broken in acorn-typescript?
2+
// export type X = number;
3+
// export type * from './elsewhere';
4+
type Y = number;
5+
6+
type Z = number;
7+
8+
export type { Y };
9+
export { type Z };
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": 3,
3+
"names": [],
4+
"sources": [
5+
"input.js"
6+
],
7+
"sourcesContent": [
8+
"// TODO i think these are currently broken in acorn-typescript?\n// export type X = number;\n// export type * from './elsewhere';\n\ntype Y = number;\ntype Z = number;\nexport type { Y };\nexport { type Z };\n"
9+
],
10+
"mappings": ";;;KAIK,CAAC,GAAG,MAAM;;KACV,CAAC,GAAG,MAAM;;cACD,CAAC;cACD,CAAC"
11+
}

test/samples/ts-export/input.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// TODO i think these are currently broken in acorn-typescript?
2+
// export type X = number;
3+
// export type * from './elsewhere';
4+
5+
type Y = number;
6+
type Z = number;
7+
export type { Y };
8+
export { type Z };

0 commit comments

Comments
 (0)