Fix visibility lookup for cjs require aliases

This commit is contained in:
Wesley Wigham 2020-10-26 14:37:35 -07:00
parent 90e944daba
commit ef810f5d02
No known key found for this signature in database
GPG key ID: D59F87F60C5400C9
3 changed files with 12 additions and 12 deletions

View file

@ -4164,6 +4164,14 @@ namespace ts {
&& isDeclarationVisible(declaration.parent)) {
return addVisibleAlias(declaration, declaration);
}
else if (isBindingElement(declaration) && isInJSFile(declaration) && declaration.parent?.parent // exported import-like top-level JS require statement
&& isVariableDeclaration(declaration.parent.parent)
&& declaration.parent.parent.parent?.parent && isVariableStatement(declaration.parent.parent.parent.parent)
&& !hasSyntacticModifier(declaration.parent.parent.parent.parent, ModifierFlags.Export)
&& declaration.parent.parent.parent.parent.parent // check if the thing containing the variable statement is visible (ie, the file)
&& isDeclarationVisible(declaration.parent.parent.parent.parent.parent)) {
return addVisibleAlias(declaration, declaration.parent.parent.parent.parent);
}
// Declaration is not visible
return false;

View file

@ -94,14 +94,6 @@ export const testFnTypes: {
[x: string]: any;
};
export namespace testFnTypes {
type input = boolean | Function | {
/**
* - Prop 1.
*/
prop1: string | RegExp | (string | RegExp)[];
/**
* - Prop 2.
*/
prop2: string;
};
type input = boolean | Function | myTypes.typeB;
}
import { myTypes } from "./file.js";

View file

@ -27,12 +27,12 @@ const testFnTypes = {
*/
function testFn(input) {
>testFn : (input: testFnTypes.input) => number | null
>input : boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; }
>input : boolean | Function | myTypes.typeB
if (typeof input === 'number') {
>typeof input === 'number' : boolean
>typeof input : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>input : boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; }
>input : boolean | Function | myTypes.typeB
>'number' : "number"
return 2 * input;