Skip to content

Fix overlapping changes when un-qualifying import use site within transformed export #40987

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 2 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/services/codefixes/convertToAsyncFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,26 @@ namespace ts.codefix {
}
});

return getSynthesizedDeepCloneWithRenames(nodeToRename, /*includeTrivia*/ true, identsToRenameMap, checker);
return getSynthesizedDeepCloneWithReplacements(nodeToRename, /*includeTrivia*/ true, original => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was, until now, the only consumer of getSynthesizedDeepCloneWithRenames, so I moved the bits that had poor reusability out to here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird that it had an unused optional callback parameter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was used originally, but I stopped using it a few months back when I greatly simplified convertToAsyncFunction.

if (isBindingElement(original) && isIdentifier(original.name) && isObjectBindingPattern(original.parent)) {
const symbol = checker.getSymbolAtLocation(original.name);
const renameInfo = symbol && identsToRenameMap.get(String(getSymbolId(symbol)));
if (renameInfo && renameInfo.text !== (original.name || original.propertyName).getText()) {
return factory.createBindingElement(
original.dotDotDotToken,
original.propertyName || original.name,
renameInfo,
original.initializer);
}
}
else if (isIdentifier(original)) {
const symbol = checker.getSymbolAtLocation(original);
const renameInfo = symbol && identsToRenameMap.get(String(getSymbolId(symbol)));
if (renameInfo) {
return factory.createIdentifier(renameInfo.text);
}
}
});
}

function getNewNameIfConflict(name: Identifier, originalNames: ReadonlyESMap<string, Symbol[]>): SynthIdentifier {
Expand Down Expand Up @@ -289,7 +308,7 @@ namespace ts.codefix {

const tryStatement = factory.createTryStatement(tryBlock, catchClause, /*finallyBlock*/ undefined);
const destructuredResult = prevArgName && varDeclIdentifier && isSynthBindingPattern(prevArgName)
&& factory.createVariableStatement(/*modifiers*/ undefined, factory.createVariableDeclarationList([factory.createVariableDeclaration(getSynthesizedDeepCloneWithRenames(prevArgName.bindingPattern), /*exclamationToken*/ undefined, /*type*/ undefined, varDeclIdentifier)], NodeFlags.Const));
&& factory.createVariableStatement(/*modifiers*/ undefined, factory.createVariableDeclarationList([factory.createVariableDeclaration(getSynthesizedDeepClone(prevArgName.bindingPattern), /*exclamationToken*/ undefined, /*type*/ undefined, varDeclIdentifier)], NodeFlags.Const));
return compact([varDeclList, tryStatement, destructuredResult]);
}

Expand Down
Loading