Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure export= is emitted correctelly in declaration files #2557

Merged
merged 1 commit into from
Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ module ts {

// Check if symbol is any of the alias
return forEachValue(symbols, symbolFromSymbolTable => {
if (symbolFromSymbolTable.flags & SymbolFlags.Alias) {
if (symbolFromSymbolTable.flags & SymbolFlags.Alias && symbolFromSymbolTable.name !== "export=") {
if (!useOnlyExternalAliasing || // We can use any type of alias to get the name
// Is this external alias, then use it to name
ts.forEach(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration)) {
Expand Down Expand Up @@ -1932,6 +1932,10 @@ module ts {
case SyntaxKind.SourceFile:
return true;

// Export assignements do not create name bindings outside the module
case SyntaxKind.ExportAssignment:
return false;

default:
Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ module m2 {

}
var m2: {
>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; }
>m2 : { (): m2.connectExport; test1: m2.connectModule; test2(): m2.connectModule; }

(): m2.connectExport;
>m2 : unknown
>connectExport : export=.connectExport
>connectExport : m2.connectExport

test1: m2.connectModule;
>test1 : export=.connectModule
>test1 : m2.connectModule
>m2 : unknown
>connectModule : export=.connectModule
>connectModule : m2.connectModule

test2(): m2.connectModule;
>test2 : () => export=.connectModule
>test2 : () => m2.connectModule
>m2 : unknown
>connectModule : export=.connectModule
>connectModule : m2.connectModule

};
export = m2;
>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; }
>m2 : { (): m2.connectExport; test1: m2.connectModule; test2(): m2.connectModule; }

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare module "express" {
function express(): express.ExpressServer;
>express : typeof express
>express : unknown
>ExpressServer : export=.ExpressServer
>ExpressServer : express.ExpressServer

module express {
>express : typeof express
Expand Down
14 changes: 7 additions & 7 deletions tests/baselines/reference/declareFileExportAssignment.types
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ module m2 {
}

var m2: {
>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; }
>m2 : { (): m2.connectExport; test1: m2.connectModule; test2(): m2.connectModule; }

(): m2.connectExport;
>m2 : unknown
>connectExport : export=.connectExport
>connectExport : m2.connectExport

test1: m2.connectModule;
>test1 : export=.connectModule
>test1 : m2.connectModule
>m2 : unknown
>connectModule : export=.connectModule
>connectModule : m2.connectModule

test2(): m2.connectModule;
>test2 : () => export=.connectModule
>test2 : () => m2.connectModule
>m2 : unknown
>connectModule : export=.connectModule
>connectModule : m2.connectModule

};

export = m2;
>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; }
>m2 : { (): m2.connectExport; test1: m2.connectModule; test2(): m2.connectModule; }

Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ module m2 {

var x = 10, m2: {
>x : number
>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; }
>m2 : { (): m2.connectExport; test1: m2.connectModule; test2(): m2.connectModule; }

(): m2.connectExport;
>m2 : unknown
>connectExport : export=.connectExport
>connectExport : m2.connectExport

test1: m2.connectModule;
>test1 : export=.connectModule
>test1 : m2.connectModule
>m2 : unknown
>connectModule : export=.connectModule
>connectModule : m2.connectModule

test2(): m2.connectModule;
>test2 : () => export=.connectModule
>test2 : () => m2.connectModule
>m2 : unknown
>connectModule : export=.connectModule
>connectModule : m2.connectModule

};

export = m2;
>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; }
>m2 : { (): m2.connectExport; test1: m2.connectModule; test2(): m2.connectModule; }

37 changes: 37 additions & 0 deletions tests/baselines/reference/es5ExportEqualsDts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//// [es5ExportEqualsDts.ts]

class A {
foo() {
var aVal: A.B;
return aVal;
}
}

module A {
export interface B { }
}

export = A

//// [es5ExportEqualsDts.js]
var A = (function () {
function A() {
}
A.prototype.foo = function () {
var aVal;
return aVal;
};
return A;
})();
module.exports = A;


//// [es5ExportEqualsDts.d.ts]
declare class A {
foo(): A.B;
}
declare module A {
interface B {
}
}
export = A;
28 changes: 28 additions & 0 deletions tests/baselines/reference/es5ExportEqualsDts.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
=== tests/cases/compiler/es5ExportEqualsDts.ts ===

class A {
>A : A

foo() {
>foo : () => A.B

var aVal: A.B;
>aVal : A.B
>A : unknown
>B : A.B

return aVal;
>aVal : A.B
}
}

module A {
>A : typeof A

export interface B { }
>B : B
}

export = A
>A : A

4 changes: 2 additions & 2 deletions tests/baselines/reference/exportAssignClassAndModule.types
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class Foo {
>Foo : Foo

x: Foo.Bar;
>x : export=.Bar
>x : Foo.Bar
>Foo : unknown
>Bar : export=.Bar
>Bar : Foo.Bar
}
module Foo {
>Foo : typeof Foo
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/exportEqualNamespaces.types
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface server {

(): server.Server;
>server : unknown
>Server : export=.Server
>Server : server.Server

startTime: Date;
>startTime : Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ interface Foo<T> {
>T : T
}
var Foo: new () => Foo.A<Foo<string>>;
>Foo : new () => export=.A<Foo<string>>
>Foo : new () => Foo.A<Foo<string>>
>Foo : unknown
>A : export=.A<T>
>A : Foo.A<T>
>Foo : Foo<T>

export = Foo;
Expand Down
16 changes: 16 additions & 0 deletions tests/cases/compiler/es5ExportEqualsDts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @target: es5
// @module: commonjs
// @declaration: true

class A {
foo() {
var aVal: A.B;
return aVal;
}
}

module A {
export interface B { }
}

export = A