public void VisitScript(object root, string selector, object callback, params object[] predicates) { if (predicates == null) { predicates = Empty; } var selectable = asSelectable(root); if (selectable != null) { SelectorHelper.Visit( selectable, selector, (current, parent, root1) => dynamicInvoker.Invoke(callback, current), (i, s) => i >= 0 && i < predicates.Length && dynamicInvoker.Invoke(predicates[i], s) is true); } }
public ICompiledStylesheet Compile( Func <object, ISelectable> asSelectable, IEvaluator evaluator, IDynamicInvoker invoker, params ScriptParameter[] closure) { if (!ContainsScripts()) { return(CompileSimple(asSelectable)); } var compiled = CompiledScript.Compile(this, invoker, asSelectable); closure = compiled.Closure.Concat(closure ?? new ScriptParameter[0]).ToArray(); var code = new StringBuilder(); code.AppendLine($"(function ({string.Join(", ", closure.Select(c => c.Name))}) {{"); code.AppendLine(compiled.Code); code.AppendLine("}).valueOf()"); var func = invoker.Invoke(evaluator.Evaluate(code.ToString()), closure.Select(c => c.Value).ToArray()); return(new ScriptStylesheet((root, arg) => invoker.Invoke(func, root, arg))); }