Skip to content

Commit 85ab935

Browse files
committed
Merge pull request #8485 from RyanCavanaugh/fix8478
Allow module augmentations to add new top-level names.
2 parents 990f1c7 + 913143d commit 85ab935

26 files changed

+744
-400
lines changed

src/compiler/checker.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15741,13 +15741,6 @@ namespace ts {
1574115741
grammarErrorOnFirstToken(node, Diagnostics.Exports_and_export_assignments_are_not_permitted_in_module_augmentations);
1574215742
break;
1574315743
case SyntaxKind.ImportEqualsDeclaration:
15744-
if ((<ImportEqualsDeclaration>node).moduleReference.kind !== SyntaxKind.StringLiteral) {
15745-
if (!isGlobalAugmentation) {
15746-
error((<ImportEqualsDeclaration>node).name, Diagnostics.Module_augmentation_cannot_introduce_new_names_in_the_top_level_scope);
15747-
}
15748-
break;
15749-
}
15750-
// fallthrough
1575115744
case SyntaxKind.ImportDeclaration:
1575215745
grammarErrorOnFirstToken(node, Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module);
1575315746
break;
@@ -15782,9 +15775,6 @@ namespace ts {
1578215775
// symbol should not originate in augmentation
1578315776
reportError = isExternalModuleAugmentation(symbol.parent.declarations[0]);
1578415777
}
15785-
if (reportError) {
15786-
error(node, Diagnostics.Module_augmentation_cannot_introduce_new_names_in_the_top_level_scope);
15787-
}
1578815778
}
1578915779
break;
1579015780
}

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,10 +1843,6 @@
18431843
"category": "Error",
18441844
"code": 2664
18451845
},
1846-
"Module augmentation cannot introduce new names in the top level scope.": {
1847-
"category": "Error",
1848-
"code": 2665
1849-
},
18501846
"Exports and export assignments are not permitted in module augmentations.": {
18511847
"category": "Error",
18521848
"code": 2666

tests/baselines/reference/augmentExportEquals3.errors.txt

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
=== tests/cases/compiler/file1.ts ===
2+
3+
function foo() {}
4+
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8))
5+
6+
namespace foo {
7+
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8))
8+
9+
export var v = 1;
10+
>v : Symbol(v, Decl(file1.ts, 3, 14))
11+
}
12+
export = foo;
13+
>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17))
14+
15+
=== tests/cases/compiler/file2.ts ===
16+
import x = require("./file1");
17+
>x : Symbol(x, Decl(file2.ts, 0, 0))
18+
19+
x.b = 1;
20+
>x.b : Symbol(x.b, Decl(file2.ts, 6, 7))
21+
>x : Symbol(x, Decl(file2.ts, 0, 0))
22+
>b : Symbol(x.b, Decl(file2.ts, 6, 7))
23+
24+
// OK - './file1' is a namespace
25+
declare module "./file1" {
26+
interface A { a }
27+
>A : Symbol(A, Decl(file2.ts, 4, 26))
28+
>a : Symbol(A.a, Decl(file2.ts, 5, 17))
29+
30+
let b: number;
31+
>b : Symbol(b, Decl(file2.ts, 6, 7))
32+
}
33+
34+
=== tests/cases/compiler/file3.ts ===
35+
import * as x from "./file1";
36+
>x : Symbol(x, Decl(file3.ts, 0, 6))
37+
38+
import "./file2";
39+
let a: x.A;
40+
>a : Symbol(a, Decl(file3.ts, 2, 3))
41+
>x : Symbol(x, Decl(file3.ts, 0, 6))
42+
>A : Symbol(x.A, Decl(file2.ts, 4, 26))
43+
44+
let b = x.b;
45+
>b : Symbol(b, Decl(file3.ts, 3, 3))
46+
>x.b : Symbol(x.b, Decl(file2.ts, 6, 7))
47+
>x : Symbol(x, Decl(file3.ts, 0, 6))
48+
>b : Symbol(x.b, Decl(file2.ts, 6, 7))
49+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=== tests/cases/compiler/file1.ts ===
2+
3+
function foo() {}
4+
>foo : typeof
5+
6+
namespace foo {
7+
>foo : typeof
8+
9+
export var v = 1;
10+
>v : number
11+
>1 : number
12+
}
13+
export = foo;
14+
>foo : typeof foo
15+
16+
=== tests/cases/compiler/file2.ts ===
17+
import x = require("./file1");
18+
>x : typeof x
19+
20+
x.b = 1;
21+
>x.b = 1 : number
22+
>x.b : number
23+
>x : typeof x
24+
>b : number
25+
>1 : number
26+
27+
// OK - './file1' is a namespace
28+
declare module "./file1" {
29+
interface A { a }
30+
>A : A
31+
>a : any
32+
33+
let b: number;
34+
>b : number
35+
}
36+
37+
=== tests/cases/compiler/file3.ts ===
38+
import * as x from "./file1";
39+
>x : typeof x
40+
41+
import "./file2";
42+
let a: x.A;
43+
>a : x.A
44+
>x : any
45+
>A : x.A
46+
47+
let b = x.b;
48+
>b : number
49+
>x.b : number
50+
>x : typeof x
51+
>b : number
52+

tests/baselines/reference/augmentExportEquals3_1.errors.txt

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=== tests/cases/compiler/file1.d.ts ===
2+
declare module "file1" {
3+
function foo(): void;
4+
>foo : Symbol(, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8))
5+
6+
namespace foo {
7+
>foo : Symbol(, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8))
8+
9+
export var v: number;
10+
>v : Symbol(v, Decl(file1.d.ts, 3, 18))
11+
}
12+
export = foo;
13+
>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25))
14+
}
15+
16+
17+
=== tests/cases/compiler/file2.ts ===
18+
/// <reference path="file1.d.ts"/>
19+
import x = require("file1");
20+
>x : Symbol(x, Decl(file2.ts, 0, 0))
21+
22+
x.b = 1;
23+
>x.b : Symbol(x.b, Decl(file2.ts, 7, 7))
24+
>x : Symbol(x, Decl(file2.ts, 0, 0))
25+
>b : Symbol(x.b, Decl(file2.ts, 7, 7))
26+
27+
// OK - './file1' is a namespace
28+
declare module "file1" {
29+
interface A { a }
30+
>A : Symbol(A, Decl(file2.ts, 5, 24))
31+
>a : Symbol(A.a, Decl(file2.ts, 6, 17))
32+
33+
let b: number;
34+
>b : Symbol(b, Decl(file2.ts, 7, 7))
35+
}
36+
37+
=== tests/cases/compiler/file3.ts ===
38+
import * as x from "file1";
39+
>x : Symbol(x, Decl(file3.ts, 0, 6))
40+
41+
import "file2";
42+
let a: x.A;
43+
>a : Symbol(a, Decl(file3.ts, 2, 3))
44+
>x : Symbol(x, Decl(file3.ts, 0, 6))
45+
>A : Symbol(x.A, Decl(file2.ts, 5, 24))
46+
47+
let b = x.b;
48+
>b : Symbol(b, Decl(file3.ts, 3, 3))
49+
>x.b : Symbol(x.b, Decl(file2.ts, 7, 7))
50+
>x : Symbol(x, Decl(file3.ts, 0, 6))
51+
>b : Symbol(x.b, Decl(file2.ts, 7, 7))
52+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
=== tests/cases/compiler/file1.d.ts ===
2+
declare module "file1" {
3+
function foo(): void;
4+
>foo : typeof
5+
6+
namespace foo {
7+
>foo : typeof
8+
9+
export var v: number;
10+
>v : number
11+
}
12+
export = foo;
13+
>foo : typeof foo
14+
}
15+
16+
17+
=== tests/cases/compiler/file2.ts ===
18+
/// <reference path="file1.d.ts"/>
19+
import x = require("file1");
20+
>x : typeof x
21+
22+
x.b = 1;
23+
>x.b = 1 : number
24+
>x.b : number
25+
>x : typeof x
26+
>b : number
27+
>1 : number
28+
29+
// OK - './file1' is a namespace
30+
declare module "file1" {
31+
interface A { a }
32+
>A : A
33+
>a : any
34+
35+
let b: number;
36+
>b : number
37+
}
38+
39+
=== tests/cases/compiler/file3.ts ===
40+
import * as x from "file1";
41+
>x : typeof x
42+
43+
import "file2";
44+
let a: x.A;
45+
>a : x.A
46+
>x : any
47+
>A : x.A
48+
49+
let b = x.b;
50+
>b : number
51+
>x.b : number
52+
>x : typeof x
53+
>b : number
54+

tests/baselines/reference/augmentExportEquals4.errors.txt

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
=== tests/cases/compiler/file1.ts ===
2+
3+
class foo {}
4+
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8))
5+
6+
namespace foo {
7+
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8))
8+
9+
export var v = 1;
10+
>v : Symbol(v, Decl(file1.ts, 3, 14))
11+
}
12+
export = foo;
13+
>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12))
14+
15+
=== tests/cases/compiler/file2.ts ===
16+
import x = require("./file1");
17+
>x : Symbol(x, Decl(file2.ts, 0, 0))
18+
19+
x.b = 1;
20+
>x.b : Symbol(x.b, Decl(file2.ts, 6, 7))
21+
>x : Symbol(x, Decl(file2.ts, 0, 0))
22+
>b : Symbol(x.b, Decl(file2.ts, 6, 7))
23+
24+
// OK - './file1' is a namespace
25+
declare module "./file1" {
26+
interface A { a }
27+
>A : Symbol(A, Decl(file2.ts, 4, 26))
28+
>a : Symbol(A.a, Decl(file2.ts, 5, 17))
29+
30+
let b: number;
31+
>b : Symbol(b, Decl(file2.ts, 6, 7))
32+
}
33+
34+
=== tests/cases/compiler/file3.ts ===
35+
import * as x from "./file1";
36+
>x : Symbol(x, Decl(file3.ts, 0, 6))
37+
38+
import "./file2";
39+
let a: x.A;
40+
>a : Symbol(a, Decl(file3.ts, 2, 3))
41+
>x : Symbol(x, Decl(file3.ts, 0, 6))
42+
>A : Symbol(x.A, Decl(file2.ts, 4, 26))
43+
44+
let b = x.b;
45+
>b : Symbol(b, Decl(file3.ts, 3, 3))
46+
>x.b : Symbol(x.b, Decl(file2.ts, 6, 7))
47+
>x : Symbol(x, Decl(file3.ts, 0, 6))
48+
>b : Symbol(x.b, Decl(file2.ts, 6, 7))
49+

0 commit comments

Comments
 (0)