Skip to content

Commit 88d25b4

Browse files
authoredOct 25, 2022
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
1 parent 8bee69a commit 88d25b4

File tree

5 files changed

+97
-1
lines changed

5 files changed

+97
-1
lines changed
 

‎src/services/formatting/formattingScanner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace ts.formatting {
126126
}
127127

128128
function shouldRescanJsxText(node: Node): boolean {
129-
return isJsxText(node);
129+
return isJsxText(node) || isJsxElement(node) && lastTokenInfo?.token.kind === SyntaxKind.JsxText;
130130
}
131131

132132
function shouldRescanSlashToken(container: Node): boolean {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @jsx: preserve
4+
// @filename: a.tsx
5+
////function Foo() {
6+
//// const foo = [
7+
//// /*a*/<div>' <span></span></div>/*b*/
8+
//// ];
9+
////}
10+
11+
goTo.file("a.tsx");
12+
goTo.select("a", "b");
13+
edit.applyRefactor({
14+
refactorName: "Extract Symbol",
15+
actionName: "constant_scope_1",
16+
actionDescription: "Extract to constant in global scope",
17+
newContent:
18+
`const newLocal = <div>' <span></span></div>;
19+
function Foo() {
20+
const foo = [
21+
/*RENAME*/newLocal
22+
];
23+
}`
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @jsx: preserve
4+
// @filename: a.tsx
5+
////function Foo() {
6+
//// const foo = [
7+
//// /*a*/<div>'" <span></span></div>/*b*/
8+
//// ];
9+
////}
10+
11+
goTo.file("a.tsx");
12+
goTo.select("a", "b");
13+
edit.applyRefactor({
14+
refactorName: "Extract Symbol",
15+
actionName: "constant_scope_1",
16+
actionDescription: "Extract to constant in global scope",
17+
newContent:
18+
`const newLocal = <div>'" <span></span></div>;
19+
function Foo() {
20+
const foo = [
21+
/*RENAME*/newLocal
22+
];
23+
}`
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @jsx: preserve
4+
// @filename: a.tsx
5+
////function Foo() {
6+
//// const foo = [
7+
//// /*a*/<div>text' <span>text' </span>text ' text " </div>/*b*/
8+
//// ];
9+
////}
10+
11+
goTo.file("a.tsx");
12+
goTo.select("a", "b");
13+
edit.applyRefactor({
14+
refactorName: "Extract Symbol",
15+
actionName: "constant_scope_1",
16+
actionDescription: "Extract to constant in global scope",
17+
newContent:
18+
`const newLocal = <div>text' <span>text' </span>text ' text " </div>;
19+
function Foo() {
20+
const foo = [
21+
/*RENAME*/newLocal
22+
];
23+
}`
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @jsx: preserve
4+
// @filename: a.tsx
5+
////function Foo() {
6+
//// const foo = [
7+
//// /*a*/<div>' {1}</div>/*b*/
8+
//// ];
9+
////}
10+
11+
goTo.file("a.tsx");
12+
goTo.select("a", "b");
13+
edit.applyRefactor({
14+
refactorName: "Extract Symbol",
15+
actionName: "constant_scope_1",
16+
actionDescription: "Extract to constant in global scope",
17+
newContent:
18+
`const newLocal = <div>' {1}</div>;
19+
function Foo() {
20+
const foo = [
21+
/*RENAME*/newLocal
22+
];
23+
}`
24+
});

0 commit comments

Comments
 (0)
Please sign in to comment.