//--------------------------------------------------------------------------------------- // ParseReturnStatement // // ReturnStatement : // 'return' Expression // // This function may return a null AST under error condition. The caller should handle // that case. // Regardless of error conditions, on exit the parser points to the first token after // the return statement. //--------------------------------------------------------------------------------------- private ReturnNode ParseReturnStatement() { var returnNode = new ReturnNode(m_currentToken.Clone(), this); GetNextToken(); if (!m_foundEndOfLine) { if (JSToken.Semicolon != m_currentToken.Token && JSToken.RightCurly != m_currentToken.Token) { m_noSkipTokenSet.Add(NoSkipTokenSet.s_EndOfStatementNoSkipTokenSet); try { returnNode.Operand = ParseExpression(); } catch (RecoveryTokenException exc) { returnNode.Operand = exc._partiallyComputedNode; if (IndexOfToken(NoSkipTokenSet.s_EndOfStatementNoSkipTokenSet, exc) == -1) { exc._partiallyComputedNode = returnNode; throw; } } finally { if (returnNode.Operand != null) { returnNode.UpdateWith(returnNode.Operand.Context); } m_noSkipTokenSet.Remove(NoSkipTokenSet.s_EndOfStatementNoSkipTokenSet); } } if (JSToken.Semicolon == m_currentToken.Token) { returnNode.TerminatingContext = m_currentToken.Clone(); GetNextToken(); } 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, returnNode.Context.IfNotNull(c => c.FlattenToEnd()), true); } } else { ReportError(JSError.NoSemicolon, false); } } return returnNode; }