How to use the vue-template-compiler.compile function in vue-template-compiler

To help you get started, we’ve selected a few vue-template-compiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codesandbox / codesandbox-client / src / sandbox / eval / transpilers / vue / template-compiler / loader.js View on Github external
const defaultModules = [
    transformRequire(options.transformRequire, loaderContext),
    transformSrcset(),
  ];
  const userModules = vueOptions.compilerModules || options.compilerModules;

  const compilerOptions = {
    preserveWhitespace: options.preserveWhitespace,
    modules: defaultModules.concat(userModules || []),
    directives:
      vueOptions.compilerDirectives || options.compilerDirectives || {},
    scopeId: options.hasScoped ? options.id : null,
    comments: options.hasComment,
  };

  const compiled = compiler.compile(html, compilerOptions);

  // tips
  if (compiled.tips && compiled.tips.length) {
    compiled.tips.forEach(tip => {
      loaderContext.emitWarning({
        name: 'vue-warning',
        message: tip,
        fileName: loaderContext._module.module.parent
          ? loaderContext._module.module.parent.path
          : loaderContext.path,
        lineNumber: 1,
        columnNumber: 1,
        source: 'vue-template-compiler',
      });
    });
  }
github locoslab / vue-typescript-jest / preprocessor.js View on Github external
let script = ''
	if (!parts.script.lang) {
		script = babel(parts.script.content)
	} else {
		throw filePath + ': unknown 
github vue-styleguidist / vue-docgen-api / src / template-handlers / __tests__ / propHandler.ts View on Github external
it('should match props in interpolated text', () => {
    const ast = compile(
      [
        '<div>',
        '  <h1>titleof the template</h1>',
        '  <button style="width:200px">',
        '    ',
        '    ',
        '    test {{props.name}} {{props.adress}}',
        '  </button>',
        '</div>',
      ].join('\n'),
      { comments: true },
    ).ast
    if (ast) {
      traverse(ast, doc, [propHandler], { functional: true, rootLeadingComment: '' })
      expect(doc.toObject().props).toMatchObject({
        name: { type: { name: 'mixed' }, description: 'Your Name' },
github LinusBorg / vue-cli-plugin-test-attrs / tests / unit / lib.spec.js View on Github external
function generateRender(options) {
  const compilerModule = generateCompilerModule(options)

  const { render } = compiler.compile(template, {
    modules: [compilerModule],
  })

  return render
}
github vue-styleguidist / vue-styleguidist / packages / vue-docgen-api / src / utils / __tests__ / extractLeadingComment.ts View on Github external
function compileIt(src: string): ASTElement | undefined {
	const ast = compile(src, { comments: true }).ast
	if (ast) {
		const firstHeader = ast.children.filter((a: ASTElement) => a.tag === 'h1') as ASTElement[]
		if (firstHeader.length) {
			return firstHeader[0]
		}
	}
	return ast
}
github egoist / babel-plugin-transform-vue-template / index.js View on Github external
function compilePath(t, path, template) {
  const { errors, tips, render, staticRenderFns } = compile(template)

  if (errors.length > 0) {
    errors.forEach(error => console.error(error))
  }
  if (tips.length > 0) {
    tips.forEach(tip => console.log(tip))
  }

  const renderFnValue = babelTemplate(stripWith(toFunction(render, 'render')))()
  renderFnValue.type = 'FunctionExpression'

  const staticRenderFnsValue = babelTemplate(
    stripWith(`[${staticRenderFns.map(fn => toFunction(fn)).join(',')}]`)
  )().expression

  path.parentPath.replaceWithMultiple([
github fuse-box / fuse-box / src / plugins / vue / VueTemplateFile.ts View on Github external
					.then(() => vueCompiler.compile(this.contents));
			}, Promise.resolve())
github Enalean / tuleap / tools / utils / scripts / gettext / file-extractor.js View on Github external
function extractFromTemplate(template_block) {
        const compiled = vueTemplateCompiler.compile(template_block.content);
        if (compiled.errors.length > 0) {
            compiled.errors.forEach((error) => log(error));
            throw new Error(`Error during Vue template compilation for file: ${file_path}`);
        }
        parseNode(compiled.ast);
    }
github vuejs / systemjs-plugin-vue / index.js View on Github external
function compileTemplateAsModule (name, template) {
  name = getTemplateModuleName(name)
  var fns = vueCompiler.compile(template)
  return `System.set(${JSON.stringify(name)},System.newModule({\n` +
    `render:${toFn(fns.render)},\n` +
    `staticRenderFns:[${fns.staticRenderFns.map(toFn).join(',')}]\n` +
  `}));`
}