Exemplo n.º 1
0
        public override void CodeGen(OutputContext output)
        {
            output.Print("catch");
            if (Argname != null)
            {
                output.Space();
                Argname.Print(output, true);
            }

            output.Space();
            output.PrintBraced(this, false);
        }
Exemplo n.º 2
0
    void PrintArrowBody(OutputContext output)
    {
        if (Body.Count == 1)
        {
            var last = Body.Last;
            if (last.IsExpression())
            {
                last.Print(output);
                return;
            }
        }

        output.PrintBraced(Body, false);
    }
Exemplo n.º 3
0
    public virtual void DoPrint(OutputContext output, bool noKeyword = false)
    {
        if (!noKeyword)
        {
            if (Async)
            {
                output.Print("async");
                output.Space();
            }

            output.Print("function");
            if (IsGenerator)
            {
                output.Print("*");
            }

            if (Name != null)
            {
                output.Space();
            }
        }

        if (Name != null)
        {
            Name.Print(output);
        }
        else if (noKeyword && Name != null)
        {
            output.Print("[");
            Name.Print(output); // Computed method name
            output.Print("]");
        }

        output.Print("(");
        for (var i = 0; i < ArgNames.Count; i++)
        {
            if (i > 0)
            {
                output.Comma();
            }
            ArgNames[(uint)i].Print(output);
        }

        output.Print(")");
        output.Space();
        output.PrintBraced(this, HasUseStrictDirective);
    }
Exemplo n.º 4
0
        public override void CodeGen(OutputContext output)
        {
            output.Print("try");
            output.Space();
            output.PrintBraced(Body, false);
            if (Bcatch != null)
            {
                output.Space();
                Bcatch.Print(output);
            }

            if (Bfinally != null)
            {
                output.Space();
                Bfinally.Print(output);
            }
        }
Exemplo n.º 5
0
        public override void DoPrint(OutputContext output, bool nokeyword = false)
        {
            var parent      = output.Parent();
            var needsParens = parent is AstBinary ||
                              parent is AstUnary ||
                              (parent is AstCall call && this == call.Expression);

            if (needsParens)
            {
                output.Print("(");
            }
            if (Async)
            {
                output.Print("async");
                output.Space();
            }

            if (ArgNames.Count == 1 && ArgNames[0] is AstSymbol)
            {
                ArgNames[0].Print(output);
            }
            else
            {
                output.Print("(");
                for (var i = 0u; i < ArgNames.Count; i++)
                {
                    if (i > 0)
                    {
                        output.Comma();
                    }
                    ArgNames[i].Print(output);
                }

                output.Print(")");
            }

            output.Space();
            output.Print("=>");
            output.Space();
            output.PrintBraced(Body, false);
            if (needsParens)
            {
                output.Print(")");
            }
        }
Exemplo n.º 6
0
        void PrintArrowBody(OutputContext output)
        {
            if (Body.Count == 1)
            {
                // We expect that only scope (function, class,...), simple statement, constants or array is valid expression
                // Invalid expressions are: AstBreak, AstCatch, AstConst, AstContinue, AstDwLoop, AstDebugger,
                // AstDefinitions, AstDo, AstEmptyStatement, AstExit, AstExport, AstFinally, AstFor, AstForIn, AstForOf,
                // AstIf, AstImport, AstIterationStatement, AstJump, AstLabeledStatement, AstLet, AstLoopControl,
                // AstReturn, AstStatementWithBody, AstSwitch, AstThrow, AstTry, AstVar, AstWhile, AstWith
                // At this level it should not be: AstAccessor, AstBlockStatement, AstCase, AstDefClass, AstDefault,
                // AstSwitchBranch, AstToplevel
                if (Body.Last is AstScope scope)
                {
                    scope.CodeGen(output);
                    return;
                }

                if (Body.Last is AstSimpleStatement simpleStatement)
                {
                    simpleStatement.Body.Print(output);
                    return;
                }

                if (Body.Last is AstConstant constant)
                {
                    constant.CodeGen(output);
                    return;
                }

                if (Body.Last is AstArray array)
                {
                    array.CodeGen(output);
                    return;
                }
            }

            output.PrintBraced(Body, false);
        }
Exemplo n.º 7
0
 public override void CodeGen(OutputContext output)
 {
     output.PrintBraced(this, false);
 }
Exemplo n.º 8
0
 public override void CodeGen(OutputContext output)
 {
     output.Print("finally");
     output.Space();
     output.PrintBraced(this, false);
 }