don't duplicate function properties when emiting definitions of overload signatures (#44235)

This commit is contained in:
Zzzen
2021-05-25 06:52:40 +08:00
committed by GitHub
parent fcabb5c0cc
commit 0e1df66a7c
5 changed files with 88 additions and 1 deletions

View File

@@ -574,6 +574,16 @@ namespace ts {
return false;
}
// If the ExpandoFunctionDeclaration have multiple overloads, then we only need to emit properties for the last one.
function shouldEmitFunctionProperties(input: FunctionDeclaration) {
if (input.body) {
return true;
}
const overloadSignatures = input.symbol.declarations?.filter(decl => isFunctionDeclaration(decl) && !decl.body);
return !overloadSignatures || overloadSignatures.indexOf(input) === overloadSignatures.length - 1;
}
function getBindingNameVisible(elem: BindingElement | VariableDeclaration | OmittedExpression): boolean {
if (isOmittedExpression(elem)) {
return false;
@@ -1194,7 +1204,7 @@ namespace ts {
ensureType(input, input.type),
/*body*/ undefined
));
if (clean && resolver.isExpandoFunctionDeclaration(input)) {
if (clean && resolver.isExpandoFunctionDeclaration(input) && shouldEmitFunctionProperties(input)) {
const props = resolver.getPropertiesOfContainerFunction(input);
// Use parseNodeFactory so it is usable as an enclosing declaration
const fakespace = parseNodeFactory.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, clean.name || factory.createIdentifier("_default"), factory.createModuleBlock([]), NodeFlags.Namespace);