Move module grammar checks to the grammar checker.
This commit is contained in:
parent
3dfa8bef24
commit
6900c8ff81
|
@ -3782,15 +3782,6 @@ module ts {
|
|||
}
|
||||
else {
|
||||
node.body = parseModuleBody();
|
||||
forEach((<Block>node.body).statements, s => {
|
||||
if (s.kind === SyntaxKind.ExportAssignment) {
|
||||
// Export assignments are not allowed in an internal module
|
||||
grammarErrorOnNode(s, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module);
|
||||
}
|
||||
else if (s.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>s).externalModuleName) {
|
||||
grammarErrorOnNode(s, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module);
|
||||
}
|
||||
});
|
||||
}
|
||||
return finishNode(node);
|
||||
}
|
||||
|
@ -4122,6 +4113,7 @@ module ts {
|
|||
case SyntaxKind.GetAccessor: return visitGetAccessor(<MethodDeclaration>node);
|
||||
case SyntaxKind.IndexSignature: return visitIndexSignature(<SignatureDeclaration>node);
|
||||
case SyntaxKind.Method: return visitMethod(<MethodDeclaration>node);
|
||||
case SyntaxKind.ModuleDeclaration: return visitModuleDeclaration(<ModuleDeclaration>node);
|
||||
case SyntaxKind.ObjectLiteral: return visitObjectLiteral(<ObjectLiteral>node);
|
||||
case SyntaxKind.Parameter: return visitParameter(<ParameterDeclaration>node);
|
||||
case SyntaxKind.PostfixOperator: return visitPostfixOperator(<UnaryExpression>node);
|
||||
|
@ -4291,6 +4283,20 @@ module ts {
|
|||
checkParameterList(node.parameters);
|
||||
}
|
||||
|
||||
function visitModuleDeclaration(node: ModuleDeclaration): void {
|
||||
if (node.name.kind === SyntaxKind.Identifier && node.body.kind === SyntaxKind.ModuleBlock) {
|
||||
forEach((<Block>node.body).statements, s => {
|
||||
if (s.kind === SyntaxKind.ExportAssignment) {
|
||||
// Export assignments are not allowed in an internal module
|
||||
grammarErrorOnNode(s, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module);
|
||||
}
|
||||
else if (s.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>s).externalModuleName) {
|
||||
grammarErrorOnNode(s, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function visitObjectLiteral(node: ObjectLiteral): void {
|
||||
var seen: Map<SymbolFlags> = {};
|
||||
var Property = 1;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
tests/cases/compiler/importDeclarationInModuleDeclaration1.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== tests/cases/compiler/importDeclarationInModuleDeclaration1.ts (1 errors) ====
|
||||
module m2 {
|
||||
import m3 = require("use_glo_M1_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
}
|
|
@ -1,12 +1,4 @@
|
|||
tests/cases/compiler/privacyGloImportParseErrors.ts(59,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyGloImportParseErrors.ts(69,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyGloImportParseErrors.ts(81,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyGloImportParseErrors.ts(82,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyGloImportParseErrors.ts(121,9): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyGloImportParseErrors.ts(125,13): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
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(146,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyGloImportParseErrors.ts(149,9): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyGloImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules.
|
||||
tests/cases/compiler/privacyGloImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules.
|
||||
tests/cases/compiler/privacyGloImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'.
|
||||
|
@ -16,7 +8,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(138,16): error TS2435: Ambie
|
|||
tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambient external modules cannot be nested in other modules.
|
||||
|
||||
|
||||
==== tests/cases/compiler/privacyGloImportParseErrors.ts (16 errors) ====
|
||||
==== tests/cases/compiler/privacyGloImportParseErrors.ts (8 errors) ====
|
||||
module m1 {
|
||||
export module m1_M1_public {
|
||||
export class c1 {
|
||||
|
@ -80,8 +72,6 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie
|
|||
var m1_im2_private_v4_private = m1_im2_private.f1();
|
||||
|
||||
import m1_im3_private = require("m1_M3_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'm1_M3_public'.
|
||||
export var m1_im3_private_v1_public = m1_im3_private.c1;
|
||||
|
@ -94,8 +84,6 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie
|
|||
var m1_im3_private_v4_private = m1_im3_private.f1();
|
||||
|
||||
import m1_im4_private = require("m1_M4_private");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'm1_M4_private'.
|
||||
export var m1_im4_private_v1_public = m1_im4_private.c1;
|
||||
|
@ -110,11 +98,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie
|
|||
export import m1_im1_public = m1_M1_public;
|
||||
export import m1_im2_public = m1_M2_private;
|
||||
export import m1_im3_public = require("m1_M3_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
export import m1_im4_public = require("m1_M4_private");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
}
|
||||
|
||||
module glo_M1_public {
|
||||
|
@ -154,14 +138,10 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie
|
|||
|
||||
module m2 {
|
||||
import errorImport = require("glo_M2_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
import nonerrorImport = glo_M1_public;
|
||||
|
||||
module m5 {
|
||||
import m5_errorImport = require("glo_M2_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
import m5_nonerrorImport = glo_M1_public;
|
||||
}
|
||||
}
|
||||
|
@ -191,13 +171,9 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie
|
|||
|
||||
module m2 {
|
||||
import m3 = require("use_glo_M1_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
module m4 {
|
||||
var a = 10;
|
||||
import m2 = require("use_glo_M1_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
}
|
||||
|
||||
}
|
|
@ -1,22 +1,6 @@
|
|||
tests/cases/compiler/privacyImportParseErrors.ts(59,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(69,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(81,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(82,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(143,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(153,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(166,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(167,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(273,9): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(277,13): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(302,9): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(306,13): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(314,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(326,9): error TS1029: 'export' modifier must precede 'declare' modifier.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(328,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(341,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(344,9): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(350,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(353,9): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules.
|
||||
tests/cases/compiler/privacyImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'.
|
||||
|
@ -49,7 +33,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(333,16): error TS2435: Ambient
|
|||
tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient external modules cannot be nested in other modules.
|
||||
|
||||
|
||||
==== tests/cases/compiler/privacyImportParseErrors.ts (49 errors) ====
|
||||
==== tests/cases/compiler/privacyImportParseErrors.ts (33 errors) ====
|
||||
export module m1 {
|
||||
export module m1_M1_public {
|
||||
export class c1 {
|
||||
|
@ -113,8 +97,6 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient
|
|||
var m1_im2_private_v4_private = m1_im2_private.f1();
|
||||
|
||||
import m1_im3_private = require("m1_M3_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'm1_M3_public'.
|
||||
export var m1_im3_private_v1_public = m1_im3_private.c1;
|
||||
|
@ -127,8 +109,6 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient
|
|||
var m1_im3_private_v4_private = m1_im3_private.f1();
|
||||
|
||||
import m1_im4_private = require("m1_M4_private");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'm1_M4_private'.
|
||||
export var m1_im4_private_v1_public = m1_im4_private.c1;
|
||||
|
@ -143,11 +123,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient
|
|||
export import m1_im1_public = m1_M1_public;
|
||||
export import m1_im2_public = m1_M2_private;
|
||||
export import m1_im3_public = require("m1_M3_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
export import m1_im4_public = require("m1_M4_private");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
}
|
||||
|
||||
module m2 {
|
||||
|
@ -213,8 +189,6 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient
|
|||
var m1_im2_private_v4_private = m1_im2_private.f1();
|
||||
|
||||
import m1_im3_private = require("m2_M3_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'm2_M3_public'.
|
||||
export var m1_im3_private_v1_public = m1_im3_private.c1;
|
||||
|
@ -227,8 +201,6 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient
|
|||
var m1_im3_private_v4_private = m1_im3_private.f1();
|
||||
|
||||
import m1_im4_private = require("m2_M4_private");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'm2_M4_private'.
|
||||
export var m1_im4_private_v1_public = m1_im4_private.c1;
|
||||
|
@ -244,11 +216,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient
|
|||
export import m1_im1_public = m2_M1_public;
|
||||
export import m1_im2_public = m2_M2_private;
|
||||
export import m1_im3_public = require("m2_M3_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
export import m1_im4_public = require("m2_M4_private");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
}
|
||||
|
||||
export module glo_M1_public {
|
||||
|
@ -375,14 +343,10 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient
|
|||
|
||||
module m2 {
|
||||
import errorImport = require("glo_M2_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
import nonerrorImport = glo_M1_public;
|
||||
|
||||
module m5 {
|
||||
import m5_errorImport = require("glo_M2_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
import m5_nonerrorImport = glo_M1_public;
|
||||
}
|
||||
}
|
||||
|
@ -416,14 +380,10 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient
|
|||
|
||||
module m2 {
|
||||
import errorImport = require("glo_M4_private");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
import nonerrorImport = glo_M3_private;
|
||||
|
||||
module m5 {
|
||||
import m5_errorImport = require("glo_M4_private");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
import m5_nonerrorImport = glo_M3_private;
|
||||
}
|
||||
}
|
||||
|
@ -481,26 +441,18 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient
|
|||
|
||||
module m2 {
|
||||
import m3 = require("use_glo_M1_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
module m4 {
|
||||
var a = 10;
|
||||
import m2 = require("use_glo_M1_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export module m3 {
|
||||
import m3 = require("use_glo_M1_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
module m4 {
|
||||
var a = 10;
|
||||
import m2 = require("use_glo_M1_public");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module m2 {
|
||||
import m3 = require("use_glo_M1_public");
|
||||
}
|
Loading…
Reference in a new issue