Skip to content

Commit

Permalink
Merge pull request #2923 from Microsoft/namespaces
Browse files Browse the repository at this point in the history
Namespaces
  • Loading branch information
ahejlsberg committed Apr 29, 2015
2 parents cde3ed0 + 4db61d8 commit 4016206
Show file tree
Hide file tree
Showing 199 changed files with 1,052 additions and 1,045 deletions.
32 changes: 16 additions & 16 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ module ts {
if (moduleSymbol) {
let exportDefaultSymbol = resolveSymbol(moduleSymbol.exports["default"]);
if (!exportDefaultSymbol) {
error(node.name, Diagnostics.External_module_0_has_no_default_export, symbolToString(moduleSymbol));
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
}
return exportDefaultSymbol;
}
Expand Down Expand Up @@ -870,10 +870,10 @@ module ts {
if (sourceFile.symbol) {
return sourceFile.symbol;
}
error(moduleReferenceLiteral, Diagnostics.File_0_is_not_an_external_module, sourceFile.fileName);
error(moduleReferenceLiteral, Diagnostics.File_0_is_not_a_module, sourceFile.fileName);
return;
}
error(moduleReferenceLiteral, Diagnostics.Cannot_find_external_module_0, moduleName);
error(moduleReferenceLiteral, Diagnostics.Cannot_find_module_0, moduleName);
}

// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
Expand All @@ -888,7 +888,7 @@ module ts {
function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression): Symbol {
let symbol = resolveExternalModuleSymbol(moduleSymbol);
if (symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
error(moduleReferenceExpression, Diagnostics.External_module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
symbol = undefined;
}
return symbol;
Expand Down Expand Up @@ -5508,7 +5508,7 @@ module ts {

switch (container.kind) {
case SyntaxKind.ModuleDeclaration:
error(node, Diagnostics.this_cannot_be_referenced_in_a_module_body);
error(node, Diagnostics.this_cannot_be_referenced_in_a_module_or_namespace_body);
// do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks
break;
case SyntaxKind.EnumDeclaration:
Expand Down Expand Up @@ -9079,7 +9079,7 @@ module ts {
let parent = getDeclarationContainer(node);
if (parent.kind === SyntaxKind.SourceFile && isExternalModule(<SourceFile>parent)) {
// If the declaration happens to be in external module, report error that require and exports are reserved keywords
error(name, Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module,
error(name, Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module,
declarationNameToString(name), declarationNameToString(name));
}
}
Expand Down Expand Up @@ -10494,10 +10494,10 @@ module ts {
let firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
if (firstNonAmbientClassOrFunc) {
if (getSourceFileOfNode(node) !== getSourceFileOfNode(firstNonAmbientClassOrFunc)) {
error(node.name, Diagnostics.A_module_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged);
error(node.name, Diagnostics.A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged);
}
else if (node.pos < firstNonAmbientClassOrFunc.pos) {
error(node.name, Diagnostics.A_module_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged);
error(node.name, Diagnostics.A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged);
}
}

Expand All @@ -10513,10 +10513,10 @@ module ts {
// Checks for ambient external modules.
if (node.name.kind === SyntaxKind.StringLiteral) {
if (!isGlobalSourceFile(node.parent)) {
error(node.name, Diagnostics.Ambient_external_modules_cannot_be_nested_in_other_modules);
error(node.name, Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules);
}
if (isExternalModuleNameRelative(node.name.text)) {
error(node.name, Diagnostics.Ambient_external_module_declaration_cannot_specify_relative_module_name);
error(node.name, Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name);
}
}
}
Expand Down Expand Up @@ -10548,16 +10548,16 @@ module ts {
let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (<ModuleDeclaration>node.parent.parent).name.kind === SyntaxKind.StringLiteral;
if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) {
error(moduleName, node.kind === SyntaxKind.ExportDeclaration ?
Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module :
Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module);
Diagnostics.Export_declarations_are_not_permitted_in_a_namespace :
Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module);
return false;
}
if (inAmbientExternalModule && isExternalModuleNameRelative((<LiteralExpression>moduleName).text)) {
// TypeScript 1.0 spec (April 2013): 12.1.6
// An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference
// other external modules only through top - level external module names.
// Relative external module names are not permitted.
error(node, Diagnostics.Import_or_export_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name);
error(node, Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name);
return false;
}
return true;
Expand Down Expand Up @@ -10651,14 +10651,14 @@ module ts {

let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (<ModuleDeclaration>node.parent.parent).name.kind === SyntaxKind.StringLiteral;
if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) {
error(node, Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module);
error(node, Diagnostics.Export_declarations_are_not_permitted_in_a_namespace);
}
}
else {
// export * from "foo"
let moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
if (moduleSymbol && moduleSymbol.exports["export="]) {
error(node.moduleSpecifier, Diagnostics.External_module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
error(node.moduleSpecifier, Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
}
}
}
Expand All @@ -10674,7 +10674,7 @@ module ts {
function checkExportAssignment(node: ExportAssignment) {
let container = node.parent.kind === SyntaxKind.SourceFile ? <SourceFile>node.parent : <ModuleDeclaration>node.parent.parent;
if (container.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>container).name.kind === SyntaxKind.Identifier) {
error(node, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module);
error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
return;
}
// Grammar checking
Expand Down
Loading

0 comments on commit 4016206

Please sign in to comment.