diff options
author | kpdecker <kpdecker@gmail.com> | 2015-12-24 09:43:36 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-12-26 18:49:28 -0600 |
commit | 118836f390ffa882c720426db94e6b6748e69242 (patch) | |
tree | c0767406262ceef65b3c7fd2bd0a1b9b6c1b8bf4 /lib/handlebars/compiler/compiler.js | |
parent | ee6fadffb47a129f27e74ad7fcb6c0735d7cc274 (diff) | |
download | handlebars.js-118836f390ffa882c720426db94e6b6748e69242.zip handlebars.js-118836f390ffa882c720426db94e6b6748e69242.tar.gz handlebars.js-118836f390ffa882c720426db94e6b6748e69242.tar.bz2 |
Throw exception if id tracking args are passed
Fixes #1151
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 040e99a..d120d28 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -421,41 +421,20 @@ Compiler.prototype = { } }; -export function precompile(input, options, env) { - if (input == null || (typeof input !== 'string' && input.type !== 'Program')) { - throw new Exception('You must pass a string or Handlebars AST to Handlebars.precompile. You passed ' + input); - } - - options = options || {}; - if (!('data' in options)) { - options.data = true; - } - if (options.compat) { - options.useDepths = true; - } +export function precompile(input, options = {}, env) { + validateInput(input, options); - let ast = env.parse(input, options), - environment = new env.Compiler().compile(ast, options); + let environment = compileEnvironment(input, options, env); return new env.JavaScriptCompiler().compile(environment, options); } export function compile(input, options = {}, env) { - if (input == null || (typeof input !== 'string' && input.type !== 'Program')) { - throw new Exception('You must pass a string or Handlebars AST to Handlebars.compile. You passed ' + input); - } - - if (!('data' in options)) { - options.data = true; - } - if (options.compat) { - options.useDepths = true; - } + validateInput(input, options); let compiled; function compileInput() { - let ast = env.parse(input, options), - environment = new env.Compiler().compile(ast, options), + let environment = compileEnvironment(input, options, env), templateSpec = new env.JavaScriptCompiler().compile(environment, options, undefined, true); return env.template(templateSpec); } @@ -469,6 +448,27 @@ export function compile(input, options = {}, env) { }; } +function validateInput(input, options) { + if (input == null || (typeof input !== 'string' && input.type !== 'Program')) { + throw new Exception('You must pass a string or Handlebars AST to Handlebars.compile. You passed ' + input); + } + + if (options.trackIds || options.stringParams) { + throw new Exception('TrackIds and stringParams are no longer supported. See Github #1145'); + } + + if (!('data' in options)) { + options.data = true; + } + if (options.compat) { + options.useDepths = true; + } +} +function compileEnvironment(input, options, env) { + let ast = env.parse(input, options); + return new env.Compiler().compile(ast, options); +} + function argEquals(a, b) { if (a === b) { return true; |