1 | var __extends = (this && this.__extends) || (function () {
|
2 | var extendStatics = Object.setPrototypeOf ||
|
3 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
4 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
5 | return function (d, b) {
|
6 | extendStatics(d, b);
|
7 | function __() { this.constructor = d; }
|
8 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
9 | };
|
10 | })();
|
11 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
12 | return new (P || (P = Promise))(function (resolve, reject) {
|
13 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
14 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
15 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
16 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
17 | });
|
18 | };
|
19 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
20 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
21 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
22 | function verb(n) { return function (v) { return step([n, v]); }; }
|
23 | function step(op) {
|
24 | if (f) throw new TypeError("Generator is already executing.");
|
25 | while (_) try {
|
26 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
27 | if (y = 0, t) op = [op[0] & 2, t.value];
|
28 | switch (op[0]) {
|
29 | case 0: case 1: t = op; break;
|
30 | case 4: _.label++; return { value: op[1], done: false };
|
31 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
32 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
33 | default:
|
34 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
35 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
36 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
37 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
38 | if (t[2]) _.ops.pop();
|
39 | _.trys.pop(); continue;
|
40 | }
|
41 | op = body.call(thisArg, _);
|
42 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
43 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
44 | }
|
45 | };
|
46 | import { Origin } from 'aurelia-metadata';
|
47 | import { Loader } from 'aurelia-loader';
|
48 | import { DOM, PLATFORM } from 'aurelia-pal';
|
49 |
|
50 |
|
51 |
|
52 | var TextTemplateLoader = (function () {
|
53 | function TextTemplateLoader() {
|
54 | }
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | TextTemplateLoader.prototype.loadTemplate = function (loader, entry) {
|
62 | return __awaiter(this, void 0, void 0, function () {
|
63 | var text;
|
64 | return __generator(this, function (_a) {
|
65 | switch (_a.label) {
|
66 | case 0: return [4 , loader.loadText(entry.address)];
|
67 | case 1:
|
68 | text = _a.sent();
|
69 | entry.template = DOM.createTemplateFromMarkup(text);
|
70 | return [2 ];
|
71 | }
|
72 | });
|
73 | });
|
74 | };
|
75 | return TextTemplateLoader;
|
76 | }());
|
77 | export { TextTemplateLoader };
|
78 | export function ensureOriginOnExports(moduleExports, moduleId) {
|
79 | var target = moduleExports;
|
80 | var key;
|
81 | var exportedValue;
|
82 | if (target.__useDefault) {
|
83 | target = target.default;
|
84 | }
|
85 | Origin.set(target, new Origin(moduleId, 'default'));
|
86 | if (typeof target === 'object') {
|
87 | for (key in target) {
|
88 | exportedValue = target[key];
|
89 | if (typeof exportedValue === 'function') {
|
90 | Origin.set(exportedValue, new Origin(moduleId, key));
|
91 | }
|
92 | }
|
93 | }
|
94 | return moduleExports;
|
95 | }
|
96 |
|
97 |
|
98 |
|
99 | var WebpackLoader = (function (_super) {
|
100 | __extends(WebpackLoader, _super);
|
101 | function WebpackLoader() {
|
102 | var _this = _super.call(this) || this;
|
103 | _this.moduleRegistry = Object.create(null);
|
104 | _this.loaderPlugins = Object.create(null);
|
105 | _this.modulesBeingLoaded = new Map();
|
106 | _this.useTemplateLoader(new TextTemplateLoader());
|
107 | _this.addPlugin('template-registry-entry', {
|
108 | fetch: function (moduleId) { return __awaiter(_this, void 0, void 0, function () {
|
109 | var HmrContext, entry;
|
110 | var _this = this;
|
111 | return __generator(this, function (_a) {
|
112 | switch (_a.label) {
|
113 | case 0:
|
114 |
|
115 | if (module.hot) {
|
116 | if (!this.hmrContext) {
|
117 | HmrContext = require('aurelia-hot-module-reload').HmrContext;
|
118 | this.hmrContext = new HmrContext(this);
|
119 | }
|
120 | module.hot.accept(moduleId, function () { return __awaiter(_this, void 0, void 0, function () {
|
121 | return __generator(this, function (_a) {
|
122 | switch (_a.label) {
|
123 | case 0: return [4 , this.hmrContext.handleViewChange(moduleId)];
|
124 | case 1:
|
125 | _a.sent();
|
126 | return [2 ];
|
127 | }
|
128 | });
|
129 | }); });
|
130 | }
|
131 | entry = this.getOrCreateTemplateRegistryEntry(moduleId);
|
132 | if (!!entry.templateIsLoaded) return [3 , 2];
|
133 | return [4 , this.templateLoader.loadTemplate(this, entry)];
|
134 | case 1:
|
135 | _a.sent();
|
136 | _a.label = 2;
|
137 | case 2: return [2 , entry];
|
138 | }
|
139 | });
|
140 | }); }
|
141 | });
|
142 | PLATFORM.eachModule = function (callback) {
|
143 | var registry = __webpack_require__.c;
|
144 | var cachedModuleIds = Object.getOwnPropertyNames(registry);
|
145 | cachedModuleIds
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | .some(function (moduleId) {
|
151 | var moduleExports = registry[moduleId].exports;
|
152 | if (typeof moduleExports === 'object') {
|
153 | return callback(moduleId, moduleExports);
|
154 | }
|
155 | return false;
|
156 | });
|
157 | };
|
158 | return _this;
|
159 | }
|
160 | WebpackLoader.prototype._import = function (address, defaultHMR) {
|
161 | if (defaultHMR === void 0) { defaultHMR = true; }
|
162 | return __awaiter(this, void 0, void 0, function () {
|
163 | var addressParts, moduleId, loaderPlugin, plugin_1, asyncModuleId, callback;
|
164 | var _this = this;
|
165 | return __generator(this, function (_a) {
|
166 | switch (_a.label) {
|
167 | case 0:
|
168 | addressParts = address.split('!');
|
169 | moduleId = addressParts.splice(addressParts.length - 1, 1)[0];
|
170 | loaderPlugin = addressParts.length === 1 ? addressParts[0] : null;
|
171 | if (!loaderPlugin) return [3 , 2];
|
172 | plugin_1 = this.loaderPlugins[loaderPlugin];
|
173 | if (!plugin_1) {
|
174 | throw new Error("Plugin " + loaderPlugin + " is not registered in the loader.");
|
175 | }
|
176 | if (module.hot && plugin_1.hot) {
|
177 | module.hot.accept(moduleId, function () { return plugin_1.hot(moduleId); });
|
178 | }
|
179 | return [4 , plugin_1.fetch(moduleId)];
|
180 | case 1: return [2 , _a.sent()];
|
181 | case 2:
|
182 | if (__webpack_require__.m[moduleId]) {
|
183 | if (defaultHMR && module.hot && this.hmrContext) {
|
184 | module.hot.accept(moduleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
|
185 | }
|
186 | return [2 , __webpack_require__(moduleId)];
|
187 | }
|
188 | asyncModuleId = "async!" + moduleId;
|
189 | if (!__webpack_require__.m[asyncModuleId]) return [3 , 4];
|
190 | if (defaultHMR && module.hot && this.hmrContext) {
|
191 | module.hot.accept(moduleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
|
192 | module.hot.accept(asyncModuleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
|
193 | }
|
194 | callback = __webpack_require__(asyncModuleId);
|
195 | return [4 , new Promise(callback)];
|
196 | case 3: return [2 , _a.sent()];
|
197 | case 4: throw new Error("Unable to find module with ID: " + moduleId);
|
198 | }
|
199 | });
|
200 | });
|
201 | };
|
202 | |
203 |
|
204 |
|
205 |
|
206 |
|
207 | WebpackLoader.prototype.map = function (id, source) { };
|
208 | |
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 | WebpackLoader.prototype.normalizeSync = function (moduleId, relativeTo) {
|
215 | return moduleId;
|
216 | };
|
217 | |
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 | WebpackLoader.prototype.normalize = function (moduleId, relativeTo) {
|
224 | return Promise.resolve(moduleId);
|
225 | };
|
226 | |
227 |
|
228 |
|
229 |
|
230 | WebpackLoader.prototype.useTemplateLoader = function (templateLoader) {
|
231 | this.templateLoader = templateLoader;
|
232 | };
|
233 | |
234 |
|
235 |
|
236 |
|
237 |
|
238 | WebpackLoader.prototype.loadAllModules = function (ids) {
|
239 | var _this = this;
|
240 | return Promise.all(ids.map(function (id) { return _this.loadModule(id); }));
|
241 | };
|
242 | |
243 |
|
244 |
|
245 |
|
246 |
|
247 | WebpackLoader.prototype.loadModule = function (moduleId, defaultHMR) {
|
248 | if (defaultHMR === void 0) { defaultHMR = true; }
|
249 | return __awaiter(this, void 0, void 0, function () {
|
250 | var existing, beingLoaded, moduleExports;
|
251 | return __generator(this, function (_a) {
|
252 | switch (_a.label) {
|
253 | case 0:
|
254 | existing = this.moduleRegistry[moduleId];
|
255 | if (existing) {
|
256 | return [2 , existing];
|
257 | }
|
258 | beingLoaded = this.modulesBeingLoaded.get(moduleId);
|
259 | if (beingLoaded) {
|
260 | return [2 , beingLoaded];
|
261 | }
|
262 | beingLoaded = this._import(moduleId, defaultHMR);
|
263 | this.modulesBeingLoaded.set(moduleId, beingLoaded);
|
264 | return [4 , beingLoaded];
|
265 | case 1:
|
266 | moduleExports = _a.sent();
|
267 | this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
|
268 | this.modulesBeingLoaded.delete(moduleId);
|
269 | return [2 , moduleExports];
|
270 | }
|
271 | });
|
272 | });
|
273 | };
|
274 | |
275 |
|
276 |
|
277 |
|
278 |
|
279 | WebpackLoader.prototype.loadTemplate = function (url) {
|
280 | return this.loadModule(this.applyPluginToUrl(url, 'template-registry-entry'), false);
|
281 | };
|
282 | |
283 |
|
284 |
|
285 |
|
286 |
|
287 | WebpackLoader.prototype.loadText = function (url) {
|
288 | return __awaiter(this, void 0, void 0, function () {
|
289 | var result, defaultExport;
|
290 | return __generator(this, function (_a) {
|
291 | switch (_a.label) {
|
292 | case 0: return [4 , this.loadModule(url, false)];
|
293 | case 1:
|
294 | result = _a.sent();
|
295 | defaultExport = result && result.__esModule ? result.default : result;
|
296 | if (defaultExport instanceof Array && defaultExport[0] instanceof Array && defaultExport.hasOwnProperty('toString')) {
|
297 |
|
298 | return [2 , defaultExport.toString()];
|
299 | }
|
300 | return [2 , result];
|
301 | }
|
302 | });
|
303 | });
|
304 | };
|
305 | |
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 | WebpackLoader.prototype.applyPluginToUrl = function (url, pluginName) {
|
312 | return pluginName + "!" + url;
|
313 | };
|
314 | |
315 |
|
316 |
|
317 |
|
318 |
|
319 | WebpackLoader.prototype.addPlugin = function (pluginName, implementation) {
|
320 | this.loaderPlugins[pluginName] = implementation;
|
321 | };
|
322 | return WebpackLoader;
|
323 | }(Loader));
|
324 | export { WebpackLoader };
|
325 | PLATFORM.Loader = WebpackLoader;
|