From 0ecdc876f38c1660cf8b686708149a81fc56e96d Mon Sep 17 00:00:00 2001 From: Wenlu Wang <805037171@163.com> Date: Tue, 9 Jan 2018 05:16:17 +0800 Subject: [PATCH] imporve conditional operator if missing colon token (#20498) f2 --- src/compiler/parser.ts | 4 +++- .../baselines/reference/jsxAndTypeAssertion.errors.txt | 10 ++-------- .../completionWithConditionalOperatorMissingColon.ts | 6 ++++++ 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 tests/cases/fourslash/completionWithConditionalOperatorMissingColon.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a072579ed63..ce2ad27329e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3504,7 +3504,9 @@ namespace ts { node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher); node.colonToken = parseExpectedToken(SyntaxKind.ColonToken, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken)); - node.whenFalse = parseAssignmentExpressionOrHigher(); + node.whenFalse = nodeIsPresent(node.colonToken) + ? parseAssignmentExpressionOrHigher() + : createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken)); return finishNode(node); } diff --git a/tests/baselines/reference/jsxAndTypeAssertion.errors.txt b/tests/baselines/reference/jsxAndTypeAssertion.errors.txt index d5df3915bf6..5aa92086c37 100644 --- a/tests/baselines/reference/jsxAndTypeAssertion.errors.txt +++ b/tests/baselines/reference/jsxAndTypeAssertion.errors.txt @@ -10,13 +10,11 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(14,45): error TS1005: '}' ex tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(18,2): error TS17008: JSX element 'foo' has no corresponding closing tag. tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(18,8): error TS17008: JSX element 'foo' has no corresponding closing tag. tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(18,13): error TS17008: JSX element 'foo' has no corresponding closing tag. -tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(18,83): error TS1109: Expression expected. tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: ':' expected. tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: ' +////1 ? fun/*1*/ +////function func () {} + +goTo.marker("1"); +verify.completionListContains("func");