@@ -560,6 +560,23 @@ namespace ts {
560
560
bindBlockScopedDeclaration ( node , SymbolFlags . BlockScopedVariable , SymbolFlags . BlockScopedVariableExcludes ) ;
561
561
}
562
562
563
+ // The binder visits every node in the syntax tree so it is a convenient place to perform a single localized
564
+ // check for reserved words used as identifiers in strict mode code.
565
+ function checkStrictModeIdentifier ( node : Identifier ) {
566
+ if ( node . parserContextFlags & ParserContextFlags . StrictMode &&
567
+ node . originalKeywordKind >= SyntaxKind . FirstFutureReservedWord &&
568
+ node . originalKeywordKind <= SyntaxKind . LastFutureReservedWord &&
569
+ ! isIdentifierName ( node ) ) {
570
+ // Report error only if there are no parse errors in file
571
+ if ( ! file . parseDiagnostics . length ) {
572
+ let message = getAncestor ( node , SyntaxKind . ClassDeclaration ) || getAncestor ( node , SyntaxKind . ClassExpression ) ?
573
+ Diagnostics . Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode :
574
+ Diagnostics . Identifier_expected_0_is_a_reserved_word_in_strict_mode ;
575
+ file . bindDiagnostics . push ( createDiagnosticForNode ( node , message , declarationNameToString ( node ) ) ) ;
576
+ }
577
+ }
578
+ }
579
+
563
580
function getDestructuringParameterName ( node : Declaration ) {
564
581
return "__" + indexOf ( ( < SignatureDeclaration > node . parent ) . parameters , node ) ;
565
582
}
@@ -588,6 +605,8 @@ namespace ts {
588
605
589
606
function bindWorker ( node : Node ) {
590
607
switch ( node . kind ) {
608
+ case SyntaxKind . Identifier :
609
+ return checkStrictModeIdentifier ( < Identifier > node ) ;
591
610
case SyntaxKind . TypeParameter :
592
611
return declareSymbolAndAddToSymbolTable ( < Declaration > node , SymbolFlags . TypeParameter , SymbolFlags . TypeParameterExcludes ) ;
593
612
case SyntaxKind . Parameter :
0 commit comments