8000 fix(typescript-estree): [ts 4.2] add support for import type equal de… · omril1/typescript-eslint@6a25faf · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a25faf

Browse files
authored
fix(typescript-estree): [ts 4.2] add support for import type equal declaration (typescript-eslint#3189)
1 parent 56af989 commit 6a25faf

File tree

12 files changed

+593
-62
lines changed

12 files changed

+593
-62
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import type foo = require('bar');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export import type foo = require('bar');

packages/types/src/ts-estree.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,7 @@ export interface TSImportEqualsDeclaration extends BaseNode {
14231423
type: AST_NODE_TYPES.TSImportEqualsDeclaration;
14241424
id: Identifier;
14251425
moduleReference: EntityName | TSExternalModuleReference;
1426+
importKind: 'type' | 'value';
14261427
isExport: boolean;
14271428
}
14281429

packages/typescript-estree/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
"devDependencies": {
5353
"@babel/code-frame": "^7.12.13",
54-
"@babel/parser": "^7.13.4",
54+
"@babel/parser": "^7.13.11",
5555
"@babel/types": "^7.13.0",
5656
"@types/babel__code-frame": "*",
5757
"@types/debug": "*",

packages/typescript-estree/src/convert.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,7 @@ export class Converter {
26902690
type: AST_NODE_TYPES.TSImportEqualsDeclaration,
26912691
id: this.convertChild(node.name),
26922692
moduleReference: this.convertChild(node.moduleReference),
2693+
importKind: node.isTypeOnly ? 'type' : 'value',
26932694
isExport: hasModifier(SyntaxKind.ExportKeyword, node),
26942695
});
26952696
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ tester.addFixturePatternConfig('typescript/basics', {
395395
'export-assignment',
396396
'import-equal-declaration',
397397
'import-export-equal-declaration',
398+
'import-equal-type-declaration',
399+
'import-export-equal-type-declaration',
398400
// babel treats declare and types as not a module
399401
'export-declare-const-named-enum',
400402
'export-declare-named-enum',

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,8 +1929,12 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e
19291929

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

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

1936+
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"`;
1937+
19341938
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/import-type-default.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
19351939

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

packages/typescript-estree/tests/snapshots/typescript/basics/import-equal-declaration.src.ts.shot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Object {
2222
],
2323
"type": "Identifier",
2424
},
25+
"importKind": "value",
2526
"isExport": false,
2627
"loc": Object {
2728
"end": Object {
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`typescript basics import-equal-type-declaration.src 1`] = `
4+
Object {
5+
"body": Array [
6+
Object {
7+
"id": Object {
8+
"loc": Object {
9+
"end": Object {
10+
"column": 15,
11+
"line": 1,
12+
},
13+
"start": Object {
14+
"column": 12,
15+
"line": 1,
16+
},
17+
},
18+
"name": "foo",
19+
"range": Array [
20+
12,
21+
15,
22+
],
23+
"type": "Identifier",
24+
},
25+
"importKind": "type",
26+
"isExport": false,
27+
"loc": Object {
28+
"end": Object {
29+
"column": 33,
30+
"line": 1,
31+
},
32+
"start": Object {
33+
"column": 0,
34+
"line": 1,
35+
},
36+
},
37+
"moduleReference": Object {
38+
"expression": Object {
39+
"loc": Object {
40+
"end": Object {
41+
"column": 31,
42+
"line": 1,
43+
},
44+
"start": Object {
45+
"column": 26,
46+
"line": 1,
47+
},
48+
},
49+
"range": Array [
50+
26,
51+
31,
52+
],
53+
"raw": "'bar'",
54+
"type": "Literal",
55+
"value": "bar",
56+
},
57+
"loc": Object {
58+
"end": Object {
59+
"column": 32,
60+
"line": 1,
61+
},
62+
"start": Object {
63+
"column": 18,
64+
"line": 1,
65+
},
66+
},
67+
"range": Array [
68+
18,
69+
32,
70+
],
71+
"type": "TSExternalModuleReference",
72+
},
73+
"range": Array [
74+
0,
75+
33,
76+
],
77+
"type": "TSImportEqualsDeclaration",
78+
},
79+
],
80+
"comments": Array [],
81+
"loc": Object {
82+
"end": Object {
83+
"column": 0,
84+
"line": 2,
85+
},
86+
"start": Object {
87+
"column": 0,
88+
"line": 1,
89+
},
90+
},
91+
"range": Array [
92+
0,
93+
34,
94+
],
95+
"sourceType": "module",
96+
"tokens": Array [
97+
Object {
98+
"loc": Object {
99+
"end": Object {
100+
"column": 6,
101+
"line": 1,
102+
},
103+
"start": Object {
104+
"column": 0,
105+
"line": 1,
106+
},
107+
},
108+
"range": Array [
109+
0,
110+
6,
111+
],
112+
"type": "Keyword",
113+
"value": "import",
114+
},
115+
Object {
116+
"loc": Object {
117+
"end": Object {
118+
"column": 11,
119+
"line": 1,
120+
},
121+
"start": Object {
122+
"column": 7,
123+
"line": 1,
124+
},
125+
},
126+
"range": Array [
127+
7,
128+
11,
129+
],
130+
"type": "Identifier",
131+
"value": "type",
132+
},
133+
Object {
134+
"loc": Object {
135+
"end": Object {
136+
"column": 15,
137+
"line": 1,
138+
},
139+
"start": Object {
140+
"column": 12,
141+
"line": 1,
142+
},
143+
},
144+
"range": Array [
145+
12,
146+
15,
147+
],
148+
"type": "Identifier",
149+
"value": "foo",
150+
},
151+
Object {
152+
"loc": Object {
153+
"end": Object {
154+
"column": 17,
155+
"line": 1,
156+
},
157+
"start": Object {
158+
"column": 16,
159+
"line": 1,
160+
},
161+
},
162+
"range": Array [
163+
16,
164+
17,
165+
],
166+
"type": "Punctuator",
167+
"value": "=",
168+
},
169+
Object {
170+
"loc": Object {
171+
"end": Object {
172+
"column": 25,
173+
"line": 1,
174+
},
175+
"start": Object {
176+
"column": 18,
177+
"line": 1,
178+
},
179+
},
180+
"range": Array [
181+
18,
182+
25,
183+
],
184+
"type": "Identifier",
185+
"value": "require",
186+
},
187+
Object {
188+
"loc": Object {
189+
"end": Object {
190+
"column": 26,
191+
"line": 1,
192+
},
193+
"start": Object {
194+
"column": 25,
195+
"line": 1,
196+
},
197+
},
198+
"range": Array [
199+
25,
200+
26,
201+
],
202+
"type": "Punctuator",
203+
"value": "(",
204+
},
205+
Object {
206+
"loc": Object {
207+
"end": Object {
208+
"column": 31,
209+
"line": 1,
210+
},
211+
"start": Object {
212+
"column": 26,
213+
"line": 1,
214+
},
215+
},
216+
"range": Array [
217+
26,
218+
31,
219+
],
220+
"type": "String",
221+
"value": "'bar'",
222+
},
223+
Object {
224+
"loc": Object {
225+
"end": Object {
226+
"column": 32,
227+
"line": 1,
228+
},
229+
"start": Object {
230+
"column": 31,
231+
"line": 1,
232+
},
233+
},
234+
"range": Array [
235+
10000 31,
236+
32,
237+
],
238+
"type": "Punctuator",
239+
"value": ")",
240+
},
241+
Object {
242+
"loc": Object {
243+
"end": Object {
244+
"column": 33,
245+
"line": 1,
246+
},
247+
"start": Object {
248+
"column": 32,
249+
"line": 1,
250+
},
251+
},
252+
"range": Array [
253+
32,
254+
33,
255+
],
256+
"type": "Punctuator",
257+
"value": ";",
258+
},
259+
],
260+
"type": "Program",
261+
}
262+
`;

packages/typescript-estree/tests/snapshots/typescript/basics/import-export-equal-declaration.src.ts.shot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Object {
2222
],
2323
"type": "Identifier",
2424
},
25+
"importKind": "value",
2526
"isExport": true,
2627
"loc": Object {
2728
"end": Object {

0 commit comments

Comments
 (0)
0