vendor: 4,302 bytes, lines 1-130
1'use strict'; 2 3var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; 4 5/******/(function (modules) { 6 // webpackBootstrap 7 /******/ // The module cache 8 /******/var installedModules = {}; 9 /******/ 10 /******/ // The require function 11 /******/function __webpack_require__(moduleId) { 12 /******/ 13 /******/ // Check if module is in cache 14 /******/if (installedModules[moduleId]) { 15 /******/return installedModules[moduleId].exports; 16 /******/ 17 } 18 /******/ // Create a new module (and put it into the cache) 19 /******/var module = installedModules[moduleId] = { 20 /******/i: moduleId, 21 /******/l: false, 22 /******/exports: {} 23 /******/ }; 24 /******/ 25 /******/ // Execute the module function 26 /******/modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 27 /******/ 28 /******/ // Flag the module as loaded 29 /******/module.l = true; 30 /******/ 31 /******/ // Return the exports of the module 32 /******/return module.exports; 33 /******/ 34 } 35 /******/ 36 /******/ 37 /******/ // expose the modules object (__webpack_modules__) 38 /******/__webpack_require__.m = modules; 39 /******/ 40 /******/ // expose the module cache 41 /******/__webpack_require__.c = installedModules; 42 /******/ 43 /******/ // define getter function for harmony exports 44 /******/__webpack_require__.d = function (exports, name, getter) { 45 /******/if (!__webpack_require__.o(exports, name)) { 46 /******/Object.defineProperty(exports, name, { 47 /******/configurable: false, 48 /******/enumerable: true, 49 /******/get: getter 50 /******/ }); 51 /******/ 52 } 53 /******/ 54 }; 55 /******/ 56 /******/ // getDefaultExport function for compatibility with non-harmony modules 57 /******/__webpack_require__.n = function (module) { 58 /******/var getter = module && module.__esModule ? 59 /******/function getDefault() { 60 return module['default']; 61 } : 62 /******/function getModuleExports() { 63 return module; 64 }; 65 /******/__webpack_require__.d(getter, 'a', getter); 66 /******/return getter; 67 /******/ 68 }; 69 /******/ 70 /******/ // Object.prototype.hasOwnProperty.call 71 /******/__webpack_require__.o = function (object, property) { 72 return Object.prototype.hasOwnProperty.call(object, property); 73 }; 74 /******/ 75 /******/ // __webpack_public_path__ 76 /******/__webpack_require__.p = ""; 77 /******/ 78 /******/ // Load entry module and return exports 79 /******/return __webpack_require__(__webpack_require__.s = 1); 80 /******/ 81})( 82/************************************************************************/ 83/******/[ 84/* 0 */ 85/***/function (module, exports, __webpack_require__) { 86 87 "use strict"; 88 89 Object.defineProperty(exports, "__esModule", { 90 value: true 91 }); 92 93 var _createClass = function () { 94 function defineProperties(target, props) { 95 for (var i = 0; i < props.length; i++) { 96 var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); 97 } 98 }return function (Constructor, protoProps, staticProps) { 99 if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; 100 }; 101 }(); 102 103 function _classCallCheck(instance, Constructor) { 104 if (!(instance instanceof Constructor)) { 105 throw new TypeError("Cannot call a class as a function"); 106 } 107 } 108 109 /** 110 * 111 */ 112 var PathResolver = function () { 113 function PathResolver() { 114 _classCallCheck(this, PathResolver); 115 } 116 117 _createClass(PathResolver, [{ 118 key: 'resolvePath', 119 120 /** 121 * Resolves the path of module. 122 * 123 * @param {string} root Root path which will be used as reference to resolve 124 * the path of the dependency. 125 * @param {string} dependency The dependency path, which have to be 126 * resolved. 127 * @return {string} The resolved dependency path. 128 */ 129 value: function resolvePath(root, dependency) { 130 if (dependency === 'require' || dependency === 'exports' || dependency === 'module' || !(dependency.indexOf('.') === 0 || dependency.indexOf('..') === 0)) {
131 return dependency; 132 } 133 134 // Split module directories 135 var moduleParts = root.split('/'); 136 137 // Remove module name 138 moduleParts.splice(-1, 1); 139 140 // Split dependency directories 141 var dependencyParts = dependency.split('/'); 142 143 // Extract dependency name 144 var dependencyName = dependencyParts.splice(-1, 1); 145 146 for (var i = 0; i < dependencyParts.length; i++) { 147 var dependencyPart = dependencyParts[i]; 148 149 if (dependencyPart === '.') { 150 continue; 151 } else if (dependencyPart === '..') { 152 if (moduleParts.length) { 153 moduleParts.splice(-1, 1); 154 } else { 155 moduleParts = moduleParts.concat(dependencyParts.slice(i)); 156 157 break; 158 } 159 } else { 160 moduleParts.push(dependencyPart); 161 } 162 } 163 164 moduleParts.push(dependencyName); 165 166 return moduleParts.join('/'); 167 } 168 }]); 169 170 return PathResolver; 171 }(); 172 173 exports.default = PathResolver; 174 175 /***/ 176}, 177/* 1 */ 178/***/function (module, exports, __webpack_require__) { 179 180 "use strict"; 181 182 var _loader = __webpack_require__(2); 183 184 var _loader2 = _interopRequireDefault(_loader); 185 186 var _es6Promise = __webpack_require__(8); 187 188 var _es6Promise2 = _interopRequireDefault(_es6Promise); 189 190 function _interopRequireDefault(obj) { 191 return obj && obj.__esModule ? obj : { default: obj }; 192 } 193 194 if (typeof window.Promise === 'undefined') { 195 window.Promise = _es6Promise2.default; 196 } 197 198 var cfg = window.__CONFIG__ || {}; 199 var namespace = typeof cfg.namespace === 'string' ? cfg.namespace : undefined; 200 var exposeGlobal = cfg.exposeGlobal === undefined ? true : cfg.exposeGlobal; 201 var loader = new _loader2.default(cfg); 202 203 if (namespace) { 204 var ns = window[namespace] ? window[namespace] : {}; 205 ns.Loader = loader; 206 window[namespace] = ns; 207 } else { 208 window.Loader = loader; 209 } 210 211 if (exposeGlobal) { 212 window.Loader = loader; 213 window.require = _loader2.default.prototype.require.bind(loader); 214 window.define = _loader2.default.prototype.define.bind(loader); 215 window.define.amd = {}; 216 } 217 218 /***/ 219}, 220/* 2 */ 221/***/function (module, exports, __webpack_require__) { 222 223 "use strict"; 224 225 Object.defineProperty(exports, "__esModule", { 226 value: true 227 }); 228 229 var _createClass = function () { 230 function defineProperties(target, props) { 231 for (var i = 0; i < props.length; i++) { 232 var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); 233 } 234 }return function (Constructor, protoProps, staticProps) { 235 if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; 236 }; 237 }(); 238 239 var _configParser = __webpack_require__(3); 240 241 var _configParser2 = _interopRequireDefault(_configParser); 242 243 var _dependencyBuilder = __webpack_require__(4); 244 245 var _dependencyBuilder2 = _interopRequireDefault(_dependencyBuilder); 246 247 var _eventEmitter = __webpack_require__(5); 248 249 var _eventEmitter2 = _interopRequireDefault(_eventEmitter); 250 251 var _pathResolver = __webpack_require__(0); 252 253 var _pathResolver2 = _interopRequireDefault(_pathResolver); 254 255 var _urlBuilder = __webpack_require__(6); 256 257 var _urlBuilder2 = _interopRequireDefault(_urlBuilder); 258 259 var _package = __webpack_require__(7); 260 261 var _package2 = _interopRequireDefault(_package); 262 263 function _interopRequireDefault(obj) { 264 return obj && obj.__esModule ? obj : { default: obj }; 265 } 266 267 function _toConsumableArray(arr) { 268 if (Array.isArray(arr)) { 269 for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { 270 arr2[i] = arr[i]; 271 }return arr2; 272 } else { 273 return Array.from(arr); 274 } 275 } 276 277 function _classCallCheck(instance, Constructor) { 278 if (!(instance instanceof Constructor)) { 279 throw new TypeError("Cannot call a class as a function"); 280 } 281 } 282 283 function _possibleConstructorReturn(self, call) { 284 if (!self) { 285 throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); 286 }return call && ((typeof call === 'undefined' ? 'undefined' : _typeof(call)) === "object" || typeof call === "function") ? call : self; 287 } 288 289 function _inherits(subClass, superClass) { 290 if (typeof superClass !== "function" && superClass !== null) { 291 throw new TypeError("Super expression must either be null or a function, not " + (typeof superClass === 'undefined' ? 'undefined' : _typeof(superClass))); 292 }subClass.prototype = Object.create(superClass && superClass.prototype, { c
292onstructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; 293 } 294 295 /** 296 * 297 */ 298 var Loader = function (_EventEmitter) { 299 _inherits(Loader, _EventEmitter); 300 301 /** 302 * Creates an instance of Loader class. 303 * 304 * @namespace Loader 305 * @extends EventEmitter 306 * @param {object=} config Configuration options (defaults to window.__CONFIG__) 307 * @param {object} document DOM document object to use (defaults to window.document) 308 * @constructor 309 */ 310 function Loader() { 311 var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; 312 var document = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; 313 314 _classCallCheck(this, Loader); 315 316 var _this = _possibleConstructorReturn(this, (Loader.__proto__ || Object.getPrototypeOf(Loader)).call(this)); 317 318 _this._config = config || window.__CONFIG__; 319 _this._document = document || window.document; 320 _this._modulesMap = {}; 321 return _this; 322 } 323 324 /** 325 * Get loader version 326 * @return {String} the version number as specified in package.json 327 */ 328 329 _createClass(Loader, [{ 330 key: 'version', 331 value: function version() { 332 return _package2.default.version; 333 } 334 335 /** 336 * Adds a module to the configuration. See {@link ConfigParser#addModule} 337 * for more details. 338 * 339 * @memberof! Loader# 340 * @param {Object} module The module which should be added to the configuration. See {@link ConfigParser#addModule} 341 * for more details. 342 * @return {Object} Returns the added module to the configuration. 343 */ 344 345 }, { 346 key: 'addModule', 347 value: function addModule(module) { 348 return this._getConfigParser().addModule(module); 349 } 350 351 /** 352 * Defines a module in the system and fires {@link Loader#event:moduleRegister} event with the registered module as 353 * param. 354 * 355 * @memberof! Loader# 356 * @param {string} name The name of the module. 357 * @param {array} dependencies List of module dependencies. 358 * @param {function} implementation The implementation of the module. 359 * @param {object=} config Object configuration: 360 * <ul> 361 * <strong>Optional properties</strong>: 362 * <li>path (String) - Explicitly set path of the module. If omitted, module name will be used as path</li> 363 * <li>condition (Object) Object which represents if the module should be added automatically after another 364 * module. It should have the following properties: 365 * </li> 366 * <ul> 367 * <li>trigger - the module, which should trigger the loading of the current module</li> 368 * <li>test - function, which should return true if module should be loaded</li> 369 * </ul> 370 * <li>exports - If the module does not expose a "define" function, then you can specify an "exports" 371 * property. The value of this property should be a string, which represents the value, 372 * which this module exports to the global namespace. For example: exports: '_'. This will 373 * mean the module exports an underscore to the global namespace. In this way you can load 374 * legacy modules. 375 * </li> 376 * </ul> 377 */ 378 379 }, { 380 key: 'define', 381 value: function define() { 382 var _this2 = this; 383 384 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 385 args[_key] = arguments[_key]; 386 } 387 388 var name = args[0]; 389 var dependencies = args[1]; 390 var implementation = args[2]; 391 var config = args[3] || {}; 392 393 config.anonymous = false; 394 395 var passedArgsCount = arguments.length; 396 397 if (passedArgsCount < 2) { 398 399 implementation = args[0]; 400 dependencies = ['module', 'exports']; 401 config.anonymous = true; 402 } else if (passedArgsCount === 2) { 403 if (typeof name === 'string') { 404 405 // there are two parameters, but the first one is not an array with dependencies, 406 // this is a module name 407 dependencies = ['module', 'exports']; 408 implementation = args[1]; 409 } else { 410 411 dependencies = args[0]; 412 implementation = args[1]; 413 config.anonymous = true; 414 } 415 } 416 /* eslint-enable prefer-rest-params */ 417 418 if (config.anonymous) { 419 // Postpone module's registration till the next scriptLoaded event 420 var onScriptLoaded = function onScriptLoaded(loadedModules) { 421 _this2.off('scriptLoaded', onScriptLoaded); 422 423 if (loadedModules.length !== 1) { 424 _this2._reportMismatchedAnonymousModules(implementation.toString()); 425 } else { 426 var moduleName = loadedModules[0]; 427 var module = _this2.getModules()[moduleName]; 428 429 if (module && module.pendingImplementation) { 430 _this2._reportMismatchedAnonymousModules(implementation.toString()); 431 } 432 433 _this2._define(moduleName, dependencies, implementation, config); 434 } 435 }; 436 437 this.on('scriptLoaded', onScriptLoaded); 438 } else { 439 // This is not an anonymous module, go directly to module's 440 // registration flow 441 this._define(name, dependencies, implementation, config); 442 } 443 } 444 445 /** 446 * Returns list of currently registered conditional modules. 447 * 448 * @memberof! Loader# 449 * @return {array} List of currently registered conditional modules. 450 */ 451 452 }, { 453 key: 'getConditionalModules', 454 value: function getConditionalModules() { 455 return this._getConfigParser().getConditionalModules(); 456 } 457 458 /** 459 * Returns list of currently registered modules. 460 * 461 * @memberof! Loader# 462 * @return {array} List of currently registered modules. 463 */ 464 465 }, { 466 key: 'getModules', 467 value: function getModules() { 468 return this._getConfigParser().getModules(); 469 } 470 471 /** 472 * Requires list of modules. If a module is not yet registered, it will be 473 * ignored and its implementation in the provided success callback will be 474 * left undefined. 475 * 476 * @memberof! Loader# 477 * @param {array|string[]} modules Modules can be specified as an array of 478 * strings or provided as multiple string 479 * parameters. 480 * @param {function} success Callback, which will be invoked in case of 481 * success. The provided parameters will be 482 * implementations of all required modules. 483 * @param {function} failure Callback, which will be invoked in case of 484 * failure. One parameter with information 485 * about the error will be provided. 486 */ 487 488 }, { 489 key: 'require', 490 value: function require() { 491 var _this3 = this; 492 493 for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 494 args[_key2] = arguments[_key2]; 495 } 496 497 var _normalizeRequireArgs2 = this._normalizeRequireArgs(args), 498 modules = _normalizeRequireArgs2.modules, 499 successCallback = _normalizeRequireArgs2.successCallback, 500 failureCallback = _normalizeRequireArgs2.failureCallback; 501 502 var configParser = this._getConfigParser();
503 var mappedModules = configParser.mapModule(modules); 504 505 var rejectTimeout = void 0; 506 507 new Promise(function (resolve, reject) { 508 _this3._resolveDependencies(mappedModules).then(function (dependencies) { 509 510 _this3._log('Resolved modules:', mappedModules, 'to:', dependencies); 511 512 var resolutionError = _this3._getResolutionError(dependencies); 513 514 if (resolutionError) { 515 reject(resolutionError); 516 517 return; 518 } 519 520 rejectTimeout = _this3._setRejectTimeout(modules, mappedModules, dependencies, reject); 521 522 _this3._loadModules(dependencies).then(resolve, reject); 523 }, reject); 524 }).then(function () { 525 526 clearTimeout(rejectTimeout); 527 528 /* istanbul ignore else */ 529 if (successCallback) { 530 var moduleImplementations = void 0; 531 532 moduleImplementations = _this3._getModuleImplementations(mappedModules); 533 534 successCallback.apply(successCallback, moduleImplementations); 535 } 536 }, function (error) { 537 538 clearTimeout(rejectTimeout); 539 540 /* istanbul ignore else */ 541 if (failureCallback) { 542 failureCallback.call(failureCallback, error); 543 } else { 544 _this3._error('Unhandled failure:', error, 'while resolving modules:', mappedModules); 545 } 546 }); 547 } 548 549 /** 550 * Extract the three nominal arguments (modules, successCallback, and 551 * failureCallback) of a require call from the arguments array. 552 * @param {Array} args the arguments array of the require call 553 * @return {Object} an object with three fields: modules, successCallback, 554 * and failureCallback, 555 */ 556 557 }, { 558 key: '_normalizeRequireArgs', 559 value: function _normalizeRequireArgs(args) { 560 var modules = void 0; 561 var successCallback = void 0; 562 var failureCallback = void 0; 563 564 // Modules can be specified by as an array, or just as parameters to the 565 // function. We do not slice or leak arguments to not cause V8 566 // performance penalties. 567 if (Array.isArray(args[0])) { 568 modules = args[0]; 569 successCallback = typeof args[1] === 'function' ? args[1] : null; 570 failureCallback = typeof args[2] === 'function' ? args[2] : null; 571 } else { 572 modules = []; 573 574 for (var i = 0; i < args.length; ++i) { 575 if (typeof args[i] === 'string') { 576 modules[i] = args[i]; 577 578 /* istanbul ignore else */ 579 } else if (typeof args[i] === 'function') { 580 successCallback = args[i]; 581 failureCallback = typeof args[++i] === 'function' ? args[i] : /* istanbul ignore next */null; 582 583 break; 584 } 585 } 586 } 587 588 return { 589 modules: modules, 590 successCallback: successCallback, 591 failureCallback: failureCallback 592 }; 593 } 594 595 /** 596 * Traverse a resolved dependencies array looking for server sent errors and 597 * return an Error if any is found. 598 * @param {Array} dependencies the resolved dependencies 599 * @return {Error} a detailed Error or null if no errors were found 600 */ 601 602 }, { 603 key: '_getResolutionError', 604 value: function _getResolutionError(dependencies) { 605 var dependencyErrors = dependencies.filter(function (dep) { 606 return dep.indexOf(':ERROR:') === 0; 607 }).map(function (dep) { 608 return dep.substr(7); 609 }); 610 611 if (dependencyErrors.length > 0) { 612 return new Error('The following problems where detected while ' + 'resolving modules:\n' + dependencyErrors.join('\n')); 613 } 614 615 return null; 616 } 617 618 /** 619 * Set a timeout (only if allowed by configuration) to reject a Promise if 620 * a certain set of modules has not been successfully loaded. 621 * @param {Array} modules the modules to be loaded 622 * @param {Array} mappedModules the modules after successful mapping 623 * @param {Array} dependencies the dependencies of the modules 624 * @param {function} reject the promise reject function 625 * @return {int} a timeout id or undefined if configuration disabled timeout 626 */ 627 628 }, { 629 key: '_setRejectTimeout', 630 value: function _setRejectTimeout(modules, mappedModules, dependencies, reject) { 631 var configParser = this._getConfigParser(); 632 var config = configParser.getConfig(); 633 634 var rejectTimeout = void 0; 635 636 // Establish a load timeout and reject the Promise in case 637 // of Error 638 if (config.waitTimeout !== 0) { 639 rejectTimeout = setTimeout(function () { 640 var registeredModules = configParser.getModules(); 641 642 var error = new Error('Load timeout for modules: ' + modules); 643 644 error.modules = modules; 645 error.mappedModules = mappedModules;
646 error.dependencies = dependencies; 647 648 var filteredDeps = void 0; 649 650 filteredDeps = dependencies.filter(function (dep) { 651 return typeof registeredModules[dep].implementation === 'undefined'; 652 }); 653 error.missingDependencies = filteredDeps; 654 655 filteredDeps = error.missingDependencies.filter(function (dep) { 656 return typeof registeredModules[dep].pendingImplementation !== 'undefined'; 657 }); 658 error.fetchedMissingDependencies = filteredDeps; 659 660 filteredDeps = error.missingDependencies.filter(function (dep) { 661 return typeof registeredModules[dep].pendingImplementation === 'undefined'; 662 }); 663 error.unfetchedMissingDependencies = filteredDeps; 664 665 // @deprecated: fill `dependecies` field to maintain 666 // backward compatibility 667 error.dependecies = error.dependencies; 668 669 reject(error); 670 }, config.waitTimeout || 7000); 671 } 672 673 return rejectTimeout; 674 } 675 676 /** 677 * Creates Promise for module. It will be resolved as soon as module is 678 * being loaded from server. 679 * 680 * @memberof! Loader# 681 * @protected 682 * @param {string} moduleName The name of module for which Promise should 683 * be created. 684 * @return {Promise} Promise, which will be resolved as soon as the 685 * requested module is being loaded. 686 */ 687 688 }, { 689 key: '_createModulePromise', 690 value: function _createModulePromise(moduleName) { 691 var _this4 = this; 692 693 return new Promise(function (resolve, reject) { 694 var registeredModules = _this4._getConfigParser().getModules(); 695 696 // Check if this is a module, which exports something 697 // If so, check if the exported value is available 698 var module = registeredModules[moduleName]; 699 700 if (module.exports) { 701 var exportedValue = _this4._getValueGlobalNS(module.exports); 702 703 if (exportedValue) { 704 resolve(exportedValue); 705 } else { 706 var onScriptLoaded = function onScriptLoaded(loadedModules) { 707 if (loadedModules.indexOf(moduleName) >= 0) { 708 _this4.off('scriptLoaded', onScriptLoaded); 709 710 var _exportedValue = _this4._getValueGlobalNS(module.exports); 711 712 if (_exportedValue) { 713 resolve(_exportedValue); 714 } else { 715 reject(new Error('Module ' + moduleName + ' does not export the specified value: ' + module.exports)); 716 } 717 } 718 }; 719 720 _this4.on('scriptLoaded', onScriptLoaded); 721 } 722 } else { 723 var onModuleRegister = function onModuleRegister(registeredModuleName) { 724 if (registeredModuleName === moduleName) { 725 _this4.off('moduleRegister', onModuleRegister); 726 727 // Overwrite the promise entry in the modules map with a simple `true` value. 728 // Hopefully GC will remove this promise from the memory. 729 _this4._modulesMap[moduleName] = true; 730 731 resolve(moduleName); 732 } 733 }; 734 735 _this4.on('moduleRegister', onModuleRegister); 736 } 737 }); 738 } 739 740 /** 741 * Defines a module in the system and fires 742 * {@link Loader#event:moduleRegister} event with the registered module as 743 * param. Called internally by {@link Loader#define} method once it 744 * normalizes the passed arguments. 745 * 746 * @memberof! Loader# 747 * @protected 748 * @param {string} name The name of the module. 749 * @param {array} dependencies List of module dependencies. 750 * @param {function} implementation The implementation of the module. 751 * @param {object=} config See {@link Loader:define} for more details. 752 */ 753 754 }, { 755 key: '_define', 756 value: function _define(name, dependencies, implementation, config) { 757 // Create a new module by merging the provided config with the passed 758 // name, dependencies and implementation. 759 var module = config || {}; 760 var configParser = this._getConfigParser(); 761 762 if (configParser.getConfig().ignoreModuleVersion) { 763 var nameParts = name.split('/'); 764 var packageParts = nameParts[0].split('@'); 765 766 nameParts[0] = packageParts[0]; 767 768 name = nameParts.join('/'); 769 } 770 771 var pathResolver = this._getPathResolver(); 772 773 // Resolve the path according to the parent module. Example: 774 // define('metal/src/component/component', ['../array/array']) 775 // will become: 776 // define('metal/src/component/component', ['metal/src/array/array'])
777 dependencies = dependencies.map(function (dependency) { 778 return pathResolver.resolvePath(name, dependency); 779 }); 780 781 module.name = name; 782 module.dependencies = dependencies; 783 module.pendingImplementation = implementation; 784 785 configParser.addModule(module); 786 787 if (!this._modulesMap[module.name]) { 788 this._modulesMap[module.name] = true; 789 } 790 791 this.emit('moduleRegister', name); 792 } 793 794 /** 795 * Returns instance of {@link ConfigParser} class. 796 * 797 * @memberof! Loader# 798 * @protected 799 * @return {ConfigParser} Instance of {@link ConfigParser} class. 800 */ 801 802 }, { 803 key: '_getConfigParser', 804 value: function _getConfigParser() { 805 /* istanbul ignore else */ 806 if (!this._configParser) { 807 this._configParser = new _configParser2.default(this._config); 808 } 809 810 return this._configParser; 811 } 812 813 /** 814 * Returns instance of {@link DependencyBuilder} class. 815 * 816 * @memberof! Loader# 817 * @protected 818 * @return {DependencyBuilder} Instance of {@link DependencyBuilder} class. 819 */ 820 821 }, { 822 key: '_getDependencyBuilder', 823 value: function _getDependencyBuilder() { 824 if (!this._dependencyBuilder) { 825 this._dependencyBuilder = new _dependencyBuilder2.default(this._getConfigParser()); 826 } 827 828 return this._dependencyBuilder; 829 } 830 831 /** 832 * Retrieves a value from the global namespace. 833 * 834 * @memberof! Loader# 835 * @protected 836 * @param {String} exports The key which should be used to retrieve the 837 * value. 838 * @return {Any} The retrieved value. 839 */ 840 841 }, { 842 key: '_getValueGlobalNS', 843 value: function _getValueGlobalNS(exports) { 844 var exportVariables = exports.split('.'); 845 846 var tmpVal = (0, eval)('this')[exportVariables[0]]; 847 848 for (var i = 1; tmpVal && i < exportVariables.length; i++) { 849 if (Object.prototype.hasOwnProperty.call(tmpVal, exportVariables[i])) { 850 tmpVal = tmpVal[exportVariables[i]]; 851 } else { 852 return null; 853 } 854 } 855 856 return tmpVal; 857 } 858 859 /** 860 * Returns an array of all missing dependencies of the passed modules. 861 * A missing dependency is a dependency, which does not have pending 862 * implementation yet. 863 * 864 * @memberof! Loader# 865 * @protected 866 * @param {array} moduleNames List of module names to be checked for missing 867 * dependencies. 868 * @return {Array<string>} A list with all missing dependencies. 869 */ 870 871 }, { 872 key: '_getMissingDependencies', 873 value: function _getMissingDependencies(moduleNames) { 874 var configParser = this._getConfigParser(); 875 var registeredModules = configParser.getModules(); 876 877 var missingDependencies = Object.create(null); 878 879 for (var i = 0; i < moduleNames.length; i++) { 880 var module = registeredModules[moduleNames[i]]; 881 882 var mappedDependencies = configParser.mapModule(module.dependencies, module.map); 883 884 for (var j = 0; j < mappedDependencies.length; j++) { 885 var dependency = mappedDependencies[j]; 886 887 var dependencyModule = registeredModules[dependency]; 888 889 if (dependency !== 'require' && dependency !== 'exports' && dependency !== 'module' && (!dependencyModule || !dependencyModule.pendingImplementation)) { 890 missingDependencies[dependency] = 1; 891 } 892 } 893 } 894 895 return Object.keys(missingDependencies); 896 } 897 898 /** 899 * Retrieves module implementations to an array. 900 * 901 * @memberof! Loader# 902 * @protected 903 * @param {array} requiredModules List of modules, which implementations 904 * will be added to an array. 905 * @return {array} List of modules implementations. 906 */ 907 908 }, { 909 key: '_getModuleImplementations', 910 value: function _getModuleImplementations(requiredModules) { 911 var moduleImplementations = []; 912 913 var modules = this._getConfigParser().getModules(); 914 915 for (var i = 0; i < requiredModules.length; i++) { 916 var requiredModule = modules[requiredModules[i]]; 917 918 moduleImplementations.push(requiredModule ? requiredModule.implementation : undefined); 919 } 920 921 return moduleImplementations; 922 } 923 924 /** 925 * Returns an instance of {@link PathResolver} class. 926 * 927 * @memberof! Loader# 928 * @protected 929 * @return {PathResolver} Instance of {@link PathResolver} class. 930 */ 931 932 }, { 933 key: '_getPathResolver', 934 value: function _getPathResolver() { 935 if (!this._pathResolver) { 936 this._pathResolver = new _pathResolver2.default(); 937 } 938 939 return this._pathResolver; 940 } 941 942 /** 943 * Returns instance of {@link URLBuilder} class. 944 * 945 * @memberof! Loader# 946 * @protected 947 * @return {URLBuilder} Instance of {@link URLBuilder} class. 948 */ 949 950 }, { 951 key: '_getURLBuilder', 952 value: function _getURLBuilder() { 953 /* istanbul ignore else */ 954 if (!this._urlBuilder) { 955 this._urlBuilder = new _urlBuilder2.default(this._getConfigParser()); 956 } 957 958 return this._urlBuilder; 959 } 960 961 /** 962 * Filters a list of modules and returns only these which don't have any of 963 * the provided list of properties. 964 * 965 * @memberof! Loader# 966 * @protected 967 * @param {array} moduleNames List of modules which which have to be 968 * filtered. 969 * @param {string|Array} property The name of the property to filter by. 970 * @return {array} List of modules matching the specified filter. 971 */ 972 973 }, { 974 key: '_filterModulesByProperty', 975 value: function _filterModulesByProperty(moduleNames, property) { 976 var properties = property; 977 978 if (typeof property === 'string') { 979 properties = [property]; 980 } 981 982 var missingModules = []; 983 984 var registeredModules = this._getConfigParser().getModules(); 985 986 for (var i = 0; i < moduleNames.length; i++) { 987 var moduleName = moduleNames[i]; 988 989 var registeredModule = registeredModules[moduleNames[i]]; 990 991 if (!registeredModule) { 992 missingModules.push(moduleName); 993 continue; 994 } 995 996 // We exclude "require", "exports" and "module" modules, which are 997 // part of AMD spec. 998 if (registeredModule === 'require' || registeredModule === 'exports' || registeredModule === 'module') { 999 continue; 1000 } 1001 1002 var found = false;
1003 1004 for (var j = 0; j < properties.length; j++) { 1005 if (registeredModule[properties[j]]) { 1006 found = true; 1007 break; 1008 } 1009 } 1010 1011 if (!found) { 1012 missingModules.push(moduleName); 1013 } 1014 } 1015 1016 return missingModules; 1017 } 1018 1019 /** 1020 * Loads list of modules. 1021 * 1022 * @memberof! Loader# 1023 * @protected 1024 * @param {array} moduleNames List of modules to be loaded. 1025 * @return {Promise} Promise, which will be resolved as soon as all module a 1026 * being loaded. 1027 */ 1028 1029 }, { 1030 key: '_loadModules', 1031 value: function _loadModules(moduleNames) { 1032 var _this5 = this; 1033 1034 return new Promise(function (resolve, reject) { 1035 // Get all modules without pending implementation or not yet 1036 // requested 1037 var modulesForLoading = _this5._filterModulesByProperty(moduleNames, ['requested', 'pendingImplementation']); 1038 1039 if (modulesForLoading.length) { 1040 // If there are modules, which have to be loaded, construct 1041 // their URLs 1042 var modulesURL = _this5._getURLBuilder().build(modulesForLoading); 1043 1044 var pendingScripts = []; 1045 1046 // Create promises for each of the scripts, which should be 1047 // loaded 1048 for (var i = 0; i < modulesURL.length; i++) { 1049 pendingScripts.push(_this5._loadScript(modulesURL[i])); 1050 } 1051 1052 // Wait for resolving all script Promises 1053 // As soon as that happens, wait for each module to define 1054 // itself 1055 1056 Promise.all(pendingScripts).then(function () { 1057 return _this5._waitForModules(moduleNames); 1058 }) 1059 // As soon as all scripts were loaded and all dependencies 1060 // have been resolved, resolve the main Promise 1061 .then(resolve) 1062 // If any script fails to load or other error happens, 1063 // reject the main Promise 1064 .catch(reject); 1065 } else { 1066 // If there are no any missing modules, just wait for modules dependencies 1067 // to be resolved and then resolve the main promise 1068 _this5._waitForModules(moduleNames).then(resolve) 1069 // If some error happens, for example if some module implementation 1070 // throws error, reject the main Promise 1071 .catch(reject); 1072 } 1073 }); 1074 } 1075 1076 /** 1077 * Loads a script element on the page. 1078 * 1079 * @memberof! Loader# 1080 * @protected 1081 * @param {object} modulesURL An Object with two properties: 1082 * - modules - List of the modules which should be loaded 1083 * - url - The URL from which the modules should be loaded 1084 * @return {Promise} Promise which will be resolved as soon as the script is being loaded. 1085 */ 1086 1087 }, { 1088 key: '_loadScript', 1089 value: function _loadScript(modulesURL) { 1090 var _this6 = this; 1091 1092 var self = this; 1093 1094 return new Promise(function (resolve, reject) { 1095 var script = _this6._document.createElement('script'); 1096 1097 script.src = modulesURL.url; 1098 script.async = false; 1099 1100 // On ready state change is needed for IE < 9, not sure if that is needed anymore, 1101 // it depends which browsers will we support at the end 1102 script.onload = script.onreadystatechange = function () { 1103 /* istanbul ignore else */ 1104 if (!this.readyState || 1105 /* istanbul ignore next */this.readyState === 'complete' || 1106 /* istanbul ignore next */this.readyState === 'load') { 1107 script.onload = script.onreadystatechange = null; 1108 1109 resolve(script); 1110 1111 self.emit('scriptLoaded', modulesURL.modules); 1112 } 1113 }; 1114 1115 // If some script fails to load, reject the main Promise 1116 script.onerror = function () { 1117 _this6._document.head.removeChild(script); 1118 1119 reject(script); 1120 }; 1121 1122 _this6._document.head.appendChild(script); 1123 }); 1124 } 1125 1126 /** 1127 * Show a message in console if the explainResolutions option is active. 1128 * 1129 * @param {Array} msgs the objects to be printed 1130 * @return {void} 1131 */ 1132 1133 }, { 1134 key: '_log', 1135 value: function _log() { 1136 for (var _len3 = arguments.length, msgs = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 1137 msgs[_key3] = arguments[_key3]; 1138 } 1139 1140 var aliasedConsole = console; 1141 var args = arguments.length === 1 ? [msgs[0]] : Array.apply(undefined, msgs); 1142 var config = this._getConfigParser().getConfig(); 1143 1144 if (config.explainResolutions) {
1145 aliasedConsole.log.apply(aliasedConsole, _toConsumableArray(['Liferay AMD Loader:'].concat(args))); 1146 } 1147 } 1148 1149 /** 1150 * Report errors to the console even in non-debug versions of the loader. 1151 * 1152 * @param {Array} msgs the objects to be printed 1153 * @return {void} 1154 */ 1155 1156 }, { 1157 key: '_error', 1158 value: function _error() { 1159 var aliasedConsole = console; 1160 var args = arguments.length === 1 ? [arguments.length <= 0 ? undefined : arguments[0]] : Array.apply(undefined, arguments); 1161 1162 aliasedConsole.log.apply(aliasedConsole, _toConsumableArray(['Liferay AMD Loader:'].concat(args))); 1163 } 1164 1165 /** 1166 * Resolves modules dependencies. 1167 * 1168 * @memberof! Loader# 1169 * @protected 1170 * @param {array} modules List of modules which dependencies should be resolved. 1171 * @return {Promise} Promise which will be resolved as soon as all dependencies are being resolved. 1172 */ 1173 1174 }, { 1175 key: '_resolveDependencies', 1176 value: function _resolveDependencies(modules) { 1177 var _this7 = this; 1178 1179 return new Promise(function (resolve, reject) { 1180 try { 1181 var dependencyBuilder = _this7._getDependencyBuilder(); 1182 1183 resolve(dependencyBuilder.resolveDependencies(modules)); 1184 } catch (error) { 1185 reject(error); 1186 } 1187 }); 1188 } 1189 1190 /** 1191 * Reports a mismatched anonymous module error. Depending on the value of the configuration property 1192 * `__CONFIG__.reportMismatchedAnonymousModules`, this method will throw an error, use the console[level] 1193 * method to log the message or silently ignore it. 1194 * 1195 * @memberof! Loader# 1196 * @protected 1197 * @param {string} msg Additional information to log with the error. 1198 */ 1199 1200 }, { 1201 key: '_reportMismatchedAnonymousModules', 1202 value: function _reportMismatchedAnonymousModules(msg) { 1203 var errorMessage = 'Mismatched anonymous define() module: ' + msg; 1204 var reportLevel = this._config.reportMismatchedAnonymousModules; 1205 1206 if (!reportLevel || reportLevel === 'exception') { 1207 throw new Error(errorMessage); 1208 } else if (console && console[reportLevel]) { 1209 // Call console's method by using the `call` function 1210 // to prevent stripDebug to remove the statement in production 1211 console[reportLevel].call(console, errorMessage); 1212 } 1213 } 1214 1215 /** 1216 * Invokes the implementation method of list of modules passing the implementations of its dependencies. 1217 * 1218 * @memberof! Loader# 1219 * @protected 1220 * @param {array} modules List of modules to which implementation should be set. 1221 */ 1222 1223 }, { 1224 key: '_setModuleImplementation', 1225 value: function _setModuleImplementation(modules) { 1226 var _this8 = this; 1227 1228 var registeredModules = this._getConfigParser().getModules(); 1229 1230 for (var i = 0; i < modules.length; i++) { 1231 var module = modules[i]; 1232 1233 if (typeof module.implementation !== 'undefined') { 1234 continue; 1235 } else if (typeof module.exports !== 'undefined') { 1236 module.implementation = this._getValueGlobalNS(module.exports); 1237 module.pendingImplementation = module.implementation; 1238 continue; 1239 } 1240 1241 var dependencyImplementations = []; 1242 1243 // Leave exports implementation to be {} by default 1244 var moduleImpl = { exports: {} }; 1245 var configParser = this._getConfigParser(); 1246 1247 for (var j = 0; j < module.dependencies.length; j++) { 1248 var dependency = module.dependencies[j]; 1249 1250 // If the current dependency of this module is 'exports', 1251 // create an empty object and pass it as implementation of 1252 // 'exports' module 1253 if (dependency === 'exports') { 1254 dependencyImplementations.push(moduleImpl.exports); 1255 } else if (dependency === 'module') { 1256 dependencyImplementations.push(moduleImpl); 1257 } else if (dependency === 'require') { 1258 var localRequire = this._createLocalRequire(module); 1259 1260 localRequire.toUrl = function (moduleName) { 1261 var moduleURLs = _this8._getURLBuilder().build([moduleName]); 1262 1263 return moduleURLs[0].url; 1264 }; 1265 1266 dependencyImplementations.push(localRequire); 1267 } else { 1268 // otherwise set as value the implementation of the registered module 1269 var dependencyModule = registeredModules[configParser.mapM
1269odule(dependency, module.map)]; 1270 1271 var impl = dependencyModule.implementation; 1272 1273 dependencyImplementations.push(impl); 1274 } 1275 } 1276 1277 var result = void 0; 1278 1279 if (typeof module.pendingImplementation === 'function') { 1280 result = module.pendingImplementation.apply(module.pendingImplementation, dependencyImplementations); 1281 } else { 1282 result = module.pendingImplementation; 1283 } 1284 1285 // Store as implementation either the returned value from the 1286 // function's invocation, or the value inside module.exports magic 1287 // dependency. 1288 // 1289 // The final implementation of this module may be {} if there is no 1290 // returned value, or the object does not assign anything to 1291 // module.exports. 1292 if (typeof result !== 'undefined') { 1293 module.implementation = result; 1294 } else { 1295 module.implementation = moduleImpl.exports; 1296 } 1297 } 1298 } 1299 1300 /** 1301 * Create a function implementing the local require method of the AMD specification. 1302 * @param {Object} module a module descriptor 1303 * @return {function} the local require implementation for the given module 1304 */ 1305 1306 }, { 1307 key: '_createLocalRequire', 1308 value: function _createLocalRequire(module) { 1309 var _this9 = this; 1310 1311 var configParser = this._getConfigParser(); 1312 var pathResolver = this._getPathResolver(); 1313 1314 return function (moduleName) { 1315 for (var _len4 = arguments.length, rest = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { 1316 rest[_key4 - 1] = arguments[_key4]; 1317 } 1318 1319 if (rest.length > 0) { 1320 return _this9.require.apply(_this9, [moduleName].concat(rest)); 1321 } else { 1322 moduleName = pathResolver.resolvePath(module.name, moduleName); 1323 1324 moduleName = configParser.mapModule(moduleName, module.map); 1325 1326 var dependencyModule = configParser.getModules()[moduleName]; 1327 1328 if (!dependencyModule || !('implementation' in dependencyModule)) { 1329 throw new Error('Module "' + moduleName + '" has not been loaded yet for context: ' + module.name); 1330 } 1331 1332 return dependencyModule.implementation; 1333 } 1334 }; 1335 } 1336 1337 /** 1338 * Resolves a Promise as soon as all module dependencies are being resolved or it has implementation already. 1339 * 1340 * @memberof! Loader# 1341 * @protected 1342 * @param {Object} moduleName The module for which this function should wait. 1343 * @return {Promise} 1344 */ 1345 1346 }, { 1347 key: '_waitForModule', 1348 value: function _waitForModule(moduleName) { 1349 // Check if there is already a promise for this module. 1350 // If there is not - create one and store it to module promises map. 1351 var modulePromise = this._modulesMap[moduleName]; 1352 1353 if (!modulePromise) { 1354 modulePromise = this._createModulePromise(moduleName); 1355 1356 this._modulesMap[moduleName] = modulePromise; 1357 } 1358 1359 return modulePromise; 1360 } 1361 1362 /** 1363 * Resolves a Promise as soon as all dependencies of all provided modules are being resolved and modules have 1364 * implementations. 1365 * 1366 * @memberof! Loader# 1367 * @protected 1368 * @param {array} moduleNames List of modules for which implementations this function should wait. 1369 * @return {Promise} 1370 */ 1371 1372 }, { 1373 key: '_waitForModules', 1374 value: function _waitForModules(moduleNames) { 1375 var _this10 = this; 1376 1377 return new Promise(function (resolve, reject) { 1378 var modulesPromises = []; 1379 1380 for (var i = 0; i < moduleNames.length; i++) { 1381 modulesPromises.push(_this10._waitForModule(moduleNames[i])); 1382 } 1383 1384 // Wait until all modules were loaded and their Promises resolved 1385 Promise.all(modulesPromises).then(function () { 1386 // The modules were loaded. However, we have to check their dependencies 1387 // one more time, because some dependencies might have not been registered in the configuration. 1388 // In this case we have to load them too, otherwise we won't be able to properly 1389 // get the implementation from the module. 1390 var registeredModules = _this10._getConfigParser().getModules(); 1391 1392 var defineModules = function defineModules() { 1393 var definedModules = []; 1394 1395 for (var _i = 0; _i < moduleNames.length; _i++) { 1396 definedModules.push(registeredModules[moduleNames[_i]]); 1397 } 1398 1399 _this10._setModuleImplementation(definedModules); 1400 1401 resolve(definedModules); 1402 }; 1403 1404 var missingDependencies = _this10._getMissingDependencies(moduleNames); 1405 1406 if (missingDependencies.length) { 1407 1408 _this10.require(missingDependencies, defineModules, reject); 1409 } else { 1410 defineModules(); 1411 } 1412 }, reject); 1413 }); 1414 } 1415 1416 /** 1417 * Indicates that a module has been registered. 1418 *
1419 * @event Loader#moduleRegister 1420 * @param {Object} module - The registered module. 1421 */ 1422 1423 }]); 1424 1425 return Loader; 1426 }(_eventEmitter2.default); 1427 1428 exports.default = Loader; 1429 1430 Loader.prototype.define.amd = {}; 1431 1432 /***/ 1433}, 1434/* 3 */ 1435/***/function (module, exports, __webpack_require__) { 1436 1437 "use strict"; 1438 1439 Object.defineProperty(exports, "__esModule", { 1440 value: true 1441 }); 1442 1443 var _createClass = function () { 1444 function defineProperties(target, props) { 1445 for (var i = 0; i < props.length; i++) { 1446 var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); 1447 } 1448 }return function (Constructor, protoProps, staticProps) { 1449 if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; 1450 }; 1451 }(); 1452 1453 function _classCallCheck(instance, Constructor) { 1454 if (!(instance instanceof Constructor)) { 1455 throw new TypeError("Cannot call a class as a function"); 1456 } 1457 } 1458 1459 /** 1460 * 1461 */ 1462 var ConfigParser = function () { 1463 /** 1464 * Creates an instance of ConfigurationParser class. 1465 * 1466 * @constructor 1467 * @param {object=} config - The configuration object to be parsed. 1468 */ 1469 function ConfigParser(config) { 1470 _classCallCheck(this, ConfigParser); 1471 1472 this._config = {}; 1473 this._modules = {}; 1474 this._conditionalModules = {}; 1475 1476 this._parseConfig(config); 1477 } 1478 1479 /** 1480 * Adds a module to the configuration. 1481 * 1482 * @param {object} module The module which should be added to the 1483 * configuration. Should have the following properties: 1484 * <ul> 1485 * <strong>Obligatory properties</strong>: 1486 * <li>name (String) The name of the module</li> 1487 * <li>dependencies (Array) The modules from which it depends</li> 1488 * </ul> 1489 * 1490 * <strong>Optional properties:</strong> 1491 * The same as those which config parameter of {@link Loader#define} 1492 * method accepts. 1493 * @return {Object} The added module 1494 */ 1495 1496 _createClass(ConfigParser, [{ 1497 key: 'addModule', 1498 value: function addModule(module) { 1499 // Module might be added via configuration or when it arrives from the 1500 // server. If it arrives from the server, it will have already a 1501 // definition. In this case, we will overwrite the existing properties 1502 // with those, provided from the module definition. Otherwise, we will 1503 // just add it to the map. 1504 var moduleDefinition = this._modules[module.name]; 1505 1506 if (moduleDefinition) { 1507 for (var key in module) { 1508 if (Object.prototype.hasOwnProperty.call(module, key)) { 1509 moduleDefinition[key] = module[key]; 1510 } 1511 } 1512 } else { 1513 this._modules[module.name] = module; 1514 } 1515 1516 this._registerConditionalModule(module); 1517 1518 return this._modules[module.name]; 1519 } 1520 1521 /** 1522 * Returns the current configuration. 1523 * 1524 * @return {object} The current configuration. 1525 */ 1526 1527 }, { 1528 key: 'getConfig', 1529 value: function getConfig() { 1530 return this._config; 1531 } 1532 1533 /** 1534 * Returns map with all currently registered conditional modules and their 1535 * triggers. 1536 * 1537 * @return {object} Map with all currently registered conditional modules. 1538 */ 1539 1540 }, { 1541 key: 'getConditionalModules', 1542 value: function getConditionalModules() { 1543 return this._conditionalModules; 1544 } 1545 1546 /** 1547 * Returns map with all currently registered modules. 1548 * 1549 * @return {object} Map with all currently registered modules. 1550 */ 1551 1552 }, { 1553 key: 'getModules', 1554 value: function getModules() { 1555 return this._modules; 1556 } 1557 1558 /** 1559 * Maps module names to their aliases. Example: 1560 * __CONFIG__.maps = { 1561 * liferay: '[email protected]' 1562 * } 1563 * 1564 * When someone does require('liferay/html/js/ac.es',...), 1565 * if the module 'liferay/html/js/ac.es' is not defined, 1566 * then a corresponding alias will be searched. If found, the name will be 1567 * replaced, so it will look like user did 1568 * require('[email protected]/html/js/ac.es',...). 1569 * 1570 * Additionally, modules can define a custom map to alias module names just 1571 * in the context of that module loading operation. When present, the 1572 * contextual module mapping will take precedence over the general one. 1573 * 1574 * @protected 1575 * @param {array|string} module The module which have to be mapped or array 1576 * of modules. 1577 * @param {?object} contextMap Contextual module mapping information 1578 * relevant to the current load operation 1579 * @return {array|string} The mapped module or array of mapped modules. 1580 */ 1581 1582 }, { 1583 key: 'mapModule', 1584 value: function mapModule(module, contextMap) { 1585 if (!this._config.maps && !contextMap) { 1586 return module; 1587 } 1588 1589 var modules = void 0; 1590 1591 if (Array.isArray(module)) { 1592 modules = module; 1593 } else { 1594 modules = [module]; 1595 } 1596 1597 if (contextMap) { 1598 modules = modules.map(this._getModuleMapper(contextMap)); 1599 } 1600 1601 if (this._config.maps) { 1602 modules = modules.map(this._getModuleMapper(this._config.maps)); 1603 } 1604 1605 return Array.isArray(module) ? modules : modules[0]; 1606 } 1607 1608 /** 1609 * Creates a function that transforms module names based on a provided 1610 * set of mappings. 1611 * 1612 * @protected 1613 * @param {object} maps Mapping information. 1614 * @return {function} The generated mapper function 1615 */ 1616 1617 }, { 1618 key: '_getModuleMapper', 1619 value: function _getModuleMapper(maps) { 1620 var _this = this; 1621 1622 return function (module) { 1623 var match = void 0; 1624 1625 match = _this._mapExactMatch(module, maps); 1626 1627 // Apply partial mapping only if exactMatch hasn't been 1628 // already applied for this mapping 1629 if (!match) { 1630 match = _this._mapPartialMatch(module, maps); 1631 } 1632 1633 // Apply * mapping only if neither exactMatch nor 1634 // partialMatch have been already applied for this mapping 1635 if (!match) { 1636 match = _this._mapWildcardMatch(module, maps); 1637 } 1638 1639 return match || module; 1640 }; 1641 } 1642 1643 /** 1644 * Transforms a module name using the exactMatch mappings 1645 * in a provided mapping object. 1646 * 1647 * @protected 1648 * @param {string} module The module which have to be mapped. 1649 * @param {object} maps Mapping information. 1650 * @return {object} An object with a boolean `matched` field and a string 1651 * `result` field containing the mapped module name 1652 */ 1653 1654 }, { 1655 key: '_mapExactMatch', 1656 value: function _mapExactMatch(module, maps) { 1657 for (var alias in maps) { 1658 /* istanbul ignore else */ 1659 if (Object.prototype.hasOwnProperty.call(maps, alias)) { 1660 var aliasValue = maps[alias]; 1661
1662 if (aliasValue.value && aliasValue.exactMatch) { 1663 if (module === alias) { 1664 return aliasValue.value; 1665 } 1666 } 1667 } 1668 } 1669 } 1670 1671 /** 1672 * Transforms a module name using the partial mappings 1673 * in a provided mapping object. 1674 * 1675 * @protected 1676 * @param {string} module The module which have to be mapped. 1677 * @param {object} maps Mapping information. 1678 * @return {object} An object with a boolean `matched` field and a string 1679 * `result` field containing the mapped module name 1680 */ 1681 1682 }, { 1683 key: '_mapPartialMatch', 1684 value: function _mapPartialMatch(module, maps) { 1685 for (var alias in maps) { 1686 /* istanbul ignore else */ 1687 if (Object.prototype.hasOwnProperty.call(maps, alias)) { 1688 var aliasValue = maps[alias]; 1689 1690 if (!aliasValue.exactMatch) { 1691 if (aliasValue.value) { 1692 aliasValue = aliasValue.value; 1693 } 1694 1695 if (module === alias || module.indexOf(alias + '/') === 0) { 1696 return aliasValue + module.substring(alias.length); 1697 } 1698 } 1699 } 1700 } 1701 } 1702 1703 /** 1704 * Transforms a module name using the wildcard mapping in a provided mapping 1705 * object. 1706 * 1707 * @protected 1708 * @param {string} module The module which have to be mapped. 1709 * @param {object} maps Mapping information. 1710 * @return {object} An object with a boolean `matched` field and a string 1711 * `result` field containing the mapped module name 1712 */ 1713 1714 }, { 1715 key: '_mapWildcardMatch', 1716 value: function _mapWildcardMatch(module, maps) { 1717 if (typeof maps['*'] === 'function') { 1718 return maps['*'](module); 1719 } 1720 } 1721 1722 /** 1723 * Parses configuration object. 1724 * 1725 * @protected 1726 * @param {object} config Configuration object to be parsed. 1727 * @return {object} The created configuration 1728 */ 1729 1730 }, { 1731 key: '_parseConfig', 1732 value: function _parseConfig(config) { 1733 for (var key in config) { 1734 /* istanbul ignore else */ 1735 if (Object.prototype.hasOwnProperty.call(config, key)) { 1736 if (key === 'modules') { 1737 this._parseModules(config[key]); 1738 } else { 1739 this._config[key] = config[key]; 1740 } 1741 } 1742 } 1743 1744 return this._config; 1745 } 1746 1747 /** 1748 * Parses a provided modules configuration. 1749 * 1750 * @protected 1751 * @param {object} modules Map of modules to be parsed. 1752 * @return {object} Map of parsed modules. 1753 */ 1754 1755 }, { 1756 key: '_parseModules', 1757 value: function _parseModules(modules) { 1758 for (var key in modules) { 1759 /* istanbul ignore else */ 1760 if (Object.prototype.hasOwnProperty.call(modules, key)) { 1761 var module = modules[key]; 1762 1763 module.name = key; 1764 1765 this.addModule(module); 1766 } 1767 } 1768 1769 return this._modules; 1770 } 1771 1772 /** 1773 * Registers conditional module to the configuration. 1774 * 1775 * @protected 1776 * @param {object} module Module object 1777 */ 1778 1779 }, { 1780 key: '_registerConditionalModule', 1781 value: function _registerConditionalModule(module) { 1782 // Create HashMap of all modules, which have conditional modules, as an 1783 // Array. 1784 if (module.condition) { 1785 var existingModules = this._conditionalModules[module.condition.trigger]; 1786 1787 if (!existingModules) { 1788 this._conditionalModules[module.condition.trigger] = existingModules = []; 1789 } 1790 1791 existingModules.push(module.name); 1792 } 1793 } 1794 }]); 1795 1796 return ConfigParser; 1797 }(); 1798 1799 exports.default = ConfigParser; 1800 1801 /***/ 1802}, 1803/* 4 */ 1804/***/function (module, exports, __webpack_require__) { 1805 1806 "use strict"; 1807 1808 Object.defineProperty(exports, "__esModule", { 1809 value: true 1810 }); 1811 1812 var _createClass = function () { 1813 function defineProperties(target, props) { 1814 for (var i = 0; i < props.length; i++) { 1815 var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); 1816 } 1817 }return function (Constructor, protoProps, staticProps) { 1818 if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; 1819 }; 1820 }(); 1821 1822 var _pathResolver = __webpack_require__(0); 1823 1824 var _pathResolver2 = _interopRequireDefault(_pathResolver); 1825 1826 function _interopRequireDefault(obj) { 1827 return obj && obj.__esModule ? obj : { default: obj }; 1828 } 1829 1830 function _classCallCheck(instance, Constructor) { 1831 if (!(instance instanceof Constructor)) { 1832 throw new TypeError("Cannot call a class as a function"); 1833 } 1834 } 1835
1836 /** 1837 * 1838 */ 1839 var DependencyBuilder = function () { 1840 /** 1841 * Creates an instance of DependencyBuilder class. 1842 * 1843 * @constructor 1844 * @param {object} configParser - instance of {@link ConfigParser} object. 1845 */ 1846 function DependencyBuilder(configParser) { 1847 _classCallCheck(this, DependencyBuilder); 1848 1849 this._configParser = configParser; 1850 this._pathResolver = new _pathResolver2.default(); 1851 1852 this._result = []; 1853 1854 /** 1855 * List of modules, which dependencies should be resolved. Initially, it 1856 * is copy of the array of modules, passed for resolving; during the 1857 * process more modules may be added to the queue. For example, these 1858 * might be conditional modules. 1859 */ 1860 this._queue = []; 1861 1862 this._cachedResolutions = {}; 1863 } 1864 1865 /** 1866 * Resolves modules dependencies. 1867 * 1868 * @param {array} modules List of modules which dependencies should be 1869 * resolved. 1870 * @return {array} List of module names, representing module dependencies. 1871 * Module name itself is being returned too. 1872 */ 1873 1874 _createClass(DependencyBuilder, [{ 1875 key: 'resolveDependencies', 1876 value: function resolveDependencies(modules) { 1877 var modulesSignature = modules.slice().sort().join(); 1878 1879 var resolution = this._cachedResolutions[modulesSignature]; 1880 1881 if (!resolution) { 1882 try { 1883 // Copy the passed modules to a resolving modules queue. 1884 // Modules may be added there during the process of resolving. 1885 this._queue = modules.slice(0); 1886 1887 this._resolveDependencies(); 1888 1889 // Reorder the modules list so the modules without dependencies will 1890 // be moved upfront 1891 resolution = this._result.reverse().slice(0); 1892 1893 // Cache resolution 1894 this._cachedResolutions[modulesSignature] = resolution; 1895 } finally { 1896 this._cleanup(); 1897 } 1898 } 1899 1900 return resolution; 1901 } 1902 1903 /** 1904 * Clears the used resources during the process of resolving dependencies. 1905 * 1906 * @protected 1907 */ 1908 1909 }, { 1910 key: '_cleanup', 1911 value: function _cleanup() { 1912 var modules = this._configParser.getModules(); 1913 1914 // Set to false all temporary markers which were set during the process 1915 // of dependencies resolving. 1916 for (var key in modules) { 1917 /* istanbul ignore else */ 1918 if (Object.prototype.hasOwnProperty.call(modules, key)) { 1919 var module = modules[key]; 1920 1921 module.conditionalMark = false; 1922 module.mark = false; 1923 module.tmpMark = false; 1924 } 1925 } 1926 1927 this._queue.length = 0; 1928 this._result.length = 0; 1929 } 1930 1931 /** 1932 * Processes conditional modules. If a module has conditional module as 1933 * dependency, this module will be added to the list of modules, which 1934 * dependencies should be resolved. 1935 * 1936 * @protected 1937 * @param {object} module Module, which will be checked for conditional 1938 * modules as dependencies. 1939 */ 1940 1941 }, { 1942 key: '_processConditionalModules', 1943 value: function _processConditionalModules(module) { 1944 var conditionalModules = this._configParser.getConditionalModules()[module.name]; 1945 1946 // If the current module has conditional modules as dependencies, 1947 // add them to the list (queue) of modules, which have to be resolved. 1948 if (conditionalModules && !module.conditionalMark) { 1949 var modules = this._configParser.getModules(); 1950 1951 for (var i = 0; i < conditionalModules.length; i++) { 1952 var conditionalModule = modules[conditionalModules[i]]; 1953 1954 if (this._queue.indexOf(conditionalModule.name) === -1 && this._testConditionalModule(conditionalModule.condition.test)) { 1955 this._queue.push(conditionalModule.name); 1956 } 1957 } 1958 1959 module.conditionalMark = true; 1960 } 1961 } 1962 1963 /** 1964 * Processes all modules in the {@link DependencyBuilder#_queue} and 1965 * resolves their dependencies. If the module is not registered to the 1966 * configuration, it will be automatically added there with no dependencies. 1967 * The function implements a standard 1968 * [topological sorting based on depth-first search]{@link http://en.wikipedia.org/wiki/Topological_sorting}. 1969 * 1970 * @protected 1971 */ 1972 1973 }, { 1974 key: '_resolveDependencies', 1975 value: function _resolveDependencies() { 1976 // Process all modules in the queue. 1977 // Note: modules may be added to the queue during the process of 1978 // evaluating. 1979 var modules = this._configParser.getModules(); 1980 1981 for (var i = 0; i < this._queue.length; i++) { 1982 var module = modules[this._queue[i]]; 1983 1984 // If not registered, add the module on the fly with no 1985 // dependencies. Note: the module name (this._queue[i]) is expected 1986 // to be already mapped. 1987 if (!module) { 1988 module = this._configParser.addModule({ 1989 name: this._queue[i], 1990 dependencies: [] 1991 }); 1992 } 1993 1994 if (!module.mark) { 1995 this._visit(module); 1996 } 1997 } 1998 } 1999 2000 /** 2001 * Executes the test function of an conditional module and adds it to the 2002 * list of module dependencies if the function returns true. 2003 * 2004 * @param {function|string} testFunction The function which have to be 2005 * executed. May be Function object or string. 2006 * @return {boolean} The result of the execution of the test function. 2007 */ 2008 2009 }, { 2010 key: '_testConditionalModule', 2011 value: function _testConditionalModule(testFunction) { 2012 if (typeof testFunction === 'function') { 2013 return testFunction(); 2014 } else { 2015 return eval('false || ' + testFunction)(); 2016 } 2017 } 2018 2019 /** 2020 * Visits a module during the process of resolving dependencies. The 2021 * function will throw exception in case of circular dependencies among 2022 * modules. If a dependency is not registered, it will be added to the 2023 * configuration as a module without dependencies. 2024 * 2025 * @protected 2026 * @param {object} module The module which have to be visited. 2027 */ 2028 2029 }, { 2030 key: '_visit', 2031 value: function _visit(module) { 2032 // Directed Acyclic Graph is supported only, throw exception if there 2033 // are circular dependencies. 2034 if (module.tmpMark) { 2035 throw new Error('Error processing module: ' + module.name + '. ' + 'The provided configuration is not Directed Acyclic Graph.'); 2036 } 2037 2038 // Check if this module has conditional modules and add them to the 2039 // queue if so. 2040 this._processConditionalModules(module); 2041 2042 if (!module.mark) { 2043 module.tmpMark = true; 2044 2045 var modules = this._configParser.getModules(); 2046 2047 for (var i = 0; i < module.dependencies.length; i++) { 2048 var dependencyName = module.dependencies[i]; 2049 2050 if (dependencyName === 'require' || dependencyName === 'exports' || dependencyName === 'module') { 2051 continue; 2052 } 2053 2054 // Resolve relative path and map the dependency to its alias 2055 dependencyName = this._pathResolver.resolvePath(module.name, dependencyName); 2056 2057 // A module may have many dependencies so we should map them.
2058 var mappedDependencyName = this._configParser.mapModule(dependencyName, module.map); 2059 var moduleDependency = modules[mappedDependencyName]; 2060 2061 // Register on the fly all unregistered in the configuration 2062 // dependencies as modules without dependencies. 2063 if (!moduleDependency) { 2064 moduleDependency = this._configParser.addModule({ 2065 name: mappedDependencyName, 2066 dependencies: [] 2067 }); 2068 } 2069 2070 this._visit(moduleDependency); 2071 } 2072 2073 module.mark = true; 2074 2075 module.tmpMark = false; 2076 2077 this._result.unshift(module.name); 2078 } 2079 } 2080 }]); 2081 2082 return DependencyBuilder; 2083 }(); 2084 2085 exports.default = DependencyBuilder; 2086 2087 /***/ 2088}, 2089/* 5 */ 2090/***/function (module, exports, __webpack_require__) { 2091 2092 "use strict"; 2093 2094 Object.defineProperty(exports, "__esModule", { 2095 value: true 2096 }); 2097 2098 var _createClass = function () { 2099 function defineProperties(target, props) { 2100 for (var i = 0; i < props.length; i++) { 2101 var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); 2102 } 2103 }return function (Constructor, protoProps, staticProps) { 2104 if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; 2105 }; 2106 }(); 2107 2108 function _classCallCheck(instance, Constructor) { 2109 if (!(instance instanceof Constructor)) { 2110 throw new TypeError("Cannot call a class as a function"); 2111 } 2112 } 2113 2114 /** 2115 * 2116 */ 2117 var EventEmitter = function () { 2118 /** 2119 * Creates an instance of EventEmitter class. 2120 * 2121 * @constructor 2122 */ 2123 function EventEmitter() { 2124 _classCallCheck(this, EventEmitter); 2125 2126 this._events = {}; 2127 } 2128 2129 /** 2130 * Adds event listener to an event. 2131 * 2132 * @param {string} event The name of the event. 2133 * @param {Function} callback Callback method to be invoked when event is 2134 * being emitted. 2135 */ 2136 2137 _createClass(EventEmitter, [{ 2138 key: 'on', 2139 value: function on(event, callback) { 2140 var listeners = this._events[event] = this._events[event] || []; 2141 2142 listeners.push(callback); 2143 } 2144 2145 /** 2146 * Removes an event from the list of event listeners to some event. 2147 * 2148 * @param {string} event The name of the event. 2149 * @param {function} callback Callback method to be removed from the list 2150 * of listeners. 2151 */ 2152 2153 }, { 2154 key: 'off', 2155 value: function off(event, callback) { 2156 var listeners = this._events[event]; 2157 2158 if (listeners) { 2159 var callbackIndex = listeners.indexOf(callback); 2160 2161 if (callbackIndex > -1) { 2162 listeners.splice(callbackIndex, 1); 2163 } else {} 2164 } else {} 2165 } 2166 2167 /** 2168 * Emits an event. The function calls all registered listeners in the order 2169 * they have been added. The provided args param will be passed to each 2170 * listener of the event. 2171 * 2172 * @param {string} event The name of the event. 2173 * @param {object} args Object, which will be passed to the listener as only 2174 * argument. 2175 */ 2176 2177 }, { 2178 key: 'emit', 2179 value: function emit(event, args) { 2180 var listeners = this._events[event]; 2181 2182 if (listeners) { 2183 // Slicing is needed to prevent the following situation: 2184 // A listener is being invoked. During its execution, it may 2185 // remove itself from the list. In this case, for loop will 2186 // be damaged, since i will be out of sync. 2187 listeners = listeners.slice(0); 2188 2189 for (var i = 0; i < listeners.length; i++) { 2190 var listener = listeners[i]; 2191 2192 listener.call(listener, args); 2193 } 2194 } else {} 2195 } 2196 }]); 2197 2198 return EventEmitter; 2199 }(); 2200 2201 exports.default = EventEmitter; 2202 2203 /***/ 2204}, 2205/* 6 */ 2206/***/function (module, exports, __webpack_require__) { 2207 2208 "use strict"; 2209 2210 Object.defineProperty(exports, "__esModule", { 2211 value: true 2212 }); 2213 2214 var _createClass = function () { 2215 function defineProperties(target, props) { 2216 for (var i = 0; i < props.length; i++) { 2217 var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); 2218 } 2219 }return function (Constructor, protoProps, staticProps) { 2220 if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; 2221 }; 2222 }(); 2223 2224 function _classCallCheck(instance, Constructor) { 2225 if (!(instance instanceof Constructor)) { 2226 throw new TypeError("Cannot call a class as a function"); 2227 } 2228 } 2229 2230 // External protocols regex, supports: "http", "https", "//" and "www." 2231 var REGEX_EXTERNAL_PROTOCOLS = /^https?:\/\/|\/\/|www\./; 2232 2233 /** 2234 * 2235 */ 2236 2237 var URLBuilder = function () { 2238 /** 2239 * Creates an instance of URLBuilder class. 2240 * 2241 * @constructor 2242 * @param {object} configParser - instance of {@link ConfigParser} object. 2243 */ 2244 function URLBuilder(configParser) { 2245 _classCallCheck(this, URLBuilder); 2246 2247 this._configParser = configParser; 2248 } 2249 2250 /** 2251 * Returns a list of URLs from provided list of modules. 2252 * 2253 * @param {array} modules List of modules for which URLs should be created. 2254 * @return {array} List of URLs. 2255 */ 2256 2257 _createClass(URLBuilder, [{ 2258 key: 'build', 2259 value: function build(modules) { 2260 var bufferAbsoluteURL = []; 2261 var bufferRelativeURL = []; 2262 var modulesAbsoluteURL = []; 2263 var modulesRelativeURL = []; 2264 var result = []; 2265 2266 var config = this._configParser.getConfig(); 2267 2268 var basePath = config.basePath || ''; 2269 var registeredModules = this._configParser.getModules(); 2270 2271 /* istanbul ignore else */ 2272 if (basePath.length && basePath.charAt(basePath.length - 1) !== '/') { 2273 basePath += '/'; 2274 } 2275 2276 for (var i = 0; i < modules.length; i++) { 2277 var module = registeredModules[modules[i]]; 2278 2279 // If module has fullPath, individual URL have to be created. 2280 if (module.fullPath) { 2281 result.push({ 2282 modules: [module.name], 2283 url: this._getURLWithParams(module.fullPath) 2284 }); 2285 } else { 2286 var path = this._getModulePath(module); 2287 var absolutePath = path.indexOf('/') === 0; 2288 2289 // If the URL starts with external protocol, individual URL 2290 // shall be created. 2291 if (REGEX_EXTERNAL_PROTOCOLS.test(path)) { 2292 result.push({ 2293 modules: [module.name], 2294 url: this._getURLWithParams(path) 2295 }); 2296 2297 // If combine is disabled, or the module is an anonymous 2298 // one, create an individual URL based on the config URL and 2299 // module's path. If the module's path starts with "/", do 2300 // not include basePath in the URL. 2301 } else if (!config.combine || module.anonymous) { 2302 result.push({ 2303 modules: [module.name], 2304 url: this._getURLWithParams(config.url + (absolutePath ? '' : basePath) + path) 2305 }); 2306 } else { 2307 // If combine is true, this is not an anonymous module and 2308 // the module does not have full path. The module will be 2309 // collected in a buffer to be loaded among with other 2310 // modules from combo loader. The path will be stored in 2311 // different buffer depending on the fact if it is absolute 2312 // URL or not. 2313 if (absolutePath) { 2314 bufferAbsoluteURL.push(path); 2315 modulesAbsoluteURL.push(module.name); 2316 } else { 2317 bufferRelativeURL.push(path); 2318 modulesRelativeURL.push(module.name); 2319 } 2320 } 2321 } 2322 2323 module.requested = true; 2324 } 2325 2326 // Add to the result all modules, which have to be combined. 2327 if (bufferRelativeURL.length) { 2328 result = result.concat(this._generateBufferURLs(modulesRelativeURL, bufferRelativeURL, { 2329 basePath: basePath, 2330 url: config.url, 2331 urlMaxLength: config.urlMaxLength 2332 })); 2333 bufferRelativeURL.length = 0; 2334 } 2335 2336 if (bufferAbsoluteURL.length) { 2337 result = result.concat(this._generateBufferURLs(modulesAbsoluteURL, bufferAbsoluteURL, { 2338 url: config.url, 2339 urlMaxLength: config.urlMaxLength 2340 })); 2341 bufferAbsoluteURL.length = 0; 2342 } 2343 2344 return result; 2345 } 2346 2347 /** 2348 * Generate the appropriate set of URLs based on the list of 2349 * required modules and the maximum allowed URL length 2350 * 2351 * @param {Array<String>} modules Array of module names 2352 * @param {Array<String>} urls Array of module URLs 2353 * @param {Object}
2353 config Configuration object containing URL, basePath and 2354 * urlMaxLength 2355 * @return {Array<Object>} Resulting array of {modules, url} objects 2356 */ 2357 2358 }, { 2359 key: '_generateBufferURLs', 2360 value: function _generateBufferURLs(modules, urls, config) { 2361 var i = void 0; 2362 var basePath = config.basePath || ''; 2363 var result = []; 2364 var urlMaxLength = config.urlMaxLength || 2000; 2365 2366 var urlResult = { 2367 modules: [modules[0]], 2368 url: config.url + basePath + urls[0] 2369 }; 2370 2371 for (i = 1; i < urls.length; i++) { 2372 var module = modules[i]; 2373 var path = urls[i]; 2374 2375 if (urlResult.url.length + basePath.length + path.length + 1 < urlMaxLength) { 2376 urlResult.modules.push(module); 2377 urlResult.url += '&' + basePath + path; 2378 } else { 2379 result.push(urlResult); 2380 2381 urlResult = { 2382 modules: [module], 2383 url: config.url + basePath + path 2384 }; 2385 } 2386 } 2387 2388 urlResult.url = this._getURLWithParams(urlResult.url); 2389 2390 result.push(urlResult); 2391 2392 return result; 2393 } 2394 2395 /** 2396 * Returns the path for a module. If module has property path, it will be 2397 * returned directly. Otherwise, the name of module will be used and 2398 * extension .js will be added to module name if omitted. 2399 * 2400 * @protected 2401 * @param {object} module The module which path should be returned. 2402 * @return {string} Module path. 2403 */ 2404 2405 }, { 2406 key: '_getModulePath', 2407 value: function _getModulePath(module) { 2408 var path = module.path || module.name; 2409 2410 var paths = this._configParser.getConfig().paths || {}; 2411 2412 var found = false; 2413 Object.keys(paths).forEach(function (item) { 2414 /* istanbul ignore else */ 2415 if (path === item || path.indexOf(item + '/') === 0) { 2416 path = paths[item] + path.substring(item.length); 2417 } 2418 }); 2419 2420 /* istanbul ignore else */ 2421 if (!found && typeof paths['*'] === 'function') { 2422 path = paths['*'](path); 2423 } 2424 2425 if (!REGEX_EXTERNAL_PROTOCOLS.test(path) && path.lastIndexOf('.js') !== path.length - 3) { 2426 path += '.js'; 2427 } 2428 2429 return path; 2430 } 2431 2432 /** 2433 * Returns an url with parameters defined in config.defaultURLParams. If 2434 * config.defaultURLParams is not defined or is an empty map, the url will 2435 * be returned unmodified. 2436 * 2437 * @protected 2438 * @param {string} url The url to be returned with parameters. 2439 * @return {string} url The url with parameters. 2440 */ 2441 2442 }, { 2443 key: '_getURLWithParams', 2444 value: function _getURLWithParams(url) { 2445 var config = this._configParser.getConfig(); 2446 2447 var defaultURLParams = config.defaultURLParams || {}; 2448 2449 var keys = Object.keys(defaultURLParams); 2450 2451 if (!keys.length) { 2452 return url; 2453 } 2454 2455 var queryString = keys.map(function (key) { 2456 return key + '=' + defaultURLParams[key]; 2457 }).join('&'); 2458 2459 return url + (url.indexOf('?') > -1 ? '&' : '?') + queryString; 2460 } 2461 }]); 2462 2463 return URLBuilder; 2464 }(); 2465 2466 exports.default = URLBuilder; 2467 2468 /***/ 2469}, 2470/* 7 */ 2471/***/function (module, exports) { 2472 2473 module.exports = { "name": "liferay-amd-loader", "version": "3.1.2", "description": "AMD Loader with support for combo URL and conditional loading", "scripts": { "clean": "rm -rf build", "build": "node bin/build-loader.js", "ci": "prettier-eslint --list-different && npm run lint && npm run build && npm run build-demo && npm test", "build-demo": "node bin/build-demo.js", "demo": "node bin/run-demo.js", "test": "jest", "format": "prettier-eslint --write 'src/**/*.js'", "lint": "eslint 'src/**/*.js' && eslint 'bin/**/*.js'", "prepublish": "publish-please guard", "publish-please": "publish-please", "prepublishOnly": "npm run build && npm run build-demo && npm test" }, "repository": { "type": "git", "url": "https://github.com/liferay/liferay-amd-loader.git" }, "jest": { "collectCoverage": true, "coverageDirectory": "build/coverage", "modulePathIgnorePatterns": ["liferay-amd-loader/build/.*", ".*/__tests__/fixture/.*"] }, "author": "Iliyan Peychev", "license": "LGPL-3.0", "keywords": ["Liferay", "AMD", "ES6", "Loader"], "bugs": { "url": "https://github.com/liferay/liferay-amd-loader/issues" }, "homepage": "https://github.com/liferay/liferay-amd-loader", "files": [".babelrc", ".eslintrc", ".publishrc", "LICENSE.md", "package.json", "README.md", "webpack.config.js", "src", "bin", "build", "src"], "dependencies": { "es6-promise": "^4.0.5" }, "devDependencies": { "babel-loader": "^7.1.2", "babel-preset-es2015": "^6.24.1", "combohandler": "^0.4.0", "eslint": "^4.17.0", "eslint-config-liferay": "^2.0.18", "fs-extra": "^5.0.0", "globby": "^7.1.1", "http-server": "^0.11.1", "jest": "^22.2.1", "liferay-module-config-generator": "^1.3.3", "prettier-eslint-cli": "^4.7.0", "publish-please": "^2.3.1", "uglifyjs-webpack-plugin": "^1.2.0", "webpack": "^3.10.0", "webpack-clear-console": "^1.0.3" } 2474 2475 /***/ }; 2476}, 2477/* 8 */ 2478/***/function (module, exports, __webpack_require__) { 2479 2480 /* WEBPACK VAR INJECTION */(function (process, global) { 2481 var require; /*! 2482 * @overview es6-promise - a tiny implementation of Promises/A+. 2483 * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) 2484 * @license Licensed under MIT license 2485 * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE 2486 * @version 4.1.0 2487 */ 2488 2489 (function (global, factory) { 2490 true ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.ES6Promise = factory(); 2491 })(this, function () { 2492 'use strict'; 2493 2494 function objectOrFunction(x) { 2495 return typeof x === 'function' || (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && x !== null; 2496 } 2497 2498 function isFunction(x) { 2499 return typeof x === 'function'; 2500 } 2501 2502 var _isArray = undefined; 2503 if (!Array.isArray) { 2504 _isArray = function _isArray(x) { 2505 return Object.prototype.toString.call(x) === '[object Array]'; 2506 }; 2507 } else { 2508 _isArray = Array.isArray; 2509 } 2510 2511 var isArray = _isArray; 2512 2513 var len = 0; 2514 var vertxNext = undefined; 2515 var customSchedulerFn = undefined; 2516 2517 var asap = function asap(callback, arg) { 2518 queue[len] = callback; 2519 queue[len + 1] = arg;
vendor: 4,155 bytes, lines 2520-2678
2520 len += 2; 2521 if (len === 2) { 2522 // If len is 2, that means that we need to schedule an async flush. 2523 // If additional callbacks are queued before the queue is flushed, they 2524 // will be processed by this flush that we are scheduling. 2525 if (customSchedulerFn) { 2526 customSchedulerFn(flush); 2527 } else { 2528 scheduleFlush(); 2529 } 2530 } 2531 }; 2532 2533 function setScheduler(scheduleFn) { 2534 customSchedulerFn = scheduleFn; 2535 } 2536 2537 function setAsap(asapFn) { 2538 asap = asapFn; 2539 } 2540 2541 var browserWindow = typeof window !== 'undefined' ? window : undefined; 2542 var browserGlobal = browserWindow || {}; 2543 var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; 2544 var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; 2545 2546 // test for web worker but not in IE10 2547 var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; 2548 2549 // node 2550 function useNextTick() { 2551 // node version 0.10.x displays a deprecation warning when nextTick is used recursively 2552 // see https://github.com/cujojs/when/issues/410 for details 2553 return function () { 2554 return process.nextTick(flush); 2555 }; 2556 } 2557 2558 // vertx 2559 function useVertxTimer() { 2560 if (typeof vertxNext !== 'undefined') { 2561 return function () { 2562 vertxNext(flush); 2563 }; 2564 } 2565 2566 return useSetTimeout(); 2567 } 2568 2569 function useMutationObserver() { 2570 var iterations = 0; 2571 var observer = new BrowserMutationObserver(flush); 2572 var node = document.createTextNode(''); 2573 observer.observe(node, { characterData: true }); 2574 2575 return function () { 2576 node.data = iterations = ++iterations % 2; 2577 }; 2578 } 2579 2580 // web worker 2581 function useMessageChannel() { 2582 var channel = new MessageChannel(); 2583 channel.port1.onmessage = flush; 2584 return function () { 2585 return channel.port2.postMessage(0); 2586 }; 2587 } 2588 2589 function useSetTimeout() { 2590 // Store setTimeout reference so es6-promise will be unaffected by 2591 // other code modifying setTimeout (like sinon.useFakeTimers()) 2592 var globalSetTimeout = setTimeout; 2593 return function () { 2594 return globalSetTimeout(flush, 1); 2595 }; 2596 } 2597 2598 var queue = new Array(1000); 2599 function flush() { 2600 for (var i = 0; i < len; i += 2) { 2601 var callback = queue[i]; 2602 var arg = queue[i + 1]; 2603 2604 callback(arg); 2605 2606 queue[i] = undefined; 2607 queue[i + 1] = undefined; 2608 } 2609 2610 len = 0; 2611 } 2612 2613 function attemptVertx() { 2614 try { 2615 var r = require; 2616 var vertx = __webpack_require__(11); 2617 vertxNext = vertx.runOnLoop || vertx.runOnContext; 2618 return useVertxTimer(); 2619 } catch (e) { 2620 return useSetTimeout(); 2621 } 2622 } 2623 2624 var scheduleFlush = undefined; 2625 // Decide what async method to use to triggering processing of queued callbacks: 2626 if (isNode) { 2627 scheduleFlush = useNextTick(); 2628 } else if (BrowserMutationObserver) { 2629 scheduleFlush = useMutationObserver(); 2630 } else if (isWorker) { 2631 scheduleFlush = useMessageChannel(); 2632 } else if (browserWindow === undefined && "function" === 'function') { 2633 scheduleFlush = attemptVertx(); 2634 } else { 2635 scheduleFlush = useSetTimeout(); 2636 } 2637 2638 function then(onFulfillment, onRejection) { 2639 var _arguments = arguments; 2640 2641 var parent = this; 2642 2643 var child = new this.constructor(noop); 2644 2645 if (child[PROMISE_ID] === undefined) { 2646 makePromise(child); 2647 } 2648 2649 var _state = parent._state; 2650 2651 if (_state) { 2652 (function () { 2653 var callback = _arguments[_state - 1]; 2654 asap(function () { 2655 return invokeCallback(_state, child, callback, parent._result); 2656 }); 2657 })(); 2658 } else { 2659 subscribe(parent, child, onFulfillment, onRejection); 2660 } 2661 2662 return child; 2663 } 2664 2665 /** 2666 `Promise.resolve` returns a promise that will become resolved with the 2667 passed `value`. It is shorthand for the following: 2668 2669 ```javascript 2670 let promise = new Promise(function(resolve, reject) { 2671 resolve(1); 2672 }); 2673 2674 promise.then(function(value) { 2675 // value === 1 2676 }); 2677 ``` 2678
vendor: 3,593 bytes, lines 2679-2815
2679 Instead of writing the above, your code now simply becomes the following: 2680 2681 ```javascript 2682 let promise = Promise.resolve(1); 2683 2684 promise.then(function(value) { 2685 // value === 1 2686 }); 2687 ``` 2688 2689 @method resolve 2690 @static 2691 @param {Any} value value that the returned promise will be resolved with 2692 Useful for tooling. 2693 @return {Promise} a promise that will become fulfilled with the given 2694 `value` 2695 */ 2696 function resolve(object) { 2697 /*jshint validthis:true */ 2698 var Constructor = this; 2699 2700 if (object && (typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object' && object.constructor === Constructor) { 2701 return object; 2702 } 2703 2704 var promise = new Constructor(noop); 2705 _resolve(promise, object); 2706 return promise; 2707 } 2708 2709 var PROMISE_ID = Math.random().toString(36).substring(16); 2710 2711 function noop() {} 2712 2713 var PENDING = void 0; 2714 var FULFILLED = 1; 2715 var REJECTED = 2; 2716 2717 var GET_THEN_ERROR = new ErrorObject(); 2718 2719 function selfFulfillment() { 2720 return new TypeError("You cannot resolve a promise with itself"); 2721 } 2722 2723 function cannotReturnOwn() { 2724 return new TypeError('A promises callback cannot return that same promise.'); 2725 } 2726 2727 function getThen(promise) { 2728 try { 2729 return promise.then; 2730 } catch (error) { 2731 GET_THEN_ERROR.error = error; 2732 return GET_THEN_ERROR; 2733 } 2734 } 2735 2736 function tryThen(then, value, fulfillmentHandler, rejectionHandler) { 2737 try { 2738 then.call(value, fulfillmentHandler, rejectionHandler); 2739 } catch (e) { 2740 return e; 2741 } 2742 } 2743 2744 function handleForeignThenable(promise, thenable, then) { 2745 asap(function (promise) { 2746 var sealed = false; 2747 var error = tryThen(then, thenable, function (value) { 2748 if (sealed) { 2749 return; 2750 } 2751 sealed = true; 2752 if (thenable !== value) { 2753 _resolve(promise, value); 2754 } else { 2755 fulfill(promise, value); 2756 } 2757 }, function (reason) { 2758 if (sealed) { 2759 return; 2760 } 2761 sealed = true; 2762 2763 _reject(promise, reason); 2764 }, 'Settle: ' + (promise._label || ' unknown promise')); 2765 2766 if (!sealed && error) { 2767 sealed = true; 2768 _reject(promise, error); 2769 } 2770 }, promise); 2771 } 2772 2773 function handleOwnThenable(promise, thenable) { 2774 if (thenable._state === FULFILLED) { 2775 fulfill(promise, thenable._result); 2776 } else if (thenable._state === REJECTED) { 2777 _reject(promise, thenable._result); 2778 } else { 2779 subscribe(thenable, undefined, function (value) { 2780 return _resolve(promise, value); 2781 }, function (reason) { 2782 return _reject(promise, reason); 2783 }); 2784 } 2785 } 2786 2787 function handleMaybeThenable(promise, maybeThenable, then$$) { 2788 if (maybeThenable.constructor === promise.constructor && then$$ === then && maybeThenable.constructor.resolve === resolve) { 2789 handleOwnThenable(promise, maybeThenable); 2790 } else { 2791 if (then$$ === GET_THEN_ERROR) { 2792 _reject(promise, GET_THEN_ERROR.error); 2793 GET_THEN_ERROR.error = null; 2794 } else if (then$$ === undefined) { 2795 fulfill(promise, maybeThenable); 2796 } else if (isFunction(then$$)) { 2797 handleForeignThenable(promise, maybeThenable, then$$); 2798 } else { 2799 fulfill(promise, maybeThenable); 2800 } 2801 } 2802 } 2803 2804 function _resolve(promise, value) { 2805 if (promise === value) { 2806 _reject(promise, selfFulfillment()); 2807 } else if (objectOrFunction(value)) { 2808 handleMaybeThenable(promise, value, getThen(value)); 2809 } else { 2810 fulfill(promise, value); 2811 } 2812 } 2813 2814 function publishRejection(promise) { 2815 if (promise._onerror) {
vendor: 4,792 bytes, lines 2816-3023
2816 promise._onerror(promise._result); 2817 } 2818 2819 publish(promise); 2820 } 2821 2822 function fulfill(promise, value) { 2823 if (promise._state !== PENDING) { 2824 return; 2825 } 2826 2827 promise._result = value; 2828 promise._state = FULFILLED; 2829 2830 if (promise._subscribers.length !== 0) { 2831 asap(publish, promise); 2832 } 2833 } 2834 2835 function _reject(promise, reason) { 2836 if (promise._state !== PENDING) { 2837 return; 2838 } 2839 promise._state = REJECTED; 2840 promise._result = reason; 2841 2842 asap(publishRejection, promise); 2843 } 2844 2845 function subscribe(parent, child, onFulfillment, onRejection) { 2846 var _subscribers = parent._subscribers; 2847 var length = _subscribers.length; 2848 2849 parent._onerror = null; 2850 2851 _subscribers[length] = child; 2852 _subscribers[length + FULFILLED] = onFulfillment; 2853 _subscribers[length + REJECTED] = onRejection; 2854 2855 if (length === 0 && parent._state) { 2856 asap(publish, parent); 2857 } 2858 } 2859 2860 function publish(promise) { 2861 var subscribers = promise._subscribers; 2862 var settled = promise._state; 2863 2864 if (subscribers.length === 0) { 2865 return; 2866 } 2867 2868 var child = undefined, 2869 callback = undefined, 2870 detail = promise._result; 2871 2872 for (var i = 0; i < subscribers.length; i += 3) { 2873 child = subscribers[i]; 2874 callback = subscribers[i + settled]; 2875 2876 if (child) { 2877 invokeCallback(settled, child, callback, detail); 2878 } else { 2879 callback(detail); 2880 } 2881 } 2882 2883 promise._subscribers.length = 0; 2884 } 2885 2886 function ErrorObject() { 2887 this.error = null; 2888 } 2889 2890 var TRY_CATCH_ERROR = new ErrorObject(); 2891 2892 function tryCatch(callback, detail) { 2893 try { 2894 return callback(detail); 2895 } catch (e) { 2896 TRY_CATCH_ERROR.error = e; 2897 return TRY_CATCH_ERROR; 2898 } 2899 } 2900 2901 function invokeCallback(settled, promise, callback, detail) { 2902 var hasCallback = isFunction(callback), 2903 value = undefined, 2904 error = undefined, 2905 succeeded = undefined, 2906 failed = undefined; 2907 2908 if (hasCallback) { 2909 value = tryCatch(callback, detail); 2910 2911 if (value === TRY_CATCH_ERROR) { 2912 failed = true; 2913 error = value.error; 2914 value.error = null; 2915 } else { 2916 succeeded = true; 2917 } 2918 2919 if (promise === value) { 2920 _reject(promise, cannotReturnOwn()); 2921 return; 2922 } 2923 } else { 2924 value = detail; 2925 succeeded = true; 2926 } 2927 2928 if (promise._state !== PENDING) { 2929 // noop 2930 } else if (hasCallback && succeeded) { 2931 _resolve(promise, value); 2932 } else if (failed) { 2933 _reject(promise, error); 2934 } else if (settled === FULFILLED) { 2935 fulfill(promise, value); 2936 } else if (settled === REJECTED) { 2937 _reject(promise, value); 2938 } 2939 } 2940 2941 function initializePromise(promise, resolver) { 2942 try { 2943 resolver(function resolvePromise(value) { 2944 _resolve(promise, value); 2945 }, function rejectPromise(reason) { 2946 _reject(promise, reason); 2947 }); 2948 } catch (e) { 2949 _reject(promise, e); 2950 } 2951 } 2952 2953 var id = 0; 2954 function nextId() { 2955 return id++; 2956 } 2957 2958 function makePromise(promise) { 2959 promise[PROMISE_ID] = id++; 2960 promise._state = undefined; 2961 promise._result = undefined; 2962 promise._subscribers = []; 2963 } 2964 2965 function Enumerator(Constructor, input) { 2966 this._instanceConstructor = Constructor; 2967 this.promise = new Constructor(noop); 2968 2969 if (!this.promise[PROMISE_ID]) { 2970 makePromise(this.promise); 2971 } 2972 2973 if (isArray(input)) { 2974 this._input = input; 2975 this.length = input.length; 2976 this._remaining = input.length; 2977 2978 this._result = new Array(this.length); 2979 2980 if (this.length === 0) { 2981 fulfill(this.promise, this._result); 2982 } else { 2983 this.length = this.length || 0; 2984 this._enumerate(); 2985 if (this._remaining === 0) { 2986 fulfill(this.promise, this._result); 2987 } 2988 } 2989 } else { 2990 _reject(this.promise, validationError()); 2991 } 2992 } 2993 2994 function validationError() { 2995 return new Error('Array Methods must be provided an Array'); 2996 }; 2997 2998 Enumerator.prototype._enumerate = function () { 2999 var length = this.length; 3000 var _input = this._input; 3001 3002 for (var i = 0; this._state === PENDING && i < length; i++) { 3003 this._eachEntry(_input[i], i); 3004 } 3005 }; 3006 3007 Enumerator.prototype._eachEntry = function (entry, i) { 3008 var c = this._instanceConstructor; 3009 var resolve$$ = c.resolve; 3010 3011 if (resolve$$ === resolve) { 3012 var _then = getThen(entry); 3013 3014 if (_then === then && entry._state !== PENDING) { 3015 this._settledAt(entry._state, i, entry._result); 3016 } else if (typeof _then !== 'function') { 3017 this._remaining--; 3018 this._result[i] = entry; 3019 } else if (c === Promise) { 3020 var promise = new c(noop); 3021 handleMaybeThenable(promise, entry, _then); 3022 this._willSettleAt(promise, i); 3023 } else {
vendor: 3,796 bytes, lines 3024-3158
3024 this._willSettleAt(new c(function (resolve$$) { 3025 return resolve$$(entry); 3026 }), i); 3027 } 3028 } else { 3029 this._willSettleAt(resolve$$(entry), i); 3030 } 3031 }; 3032 3033 Enumerator.prototype._settledAt = function (state, i, value) { 3034 var promise = this.promise; 3035 3036 if (promise._state === PENDING) { 3037 this._remaining--; 3038 3039 if (state === REJECTED) { 3040 _reject(promise, value); 3041 } else { 3042 this._result[i] = value; 3043 } 3044 } 3045 3046 if (this._remaining === 0) { 3047 fulfill(promise, this._result); 3048 } 3049 }; 3050 3051 Enumerator.prototype._willSettleAt = function (promise, i) { 3052 var enumerator = this; 3053 3054 subscribe(promise, undefined, function (value) { 3055 return enumerator._settledAt(FULFILLED, i, value); 3056 }, function (reason) { 3057 return enumerator._settledAt(REJECTED, i, reason); 3058 }); 3059 }; 3060 3061 /** 3062 `Promise.all` accepts an array of promises, and returns a new promise which 3063 is fulfilled with an array of fulfillment values for the passed promises, or 3064 rejected with the reason of the first passed promise to be rejected. It casts all 3065 elements of the passed iterable to promises as it runs this algorithm. 3066 3067 Example: 3068 3069 ```javascript 3070 let promise1 = resolve(1); 3071 let promise2 = resolve(2); 3072 let promise3 = resolve(3); 3073 let promises = [ promise1, promise2, promise3 ]; 3074 3075 Promise.all(promises).then(function(array) { 3076 // The array here would be [ 1, 2, 3 ]; 3077 }); 3078 ``` 3079 3080 If any of the `promises` given to `all` are rejected, the first promise 3081 that is rejected will be given as an argument to the returned promises's 3082 rejection handler. For example: 3083 3084 Example: 3085 3086 ```javascript 3087 let promise1 = resolve(1); 3088 let promise2 = reject(new Error("2")); 3089 let promise3 = reject(new Error("3")); 3090 let promises = [ promise1, promise2, promise3 ]; 3091 3092 Promise.all(promises).then(function(array) { 3093 // Code here never runs because there are rejected promises! 3094 }, function(error) { 3095 // error.message === "2" 3096 }); 3097 ``` 3098 3099 @method all 3100 @static 3101 @param {Array} entries array of promises 3102 @param {String} label optional string for labeling the promise. 3103 Useful for tooling. 3104 @return {Promise} promise that is fulfilled when all `promises` have been 3105 fulfilled, or rejected if any of them become rejected. 3106 @static 3107 */ 3108 function all(entries) { 3109 return new Enumerator(this, entries).promise; 3110 } 3111 3112 /** 3113 `Promise.race` returns a new promise which is settled in the same way as the 3114 first passed promise to settle. 3115 3116 Example: 3117 3118 ```javascript 3119 let promise1 = new Promise(function(resolve, reject) { 3120 setTimeout(function() { 3121 resolve('promise 1'); 3122 }, 200); 3123 }); 3124 3125 let promise2 = new Promise(function(resolve, reject) { 3126 setTimeout(function() { 3127 resolve('promise 2'); 3128 }, 100); 3129 }); 3130 3131 Promise.race([promise1, promise2]).then(function(result) { 3132 // result === 'promise 2' because it was resolved before promise1 3133 // was resolved. 3134 }); 3135 ``` 3136 3137 `Promise.race` is deterministic in that only the state of the first 3138 settled promise matters. For example, even if other promises given to the 3139 `promises` array argument are resolved, but the first settled promise has 3140 become rejected before the other promises became fulfilled, the returned 3141 promise will become rejected: 3142 3143 ```javascript 3144 let promise1 = new Promise(function(resolve, reject) { 3145 setTimeout(function() { 3146 resolve('promise 1'); 3147 }, 200); 3148 }); 3149 3150 let promise2 = new Promise(function(resolve, reject) { 3151 setTimeout(function() { 3152 reject(new Error('promise 2')); 3153 }, 100); 3154 }); 3155 3156 Promise.race([promise1, promise2]).then(function(result) { 3157 // Code here never runs 3158 }, function(reason) {
3159 // reason.message === 'promise 2' because promise 2 became rejected before 3160 // promise 1 became fulfilled 3161 }); 3162 ``` 3163 3164 An example real-world use case is implementing timeouts: 3165 3166 ```javascript 3167 Promise.race([ajax('foo.json'), timeout(5000)]) 3168 ``` 3169 3170 @method race 3171 @static 3172 @param {Array} promises array of promises to observe 3173 Useful for tooling. 3174 @return {Promise} a promise which settles in the same way as the first passed 3175 promise to settle. 3176 */ 3177 function race(entries) { 3178 /*jshint validthis:true */ 3179 var Constructor = this; 3180 3181 if (!isArray(entries)) { 3182 return new Constructor(function (_, reject) { 3183 return reject(new TypeError('You must pass an array to race.')); 3184 }); 3185 } else { 3186 return new Constructor(function (resolve, reject) { 3187 var length = entries.length; 3188 for (var i = 0; i < length; i++) { 3189 Constructor.resolve(entries[i]).then(resolve, reject); 3190 } 3191 }); 3192 } 3193 } 3194 3195 /** 3196 `Promise.reject` returns a promise rejected with the passed `reason`. 3197 It is shorthand for the following: 3198 3199 ```javascript 3200 let promise = new Promise(function(resolve, reject) { 3201 reject(new Error('WHOOPS')); 3202 }); 3203 3204 promise.then(function(value) { 3205 // Code here doesn't run because the promise is rejected! 3206 }, function(reason) { 3207 // reason.message === 'WHOOPS' 3208 }); 3209 ``` 3210 3211 Instead of writing the above, your code now simply becomes the following: 3212 3213 ```javascript 3214 let promise = Promise.reject(new Error('WHOOPS')); 3215 3216 promise.then(function(value) { 3217 // Code here doesn't run because the promise is rejected! 3218 }, function(reason) { 3219 // reason.message === 'WHOOPS' 3220 }); 3221 ``` 3222 3223 @method reject 3224 @static 3225 @param {Any} reason value that the returned promise will be rejected with. 3226 Useful for tooling. 3227 @return {Promise} a promise rejected with the given `reason`. 3228 */ 3229 function reject(reason) { 3230 /*jshint validthis:true */ 3231 var Constructor = this; 3232 var promise = new Constructor(noop); 3233 _reject(promise, reason); 3234 return promise; 3235 } 3236 3237 function needsResolver() { 3238 throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); 3239 } 3240 3241 function needsNew() { 3242 throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object c
3242onstructor cannot be called as a function."); 3243 } 3244 3245 /** 3246 Promise objects represent the eventual result of an asynchronous operation. The 3247 primary way of interacting with a promise is through its `then` method, which 3248 registers callbacks to receive either a promise's eventual value or the reason 3249 why the promise cannot be fulfilled. 3250 3251 Terminology 3252 ----------- 3253 3254 - `promise` is an object or function with a `then` method whose behavior conforms to this specification. 3255 - `thenable` is an object or function that defines a `then` method. 3256 - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). 3257 - `exception` is a value that is thrown using the throw statement. 3258 - `reason` is a value that indicates why a promise was rejected. 3259 - `settled` the final resting state of a promise, fulfilled or rejected. 3260 3261 A promise can be in one of three states: pending, fulfilled, or rejected. 3262 3263 Promises that are fulfilled have a fulfillment value and are in the fulfilled 3264 state. Promises that are rejected have a rejection reason and are in the 3265 rejected state. A fulfillment value is never a thenable. 3266 3267 Promises can also be said to *resolve* a value. If this value is also a 3268 promise, then the original promise's settled state will match the value's 3269 settled state. So a promise that *resolves* a promise that rejects will 3270 itself reject, and a promise that *resolves* a promise that fulfills will 3271 itself fulfill. 3272 3273 Basic Usage: 3274 ------------ 3275 3276 ```js 3277 let promise = new Promise(function(resolve, reject) { 3278 // on success 3279 resolve(value); 3280 3281 // on failure 3282 reject(reason); 3283 }); 3284 3285 promise.then(function(value) { 3286 // on fulfillment 3287 }, function(reason) { 3288 // on rejection 3289 }); 3290 ``` 3291 3292 Advanced Usage: 3293 --------------- 3294 3295 Promises shine when abstracting away asynchronous interactions such as 3296 `XMLHttpRequest`s. 3297 3298 ```js 3299 function getJSON(url) { 3300 return new Promise(function(resolve, reject) { 3301 let xhr = new XMLHttpRequest(); 3302 3303 xhr.open('GET', url); 3304 xhr.onreadystatechange = handler; 3305 xhr.responseType = 'json'; 3306 xhr.setRequestHeader('Accept', 'application/json'); 3307 xhr.send(); 3308 3309 function handler() { 3310 if (this.readyState === this.DONE) { 3311 if (this.status === 200) { 3312 resolve(this.response); 3313 } else { 3314 reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); 3315 } 3316 } 3317 }; 3318 }); 3319 } 3320 3321 getJSON('/posts.json').then(function(json) { 3322 // on fulfillment 3323 }, function(reason) { 3324 // on rejection 3325 }); 3326 ``` 3327 3328 Unlike callbacks, promises are great composable primitives. 3329 3330 ```js 3331 Promise.all([ 3332 getJSON('/posts'), 3333 getJSON('/comments') 3334 ]).then(function(values) { 3335 values[0] // => postsJSON 3336 values[1] // => commentsJSON 3337 3338 return values; 3339 }); 3340 ``` 3341 3342 @class Promise 3343 @param {function} resolver 3344 Useful for tooling. 3345 @constructor 3346 */ 3347 function Promise(resolver) { 3348 this[PROMISE_ID] = nextId(); 3349 this._result = this._state = undefined; 3350 this._subscribers = []; 3351 3352 if (noop !== resolver) { 3353 typeof resolver !== 'function' && needsResolver(); 3354 this instanceof Promise ? initializePromise(this, resolver) : needsNew(); 3355 } 3356 } 3357 3358 Promise.all = all; 3359 Promise.race = race; 3360 Promise.resolve = resolve; 3361 Promise.reject = reject; 3362 Promise._setScheduler = setScheduler; 3363 Promise._setAsap = setAsap; 3364 Promise._asap = asap; 3365 3366 Promise.prototype = { 3367 constructor: Promise, 3368 3369 /** 3370 The primary way of interacting with a promise is through its `then` method, 3371 which registers callbacks to receive either a promise's eventual value or the 3372 reason why the promise cannot be fulfilled. 3373 3374 ```js 3375 findUser().then(function(user) { 3376 // user is available 3377 }, function(reason) { 3378 // user is unavailable, and you are given the reason why 3379 }); 3380 ``` 3381 3382 Chaining 3383 -------- 3384 3385 The return value of `then` is itself a promise. This second, 'downstream' 3386 promise is resolved with the return value of the first promise's fulfillment 3387 or rejection handler, or rejected if the handler throws an exception. 3388 3389 ```js 3390 findUser().then(function (user) { 3391 return user.name; 3392 }, function(reason) { 3393 return 'default name'; 3394 }).then(function (userName) { 3395 // If `findUser` fulfilled, `userName` will be the user's name, otherwise it 3396 // will be `'default name'` 3397 }); 3398 3399 findUser().then(function (user) { 3400 throw new Error('Found user, but still unhappy'); 3401 }, function(reason) { 3402 throw new Error('`findUser` rejected and we're unhappy'); 3403 }).then(function (value) { 3404 // never reached 3405 }, function(reason) { 3406 // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. 3407 // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. 3408 }); 3409 ``` 3410 If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. 3411 3412 ```js 3413 findUser().then(function (user) { 3414 throw new PedagogicalException('Upstream error'); 3415 }).then(function (value) { 3416 // never reached 3417 }).then(function (value) { 3418 // never reached 3419 }, function(reason) { 3420 // The `PedgagocialException` is propagated all the way down to here 3421 }); 3422 ``` 3423 3424 Assimilation 3425 ------------ 3426 3427 Sometimes the value you want to propagate to a downstream promise can only be 3428 retrieved asynchronously. This can be achieved by returning a promise in the 3429 fulfillment or rejection handler. The downstream promise will then be pending 3430 until the returned promise is settled. This is called *assimilation*. 3431 3432 ```js 3433 findUser().then(function (user) { 3434 return findCommentsByAuthor(user); 3435 }).then(function (comments) { 3436 // The user's comments are now available 3437 }); 3438 ``` 3439 3440 If the assimliated promise rejects, then the downstream promise will also reject. 3441 3442 ```js 3443 findUser().then(function (user) { 3444 return findCommentsByAuthor(user); 3445 }).then(function (comments) { 3446 // If `findCommentsByAuthor` fulfills, we'll have the value here 3447 }, function(reason) { 3448 // If `findCommentsByAuthor` rejects, we'll have the reason here 3449 }); 3450 ``` 3451
vendor: 6,630 bytes, lines 3452-3730
3452 Simple Example 3453 -------------- 3454 3455 Synchronous Example 3456 3457 ```javascript 3458 let result; 3459 3460 try { 3461 result = findResult(); 3462 // success 3463 } catch(reason) { 3464 // failure 3465 } 3466 ``` 3467 3468 Errback Example 3469 3470 ```js 3471 findResult(function(result, err) { 3472 if (err) { 3473 // failure 3474 } else { 3475 // success 3476 } 3477 }); 3478 ``` 3479 3480 Promise Example; 3481 3482 ```javascript 3483 findResult().then(function(result) { 3484 // success 3485 }, function(reason) { 3486 // failure 3487 }); 3488 ``` 3489 3490 Advanced Example 3491 -------------- 3492 3493 Synchronous Example 3494 3495 ```javascript 3496 let author, books; 3497 3498 try { 3499 author = findAuthor(); 3500 books = findBooksByAuthor(author); 3501 // success 3502 } catch(reason) { 3503 // failure 3504 } 3505 ``` 3506 3507 Errback Example 3508 3509 ```js 3510 3511 function foundBooks(books) { 3512 3513 } 3514 3515 function failure(reason) { 3516 3517 } 3518 3519 findAuthor(function(author, err) { 3520 if (err) { 3521 failure(err); 3522 // failure 3523 } else { 3524 try { 3525 findBoooksByAuthor(author, function(books, err) { 3526 if (err) { 3527 failure(err); 3528 } else { 3529 try { 3530 foundBooks(books); 3531 } catch(reason) { 3532 failure(reason); 3533 } 3534 } 3535 }); 3536 } catch(error) { 3537 failure(err); 3538 } 3539 // success 3540 } 3541 }); 3542 ``` 3543 3544 Promise Example; 3545 3546 ```javascript 3547 findAuthor(). 3548 then(findBooksByAuthor). 3549 then(function(books) { 3550 // found books 3551 }).catch(function(reason) { 3552 // something went wrong 3553 }); 3554 ``` 3555 3556 @method then 3557 @param {Function} onFulfilled 3558 @param {Function} onRejected 3559 Useful for tooling. 3560 @return {Promise} 3561 */ 3562 then: then, 3563 3564 /** 3565 `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same 3566 as the catch block of a try/catch statement. 3567 3568 ```js 3569 function findAuthor() { 3570 throw new Error('couldn't find that author'); 3571 } 3572 3573 // synchronous 3574 try { 3575 findAuthor(); 3576 } catch(reason) { 3577 // something went wrong 3578 } 3579 3580 // async with promises 3581 findAuthor().catch(function(reason) { 3582 // something went wrong 3583 }); 3584 ``` 3585 3586 @method catch 3587 @param {Function} onRejection 3588 Useful for tooling. 3589 @return {Promise} 3590 */ 3591 'catch': function _catch(onRejection) { 3592 return this.then(null, onRejection); 3593 } 3594 }; 3595 3596 function polyfill() { 3597 var local = undefined; 3598 3599 if (typeof global !== 'undefined') { 3600 local = global; 3601 } else if (typeof self !== 'undefined') { 3602 local = self; 3603 } else { 3604 try { 3605 local = Function('return this')(); 3606 } catch (e) { 3607 throw new Error('polyfill failed because global object is unavailable in this environment'); 3608 } 3609 } 3610 3611 var P = local.Promise; 3612 3613 if (P) { 3614 var promiseToString = null; 3615 try { 3616 promiseToString = Object.prototype.toString.call(P.resolve()); 3617 } catch (e) { 3618 // silently ignored 3619 } 3620 3621 if (promiseToString === '[object Promise]' && !P.cast) { 3622 return; 3623 } 3624 } 3625 3626 local.Promise = Promise; 3627 } 3628 3629 // Strange compat.. 3630 Promise.polyfill = polyfill; 3631 Promise.Promise = Promise; 3632 3633 return Promise; 3634 }); 3635 //# sourceMappingURL=es6-promise.map 3636 3637 /* WEBPACK VAR INJECTION */ 3638 }).call(exports, __webpack_require__(9), __webpack_require__(10)); 3639 3640 /***/ 3641}, 3642/* 9 */ 3643/***/function (module, exports) { 3644 3645 // shim for using process in browser 3646 var process = module.exports = {}; 3647 3648 // cached from whatever global is present so that test runners that stub it 3649 // don't break things. But we need to wrap it in a try catch in case it is 3650 // wrapped in strict mode code which doesn't define any globals. It's inside a 3651 // function because try/catches deoptimize in certain engines. 3652 3653 var cachedSetTimeout; 3654 var cachedClearTimeout; 3655 3656 function defaultSetTimout() { 3657 throw new Error('setTimeout has not been defined'); 3658 } 3659 function defaultClearTimeout() { 3660 throw new Error('clearTimeout has not been defined'); 3661 } 3662 (function () { 3663 try { 3664 if (typeof setTimeout === 'function') { 3665 cachedSetTimeout = setTimeout; 3666 } else { 3667 cachedSetTimeout = defaultSetTimout; 3668 } 3669 } catch (e) { 3670 cachedSetTimeout = defaultSetTimout; 3671 } 3672 try { 3673 if (typeof clearTimeout === 'function') { 3674 cachedClearTimeout = clearTimeout; 3675 } else { 3676 cachedClearTimeout = defaultClearTimeout; 3677 } 3678 } catch (e) { 3679 cachedClearTimeout = defaultClearTimeout; 3680 } 3681 })(); 3682 function runTimeout(fun) { 3683 if (cachedSetTimeout === setTimeout) { 3684 //normal enviroments in sane situations 3685 return setTimeout(fun, 0); 3686 } 3687 // if setTimeout wasn't available but was latter defined 3688 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { 3689 cachedSetTimeout = setTimeout; 3690 return setTimeout(fun, 0); 3691 } 3692 try { 3693 // when when somebody has screwed with setTimeout but no I.E. maddness 3694 return cachedSetTimeout(fun, 0); 3695 } catch (e) { 3696 try { 3697 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally 3698 return cachedSetTimeout.call(null, fun, 0); 3699 } catch (e) { 3700 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error 3701 return cachedSetTimeout.call(this, fun, 0); 3702 } 3703 } 3704 } 3705 function runClearTimeout(marker) { 3706 if (cachedClearTimeout === clearTimeout) { 3707 //normal enviroments in sane situations 3708 return clearTimeout(marker); 3709 } 3710 // if clearTimeout wasn't available but was latter defined 3711 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { 3712 cachedClearTimeout = clearTimeout; 3713 return clearTimeout(marker); 3714 } 3715 try { 3716 // when when somebody has screwed with setTimeout but no I.E. maddness 3717 return cachedClearTimeout(marker); 3718 } catch (e) { 3719 try { 3720 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally 3721 return cachedClearTimeout.call(null, marker); 3722 } catch (e) { 3723 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. 3724 // Some versions of I.E. have different rules for clearTimeout vs setTimeout 3725 return cachedClearTimeout.call(this, marker); 3726 } 3727 } 3728 } 3729 var queue = []; 3730 var draining = false;
vendor: 2,749 bytes, lines 3731-3866
3731 var currentQueue; 3732 var queueIndex = -1; 3733 3734 function cleanUpNextTick() { 3735 if (!draining || !currentQueue) { 3736 return; 3737 } 3738 draining = false; 3739 if (currentQueue.length) { 3740 queue = currentQueue.concat(queue); 3741 } else { 3742 queueIndex = -1; 3743 } 3744 if (queue.length) { 3745 drainQueue(); 3746 } 3747 } 3748 3749 function drainQueue() { 3750 if (draining) { 3751 return; 3752 } 3753 var timeout = runTimeout(cleanUpNextTick); 3754 draining = true; 3755 3756 var len = queue.length; 3757 while (len) { 3758 currentQueue = queue; 3759 queue = []; 3760 while (++queueIndex < len) { 3761 if (currentQueue) { 3762 currentQueue[queueIndex].run(); 3763 } 3764 } 3765 queueIndex = -1; 3766 len = queue.length; 3767 } 3768 currentQueue = null; 3769 draining = false; 3770 runClearTimeout(timeout); 3771 } 3772 3773 process.nextTick = function (fun) { 3774 var args = new Array(arguments.length - 1); 3775 if (arguments.length > 1) { 3776 for (var i = 1; i < arguments.length; i++) { 3777 args[i - 1] = arguments[i]; 3778 } 3779 } 3780 queue.push(new Item(fun, args)); 3781 if (queue.length === 1 && !draining) { 3782 runTimeout(drainQueue); 3783 } 3784 }; 3785 3786 // v8 likes predictible objects 3787 function Item(fun, array) { 3788 this.fun = fun; 3789 this.array = array; 3790 } 3791 Item.prototype.run = function () { 3792 this.fun.apply(null, this.array); 3793 }; 3794 process.title = 'browser'; 3795 process.browser = true; 3796 process.env = {}; 3797 process.argv = []; 3798 process.version = ''; // empty string to avoid regexp issues 3799 process.versions = {}; 3800 3801 function noop() {} 3802 3803 process.on = noop; 3804 process.addListener = noop; 3805 process.once = noop; 3806 process.off = noop; 3807 process.removeListener = noop; 3808 process.removeAllListeners = noop; 3809 process.emit = noop; 3810 process.prependListener = noop; 3811 process.prependOnceListener = noop; 3812 3813 process.listeners = function (name) { 3814 return []; 3815 }; 3816 3817 process.binding = function (name) { 3818 throw new Error('process.binding is not supported'); 3819 }; 3820 3821 process.cwd = function () { 3822 return '/'; 3823 }; 3824 process.chdir = function (dir) { 3825 throw new Error('process.chdir is not supported'); 3826 }; 3827 process.umask = function () { 3828 return 0; 3829 }; 3830 3831 /***/ 3832}, 3833/* 10 */ 3834/***/function (module, exports) { 3835 3836 var g; 3837 3838 // This works in non-strict mode 3839 g = function () { 3840 return this; 3841 }(); 3842 3843 try { 3844 // This works if eval is allowed (see CSP) 3845 g = g || Function("return this")() || (1, eval)("this"); 3846 } catch (e) { 3847 // This works if the window reference is available 3848 if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) === "object") g = window; 3849 } 3850 3851 // g can still be undefined, but nothing to do about it... 3852 // We return undefined, instead of nothing here, so it's 3853 // easier to handle this case. if(!global) { ...} 3854 3855 module.exports = g; 3856 3857 /***/ 3858}, 3859/* 11 */ 3860/***/function (module, exports) { 3861 3862 /* (ignored) */ 3863 3864 /***/}] 3865/******/); 3866//# sourceMappingURL=loader.3.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.