Post compiler for Vue template render functions to support ES2015+ features
npx @tessl/cli install tessl/npm-vue-template-es2015-compiler@1.9.0Vue Template ES2015 Compiler is a post-processor for Vue.js template render functions that adds ES2015+ feature support and ensures strict-mode compliance. It transforms raw render functions generated by vue-template-compiler to support modern JavaScript features while maintaining broad browser compatibility.
npm install vue-template-es2015-compilerconst transpile = require("vue-template-es2015-compiler");const transpile = require("vue-template-es2015-compiler");
// Basic transpilation of render function code
const renderCode = 'function render() { return this.items.map(({ name, ...rest }) => h("div", rest, name)); }';
const transpiledCode = transpile(renderCode);
// With custom options
const customOptions = {
transforms: {
stripWith: true,
stripWithFunctional: false
},
objectAssign: 'Object.assign'
};
const transpiledWithOptions = transpile(renderCode, customOptions);Vue Template ES2015 Compiler is designed as a lightweight, single-purpose utility that:
Transforms JavaScript code with ES2015+ features to ensure compatibility and Vue.js-specific optimizations.
/**
* Transpiles JavaScript code with ES2015+ features for Vue.js templates
* @param {string} code - The JavaScript code to transpile
* @param {TranspileOptions} [opts] - Optional configuration options
* @returns {string} Transpiled JavaScript code
*/
function transpile(code, opts);Usage Examples:
const transpile = require("vue-template-es2015-compiler");
// Object spread transpilation
const spreadCode = 'const obj = { ...a, ...b };';
const result = transpile(spreadCode);
// Converts to: const obj = Object.assign({}, a, b);
// Arrow function transpilation in render context
const arrowCode = 'items.map(item => ({ ...item, processed: true }))';
const processed = transpile(arrowCode);
// With custom configuration
const customConfig = {
transforms: {
stripWith: false, // Keep 'with' blocks
modules: false
},
objectAssign: 'customAssign'
};
const customResult = transpile(spreadCode, customConfig);The transpiler uses the following default configuration when no options are provided:
transforms.modules: false - Module transforms are disabledtransforms.stripWith: true - 'with' blocks are stripped from Vue render functionstransforms.stripWithFunctional: false - Functional render context handling is disabledobjectAssign: 'Object.assign' - Object spread operations use Object.assign polyfill/**
* Configuration options for the transpile function
* @typedef {Object} TranspileOptions
* @property {Object} [transforms] - Transform configuration settings
* @property {boolean} [transforms.modules=false] - Whether to transform ES modules
* @property {boolean} [transforms.stripWith=true] - Whether to strip 'with' blocks from render functions
* @property {boolean} [transforms.stripWithFunctional=false] - Whether to handle functional render context
* @property {string} [objectAssign='Object.assign'] - Polyfill method for object spread operations
*/