本文整理汇总了TypeScript中dom5/lib/index-next.predicates.OR方法的典型用法代码示例。如果您正苦于以下问题:TypeScript predicates.OR方法的具体用法?TypeScript predicates.OR怎么用?TypeScript predicates.OR使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dom5/lib/index-next.predicates
的用法示例。
在下文中一共展示了predicates.OR方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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)));
}));
}