Skip to content

Commit

Permalink
fix(44249): JSX: "extract to constant" generates invalid code when us…
Browse files Browse the repository at this point in the history
…ing fragment syntax (#44252)

Fixes #44249
  • Loading branch information
OliverJAsh authored May 26, 2021
1 parent 459bd19 commit 3e29397
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/services/refactors/extractSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,6 @@ namespace ts.refactor.extractSymbol {
}

function isInJSXContent(node: Node) {
return (isJsxElement(node) || isJsxSelfClosingElement(node) || isJsxFragment(node)) && isJsxElement(node.parent);
return (isJsxElement(node) || isJsxSelfClosingElement(node) || isJsxFragment(node)) && (isJsxElement(node.parent) || isJsxFragment(node.parent));
}
}
28 changes: 28 additions & 0 deletions tests/cases/fourslash/extract-const_insideJsxFragment1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// <reference path='fourslash.ts' />

// @jsx: preserve
// @filename: a.tsx
////function Foo() {
//// return (
//// <>
//// /*a*/<span></span>/*b*/
//// </>
//// );
////}

goTo.file("a.tsx");
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Extract Symbol",
actionName: "constant_scope_1",
actionDescription: "Extract to constant in global scope",
newContent:
`const /*RENAME*/newLocal = <span></span>;
function Foo() {
return (
<>
{newLocal}
</>
);
}`
});

0 comments on commit 3e29397

Please sign in to comment.