Support UMD when targeted module uses export =

This commit is contained in:
Ryan Cavanaugh 2016-03-07 12:30:57 -08:00
parent 34cf10542c
commit 132d75c267
5 changed files with 80 additions and 1 deletions

View File

@ -982,7 +982,13 @@ namespace ts {
}
function getTargetOfGlobalModuleExportDeclaration(node: GlobalModuleExportDeclaration): Symbol {
return node.parent.symbol;
const moduleSymbol = node.parent.symbol;
if (moduleSymbol && moduleSymbol.exports && moduleSymbol.exports["export="]) {
return moduleSymbol.exports["export="].exportSymbol;
}
else {
return moduleSymbol;
}
}
function getTargetOfExportSpecifier(node: ExportSpecifier): Symbol {

View File

@ -0,0 +1,18 @@
//// [tests/cases/conformance/externalModules/umd6.ts] ////
//// [foo.d.ts]
declare namespace Thing {
export function fn(): number;
}
export = Thing;
export as namespace Foo;
//// [a.ts]
/// <reference path="foo.d.ts" />
let y: number = Foo.fn();
//// [a.js]
/// <reference path="foo.d.ts" />
var y = exports.Foo.fn();

View File

@ -0,0 +1,19 @@
=== tests/cases/conformance/externalModules/a.ts ===
/// <reference path="foo.d.ts" />
let y: number = Foo.fn();
>y : Symbol(y, Decl(a.ts, 1, 3))
>Foo : Symbol(Foo, Decl(foo.d.ts, 4, 15))
=== tests/cases/conformance/externalModules/foo.d.ts ===
declare namespace Thing {
>Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0))
export function fn(): number;
>fn : Symbol(fn, Decl(foo.d.ts, 1, 25))
}
export = Thing;
>Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0))
export as namespace Foo;

View File

@ -0,0 +1,23 @@
=== tests/cases/conformance/externalModules/a.ts ===
/// <reference path="foo.d.ts" />
let y: number = Foo.fn();
>y : number
>Foo.fn() : any
>Foo.fn : any
>Foo : any
>fn : any
=== tests/cases/conformance/externalModules/foo.d.ts ===
declare namespace Thing {
>Thing : typeof Thing
export function fn(): number;
>fn : () => number
}
export = Thing;
>Thing : typeof Thing
export as namespace Foo;
>Foo : any

View File

@ -0,0 +1,13 @@
// @module: commonjs
// @noImplicitReferences: true
// @filename: foo.d.ts
declare namespace Thing {
export function fn(): number;
}
export = Thing;
export as namespace Foo;
// @filename: a.ts
/// <reference path="foo.d.ts" />
let y: number = Foo.fn();