-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38776 from a-tarasyuk/bug/29890
fix(29890): JSX: "extract to constant" generates invalid code
- Loading branch information
Showing
19 changed files
with
585 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////function Foo() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<span></span>/*b*/ | ||
//// </div> | ||
//// ); | ||
////} | ||
|
||
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 /*RENAME*/newLocal = <span></span>; | ||
function Foo() { | ||
return ( | ||
<div> | ||
{newLocal} | ||
</div> | ||
); | ||
}` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////function Foo() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<span></span>/*b*/ | ||
//// </div> | ||
//// ); | ||
////} | ||
|
||
goTo.file("a.tsx"); | ||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Extract Symbol", | ||
actionName: "constant_scope_0", | ||
actionDescription: "Extract to constant in enclosing scope", | ||
newContent: | ||
`function Foo() { | ||
const /*RENAME*/newLocal = <span></span>; | ||
return ( | ||
<div> | ||
{newLocal} | ||
</div> | ||
); | ||
}` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////declare var React: any; | ||
////class Foo extends React.Component<{}, {}> { | ||
//// render() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<span></span>/*b*/ | ||
//// </div> | ||
//// ); | ||
//// } | ||
////} | ||
|
||
goTo.file("a.tsx"); | ||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Extract Symbol", | ||
actionName: "constant_scope_1", | ||
actionDescription: "Extract to readonly field in class 'Foo'", | ||
newContent: | ||
`declare var React: any; | ||
class Foo extends React.Component<{}, {}> { | ||
private readonly newProperty = <span></span>; | ||
render() { | ||
return ( | ||
<div> | ||
{this./*RENAME*/newProperty} | ||
</div> | ||
); | ||
} | ||
}` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////function Foo() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<></>/*b*/ | ||
//// </div> | ||
//// ); | ||
////} | ||
|
||
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 /*RENAME*/newLocal = <></>; | ||
function Foo() { | ||
return ( | ||
<div> | ||
{newLocal} | ||
</div> | ||
); | ||
}` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////function Foo() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<></>/*b*/ | ||
//// </div> | ||
//// ); | ||
////} | ||
|
||
goTo.file("a.tsx"); | ||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Extract Symbol", | ||
actionName: "constant_scope_0", | ||
actionDescription: "Extract to constant in enclosing scope", | ||
newContent: | ||
`function Foo() { | ||
const /*RENAME*/newLocal = <></>; | ||
return ( | ||
<div> | ||
{newLocal} | ||
</div> | ||
); | ||
}` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////declare var React: any; | ||
////class Foo extends React.Component<{}, {}> { | ||
//// render() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<></>/*b*/ | ||
//// </div> | ||
//// ); | ||
//// } | ||
////} | ||
|
||
goTo.file("a.tsx"); | ||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Extract Symbol", | ||
actionName: "constant_scope_1", | ||
actionDescription: "Extract to readonly field in class 'Foo'", | ||
newContent: | ||
`declare var React: any; | ||
class Foo extends React.Component<{}, {}> { | ||
private readonly newProperty = <></>; | ||
render() { | ||
return ( | ||
<div> | ||
{this./*RENAME*/newProperty} | ||
</div> | ||
); | ||
} | ||
}` | ||
}); |
28 changes: 28 additions & 0 deletions
28
tests/cases/fourslash/extract-const_jsxSelfClosingElement1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////function Foo() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<br />/*b*/ | ||
//// </div> | ||
//// ); | ||
////} | ||
|
||
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 /*RENAME*/newLocal = <br />; | ||
function Foo() { | ||
return ( | ||
<div> | ||
{newLocal} | ||
</div> | ||
); | ||
}` | ||
}); |
28 changes: 28 additions & 0 deletions
28
tests/cases/fourslash/extract-const_jsxSelfClosingElement2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////function Foo() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<br />/*b*/ | ||
//// </div> | ||
//// ); | ||
////} | ||
|
||
goTo.file("a.tsx"); | ||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Extract Symbol", | ||
actionName: "constant_scope_0", | ||
actionDescription: "Extract to constant in enclosing scope", | ||
newContent: | ||
`function Foo() { | ||
const /*RENAME*/newLocal = <br />; | ||
return ( | ||
<div> | ||
{newLocal} | ||
</div> | ||
); | ||
}` | ||
}); |
35 changes: 35 additions & 0 deletions
35
tests/cases/fourslash/extract-const_jsxSelfClosingElement3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////declare var React: any; | ||
////class Foo extends React.Component<{}, {}> { | ||
//// render() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<br />/*b*/ | ||
//// </div> | ||
//// ); | ||
//// } | ||
////} | ||
|
||
goTo.file("a.tsx"); | ||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Extract Symbol", | ||
actionName: "constant_scope_1", | ||
actionDescription: "Extract to readonly field in class 'Foo'", | ||
newContent: | ||
`declare var React: any; | ||
class Foo extends React.Component<{}, {}> { | ||
private readonly newProperty = <br />; | ||
render() { | ||
return ( | ||
<div> | ||
{this./*RENAME*/newProperty} | ||
</div> | ||
); | ||
} | ||
}` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////function Foo() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<span></span>/*b*/ | ||
//// </div> | ||
//// ); | ||
////} | ||
|
||
goTo.file("a.tsx"); | ||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Extract Symbol", | ||
actionName: "function_scope_1", | ||
actionDescription: "Extract to function in global scope", | ||
newContent: | ||
`function Foo() { | ||
return ( | ||
<div> | ||
{newFunction()} | ||
</div> | ||
); | ||
} | ||
function /*RENAME*/newFunction() { | ||
return <span></span>; | ||
} | ||
` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @jsx: preserve | ||
// @filename: a.tsx | ||
////function Foo() { | ||
//// return ( | ||
//// <div> | ||
//// /*a*/<span></span>/*b*/ | ||
//// </div> | ||
//// ); | ||
////} | ||
|
||
goTo.file("a.tsx"); | ||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Extract Symbol", | ||
actionName: "function_scope_0", | ||
actionDescription: "Extract to inner function in function 'Foo'", | ||
newContent: | ||
`function Foo() { | ||
return ( | ||
<div> | ||
{newFunction()} | ||
</div> | ||
); | ||
function /*RENAME*/newFunction() { | ||
return <span></span>; | ||
} | ||
}` | ||
}); |
Oops, something went wrong.