private ParametrizedCode FormatJavascript(JsExpression node, bool allowObservableResult = true) { var expr = new JsParenthesizedExpression(node.Clone()); expr.AcceptVisitor(new KnockoutObservableHandlingVisitor(allowObservableResult)); JavascriptNullCheckAdder.AddNullChecks(expr); expr = new JsParenthesizedExpression((JsExpression)JsTemporaryVariableResolver.ResolveVariables(expr.Expression.Detach())); return((StartsWithStatementLikeExpression(expr.Expression) ? expr : expr.Expression).FormatParametrizedScript(niceMode: configuration.Debug)); }
public override JsExpression GetJsTranslation(JsExpression dataContext) { JsExpression index() => dataContext.Clone().Member("$index").Invoke(); return(new JsObjectExpression( new JsObjectProperty(nameof(BindingCollectionInfo.Index), index()), new JsObjectProperty(nameof(BindingCollectionInfo.IsFirst), new JsBinaryExpression(index(), BinaryOperatorType.Equal, new JsLiteral(0))), new JsObjectProperty(nameof(BindingCollectionInfo.IsOdd), new JsBinaryExpression(new JsBinaryExpression(index(), BinaryOperatorType.Modulo, new JsLiteral(2)), BinaryOperatorType.Equal, new JsLiteral(1))), new JsObjectProperty(nameof(BindingCollectionInfo.IsEven), new JsBinaryExpression(new JsBinaryExpression(index(), BinaryOperatorType.Modulo, new JsLiteral(2)), BinaryOperatorType.Equal, new JsLiteral(0))) )); }
JsExpression CreateAnonymousJsDelegate(JsExpression instanceContext, JsExpression func) { if (instanceContext == null) { return(func); } return(new JsInvocationExpression { Member = new JsMemberExpression { Name = "$CreateAnonymousDelegate" }, Arguments = new List <JsExpression> { instanceContext.Clone(), func } }); }