Skip to content

Commit

Permalink
fix(50068): Refactors trigger debug failure when JSX text has a ' and…
Browse files Browse the repository at this point in the history
… a tag on the same line. (#51299)

* fix(50068): rescan JsxText on JsxElement context

* fix lint errors

* add tests
  • Loading branch information
a-tarasyuk committed Oct 25, 2022
1 parent 8bee69a commit 88d25b4
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/services/formatting/formattingScanner.ts
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions tests/cases/fourslash/extract-const_jsxElement4.ts
@@ -0,0 +1,24 @@
/// <reference path="fourslash.ts" />

// @jsx: preserve
// @filename: a.tsx
////function Foo() {
//// const foo = [
//// /*a*/<div>' <span></span></div>/*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 = <div>' <span></span></div>;
function Foo() {
const foo = [
/*RENAME*/newLocal
];
}`
});
24 changes: 24 additions & 0 deletions tests/cases/fourslash/extract-const_jsxElement5.ts
@@ -0,0 +1,24 @@
/// <reference path="fourslash.ts" />

// @jsx: preserve
// @filename: a.tsx
////function Foo() {
//// const foo = [
//// /*a*/<div>'" <span></span></div>/*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 = <div>'" <span></span></div>;
function Foo() {
const foo = [
/*RENAME*/newLocal
];
}`
});
24 changes: 24 additions & 0 deletions tests/cases/fourslash/extract-const_jsxElement6.ts
@@ -0,0 +1,24 @@
/// <reference path="fourslash.ts" />

// @jsx: preserve
// @filename: a.tsx
////function Foo() {
//// const foo = [
//// /*a*/<div>text' <span>text' </span>text ' text " </div>/*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 = <div>text' <span>text' </span>text ' text " </div>;
function Foo() {
const foo = [
/*RENAME*/newLocal
];
}`
});
24 changes: 24 additions & 0 deletions tests/cases/fourslash/extract-const_jsxElement7.ts
@@ -0,0 +1,24 @@
/// <reference path="fourslash.ts" />

// @jsx: preserve
// @filename: a.tsx
////function Foo() {
//// const foo = [
//// /*a*/<div>' {1}</div>/*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 = <div>' {1}</div>;
function Foo() {
const foo = [
/*RENAME*/newLocal
];
}`
});

0 comments on commit 88d25b4

Please sign in to comment.