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


TypeScript polymer-analyzer.Analyzer类代码示例

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


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

示例1: constructor

  constructor(options?: Options) {
    const opts = options ? options : {};

    // In order for the bundler to use a given analyzer, we'll have to fork it
    // so we can provide our own overlayUrlLoader which falls back to the
    // analyzer's load method.
    if (opts.analyzer) {
      const analyzer = opts.analyzer;
      this._overlayUrlLoader = new InMemoryOverlayUrlLoader(analyzer);
      this.analyzer = analyzer._fork({urlLoader: this._overlayUrlLoader});
    } else {
      this._overlayUrlLoader =
          new InMemoryOverlayUrlLoader(new FsUrlLoader(resolvePath('.')));
      this.analyzer = new Analyzer({urlLoader: this._overlayUrlLoader});
    }

    this.excludes = Array.isArray(opts.excludes) ? opts.excludes : [];
    this.stripComments = Boolean(opts.stripComments);
    this.enableCssInlining =
        opts.inlineCss === undefined ? true : opts.inlineCss;
    this.enableScriptInlining =
        opts.inlineScripts === undefined ? true : opts.inlineScripts;
    this.rewriteUrlsInTemplates = Boolean(opts.rewriteUrlsInTemplates);
    this.sourcemaps = Boolean(opts.sourcemaps);
    this.strategy =
        opts.strategy || bundleManifestLib.generateSharedDepsMergeStrategy();
    this.urlMapper = opts.urlMapper ||
        bundleManifestLib.generateCountingSharedBundleUrlMapper(
            this.analyzer.resolveUrl('shared_bundle_')!);
  }
开发者ID:Polymer,项目名称:vulcanize,代码行数:30,代码来源:bundler.ts

示例2: assertFileEdited

export async function assertFileEdited(
    analyzer: Analyzer,
    editResult: EditResult,
    inputFile: string,
    goldenFile: string) {
  assert.deepEqual(
      editResult.editedFiles.get(analyzer.resolveUrl(inputFile)!),
      (await analyzer.load(analyzer.resolveUrl(goldenFile)!)));
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:9,代码来源:util.ts

示例3: assertExpectedFixes

export async function assertExpectedFixes(
    linter: Linter, analyzer: Analyzer, inputFile: string, goldenFile: string) {
  const {warnings} = await linter.lint([inputFile]);
  const edits = warnings.filter((w) => w.fix).map((w) => w.fix!);
  const loader = makeParseLoader(analyzer);
  const {editedFiles, incompatibleEdits} = await applyEdits(edits, loader);
  assert.deepEqual(incompatibleEdits, []);
  const inputFileContent = editedFiles.get(analyzer.resolveUrl(inputFile)!);
  const outputFileContent =
      (await loader(analyzer.resolveUrl(goldenFile)!)).contents;
  assert.deepEqual(inputFileContent, outputFileContent);
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:12,代码来源:util.ts

示例4: getExistingSourcemap

export async function getExistingSourcemap(
    analyzer: Analyzer, sourceUrl: string, sourceContent: string) {
  const sourceMappingUrlParts = sourceContent.match(sourceMappingUrlExpr);
  if (sourceMappingUrlParts === null) {
    return null;
  }

  let sourcemap: RawSourceMap;
  let mapUrl = sourceUrl;
  const inlineSourcemapParts =
      sourceMappingUrlParts[1].match(inlineSourceMapExpr);
  if (inlineSourcemapParts !== null) {
    sourcemap = base64StringToRawSourceMap(inlineSourcemapParts[2]);
  } else {
    mapUrl = urlLib.resolve(sourceUrl, sourceMappingUrlParts[1].trim());
    sourcemap =
        JSON.parse(await analyzer.load(mapUrl as ResolvedUrl)) as RawSourceMap;
  }

  // Rewrite the sources array to be relative to the current URL
  if (sourcemap.sources) {
    sourcemap.sources =
        sourcemap.sources.map((source) => urlLib.resolve(mapUrl, source));
  }
  return sourcemap;
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:26,代码来源:source-map.ts

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

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

  /**
   * Given an array of Bundles, remove all files from bundles which are in the
   * "excludes" set.  Remove any bundles which are left empty after excluded
   * files are removed.
   */
  private _filterExcludesFromBundles(bundles: Bundle[]) {
    // Remove excluded files from bundles.
    for (const bundle of bundles) {
      for (const exclude of this.excludes) {
        const resolvedExclude = this.analyzer.resolveUrl(exclude);
        if (!resolvedExclude) {
          continue;
        }
        bundle.files.delete(resolvedExclude);
        const excludeAsFolder = exclude.endsWith('/') ? exclude : exclude + '/';
        for (const file of bundle.files) {
          if (file.startsWith(excludeAsFolder)) {
            bundle.files.delete(file);
          }
        }
      }
    }

    let b = 0;
    while (b < bundles.length) {
      if (bundles[b].files.size < 0) {
        bundles.splice(b, 1);
        continue;
      }
      ++b;
    }
  }
开发者ID:Polymer,项目名称:vulcanize,代码行数:32,代码来源:bundler.ts

示例8: lintPackage

 public async lintPackage(): Promise<LintResult> {
   const analysis = await this._analyzer.analyzePackage();
   const warnings = analysis.getWarnings();
   warnings.push(
       ...await this._lintDocuments(analysis.getFeatures({kind: 'document'})));
   return makeLintResult(warnings, analysis);
 }
开发者ID:asdfg9822,项目名称:polymer-linter,代码行数:7,代码来源:linter.ts

示例9: _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

示例10: generatePushManifest

  async generatePushManifest(): Promise<PushManifest> {
    // Bundler's buildDepsIndex code generates an index with all fragments and
    // all lazy-imports encountered are the keys, so we'll use that function to
    // produce the set of all fragments to generate push-manifest entries for.
    const depsIndex = await buildDepsIndex(
        this.config.allFragments.map(
            (path) => this.analyzer.resolveUrl(urlFromPath(
                this.config.root as LocalFsPath, path as LocalFsPath))!),
        this.analyzer);
    // Don't include bundler's fake "sub-bundle" URLs (e.g.
    // "foo.html>external#1>bar.js").
    const allFragments =
        new Set([...depsIndex.keys()].filter((url) => !url.includes('>')));

    // If an app-shell exists, use that as our main push URL because it has a
    // reliable URL. Otherwise, support the single entrypoint URL.
    const mainPushEntrypointUrl = this.analyzer.resolveUrl(urlFromPath(
        this.config.root as LocalFsPath,
        this.config.shell as LocalFsPath ||
            this.config.entrypoint as LocalFsPath))!;
    allFragments.add(mainPushEntrypointUrl);

    // Generate the dependencies to push for each fragment.
    const pushManifest: PushManifest = {};
    for (const fragment of allFragments) {
      const absoluteFragmentUrl =
          '/' + this.analyzer.urlResolver.relative(fragment);
      pushManifest[absoluteFragmentUrl] =
          await generatePushManifestEntryForUrl(this.analyzer, fragment);
    }

    // The URLs we got may be absolute or relative depending on how they were
    // declared in the source. This will normalize them to relative by stripping
    // any leading slash.
    //
    // TODO Decide whether they should really be relative or absolute. Relative
    // was chosen here only because most links were already relative so it was
    // a smaller change, but
    // https://github.com/GoogleChrome/http2-push-manifest actually shows
    // relative for the keys and absolute for the values.
    const normalize = (p: string) =>
        path.posix.join(this.basePath, p).replace(/^\/+/, '');

    const normalized: PushManifest = {};
    for (const source of Object.keys(pushManifest)) {
      const targets: PushManifestEntryCollection = {};
      for (const target of Object.keys(pushManifest[source])) {
        targets[normalize(target)] = pushManifest[source][target];
      }
      normalized[normalize(source)] = targets;
    }
    return normalized;
  }
开发者ID:Polymer,项目名称:tools,代码行数:53,代码来源:push-manifest.ts


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