Enable renaming object binding patterns when needed

This commit is contained in:
Andrew Branch 2019-04-17 18:35:47 -07:00
parent ef18453166
commit 08bb58b0c1
No known key found for this signature in database
GPG Key ID: 22CCA4B120C427D2
3 changed files with 39 additions and 1 deletions

View File

@ -1717,7 +1717,19 @@ namespace ts {
export function getSynthesizedDeepCloneWithRenames<T extends Node>(node: T, includeTrivia = true, renameMap?: Map<Identifier>, checker?: TypeChecker, callback?: (originalNode: Node, clone: Node) => any): T {
let clone;
if (isIdentifier(node) && renameMap && checker) {
if (renameMap && checker && isBindingElement(node) && isIdentifier(node.name) && isObjectBindingPattern(node.parent)) {
const symbol = checker.getSymbolAtLocation(node.name);
const renameInfo = symbol && renameMap.get(String(getSymbolId(symbol)));
if (renameInfo && renameInfo.text !== (node.name || node.propertyName).getText()) {
clone = createBindingElement(
node.dotDotDotToken,
node.propertyName || node.name,
renameInfo,
node.initializer);
}
}
else if (renameMap && checker && isIdentifier(node) && !(node.parent && node.parent.parent && isBindingElement(node.parent) && isObjectBindingPattern(node.parent.parent))) {
const symbol = checker.getSymbolAtLocation(node);
const renameInfo = symbol && renameMap.get(String(getSymbolId(symbol)));

View File

@ -0,0 +1,13 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/(): Promise<void>{
const result = getResult();
return fetch('https://typescriptlang.org').then(([result]) => { console.log(result) });
}
// ==ASYNC FUNCTION::Convert to async function==
async function f(): Promise<void>{
const result = getResult();
const [result_1] = await fetch('https://typescriptlang.org');
console.log(result_1);
}

View File

@ -0,0 +1,13 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/(): Promise<void>{
const result = getResult();
return fetch('https://typescriptlang.org').then(({ result }) => { console.log(result) });
}
// ==ASYNC FUNCTION::Convert to async function==
async function f(): Promise<void>{
const result = getResult();
const { result: result_1 } = await fetch('https://typescriptlang.org');
console.log(result_1);
}