From fd0370822fab65cddff7d2d6fe6ce04d0f048a11 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 16 Feb 2023 21:34:58 -0500 Subject: [PATCH] Fix crash in 'Wrap in JSX Fragment' quick fix (#52816) --- src/services/formatting/formatting.ts | 4 ++-- .../fourslash/codeFixWrapJsxInFragmentWithGrammarError1.ts | 7 +++++++ .../fourslash/refactorExtractTypeRemoveGrammarError2.ts | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/codeFixWrapJsxInFragmentWithGrammarError1.ts diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 51d9950f562..0c08ffac504 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -804,7 +804,7 @@ function formatSpanWorker( isFirstListItem?: boolean): number { Debug.assert(!nodeIsSynthesized(child)); - if (nodeIsMissing(child)) { + if (nodeIsMissing(child) || isGrammarError(parent, child)) { return inheritedIndentation; } @@ -864,7 +864,7 @@ function formatSpanWorker( // if child node is a token, it does not impact indentation, proceed it using parent indentation scope rules const tokenInfo = formattingScanner.readTokenInfo(child); // JSX text shouldn't affect indenting - if (child.kind !== SyntaxKind.JsxText && !isGrammarError(parent, child)) { + if (child.kind !== SyntaxKind.JsxText) { Debug.assert(tokenInfo.token.end === child.end, "Token end is child end"); consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation, child); return inheritedIndentation; diff --git a/tests/cases/fourslash/codeFixWrapJsxInFragmentWithGrammarError1.ts b/tests/cases/fourslash/codeFixWrapJsxInFragmentWithGrammarError1.ts new file mode 100644 index 00000000000..2e17dc67d79 --- /dev/null +++ b/tests/cases/fourslash/codeFixWrapJsxInFragmentWithGrammarError1.ts @@ -0,0 +1,7 @@ +/// + +// @jsx: react-jsxdev +// @Filename: /a.tsx +////[|
|] + +verify.rangeAfterCodeFix(`<>
`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0); diff --git a/tests/cases/fourslash/refactorExtractTypeRemoveGrammarError2.ts b/tests/cases/fourslash/refactorExtractTypeRemoveGrammarError2.ts index e1c7fa2b05c..f6762c1e3f4 100644 --- a/tests/cases/fourslash/refactorExtractTypeRemoveGrammarError2.ts +++ b/tests/cases/fourslash/refactorExtractTypeRemoveGrammarError2.ts @@ -11,7 +11,7 @@ edit.applyRefactor({ newContent: `type /*RENAME*/NewType = { x: string; - }; +}; type Foo = T`, });