Skip to content

Commit e43680d

Browse files
committed
show more clearly error message when found missing module name
Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json
1 parent 78f81ef commit e43680d

24 files changed

+172
-155
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,13 @@ module ts {
803803

804804
let symbol: Symbol;
805805
if (name.kind === SyntaxKind.Identifier) {
806-
symbol = resolveName(name, (<Identifier>name).text, meaning, Diagnostics.Cannot_find_name_0, <Identifier>name);
806+
let message: DiagnosticMessage;
807+
if (meaning === SymbolFlags.Namespace) {
808+
message = Diagnostics.Cannot_find_namespace_0;
809+
} else {
810+
message = Diagnostics.Cannot_find_name_0;
811+
}
812+
symbol = resolveName(name, (<Identifier>name).text, meaning, message, <Identifier>name);
807813
if (!symbol) {
808814
return undefined;
809815
}

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ module ts {
364364
A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2500, category: DiagnosticCategory.Error, key: "A class can only implement an identifier/qualified-name with optional type arguments." },
365365
A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
366366
_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." },
367+
Cannot_find_namespace_0: { code: 2503, category: DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." },
367368
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
368369
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
369370
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,10 @@
14441444
"category": "Error",
14451445
"code": 2502
14461446
},
1447+
"Cannot find namespace '{0}'.": {
1448+
"category": "Error",
1449+
"code": 2503
1450+
},
14471451

14481452
"Import declaration '{0}' is using private name '{1}'.": {
14491453
"category": "Error",

tests/baselines/reference/aliasErrors.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/compiler/aliasErrors.ts(11,12): error TS2304: Cannot find name 'no'.
2-
tests/cases/compiler/aliasErrors.ts(12,13): error TS2304: Cannot find name 'no'.
1+
tests/cases/compiler/aliasErrors.ts(11,12): error TS2503: Cannot find namespace 'no'.
2+
tests/cases/compiler/aliasErrors.ts(12,13): error TS2503: Cannot find namespace 'no'.
33
tests/cases/compiler/aliasErrors.ts(13,12): error TS1003: Identifier expected.
44
tests/cases/compiler/aliasErrors.ts(14,12): error TS1003: Identifier expected.
55
tests/cases/compiler/aliasErrors.ts(15,12): error TS1003: Identifier expected.
6-
tests/cases/compiler/aliasErrors.ts(16,12): error TS2304: Cannot find name 'undefined'.
6+
tests/cases/compiler/aliasErrors.ts(16,12): error TS2503: Cannot find namespace 'undefined'.
77
tests/cases/compiler/aliasErrors.ts(26,15): error TS2305: Module 'foo.bar.baz' has no exported member 'bar'.
88

99

@@ -20,10 +20,10 @@ tests/cases/compiler/aliasErrors.ts(26,15): error TS2305: Module 'foo.bar.baz' h
2020

2121
import m = no;
2222
~~
23-
!!! error TS2304: Cannot find name 'no'.
23+
!!! error TS2503: Cannot find namespace 'no'.
2424
import m2 = no.mod;
2525
~~
26-
!!! error TS2304: Cannot find name 'no'.
26+
!!! error TS2503: Cannot find namespace 'no'.
2727
import n = 5;
2828
~
2929
!!! error TS1003: Identifier expected.
@@ -35,7 +35,7 @@ tests/cases/compiler/aliasErrors.ts(26,15): error TS2305: Module 'foo.bar.baz' h
3535
!!! error TS1003: Identifier expected.
3636
import r = undefined;
3737
~~~~~~~~~
38-
!!! error TS2304: Cannot find name 'undefined'.
38+
!!! error TS2503: Cannot find namespace 'undefined'.
3939

4040

4141
var p = new provide.Provide();

tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2304: Cannot find name 'module'.
2+
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2503: Cannot find namespace 'module'.
23
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(11,19): error TS1005: ';' expected.
34
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,35): error TS1005: ')' expected.
45
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
@@ -82,7 +83,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,55): error T
8283
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS1128: Declaration or statement expected.
8384

8485

85-
==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (82 errors) ====
86+
==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (83 errors) ====
8687
declare module "fs" {
8788
export class File {
8889
constructor(filename: string);
@@ -96,6 +97,8 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
9697
import fs = module("fs");
9798
~~~~~~
9899
!!! error TS2304: Cannot find name 'module'.
100+
~~~~~~
101+
!!! error TS2503: Cannot find namespace 'module'.
99102
~
100103
!!! error TS1005: ';' expected.
101104

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
tests/cases/compiler/declareModifierOnImport1.ts(1,1): error TS1079: A 'declare' modifier cannot be used with an import declaration.
2-
tests/cases/compiler/declareModifierOnImport1.ts(1,20): error TS2304: Cannot find name 'b'.
2+
tests/cases/compiler/declareModifierOnImport1.ts(1,20): error TS2503: Cannot find namespace 'b'.
33

44

55
==== tests/cases/compiler/declareModifierOnImport1.ts (2 errors) ====
66
declare import a = b;
77
~~~~~~~
88
!!! error TS1079: A 'declare' modifier cannot be used with an import declaration.
99
~
10-
!!! error TS2304: Cannot find name 'b'.
10+
!!! error TS2503: Cannot find namespace 'b'.

tests/baselines/reference/importedModuleAddToGlobal.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/importedModuleAddToGlobal.ts(15,23): error TS2304: Cannot find name 'b'.
1+
tests/cases/compiler/importedModuleAddToGlobal.ts(15,23): error TS2503: Cannot find namespace 'b'.
22

33

44
==== tests/cases/compiler/importedModuleAddToGlobal.ts (1 errors) ====
@@ -18,5 +18,5 @@ tests/cases/compiler/importedModuleAddToGlobal.ts(15,23): error TS2304: Cannot f
1818
import a = A;
1919
function hello(): b.B { return null; }
2020
~
21-
!!! error TS2304: Cannot find name 'b'.
21+
!!! error TS2503: Cannot find namespace 'b'.
2222
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(5,12): error TS2304: Cannot find name 'V'.
2-
tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(11,12): error TS2304: Cannot find name 'C'.
3-
tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(17,12): error TS2304: Cannot find name 'E'.
4-
tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2304: Cannot find name 'I'.
1+
tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(5,12): error TS2503: Cannot find namespace 'V'.
2+
tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(11,12): error TS2503: Cannot find namespace 'C'.
3+
tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(17,12): error TS2503: Cannot find namespace 'E'.
4+
tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2503: Cannot find namespace 'I'.
55

66

77
==== tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts (4 errors) ====
@@ -11,29 +11,29 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIde
1111

1212
import v = V;
1313
~
14-
!!! error TS2304: Cannot find name 'V'.
14+
!!! error TS2503: Cannot find namespace 'V'.
1515

1616
class C {
1717
name: string;
1818
}
1919

2020
import c = C;
2121
~
22-
!!! error TS2304: Cannot find name 'C'.
22+
!!! error TS2503: Cannot find namespace 'C'.
2323

2424
enum E {
2525
Red, Blue
2626
}
2727

2828
import e = E;
2929
~
30-
!!! error TS2304: Cannot find name 'E'.
30+
!!! error TS2503: Cannot find namespace 'E'.
3131

3232
interface I {
3333
id: number;
3434
}
3535

3636
import i = I;
3737
~
38-
!!! error TS2304: Cannot find name 'I'.
38+
!!! error TS2503: Cannot find namespace 'I'.
3939

tests/baselines/reference/invalidInstantiatedModule.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(2,18): error TS2300: Duplicate identifier 'Point'.
22
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(3,16): error TS2300: Duplicate identifier 'Point'.
3-
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(12,8): error TS2304: Cannot find name 'm'.
3+
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(12,8): error TS2503: Cannot find namespace 'm'.
44

55

66
==== tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts (3 errors) ====
@@ -21,7 +21,7 @@ tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedMo
2121
var m = M2;
2222
var p: m.Point; // Error
2323
~
24-
!!! error TS2304: Cannot find name 'm'.
24+
!!! error TS2503: Cannot find namespace 'm'.
2525

2626

2727

tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body.
22
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(2,18): error TS2304: Cannot find name 'Role'.
3-
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2304: Cannot find name 'ng'.
3+
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2503: Cannot find namespace 'ng'.
44

55

66
==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (3 errors) ====
@@ -13,5 +13,5 @@ tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): er
1313
this.roleService.add(role)
1414
.then((data: ng.IHttpPromiseCallbackArg<Role>) => data.data));
1515
~~
16-
!!! error TS2304: Cannot find name 'ng'.
16+
!!! error TS2503: Cannot find namespace 'ng'.
1717

0 commit comments

Comments
 (0)