Skip to content

Commit 0f323ea

Browse files
committed
allow top level 'import x = identifier | qname' in module augmentations
1 parent 78177cf commit 0f323ea

File tree

6 files changed

+69
-16
lines changed

6 files changed

+69
-16
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ namespace ts {
355355
function declareModuleMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol {
356356
const hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export;
357357
if (symbolFlags & SymbolFlags.Alias) {
358-
if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && hasExportModifier)) {
358+
if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && (hasExportModifier || container.flags & NodeFlags.ExportContext))) {
359359
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
360360
}
361361
else {

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15572,7 +15572,9 @@ namespace ts {
1557215572
break;
1557315573
case SyntaxKind.ImportEqualsDeclaration:
1557415574
if ((<ImportEqualsDeclaration>node).moduleReference.kind !== SyntaxKind.StringLiteral) {
15575-
error((<ImportEqualsDeclaration>node).name, Diagnostics.Module_augmentation_cannot_introduce_new_names_in_the_top_level_scope);
15575+
if (!isGlobalAugmentation) {
15576+
error((<ImportEqualsDeclaration>node).name, Diagnostics.Module_augmentation_cannot_introduce_new_names_in_the_top_level_scope);
15577+
}
1557615578
break;
1557715579
}
1557815580
// fallthrough

tests/baselines/reference/newNamesInGlobalAugmentations1.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@
44

55
export {};
66

7+
declare module M.M1 {
8+
export let x: number;
9+
}
710
declare global {
811
interface SymbolConstructor {
912
observable: symbol;
1013
}
1114
class Cls {x}
1215
let [a, b]: number[];
16+
import X = M.M1.x;
1317
}
1418

1519
//// [main.ts]
1620

1721
Symbol.observable;
18-
new Cls().x
22+
new Cls().x
23+
let c = a + b + X;
1924

2025
//// [main.js]
2126
Symbol.observable;
2227
new Cls().x;
28+
let c = a + b + X;

tests/baselines/reference/newNamesInGlobalAugmentations1.symbols

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,52 @@
22

33
export {};
44

5+
declare module M.M1 {
6+
>M : Symbol(M, Decl(f1.d.ts, 1, 10))
7+
>M1 : Symbol(M1, Decl(f1.d.ts, 3, 17))
8+
9+
export let x: number;
10+
>x : Symbol(x, Decl(f1.d.ts, 4, 14))
11+
}
512
declare global {
6-
>global : Symbol(, Decl(f1.d.ts, 1, 10))
13+
>global : Symbol(, Decl(f1.d.ts, 5, 1))
714

815
interface SymbolConstructor {
9-
>SymbolConstructor : Symbol(SymbolConstructor, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(f1.d.ts, 3, 16))
16+
>SymbolConstructor : Symbol(SymbolConstructor, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(f1.d.ts, 6, 16))
1017

1118
observable: symbol;
12-
>observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 4, 33))
19+
>observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 7, 33))
1320
}
1421
class Cls {x}
15-
>Cls : Symbol(Cls, Decl(f1.d.ts, 6, 5))
16-
>x : Symbol(Cls.x, Decl(f1.d.ts, 7, 15))
22+
>Cls : Symbol(Cls, Decl(f1.d.ts, 9, 5))
23+
>x : Symbol(Cls.x, Decl(f1.d.ts, 10, 15))
1724

1825
let [a, b]: number[];
19-
>a : Symbol(a, Decl(f1.d.ts, 8, 9))
20-
>b : Symbol(b, Decl(f1.d.ts, 8, 11))
26+
>a : Symbol(a, Decl(f1.d.ts, 11, 9))
27+
>b : Symbol(b, Decl(f1.d.ts, 11, 11))
28+
29+
import X = M.M1.x;
30+
>X : Symbol(X, Decl(f1.d.ts, 11, 25))
31+
>M : Symbol(M, Decl(f1.d.ts, 1, 10))
32+
>M1 : Symbol(M.M1, Decl(f1.d.ts, 3, 17))
33+
>x : Symbol(X, Decl(f1.d.ts, 4, 14))
2134
}
2235

2336
=== tests/cases/compiler/main.ts ===
2437

2538
Symbol.observable;
26-
>Symbol.observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 4, 33))
39+
>Symbol.observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 7, 33))
2740
>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --))
28-
>observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 4, 33))
41+
>observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 7, 33))
2942

3043
new Cls().x
31-
>new Cls().x : Symbol(Cls.x, Decl(f1.d.ts, 7, 15))
32-
>Cls : Symbol(Cls, Decl(f1.d.ts, 6, 5))
33-
>x : Symbol(Cls.x, Decl(f1.d.ts, 7, 15))
44+
>new Cls().x : Symbol(Cls.x, Decl(f1.d.ts, 10, 15))
45+
>Cls : Symbol(Cls, Decl(f1.d.ts, 9, 5))
46+
>x : Symbol(Cls.x, Decl(f1.d.ts, 10, 15))
47+
48+
let c = a + b + X;
49+
>c : Symbol(c, Decl(main.ts, 3, 3))
50+
>a : Symbol(a, Decl(f1.d.ts, 11, 9))
51+
>b : Symbol(b, Decl(f1.d.ts, 11, 11))
52+
>X : Symbol(X, Decl(f1.d.ts, 11, 25))
3453

tests/baselines/reference/newNamesInGlobalAugmentations1.types

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
export {};
44

5+
declare module M.M1 {
6+
>M : typeof M
7+
>M1 : typeof M1
8+
9+
export let x: number;
10+
>x : number
11+
}
512
declare global {
613
>global : any
714

@@ -18,6 +25,12 @@ declare global {
1825
let [a, b]: number[];
1926
>a : number
2027
>b : number
28+
29+
import X = M.M1.x;
30+
>X : number
31+
>M : typeof M
32+
>M1 : typeof M.M1
33+
>x : number
2134
}
2235

2336
=== tests/cases/compiler/main.ts ===
@@ -33,3 +46,11 @@ new Cls().x
3346
>Cls : typeof Cls
3447
>x : any
3548

49+
let c = a + b + X;
50+
>c : number
51+
>a + b + X : number
52+
>a + b : number
53+
>a : number
54+
>b : number
55+
>X : number
56+

tests/cases/compiler/newNamesInGlobalAugmentations1.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
// @filename: f1.d.ts
44
export {};
55

6+
declare module M.M1 {
7+
export let x: number;
8+
}
69
declare global {
710
interface SymbolConstructor {
811
observable: symbol;
912
}
1013
class Cls {x}
1114
let [a, b]: number[];
15+
import X = M.M1.x;
1216
}
1317

1418
// @filename: main.ts
1519

1620
Symbol.observable;
17-
new Cls().x
21+
new Cls().x
22+
let c = a + b + X;

0 commit comments

Comments
 (0)