Skip to content

Commit 805a61d

Browse files
committed
Strict, but only on true side
1 parent fb6ba84 commit 805a61d

9 files changed

+19
-30
lines changed

src/compiler/parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,7 +4369,7 @@ namespace ts {
43694369
}
43704370

43714371
// It wasn't an assignment or a lambda. This is a conditional expression:
4372-
return parseConditionalExpressionRest(expr, pos);
4372+
return parseConditionalExpressionRest(expr, pos, disallowReturnTypeInArrowFunction);
43734373
}
43744374

43754375
function isYieldExpression(): boolean {
@@ -4783,7 +4783,7 @@ namespace ts {
47834783
return node;
47844784
}
47854785

4786-
function parseConditionalExpressionRest(leftOperand: Expression, pos: number): Expression {
4786+
function parseConditionalExpressionRest(leftOperand: Expression, pos: number, disallowReturnTypeInArrowFunction: boolean): Expression {
47874787
// Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher.
47884788
const questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
47894789
if (!questionToken) {
@@ -4800,7 +4800,7 @@ namespace ts {
48004800
doOutsideOfContext(disallowInAndDecoratorContext, () => parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ true)),
48014801
colonToken = parseExpectedToken(SyntaxKind.ColonToken),
48024802
nodeIsPresent(colonToken)
4803-
? parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ true)
4803+
? parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction) // inherit disallowReturnTypeInArrowFunction in false side
48044804
: createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken))
48054805
),
48064806
pos
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts(1,1): error TS2304: Cannot find name 'a'.
22
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.
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'.
65

76

8-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts (5 errors) ====
7+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts (4 errors) ====
98
a ? (b) : c => (d) : e => f
109
~
1110
!!! error TS2304: Cannot find name 'a'.
1211
~
1312
!!! error TS2304: Cannot find name 'b'.
14-
~
15-
!!! error TS2304: Cannot find name 'd'.
16-
~
17-
!!! error TS1005: ';' expected.
13+
~
14+
!!! error TS2304: Cannot find name 'e'.
1815
~
1916
!!! error TS2304: Cannot find name 'f'.
2017

tests/baselines/reference/parserArrowFunctionExpression10.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ 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 ? (b) : function (c) { return function (d) { return f; }; };
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/parserArrowFunctionExpression10.ts ===
22
a ? (b) : c => (d) : e => f
33
>c : Symbol(c, Decl(parserArrowFunctionExpression10.ts, 0, 9))
4-
>e : Symbol(e, Decl(parserArrowFunctionExpression10.ts, 0, 20))
4+
>d : Symbol(d, Decl(parserArrowFunctionExpression10.ts, 0, 16))
5+
>e : Symbol(e)
56

Lines changed: 3 additions & 5 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
55
>(b) : any
66
>b : any
7-
>c => (d) : (c: any) => any
7+
>c => (d) : e => f : (c: any) => (d: any) => e
88
>c : any
9-
>(d) : any
9+
>(d) : e => f : (d: any) => e
1010
>d : any
11-
>e => f : (e: any) => any
12-
>e : any
1311
>f : any
1412

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts(1,1): error TS2304: Cannot find name 'a'.
22
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts(1,11): error TS2304: Cannot find name 'a'.
3-
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts(1,19): error TS1109: Expression expected.
43

54

6-
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts (3 errors) ====
5+
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts (2 errors) ====
76
a ? () => a() : (): any => null;
87
~
98
!!! error TS2304: Cannot find name 'a'.
109
~
1110
!!! error TS2304: Cannot find name 'a'.
12-
~
13-
!!! error TS1109: Expression expected.
1411

tests/baselines/reference/parserArrowFunctionExpression13.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ a ? () => a() : (): any => null;
33

44

55
//// [parserArrowFunctionExpression13.js]
6-
a ? function () { return a(); } : ;
7-
(function (any) { return null; });
6+
a ? function () { return a(); } : function () { return null; };
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts ===
22
a ? () => a() : (): any => null;
3-
>any : Symbol(any, Decl(parserArrowFunctionExpression13.ts, 0, 19))
4-
3+
No type information for this code.
4+
No type information for this code.
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts ===
22
a ? () => a() : (): any => null;
3-
>a ? () => a() : () : any
3+
>a ? () => a() : (): any => null : () => any
44
>a : any
55
>() => a() : () => any
66
>a() : any
77
>a : any
8-
> : any
9-
>any => null : (any: any) => any
10-
>any : any
8+
>(): any => null : () => any
119
>null : null
1210

0 commit comments

Comments
 (0)