Skip to content

Commit

Permalink
feat(typescript-estree): support type-only module specifiers (#4076)
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Nov 12, 2021
1 parent 939d8ea commit 77baa92
Show file tree
Hide file tree
Showing 40 changed files with 834 additions and 13 deletions.
2 changes: 2 additions & 0 deletions packages/ast-spec/src/special/ExportSpecifier/spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BaseNode } from '../../base/BaseNode';
import type { ExportKind } from '../../declaration/ExportAndImportKind';
import type { Identifier } from '../../expression/Identifier/spec';

export interface ExportSpecifier extends BaseNode {
type: AST_NODE_TYPES.ExportSpecifier;
local: Identifier;
exported: Identifier;
exportKind: ExportKind;
}
2 changes: 2 additions & 0 deletions packages/ast-spec/src/special/ImportSpecifier/spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BaseNode } from '../../base/BaseNode';
import type { ImportKind } from '../../declaration/ExportAndImportKind';
import type { Identifier } from '../../expression/Identifier/spec';

export interface ImportSpecifier extends BaseNode {
type: AST_NODE_TYPES.ImportSpecifier;
local: Identifier;
imported: Identifier;
importKind: ImportKind;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { type A, type B } from "mod";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { type A, type B } from "mod";
2 changes: 2 additions & 0 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,7 @@ export class Converter {
type: AST_NODE_TYPES.ImportSpecifier,
local: this.convertChild(node.name),
imported: this.convertChild(node.propertyName ?? node.name),
importKind: node.isTypeOnly ? 'type' : 'value',
});

case SyntaxKind.ImportClause: {
Expand Down Expand Up @@ -1841,6 +1842,7 @@ export class Converter {
type: AST_NODE_TYPES.ExportSpecifier,
local: this.convertChild(node.propertyName ?? node.name),
exported: this.convertChild(node.name),
exportKind: node.isTypeOnly ? 'type' : 'value',
});

case SyntaxKind.ExportAssignment:
Expand Down
12 changes: 0 additions & 12 deletions packages/typescript-estree/tests/ast-alignment/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,6 @@ export function preprocessBabylonAST(ast: File): any {
Object.keys(node).forEach(key => delete node[key]);
Object.assign(node, typeAnnotation);
},
/**
* @see https://github.com/babel/babel/pull/13802
*/
ImportSpecifier(node) {
delete node.importKind;
},
/**
* @see https://github.com/babel/babel/pull/13802
*/
ExportSpecifier(node) {
delete node.exportKind;
},
/*
* Babel's AST has no `assertions` property if there are no assertions.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

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

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

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

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

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/type-parameters-comments-heritage.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Object {
},
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Object {
},
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Object {
},
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Object {
},
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -95,6 +96,7 @@ Object {
"type": "ExportSpecifier",
},
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Object {
},
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Object {
},
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -95,6 +96,7 @@ Object {
"type": "ExportSpecifier",
},
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Object {
"source": null,
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Object {
"source": null,
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Object {
"source": null,
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -77,6 +78,7 @@ Object {
"type": "ExportSpecifier",
},
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Object {
"source": null,
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Object {
"source": null,
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -77,6 +78,7 @@ Object {
"type": "ExportSpecifier",
},
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Object {
"source": null,
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -77,6 +78,7 @@ Object {
"type": "ExportSpecifier",
},
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Object {
"type": "ImportDefaultSpecifier",
},
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object {
},
"specifiers": Array [
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object {
},
"specifiers": Array [
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object {
},
"specifiers": Array [
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -94,6 +95,7 @@ Object {
"type": "ImportSpecifier",
},
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object {
},
"specifiers": Array [
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object {
},
"specifiers": Array [
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -94,6 +95,7 @@ Object {
"type": "ImportSpecifier",
},
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object {
},
"specifiers": Array [
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -94,6 +95,7 @@ Object {
"type": "ImportSpecifier",
},
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object {
},
"specifiers": Array [
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Object {
"source": null,
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Object {
"source": null,
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Object {
},
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Object {
},
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Object {
"source": null,
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Object {
},
"specifiers": Array [
Object {
"exportKind": "value",
"exported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Object {
"type": "ImportDefaultSpecifier",
},
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object {
},
"specifiers": Array [
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object {
},
"specifiers": Array [
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -94,6 +95,7 @@ Object {
"type": "ImportSpecifier",
},
Object {
"importKind": "value",
"imported": Object {
"loc": Object {
"end": Object {
Expand Down
Loading

0 comments on commit 77baa92

Please sign in to comment.