@@ -10524,6 +10524,8 @@ module ts {
1052410524 }
1052510525
1052610526 function checkImportDeclaration(node: ImportDeclaration) {
10527+ checkGrammarImportDeclarationNameInStrictMode(node);
10528+
1052710529 if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) {
1052810530 grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers);
1052910531 }
@@ -10546,6 +10548,8 @@ module ts {
1054610548 }
1054710549
1054810550 function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) {
10551+ checkGrammarDeclarationNameInStrictMode(node);
10552+
1054910553 checkGrammarDecorators(node) || checkGrammarModifiers(node);
1055010554 if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
1055110555 checkImportBinding(node);
@@ -11952,6 +11956,35 @@ module ts {
1195211956 return false;
1195311957 }
1195411958
11959+ function checkGrammarImportDeclarationNameInStrictMode(node: ImportDeclaration): boolean {
11960+ // Check if the import declaration used strict-mode reserved word in its names bindings
11961+ if (node.importClause) {
11962+ let impotClause = node.importClause;
11963+ if (impotClause.namedBindings) {
11964+ let nameBindings = impotClause.namedBindings;
11965+ if (nameBindings.kind === SyntaxKind.NamespaceImport) {
11966+ let name = <Identifier>(<NamespaceImport>nameBindings).name;
11967+ if (name.strictModeKind) {
11968+ let nameText = declarationNameToString(name);
11969+ return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
11970+ }
11971+ }
11972+ else if (nameBindings.kind === SyntaxKind.NamedImports) {
11973+ let reportError = false;
11974+ for (let element of (<NamedImports>nameBindings).elements) {
11975+ let name = element.name;
11976+ if (name.strictModeKind) {
11977+ let nameText = declarationNameToString(name);
11978+ reportError = grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
11979+ }
11980+ }
11981+ return reportError;
11982+ }
11983+ }
11984+ }
11985+ return false;
11986+ }
11987+
1195511988 function checkGrammarDeclarationNameInStrictMode(node: Declaration): boolean {
1195611989 let name = node.name;
1195711990 if (name && name.kind === SyntaxKind.Identifier && (<Identifier>name).strictModeKind) {
@@ -11971,15 +12004,15 @@ module ts {
1197112004 return reportError ? reportError : false;
1197212005
1197312006 case SyntaxKind.ClassDeclaration:
12007+ // Report an error if the class declaration uses strict-mode reserved word.
1197412008 return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText);
1197512009
1197612010 case SyntaxKind.ModuleDeclaration:
11977- return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText);
12011+ // Report an error if the module declaration uses strict-mode reserved word.
12012+ return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode, nameText);
1197812013
11979- case SyntaxKind.ImportDeclaration:
11980- case SyntaxKind.ExportDeclaration:
1198112014 case SyntaxKind.ImportEqualsDeclaration:
11982- return grammarErrorOnNode(name, Diagnostics.ImportDecl_SlashExportDecl_SlashImportEqaul );
12015+ return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText );
1198312016 }
1198412017 }
1198512018 return false;
0 commit comments