Skip to content

Commit 3afe2d6

Browse files
authored
Resolve parsingContextErrors TODO (#50011)
* Add a test with broken code * Resolve TODO
1 parent bcd22b4 commit 3afe2d6

7 files changed

+280
-1
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,10 @@
14971497
"category": "Error",
14981498
"code": 1477
14991499
},
1500+
"Identifier or string literal expected.": {
1501+
"category": "Error",
1502+
"code": 1478
1503+
},
15001504

15011505
"The types of '{0}' are incompatible between these types.": {
15021506
"category": "Error",

src/compiler/parser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2780,7 +2780,9 @@ namespace ts {
27802780
case ParsingContext.ImportOrExportSpecifiers: return parseErrorAtCurrentToken(Diagnostics.Identifier_expected);
27812781
case ParsingContext.JsxAttributes: return parseErrorAtCurrentToken(Diagnostics.Identifier_expected);
27822782
case ParsingContext.JsxChildren: return parseErrorAtCurrentToken(Diagnostics.Identifier_expected);
2783-
default: return [undefined!]; // TODO: GH#18217 `default: Debug.assertNever(context);`
2783+
case ParsingContext.AssertEntries: return parseErrorAtCurrentToken(Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
2784+
case ParsingContext.Count: return Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
2785+
default: Debug.assertNever(context);
27842786
}
27852787
}
27862788

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/index.ts(2,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
2+
/index.ts(2,32): error TS1478: Identifier or string literal expected.
3+
/index.ts(2,32): error TS2695: Left side of comma operator is unused and has no side effects.
4+
/index.ts(2,55): error TS1005: ';' expected.
5+
/index.ts(2,66): error TS1128: Declaration or statement expected.
6+
/index.ts(2,68): error TS1128: Declaration or statement expected.
7+
/index.ts(2,69): error TS1128: Declaration or statement expected.
8+
/index.ts(2,70): error TS1128: Declaration or statement expected.
9+
/index.ts(2,71): error TS2304: Cannot find name 'RequireInterface'.
10+
/index.ts(3,36): error TS1005: ':' expected.
11+
/index.ts(3,70): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'.
12+
/index.ts(5,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
13+
/index.ts(5,59): error TS1478: Identifier or string literal expected.
14+
/index.ts(5,59): error TS2695: Left side of comma operator is unused and has no side effects.
15+
/index.ts(5,82): error TS1005: ';' expected.
16+
/index.ts(5,93): error TS1128: Declaration or statement expected.
17+
/index.ts(5,95): error TS1128: Declaration or statement expected.
18+
/index.ts(5,96): error TS1128: Declaration or statement expected.
19+
/index.ts(5,97): error TS1128: Declaration or statement expected.
20+
/index.ts(5,98): error TS1434: Unexpected keyword or identifier.
21+
/index.ts(5,98): error TS2304: Cannot find name 'RequireInterface'.
22+
/index.ts(5,114): error TS1128: Declaration or statement expected.
23+
/index.ts(6,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
24+
/index.ts(6,59): error TS1478: Identifier or string literal expected.
25+
/index.ts(6,59): error TS2695: Left side of comma operator is unused and has no side effects.
26+
/index.ts(6,82): error TS1005: ';' expected.
27+
/index.ts(6,92): error TS1128: Declaration or statement expected.
28+
/index.ts(6,94): error TS1128: Declaration or statement expected.
29+
/index.ts(6,95): error TS1128: Declaration or statement expected.
30+
/index.ts(6,96): error TS1128: Declaration or statement expected.
31+
/index.ts(6,97): error TS1434: Unexpected keyword or identifier.
32+
/index.ts(6,97): error TS2304: Cannot find name 'ImportInterface'.
33+
/index.ts(6,112): error TS1128: Declaration or statement expected.
34+
35+
36+
==== /index.ts (33 errors) ====
37+
export type LocalInterface =
38+
& import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface
39+
~~~~~~~~~~~~~~~~~~~~~~~~~
40+
!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
41+
~~~~
42+
!!! error TS1478: Identifier or string literal expected.
43+
~~~~
44+
!!! error TS2695: Left side of comma operator is unused and has no side effects.
45+
~
46+
!!! error TS1005: ';' expected.
47+
~
48+
!!! error TS1128: Declaration or statement expected.
49+
~
50+
!!! error TS1128: Declaration or statement expected.
51+
~
52+
!!! error TS1128: Declaration or statement expected.
53+
~
54+
!!! error TS1128: Declaration or statement expected.
55+
~~~~~~~~~~~~~~~~
56+
!!! error TS2304: Cannot find name 'RequireInterface'.
57+
& import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface;
58+
~
59+
!!! error TS1005: ':' expected.
60+
~~~~~~~~~~~~~~~
61+
!!! error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'.
62+
63+
export const a = (null as any as import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface);
64+
~~~~~~~~~~~~~~~~~~~~~~~~~
65+
!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
66+
~~~~
67+
!!! error TS1478: Identifier or string literal expected.
68+
~~~~
69+
!!! error TS2695: Left side of comma operator is unused and has no side effects.
70+
~
71+
!!! error TS1005: ';' expected.
72+
~
73+
!!! error TS1128: Declaration or statement expected.
74+
~
75+
!!! error TS1128: Declaration or statement expected.
76+
~
77+
!!! error TS1128: Declaration or statement expected.
78+
~
79+
!!! error TS1128: Declaration or statement expected.
80+
~~~~~~~~~~~~~~~~
81+
!!! error TS1434: Unexpected keyword or identifier.
82+
~~~~~~~~~~~~~~~~
83+
!!! error TS2304: Cannot find name 'RequireInterface'.
84+
~
85+
!!! error TS1128: Declaration or statement expected.
86+
export const b = (null as any as import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface);
87+
~~~~~~~~~~~~~~~~~~~~~~~~~
88+
!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
89+
~~~~
90+
!!! error TS1478: Identifier or string literal expected.
91+
~~~~
92+
!!! error TS2695: Left side of comma operator is unused and has no side effects.
93+
~
94+
!!! error TS1005: ';' expected.
95+
~
96+
!!! error TS1128: Declaration or statement expected.
97+
~
98+
!!! error TS1128: Declaration or statement expected.
99+
~
100+
!!! error TS1128: Declaration or statement expected.
101+
~
102+
!!! error TS1128: Declaration or statement expected.
103+
~~~~~~~~~~~~~~~
104+
!!! error TS1434: Unexpected keyword or identifier.
105+
~~~~~~~~~~~~~~~
106+
!!! error TS2304: Cannot find name 'ImportInterface'.
107+
~
108+
!!! error TS1128: Declaration or statement expected.
109+
110+
==== /node_modules/pkg/package.json (0 errors) ====
111+
{
112+
"name": "pkg",
113+
"version": "0.0.1",
114+
"exports": {
115+
"import": "./import.js",
116+
"require": "./require.js"
117+
}
118+
}
119+
==== /node_modules/pkg/import.d.ts (0 errors) ====
120+
export interface ImportInterface {}
121+
==== /node_modules/pkg/require.d.ts (0 errors) ====
122+
export interface RequireInterface {}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//// [tests/cases/compiler/parseAssertEntriesError.ts] ////
2+
3+
//// [package.json]
4+
{
5+
"name": "pkg",
6+
"version": "0.0.1",
7+
"exports": {
8+
"import": "./import.js",
9+
"require": "./require.js"
10+
}
11+
}
12+
//// [import.d.ts]
13+
export interface ImportInterface {}
14+
//// [require.d.ts]
15+
export interface RequireInterface {}
16+
//// [index.ts]
17+
export type LocalInterface =
18+
& import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface
19+
& import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface;
20+
21+
export const a = (null as any as import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface);
22+
export const b = (null as any as import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface);
23+
24+
25+
//// [index.js]
26+
"use strict";
27+
Object.defineProperty(exports, "__esModule", { value: true });
28+
exports.b = exports.a = void 0;
29+
1234, "resolution-mode";
30+
"require";
31+
RequireInterface
32+
& import("pkg", { assert: { 1234: , "resolution-mode": "import" } }).ImportInterface;
33+
exports.a = null;
34+
1234, "resolution-mode";
35+
"require";
36+
RequireInterface;
37+
;
38+
exports.b = null;
39+
1234, "resolution-mode";
40+
"import";
41+
ImportInterface;
42+
;
43+
44+
45+
//// [index.d.ts]
46+
export declare type LocalInterface = import("pkg", { assert: {} });
47+
export declare const a: any;
48+
export declare const b: any;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== /index.ts ===
2+
export type LocalInterface =
3+
>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 0, 0))
4+
5+
& import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface
6+
& import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface;
7+
>"pkg" : Symbol("/node_modules/pkg/import", Decl(import.d.ts, 0, 0))
8+
>assert : Symbol(assert, Decl(index.ts, 2, 21))
9+
>1234 : Symbol(1234, Decl(index.ts, 2, 31))
10+
>"resolution-mode" : Symbol("resolution-mode", Decl(index.ts, 2, 36))
11+
12+
export const a = (null as any as import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface);
13+
>a : Symbol(a, Decl(index.ts, 4, 12))
14+
15+
export const b = (null as any as import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface);
16+
>b : Symbol(b, Decl(index.ts, 5, 12))
17+
18+
=== /node_modules/pkg/import.d.ts ===
19+
export interface ImportInterface {}
20+
>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0))
21+
22+
=== /node_modules/pkg/require.d.ts ===
23+
export interface RequireInterface {}
24+
>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0))
25+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
=== /index.ts ===
2+
export type LocalInterface =
3+
>LocalInterface : any
4+
5+
& import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface
6+
>1234, "resolution-mode" : "resolution-mode"
7+
>1234 : 1234
8+
>"resolution-mode" : "resolution-mode"
9+
>"require" : "require"
10+
>RequireInterface & import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface : number
11+
>RequireInterface : any
12+
13+
& import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface;
14+
>import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface : any
15+
>import("pkg", { assert: {1234, "resolution-mode": "import"} }) : Promise<{ default: typeof import("/node_modules/pkg/import"); }>
16+
>"pkg" : "pkg"
17+
>{ assert: {1234, "resolution-mode": "import"} } : { assert: { 1234: any; "resolution-mode": string; }; }
18+
>assert : { 1234: any; "resolution-mode": string; }
19+
>{1234, "resolution-mode": "import"} : { 1234: any; "resolution-mode": string; }
20+
>1234 : any
21+
> : any
22+
>"resolution-mode" : string
23+
>"import" : "import"
24+
>ImportInterface : any
25+
26+
export const a = (null as any as import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface);
27+
>a : any
28+
>(null as any as import("pkg", { assert: { : any
29+
>null as any as import("pkg", { assert: { : any
30+
>null as any : any
31+
>null : null
32+
>1234, "resolution-mode" : "resolution-mode"
33+
>1234 : 1234
34+
>"resolution-mode" : "resolution-mode"
35+
>"require" : "require"
36+
>RequireInterface : any
37+
38+
export const b = (null as any as import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface);
39+
>b : any
40+
>(null as any as import("pkg", { assert: { : any
41+
>null as any as import("pkg", { assert: { : any
42+
>null as any : any
43+
>null : null
44+
>1234, "resolution-mode" : "resolution-mode"
45+
>1234 : 1234
46+
>"resolution-mode" : "resolution-mode"
47+
>"import" : "import"
48+
>ImportInterface : any
49+
50+
=== /node_modules/pkg/import.d.ts ===
51+
export interface ImportInterface {}
52+
No type information for this code.=== /node_modules/pkg/require.d.ts ===
53+
export interface RequireInterface {}
54+
No type information for this code.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @noImplicitReferences: true
2+
// @module: nodenext
3+
// @declaration: true
4+
// @outDir: out
5+
// @filename: /node_modules/pkg/package.json
6+
{
7+
"name": "pkg",
8+
"version": "0.0.1",
9+
"exports": {
10+
"import": "./import.js",
11+
"require": "./require.js"
12+
}
13+
}
14+
// @filename: /node_modules/pkg/import.d.ts
15+
export interface ImportInterface {}
16+
// @filename: /node_modules/pkg/require.d.ts
17+
export interface RequireInterface {}
18+
// @filename: /index.ts
19+
export type LocalInterface =
20+
& import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface
21+
& import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface;
22+
23+
export const a = (null as any as import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface);
24+
export const b = (null as any as import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface);

0 commit comments

Comments
 (0)