Code coverage report for spec/env/runtime.js

Statements: 34.62% (9 / 26)      Branches: 100% (0 / 0)      Functions: 0% (0 / 5)      Lines: 34.62% (9 / 26)      Ignored: none     

All files » spec/env/ » runtime.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49  1   1       1 1   1 1 1   1                                                   1                
/*global handlebarsEnv */
require('./common');
 
var _ = require('underscore'),
    fs = require('fs'),
    vm = require('vm');
 
global.Handlebars = undefined;
vm.runInThisContext(fs.readFileSync(__dirname + '/../../dist/handlebars.runtime.js'), 'dist/handlebars.runtime.js');
 
var parse = require('../../dist/cjs/handlebars/compiler/base').parse;
var compiler = require('../../dist/cjs/handlebars/compiler/compiler');
var JavaScriptCompiler = require('../../dist/cjs/handlebars/compiler/javascript-compiler')['default'];
 
global.CompilerContext = {
  compile: function(template, options) {
    // Hack the compiler on to the environment for these specific tests
    handlebarsEnv.precompile = function(template, options) {
      return compiler.precompile(template, options, handlebarsEnv);
    };
    handlebarsEnv.parse = parse;
    handlebarsEnv.Compiler = compiler.Compiler;
    handlebarsEnv.JavaScriptCompiler = JavaScriptCompiler;
 
    var templateSpec = handlebarsEnv.precompile(template, options);
    return handlebarsEnv.template(safeEval(templateSpec));
  },
  compileWithPartial: function(template, options) {
    // Hack the compiler on to the environment for these specific tests
    handlebarsEnv.compile = function(template, options) {
      return compiler.compile(template, options, handlebarsEnv);
    };
    handlebarsEnv.parse = parse;
    handlebarsEnv.Compiler = compiler.Compiler;
    handlebarsEnv.JavaScriptCompiler = JavaScriptCompiler;
 
    return handlebarsEnv.compile(template, options);
  }
};
 
function safeEval(templateSpec) {
  try {
    return eval('(' + templateSpec + ')');
  } catch (err) {
    console.error(templateSpec);
    throw err;
  }
}