@oicl-lit/analyzer 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/README.md +76 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +10 -0
- package/index.js.map +1 -0
- package/lib/analyzer.d.ts +47 -0
- package/lib/analyzer.d.ts.map +1 -0
- package/lib/analyzer.js +90 -0
- package/lib/analyzer.js.map +1 -0
- package/lib/custom-elements/custom-elements.d.ts +33 -0
- package/lib/custom-elements/custom-elements.d.ts.map +1 -0
- package/lib/custom-elements/custom-elements.js +124 -0
- package/lib/custom-elements/custom-elements.js.map +1 -0
- package/lib/custom-elements/events.d.ts +19 -0
- package/lib/custom-elements/events.d.ts.map +1 -0
- package/lib/custom-elements/events.js +25 -0
- package/lib/custom-elements/events.js.map +1 -0
- package/lib/diagnostic-code.d.ts +21 -0
- package/lib/diagnostic-code.d.ts.map +1 -0
- package/lib/diagnostic-code.js +20 -0
- package/lib/diagnostic-code.js.map +1 -0
- package/lib/errors.d.ts +24 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +17 -0
- package/lib/errors.js.map +1 -0
- package/lib/javascript/classes.d.ts +50 -0
- package/lib/javascript/classes.d.ts.map +1 -0
- package/lib/javascript/classes.js +307 -0
- package/lib/javascript/classes.js.map +1 -0
- package/lib/javascript/functions.d.ts +31 -0
- package/lib/javascript/functions.d.ts.map +1 -0
- package/lib/javascript/functions.js +144 -0
- package/lib/javascript/functions.js.map +1 -0
- package/lib/javascript/jsdoc.d.ts +67 -0
- package/lib/javascript/jsdoc.d.ts.map +1 -0
- package/lib/javascript/jsdoc.js +244 -0
- package/lib/javascript/jsdoc.js.map +1 -0
- package/lib/javascript/mixins.d.ts +45 -0
- package/lib/javascript/mixins.d.ts.map +1 -0
- package/lib/javascript/mixins.js +147 -0
- package/lib/javascript/mixins.js.map +1 -0
- package/lib/javascript/modules.d.ts +42 -0
- package/lib/javascript/modules.d.ts.map +1 -0
- package/lib/javascript/modules.js +277 -0
- package/lib/javascript/modules.js.map +1 -0
- package/lib/javascript/packages.d.ts +18 -0
- package/lib/javascript/packages.d.ts.map +1 -0
- package/lib/javascript/packages.js +53 -0
- package/lib/javascript/packages.js.map +1 -0
- package/lib/javascript/variables.d.ts +29 -0
- package/lib/javascript/variables.d.ts.map +1 -0
- package/lib/javascript/variables.js +143 -0
- package/lib/javascript/variables.js.map +1 -0
- package/lib/lit/decorators.d.ts +36 -0
- package/lib/lit/decorators.d.ts.map +1 -0
- package/lib/lit/decorators.js +32 -0
- package/lib/lit/decorators.js.map +1 -0
- package/lib/lit/lit-element.d.ts +39 -0
- package/lib/lit/lit-element.d.ts.map +1 -0
- package/lib/lit/lit-element.js +96 -0
- package/lib/lit/lit-element.js.map +1 -0
- package/lib/lit/modules.d.ts +28 -0
- package/lib/lit/modules.d.ts.map +1 -0
- package/lib/lit/modules.js +62 -0
- package/lib/lit/modules.js.map +1 -0
- package/lib/lit/properties.d.ts +43 -0
- package/lib/lit/properties.d.ts.map +1 -0
- package/lib/lit/properties.js +268 -0
- package/lib/lit/properties.js.map +1 -0
- package/lib/lit/template.d.ts +110 -0
- package/lib/lit/template.d.ts.map +1 -0
- package/lib/lit/template.js +412 -0
- package/lib/lit/template.js.map +1 -0
- package/lib/lit-element/decorators.d.ts +11 -0
- package/lib/lit-element/decorators.d.ts.map +1 -0
- package/lib/lit-element/decorators.js +11 -0
- package/lib/lit-element/decorators.js.map +1 -0
- package/lib/lit-element/lit-element.d.ts +11 -0
- package/lib/lit-element/lit-element.d.ts.map +1 -0
- package/lib/lit-element/lit-element.js +11 -0
- package/lib/lit-element/lit-element.js.map +1 -0
- package/lib/lit-element/properties.d.ts +11 -0
- package/lib/lit-element/properties.d.ts.map +1 -0
- package/lib/lit-element/properties.js +11 -0
- package/lib/lit-element/properties.js.map +1 -0
- package/lib/model.d.ts +506 -0
- package/lib/model.d.ts.map +1 -0
- package/lib/model.js +392 -0
- package/lib/model.js.map +1 -0
- package/lib/package-analyzer.d.ts +25 -0
- package/lib/package-analyzer.d.ts.map +1 -0
- package/lib/package-analyzer.js +81 -0
- package/lib/package-analyzer.js.map +1 -0
- package/lib/paths.d.ts +24 -0
- package/lib/paths.d.ts.map +1 -0
- package/lib/paths.js +35 -0
- package/lib/paths.js.map +1 -0
- package/lib/references.d.ts +107 -0
- package/lib/references.d.ts.map +1 -0
- package/lib/references.js +345 -0
- package/lib/references.js.map +1 -0
- package/lib/types.d.ts +25 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +257 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +22 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +51 -0
- package/lib/utils.js.map +1 -0
- package/package-analyzer.d.ts +8 -0
- package/package-analyzer.d.ts.map +1 -0
- package/package-analyzer.js +8 -0
- package/package-analyzer.js.map +1 -0
- package/package.json +109 -0
package/lib/model.js
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
export class PackageInfo {
|
|
7
|
+
constructor(init) {
|
|
8
|
+
this.name = init.name;
|
|
9
|
+
this.rootDir = init.rootDir;
|
|
10
|
+
this.packageJson = init.packageJson;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class Package extends PackageInfo {
|
|
14
|
+
constructor(init) {
|
|
15
|
+
super(init);
|
|
16
|
+
this.modules = init.modules;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns a list of modules in this package containing LitElement
|
|
20
|
+
* declarations, along with the filtered list of LitElementDeclarations.
|
|
21
|
+
*/
|
|
22
|
+
getLitElementModules() {
|
|
23
|
+
const modules = [];
|
|
24
|
+
for (const module of this.modules) {
|
|
25
|
+
const declarations = module.declarations.filter((d) => d.isLitElementDeclaration());
|
|
26
|
+
if (declarations.length > 0) {
|
|
27
|
+
modules.push({
|
|
28
|
+
module,
|
|
29
|
+
declarations,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return modules;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export class Module {
|
|
37
|
+
constructor(init) {
|
|
38
|
+
/**
|
|
39
|
+
* Private storage for all declarations within this module, memoized
|
|
40
|
+
* in `get declarations()` getter.
|
|
41
|
+
*/
|
|
42
|
+
this._declarations = undefined;
|
|
43
|
+
this.sourceFile = init.sourceFile;
|
|
44
|
+
this.sourcePath = init.sourcePath;
|
|
45
|
+
this.jsPath = init.jsPath;
|
|
46
|
+
this.packageJson = init.packageJson;
|
|
47
|
+
this._declarationMap = init.declarationMap;
|
|
48
|
+
this.dependencies = init.dependencies;
|
|
49
|
+
this._exportMap = init.exportMap;
|
|
50
|
+
this._finalizeExports = init.finalizeExports;
|
|
51
|
+
this.description = init.description;
|
|
52
|
+
this.summary = init.summary;
|
|
53
|
+
this.deprecated = init.deprecated;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Ensures the list of exports includes the names of all reexports
|
|
57
|
+
* from other modules.
|
|
58
|
+
*/
|
|
59
|
+
_ensureExportsFinalized() {
|
|
60
|
+
if (this._finalizeExports !== undefined) {
|
|
61
|
+
this._finalizeExports();
|
|
62
|
+
this._finalizeExports = undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns names of all exported declarations.
|
|
67
|
+
*/
|
|
68
|
+
get exportNames() {
|
|
69
|
+
this._ensureExportsFinalized();
|
|
70
|
+
return Array.from(this._exportMap.keys());
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Given an exported symbol name, returns a Declaration if it was
|
|
74
|
+
* defined in this module, or a Reference if it was imported from
|
|
75
|
+
* another module.
|
|
76
|
+
*/
|
|
77
|
+
getExport(name) {
|
|
78
|
+
this._ensureExportsFinalized();
|
|
79
|
+
const exp = this._exportMap.get(name);
|
|
80
|
+
if (exp === undefined) {
|
|
81
|
+
throw new Error(`Module ${this.sourcePath} did not contain an export named ${name}`);
|
|
82
|
+
}
|
|
83
|
+
else if (exp instanceof Reference) {
|
|
84
|
+
return exp;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return this.getDeclaration(exp);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Return Reference for given export name.
|
|
92
|
+
*
|
|
93
|
+
* For references to local declarations, the module will be undefined.
|
|
94
|
+
* For re-exports, the Reference will point to a package & module.
|
|
95
|
+
*/
|
|
96
|
+
getExportReference(name) {
|
|
97
|
+
const exp = this.getExport(name);
|
|
98
|
+
if (exp instanceof Declaration) {
|
|
99
|
+
return new Reference({ name: exp.name, dereference: () => exp });
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return exp;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Given an exported symbol name, returns the concrete Declaration
|
|
107
|
+
* for that symbol, following it through any re-exports.
|
|
108
|
+
*/
|
|
109
|
+
getResolvedExport(name) {
|
|
110
|
+
let exp = this.getExport(name);
|
|
111
|
+
while (exp instanceof Reference) {
|
|
112
|
+
exp = exp.dereference();
|
|
113
|
+
}
|
|
114
|
+
return exp;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Returns a `Declaration` model for the given name in top-level module scope.
|
|
118
|
+
*
|
|
119
|
+
* Note, the name is local to the module, and the declaration may be exported
|
|
120
|
+
* from with a different name. The declaration is always concrete, and will
|
|
121
|
+
* never be a `Reference`.
|
|
122
|
+
*/
|
|
123
|
+
getDeclaration(name) {
|
|
124
|
+
let dec = this._declarationMap.get(name);
|
|
125
|
+
if (dec === undefined) {
|
|
126
|
+
throw new Error(`Module ${this.sourcePath} did not contain a declaration named ${name}`);
|
|
127
|
+
}
|
|
128
|
+
// Overwrite a factory with its output (a `Declaration` model) on first
|
|
129
|
+
// request
|
|
130
|
+
if (typeof dec === 'function') {
|
|
131
|
+
this._declarationMap.set(name, (dec = dec()));
|
|
132
|
+
}
|
|
133
|
+
return dec;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns a list of all Declarations locally defined in this module.
|
|
137
|
+
*/
|
|
138
|
+
get declarations() {
|
|
139
|
+
return (this._declarations ??= Array.from(this._declarationMap.keys()).map((name) => this.getDeclaration(name)));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Returns all custom elements registered in this module.
|
|
143
|
+
*/
|
|
144
|
+
getCustomElementExports() {
|
|
145
|
+
return this.declarations.filter((d) => d.isLitElementDeclaration() && d.tagname !== undefined);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export class Declaration {
|
|
149
|
+
constructor(init) {
|
|
150
|
+
this.name = init.name;
|
|
151
|
+
this.description = init.description;
|
|
152
|
+
this.summary = init.summary;
|
|
153
|
+
this.deprecated = init.deprecated;
|
|
154
|
+
this.node = init.node;
|
|
155
|
+
}
|
|
156
|
+
isVariableDeclaration() {
|
|
157
|
+
return this instanceof VariableDeclaration;
|
|
158
|
+
}
|
|
159
|
+
isClassDeclaration() {
|
|
160
|
+
return this instanceof ClassDeclaration;
|
|
161
|
+
}
|
|
162
|
+
isLitElementDeclaration() {
|
|
163
|
+
return this instanceof LitElementDeclaration;
|
|
164
|
+
}
|
|
165
|
+
isFunctionDeclaration() {
|
|
166
|
+
return this instanceof FunctionDeclaration;
|
|
167
|
+
}
|
|
168
|
+
isMixinDeclaration() {
|
|
169
|
+
return this instanceof MixinDeclaration;
|
|
170
|
+
}
|
|
171
|
+
isClassField() {
|
|
172
|
+
return this instanceof ClassField;
|
|
173
|
+
}
|
|
174
|
+
isClassMethod() {
|
|
175
|
+
return this instanceof ClassMethod;
|
|
176
|
+
}
|
|
177
|
+
isCustomElementDeclaration() {
|
|
178
|
+
return this instanceof CustomElementDeclaration;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
export class VariableDeclaration extends Declaration {
|
|
182
|
+
constructor(init) {
|
|
183
|
+
super(init);
|
|
184
|
+
this.type = init.type;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export class FunctionDeclaration extends Declaration {
|
|
188
|
+
constructor(init) {
|
|
189
|
+
super(init);
|
|
190
|
+
this.parameters = init.parameters;
|
|
191
|
+
this.return = init.return;
|
|
192
|
+
this.overloads = init.overloads;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export class FunctionOverloadDeclaration extends FunctionDeclaration {
|
|
196
|
+
constructor(init) {
|
|
197
|
+
super(init);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
export class ClassMethod extends FunctionDeclaration {
|
|
201
|
+
constructor(init) {
|
|
202
|
+
super(init);
|
|
203
|
+
this.static = init.static;
|
|
204
|
+
this.privacy = init.privacy;
|
|
205
|
+
this.inheritedFrom = init.inheritedFrom;
|
|
206
|
+
this.source = init.source;
|
|
207
|
+
this.node = init.node;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
export class ClassField extends Declaration {
|
|
211
|
+
constructor(init) {
|
|
212
|
+
super(init);
|
|
213
|
+
this.static = init.static;
|
|
214
|
+
this.privacy = init.privacy;
|
|
215
|
+
this.inheritedFrom = init.inheritedFrom;
|
|
216
|
+
this.source = init.source;
|
|
217
|
+
this.type = init.type;
|
|
218
|
+
this.default = init.default;
|
|
219
|
+
this.readonly = init.readonly;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
export class ClassDeclaration extends Declaration {
|
|
223
|
+
constructor(init) {
|
|
224
|
+
super(init);
|
|
225
|
+
this._heritage = undefined;
|
|
226
|
+
this.node = init.node;
|
|
227
|
+
this._getHeritage = init.getHeritage;
|
|
228
|
+
this._fieldMap = init.fieldMap ?? new Map();
|
|
229
|
+
this._staticFieldMap = init.staticFieldMap ?? new Map();
|
|
230
|
+
this._methodMap = init.methodMap ?? new Map();
|
|
231
|
+
this._staticMethodMap = init.staticMethodMap ?? new Map();
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Returns this class's `ClassHeritage` model, with references to its
|
|
235
|
+
* `superClass` and `mixins`.
|
|
236
|
+
*/
|
|
237
|
+
get heritage() {
|
|
238
|
+
return (this._heritage ??= this._getHeritage());
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Returns iterator of the non-static `ClassField`s defined on the immediate
|
|
242
|
+
* class (excluding any inherited members).
|
|
243
|
+
*/
|
|
244
|
+
get fields() {
|
|
245
|
+
return this._fieldMap.values();
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Returns iterator of the static `ClassField`s defined on the immediate class
|
|
249
|
+
* (excluding any inherited members).
|
|
250
|
+
*/
|
|
251
|
+
get staticFields() {
|
|
252
|
+
return this._staticFieldMap.values();
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Returns iterator of the non-static `ClassMethod`s defined on the immediate
|
|
256
|
+
* class (excluding any inherited members).
|
|
257
|
+
*/
|
|
258
|
+
get methods() {
|
|
259
|
+
return this._methodMap.values();
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Returns iterator of the static `ClassMethod`s defined on the immediate
|
|
263
|
+
* class (excluding any inherited members).
|
|
264
|
+
*/
|
|
265
|
+
get staticMethods() {
|
|
266
|
+
return this._staticMethodMap.values();
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Returns a non-static `ClassField` model the given name defined on the
|
|
270
|
+
* immediate class (excluding any inherited members).
|
|
271
|
+
*/
|
|
272
|
+
getField(name) {
|
|
273
|
+
return this._fieldMap.get(name);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Returns a static `ClassField` model the given name defined on the immediate
|
|
277
|
+
* class (excluding any inherited members).
|
|
278
|
+
*/
|
|
279
|
+
getStaticField(name) {
|
|
280
|
+
return this._staticFieldMap.get(name);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Returns a non-static `ClassMethod` model for the given name defined on the
|
|
284
|
+
* immediate class (excluding any inherited members).
|
|
285
|
+
*/
|
|
286
|
+
getMethod(name) {
|
|
287
|
+
return this._methodMap.get(name);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Returns a static `ClassMethod` model for the given name defined on the
|
|
291
|
+
* immediate class (excluding any inherited members).
|
|
292
|
+
*/
|
|
293
|
+
getStaticMethod(name) {
|
|
294
|
+
return this._staticMethodMap.get(name);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Returns a `ClassField` or `ClassMethod` model for the given name defined on
|
|
298
|
+
* the immediate class (excluding any inherited members).
|
|
299
|
+
*
|
|
300
|
+
* Note that if a field and method of the same name were defined (error is TS,
|
|
301
|
+
* but possible in JS), the `ClassField` will be returned from this method, as
|
|
302
|
+
* it takes precedence by virtue of being an instance property (vs. a method,
|
|
303
|
+
* which is defined on the prototype).
|
|
304
|
+
*/
|
|
305
|
+
getMember(name) {
|
|
306
|
+
return this.getField(name) ?? this.getMethod(name);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
export class MixinDeclaration extends FunctionDeclaration {
|
|
310
|
+
constructor(init) {
|
|
311
|
+
super(init);
|
|
312
|
+
this.classDeclaration = init.classDeclaration;
|
|
313
|
+
this.superClassArgIndex = init.superClassArgIndex;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
export class CustomElementDeclaration extends ClassDeclaration {
|
|
317
|
+
constructor(init) {
|
|
318
|
+
super(init);
|
|
319
|
+
this.tagname = init.tagname;
|
|
320
|
+
this.events = init.events;
|
|
321
|
+
this.slots = init.slots;
|
|
322
|
+
this.cssProperties = init.cssProperties;
|
|
323
|
+
this.cssParts = init.cssParts;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
export class LitElementDeclaration extends CustomElementDeclaration {
|
|
327
|
+
constructor(init) {
|
|
328
|
+
super(init);
|
|
329
|
+
this.reactiveProperties = init.reactiveProperties;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
export class Reference {
|
|
333
|
+
constructor(init) {
|
|
334
|
+
this._model = undefined;
|
|
335
|
+
this.name = init.name;
|
|
336
|
+
this.package = init.package;
|
|
337
|
+
this.module = init.module;
|
|
338
|
+
this.isGlobal = init.isGlobal ?? false;
|
|
339
|
+
this._dereference = init.dereference ?? (() => undefined);
|
|
340
|
+
}
|
|
341
|
+
get moduleSpecifier() {
|
|
342
|
+
const separator = this.package && this.module ? '/' : '';
|
|
343
|
+
return this.isGlobal
|
|
344
|
+
? undefined
|
|
345
|
+
: (this.package || '') + separator + (this.module || '');
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Returns the Declaration model that this reference points to, optionally
|
|
349
|
+
* validating (and casting) it to be of a given type by passing a model
|
|
350
|
+
* constructor.
|
|
351
|
+
*/
|
|
352
|
+
dereference(type) {
|
|
353
|
+
const model = (this._model ??= this._dereference());
|
|
354
|
+
if (type !== undefined && model !== undefined && !(model instanceof type)) {
|
|
355
|
+
throw new Error(`Expected reference to ${this.name} in module ${this.moduleSpecifier} to be of type ${type.name}`);
|
|
356
|
+
}
|
|
357
|
+
return model;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
export class Type {
|
|
361
|
+
constructor(init) {
|
|
362
|
+
this._references = undefined;
|
|
363
|
+
this.type = init.type;
|
|
364
|
+
this.text = init.text;
|
|
365
|
+
this._getReferences = init.getReferences;
|
|
366
|
+
}
|
|
367
|
+
get references() {
|
|
368
|
+
return (this._references ??= this._getReferences());
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Returns a deduped / coalesced string of import statements required to load
|
|
373
|
+
* the given references.
|
|
374
|
+
* TODO(kschaaf): Probably want to accept info about existing imports to dedupe
|
|
375
|
+
* with.
|
|
376
|
+
*/
|
|
377
|
+
export const getImportsStringForReferences = (references) => {
|
|
378
|
+
const modules = new Map();
|
|
379
|
+
for (const { moduleSpecifier, name, isGlobal } of references) {
|
|
380
|
+
if (!isGlobal) {
|
|
381
|
+
let namesForModule = modules.get(moduleSpecifier);
|
|
382
|
+
if (namesForModule === undefined) {
|
|
383
|
+
modules.set(moduleSpecifier, (namesForModule = new Set()));
|
|
384
|
+
}
|
|
385
|
+
namesForModule.add(name);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return Array.from(modules)
|
|
389
|
+
.map(([moduleSpecifier, namesForModule]) => `import {${Array.from(namesForModule).join(', ')}} from '${moduleSpecifier}';`)
|
|
390
|
+
.join('\n');
|
|
391
|
+
};
|
|
392
|
+
//# sourceMappingURL=model.js.map
|
package/lib/model.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/lib/model.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4BH,MAAM,OAAO,WAAW;IAKtB,YAAY,IAAqB;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IACtC,CAAC;CACF;AAMD,MAAM,OAAO,OAAQ,SAAQ,WAAW;IAGtC,YAAY,IAAiB;QAC3B,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACH,oBAAoB;QAClB,MAAM,OAAO,GACX,EAAE,CAAC;QACL,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CACpD,CAAC,CAAC,uBAAuB,EAAE,CACD,CAAC;YAC7B,IAAI,YAAY,CA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c,KAAK,SAAS,EAAE,CAAC;gBACjC,OAAO,CAAC,GAAG,CAAC,eAAgB,EAAE,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;YAC9D,CAAC;YACD,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;SACvB,GAAG,CACF,CAAC,CAAC,eAAe,EAAE,cAAc,CAAC,EAAE,EAAE,CACpC,WAAW,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CACxC,IAAI,CACL,WAAW,eAAe,IAAI,CAClC;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport type ts from 'typescript';\nimport {AbsolutePath, PackagePath} from './paths.js';\n\nimport {IPackageJson as PackageJson} from 'package-json-type';\nexport {PackageJson};\n\nexport type TypeScript = typeof ts;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Constructor<T> = new (...args: any[]) => T;\n\n/**\n * Return type of `getLitElementModules`: contains a module and filtered list of\n * LitElementDeclarations contained within it.\n */\nexport type ModuleWithLitElementDeclarations = {\n module: Module;\n declarations: LitElementDeclaration[];\n};\n\nexport interface PackageInfoInit {\n name: string;\n rootDir: AbsolutePath;\n packageJson: PackageJson;\n}\n\nexport class PackageInfo {\n readonly name: string;\n readonly rootDir: AbsolutePath;\n readonly packageJson: PackageJson;\n\n constructor(init: PackageInfoInit) {\n this.name = init.name;\n this.rootDir = init.rootDir;\n this.packageJson = init.packageJson;\n }\n}\n\nexport interface PackageInit extends PackageInfo {\n modules: ReadonlyArray<Module>;\n}\n\nexport class Package extends PackageInfo {\n readonly modules: ReadonlyArray<Module>;\n\n constructor(init: PackageInit) {\n super(init);\n this.modules = init.modules;\n }\n\n /**\n * Returns a list of modules in this package containing LitElement\n * declarations, along with the filtered list of LitElementDeclarations.\n */\n getLitElementModules() {\n const modules: {module: Module; declarations: LitElementDeclaration[]}[] =\n [];\n for (const module of this.modules) {\n const declarations = module.declarations.filter((d) =>\n d.isLitElementDeclaration()\n ) as LitElementDeclaration[];\n if (declarations.length > 0) {\n modules.push({\n module,\n declarations,\n });\n }\n }\n return modules;\n }\n}\n\nexport type LocalNameOrReference = string | Reference;\nexport type ExportMap = Map<string, LocalNameOrReference>;\nexport type DeclarationMap = Map<string, Declaration | (() => Declaration)>;\n\nexport interface ModuleInit extends DeprecatableDescribed {\n sourceFile: ts.SourceFile;\n sourcePath: PackagePath;\n jsPath: PackagePath;\n packageJson: PackageJson;\n declarationMap: DeclarationMap;\n exportMap: ExportMap;\n dependencies: Set<AbsolutePath>;\n finalizeExports?: () => void;\n}\n\nexport interface ModuleInfo {\n sourcePath: PackagePath;\n jsPath: PackagePath;\n packageJson: PackageJson;\n}\n\nexport class Module {\n /**\n * The TS AST node for the file\n */\n readonly sourceFile: ts.SourceFile;\n /**\n * The path to the source file for this module. In a TS project, this will be\n * a .ts file. In a JS project, this will be the same as `jsPath`.\n */\n readonly sourcePath: PackagePath;\n /**\n * The path to the javascript file for this module. In a TS project, this will\n * be the output location of the compiler for the given `sourcePath`. In a JS\n * project this will be the same as `sourcePath`.\n */\n readonly jsPath: PackagePath;\n /**\n * A map of names to models or model factories for all Declarations in this module.\n */\n private readonly _declarationMap: DeclarationMap;\n /**\n * Private storage for all declarations within this module, memoized\n * in `get declarations()` getter.\n */\n private _declarations: Declaration[] | undefined = undefined;\n /**\n * A set of all dependencies of this module, as module absolute paths.\n */\n readonly dependencies: Set<AbsolutePath>;\n /**\n * The package.json contents for the package containing this module.\n */\n readonly packageJson: PackageJson;\n /**\n * A map of exported names to local declaration names or References, in\n * the case of re-exported symbols.\n */\n private readonly _exportMap: ExportMap;\n /**\n * A list of module paths for all wildcard re-exports\n */\n private _finalizeExports: (() => void) | undefined;\n /**\n * The module's user-facing description.\n */\n readonly description?: string | undefined;\n /**\n * The module's user-facing summary.\n */\n readonly summary?: string | undefined;\n /**\n * The module's user-facing deprecation status.\n */\n readonly deprecated?: string | boolean | undefined;\n\n constructor(init: ModuleInit) {\n this.sourceFile = init.sourceFile;\n this.sourcePath = init.sourcePath;\n this.jsPath = init.jsPath;\n this.packageJson = init.packageJson;\n this._declarationMap = init.declarationMap;\n this.dependencies = init.dependencies;\n this._exportMap = init.exportMap;\n this._finalizeExports = init.finalizeExports;\n this.description = init.description;\n this.summary = init.summary;\n this.deprecated = init.deprecated;\n }\n\n /**\n * Ensures the list of exports includes the names of all reexports\n * from other modules.\n */\n private _ensureExportsFinalized() {\n if (this._finalizeExports !== undefined) {\n this._finalizeExports();\n this._finalizeExports = undefined;\n }\n }\n\n /**\n * Returns names of all exported declarations.\n */\n get exportNames() {\n this._ensureExportsFinalized();\n return Array.from(this._exportMap.keys());\n }\n\n /**\n * Given an exported symbol name, returns a Declaration if it was\n * defined in this module, or a Reference if it was imported from\n * another module.\n */\n getExport(name: string): Declaration | Reference {\n this._ensureExportsFinalized();\n const exp = this._exportMap.get(name);\n if (exp === undefined) {\n throw new Error(\n `Module ${this.sourcePath} did not contain an export named ${name}`\n );\n } else if (exp instanceof Reference) {\n return exp;\n } else {\n return this.getDeclaration(exp);\n }\n }\n\n /**\n * Return Reference for given export name.\n *\n * For references to local declarations, the module will be undefined.\n * For re-exports, the Reference will point to a package & module.\n */\n getExportReference(name: string): Reference {\n const exp = this.getExport(name);\n if (exp instanceof Declaration) {\n return new Reference({name: exp.name, dereference: () => exp});\n } else {\n return exp;\n }\n }\n\n /**\n * Given an exported symbol name, returns the concrete Declaration\n * for that symbol, following it through any re-exports.\n */\n getResolvedExport(name: string): Declaration {\n let exp = this.getExport(name);\n while (exp instanceof Reference) {\n exp = exp.dereference();\n }\n return exp as Declaration;\n }\n\n /**\n * Returns a `Declaration` model for the given name in top-level module scope.\n *\n * Note, the name is local to the module, and the declaration may be exported\n * from with a different name. The declaration is always concrete, and will\n * never be a `Reference`.\n */\n getDeclaration(name: string): Declaration {\n let dec = this._declarationMap.get(name);\n if (dec === undefined) {\n throw new Error(\n `Module ${this.sourcePath} did not contain a declaration named ${name}`\n );\n }\n // Overwrite a factory with its output (a `Declaration` model) on first\n // request\n if (typeof dec === 'function') {\n this._declarationMap.set(name, (dec = dec()));\n }\n return dec;\n }\n\n /**\n * Returns a list of all Declarations locally defined in this module.\n */\n get declarations() {\n return (this._declarations ??= Array.from(this._declarationMap.keys()).map(\n (name) => this.getDeclaration(name)\n ));\n }\n\n /**\n * Returns all custom elements registered in this module.\n */\n getCustomElementExports(): LitElementExport[] {\n return this.declarations.filter(\n (d) => d.isLitElementDeclaration() && d.tagname !== undefined\n ) as LitElementExport[];\n }\n}\n\ninterface DeclarationInit extends DeprecatableDescribed {\n name: string;\n node: ts.Node;\n}\n\nexport abstract class Declaration {\n readonly name: string;\n readonly description?: string | undefined;\n readonly summary?: string | undefined;\n readonly deprecated?: string | boolean | undefined;\n readonly node: ts.Node;\n\n constructor(init: DeclarationInit) {\n this.name = init.name;\n this.description = init.description;\n this.summary = init.summary;\n this.deprecated = init.deprecated;\n this.node = init.node;\n }\n\n isVariableDeclaration(): this is VariableDeclaration {\n return this instanceof VariableDeclaration;\n }\n\n isClassDeclaration(): this is ClassDeclaration {\n return this instanceof ClassDeclaration;\n }\n\n isLitElementDeclaration(): this is LitElementDeclaration {\n return this instanceof LitElementDeclaration;\n }\n\n isFunctionDeclaration(): this is FunctionDeclaration {\n return this instanceof FunctionDeclaration;\n }\n\n isMixinDeclaration(): this is MixinDeclaration {\n return this instanceof MixinDeclaration;\n }\n\n isClassField(): this is ClassField {\n return this instanceof ClassField;\n }\n\n isClassMethod(): this is ClassMethod {\n return this instanceof ClassMethod;\n }\n\n isCustomElementDeclaration(): this is CustomElementDeclaration {\n return this instanceof CustomElementDeclaration;\n }\n}\n\nexport interface VariableDeclarationInit extends DeclarationInit {\n node: ts.VariableDeclaration | ts.ExportAssignment | ts.EnumDeclaration;\n type: Type | undefined;\n}\n\nexport class VariableDeclaration extends Declaration {\n readonly type: Type | undefined;\n declare readonly node:\n | ts.VariableDeclaration\n | ts.ExportAssignment\n | ts.EnumDeclaration;\n\n constructor(init: VariableDeclarationInit) {\n super(init);\n this.type = init.type;\n }\n}\n\nexport interface FunctionLikeInit extends DeclarationInit {\n name: string;\n parameters?: Parameter[] | undefined;\n return?: Return | undefined;\n overloads?: FunctionOverloadDeclaration[] | undefined;\n node: ts.FunctionLikeDeclaration;\n}\n\nexport class FunctionDeclaration extends Declaration {\n parameters?: Parameter[] | undefined;\n return?: Return | undefined;\n overloads?: FunctionOverloadDeclaration[] | undefined;\n declare readonly node: ts.FunctionLikeDeclaration;\n\n constructor(init: FunctionLikeInit) {\n super(init);\n this.parameters = init.parameters;\n this.return = init.return;\n this.overloads = init.overloads;\n }\n}\n\nexport interface FunctionLikeOverloadInit extends FunctionLikeInit {\n overloads?: undefined;\n}\n\nexport class FunctionOverloadDeclaration extends FunctionDeclaration {\n override overloads: undefined;\n constructor(init: FunctionLikeOverloadInit) {\n super(init);\n }\n}\n\nexport type Privacy = 'public' | 'private' | 'protected';\n\nexport interface SourceReference {\n href: string;\n}\n\nexport interface ClassMethodInit extends FunctionLikeInit {\n static?: boolean | undefined;\n privacy?: Privacy | undefined;\n inheritedFrom?: Reference | undefined;\n source?: SourceReference | undefined;\n node: ts.MethodDeclaration;\n}\n\nexport class ClassMethod extends FunctionDeclaration {\n static?: boolean | undefined;\n privacy?: Privacy | undefined;\n inheritedFrom?: Reference | undefined;\n source?: SourceReference | undefined;\n override readonly node: ts.MethodDeclaration;\n\n constructor(init: ClassMethodInit) {\n super(init);\n this.static = init.static;\n this.privacy = init.privacy;\n this.inheritedFrom = init.inheritedFrom;\n this.source = init.source;\n this.node = init.node;\n }\n}\n\nexport interface ClassFieldInit extends DeclarationInit, PropertyLike {\n static?: boolean | undefined;\n privacy?: Privacy | undefined;\n inheritedFrom?: Reference | undefined;\n source?: SourceReference | undefined;\n readonly?: boolean | undefined;\n node:\n | ts.PropertyDeclaration\n | ts.AssignmentExpression<ts.EqualsToken>\n | ts.AccessorDeclaration;\n}\n\nexport class ClassField extends Declaration {\n static?: boolean | undefined;\n privacy?: Privacy | undefined;\n inheritedFrom?: Reference | undefined;\n source?: SourceReference | undefined;\n readonly?: boolean | undefined;\n type?: Type | undefined;\n default?: string | undefined;\n declare node:\n | ts.PropertyDeclaration\n | ts.AssignmentExpression<ts.EqualsToken>\n | ts.AccessorDeclaration;\n\n constructor(init: ClassFieldInit) {\n super(init);\n this.static = init.static;\n this.privacy = init.privacy;\n this.inheritedFrom = init.inheritedFrom;\n this.source = init.source;\n this.type = init.type;\n this.default = init.default;\n this.readonly = init.readonly;\n }\n}\n\nexport type ClassHeritage = {\n mixins: Reference[];\n superClass: Reference | undefined;\n};\n\nexport interface ClassDeclarationInit extends DeclarationInit {\n node: ts.ClassDeclaration | ts.ClassLikeDeclaration | ts.CallExpression;\n getHeritage: () => ClassHeritage;\n fieldMap?: Map<string, ClassField> | undefined;\n staticFieldMap?: Map<string, ClassField> | undefined;\n methodMap?: Map<string, ClassMethod> | undefined;\n staticMethodMap?: Map<string, ClassMethod> | undefined;\n}\n\nexport class ClassDeclaration extends Declaration {\n private _getHeritage: () => ClassHeritage;\n private _heritage: ClassHeritage | undefined = undefined;\n readonly _fieldMap: Map<string, ClassField>;\n readonly _staticFieldMap: Map<string, ClassField>;\n readonly _methodMap: Map<string, ClassMethod>;\n readonly _staticMethodMap: Map<string, ClassMethod>;\n override readonly node: ts.ClassLikeDeclaration | ts.CallExpression;\n\n constructor(init: ClassDeclarationInit) {\n super(init);\n this.node = init.node;\n this._getHeritage = init.getHeritage;\n this._fieldMap = init.fieldMap ?? new Map();\n this._staticFieldMap = init.staticFieldMap ?? new Map();\n this._methodMap = init.methodMap ?? new Map();\n this._staticMethodMap = init.staticMethodMap ?? new Map();\n }\n\n /**\n * Returns this class's `ClassHeritage` model, with references to its\n * `superClass` and `mixins`.\n */\n get heritage(): ClassHeritage {\n return (this._heritage ??= this._getHeritage());\n }\n\n /**\n * Returns iterator of the non-static `ClassField`s defined on the immediate\n * class (excluding any inherited members).\n */\n get fields(): IterableIterator<ClassField> {\n return this._fieldMap.values();\n }\n\n /**\n * Returns iterator of the static `ClassField`s defined on the immediate class\n * (excluding any inherited members).\n */\n get staticFields(): IterableIterator<ClassField> {\n return this._staticFieldMap.values();\n }\n\n /**\n * Returns iterator of the non-static `ClassMethod`s defined on the immediate\n * class (excluding any inherited members).\n */\n get methods(): IterableIterator<ClassMethod> {\n return this._methodMap.values();\n }\n\n /**\n * Returns iterator of the static `ClassMethod`s defined on the immediate\n * class (excluding any inherited members).\n */\n get staticMethods(): IterableIterator<ClassMethod> {\n return this._staticMethodMap.values();\n }\n\n /**\n * Returns a non-static `ClassField` model the given name defined on the\n * immediate class (excluding any inherited members).\n */\n getField(name: string): ClassField | undefined {\n return this._fieldMap.get(name);\n }\n\n /**\n * Returns a static `ClassField` model the given name defined on the immediate\n * class (excluding any inherited members).\n */\n getStaticField(name: string): ClassField | undefined {\n return this._staticFieldMap.get(name);\n }\n\n /**\n * Returns a non-static `ClassMethod` model for the given name defined on the\n * immediate class (excluding any inherited members).\n */\n getMethod(name: string): ClassMethod | undefined {\n return this._methodMap.get(name);\n }\n\n /**\n * Returns a static `ClassMethod` model for the given name defined on the\n * immediate class (excluding any inherited members).\n */\n getStaticMethod(name: string): ClassMethod | undefined {\n return this._staticMethodMap.get(name);\n }\n\n /**\n * Returns a `ClassField` or `ClassMethod` model for the given name defined on\n * the immediate class (excluding any inherited members).\n *\n * Note that if a field and method of the same name were defined (error is TS,\n * but possible in JS), the `ClassField` will be returned from this method, as\n * it takes precedence by virtue of being an instance property (vs. a method,\n * which is defined on the prototype).\n */\n getMember(name: string): ClassMethod | ClassField | undefined {\n return this.getField(name) ?? this.getMethod(name);\n }\n}\n\nexport interface MixinDeclarationInit extends FunctionLikeInit {\n classDeclaration: ClassDeclaration;\n superClassArgIndex: number;\n}\n\nexport class MixinDeclaration extends FunctionDeclaration {\n readonly classDeclaration: ClassDeclaration;\n readonly superClassArgIndex: number;\n constructor(init: MixinDeclarationInit) {\n super(init);\n this.classDeclaration = init.classDeclaration;\n this.superClassArgIndex = init.superClassArgIndex;\n }\n}\n\nexport interface Described {\n description?: string | undefined;\n summary?: string | undefined;\n}\n\nexport interface NamedDescribed extends Described {\n name: string;\n default?: string;\n}\n\nexport interface CSSPropertyInfo extends NamedDescribed {\n syntax?: string;\n}\n\nexport interface TypedNamedDescribed extends NamedDescribed {\n type?: string;\n}\n\nexport interface DeprecatableDescribed extends Described {\n deprecated?: string | boolean | undefined;\n}\n\ninterface CustomElementDeclarationInit extends ClassDeclarationInit {\n tagname: string | undefined;\n events: Map<string, Event>;\n slots: Map<string, NamedDescribed>;\n cssProperties: Map<string, CSSPropertyInfo>;\n cssParts: Map<string, NamedDescribed>;\n}\n\ninterface LitElementDeclarationInit extends CustomElementDeclarationInit {\n reactiveProperties: Map<string, ReactiveProperty>;\n}\n\nexport class CustomElementDeclaration extends ClassDeclaration {\n /**\n * The element's tag name, if one is associated with this class declaration,\n * such as with a `@customElement()` decorator or `customElements.define()`\n * call int he same module.\n *\n * This is undefined if the element has no associated custom element\n * registration in the same module. This class might be intended for use as a\n * base class or with scoped custom element registries.\n */\n readonly tagname: string | undefined;\n readonly events: Map<string, Event>;\n readonly slots: Map<string, NamedDescribed>;\n readonly cssProperties: Map<string, CSSPropertyInfo>;\n readonly cssParts: Map<string, NamedDescribed>;\n\n constructor(init: CustomElementDeclarationInit) {\n super(init);\n this.tagname = init.tagname;\n this.events = init.events;\n this.slots = init.slots;\n this.cssProperties = init.cssProperties;\n this.cssParts = init.cssParts;\n }\n}\n\nexport class LitElementDeclaration extends CustomElementDeclaration {\n readonly reactiveProperties: Map<string, ReactiveProperty>;\n\n constructor(init: LitElementDeclarationInit) {\n super(init);\n this.reactiveProperties = init.reactiveProperties;\n }\n}\n\n/**\n * A LitElementDeclaration that has been globally registered with a tagname.\n */\nexport interface LitElementExport extends LitElementDeclaration {\n tagname: string;\n}\n\nexport interface PropertyLike extends DeprecatableDescribed {\n name: string;\n node: ts.Node;\n type: Type | undefined;\n default?: string | undefined;\n}\n\nexport interface Return {\n type?: Type | undefined;\n summary?: string | undefined;\n description?: string | undefined;\n}\n\nexport interface Parameter extends PropertyLike {\n node: ts.ParameterDeclaration;\n optional?: boolean | undefined;\n rest?: boolean | undefined;\n}\n\nexport interface ReactiveProperty extends PropertyLike {\n /**\n * The property declaration.\n *\n * A ts.PropertyDeclaration if the property was declared as a class field,\n * or a ts.PropertyAssignment if the property was declared in a static\n * properties block.\n */\n node: ts.PropertyDeclaration | ts.PropertyAssignment;\n\n optionsNode: ts.ObjectLiteralExpression | undefined;\n\n reflect: boolean;\n\n // TODO(justinfagnani): should we convert into attribute name?\n attribute: boolean | string | undefined;\n\n /**\n * The test of the `type` property option.\n *\n * This is really only useful if the type is one of the well known types:\n * String, Number, or Boolean.\n */\n typeOption: string | undefined;\n\n /**\n * The Node for the `converter` option if present.\n *\n * This is mostly useful to know whether the `type` option can be interpreted\n * with the default semantics or not.\n */\n converter: ts.Node | undefined;\n\n // TODO(justinfagnani): hasChanged?\n}\n\nexport interface Event {\n name: string;\n description: string | undefined;\n summary: string | undefined;\n type: Type | undefined;\n}\n\nexport interface LitModule {\n module: Module;\n elements: LitElementDeclaration[];\n}\n\nexport interface ReferenceInit {\n name: string;\n package?: string | undefined;\n module?: string | undefined;\n isGlobal?: boolean;\n dereference?: () => Declaration | undefined;\n}\n\nexport class Reference {\n readonly name: string;\n readonly package: string | undefined;\n readonly module: string | undefined;\n readonly isGlobal: boolean;\n private readonly _dereference: () => Declaration | undefined;\n private _model: Declaration | undefined = undefined;\n constructor(init: ReferenceInit) {\n this.name = init.name;\n this.package = init.package;\n this.module = init.module;\n this.isGlobal = init.isGlobal ?? false;\n this._dereference = init.dereference ?? (() => undefined);\n }\n\n get moduleSpecifier() {\n const separator = this.package && this.module ? '/' : '';\n return this.isGlobal\n ? undefined\n : (this.package || '') + separator + (this.module || '');\n }\n\n /**\n * Returns the Declaration model that this reference points to, optionally\n * validating (and casting) it to be of a given type by passing a model\n * constructor.\n */\n dereference<T extends Declaration>(type?: Constructor<T> | undefined): T {\n const model = (this._model ??= this._dereference());\n if (type !== undefined && model !== undefined && !(model instanceof type)) {\n throw new Error(\n `Expected reference to ${this.name} in module ${this.moduleSpecifier} to be of type ${type.name}`\n );\n }\n return model as T;\n }\n}\n\nexport interface TypeInit {\n type: ts.Type;\n text: string;\n getReferences: () => Reference[];\n}\n\nexport class Type {\n type: ts.Type;\n text: string;\n private _getReferences: () => Reference[];\n private _references: Reference[] | undefined = undefined;\n\n constructor(init: TypeInit) {\n this.type = init.type;\n this.text = init.text;\n this._getReferences = init.getReferences;\n }\n\n get references() {\n return (this._references ??= this._getReferences());\n }\n}\n\n/**\n * Returns a deduped / coalesced string of import statements required to load\n * the given references.\n * TODO(kschaaf): Probably want to accept info about existing imports to dedupe\n * with.\n */\nexport const getImportsStringForReferences = (references: Reference[]) => {\n const modules = new Map<string, Set<string>>();\n for (const {moduleSpecifier, name, isGlobal} of references) {\n if (!isGlobal) {\n let namesForModule = modules.get(moduleSpecifier!);\n if (namesForModule === undefined) {\n modules.set(moduleSpecifier!, (namesForModule = new Set()));\n }\n namesForModule.add(name);\n }\n }\n return Array.from(modules)\n .map(\n ([moduleSpecifier, namesForModule]) =>\n `import {${Array.from(namesForModule).join(\n ', '\n )}} from '${moduleSpecifier}';`\n )\n .join('\\n');\n};\n\nexport interface AnalyzerInterface {\n moduleCache: Map<AbsolutePath, Module>;\n typescript: TypeScript;\n program: ts.Program;\n commandLine: ts.ParsedCommandLine;\n fs: Pick<\n ts.System,\n | 'readDirectory'\n | 'readFile'\n | 'realpath'\n | 'fileExists'\n | 'useCaseSensitiveFileNames'\n >;\n path: Pick<\n typeof import('path'),\n | 'join'\n | 'relative'\n | 'dirname'\n | 'basename'\n | 'dirname'\n | 'parse'\n | 'normalize'\n | 'isAbsolute'\n | 'sep'\n >;\n\n addDiagnostic(diagnostic: ts.Diagnostic): void;\n getDiagnostics(): IterableIterator<ts.Diagnostic>;\n}\n\n/**\n * The name, model factory, and export information about a given declaration.\n */\nexport type DeclarationInfo = {\n name: string;\n node: ts.Node;\n factory: () => Declaration;\n isExport?: boolean;\n};\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import { AbsolutePath } from './paths.js';
|
|
7
|
+
import { Analyzer } from './analyzer.js';
|
|
8
|
+
export interface AnalyzerOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Glob of source files to exclude from project during analysis.
|
|
11
|
+
*
|
|
12
|
+
* Useful for excluding things source like test folders that might otherwise
|
|
13
|
+
* be included in a project's tsconfig.
|
|
14
|
+
*/
|
|
15
|
+
exclude?: string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns an analyzer for a Lit npm package based on a filesystem path.
|
|
19
|
+
*
|
|
20
|
+
* The path may specify a package root folder, or a specific tsconfig file. When
|
|
21
|
+
* specifying a folder, if no tsconfig.json file is found directly in the root
|
|
22
|
+
* folder, the project will be analyzed as JavaScript.
|
|
23
|
+
*/
|
|
24
|
+
export declare const createPackageAnalyzer: (packagePath: AbsolutePath, options?: AnalyzerOptions) => Analyzer;
|
|
25
|
+
//# sourceMappingURL=package-analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-analyzer.d.ts","sourceRoot":"","sources":["../src/lib/package-analyzer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAExC,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAEvC,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAChC,aAAa,YAAY,EACzB,UAAS,eAAoB,aAsF9B,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import ts from 'typescript';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { Analyzer } from './analyzer.js';
|
|
9
|
+
/**
|
|
10
|
+
* Returns an analyzer for a Lit npm package based on a filesystem path.
|
|
11
|
+
*
|
|
12
|
+
* The path may specify a package root folder, or a specific tsconfig file. When
|
|
13
|
+
* specifying a folder, if no tsconfig.json file is found directly in the root
|
|
14
|
+
* folder, the project will be analyzed as JavaScript.
|
|
15
|
+
*/
|
|
16
|
+
export const createPackageAnalyzer = (packagePath, options = {}) => {
|
|
17
|
+
// This logic accepts either a path to folder containing a tsconfig.json
|
|
18
|
+
// directly inside it or a path to a specific tsconfig file. If no tsconfig
|
|
19
|
+
// file is found, we fallback to creating a JavaScript program.
|
|
20
|
+
const isDirectory = ts.sys.directoryExists(packagePath);
|
|
21
|
+
const configFileName = isDirectory
|
|
22
|
+
? path.join(packagePath, 'tsconfig.json')
|
|
23
|
+
: packagePath;
|
|
24
|
+
let commandLine;
|
|
25
|
+
if (ts.sys.fileExists(configFileName)) {
|
|
26
|
+
const configFile = ts.readConfigFile(configFileName, ts.sys.readFile);
|
|
27
|
+
if (options.exclude !== undefined) {
|
|
28
|
+
(configFile.config.exclude ??= []).push(...options.exclude);
|
|
29
|
+
}
|
|
30
|
+
commandLine = ts.parseJsonConfigFileContent(configFile.config /* json */, ts.sys /* host */, isDirectory ? packagePath : path.dirname(packagePath) /* basePath */, {} /* existingOptions */, configFileName /* configFileName */);
|
|
31
|
+
}
|
|
32
|
+
else if (isDirectory) {
|
|
33
|
+
console.info(`No tsconfig.json found; assuming package is JavaScript.`);
|
|
34
|
+
commandLine = ts.parseJsonConfigFileContent({
|
|
35
|
+
compilerOptions: {
|
|
36
|
+
// TODO(kschaaf): probably want to make this configurable
|
|
37
|
+
module: 'es2021',
|
|
38
|
+
lib: ['es2021', 'DOM'],
|
|
39
|
+
allowJs: true,
|
|
40
|
+
skipLibCheck: true,
|
|
41
|
+
skipDefaultLibCheck: true,
|
|
42
|
+
// With `allowJs: true`, the program will automatically include every
|
|
43
|
+
// .d.ts file under node_modules/@types regardless of whether the
|
|
44
|
+
// program imported modules associated with those types, which can
|
|
45
|
+
// dramatically slow down the program analysis (this does not
|
|
46
|
+
// automatically happen when allowJs is false). For now, eliminating
|
|
47
|
+
// `typeRoots` fixes the automatic over-inclusion of .d.ts files as
|
|
48
|
+
// long as nodeResolution is properly set (it will still import .d.ts
|
|
49
|
+
// files into the project as expected based on imports). It may
|
|
50
|
+
// however cause a failure to find definitely-typed .d.ts files for
|
|
51
|
+
// imports in a JS project, but it seems unlikely these would be
|
|
52
|
+
// installed anyway.
|
|
53
|
+
typeRoots: [],
|
|
54
|
+
moduleResolution: 'node',
|
|
55
|
+
},
|
|
56
|
+
include: ['**/*.js'],
|
|
57
|
+
exclude: options.exclude ?? [],
|
|
58
|
+
}, ts.sys /* host */, packagePath /* basePath */);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw new Error(`The specified path '${packagePath}' was not a folder or a tsconfig file.`);
|
|
62
|
+
}
|
|
63
|
+
// Ensure that `parent` nodes are set in the AST by creating a compiler
|
|
64
|
+
// host with this configuration; without these, `getText()` and other
|
|
65
|
+
// API's that require crawling up the AST tree to find the source file
|
|
66
|
+
// text may fail
|
|
67
|
+
const compilerHost = ts.createCompilerHost(commandLine.options,
|
|
68
|
+
/* setParentNodes */ true);
|
|
69
|
+
const program = ts.createProgram(commandLine.fileNames, commandLine.options, compilerHost, undefined, commandLine.errors);
|
|
70
|
+
const analyzer = new Analyzer({
|
|
71
|
+
getProgram: () => program,
|
|
72
|
+
typescript: ts,
|
|
73
|
+
fs: ts.sys,
|
|
74
|
+
path,
|
|
75
|
+
});
|
|
76
|
+
for (const diagnostic of program.getSyntacticDiagnostics()) {
|
|
77
|
+
analyzer.addDiagnostic(diagnostic);
|
|
78
|
+
}
|
|
79
|
+
return analyzer;
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=package-analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-analyzer.js","sourceRoot":"","sources":["../src/lib/package-analyzer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAYvC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,WAAyB,EACzB,UAA2B,EAAE,EAC7B,EAAE;IACF,wEAAwE;IACxE,2EAA2E;IAC3E,+DAA+D;IAC/D,MAAM,WAAW,GAAG,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IACxD,MAAM,cAAc,GAAG,WAAW;QAChC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC;QACzC,CAAC,CAAC,WAAW,CAAC;IAChB,IAAI,WAAiC,CAAC;IACtC,IAAI,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QACtC,MAAM,UAAU,GAAG,EAAE,CAAC,cAAc,CAAC,cAAc,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACtE,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAClC,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,KAAK,EAAE,CAAC,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AAY,GAAG,EAAE,CAAC,kBAAkB,CACxC,WAAW,CAAC,OAAO;IACnB,oBAAoB,CAAC,IAAI,CAC1B,CAAC;IACF,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAC9B,WAAW,CAAC,SAAS,EACrB,WAAW,CAAC,OAAO,EACnB,YAAY,EACZ,SAAS,EACT,WAAW,CAAC,MAAM,CACnB,CAAC;IAEF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC;QAC5B,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO;QACzB,UAAU,EAAE,EAAE;QACd,EAAE,EAAE,EAAE,CAAC,GAAG;QACV,IAAI;KACL,CAAC,CAAC;IACH,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC;QAC3D,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport ts from 'typescript';\nimport {AbsolutePath} from './paths.js';\nimport * as path from 'path';\nimport {Analyzer} from './analyzer.js';\n\nexport interface AnalyzerOptions {\n /**\n * Glob of source files to exclude from project during analysis.\n *\n * Useful for excluding things source like test folders that might otherwise\n * be included in a project's tsconfig.\n */\n exclude?: string[];\n}\n\n/**\n * Returns an analyzer for a Lit npm package based on a filesystem path.\n *\n * The path may specify a package root folder, or a specific tsconfig file. When\n * specifying a folder, if no tsconfig.json file is found directly in the root\n * folder, the project will be analyzed as JavaScript.\n */\nexport const createPackageAnalyzer = (\n packagePath: AbsolutePath,\n options: AnalyzerOptions = {}\n) => {\n // This logic accepts either a path to folder containing a tsconfig.json\n // directly inside it or a path to a specific tsconfig file. If no tsconfig\n // file is found, we fallback to creating a JavaScript program.\n const isDirectory = ts.sys.directoryExists(packagePath);\n const configFileName = isDirectory\n ? path.join(packagePath, 'tsconfig.json')\n : packagePath;\n let commandLine: ts.ParsedCommandLine;\n if (ts.sys.fileExists(configFileName)) {\n const configFile = ts.readConfigFile(configFileName, ts.sys.readFile);\n if (options.exclude !== undefined) {\n (configFile.config.exclude ??= []).push(...options.exclude);\n }\n commandLine = ts.parseJsonConfigFileContent(\n configFile.config /* json */,\n ts.sys /* host */,\n isDirectory ? packagePath : path.dirname(packagePath) /* basePath */,\n {} /* existingOptions */,\n configFileName /* configFileName */\n );\n } else if (isDirectory) {\n console.info(`No tsconfig.json found; assuming package is JavaScript.`);\n commandLine = ts.parseJsonConfigFileContent(\n {\n compilerOptions: {\n // TODO(kschaaf): probably want to make this configurable\n module: 'es2021',\n lib: ['es2021', 'DOM'],\n allowJs: true,\n skipLibCheck: true,\n skipDefaultLibCheck: true,\n // With `allowJs: true`, the program will automatically include every\n // .d.ts file under node_modules/@types regardless of whether the\n // program imported modules associated with those types, which can\n // dramatically slow down the program analysis (this does not\n // automatically happen when allowJs is false). For now, eliminating\n // `typeRoots` fixes the automatic over-inclusion of .d.ts files as\n // long as nodeResolution is properly set (it will still import .d.ts\n // files into the project as expected based on imports). It may\n // however cause a failure to find definitely-typed .d.ts files for\n // imports in a JS project, but it seems unlikely these would be\n // installed anyway.\n typeRoots: [],\n moduleResolution: 'node',\n },\n include: ['**/*.js'],\n exclude: options.exclude ?? [],\n },\n ts.sys /* host */,\n packagePath /* basePath */\n );\n } else {\n throw new Error(\n `The specified path '${packagePath}' was not a folder or a tsconfig file.`\n );\n }\n\n // Ensure that `parent` nodes are set in the AST by creating a compiler\n // host with this configuration; without these, `getText()` and other\n // API's that require crawling up the AST tree to find the source file\n // text may fail\n const compilerHost = ts.createCompilerHost(\n commandLine.options,\n /* setParentNodes */ true\n );\n const program = ts.createProgram(\n commandLine.fileNames,\n commandLine.options,\n compilerHost,\n undefined,\n commandLine.errors\n );\n\n const analyzer = new Analyzer({\n getProgram: () => program,\n typescript: ts,\n fs: ts.sys,\n path,\n });\n for (const diagnostic of program.getSyntacticDiagnostics()) {\n analyzer.addDiagnostic(diagnostic);\n }\n\n return analyzer;\n};\n"]}
|
package/lib/paths.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import { AnalyzerInterface } from './model.js';
|
|
7
|
+
/**
|
|
8
|
+
* An absolute path
|
|
9
|
+
*/
|
|
10
|
+
export type AbsolutePath = string & {
|
|
11
|
+
__absolutePathBrand: never;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A path relative to a package root
|
|
15
|
+
*/
|
|
16
|
+
export type PackagePath = string & {
|
|
17
|
+
__packagePathBrand: never;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Convert an absolute path to a package-relative path
|
|
21
|
+
*/
|
|
22
|
+
export declare const absoluteToPackage: (path: AbsolutePath, packageRoot: AbsolutePath, seperator: string) => PackagePath;
|
|
23
|
+
export declare const resolveExtension: (path: AbsolutePath, analyzer: AnalyzerInterface, extensions?: string[]) => string;
|
|
24
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/lib/paths.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAClC,mBAAmB,EAAE,KAAK,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IACjC,kBAAkB,EAAE,KAAK,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,YAAY,EAClB,aAAa,YAAY,EACzB,WAAW,MAAM,KAChB,WAaF,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,MAAM,YAAY,EAClB,UAAU,iBAAiB,EAC3B,qBAA0B,WAY3B,CAAC"}
|
package/lib/paths.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Convert an absolute path to a package-relative path
|
|
8
|
+
*/
|
|
9
|
+
export const absoluteToPackage = (path, packageRoot, seperator) => {
|
|
10
|
+
if (!path.startsWith(packageRoot)) {
|
|
11
|
+
throw new Error(`path ${path} is not contained in ${packageRoot}`);
|
|
12
|
+
}
|
|
13
|
+
let packagePath = path.substring(packageRoot.length);
|
|
14
|
+
if (!packageRoot.endsWith(seperator)) {
|
|
15
|
+
// Make sure we don't have path='/abc/def' and root='/ab'
|
|
16
|
+
if (!packagePath.startsWith(seperator)) {
|
|
17
|
+
throw new Error(`path ${path} is not contained in ${packageRoot}`);
|
|
18
|
+
}
|
|
19
|
+
packagePath = packagePath.substring(1, packagePath.length);
|
|
20
|
+
}
|
|
21
|
+
return packagePath;
|
|
22
|
+
};
|
|
23
|
+
export const resolveExtension = (path, analyzer, extensions = ['js', 'mjs']) => {
|
|
24
|
+
if (analyzer.fs.fileExists(path)) {
|
|
25
|
+
return path;
|
|
26
|
+
}
|
|
27
|
+
for (const ext of extensions) {
|
|
28
|
+
const fileName = `${path}.${ext}`;
|
|
29
|
+
if (analyzer.fs.fileExists(fileName)) {
|
|
30
|
+
return fileName;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`Could not resolve ${path} to a file on disk.`);
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=paths.js.map
|