Skip to content

Commit 133f622

Browse files
authored
feat(typescript-estree): support 3.8 export * as ns (typescript-eslint#1698)
1 parent b5b3be0 commit 133f622

File tree

9 files changed

+281
-7
lines changed

9 files changed

+281
-7
lines changed

packages/parser/tests/lib/__snapshots__/typescript.ts.snap

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16384,6 +16384,56 @@ Object {
1638416384
}
1638516385
`;
1638616386

16387+
exports[`typescript fixtures/basics/export-star-as-ns-from.src 1`] = `
16388+
Object {
16389+
"$id": 1,
16390+
"block": Object {
16391+
"range": Array [
16392+
0,
16393+
28,
16394+
],
16395+
"type": "Program",
16396+
},
16397+
"childScopes": Array [
16398+
Object {
16399+
"$id": 0,
16400+
"block": Object {
16401+
"range": Array [
16402+
0,
16403+
28,
16404+
],
16405+
"type": "Program",
16406+
},
16407+
"childScopes": Array [],
16408+
"functionExpressionScope": false,
16409+
"isStrict": true,
16410+
"references": Array [],
16411+
"throughReferences": Array [],
16412+
"type": "module",
16413+
"upperScope": Object {
16414+
"$ref": 1,
16415+
},
16416+
"variableMap": Object {},
16417+
"variableScope": Object {
16418+
"$ref": 0,
16419+
},
16420+
"variables": Array [],
16421+
},
16422+
],
16423+
"functionExpressionScope": false,
16424+
"isStrict": false,
16425+
"references": Array [],
16426+
"throughReferences": Array [],
16427+
"type": "global",
16428+
"upperScope": null,
16429+
"variableMap": Object {},
16430+
"variableScope": Object {
16431+
"$ref": 1,
16432+
},
16433+
"variables": Array [],
16434+
}
16435+
`;
16436+
1638716437
exports[`typescript fixtures/basics/export-type.src 1`] = `
1638816438
Object {
1638916439
"$id": 2,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as foo from 'bar';

packages/typescript-estree/src/convert.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,10 +1586,7 @@ export class Converter {
15861586
});
15871587

15881588
case SyntaxKind.ExportDeclaration:
1589-
if (node.exportClause) {
1590-
if (node.exportClause.kind !== SyntaxKind.NamedExports) {
1591-
throw new Error('`export * as ns` is not yet supported.');
1592-
}
1589+
if (node.exportClause?.kind === SyntaxKind.NamedExports) {
15931590
return this.createNode<TSESTree.ExportNamedDeclaration>(node, {
15941591
type: AST_NODE_TYPES.ExportNamedDeclaration,
15951592
source: this.convertChild(node.moduleSpecifier),
@@ -1604,6 +1601,10 @@ export class Converter {
16041601
type: AST_NODE_TYPES.ExportAllDeclaration,
16051602
source: this.convertChild(node.moduleSpecifier),
16061603
exportKind: node.isTypeOnly ? 'type' : 'value',
1604+
exported:
1605+
node.exportClause?.kind === SyntaxKind.NamespaceExport
1606+
? this.convertChild(node.exportClause.name)
1607+
: null,
16071608
});
16081609
}
16091610

packages/typescript-estree/src/ts-estree/ts-estree.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ export interface ExportAllDeclaration extends BaseNode {
869869
type: AST_NODE_TYPES.ExportAllDeclaration;
870870
source: Expression | null;
871871
exportKind: 'type' | 'value';
872+
exported: Identifier | null;
872873
}
873874

874875
export interface ExportDefaultDeclaration extends BaseNode {

packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ tester.addFixturePatternConfig('typescript/basics', {
436436
'import-type-named-as',
437437
'import-type-named',
438438
'import-type-star-as-ns',
439+
/**
440+
* TS 3.8 export * as namespace
441+
* babel uses a representation that does not match the ESTree spec: https://github.com/estree/estree/pull/205
442+
*/
443+
'export-star-as-ns-from',
439444
],
440445
ignoreSourceType: [
441446
/**

packages/typescript-estree/tests/ast-alignment/utils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
249249
}
250250
},
251251
/**
252-
* TS 3.8 import/export type
253-
* babel coming soon https://github.com/babel/babel/pull/11171
252+
* TS 3.8 features
254253
*/
255254
ExportNamedDeclaration(node: any) {
256255
/**
@@ -281,10 +280,17 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
281280
node.exportKind = 'value';
282281
}
283282
}
283+
/**
284+
* TS 3.8 export * as namespace
285+
* babel uses a representation that does not match the ESTree spec: https://github.com/estree/estree/pull/205
286+
*/
287+
if (!node.exported) {
288+
node.exported = null;
289+
}
284290
},
285291
ImportDeclaration(node) {
286292
/**
287-
* TS 3.8: export type
293+
* TS 3.8: import type
288294
*/
289295
if (!node.importKind) {
290296
node.importKind = 'value';

packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111896,6 +111896,7 @@ Object {
111896111896
"body": Array [
111897111897
Object {
111898111898
"exportKind": "value",
111899+
"exported": null,
111899111900
"loc": Object {
111900111901
"end": Object {
111901111902
"column": 20,

packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,8 @@ Object {
18781878
}
18791879
`;
18801880

1881+
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"`;
1882+
18811883
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/export-type.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
18821884

18831885
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/export-type-as.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46829,6 +46829,212 @@ Object {
4682946829
}
4683046830
`;
4683146831

46832+
exports[`typescript fixtures/basics/export-star-as-ns-from.src 1`] = `
46833+
Object {
46834+
"body": Array [
46835+
Object {
46836+
"exportKind": "value",
46837+
"exported": Object {
46838+
"loc": Object {
46839+
"end": Object {
46840+
"column": 15,
46841+
"line": 1,
46842+
},
46843+
"start": Object {
46844+
"column": 12,
46845+
"line": 1,
46846+
},
46847+
},
46848+
"name": "foo",
46849+
"range": Array [
46850+
12,
46851+
15,
46852+
],
46853+
"type": "Identifier",
46854+
},
46855+
"loc": Object {
46856+
"end": Object {
46857+
"column": 27,
46858+
"line": 1,
46859+
},
46860+
"start": Object {
46861+
"column": 0,
46862+
"line": 1,
46863+
},
46864+
},
46865+
"range": Array [
46866+
0,
46867+
27,
46868+
],
46869+
"source": Object {
46870+
"loc": Object {
46871+
"end": Object {
46872+
"column": 26,
46873+
"line": 1,
46874+
},
46875+
"start": Object {
46876+
"column": 21,
46877+
"line": 1,
46878+
},
46879+
},
46880+
"range": Array [
46881+
21,
46882+
26,
46883+
],
46884+
"raw": "'bar'",
46885+
"type": "Literal",
46886+
"value": "bar",
46887+
},
46888+
"type": "ExportAllDeclaration",
46889+
},
46890+
],
46891+
"loc": Object {
46892+
"end": Object {
46893+
"column": 0,
46894+
"line": 2,
46895+
},
46896+
"start": Object {
46897+
"column": 0,
46898+
"line": 1,
46899+
},
46900+
},
46901+
"range": Array [
46902+
0,
46903+
28,
46904+
],
46905+
"sourceType": "module",
46906+
"tokens": Array [
46907+
Object {
46908+
"loc": Object {
46909+
"end": Object {
46910+
"column": 6,
46911+
"line": 1,
46912+
},
46913+
"start": Object {
46914+
"column": 0,
46915+
"line": 1,
46916+
},
46917+
},
46918+
"range": Array [
46919+
0,
46920+
6,
46921+
],
46922+
"type": "Keyword",
46923+
"value": "export",
46924+
},
46925+
Object {
46926+
"loc": Object {
46927+
"end": Object {
46928+
"column": 8,
46929+
"line": 1,
46930+
},
46931+
"start": Object {
46932+
"column": 7,
46933+
"line": 1,
46934+
},
46935+
},
46936+
"range": Array [
46937+
7,
46938+
8,
46939+
],
46940+
"type": "Punctuator",
46941+
"value": "*",
46942+
},
46943+
Object {
46944+
"loc": Object {
46945+
"end": Object {
46946+
"column": 11,
46947+
"line": 1,
46948+
},
46949+
"start": Object {
46950+
"column": 9,
46951+
"line": 1,
46952+
},
46953+
},
46954+
"range": Array [
46955+
9,
46956+
11,
46957+
],
46958+
"type": "Identifier",
46959+
"value": "as",
46960+
},
46961+
Object {
46962+
"loc": Object {
46963+
"end": Object {
46964+
"column": 15,
46965+
"line": 1,
46966+
},
46967+
"start": Object {
46968+
"column": 12,
46969+
"line": 1,
46970+
},
46971+
},
46972+
"range": Array [
46973+
12,
46974+
15,
46975+
],
46976+
"type": "Identifier",
46977+
"value": "foo",
46978+
},
46979+
Object {
46980+
"loc": Object {
46981+
"end": Object {
46982+
"column": 20,
46983+
"line": 1,
46984+
},
46985+
"start": Object {
46986+
"column": 16,
46987+
"line": 1,
46988+
},
46989+
},
46990+
"range": Array [
46991+
16,
46992+
20,
46993+
],
46994+
"type": "Identifier",
46995+
"value": "from",
46996+
},
46997+
Object {
46998+
"loc": Object {
46999+
"end": Object {
47000+
"column": 26,
47001+
"line": 1,
47002+
},
47003+
"start": Object {
47004+
"column": 21,
47005+
"line": 1,
47006+
},
47007+
},
47008+
"range": Array [
47009+
21,
47010+
26,
47011+
],
47012+
"type": "String",
47013+
"value": "'bar'",
47014+
},
47015+
Object {
47016+
"loc": Object {
47017+
"end": Object {
47018+
"column": 27,
47019+
"line": 1,
47020+
},
47021+
"start": Object {
47022+
"column": 26,
47023+
"line": 1,
47024+
},
47025+
},
47026+
"range": Array [
47027+
26,
47028+
27,
47029+
],
47030+
"type": "Punctuator",
47031+
"value": ";",
47032+
},
47033+
],
47034+
"type": "Program",
47035+
}
47036+
`;
47037+
4683247038
exports[`typescript fixtures/basics/export-type.src 1`] = `
4683347039
Object {
4683447040
"body": Array [
@@ -47846,6 +48052,7 @@ Object {
4784648052
"body": Array [
4784748053
Object {
4784848054
"exportKind": "type",
48055+
"exported": null,
4784948056
"loc": Object {
4785048057
"end": Object {
4785148058
"column": 25,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy