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


TypeScript predicates.AND方法代码示例

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


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

示例1: parse

  /**
   * 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

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

示例3:

 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

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

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

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

示例7:

 */

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

示例8: require

import {predicates as p} from 'dom5';
import * as parse5 from 'parse5';
import * as url from 'url';

import File = require('vinyl');
import {AsyncTransformStream, getFileContents} from './streams';

const attrValueMatches = (attrName: string, regex: RegExp) => {
  return (node: parse5.ASTNode) => {
    const attrValue = dom5.getAttribute(node, attrName);
    return attrValue != null && regex.test(attrValue);
  };
};

const webcomponentsLoaderRegex = /\bwebcomponents\-(loader|lite)\.js\b/;
const webcomponentsLoaderMatcher = p.AND(
    p.hasTagName('script'), attrValueMatches('src', webcomponentsLoaderRegex));

/**
 * Wraps `addCustomElementsEs5Adapter()` in a `stream.Transform`.
 */
export class CustomElementsEs5AdapterInjector extends
    AsyncTransformStream<File, File> {
  constructor() {
    super({objectMode: true});
  }

  protected async *
      _transformIter(files: AsyncIterable<File>): AsyncIterable<File> {
    for await (const file of files) {
      if (file.contents === null || file.extname !== '.html') {
        yield file;
开发者ID:chrisekelley,项目名称:polymer-build,代码行数:32,代码来源:custom-elements-es5-adapter.ts

示例9: simpleSelectorToPredicate

 return dom5.predicates.OR(...parsed.map((simpleSelectors) => {
   return dom5.predicates.AND(...simpleSelectors.map(
       (selector) => simpleSelectorToPredicate(selector, isPolymerTemplate)));
 }));
开发者ID:asdfg9822,项目名称:polymer-linter,代码行数:4,代码来源:util.ts


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