diff options
author | Peter Wagenet <peter.wagenet@gmail.com> | 2013-01-29 11:43:43 -0800 |
---|---|---|
committer | Peter Wagenet <peter.wagenet@gmail.com> | 2013-01-29 13:29:19 -0800 |
commit | d7758fe1a9abdb0643e84a4534d352ab37e3094b (patch) | |
tree | b4c482946379d8be88084844014bff2c0a1e719d | |
parent | a3376e24b1a25f72cf86d1d999bd2ea93fa4dc39 (diff) | |
download | handlebars.js-d7758fe1a9abdb0643e84a4534d352ab37e3094b.zip handlebars.js-d7758fe1a9abdb0643e84a4534d352ab37e3094b.tar.gz handlebars.js-d7758fe1a9abdb0643e84a4534d352ab37e3094b.tar.bz2 |
Check version when evaluating templates.
This makes sure that we throw an error when a template was precompiled
with a version of Handlebars that doesn't match the evaluating version.
-rw-r--r-- | dist/handlebars.js | 7 | ||||
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/dist/handlebars.js b/dist/handlebars.js index c91b30d..072ae53 100644 --- a/dist/handlebars.js +++ b/dist/handlebars.js @@ -1380,6 +1380,13 @@ Handlebars.JavaScriptCompiler = function() {}; // Perform a second pass over the output to merge content when possible var source = this.mergeSource(); + if (!this.isChild) { + source = "if (Handlebars.VERSION !== '"+Handlebars.VERSION+"') {\n"+ + "throw 'Template was compiled with "+Handlebars.VERSION+", but runtime is '+Handlebars.VERSION;\n"+ + "}\n"+ + source; + } + if (asObject) { params.push(source); diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 0d21739..b148bbb 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -538,6 +538,13 @@ Handlebars.JavaScriptCompiler = function() {}; // Perform a second pass over the output to merge content when possible var source = this.mergeSource(); + if (!this.isChild) { + source = "if (Handlebars.VERSION !== '"+Handlebars.VERSION+"') {\n"+ + "throw 'Template was compiled with "+Handlebars.VERSION+", but runtime is '+Handlebars.VERSION;\n"+ + "}\n"+ + source; + } + if (asObject) { params.push(source); |