Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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();
}
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
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;
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"
};
}
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
}
})
}
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;
};
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',
};
}
function toDescriptor(source) {
return parse({
source: source,
compiler,
needMap: false
});
}