mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
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:
parent
459bd19941
commit
3e29397d74
@ -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
tests/cases/fourslash/extract-const_insideJsxFragment1.ts
Normal file
28
tests/cases/fourslash/extract-const_insideJsxFragment1.ts
Normal 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}
|
||||
</>
|
||||
);
|
||||
}`
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user