UNPKG

6.4 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at
5 * http://polymer.github.io/LICENSE.txt
6 * The complete set of authors may be found at
7 * http://polymer.github.io/AUTHORS.txt
8 * The complete set of contributors may be found at
9 * http://polymer.github.io/CONTRIBUTORS.txt
10 * Code distributed by Google as part of the polymer project is also
11 * subject to an additional IP rights grant found at
12 * http://polymer.github.io/PATENTS.txt
13 */
14import { ForkOptions, Options } from '../core/analyzer';
15import { Result } from '../model/analysis';
16import { Document, ScannedDocument, Warning } from '../model/model';
17import { PackageRelativeUrl, ResolvedUrl } from '../model/url';
18import { ParsedDocument } from '../parser/document';
19import { Parser } from '../parser/parser';
20import { Scanner } from '../scanning/scanner';
21import { UrlLoader } from '../url-loader/url-loader';
22import { UrlResolver } from '../url-loader/url-resolver';
23import { AnalysisCache } from './analysis-cache';
24import { MinimalCancelToken } from './cancel-token';
25export declare const analyzerVersion: string;
26/**
27 * An analysis of a set of files at a specific point-in-time with respect to
28 * updates to those files. New files can be added to an existing context, but
29 * updates to files will cause a fork of the context with new analysis results.
30 *
31 * All file contents and analysis results are consistent within a single
32 * anaysis context. A context is forked via either the fileChanged or
33 * clearCaches methods.
34 *
35 * For almost all purposes this is an entirely internal implementation detail.
36 * An Analyzer instance has a reference to its current context, so it will
37 * appear to be statefull with respect to file updates.
38 */
39export declare class AnalysisContext {
40 readonly parsers: Map<string, Parser<ParsedDocument<{} | null | undefined, {}>>>;
41 private readonly _languageAnalyzers;
42 /** A map from import url to urls that document lazily depends on. */
43 private readonly _lazyEdges;
44 private readonly _scanners;
45 readonly loader: UrlLoader;
46 readonly resolver: UrlResolver;
47 private readonly _cache;
48 /** Incremented each time we fork. Useful for debugging. */
49 private readonly _generation;
50 /**
51 * Resolves when the previous analysis has completed.
52 *
53 * Used to serialize analysis requests, not for correctness surprisingly
54 * enough, but for performance, so that we can reuse AnalysisResults.
55 */
56 private _analysisComplete;
57 static getDefaultScanners(options: Options): Map<string, Scanner<ParsedDocument<{} | null | undefined, {}>, {} | null | undefined, {}>[]>;
58 constructor(options: Options, cache?: AnalysisCache, generation?: number);
59 /**
60 * Returns a copy of this cache context with proper cache invalidation.
61 */
62 filesChanged(urls: PackageRelativeUrl[]): AnalysisContext;
63 /**
64 * Implements Analyzer#analyze, see its docs.
65 */
66 analyze(urls: PackageRelativeUrl[], cancelToken: MinimalCancelToken): Promise<AnalysisContext>;
67 /**
68 * Internal analysis method called when we know we need to fork.
69 */
70 private _analyze;
71 /**
72 * Gets an analyzed Document from the document cache. This is only useful for
73 * Analyzer plugins. You almost certainly want to use `analyze()` instead.
74 *
75 * If a document has been analyzed, it returns the analyzed Document. If not
76 * the scanned document cache is used and a new analyzed Document is returned.
77 * If a file is in neither cache, it returns `undefined`.
78 */
79 getDocument(resolvedUrl: ResolvedUrl): Document | Warning;
80 /**
81 * This is only useful for Analyzer plugins.
82 *
83 * If a url has been scanned, returns the ScannedDocument.
84 */
85 _getScannedDocument(resolvedUrl: ResolvedUrl): ScannedDocument | undefined;
86 /**
87 * Clear all cached information from this analyzer instance.
88 *
89 * Note: if at all possible, instead tell the analyzer about the specific
90 * files that changed rather than clearing caches like this. Caching provides
91 * large performance gains.
92 */
93 clearCaches(): AnalysisContext;
94 /**
95 * Returns a copy of the context but with optional replacements of cache or
96 * constructor options.
97 *
98 * Note: this feature is experimental.
99 */
100 _fork(cache?: AnalysisCache, options?: ForkOptions): AnalysisContext;
101 /**
102 * Scans a file locally, that is for features that do not depend
103 * on this files imports. Local features can be cached even when
104 * imports are invalidated. This method does not trigger transitive
105 * scanning, _scan() does that.
106 *
107 * TODO(justinfagnani): consider renaming this to something like
108 * _preScan, since about the only useful things it can find are
109 * imports, exports and other syntactic structures.
110 */
111 private _scanLocal;
112 /**
113 * Scan a toplevel document and all of its transitive dependencies.
114 */
115 scan(resolvedUrl: ResolvedUrl, cancelToken: MinimalCancelToken): Promise<Result<ScannedDocument, Warning>>;
116 /**
117 * Scans a ParsedDocument.
118 */
119 private _scanDocument;
120 private _getScannedFeatures;
121 private _scanInlineDocuments;
122 /**
123 * Returns `true` if the provided resolved URL can be loaded. Obeys the
124 * semantics defined by `UrlLoader` and should only be used to check
125 * resolved URLs.
126 */
127 canLoad(resolvedUrl: ResolvedUrl): boolean;
128 /**
129 * Loads the content at the provided resolved URL. Obeys the semantics
130 * defined by `UrlLoader` and should only be used to attempt to load resolved
131 * URLs.
132 *
133 * Currently does no caching. If the provided contents are given then they
134 * are used instead of hitting the UrlLoader (e.g. when you have in-memory
135 * contents that should override disk).
136 */
137 load(resolvedUrl: ResolvedUrl): Promise<Result<string, string>>;
138 /**
139 * Caching + loading wrapper around _parseContents.
140 */
141 private _parse;
142 /**
143 * Parse the given string into the Abstract Syntax Tree (AST) corresponding
144 * to its type.
145 */
146 private _parseContents;
147 /**
148 * Resolves all resolvable URLs in the list, removes unresolvable ones.
149 */
150 resolveUserInputUrls(urls: PackageRelativeUrl[]): ResolvedUrl[];
151}