Use merged symbol to pick up js-alias-merged members on export assignments (#37162)

This commit is contained in:
Wesley Wigham 2020-03-02 12:57:00 -08:00 committed by GitHub
parent 24b926f0f9
commit d209092ccc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 99 additions and 1 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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))
}

View file

@ -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
}

View file

@ -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;
}