Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should contain title interpolation in h1 @book-list-will-contain-title-interpolation', () => {
let file;
try {
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookList.vue'), 'utf8');
} catch (e) {
assert(false, 'The BookList.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 BookList component does not contain a template tag")
}
const content = parse5.serialize(template[0].content);
const dom = new JSDOM(content, { includeNodeLocations: true });
const document = dom.window.document;
// Test for booklist in the app div
const results = document.querySelector('h1');
assert(results != null, "The BookList template does not contain an h1 tag")
it('should contain correct styles @book-list-vue-will-have-correct-styles', () => {
let file;
try {
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookList.vue'), 'utf8');
} catch (e) {
assert(false, 'The BookList.vue file does not exist');
}
// Parse document and retrieve the style section
const doc = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true });
const nodes = doc.childNodes;
const styles = nodes.filter(node => node.nodeName === 'style');
if (styles.length == 0) {
assert(false, "The BookList.vue file does not contain a style element.")
}
if (styles[0].childNodes.length == 0) {
assert(false, "The BookList style tag does not contain any CSS rules.")
}
const style = styles[0].childNodes[0].value;
const parsed = cssom.parse(style);
const results = parsed.cssRules.find(node => node.selectorText);
assert(results.selectorText, 'The `"h1, h2"` selector is not present in BookList\'s styles');
scriptingEnabled: false,
treeAdapter: defaultAdapter
};
parse5.parse("", opt); // $ExpectType Document
opt = {
sourceCodeLocationInfo: true,
scriptingEnabled: false,
treeAdapter: defaultAdapter
};
parse5.parse("", opt); // $ExpectType Document
// parseFragment
const fragment = parse5.parseFragment("<div>");
fragment; // $ExpectType DocumentFragment
parse5.parseFragment("<div>", {});
parse5.parseFragment("<div>", { sourceCodeLocationInfo: true });
parse5.parseFragment("<div>", { treeAdapter: defaultAdapter });
parse5.parseFragment("<div>", {
sourceCodeLocationInfo: true,
treeAdapter: defaultAdapter
});
parse5.parseFragment("<div>", {
sourceCodeLocationInfo: true,
treeAdapter: defaultAdapter
});
const element = (parse5.parseFragment(</div></div></div></div></div></div>
const parseSvg = (
text: string,
additionalAttributes: parse5.AST.Default.Attribute[]
) => {
const parsedSVG = parse5.parseFragment(
text
) as parse5.AST.Default.DocumentFragment
const root = parsedSVG.childNodes.find(
node => node.nodeName === 'svg'
)! as parse5.AST.Default.Element
// if it's a super simple SVG, ignore it
const isSuperSimple = (node: parse5.AST.Default.Node): boolean => {
const elemnt = node as parse5.AST.Default.Element
if (!elemnt.childNodes) return true
const notSimpleElement = !['svg', 'path', 'g', 'defs', 'desc'].includes(
elemnt.nodeName
)
if (notSimpleElement) {
return false
}
function parseContent (content) {
// noinspection JSValidateTypes
return parse5.parseFragment(content, {locationInfo: true})
}
private _createRestoreStoragesScript (storageKey, storages) {
const scriptStr = createSelfRemovingScript(`
window.localStorage.setItem("${ storageKey }", ${ JSON.stringify(storages.localStorage) });
window.sessionStorage.setItem("${ storageKey }", ${ JSON.stringify(storages.sessionStorage) });
`);
const parsedDocumentFragment = parse5.parseFragment(scriptStr);
return parsedDocumentFragment.childNodes[0];
}
inTagMatch.forEach(e => {
const htmlFragment = parse5.parseFragment(e);
let _names = [];
if (htmlFragment && htmlFragment.childNodes && htmlFragment.childNodes[0]) {
let type = htmlFragment.childNodes[0].attrs.find(attr => ['type', '[type]', 'nztype', '[nztype]'].indexOf(attr.name) !== -1);
let theme = htmlFragment.childNodes[0].attrs.find(attr => ['theme', '[theme]', 'nztheme', '[nztheme]'].indexOf(attr.name) !== -1);
/**
* type="icon"
* nzType="icon"
*/
if (type && ['type', 'nztype'].indexOf(type.name) !== -1 && /^[A-Za-z]/g.test(type.value) && type.value.indexOf(' ') === -1) {
_names.push(type.value);
}
/**
* [type]="value ? 'icon' : 'icon'"
* [nzType]="value ? 'icon' : 'icon'"
setInnerHTML(el, value) {
this.clearNodes(el);
const /** @type {?} */ content = parse5$1.parseFragment(value, { treeAdapter });
for (let /** @type {?} */ i = 0; i < content.childNodes.length; i++) {
treeAdapter.appendChild(el, content.childNodes[i]);
}
}
/**
export function findElementsWithAttribute(html: string, attributeName: string) {
const document = parseFragment(html, {sourceCodeLocationInfo: true}) as DefaultTreeDocument;
const elements: DefaultTreeElement[] = [];
const visitNodes = nodes => {
nodes.forEach(node => {
if (node.childNodes) {
visitNodes(node.childNodes);
}
if (node.attrs && node.attrs.some(attr => attr.name === attributeName.toLowerCase())) {
elements.push(node);
}
});
};
visitNodes(document.childNodes);
export function parseFragmentUtil(ownerDocument: any, html: string) {
if (typeof html === 'string') {
html = html.trim();
} else {
html = '';
}
const frag = parseFragment(
html,
getParser(ownerDocument)
) as any;
return frag;
}