Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(50068): Refactors trigger debug failure when JSX text has a ' and a tag on the same line. #51299

Merged
merged 3 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/services/formatting/formattingScanner.ts
Original file line number Diff line number Diff line change
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;
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
}

function shouldRescanSlashToken(container: Node): boolean {
Expand Down
24 changes: 24 additions & 0 deletions tests/cases/fourslash/extract-const_jsxElement4.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
];
}`
});