Skip to content

Commit 5810bfe

Browse files
committed
Ambient module declarations (exception import declaration) are visible
1 parent 5d21db9 commit 5810bfe

7 files changed

+34
-90
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,24 +1104,21 @@ module ts {
11041104
function determineIfDeclarationIsVisible() {
11051105
switch (node.kind) {
11061106
case SyntaxKind.VariableDeclaration:
1107-
if (!(node.flags & NodeFlags.Export)) {
1108-
// node.parent is variable statement so look at the variable statement's parent
1109-
return isGlobalSourceFile(node.parent.parent) || isUsedInExportAssignment(node);
1110-
}
1111-
// Exported members are visible if parent is visible
1112-
return isDeclarationVisible(node.parent.parent);
1113-
11141107
case SyntaxKind.ModuleDeclaration:
11151108
case SyntaxKind.ClassDeclaration:
11161109
case SyntaxKind.InterfaceDeclaration:
11171110
case SyntaxKind.FunctionDeclaration:
11181111
case SyntaxKind.EnumDeclaration:
11191112
case SyntaxKind.ImportDeclaration:
1120-
if (!(node.flags & NodeFlags.Export)) {
1121-
return isGlobalSourceFile(node.parent) || isUsedInExportAssignment(node);
1113+
// In case of variable declaration, node.parent is variable statement so look at the variable statement's parent
1114+
var parent = node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent : node.parent;
1115+
// If the node is not exported or it is not ambient module element (except import declaration)
1116+
if (!(node.flags & NodeFlags.Export) &&
1117+
!(node.kind !== SyntaxKind.ImportDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) {
1118+
return isGlobalSourceFile(parent) || isUsedInExportAssignment(node);
11221119
}
1123-
// Exported members are visible if parent is visible
1124-
return isDeclarationVisible(node.parent);
1120+
// Exported members/ambient module elements (exception import declaraiton) are visible if parent is visible
1121+
return isDeclarationVisible(parent);
11251122

11261123
case SyntaxKind.Property:
11271124
case SyntaxKind.Method:

tests/baselines/reference/declFileAmbientExternalModuleWithSingleExportedModule.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,12 @@ exports.x;
2727
declare module "SubModule" {
2828
module m {
2929
module m3 {
30+
interface c {
31+
}
3032
}
3133
}
3234
}
3335
//// [declFileAmbientExternalModuleWithSingleExportedModule_1.d.ts]
3436
/// <reference path='declFileAmbientExternalModuleWithSingleExportedModule_0.d.ts' />
3537
import SubModule = require('SubModule');
3638
export declare var x: SubModule.m.m3.c;
37-
38-
39-
//// [DtsFileErrors]
40-
41-
42-
==== tests/cases/compiler/declFileAmbientExternalModuleWithSingleExportedModule_1.d.ts (1 errors) ====
43-
/// <reference path='declFileAmbientExternalModuleWithSingleExportedModule_0.d.ts' />
44-
import SubModule = require('SubModule');
45-
export declare var x: SubModule.m.m3.c;
46-
~~~~~~~~~~~~~~~~
47-
!!! Module '"SubModule".m.m3' has no exported member 'c'.
48-
49-
==== tests/cases/compiler/declFileAmbientExternalModuleWithSingleExportedModule_0.d.ts (0 errors) ====
50-
declare module "SubModule" {
51-
module m {
52-
module m3 {
53-
}
54-
}
55-
}
56-

tests/baselines/reference/declFileGenericType2.js

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,21 @@ var templa;
9191

9292
//// [declFileGenericType2.d.ts]
9393
declare module templa.mvc {
94+
interface IModel {
95+
}
9496
}
9597
declare module templa.mvc {
98+
interface IController<ModelType extends IModel> {
99+
}
96100
}
97101
declare module templa.mvc {
102+
class AbstractController<ModelType extends IModel> implements IController<ModelType> {
103+
}
98104
}
99105
declare module templa.mvc.composite {
106+
interface ICompositeControllerModel extends IModel {
107+
getControllers(): IController<IModel>[];
108+
}
100109
}
101110
declare module templa.dom.mvc {
102111
interface IElementController<ModelType extends templa.mvc.IModel> extends templa.mvc.IController<ModelType> {
@@ -113,45 +122,3 @@ declare module templa.dom.mvc.composite {
113122
constructor();
114123
}
115124
}
116-
117-
118-
//// [DtsFileErrors]
119-
120-
121-
==== tests/cases/compiler/declFileGenericType2.d.ts (6 errors) ====
122-
declare module templa.mvc {
123-
}
124-
declare module templa.mvc {
125-
}
126-
declare module templa.mvc {
127-
}
128-
declare module templa.mvc.composite {
129-
}
130-
declare module templa.dom.mvc {
131-
interface IElementController<ModelType extends templa.mvc.IModel> extends templa.mvc.IController<ModelType> {
132-
~~~~~~~~~~~~~~~~~
133-
!!! Module 'templa.mvc' has no exported member 'IModel'.
134-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135-
!!! Module 'templa.mvc' has no exported member 'IController'.
136-
}
137-
}
138-
declare module templa.dom.mvc {
139-
class AbstractElementController<ModelType extends templa.mvc.IModel> extends templa.mvc.AbstractController<ModelType> implements IElementController<ModelType> {
140-
~~~~~~~~~~~~~~~~~
141-
!!! Module 'templa.mvc' has no exported member 'IModel'.
142-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
143-
!!! Module 'templa.mvc' has no exported member 'AbstractController'.
144-
constructor();
145-
}
146-
}
147-
declare module templa.dom.mvc.composite {
148-
class AbstractCompositeElementController<ModelType extends templa.mvc.composite.ICompositeControllerModel> extends AbstractElementController<ModelType> {
149-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150-
!!! Module 'templa.mvc.composite' has no exported member 'ICompositeControllerModel'.
151-
_controllers: templa.mvc.IController<templa.mvc.IModel>[];
152-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153-
!!! Module 'templa.mvc' has no exported member 'IController'.
154-
constructor();
155-
}
156-
}
157-

tests/baselines/reference/declFileImportedTypeUseInTypeArgPosition.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,10 @@ var List = (function () {
2525
declare class List<T> {
2626
}
2727
declare module 'mod1' {
28+
class Foo {
29+
}
2830
}
2931
declare module 'moo' {
3032
import x = require('mod1');
3133
var p: List<x.Foo>;
3234
}
33-
34-
35-
//// [DtsFileErrors]
36-
37-
38-
==== tests/cases/compiler/declFileImportedTypeUseInTypeArgPosition.d.ts (1 errors) ====
39-
declare class List<T> {
40-
}
41-
declare module 'mod1' {
42-
}
43-
declare module 'moo' {
44-
import x = require('mod1');
45-
var p: List<x.Foo>;
46-
~~~~~
47-
!!! Module ''mod1'' has no exported member 'Foo'.
48-
}
49-

tests/baselines/reference/declFileWithExtendsClauseThatHasItsContainerNameConflict.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ var A;
5858

5959
//// [declFileWithExtendsClauseThatHasItsContainerNameConflict.d.ts]
6060
declare module A.B.C {
61+
class B {
62+
}
6163
}
6264
declare module A.B {
6365
class EventManager {

tests/baselines/reference/enumDecl1.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ declare module mAmbient {
1414

1515
//// [enumDecl1.d.ts]
1616
declare module mAmbient {
17+
enum e {
18+
x,
19+
y,
20+
z,
21+
}
1722
}

tests/baselines/reference/moduleOuterQualification.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ declare module outer {
1414

1515
//// [moduleOuterQualification.d.ts]
1616
declare module outer {
17+
interface Beta {
18+
}
19+
module inner {
20+
interface Beta extends outer.Beta {
21+
}
22+
}
1723
}

0 commit comments

Comments
 (0)