Skip to content

Commit 96660f6

Browse files
committed
Just look at the current node instead of context
1 parent 9699080 commit 96660f6

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/compiler/parser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,9 +3693,11 @@ namespace ts {
36933693
// - "(x = 10)" is an assignment expression parsed as a signature with a default parameter value.
36943694
// - "(x,y)" is a comma expression parsed as a signature with two parameters.
36953695
// - "a ? (b): c" will have "(b):" parsed as a signature with a return type annotation.
3696+
// - "a ? (b): function() {}" will too, since function() is a valid JSDoc function type.
36963697
//
36973698
// So we need just a bit of lookahead to ensure that it can only be a signature.
3698-
if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && (contextFlags & NodeFlags.InConditionalWhenTrue || token() !== SyntaxKind.OpenBraceToken)) {
3699+
const hasJSDocFunctionType = node.type && isJSDocFunctionType(node.type);
3700+
if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && (hasJSDocFunctionType || token() !== SyntaxKind.OpenBraceToken)) {
36993701
// Returning undefined here will cause our caller to rewind to where we started from.
37003702
return undefined;
37013703
}
@@ -3747,9 +3749,7 @@ namespace ts {
37473749
const node = <ConditionalExpression>createNode(SyntaxKind.ConditionalExpression, leftOperand.pos);
37483750
node.condition = leftOperand;
37493751
node.questionToken = questionToken;
3750-
node.whenTrue = doInsideOfContext(
3751-
NodeFlags.InConditionalWhenTrue,
3752-
() => doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher));
3752+
node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher);
37533753
node.colonToken = parseExpectedToken(SyntaxKind.ColonToken);
37543754
node.whenFalse = nodeIsPresent(node.colonToken)
37553755
? parseAssignmentExpressionOrHigher()

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ namespace ts {
553553
/* @internal */ Ambient = 1 << 22, // If node was inside an ambient context -- a declaration file, or inside something with the `declare` modifier.
554554
/* @internal */ InWithStatement = 1 << 23, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`)
555555
JsonFile = 1 << 24, // If node was parsed in a Json
556-
/* @internal */ InConditionalWhenTrue = 1 << 25, // If node was parsed in the true side of a ConditionalExpression
557556

558557
BlockScoped = Let | Const,
559558

0 commit comments

Comments
 (0)