Merge pull request #30699 from andrewbranch/bug/30635

Fix ternaries where "true" is a parenthesized variable and "false" is a function expression
This commit is contained in:
Andrew Branch
2019-04-02 14:03:11 -07:00
committed by GitHub
5 changed files with 33 additions and 1 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 && 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;
}