public void Visit(JsTryNode node)
        {
            if (node != null)
            {
                node.Index = NextOrderIndex;

                if (node.TryBlock != null)
                {
                    node.TryBlock.Accept(this);
                }

                // add this catch parameter to the list of catch parameters the variable
                // scope will need to ghost later.
                if (node.CatchParameter != null)
                {
                    CurrentVariableScope.GhostedCatchParameters.Add(node.CatchParameter);
                }

                if (node.CatchBlock != null)
                {
                    // create the catch-scope, add the catch parameter to it, and recurse the catch block.
                    // the block itself will push the scope onto the stack and pop it off, so we don't have to.
                    node.CatchBlock.BlockScope = new JsCatchScope(CurrentLexicalScope, node.CatchBlock.Context, m_settings, node.CatchParameter)
                    {
                        IsInWithScope = m_withDepth > 0
                    };
                    node.CatchBlock.BlockScope.LexicallyDeclaredNames.Add(node.CatchParameter);
                    node.CatchBlock.Accept(this);
                }

                if (node.FinallyBlock != null)
                {
                    node.FinallyBlock.Accept(this);
                }
            }
        }
 public void Visit(JsTryNode node)
 {
     // invalid! ignore
     IsValid = false;
 }
 public void Visit(JsTryNode node)
 {
     // starts with 'try', so we don't care
 }
Exemplo n.º 4
0
 public void Visit(JsTryNode node)
 {
     // not applicable; terminate
 }
Exemplo n.º 5
0
 public void Visit(JsTryNode node)
 {
     // invalid! ignore
     IsValid = false;
 }
        public void Visit(JsTryNode node)
        {
            if (node != null)
            {
                node.Index = NextOrderIndex;

                if (node.TryBlock != null)
                {
                    node.TryBlock.Accept(this);
                }

                // add this catch parameter to the list of catch parameters the variable
                // scope will need to ghost later.
                if (node.CatchParameter != null)
                {
                    CurrentVariableScope.GhostedCatchParameters.Add(node.CatchParameter);
                }

                if (node.CatchBlock != null)
                {
                    // create the catch-scope, add the catch parameter to it, and recurse the catch block.
                    // the block itself will push the scope onto the stack and pop it off, so we don't have to.
                    node.CatchBlock.BlockScope = new JsCatchScope(CurrentLexicalScope, node.CatchBlock.Context, m_settings, node.CatchParameter)
                    {
                        IsInWithScope = m_withDepth > 0
                    };
                    node.CatchBlock.BlockScope.LexicallyDeclaredNames.Add(node.CatchParameter);
                    node.CatchBlock.Accept(this);
                }

                if (node.FinallyBlock != null)
                {
                    node.FinallyBlock.Accept(this);
                }
            }
        }
 public void Visit(JsTryNode node)
 {
     Debug.Fail("shouldn't get here");
 }
Exemplo n.º 8
0
 public void Visit(JsTryNode node)
 {
     Debug.Fail("shouldn't get here");
 }
 public void Visit(JsTryNode node)
 {
     // not applicable; terminate
 }
Exemplo n.º 10
0
        private void OutputTryBranch(JsTryNode node)
        {
            Output("try");
            MarkSegment(node, null, node.Context);
            SetContextOutputPosition(node.Context);
            if (node.TryBlock == null || node.TryBlock.Count == 0)
            {
                if (m_settings.OutputMode == MinifierOutputMode.MultipleLines)
                {
                    OutputPossibleLineBreak(' ');
                }

                Output("{}");
                BreakLine(false);
            }
            else
            {
                if (m_settings.BlocksStartOnSameLine == MinifierBlockStart.NewLine
                    || (m_settings.BlocksStartOnSameLine == MinifierBlockStart.UseSource && node.TryBlock.BraceOnNewLine))
                {
                    NewLine();
                }
                else if (m_settings.OutputMode == MinifierOutputMode.MultipleLines)
                {
                    OutputPossibleLineBreak(' ');
                }

                node.TryBlock.Accept(this);
            }
        }
Exemplo n.º 11
0
        private void OutputCatchBranch(JsTryNode node)
        {
            NewLine();
            Output("catch(");
            MarkSegment(node, null, node.CatchVarContext);
            if (node.CatchParameter != null)
            {
                node.CatchParameter.Accept(this);
            }

            OutputPossibleLineBreak(')');

            if (node.CatchBlock == null || node.CatchBlock.Count == 0)
            {
                if (m_settings.OutputMode == MinifierOutputMode.MultipleLines)
                {
                    OutputPossibleLineBreak(' ');
                }

                Output("{}");
                BreakLine(false);
            }
            else
            {
                if (m_settings.BlocksStartOnSameLine == MinifierBlockStart.NewLine
                    || (m_settings.BlocksStartOnSameLine == MinifierBlockStart.UseSource && node.CatchBlock.BraceOnNewLine))
                {
                    NewLine();
                }
                else if (m_settings.OutputMode == MinifierOutputMode.MultipleLines)
                {
                    OutputPossibleLineBreak(' ');
                }

                node.CatchBlock.Accept(this);
            }
        }
Exemplo n.º 12
0
        public void Visit(JsTryNode node)
        {
            if (node != null)
            {
                var symbol = StartSymbol(node);
                OutputTryBranch(node);

                var hasCatchBlock = false;
                if (!string.IsNullOrEmpty(node.CatchVarName))
                {
                    hasCatchBlock = true;
                    OutputCatchBranch(node);
                }

                if (!hasCatchBlock || (node.FinallyBlock != null && node.FinallyBlock.Count > 0))
                {
                    OutputFinallyBranch(node);
                }

                EndSymbol(symbol);
            }
        }
        public override void Visit(JsTryNode node)
        {
            if (node != null)
            {
                // anaylze the blocks
                base.Visit(node);

                // if the try block is empty, then set it to null
                if (node.TryBlock != null && node.TryBlock.Count == 0)
                {
                    node.TryBlock = null;
                }

                // eliminate an empty finally block UNLESS there is no catch block.
                if (node.FinallyBlock != null && node.FinallyBlock.Count == 0 && node.CatchBlock != null
                    && m_parser.Settings.IsModificationAllowed(JsTreeModifications.RemoveEmptyFinally))
                {
                    node.FinallyBlock = null;
                }

                // check strict-mode restrictions
                if (m_scopeStack.Peek().UseStrict && !string.IsNullOrEmpty(node.CatchVarName))
                {
                    // catch variable cannot be named "eval" or "arguments"
                    if (string.CompareOrdinal(node.CatchVarName, "eval") == 0
                        || string.CompareOrdinal(node.CatchVarName, "arguments") == 0)
                    {
                        node.CatchVarContext.HandleError(JsError.StrictModeVariableName, true);
                    }
                }

                if (node.CatchParameter != null)
                {
                    // if the block has a lexical scope, check it for conflicts
                    foreach(var lexDecl in node.CatchBlock.BlockScope.LexicallyDeclaredNames)
                    {
                        if (lexDecl != node.CatchParameter
                            && string.CompareOrdinal(lexDecl.Name, node.CatchParameter.Name) == 0)
                        {
                            // report the error (catchvar collides with lex/const) or warning (catchvar collides with funcdecl)
                            lexDecl.NameContext.HandleError(JsError.DuplicateLexicalDeclaration, lexDecl is JsLexicalDeclaration);

                            // link the inner one to the outer one so any renaming stays in sync.
                            if (lexDecl.VariableField != null)
                            {
                                lexDecl.VariableField.OuterField = node.CatchParameter.VariableField;
                                if (node.CatchParameter.VariableField != null && !lexDecl.VariableField.CanCrunch)
                                {
                                    node.CatchParameter.VariableField.CanCrunch = false;
                                }
                            }
                        }
                    }

                    // check to make sure there are no var-decl'd names with the same name.
                    foreach (var varDecl in node.CatchBlock.BlockScope.VarDeclaredNames)
                    {
                        if (string.CompareOrdinal(varDecl.Name, node.CatchParameter.Name) == 0)
                        {
                            // report the warning (catchvar collides with var)
                            // we shouldn't have to link them; the catchvar should already ghosted.
                            varDecl.NameContext.HandleError(JsError.DuplicateLexicalDeclaration, false);
                        }
                    }
                }
            }
        }