Skip to content

Commit 50b93bc

Browse files
authored
Allow trailing commas after import attributes in ImportType (#61920)
1 parent 78c1679 commit 50b93bc

File tree

6 files changed

+246
-0
lines changed

6 files changed

+246
-0
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,6 +4564,7 @@ namespace Parser {
45644564
}
45654565
parseExpected(SyntaxKind.ColonToken);
45664566
attributes = parseImportAttributes(currentToken as SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword, /*skipKeyword*/ true);
4567+
parseOptional(SyntaxKind.CommaToken);
45674568
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
45684569
const lastError = lastOrUndefined(parseDiagnostics);
45694570
if (lastError && lastError.code === Diagnostics._0_expected.code) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
b.ts(22,5): error TS1005: '}' expected.
2+
b.ts(23,1): error TS1128: Declaration or statement expected.
3+
b.ts(23,2): error TS1128: Declaration or statement expected.
4+
b.ts(27,18): error TS1478: Identifier or string literal expected.
5+
6+
7+
==== ./a.json (0 errors) ====
8+
{ "key": "value" }
9+
10+
==== ./b.ts (4 errors) ====
11+
declare global {
12+
interface ImportAttributes {
13+
type: "json"
14+
}
15+
}
16+
17+
export type Test1 = typeof import("./a.json", {
18+
with: {
19+
type: "json"
20+
},
21+
});
22+
23+
export type Test2 = typeof import("./a.json", {
24+
with: {
25+
type: "json",
26+
}
27+
});
28+
29+
export type Test3 = typeof import("./a.json", {
30+
with: {
31+
type: "json"
32+
},,
33+
~
34+
!!! error TS1005: '}' expected.
35+
!!! related TS1007 b.ts:19:47: The parser expected to find a '}' to match the '{' token here.
36+
});
37+
~
38+
!!! error TS1128: Declaration or statement expected.
39+
~
40+
!!! error TS1128: Declaration or statement expected.
41+
42+
export type Test4 = typeof import("./a.json", {
43+
with: {
44+
type: "json",,
45+
~
46+
!!! error TS1478: Identifier or string literal expected.
47+
}
48+
});
49+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//// [tests/cases/conformance/importAttributes/importAttributes10.ts] ////
2+
3+
//// [a.json]
4+
{ "key": "value" }
5+
6+
//// [b.ts]
7+
declare global {
8+
interface ImportAttributes {
9+
type: "json"
10+
}
11+
}
12+
13+
export type Test1 = typeof import("./a.json", {
14+
with: {
15+
type: "json"
16+
},
17+
});
18+
19+
export type Test2 = typeof import("./a.json", {
20+
with: {
21+
type: "json",
22+
}
23+
});
24+
25+
export type Test3 = typeof import("./a.json", {
26+
with: {
27+
type: "json"
28+
},,
29+
});
30+
31+
export type Test4 = typeof import("./a.json", {
32+
with: {
33+
type: "json",,
34+
}
35+
});
36+
37+
38+
//// [b.js]
39+
"use strict";
40+
Object.defineProperty(exports, "__esModule", { value: true });
41+
;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//// [tests/cases/conformance/importAttributes/importAttributes10.ts] ////
2+
3+
=== ./a.json ===
4+
{ "key": "value" }
5+
>"key" : Symbol("key", Decl(a.json, 0, 1))
6+
7+
=== ./b.ts ===
8+
declare global {
9+
>global : Symbol(global, Decl(b.ts, 0, 0))
10+
11+
interface ImportAttributes {
12+
>ImportAttributes : Symbol(ImportAttributes, Decl(lib.es5.d.ts, --, --), Decl(b.ts, 0, 16))
13+
14+
type: "json"
15+
>type : Symbol(ImportAttributes.type, Decl(b.ts, 1, 32))
16+
}
17+
}
18+
19+
export type Test1 = typeof import("./a.json", {
20+
>Test1 : Symbol(Test1, Decl(b.ts, 4, 1))
21+
22+
with: {
23+
type: "json"
24+
},
25+
});
26+
27+
export type Test2 = typeof import("./a.json", {
28+
>Test2 : Symbol(Test2, Decl(b.ts, 10, 3))
29+
30+
with: {
31+
type: "json",
32+
}
33+
});
34+
35+
export type Test3 = typeof import("./a.json", {
36+
>Test3 : Symbol(Test3, Decl(b.ts, 16, 3))
37+
38+
with: {
39+
type: "json"
40+
},,
41+
});
42+
43+
export type Test4 = typeof import("./a.json", {
44+
>Test4 : Symbol(Test4, Decl(b.ts, 22, 3))
45+
46+
with: {
47+
type: "json",,
48+
}
49+
});
50+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//// [tests/cases/conformance/importAttributes/importAttributes10.ts] ////
2+
3+
=== ./a.json ===
4+
{ "key": "value" }
5+
>{ "key": "value" } : { key: string; }
6+
> : ^^^^^^^^^^^^^^^^
7+
>"key" : string
8+
> : ^^^^^^
9+
>"value" : "value"
10+
> : ^^^^^^^
11+
12+
=== ./b.ts ===
13+
declare global {
14+
>global : any
15+
> : ^^^
16+
17+
interface ImportAttributes {
18+
type: "json"
19+
>type : "json"
20+
> : ^^^^^^
21+
}
22+
}
23+
24+
export type Test1 = typeof import("./a.json", {
25+
>Test1 : { key: string; }
26+
> : ^^^^^^^^^^^^^^^^
27+
28+
with: {
29+
type: "json"
30+
>type : any
31+
> : ^^^
32+
33+
},
34+
});
35+
36+
export type Test2 = typeof import("./a.json", {
37+
>Test2 : { key: string; }
38+
> : ^^^^^^^^^^^^^^^^
39+
40+
with: {
41+
type: "json",
42+
>type : any
43+
> : ^^^
44+
}
45+
});
46+
47+
export type Test3 = typeof import("./a.json", {
48+
>Test3 : { key: string; }
49+
> : ^^^^^^^^^^^^^^^^
50+
51+
with: {
52+
type: "json"
53+
>type : any
54+
> : ^^^
55+
56+
},,
57+
});
58+
59+
export type Test4 = typeof import("./a.json", {
60+
>Test4 : { key: string; }
61+
> : ^^^^^^^^^^^^^^^^
62+
63+
with: {
64+
type: "json",,
65+
>type : any
66+
> : ^^^
67+
}
68+
});
69+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @module: nodenext
2+
// @target: esnext
3+
// @moduleResolution: nodenext
4+
// @filename: ./a.json
5+
{ "key": "value" }
6+
7+
// @filename: ./b.ts
8+
declare global {
9+
interface ImportAttributes {
10+
type: "json"
11+
}
12+
}
13+
14+
export type Test1 = typeof import("./a.json", {
15+
with: {
16+
type: "json"
17+
},
18+
});
19+
20+
export type Test2 = typeof import("./a.json", {
21+
with: {
22+
type: "json",
23+
}
24+
});
25+
26+
export type Test3 = typeof import("./a.json", {
27+
with: {
28+
type: "json"
29+
},,
30+
});
31+
32+
export type Test4 = typeof import("./a.json", {
33+
with: {
34+
type: "json",,
35+
}
36+
});

0 commit comments

Comments
 (0)