コード例 #1
0
        public void Visit(JsConstStatement 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(JsConstStatement node)
 {
     // invalid! ignore
     IsValid = false;
 }
コード例 #3
0
 public void Visit(JsConstStatement node)
 {
     // starts with a 'const', so we don't care
 }
コード例 #4
0
 public void Visit(JsConstStatement node)
 {
     // not applicable; terminate
 }
コード例 #5
0
 public void Visit(JsConstStatement node)
 {
     // invalid! ignore
     IsValid = false;
 }
コード例 #6
0
        public void Visit(JsConstStatement 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);
                    }
                }
            }
        }
コード例 #7
0
 public void Visit(JsConstStatement node)
 {
     Debug.Fail("shouldn't get here");
 }
コード例 #8
0
 public void Visit(JsConstStatement node)
 {
     Debug.Fail("shouldn't get here");
 }
コード例 #9
0
        //---------------------------------------------------------------------------------------
        // ParseVariableStatement
        //
        //  VariableStatement :
        //    'var' VariableDeclarationList
        //    or
        //    'const' VariableDeclarationList
        //    or
        //    'let' VariableDeclarationList
        //
        //  VariableDeclarationList :
        //    VariableDeclaration |
        //    VariableDeclaration ',' VariableDeclarationList
        //
        //  VariableDeclaration :
        //    Identifier Initializer
        //
        //  Initializer :
        //    <empty> |
        //    '=' AssignmentExpression
        //---------------------------------------------------------------------------------------
        private JsAstNode ParseVariableStatement()
        {
            // create the appropriate statement: var- or const-statement
            JsDeclaration varList;
            if (m_currentToken.Token == JsToken.Var)
            {
                varList = new JsVar(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 JsConstStatement(m_currentToken.Clone(), this);
                }
                else
                {
                    varList = new JsLexicalDeclaration(m_currentToken.Clone(), this)
                        {
                            StatementToken = m_currentToken.Token
                        };
                }
            }
            else
            {
                Debug.Fail("shouldn't get here");
                return null;
            }

            bool single = true;
            JsAstNode vdecl = null;
            JsAstNode 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;
        }
コード例 #10
0
 public void Visit(JsConstStatement node)
 {
     // not applicable; terminate
 }
コード例 #11
0
        public void Visit(JsConstStatement node)
        {
            if (node != null)
            {
                var symbol = StartSymbol(node);
                Output("const");
                MarkSegment(node, null, node.Context);
                SetContextOutputPosition(node.Context);
                m_startOfStatement = false;
                Indent();

                for (var ndx = 0; ndx < node.Count; ++ndx)
                {
                    var decl = node[ndx];
                    if (decl != null)
                    {
                        if (ndx > 0)
                        {
                            OutputPossibleLineBreak(',');
                            NewLine();
                        }

                        decl.Accept(this);
                    }
                }
                Unindent();
                EndSymbol(symbol);
            }
        }
コード例 #12
0
        public override void Visit(JsConstStatement 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);
            }
        }