Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
compiled.errors.map(e => ` - ${e}`).join('\n') +
'\n'
)
);
code = 'module.exports={render:function(){},staticRenderFns:[]}';
} else {
const bubleOptions = options.buble;
const stripWith = bubleOptions.transforms.stripWith !== false;
const stripWithFunctional = bubleOptions.transforms.stripWithFunctional;
const staticRenderFns = compiled.staticRenderFns.map(fn =>
toFunction(fn, stripWithFunctional)
);
code =
transpile(
'var render = ' +
toFunction(compiled.render, stripWithFunctional) +
'\n' +
'var staticRenderFns = [' +
staticRenderFns.join(',') +
']',
bubleOptions
) + '\n';
// mark with stripped (this enables Vue to use correct runtime proxy detection)
if (stripWith) {
code += `render._withStripped = true\n`;
}
const exports = `{ render: render, staticRenderFns: staticRenderFns }`;
code += `module.exports = ${exports}`;
}
// render function with extra ES2015 features,
// and most importantly striping with and supports functional.
const bubleOptions = {
transforms: {
stripWith: true,
stripWithFunctional: stripWithFunctional
}
}
const staticRenderFns = compiled.staticRenderFns.map(fn =>
toFunction(fn, stripWithFunctional)
)
let code =
transpile(
'var render = ' +
toFunction(compiled.render, stripWithFunctional) +
'\n' +
'var staticRenderFns = [' +
staticRenderFns.join(',') +
']',
bubleOptions
) + '\n'
if (bubleOptions.transforms.stripWith) {
// mark with stripped (this enables Vue to use correct runtime proxy detection)
code += `render._withStripped = true\n`
}
code += `export { render, staticRenderFns }`
const sourceUrl = url + '#source'
compiled.errors.map(e => ` - ${e}`).join('\n') +
'\n'
)
);
code = 'module.exports={render:function(){},staticRenderFns:[]}';
} else {
const bubleOptions = options.buble;
const stripWith = bubleOptions.transforms.stripWith !== false;
const { stripWithFunctional } = bubleOptions.transforms;
const staticRenderFns = compiled.staticRenderFns.map(fn =>
toFunction(fn, stripWithFunctional)
);
code =
transpile(
'var render = ' +
toFunction(compiled.render, stripWithFunctional) +
'\n' +
'var staticRenderFns = [' +
staticRenderFns.join(',') +
']',
bubleOptions
) + '\n';
// mark with stripped (this enables Vue to use correct runtime proxy detection)
if (stripWith) {
code += `render._withStripped = true\n`;
}
const exports = `{ render: render, staticRenderFns: staticRenderFns }`;
code += `module.exports = ${exports}`;
}
export function renderJs (rawScript, render, lang, id, options) {
const { matches, script } = findInjectionPosition(rawScript)
if (matches && matches.length) {
let renderScript = 'module.exports={' +
`render: ${wrapRenderFunction(render.render)},` +
'staticRenderFns: [' +
`${render.staticRenderFns.map(wrapRenderFunction).join(',')}],}`
if (options.stripWith !== false) {
renderScript = transpileVueTemplate(renderScript, options.vue)
}
return script.split(matches[1]).join(renderScript.replace('module.exports={', matches[1]).replace(/\}$/, ''))
}
throw new Error(
`[rollup-plugin-vue] Generated render function is injected in the default export of .vue file (lang: ${lang}). In ${id}, it cannot find 'export defaults'.`
)
}
export function moduleJs (rawScript, modules, lang, id, options) {
function toFunction (code) {
return transpile('(function(){' + code + '})').slice(1, -1)
}
function toFunction (code) {
return transpile('(function(){' + code + '})').slice(1, -1)
}