Skip to content
Permalink
Browse files
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
  • Loading branch information
a-tarasyuk committed Oct 25, 2022
1 parent 8bee69a commit 88d25b4f232929df59729156dfda6b65277affec
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
@@ -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 {
@@ -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
];
}`
});
@@ -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
];
}`
});
@@ -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
];
}`
});
@@ -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.