Skip to content

Commit 1ac2539

Browse files
committed
Merge pull request #8200 from Microsoft/no-errors-on-augmentations-in-ambient-context
do not validate module names in augmentations defined in ambient context
2 parents 24f535e + 950571b commit 1ac2539

9 files changed

+76
-5
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ namespace ts {
398398
}
399399
else {
400400
// find a module that about to be augmented
401-
let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found);
401+
// do not validate names of augmentations that are defined in ambient context
402+
const moduleNotFoundError = !isInAmbientContext(moduleName.parent.parent)
403+
? Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found
404+
: undefined;
405+
let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError);
402406
if (!mainModule) {
403407
return;
404408
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/compiler/moduleAugmentationInDependency.ts] ////
2+
3+
//// [index.d.ts]
4+
declare module "ext" {
5+
}
6+
export {};
7+
8+
//// [app.ts]
9+
import "A"
10+
11+
//// [app.js]
12+
"use strict";
13+
require("A");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== /node_modules/A/index.d.ts ===
2+
declare module "ext" {
3+
No type information for this code.}
4+
No type information for this code.export {};
5+
No type information for this code.
6+
No type information for this code.=== /src/app.ts ===
7+
import "A"
8+
No type information for this code.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== /node_modules/A/index.d.ts ===
2+
declare module "ext" {
3+
No type information for this code.}
4+
No type information for this code.export {};
5+
No type information for this code.
6+
No type information for this code.=== /src/app.ts ===
7+
import "A"
8+
No type information for this code.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/node_modules/A/index.ts(1,16): error TS2664: Invalid module name in augmentation, module 'ext' cannot be found.
2+
3+
4+
==== /node_modules/A/index.ts (1 errors) ====
5+
declare module "ext" {
6+
~~~~~
7+
!!! error TS2664: Invalid module name in augmentation, module 'ext' cannot be found.
8+
}
9+
export {};
10+
11+
==== /src/app.ts (0 errors) ====
12+
import "A"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [tests/cases/compiler/moduleAugmentationInDependency2.ts] ////
2+
3+
//// [index.ts]
4+
declare module "ext" {
5+
}
6+
export {};
7+
8+
//// [app.ts]
9+
import "A"
10+
11+
//// [index.js]
12+
"use strict";
13+
//// [app.js]
14+
"use strict";
15+
require("A");

tests/baselines/reference/privacyGloImportParseErrors.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(125,45): error TS1147: Impor
1414
tests/cases/compiler/privacyGloImportParseErrors.ts(133,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
1515
tests/cases/compiler/privacyGloImportParseErrors.ts(133,24): error TS2435: Ambient modules cannot be nested in other modules or namespaces.
1616
tests/cases/compiler/privacyGloImportParseErrors.ts(138,16): error TS2435: Ambient modules cannot be nested in other modules or namespaces.
17-
tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2664: Invalid module name in augmentation, module 'abc3' cannot be found.
1817
tests/cases/compiler/privacyGloImportParseErrors.ts(146,25): error TS1147: Import declarations in a namespace cannot reference a module.
1918
tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Import declarations in a namespace cannot reference a module.
2019

2120

22-
==== tests/cases/compiler/privacyGloImportParseErrors.ts (19 errors) ====
21+
==== tests/cases/compiler/privacyGloImportParseErrors.ts (18 errors) ====
2322
module m1 {
2423
export module m1_M1_public {
2524
export class c1 {
@@ -193,8 +192,6 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Impor
193192
}
194193
}
195194
module "abc3" {
196-
~~~~~~
197-
!!! error TS2664: Invalid module name in augmentation, module 'abc3' cannot be found.
198195
}
199196
}
200197

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @filename: /node_modules/A/index.d.ts
2+
declare module "ext" {
3+
}
4+
export {};
5+
6+
// @filename: /src/app.ts
7+
import "A"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @filename: /node_modules/A/index.ts
2+
declare module "ext" {
3+
}
4+
export {};
5+
6+
// @filename: /src/app.ts
7+
import "A"

0 commit comments

Comments
 (0)