fix(44249): JSX: "extract to constant" generates invalid code when using fragment syntax (#44252)

Fixes https://github.com/microsoft/TypeScript/issues/44249
This commit is contained in:
Oliver Joseph Ash 2021-05-26 21:24:02 +01:00 committed by GitHub
parent 459bd19941
commit 3e29397d74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -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));
}
}

View File

@ -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}
</>
);
}`
});