diff --git a/tests/baselines/reference/moduleElementsInWrongContext.errors.txt b/tests/baselines/reference/moduleElementsInWrongContext.errors.txt new file mode 100644 index 00000000000..4ab5c5b42c0 --- /dev/null +++ b/tests/baselines/reference/moduleElementsInWrongContext.errors.txt @@ -0,0 +1,87 @@ +tests/cases/compiler/moduleElementsInWrongContext.ts(2,5): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(3,5): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(7,5): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(9,5): error TS1234: An ambient module declaration is only allowed at the top level in a file. +tests/cases/compiler/moduleElementsInWrongContext.ts(13,5): error TS1231: An export assignment can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext.ts(17,5): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext.ts(18,5): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext.ts(19,5): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext.ts(19,14): error TS2305: Module '"ambient"' has no exported member 'baz'. +tests/cases/compiler/moduleElementsInWrongContext.ts(20,5): error TS1231: An export assignment can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext.ts(21,5): error TS1184: Modifiers cannot appear here. +tests/cases/compiler/moduleElementsInWrongContext.ts(22,5): error TS1184: Modifiers cannot appear here. +tests/cases/compiler/moduleElementsInWrongContext.ts(23,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(24,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(25,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(26,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(27,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(28,5): error TS1232: An import declaration can only be used in a namespace or module. + + +==== tests/cases/compiler/moduleElementsInWrongContext.ts (18 errors) ==== + { + module M { } + ~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + export namespace N { + ~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + export interface I { } + } + + namespace Q.K { } + ~~~~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + + declare module "ambient" { + ~~~~~~~ +!!! error TS1234: An ambient module declaration is only allowed at the top level in a file. + + } + + export = M; + ~~~~~~ +!!! error TS1231: An export assignment can only be used in a module. + + var v; + function foo() { } + export * from "ambient"; + ~~~~~~ +!!! error TS1233: An export declaration can only be used in a module. + export { foo }; + ~~~~~~ +!!! error TS1233: An export declaration can only be used in a module. + export { baz as b } from "ambient"; + ~~~~~~ +!!! error TS1233: An export declaration can only be used in a module. + ~~~ +!!! error TS2305: Module '"ambient"' has no exported member 'baz'. + export default v; + ~~~~~~ +!!! error TS1231: An export assignment can only be used in a module. + export default class C { } + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. + export function bee() { } + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. + import I = M; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import I2 = require("foo"); + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import * as Foo from "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import bar from "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import { baz } from "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/moduleElementsInWrongContext.js b/tests/baselines/reference/moduleElementsInWrongContext.js new file mode 100644 index 00000000000..635da02bdf2 --- /dev/null +++ b/tests/baselines/reference/moduleElementsInWrongContext.js @@ -0,0 +1,47 @@ +//// [moduleElementsInWrongContext.ts] +{ + module M { } + export namespace N { + export interface I { } + } + + namespace Q.K { } + + declare module "ambient" { + + } + + export = M; + + var v; + function foo() { } + export * from "ambient"; + export { foo }; + export { baz as b } from "ambient"; + export default v; + export default class C { } + export function bee() { } + import I = M; + import I2 = require("foo"); + import * as Foo from "ambient"; + import bar from "ambient"; + import { baz } from "ambient"; + import "ambient"; +} + + +//// [moduleElementsInWrongContext.js] +{ + var v; + function foo() { } + __export(require("ambient")); + exports["default"] = v; + var C = (function () { + function C() { + } + return C; + })(); + exports["default"] = C; + function bee() { } + exports.bee = bee; +} diff --git a/tests/baselines/reference/moduleElementsInWrongContext2.errors.txt b/tests/baselines/reference/moduleElementsInWrongContext2.errors.txt new file mode 100644 index 00000000000..d6611e71831 --- /dev/null +++ b/tests/baselines/reference/moduleElementsInWrongContext2.errors.txt @@ -0,0 +1,87 @@ +tests/cases/compiler/moduleElementsInWrongContext2.ts(2,5): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(3,5): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(7,5): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(9,5): error TS1234: An ambient module declaration is only allowed at the top level in a file. +tests/cases/compiler/moduleElementsInWrongContext2.ts(13,5): error TS1231: An export assignment can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(17,5): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(18,5): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(19,5): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(19,30): error TS2307: Cannot find module 'ambient'. +tests/cases/compiler/moduleElementsInWrongContext2.ts(20,5): error TS1231: An export assignment can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(21,5): error TS1184: Modifiers cannot appear here. +tests/cases/compiler/moduleElementsInWrongContext2.ts(22,5): error TS1184: Modifiers cannot appear here. +tests/cases/compiler/moduleElementsInWrongContext2.ts(23,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(24,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(25,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(26,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(27,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(28,5): error TS1232: An import declaration can only be used in a namespace or module. + + +==== tests/cases/compiler/moduleElementsInWrongContext2.ts (18 errors) ==== + function blah () { + module M { } + ~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + export namespace N { + ~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + export interface I { } + } + + namespace Q.K { } + ~~~~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + + declare module "ambient" { + ~~~~~~~ +!!! error TS1234: An ambient module declaration is only allowed at the top level in a file. + + } + + export = M; + ~~~~~~ +!!! error TS1231: An export assignment can only be used in a module. + + var v; + function foo() { } + export * from "ambient"; + ~~~~~~ +!!! error TS1233: An export declaration can only be used in a module. + export { foo }; + ~~~~~~ +!!! error TS1233: An export declaration can only be used in a module. + export { baz as b } from "ambient"; + ~~~~~~ +!!! error TS1233: An export declaration can only be used in a module. + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'ambient'. + export default v; + ~~~~~~ +!!! error TS1231: An export assignment can only be used in a module. + export default class C { } + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. + export function bee() { } + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. + import I = M; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import I2 = require("foo"); + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import * as Foo from "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import bar from "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import { baz } from "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/moduleElementsInWrongContext2.js b/tests/baselines/reference/moduleElementsInWrongContext2.js new file mode 100644 index 00000000000..fdf1222e549 --- /dev/null +++ b/tests/baselines/reference/moduleElementsInWrongContext2.js @@ -0,0 +1,47 @@ +//// [moduleElementsInWrongContext2.ts] +function blah () { + module M { } + export namespace N { + export interface I { } + } + + namespace Q.K { } + + declare module "ambient" { + + } + + export = M; + + var v; + function foo() { } + export * from "ambient"; + export { foo }; + export { baz as b } from "ambient"; + export default v; + export default class C { } + export function bee() { } + import I = M; + import I2 = require("foo"); + import * as Foo from "ambient"; + import bar from "ambient"; + import { baz } from "ambient"; + import "ambient"; +} + + +//// [moduleElementsInWrongContext2.js] +function blah() { + var v; + function foo() { } + __export(require("ambient")); + exports["default"] = v; + var C = (function () { + function C() { + } + return C; + })(); + exports["default"] = C; + function bee() { } + exports.bee = bee; +} diff --git a/tests/baselines/reference/moduleElementsInWrongContext3.errors.txt b/tests/baselines/reference/moduleElementsInWrongContext3.errors.txt new file mode 100644 index 00000000000..f5361319b68 --- /dev/null +++ b/tests/baselines/reference/moduleElementsInWrongContext3.errors.txt @@ -0,0 +1,88 @@ +tests/cases/compiler/moduleElementsInWrongContext3.ts(3,9): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(4,9): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(8,9): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(10,9): error TS1234: An ambient module declaration is only allowed at the top level in a file. +tests/cases/compiler/moduleElementsInWrongContext3.ts(14,9): error TS1231: An export assignment can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(18,9): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(19,9): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(20,9): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(20,34): error TS2307: Cannot find module 'ambient'. +tests/cases/compiler/moduleElementsInWrongContext3.ts(21,9): error TS1231: An export assignment can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(22,9): error TS1184: Modifiers cannot appear here. +tests/cases/compiler/moduleElementsInWrongContext3.ts(23,9): error TS1184: Modifiers cannot appear here. +tests/cases/compiler/moduleElementsInWrongContext3.ts(24,9): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(25,9): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(26,9): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(27,9): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(28,9): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(29,9): error TS1232: An import declaration can only be used in a namespace or module. + + +==== tests/cases/compiler/moduleElementsInWrongContext3.ts (18 errors) ==== + module P { + { + module M { } + ~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + export namespace N { + ~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + export interface I { } + } + + namespace Q.K { } + ~~~~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + + declare module "ambient" { + ~~~~~~~ +!!! error TS1234: An ambient module declaration is only allowed at the top level in a file. + + } + + export = M; + ~~~~~~ +!!! error TS1231: An export assignment can only be used in a module. + + var v; + function foo() { } + export * from "ambient"; + ~~~~~~ +!!! error TS1233: An export declaration can only be used in a module. + export { foo }; + ~~~~~~ +!!! error TS1233: An export declaration can only be used in a module. + export { baz as b } from "ambient"; + ~~~~~~ +!!! error TS1233: An export declaration can only be used in a module. + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'ambient'. + export default v; + ~~~~~~ +!!! error TS1231: An export assignment can only be used in a module. + export default class C { } + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. + export function bee() { } + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. + import I = M; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import I2 = require("foo"); + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import * as Foo from "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import bar from "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import { baz } from "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + import "ambient"; + ~~~~~~ +!!! error TS1232: An import declaration can only be used in a namespace or module. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/moduleElementsInWrongContext3.js b/tests/baselines/reference/moduleElementsInWrongContext3.js new file mode 100644 index 00000000000..d464d9d31b1 --- /dev/null +++ b/tests/baselines/reference/moduleElementsInWrongContext3.js @@ -0,0 +1,51 @@ +//// [moduleElementsInWrongContext3.ts] +module P { + { + module M { } + export namespace N { + export interface I { } + } + + namespace Q.K { } + + declare module "ambient" { + + } + + export = M; + + var v; + function foo() { } + export * from "ambient"; + export { foo }; + export { baz as b } from "ambient"; + export default v; + export default class C { } + export function bee() { } + import I = M; + import I2 = require("foo"); + import * as Foo from "ambient"; + import bar from "ambient"; + import { baz } from "ambient"; + import "ambient"; + } +} + +//// [moduleElementsInWrongContext3.js] +var P; +(function (P) { + { + var v; + function foo() { } + __export(require("ambient")); + P["default"] = v; + var C = (function () { + function C() { + } + return C; + })(); + exports["default"] = C; + function bee() { } + P.bee = bee; + } +})(P || (P = {})); diff --git a/tests/cases/compiler/moduleElementsInWrongContext.ts b/tests/cases/compiler/moduleElementsInWrongContext.ts new file mode 100644 index 00000000000..778e2775467 --- /dev/null +++ b/tests/cases/compiler/moduleElementsInWrongContext.ts @@ -0,0 +1,29 @@ +{ + module M { } + export namespace N { + export interface I { } + } + + namespace Q.K { } + + declare module "ambient" { + + } + + export = M; + + var v; + function foo() { } + export * from "ambient"; + export { foo }; + export { baz as b } from "ambient"; + export default v; + export default class C { } + export function bee() { } + import I = M; + import I2 = require("foo"); + import * as Foo from "ambient"; + import bar from "ambient"; + import { baz } from "ambient"; + import "ambient"; +} diff --git a/tests/cases/compiler/moduleElementsInWrongContext2.ts b/tests/cases/compiler/moduleElementsInWrongContext2.ts new file mode 100644 index 00000000000..936893b96c2 --- /dev/null +++ b/tests/cases/compiler/moduleElementsInWrongContext2.ts @@ -0,0 +1,29 @@ +function blah () { + module M { } + export namespace N { + export interface I { } + } + + namespace Q.K { } + + declare module "ambient" { + + } + + export = M; + + var v; + function foo() { } + export * from "ambient"; + export { foo }; + export { baz as b } from "ambient"; + export default v; + export default class C { } + export function bee() { } + import I = M; + import I2 = require("foo"); + import * as Foo from "ambient"; + import bar from "ambient"; + import { baz } from "ambient"; + import "ambient"; +} diff --git a/tests/cases/compiler/moduleElementsInWrongContext3.ts b/tests/cases/compiler/moduleElementsInWrongContext3.ts new file mode 100644 index 00000000000..efc69016269 --- /dev/null +++ b/tests/cases/compiler/moduleElementsInWrongContext3.ts @@ -0,0 +1,31 @@ +module P { + { + module M { } + export namespace N { + export interface I { } + } + + namespace Q.K { } + + declare module "ambient" { + + } + + export = M; + + var v; + function foo() { } + export * from "ambient"; + export { foo }; + export { baz as b } from "ambient"; + export default v; + export default class C { } + export function bee() { } + import I = M; + import I2 = require("foo"); + import * as Foo from "ambient"; + import bar from "ambient"; + import { baz } from "ambient"; + import "ambient"; + } +} \ No newline at end of file