Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8');
} catch (e) {
assert(false, 'The BookForm.vue file does not exist');
}
// Parse document
const doc = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true });
const nodes = doc.childNodes;
// Parse for HTML in template
const template = nodes.filter(node => node.nodeName === 'template');
if (template.length == 0) {
assert(false, "The BookForm component does not contain a template tag")
}
const content = parse5.serialize(template[0].content);
const dom = new JSDOM(content, { includeNodeLocations: true, SVG_LCASE: true });
const document = dom.window.document;
// Test for for form existance
const results = document.querySelector('form');
if (results == null) {
assert(false, "The BookForm template does not contain a `form` tag.")
}
assert(results.length > 0, 'The BookForm template does not contain a `form` tag');
});
});
// Inject into the html
const indexSource = new webpack_sources_1.ReplaceSource(new webpack_sources_1.RawSource(inputContent), this._options.input);
const scriptElements = treeAdapter.createDocumentFragment();
for (const script of scripts) {
const attrs = [
{ name: 'type', value: 'text/javascript' },
{ name: 'src', value: (this._options.deployUrl || '') + script },
];
if (this._options.sri) {
const content = compilation.assets[script].source();
attrs.push(...this._generateSriAttributes(content));
}
const element = treeAdapter.createElement('script', undefined, attrs);
treeAdapter.appendChild(scriptElements, element);
}
indexSource.insert(scriptInsertionPoint, parse5.serialize(scriptElements, { treeAdapter }));
// Adjust base href if specified
if (typeof this._options.baseHref == 'string') {
let baseElement;
for (const headChild of headElement.childNodes) {
if (headChild.tagName === 'base') {
baseElement = headChild;
}
}
const baseFragment = treeAdapter.createDocumentFragment();
if (!baseElement) {
baseElement = treeAdapter.createElement('base', undefined, [
{ name: 'href', value: this._options.baseHref },
]);
treeAdapter.appendChild(baseFragment, baseElement);
indexSource.insert(headElement.__location.startTag.endOffset + 1, parse5.serialize(baseFragment, { treeAdapter }));
}
// `external:false` skips processing of external sheets
if (this.options.external !== false) {
const externalSheets = document.querySelectorAll('link[rel="stylesheet"]');
await Promise.all(externalSheets.map(
link => this.embedLinkedStylesheet(link, compilation, outputPath)
));
}
// go through all the style tags in the document and reduce them to only critical CSS
const styles = document.querySelectorAll('style');
await Promise.all(styles.map(
style => this.processStyle(style, document)
));
// serialize the document back to HTML and we're done
const html = parse5.serialize(document, PARSE5_OPTS);
return { html };
}
const noModuleScript = treeAdapter.createElement('script', undefined, nomodule.concat([
{name: 'src', value: `/${relative(s)}?v=${timestamp()}`},
]));
treeAdapter.appendChild(body, noModuleScript);
}
}
for (const s of params.filter(s => /\.css$/.test(s))) {
const stylesheet = treeAdapter.createElement('link', undefined, [
{name: 'rel', value: 'stylesheet'},
{name: 'href', value: `/${relative(s)}?v=${timestamp()}`},
]);
treeAdapter.appendChild(head, stylesheet);
}
const content = parse5.serialize(document, {treeAdapter});
write(outputFile, content, {encoding: 'utf-8'});
return 0;
}
Parse5DomAdapter.prototype.getInnerHTML = function (el) {
return parse5.serialize(this.templateAwareRoot(el), { treeAdapter: treeAdapter });
};
/**
processStyle (node, filePath, content) {
const lang = checkLang(node) || 'css'
let style = this.checkSrc(node, filePath)
const injectFnName = '__$styleInject'
if (!style) {
style = parse5.serialize(node)
const location = content.indexOf(style)
const before = padContent(content.slice(0, location))
style = before + style
}
let options = this.options.postcss
options.from = filePath
options.to = filePath
return this.compileAsPromise('style', style, lang, filePath)
.then((res) => {
return postcss(this.options.postcss.plugins || [])
.process(res.code, options)
.then((res) => {
const code = `export ${injectFnName}(${JSON.stringify(res.css)});`
return {code: code, type: 'style'}
})
})
Parse5DomAdapter.prototype.getInnerHTML = function (el) {
return parse5.serialize(this.templateAwareRoot(el), { treeAdapter: treeAdapter });
};
Parse5DomAdapter.prototype.getTemplateContent = function (el) { return null; };
getInnerHTML(el) {
return parse5$1.serialize(this.templateAwareRoot(el), { treeAdapter });
}
/**
async function parsePartial(
fn: typeof parse | typeof parseFragment,
strings: TemplateStringsArray,
...exps: any[]
) {
try {
const content = await processLiterals(strings, ...exps);
return serialize(fn(content));
} catch (e) {
throw e;
}
}