UMD support

This commit is contained in:
Ryan Cavanaugh
2016-03-02 10:52:16 -08:00
parent b29f460641
commit 44aa7388ea
32 changed files with 687 additions and 16 deletions

View File

@@ -0,0 +1,60 @@
tests/cases/conformance/externalModules/err1.d.ts(3,1): error TS1314: Global module exports may only appear in module files.
tests/cases/conformance/externalModules/err2.d.ts(3,2): error TS1314: Global module exports may only appear in module files.
tests/cases/conformance/externalModules/err2.d.ts(3,2): error TS1316: Global module exports may only appear at top level.
tests/cases/conformance/externalModules/err3.d.ts(3,1): error TS1184: Modifiers cannot appear here.
tests/cases/conformance/externalModules/err3.d.ts(4,1): error TS1184: Modifiers cannot appear here.
tests/cases/conformance/externalModules/err3.d.ts(5,1): error TS1184: Modifiers cannot appear here.
tests/cases/conformance/externalModules/err3.d.ts(6,7): error TS1134: Variable declaration expected.
tests/cases/conformance/externalModules/err4.d.ts(3,2): error TS1316: Global module exports may only appear at top level.
tests/cases/conformance/externalModules/err5.ts(3,1): error TS1315: Global module exports may only appear in declaration files.
==== tests/cases/conformance/externalModules/err1.d.ts (1 errors) ====
// Illegal, can't be in script file
export as namespace Foo;
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1314: Global module exports may only appear in module files.
==== tests/cases/conformance/externalModules/err2.d.ts (2 errors) ====
// Illegal, can't be in external ambient module
declare module "Foo" {
export as namespace Bar;
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1314: Global module exports may only appear in module files.
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1316: Global module exports may only appear at top level.
}
==== tests/cases/conformance/externalModules/err3.d.ts (4 errors) ====
// Illegal, can't have modifiers
export var p;
static export as namespace oo1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1184: Modifiers cannot appear here.
declare export as namespace oo2;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1184: Modifiers cannot appear here.
public export as namespace oo3;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1184: Modifiers cannot appear here.
const export as namespace oo4;
~~~~~~
!!! error TS1134: Variable declaration expected.
==== tests/cases/conformance/externalModules/err4.d.ts (1 errors) ====
// Illegal, must be at top-level
export namespace B {
export as namespace C1;
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1316: Global module exports may only appear at top level.
}
==== tests/cases/conformance/externalModules/err5.ts (1 errors) ====
// Illegal, may not appear in implementation files
export var v;
export as namespace C2;
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1315: Global module exports may only appear in declaration files.

View File

@@ -0,0 +1,36 @@
//// [tests/cases/conformance/externalModules/umd-errors.ts] ////
//// [err1.d.ts]
// Illegal, can't be in script file
export as namespace Foo;
//// [err2.d.ts]
// Illegal, can't be in external ambient module
declare module "Foo" {
export as namespace Bar;
}
//// [err3.d.ts]
// Illegal, can't have modifiers
export var p;
static export as namespace oo1;
declare export as namespace oo2;
public export as namespace oo3;
const export as namespace oo4;
//// [err4.d.ts]
// Illegal, must be at top-level
export namespace B {
export as namespace C1;
}
//// [err5.ts]
// Illegal, may not appear in implementation files
export var v;
export as namespace C2;
//// [err5.js]
"use strict";

View File

@@ -0,0 +1,8 @@
=== tests/cases/conformance/externalModules/err5.d.ts ===
// Illegal, may not appear in implementation files
export var v;
>v : Symbol(v, Decl(err5.d.ts, 1, 10))
export as namespace C;

View File

@@ -0,0 +1,9 @@
=== tests/cases/conformance/externalModules/err5.d.ts ===
// Illegal, may not appear in implementation files
export var v;
>v : any
export as namespace C;
>C : any

View File

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

View File

@@ -0,0 +1,33 @@
=== tests/cases/conformance/externalModules/a.ts ===
/// <reference path="foo.d.ts" />
Foo.fn();
>Foo.fn : Symbol(Foo.fn, Decl(foo.d.ts, 1, 21))
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38))
>fn : Symbol(Foo.fn, Decl(foo.d.ts, 1, 21))
let x: Foo.Thing;
>x : Symbol(x, Decl(a.ts, 2, 3))
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38))
>Thing : Symbol(Foo.Thing, Decl(foo.d.ts, 2, 27))
let y: number = x.n;
>y : Symbol(y, Decl(a.ts, 3, 3))
>x.n : Symbol(Foo.Thing.n, Decl(foo.d.ts, 3, 24))
>x : Symbol(x, Decl(a.ts, 2, 3))
>n : Symbol(Foo.Thing.n, Decl(foo.d.ts, 3, 24))
=== tests/cases/conformance/externalModules/foo.d.ts ===
export var x: number;
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
export function fn(): void;
>fn : Symbol(fn, Decl(foo.d.ts, 1, 21))
export interface Thing { n: typeof x }
>Thing : Symbol(Thing, Decl(foo.d.ts, 2, 27))
>n : Symbol(n, Decl(foo.d.ts, 3, 24))
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
export as namespace Foo;

View File

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

View File

@@ -0,0 +1,19 @@
tests/cases/conformance/externalModules/a.ts(1,1): error TS2304: Cannot find name 'Foo'.
tests/cases/conformance/externalModules/a.ts(2,8): error TS2503: Cannot find namespace 'Foo'.
==== tests/cases/conformance/externalModules/a.ts (2 errors) ====
Foo.fn();
~~~
!!! error TS2304: Cannot find name 'Foo'.
let x: Foo.Thing;
~~~
!!! error TS2503: Cannot find namespace 'Foo'.
let y: number = x.n;
==== tests/cases/conformance/externalModules/foo.d.ts (0 errors) ====
export var x: number;
export function fn(): void;
export as namespace Foo;

View File

@@ -0,0 +1,18 @@
//// [tests/cases/conformance/externalModules/umd2.ts] ////
//// [foo.d.ts]
export var x: number;
export function fn(): void;
export as namespace Foo;
//// [a.ts]
Foo.fn();
let x: Foo.Thing;
let y: number = x.n;
//// [a.js]
Foo.fn();
var x;
var y = x.n;

View File

@@ -0,0 +1,22 @@
//// [tests/cases/conformance/externalModules/umd3.ts] ////
//// [foo.d.ts]
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
export as namespace Foo;
//// [a.ts]
import * as Foo from './foo';
Foo.fn();
let x: Foo.Thing;
let y: number = x.n;
//// [a.js]
"use strict";
var Foo = require('./foo');
Foo.fn();
var x;
var y = x.n;

View File

@@ -0,0 +1,35 @@
=== tests/cases/conformance/externalModules/a.ts ===
import * as Foo from './foo';
>Foo : Symbol(Foo, Decl(a.ts, 0, 6))
Foo.fn();
>Foo.fn : Symbol(Foo.fn, Decl(foo.d.ts, 1, 21))
>Foo : Symbol(Foo, Decl(a.ts, 0, 6))
>fn : Symbol(Foo.fn, Decl(foo.d.ts, 1, 21))
let x: Foo.Thing;
>x : Symbol(x, Decl(a.ts, 2, 3))
>Foo : Symbol(Foo, Decl(a.ts, 0, 6))
>Thing : Symbol(Foo.Thing, Decl(foo.d.ts, 2, 27))
let y: number = x.n;
>y : Symbol(y, Decl(a.ts, 3, 3))
>x.n : Symbol(Foo.Thing.n, Decl(foo.d.ts, 3, 24))
>x : Symbol(x, Decl(a.ts, 2, 3))
>n : Symbol(Foo.Thing.n, Decl(foo.d.ts, 3, 24))
=== tests/cases/conformance/externalModules/foo.d.ts ===
export var x: number;
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
export function fn(): void;
>fn : Symbol(fn, Decl(foo.d.ts, 1, 21))
export interface Thing { n: typeof x }
>Thing : Symbol(Thing, Decl(foo.d.ts, 2, 27))
>n : Symbol(n, Decl(foo.d.ts, 3, 24))
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
export as namespace Foo;

View File

@@ -0,0 +1,37 @@
=== tests/cases/conformance/externalModules/a.ts ===
import * as Foo from './foo';
>Foo : typeof Foo
Foo.fn();
>Foo.fn() : void
>Foo.fn : () => void
>Foo : typeof Foo
>fn : () => void
let x: Foo.Thing;
>x : Foo.Thing
>Foo : any
>Thing : Foo.Thing
let y: number = x.n;
>y : number
>x.n : number
>x : Foo.Thing
>n : number
=== tests/cases/conformance/externalModules/foo.d.ts ===
export var x: number;
>x : number
export function fn(): void;
>fn : () => void
export interface Thing { n: typeof x }
>Thing : Thing
>n : number
>x : number
export as namespace Foo;
>Foo : any

View File

@@ -0,0 +1,22 @@
//// [tests/cases/conformance/externalModules/umd4.ts] ////
//// [foo.d.ts]
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
export as namespace Foo;
//// [a.ts]
import * as Bar from './foo';
Bar.fn();
let x: Bar.Thing;
let y: number = x.n;
//// [a.js]
"use strict";
var Bar = require('./foo');
Bar.fn();
var x;
var y = x.n;

View File

@@ -0,0 +1,35 @@
=== tests/cases/conformance/externalModules/a.ts ===
import * as Bar from './foo';
>Bar : Symbol(Bar, Decl(a.ts, 0, 6))
Bar.fn();
>Bar.fn : Symbol(Bar.fn, Decl(foo.d.ts, 1, 21))
>Bar : Symbol(Bar, Decl(a.ts, 0, 6))
>fn : Symbol(Bar.fn, Decl(foo.d.ts, 1, 21))
let x: Bar.Thing;
>x : Symbol(x, Decl(a.ts, 2, 3))
>Bar : Symbol(Bar, Decl(a.ts, 0, 6))
>Thing : Symbol(Bar.Thing, Decl(foo.d.ts, 2, 27))
let y: number = x.n;
>y : Symbol(y, Decl(a.ts, 3, 3))
>x.n : Symbol(Bar.Thing.n, Decl(foo.d.ts, 3, 24))
>x : Symbol(x, Decl(a.ts, 2, 3))
>n : Symbol(Bar.Thing.n, Decl(foo.d.ts, 3, 24))
=== tests/cases/conformance/externalModules/foo.d.ts ===
export var x: number;
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
export function fn(): void;
>fn : Symbol(fn, Decl(foo.d.ts, 1, 21))
export interface Thing { n: typeof x }
>Thing : Symbol(Thing, Decl(foo.d.ts, 2, 27))
>n : Symbol(n, Decl(foo.d.ts, 3, 24))
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
export as namespace Foo;

View File

@@ -0,0 +1,37 @@
=== tests/cases/conformance/externalModules/a.ts ===
import * as Bar from './foo';
>Bar : typeof Bar
Bar.fn();
>Bar.fn() : void
>Bar.fn : () => void
>Bar : typeof Bar
>fn : () => void
let x: Bar.Thing;
>x : Bar.Thing
>Bar : any
>Thing : Bar.Thing
let y: number = x.n;
>y : number
>x.n : number
>x : Bar.Thing
>n : number
=== tests/cases/conformance/externalModules/foo.d.ts ===
export var x: number;
>x : number
export function fn(): void;
>fn : () => void
export interface Thing { n: typeof x }
>Thing : Thing
>n : number
>x : number
export as namespace Foo;
>Foo : any

View File

@@ -0,0 +1,20 @@
tests/cases/conformance/externalModules/a.ts(6,9): error TS2304: Cannot find name 'Foo'.
==== tests/cases/conformance/externalModules/a.ts (1 errors) ====
import * as Bar from './foo';
Bar.fn();
let x: Bar.Thing;
let y: number = x.n;
// should error
let z = Foo;
~~~
!!! error TS2304: Cannot find name 'Foo'.
==== tests/cases/conformance/externalModules/foo.d.ts (0 errors) ====
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
export as namespace Foo;

View File

@@ -0,0 +1,26 @@
//// [tests/cases/conformance/externalModules/umd5.ts] ////
//// [foo.d.ts]
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
export as namespace Foo;
//// [a.ts]
import * as Bar from './foo';
Bar.fn();
let x: Bar.Thing;
let y: number = x.n;
// should error
let z = Foo;
//// [a.js]
"use strict";
var Bar = require('./foo');
Bar.fn();
var x;
var y = x.n;
// should error
var z = Foo;

View File

@@ -0,0 +1,31 @@
// @module: commonjs
// @filename: err1.d.ts
// Illegal, can't be in script file
export as namespace Foo;
// @filename: err2.d.ts
// Illegal, can't be in external ambient module
declare module "Foo" {
export as namespace Bar;
}
// @filename: err3.d.ts
// Illegal, can't have modifiers
export var p;
static export as namespace oo1;
declare export as namespace oo2;
public export as namespace oo3;
const export as namespace oo4;
// @filename: err4.d.ts
// Illegal, must be at top-level
export namespace B {
export as namespace C1;
}
// @filename: err5.ts
// Illegal, may not appear in implementation files
export var v;
export as namespace C2;

View File

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

View File

@@ -0,0 +1,12 @@
// @module: commonjs
// @noImplicitReferences: true
// @filename: foo.d.ts
export var x: number;
export function fn(): void;
export as namespace Foo;
// @filename: a.ts
Foo.fn();
let x: Foo.Thing;
let y: number = x.n;

View File

@@ -0,0 +1,14 @@
// @module: commonjs
// @noImplicitReferences: true
// @filename: foo.d.ts
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
export as namespace Foo;
// @filename: a.ts
import * as Foo from './foo';
Foo.fn();
let x: Foo.Thing;
let y: number = x.n;

View File

@@ -0,0 +1,14 @@
// @module: commonjs
// @noImplicitReferences: true
// @filename: foo.d.ts
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
export as namespace Foo;
// @filename: a.ts
import * as Bar from './foo';
Bar.fn();
let x: Bar.Thing;
let y: number = x.n;

View File

@@ -0,0 +1,16 @@
// @module: commonjs
// @noImplicitReferences: true
// @filename: foo.d.ts
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
export as namespace Foo;
// @filename: a.ts
import * as Bar from './foo';
Bar.fn();
let x: Bar.Thing;
let y: number = x.n;
// should error
let z = Foo;