diff --git a/.changeset/twelve-heads-lead.md b/.changeset/twelve-heads-lead.md new file mode 100644 index 0000000..e95e78d --- /dev/null +++ b/.changeset/twelve-heads-lead.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/acorn-typescript': patch +--- + +fix: support `export type *` diff --git a/src/index.ts b/src/index.ts index ab245f7..2fb8d40 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3116,9 +3116,15 @@ export function tsPlugin(options?: { this.importOrExportOuterKind = undefined; return this.finishNode(decl, 'TSNamespaceExportDeclaration'); } else { + const lookahead2 = this.lookahead(2).type; + + // Ideally we can just say "ok this is a type export of some kind" + // but that doesn't work for shouldParseExportStatement() below + // which wants to handle the `export type Foo = ...` case if ( this.ts_isContextualWithState(enterHead, tokTypes.type) && - this.lookahead(2).type === tt.braceL + (lookahead2 === tt.braceL || // export type { ... } + lookahead2 === tt.star) // export type * ) { this.next(); this.importOrExportOuterKind = 'type'; diff --git a/test/export_type_star/expected.json b/test/export_type_star/expected.json new file mode 100644 index 0000000..6bfaeb9 --- /dev/null +++ b/test/export_type_star/expected.json @@ -0,0 +1,52 @@ +{ + "body": [ + { + "end": 27, + "exportKind": "type", + "exported": null, + "loc": { + "end": { + "column": 27, + "line": 1 + }, + "start": { + "column": 0, + "line": 1 + } + }, + "source": { + "end": 26, + "loc": { + "end": { + "column": 26, + "line": 1 + }, + "start": { + "column": 19, + "line": 1 + } + }, + "raw": "'./foo'", + "start": 19, + "type": "Literal", + "value": "./foo" + }, + "start": 0, + "type": "ExportAllDeclaration" + } + ], + "end": 27, + "loc": { + "end": { + "column": 27, + "line": 1 + }, + "start": { + "column": 0, + "line": 1 + } + }, + "sourceType": "module", + "start": 0, + "type": "Program" +} diff --git a/test/export_type_star/input.ts b/test/export_type_star/input.ts new file mode 100644 index 0000000..6b78417 --- /dev/null +++ b/test/export_type_star/input.ts @@ -0,0 +1 @@ +export type * from './foo'; \ No newline at end of file