本文整理汇总了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;
}
示例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);
}
}));
}
示例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;
});
}
示例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;
}
});
}
示例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);
}