Skip to content

Commit

Permalink
Merge pull request #424 from wagenet/version-check-v2
Browse files Browse the repository at this point in the history
Improved precompile template version check
  • Loading branch information
wycats committed Jan 31, 2013
2 parents edb6f11 + 6fe7f17 commit 448e43c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
14 changes: 8 additions & 6 deletions dist/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -1381,10 +1381,7 @@ Handlebars.JavaScriptCompiler = function() {};
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;
source = "this.compiledVersion = '"+Handlebars.VERSION+"';\n"+source;
}

if (asObject) {
Expand Down Expand Up @@ -2126,12 +2123,17 @@ Handlebars.VM = {
}
},
programWithDepth: Handlebars.VM.programWithDepth,
noop: Handlebars.VM.noop
noop: Handlebars.VM.noop,
compiledVersion: null
};

return function(context, options) {
options = options || {};
return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
if (container.compiledVersion !== Handlebars.VERSION) {
throw "Template was compiled with "+(container.compiledVersion || 'unknown version')+", but runtime is "+Handlebars.VERSION;
}
return result;
};
},

Expand Down
9 changes: 7 additions & 2 deletions dist/handlebars.runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,17 @@ Handlebars.VM = {
}
},
programWithDepth: Handlebars.VM.programWithDepth,
noop: Handlebars.VM.noop
noop: Handlebars.VM.noop,
compiledVersion: null
};

return function(context, options) {
options = options || {};
return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
if (container.compiledVersion !== Handlebars.VERSION) {
throw "Template was compiled with "+(container.compiledVersion || 'unknown version')+", but runtime is "+Handlebars.VERSION;
}
return result;
};
},

Expand Down
5 changes: 1 addition & 4 deletions lib/handlebars/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,7 @@ Handlebars.JavaScriptCompiler = function() {};
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;
source = "this.compiledVersion = '"+Handlebars.VERSION+"';\n"+source;
}

if (asObject) {
Expand Down
9 changes: 7 additions & 2 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ Handlebars.VM = {
}
},
programWithDepth: Handlebars.VM.programWithDepth,
noop: Handlebars.VM.noop
noop: Handlebars.VM.noop,
compiledVersion: null
};

return function(context, options) {
options = options || {};
return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
if (container.compiledVersion !== Handlebars.VERSION) {
throw "Template was compiled with "+(container.compiledVersion || 'unknown version')+", but runtime is "+Handlebars.VERSION;
}
return result;
};
},

Expand Down

0 comments on commit 448e43c

Please sign in to comment.