Skip to content

Commit

Permalink
Strict, but only on true side
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Apr 20, 2022
1 parent f5ecb51 commit 47afffd
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4369,7 +4369,7 @@ namespace ts {
}

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

function isYieldExpression(): boolean {
Expand Down Expand Up @@ -4788,7 +4788,7 @@ namespace ts {
return node;
}

function parseConditionalExpressionRest(leftOperand: Expression, pos: number): Expression {
function parseConditionalExpressionRest(leftOperand: Expression, pos: number, disallowReturnTypeInArrowFunction: boolean): Expression {
// Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher.
const questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
if (!questionToken) {
Expand All @@ -4805,7 +4805,7 @@ namespace ts {
doOutsideOfContext(disallowInAndDecoratorContext, () => parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ true)),
colonToken = parseExpectedToken(SyntaxKind.ColonToken),
nodeIsPresent(colonToken)
? parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ true)
? parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction) // inherit disallowReturnTypeInArrowFunction in false side
: createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken))
),
pos
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
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,22): error TS2304: Cannot find name 'e'.
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) ====
==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts (4 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 'e'.
~
!!! error TS2304: Cannot find name 'f'.

3 changes: 1 addition & 2 deletions tests/baselines/reference/parserArrowFunctionExpression10.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ a ? (b) : c => (d) : e => f


//// [parserArrowFunctionExpression10.js]
a ? (b) : function (c) { return (d); };
(function (e) { return f; });
a ? (b) : function (c) { return function (d) { return f; }; };
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
=== 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))
>d : Symbol(d, Decl(parserArrowFunctionExpression10.ts, 0, 16))
>e : Symbol(e)

Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
=== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression10.ts ===
a ? (b) : c => (d) : e => f
>a ? (b) : c => (d) : any
>a ? (b) : c => (d) : e => f : any
>a : any
>(b) : any
>b : any
>c => (d) : (c: any) => any
>c => (d) : e => f : (c: any) => (d: any) => e
>c : any
>(d) : any
>(d) : e => f : (d: any) => e
>d : any
>e => f : (e: any) => any
>e : any
>f : any

Original file line number Diff line number Diff line change
@@ -1,17 +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(1,18): error TS1109: Expression expected.
tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts(1,19): error TS1005: ';' expected.


==== tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression13.ts (4 errors) ====
==== 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'.
~
!!! error TS1109: Expression expected.
~
!!! error TS1005: ';' expected.

3 changes: 1 addition & 2 deletions tests/baselines/reference/parserArrowFunctionExpression13.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ a ? () => a() : (): any => null;


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

0 comments on commit 47afffd

Please sign in to comment.