Just look at the current node instead of context

This commit is contained in:
Andrew Branch 2019-04-02 11:31:05 -07:00
parent 96990800e3
commit 96660f6c00
No known key found for this signature in database
GPG Key ID: 22CCA4B120C427D2
2 changed files with 4 additions and 5 deletions

View File

@ -3693,9 +3693,11 @@ namespace ts {
// - "(x = 10)" is an assignment expression parsed as a signature with a default parameter value.
// - "(x,y)" is a comma expression parsed as a signature with two parameters.
// - "a ? (b): c" will have "(b):" parsed as a signature with a return type annotation.
// - "a ? (b): function() {}" will too, since function() is a valid JSDoc function type.
//
// So we need just a bit of lookahead to ensure that it can only be a signature.
if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && (contextFlags & NodeFlags.InConditionalWhenTrue || token() !== SyntaxKind.OpenBraceToken)) {
const hasJSDocFunctionType = node.type && isJSDocFunctionType(node.type);
if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && (hasJSDocFunctionType || token() !== SyntaxKind.OpenBraceToken)) {
// Returning undefined here will cause our caller to rewind to where we started from.
return undefined;
}
@ -3747,9 +3749,7 @@ namespace ts {
const node = <ConditionalExpression>createNode(SyntaxKind.ConditionalExpression, leftOperand.pos);
node.condition = leftOperand;
node.questionToken = questionToken;
node.whenTrue = doInsideOfContext(
NodeFlags.InConditionalWhenTrue,
() => doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher));
node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher);
node.colonToken = parseExpectedToken(SyntaxKind.ColonToken);
node.whenFalse = nodeIsPresent(node.colonToken)
? parseAssignmentExpressionOrHigher()

View File

@ -553,7 +553,6 @@ namespace ts {
/* @internal */ Ambient = 1 << 22, // If node was inside an ambient context -- a declaration file, or inside something with the `declare` modifier.
/* @internal */ InWithStatement = 1 << 23, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`)
JsonFile = 1 << 24, // If node was parsed in a Json
/* @internal */ InConditionalWhenTrue = 1 << 25, // If node was parsed in the true side of a ConditionalExpression
BlockScoped = Let | Const,