@@ -1169,6 +1169,11 @@ module ts {
11691169
11701170 function finishNode < T extends Node > ( node : T ) : T {
11711171 node . end = scanner . getStartPos ( ) ;
1172+
1173+ if ( isInStrictMode ) {
1174+ node . flags |= NodeFlags . ParsedInStrictMode ;
1175+ }
1176+
11721177 return node ;
11731178 }
11741179
@@ -1703,16 +1708,7 @@ module ts {
17031708
17041709 for ( var i = 0 ; i < parameterCount ; i ++ ) {
17051710 var parameter = parameters [ i ] ;
1706- // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the
1707- // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code
1708- // or if its FunctionBody is strict code(11.1.5).
1709- // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
1710- // strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
1711- if ( isInStrictMode && isEvalOrArgumentsIdentifier ( parameter . name ) ) {
1712- reportInvalidUseInStrictMode ( parameter . name ) ;
1713- return ;
1714- }
1715- else if ( parameter . flags & NodeFlags . Rest ) {
1711+ if ( parameter . flags & NodeFlags . Rest ) {
17161712 if ( i !== ( parameterCount - 1 ) ) {
17171713 grammarErrorOnNode ( parameter . name , Diagnostics . A_rest_parameter_must_be_last_in_a_parameter_list ) ;
17181714 return ;
@@ -4322,7 +4318,7 @@ module ts {
43224318 else {
43234319 // No parser errors were reported. Perform our stricted grammar checks.
43244320 file . _syntacticDiagnostics = [ ] ;
4325- performGrammarChecks ( file ) ;
4321+ performGrammarChecks ( sourceText , file ) ;
43264322 }
43274323
43284324 file . _parserDiagnostics = undefined ;
@@ -4363,9 +4359,54 @@ module ts {
43634359 return file ;
43644360 }
43654361
4366- function performGrammarChecks ( child : Node ) {
4362+ function performGrammarChecks ( sourceText : string , file : SourceFileInternal ) {
4363+ performNodeChecks ( file ) ;
4364+
4365+ function performNodeChecks ( node : Node ) {
4366+ // First recurse and perform all grammar checks on the children of this node. If any
4367+ // children had an grammar error, then skip reporting errors for this node or anything
4368+ // higher.
4369+ if ( forEachChild ( node , performNodeChecks ) ) {
4370+ return true ;
4371+ }
4372+
4373+ // No grammar errors on any of our children. Check this node for grammar errors.
4374+ switch ( node . kind ) {
4375+ case SyntaxKind . Parameter :
4376+ return performParameterChecks ( < ParameterDeclaration > node ) ;
4377+ }
4378+ }
4379+
4380+ function grammarErrorOnNode ( node : Node , message : DiagnosticMessage , arg0 ?: any , arg1 ?: any , arg2 ?: any ) : void {
4381+ var span = getErrorSpanForNode ( node ) ;
4382+ var start = span . end > span . pos ? skipTrivia ( file . text , span . pos ) : span . pos ;
4383+ var length = span . end - start ;
4384+
4385+ file . _syntacticDiagnostics . push ( createFileDiagnostic ( file , start , length , message , arg0 , arg1 , arg2 ) ) ;
4386+ }
4387+
4388+ function reportInvalidUseInStrictMode ( node : Identifier ) : void {
4389+ // declarationNameToString cannot be used here since it uses a backreference to 'parent' that is not yet set
4390+ var name = sourceText . substring ( skipTrivia ( sourceText , node . pos ) , node . end ) ;
4391+ grammarErrorOnNode ( node , Diagnostics . Invalid_use_of_0_in_strict_mode , name ) ;
4392+ }
4393+
4394+ function performParameterChecks ( node : ParameterDeclaration ) : boolean {
4395+ // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the
4396+ // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code
4397+ // or if its FunctionBody is strict code(11.1.5).
4398+ // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
4399+ // strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
4400+ if ( node . flags & NodeFlags . ParsedInStrictMode && isEvalOrArgumentsIdentifier ( node . name ) ) {
4401+ reportInvalidUseInStrictMode ( node . name ) ;
4402+ return true ;
4403+ }
4404+
4405+ return false ;
4406+ }
43674407 }
43684408
4409+
43694410 export function createProgram ( rootNames : string [ ] , options : CompilerOptions , host : CompilerHost ) : Program {
43704411 var program : Program ;
43714412 var files : SourceFile [ ] = [ ] ;
0 commit comments