Skip to content

Commit 5560b81

Browse files
committed
Fix up visibility
1 parent aa82b67 commit 5560b81

27 files changed

+1207
-609
lines changed

src/compiler/checker.ts

+8-28
Original file line numberDiff line numberDiff line change
@@ -41974,47 +41974,27 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4197441974
return canHaveLiteralInitializer(node) && isLiteralConstDeclaration(node as CanHaveLiteralInitializer); // TODO: Make safe
4197541975
}
4197641976

41977-
function getBindingNameVisible(elem: BindingElement | VariableDeclaration | OmittedExpression): boolean {
41977+
function isPrivateDeclaration(node: Node) {
41978+
return hasEffectiveModifier(node, ModifierFlags.Private) || isPrivateIdentifierClassElementDeclaration(node);
41979+
}
41980+
41981+
function isVisibleExternally(elem: ParameterDeclaration | PropertyDeclaration | PropertySignature | VariableDeclaration | BindingElement | OmittedExpression): boolean {
4197841982
if (isOmittedExpression(elem)) {
4197941983
return false;
4198041984
}
4198141985
if (isBindingPattern(elem.name)) {
41982-
// If any child binding pattern element has been marked visible (usually by collect linked aliases), then this is visible
41983-
return some(elem.name.elements, getBindingNameVisible);
41986+
return some(elem.name.elements, isVisibleExternally);
4198441987
}
4198541988
else {
4198641989
return isDeclarationVisible(elem);
4198741990
}
4198841991
}
4198941992

41990-
function isDeclarationAndNotVisible(node: NamedDeclaration) {
41991-
switch (node.kind) {
41992-
case SyntaxKind.FunctionDeclaration:
41993-
case SyntaxKind.ModuleDeclaration:
41994-
case SyntaxKind.InterfaceDeclaration:
41995-
case SyntaxKind.ClassDeclaration:
41996-
case SyntaxKind.TypeAliasDeclaration:
41997-
case SyntaxKind.EnumDeclaration:
41998-
return !isDeclarationVisible(node);
41999-
// The following should be doing their own visibility checks based on filtering their members
42000-
case SyntaxKind.VariableDeclaration:
42001-
return !getBindingNameVisible(node as VariableDeclaration);
42002-
case SyntaxKind.ImportEqualsDeclaration:
42003-
case SyntaxKind.ImportDeclaration:
42004-
case SyntaxKind.ExportDeclaration:
42005-
case SyntaxKind.ExportAssignment:
42006-
return false;
42007-
case SyntaxKind.ClassStaticBlockDeclaration:
42008-
return true;
42009-
}
42010-
return false;
42011-
}
42012-
4201341993
if (
4201441994
!(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.Signature))
4201541995
&& !shouldPrintWithInitializer(node)
42016-
&& !(hasEffectiveModifier(node, ModifierFlags.Private) || isPrivateIdentifierClassElementDeclaration(node))
42017-
&& !isDeclarationAndNotVisible(node)
41996+
&& !isPrivateDeclaration(node)
41997+
&& isVisibleExternally(node)
4201841998
) {
4201941999
const widenedLiteralType = getWidenedLiteralType(type);
4202042000
if (!isTypeIdenticalTo(type, widenedLiteralType)) {

tests/baselines/reference/ambiguousLiteralWideningEmit.errors.txt

-16
This file was deleted.

tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
contextualTypingWithFixedTypeParameters1.ts(2,22): error TS2339: Property 'foo' does not exist on type 'string'.
2-
contextualTypingWithFixedTypeParameters1.ts(3,25): error TS2856: The type of this declaration is ambiguous and may be observed as either 'string' or '""'.
32
contextualTypingWithFixedTypeParameters1.ts(3,32): error TS2339: Property 'foo' does not exist on type '""'.
43
contextualTypingWithFixedTypeParameters1.ts(3,38): error TS2345: Argument of type '1' is not assignable to parameter of type '""'.
54

65

7-
==== contextualTypingWithFixedTypeParameters1.ts (4 errors) ====
6+
==== contextualTypingWithFixedTypeParameters1.ts (3 errors) ====
87
var f10: <T>(x: T, b: () => (a: T) => void, y: T) => T;
98
f10('', () => a => a.foo, ''); // a is ""
109
~~~
1110
!!! error TS2339: Property 'foo' does not exist on type 'string'.
1211
var r9 = f10('', () => (a => a.foo), 1); // error
13-
~
14-
!!! error TS2856: The type of this declaration is ambiguous and may be observed as either 'string' or '""'.
1512
~~~
1613
!!! error TS2339: Property 'foo' does not exist on type '""'.
1714
~

tests/baselines/reference/declFileImportModuleWithExportAssignment.js

+44-7
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ exports.a.test1(null, null, null);
4141

4242
//// [declFileImportModuleWithExportAssignment_0.d.ts]
4343
declare namespace m2 {
44-
interface connectModule {
45-
(res: any, req: any, next: any): void;
46-
}
47-
interface connectExport {
48-
use: (mod: connectModule) => connectExport;
49-
listen: (port: number) => void;
50-
}
5144
}
5245
declare var m2: {
5346
(): m2.connectExport;
@@ -63,3 +56,47 @@ export declare var a: {
6356
test1: a1.connectModule;
6457
test2(): a1.connectModule;
6558
};
59+
60+
61+
//// [DtsFileErrors]
62+
63+
64+
declFileImportModuleWithExportAssignment_0.d.ts(4,12): error TS2694: Namespace 'm2' has no exported member 'connectExport'.
65+
declFileImportModuleWithExportAssignment_0.d.ts(5,15): error TS2694: Namespace 'm2' has no exported member 'connectModule'.
66+
declFileImportModuleWithExportAssignment_0.d.ts(6,17): error TS2694: Namespace 'm2' has no exported member 'connectModule'.
67+
declFileImportModuleWithExportAssignment_1.d.ts(4,12): error TS2694: Namespace 'm2' has no exported member 'connectExport'.
68+
declFileImportModuleWithExportAssignment_1.d.ts(5,15): error TS2694: Namespace 'm2' has no exported member 'connectModule'.
69+
declFileImportModuleWithExportAssignment_1.d.ts(6,17): error TS2694: Namespace 'm2' has no exported member 'connectModule'.
70+
71+
72+
==== declFileImportModuleWithExportAssignment_1.d.ts (3 errors) ====
73+
/**This is on import declaration*/
74+
import a1 = require("./declFileImportModuleWithExportAssignment_0");
75+
export declare var a: {
76+
(): a1.connectExport;
77+
~~~~~~~~~~~~~
78+
!!! error TS2694: Namespace 'm2' has no exported member 'connectExport'.
79+
test1: a1.connectModule;
80+
~~~~~~~~~~~~~
81+
!!! error TS2694: Namespace 'm2' has no exported member 'connectModule'.
82+
test2(): a1.connectModule;
83+
~~~~~~~~~~~~~
84+
!!! error TS2694: Namespace 'm2' has no exported member 'connectModule'.
85+
};
86+
87+
==== declFileImportModuleWithExportAssignment_0.d.ts (3 errors) ====
88+
declare namespace m2 {
89+
}
90+
declare var m2: {
91+
(): m2.connectExport;
92+
~~~~~~~~~~~~~
93+
!!! error TS2694: Namespace 'm2' has no exported member 'connectExport'.
94+
test1: m2.connectModule;
95+
~~~~~~~~~~~~~
96+
!!! error TS2694: Namespace 'm2' has no exported member 'connectModule'.
97+
test2(): m2.connectModule;
98+
~~~~~~~~~~~~~
99+
!!! error TS2694: Namespace 'm2' has no exported member 'connectModule'.
100+
};
101+
export = m2;
102+

tests/baselines/reference/declarationEmitPrivateReadonlyLiterals.errors.txt

-22
This file was deleted.

tests/baselines/reference/declarationMaps.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,36 @@ module.exports = m2;
2828

2929
//// [declarationMaps.d.ts]
3030
declare namespace m2 {
31-
interface connectModule {
32-
(res: any, req: any, next: any): void;
33-
}
34-
interface connectExport {
35-
use: (mod: connectModule) => connectExport;
36-
listen: (port: number) => void;
37-
}
3831
}
3932
declare var m2: {
4033
(): m2.connectExport;
4134
test1: m2.connectModule;
4235
test2(): m2.connectModule;
4336
};
4437
export = m2;
45-
//# sourceMappingURL=declarationMaps.d.ts.map
38+
//# sourceMappingURL=declarationMaps.d.ts.map
39+
40+
//// [DtsFileErrors]
41+
42+
43+
declarationMaps.d.ts(4,12): error TS2694: Namespace 'm2' has no exported member 'connectExport'.
44+
declarationMaps.d.ts(5,15): error TS2694: Namespace 'm2' has no exported member 'connectModule'.
45+
declarationMaps.d.ts(6,17): error TS2694: Namespace 'm2' has no exported member 'connectModule'.
46+
47+
48+
==== declarationMaps.d.ts (3 errors) ====
49+
declare namespace m2 {
50+
}
51+
declare var m2: {
52+
(): m2.connectExport;
53+
~~~~~~~~~~~~~
54+
!!! error TS2694: Namespace 'm2' has no exported member 'connectExport'.
55+
test1: m2.connectModule;
56+
~~~~~~~~~~~~~
57+
!!! error TS2694: Namespace 'm2' has no exported member 'connectModule'.
58+
test2(): m2.connectModule;
59+
~~~~~~~~~~~~~
60+
!!! error TS2694: Namespace 'm2' has no exported member 'connectModule'.
61+
};
62+
export = m2;
63+
//# sourceMappingURL=declarationMaps.d.ts.map

tests/baselines/reference/declarationMaps.js.map

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)