本文整理匯總了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_')!);
}
示例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)!)));
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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};
}
示例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;
}