Skip to content

Commit ac652a3

Browse files
authored
fix: support export type * (#10)
1 parent b40fc77 commit ac652a3

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

.changeset/twelve-heads-lead.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/acorn-typescript': patch
3+
---
4+
5+
fix: support `export type *`

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3116,9 +3116,15 @@ export function tsPlugin(options?: {
31163116
this.importOrExportOuterKind = undefined;
31173117
return this.finishNode(decl, 'TSNamespaceExportDeclaration');
31183118
} else {
3119+
const lookahead2 = this.lookahead(2).type;
3120+
3121+
// Ideally we can just say "ok this is a type export of some kind"
3122+
// but that doesn't work for shouldParseExportStatement() below
3123+
// which wants to handle the `export type Foo = ...` case
31193124
if (
31203125
this.ts_isContextualWithState(enterHead, tokTypes.type) &&
3121-
this.lookahead(2).type === tt.braceL
3126+
(lookahead2 === tt.braceL || // export type { ... }
3127+
lookahead2 === tt.star) // export type *
31223128
) {
31233129
this.next();
31243130
this.importOrExportOuterKind = 'type';

test/export_type_star/expected.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"body": [
3+
{
4+
"end": 27,
5+
"exportKind": "type",
6+
"exported": null,
7+
"loc": {
8+
"end": {
9+
"column": 27,
10+
"line": 1
11+
},
12+
"start": {
13+
"column": 0,
14+
"line": 1
15+
}
16+
},
17+
"source": {
18+
"end": 26,
19+
"loc": {
20+
"end": {
21+
"column": 26,
22+
"line": 1
23+
},
24+
"start": {
25+
"column": 19,
26+
"line": 1
27+
}
28+
},
29+
"raw": "'./foo'",
30+
"start": 19,
31+
"type": "Literal",
32+
"value": "./foo"
33+
},
34+
"start": 0,
35+
"type": "ExportAllDeclaration"
36+
}
37+
],
38+
"end": 27,
39+
"loc": {
40+
"end": {
41+
"column": 27,
42+
"line": 1
43+
},
44+
"start": {
45+
"column": 0,
46+
"line": 1
47+
}
48+
},
49+
"sourceType": "module",
50+
"start": 0,
51+
"type": "Program"
52+
}

test/export_type_star/input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type * from './foo';

0 commit comments

Comments
 (0)