Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function genInlineComponentText(template, script) {
// https://github.com/vuejs/vue-loader/blob/423b8341ab368c2117931e909e2da9af74503635/lib/loaders/templateLoader.js#L46
const finalOptions = {
source: `<div>${template}</div>`,
filename: 'inline-component', // TODO:这里有待调整
compiler
};
const compiled = compileTemplate(finalOptions);
// tips
if (compiled.tips && compiled.tips.length) {
compiled.tips.forEach(tip => {
console.warn(tip);
});
}
// errors
if (compiled.errors && compiled.errors.length) {
console.error(
`\n Error compiling template:\n${pad(compiled.source)}\n` +
compiled.errors.map(e => ` - ${e}`).join('\n') +
'\n'
);
}
let demoComponentContent = `
${compiled.code}
// for vue-component-compiler
const finalOptions = {
source,
filename: this.resourcePath,
compiler,
compilerOptions,
// allow customizing behavior of vue-template-es2015-compiler
transpileOptions: options.transpileOptions,
transformAssetUrls: options.transformAssetUrls || true,
isProduction,
isFunctional,
optimizeSSR: isServer && options.optimizeSSR !== false,
prettify: options.prettify
}
const compiled = compileTemplate(finalOptions)
// tips
if (compiled.tips && compiled.tips.length) {
compiled.tips.forEach(tip => {
loaderContext.emitWarning(typeof tip === 'object' ? tip.msg : tip)
})
}
// errors
if (compiled.errors && compiled.errors.length) {
// 2.6 compiler outputs errors as objects with range
if (compiler.generateCodeFrame && finalOptions.compilerOptions.outputSourceRange) {
// TODO account for line offset in case template isn't placed at top
// of the file
loaderContext.emitError(
`\n\n Errors compiling template:\n\n` +
// for vue-component-compiler
const finalOptions = {
source,
filename: this.resourcePath,
compiler,
compilerOptions,
// allow customizing behavior of vue-template-es2015-compiler
transpileOptions: options.transpileOptions,
transformAssetUrls: options.transformAssetUrls || true,
isProduction,
isFunctional,
optimizeSSR: isServer && options.optimizeSSR !== false,
prettify: options.prettify
}
const compiled = compileTemplate(finalOptions)
// tips
if (compiled.tips && compiled.tips.length) {
compiled.tips.forEach(tip => {
loaderContext.emitWarning(typeof tip === 'object' ? tip.msg : tip)
})
}
// errors
if (compiled.errors && compiled.errors.length) {
// 2.6 compiler outputs errors as objects with range
if (compiler.generateCodeFrame && finalOptions.compilerOptions.outputSourceRange) {
// TODO account for line offset in case template isn't placed at top
// of the file
loaderContext.emitError(
`\n\n Errors compiling template:\n\n` +
const finalOptions = {
source,
filename: this.resourcePath,
compiler,
compilerOptions: Object.assign( {}, compilerOptions, {
imports: cOptions.imports,
} ),
// allow customizing behavior of vue-template-es2015-compiler
transpileOptions: options.transpileOptions,
transformAssetUrls: options.transformAssetUrls || true,
isProduction,
isFunctional,
optimizeSSR: false
}
const compiled = compileTemplate(finalOptions)
// tips
if (compiled.tips && compiled.tips.length) {
compiled.tips.forEach(tip => {
loaderContext.emitWarning(tip)
})
}
// errors
if (compiled.errors && compiled.errors.length) {
loaderContext.emitError(
`\n Error compiling template:\n${pad(compiled.source)}\n` +
compiled.errors.map(e => ` - ${e}`).join('\n') +
'\n'
)
}
function compileTemplate(template: string) {
const result = compileUtils.compileTemplate({
compiler,
source: template,
isProduction: true
} as any);
return result.code;
}
function processTemplate(template, filename, config) {
if (!template) {
return null
}
const vueJestConfig = getVueJestConfig(config)
if (template.src) {
template.content = loadSrc(template.src, filename)
}
const result = compilerUtils.compileTemplate({
source: template.content,
compiler: VueTemplateCompiler,
filename: filename,
compilerOptions: {
optimize: false
},
isFunctional: template.attrs.functional,
preprocessLang: template.lang,
preprocessOptions: vueJestConfig[template.lang]
})
logResultErrors(result)
return result
}
) {
if (!template) {
return '';
}
const content = retrieveAndTranspileContent(
filename,
template,
hook,
[ 'html' ],
globalConfig.transpileTemplates && transpileTemplateSpecial
);
const isFunctional = template.attrs.functional;
const compiled = compileTemplate({
source: content,
filename,
compiler,
compilerOptions: { preserveWhitespace: false },
isFunctional
});
return [
compiled.code,
`;${COMPONENT_OPTIONS}.render=render;`,
`${COMPONENT_OPTIONS}.staticRenderFns=staticRenderFns;`,
`${COMPONENT_OPTIONS}._compiled = true;`,
isFunctional ? `${COMPONENT_OPTIONS}.functional = true;` : ''
].join('\n');
}
module.exports = function compile (template, options = {}) {
const compiled = compileTemplate({
source: template,
filename: options.filename,
compiler,
transformAssetUrls: options.transformAssetUrls,
isFunctional: options.functional,
isProduction: options.isProduction,
optimizeSSR: options.optimizeSSR
})
if (compiled.errors.length > 0) {
return {
errors: compiled.errors,
code: empty
}
}