diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e218766a708e3..30a09a98434d2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39655,7 +39655,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; @@ -39993,7 +39993,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; } @@ -40027,7 +40027,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; } @@ -40066,7 +40066,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; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 34685f0ef7b28..a51336a4829dc 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 7017f138224e9..f6cacfe719881 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -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, diff --git a/tests/baselines/reference/importDeclarationInModuleDeclaration2.errors.txt b/tests/baselines/reference/importDeclarationInModuleDeclaration2.errors.txt new file mode 100644 index 0000000000000..2541c20897fa5 --- /dev/null +++ b/tests/baselines/reference/importDeclarationInModuleDeclaration2.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/check.js(2,5): error TS1473: An import declaration can only be used at the top level of a module. + + +==== tests/cases/compiler/check.js (1 errors) ==== + function container() { + import "fs"; + ~~~~~~ +!!! error TS1473: An import declaration can only be used at the top level of a module. + } \ No newline at end of file diff --git a/tests/baselines/reference/importDeclarationInModuleDeclaration2.symbols b/tests/baselines/reference/importDeclarationInModuleDeclaration2.symbols new file mode 100644 index 0000000000000..ae8fbc1291a0c --- /dev/null +++ b/tests/baselines/reference/importDeclarationInModuleDeclaration2.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/check.js === +function container() { +>container : Symbol(container, Decl(check.js, 0, 0)) + + import "fs"; +} diff --git a/tests/baselines/reference/importDeclarationInModuleDeclaration2.types b/tests/baselines/reference/importDeclarationInModuleDeclaration2.types new file mode 100644 index 0000000000000..a100c277dca5e --- /dev/null +++ b/tests/baselines/reference/importDeclarationInModuleDeclaration2.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/check.js === +function container() { +>container : () => void + + import "fs"; +} diff --git a/tests/baselines/reference/labeledStatementWithLabel.errors.txt b/tests/baselines/reference/labeledStatementWithLabel.errors.txt index c7259e484eaaa..64dd004249f81 100644 --- a/tests/baselines/reference/labeledStatementWithLabel.errors.txt +++ b/tests/baselines/reference/labeledStatementWithLabel.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.ts(11,8): error TS1235: A namespace declaration is only allowed in a namespace or module. -tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.ts(12,8): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.ts(11,8): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.ts(12,8): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. ==== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.ts (2 errors) ==== @@ -15,9 +15,9 @@ tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.t label: module M { } ~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. label: namespace N {} ~~~~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. label: type T = {} \ No newline at end of file diff --git a/tests/baselines/reference/labeledStatementWithLabel_es2015.errors.txt b/tests/baselines/reference/labeledStatementWithLabel_es2015.errors.txt index 95c136b953de6..c2945254121ed 100644 --- a/tests/baselines/reference/labeledStatementWithLabel_es2015.errors.txt +++ b/tests/baselines/reference/labeledStatementWithLabel_es2015.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_es2015.ts(11,8): error TS1235: A namespace declaration is only allowed in a namespace or module. -tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_es2015.ts(12,8): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_es2015.ts(11,8): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_es2015.ts(12,8): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. ==== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_es2015.ts (2 errors) ==== @@ -15,9 +15,9 @@ tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_e label: module M { } ~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. label: namespace N {} ~~~~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. label: type T = {} \ No newline at end of file diff --git a/tests/baselines/reference/labeledStatementWithLabel_strict.errors.txt b/tests/baselines/reference/labeledStatementWithLabel_strict.errors.txt index 863604a083680..01f09aeab4df1 100644 --- a/tests/baselines/reference/labeledStatementWithLabel_strict.errors.txt +++ b/tests/baselines/reference/labeledStatementWithLabel_strict.errors.txt @@ -8,9 +8,9 @@ tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_s tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(9,1): error TS1344: 'A label is not allowed here. tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(10,1): error TS1344: 'A label is not allowed here. tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(12,1): error TS1344: 'A label is not allowed here. -tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(12,8): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(12,8): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(13,1): error TS1344: 'A label is not allowed here. -tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(13,8): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(13,8): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(14,1): error TS1344: 'A label is not allowed here. @@ -48,12 +48,12 @@ tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_s ~~~~~ !!! error TS1344: 'A label is not allowed here. ~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. label: namespace N {} ~~~~~ !!! error TS1344: 'A label is not allowed here. ~~~~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. label: type T = {} ~~~~~ !!! error TS1344: 'A label is not allowed here. diff --git a/tests/baselines/reference/moduleElementsInWrongContext.errors.txt b/tests/baselines/reference/moduleElementsInWrongContext.errors.txt index 146a6dcd951df..4226266e82992 100644 --- a/tests/baselines/reference/moduleElementsInWrongContext.errors.txt +++ b/tests/baselines/reference/moduleElementsInWrongContext.errors.txt @@ -1,36 +1,36 @@ -tests/cases/compiler/moduleElementsInWrongContext.ts(2,5): error TS1235: A namespace declaration is only allowed in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext.ts(3,5): error TS1235: A namespace declaration is only allowed in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext.ts(7,5): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(2,5): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(3,5): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(7,5): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. tests/cases/compiler/moduleElementsInWrongContext.ts(9,5): error TS1234: An ambient module declaration is only allowed at the top level in a file. tests/cases/compiler/moduleElementsInWrongContext.ts(13,5): error TS1231: An export assignment must be at the top level of a file or module declaration. -tests/cases/compiler/moduleElementsInWrongContext.ts(17,5): error TS1233: An export declaration can only be used in a module. -tests/cases/compiler/moduleElementsInWrongContext.ts(18,5): error TS1233: An export declaration can only be used in a module. -tests/cases/compiler/moduleElementsInWrongContext.ts(19,5): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext.ts(17,5): error TS1233: An export declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(18,5): error TS1233: An export declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(19,5): error TS1233: An export declaration can only be used at the top level of a namespace or module. tests/cases/compiler/moduleElementsInWrongContext.ts(20,5): error TS1258: A default export must be at the top level of a file or module declaration. tests/cases/compiler/moduleElementsInWrongContext.ts(21,5): error TS1184: Modifiers cannot appear here. tests/cases/compiler/moduleElementsInWrongContext.ts(22,5): error TS1184: Modifiers cannot appear here. -tests/cases/compiler/moduleElementsInWrongContext.ts(23,5): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext.ts(24,5): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext.ts(25,5): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext.ts(26,5): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext.ts(27,5): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext.ts(28,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(23,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(24,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(25,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(26,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(27,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext.ts(28,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. ==== tests/cases/compiler/moduleElementsInWrongContext.ts (17 errors) ==== { module M { } ~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. export namespace N { ~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. export interface I { } } namespace Q.K { } ~~~~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. declare module "ambient" { ~~~~~~~ @@ -46,13 +46,13 @@ tests/cases/compiler/moduleElementsInWrongContext.ts(28,5): error TS1232: An imp function foo() { } export * from "ambient"; ~~~~~~ -!!! error TS1233: An export declaration can only be used in a module. +!!! error TS1233: An export declaration can only be used at the top level of a namespace or module. export { foo }; ~~~~~~ -!!! error TS1233: An export declaration can only be used in a module. +!!! error TS1233: An export declaration can only be used at the top level of a namespace or module. export { baz as b } from "ambient"; ~~~~~~ -!!! error TS1233: An export declaration can only be used in a module. +!!! error TS1233: An export declaration can only be used at the top level of a namespace or module. export default v; ~~~~~~ !!! error TS1258: A default export must be at the top level of a file or module declaration. @@ -64,21 +64,21 @@ tests/cases/compiler/moduleElementsInWrongContext.ts(28,5): error TS1232: An imp !!! error TS1184: Modifiers cannot appear here. import I = M; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import I2 = require("foo"); ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import * as Foo from "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import bar from "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import { baz } from "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. } \ No newline at end of file diff --git a/tests/baselines/reference/moduleElementsInWrongContext2.errors.txt b/tests/baselines/reference/moduleElementsInWrongContext2.errors.txt index f858bf9923e2b..22fa234747db1 100644 --- a/tests/baselines/reference/moduleElementsInWrongContext2.errors.txt +++ b/tests/baselines/reference/moduleElementsInWrongContext2.errors.txt @@ -1,36 +1,36 @@ -tests/cases/compiler/moduleElementsInWrongContext2.ts(2,5): error TS1235: A namespace declaration is only allowed in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext2.ts(3,5): error TS1235: A namespace declaration is only allowed in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext2.ts(7,5): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(2,5): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(3,5): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(7,5): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. tests/cases/compiler/moduleElementsInWrongContext2.ts(9,5): error TS1234: An ambient module declaration is only allowed at the top level in a file. tests/cases/compiler/moduleElementsInWrongContext2.ts(13,5): error TS1231: An export assignment must be at the top level of a file or module declaration. -tests/cases/compiler/moduleElementsInWrongContext2.ts(17,5): error TS1233: An export declaration can only be used in a module. -tests/cases/compiler/moduleElementsInWrongContext2.ts(18,5): error TS1233: An export declaration can only be used in a module. -tests/cases/compiler/moduleElementsInWrongContext2.ts(19,5): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(17,5): error TS1233: An export declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(18,5): error TS1233: An export declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(19,5): error TS1233: An export declaration can only be used at the top level of a namespace or module. tests/cases/compiler/moduleElementsInWrongContext2.ts(20,5): error TS1258: A default export must be at the top level of a file or module declaration. tests/cases/compiler/moduleElementsInWrongContext2.ts(21,5): error TS1184: Modifiers cannot appear here. tests/cases/compiler/moduleElementsInWrongContext2.ts(22,5): error TS1184: Modifiers cannot appear here. -tests/cases/compiler/moduleElementsInWrongContext2.ts(23,5): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext2.ts(24,5): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext2.ts(25,5): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext2.ts(26,5): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext2.ts(27,5): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext2.ts(28,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(23,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(24,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(25,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(26,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(27,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext2.ts(28,5): error TS1232: An import declaration can only be used at the top level of a namespace or module. ==== tests/cases/compiler/moduleElementsInWrongContext2.ts (17 errors) ==== function blah () { module M { } ~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. export namespace N { ~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. export interface I { } } namespace Q.K { } ~~~~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. declare module "ambient" { ~~~~~~~ @@ -46,13 +46,13 @@ tests/cases/compiler/moduleElementsInWrongContext2.ts(28,5): error TS1232: An im function foo() { } export * from "ambient"; ~~~~~~ -!!! error TS1233: An export declaration can only be used in a module. +!!! error TS1233: An export declaration can only be used at the top level of a namespace or module. export { foo }; ~~~~~~ -!!! error TS1233: An export declaration can only be used in a module. +!!! error TS1233: An export declaration can only be used at the top level of a namespace or module. export { baz as b } from "ambient"; ~~~~~~ -!!! error TS1233: An export declaration can only be used in a module. +!!! error TS1233: An export declaration can only be used at the top level of a namespace or module. export default v; ~~~~~~ !!! error TS1258: A default export must be at the top level of a file or module declaration. @@ -64,21 +64,21 @@ tests/cases/compiler/moduleElementsInWrongContext2.ts(28,5): error TS1232: An im !!! error TS1184: Modifiers cannot appear here. import I = M; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import I2 = require("foo"); ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import * as Foo from "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import bar from "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import { baz } from "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. } \ No newline at end of file diff --git a/tests/baselines/reference/moduleElementsInWrongContext3.errors.txt b/tests/baselines/reference/moduleElementsInWrongContext3.errors.txt index df78fa08741f1..55d9ec47c03bf 100644 --- a/tests/baselines/reference/moduleElementsInWrongContext3.errors.txt +++ b/tests/baselines/reference/moduleElementsInWrongContext3.errors.txt @@ -1,20 +1,20 @@ -tests/cases/compiler/moduleElementsInWrongContext3.ts(3,9): error TS1235: A namespace declaration is only allowed in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext3.ts(4,9): error TS1235: A namespace declaration is only allowed in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext3.ts(8,9): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(3,9): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(4,9): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(8,9): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. tests/cases/compiler/moduleElementsInWrongContext3.ts(10,9): error TS1234: An ambient module declaration is only allowed at the top level in a file. tests/cases/compiler/moduleElementsInWrongContext3.ts(14,9): error TS1231: An export assignment must be at the top level of a file or module declaration. -tests/cases/compiler/moduleElementsInWrongContext3.ts(18,9): error TS1233: An export declaration can only be used in a module. -tests/cases/compiler/moduleElementsInWrongContext3.ts(19,9): error TS1233: An export declaration can only be used in a module. -tests/cases/compiler/moduleElementsInWrongContext3.ts(20,9): error TS1233: An export declaration can only be used in a module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(18,9): error TS1233: An export declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(19,9): error TS1233: An export declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(20,9): error TS1233: An export declaration can only be used at the top level of a namespace or module. tests/cases/compiler/moduleElementsInWrongContext3.ts(21,9): error TS1258: A default export must be at the top level of a file or module declaration. tests/cases/compiler/moduleElementsInWrongContext3.ts(22,9): error TS1184: Modifiers cannot appear here. tests/cases/compiler/moduleElementsInWrongContext3.ts(23,9): error TS1184: Modifiers cannot appear here. -tests/cases/compiler/moduleElementsInWrongContext3.ts(24,9): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext3.ts(25,9): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext3.ts(26,9): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext3.ts(27,9): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext3.ts(28,9): error TS1232: An import declaration can only be used in a namespace or module. -tests/cases/compiler/moduleElementsInWrongContext3.ts(29,9): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(24,9): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(25,9): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(26,9): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(27,9): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(28,9): error TS1232: An import declaration can only be used at the top level of a namespace or module. +tests/cases/compiler/moduleElementsInWrongContext3.ts(29,9): error TS1232: An import declaration can only be used at the top level of a namespace or module. ==== tests/cases/compiler/moduleElementsInWrongContext3.ts (17 errors) ==== @@ -22,16 +22,16 @@ tests/cases/compiler/moduleElementsInWrongContext3.ts(29,9): error TS1232: An im { module M { } ~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. export namespace N { ~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. export interface I { } } namespace Q.K { } ~~~~~~~~~ -!!! error TS1235: A namespace declaration is only allowed in a namespace or module. +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. declare module "ambient" { ~~~~~~~ @@ -47,13 +47,13 @@ tests/cases/compiler/moduleElementsInWrongContext3.ts(29,9): error TS1232: An im function foo() { } export * from "ambient"; ~~~~~~ -!!! error TS1233: An export declaration can only be used in a module. +!!! error TS1233: An export declaration can only be used at the top level of a namespace or module. export { foo }; ~~~~~~ -!!! error TS1233: An export declaration can only be used in a module. +!!! error TS1233: An export declaration can only be used at the top level of a namespace or module. export { baz as b } from "ambient"; ~~~~~~ -!!! error TS1233: An export declaration can only be used in a module. +!!! error TS1233: An export declaration can only be used at the top level of a namespace or module. export default v; ~~~~~~ !!! error TS1258: A default export must be at the top level of a file or module declaration. @@ -65,21 +65,21 @@ tests/cases/compiler/moduleElementsInWrongContext3.ts(29,9): error TS1232: An im !!! error TS1184: Modifiers cannot appear here. import I = M; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import I2 = require("foo"); ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import * as Foo from "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import bar from "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import { baz } from "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. import "ambient"; ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1232: An import declaration can only be used at the top level of a namespace or module. } } \ No newline at end of file diff --git a/tests/baselines/reference/plainJSGrammarErrors.errors.txt b/tests/baselines/reference/plainJSGrammarErrors.errors.txt index fa3affdb840ed..c49f7618bf424 100644 --- a/tests/baselines/reference/plainJSGrammarErrors.errors.txt +++ b/tests/baselines/reference/plainJSGrammarErrors.errors.txt @@ -44,8 +44,8 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(65,1): error TS1042: 'asyn tests/cases/conformance/salsa/plainJSGrammarErrors.js(66,1): error TS1042: 'async' modifier cannot be used here. tests/cases/conformance/salsa/plainJSGrammarErrors.js(67,1): error TS1191: An import declaration cannot have modifiers. tests/cases/conformance/salsa/plainJSGrammarErrors.js(68,1): error TS1193: An export declaration cannot have modifiers. -tests/cases/conformance/salsa/plainJSGrammarErrors.js(70,5): error TS1233: An export declaration can only be used in a module. -tests/cases/conformance/salsa/plainJSGrammarErrors.js(71,5): error TS1232: An import declaration can only be used in a namespace or module. +tests/cases/conformance/salsa/plainJSGrammarErrors.js(70,5): error TS1474: An export declaration can only be used at the top level of a module. +tests/cases/conformance/salsa/plainJSGrammarErrors.js(71,5): error TS1473: An import declaration can only be used at the top level of a module. tests/cases/conformance/salsa/plainJSGrammarErrors.js(72,5): error TS1258: A default export must be at the top level of a file or module declaration. tests/cases/conformance/salsa/plainJSGrammarErrors.js(75,5): error TS1184: Modifiers cannot appear here. tests/cases/conformance/salsa/plainJSGrammarErrors.js(78,5): error TS1042: 'static' modifier cannot be used here. @@ -267,10 +267,10 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(207,1): error TS1108: A 'r function nestedExports() { export { staticParam } ~~~~~~ -!!! error TS1233: An export declaration can only be used in a module. +!!! error TS1474: An export declaration can only be used at the top level of a module. import 'fs' ~~~~~~ -!!! error TS1232: An import declaration can only be used in a namespace or module. +!!! error TS1473: An import declaration can only be used at the top level of a module. export default 12 ~~~~~~ !!! error TS1258: A default export must be at the top level of a file or module declaration. diff --git a/tests/cases/compiler/importDeclarationInModuleDeclaration2.ts b/tests/cases/compiler/importDeclarationInModuleDeclaration2.ts new file mode 100644 index 0000000000000..2df0aadb8ae67 --- /dev/null +++ b/tests/cases/compiler/importDeclarationInModuleDeclaration2.ts @@ -0,0 +1,8 @@ +// @allowJs: true +// @noEmit: true +// @checkJs: true + +// @filename: check.js +function container() { + import "fs"; +} \ No newline at end of file