Skip to content

Commit f579f33

Browse files
authored
Revert "Don't treat a colon in a conditional expression branch as part of an arrow function" (microsoft#48940)
1 parent c8ec855 commit f579f33

33 files changed

+199
-124
lines changed

src/compiler/parser.ts

Lines changed: 32 additions & 50 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,1): error TS2304: Cannot find name 'a'.
2-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,6): error TS2304: Cannot find name 'b'.
3-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,17): error TS2304: Cannot find name 'd'.
4-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,20): error TS1005: ';' expected.
2+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,11): error TS2304: Cannot find name 'c'.
3+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,22): error TS2304: Cannot find name 'e'.
54
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,27): error TS2304: Cannot find name 'f'.
5+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(2,1): error TS1005: ':' expected.
66

77

88
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts (5 errors) ====
99
a ? (b) : c => (d) : e => f
1010
~
1111
!!! error TS2304: Cannot find name 'a'.
12-
~
13-
!!! error TS2304: Cannot find name 'b'.
14-
~
15-
!!! error TS2304: Cannot find name 'd'.
16-
~
17-
!!! error TS1005: ';' expected.
12+
~
13+
!!! error TS2304: Cannot find name 'c'.
14+
~
15+
!!! error TS2304: Cannot find name 'e'.
1816
~
1917
!!! error TS2304: Cannot find name 'f'.
20-
18+
19+
20+
!!! error TS1005: ':' expected.

tests/baselines/reference/parserArrowFunctionExpression10.js

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

44

55
//// [parserArrowFunctionExpression10.js]
6-
a ? (b) : function (c) { return (d); };
7-
(function (e) { return f; });
6+
a ? function (b) { return function (d) { return f; }; }
7+
:
8+
;
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts ===
22
a ? (b) : c => (d) : e => f
3-
>c : Symbol(c, Decl(parserArrowFunctionExpression10.ts, 0, 9))
4-
>e : Symbol(e, Decl(parserArrowFunctionExpression10.ts, 0, 20))
3+
>b : Symbol(b, Decl(parserArrowFunctionExpression10.ts, 0, 5))
4+
>c : Symbol(c)
5+
>d : Symbol(d, Decl(parserArrowFunctionExpression10.ts, 0, 16))
6+
>e : Symbol(e)
57

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts ===
22
a ? (b) : c => (d) : e => f
3-
>a ? (b) : c => (d) : any
3+
>a ? (b) : c => (d) : e => f : any
44
>a : any
5-
>(b) : any
5+
>(b) : c => (d) : e => f : (b: any) => c
66
>b : any
7-
>c => (d) : (c: any) => any
8-
>c : any
9-
>(d) : any
7+
>(d) : e => f : (d: any) => e
108
>d : any
11-
>e => f : (e: any) => any
12-
>e : any
139
>f : any
1410

11+
> : any
12+
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,1): error TS2304: Cannot find name 'a'.
22
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,5): error TS2304: Cannot find name 'b'.
33
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,9): error TS2304: Cannot find name 'c'.
4-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,14): error TS2304: Cannot find name 'd'.
4+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,19): error TS2304: Cannot find name 'e'.
55
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,24): error TS2304: Cannot find name 'f'.
6+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(2,1): error TS1005: ':' expected.
67

78

8-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts (5 errors) ====
9+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts (6 errors) ====
910
a ? b ? c : (d) : e => f
1011
~
1112
!!! error TS2304: Cannot find name 'a'.
1213
~
1314
!!! error TS2304: Cannot find name 'b'.
1415
~
1516
!!! error TS2304: Cannot find name 'c'.
16-
~
17-
!!! error TS2304: Cannot find name 'd'.
17+
~
18+
!!! error TS2304: Cannot find name 'e'.
1819
~
1920
!!! error TS2304: Cannot find name 'f'.
20-
21+
22+
23+
!!! error TS1005: ':' expected.

tests/baselines/reference/parserArrowFunctionExpression11.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ a ? b ? c : (d) : e => f
33

44

55
//// [parserArrowFunctionExpression11.js]
6-
a ? b ? c : (d) : function (e) { return f; };
6+
a ? b ? c : function (d) { return f; }
7+
:
8+
;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts ===
22
a ? b ? c : (d) : e => f
3-
>e : Symbol(e, Decl(parserArrowFunctionExpression11.ts, 0, 17))
3+
>d : Symbol(d, Decl(parserArrowFunctionExpression11.ts, 0, 13))
4+
>e : Symbol(e)
45

tests/baselines/reference/parserArrowFunctionExpression11.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
a ? b ? c : (d) : e => f
33
>a ? b ? c : (d) : e => f : any
44
>a : any
5-
>b ? c : (d) : any
5+
>b ? c : (d) : e => f : any
66
>b : any
77
>c : any
8-
>(d) : any
8+
>(d) : e => f : (d: any) => e
99
>d : any
10-
>e => f : (e: any) => any
11-
>e : any
1210
>f : any
1311

12+
> : any
13+
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts(1,1): error TS2304: Cannot find name 'a'.
2-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts(1,13): error TS2304: Cannot find name 'c'.
2+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts(1,17): error TS2304: Cannot find name 'd'.
33
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts(1,22): error TS2304: Cannot find name 'e'.
4+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts(2,1): error TS1005: ':' expected.
45

56

6-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts (3 errors) ====
7+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts (4 errors) ====
78
a ? (b) => (c): d => e
89
~
910
!!! error TS2304: Cannot find name 'a'.
10-
~
11-
!!! error TS2304: Cannot find name 'c'.
11+
~
12+
!!! error TS2304: Cannot find name 'd'.
1213
~
1314
!!! error TS2304: Cannot find name 'e'.
14-
15+
16+
17+
!!! error TS1005: ':' expected.

tests/baselines/reference/parserArrowFunctionExpression12.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ a ? (b) => (c): d => e
33

44

55
//// [parserArrowFunctionExpression12.js]
6-
a ? function (b) { return (c); } : function (d) { return e; };
6+
a ? function (b) { return function (c) { return e; }; }
7+
:
8+
;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts ===
22
a ? (b) => (c): d => e
33
>b : Symbol(b, Decl(parserArrowFunctionExpression12.ts, 0, 5))
4-
>d : Symbol(d, Decl(parserArrowFunctionExpression12.ts, 0, 15))
4+
>c : Symbol(c, Decl(parserArrowFunctionExpression12.ts, 0, 12))
5+
>d : Symbol(d)
56

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts ===
22
a ? (b) => (c): d => e
3-
>a ? (b) => (c): d => e : (b: any) => any
3+
>a ? (b) => (c): d => e : any
44
>a : any
5-
>(b) => (c) : (b: any) => any
5+
>(b) => (c): d => e : (b: any) => (c: any) => d
66
>b : any
7-
>(c) : any
7+
>(c): d => e : (c: any) => d
88
>c : any
9-
>d => e : (d: any) => any
10-
>d : any
119
>e : any
1210

11+
> : any
12+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [parserArrowFunctionExpression15.ts]
2+
false ? (param): string => param : null
3+
4+
5+
//// [parserArrowFunctionExpression15.js]
6+
false ? function (param) { return param; } : null;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression15.ts ===
2+
false ? (param): string => param : null
3+
>param : Symbol(param, Decl(parserArrowFunctionExpression15.ts, 0, 9))
4+
>param : Symbol(param, Decl(parserArrowFunctionExpression15.ts, 0, 9))
5+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression15.ts ===
2+
false ? (param): string => param : null
3+
>false ? (param): string => param : null : (param: any) => string
4+
>false : false
5+
>(param): string => param : (param: any) => string
6+
>param : any
7+
>param : any
8+
>null : null
9+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [parserArrowFunctionExpression16.ts]
2+
true ? false ? (param): string => param : null : null
3+
4+
5+
//// [parserArrowFunctionExpression16.js]
6+
true ? false ? function (param) { return param; } : null : null;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression16.ts ===
2+
true ? false ? (param): string => param : null : null
3+
>param : Symbol(param, Decl(parserArrowFunctionExpression16.ts, 0, 16))
4+
>param : Symbol(param, Decl(parserArrowFunctionExpression16.ts, 0, 16))
5+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression16.ts ===
2+
true ? false ? (param): string => param : null : null
3+
>true ? false ? (param): string => param : null : null : (param: any) => string
4+
>true : true
5+
>false ? (param): string => param : null : (param: any) => string
6+
>false : false
7+
>(param): string => param : (param: any) => string
8+
>param : any
9+
>param : any
10+
>null : null
11+
>null : null
12+
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts(1,1): error TS2304: Cannot find name 'x'.
2+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts(1,20): error TS2304: Cannot find name 'z'.
3+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts(1,28): error TS18004: No value exists in scope for the shorthand property 'z'. Either declare one or provide an initializer.
4+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts(2,1): error TS1005: ':' expected.
25

36

4-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts (1 errors) ====
7+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts (4 errors) ====
58
x ? y => ({ y }) : z => ({ z })
69
~
710
!!! error TS2304: Cannot find name 'x'.
8-
11+
~
12+
!!! error TS2304: Cannot find name 'z'.
13+
~
14+
!!! error TS18004: No value exists in scope for the shorthand property 'z'. Either declare one or provide an initializer.
15+
16+
17+
!!! error TS1005: ':' expected.

tests/baselines/reference/parserArrowFunctionExpression8.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ x ? y => ({ y }) : z => ({ z })
33

44

55
//// [parserArrowFunctionExpression8.js]
6-
x ? function (y) { return ({ y: y }); } : function (z) { return ({ z: z }); };
6+
x ? function (y) { return function (_a) {
7+
var y = _a.y;
8+
return ({ z: z });
9+
}; }
10+
:
11+
;

tests/baselines/reference/parserArrowFunctionExpression8.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
x ? y => ({ y }) : z => ({ z })
33
>y : Symbol(y, Decl(parserArrowFunctionExpression8.ts, 0, 3))
44
>y : Symbol(y, Decl(parserArrowFunctionExpression8.ts, 0, 11))
5-
>z : Symbol(z, Decl(parserArrowFunctionExpression8.ts, 0, 18))
5+
>z : Symbol(z)
66
>z : Symbol(z, Decl(parserArrowFunctionExpression8.ts, 0, 26))
77

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts ===
22
x ? y => ({ y }) : z => ({ z })
3-
>x ? y => ({ y }) : z => ({ z }) : ((y: any) => { y: any; }) | ((z: any) => { z: any; })
3+
>x ? y => ({ y }) : z => ({ z }) : any
44
>x : any
5-
>y => ({ y }) : (y: any) => { y: any; }
5+
>y => ({ y }) : z => ({ z }) : (y: any) => ({ y }: { y: any; }) => z
66
>y : any
7-
>({ y }) : { y: any; }
8-
>{ y } : { y: any; }
7+
>({ y }) : z => ({ z }) : ({ y }: { y: any; }) => z
98
>y : any
10-
>z => ({ z }) : (z: any) => { z: any; }
11-
>z : any
129
>({ z }) : { z: any; }
1310
>{ z } : { z: any; }
1411
>z : any
1512

13+
> : any
14+
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js(1,1): error TS2304: Cannot find name 'x'.
2+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js(1,20): error TS2304: Cannot find name 'z'.
3+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js(1,20): error TS8010: Type annotations can only be used in TypeScript files.
4+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js(1,28): error TS18004: No value exists in scope for the shorthand property 'z'. Either declare one or provide an initializer.
5+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js(2,1): error TS1005: ':' expected.
26

37

4-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js (1 errors) ====
8+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js (5 errors) ====
59
x ? y => ({ y }) : z => ({ z })
610
~
711
!!! error TS2304: Cannot find name 'x'.
8-
12+
~
13+
!!! error TS2304: Cannot find name 'z'.
14+
~
15+
!!! error TS8010: Type annotations can only be used in TypeScript files.
16+
~
17+
!!! error TS18004: No value exists in scope for the shorthand property 'z'. Either declare one or provide an initializer.
18+
19+
20+
!!! error TS1005: ':' expected.

tests/baselines/reference/parserArrowFunctionExpression8Js.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ x ? y => ({ y }) : z => ({ z })
33

44

55
//// [file.js]
6-
x ? function (y) { return ({ y: y }); } : function (z) { return ({ z: z }); };
6+
x ? function (y) { return function (_a) {
7+
var y = _a.y;
8+
return ({ z: z });
9+
}; }
10+
:
11+
;

tests/baselines/reference/parserArrowFunctionExpression8Js.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
x ? y => ({ y }) : z => ({ z })
33
>y : Symbol(y, Decl(file.js, 0, 3))
44
>y : Symbol(y, Decl(file.js, 0, 11))
5-
>z : Symbol(z, Decl(file.js, 0, 18))
5+
>z : Symbol(z)
66
>z : Symbol(z, Decl(file.js, 0, 26))
77

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js ===
22
x ? y => ({ y }) : z => ({ z })
3-
>x ? y => ({ y }) : z => ({ z }) : ((y: any) => { y: any; }) | ((z: any) => { z: any; })
3+
>x ? y => ({ y }) : z => ({ z }) : any
44
>x : any
5-
>y => ({ y }) : (y: any) => { y: any; }
5+
>y => ({ y }) : z => ({ z }) : (y: any) => ({ y }: { y: any; }) => z
66
>y : any
7-
>({ y }) : { y: any; }
8-
>{ y } : { y: any; }
7+
>({ y }) : z => ({ z }) : ({ y }: { y: any; }) => z
98
>y : any
10-
>z => ({ z }) : (z: any) => { z: any; }
11-
>z : any
129
>({ z }) : { z: any; }
1310
>{ z } : { z: any; }
1411
>z : any
1512

13+
> : any
14+
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts(1,1): error TS2304: Cannot find name 'b'.
2-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts(1,6): error TS2304: Cannot find name 'c'.
2+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts(1,11): error TS2304: Cannot find name 'd'.
33
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts(1,16): error TS2304: Cannot find name 'e'.
4+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts(2,1): error TS1005: ':' expected.
45

56

6-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts (3 errors) ====
7+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts (4 errors) ====
78
b ? (c) : d => e
89
~
910
!!! error TS2304: Cannot find name 'b'.
10-
~
11-
!!! error TS2304: Cannot find name 'c'.
11+
~
12+
!!! error TS2304: Cannot find name 'd'.
1213
~
1314
!!! error TS2304: Cannot find name 'e'.
14-
15+
16+
17+
!!! error TS1005: ':' expected.

0 commit comments

Comments
 (0)