Skip to content

Commit 9e712dd

Browse files
authored
Consider SymbolFlags.Method as function-esque during js declaration emit (microsoft#36274)
1 parent 6f0c641 commit 9e712dd

File tree

5 files changed

+136
-1
lines changed

5 files changed

+136
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5387,7 +5387,7 @@ namespace ts {
53875387
symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.FunctionScopedVariable | SymbolFlags.Property) &&
53885388
symbol.escapedName !== InternalSymbolName.ExportEquals;
53895389
const isConstMergedWithNSPrintableAsSignatureMerge = isConstMergedWithNS && isTypeRepresentableAsFunctionNamespaceMerge(getTypeOfSymbol(symbol), symbol);
5390-
if (symbol.flags & SymbolFlags.Function || isConstMergedWithNSPrintableAsSignatureMerge) {
5390+
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) || isConstMergedWithNSPrintableAsSignatureMerge) {
53915391
serializeAsFunctionNamespaceMerge(getTypeOfSymbol(symbol), symbol, getInternalSymbolName(symbol, symbolName), modifierFlags);
53925392
}
53935393
if (symbol.flags & SymbolFlags.TypeAlias) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//// [source.js]
2+
module.exports = MyClass;
3+
4+
function MyClass() {}
5+
MyClass.staticMethod = function() {}
6+
MyClass.prototype.method = function() {}
7+
MyClass.staticProperty = 123;
8+
9+
/**
10+
* Callback to be invoked when test execution is complete.
11+
*
12+
* @callback DoneCB
13+
* @param {number} failures - Number of failures that occurred.
14+
*/
15+
16+
//// [source.js]
17+
module.exports = MyClass;
18+
function MyClass() { }
19+
MyClass.staticMethod = function () { };
20+
MyClass.prototype.method = function () { };
21+
MyClass.staticProperty = 123;
22+
/**
23+
* Callback to be invoked when test execution is complete.
24+
*
25+
* @callback DoneCB
26+
* @param {number} failures - Number of failures that occurred.
27+
*/
28+
29+
30+
//// [source.d.ts]
31+
export = MyClass;
32+
declare function MyClass(): void;
33+
declare class MyClass {
34+
method(): void;
35+
}
36+
declare namespace MyClass {
37+
export { staticMethod, staticProperty, DoneCB };
38+
}
39+
declare function staticMethod(): void;
40+
declare var staticProperty: number;
41+
/**
42+
* Callback to be invoked when test execution is complete.
43+
*/
44+
type DoneCB = (failures: number) => any;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/conformance/jsdoc/declarations/source.js ===
2+
module.exports = MyClass;
3+
>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/source", Decl(source.js, 0, 0))
4+
>module : Symbol(export=, Decl(source.js, 0, 0))
5+
>exports : Symbol(export=, Decl(source.js, 0, 0))
6+
>MyClass : Symbol(MyClass, Decl(source.js, 0, 25), Decl(source.js, 2, 21), Decl(source.js, 4, 40))
7+
8+
function MyClass() {}
9+
>MyClass : Symbol(MyClass, Decl(source.js, 0, 25), Decl(source.js, 2, 21), Decl(source.js, 4, 40))
10+
11+
MyClass.staticMethod = function() {}
12+
>MyClass.staticMethod : Symbol(MyClass.staticMethod, Decl(source.js, 2, 21))
13+
>MyClass : Symbol(MyClass, Decl(source.js, 0, 25), Decl(source.js, 2, 21), Decl(source.js, 4, 40))
14+
>staticMethod : Symbol(MyClass.staticMethod, Decl(source.js, 2, 21))
15+
16+
MyClass.prototype.method = function() {}
17+
>MyClass.prototype : Symbol(MyClass.method, Decl(source.js, 3, 36))
18+
>MyClass : Symbol(MyClass, Decl(source.js, 0, 25), Decl(source.js, 2, 21), Decl(source.js, 4, 40))
19+
>prototype : Symbol(Function.prototype, Decl(lib.es5.d.ts, --, --))
20+
>method : Symbol(MyClass.method, Decl(source.js, 3, 36))
21+
22+
MyClass.staticProperty = 123;
23+
>MyClass.staticProperty : Symbol(MyClass.staticProperty, Decl(source.js, 4, 40))
24+
>MyClass : Symbol(MyClass, Decl(source.js, 0, 25), Decl(source.js, 2, 21), Decl(source.js, 4, 40))
25+
>staticProperty : Symbol(MyClass.staticProperty, Decl(source.js, 4, 40))
26+
27+
/**
28+
* Callback to be invoked when test execution is complete.
29+
*
30+
* @callback DoneCB
31+
* @param {number} failures - Number of failures that occurred.
32+
*/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== tests/cases/conformance/jsdoc/declarations/source.js ===
2+
module.exports = MyClass;
3+
>module.exports = MyClass : typeof MyClass
4+
>module.exports : typeof MyClass
5+
>module : { "\"tests/cases/conformance/jsdoc/declarations/source\"": typeof MyClass; }
6+
>exports : typeof MyClass
7+
>MyClass : typeof MyClass
8+
9+
function MyClass() {}
10+
>MyClass : typeof MyClass
11+
12+
MyClass.staticMethod = function() {}
13+
>MyClass.staticMethod = function() {} : () => void
14+
>MyClass.staticMethod : () => void
15+
>MyClass : typeof MyClass
16+
>staticMethod : () => void
17+
>function() {} : () => void
18+
19+
MyClass.prototype.method = function() {}
20+
>MyClass.prototype.method = function() {} : () => void
21+
>MyClass.prototype.method : any
22+
>MyClass.prototype : any
23+
>MyClass : typeof MyClass
24+
>prototype : any
25+
>method : any
26+
>function() {} : () => void
27+
28+
MyClass.staticProperty = 123;
29+
>MyClass.staticProperty = 123 : 123
30+
>MyClass.staticProperty : number
31+
>MyClass : typeof MyClass
32+
>staticProperty : number
33+
>123 : 123
34+
35+
/**
36+
* Callback to be invoked when test execution is complete.
37+
*
38+
* @callback DoneCB
39+
* @param {number} failures - Number of failures that occurred.
40+
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @target: es5
4+
// @outDir: ./out
5+
// @declaration: true
6+
// @filename: source.js
7+
module.exports = MyClass;
8+
9+
function MyClass() {}
10+
MyClass.staticMethod = function() {}
11+
MyClass.prototype.method = function() {}
12+
MyClass.staticProperty = 123;
13+
14+
/**
15+
* Callback to be invoked when test execution is complete.
16+
*
17+
* @callback DoneCB
18+
* @param {number} failures - Number of failures that occurred.
19+
*/

0 commit comments

Comments
 (0)