Files
handlebars.js/lib/handlebars/compiler/base.js
T
kpdecker 928ba56b95 Rework strip flags to make clearer at in AST level
Rather than keeping state in the AST, which requires some gymnastics, we create a separate visitor flow which does the top down iteration necessary to calculate all of the state needed for proper whitespace control evaluation.
2014-11-28 23:13:06 -06:00

26 lines
687 B
JavaScript

import parser from "./parser";
import AST from "./ast";
import WhitespaceControl from "./whitespace-control";
module Helpers from "./helpers";
import { extend } from "../utils";
export { parser };
var yy = {};
extend(yy, Helpers, AST);
export function parse(input, options) {
// Just return if an already-compile AST was passed in.
if (input.type === 'Program') { return input; }
parser.yy = yy;
// Altering the shared object here, but this is ok as parser is a sync operation
yy.locInfo = function(locInfo) {
return new yy.SourceLocation(options && options.srcName, locInfo);
};
var strip = new WhitespaceControl();
return strip.accept(parser.parse(input));
}