Skip to content

Commit d209092

Browse files
authored
Use merged symbol to pick up js-alias-merged members on export assignments (#37162)
1 parent 24b926f commit d209092

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6138,7 +6138,7 @@ namespace ts {
61386138
const varName = getUnusedName(name, symbol);
61396139
// We have to use `getWidenedType` here since the object within a json file is unwidened within the file
61406140
// (Unwidened types can only exist in expression contexts and should never be serialized)
6141-
const typeToSerialize = getWidenedType(getTypeOfSymbol(symbol));
6141+
const typeToSerialize = getWidenedType(getTypeOfSymbol(getMergedSymbol(symbol)));
61426142
if (isTypeRepresentableAsFunctionNamespaceMerge(typeToSerialize, symbol)) {
61436143
// If there are no index signatures and `typeToSerialize` is an object type, emit as a namespace instead of a const
61446144
serializeAsFunctionNamespaceMerge(typeToSerialize, symbol, varName, isExportAssignment ? ModifierFlags.None : ModifierFlags.Export);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [index.js]
2+
// @ts-nocheck
3+
function foo() {
4+
module.exports = exports = function (o) {
5+
return (o == null) ? create(base) : defineProperties(Object(o), descriptors);
6+
};
7+
exports.methods = methods;
8+
}
9+
10+
//// [index.js]
11+
// @ts-nocheck
12+
function foo() {
13+
module.exports = exports = function (o) {
14+
return (o == null) ? create(base) : defineProperties(Object(o), descriptors);
15+
};
16+
exports.methods = methods;
17+
}
18+
19+
20+
//// [index.d.ts]
21+
declare function _exports(o: any): any;
22+
declare namespace _exports {
23+
export const methods: any;
24+
}
25+
export = _exports;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/jsdoc/declarations/index.js ===
2+
// @ts-nocheck
3+
function foo() {
4+
>foo : Symbol(foo, Decl(index.js, 0, 0))
5+
6+
module.exports = exports = function (o) {
7+
>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0))
8+
>module : Symbol(export=, Decl(index.js, 1, 16))
9+
>exports : Symbol(export=, Decl(index.js, 1, 16))
10+
>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0))
11+
>o : Symbol(o, Decl(index.js, 2, 41))
12+
13+
return (o == null) ? create(base) : defineProperties(Object(o), descriptors);
14+
>o : Symbol(o, Decl(index.js, 2, 41))
15+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
16+
>o : Symbol(o, Decl(index.js, 2, 41))
17+
18+
};
19+
exports.methods = methods;
20+
>exports : Symbol(methods, Decl(index.js, 4, 6))
21+
>methods : Symbol(methods, Decl(index.js, 4, 6))
22+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=== tests/cases/conformance/jsdoc/declarations/index.js ===
2+
// @ts-nocheck
3+
function foo() {
4+
>foo : () => void
5+
6+
module.exports = exports = function (o) {
7+
>module.exports = exports = function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); } : any
8+
>module.exports : any
9+
>module : { "\"tests/cases/conformance/jsdoc/declarations/index\"": any; }
10+
>exports : any
11+
>exports = function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); } : (o: any) => any
12+
>exports : any
13+
>function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); } : (o: any) => any
14+
>o : any
15+
16+
return (o == null) ? create(base) : defineProperties(Object(o), descriptors);
17+
>(o == null) ? create(base) : defineProperties(Object(o), descriptors) : any
18+
>(o == null) : boolean
19+
>o == null : boolean
20+
>o : any
21+
>null : null
22+
>create(base) : error
23+
>create : error
24+
>base : error
25+
>defineProperties(Object(o), descriptors) : error
26+
>defineProperties : error
27+
>Object(o) : any
28+
>Object : ObjectConstructor
29+
>o : any
30+
>descriptors : error
31+
32+
};
33+
exports.methods = methods;
34+
>exports.methods = methods : error
35+
>exports.methods : any
36+
>exports : any
37+
>methods : any
38+
>methods : error
39+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @outDir: ./out
4+
// @declaration: true
5+
// @filename: index.js
6+
// @ts-nocheck
7+
function foo() {
8+
module.exports = exports = function (o) {
9+
return (o == null) ? create(base) : defineProperties(Object(o), descriptors);
10+
};
11+
exports.methods = methods;
12+
}

0 commit comments

Comments
 (0)