Skip to content

Commit 19a985e

Browse files
authored
Dont consider global augmentation top-level members as having the export modifier (microsoft#23846)
* Dont consider global argumentation top-level members as having the export modifier * Remove unneeded test parts from repro
1 parent b467cd8 commit 19a985e

5 files changed

Lines changed: 82 additions & 1 deletion

File tree

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21319,7 +21319,7 @@ namespace ts {
2131921319
n.parent.kind !== SyntaxKind.ClassDeclaration &&
2132021320
n.parent.kind !== SyntaxKind.ClassExpression &&
2132121321
n.flags & NodeFlags.Ambient) {
21322-
if (!(flags & ModifierFlags.Ambient)) {
21322+
if (!(flags & ModifierFlags.Ambient) && !(isModuleBlock(n.parent) && isModuleDeclaration(n.parent.parent) && isGlobalScopeAugmentation(n.parent.parent))) {
2132321323
// It is nested in an ambient context, which means it is automatically exported
2132421324
flags |= ModifierFlags.Export;
2132521325
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/globalFunctionAugmentationOverload.ts] ////
2+
3+
//// [mod.d.ts]
4+
declare function expect(spy: Function): void;
5+
declare module "mod" {
6+
class mod {}
7+
export = mod;
8+
}
9+
//// [mine.ts]
10+
import "mod";
11+
12+
declare global {
13+
function expect(element: string): void;
14+
}
15+
16+
//// [mine.js]
17+
"use strict";
18+
exports.__esModule = true;
19+
require("mod");
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/compiler/mod.d.ts ===
2+
declare function expect(spy: Function): void;
3+
>expect : Symbol(expect, Decl(mod.d.ts, 0, 0), Decl(mine.ts, 2, 16))
4+
>spy : Symbol(spy, Decl(mod.d.ts, 0, 24))
5+
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
6+
7+
declare module "mod" {
8+
>"mod" : Symbol("mod", Decl(mod.d.ts, 0, 45))
9+
10+
class mod {}
11+
>mod : Symbol(mod, Decl(mod.d.ts, 1, 22))
12+
13+
export = mod;
14+
>mod : Symbol(mod, Decl(mod.d.ts, 1, 22))
15+
}
16+
=== tests/cases/compiler/mine.ts ===
17+
import "mod";
18+
19+
declare global {
20+
>global : Symbol(global, Decl(mine.ts, 0, 13))
21+
22+
function expect(element: string): void;
23+
>expect : Symbol(expect, Decl(mod.d.ts, 0, 0), Decl(mine.ts, 2, 16))
24+
>element : Symbol(element, Decl(mine.ts, 3, 20))
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/compiler/mod.d.ts ===
2+
declare function expect(spy: Function): void;
3+
>expect : { (spy: Function): void; (element: string): void; }
4+
>spy : Function
5+
>Function : Function
6+
7+
declare module "mod" {
8+
>"mod" : typeof import("mod")
9+
10+
class mod {}
11+
>mod : mod
12+
13+
export = mod;
14+
>mod : mod
15+
}
16+
=== tests/cases/compiler/mine.ts ===
17+
import "mod";
18+
19+
declare global {
20+
>global : typeof global
21+
22+
function expect(element: string): void;
23+
>expect : { (spy: Function): void; (element: string): void; }
24+
>element : string
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @filename: mod.d.ts
2+
declare function expect(spy: Function): void;
3+
declare module "mod" {
4+
class mod {}
5+
export = mod;
6+
}
7+
// @filename: mine.ts
8+
import "mod";
9+
10+
declare global {
11+
function expect(element: string): void;
12+
}

0 commit comments

Comments
 (0)