From 4d2cd6f88bc0e1c4fde15e9fe5494136428b4b37 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sun, 31 Jan 2016 12:10:33 -0800 Subject: [PATCH] properly dotted namespace names in System modules --- src/compiler/emitter.ts | 4 +-- .../reference/dottedNamesInSystem.js | 35 +++++++++++++++++++ .../reference/dottedNamesInSystem.symbols | 22 ++++++++++++ .../reference/dottedNamesInSystem.types | 23 ++++++++++++ tests/cases/compiler/dottedNamesInSystem.ts | 8 +++++ 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/dottedNamesInSystem.js create mode 100644 tests/baselines/reference/dottedNamesInSystem.symbols create mode 100644 tests/baselines/reference/dottedNamesInSystem.types create mode 100644 tests/cases/compiler/dottedNamesInSystem.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a62739e133..98ad7c874d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2583,12 +2583,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge return false; } - let current: Node = node; + let current = getRootDeclaration(node).parent; while (current) { if (current.kind === SyntaxKind.SourceFile) { return !isExported || ((getCombinedNodeFlags(node) & NodeFlags.Export) !== 0); } - else if (isFunctionLike(current) || current.kind === SyntaxKind.ModuleBlock) { + else if (isDeclaration(current)) { return false; } else { diff --git a/tests/baselines/reference/dottedNamesInSystem.js b/tests/baselines/reference/dottedNamesInSystem.js new file mode 100644 index 0000000000..4f1814f393 --- /dev/null +++ b/tests/baselines/reference/dottedNamesInSystem.js @@ -0,0 +1,35 @@ +//// [dottedNamesInSystem.ts] +export namespace A.B.C { + export function foo() {} +} + +export function bar() { + return A.B.C.foo(); +} + +//// [dottedNamesInSystem.js] +System.register([], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var A; + function bar() { + return A.B.C.foo(); + } + exports_1("bar", bar); + return { + setters:[], + execute: function() { + (function (A) { + var B; + (function (B) { + var C; + (function (C) { + function foo() { } + C.foo = foo; + })(C = B.C || (B.C = {})); + })(B = A.B || (A.B = {})); + })(A = A || (A = {})); + exports_1("A", A); + } + } +}); diff --git a/tests/baselines/reference/dottedNamesInSystem.symbols b/tests/baselines/reference/dottedNamesInSystem.symbols new file mode 100644 index 0000000000..bfbc57ed1b --- /dev/null +++ b/tests/baselines/reference/dottedNamesInSystem.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/dottedNamesInSystem.ts === +export namespace A.B.C { +>A : Symbol(A, Decl(dottedNamesInSystem.ts, 0, 0)) +>B : Symbol(B, Decl(dottedNamesInSystem.ts, 0, 19)) +>C : Symbol(C, Decl(dottedNamesInSystem.ts, 0, 21)) + + export function foo() {} +>foo : Symbol(foo, Decl(dottedNamesInSystem.ts, 0, 24)) +} + +export function bar() { +>bar : Symbol(bar, Decl(dottedNamesInSystem.ts, 2, 1)) + + return A.B.C.foo(); +>A.B.C.foo : Symbol(A.B.C.foo, Decl(dottedNamesInSystem.ts, 0, 24)) +>A.B.C : Symbol(A.B.C, Decl(dottedNamesInSystem.ts, 0, 21)) +>A.B : Symbol(A.B, Decl(dottedNamesInSystem.ts, 0, 19)) +>A : Symbol(A, Decl(dottedNamesInSystem.ts, 0, 0)) +>B : Symbol(A.B, Decl(dottedNamesInSystem.ts, 0, 19)) +>C : Symbol(A.B.C, Decl(dottedNamesInSystem.ts, 0, 21)) +>foo : Symbol(A.B.C.foo, Decl(dottedNamesInSystem.ts, 0, 24)) +} diff --git a/tests/baselines/reference/dottedNamesInSystem.types b/tests/baselines/reference/dottedNamesInSystem.types new file mode 100644 index 0000000000..78de0e3388 --- /dev/null +++ b/tests/baselines/reference/dottedNamesInSystem.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/dottedNamesInSystem.ts === +export namespace A.B.C { +>A : typeof A +>B : typeof B +>C : typeof C + + export function foo() {} +>foo : () => void +} + +export function bar() { +>bar : () => void + + return A.B.C.foo(); +>A.B.C.foo() : void +>A.B.C.foo : () => void +>A.B.C : typeof A.B.C +>A.B : typeof A.B +>A : typeof A +>B : typeof A.B +>C : typeof A.B.C +>foo : () => void +} diff --git a/tests/cases/compiler/dottedNamesInSystem.ts b/tests/cases/compiler/dottedNamesInSystem.ts new file mode 100644 index 0000000000..43b8eb233b --- /dev/null +++ b/tests/cases/compiler/dottedNamesInSystem.ts @@ -0,0 +1,8 @@ +// @module: system +export namespace A.B.C { + export function foo() {} +} + +export function bar() { + return A.B.C.foo(); +} \ No newline at end of file