1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | const document_1 = require("./document");
|
17 | const warning_1 = require("./warning");
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | class ScannedImport {
|
25 | constructor(type, url, sourceRange, urlSourceRange, ast, lazy) {
|
26 | this.warnings = [];
|
27 | this.type = type;
|
28 | this.url = url;
|
29 | this.sourceRange = sourceRange;
|
30 | this.urlSourceRange = urlSourceRange;
|
31 | this.astNode = ast;
|
32 | this.lazy = lazy;
|
33 | }
|
34 | resolve(document) {
|
35 | const resolvedUrl = this.getLoadableUrlOrWarn(document);
|
36 | if (this.url === undefined || resolvedUrl === undefined) {
|
37 |
|
38 |
|
39 | return undefined;
|
40 | }
|
41 | const importedDocumentOrWarning = document._analysisContext.getDocument(resolvedUrl);
|
42 | let importedDocument;
|
43 | if (!(importedDocumentOrWarning instanceof document_1.Document)) {
|
44 | this.addCouldNotLoadWarning(document, importedDocumentOrWarning);
|
45 | importedDocument = undefined;
|
46 | }
|
47 | else {
|
48 | importedDocument = importedDocumentOrWarning;
|
49 | }
|
50 | return this.constructImport(resolvedUrl, this.url, importedDocument, document);
|
51 | }
|
52 | constructImport(resolvedUrl, relativeUrl, importedDocument, _containingDocument) {
|
53 | return new Import(resolvedUrl, relativeUrl, this.type, importedDocument, this.sourceRange, this.urlSourceRange, this.astNode, this.warnings, this.lazy);
|
54 | }
|
55 | addCouldNotLoadWarning(document, warning) {
|
56 | const error = this.error && this.error.message || this.error ||
|
57 | warning && warning.message || '';
|
58 | if (error) {
|
59 | document.warnings.push(new warning_1.Warning({
|
60 | code: 'could-not-load',
|
61 | message: `Unable to load import: ${error}`,
|
62 | sourceRange: (this.urlSourceRange || this.sourceRange),
|
63 | severity: warning_1.Severity.ERROR,
|
64 | parsedDocument: document.parsedDocument,
|
65 | }));
|
66 | }
|
67 | }
|
68 | |
69 |
|
70 |
|
71 | getLoadableUrlOrWarn(document) {
|
72 | if (this.url === undefined) {
|
73 | return;
|
74 | }
|
75 | const resolvedUrl = document._analysisContext.resolver.resolve(document.parsedDocument.baseUrl, this.url, this);
|
76 | if (!resolvedUrl) {
|
77 | return;
|
78 | }
|
79 | if (!document._analysisContext.loader.canLoad(resolvedUrl)) {
|
80 |
|
81 | document.warnings.push(new warning_1.Warning({
|
82 | code: 'not-loadable',
|
83 | message: `URL loader not configured to load '${resolvedUrl}'`,
|
84 | sourceRange: (this.urlSourceRange || this.sourceRange),
|
85 | severity: warning_1.Severity.WARNING,
|
86 | parsedDocument: document.parsedDocument,
|
87 | }));
|
88 | return undefined;
|
89 | }
|
90 | return resolvedUrl;
|
91 | }
|
92 | }
|
93 | exports.ScannedImport = ScannedImport;
|
94 | class Import {
|
95 | constructor(url, originalUrl, type, document, sourceRange, urlSourceRange, ast, warnings, lazy) {
|
96 | this.identifiers = new Set();
|
97 | this.kinds = new Set(['import']);
|
98 | this.url = url;
|
99 | this.originalUrl = originalUrl;
|
100 | this.type = type;
|
101 | this.document = document;
|
102 | this.kinds.add(this.type);
|
103 | this.sourceRange = sourceRange;
|
104 | this.urlSourceRange = urlSourceRange;
|
105 | this.astNode = ast;
|
106 | this.warnings = warnings;
|
107 | this.lazy = lazy;
|
108 | if (lazy) {
|
109 | this.kinds.add('lazy-import');
|
110 | }
|
111 | }
|
112 | toString() {
|
113 | return `<Import type="${this.type}" url="${this.url}">`;
|
114 | }
|
115 | }
|
116 | exports.Import = Import;
|
117 |
|
\ | No newline at end of file |