コード例 #1
0
 private void WriteGlobalBlock(ModuleMember module)
 {
     if (module.GloalBlock != null)
     {
         JavaScriptStatementWriter.WriteStatementLine(_code, module.GloalBlock);
     }
 }
コード例 #2
0
        private static void WriteBody(CodeTextBuilder code, BlockStatement body)
        {
            code.WriteLine("{");
            code.Indent(1);

            foreach (var statement in body.Statements)
            {
                JavaScriptStatementWriter.WriteStatementLine(code, statement);
            }

            code.Indent(-1);
            code.Write("}");
        }
コード例 #3
0
        public static void WriteArrowFunction(CodeTextBuilder code, MethodSignature signature, BlockStatement body)
        {
            if (signature.IsAsync)
            {
                code.Write("async ");
            }

            if (signature.Parameters.Count != 1)
            {
                WriteParameters(code, signature);
            }
            else
            {
                code.Write($"{signature.Parameters[0].Name} ");
            }

            code.Write("=> ");

            switch (body.Statements.Count)
            {
            case 0:
                code.Write("{ }");
                break;

            case 1:
                if (body.Statements[0] is ReturnStatement @return)
                {
                    var needParentheses = (@return.Expression is ObjectInitializerExpression init && init.PropertyValues.Count > 1);
                    code.WriteIf(needParentheses, "(");
                    JavaScriptExpressionWriter.WriteExpression(code, @return.Expression);
                    code.WriteIf(needParentheses, ")");
                }
                else
                {
                    // code.WriteLine();
                    // code.Indent(1);
                    JavaScriptStatementWriter.WriteStatement(code, body.Statements[0]);
                    // code.WriteLine();
                    // code.Indent(-1);
                }
                break;

            default:
                WriteBody(code, body);
                break;
            }
        }