Beispiel #1
0
        private static void WriteObjectInitializer(CodeTextBuilder code, ObjectInitializerExpression expression)
        {
            if (expression.PropertyValues == null || expression.PropertyValues.Count == 0)
            {
                code.Write("{ }");
                return;
            }

            code.WriteListStart(opener: "{", closer: "}", separator: ",", newLine: true);

            foreach (var keyValue in expression.PropertyValues)
            {
                code.WriteListItem();
                code.Write(keyValue.Name.GetSealedOrCased(CasingStyle.Camel, sealLanguage: LanguageInfo.Entries.JavaScript()));

                if (keyValue.Value is IAssignable assignable && assignable.Name == keyValue.Name)
                {
                    continue;
                }

                code.Write(": ");
                WriteExpression(code, keyValue.Value);
            }

            code.WriteListEnd();
        }
Beispiel #2
0
        public void Write(XElement element)
        {
            WriteStartElement(element);

            if (!element.IsEmpty)
            {
                _code.WriteListStart(opener: "", closer: "", separator: "", newLine: true);

                foreach (var child in element.Nodes())
                {
                    _code.WriteListItem();

                    if (child is XElement childElement)
                    {
                        Write(childElement);
                    }
                    else
                    {
                        _code.Write(child.ToString());
                    }
                }

                _code.WriteListEnd();
            }

            WriteEndElement(element);
        }
Beispiel #3
0
        private static void WriteBlockInsideBraces(CodeTextBuilder code, BlockStatement block)
        {
            code.WriteListStart(opener: "{", closer: "}", separator: "", newLine: true);

            if (block != null)
            {
                WriteBlock(code, block);
            }

            code.WriteListEnd();
        }
Beispiel #4
0
        private static void WriteArray(CodeTextBuilder code, Array array)
        {
            code.WriteListStart(opener: "[", closer: "]", separator: ",");

            foreach (var item in array)
            {
                code.WriteListItem();
                WriteLiteral(code, item);
            }

            code.WriteListEnd();
        }
Beispiel #5
0
        private static void WriteDelegateInvocation(CodeTextBuilder code, DelegateInvocationExpression expression)
        {
            WriteExpression(code, expression.Delegate);

            code.WriteListStart(opener: "(", separator: ", ", closer: ")");

            foreach (var argument in expression.Arguments)
            {
                code.WriteListItem();
                WriteExpression(code, argument.Expression);
            }

            code.WriteListEnd();
        }
Beispiel #6
0
        private static void WriteNewArray(CodeTextBuilder code, NewArrayExpression expression)
        {
            code.WriteListStart(opener: "[", closer: "]", separator: ",", newLine: true);

            if (expression.DimensionInitializerValues != null)
            {
                foreach (var item in expression.DimensionInitializerValues.SelectMany(x => x))
                {
                    code.WriteListItem();
                    WriteExpression(code, item);
                }
            }

            code.WriteListEnd();
        }
Beispiel #7
0
        private static void WriteJsx(CodeTextBuilder code, XmlExpression expression)
        {
            if (expression.Xml == null)
            {
                code.Write("null");
                return;
            }

            var xmlText   = new StringBuilder();
            var jsxWriter = new JsxCodeWriter(code);

            code.WriteListStart(opener: "(", separator: "", closer: ")", newLine: true);
            code.WriteListItem();

            jsxWriter.Write(expression.Xml);

            code.WriteListEnd();
        }
Beispiel #8
0
        private static void WriteMethodCall(CodeTextBuilder code, MethodCallExpression call)
        {
            if (call.Target != null)
            {
                WriteExpression(code, call.Target);
                code.Write(".");
            }

            code.Write(ToCamelCase(call.MethodName ?? call.Method.Name));
            code.WriteListStart(opener: "(", separator: ", ", closer: ")");

            foreach (var argument in call.Arguments)
            {
                code.WriteListItem();
                WriteExpression(code, argument.Expression);
            }

            code.WriteListEnd();
        }
Beispiel #9
0
        private static void WriteParameters(CodeTextBuilder code, MethodSignature signature)
        {
            code.WriteListStart(opener: "(", separator: ", ", closer: ") ");

            signature.Parameters.ForEach(parameter => {
                code.WriteListItem();

                if (parameter.Tuple != null)
                {
                    JavaScriptExpressionWriter.WriteTuple(code, parameter.Tuple);
                }
                else
                {
                    code.Write(parameter.Name);
                }
            });

            code.WriteListEnd();
        }