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


TypeScript dom5.removeFakeRootElements函數代碼示例

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


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

示例1: bundle

  async bundle(): Promise<BundledDocument> {
    this.document = await this._prepareBundleDocument();
    let ast = clone(this.document.parsedDocument.ast);
    dom5.removeFakeRootElements(ast);
    this._injectHtmlImportsForBundle(ast);
    this._rewriteAstToEmulateBaseTag(ast, this.assignedBundle.url);

    // Re-analyzing the document using the updated ast to refresh the scanned
    // imports, since we may now have appended some that were not initially
    // present.
    this.document = await this._reanalyze(serialize(ast));

    await this._inlineHtmlImports(ast);

    await this._updateExternalModuleScripts(ast);
    if (this.bundler.enableScriptInlining) {
      await this._inlineNonModuleScripts(ast);
      await this._inlineModuleScripts(ast);
    }
    if (this.bundler.enableCssInlining) {
      await this._inlineStylesheetLinks(ast);
      await this._inlineStylesheetImports(ast);
    }
    if (this.bundler.stripComments) {
      stripComments(ast);
    }
    this._removeEmptyHiddenDivs(ast);
    if (this.bundler.sourcemaps) {
      ast = updateSourcemapLocations(this.document, ast);
    }
    const content = serialize(ast);
    const files = [...this.assignedBundle.bundle.files];
    return {ast, content, files};
  }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:34,代碼來源: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: _inlineModuleScripts

 /**
  * Inlines the contents of external module scripts and rolls-up imported
  * modules into inline scripts.
  */
 private async _inlineModuleScripts(ast: ASTNode) {
   this.document = await this._reanalyze(serialize(ast));
   rewriteObject(ast, this.document.parsedDocument.ast);
   dom5.removeFakeRootElements(ast);
   const es6Rewriter =
       new Es6Rewriter(this.bundler, this.manifest, this.assignedBundle);
   const inlineModuleScripts =
       [...this.document.getFeatures({
         kind: 'js-document',
         imported: false,
         externalPackages: true,
         excludeBackreferences: true,
       })].filter(({
                    isInline,
                    parsedDocument: {parsedAsSourceType}
                  }) => isInline && parsedAsSourceType === 'module');
   for (const inlineModuleScript of inlineModuleScripts) {
     const {code} = await es6Rewriter.rollup(
         this.document.parsedDocument.baseUrl,
         inlineModuleScript.parsedDocument.contents);
     // Second argument 'true' tells encodeString to escape the <script>
     // content.
     dom5.setTextContent(
         (inlineModuleScript.astNode as any).node,
         encodeString(`\n${code}\n`, true));
   }
 }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:31,代碼來源:html-bundler.ts

示例4: _rollupInlineModuleScripts

 /**
  * Inlines the contents of external module scripts and rolls-up imported
  * modules into inline scripts.
  */
 private async _rollupInlineModuleScripts(ast: ASTNode) {
   this.document = await this._reanalyze(serialize(ast));
   rewriteObject(ast, this.document.parsedDocument.ast);
   dom5.removeFakeRootElements(ast);
   const es6Rewriter =
       new Es6Rewriter(this.bundler, this.manifest, this.assignedBundle);
   const inlineModuleScripts =
       [...this.document.getFeatures({
         kind: 'js-document',
         imported: false,
         externalPackages: true,
         excludeBackreferences: true,
       })].filter(({
                    isInline,
                    parsedDocument: {parsedAsSourceType}
                  }) => isInline && parsedAsSourceType === 'module');
   for (const inlineModuleScript of inlineModuleScripts) {
     const ast = clone(inlineModuleScript.parsedDocument.ast);
     const importResolutions =
         es6Rewriter.getEs6ImportResolutions(inlineModuleScript);
     es6Rewriter.rewriteEs6SourceUrlsToResolved(ast, importResolutions);
     const serializedCode = serializeEs6(ast).code;
     const {code} = await es6Rewriter.rollup(
         this.document.parsedDocument.baseUrl,
         serializedCode,
         inlineModuleScript);
     if (inlineModuleScript.astNode &&
         inlineModuleScript.astNode.language === 'html') {
       // Second argument 'true' tells encodeString to escape the <script>
       // content.
       dom5.setTextContent(
           inlineModuleScript.astNode.node, encodeString(`\n${code}\n`, true));
     }
   }
 }
開發者ID:Polymer,項目名稱:tools,代碼行數:39,代碼來源:html-bundler.ts

示例5: _prepareBundleDocument

 /**
  * Generate a fresh document to bundle contents into.  If we're building
  * a bundle which is based on an existing file, we should load that file and
  * prepare it as the bundle document, otherwise we'll create a clean/empty
  * HTML document.
  */
 private async _prepareBundleDocument(): Promise<Document> {
   if (!this.assignedBundle.bundle.files.has(this.assignedBundle.url)) {
     return this._reanalyze('');
   }
   const analysis =
       await this.bundler.analyzer.analyze([this.assignedBundle.url]);
   const document = getAnalysisDocument(analysis, this.assignedBundle.url);
   const ast = clone(document.parsedDocument.ast);
   this._moveOrderedImperativesFromHeadIntoHiddenDiv(ast);
   this._moveUnhiddenHtmlImportsIntoHiddenDiv(ast);
   dom5.removeFakeRootElements(ast);
   return this._reanalyze(serialize(ast));
 }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:19,代碼來源:html-bundler.ts

示例6: _transformIter

  protected async *
      _transformIter(files: AsyncIterable<File>): AsyncIterable<File> {
    for await (const file of files) {
      if (file.path !== this.filePath) {
        yield file;
        continue;
      }

      const contents = await getFileContents(file);
      const parsed = parse5.parse(contents, {locationInfo: true});
      const base = dom5.query(parsed, baseMatcher);
      if (!base || dom5.getAttribute(base, 'href') === this.newHref) {
        yield file;
        continue;
      }

      dom5.setAttribute(base, 'href', this.newHref);
      dom5.removeFakeRootElements(parsed);
      const updatedFile = file.clone();
      updatedFile.contents = new Buffer(parse5.serialize(parsed), 'utf-8');
      yield updatedFile;
    }
  }
開發者ID:chrisekelley,項目名稱:polymer-build,代碼行數:23,代碼來源:base-tag-updater.ts

示例7: parse

export function parse(html: string, options?: ParserOptions): ASTNode {
  const ast = _parse(html, Object.assign({locationInfo: true}, options));
  dom5.removeFakeRootElements(ast);
  return ast;
}
開發者ID:MehdiRaash,項目名稱:tools,代碼行數:5,代碼來源:parse5-utils.ts


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