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


TypeScript Iterable.from方法代码示例

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


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

示例1: addJsImports

  /**
   * Injects JS imports at the top of the program based on html imports and
   * the imports in this.module.importedReferences.
   */
  private addJsImports(
      program: Program,
      importedReferences:
          ReadonlyMap<ConvertedDocumentUrl, ReadonlySet<ImportReference>>):
      boolean {
    // Collect Identifier nodes within trees that will be completely replaced
    // with an import reference.
    const ignoredIdentifiers: Set<Identifier> = new Set();
    for (const referenceSet of importedReferences.values()) {
      for (const reference of referenceSet) {
        astTypes.visit(reference.path.node, {
          visitIdentifier(path: NodePath<Identifier>): (boolean | void) {
            ignoredIdentifiers.add(path.node);
            this.traverse(path);
          },
        });
      }
    }
    const usedIdentifiers = collectIdentifierNames(program, ignoredIdentifiers);

    const jsExplicitImports = new Set<string>();
    // Rewrite HTML Imports to JS imports
    const jsImportDeclarations = [];
    for (const htmlImport of this.getHtmlImports()) {
      const importedJsDocumentUrl = this.convertDocumentUrl(
          this.urlHandler.getDocumentUrl(htmlImport.document));

      const references = importedReferences.get(importedJsDocumentUrl);
      const namedExports =
          new Set(IterableX.from(references || []).map((ref) => ref.target));

      const jsFormattedImportUrl =
          this.formatImportUrl(importedJsDocumentUrl, htmlImport.originalUrl);
      jsImportDeclarations.push(...getImportDeclarations(
          jsFormattedImportUrl, namedExports, references, usedIdentifiers));

      jsExplicitImports.add(importedJsDocumentUrl);
    }
    // Add JS imports for any additional, implicit HTML imports
    for (const jsImplicitImportUrl of importedReferences.keys()) {
      if (jsExplicitImports.has(jsImplicitImportUrl)) {
        continue;
      }

      const references = importedReferences.get(jsImplicitImportUrl);
      const namedExports =
          new Set(IterableX.from(references || []).map((ref) => ref.target));
      const jsFormattedImportUrl = this.formatImportUrl(jsImplicitImportUrl);
      jsImportDeclarations.push(...getImportDeclarations(
          jsFormattedImportUrl, namedExports, references, usedIdentifiers));
    }

    // Prepend JS imports into the program body
    program.body.splice(0, 0, ...jsImportDeclarations);
    // Return true if any imports were added, false otherwise
    return jsImportDeclarations.length > 0;
  }
开发者ID:,项目名称:,代码行数:61,代码来源:

示例2: writeFileResults

export async function writeFileResults(
    outDir: string, files: Map<ConvertedDocumentFilePath, string|undefined>) {
  return Promise.all(IterableX.from(files).map(async ([newPath, newSource]) => {
    const filePath = path.join(outDir, newPath);
    await mkdirp(path.dirname(filePath));
    if (newSource !== undefined) {
      await fse.writeFile(filePath, newSource);
    } else if (await fse.pathExists(filePath)) {
      await fse.unlink(filePath);
    }
  }));
}
开发者ID:,项目名称:,代码行数:12,代码来源:

示例3: getNamespaceNames

/**
 * Get all namespace names for an analysis object.
 */
function getNamespaceNames(analysis: Analysis) {
  return IterableX
      .from(analysis.getFeatures(
          {kind: 'namespace', externalPackages: true, imported: true}))
      .map((n) => {
        const name = n.name;
        if (name.startsWith('window.')) {
          return name.slice('window.'.length);
        }
        return name;
      });
}
开发者ID:,项目名称:,代码行数:15,代码来源:

示例4: rewriteReferencesToLocalExports

export function rewriteReferencesToLocalExports(
    program: estree.Program,
    exportMigrationRecords: Iterable<NamespaceMemberToExport>) {
  const rewriteMap = new Map<string|undefined, string>(
      IterableX.from(exportMigrationRecords)
          .filter((m) => m.es6ExportName !== '*')
          .map(
              (m) => [m.oldNamespacedName,
                      m.es6ExportName] as [string, string]));
  astTypes.visit(program, {
    visitMemberExpression(path: NodePath<estree.MemberExpression>) {
      const memberName = getMemberName(path.node);
      const newLocalName = rewriteMap.get(memberName);
      if (newLocalName) {
        path.replace(jsc.identifier(newLocalName));
        return false;
      }
      this.traverse(path);
      return;
    }
  });
}
开发者ID:,项目名称:,代码行数:22,代码来源:

示例5: getCommentsBetween

export function getCommentsBetween(
    document: parse5.ASTNode,
    from: parse5.ASTNode|undefined,
    until: parse5.ASTNode|undefined): string[] {
  const nodesStart =
      from === undefined ? nodesInside(document) : nodesAfter(from);
  const nodesBetween =
      IterableX.from(nodesStart).takeWhile((node) => node !== until);
  const commentNodesBetween =
      nodesBetween.filter((node) => dom5.isCommentNode(node));
  const commentStringsBetween =
      commentNodesBetween.map((node) => dom5.getTextContent(node));
  const formattedCommentStringsBetween =
      commentStringsBetween.map((commentText) => {
        // If it looks like there might be jsdoc in the comment, start the
        // comment with an extra * so that the js comment looks like a jsdoc
        // comment.
        if (/@\w+/.test(commentText)) {
          return '*' + commentText;
        }
        return commentText;
      });
  return Array.from(formattedCommentStringsBetween);
}
开发者ID:,项目名称:,代码行数:24,代码来源:


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