vue-template-babel-compiler
Advanced tools
Comparing version 1.0.0-0 to 1.0.0-1
@@ -78,3 +78,10 @@ 'use strict'; | ||
const matchWithRegex = new RegExp(escapeRegExp(`/*${WithStatementReplaceComment}*/`), 'g'); | ||
function compileRenderCode(code) { | ||
const withReplacement = 'var _vm=this;\n var _h=_vm.$createElement;\n var _c=_vm._self._c||_h;\n'; | ||
const functionalWithReplacement = 'var _c=_vm._c;\n'; | ||
function renderCompiler(code, options) { | ||
var _options$filename, _options$transforms; | ||
// TODO add customize individual options | ||
const fileNameHasFunctional = options === null || options === void 0 ? void 0 : (_options$filename = options.filename) === null || _options$filename === void 0 ? void 0 : _options$filename.includes((options === null || options === void 0 ? void 0 : options.functionalComponentFileIdentifier) || '.functional'); | ||
const isFunctional = fileNameHasFunctional || (options === null || options === void 0 ? void 0 : (_options$transforms = options.transforms) === null || _options$transforms === void 0 ? void 0 : _options$transforms.stripWithFunctional); | ||
const output = babel.transformSync(code, { | ||
@@ -86,6 +93,6 @@ filename: 'compiledTemplate', | ||
}); | ||
return output.code.replace(matchWithRegex, 'var _vm=this;\n var _h=_vm.$createElement;\n var _c=_vm._self._c||_h;\n'); | ||
return output.code.replace(matchWithRegex, isFunctional ? functionalWithReplacement : withReplacement); | ||
} | ||
const compiler = require('vue-template-compiler'); | ||
const templateCompiler = require('vue-template-compiler'); | ||
@@ -119,3 +126,3 @@ function toFunction(code, isFunctional) { | ||
const renderSeparator = '/* renderSeparator */'; | ||
function compileTemplateCode(source, options) { | ||
function compileTemplate(source, options) { | ||
var _options$transforms; | ||
@@ -130,3 +137,3 @@ | ||
errors | ||
} = compiler.compile(source, options); // TODO rm semicolon && \n : https://babeljs.io/docs/en/options#minified | ||
} = templateCompiler.compile(source, options); // TODO rm semicolon && \n : https://babeljs.io/docs/en/options#minified | ||
@@ -140,3 +147,3 @@ let code = `var render = ${toFunction(render, isFunctional)}` + ';' + renderSeparator; | ||
const [compiledRender, compiledStaticRenders] = compileRenderCode(code).split(renderSeparator); | ||
const [compiledRender, compiledStaticRenders] = renderCompiler(code, options).split(renderSeparator); | ||
return { | ||
@@ -150,14 +157,13 @@ ast, | ||
} | ||
function extendTemplateCompiler(obj) { | ||
for (const key in templateCompiler) { | ||
obj[key] = templateCompiler[key]; | ||
} | ||
module.exports = function (source, options) { | ||
let ret = {}; | ||
const compileRenderMode = Boolean(options === null || options === void 0 ? void 0 : options.transforms); | ||
obj.compile = compileTemplate; | ||
} | ||
if (compileRenderMode) { | ||
ret = compileRenderCode(source); | ||
} else { | ||
ret = compileTemplateCode(source, options); | ||
} | ||
const transpile = renderCompiler; // enhance vue-template-compiler with babel: | ||
return ret; | ||
}; | ||
extendTemplateCompiler(transpile); | ||
module.exports = transpile; |
{ | ||
"name": "vue-template-babel-compiler", | ||
"version": "1.0.0-0", | ||
"version": "1.0.0-1", | ||
"description": "Post compiler for Vue template render functions to support ES features with Babel", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10362
137