Skip to content

Commit 08bb58b

Browse files
committed
Enable renaming object binding patterns when needed
1 parent ef18453 commit 08bb58b

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/services/utilities.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,19 @@ namespace ts {
17171717

17181718
export function getSynthesizedDeepCloneWithRenames<T extends Node>(node: T, includeTrivia = true, renameMap?: Map<Identifier>, checker?: TypeChecker, callback?: (originalNode: Node, clone: Node) => any): T {
17191719
let clone;
1720-
if (isIdentifier(node) && renameMap && checker) {
1720+
if (renameMap && checker && isBindingElement(node) && isIdentifier(node.name) && isObjectBindingPattern(node.parent)) {
1721+
const symbol = checker.getSymbolAtLocation(node.name);
1722+
const renameInfo = symbol && renameMap.get(String(getSymbolId(symbol)));
1723+
1724+
if (renameInfo && renameInfo.text !== (node.name || node.propertyName).getText()) {
1725+
clone = createBindingElement(
1726+
node.dotDotDotToken,
1727+
node.propertyName || node.name,
1728+
renameInfo,
1729+
node.initializer);
1730+
}
1731+
}
1732+
else if (renameMap && checker && isIdentifier(node) && !(node.parent && node.parent.parent && isBindingElement(node.parent) && isObjectBindingPattern(node.parent.parent))) {
17211733
const symbol = checker.getSymbolAtLocation(node);
17221734
const renameInfo = symbol && renameMap.get(String(getSymbolId(symbol)));
17231735

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/(): Promise<void>{
4+
const result = getResult();
5+
return fetch('https://typescriptlang.org').then(([result]) => { console.log(result) });
6+
}
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
async function f(): Promise<void>{
10+
const result = getResult();
11+
const [result_1] = await fetch('https://typescriptlang.org');
12+
console.log(result_1);
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/(): Promise<void>{
4+
const result = getResult();
5+
return fetch('https://typescriptlang.org').then(({ result }) => { console.log(result) });
6+
}
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
async function f(): Promise<void>{
10+
const result = getResult();
11+
const { result: result_1 } = await fetch('https://typescriptlang.org');
12+
console.log(result_1);
13+
}

0 commit comments

Comments
 (0)