Skip to content

Commit 2dede20

Browse files
authored
Don't treat a colon in a conditional expression branch as part of an arrow function (microsoft#47550)
1 parent dda6583 commit 2dede20

File tree

41 files changed

+363
-32
lines changed

Some content is hidden

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

41 files changed

+363
-32
lines changed

Diff for: src/compiler/parser.ts

+50-32
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
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.
5+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,27): error TS2304: Cannot find name 'f'.
6+
7+
8+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts (5 errors) ====
9+
a ? (b) : c => (d) : e => f
10+
~
11+
!!! 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.
18+
~
19+
!!! error TS2304: Cannot find name 'f'.
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [parserArrowFunctionExpression10.ts]
2+
a ? (b) : c => (d) : e => f
3+
4+
5+
//// [parserArrowFunctionExpression10.js]
6+
a ? (b) : function (c) { return (d); };
7+
(function (e) { return f; });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts ===
2+
a ? (b) : c => (d) : e => f
3+
>c : Symbol(c, Decl(parserArrowFunctionExpression10.ts, 0, 9))
4+
>e : Symbol(e, Decl(parserArrowFunctionExpression10.ts, 0, 20))
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts ===
2+
a ? (b) : c => (d) : e => f
3+
>a ? (b) : c => (d) : any
4+
>a : any
5+
>(b) : any
6+
>b : any
7+
>c => (d) : (c: any) => any
8+
>c : any
9+
>(d) : any
10+
>d : any
11+
>e => f : (e: any) => any
12+
>e : any
13+
>f : any
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,1): error TS2304: Cannot find name 'a'.
2+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,5): error TS2304: Cannot find name 'b'.
3+
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'.
5+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,24): error TS2304: Cannot find name 'f'.
6+
7+
8+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts (5 errors) ====
9+
a ? b ? c : (d) : e => f
10+
~
11+
!!! error TS2304: Cannot find name 'a'.
12+
~
13+
!!! error TS2304: Cannot find name 'b'.
14+
~
15+
!!! error TS2304: Cannot find name 'c'.
16+
~
17+
!!! error TS2304: Cannot find name 'd'.
18+
~
19+
!!! error TS2304: Cannot find name 'f'.
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [parserArrowFunctionExpression11.ts]
2+
a ? b ? c : (d) : e => f
3+
4+
5+
//// [parserArrowFunctionExpression11.js]
6+
a ? b ? c : (d) : function (e) { return f; };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts ===
2+
a ? b ? c : (d) : e => f
3+
>e : Symbol(e, Decl(parserArrowFunctionExpression11.ts, 0, 17))
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts ===
2+
a ? b ? c : (d) : e => f
3+
>a ? b ? c : (d) : e => f : any
4+
>a : any
5+
>b ? c : (d) : any
6+
>b : any
7+
>c : any
8+
>(d) : any
9+
>d : any
10+
>e => f : (e: any) => any
11+
>e : any
12+
>f : any
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
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'.
3+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts(1,22): error TS2304: Cannot find name 'e'.
4+
5+
6+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts (3 errors) ====
7+
a ? (b) => (c): d => e
8+
~
9+
!!! error TS2304: Cannot find name 'a'.
10+
~
11+
!!! error TS2304: Cannot find name 'c'.
12+
~
13+
!!! error TS2304: Cannot find name 'e'.
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [parserArrowFunctionExpression12.ts]
2+
a ? (b) => (c): d => e
3+
4+
5+
//// [parserArrowFunctionExpression12.js]
6+
a ? function (b) { return (c); } : function (d) { return e; };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts ===
2+
a ? (b) => (c): d => e
3+
>b : Symbol(b, Decl(parserArrowFunctionExpression12.ts, 0, 5))
4+
>d : Symbol(d, Decl(parserArrowFunctionExpression12.ts, 0, 15))
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts ===
2+
a ? (b) => (c): d => e
3+
>a ? (b) => (c): d => e : (b: any) => any
4+
>a : any
5+
>(b) => (c) : (b: any) => any
6+
>b : any
7+
>(c) : any
8+
>c : any
9+
>d => e : (d: any) => any
10+
>d : any
11+
>e : any
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts(1,1): error TS2304: Cannot find name 'a'.
2+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts(1,11): error TS2304: Cannot find name 'a'.
3+
4+
5+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts (2 errors) ====
6+
a ? () => a() : (): any => null;
7+
~
8+
!!! error TS2304: Cannot find name 'a'.
9+
~
10+
!!! error TS2304: Cannot find name 'a'.
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [parserArrowFunctionExpression13.ts]
2+
a ? () => a() : (): any => null;
3+
4+
5+
//// [parserArrowFunctionExpression13.js]
6+
a ? function () { return a(); } : function () { return null; };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts ===
2+
a ? () => a() : (): any => null;
3+
No type information for this code.
4+
No type information for this code.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts ===
2+
a ? () => a() : (): any => null;
3+
>a ? () => a() : (): any => null : () => any
4+
>a : any
5+
>() => a() : () => any
6+
>a() : any
7+
>a : any
8+
>(): any => null : () => any
9+
>null : null
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts(1,1): error TS2304: Cannot find name 'a'.
2+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts(1,40): error TS2304: Cannot find name 'd'.
3+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts(1,46): error TS2304: Cannot find name 'e'.
4+
5+
6+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts (3 errors) ====
7+
a() ? (b: number, c?: string): void => d() : e;
8+
~
9+
!!! error TS2304: Cannot find name 'a'.
10+
~
11+
!!! error TS2304: Cannot find name 'd'.
12+
~
13+
!!! error TS2304: Cannot find name 'e'.
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [parserArrowFunctionExpression14.ts]
2+
a() ? (b: number, c?: string): void => d() : e;
3+
4+
5+
//// [parserArrowFunctionExpression14.js]
6+
a() ? function (b, c) { return d(); } : e;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts ===
2+
a() ? (b: number, c?: string): void => d() : e;
3+
>b : Symbol(b, Decl(parserArrowFunctionExpression14.ts, 0, 7))
4+
>c : Symbol(c, Decl(parserArrowFunctionExpression14.ts, 0, 17))
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts ===
2+
a() ? (b: number, c?: string): void => d() : e;
3+
>a() ? (b: number, c?: string): void => d() : e : any
4+
>a() : any
5+
>a : any
6+
>(b: number, c?: string): void => d() : (b: number, c?: string) => void
7+
>b : number
8+
>c : string
9+
>d() : any
10+
>d : any
11+
>e : any
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts(1,1): error TS2304: Cannot find name 'x'.
2+
3+
4+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts (1 errors) ====
5+
x ? y => ({ y }) : z => ({ z })
6+
~
7+
!!! error TS2304: Cannot find name 'x'.
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [parserArrowFunctionExpression8.ts]
2+
x ? y => ({ y }) : z => ({ z })
3+
4+
5+
//// [parserArrowFunctionExpression8.js]
6+
x ? function (y) { return ({ y: y }); } : function (z) { return ({ z: z }); };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts ===
2+
x ? y => ({ y }) : z => ({ z })
3+
>y : Symbol(y, Decl(parserArrowFunctionExpression8.ts, 0, 3))
4+
>y : Symbol(y, Decl(parserArrowFunctionExpression8.ts, 0, 11))
5+
>z : Symbol(z, Decl(parserArrowFunctionExpression8.ts, 0, 18))
6+
>z : Symbol(z, Decl(parserArrowFunctionExpression8.ts, 0, 26))
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts ===
2+
x ? y => ({ y }) : z => ({ z })
3+
>x ? y => ({ y }) : z => ({ z }) : ((y: any) => { y: any; }) | ((z: any) => { z: any; })
4+
>x : any
5+
>y => ({ y }) : (y: any) => { y: any; }
6+
>y : any
7+
>({ y }) : { y: any; }
8+
>{ y } : { y: any; }
9+
>y : any
10+
>z => ({ z }) : (z: any) => { z: any; }
11+
>z : any
12+
>({ z }) : { z: any; }
13+
>{ z } : { z: any; }
14+
>z : any
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js(1,1): error TS2304: Cannot find name 'x'.
2+
3+
4+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js (1 errors) ====
5+
x ? y => ({ y }) : z => ({ z })
6+
~
7+
!!! error TS2304: Cannot find name 'x'.
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [file.js]
2+
x ? y => ({ y }) : z => ({ z })
3+
4+
5+
//// [file.js]
6+
x ? function (y) { return ({ y: y }); } : function (z) { return ({ z: z }); };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js ===
2+
x ? y => ({ y }) : z => ({ z })
3+
>y : Symbol(y, Decl(file.js, 0, 3))
4+
>y : Symbol(y, Decl(file.js, 0, 11))
5+
>z : Symbol(z, Decl(file.js, 0, 18))
6+
>z : Symbol(z, Decl(file.js, 0, 26))
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js ===
2+
x ? y => ({ y }) : z => ({ z })
3+
>x ? y => ({ y }) : z => ({ z }) : ((y: any) => { y: any; }) | ((z: any) => { z: any; })
4+
>x : any
5+
>y => ({ y }) : (y: any) => { y: any; }
6+
>y : any
7+
>({ y }) : { y: any; }
8+
>{ y } : { y: any; }
9+
>y : any
10+
>z => ({ z }) : (z: any) => { z: any; }
11+
>z : any
12+
>({ z }) : { z: any; }
13+
>{ z } : { z: any; }
14+
>z : any
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
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'.
3+
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts(1,16): error TS2304: Cannot find name 'e'.
4+
5+
6+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts (3 errors) ====
7+
b ? (c) : d => e
8+
~
9+
!!! error TS2304: Cannot find name 'b'.
10+
~
11+
!!! error TS2304: Cannot find name 'c'.
12+
~
13+
!!! error TS2304: Cannot find name 'e'.
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [parserArrowFunctionExpression9.ts]
2+
b ? (c) : d => e
3+
4+
5+
//// [parserArrowFunctionExpression9.js]
6+
b ? (c) : function (d) { return e; };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts ===
2+
b ? (c) : d => e
3+
>d : Symbol(d, Decl(parserArrowFunctionExpression9.ts, 0, 9))
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts ===
2+
b ? (c) : d => e
3+
>b ? (c) : d => e : any
4+
>b : any
5+
>(c) : any
6+
>c : any
7+
>d => e : (d: any) => any
8+
>d : any
9+
>e : any
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a ? (b) : c => (d) : e => f
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a ? b ? c : (d) : e => f
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a ? (b) => (c): d => e
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a ? () => a() : (): any => null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a() ? (b: number, c?: string): void => d() : e;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x ? y => ({ y }) : z => ({ z })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @filename: file.js
2+
// @allowjs: true
3+
// @checkjs: true
4+
// @outdir: out
5+
6+
x ? y => ({ y }) : z => ({ z })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b ? (c) : d => e

0 commit comments

Comments
 (0)