fix(47076):Fix error term of declaration in modules (#47087)

* Fix error term of declaration in modules

* fix test

* change error code of "An import declaration can only be used at the top level of a module."

* Separate js and ts files for export errors in module.

* Change non-top-level error in namespace

* format

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
islandryu
2022-02-10 06:19:30 +09:00
committed by GitHub
parent 2d0a00d457
commit 95c22d1750
14 changed files with 135 additions and 98 deletions

View File

@@ -39683,7 +39683,7 @@ namespace ts {
const isAmbientExternalModule: boolean = isAmbientModule(node);
const contextErrorMessage = isAmbientExternalModule
? Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
: Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module;
: Diagnostics.A_namespace_declaration_is_only_allowed_at_the_top_level_of_a_namespace_or_module;
if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
// If we hit a module declaration in an illegal context, just bail out to avoid cascading errors.
return;
@@ -40021,7 +40021,7 @@ namespace ts {
}
function checkImportDeclaration(node: ImportDeclaration) {
if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
if (checkGrammarModuleElementContext(node, isInJSFile(node) ? Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module : Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)) {
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
return;
}
@@ -40055,7 +40055,7 @@ namespace ts {
}
function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) {
if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
if (checkGrammarModuleElementContext(node, isInJSFile(node) ? Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module : Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)) {
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
return;
}
@@ -40094,7 +40094,7 @@ namespace ts {
}
function checkExportDeclaration(node: ExportDeclaration) {
if (checkGrammarModuleElementContext(node, Diagnostics.An_export_declaration_can_only_be_used_in_a_module)) {
if (checkGrammarModuleElementContext(node, isInJSFile(node) ? Diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_module : Diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)) {
// If we hit an export in an illegal context, just bail out to avoid cascading errors.
return;
}

View File

@@ -727,11 +727,11 @@
"category": "Error",
"code": 1231
},
"An import declaration can only be used in a namespace or module.": {
"An import declaration can only be used at the top level of a namespace or module.": {
"category": "Error",
"code": 1232
},
"An export declaration can only be used in a module.": {
"An export declaration can only be used at the top level of a namespace or module.": {
"category": "Error",
"code": 1233
},
@@ -739,7 +739,7 @@
"category": "Error",
"code": 1234
},
"A namespace declaration is only allowed in a namespace or module.": {
"A namespace declaration is only allowed at the top level of a namespace or module.": {
"category": "Error",
"code": 1235
},
@@ -1413,7 +1413,15 @@
"category": "Error",
"code": 1472
},
"An import declaration can only be used at the top level of a module.": {
"category": "Error",
"code": 1473
},
"An export declaration can only be used at the top level of a module.": {
"category": "Error",
"code": 1474
},
"The types of '{0}' are incompatible between these types.": {
"category": "Error",
"code": 2200

View File

@@ -861,9 +861,9 @@ namespace ts {
Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code,
Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code,
Diagnostics.An_export_declaration_can_only_be_used_in_a_module.code,
Diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_module.code,
Diagnostics.An_export_declaration_cannot_have_modifiers.code,
Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module.code,
Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module.code,
Diagnostics.An_import_declaration_cannot_have_modifiers.code,
Diagnostics.An_object_member_cannot_be_declared_optional.code,
Diagnostics.Argument_of_dynamic_import_cannot_be_spread_element.code,