-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Handle imports and exports in 'convert parameters to destructured object' #30475
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
ecd4aca
add test for imported function
988626d
start to implement import references check
ef1d93d
fix imported function test
79027a0
skip alias when looking for symbol target
481fdff
recognize ES6 imports
9d09314
recognize some export syntax
9601d15
add tests for imports/exports
65e75fd
add test for imported function
f7a3001
start to implement import references check
902d0d1
fix imported function test
db3d161
skip alias when looking for symbol target
bd047a5
recognize ES6 imports
ec79b28
recognize some export syntax
0ac92a9
add tests for imports/exports
229886d
add test for imported function
a92659c
start to implement import references check
8b7d3e0
fix imported function test
b4f4375
recognize ES6 imports
ef19c85
recognize some export syntax
519cd8a
add mode import/export syntax cases
1fc427f
fix entryToFunctionCall to deal with new calls through property/eleme…
bd79bef
add more tests for imports/exports
1416153
allow function and class declarations that have no name but have a de…
fab5fd7
rename tests
7bb4a72
Merge branch 'namedParametersImportExport' of https://github.com/Micr…
1a3ce43
fix conflict
86431e6
fix tests
9e5f633
add test for nameless class
8ab900d
rename function
d0526c6
minor refactor
8f7a2f7
Merge branch 'master' into namedParametersImportExport
d1115cd
remove old tests
8c17d67
Merge branch 'master' into namedParametersImportExport
6d15398
delete old test
f191363
refactor as suggested
e96171b
use getContainingFunctionDeclaration
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
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
8 changes: 0 additions & 8 deletions
8
tests/cases/fourslash/refactorConvertParamsToDestructuredObject_defaultClass.ts
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction.ts
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,24 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: f.ts | ||
////export function f(/*a*/a: number, b: string/*b*/): string { | ||
//// return b; | ||
////} | ||
|
||
// @Filename: a.ts | ||
////import { f as g } from "./f"; | ||
////g(4, "b"); | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert parameters to destructured object", | ||
actionName: "Convert parameters to destructured object", | ||
actionDescription: "Convert parameters to destructured object", | ||
newContent: `export function f({ a, b }: { a: number; b: string; }): string { | ||
return b; | ||
}` | ||
}); | ||
|
||
goTo.file("a.ts"); | ||
verify.currentFileContentIs(`import { f as g } from "./f"; | ||
g({ a: 4, b: "b" });`) |
24 changes: 24 additions & 0 deletions
24
tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction2.ts
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,24 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: f.ts | ||
////export default function f(/*a*/a: number, b: string/*b*/): string { | ||
//// return b; | ||
////} | ||
|
||
// @Filename: a.ts | ||
////import g from "./f"; | ||
////g(4, "b"); | ||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert parameters to destructured object", | ||
actionName: "Convert parameters to destructured object", | ||
actionDescription: "Convert parameters to destructured object", | ||
newContent: `export default function f({ a, b }: { a: number; b: string; }): string { | ||
return b; | ||
}` | ||
}); | ||
|
||
goTo.file("a.ts"); | ||
verify.currentFileContentIs(`import g from "./f"; | ||
g({ a: 4, b: "b" });`) |
23 changes: 23 additions & 0 deletions
23
tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction3.ts
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' /> | ||
|
||
// @Filename: f.ts | ||
////function foo(/*a*/a: string, b: string/*b*/) { } | ||
////export = foo; | ||
|
||
// @Filename: a.ts | ||
////import bar = require("./f"); | ||
////bar("a", "b"); | ||
|
||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert parameters to destructured object", | ||
actionName: "Convert parameters to destructured object", | ||
actionDescription: "Convert parameters to destructured object", | ||
newContent: `function foo({ a, b }: { a: string; b: string; }) { } | ||
export = foo;` | ||
}); | ||
|
||
goTo.file("a.ts"); | ||
verify.currentFileContentIs(`import bar = require("./f"); | ||
bar({ a: "a", b: "b" });`) |
27 changes: 27 additions & 0 deletions
27
tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction4.ts
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,27 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: f.ts | ||
////export { foo as default }; | ||
////function /*a*/foo/*b*/(a: number, b: number) { | ||
//// return a + b; | ||
////} | ||
|
||
// @Filename: a.ts | ||
////import bar from "./f"; | ||
////bar(1, 2); | ||
|
||
|
||
goTo.select("a", "b"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert parameters to destructured object", | ||
actionName: "Convert parameters to destructured object", | ||
actionDescription: "Convert parameters to destructured object", | ||
newContent: `export { foo as default }; | ||
function foo({ a, b }: { a: number; b: number; }) { | ||
return a + b; | ||
}` | ||
}); | ||
|
||
goTo.file("a.ts"); | ||
verify.currentFileContentIs(`import bar from "./f"; | ||
bar({ a: 1, b: 2 });`) |
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.
I think you can also
export = function(...
. Is that case supported?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.
("No" is a reasonable answer - I mostly want to know if the case was considered.)
In reply to: 269694751 [](ancestors = 269694751)
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.
It's not supported, but I didn't considered it, that's a good point. The refactoring is not offered in this case because this is a function expression (or an arrow function) that is in an export assignment and we only offer it if the function expression is assigned to a const variable.
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.
i've briefly thought about supporting this case and it would require some changes to be able to call findAllReferences, so i think it's better to consider supporting this on another PR later.