Skip to content
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

Consider SymbolFlags.Method as function-esque during js declaration emit #36274

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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5370,7 +5370,7 @@ namespace ts {
symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.FunctionScopedVariable | SymbolFlags.Property) &&
symbol.escapedName !== InternalSymbolName.ExportEquals;
const isConstMergedWithNSPrintableAsSignatureMerge = isConstMergedWithNS && isTypeRepresentableAsFunctionNamespaceMerge(getTypeOfSymbol(symbol), symbol);
if (symbol.flags & SymbolFlags.Function || isConstMergedWithNSPrintableAsSignatureMerge) {
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) || isConstMergedWithNSPrintableAsSignatureMerge) {
serializeAsFunctionNamespaceMerge(getTypeOfSymbol(symbol), symbol, getInternalSymbolName(symbol, symbolName), modifierFlags);
}
if (symbol.flags & SymbolFlags.TypeAlias) {
Expand Down
44 changes: 44 additions & 0 deletions tests/baselines/reference/jsDeclarationsFunctionPrototypeStatic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//// [source.js]
module.exports = MyClass;

function MyClass() {}
MyClass.staticMethod = function() {}
MyClass.prototype.method = function() {}
MyClass.staticProperty = 123;

/**
* Callback to be invoked when test execution is complete.
*
* @callback DoneCB
* @param {number} failures - Number of failures that occurred.
*/

//// [source.js]
module.exports = MyClass;
function MyClass() { }
MyClass.staticMethod = function () { };
MyClass.prototype.method = function () { };
MyClass.staticProperty = 123;
/**
* Callback to be invoked when test execution is complete.
*
* @callback DoneCB
* @param {number} failures - Number of failures that occurred.
*/


//// [source.d.ts]
export = MyClass;
declare function MyClass(): void;
declare class MyClass {
method(): void;
}
declare namespace MyClass {
export { staticMethod, staticProperty, DoneCB };
}
declare function staticMethod(): void;
declare var staticProperty: number;
/**
* Callback to be invoked when test execution is complete.
*/
type DoneCB = (failures: number) => any;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
=== tests/cases/conformance/jsdoc/declarations/source.js ===
module.exports = MyClass;
>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/source", Decl(source.js, 0, 0))
>module : Symbol(export=, Decl(source.js, 0, 0))
>exports : Symbol(export=, Decl(source.js, 0, 0))
>MyClass : Symbol(MyClass, Decl(source.js, 0, 25), Decl(source.js, 2, 21), Decl(source.js, 4, 40))

function MyClass() {}
>MyClass : Symbol(MyClass, Decl(source.js, 0, 25), Decl(source.js, 2, 21), Decl(source.js, 4, 40))

MyClass.staticMethod = function() {}
>MyClass.staticMethod : Symbol(MyClass.staticMethod, Decl(source.js, 2, 21))
>MyClass : Symbol(MyClass, Decl(source.js, 0, 25), Decl(source.js, 2, 21), Decl(source.js, 4, 40))
>staticMethod : Symbol(MyClass.staticMethod, Decl(source.js, 2, 21))

MyClass.prototype.method = function() {}
>MyClass.prototype : Symbol(MyClass.method, Decl(source.js, 3, 36))
>MyClass : Symbol(MyClass, Decl(source.js, 0, 25), Decl(source.js, 2, 21), Decl(source.js, 4, 40))
>prototype : Symbol(Function.prototype, Decl(lib.es5.d.ts, --, --))
>method : Symbol(MyClass.method, Decl(source.js, 3, 36))

MyClass.staticProperty = 123;
>MyClass.staticProperty : Symbol(MyClass.staticProperty, Decl(source.js, 4, 40))
>MyClass : Symbol(MyClass, Decl(source.js, 0, 25), Decl(source.js, 2, 21), Decl(source.js, 4, 40))
>staticProperty : Symbol(MyClass.staticProperty, Decl(source.js, 4, 40))

/**
* Callback to be invoked when test execution is complete.
*
* @callback DoneCB
* @param {number} failures - Number of failures that occurred.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
=== tests/cases/conformance/jsdoc/declarations/source.js ===
module.exports = MyClass;
>module.exports = MyClass : typeof MyClass
>module.exports : typeof MyClass
>module : { "\"tests/cases/conformance/jsdoc/declarations/source\"": typeof MyClass; }
>exports : typeof MyClass
>MyClass : typeof MyClass

function MyClass() {}
>MyClass : typeof MyClass

MyClass.staticMethod = function() {}
>MyClass.staticMethod = function() {} : () => void
>MyClass.staticMethod : () => void
>MyClass : typeof MyClass
>staticMethod : () => void
>function() {} : () => void

MyClass.prototype.method = function() {}
>MyClass.prototype.method = function() {} : () => void
>MyClass.prototype.method : any
>MyClass.prototype : any
>MyClass : typeof MyClass
>prototype : any
>method : any
>function() {} : () => void

MyClass.staticProperty = 123;
>MyClass.staticProperty = 123 : 123
>MyClass.staticProperty : number
>MyClass : typeof MyClass
>staticProperty : number
>123 : 123

/**
* Callback to be invoked when test execution is complete.
*
* @callback DoneCB
* @param {number} failures - Number of failures that occurred.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @allowJs: true
// @checkJs: true
// @target: es5
// @outDir: ./out
// @declaration: true
// @filename: source.js
module.exports = MyClass;

function MyClass() {}
MyClass.staticMethod = function() {}
MyClass.prototype.method = function() {}
MyClass.staticProperty = 123;

/**
* Callback to be invoked when test execution is complete.
*
* @callback DoneCB
* @param {number} failures - Number of failures that occurred.
*/