-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle imports and exports in 'convert parameters to destructured obj…
…ect' (#30475) * add test for imported function * start to implement import references check * fix imported function test * skip alias when looking for symbol target * recognize ES6 imports * recognize some export syntax * add tests for imports/exports * add test for imported function * start to implement import references check * fix imported function test * skip alias when looking for symbol target * recognize ES6 imports * recognize some export syntax * add tests for imports/exports * add test for imported function * start to implement import references check * fix imported function test * recognize ES6 imports * recognize some export syntax * add mode import/export syntax cases * fix entryToFunctionCall to deal with new calls through property/element access expressions * add more tests for imports/exports * allow function and class declarations that have no name but have a default modifier * rename tests * fix conflict * fix tests * add test for nameless class * rename function * minor refactor * remove old tests * delete old test * refactor as suggested * use getContainingFunctionDeclaration
- Loading branch information
Showing
12 changed files
with
270 additions
and
52 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
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
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 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 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 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 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.