getExternalModuleMember:always resolve alias of moduleSymbol (#43718)
Previously, getExternalModuleMember passed through its received value of `dontResolveAlias` to every function that accepted it. That includes (1) resolution of the module symbol and (2) resolution of the module specifier. However, in TS, the module symbol is never an alias anyway, so dontResolveAlias doesn't make a difference. In JS, the module symbol *can* be an alias, and it should always be resolved. That's what this PR does. Fixes #43713
This commit is contained in:
parent
d16790e3cc
commit
c9eb62fafb
|
@ -2742,7 +2742,7 @@ namespace ts {
|
|||
return undefined;
|
||||
}
|
||||
const suppressInteropError = name.escapedText === InternalSymbolName.Default && !!(compilerOptions.allowSyntheticDefaultImports || compilerOptions.esModuleInterop);
|
||||
const targetSymbol = resolveESModuleSymbol(moduleSymbol, moduleSpecifier, dontResolveAlias, suppressInteropError);
|
||||
const targetSymbol = resolveESModuleSymbol(moduleSymbol, moduleSpecifier, /*dontResolveAlias*/ false, suppressInteropError);
|
||||
if (targetSymbol) {
|
||||
if (name.escapedText) {
|
||||
if (isShorthandAmbientModuleSymbol(moduleSymbol)) {
|
||||
|
|
42
tests/baselines/reference/commonJSAliasedExport.js
Normal file
42
tests/baselines/reference/commonJSAliasedExport.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
//// [tests/cases/conformance/salsa/commonJSAliasedExport.ts] ////
|
||||
|
||||
//// [commonJSAliasedExport.js]
|
||||
const donkey = (ast) => ast;
|
||||
|
||||
function funky(declaration) {
|
||||
return false;
|
||||
}
|
||||
module.exports = donkey;
|
||||
module.exports.funky = funky;
|
||||
|
||||
//// [bug43713.js]
|
||||
const { funky } = require('./commonJSAliasedExport');
|
||||
/** @type {boolean} */
|
||||
var diddy
|
||||
var diddy = funky(1)
|
||||
|
||||
|
||||
|
||||
//// [commonJSAliasedExport.js]
|
||||
var donkey = function (ast) { return ast; };
|
||||
function funky(declaration) {
|
||||
return false;
|
||||
}
|
||||
module.exports = donkey;
|
||||
module.exports.funky = funky;
|
||||
//// [bug43713.js]
|
||||
var funky = require('./commonJSAliasedExport').funky;
|
||||
/** @type {boolean} */
|
||||
var diddy;
|
||||
var diddy = funky(1);
|
||||
|
||||
|
||||
//// [commonJSAliasedExport.d.ts]
|
||||
export = donkey;
|
||||
declare function donkey(ast: any): any;
|
||||
declare namespace donkey {
|
||||
export { funky };
|
||||
}
|
||||
declare function funky(declaration: any): boolean;
|
||||
//// [bug43713.d.ts]
|
||||
export {};
|
41
tests/baselines/reference/commonJSAliasedExport.symbols
Normal file
41
tests/baselines/reference/commonJSAliasedExport.symbols
Normal file
|
@ -0,0 +1,41 @@
|
|||
=== tests/cases/conformance/salsa/bug43713.js ===
|
||||
const { funky } = require('./commonJSAliasedExport');
|
||||
>funky : Symbol(funky, Decl(bug43713.js, 0, 7))
|
||||
>require : Symbol(require)
|
||||
>'./commonJSAliasedExport' : Symbol("tests/cases/conformance/salsa/commonJSAliasedExport", Decl(commonJSAliasedExport.js, 0, 0))
|
||||
|
||||
/** @type {boolean} */
|
||||
var diddy
|
||||
>diddy : Symbol(diddy, Decl(bug43713.js, 2, 3), Decl(bug43713.js, 3, 3))
|
||||
|
||||
var diddy = funky(1)
|
||||
>diddy : Symbol(diddy, Decl(bug43713.js, 2, 3), Decl(bug43713.js, 3, 3))
|
||||
>funky : Symbol(funky, Decl(bug43713.js, 0, 7))
|
||||
|
||||
|
||||
=== tests/cases/conformance/salsa/commonJSAliasedExport.js ===
|
||||
const donkey = (ast) => ast;
|
||||
>donkey : Symbol(donkey, Decl(commonJSAliasedExport.js, 0, 5))
|
||||
>ast : Symbol(ast, Decl(commonJSAliasedExport.js, 0, 16))
|
||||
>ast : Symbol(ast, Decl(commonJSAliasedExport.js, 0, 16))
|
||||
|
||||
function funky(declaration) {
|
||||
>funky : Symbol(funky, Decl(commonJSAliasedExport.js, 0, 29))
|
||||
>declaration : Symbol(declaration, Decl(commonJSAliasedExport.js, 2, 15))
|
||||
|
||||
return false;
|
||||
}
|
||||
module.exports = donkey;
|
||||
>module.exports : Symbol(module.exports, Decl(commonJSAliasedExport.js, 0, 0))
|
||||
>module : Symbol(export=, Decl(commonJSAliasedExport.js, 4, 1))
|
||||
>exports : Symbol(export=, Decl(commonJSAliasedExport.js, 4, 1))
|
||||
>donkey : Symbol(donkey, Decl(commonJSAliasedExport.js, 0, 5))
|
||||
|
||||
module.exports.funky = funky;
|
||||
>module.exports.funky : Symbol(funky, Decl(commonJSAliasedExport.js, 5, 24))
|
||||
>module.exports : Symbol(funky, Decl(commonJSAliasedExport.js, 5, 24))
|
||||
>module : Symbol(module, Decl(commonJSAliasedExport.js, 4, 1))
|
||||
>exports : Symbol(module.exports, Decl(commonJSAliasedExport.js, 0, 0))
|
||||
>funky : Symbol(funky, Decl(commonJSAliasedExport.js, 5, 24))
|
||||
>funky : Symbol(funky, Decl(commonJSAliasedExport.js, 0, 29))
|
||||
|
48
tests/baselines/reference/commonJSAliasedExport.types
Normal file
48
tests/baselines/reference/commonJSAliasedExport.types
Normal file
|
@ -0,0 +1,48 @@
|
|||
=== tests/cases/conformance/salsa/bug43713.js ===
|
||||
const { funky } = require('./commonJSAliasedExport');
|
||||
>funky : (declaration: any) => boolean
|
||||
>require('./commonJSAliasedExport') : (ast: any) => any
|
||||
>require : any
|
||||
>'./commonJSAliasedExport' : "./commonJSAliasedExport"
|
||||
|
||||
/** @type {boolean} */
|
||||
var diddy
|
||||
>diddy : boolean
|
||||
|
||||
var diddy = funky(1)
|
||||
>diddy : boolean
|
||||
>funky(1) : boolean
|
||||
>funky : (declaration: any) => boolean
|
||||
>1 : 1
|
||||
|
||||
|
||||
=== tests/cases/conformance/salsa/commonJSAliasedExport.js ===
|
||||
const donkey = (ast) => ast;
|
||||
>donkey : (ast: any) => any
|
||||
>(ast) => ast : (ast: any) => any
|
||||
>ast : any
|
||||
>ast : any
|
||||
|
||||
function funky(declaration) {
|
||||
>funky : (declaration: any) => boolean
|
||||
>declaration : any
|
||||
|
||||
return false;
|
||||
>false : false
|
||||
}
|
||||
module.exports = donkey;
|
||||
>module.exports = donkey : { (ast: any): any; funky: (declaration: any) => boolean; }
|
||||
>module.exports : { (ast: any): any; funky: (declaration: any) => boolean; }
|
||||
>module : { exports: { (ast: any): any; funky: (declaration: any) => boolean; }; }
|
||||
>exports : { (ast: any): any; funky: (declaration: any) => boolean; }
|
||||
>donkey : (ast: any) => any
|
||||
|
||||
module.exports.funky = funky;
|
||||
>module.exports.funky = funky : (declaration: any) => boolean
|
||||
>module.exports.funky : (declaration: any) => boolean
|
||||
>module.exports : { (ast: any): any; funky: (declaration: any) => boolean; }
|
||||
>module : { exports: { (ast: any): any; funky: (declaration: any) => boolean; }; }
|
||||
>exports : { (ast: any): any; funky: (declaration: any) => boolean; }
|
||||
>funky : (declaration: any) => boolean
|
||||
>funky : (declaration: any) => boolean
|
||||
|
6232
tests/baselines/tj.json
Normal file
6232
tests/baselines/tj.json
Normal file
File diff suppressed because it is too large
Load diff
18
tests/cases/conformance/salsa/commonJSAliasedExport.ts
Normal file
18
tests/cases/conformance/salsa/commonJSAliasedExport.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
// @checkJs: true
|
||||
// @outdir: out/
|
||||
// @declaration: true
|
||||
// @Filename: commonJSAliasedExport.js
|
||||
const donkey = (ast) => ast;
|
||||
|
||||
function funky(declaration) {
|
||||
return false;
|
||||
}
|
||||
module.exports = donkey;
|
||||
module.exports.funky = funky;
|
||||
|
||||
// @Filename: bug43713.js
|
||||
const { funky } = require('./commonJSAliasedExport');
|
||||
/** @type {boolean} */
|
||||
var diddy
|
||||
var diddy = funky(1)
|
||||
|
Loading…
Reference in a new issue