Пример #1
0
        public static ParametrizedCode FormatParametrizedScript(this JsNode node, bool niceMode = false, string indent = "\t")
        {
            node.FixParenthesis();
            var visitor = new JsFormattingVisitor(niceMode, indent);

            node.AcceptVisitor(visitor);
            return(visitor.GetResult(JsParensFixingVisitor.GetOperatorPrecedence(node as JsExpression)));
        }
Пример #2
0
        public static string FormatScript(this JsNode node, bool niceMode = false, string indent = "\t", bool isDebugString = false)
        {
            node.FixParenthesis();
            var visitor = new JsFormattingVisitor(niceMode, indent);

            node.AcceptVisitor(visitor);
            return(isDebugString ? visitor.ToString() : visitor.GetParameterlessResult());
        }
Пример #3
0
        private static string GenerateHandlerOptions(DotvvmBindableObject handler, Dictionary <string, object> options)
        {
            JsExpression optionsExpr = new JsObjectExpression(
                options.Where(o => o.Value != null).Select(o => new JsObjectProperty(o.Key, TransformOptionValueToExpression(handler, o.Value)))
                );

            if (options.Any(o => o.Value is IValueBinding))
            {
                optionsExpr = new JsFunctionExpression(
                    new[] { new JsIdentifier("c"), new JsIdentifier("d") },
                    new JsBlockStatement(new JsReturnStatement(optionsExpr))
                    );
            }

            optionsExpr.FixParenthesis();
            var script = new JsFormattingVisitor().ApplyAction(optionsExpr.AcceptVisitor).GetParameterlessResult();

            return(script);
        }
Пример #4
0
        private static string GenerateHandlerOptions(DotvvmBindableObject handler, Dictionary <string, object> options)
        {
            JsExpression optionsExpr = new JsObjectExpression(
                options.Where(o => o.Value != null).Select(o => new JsObjectProperty(o.Key, o.Value is IValueBinding b ?
                                                                                     (JsExpression) new JsIdentifierExpression(
                                                                                         JavascriptTranslator.FormatKnockoutScript(b.GetParametrizedKnockoutExpression(handler, unwrapped: true), new ParametrizedCode("c"), new ParametrizedCode("d"))) :
                                                                                     new JsLiteral(o.Value)))
                );

            if (options.Any(o => o.Value is IValueBinding))
            {
                optionsExpr = new JsFunctionExpression(
                    new[] { new JsIdentifier("c"), new JsIdentifier("d") },
                    new JsBlockStatement(new JsReturnStatement(optionsExpr))
                    );
            }

            optionsExpr.FixParenthesis();
            var script = new JsFormattingVisitor().ApplyAction(optionsExpr.AcceptVisitor).GetParameterlessResult();

            return(script);
        }