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


TypeScript dom5.queryAll函數代碼示例

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


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

示例1: _rewriteAstToEmulateBaseTag

 /**
  * Given an import document with a base tag, transform all of its URLs and
  * set link and form target attributes and remove the base tag.
  */
 private _rewriteAstToEmulateBaseTag(ast: ASTNode, docUrl: ResolvedUrl) {
   const baseTag = dom5.query(ast, matchers.base);
   const p = dom5.predicates;
   // If there's no base tag, there's nothing to do.
   if (!baseTag) {
     return;
   }
   for (const baseTag of dom5.queryAll(ast, matchers.base)) {
     removeElementAndNewline(baseTag);
   }
   if (dom5.predicates.hasAttr('href')(baseTag)) {
     const baseUrl = this.bundler.analyzer.urlResolver.resolve(
         docUrl, dom5.getAttribute(baseTag, 'href')! as FileRelativeUrl);
     if (baseUrl) {
       this._rewriteAstBaseUrl(ast, baseUrl, docUrl);
     }
   }
   if (p.hasAttr('target')(baseTag)) {
     const baseTarget = dom5.getAttribute(baseTag, 'target')!;
     const tagsToTarget = dom5.queryAll(
         ast,
         p.AND(
             p.OR(p.hasTagName('a'), p.hasTagName('form')),
             p.NOT(p.hasAttr('target'))));
     for (const tag of tagsToTarget) {
       dom5.setAttribute(tag, 'target', baseTarget);
     }
   }
 }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:33,代碼來源:html-bundler.ts

示例2: test

  test('lazy imports are not moved', async () => {
    const bundler = getBundler();
    const manifest =
        await bundler.generateManifest([resolve('imports/lazy-imports.html')]);
    const {documents} = await bundler.bundle(manifest);

    // The `lazy-imports.html` file has 2 imports in the head of the
    // document.  The first is eager and should be moved.  The remaining
    // one is lazy and should not be moved.
    const entrypointBundle =
        documents.getHtmlDoc(resolve('imports/lazy-imports.html'))!.ast;
    const entrypointLazyImports = dom5.queryAll(
        entrypointBundle,
        preds.AND(preds.parentMatches(matchers.head), matchers.htmlImport));
    assert.equal(entrypointLazyImports.length, 1);
    assert.equal(dom5.getAttribute(entrypointLazyImports[0]!, 'group'), 'one');

    // The shared bundle has an inlined dom-module with an embedded
    // lazy-import via `shared-eager-import-2.html` that we are verifying
    // is preserved.
    const sharedBundle =
        documents.getHtmlDoc(resolve('shared_bundle_1.html'))!.ast;
    const sharedLazyImports = dom5.queryAll(
        sharedBundle,
        preds.AND(
            preds.parentMatches(preds.hasTagName('dom-module')),
            preds.hasTagName('link'),
            preds.hasAttrValue('rel', 'lazy-import')));
    assert.equal(sharedLazyImports.length, 1);
    assert.equal(dom5.getAttribute(sharedLazyImports[0]!, 'group'), 'deeply');
  });
開發者ID:Polymer,項目名稱:tools,代碼行數:31,代碼來源:bundler_test.ts

示例3: assertContainsAndExcludes

 function assertContainsAndExcludes(
     doc: parse5.ASTNode,
     contains: dom5.Predicate[],
     excludes: dom5.Predicate[]) {
   for (const test of contains) {
     const found = dom5.queryAll(doc, test);
     assert.equal(found.length, 1);
   }
   for (const test of excludes) {
     const found = dom5.queryAll(doc, test);
     assert.equal(found.length, 0);
   }
 }
開發者ID:MehdiRaash,項目名稱:tools,代碼行數:13,代碼來源:shards_test.ts

示例4: 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

示例5: _inlineStylesheetLinks

 /**
  * Replace all external stylesheet references, in `<link rel="stylesheet">`
  * tags with `<style>` tags containing file contents, with internal URLs
  * relatively transposed as necessary.
  */
 private async _inlineStylesheetLinks(ast: ASTNode) {
   const cssLinks = dom5.queryAll(
       ast, matchers.externalStyle, undefined, dom5.childNodesIncludeTemplate);
   for (const cssLink of cssLinks) {
     await this._inlineStylesheet(cssLink);
   }
 }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:12,代碼來源:html-bundler.ts

示例6: _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

示例7: _removeEmptyHiddenDivs

 /**
  * Removes all empty hidden container divs from the AST.
  */
 private _removeEmptyHiddenDivs(ast: ASTNode) {
   for (const div of dom5.queryAll(ast, matchers.hiddenDiv)) {
     if (serialize(div).trim() === '') {
       dom5.remove(div);
     }
   }
 }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:10,代碼來源:html-bundler.ts


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