diff --git a/src/services/formatting/formattingScanner.ts b/src/services/formatting/formattingScanner.ts index 56ad87770ba7b..4eeaf1b705804 100644 --- a/src/services/formatting/formattingScanner.ts +++ b/src/services/formatting/formattingScanner.ts @@ -126,7 +126,7 @@ namespace ts.formatting { } function shouldRescanJsxText(node: Node): boolean { - return isJsxText(node); + return isJsxText(node) || isJsxElement(node) && lastTokenInfo?.token.kind === SyntaxKind.JsxText; } function shouldRescanSlashToken(container: Node): boolean { diff --git a/tests/cases/fourslash/extract-const_jsxElement4.ts b/tests/cases/fourslash/extract-const_jsxElement4.ts new file mode 100644 index 0000000000000..5e578ab0338f5 --- /dev/null +++ b/tests/cases/fourslash/extract-const_jsxElement4.ts @@ -0,0 +1,24 @@ +/// + +// @jsx: preserve +// @filename: a.tsx +////function Foo() { +//// const foo = [ +//// /*a*/
'
/*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 newLocal =
'
; +function Foo() { + const foo = [ + /*RENAME*/newLocal + ]; +}` +}); diff --git a/tests/cases/fourslash/extract-const_jsxElement5.ts b/tests/cases/fourslash/extract-const_jsxElement5.ts new file mode 100644 index 0000000000000..a419ab3c1e154 --- /dev/null +++ b/tests/cases/fourslash/extract-const_jsxElement5.ts @@ -0,0 +1,24 @@ +/// + +// @jsx: preserve +// @filename: a.tsx +////function Foo() { +//// const foo = [ +//// /*a*/
'"
/*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 newLocal =
'"
; +function Foo() { + const foo = [ + /*RENAME*/newLocal + ]; +}` +}); diff --git a/tests/cases/fourslash/extract-const_jsxElement6.ts b/tests/cases/fourslash/extract-const_jsxElement6.ts new file mode 100644 index 0000000000000..fc43d5c82bb6c --- /dev/null +++ b/tests/cases/fourslash/extract-const_jsxElement6.ts @@ -0,0 +1,24 @@ +/// + +// @jsx: preserve +// @filename: a.tsx +////function Foo() { +//// const foo = [ +//// /*a*/
text' text' text ' text "
/*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 newLocal =
text' text' text ' text "
; +function Foo() { + const foo = [ + /*RENAME*/newLocal + ]; +}` +}); diff --git a/tests/cases/fourslash/extract-const_jsxElement7.ts b/tests/cases/fourslash/extract-const_jsxElement7.ts new file mode 100644 index 0000000000000..70bdba0571036 --- /dev/null +++ b/tests/cases/fourslash/extract-const_jsxElement7.ts @@ -0,0 +1,24 @@ +/// + +// @jsx: preserve +// @filename: a.tsx +////function Foo() { +//// const foo = [ +//// /*a*/
' {1}
/*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 newLocal =
' {1}
; +function Foo() { + const foo = [ + /*RENAME*/newLocal + ]; +}` +});