本文整理匯總了TypeScript中dom5.predicates.AND方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript predicates.AND方法的具體用法?TypeScript predicates.AND怎麽用?TypeScript predicates.AND使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dom5.predicates
的用法示例。
在下文中一共展示了predicates.AND方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: parse
/**
* Parse html into ASTs.
*
* @param {string} htmlString an HTML document.
* @param {string} href is the path of the document.
*/
parse(
contents: string, url: ResolvedUrl, urlResolver: UrlResolver,
inlineInfo?: InlineDocInfo<any>): ParsedHtmlDocument {
const ast = parseHtml(contents, {locationInfo: true});
// There should be at most one <base> tag and it must be inside <head> tag.
const baseTag = query(
ast,
p.AND(
p.parentMatches(p.hasTagName('head')),
p.hasTagName('base'),
p.hasAttr('href')));
let baseUrl;
if (baseTag) {
const baseHref = getAttribute(baseTag, 'href')! as FileRelativeUrl;
baseUrl = urlResolver.resolve(baseHref, url, undefined);
} else {
baseUrl = url;
}
const isInline = !!inlineInfo;
inlineInfo = inlineInfo || {};
return new ParsedHtmlDocument({
url,
baseUrl,
contents,
ast,
locationOffset: inlineInfo.locationOffset,
astNode: inlineInfo.astNode,
isInline,
});
}
示例2: _addSharedImportsToShell
_addSharedImportsToShell(bundles: Map<string, string[]>): string {
console.assert(this.shell != null);
let shellDeps = bundles.get(this.shell)
.map((d) => path.relative(path.dirname(this.shell), d));
let file = this.analyzer.files.get(this.shell);
console.assert(file != null);
let contents = file.contents.toString();
let doc = dom5.parse(contents);
let imports = dom5.queryAll(doc, dom5.predicates.AND(
dom5.predicates.hasTagName('link'),
dom5.predicates.hasAttrValue('rel', 'import')
));
// Remove all imports that are in the shared deps list so that we prefer
// the ordering or shared deps. Any imports left should be independent of
// ordering of shared deps.
let shellDepsSet = new Set(shellDeps);
for (let _import of imports) {
if (shellDepsSet.has(dom5.getAttribute(_import, 'href'))) {
dom5.remove(_import);
}
}
// Append all shared imports to the end of <head>
let head = dom5.query(doc, dom5.predicates.hasTagName('head'));
for (let dep of shellDeps) {
let newImport = dom5.constructors.element('link');
dom5.setAttribute(newImport, 'rel', 'import');
dom5.setAttribute(newImport, 'href', dep);
dom5.append(head, newImport);
}
let newContents = dom5.serialize(doc);
return newContents;
}
示例3:
const hasMarker = (doc: ASTNode, id: string) => {
const marker = dom5.query(
doc,
dom5.predicates.AND(
dom5.predicates.hasTagName('div'),
dom5.predicates.hasAttrValue('id', id)));
return marker != null;
};
示例4: _moveUnhiddenHtmlImportsIntoHiddenDiv
/**
* Move any remaining htmlImports that are not inside the hidden div
* already, into the hidden div.
*/
private _moveUnhiddenHtmlImportsIntoHiddenDiv(ast: ASTNode) {
const unhiddenHtmlImports = dom5.queryAll(
ast,
dom5.predicates.AND(
matchers.eagerHtmlImport,
dom5.predicates.NOT(matchers.inHiddenDiv)));
for (const htmlImport of unhiddenHtmlImports) {
removeElementAndNewline(htmlImport);
dom5.append(this._findOrCreateHiddenDiv(ast), htmlImport);
}
}
示例5: _addSharedImportsToShell
_addSharedImportsToShell(bundles: Map<string, string[]>): string {
console.assert(this.shell != null);
let shellUrl = urlFromPath(this.root, this.shell);
let shellUrlDir = posixPath.dirname(shellUrl);
let shellDeps = bundles.get(shellUrl)
.map((d) => posixPath.relative(shellUrlDir, d));
logger.debug('found shell dependencies', {
shellUrl: shellUrl,
shellUrlDir: shellUrlDir,
shellDeps: shellDeps,
});
let file = this.analyzer.getFile(this.shell);
console.assert(file != null);
let contents = file.contents.toString();
let doc = dom5.parse(contents);
let imports = dom5.queryAll(doc, dom5.predicates.AND(
dom5.predicates.hasTagName('link'),
dom5.predicates.hasAttrValue('rel', 'import')
));
logger.debug('found html import elements', {
imports: imports.map((el) => dom5.getAttribute(el, 'href')),
});
// Remove all imports that are in the shared deps list so that we prefer
// the ordering or shared deps. Any imports left should be independent of
// ordering of shared deps.
let shellDepsSet = new Set(shellDeps);
for (let _import of imports) {
let importHref = dom5.getAttribute(_import, 'href');
if (shellDepsSet.has(importHref)) {
logger.debug(`removing duplicate import element "${importHref}"...`);
dom5.remove(_import);
}
}
// Append all shared imports to the end of <head>
let head = dom5.query(doc, dom5.predicates.hasTagName('head'));
for (let dep of shellDeps) {
let newImport = dom5.constructors.element('link');
dom5.setAttribute(newImport, 'rel', 'import');
dom5.setAttribute(newImport, 'href', dep);
dom5.append(head, newImport);
}
let newContents = dom5.serialize(doc);
return newContents;
}
示例6: test
test('with 2 entrypoints and shell, all deps in their places', async () => {
const analyzer = getAnalyzer();
const {documents} =
await bundleMultiple([shell, entrypoint1, entrypoint2], {
strategy: generateShellMergeStrategy(analyzer.resolveUrl(shell)!, 2)
});
assert.equal(documents.size, 3);
const shellDoc = documents.get(shell)!.ast as dom5.Node;
assert.isDefined(shellDoc);
const entrypoint1Doc = documents.get(entrypoint1)!.ast as dom5.Node;
assert.isDefined(entrypoint1Doc);
const entrypoint2Doc = documents.get(entrypoint2)!.ast as dom5.Node;
assert.isDefined(entrypoint2Doc);
const shellDiv = dom5.predicates.hasAttrValue('id', 'shell');
const shellImport = dom5.predicates.AND(
dom5.predicates.hasTagName('link'),
dom5.predicates.hasSpaceSeparatedAttrValue('rel', 'import'),
dom5.predicates.hasAttrValue('href', 'shell.html'));
const commonModule = domModulePredicate('common-module');
const elOne = domModulePredicate('el-one');
const elTwo = domModulePredicate('el-two');
const depOne = domModulePredicate('el-dep1');
const depTwo = domModulePredicate('el-dep2');
// Check that all the dom modules are in their expected shards
assertContainsAndExcludes(
shellDoc, [shellDiv, commonModule, depOne], [elOne, elTwo, depTwo]);
assertContainsAndExcludes(
entrypoint1Doc,
[elOne],
[commonModule, elTwo, depOne, depTwo, shellImport]);
assertContainsAndExcludes(
entrypoint2Doc,
[elTwo, depTwo],
[commonModule, elOne, depOne, shellImport]);
});
示例7:
*/
// jshint node: true
'use strict';
import constants from './constants';
import {predicates} from 'dom5';
import * as parse5 from 'parse5';
export interface Matcher { (node: parse5.ASTNode): boolean; }
// TODO(aomarks) Look at what's using this matcher. A number of code paths
// should probably not be excluding type=module scripts.
export const nonModuleScript: Matcher = predicates.AND(
predicates.hasTagName('script'),
predicates.OR(
predicates.NOT(predicates.hasAttr('type')),
predicates.hasAttrValue('type', 'text/javascript'),
predicates.hasAttrValue('type', 'application/javascript')));
export const moduleScript: Matcher = predicates.AND(
predicates.hasTagName('script'), predicates.hasAttrValue('type', 'module'));
export const externalStyle: Matcher = predicates.AND(
predicates.hasTagName('link'),
predicates.hasAttrValue('rel', 'stylesheet'));
// polymer specific external stylesheet
export const polymerExternalStyle: Matcher = predicates.AND(
predicates.hasTagName('link'),
predicates.hasAttrValue('rel', 'import'),
predicates.hasAttrValue('type', 'css'));
示例8: require
import {predicates as p} from 'dom5';
import * as parse5 from 'parse5';
import * as url from 'url';
import File = require('vinyl');
import {AsyncTransformStream, getFileContents} from './streams';
const attrValueMatches = (attrName: string, regex: RegExp) => {
return (node: parse5.ASTNode) => {
const attrValue = dom5.getAttribute(node, attrName);
return attrValue != null && regex.test(attrValue);
};
};
const webcomponentsLoaderRegex = /\bwebcomponents\-(loader|lite)\.js\b/;
const webcomponentsLoaderMatcher = p.AND(
p.hasTagName('script'), attrValueMatches('src', webcomponentsLoaderRegex));
/**
* Wraps `addCustomElementsEs5Adapter()` in a `stream.Transform`.
*/
export class CustomElementsEs5AdapterInjector extends
AsyncTransformStream<File, File> {
constructor() {
super({objectMode: true});
}
protected async *
_transformIter(files: AsyncIterable<File>): AsyncIterable<File> {
for await (const file of files) {
if (file.contents === null || file.extname !== '.html') {
yield file;
示例9: simpleSelectorToPredicate
return dom5.predicates.OR(...parsed.map((simpleSelectors) => {
return dom5.predicates.AND(...simpleSelectors.map(
(selector) => simpleSelectorToPredicate(selector, isPolymerTemplate)));
}));