1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | import * as analyzer from 'polymer-analyzer';
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export function isEsModuleDocument(doc: analyzer.Document):
|
19 | doc is analyzer.Document<analyzer.ParsedJavaScriptDocument> {
|
20 | return doc.type === 'js' &&
|
21 | (doc.parsedDocument as analyzer.ParsedJavaScriptDocument)
|
22 | .parsedAsSourceType === 'module';
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export function resolveImportExportFeature(
|
29 | feature: analyzer.JavascriptImport|analyzer.Export,
|
30 | identifier: string,
|
31 | doc: analyzer.Document): analyzer.Reference<ResolvedTypes>|undefined {
|
32 | for (const kind of resolveKinds) {
|
33 | const reference = new analyzer.ScannedReference(
|
34 | kind,
|
35 | identifier,
|
36 | feature.sourceRange,
|
37 | feature.astNode,
|
38 | feature.astNodePath);
|
39 | const resolved = reference.resolve(doc);
|
40 | if (resolved.feature !== undefined) {
|
41 | return resolved as analyzer.Reference<ResolvedTypes>;
|
42 | }
|
43 | }
|
44 | return undefined;
|
45 | }
|
46 |
|
47 | const resolveKinds: Array<keyof analyzer.FeatureKindMap> = [
|
48 | 'element',
|
49 | 'behavior',
|
50 | 'element-mixin',
|
51 | 'class',
|
52 | 'function',
|
53 | 'namespace',
|
54 | ];
|
55 |
|
56 | export type ResolvedTypes = analyzer.Element|analyzer.PolymerBehavior|
|
57 | analyzer.ElementMixin|analyzer.Class|
|
58 | analyzer.Function|analyzer.Namespace;
|