UNPKG

wallaby-vue-compiler

Version:

Wallaby.js compiler to display code coverage in single file `.vue` components. Accepts another compiler (for the script section compilation) as a parameter.

32 lines (25 loc) 994 B
module.exports = function (scriptCompiler) { var compiler = require('vue-template-compiler'); var parseVueComponent = compiler.parseComponent.bind(compiler); // patching the original function because otherwise // vue-loader creates a second line padding compiler.parseComponent = function (content, opts) { return parseVueComponent(content); }; return function (file) { var output = parseVueComponent(file.content, {pad: 'line'}); if (!output.script) return {code: file.content, noScript: true}; var compilationResult = scriptCompiler({ path: file.path, content: output.script.content }); compilationResult.scriptRange = { start: output.script.start, end: output.script.start + compilationResult.code.length }; compilationResult.code = file.content.substring(0, compilationResult.scriptRange.start) + compilationResult.code + file.content.substring(output.script.end); return compilationResult; }; }