Skip to content

Commit fd03708

Browse files
authored
Fix crash in 'Wrap in JSX Fragment' quick fix (#52816)
1 parent 3980b5b commit fd03708

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/services/formatting/formatting.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ function formatSpanWorker(
804804
isFirstListItem?: boolean): number {
805805
Debug.assert(!nodeIsSynthesized(child));
806806

807-
if (nodeIsMissing(child)) {
807+
if (nodeIsMissing(child) || isGrammarError(parent, child)) {
808808
return inheritedIndentation;
809809
}
810810

@@ -864,7 +864,7 @@ function formatSpanWorker(
864864
// if child node is a token, it does not impact indentation, proceed it using parent indentation scope rules
865865
const tokenInfo = formattingScanner.readTokenInfo(child);
866866
// JSX text shouldn't affect indenting
867-
if (child.kind !== SyntaxKind.JsxText && !isGrammarError(parent, child)) {
867+
if (child.kind !== SyntaxKind.JsxText) {
868868
Debug.assert(tokenInfo.token.end === child.end, "Token end is child end");
869869
consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation, child);
870870
return inheritedIndentation;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @jsx: react-jsxdev
4+
// @Filename: /a.tsx
5+
////[|<div abc={{ foo = 10 }}></div><div abc={{ foo = 10 }}></div>|]
6+
7+
verify.rangeAfterCodeFix(`<><div abc={{ foo = 10 }}></div><div abc={{ foo = 10 }}></div></>`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0);

tests/cases/fourslash/refactorExtractTypeRemoveGrammarError2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ edit.applyRefactor({
1111
newContent:
1212
`type /*RENAME*/NewType = {
1313
x: string;
14-
};
14+
};
1515
1616
type Foo<T extends NewType> = T`,
1717
});

0 commit comments

Comments
 (0)