Example #1
0
        public void Visit(JsDoWhile node)
        {
            if (node != null)
            {
                node.Index = NextOrderIndex;
                if (node.Body != null)
                {
                    node.Body.Accept(this);
                }

                if (node.Condition != null)
                {
                    node.Condition.Accept(this);
                }
            }
        }
 public void Visit(JsDoWhile node)
 {
     // starts with a 'do', so we don't care
 }
 public void Visit(JsDoWhile node)
 {
     // starts with a 'do', so we don't care
 }
 private void DoDoWhile(JsDoWhile node)
 {
     if (m_parser.Settings.IsModificationAllowed(JsTreeModifications.EvaluateNumericExpressions))
     {
         // if the condition is a constant, we can simplify things
         JsConstantWrapper constantCondition = node.Condition as JsConstantWrapper;
         if (constantCondition != null && constantCondition.IsNotOneOrPositiveZero)
         {
             try
             {
                 // the condition is a constant, so it is always either true or false
                 // we can replace the condition with a one or a zero -- only one byte
                 node.Condition =
                     new JsConstantWrapper(constantCondition.ToBoolean() ? 1 : 0, JsPrimitiveType.Number, node.Condition.Context, m_parser);
             }
             catch (InvalidCastException)
             {
                 // ignore any invalid cast errors
             }
         }
     }
 }
        public override void Visit(JsDoWhile node)
        {
            if (node != null)
            {
                // depth-first
                base.Visit(node);

                DoDoWhile(node);
            }
        }
 public void Visit(JsDoWhile node)
 {
     // invalid! ignore
     IsValid = false;
 }
 public void Visit(JsDoWhile node)
 {
     // invalid! ignore
     IsValid = false;
 }
Example #8
0
 public void Visit(JsDoWhile node)
 {
     // not applicable; terminate
 }
 public void Visit(JsDoWhile node)
 {
     // not applicable; terminate
 }
 public void Visit(JsDoWhile node)
 {
     Debug.Fail("shouldn't get here");
 }
        public void Visit(JsDoWhile node)
        {
            if (node != null)
            {
                node.Index = NextOrderIndex;
                if (node.Body != null)
                {
                    node.Body.Accept(this);
                }

                if (node.Condition != null)
                {
                    node.Condition.Accept(this);
                }
            }
        }
Example #12
0
 public void Visit(JsDoWhile node)
 {
     Debug.Fail("shouldn't get here");
 }
        public void Visit(JsDoWhile node)
        {
            if (node != null)
            {
                var symbol = StartSymbol(node);

                Output("do");
                MarkSegment(node, null, node.Context);
                SetContextOutputPosition(node.Context);

                if (node.Body == null || node.Body.Count == 0)
                {
                    // semicolon-replacement cannot create an empty statement
                    OutputPossibleLineBreak(';');
                }
                else if (node.Body.Count == 1 && !node.Body.EncloseBlock(EncloseBlockType.SingleDoWhile))
                {
                    // there's only one statement, which means we don't need curley braces.
                    // HOWEVER, if the one statement ends in a do-while statement, then we DO need curley-braces
                    // because of an IE bug. IE parses the semi-colon that terminates the do-while as an empty
                    // statement FOLLOWING the do-while, which means the while-clause of the do-while is in the
                    // wrong spot. We *could* leave the semi-colon out and all browsers will parse it properly, but
                    // that isn't strictly correct JS. So just wrap it in curly-braces to remain proper AND work in
                    // all browsers.
                    Indent();
                    NewLine();
                    m_startOfStatement = true;
                    node.Body[0].Accept(this);

                    if (node.Body[0].RequiresSeparator)
                    {
                        // because the next thing we are going to output is a while keyword, if the
                        // semicolon would be at the end of a line, we can skip it and just let the
                        // end of line trigger the semicolon-insertion rules.
                        if (ReplaceableSemicolon())
                        {
                            MarkSegment(node.Body[0], null, node.Body[0].TerminatingContext);
                        }
                    }

                    Unindent();
                    NewLine();
                }
                else
                {
                    if (m_settings.BlocksStartOnSameLine == MinifierBlockStart.NewLine
                        || (m_settings.BlocksStartOnSameLine == MinifierBlockStart.UseSource && node.Body.BraceOnNewLine))
                    {
                        NewLine();
                    }
                    else if (m_settings.OutputMode == MinifierOutputMode.MultipleLines)
                    {
                        OutputPossibleLineBreak(' ');
                    }

                    node.Body.Accept(this);

                    if (m_settings.OutputMode == MinifierOutputMode.MultipleLines)
                    {
                        OutputPossibleLineBreak(' ');
                    }
                }

                Output("while");
                MarkSegment(node, null, node.WhileContext);
                if (m_settings.OutputMode == MinifierOutputMode.MultipleLines)
                {
                    OutputPossibleLineBreak(' ');
                }

                OutputPossibleLineBreak('(');
                m_startOfStatement = false;
                if (node.Condition != null)
                {
                    node.Condition.Accept(this);
                }

                Output(')');

                EndSymbol(symbol);
            }
        }
        public override void Visit(JsDoWhile node)
        {
            if (node != null)
            {
                // if we are stripping debugger statements and the body is
                // just a debugger statement, replace it with a null
                if (m_parser.Settings.StripDebugStatements
                     && m_parser.Settings.IsModificationAllowed(JsTreeModifications.StripDebugStatements)
                     && node.Body != null
                     && node.Body.IsDebuggerStatement)
                {
                    node.Body = null;
                }

                // recurse
                base.Visit(node);

                // if the body is now empty, make it null
                if (node.Body != null && node.Body.Count == 0)
                {
                    node.Body = null;
                }
            }
        }