From 5810bfed6d7d317fc0cd3b2bec7912b74feb5326 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 6 Aug 2014 15:13:06 -0700 Subject: [PATCH] Ambient module declarations (exception import declaration) are visible --- src/compiler/checker.ts | 19 +++---- ...tExternalModuleWithSingleExportedModule.js | 22 +------- .../reference/declFileGenericType2.js | 51 ++++--------------- ...eclFileImportedTypeUseInTypeArgPosition.js | 19 +------ ...dsClauseThatHasItsContainerNameConflict.js | 2 + tests/baselines/reference/enumDecl1.js | 5 ++ .../reference/moduleOuterQualification.js | 6 +++ 7 files changed, 34 insertions(+), 90 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b01ba9dc46f..be4739ef041 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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: diff --git a/tests/baselines/reference/declFileAmbientExternalModuleWithSingleExportedModule.js b/tests/baselines/reference/declFileAmbientExternalModuleWithSingleExportedModule.js index cbb32282032..d8e729782f8 100644 --- a/tests/baselines/reference/declFileAmbientExternalModuleWithSingleExportedModule.js +++ b/tests/baselines/reference/declFileAmbientExternalModuleWithSingleExportedModule.js @@ -27,6 +27,8 @@ exports.x; declare module "SubModule" { module m { module m3 { + interface c { + } } } } @@ -34,23 +36,3 @@ declare module "SubModule" { /// import SubModule = require('SubModule'); export declare var x: SubModule.m.m3.c; - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/declFileAmbientExternalModuleWithSingleExportedModule_1.d.ts (1 errors) ==== - /// - 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 { - } - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/declFileGenericType2.js b/tests/baselines/reference/declFileGenericType2.js index 9e0578e0ef9..dd751feeaae 100644 --- a/tests/baselines/reference/declFileGenericType2.js +++ b/tests/baselines/reference/declFileGenericType2.js @@ -91,12 +91,21 @@ var templa; //// [declFileGenericType2.d.ts] declare module templa.mvc { + interface IModel { + } } declare module templa.mvc { + interface IController { + } } declare module templa.mvc { + class AbstractController implements IController { + } } declare module templa.mvc.composite { + interface ICompositeControllerModel extends IModel { + getControllers(): IController[]; + } } declare module templa.dom.mvc { interface IElementController extends templa.mvc.IController { @@ -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 extends templa.mvc.IController { - ~~~~~~~~~~~~~~~~~ -!!! Module 'templa.mvc' has no exported member 'IModel'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Module 'templa.mvc' has no exported member 'IController'. - } - } - declare module templa.dom.mvc { - class AbstractElementController extends templa.mvc.AbstractController implements IElementController { - ~~~~~~~~~~~~~~~~~ -!!! 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 extends AbstractElementController { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Module 'templa.mvc.composite' has no exported member 'ICompositeControllerModel'. - _controllers: templa.mvc.IController[]; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Module 'templa.mvc' has no exported member 'IController'. - constructor(); - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/declFileImportedTypeUseInTypeArgPosition.js b/tests/baselines/reference/declFileImportedTypeUseInTypeArgPosition.js index f17e02ec390..e12a921ffc2 100644 --- a/tests/baselines/reference/declFileImportedTypeUseInTypeArgPosition.js +++ b/tests/baselines/reference/declFileImportedTypeUseInTypeArgPosition.js @@ -25,25 +25,10 @@ var List = (function () { declare class List { } declare module 'mod1' { + class Foo { + } } declare module 'moo' { import x = require('mod1'); var p: List; } - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/declFileImportedTypeUseInTypeArgPosition.d.ts (1 errors) ==== - declare class List { - } - declare module 'mod1' { - } - declare module 'moo' { - import x = require('mod1'); - var p: List; - ~~~~~ -!!! Module ''mod1'' has no exported member 'Foo'. - } - \ No newline at end of file diff --git a/tests/baselines/reference/declFileWithExtendsClauseThatHasItsContainerNameConflict.js b/tests/baselines/reference/declFileWithExtendsClauseThatHasItsContainerNameConflict.js index e0d582806dd..a96cc86cdf3 100644 --- a/tests/baselines/reference/declFileWithExtendsClauseThatHasItsContainerNameConflict.js +++ b/tests/baselines/reference/declFileWithExtendsClauseThatHasItsContainerNameConflict.js @@ -58,6 +58,8 @@ var A; //// [declFileWithExtendsClauseThatHasItsContainerNameConflict.d.ts] declare module A.B.C { + class B { + } } declare module A.B { class EventManager { diff --git a/tests/baselines/reference/enumDecl1.js b/tests/baselines/reference/enumDecl1.js index f912586f28e..fb1c00a19a6 100644 --- a/tests/baselines/reference/enumDecl1.js +++ b/tests/baselines/reference/enumDecl1.js @@ -14,4 +14,9 @@ declare module mAmbient { //// [enumDecl1.d.ts] declare module mAmbient { + enum e { + x, + y, + z, + } } diff --git a/tests/baselines/reference/moduleOuterQualification.js b/tests/baselines/reference/moduleOuterQualification.js index e5c22402625..83c79703f99 100644 --- a/tests/baselines/reference/moduleOuterQualification.js +++ b/tests/baselines/reference/moduleOuterQualification.js @@ -14,4 +14,10 @@ declare module outer { //// [moduleOuterQualification.d.ts] declare module outer { + interface Beta { + } + module inner { + interface Beta extends outer.Beta { + } + } }