-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Convert destruction #39832
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
Closed
Closed
Convert destruction #39832
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
cde9b9f
wip
Kingwl 3566774
wip
Kingwl deac7f6
add desruction refactor
Kingwl b146289
Add smart selection and unique name detection
Kingwl 9c72d1c
add call and assignment detection
Kingwl de08600
fix incorrect convert
Kingwl bf481c1
fix lint
Kingwl 7846923
add some tests
Kingwl fa63cbe
fix element access
Kingwl 8465df6
fix element access collapse
Kingwl 9f37ce9
Do not allow invalid identifier name
Kingwl 87facd2
Fix hosting
Kingwl 7133140
Add more cases
Kingwl bfb782a
refactor some code
Kingwl 39d2ccb
Add array like destruction
Kingwl 9fb1d62
Add more case
Kingwl 5dcbc3f
Refactor common logic
Kingwl 53a955b
Update description
Kingwl 5a9faec
Add some comment test
Kingwl 56a7d1d
Merge branch 'master' into convert_destruction
Kingwl f9a0828
update refactor behavior
Kingwl 14daf2f
Merge branch 'master' into convert_destruction
Kingwl ad8349b
Add kind and support empty span
Kingwl 9ac8cbc
Add support for notApplicableReason
Kingwl 8ba4ad9
Rename all code
Kingwl 12c73ae
Fix typo
Kingwl adba14f
Provide array to object destruction if invoked
Kingwl a66d51d
Avoid refactor if only one props or one ref
Kingwl 71210ac
Care deeper for container
Kingwl 76d31d0
Merge branch 'main' into convert_destruction
Kingwl 38e874f
fix missing merge
Kingwl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,18 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// const item = { | ||
//// a: 1, b: 2 | ||
//// } | ||
//// call(/*a*/item/*b*/.a, item.b) | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert to destruction", | ||
actionName: "Convert to destruction", | ||
actionDescription: ts.Diagnostics.Convert_access_expression_to_destruction.message, | ||
newContent: `const item = { | ||
a: 1, b: 2 | ||
} | ||
const { a, b } = item | ||
call(a, b)`, | ||
}); |
This file contains hidden or 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,16 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// function foo (item: { a: string, b: number }) { | ||
//// call(/*a*/item/*b*/.a, item.b) | ||
//// } | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert to destruction", | ||
actionName: "Convert to destruction", | ||
actionDescription: ts.Diagnostics.Convert_access_expression_to_destruction.message, | ||
newContent: `function foo (item: { a: string, b: number }) { | ||
const { a, b } = item; | ||
call(a, b) | ||
}`, | ||
}); |
This file contains hidden or 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,18 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// const item = { | ||
//// a: 1, b: 2 | ||
//// } | ||
//// call(/*a*/item/*b*/["a"], item.b) | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert to destruction", | ||
actionName: "Convert to destruction", | ||
actionDescription: ts.Diagnostics.Convert_access_expression_to_destruction.message, | ||
newContent: `const item = { | ||
a: 1, b: 2 | ||
} | ||
const { a, b } = item | ||
call(a, b)`, | ||
}); |
This file contains hidden or 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,10 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// const item = { | ||
//// a: 1, b: 2 | ||
//// } | ||
//// const key = "a" | ||
//// call(/*a*/item/*b*/[key], item.b) | ||
|
||
goTo.select("a", "b"); | ||
verify.not.refactorAvailable("Convert to destruction") |
This file contains hidden or 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,20 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// const item = { | ||
//// a: 1, b: 2 | ||
//// } | ||
//// const a = false | ||
//// call(/*a*/item/*b*/.a, item.b) | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert to destruction", | ||
actionName: "Convert to destruction", | ||
actionDescription: ts.Diagnostics.Convert_access_expression_to_destruction.message, | ||
newContent: `const item = { | ||
a: 1, b: 2 | ||
} | ||
const a = false | ||
const { a: a_1, b } = item | ||
call(a_1, b)`, | ||
}); |
This file contains hidden or 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' /> | ||
|
||
//// const item = { | ||
//// a: 1, b: { | ||
//// c: { | ||
//// d: 1, | ||
//// e: 2 | ||
//// } | ||
//// } | ||
//// } | ||
//// call(/*a*/item/*b*/.a, item.b, item.b.c, item.b.c.d, item.b.c.e) | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert to destruction", | ||
actionName: "Convert to destruction", | ||
actionDescription: ts.Diagnostics.Convert_access_expression_to_destruction.message, | ||
newContent: `const item = { | ||
a: 1, b: { | ||
c: { | ||
d: 1, | ||
e: 2 | ||
} | ||
} | ||
} | ||
const { a, b } = item | ||
call(a, b, b.c, b.c.d, b.c.e)`, | ||
}); |
This file contains hidden or 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,29 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// const item = { | ||
//// a: 1, b: { | ||
//// c: { | ||
//// d: 1, | ||
//// e: 2 | ||
//// } | ||
//// } | ||
//// } | ||
//// call(item.a, item.b, /*a*/item.b/*b*/.c, item.b.c.d, item.b.c.e) | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert to destruction", | ||
actionName: "Convert to destruction", | ||
actionDescription: ts.Diagnostics.Convert_access_expression_to_destruction.message, | ||
newContent: `const item = { | ||
a: 1, b: { | ||
c: { | ||
d: 1, | ||
e: 2 | ||
} | ||
} | ||
} | ||
const { c } = item.b | ||
call(item.a, item.b, c, c.d, c.e)`, | ||
}); | ||
|
This file contains hidden or 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' /> | ||
|
||
//// const item = { | ||
//// a: 1, b: { | ||
//// c: { | ||
//// d: 1, | ||
//// e: 2 | ||
//// } | ||
//// } | ||
//// } | ||
//// call(item.a, item.b, item.b.c, /*a*/item.b.c/*b*/.d, item.b.c.e) | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert to destruction", | ||
actionName: "Convert to destruction", | ||
actionDescription: ts.Diagnostics.Convert_access_expression_to_destruction.message, | ||
newContent: `const item = { | ||
a: 1, b: { | ||
c: { | ||
d: 1, | ||
e: 2 | ||
} | ||
} | ||
} | ||
const { d, e } = item.b.c | ||
call(item.a, item.b, item.b.c, d, e)`, | ||
}); |
This file contains hidden or 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,23 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// interface A { | ||
//// f: 1, | ||
//// b: number | ||
//// c: () => void | ||
//// } | ||
//// interface B { | ||
//// f: 2, | ||
//// b: number | ||
//// c: () => string | ||
//// } | ||
//// declare const a: A | B | ||
//// if (/*a*/a/*b*/.f === 1) { | ||
//// a.b = 1 | ||
//// a.c() | ||
//// } else { | ||
//// a.b = 2 | ||
//// a.c() | ||
//// } | ||
|
||
goTo.select("a", "b"); | ||
verify.not.refactorAvailable("Convert to destruction") |
This file contains hidden or 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,43 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// interface A { | ||
//// f: 1, | ||
//// b: number | ||
//// c: () => void | ||
//// } | ||
//// interface B { | ||
//// f: 2, | ||
//// b: number | ||
//// c: () => string | ||
//// } | ||
//// declare const a: A | B | ||
//// if (/*a*/a/*b*/.f === 1) { | ||
//// a.b = 1 | ||
//// } else { | ||
//// a.b = 2 | ||
//// } | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert to destruction", | ||
actionName: "Convert to destruction", | ||
triggerReason: "invoked", | ||
actionDescription: ts.Diagnostics.Convert_access_expression_to_destruction.message, | ||
newContent: `interface A { | ||
f: 1, | ||
b: number | ||
c: () => void | ||
} | ||
interface B { | ||
f: 2, | ||
b: number | ||
c: () => string | ||
} | ||
declare const a: A | B | ||
const { f } = a | ||
if (f === 1) { | ||
a.b = 1 | ||
} else { | ||
a.b = 2 | ||
}`, | ||
}); |
This file contains hidden or 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,9 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// const item = { | ||
//// "a-a-a": 1, b: 2 | ||
//// } | ||
//// call(/*a*/item/*b*/["a-a-a"], item.b) | ||
|
||
goTo.select("a", "b"); | ||
verify.not.refactorAvailable("Convert to destruction") |
This file contains hidden or 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,18 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// const item = { | ||
//// a: 1, b: 2 | ||
//// } | ||
//// call(item.a, /*a*/item/*b*/.b) | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert to destruction", | ||
actionName: "Convert to destruction", | ||
actionDescription: ts.Diagnostics.Convert_access_expression_to_destruction.message, | ||
newContent: `const item = { | ||
a: 1, b: 2 | ||
} | ||
const { a, b } = item | ||
call(a, b)`, | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invoking the refactor with
a
selected here incorrectly gives this: