Skip to content

Commit 432a7ff

Browse files
authored
fix(parser/typescript): parse import("./a", {with:{},}) (#17465)
1 parent 741cbd2 commit 432a7ff

File tree

9 files changed

+213
-3
lines changed

9 files changed

+213
-3
lines changed

eslint/babel-eslint-parser/test/typescript-estree.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ function deeplyRemoveProperties(obj, props) {
341341
// Pending release https://github.com/microsoft/TypeScript/pull/61764
342342
"typescript/explicit-resource-management/valid-for-using-declaration-binding-of/input.js",
343343

344+
// Pending ts-eslint upgrade
345+
"typescript/types/import-type-options-with-trailing-comma/input.ts",
346+
344347
// ts-eslint/tsc does not support arrow generic in tsx mode
345348
"typescript/arrow-function/async-await-null/input.ts",
346349
"typescript/arrow-function/async-generic-after-await/input.ts",

packages/babel-parser/src/plugins/typescript/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
646646
this.expect(tt.colon);
647647
withProperty.value = this.tsParseImportTypeWithPropertyValue();
648648
node.properties = [this.finishObjectProperty(withProperty)];
649+
this.eat(tt.comma);
649650
this.expect(tt.braceR);
650651
return this.finishNode(node, "ObjectExpression");
651652
}

packages/babel-parser/test/fixtures/typescript/types/invalid-import-type-options-with-trailing-comma/input.ts renamed to packages/babel-parser/test/fixtures/typescript/types/import-type-options-with-trailing-comma-babel-7/input.ts

File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"BABEL_8_BREAKING": false
3+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}},
4+
"program": {
5+
"type": "Program",
6+
"start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}},
7+
"sourceType": "module",
8+
"interpreter": null,
9+
"body": [
10+
{
11+
"type": "VariableDeclaration",
12+
"start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}},
13+
"declarations": [
14+
{
15+
"type": "VariableDeclarator",
16+
"start":4,"end":61,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":61,"index":61}},
17+
"id": {
18+
"type": "Identifier",
19+
"start":4,"end":61,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":61,"index":61},"identifierName":"x"},
20+
"name": "x",
21+
"typeAnnotation": {
22+
"type": "TSTypeAnnotation",
23+
"start":5,"end":61,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":61,"index":61}},
24+
"typeAnnotation": {
25+
"type": "TSTypeQuery",
26+
"start":7,"end":61,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":61,"index":61}},
27+
"exprName": {
28+
"type": "TSImportType",
29+
"start":14,"end":61,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":61,"index":61}},
30+
"argument": {
31+
"type": "StringLiteral",
32+
"start":21,"end":31,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":31,"index":31}},
33+
"extra": {
34+
"rawValue": "foo.json",
35+
"raw": "\"foo.json\""
36+
},
37+
"value": "foo.json"
38+
},
39+
"options": {
40+
"type": "ObjectExpression",
41+
"start":33,"end":60,"loc":{"start":{"line":1,"column":33,"index":33},"end":{"line":1,"column":60,"index":60}},
42+
"properties": [
43+
{
44+
"type": "ObjectProperty",
45+
"start":35,"end":57,"loc":{"start":{"line":1,"column":35,"index":35},"end":{"line":1,"column":57,"index":57}},
46+
"method": false,
47+
"key": {
48+
"type": "Identifier",
49+
"start":35,"end":39,"loc":{"start":{"line":1,"column":35,"index":35},"end":{"line":1,"column":39,"index":39},"identifierName":"with"},
50+
"name": "with"
51+
},
52+
"computed": false,
53+
"shorthand": false,
54+
"value": {
55+
"type": "ObjectExpression",
56+
"start":41,"end":57,"loc":{"start":{"line":1,"column":41,"index":41},"end":{"line":1,"column":57,"index":57}},
57+
"properties": [
58+
{
59+
"type": "ObjectProperty",
60+
"start":43,"end":55,"loc":{"start":{"line":1,"column":43,"index":43},"end":{"line":1,"column":55,"index":55}},
61+
"method": false,
62+
"key": {
63+
"type": "Identifier",
64+
"start":43,"end":47,"loc":{"start":{"line":1,"column":43,"index":43},"end":{"line":1,"column":47,"index":47},"identifierName":"type"},
65+
"name": "type"
66+
},
67+
"computed": false,
68+
"shorthand": false,
69+
"value": {
70+
"type": "StringLiteral",
71+
"start":49,"end":55,"loc":{"start":{"line":1,"column":49,"index":49},"end":{"line":1,"column":55,"index":55}},
72+
"extra": {
73+
"rawValue": "json",
74+
"raw": "\"json\""
75+
},
76+
"value": "json"
77+
}
78+
}
79+
]
80+
}
81+
}
82+
]
83+
}
84+
}
85+
}
86+
}
87+
},
88+
"init": null
89+
}
90+
],
91+
"kind": "let"
92+
}
93+
],
94+
"directives": [],
95+
"extra": {
96+
"topLevelAwait": false
97+
}
98+
}
99+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let x: typeof import("foo.json", { with: { type: "json" }, });
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"BABEL_8_BREAKING": true
3+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}},
4+
"program": {
5+
"type": "Program",
6+
"start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}},
7+
"sourceType": "module",
8+
"interpreter": null,
9+
"body": [
10+
{
11+
"type": "VariableDeclaration",
12+
"start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}},
13+
"declarations": [
14+
{
15+
"type": "VariableDeclarator",
16+
"start":4,"end":61,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":61,"index":61}},
17+
"id": {
18+
"type": "Identifier",
19+
"start":4,"end":61,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":61,"index":61},"identifierName":"x"},
20+
"name": "x",
21+
"typeAnnotation": {
22+
"type": "TSTypeAnnotation",
23+
"start":5,"end":61,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":61,"index":61}},
24+
"typeAnnotation": {
25+
"type": "TSTypeQuery",
26+
"start":7,"end":61,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":61,"index":61}},
27+
"exprName": {
28+
"type": "TSImportType",
29+
"start":14,"end":61,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":61,"index":61}},
30+
"argument": {
31+
"type": "TSLiteralType",
32+
"start":21,"end":31,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":31,"index":31}},
33+
"literal": {
34+
"type": "StringLiteral",
35+
"start":21,"end":31,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":31,"index":31}},
36+
"extra": {
37+
"rawValue": "foo.json",
38+
"raw": "\"foo.json\""
39+
},
40+
"value": "foo.json"
41+
}
42+
},
43+
"options": {
44+
"type": "ObjectExpression",
45+
"start":33,"end":60,"loc":{"start":{"line":1,"column":33,"index":33},"end":{"line":1,"column":60,"index":60}},
46+
"properties": [
47+
{
48+
"type": "ObjectProperty",
49+
"start":35,"end":57,"loc":{"start":{"line":1,"column":35,"index":35},"end":{"line":1,"column":57,"index":57}},
50+
"method": false,
51+
"key": {
52+
"type": "Identifier",
53+
"start":35,"end":39,"loc":{"start":{"line":1,"column":35,"index":35},"end":{"line":1,"column":39,"index":39},"identifierName":"with"},
54+
"name": "with"
55+
},
56+
"computed": false,
57+
"shorthand": false,
58+
"value": {
59+
"type": "ObjectExpression",
60+
"start":41,"end":57,"loc":{"start":{"line":1,"column":41,"index":41},"end":{"line":1,"column":57,"index":57}},
61+
"properties": [
62+
{
63+
"type": "ObjectProperty",
64+
"start":43,"end":55,"loc":{"start":{"line":1,"column":43,"index":43},"end":{"line":1,"column":55,"index":55}},
65+
"method": false,
66+
"key": {
67+
"type": "Identifier",
68+
"start":43,"end":47,"loc":{"start":{"line":1,"column":43,"index":43},"end":{"line":1,"column":47,"index":47},"identifierName":"type"},
69+
"name": "type"
70+
},
71+
"computed": false,
72+
"shorthand": false,
73+
"value": {
74+
"type": "StringLiteral",
75+
"start":49,"end":55,"loc":{"start":{"line":1,"column":49,"index":49},"end":{"line":1,"column":55,"index":55}},
76+
"extra": {
77+
"rawValue": "json",
78+
"raw": "\"json\""
79+
},
80+
"value": "json"
81+
}
82+
}
83+
]
84+
}
85+
}
86+
]
87+
}
88+
}
89+
}
90+
}
91+
},
92+
"init": null
93+
}
94+
],
95+
"kind": "let"
96+
}
97+
],
98+
"directives": [],
99+
"extra": {
100+
"topLevelAwait": false
101+
}
102+
}
103+
}

packages/babel-parser/test/fixtures/typescript/types/invalid-import-type-options-with-trailing-comma/options.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)