本文整理匯總了TypeScript中dom5.predicates.OR方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript predicates.OR方法的具體用法?TypeScript predicates.OR怎麽用?TypeScript predicates.OR使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dom5.predicates
的用法示例。
在下文中一共展示了predicates.OR方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: simpleSelectorToPredicate
function simpleSelectorToPredicate(
selector: cssWhat.Simple, isPolymerTemplate: boolean) {
switch (selector.type) {
case 'adjacent':
case 'child':
case 'descendant':
case 'parent':
case 'sibling':
case 'pseudo':
throw new Error(`Unsupported CSS operator: ${selector.type}`);
case 'attribute':
if (isPolymerTemplate) {
return dom5.predicates.OR(
attributeSelectorToPredicate(selector),
attributeSelectorToPredicate(
{...selector, name: selector.name + '$'}));
}
return attributeSelectorToPredicate(selector);
case 'tag':
return dom5.predicates.hasTagName(selector.name);
case 'universal':
return () => true;
}
const never: never = selector;
throw new Error(`Unexpected node type from css parser: ${never}`);
}
示例2: test
test('bundle documents should not have tags added to them', async () => {
const {ast} = await bundle('imports/simple-import.html');
assert.isNull(dom5.query(
ast,
dom5.predicates.OR(
dom5.predicates.hasTagName('html'),
dom5.predicates.hasTagName('head'),
dom5.predicates.hasTagName('body'))));
});
示例3: elementSelectorToPredicate
export function elementSelectorToPredicate(
simpleSelector: string,
isPolymerTemplate: boolean = false): dom5.Predicate {
const parsed = cssWhat(simpleSelector);
// The output of cssWhat is two levels of arrays. The outer level are any
// selectors joined with a comma, so it matches if any of the inner selectors
// match. The inner array are simple selectors like `.foo` and `#bar` which
// must all match.
return dom5.predicates.OR(...parsed.map((simpleSelectors) => {
return dom5.predicates.AND(...simpleSelectors.map(
(selector) => simpleSelectorToPredicate(selector, isPolymerTemplate)));
}));
}
示例4:
// 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'));
export const styleMatcher: Matcher = predicates.AND(