Skip to content

do not validate module names in augmentations defined in ambient context #8200

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

Merged
merged 1 commit into from
Apr 20, 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
6 changes: 5 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ namespace ts {
}
else {
// find a module that about to be augmented
let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found);
// do not validate names of augmentations that are defined in ambient context
const moduleNotFoundError = !isInAmbientContext(moduleName.parent.parent)
? Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found
: undefined;
let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError);
if (!mainModule) {
return;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/baselines/reference/moduleAugmentationInDependency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/moduleAugmentationInDependency.ts] ////

//// [index.d.ts]
declare module "ext" {
}
export {};

//// [app.ts]
import "A"

//// [app.js]
"use strict";
require("A");
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== /node_modules/A/index.d.ts ===
declare module "ext" {
No type information for this code.}
No type information for this code.export {};
No type information for this code.
No type information for this code.=== /src/app.ts ===
import "A"
No type information for this code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== /node_modules/A/index.d.ts ===
declare module "ext" {
No type information for this code.}
No type information for this code.export {};
No type information for this code.
No type information for this code.=== /src/app.ts ===
import "A"
No type information for this code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/node_modules/A/index.ts(1,16): error TS2664: Invalid module name in augmentation, module 'ext' cannot be found.


==== /node_modules/A/index.ts (1 errors) ====
declare module "ext" {
~~~~~
!!! error TS2664: Invalid module name in augmentation, module 'ext' cannot be found.
}
export {};

==== /src/app.ts (0 errors) ====
import "A"
15 changes: 15 additions & 0 deletions tests/baselines/reference/moduleAugmentationInDependency2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/compiler/moduleAugmentationInDependency2.ts] ////

//// [index.ts]
declare module "ext" {
}
export {};

//// [app.ts]
import "A"

//// [index.js]
"use strict";
//// [app.js]
"use strict";
require("A");
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(125,45): error TS1147: Impor
tests/cases/compiler/privacyGloImportParseErrors.ts(133,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
tests/cases/compiler/privacyGloImportParseErrors.ts(133,24): error TS2435: Ambient modules cannot be nested in other modules or namespaces.
tests/cases/compiler/privacyGloImportParseErrors.ts(138,16): error TS2435: Ambient modules cannot be nested in other modules or namespaces.
tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2664: Invalid module name in augmentation, module 'abc3' cannot be found.
tests/cases/compiler/privacyGloImportParseErrors.ts(146,25): error TS1147: Import declarations in a namespace cannot reference a module.
tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Import declarations in a namespace cannot reference a module.


==== tests/cases/compiler/privacyGloImportParseErrors.ts (19 errors) ====
==== tests/cases/compiler/privacyGloImportParseErrors.ts (18 errors) ====
module m1 {
export module m1_M1_public {
export class c1 {
Expand Down Expand Up @@ -193,8 +192,6 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Impor
}
}
module "abc3" {
~~~~~~
!!! error TS2664: Invalid module name in augmentation, module 'abc3' cannot be found.
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/cases/compiler/moduleAugmentationInDependency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @filename: /node_modules/A/index.d.ts
declare module "ext" {
}
export {};

// @filename: /src/app.ts
import "A"
7 changes: 7 additions & 0 deletions tests/cases/compiler/moduleAugmentationInDependency2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @filename: /node_modules/A/index.ts
declare module "ext" {
}
export {};

// @filename: /src/app.ts
import "A"