Skip to content

Commit 7ac56c3

Browse files
committed
Fix arrow functions in conditional expressions
1 parent 4aaf1db commit 7ac56c3

41 files changed

Lines changed: 268 additions & 414 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/compiler/parser.ts

Lines changed: 58 additions & 32 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,1): error TS2304: Cannot find name 'a'.
22
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,11): error TS2304: Cannot find name 'c'.
33
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,11): error TS8010: Type annotations can only be used in TypeScript files.
4-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,22): error TS2304: Cannot find name 'e'.
5-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,22): error TS8010: Type annotations can only be used in TypeScript files.
4+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,17): error TS2304: Cannot find name 'd'.
65
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,27): error TS2304: Cannot find name 'f'.
7-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(2,1): error TS1005: ':' expected.
86
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,1): error TS2304: Cannot find name 'a'.
97
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,11): error TS2304: Cannot find name 'c'.
10-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,22): error TS2304: Cannot find name 'e'.
8+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,17): error TS2304: Cannot find name 'd'.
119
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,27): error TS2304: Cannot find name 'f'.
12-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(2,1): error TS1005: ':' expected.
1310

1411

15-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js (7 errors) ====
12+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js (5 errors) ====
1613
a ? (b) : c => (d) : e => f // Not legal JS; "Unexpected token ':'" at last colon
1714
~
1815
!!! error TS2304: Cannot find name 'a'.
1916
~
2017
!!! error TS2304: Cannot find name 'c'.
2118
~
2219
!!! error TS8010: Type annotations can only be used in TypeScript files.
23-
~
24-
!!! error TS2304: Cannot find name 'e'.
25-
~
26-
!!! error TS8010: Type annotations can only be used in TypeScript files.
20+
~
21+
!!! error TS2304: Cannot find name 'd'.
2722
~
2823
!!! error TS2304: Cannot find name 'f'.
2924

30-
31-
!!! error TS1005: ':' expected.
32-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts (5 errors) ====
25+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts (4 errors) ====
3326
a ? (b) : c => (d) : e => f
3427
~
3528
!!! error TS2304: Cannot find name 'a'.
3629
~
3730
!!! error TS2304: Cannot find name 'c'.
38-
~
39-
!!! error TS2304: Cannot find name 'e'.
31+
~
32+
!!! error TS2304: Cannot find name 'd'.
4033
~
4134
!!! error TS2304: Cannot find name 'f'.
42-
43-
44-
!!! error TS1005: ':' expected.
35+

tests/baselines/reference/parserArrowFunctionExpression10(target=es3).js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ a ? (b) : c => (d) : e => f
88

99

1010
//// [fileJs.js]
11-
a ? function (b) { return function (d) { return f; }; }
12-
:
13-
; // Not legal JS; "Unexpected token ':'" at last colon
11+
a ? function (b) { return (d); } : function (e) { return f; }; // Not legal JS; "Unexpected token ':'" at last colon
1412
//// [fileTs.js]
15-
a ? function (b) { return function (d) { return f; }; }
16-
:
17-
;
13+
a ? function (b) { return (d); } : function (e) { return f; };

tests/baselines/reference/parserArrowFunctionExpression10(target=es3).symbols

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
a ? (b) : c => (d) : e => f // Not legal JS; "Unexpected token ':'" at last colon
33
>b : Symbol(b, Decl(fileJs.js, 0, 5))
44
>c : Symbol(c)
5-
>d : Symbol(d, Decl(fileJs.js, 0, 16))
6-
>e : Symbol(e)
5+
>e : Symbol(e, Decl(fileJs.js, 0, 20))
76

87
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts ===
98
a ? (b) : c => (d) : e => f
109
>b : Symbol(b, Decl(fileTs.ts, 0, 5))
1110
>c : Symbol(c)
12-
>d : Symbol(d, Decl(fileTs.ts, 0, 16))
13-
>e : Symbol(e)
11+
>e : Symbol(e, Decl(fileTs.ts, 0, 20))
1412

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js ===
22
a ? (b) : c => (d) : e => f // Not legal JS; "Unexpected token ':'" at last colon
3-
>a ? (b) : c => (d) : e => f : any
3+
>a ? (b) : c => (d) : e => f : (b: any) => c
44
>a : any
5-
>(b) : c => (d) : e => f : (b: any) => c
5+
>(b) : c => (d) : (b: any) => c
66
>b : any
7-
>(d) : e => f : (d: any) => e
7+
>(d) : any
88
>d : any
9+
>e => f : (e: any) => any
10+
>e : any
911
>f : any
1012

11-
> : any
12-
1313
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts ===
1414
a ? (b) : c => (d) : e => f
15-
>a ? (b) : c => (d) : e => f : any
15+
>a ? (b) : c => (d) : e => f : (b: any) => c
1616
>a : any
17-
>(b) : c => (d) : e => f : (b: any) => c
17+
>(b) : c => (d) : (b: any) => c
1818
>b : any
19-
>(d) : e => f : (d: any) => e
19+
>(d) : any
2020
>d : any
21+
>e => f : (e: any) => any
22+
>e : any
2123
>f : any
2224

23-
> : any
24-
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,1): error TS2304: Cannot find name 'a'.
22
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,11): error TS2304: Cannot find name 'c'.
33
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,11): error TS8010: Type annotations can only be used in TypeScript files.
4-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,22): error TS2304: Cannot find name 'e'.
5-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,22): error TS8010: Type annotations can only be used in TypeScript files.
4+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,17): error TS2304: Cannot find name 'd'.
65
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,27): error TS2304: Cannot find name 'f'.
7-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(2,1): error TS1005: ':' expected.
86
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,1): error TS2304: Cannot find name 'a'.
97
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,11): error TS2304: Cannot find name 'c'.
10-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,22): error TS2304: Cannot find name 'e'.
8+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,17): error TS2304: Cannot find name 'd'.
119
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,27): error TS2304: Cannot find name 'f'.
12-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(2,1): error TS1005: ':' expected.
1310

1411

15-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js (7 errors) ====
12+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js (5 errors) ====
1613
a ? (b) : c => (d) : e => f // Not legal JS; "Unexpected token ':'" at last colon
1714
~
1815
!!! error TS2304: Cannot find name 'a'.
1916
~
2017
!!! error TS2304: Cannot find name 'c'.
2118
~
2219
!!! error TS8010: Type annotations can only be used in TypeScript files.
23-
~
24-
!!! error TS2304: Cannot find name 'e'.
25-
~
26-
!!! error TS8010: Type annotations can only be used in TypeScript files.
20+
~
21+
!!! error TS2304: Cannot find name 'd'.
2722
~
2823
!!! error TS2304: Cannot find name 'f'.
2924

30-
31-
!!! error TS1005: ':' expected.
32-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts (5 errors) ====
25+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts (4 errors) ====
3326
a ? (b) : c => (d) : e => f
3427
~
3528
!!! error TS2304: Cannot find name 'a'.
3629
~
3730
!!! error TS2304: Cannot find name 'c'.
38-
~
39-
!!! error TS2304: Cannot find name 'e'.
31+
~
32+
!!! error TS2304: Cannot find name 'd'.
4033
~
4134
!!! error TS2304: Cannot find name 'f'.
42-
43-
44-
!!! error TS1005: ':' expected.
35+

tests/baselines/reference/parserArrowFunctionExpression10(target=es6).js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ a ? (b) : c => (d) : e => f
88

99

1010
//// [fileJs.js]
11-
a ? (b) => (d) => f
12-
:
13-
; // Not legal JS; "Unexpected token ':'" at last colon
11+
a ? (b) => (d) : e => f; // Not legal JS; "Unexpected token ':'" at last colon
1412
//// [fileTs.js]
15-
a ? (b) => (d) => f
16-
:
17-
;
13+
a ? (b) => (d) : e => f;

tests/baselines/reference/parserArrowFunctionExpression10(target=es6).symbols

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
a ? (b) : c => (d) : e => f // Not legal JS; "Unexpected token ':'" at last colon
33
>b : Symbol(b, Decl(fileJs.js, 0, 5))
44
>c : Symbol(c)
5-
>d : Symbol(d, Decl(fileJs.js, 0, 16))
6-
>e : Symbol(e)
5+
>e : Symbol(e, Decl(fileJs.js, 0, 20))
76

87
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts ===
98
a ? (b) : c => (d) : e => f
109
>b : Symbol(b, Decl(fileTs.ts, 0, 5))
1110
>c : Symbol(c)
12-
>d : Symbol(d, Decl(fileTs.ts, 0, 16))
13-
>e : Symbol(e)
11+
>e : Symbol(e, Decl(fileTs.ts, 0, 20))
1412

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js ===
22
a ? (b) : c => (d) : e => f // Not legal JS; "Unexpected token ':'" at last colon
3-
>a ? (b) : c => (d) : e => f : any
3+
>a ? (b) : c => (d) : e => f : (b: any) => c
44
>a : any
5-
>(b) : c => (d) : e => f : (b: any) => c
5+
>(b) : c => (d) : (b: any) => c
66
>b : any
7-
>(d) : e => f : (d: any) => e
7+
>(d) : any
88
>d : any
9+
>e => f : (e: any) => any
10+
>e : any
911
>f : any
1012

11-
> : any
12-
1313
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts ===
1414
a ? (b) : c => (d) : e => f
15-
>a ? (b) : c => (d) : e => f : any
15+
>a ? (b) : c => (d) : e => f : (b: any) => c
1616
>a : any
17-
>(b) : c => (d) : e => f : (b: any) => c
17+
>(b) : c => (d) : (b: any) => c
1818
>b : any
19-
>(d) : e => f : (d: any) => e
19+
>(d) : any
2020
>d : any
21+
>e => f : (e: any) => any
22+
>e : any
2123
>f : any
2224

23-
> : any
24-
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,38 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,1): error TS2304: Cannot find name 'a'.
22
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,5): error TS2304: Cannot find name 'b'.
33
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,9): error TS2304: Cannot find name 'c'.
4-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,19): error TS2304: Cannot find name 'e'.
5-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,19): error TS8010: Type annotations can only be used in TypeScript files.
4+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,14): error TS2304: Cannot find name 'd'.
65
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(1,24): error TS2304: Cannot find name 'f'.
7-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js(2,1): error TS1005: ':' expected.
86
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,1): error TS2304: Cannot find name 'a'.
97
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,5): error TS2304: Cannot find name 'b'.
108
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,9): error TS2304: Cannot find name 'c'.
11-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,19): error TS2304: Cannot find name 'e'.
9+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,14): error TS2304: Cannot find name 'd'.
1210
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(1,24): error TS2304: Cannot find name 'f'.
13-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts(2,1): error TS1005: ':' expected.
1411

1512

16-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js (7 errors) ====
13+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileJs.js (5 errors) ====
1714
a ? b ? c : (d) : e => f // Legal JS
1815
~
1916
!!! error TS2304: Cannot find name 'a'.
2017
~
2118
!!! error TS2304: Cannot find name 'b'.
2219
~
2320
!!! error TS2304: Cannot find name 'c'.
24-
~
25-
!!! error TS2304: Cannot find name 'e'.
26-
~
27-
!!! error TS8010: Type annotations can only be used in TypeScript files.
21+
~
22+
!!! error TS2304: Cannot find name 'd'.
2823
~
2924
!!! error TS2304: Cannot find name 'f'.
3025

31-
32-
!!! error TS1005: ':' expected.
33-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts (6 errors) ====
26+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/fileTs.ts (5 errors) ====
3427
a ? b ? c : (d) : e => f
3528
~
3629
!!! error TS2304: Cannot find name 'a'.
3730
~
3831
!!! error TS2304: Cannot find name 'b'.
3932
~
4033
!!! error TS2304: Cannot find name 'c'.
41-
~
42-
!!! error TS2304: Cannot find name 'e'.
34+
~
35+
!!! error TS2304: Cannot find name 'd'.
4336
~
4437
!!! error TS2304: Cannot find name 'f'.
45-
46-
47-
!!! error TS1005: ':' expected.
38+

0 commit comments

Comments
 (0)