Skip to content

Commit 7a33193

Browse files
authored
Integrate JS syntax checks with parser and remove separate pass (#1732)
1 parent 1ca5a2d commit 7a33193

13 files changed

+413
-168
lines changed

internal/parser/parser.go

Lines changed: 129 additions & 111 deletions
Large diffs are not rendered by default.

testdata/baselines/reference/submodule/compiler/jsFileCompilationConstructorOverloadSyntax.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ a.js(2,3): error TS8017: Signature declarations can only be used in TypeScript f
44
==== a.js (1 errors) ====
55
class A {
66
constructor();
7-
~~~~~~~~~~~
7+
~~~~~~~~~~~~~~
88
!!! error TS8017: Signature declarations can only be used in TypeScript files.
99
}
1010

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
a.js(1,10): error TS8017: Signature declarations can only be used in TypeScript files.
1+
a.js(1,1): error TS8017: Signature declarations can only be used in TypeScript files.
22

33

44
==== a.js (1 errors) ====
55
function foo();
6-
~~~
6+
~~~~~~~~~~~~~~~
77
!!! error TS8017: Signature declarations can only be used in TypeScript files.
88

testdata/baselines/reference/submodule/compiler/jsFileCompilationMethodOverloadSyntax.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ a.js(2,3): error TS8017: Signature declarations can only be used in TypeScript f
44
==== a.js (1 errors) ====
55
class A {
66
foo();
7-
~~~
7+
~~~~~~
88
!!! error TS8017: Signature declarations can only be used in TypeScript files.
99
}
1010

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

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ index.js(5,12): error TS8010: Type annotations can only be used in TypeScript fi
33
index.js(8,16): error TS8004: Type parameter declarations can only be used in TypeScript files.
44
index.js(8,29): error TS8011: Type arguments can only be used in TypeScript files.
55
index.js(9,12): error TS8010: Type annotations can only be used in TypeScript files.
6-
index.js(13,11): error TS8010: Type annotations can only be used in TypeScript files.
7-
index.js(19,11): error TS8010: Type annotations can only be used in TypeScript files.
8-
index.js(23,11): error TS8010: Type annotations can only be used in TypeScript files.
9-
index.js(27,11): error TS8010: Type annotations can only be used in TypeScript files.
10-
index.js(28,11): error TS8010: Type annotations can only be used in TypeScript files.
11-
index.js(32,11): error TS8010: Type annotations can only be used in TypeScript files.
12-
index.js(39,11): error TS8010: Type annotations can only be used in TypeScript files.
13-
index.js(43,11): error TS8010: Type annotations can only be used in TypeScript files.
14-
index.js(47,11): error TS8010: Type annotations can only be used in TypeScript files.
15-
index.js(48,11): error TS8010: Type annotations can only be used in TypeScript files.
16-
index.js(52,11): error TS8010: Type annotations can only be used in TypeScript files.
17-
index.js(53,11): error TS8010: Type annotations can only be used in TypeScript files.
18-
index.js(59,11): error TS8010: Type annotations can only be used in TypeScript files.
19-
index.js(63,11): error TS8010: Type annotations can only be used in TypeScript files.
20-
index.js(67,11): error TS8010: Type annotations can only be used in TypeScript files.
21-
index.js(68,11): error TS8010: Type annotations can only be used in TypeScript files.
6+
index.js(13,5): error TS8017: Signature declarations can only be used in TypeScript files.
7+
index.js(19,5): error TS8017: Signature declarations can only be used in TypeScript files.
8+
index.js(23,5): error TS8017: Signature declarations can only be used in TypeScript files.
9+
index.js(27,5): error TS8017: Signature declarations can only be used in TypeScript files.
10+
index.js(28,5): error TS8017: Signature declarations can only be used in TypeScript files.
11+
index.js(32,5): error TS8017: Signature declarations can only be used in TypeScript files.
12+
index.js(39,5): error TS8017: Signature declarations can only be used in TypeScript files.
13+
index.js(43,5): error TS8017: Signature declarations can only be used in TypeScript files.
14+
index.js(47,5): error TS8017: Signature declarations can only be used in TypeScript files.
15+
index.js(48,5): error TS8017: Signature declarations can only be used in TypeScript files.
16+
index.js(52,5): error TS8017: Signature declarations can only be used in TypeScript files.
17+
index.js(53,5): error TS8017: Signature declarations can only be used in TypeScript files.
18+
index.js(59,5): error TS8017: Signature declarations can only be used in TypeScript files.
19+
index.js(63,5): error TS8017: Signature declarations can only be used in TypeScript files.
20+
index.js(67,5): error TS8017: Signature declarations can only be used in TypeScript files.
21+
index.js(68,5): error TS8017: Signature declarations can only be used in TypeScript files.
2222

2323

2424
==== index.js (21 errors) ====
@@ -45,92 +45,92 @@ index.js(68,11): error TS8010: Type annotations can only be used in TypeScript f
4545

4646
export class O {
4747
[idx: string]: string;
48-
~~~~~~
49-
!!! error TS8010: Type annotations can only be used in TypeScript files.
48+
~~~~~~~~~~~~~~~~~~~~~~
49+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
5050
}
5151

5252
export class P extends O {}
5353

5454
export class Q extends O {
5555
[idx: string]: "ok";
56-
~~~~~~
57-
!!! error TS8010: Type annotations can only be used in TypeScript files.
56+
~~~~~~~~~~~~~~~~~~~~
57+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
5858
}
5959

6060
export class R extends O {
6161
[idx: number]: "ok";
62-
~~~~~~
63-
!!! error TS8010: Type annotations can only be used in TypeScript files.
62+
~~~~~~~~~~~~~~~~~~~~
63+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
6464
}
6565

6666
export class S extends O {
6767
[idx: string]: "ok";
68-
~~~~~~
69-
!!! error TS8010: Type annotations can only be used in TypeScript files.
68+
~~~~~~~~~~~~~~~~~~~~
69+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
7070
[idx: number]: never;
71-
~~~~~~
72-
!!! error TS8010: Type annotations can only be used in TypeScript files.
71+
~~~~~~~~~~~~~~~~~~~~~
72+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
7373
}
7474

7575
export class T {
7676
[idx: number]: string;
77-
~~~~~~
78-
!!! error TS8010: Type annotations can only be used in TypeScript files.
77+
~~~~~~~~~~~~~~~~~~~~~~
78+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
7979
}
8080

8181
export class U extends T {}
8282

8383

8484
export class V extends T {
8585
[idx: string]: string;
86-
~~~~~~
87-
!!! error TS8010: Type annotations can only be used in TypeScript files.
86+
~~~~~~~~~~~~~~~~~~~~~~
87+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
8888
}
8989

9090
export class W extends T {
9191
[idx: number]: "ok";
92-
~~~~~~
93-
!!! error TS8010: Type annotations can only be used in TypeScript files.
92+
~~~~~~~~~~~~~~~~~~~~
93+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
9494
}
9595

9696
export class X extends T {
9797
[idx: string]: string;
98-
~~~~~~
99-
!!! error TS8010: Type annotations can only be used in TypeScript files.
98+
~~~~~~~~~~~~~~~~~~~~~~
99+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
100100
[idx: number]: "ok";
101-
~~~~~~
102-
!!! error TS8010: Type annotations can only be used in TypeScript files.
101+
~~~~~~~~~~~~~~~~~~~~
102+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
103103
}
104104

105105
export class Y {
106106
[idx: string]: {x: number};
107-
~~~~~~
108-
!!! error TS8010: Type annotations can only be used in TypeScript files.
107+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
108+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
109109
[idx: number]: {x: number, y: number};
110-
~~~~~~
111-
!!! error TS8010: Type annotations can only be used in TypeScript files.
110+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
112112
}
113113

114114
export class Z extends Y {}
115115

116116
export class AA extends Y {
117117
[idx: string]: {x: number, y: number};
118-
~~~~~~
119-
!!! error TS8010: Type annotations can only be used in TypeScript files.
118+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
119+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
120120
}
121121

122122
export class BB extends Y {
123123
[idx: number]: {x: 0, y: 0};
124-
~~~~~~
125-
!!! error TS8010: Type annotations can only be used in TypeScript files.
124+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
126126
}
127127

128128
export class CC extends Y {
129129
[idx: string]: {x: number, y: number};
130-
~~~~~~
131-
!!! error TS8010: Type annotations can only be used in TypeScript files.
130+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
132132
[idx: number]: {x: 0, y: 0};
133-
~~~~~~
134-
!!! error TS8010: Type annotations can only be used in TypeScript files.
133+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
135135
}
136136

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
index.js(4,18): error TS8006: 'namespace' declarations can only be used in TypeScript files.
2+
index.js(6,22): error TS8006: 'namespace' declarations can only be used in TypeScript files.
23

34

4-
==== index.js (1 errors) ====
5+
==== index.js (2 errors) ====
56
/// <reference types="node" />
67
export const Something = 2; // to show conflict that can occur
78
// @ts-ignore
@@ -10,6 +11,8 @@ index.js(4,18): error TS8006: 'namespace' declarations can only be used in TypeS
1011
!!! error TS8006: 'namespace' declarations can only be used in TypeScript files.
1112
// @ts-ignore
1213
export namespace B {
14+
~
15+
!!! error TS8006: 'namespace' declarations can only be used in TypeScript files.
1316
const Something = require("fs").Something;
1417
const thing = new Something();
1518
// @ts-ignore

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ plainJSGrammarErrors.js(26,11): error TS1030: 'async' modifier already seen.
1313
plainJSGrammarErrors.js(28,11): error TS1029: 'static' modifier must precede 'async' modifier.
1414
plainJSGrammarErrors.js(29,5): error TS1031: 'export' modifier cannot appear on class elements of this kind.
1515
plainJSGrammarErrors.js(30,5): error TS1031: 'export' modifier cannot appear on class elements of this kind.
16-
plainJSGrammarErrors.js(34,9): error TS8017: Signature declarations can only be used in TypeScript files.
16+
plainJSGrammarErrors.js(34,5): error TS8017: Signature declarations can only be used in TypeScript files.
1717
plainJSGrammarErrors.js(34,22): error TS1005: '{' expected.
1818
plainJSGrammarErrors.js(35,9): error TS1054: A 'get' accessor cannot have parameters.
1919
plainJSGrammarErrors.js(36,9): error TS1049: A 'set' accessor must have exactly one parameter.
@@ -166,7 +166,7 @@ plainJSGrammarErrors.js(205,36): error TS1325: Argument of dynamic import cannot
166166

167167
// accessor mistakes
168168
get incorporeal();
169-
~~~~~~~~~~~
169+
~~~~~~~~~~~~~~~~~~
170170
!!! error TS8017: Signature declarations can only be used in TypeScript files.
171171
~
172172
!!! error TS1005: '{' expected.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- old.jsFileCompilationConstructorOverloadSyntax.errors.txt
2+
+++ new.jsFileCompilationConstructorOverloadSyntax.errors.txt
3+
@@= skipped -3, +3 lines =@@
4+
==== a.js (1 errors) ====
5+
class A {
6+
constructor();
7+
- ~~~~~~~~~~~
8+
+ ~~~~~~~~~~~~~~
9+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
10+
}
11+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--- old.jsFileCompilationFunctionOverloadSyntax.errors.txt
2+
+++ new.jsFileCompilationFunctionOverloadSyntax.errors.txt
3+
@@= skipped -0, +0 lines =@@
4+
-a.js(1,10): error TS8017: Signature declarations can only be used in TypeScript files.
5+
+a.js(1,1): error TS8017: Signature declarations can only be used in TypeScript files.
6+
7+
8+
==== a.js (1 errors) ====
9+
function foo();
10+
- ~~~
11+
+ ~~~~~~~~~~~~~~~
12+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
13+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- old.jsFileCompilationMethodOverloadSyntax.errors.txt
2+
+++ new.jsFileCompilationMethodOverloadSyntax.errors.txt
3+
@@= skipped -3, +3 lines =@@
4+
==== a.js (1 errors) ====
5+
class A {
6+
foo();
7+
- ~~~
8+
+ ~~~~~~
9+
!!! error TS8017: Signature declarations can only be used in TypeScript files.
10+
}
11+

0 commit comments

Comments
 (0)