diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index 9eea694d46d..6357445c265 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.src 1`] = ` Object { "$id": 2, 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 97dc43a5ee2..74c701b7fc4 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1586,10 +1586,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), @@ -1604,6 +1601,10 @@ export class Converter { type: AST_NODE_TYPES.ExportAllDeclaration, source: this.convertChild(node.moduleSpecifier), exportKind: node.isTypeOnly ? 'type' : 'value', + 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 10685a507b9..cbf7787c805 100644 --- a/packages/typescript-estree/src/ts-estree/ts-estree.ts +++ b/packages/typescript-estree/src/ts-estree/ts-estree.ts @@ -869,6 +869,7 @@ export interface ExportAllDeclaration extends BaseNode { type: AST_NODE_TYPES.ExportAllDeclaration; source: Expression | null; exportKind: 'type' | 'value'; + 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 b970aa38f41..c2f1834baeb 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -436,6 +436,11 @@ tester.addFixturePatternConfig('typescript/basics', { 'import-type-named-as', 'import-type-named', 'import-type-star-as-ns', + /** + * 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 6a2426b147f..8f031b534f8 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -249,8 +249,7 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any { } }, /** - * TS 3.8 import/export type - * babel coming soon https://github.com/babel/babel/pull/11171 + * TS 3.8 features */ ExportNamedDeclaration(node: any) { /** @@ -281,10 +280,17 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any { node.exportKind = 'value'; } } + /** + * TS 3.8 export * as namespace + * babel uses a representation that does not match the ESTree spec: https://github.com/estree/estree/pull/205 + */ + if (!node.exported) { + node.exported = null; + } }, ImportDeclaration(node) { /** - * TS 3.8: export type + * TS 3.8: import type */ if (!node.importKind) { node.importKind = 'value'; diff --git a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap index ef4ac4c58c1..4a07dceeaab 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap @@ -111896,6 +111896,7 @@ Object { "body": Array [ Object { "exportKind": "value", + "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 f3189765268..8d197deb452 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.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/export-type-as.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 dc2275c4cd3..f098a7d851e 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -46829,6 +46829,212 @@ Object { } `; +exports[`typescript fixtures/basics/export-star-as-ns-from.src 1`] = ` +Object { + "body": Array [ + Object { + "exportKind": "value", + "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.src 1`] = ` Object { "body": Array [ @@ -47846,6 +48052,7 @@ Object { "body": Array [ Object { "exportKind": "type", + "exported": null, "loc": Object { "end": Object { "column": 25,