1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
16 | return new (P || (P = Promise))(function (resolve, reject) {
|
17 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
18 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
19 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
20 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
21 | });
|
22 | };
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | const streams_1 = require("./streams");
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | class FileMapUrlLoader {
|
30 | constructor(files, fallbackLoader) {
|
31 | this.files = files;
|
32 | this.fallbackLoader = fallbackLoader;
|
33 | }
|
34 |
|
35 | canLoad(url) {
|
36 | return !!(this.files.has(url) ||
|
37 | this.fallbackLoader && this.fallbackLoader.canLoad(url));
|
38 | }
|
39 |
|
40 |
|
41 | load(url) {
|
42 | return __awaiter(this, void 0, void 0, function* () {
|
43 | const file = this.files.get(url);
|
44 | if (file == null) {
|
45 | if (this.fallbackLoader) {
|
46 | if (this.fallbackLoader.canLoad(url)) {
|
47 | return this.fallbackLoader.load(url);
|
48 | }
|
49 | throw new Error(`${url} not present in file map and fallback loader can not load.`);
|
50 | }
|
51 | throw new Error(`${url} not present in file map and no fallback loader.`);
|
52 | }
|
53 | return streams_1.getFileContents(file);
|
54 | });
|
55 | }
|
56 | }
|
57 | exports.FileMapUrlLoader = FileMapUrlLoader;
|
58 |
|
\ | No newline at end of file |