Skip to content

Commit 3e29397

Browse files
authored
fix(44249): JSX: "extract to constant" generates invalid code when using fragment syntax (#44252)
Fixes #44249
1 parent 459bd19 commit 3e29397

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/services/refactors/extractSymbol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,6 @@ namespace ts.refactor.extractSymbol {
20022002
}
20032003

20042004
function isInJSXContent(node: Node) {
2005-
return (isJsxElement(node) || isJsxSelfClosingElement(node) || isJsxFragment(node)) && isJsxElement(node.parent);
2005+
return (isJsxElement(node) || isJsxSelfClosingElement(node) || isJsxFragment(node)) && (isJsxElement(node.parent) || isJsxFragment(node.parent));
20062006
}
20072007
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @jsx: preserve
4+
// @filename: a.tsx
5+
////function Foo() {
6+
//// return (
7+
//// <>
8+
//// /*a*/<span></span>/*b*/
9+
//// </>
10+
//// );
11+
////}
12+
13+
goTo.file("a.tsx");
14+
goTo.select("a", "b");
15+
edit.applyRefactor({
16+
refactorName: "Extract Symbol",
17+
actionName: "constant_scope_1",
18+
actionDescription: "Extract to constant in global scope",
19+
newContent:
20+
`const /*RENAME*/newLocal = <span></span>;
21+
function Foo() {
22+
return (
23+
<>
24+
{newLocal}
25+
</>
26+
);
27+
}`
28+
});

0 commit comments

Comments
 (0)