Skip to content

Commit

Permalink
feat(typescript-estree): support 3.8 export * as ns
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Mar 9, 2020
1 parent 55a58ff commit ad11fb8
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 4 deletions.
50 changes: 50 additions & 0 deletions packages/parser/tests/lib/__snapshots__/typescript.ts.snap
Expand Up @@ -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,
Expand Down
@@ -0,0 +1 @@
export * as foo from 'bar';
9 changes: 5 additions & 4 deletions packages/typescript-estree/src/convert.ts
Expand Up @@ -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<TSESTree.ExportNamedDeclaration>(node, {
type: AST_NODE_TYPES.ExportNamedDeclaration,
source: this.convertChild(node.moduleSpecifier),
Expand All @@ -1593,6 +1590,10 @@ export class Converter {
return this.createNode<TSESTree.ExportAllDeclaration>(node, {
type: AST_NODE_TYPES.ExportAllDeclaration,
source: this.convertChild(node.moduleSpecifier),
exported:
node.exportClause?.kind === SyntaxKind.NamespaceExport
? this.convertChild(node.exportClause.name)
: null,
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/typescript-estree/src/ts-estree/ts-estree.ts
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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: [
/**
Expand Down
9 changes: 9 additions & 0 deletions packages/typescript-estree/tests/ast-alignment/utils.ts
Expand Up @@ -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;
}
},
},
);
}
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -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"`;
Expand Down
205 changes: 205 additions & 0 deletions packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
Expand Up @@ -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 [
Expand Down

0 comments on commit ad11fb8

Please sign in to comment.