Skip to content

Improved precompile template version check #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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