Skip to content

Commit cc68740

Browse files
authored
Port "Allow trailing commas after import attributes in ImportType" (#1818)
1 parent 117a38c commit cc68740

File tree

5 files changed

+8
-49
lines changed

5 files changed

+8
-49
lines changed

internal/parser/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,6 +2887,7 @@ func (p *Parser) parseImportType() *ast.Node {
28872887
}
28882888
p.parseExpected(ast.KindColonToken)
28892889
attributes = p.parseImportAttributes(currentToken, true /*skipKeyword*/)
2890+
p.parseOptional(ast.KindCommaToken)
28902891
if !p.parseExpected(ast.KindCloseBraceToken) {
28912892
if len(p.diagnostics) != 0 {
28922893
lastDiagnostic := p.diagnostics[len(p.diagnostics)-1]

testdata/baselines/reference/submodule/conformance/importAttributes10.errors.txt

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
b.ts(7,35): error TS2732: Cannot find module './a.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
2-
b.ts(10,4): error TS1005: '}' expected.
3-
b.ts(11,1): error TS1128: Declaration or statement expected.
4-
b.ts(11,2): error TS1128: Declaration or statement expected.
52
b.ts(13,35): error TS2732: Cannot find module './a.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
63
b.ts(19,35): error TS2732: Cannot find module './a.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
7-
b.ts(22,4): error TS1005: '}' expected.
8-
b.ts(22,5): error TS1128: Declaration or statement expected.
4+
b.ts(22,5): error TS1005: '}' expected.
95
b.ts(23,1): error TS1128: Declaration or statement expected.
106
b.ts(23,2): error TS1128: Declaration or statement expected.
117
b.ts(25,35): error TS2732: Cannot find module './a.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
@@ -15,7 +11,7 @@ b.ts(27,18): error TS1478: Identifier or string literal expected.
1511
==== a.json (0 errors) ====
1612
{ "key": "value" }
1713

18-
==== b.ts (12 errors) ====
14+
==== b.ts (8 errors) ====
1915
declare global {
2016
interface ImportAttributes {
2117
type: "json"
@@ -28,14 +24,7 @@ b.ts(27,18): error TS1478: Identifier or string literal expected.
2824
with: {
2925
type: "json"
3026
},
31-
~
32-
!!! error TS1005: '}' expected.
33-
!!! related TS1007 b.ts:7:47: The parser expected to find a '}' to match the '{' token here.
3427
});
35-
~
36-
!!! error TS1128: Declaration or statement expected.
37-
~
38-
!!! error TS1128: Declaration or statement expected.
3928

4029
export type Test2 = typeof import("./a.json", {
4130
~~~~~~~~~~
@@ -51,11 +40,9 @@ b.ts(27,18): error TS1478: Identifier or string literal expected.
5140
with: {
5241
type: "json"
5342
},,
54-
~
43+
~
5544
!!! error TS1005: '}' expected.
5645
!!! related TS1007 b.ts:19:47: The parser expected to find a '}' to match the '{' token here.
57-
~
58-
!!! error TS1128: Declaration or statement expected.
5946
});
6047
~
6148
!!! error TS1128: Declaration or statement expected.

testdata/baselines/reference/submodule/conformance/importAttributes10.errors.txt.diff

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
--- old.importAttributes10.errors.txt
22
+++ new.importAttributes10.errors.txt
33
@@= skipped -0, +0 lines =@@
4-
-b.ts(22,5): error TS1005: '}' expected.
54
+b.ts(7,35): error TS2732: Cannot find module './a.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
6-
+b.ts(10,4): error TS1005: '}' expected.
7-
+b.ts(11,1): error TS1128: Declaration or statement expected.
8-
+b.ts(11,2): error TS1128: Declaration or statement expected.
95
+b.ts(13,35): error TS2732: Cannot find module './a.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
106
+b.ts(19,35): error TS2732: Cannot find module './a.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
11-
+b.ts(22,4): error TS1005: '}' expected.
12-
+b.ts(22,5): error TS1128: Declaration or statement expected.
7+
b.ts(22,5): error TS1005: '}' expected.
138
b.ts(23,1): error TS1128: Declaration or statement expected.
149
b.ts(23,2): error TS1128: Declaration or statement expected.
1510
+b.ts(25,35): error TS2732: Cannot find module './a.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
@@ -20,11 +15,11 @@
2015
{ "key": "value" }
2116

2217
-==== b.ts (4 errors) ====
23-
+==== b.ts (12 errors) ====
18+
+==== b.ts (8 errors) ====
2419
declare global {
2520
interface ImportAttributes {
2621
type: "json"
27-
@@= skipped -14, +22 lines =@@
22+
@@= skipped -14, +18 lines =@@
2823
}
2924

3025
export type Test1 = typeof import("./a.json", {
@@ -33,14 +28,7 @@
3328
with: {
3429
type: "json"
3530
},
36-
+ ~
37-
+!!! error TS1005: '}' expected.
38-
+!!! related TS1007 b.ts:7:47: The parser expected to find a '}' to match the '{' token here.
3931
});
40-
+ ~
41-
+!!! error TS1128: Declaration or statement expected.
42-
+ ~
43-
+!!! error TS1128: Declaration or statement expected.
4432

4533
export type Test2 = typeof import("./a.json", {
4634
+ ~~~~~~~~~~
@@ -56,16 +44,7 @@
5644
with: {
5745
type: "json"
5846
},,
59-
- ~
60-
+ ~
61-
!!! error TS1005: '}' expected.
62-
!!! related TS1007 b.ts:19:47: The parser expected to find a '}' to match the '{' token here.
63-
+ ~
64-
+!!! error TS1128: Declaration or statement expected.
65-
});
66-
~
67-
!!! error TS1128: Declaration or statement expected.
68-
@@= skipped -25, +40 lines =@@
47+
@@= skipped -25, +31 lines =@@
6948
!!! error TS1128: Declaration or statement expected.
7049

7150
export type Test4 = typeof import("./a.json", {

testdata/baselines/reference/submodule/conformance/importAttributes10.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,3 @@ export type Test4 = typeof import("./a.json", {
3939
"use strict";
4040
Object.defineProperty(exports, "__esModule", { value: true });
4141
;
42-
;

testdata/baselines/reference/submodule/conformance/importAttributes10.js.diff

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

0 commit comments

Comments
 (0)