From 2856aabd70463e320ccc0afc9a0d813187d17d9d Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 21 May 2019 15:28:16 -0700 Subject: [PATCH] Parse stray identifier-ish as JSXText instead of trivia --- src/compiler/parser.ts | 5 +++-- src/harness/fourslash.ts | 9 +++++---- tests/cases/fourslash/fourslash.ts | 2 +- .../fourslash/jsxExpressionFollowedByIdentifier.ts | 13 +++++-------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f3b0c2c06e6..e56ff98846e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4439,8 +4439,9 @@ namespace ts { parseExpected(SyntaxKind.CloseBraceToken); } else { - parseExpected(SyntaxKind.CloseBraceToken, /*message*/ undefined, /*shouldAdvance*/ false); - scanJsxText(); + if (parseExpected(SyntaxKind.CloseBraceToken, /*message*/ undefined, /*shouldAdvance*/ false)) { + scanJsxText(); + } } return finishNode(node); diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index a2e2c0f29af..5d0725ea106 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -582,12 +582,13 @@ namespace FourSlash { }); } - public verifyErrorExistsAtRange(range: Range, code: number) { + public verifyErrorExistsAtRange(range: Range, code: number, expectedMessage?: string) { const span = ts.createTextSpanFromRange(range); const hasMatchingError = ts.some( this.getDiagnostics(range.fileName), - ({ code, start, length }) => + ({ code, messageText, start, length }) => code === code && + (!expectedMessage || expectedMessage === messageText) && ts.isNumber(start) && ts.isNumber(length) && ts.textSpansEqual(span, { start, length })); @@ -3982,8 +3983,8 @@ namespace FourSlashInterface { this.state.verifyNoErrors(); } - public errorExistsAtRange(range: FourSlash.Range, code: number) { - this.state.verifyErrorExistsAtRange(range, code); + public errorExistsAtRange(range: FourSlash.Range, code: number, message?: string) { + this.state.verifyErrorExistsAtRange(range, code, message); } public numberOfErrorsInCurrentFile(expected: number) { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 427a3558b31..e6f2a08f002 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -238,7 +238,7 @@ declare namespace FourSlashInterface { signatureHelp(...options: VerifySignatureHelpOptions[], ): void; // Checks that there are no compile errors. noErrors(): void; - errorExistsAtRange(range: Range, code: number): void; + errorExistsAtRange(range: Range, code: number, message?: string): void; numberOfErrorsInCurrentFile(expected: number): void; baselineCurrentFileBreakpointLocations(): void; baselineCurrentFileNameOrDottedNameSpans(): void; diff --git a/tests/cases/fourslash/jsxExpressionFollowedByIdentifier.ts b/tests/cases/fourslash/jsxExpressionFollowedByIdentifier.ts index d040bacd546..501a325b989 100644 --- a/tests/cases/fourslash/jsxExpressionFollowedByIdentifier.ts +++ b/tests/cases/fourslash/jsxExpressionFollowedByIdentifier.ts @@ -2,14 +2,11 @@ //@Filename: jsxExpressionFollowedByIdentifier.tsx ////declare var React: any; -////declare var x: string; ////const a =
{
[|x|]}
////const b =
[|x|]} /> -const range = test.ranges()[0]; -verify.getSyntacticDiagnostics([{ - code: 1005, - message: "'}' expected.", - range, -}]); -verify.quickInfoAt(range, 'var x: string'); \ No newline at end of file +test.ranges().forEach(range => { + verify.errorExistsAtRange(range, 1005, "'}' expected."); + // This is just to ensure getting quick info doesn’t crash + verify.not.quickInfoExists(); +});