47adcda485
- Handle path-separators properly. Use "path.sep" instead of "/". Or use "require.resolve()" if possible - Use "execFile" instead of "exec" to run the Handlebars executable. This prevents problems due to (missing) shell escaping. - Use explicit call to "node" in order to run the executable on Windows. - Add "appveyor"-CI in order to run regular tests on Windows.
37 lines
917 B
JavaScript
37 lines
917 B
JavaScript
require('./common');
|
|
|
|
var fs = require('fs'),
|
|
vm = require('vm');
|
|
|
|
global.Handlebars = 'no-conflict';
|
|
|
|
var filename = 'dist/handlebars.js';
|
|
if (global.minimizedTest) {
|
|
filename = 'dist/handlebars.min.js';
|
|
}
|
|
var distHandlebars = fs.readFileSync(require.resolve(`../../${filename}`), 'utf-8');
|
|
vm.runInThisContext(distHandlebars, filename);
|
|
|
|
global.CompilerContext = {
|
|
browser: true,
|
|
|
|
compile: function(template, options) {
|
|
var templateSpec = handlebarsEnv.precompile(template, options);
|
|
return handlebarsEnv.template(safeEval(templateSpec));
|
|
},
|
|
compileWithPartial: function(template, options) {
|
|
return handlebarsEnv.compile(template, options);
|
|
}
|
|
};
|
|
|
|
function safeEval(templateSpec) {
|
|
/*eslint-disable no-eval, no-console */
|
|
try {
|
|
return eval('(' + templateSpec + ')');
|
|
} catch (err) {
|
|
console.error(templateSpec);
|
|
throw err;
|
|
}
|
|
/*eslint-enable no-eval, no-console */
|
|
}
|