diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2db4b3468ad..18d32322297 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6138,7 +6138,7 @@ namespace ts { const varName = getUnusedName(name, symbol); // We have to use `getWidenedType` here since the object within a json file is unwidened within the file // (Unwidened types can only exist in expression contexts and should never be serialized) - const typeToSerialize = getWidenedType(getTypeOfSymbol(symbol)); + const typeToSerialize = getWidenedType(getTypeOfSymbol(getMergedSymbol(symbol))); if (isTypeRepresentableAsFunctionNamespaceMerge(typeToSerialize, symbol)) { // If there are no index signatures and `typeToSerialize` is an object type, emit as a namespace instead of a const serializeAsFunctionNamespaceMerge(typeToSerialize, symbol, varName, isExportAssignment ? ModifierFlags.None : ModifierFlags.Export); diff --git a/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.js b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.js new file mode 100644 index 00000000000..93bec6bfbec --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.js @@ -0,0 +1,25 @@ +//// [index.js] +// @ts-nocheck +function foo() { + module.exports = exports = function (o) { + return (o == null) ? create(base) : defineProperties(Object(o), descriptors); + }; + exports.methods = methods; +} + +//// [index.js] +// @ts-nocheck +function foo() { + module.exports = exports = function (o) { + return (o == null) ? create(base) : defineProperties(Object(o), descriptors); + }; + exports.methods = methods; +} + + +//// [index.d.ts] +declare function _exports(o: any): any; +declare namespace _exports { + export const methods: any; +} +export = _exports; diff --git a/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.symbols b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.symbols new file mode 100644 index 00000000000..5031ff1166d --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.symbols @@ -0,0 +1,22 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +// @ts-nocheck +function foo() { +>foo : Symbol(foo, Decl(index.js, 0, 0)) + + module.exports = exports = function (o) { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 1, 16)) +>exports : Symbol(export=, Decl(index.js, 1, 16)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>o : Symbol(o, Decl(index.js, 2, 41)) + + return (o == null) ? create(base) : defineProperties(Object(o), descriptors); +>o : Symbol(o, Decl(index.js, 2, 41)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>o : Symbol(o, Decl(index.js, 2, 41)) + + }; + exports.methods = methods; +>exports : Symbol(methods, Decl(index.js, 4, 6)) +>methods : Symbol(methods, Decl(index.js, 4, 6)) +} diff --git a/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.types b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.types new file mode 100644 index 00000000000..c58351d7a66 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +// @ts-nocheck +function foo() { +>foo : () => void + + module.exports = exports = function (o) { +>module.exports = exports = function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); } : any +>module.exports : any +>module : { "\"tests/cases/conformance/jsdoc/declarations/index\"": any; } +>exports : any +>exports = function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); } : (o: any) => any +>exports : any +>function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); } : (o: any) => any +>o : any + + return (o == null) ? create(base) : defineProperties(Object(o), descriptors); +>(o == null) ? create(base) : defineProperties(Object(o), descriptors) : any +>(o == null) : boolean +>o == null : boolean +>o : any +>null : null +>create(base) : error +>create : error +>base : error +>defineProperties(Object(o), descriptors) : error +>defineProperties : error +>Object(o) : any +>Object : ObjectConstructor +>o : any +>descriptors : error + + }; + exports.methods = methods; +>exports.methods = methods : error +>exports.methods : any +>exports : any +>methods : any +>methods : error +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportDoubleAssignmentInClosure.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportDoubleAssignmentInClosure.ts new file mode 100644 index 00000000000..bcb7644f8bd --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportDoubleAssignmentInClosure.ts @@ -0,0 +1,12 @@ +// @allowJs: true +// @checkJs: true +// @outDir: ./out +// @declaration: true +// @filename: index.js +// @ts-nocheck +function foo() { + module.exports = exports = function (o) { + return (o == null) ? create(base) : defineProperties(Object(o), descriptors); + }; + exports.methods = methods; +} \ No newline at end of file