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


TypeScript dom5.query函数代码示例

本文整理汇总了TypeScript中dom5.query函数的典型用法代码示例。如果您正苦于以下问题:TypeScript query函数的具体用法?TypeScript query怎么用?TypeScript query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _moveDomModuleStyleIntoTemplate

  /**
   * Old Polymer supported `<style>` tag in `<dom-module>` but outside of
   * `<template>`.  This is also where the deprecated Polymer CSS import tag
   * `<link rel="import" type="css">` would generate inline `<style>`.
   * Migrates these `<style>` tags into available `<template>` of the
   * `<dom-module>`.  Will create a `<template>` container if not present.
   *
   * TODO(usergenic): Why is this in bundler... shouldn't this be some kind of
   * polyup or pre-bundle operation?
   */
  private _moveDomModuleStyleIntoTemplate(style: ASTNode, refStyle?: ASTNode) {
    const domModule =
        dom5.nodeWalkAncestors(style, dom5.predicates.hasTagName('dom-module'));
    if (!domModule) {
      return;
    }
    let template = dom5.query(domModule, matchers.template);
    if (!template) {
      template = dom5.constructors.element('template')!;
      treeAdapters.default.setTemplateContent(
          template, dom5.constructors.fragment());
      prepend(domModule, template);
    }
    removeElementAndNewline(style);

    // Ignore the refStyle object if it is contained within a different
    // dom-module.
    if (refStyle &&
        !dom5.query(
            domModule, (n) => n === refStyle, dom5.childNodesIncludeTemplate)) {
      refStyle = undefined;
    }

    // keep ordering if previding with a reference style
    if (!refStyle) {
      prepend(treeAdapters.default.getTemplateContent(template), style);
    } else {
      insertAfter(refStyle, style);
    }
  }
开发者ID:Polymer,项目名称:vulcanize,代码行数:40,代码来源:html-bundler.ts

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

示例3: async

 async () => {
   const {ast: doc} = await bundle('inline-styles.html', options);
   const domModule = dom5.query(doc, preds.hasTagName('dom-module'))!;
   assert(domModule);
   const template = dom5.query(domModule, matchers.template)!;
   assert(template);
   const style = dom5.query(
       template, matchers.styleMatcher, dom5.childNodesIncludeTemplate);
   assert(style);
 });
开发者ID:Polymer,项目名称:tools,代码行数:10,代码来源:bundler_test.ts

示例4: test

 test('Handle <base> tag', async () => {
   const span = preds.AND(
       preds.hasTagName('span'), preds.hasAttrValue('href', 'imports/hello'));
   const a = preds.AND(
       preds.hasTagName('a'),
       preds.hasAttrValue('href', 'imports/sub-base/sub-base.html'));
   const {ast: doc} = await bundle(resolve('base.html'));
   const spanHref = dom5.query(doc, span);
   assert.ok(spanHref);
   const anchorRef = dom5.query(doc, a);
   assert.ok(anchorRef);
 });
开发者ID:Polymer,项目名称:tools,代码行数:12,代码来源:bundler_test.ts

示例5: _attachHiddenDiv

 /**
  * Set the hidden div at the appropriate location within the document.  The
  * goal is to place the hidden div at the same place as the first html
  * import.  However, the div can't be placed in the `<head>` of the document
  * so if first import is found in the head, we prepend the div to the body.
  * If there is no body, we'll just attach the hidden div to the document at
  * the end.
  */
 private _attachHiddenDiv(ast: ASTNode, hiddenDiv: ASTNode) {
   const firstHtmlImport = dom5.query(ast, matchers.eagerHtmlImport);
   const body = dom5.query(ast, matchers.body);
   if (body) {
     if (firstHtmlImport &&
         dom5.predicates.parentMatches(matchers.body)(firstHtmlImport)) {
       insertAfter(firstHtmlImport, hiddenDiv);
     } else {
       prepend(body, hiddenDiv);
     }
   } else {
     dom5.append(ast, hiddenDiv);
   }
 }
开发者ID:Polymer,项目名称:vulcanize,代码行数:22,代码来源:html-bundler.ts

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

示例7: stripComments

export function stripComments(document: ASTNode) {
  const uniqueLicenseTexts = new Set<string>();
  const licenseComments: ASTNode[] = [];
  for (const comment of dom5.nodeWalkAll(
           document,
           dom5.isCommentNode,
           undefined,
           dom5.childNodesIncludeTemplate)) {
    if (isImportantComment(comment) || isServerSideIncludeComment(comment)) {
      continue;
    }

    // Make whitespace uniform so we can deduplicate based on actual content.
    const commentText = (comment.data || '').replace(/\s+/g, ' ').trim();

    if (isLicenseComment(comment) && !uniqueLicenseTexts.has(commentText)) {
      uniqueLicenseTexts.add(commentText);
      licenseComments.push(comment);
    }

    removeElementAndNewline(comment);
  }
  const prependTarget = dom5.query(document, matchers.head) || document;
  for (const comment of licenseComments.reverse()) {
    prepend(prependTarget, comment);
  }
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:27,代码来源:parse5-utils.ts

示例8: processFile

  private async processFile(file: File): Promise<File> {
    if (file.path !== this.entrypoint) {
      return file;
    }
    const contents = await getFileContents(file);
    const document = parse5.parse(contents);

    const babelHelpersFragment =
        parse5.parseFragment('\n\n<script></script>\n\n');
    dom5.setTextContent(
        babelHelpersFragment.childNodes![1]!,
        await fs.readFile(
            path.join(__dirname, 'babel-helpers.min.js'), 'utf-8'));

    const firstScriptOrImport = dom5.nodeWalk(document, scriptOrImport);
    if (firstScriptOrImport) {
      dom5.insertBefore(
          firstScriptOrImport.parentNode!,
          firstScriptOrImport,
          babelHelpersFragment);
    } else {
      const head =
          dom5.query(document, dom5.predicates.hasTagName('head')) || document;
      dom5.append(head, babelHelpersFragment);
    }

    const newFile = file.clone();
    newFile.contents = new Buffer(parse5.serialize(document), 'utf-8');
    return newFile;
  }
开发者ID:chrisekelley,项目名称:polymer-build,代码行数:30,代码来源:inject-babel-helpers.ts


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