當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript dom5.predicates類代碼示例

本文整理匯總了TypeScript中dom5.predicates的典型用法代碼示例。如果您正苦於以下問題:TypeScript predicates類的具體用法?TypeScript predicates怎麽用?TypeScript predicates使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了predicates類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: attributeSelectorToPredicate

function attributeSelectorToPredicate(selector: cssWhat.Attribute):
    dom5.Predicate {
  switch (selector.action) {
    case 'exists':
      return dom5.predicates.hasAttr(selector.name);
    case 'equals':
      return dom5.predicates.hasAttrValue(selector.name, selector.value);
    case 'start':
      return (el) => {
        const attrValue = dom5.getAttribute(el, selector.name);
        return attrValue != null && attrValue.startsWith(selector.value);
      };
    case 'end':
      return (el) => {
        const attrValue = dom5.getAttribute(el, selector.name);
        return attrValue != null && attrValue.endsWith(selector.value);
      };
    case 'element':
      return dom5.predicates.hasSpaceSeparatedAttrValue(
          selector.name, selector.value);
    case 'any':
      return (el) => {
        const attrValue = dom5.getAttribute(el, selector.name);
        return attrValue != null && attrValue.includes(selector.value);
      };
  }
  const never: never = selector.action;
  throw new Error(
      `Unexpected type of attribute matcher from CSS parser ${never}`);
}
開發者ID:asdfg9822,項目名稱:polymer-linter,代碼行數:30,代碼來源:util.ts

示例2: 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}`);
}
開發者ID:asdfg9822,項目名稱:polymer-linter,代碼行數:26,代碼來源:util.ts

示例3: createLinks

export function createLinks(
    html: string,
    baseUrl: string,
    deps: Set<string>,
    absolute: boolean = false): string {
  const ast = parse5.parse(html, {locationInfo: true});
  const baseTag = dom5.query(ast, dom5.predicates.hasTagName('base'));
  const baseTagHref = baseTag ? dom5.getAttribute(baseTag, 'href') : '';

  // parse5 always produces a <head> element.
  const head = dom5.query(ast, dom5.predicates.hasTagName('head'))!;
  for (const dep of deps) {
    let href;
    if (absolute && !baseTagHref) {
      href = absUrl(dep);
    } else {
      href = relativeUrl(absUrl(baseUrl), absUrl(dep));
    }
    const link = dom5.constructors.element('link');
    dom5.setAttribute(link, 'rel', 'prefetch');
    dom5.setAttribute(link, 'href', href);
    dom5.append(head, link);
  }
  dom5.removeFakeRootElements(ast);
  return parse5.serialize(ast);
}
開發者ID:chrisekelley,項目名稱:polymer-build,代碼行數:26,代碼來源:prefetch-links.ts

示例4: _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;
  }
開發者ID:LostInBrittany,項目名稱:polymer-cli,代碼行數:35,代碼來源:bundle.ts

示例5:

 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;
 };
開發者ID:chrisekelley,項目名稱:polymer-build,代碼行數:8,代碼來源:bundle_test.ts

示例6: 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'))));
 });
開發者ID:Polymer,項目名稱:tools,代碼行數:9,代碼來源:bundler_test.ts

示例7: _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);
   }
 }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:15,代碼來源:html-bundler.ts

示例8: test

    test('works for elements', async () => {
      const liTags =
          dom5.queryAll(document.ast, dom5.predicates.hasTagName('li'));

      assert.equal(liTags.length, 4);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(liTags[0]!)!),
          `
        <li>1
        ~~~~~
        <li>2</li>
~~~~~~~~`);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(liTags[1]!)!),
          `
        <li>2</li>
        ~~~~~~~~~~`);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(liTags[2]!)), `
        <li><li>
        ~~~~`);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(liTags[3]!)), `
        <li><li>
            ~~~~
      </ul>
~~~~~~`);

      const pTags =
          dom5.queryAll(document.ast, dom5.predicates.hasTagName('p'));
      assert.equal(pTags.length, 2);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(pTags[0]!)), `
    <p>
    ~~~
      This is a paragraph without a closing tag.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    <p>This is a paragraph with a closing tag.</p>
~~~~`);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(pTags[1]!)), `
    <p>This is a paragraph with a closing tag.</p>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`);
    });
開發者ID:asdfg9822,項目名稱:polymer-analyzer,代碼行數:50,代碼來源:html-document_test.ts

示例9: ParsedHtmlDocument

  /**
   * 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,
    });
  }
開發者ID:asdfg9822,項目名稱:polymer-analyzer,代碼行數:39,代碼來源:html-parser.ts


注:本文中的dom5.predicates類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。