public Expression Compile(IEnumerable <Expression> expressions, Expression parentContext, string templatePath = null) { try { if (expressions.Any() == false) { return(_emptyLambda); } if (expressions.IsOneOf <Expression, DefaultExpression>() == true) { return(_emptyLambda); } var compilationContext = new CompilationContext(_configuration); var expression = CreateExpressionBlock(expressions); expression = CommentVisitor.Visit(expression, compilationContext); expression = UnencodedStatementVisitor.Visit(expression, compilationContext); expression = PartialBinder.Bind(expression, compilationContext); expression = StaticReplacer.Replace(expression, compilationContext); expression = IteratorBinder.Bind(expression, compilationContext); expression = BlockHelperFunctionBinder.Bind(expression, compilationContext); expression = DeferredSectionVisitor.Bind(expression, compilationContext); expression = HelperFunctionBinder.Bind(expression, compilationContext); expression = BoolishConverter.Convert(expression, compilationContext); expression = PathBinder.Bind(expression, compilationContext); expression = SubExpressionVisitor.Visit(expression, compilationContext); expression = ContextBinder.Bind(expression, compilationContext, parentContext, templatePath); return(expression); } catch (Exception ex) { throw new HandlebarsCompilerException("An unhandled exception occurred while trying to compile the template", ex); } }
public static Expression Reduce(Expression expression, CompilationContext context) { expression = new CommentVisitor().Visit(expression); expression = new UnencodedStatementVisitor(context).Visit(expression); expression = new PartialBinder(context).Visit(expression); expression = new StaticReplacer(context).Visit(expression); expression = new IteratorBinder(context).Visit(expression); expression = new BlockHelperFunctionBinder(context).Visit(expression); expression = new HelperFunctionBinder(context).Visit(expression); expression = new BoolishConverter(context).Visit(expression); expression = new PathBinder(context).Visit(expression); expression = new SubExpressionVisitor(context).Visit(expression); expression = new HashParameterBinder().Visit(expression); return(expression); }