diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index e23e1fc4874..c44d76efc74 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -16384,6 +16384,56 @@ Object { } `; +exports[`typescript fixtures/basics/export-star-as-ns-from.src 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 28, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 28, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "module", + "upperScope": Object { + "$ref": 1, + }, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], + }, + ], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [], +} +`; + exports[`typescript fixtures/basics/export-type-alias-declaration.src 1`] = ` Object { "$id": 1, diff --git a/packages/shared-fixtures/fixtures/typescript/basics/export-star-as-ns-from.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/export-star-as-ns-from.src.ts new file mode 100644 index 00000000000..ee2c09704ba --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/export-star-as-ns-from.src.ts @@ -0,0 +1 @@ +export * as foo from 'bar'; diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index eb21bdbf2cd..52c894bad71 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1577,10 +1577,7 @@ export class Converter { }); case SyntaxKind.ExportDeclaration: - if (node.exportClause) { - if (node.exportClause.kind !== SyntaxKind.NamedExports) { - throw new Error('`export * as ns` is not yet supported.'); - } + if (node.exportClause?.kind === SyntaxKind.NamedExports) { return this.createNode(node, { type: AST_NODE_TYPES.ExportNamedDeclaration, source: this.convertChild(node.moduleSpecifier), @@ -1593,6 +1590,10 @@ export class Converter { return this.createNode(node, { type: AST_NODE_TYPES.ExportAllDeclaration, source: this.convertChild(node.moduleSpecifier), + exported: + node.exportClause?.kind === SyntaxKind.NamespaceExport + ? this.convertChild(node.exportClause.name) + : null, }); } diff --git a/packages/typescript-estree/src/ts-estree/ts-estree.ts b/packages/typescript-estree/src/ts-estree/ts-estree.ts index 94d4b7c2440..0b2cb0aaa75 100644 --- a/packages/typescript-estree/src/ts-estree/ts-estree.ts +++ b/packages/typescript-estree/src/ts-estree/ts-estree.ts @@ -868,6 +868,7 @@ export interface EmptyStatement extends BaseNode { export interface ExportAllDeclaration extends BaseNode { type: AST_NODE_TYPES.ExportAllDeclaration; source: Expression | null; + exported: Identifier | null; } export interface ExportDefaultDeclaration extends BaseNode { diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index ab677004678..5dae1758443 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -422,6 +422,11 @@ tester.addFixturePatternConfig('typescript/basics', { */ 'abstract-class-with-declare-properties', 'class-with-declare-properties', + /** + * TS 3.8 export * as namespace + * babel uses a representation that does not match the ESTree spec: https://github.com/estree/estree/pull/205 + */ + 'export-star-as-ns-from', ], ignoreSourceType: [ /** diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index 002a4c66dcb..c5300e438a6 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -248,6 +248,15 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any { node.asserts = false; } }, + /** + * TS 3.8 export * as namespace + * babel uses a representation that does not match the ESTree spec: https://github.com/estree/estree/pull/205 + */ + ExportAllDeclaration(node) { + if (!node.exported) { + node.exported = null; + } + }, }, ); } diff --git a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap index 0f9639a3bcb..9ffbb627352 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap @@ -111891,6 +111891,7 @@ exports[`javascript fixtures/modules/export-from-batch.src 1`] = ` Object { "body": Array [ Object { + "exported": null, "loc": Object { "end": Object { "column": 20, diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index e1c91feca7f..845be2e1ac6 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -1878,6 +1878,8 @@ Object { } `; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/export-star-as-ns-from.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/export-type-alias-declaration.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/export-type-class-declaration.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index cbd1e12b378..7eba3575230 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -46816,6 +46816,211 @@ Object { } `; +exports[`typescript fixtures/basics/export-star-as-ns-from.src 1`] = ` +Object { + "body": Array [ + Object { + "exported": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 12, + 15, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 27, + ], + "source": Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 26, + ], + "raw": "'bar'", + "type": "Literal", + "value": "bar", + }, + "type": "ExportAllDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 28, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Punctuator", + "value": "*", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 11, + ], + "type": "Identifier", + "value": "as", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 15, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 20, + ], + "type": "Identifier", + "value": "from", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 26, + ], + "type": "String", + "value": "'bar'", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 26, + "line": 1, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/basics/export-type-alias-declaration.src 1`] = ` Object { "body": Array [