public void Visit(ConstStatement node)
        {
            if (node != null)
            {
                // declarations get -1 position
                node.Index = -1;

                // the statement itself doesn't get executed, but the initializers do
                for (var ndx = 0; ndx < node.Count; ++ndx)
                {
                    var item = node[ndx];
                    if (item != null)
                    {
                        item.Accept(this);
                    }
                }
            }
        }
示例#2
0
 public void Visit(ConstStatement node)
 {
     // invalid! ignore
     IsValid = false;
 }
 public void Visit(ConstStatement node)
 {
     // invalid! ignore
     IsValid = false;
 }
 public void Visit(ConstStatement node)
 {
     Debug.Fail("shouldn't get here");
 }
示例#5
0
 public void Visit(ConstStatement node)
 {
     // not applicable; terminate
 }
        public void Visit(ConstStatement node)
        {
            if (node != null)
            {
                // declarations get -1 position
                node.Index = -1;

                // the statement itself doesn't get executed, but the initializers do
                for (var ndx = 0; ndx < node.Count; ++ndx)
                {
                    var item = node[ndx];
                    if (item != null)
                    {
                        item.Accept(this);
                    }
                }
            }
        }
 public void Visit(ConstStatement node)
 {
     Debug.Fail("shouldn't get here");
 }
示例#8
0
        //---------------------------------------------------------------------------------------
        // 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(ConstStatement node)
 {
     // not applicable; terminate
 }
        public override void Visit(ConstStatement node)
        {
            if (node != null)
            {
                // we want to weed out duplicates
                // var a=1, a=2 is okay, but var a, a=2 and var a=2, a should both be just var a=2, 
                // and var a, a should just be var a
                for (int ndx = 0; ndx < node.Count; ++ndx)
                {
                    string thisName = node[ndx].Identifier;

                    // we just want to throw an error if there are any duplicates. 
                    // we don't want to REMOVE anything, because we don't know if the browsers that
                    // implement this non-standard statement do first-win or last-win.
                    for (var ndx2 = ndx + 1; ndx2 < node.Count; ++ndx2)
                    {
                        if (string.CompareOrdinal(thisName, node[ndx2].Identifier) == 0)
                        {
                            node[ndx2].Context.HandleError(JSError.DuplicateConstantDeclaration, true);
                        }
                    }
                }

                // recurse the analyze
                base.Visit(node);
            }
        }