From 88d25b4f232929df59729156dfda6b65277affec Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 25 Oct 2022 23:10:31 +0300 Subject: [PATCH] fix(50068): Refactors trigger debug failure when JSX text has a ' and a tag on the same line. (#51299) * fix(50068): rescan JsxText on JsxElement context * fix lint errors * add tests --- src/services/formatting/formattingScanner.ts | 2 +- .../fourslash/extract-const_jsxElement4.ts | 24 +++++++++++++++++++ .../fourslash/extract-const_jsxElement5.ts | 24 +++++++++++++++++++ .../fourslash/extract-const_jsxElement6.ts | 24 +++++++++++++++++++ .../fourslash/extract-const_jsxElement7.ts | 24 +++++++++++++++++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/extract-const_jsxElement4.ts create mode 100644 tests/cases/fourslash/extract-const_jsxElement5.ts create mode 100644 tests/cases/fourslash/extract-const_jsxElement6.ts create mode 100644 tests/cases/fourslash/extract-const_jsxElement7.ts 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 + ]; +}` +});