Skip to content

Commit 455364c

Browse files
committed
Do not emit the signature for implementation of overload in the declaration file
1 parent d1cdf03 commit 455364c

14 files changed

+13
-37
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5722,6 +5722,14 @@ module ts {
57225722
return false;
57235723
}
57245724

5725+
function isImplementationOfOverload(node: FunctionDeclaration) {
5726+
if (node.body) {
5727+
var symbol = getSymbolOfNode(node);
5728+
return getSignaturesOfSymbol(symbol).length > 1;
5729+
}
5730+
return false;
5731+
}
5732+
57255733
function getNodeCheckFlags(node: Node): NodeCheckFlags {
57265734
return getNodeLinks(node).flags;
57275735
}
@@ -5742,7 +5750,8 @@ module ts {
57425750
getEnumMemberValue: getEnumMemberValue,
57435751
isTopLevelValueImportedViaEntityName: isTopLevelValueImportedViaEntityName,
57445752
shouldEmitDeclarations: shouldEmitDeclarations,
5745-
isReferencedInExportAssignment: isReferencedInExportAssignment
5753+
isReferencedInExportAssignment: isReferencedInExportAssignment,
5754+
isImplementationOfOverload: isImplementationOfOverload
57465755
};
57475756
checkProgram();
57485757
return emitFiles(resolver);

src/compiler/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,9 +2125,9 @@ module ts {
21252125
}
21262126

21272127
function emitFunctionDeclaration(node: FunctionDeclaration) {
2128-
// TODO(shkamat): if this is overloaded declaration do not emit if body is present
21292128
// If we are emitting Method/Constructor it isnt moduleElement and doesnt need canEmitModuleElement check
2130-
if (node.kind !== SyntaxKind.FunctionDeclaration || canEmitModuleElementDeclaration(node)) {
2129+
if ((node.kind !== SyntaxKind.FunctionDeclaration || canEmitModuleElementDeclaration(node)) &&
2130+
!resolver.isImplementationOfOverload(node)) {
21312131
emitDeclarationFlags(node);
21322132
if (node.kind === SyntaxKind.FunctionDeclaration) {
21332133
write("function ");

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ module ts {
602602
getEnumMemberValue(node: EnumMember): number;
603603
shouldEmitDeclarations(): boolean;
604604
isReferencedInExportAssignment(node: Declaration): boolean;
605+
isImplementationOfOverload(node: FunctionDeclaration): boolean;
605606
}
606607

607608
export enum SymbolFlags {

tests/baselines/reference/commentsCommentParsing.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ declare function sum(a, b);
242242
declare function multiply(a, b, c?, d?, e?);
243243
declare function f1(a);
244244
declare function f1(b);
245-
declare function f1(aOrb, opt?);
246245
declare function subtract(a, b, c?, d?, e?, f?);
247246
declare function square(a);
248247
declare function divide(a, b);

tests/baselines/reference/commentsOverloads.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,12 @@ var c5_i_2 = new c5("hello");
259259
//// [commentsOverloads.d.ts]
260260
declare function f1(a);
261261
declare function f1(b);
262-
declare function f1(aOrb);
263262
declare function f2(a);
264263
declare function f2(b);
265-
declare function f2(aOrb);
266264
declare function f3(a);
267265
declare function f3(b);
268-
declare function f3(aOrb);
269266
declare function f4(a);
270267
declare function f4(b);
271-
declare function f4(aOrb);
272268
interface i1 {
273269
(a);
274270
(b);
@@ -310,44 +306,34 @@ interface i4 {
310306
declare class c {
311307
prop1(a);
312308
prop1(b);
313-
prop1(aorb);
314309
prop2(a);
315310
prop2(b);
316-
prop2(aorb);
317311
prop3(a);
318312
prop3(b);
319-
prop3(aorb);
320313
prop4(a);
321314
prop4(b);
322-
prop4(aorb);
323315
prop5(a);
324316
prop5(b);
325-
prop5(aorb);
326317
}
327318
declare class c1 {
328319
constructor (a);
329320
constructor (b);
330-
constructor (aorb);
331321
}
332322
declare class c2 {
333323
constructor (a);
334324
constructor (b);
335-
constructor (aorb);
336325
}
337326
declare class c3 {
338327
constructor (a);
339328
constructor (b);
340-
constructor (aorb);
341329
}
342330
declare class c4 {
343331
constructor (a);
344332
constructor (b);
345-
constructor (aorb);
346333
}
347334
declare class c5 {
348335
constructor (a);
349336
constructor (b);
350-
constructor (aorb);
351337
}
352338
declare var c_i;
353339
declare var c1_i_1;

tests/baselines/reference/commentsdoNotEmitComments.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ declare class c {
142142
prop1;
143143
foo1(a);
144144
foo1(b);
145-
foo1(aOrb);
146145
}
147146
declare var i;
148147
interface i1 {

tests/baselines/reference/commentsemitComments.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ declare class c {
142142
prop1;
143143
foo1(a);
144144
foo1(b);
145-
foo1(aOrb);
146145
}
147146
declare var i;
148147
interface i1 {

tests/baselines/reference/declFileConstructors.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ export declare class ConstructorWithRestParamters {
224224
export declare class ConstructorWithOverloads {
225225
constructor (a);
226226
constructor (a);
227-
constructor (a);
228227
}
229228
export declare class ConstructorWithPublicParameterProperty {
230229
x;
@@ -255,7 +254,6 @@ declare class GlobalConstructorWithRestParamters {
255254
declare class GlobalConstructorWithOverloads {
256255
constructor (a);
257256
constructor (a);
258-
constructor (a);
259257
}
260258
declare class GlobalConstructorWithPublicParameterProperty {
261259
x;

tests/baselines/reference/declFileForClassWithPrivateOverloadedFunction.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ var C = (function () {
2020
declare class C {
2121
private foo(x);
2222
private foo(x);
23-
private foo(x);
2423
}

tests/baselines/reference/declFileFunctions.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,9 @@ export declare function fooWithParameters(a, b);
118118
export declare function fooWithRestParameters(a, ...rests);
119119
export declare function fooWithOverloads(a);
120120
export declare function fooWithOverloads(a);
121-
export declare function fooWithOverloads(a);
122121
//// [declFileFunctions_1.d.ts]
123122
declare function globalfoo();
124123
declare function globalfooWithParameters(a, b);
125124
declare function globalfooWithRestParameters(a, ...rests);
126125
declare function globalfooWithOverloads(a);
127126
declare function globalfooWithOverloads(a);
128-
declare function globalfooWithOverloads(a);

tests/baselines/reference/declFileMethods.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,25 +332,21 @@ export declare class c1 {
332332
fooWithRestParameters(a, ...rests);
333333
fooWithOverloads(a);
334334
fooWithOverloads(a);
335-
fooWithOverloads(a);
336335
private privateFoo();
337336
private privateFooWithParameters(a, b);
338337
private privateFooWithRestParameters(a, ...rests);
339338
private privateFooWithOverloads(a);
340339
private privateFooWithOverloads(a);
341-
private privateFooWithOverloads(a);
342340
static staticFoo();
343341
static staticFooWithParameters(a, b);
344342
static staticFooWithRestParameters(a, ...rests);
345343
static staticFooWithOverloads(a);
346344
static staticFooWithOverloads(a);
347-
static staticFooWithOverloads(a);
348345
private static privateStaticFoo();
349346
private static privateStaticFooWithParameters(a, b);
350347
private static privateStaticFooWithRestParameters(a, ...rests);
351348
private static privateStaticFooWithOverloads(a);
352349
private static privateStaticFooWithOverloads(a);
353-
private static privateStaticFooWithOverloads(a);
354350
}
355351
export interface I1 {
356352
foo();
@@ -366,25 +362,21 @@ declare class c2 {
366362
fooWithRestParameters(a, ...rests);
367363
fooWithOverloads(a);
368364
fooWithOverloads(a);
369-
fooWithOverloads(a);
370365
private privateFoo();
371366
private privateFooWithParameters(a, b);
372367
private privateFooWithRestParameters(a, ...rests);
373368
private privateFooWithOverloads(a);
374369
private privateFooWithOverloads(a);
375-
private privateFooWithOverloads(a);
376370
static staticFoo();
377371
static staticFooWithParameters(a, b);
378372
static staticFooWithRestParameters(a, ...rests);
379373
static staticFooWithOverloads(a);
380374
static staticFooWithOverloads(a);
381-
static staticFooWithOverloads(a);
382375
private static privateStaticFoo();
383376
private static privateStaticFooWithParameters(a, b);
384377
private static privateStaticFooWithRestParameters(a, ...rests);
385378
private static privateStaticFooWithOverloads(a);
386379
private static privateStaticFooWithOverloads(a);
387-
private static privateStaticFooWithOverloads(a);
388380
}
389381
interface I2 {
390382
foo();

tests/baselines/reference/declFileTypeofFunction.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ function foo5(x) {
6666
//// [declFileTypeofFunction.d.ts]
6767
declare function f(n);
6868
declare function f(n);
69-
declare function f();
7069
declare function g(n);
7170
declare function g(n);
72-
declare function g();
7371
declare var b;
7472
declare function b1();
7573
declare function foo();

tests/baselines/reference/funcdecl.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ declare function withRestParams(a, ...myRestParameter);
153153
declare var withRestParamsVar;
154154
declare function overload1(n);
155155
declare function overload1(s);
156-
declare function overload1(ns);
157156
declare var withOverloadSignature;
158157
declare function f(n);
159158
declare module m2 {

tests/baselines/reference/methodSignatureDeclarationEmit1.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ var C = (function () {
2020
declare class C {
2121
foo(n);
2222
foo(s);
23-
foo(a);
2423
}

0 commit comments

Comments
 (0)