当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript predicates.hasAttrValue方法代码示例

本文整理汇总了TypeScript中dom5.predicates.hasAttrValue方法的典型用法代码示例。如果您正苦于以下问题:TypeScript predicates.hasAttrValue方法的具体用法?TypeScript predicates.hasAttrValue怎么用?TypeScript predicates.hasAttrValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dom5.predicates的用法示例。


在下文中一共展示了predicates.hasAttrValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

 const hasImport = (doc: ASTNode, url: string) => {
   const link = dom5.query(
       doc,
       dom5.predicates.AND(
           dom5.predicates.hasTagName('link'),
           dom5.predicates.hasAttrValue('rel', 'import'),
           dom5.predicates.hasAttrValue('href', url)));
   return link != null;
 };
开发者ID:chrisekelley,项目名称:polymer-build,代码行数:9,代码来源:bundle_test.ts

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

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

示例4: test

    test('Deprecated CSS imports should inline correctly', async () => {
      const {ast: doc} = await bundle('css-imports.html', {inlineCss: true});

      const styleA =
          fs.readFileSync('test/html/css-import/import-a.css', 'utf-8');
      const styleB =
          fs.readFileSync('test/html/css-import/import-b.css', 'utf-8');

      const elementA =
          dom5.query(doc, dom5.predicates.hasAttrValue('id', 'element-a'))!;
      assert(elementA, 'element-a not found.');
      assert.include(parse5.serialize(elementA), styleA);
      assert.notInclude(parse5.serialize(elementA), styleB);

      const elementB =
          dom5.query(doc, dom5.predicates.hasAttrValue('id', 'element-b'))!;
      assert(elementB, 'element-b not found.');
      assert.notInclude(parse5.serialize(elementB), styleA);
      assert.include(parse5.serialize(elementB), styleB);
    });
开发者ID:Polymer,项目名称:tools,代码行数:20,代码来源:bundler_test.ts

示例5: 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]);
    });
开发者ID:MehdiRaash,项目名称:tools,代码行数:36,代码来源:shards_test.ts

示例6: _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;
  }
开发者ID:augint,项目名称:polymer-cli,代码行数:47,代码来源:bundle.ts

示例7: async

        'changes the href to another bundle if strategy moved it', async () => {
          const bundler = getBundler({
            // This strategy moves a file to a different bundle.
            strategy: (bundles: Bundle[]): Bundle[] => {
              return [
                new Bundle(
                    'html-fragment',
                    new Set([resolve('default.html')]),
                    new Set([resolve('default.html')])),
                new Bundle(
                    'html-fragment',
                    new Set(),  //
                    new Set([
                      resolve('imports/simple-import.html'),
                      resolve('imports/another-simple-import.html'),
                    ]))
              ];
            }
          });
          const manifest =
              await bundler.generateManifest([resolve('default.html')]);
          const {documents} = await bundler.bundle(manifest);
          const document = documents.getHtmlDoc(resolve('default.html'))!;
          assert(document);

          // We've moved the 'imports/simple-import.html' into a shared bundle
          // so a link to import it now points to the shared bundle instead.
          const linkTag = dom5.query(
              document.ast!,
              preds.AND(
                  preds.hasTagName('link'),
                  preds.hasAttrValue('rel', 'import')))!;
          assert(linkTag);
          assert.equal(
              dom5.getAttribute(linkTag, 'href'), 'shared_bundle_1.html');

          const shared = documents.getHtmlDoc(resolve('shared_bundle_1.html'))!;
          assert(shared);
          assert.isOk(dom5.query(
              shared.ast, dom5.predicates.hasAttrValue('id', 'my-element')));
        });
开发者ID:Polymer,项目名称:tools,代码行数:41,代码来源:bundler_test.ts

示例8:

// 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(
开发者ID:MehdiRaash,项目名称:tools,代码行数:31,代码来源:matchers.ts


注:本文中的dom5.predicates.hasAttrValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。