From 372f640a2cfb871f7cd51ffe586b709af05c9c15 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 16 Feb 2023 19:06:03 -0500 Subject: [PATCH 1/2] Fix crash in 'Wrap in JSX Fragment' quick fix --- src/services/formatting/formatting.ts | 4 ++-- .../fourslash/codeFixWrapJsxInFragmentWithGrammarError1.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/codeFixWrapJsxInFragmentWithGrammarError1.ts diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 51d9950f562f7..0c08ffac50460 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 0000000000000..2e17dc67d79d4 --- /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); From 1bdbbc36754a402bdf9e8a9acfd543f1fa4c246e Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 16 Feb 2023 20:47:07 -0500 Subject: [PATCH 2/2] Update failing test --- tests/cases/fourslash/refactorExtractTypeRemoveGrammarError2.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/refactorExtractTypeRemoveGrammarError2.ts b/tests/cases/fourslash/refactorExtractTypeRemoveGrammarError2.ts index e1c7fa2b05c72..f6762c1e3f459 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`, });