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