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

Allow module augmentations to add new top-level names. #8485

Merged
merged 2 commits into from
May 5, 2016
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
10 changes: 0 additions & 10 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15741,13 +15741,6 @@ namespace ts {
grammarErrorOnFirstToken(node, Diagnostics.Exports_and_export_assignments_are_not_permitted_in_module_augmentations);
break;
case SyntaxKind.ImportEqualsDeclaration:
if ((<ImportEqualsDeclaration>node).moduleReference.kind !== SyntaxKind.StringLiteral) {
if (!isGlobalAugmentation) {
error((<ImportEqualsDeclaration>node).name, Diagnostics.Module_augmentation_cannot_introduce_new_names_in_the_top_level_scope);
}
break;
}
// fallthrough
case SyntaxKind.ImportDeclaration:
grammarErrorOnFirstToken(node, Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module);
break;
Expand Down Expand Up @@ -15782,9 +15775,6 @@ namespace ts {
// symbol should not originate in augmentation
reportError = isExternalModuleAugmentation(symbol.parent.declarations[0]);
}
if (reportError) {
error(node, Diagnostics.Module_augmentation_cannot_introduce_new_names_in_the_top_level_scope);
}
}
break;
}
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1843,10 +1843,6 @@
"category": "Error",
"code": 2664
},
"Module augmentation cannot introduce new names in the top level scope.": {
"category": "Error",
"code": 2665
},
"Exports and export assignments are not permitted in module augmentations.": {
"category": "Error",
"code": 2666
Expand Down
31 changes: 0 additions & 31 deletions tests/baselines/reference/augmentExportEquals3.errors.txt

This file was deleted.

49 changes: 49 additions & 0 deletions tests/baselines/reference/augmentExportEquals3.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
=== tests/cases/compiler/file1.ts ===

function foo() {}
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8))

namespace foo {
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8))

export var v = 1;
>v : Symbol(v, Decl(file1.ts, 3, 14))
}
export = foo;
>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17))

=== tests/cases/compiler/file2.ts ===
import x = require("./file1");
>x : Symbol(x, Decl(file2.ts, 0, 0))

x.b = 1;
>x.b : Symbol(x.b, Decl(file2.ts, 6, 7))
>x : Symbol(x, Decl(file2.ts, 0, 0))
>b : Symbol(x.b, Decl(file2.ts, 6, 7))

// OK - './file1' is a namespace
declare module "./file1" {
interface A { a }
>A : Symbol(A, Decl(file2.ts, 4, 26))
>a : Symbol(A.a, Decl(file2.ts, 5, 17))

let b: number;
>b : Symbol(b, Decl(file2.ts, 6, 7))
}

=== tests/cases/compiler/file3.ts ===
import * as x from "./file1";
>x : Symbol(x, Decl(file3.ts, 0, 6))

import "./file2";
let a: x.A;
>a : Symbol(a, Decl(file3.ts, 2, 3))
>x : Symbol(x, Decl(file3.ts, 0, 6))
>A : Symbol(x.A, Decl(file2.ts, 4, 26))

let b = x.b;
>b : Symbol(b, Decl(file3.ts, 3, 3))
>x.b : Symbol(x.b, Decl(file2.ts, 6, 7))
>x : Symbol(x, Decl(file3.ts, 0, 6))
>b : Symbol(x.b, Decl(file2.ts, 6, 7))

52 changes: 52 additions & 0 deletions tests/baselines/reference/augmentExportEquals3.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
=== tests/cases/compiler/file1.ts ===

function foo() {}
>foo : typeof

namespace foo {
>foo : typeof

export var v = 1;
>v : number
>1 : number
}
export = foo;
>foo : typeof foo

=== tests/cases/compiler/file2.ts ===
import x = require("./file1");
>x : typeof x

x.b = 1;
>x.b = 1 : number
>x.b : number
>x : typeof x
>b : number
>1 : number

// OK - './file1' is a namespace
declare module "./file1" {
interface A { a }
>A : A
>a : any

let b: number;
>b : number
}

=== tests/cases/compiler/file3.ts ===
import * as x from "./file1";
>x : typeof x

import "./file2";
let a: x.A;
>a : x.A
>x : any
>A : x.A

let b = x.b;
>b : number
>x.b : number
>x : typeof x
>b : number

34 changes: 0 additions & 34 deletions tests/baselines/reference/augmentExportEquals3_1.errors.txt

This file was deleted.

52 changes: 52 additions & 0 deletions tests/baselines/reference/augmentExportEquals3_1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
=== tests/cases/compiler/file1.d.ts ===
declare module "file1" {
function foo(): void;
>foo : Symbol(, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8))

namespace foo {
>foo : Symbol(, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8))

export var v: number;
>v : Symbol(v, Decl(file1.d.ts, 3, 18))
}
export = foo;
>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25))
}


=== tests/cases/compiler/file2.ts ===
/// <reference path="file1.d.ts"/>
import x = require("file1");
>x : Symbol(x, Decl(file2.ts, 0, 0))

x.b = 1;
>x.b : Symbol(x.b, Decl(file2.ts, 7, 7))
>x : Symbol(x, Decl(file2.ts, 0, 0))
>b : Symbol(x.b, Decl(file2.ts, 7, 7))

// OK - './file1' is a namespace
declare module "file1" {
interface A { a }
>A : Symbol(A, Decl(file2.ts, 5, 24))
>a : Symbol(A.a, Decl(file2.ts, 6, 17))

let b: number;
>b : Symbol(b, Decl(file2.ts, 7, 7))
}

=== tests/cases/compiler/file3.ts ===
import * as x from "file1";
>x : Symbol(x, Decl(file3.ts, 0, 6))

import "file2";
let a: x.A;
>a : Symbol(a, Decl(file3.ts, 2, 3))
>x : Symbol(x, Decl(file3.ts, 0, 6))
>A : Symbol(x.A, Decl(file2.ts, 5, 24))

let b = x.b;
>b : Symbol(b, Decl(file3.ts, 3, 3))
>x.b : Symbol(x.b, Decl(file2.ts, 7, 7))
>x : Symbol(x, Decl(file3.ts, 0, 6))
>b : Symbol(x.b, Decl(file2.ts, 7, 7))

54 changes: 54 additions & 0 deletions tests/baselines/reference/augmentExportEquals3_1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
=== tests/cases/compiler/file1.d.ts ===
declare module "file1" {
function foo(): void;
>foo : typeof

namespace foo {
>foo : typeof

export var v: number;
>v : number
}
export = foo;
>foo : typeof foo
}


=== tests/cases/compiler/file2.ts ===
/// <reference path="file1.d.ts"/>
import x = require("file1");
>x : typeof x

x.b = 1;
>x.b = 1 : number
>x.b : number
>x : typeof x
>b : number
>1 : number

// OK - './file1' is a namespace
declare module "file1" {
interface A { a }
>A : A
>a : any

let b: number;
>b : number
}

=== tests/cases/compiler/file3.ts ===
import * as x from "file1";
>x : typeof x

import "file2";
let a: x.A;
>a : x.A
>x : any
>A : x.A

let b = x.b;
>b : number
>x.b : number
>x : typeof x
>b : number

31 changes: 0 additions & 31 deletions tests/baselines/reference/augmentExportEquals4.errors.txt

This file was deleted.

49 changes: 49 additions & 0 deletions tests/baselines/reference/augmentExportEquals4.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
=== tests/cases/compiler/file1.ts ===

class foo {}
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8))

namespace foo {
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8))

export var v = 1;
>v : Symbol(v, Decl(file1.ts, 3, 14))
}
export = foo;
>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12))

=== tests/cases/compiler/file2.ts ===
import x = require("./file1");
>x : Symbol(x, Decl(file2.ts, 0, 0))

x.b = 1;
>x.b : Symbol(x.b, Decl(file2.ts, 6, 7))
>x : Symbol(x, Decl(file2.ts, 0, 0))
>b : Symbol(x.b, Decl(file2.ts, 6, 7))

// OK - './file1' is a namespace
declare module "./file1" {
interface A { a }
>A : Symbol(A, Decl(file2.ts, 4, 26))
>a : Symbol(A.a, Decl(file2.ts, 5, 17))

let b: number;
>b : Symbol(b, Decl(file2.ts, 6, 7))
}

=== tests/cases/compiler/file3.ts ===
import * as x from "./file1";
>x : Symbol(x, Decl(file3.ts, 0, 6))

import "./file2";
let a: x.A;
>a : Symbol(a, Decl(file3.ts, 2, 3))
>x : Symbol(x, Decl(file3.ts, 0, 6))
>A : Symbol(x.A, Decl(file2.ts, 4, 26))

let b = x.b;
>b : Symbol(b, Decl(file3.ts, 3, 3))
>x.b : Symbol(x.b, Decl(file2.ts, 6, 7))
>x : Symbol(x, Decl(file3.ts, 0, 6))
>b : Symbol(x.b, Decl(file2.ts, 6, 7))

Loading