Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typescript-estree): [ts 4.2] add support for import type equal declaration #3189

Merged
merged 1 commit into from Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
import type foo = require('bar');
@@ -0,0 +1 @@
export import type foo = require('bar');
1 change: 1 addition & 0 deletions packages/types/src/ts-estree.ts
Expand Up @@ -1423,6 +1423,7 @@ export interface TSImportEqualsDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSImportEqualsDeclaration;
id: Identifier;
moduleReference: EntityName | TSExternalModuleReference;
importKind: 'type' | 'value';
isExport: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-estree/package.json
Expand Up @@ -51,7 +51,7 @@
},
"devDependencies": {
"@babel/code-frame": "^7.12.13",
"@babel/parser": "^7.13.4",
"@babel/parser": "^7.13.11",
"@babel/types": "^7.13.0",
"@types/babel__code-frame": "*",
"@types/debug": "*",
Expand Down
1 change: 1 addition & 0 deletions packages/typescript-estree/src/convert.ts
Expand Up @@ -2690,6 +2690,7 @@ export class Converter {
type: AST_NODE_TYPES.TSImportEqualsDeclaration,
id: this.convertChild(node.name),
moduleReference: this.convertChild(node.moduleReference),
importKind: node.isTypeOnly ? 'type' : 'value',
isExport: hasModifier(SyntaxKind.ExportKeyword, node),
});
}
Expand Down
Expand Up @@ -395,6 +395,8 @@ tester.addFixturePatternConfig('typescript/basics', {
'export-assignment',
'import-equal-declaration',
'import-export-equal-declaration',
'import-equal-type-declaration',
'import-export-equal-type-declaration',
// babel treats declare and types as not a module
'export-declare-const-named-enum',
'export-declare-named-enum',
Expand Down
Expand Up @@ -1929,8 +1929,12 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

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

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

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

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

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

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/import-type-empty.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down
Expand Up @@ -22,6 +22,7 @@ Object {
],
"type": "Identifier",
},
"importKind": "value",
"isExport": false,
"loc": Object {
"end": Object {
Expand Down
@@ -0,0 +1,262 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`typescript basics import-equal-type-declaration.src 1`] = `
Object {
"body": Array [
Object {
"id": Object {
"loc": Object {
"end": Object {
"column": 15,
"line": 1,
},
"start": Object {
"column": 12,
"line": 1,
},
},
"name": "foo",
"range": Array [
12,
15,
],
"type": "Identifier",
},
"importKind": "type",
"isExport": false,
"loc": Object {
"end": Object {
"column": 33,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"moduleReference": Object {
"expression": Object {
"loc": Object {
"end": Object {
"column": 31,
"line": 1,
},
"start": Object {
"column": 26,
"line": 1,
},
},
"range": Array [
26,
31,
],
"raw": "'bar'",
"type": "Literal",
"value": "bar",
},
"loc": Object {
"end": Object {
"column": 32,
"line": 1,
},
"start": Object {
"column": 18,
"line": 1,
},
},
"range": Array [
18,
32,
],
"type": "TSExternalModuleReference",
},
"range": Array [
0,
33,
],
"type": "TSImportEqualsDeclaration",
},
],
"comments": Array [],
"loc": Object {
"end": Object {
"column": 0,
"line": 2,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
34,
],
"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": "import",
},
Object {
"loc": Object {
"end": Object {
"column": 11,
"line": 1,
},
"start": Object {
"column": 7,
"line": 1,
},
},
"range": Array [
7,
11,
],
"type": "Identifier",
"value": "type",
},
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": 17,
"line": 1,
},
"start": Object {
"column": 16,
"line": 1,
},
},
"range": Array [
16,
17,
],
"type": "Punctuator",
"value": "=",
},
Object {
"loc": Object {
"end": Object {
"column": 25,
"line": 1,
},
"start": Object {
"column": 18,
"line": 1,
},
},
"range": Array [
18,
25,
],
"type": "Identifier",
"value": "require",
},
Object {
"loc": Object {
"end": Object {
"column": 26,
"line": 1,
},
"start": Object {
"column": 25,
"line": 1,
},
},
"range": Array [
25,
26,
],
"type": "Punctuator",
"value": "(",
},
Object {
"loc": Object {
"end": Object {
"column": 31,
"line": 1,
},
"start": Object {
"column": 26,
"line": 1,
},
},
"range": Array [
26,
31,
],
"type": "String",
"value": "'bar'",
},
Object {
"loc": Object {
"end": Object {
"column": 32,
"line": 1,
},
"start": Object {
"column": 31,
"line": 1,
},
},
"range": Array [
31,
32,
],
"type": "Punctuator",
"value": ")",
},
Object {
"loc": Object {
"end": Object {
"column": 33,
"line": 1,
},
"start": Object {
"column": 32,
"line": 1,
},
},
"range": Array [
32,
33,
],
"type": "Punctuator",
"value": ";",
},
],
"type": "Program",
}
`;
Expand Up @@ -22,6 +22,7 @@ Object {
],
"type": "Identifier",
},
"importKind": "value",
"isExport": true,
"loc": Object {
"end": Object {
Expand Down