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


TypeScript Analyzer.analyze方法代码示例

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


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

示例1: generatePushManifestEntryForUrl

/**
 * Analyze the given URL and resolve with a collection of push manifest entries
 * to be added to the overall push manifest.
 */
async function generatePushManifestEntryForUrl(
    analyzer: Analyzer, url: string): Promise<PushManifestEntryCollection> {
  const analysis = await analyzer.analyze([url]);
  const analyzedDocument = analysis.getDocument(url);

  if (!(analyzedDocument instanceof Document)) {
    const message = analyzedDocument && analyzedDocument.message || 'unknown';
    throw new Error(`Unable to get document ${url}: ${message}`);
  }

  const analyzedImports =
      [...analyzedDocument.getFeatures({
        kind: 'import',
        externalPackages: true,
        imported: true,
        noLazyImports: true,
      })].filter((i) => !(i.type === 'html-import' && i.lazy));
  const pushManifestEntries: PushManifestEntryCollection = {};

  for (const analyzedImport of analyzedImports) {
    // TODO This import URL does not respect the document's base tag.
    // Probably an issue more generally with all URLs analyzed out of
    // documents, but base tags are somewhat rare.
    const analyzedImportUrl = analyzedImport.url;
    const analyzedImportEntry = pushManifestEntries[analyzedImportUrl];
    if (!analyzedImportEntry) {
      pushManifestEntries[analyzedImportUrl] =
          createPushEntryFromImport(analyzedImport);
    }
  }

  return pushManifestEntries;
}
开发者ID:chrisekelley,项目名称:polymer-build,代码行数:37,代码来源:push-manifest.ts

示例2: reserveBundleModuleExportNames

export async function reserveBundleModuleExportNames(
    analyzer: Analyzer, manifest: BundleManifest) {
  const es6ModuleBundles =
      [...manifest.bundles]
          .map(([url, bundle]) => ({url, bundle}))
          .filter(({bundle}) => bundle.type === 'es6-module');
  const analysis = await analyzer.analyze(es6ModuleBundles.map(({url}) => url));
  for (const {url, bundle} of es6ModuleBundles) {
    if (bundle.files.has(url)) {
      const document = getAnalysisDocument(analysis, url);
      for (const exportName of getModuleExportNames(document)) {
        getOrSetBundleModuleExportName({url, bundle}, url, exportName);
      }
    }
  }
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:16,代码来源:es6-module-utils.ts

示例3: _analyzeAll

  private async _analyzeAll(files: string[], options?: AnalyzeOptions) {
    const analysis = await this._analyzer.analyze(files, options);
    const documents = [];
    const warnings = [];

    for (const file of files) {
      const result = analysis.getDocument(file);
      if (result.successful) {
        documents.push(result.value);
      } else if (result.error !== undefined) {
        warnings.push(result.error);
      }
    }

    return {documents, warnings, analysis};
  }
开发者ID:MehdiRaash,项目名称:tools,代码行数:16,代码来源:linter.ts

示例4: buildDepsIndex

export async function buildDepsIndex(
    entrypoints: ResolvedUrl[], analyzer: Analyzer): Promise<DepsIndex> {
  const depsIndex = new Map<ResolvedUrl, Set<ResolvedUrl>>();
  const analysis = await analyzer.analyze(entrypoints);
  const allEntrypoints = new Set<ResolvedUrl>(entrypoints);
  const inlineDocuments = new Map<ResolvedUrl, Document>();

  // Note: the following iteration takes place over a Set which may be added
  // to from within the loop.
  for (const entrypoint of allEntrypoints) {
    let document;
    try {
      document = inlineDocuments.has(entrypoint) ?
          inlineDocuments.get(entrypoint)! :
          getAnalysisDocument(analysis, entrypoint);
    } catch (e) {
      console.warn(e.message);
    }
    if (document) {
      const deps = getDependencies(analyzer, document);
      depsIndex.set(entrypoint, new Set([
                      ...(document.isInline ? [] : [document.url]),
                      ...deps.eagerDeps
                    ]));

      // Add lazy imports to the set of all entrypoints, which supports
      // recursive
      for (const dep of deps.lazyImports) {
        allEntrypoints.add(dep);
      }

      // Treat top-level module imports as entrypoints by creating "sub-bundle"
      // URLs to enable the inline document to be processed as an entrypoint
      // document on a subsequent iteration of the outer loop over all
      // entrypoints.
      for (const [id, imported] of deps.moduleScriptImports) {
        const subBundleUrl = getSubBundleUrl(document.url, id);
        allEntrypoints.add(subBundleUrl);
        inlineDocuments.set(subBundleUrl, imported);
      }
    }
  }

  return depsIndex;
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:45,代码来源:deps-index.ts

示例5: _analyzeAll

  private async _analyzeAll(files: string[]) {
    const analysis = await this._analyzer.analyze(files);
    const documents = [];
    const warnings = [];

    for (const file of files) {
      const result = analysis.getDocument(this._analyzer.resolveUrl(file));
      if (!result) {
        continue;
      } else if (result instanceof Document) {
        documents.push(result);
      } else {
        warnings.push(result);
      }
    }

    return {documents, warnings, analysis};
  }
开发者ID:asdfg9822,项目名称:polymer-linter,代码行数:18,代码来源:linter.ts

示例6: analyze

export async function analyze(
    root: string, inputs: string[]): Promise<AnalysisFormat|undefined> {
  const analyzer = new Analyzer({
    urlLoader: new FSUrlLoader(root),
    urlResolver: new PackageUrlResolver(),
  });

  const isInTests = /(\b|\/|\\)(test)(\/|\\)/;
  const isNotTest = (f: Feature) =>
      f.sourceRange != null && !isInTests.test(f.sourceRange.file);

  if (inputs == null || inputs.length === 0) {
    const _package = await analyzer.analyzePackage();
    return generateAnalysis(_package, '', isNotTest);
  } else {
    const analysis = await analyzer.analyze(await globby(inputs));
    return generateAnalysis(analysis, '', isNotTest);
  }
}
开发者ID:abdonrd,项目名称:polymer-cli,代码行数:19,代码来源:analyze.ts

示例7: generatePushManifestEntryForUrl

/**
 * Analyze the given URL and resolve with a collection of push manifest entries
 * to be added to the overall push manifest.
 */
async function generatePushManifestEntryForUrl(
    analyzer: Analyzer,
    url: ResolvedUrl): Promise<PushManifestEntryCollection> {
  const analysis = await analyzer.analyze([url]);
  const result = analysis.getDocument(url);

  if (result.successful === false) {
    const message = result.error && result.error.message || 'unknown';
    throw new Error(`Unable to get document ${url}: ${message}`);
  }

  const analyzedDocument = result.value;
  const rawImports = [...analyzedDocument.getFeatures({
    kind: 'import',
    externalPackages: true,
    imported: true,
    noLazyImports: true,
  })];
  const importsToPush = rawImports.filter(
      (i) => !(i.type === 'html-import' && i.lazy) &&
          !(i.kinds.has('html-script-back-reference')));
  const pushManifestEntries: PushManifestEntryCollection = {};

  for (const analyzedImport of importsToPush) {
    // TODO This import URL does not respect the document's base tag.
    // Probably an issue more generally with all URLs analyzed out of
    // documents, but base tags are somewhat rare.
    const analyzedImportUrl = analyzedImport.url;
    const relativeImportUrl = analyzer.urlResolver.relative(analyzedImportUrl);
    const analyzedImportEntry = pushManifestEntries[relativeImportUrl];
    if (!analyzedImportEntry) {
      pushManifestEntries[relativeImportUrl] =
          createPushEntryFromImport(analyzedImport);
    }
  }

  return pushManifestEntries;
}
开发者ID:Polymer,项目名称:tools,代码行数:42,代码来源:push-manifest.ts

示例8: analyzeContents

 /**
  * Analyze an HTML URL using the given contents in place of what would
  * otherwise have been loaded.
  */
 async analyzeContents(
     url: ResolvedUrl, contents: string,
     // By default, the contents given to analyzeContents are not kept in the
     // Analyzer's cache and the Analyzer will act as though it never happened.
     // By giving a `true` value to `permanent`, the Analysis cache and the
     // in-memory overlay will not be purged of the contents.  This toggle lets
     // us use the Analyzer to process documents in intermediate stages without
     // committing to them.
     permanent?: boolean): Promise<Document> {
   this._overlayUrlLoader.urlContentsMap.set(url, contents);
   await this.analyzer.filesChanged([url]);
   const analysis = await this.analyzer.analyze([url]);
   const document = getAnalysisDocument(analysis, url);
   // Unless we explicitly want to make this analysis permanent, we remove the
   // entry from the overlay and tell analyzer to forget what it just analyzed.
   // This is because logic in many parts of the bundler assume the documents
   // and features will be of the original content.
   if (!permanent) {
     this._overlayUrlLoader.urlContentsMap.delete(url);
     await this.analyzer.filesChanged([url]);
   }
   return document;
 }
开发者ID:Polymer,项目名称:tools,代码行数:27,代码来源:bundler.ts

示例9: _transformIter

  protected async *
      _transformIter(files: AsyncIterable<File>): AsyncIterable<File> {
    const htmlFileUrls = [];

    // Map all files; pass-through all non-HTML files.
    for await (const file of files) {
      const fileUrl = urlFromPath(this._config.root, file.path);
      this.files.set(fileUrl, file);
      if (path.extname(file.path) !== '.html') {
        yield file;
      } else {
        htmlFileUrls.push(fileUrl);
      }
    }

    // Analyze each HTML file and add prefetch links.
    const analysis = await this._analyzer.analyze(htmlFileUrls);

    for (const documentUrl of htmlFileUrls) {
      const document = analysis.getDocument(documentUrl);
      if (!(document instanceof Document)) {
        const message = document && document.message;
        console.warn(`Unable to get document ${documentUrl}: ${message}`);
        continue;
      }

      const allDependencyUrls = [
        ...document.getFeatures({
          kind: 'import',
          externalPackages: true,
          imported: true,
          noLazyImports: true
        })
      ].filter((d) => !d.lazy).map((d) => d.document.url);

      const directDependencyUrls = [
        ...document.getFeatures({
          kind: 'import',
          externalPackages: true,
          imported: false,
          noLazyImports: true
        })
      ].filter((d) => !d.lazy).map((d) => d.document.url);

      const onlyTransitiveDependencyUrls = allDependencyUrls.filter(
          (d) => directDependencyUrls.indexOf(d) === -1);

      // No need to transform a file if it has no dependencies to prefetch.
      if (onlyTransitiveDependencyUrls.length === 0) {
        yield this.files.get(documentUrl)!;
        continue;
      }

      const prefetchUrls = new Set(onlyTransitiveDependencyUrls);

      const html = createLinks(
          document.parsedDocument.contents,
          document.parsedDocument.baseUrl,
          prefetchUrls,
          document.url ===
              urlFromPath(this._config.root, this._config.entrypoint));
      const filePath = pathFromUrl(this._config.root, documentUrl);
      yield new File({contents: new Buffer(html, 'utf-8'), path: filePath})
    }
  }
开发者ID:chrisekelley,项目名称:polymer-build,代码行数:65,代码来源:prefetch-links.ts


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