All files / src/lib template-compiler.js

72.73% Statements 8/11
50% Branches 1/2
66.67% Functions 2/3
72.73% Lines 8/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231x 1x 1x   1x 1x 1x           1x               1x    
var chalk = require('chalk')
var vueCompiler = require('vue-template-compiler')
var transpile = require('vue-template-es2015-compiler')
 
module.exports = function compileTemplate (template) {
  var compiled = vueCompiler.compile(template)
  Iif (compiled.errors.length) {
    compiled.errors.forEach(function (msg) {
      console.error('\n' + chalk.red(msg) + '\n')
    })
    throw new Error('Vue template compilation failed')
  } else {
    return {
      render: toFunction(compiled.render),
      staticRenderFns: '[' + compiled.staticRenderFns.map(toFunction).join(',') + ']'
    }
  }
}
 
function toFunction (code) {
  return transpile('function render () {' + code + '}')
}