Skip to content

Commit

Permalink
Don't treat a colon in a conditional expression branch as part of an …
Browse files Browse the repository at this point in the history
…arrow function (microsoft#47550)
  • Loading branch information
jakebailey authored Feb 25, 2022
1 parent dda6583 commit 2dede20
Show file tree
Hide file tree
Showing 41 changed files with 363 additions and 32 deletions.
82 changes: 50 additions & 32 deletions src/compiler/parser.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,1): error TS2304: Cannot find name 'a'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,6): error TS2304: Cannot find name 'b'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,17): error TS2304: Cannot find name 'd'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,20): error TS1005: ';' expected.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,27): error TS2304: Cannot find name 'f'.


==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts (5 errors) ====
a ? (b) : c => (d) : e => f
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS2304: Cannot find name 'b'.
~
!!! error TS2304: Cannot find name 'd'.
~
!!! error TS1005: ';' expected.
~
!!! error TS2304: Cannot find name 'f'.

7 changes: 7 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [parserArrowFunctionExpression10.ts]
a ? (b) : c => (d) : e => f


//// [parserArrowFunctionExpression10.js]
a ? (b) : function (c) { return (d); };
(function (e) { return f; });
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts ===
a ? (b) : c => (d) : e => f
>c : Symbol(c, Decl(parserArrowFunctionExpression10.ts, 0, 9))
>e : Symbol(e, Decl(parserArrowFunctionExpression10.ts, 0, 20))

14 changes: 14 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression10.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts ===
a ? (b) : c => (d) : e => f
>a ? (b) : c => (d) : any
>a : any
>(b) : any
>b : any
>c => (d) : (c: any) => any
>c : any
>(d) : any
>d : any
>e => f : (e: any) => any
>e : any
>f : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,1): error TS2304: Cannot find name 'a'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,5): error TS2304: Cannot find name 'b'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,9): error TS2304: Cannot find name 'c'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,14): error TS2304: Cannot find name 'd'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts(1,24): error TS2304: Cannot find name 'f'.


==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts (5 errors) ====
a ? b ? c : (d) : e => f
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS2304: Cannot find name 'b'.
~
!!! error TS2304: Cannot find name 'c'.
~
!!! error TS2304: Cannot find name 'd'.
~
!!! error TS2304: Cannot find name 'f'.

6 changes: 6 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [parserArrowFunctionExpression11.ts]
a ? b ? c : (d) : e => f


//// [parserArrowFunctionExpression11.js]
a ? b ? c : (d) : function (e) { return f; };
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts ===
a ? b ? c : (d) : e => f
>e : Symbol(e, Decl(parserArrowFunctionExpression11.ts, 0, 17))

13 changes: 13 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression11.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression11.ts ===
a ? b ? c : (d) : e => f
>a ? b ? c : (d) : e => f : any
>a : any
>b ? c : (d) : any
>b : any
>c : any
>(d) : any
>d : any
>e => f : (e: any) => any
>e : any
>f : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts(1,1): error TS2304: Cannot find name 'a'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts(1,13): error TS2304: Cannot find name 'c'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts(1,22): error TS2304: Cannot find name 'e'.


==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts (3 errors) ====
a ? (b) => (c): d => e
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS2304: Cannot find name 'c'.
~
!!! error TS2304: Cannot find name 'e'.

6 changes: 6 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression12.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [parserArrowFunctionExpression12.ts]
a ? (b) => (c): d => e


//// [parserArrowFunctionExpression12.js]
a ? function (b) { return (c); } : function (d) { return e; };
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts ===
a ? (b) => (c): d => e
>b : Symbol(b, Decl(parserArrowFunctionExpression12.ts, 0, 5))
>d : Symbol(d, Decl(parserArrowFunctionExpression12.ts, 0, 15))

12 changes: 12 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression12.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression12.ts ===
a ? (b) => (c): d => e
>a ? (b) => (c): d => e : (b: any) => any
>a : any
>(b) => (c) : (b: any) => any
>b : any
>(c) : any
>c : any
>d => e : (d: any) => any
>d : any
>e : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts(1,1): error TS2304: Cannot find name 'a'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts(1,11): error TS2304: Cannot find name 'a'.


==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts (2 errors) ====
a ? () => a() : (): any => null;
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS2304: Cannot find name 'a'.

6 changes: 6 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression13.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [parserArrowFunctionExpression13.ts]
a ? () => a() : (): any => null;


//// [parserArrowFunctionExpression13.js]
a ? function () { return a(); } : function () { return null; };
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts ===
a ? () => a() : (): any => null;
No type information for this code.
No type information for this code.
10 changes: 10 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression13.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts ===
a ? () => a() : (): any => null;
>a ? () => a() : (): any => null : () => any
>a : any
>() => a() : () => any
>a() : any
>a : any
>(): any => null : () => any
>null : null

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts(1,1): error TS2304: Cannot find name 'a'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts(1,40): error TS2304: Cannot find name 'd'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts(1,46): error TS2304: Cannot find name 'e'.


==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts (3 errors) ====
a() ? (b: number, c?: string): void => d() : e;
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS2304: Cannot find name 'd'.
~
!!! error TS2304: Cannot find name 'e'.

6 changes: 6 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression14.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [parserArrowFunctionExpression14.ts]
a() ? (b: number, c?: string): void => d() : e;


//// [parserArrowFunctionExpression14.js]
a() ? function (b, c) { return d(); } : e;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts ===
a() ? (b: number, c?: string): void => d() : e;
>b : Symbol(b, Decl(parserArrowFunctionExpression14.ts, 0, 7))
>c : Symbol(c, Decl(parserArrowFunctionExpression14.ts, 0, 17))

12 changes: 12 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression14.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression14.ts ===
a() ? (b: number, c?: string): void => d() : e;
>a() ? (b: number, c?: string): void => d() : e : any
>a() : any
>a : any
>(b: number, c?: string): void => d() : (b: number, c?: string) => void
>b : number
>c : string
>d() : any
>d : any
>e : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts(1,1): error TS2304: Cannot find name 'x'.


==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts (1 errors) ====
x ? y => ({ y }) : z => ({ z })
~
!!! error TS2304: Cannot find name 'x'.

6 changes: 6 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [parserArrowFunctionExpression8.ts]
x ? y => ({ y }) : z => ({ z })


//// [parserArrowFunctionExpression8.js]
x ? function (y) { return ({ y: y }); } : function (z) { return ({ z: z }); };
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts ===
x ? y => ({ y }) : z => ({ z })
>y : Symbol(y, Decl(parserArrowFunctionExpression8.ts, 0, 3))
>y : Symbol(y, Decl(parserArrowFunctionExpression8.ts, 0, 11))
>z : Symbol(z, Decl(parserArrowFunctionExpression8.ts, 0, 18))
>z : Symbol(z, Decl(parserArrowFunctionExpression8.ts, 0, 26))

15 changes: 15 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression8.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression8.ts ===
x ? y => ({ y }) : z => ({ z })
>x ? y => ({ y }) : z => ({ z }) : ((y: any) => { y: any; }) | ((z: any) => { z: any; })
>x : any
>y => ({ y }) : (y: any) => { y: any; }
>y : any
>({ y }) : { y: any; }
>{ y } : { y: any; }
>y : any
>z => ({ z }) : (z: any) => { z: any; }
>z : any
>({ z }) : { z: any; }
>{ z } : { z: any; }
>z : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js(1,1): error TS2304: Cannot find name 'x'.


==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js (1 errors) ====
x ? y => ({ y }) : z => ({ z })
~
!!! error TS2304: Cannot find name 'x'.

6 changes: 6 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression8Js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [file.js]
x ? y => ({ y }) : z => ({ z })


//// [file.js]
x ? function (y) { return ({ y: y }); } : function (z) { return ({ z: z }); };
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js ===
x ? y => ({ y }) : z => ({ z })
>y : Symbol(y, Decl(file.js, 0, 3))
>y : Symbol(y, Decl(file.js, 0, 11))
>z : Symbol(z, Decl(file.js, 0, 18))
>z : Symbol(z, Decl(file.js, 0, 26))

15 changes: 15 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression8Js.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/file.js ===
x ? y => ({ y }) : z => ({ z })
>x ? y => ({ y }) : z => ({ z }) : ((y: any) => { y: any; }) | ((z: any) => { z: any; })
>x : any
>y => ({ y }) : (y: any) => { y: any; }
>y : any
>({ y }) : { y: any; }
>{ y } : { y: any; }
>y : any
>z => ({ z }) : (z: any) => { z: any; }
>z : any
>({ z }) : { z: any; }
>{ z } : { z: any; }
>z : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts(1,1): error TS2304: Cannot find name 'b'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts(1,6): error TS2304: Cannot find name 'c'.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts(1,16): error TS2304: Cannot find name 'e'.


==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts (3 errors) ====
b ? (c) : d => e
~
!!! error TS2304: Cannot find name 'b'.
~
!!! error TS2304: Cannot find name 'c'.
~
!!! error TS2304: Cannot find name 'e'.

6 changes: 6 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [parserArrowFunctionExpression9.ts]
b ? (c) : d => e


//// [parserArrowFunctionExpression9.js]
b ? (c) : function (d) { return e; };
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts ===
b ? (c) : d => e
>d : Symbol(d, Decl(parserArrowFunctionExpression9.ts, 0, 9))

10 changes: 10 additions & 0 deletions tests/baselines/reference/parserArrowFunctionExpression9.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression9.ts ===
b ? (c) : d => e
>b ? (c) : d => e : any
>b : any
>(c) : any
>c : any
>d => e : (d: any) => any
>d : any
>e : any

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a ? (b) : c => (d) : e => f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a ? b ? c : (d) : e => f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a ? (b) => (c): d => e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a ? () => a() : (): any => null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a() ? (b: number, c?: string): void => d() : e;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x ? y => ({ y }) : z => ({ z })
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @filename: file.js
// @allowjs: true
// @checkjs: true
// @outdir: out

x ? y => ({ y }) : z => ({ z })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b ? (c) : d => e

0 comments on commit 2dede20

Please sign in to comment.