UNPKG

5.96 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 * as babel from '@babel/types';
15import { AnalysisContext } from '../core/analysis-context';
16import { ParsedCssDocument } from '../css/css-document';
17import { ParsedHtmlDocument } from '../html/html-document';
18import { JavaScriptDocument } from '../javascript/javascript-document';
19import { ParsedJsonDocument } from '../json/json-document';
20import { ParsedDocument } from '../parser/document';
21import { ParsedTypeScriptDocument } from '../typescript/typescript-document';
22import { Feature, ScannedFeature } from './feature';
23import { ImmutableSet } from './immutable';
24import { AstNodeWithLanguage } from './inline-document';
25import { DocumentQuery as Query, DocumentQueryWithKind as QueryWithKind, FeatureKind, FeatureKindMap, Queryable } from './queryable';
26import { SourceRange } from './source-range';
27import { ResolvedUrl } from './url';
28import { Warning } from './warning';
29/**
30 * The metadata for all features and elements defined in one document
31 */
32export declare class ScannedDocument {
33 document: ParsedDocument;
34 features: ScannedFeature[];
35 warnings: Warning[];
36 isInline: boolean;
37 readonly sourceRange: SourceRange;
38 readonly astNode: AstNodeWithLanguage | undefined;
39 constructor(document: ParsedDocument, features: ScannedFeature[], warnings?: Warning[]);
40 readonly url: ResolvedUrl;
41 /**
42 * Gets all features in this scanned document and all inline documents it
43 * contains.
44 */
45 getNestedFeatures(): ScannedFeature[];
46 private _getNestedFeatures;
47}
48export interface DeclaredWithStatement {
49 /**
50 * This is the nearest statement at or above `this.astNode`.
51 *
52 * This is a fast and simple way to get a canonical, indexable AST node,
53 * so that we can look up a feature syntactically.
54 *
55 * Populate this field with `esutil.getCanonicalStatement`.
56 */
57 statementAst: babel.Statement | undefined;
58}
59declare module './queryable' {
60 interface FeatureKindMap {
61 'document': Document;
62 'html-document': Document<ParsedHtmlDocument>;
63 'js-document': Document<JavaScriptDocument>;
64 'json-document': Document<ParsedJsonDocument>;
65 'css-document': Document<ParsedCssDocument>;
66 'typescript-document': Document<ParsedTypeScriptDocument>;
67 }
68}
69export declare class Document<ParsedType extends ParsedDocument = ParsedDocument> implements Feature, Queryable {
70 readonly kinds: ImmutableSet<string>;
71 readonly identifiers: ImmutableSet<string>;
72 /**
73 * AnalysisContext is a private type. Only internal analyzer code should touch
74 * this field.
75 */
76 _analysisContext: AnalysisContext;
77 warnings: Warning[];
78 languageAnalysis?: {};
79 private readonly _localFeatures;
80 private readonly _scannedDocument;
81 private readonly _localFeaturesByStatement;
82 /**
83 * To handle recursive dependency graphs we must track whether we've started
84 * resolving this Document so that we can reliably early exit even if one
85 * of our dependencies tries to resolve this document.
86 */
87 private _begunResolving;
88 /**
89 * True after this document and all of its children are finished resolving.
90 */
91 private _doneResolving;
92 constructor(base: ScannedDocument, analyzer: AnalysisContext, languageAnalysis?: {});
93 readonly url: ResolvedUrl;
94 readonly isInline: boolean;
95 readonly sourceRange: SourceRange | undefined;
96 readonly astNode: AstNodeWithLanguage | undefined;
97 readonly parsedDocument: ParsedType;
98 readonly resolved: boolean;
99 readonly type: string;
100 /**
101 * Resolves all features of this document, so that they have references to all
102 * their dependencies.
103 *
104 * This method can only be called once
105 */
106 resolve(): void;
107 /**
108 * Adds and indexes a feature to this document before resolve().
109 */
110 _addFeature(feature: Feature): void;
111 /**
112 * Get features on the document.
113 *
114 * Be default it includes only features on the document, but you can specify
115 * whether to include features that are reachable by imports, features from
116 * outside the current package, etc. See the documentation for Query for more
117 * details.
118 *
119 * You can also narrow by feature kind and identifier.
120 */
121 getFeatures<K extends FeatureKind>(query: QueryWithKind<K>): Set<FeatureKindMap[K]>;
122 getFeatures(query?: Query): Set<Feature>;
123 private _getByKind;
124 private _getById;
125 private _getByStatement;
126 /** Filters out the given features by the given kind. */
127 private _filterByKind;
128 private _isCachable;
129 private _getSlowlyByKind;
130 /**
131 * Walks the graph of documents, starting from `this`, finding features which
132 * match the given query and adding them to the `result` set. Uses `visited`
133 * to deal with cycles.
134 *
135 * This method is O(numFeatures), though it does not walk documents that are
136 * not relevant to the query (e.g. based on whether the query follows imports,
137 * or excludes lazy imports)
138 */
139 private _listFeatures;
140 private _filterOutExternal;
141 /**
142 * Get warnings for the document and all matched features.
143 */
144 getWarnings(query?: Query): Warning[];
145 toString(): string;
146 private _toString;
147 stringify(): string;
148 private _indexFeature;
149 private _featuresByKind;
150 private _featuresByKindAndId;
151 private _buildIndexes;
152}