mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 02:30:15 -06:00
Enable renaming object binding patterns when needed
This commit is contained in:
parent
ef18453166
commit
08bb58b0c1
@ -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)));
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user