mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Ambient module declarations (exception import declaration) are visible
This commit is contained in:
parent
5d21db9ccf
commit
5810bfed6d
@ -1104,24 +1104,21 @@ module ts {
|
||||
function determineIfDeclarationIsVisible() {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
// node.parent is variable statement so look at the variable statement's parent
|
||||
return isGlobalSourceFile(node.parent.parent) || isUsedInExportAssignment(node);
|
||||
}
|
||||
// Exported members are visible if parent is visible
|
||||
return isDeclarationVisible(node.parent.parent);
|
||||
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
return isGlobalSourceFile(node.parent) || isUsedInExportAssignment(node);
|
||||
// In case of variable declaration, node.parent is variable statement so look at the variable statement's parent
|
||||
var parent = node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent : node.parent;
|
||||
// If the node is not exported or it is not ambient module element (except import declaration)
|
||||
if (!(node.flags & NodeFlags.Export) &&
|
||||
!(node.kind !== SyntaxKind.ImportDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) {
|
||||
return isGlobalSourceFile(parent) || isUsedInExportAssignment(node);
|
||||
}
|
||||
// Exported members are visible if parent is visible
|
||||
return isDeclarationVisible(node.parent);
|
||||
// Exported members/ambient module elements (exception import declaraiton) are visible if parent is visible
|
||||
return isDeclarationVisible(parent);
|
||||
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.Method:
|
||||
|
||||
@ -27,6 +27,8 @@ exports.x;
|
||||
declare module "SubModule" {
|
||||
module m {
|
||||
module m3 {
|
||||
interface c {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -34,23 +36,3 @@ declare module "SubModule" {
|
||||
/// <reference path='declFileAmbientExternalModuleWithSingleExportedModule_0.d.ts' />
|
||||
import SubModule = require('SubModule');
|
||||
export declare var x: SubModule.m.m3.c;
|
||||
|
||||
|
||||
//// [DtsFileErrors]
|
||||
|
||||
|
||||
==== tests/cases/compiler/declFileAmbientExternalModuleWithSingleExportedModule_1.d.ts (1 errors) ====
|
||||
/// <reference path='declFileAmbientExternalModuleWithSingleExportedModule_0.d.ts' />
|
||||
import SubModule = require('SubModule');
|
||||
export declare var x: SubModule.m.m3.c;
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! Module '"SubModule".m.m3' has no exported member 'c'.
|
||||
|
||||
==== tests/cases/compiler/declFileAmbientExternalModuleWithSingleExportedModule_0.d.ts (0 errors) ====
|
||||
declare module "SubModule" {
|
||||
module m {
|
||||
module m3 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,12 +91,21 @@ var templa;
|
||||
|
||||
//// [declFileGenericType2.d.ts]
|
||||
declare module templa.mvc {
|
||||
interface IModel {
|
||||
}
|
||||
}
|
||||
declare module templa.mvc {
|
||||
interface IController<ModelType extends IModel> {
|
||||
}
|
||||
}
|
||||
declare module templa.mvc {
|
||||
class AbstractController<ModelType extends IModel> implements IController<ModelType> {
|
||||
}
|
||||
}
|
||||
declare module templa.mvc.composite {
|
||||
interface ICompositeControllerModel extends IModel {
|
||||
getControllers(): IController<IModel>[];
|
||||
}
|
||||
}
|
||||
declare module templa.dom.mvc {
|
||||
interface IElementController<ModelType extends templa.mvc.IModel> extends templa.mvc.IController<ModelType> {
|
||||
@ -113,45 +122,3 @@ declare module templa.dom.mvc.composite {
|
||||
constructor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [DtsFileErrors]
|
||||
|
||||
|
||||
==== tests/cases/compiler/declFileGenericType2.d.ts (6 errors) ====
|
||||
declare module templa.mvc {
|
||||
}
|
||||
declare module templa.mvc {
|
||||
}
|
||||
declare module templa.mvc {
|
||||
}
|
||||
declare module templa.mvc.composite {
|
||||
}
|
||||
declare module templa.dom.mvc {
|
||||
interface IElementController<ModelType extends templa.mvc.IModel> extends templa.mvc.IController<ModelType> {
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! Module 'templa.mvc' has no exported member 'IModel'.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Module 'templa.mvc' has no exported member 'IController'.
|
||||
}
|
||||
}
|
||||
declare module templa.dom.mvc {
|
||||
class AbstractElementController<ModelType extends templa.mvc.IModel> extends templa.mvc.AbstractController<ModelType> implements IElementController<ModelType> {
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! Module 'templa.mvc' has no exported member 'IModel'.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Module 'templa.mvc' has no exported member 'AbstractController'.
|
||||
constructor();
|
||||
}
|
||||
}
|
||||
declare module templa.dom.mvc.composite {
|
||||
class AbstractCompositeElementController<ModelType extends templa.mvc.composite.ICompositeControllerModel> extends AbstractElementController<ModelType> {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Module 'templa.mvc.composite' has no exported member 'ICompositeControllerModel'.
|
||||
_controllers: templa.mvc.IController<templa.mvc.IModel>[];
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Module 'templa.mvc' has no exported member 'IController'.
|
||||
constructor();
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,25 +25,10 @@ var List = (function () {
|
||||
declare class List<T> {
|
||||
}
|
||||
declare module 'mod1' {
|
||||
class Foo {
|
||||
}
|
||||
}
|
||||
declare module 'moo' {
|
||||
import x = require('mod1');
|
||||
var p: List<x.Foo>;
|
||||
}
|
||||
|
||||
|
||||
//// [DtsFileErrors]
|
||||
|
||||
|
||||
==== tests/cases/compiler/declFileImportedTypeUseInTypeArgPosition.d.ts (1 errors) ====
|
||||
declare class List<T> {
|
||||
}
|
||||
declare module 'mod1' {
|
||||
}
|
||||
declare module 'moo' {
|
||||
import x = require('mod1');
|
||||
var p: List<x.Foo>;
|
||||
~~~~~
|
||||
!!! Module ''mod1'' has no exported member 'Foo'.
|
||||
}
|
||||
|
||||
@ -58,6 +58,8 @@ var A;
|
||||
|
||||
//// [declFileWithExtendsClauseThatHasItsContainerNameConflict.d.ts]
|
||||
declare module A.B.C {
|
||||
class B {
|
||||
}
|
||||
}
|
||||
declare module A.B {
|
||||
class EventManager {
|
||||
|
||||
@ -14,4 +14,9 @@ declare module mAmbient {
|
||||
|
||||
//// [enumDecl1.d.ts]
|
||||
declare module mAmbient {
|
||||
enum e {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,4 +14,10 @@ declare module outer {
|
||||
|
||||
//// [moduleOuterQualification.d.ts]
|
||||
declare module outer {
|
||||
interface Beta {
|
||||
}
|
||||
module inner {
|
||||
interface Beta extends outer.Beta {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user