Skip to content

Commit ef810f5

Browse files
committed
Fix visibility lookup for cjs require aliases
1 parent 90e944d commit ef810f5

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,6 +4164,14 @@ namespace ts {
41644164
&& isDeclarationVisible(declaration.parent)) {
41654165
return addVisibleAlias(declaration, declaration);
41664166
}
4167+
else if (isBindingElement(declaration) && isInJSFile(declaration) && declaration.parent?.parent // exported import-like top-level JS require statement
4168+
&& isVariableDeclaration(declaration.parent.parent)
4169+
&& declaration.parent.parent.parent?.parent && isVariableStatement(declaration.parent.parent.parent.parent)
4170+
&& !hasSyntacticModifier(declaration.parent.parent.parent.parent, ModifierFlags.Export)
4171+
&& declaration.parent.parent.parent.parent.parent // check if the thing containing the variable statement is visible (ie, the file)
4172+
&& isDeclarationVisible(declaration.parent.parent.parent.parent.parent)) {
4173+
return addVisibleAlias(declaration, declaration.parent.parent.parent.parent);
4174+
}
41674175

41684176
// Declaration is not visible
41694177
return false;

tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,6 @@ export const testFnTypes: {
9494
[x: string]: any;
9595
};
9696
export namespace testFnTypes {
97-
type input = boolean | Function | {
98-
/**
99-
* - Prop 1.
100-
*/
101-
prop1: string | RegExp | (string | RegExp)[];
102-
/**
103-
* - Prop 2.
104-
*/
105-
prop2: string;
106-
};
97+
type input = boolean | Function | myTypes.typeB;
10798
}
99+
import { myTypes } from "./file.js";

tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ const testFnTypes = {
2727
*/
2828
function testFn(input) {
2929
>testFn : (input: testFnTypes.input) => number | null
30-
>input : boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; }
30+
>input : boolean | Function | myTypes.typeB
3131

3232
if (typeof input === 'number') {
3333
>typeof input === 'number' : boolean
3434
>typeof input : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
35-
>input : boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; }
35+
>input : boolean | Function | myTypes.typeB
3636
>'number' : "number"
3737

3838
return 2 * input;

0 commit comments

Comments
 (0)