How to use the @vue/component-compiler-utils.parse function in @vue/component-compiler-utils

To help you get started, we’ve selected a few @vue/component-compiler-utils 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 vuejs / vue-loader / lib / index.js View on Github external
resourceQuery
  } = loaderContext

  const rawQuery = resourceQuery.slice(1)
  const inheritQuery = `&${rawQuery}`
  const incomingQuery = qs.parse(rawQuery)
  const options = loaderUtils.getOptions(loaderContext) || {}

  const isServer = target === 'node'
  const isShadow = !!options.shadowMode
  const isProduction = options.productionMode || minimize || process.env.NODE_ENV === 'production'
  const filename = path.basename(resourcePath)
  const context = rootContext || process.cwd()
  const sourceRoot = path.dirname(path.relative(context, resourcePath))

  const descriptor = parse({
    source,
    compiler: options.compiler || loadTemplateCompiler(loaderContext),
    filename,
    sourceRoot,
    needMap: sourceMap
  })

  // if the query has a type field, this is a language block request
  // e.g. foo.vue?type=template&id=xxxxx
  // and we will return early
  if (incomingQuery.type) {
    return selectBlock(
      descriptor,
      loaderContext,
      incomingQuery,
      !!options.appendExtension
github Polyconseil / easygettext / src / extract.js View on Github external
function preprocessTemplate(data, type) {
  let templateData = data;
  switch (type) {
  case 'jade':
  case 'pug':
    // Add empty require function to the context to avoid errors with webpack require inside pug
    templateData = pug.render(data, {filename: 'source.html', pretty: true, require: function() {}});
    break;
  case 'vue':
    const vueFile = vueCompiler.parse({ compiler, source: data, needMap: false});
    if (!vueFile.template) return '';  // return an empty string
    templateData = vueFile.template.content;
    if (vueFile.template.lang) {
      return preprocessTemplate(templateData, vueFile.template.lang);
    }
    break;
  default:
    break;
  }
  return templateData.trim();
}
github chrisvfritz / hello-vue-components / build-utils / build-lib.js View on Github external
filter: filePath => {
      return !/\.unit\.js$/.test(filePath)
    }
  })
  fs.writeFileSync(
    path.resolve(destPackageFolder, 'index.js'),
    `\
export * from './src${componentName ? '/' + componentName + '.vue' : ''}'
`
  )

  let description = libConfig.description
  let example
  if (componentName) {
    const srcFilePath = getPath(`../src/${componentName}.vue`)
    const result = parseComponent({
      source: fs.readFileSync(srcFilePath, { encoding: 'utf8' }),
      filename: srcFilePath,
      compiler: require('vue-template-compiler')
    })
    description = JSON.parse(
      result.customBlocks.find(block => block.type === 'meta').content
    ).description
    example = result.customBlocks
      .find(block => block.type === 'example')
      .content.trim()
  }
  const packageConfig = {
    name: packageName,
    moduleName: componentName || _.upperFirst(_.camelCase(packageName)),
    description,
    example
github Enalean / tuleap / tools / utils / scripts / gettext / file-extractor.js View on Github external
function extractFromVueFile(file, file_path, gettext_extractor, gettext_parser) {
    const sfc_descriptor = vueParser.parse({
        source: file,
        filename: file_path,
        compiler: vueTemplateCompiler,
        needMap: false,
    });

    if (sfc_descriptor.script !== null) {
        extractFromVueScript(sfc_descriptor.script);
    }
    if (sfc_descriptor.template !== null) {
        extractFromTemplate(sfc_descriptor.template);
    }

    function extractFromVueScript(script_block) {
        const lang = script_block.lang !== null ? script_block.lang : "js";
        const scriptKind = lang === "ts" ? ts.ScriptKind.TS : ts.ScriptKind.JS;
github Enalean / tuleap / tools / utils / scripts / gettext / extract.js View on Github external
function preprocessVueFile(data) {
    const vueFile = vueCompiler.parse({ compiler, source: data, needMap: false });
    if (!vueFile.script) {
        return null;
    }
    return {
        content: vueFile.script.content.trim(),
        lang: vueFile.script.lang || "js"
    };
}
github kazupon / vue-i18n-locale-message / src / reflector.ts View on Github external
return components.map(target => {
    const desc = parse({
      source: target.content,
      filename: target.path,
      compiler: compiler as VueTemplateCompiler
    })
    const { contentPath, component, messageHierarchy } = parsePath(basePath, target.path)
    const cm = ''
    return {
      contentPath,
      content: cm,
      blocks: desc.customBlocks,
      component,
      messageHierarchy
    }
  })
}
github mya-ake / vuepress-plugin-component-catalog / src / build / markdown.js View on Github external
const createDocContent = context => {
  const source = readFile(context.filePathname);
  const descriptor = parse({
    source,
    compiler,
    filename: context.filename,
  });
  const docsBlock = extractDocs(descriptor.customBlocks);
  if (typeof docsBlock === 'undefined') {
    return null;
  }
  context.existDoc = true;
  return docsBlock.content;
};
github Polyconseil / easygettext / src / extract.js View on Github external
function preprocessVueFile(data) {
  const vueFile = vueCompiler.parse({ compiler, source: data, needMap: false });
  if (!vueFile.script) {
    return null;
  }
  return {
    content: vueFile.script.content.trim(),
    lang: vueFile.script.lang || 'js',
  };
}
github mrodal / vue-inheritance-loader / src / index.js View on Github external
function toDescriptor(source) {
  return parse({
    source: source,
    compiler,
    needMap: false
  });
}

@vue/component-compiler-utils

Lower level utilities for compiling Vue single file components

MIT
Latest version published 3 years ago

Package Health Score

66 / 100
Full package analysis