public void Visit(LexicalDeclaration node) { if (node != null) { // lexical declarations get an order index node.Index = NextOrderIndex; for (var ndx = 0; ndx < node.Count; ++ndx) { var decl = node[ndx]; if (decl != null) { decl.Accept(this); } } } }
public void Visit(LexicalDeclaration node) { // invalid! ignore IsValid = false; }
public void Visit(LexicalDeclaration node) { // invalid! ignore IsValid = false; }
public void Visit(LexicalDeclaration node) { Debug.Fail("shouldn't get here"); }
public void Visit(LexicalDeclaration node) { // not applicable; terminate }
public void Visit(LexicalDeclaration node) { if (node != null) { // lexical declarations get an order index node.Index = NextOrderIndex; for (var ndx = 0; ndx < node.Count; ++ndx) { var decl = node[ndx]; if (decl != null) { decl.Accept(this); } } } }
public void Visit(LexicalDeclaration node) { Debug.Fail("shouldn't get here"); }
private AstNode ParseForStatement() { m_blockType.Add(BlockType.Loop); AstNode forNode = null; try { Context forCtx = m_currentToken.Clone(); GetNextToken(); if (JSToken.LeftParenthesis != m_currentToken.Token) { ReportError(JSError.NoLeftParenthesis); } GetNextToken(); bool isForIn = false, recoveryInForIn = false; AstNode lhs = null, initializer = null, condOrColl = null, increment = null; Context operatorContext = null; Context separator1Context = null; Context separator2Context = null; try { if (JSToken.Var == m_currentToken.Token || JSToken.Let == m_currentToken.Token || JSToken.Const == m_currentToken.Token) { isForIn = true; Declaration declaration; if (m_currentToken.Token == JSToken.Var) { declaration = new Var(m_currentToken.Clone(), this); } else { declaration = new LexicalDeclaration(m_currentToken.Clone(), this) { StatementToken = m_currentToken.Token }; } declaration.Append(ParseIdentifierInitializer(JSToken.In)); // a list of variable initializers is allowed only in a for(;;) while (JSToken.Comma == m_currentToken.Token) { isForIn = false; declaration.Append(ParseIdentifierInitializer(JSToken.In)); //initializer = new Comma(initializer.context.CombineWith(var.context), initializer, var); } initializer = declaration; // if it could still be a for..in, now it's time to get the 'in' // TODO: for ES6 might be 'of' if (isForIn) { if (JSToken.In == m_currentToken.Token || (m_currentToken.Token == JSToken.Identifier && string.CompareOrdinal(m_currentToken.Code, "of") == 0)) { operatorContext = m_currentToken.Clone(); GetNextToken(); condOrColl = ParseExpression(); } else { isForIn = false; } } } else { if (JSToken.Semicolon != m_currentToken.Token) { bool isLHS; initializer = ParseUnaryExpression(out isLHS, false); if (isLHS && (JSToken.In == m_currentToken.Token || (m_currentToken.Token == JSToken.Identifier && string.CompareOrdinal(m_currentToken.Code, "of") == 0))) { isForIn = true; operatorContext = m_currentToken.Clone(); lhs = initializer; initializer = null; GetNextToken(); m_noSkipTokenSet.Add(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet); try { condOrColl = ParseExpression(); } catch (RecoveryTokenException exc) { if (IndexOfToken(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet, exc) == -1) { exc._partiallyComputedNode = null; throw; } else { if (exc._partiallyComputedNode == null) condOrColl = new ConstantWrapper(true, PrimitiveType.Boolean, CurrentPositionContext(), this); // what could we put here? else condOrColl = exc._partiallyComputedNode; } if (exc._token == JSToken.RightParenthesis) { GetNextToken(); recoveryInForIn = true; } } finally { m_noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet); } } else { initializer = ParseExpression(initializer, false, isLHS, JSToken.In); } } } } catch (RecoveryTokenException exc) { // error is too early abort for exc._partiallyComputedNode = null; throw; } // at this point we know whether or not is a for..in if (isForIn) { if (!recoveryInForIn) { if (JSToken.RightParenthesis != m_currentToken.Token) ReportError(JSError.NoRightParenthesis); forCtx.UpdateWith(m_currentToken); GetNextToken(); } AstNode body = null; // if the statements aren't withing curly-braces, throw a possible error if (JSToken.LeftCurly != m_currentToken.Token) { ReportError(JSError.StatementBlockExpected, CurrentPositionContext(), true); } try { // parse a Statement, not a SourceElement body = ParseStatement(false); } catch (RecoveryTokenException exc) { if (exc._partiallyComputedNode == null) body = new Block(CurrentPositionContext(), this); else body = exc._partiallyComputedNode; exc._partiallyComputedNode = new ForIn(forCtx, this) { Variable = (lhs != null ? lhs : initializer), OperatorContext = operatorContext, Collection = condOrColl, Body = AstNode.ForceToBlock(body), }; throw; } // for (a in b) // lhs = a, initializer = null // for (var a in b) // lhs = null, initializer = var a forNode = new ForIn(forCtx, this) { Variable = (lhs != null ? lhs : initializer), OperatorContext = operatorContext, Collection = condOrColl, Body = AstNode.ForceToBlock(body), }; } else { m_noSkipTokenSet.Add(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet); try { if (JSToken.Semicolon == m_currentToken.Token) { separator1Context = m_currentToken.Clone(); } else { ReportError(JSError.NoSemicolon); if (JSToken.Colon == m_currentToken.Token) { m_noSkipTokenSet.Add(NoSkipTokenSet.s_VariableDeclNoSkipTokenSet); try { SkipTokensAndThrow(); } catch (RecoveryTokenException) { if (JSToken.Semicolon == m_currentToken.Token) { m_useCurrentForNext = false; } else { throw; } } finally { m_noSkipTokenSet.Remove(NoSkipTokenSet.s_VariableDeclNoSkipTokenSet); } } } GetNextToken(); if (JSToken.Semicolon != m_currentToken.Token) { condOrColl = ParseExpression(); if (JSToken.Semicolon != m_currentToken.Token) { ReportError(JSError.NoSemicolon); } } separator2Context = m_currentToken.Clone(); GetNextToken(); if (JSToken.RightParenthesis != m_currentToken.Token) { increment = ParseExpression(); } if (JSToken.RightParenthesis != m_currentToken.Token) { ReportError(JSError.NoRightParenthesis); } forCtx.UpdateWith(m_currentToken); GetNextToken(); } catch (RecoveryTokenException exc) { if (IndexOfToken(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet, exc) == -1) { exc._partiallyComputedNode = null; throw; } else { // discard any partial info, just genrate empty condition and increment and keep going exc._partiallyComputedNode = null; if (condOrColl == null) condOrColl = new ConstantWrapper(true, PrimitiveType.Boolean, CurrentPositionContext(), this); } if (exc._token == JSToken.RightParenthesis) { GetNextToken(); } } finally { m_noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet); } // if this is an assignment, throw a warning in case the developer // meant to use == instead of = // but no warning if the condition is wrapped in parens. var binOp = condOrColl as BinaryOperator; if (binOp != null && binOp.OperatorToken == JSToken.Assign) { condOrColl.Context.HandleError(JSError.SuspectAssignment); } AstNode body = null; // if the statements aren't withing curly-braces, throw a possible error if (JSToken.LeftCurly != m_currentToken.Token) { ReportError(JSError.StatementBlockExpected, CurrentPositionContext(), true); } try { // parse a Statement, not a SourceElement body = ParseStatement(false); } catch (RecoveryTokenException exc) { if (exc._partiallyComputedNode == null) body = new Block(CurrentPositionContext(), this); else body = exc._partiallyComputedNode; exc._partiallyComputedNode = new ForNode(forCtx, this) { Initializer = initializer, Separator1Context = separator1Context, Condition = condOrColl, Separator2Context = separator2Context, Incrementer = increment, Body = AstNode.ForceToBlock(body) }; throw; } forNode = new ForNode(forCtx, this) { Initializer = initializer, Separator1Context = separator1Context, Condition = condOrColl, Separator2Context = separator2Context, Incrementer = increment, Body = AstNode.ForceToBlock(body) }; } } finally { m_blockType.RemoveAt(m_blockType.Count - 1); } return forNode; }
//--------------------------------------------------------------------------------------- // ParseVariableStatement // // VariableStatement : // 'var' VariableDeclarationList // or // 'const' VariableDeclarationList // or // 'let' VariableDeclarationList // // VariableDeclarationList : // VariableDeclaration | // VariableDeclaration ',' VariableDeclarationList // // VariableDeclaration : // Identifier Initializer // // Initializer : // <empty> | // '=' AssignmentExpression //--------------------------------------------------------------------------------------- private AstNode ParseVariableStatement() { // create the appropriate statement: var- or const-statement Declaration varList; if (m_currentToken.Token == JSToken.Var) { varList = new Var(m_currentToken.Clone(), this); } else if (m_currentToken.Token == JSToken.Const || m_currentToken.Token == JSToken.Let) { if (m_currentToken.Token == JSToken.Const && m_settings.ConstStatementsMozilla) { varList = new ConstStatement(m_currentToken.Clone(), this); } else { varList = new LexicalDeclaration(m_currentToken.Clone(), this) { StatementToken = m_currentToken.Token }; } } else { Debug.Fail("shouldn't get here"); return null; } bool single = true; AstNode vdecl = null; AstNode identInit = null; for (; ; ) { m_noSkipTokenSet.Add(NoSkipTokenSet.s_EndOfLineToken); try { identInit = ParseIdentifierInitializer(JSToken.None); } catch (RecoveryTokenException exc) { // an exception is passing by, possibly bringing some info, save the info if any if (exc._partiallyComputedNode != null) { if (!single) { varList.Append(exc._partiallyComputedNode); varList.Context.UpdateWith(exc._partiallyComputedNode.Context); exc._partiallyComputedNode = varList; } } if (IndexOfToken(NoSkipTokenSet.s_EndOfLineToken, exc) == -1) throw; else { if (single) identInit = exc._partiallyComputedNode; } } finally { m_noSkipTokenSet.Remove(NoSkipTokenSet.s_EndOfLineToken); } if (identInit != null) { vdecl = identInit; varList.Append(vdecl); } if (m_currentToken.Token == JSToken.Comma) { single = false; vdecl.IfNotNull(d => d.TerminatingContext = m_currentToken.Clone()); } else if (m_currentToken.Token == JSToken.Semicolon) { varList.TerminatingContext = m_currentToken.Clone(); GetNextToken(); break; } else if (m_foundEndOfLine || m_currentToken.Token == JSToken.RightCurly || m_currentToken.Token == JSToken.EndOfFile) { // semicolon insertion rules // a right-curly or an end of line is something we don't WANT to throw a warning for. // Just too common and doesn't really warrant a warning (in my opinion) if (JSToken.RightCurly != m_currentToken.Token && JSToken.EndOfFile != m_currentToken.Token) { ReportError(JSError.SemicolonInsertion, varList.Context.IfNotNull(c => c.FlattenToEnd()), true); } break; } else { ReportError(JSError.NoSemicolon, false); break; } } if (vdecl != null) { varList.Context.UpdateWith(vdecl.Context); } return varList; }
public void Visit(LexicalDeclaration node) { // not applicable; terminate }