Esempio n. 1
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 is AstSymbol)
            {
                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);
        }
Esempio n. 2
0
        public override void CodeGen(OutputContext output)
        {
            output.Print("class");
            output.Space();
            if (Name != null)
            {
                Name.Print(output);
                output.Space();
            }

            if (Extends != null)
            {
                var parens = !(Extends is AstSymbolRef) &&
                             !(Extends is AstPropAccess) &&
                             !(Extends is AstClassExpression) &&
                             !(Extends is AstFunction);
                output.Print("extends");
                if (!parens)
                {
                    output.Space();
                }

                Extends.Print(output, parens);
                if (!parens)
                {
                    output.Space();
                }
            }

            if (Properties.Count > 0)
            {
                output.Print("{");
                output.Newline();
                output.Indentation += output.Options.IndentLevel;
                output.Indent();
                for (var i = 0u; i < Properties.Count; i++)
                {
                    if (i > 0)
                    {
                        output.Newline();
                    }

                    output.Indent();
                    Properties[i].Print(output);
                }

                output.Newline();
                output.Indentation -= output.Options.IndentLevel;
                output.Indent();
                output.Print("}");
            }
            else
            {
                output.Print("{}");
            }
        }