1/* 2 * SystemJS v0.19.27 3 */ 4(function() { 5function bootstrap() {// from https://gist.github.com/Yaffle/1088850 6(function(global) { 7function URLPolyfill(url, baseURL) { 8 if (typeof url != 'string') 9 throw new TypeError('URL must be a string'); 10 var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/); 11 if (!m) 12 throw new RangeError('Invalid URL format'); 13 var protocol = m[1] || ""; 14 var username = m[2] || ""; 15 var password = m[3] || ""; 16 var host = m[4] || ""; 17 var hostname = m[5] || ""; 18 var port = m[6] || ""; 19 var pathname = m[7] || ""; 20 var search = m[8] || ""; 21 var hash = m[9] || ""; 22 if (baseURL !== undefined) { 23 var base = baseURL instanceof URLPolyfill ? baseURL : new URLPolyfill(baseURL); 24 var flag = !protocol && !host && !username; 25 if (flag && !pathname && !search) 26 search = base.search; 27 if (flag && pathname[0] !== "/") 28 pathname = (pathname ? (((base.host || base.username) && !base.pathname ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname); 29 // dot segments removal 30 var output = []; 31 pathname.replace(/^(\.\.?(\/|$))+/, "") 32 .replace(/\/(\.(\/|$))+/g, "/") 33 .replace(/\/\.\.$/, "/../") 34 .replace(/\/?[^\/]*/g, function (p) { 35 if (p === "/..") 36 output.pop(); 37 else 38 output.push(p); 39 }); 40 pathname = output.join("").replace(/^\//, pathname[0] === "/" ? "/" : ""); 41 if (flag) { 42 port = base.port; 43 hostname = base.hostname; 44 host = base.host; 45 password = base.password; 46 username = base.username; 47 } 48 if (!protocol) 49 protocol = base.protocol; 50 } 51 52 // convert windows file URLs to use / 53 if (protocol == 'file:') 54 pathname = pathname.replace(/\\/g, '/'); 55 56 this.origin = host ? protocol + (protocol !== "" || host !== "" ? "//" : "") + host : ""; 57 this.href = protocol + (protocol && host || protocol == "file:" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash; 58 this.protocol = protocol; 59 this.username = username; 60 this.password = password; 61 this.host = host; 62 this.hostname = hostname; 63 this.port = port; 64 this.pathname = pathname; 65 this.search = search; 66 this.hash = hash; 67} 68global.URLPolyfill = URLPolyfill; 69})(typeof self != 'undefined' ? self : global);(function(__global) { 70 71 var isWorker = typeof window == 'undefined' && typeof self != 'undefined' && typeof importScripts != 'undefined'; 72 var isBrowser = typeof window != 'undefined' && typeof document != 'undefined'; 73 var isWindows = typeof process != 'undefined' && typeof process.platform != 'undefined' && !!process.platform.match(/^win/); 74 75 if (!__global.console) 76 __global.console = { assert: function() {} }; 77 78 // IE8 support 79 var indexOf = Array.prototype.indexOf || function(item) { 80 for (var i = 0, thisLen = this.length; i < thisLen; i++) { 81 if (this[i] === item) { 82 return i; 83 } 84 } 85 return -1; 86 }; 87 88 var defineProperty; 89 (function () { 90 try { 91 if (!!Object.defineProperty({}, 'a', {})) 92 defineProperty = Object.defineProperty; 93 } 94 catch (e) { 95 defineProperty = function(obj, prop, opt) { 96 try { 97 obj[prop] = opt.value || opt.get.call(obj); 98 } 99 catch(e) {} 100 } 101 } 102 })(); 103 104 var errArgs = new Error(0, '_').fileName == '_'; 105 106 function addToError(err, msg) { 107 // parse the stack removing loader code lines for simplification 108 if (!err.originalErr) { 109 var stack = (err.stack || err.message || err).split('\n'); 110 var newStack = []; 111 for (var i = 0; i < stack.length; i++) { 112 if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1) 113 newStack.push(stack[i]); 114 } 115 } 116 117 var newMsg = (newStack ? newStack.join('\n\t') : err.message) + '\n\t' + msg; 118 119 // Convert file:/// URLs to paths in Node 120 if (!isBrowser) 121 newMsg = newMsg.replace(isWindows ? /file:\/\/\//g : /file:\/\//g, ''); 122 123 var newErr = errArgs ? new Error(newMsg, err.fileName, err.lineNumber) : new Error(newMsg); 124 125 // Node needs stack adjustment for throw to show message 126 if (!isBrowser) 127 newErr.stack = newMsg; 128 // Clearing the stack stops unnecessary loader lines showing 129 else 130 newErr.stack = null; 131 132 // track the original error 133 newErr.originalErr = err.originalErr || err; 134 135 return newErr; 136 } 137 138 function __eval(source, debugName, context) { 139 try { 140 new Function(source).call(context); 141 } 142 catch(e) {
143 throw addToError(e, 'Evaluating ' + debugName); 144 } 145 } 146 147 var baseURI; 148 // environent baseURI detection 149 if (typeof document != 'undefined' && document.getElementsByTagName) { 150 baseURI = document.baseURI; 151 152 if (!baseURI) { 153 var bases = document.getElementsByTagName('base'); 154 baseURI = bases[0] && bases[0].href || window.location.href; 155 } 156 157 // sanitize out the hash and querystring 158 baseURI = baseURI.split('#')[0].split('?')[0]; 159 baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1); 160 } 161 else if (typeof process != 'undefined' && process.cwd) { 162 baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/'; 163 if (isWindows) 164 baseURI = baseURI.replace(/\\/g, '/'); 165 } 166 else if (typeof location != 'undefined') { 167 baseURI = __global.location.href; 168 } 169 else { 170 throw new TypeError('No environment baseURI'); 171 } 172 173 try { 174 var nativeURL = new __global.URL('test:///').protocol == 'test:'; 175 } 176 catch(e) {} 177 178 var URL = nativeURL ? __global.URL : __global.URLPolyfill; 179/* 180********************************************************************************************* 181 182 Dynamic Module Loader Polyfill 183 184 - Implemented exactly to the former 2014-08-24 ES6 Specification Draft Rev 27, Section 15 185 http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#august_24_2014_draft_rev_27 186 187 - Functions are commented with their spec numbers, with spec differences commented. 188 189 - Spec bugs are commented in this code with links. 190 191 - Abstract functions have been combined where possible, and their associated functions 192 commented. 193 194 - Realm implementation is entirely omitted. 195 196********************************************************************************************* 197*/ 198 199function Module() {} 200// http://www.ecma-international.org/ecma-262/6.0/#sec-@@tostringtag 201defineProperty(Module.prototype, 'toString', { 202 value: function() { 203 return 'Module'; 204 } 205}); 206function Loader(options) { 207 this._loader = { 208 loaderObj: this, 209 loads: [], 210 modules: {}, 211 importPromises: {}, 212 moduleRecords: {} 213 }; 214 215 // 26.3.3.6 216 defineProperty(this, 'global', { 217 get: function() { 218 return __global; 219 } 220 }); 221 222 // 26.3.3.13 realm not implemented 223} 224 225(function() { 226 227// Some Helpers 228 229// logs a linkset snapshot for debugging 230/* function snapshot(loader) { 231 console.log('---Snapshot---'); 232 for (var i = 0; i < loader.loads.length; i++) { 233 var load = loader.loads[i]; 234 var linkSetLog = ' ' + load.name + ' (' + load.status + '): '; 235 236 for (var j = 0; j < load.linkSets.length; j++) { 237 linkSetLog += '{' + logloads(load.linkSets[j].loads) + '} '; 238 } 239 console.log(linkSetLog); 240 } 241 console.log(''); 242} 243function logloads(loads) { 244 var log = ''; 245 for (var k = 0; k < loads.length; k++) 246 log += loads[k].name + (k != loads.length - 1 ? ' ' : ''); 247 return log; 248} */ 249 250 251/* function checkInvariants() { 252 // see https://bugs.ecmascript.org/show_bug.cgi?id=2603#c1 253 254 var loads = System._loader.loads; 255 var linkSets = []; 256 257 for (var i = 0; i < loads.length; i++) { 258 var load = loads[i]; 259 console.assert(load.status == 'loading' || load.status == 'loaded', 'Each load is loading or loaded'); 260 261 for (var j = 0; j < load.linkSets.length; j++) { 262 var linkSet = load.linkSets[j]; 263 264 for (var k = 0; k < linkSet.loads.length; k++) 265 console.assert(loads.indexOf(linkSet.loads[k]) != -1, 'linkSet loads are a subset of loader loads'); 266 267 if (linkSets.indexOf(linkSet) == -1) 268 linkSets.push(linkSet); 269 } 270 } 271 272 for (var i = 0; i < loads.length; i++) { 273 var load = loads[i]; 274 for (var j = 0; j < linkSets.length; j++) { 275 var linkSet = linkSets[j]; 276 277 if (linkSet.loads.indexOf(load) != -1) 278 console.assert(load.linkSets.indexOf(linkSet) != -1, 'linkSet contains load -> load contains linkSet'); 279 280 if (load.linkSets.indexOf(linkSet) != -1) 281 console.assert(linkSet.loads.indexOf(load) != -1, 'load contains linkSet -> linkSet contains load'); 282 } 283 } 284 285 for (var i = 0; i < linkSets.length; i++) { 286 var linkSet = linkSets[i]; 287 for (var j = 0; j < linkSet.loads.length; j++) { 288 var load = linkSet.loads[j]; 289 290 for (var k = 0; k < load.dependencies.length; k++) { 291 var depName = load.dependencies[k].value; 292 var depLoad; 293 for (var l = 0; l < loads.length; l++) { 294 if (loads[l].name != depName) 295 continue; 296 depLoad = loads[l]; 297 break; 298 } 299 300 // loading records are allowed not to have their dependencies yet 301 // if (load.status != 'loading') 302 // console.assert(depLoad, 'depLoad found'); 303 304 // console.assert(linkSet.loads.indexOf(depLoad) != -1, 'linkset contains all dependencies'); 305 } 306 } 307 } 308} */ 309 310 // 15.2.3 - Runtime Semantics: Loader State 311 312 // 15.2.3.11 313 function createLoaderLoad(object) { 314 return { 315 // modules is an object for ES5 implementation 316 modules: {}, 317 loads: [], 318 loaderObj: object 319 }; 320 } 321 322 // 15.2.3.2 Load Records and LoadRequest Objects 323 324 // 15.2.3.2.1 325 function createLoad(name) { 326 return { 327 status: 'loading', 328 name: name, 329 linkSets: [], 330 dependencies: [], 331 metadata: {} 332 }; 333 } 334 335 // 15.2.3.2.2 createLoadRequestObject, absorbed into calling functions 336 337 // 15.2.4 338 339 // 15.2.4.1 340 function loadModule(loader, name, options) { 341 return new Promise(asyncStartLoadPartwayThrough({ 342 step: options.address ? 'fetch' : 'locate', 343 loader: loader, 344 moduleName: name, 345 // allow metadata for import https://bugs.ecmascript.org/show_bug.cgi?id=3091 346 moduleMetadata: options && options.metadata || {}, 347 moduleSource: options.source, 348 moduleAddress: options.address 349 })); 350 } 351 352 // 15.2.4.2 353 function requestLoad(loader, request, refererName, refererAddress) { 354 // 15.2.4.2.1 CallNormalize 355 return new Promise(function(resolve, reject) { 356 resolve(loader.loaderObj.normalize(request, refererName, refererAddress)); 357 }) 358 // 15.2.4.2.2 GetOrCreateLoad 359 .then(function(name) { 360 var load; 361 if (loader.modules[name]) { 362 load = createLoad(name); 363 load.status = 'linked'; 364 // https://bugs.ecmascript.org/show_bug.cgi?id=2795 365 load.module = loader.modules[name]; 366 return load; 367 } 368 369 for (var i = 0, l = loader.loads.length; i < l; i++) { 370 load = loader.loads[i]; 371 if (load.name != name) 372 continue; 373 console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded'); 374 return load; 375 } 376 377 load = createLoad(name); 378 loader.loads.push(load); 379 380 proceedToLocate(loader, load); 381 382 return load; 383 }); 384 } 385 386 // 15.2.4.3 387 function proceedToLocate(loader, load) { 388 proceedToFetch(loader, load, 389 Promise.resolve() 390 // 15.2.4.3.1 CallLocate 391 .then(function() { 392 return loader.loaderObj.locate({ name: load.name, metadata: load.metadata }); 393 }) 394 ); 395 } 396 397 // 15.2.4.4 398 function proceedToFetch(loader, load, p) { 399 proceedToTranslate(loader, load, 400 p 401 // 15.2.4.4.1 CallFetch 402 .then(function(address) { 403 // adjusted, see https://bugs.ecmascript.org/show_bug.cgi?id=2602 404 if (load.status != 'loading') 405 return; 406 load.address = address; 407 408 return loader.loaderObj.fetch({ name: load.name, metadata: load.metadata, address: address }); 409 }) 410 ); 411 } 412 413 var anonCnt = 0; 414 415 // 15.2.4.5 416 function proceedToTranslate(loader, load, p) { 417 p 418 // 15.2.4.5.1 CallTranslate 419 .then(function(source) { 420 if (load.status != 'loading') 421 return; 422 423 return Promise.resolve(loader.loaderObj.translate({ name: load.name, metadata: load.metadata, address: load.address, source: source })) 424 425 // 15.2.4.5.2 CallInstantiate 426 .then(function(source) { 427 load.source = source; 428 return loader.loaderObj.instantiate({ name: load.name, metadata: load.metadata, address: load.address, source: source }); 429 }) 430 431 // 15.2.4.5.3 InstantiateSucceeded 432 .then(function(instantiateResult) { 433 if (instantiateResult === undefined) { 434 load.address = load.address || '<Anonymous Module ' + ++anonCnt + '>'; 435 436 // instead of load.kind, use load.isDeclarative 437 load.isDeclarative = true;
438 return transpile.call(loader.loaderObj, load) 439 .then(function(transpiled) { 440 // Hijack System.register to set declare function 441 var curSystem = __global.System; 442 var curRegister = curSystem.register; 443 curSystem.register = function(name, deps, declare) { 444 if (typeof name != 'string') { 445 declare = deps; 446 deps = name; 447 } 448 // store the registered declaration as load.declare 449 // store the deps as load.deps 450 load.declare = declare; 451 load.depsList = deps; 452 } 453 // empty {} context is closest to undefined 'this' we can get 454 __eval(transpiled, load.address, {}); 455 curSystem.register = curRegister; 456 }); 457 } 458 else if (typeof instantiateResult == 'object') { 459 load.depsList = instantiateResult.deps || []; 460 load.execute = instantiateResult.execute; 461 load.isDeclarative = false; 462 } 463 else 464 throw TypeError('Invalid instantiate return value'); 465 }) 466 // 15.2.4.6 ProcessLoadDependencies 467 .then(function() { 468 load.dependencies = []; 469 var depsList = load.depsList; 470 471 var loadPromises = []; 472 for (var i = 0, l = depsList.length; i < l; i++) (function(request, index) { 473 loadPromises.push( 474 requestLoad(loader, request, load.name, load.address) 475 476 // 15.2.4.6.1 AddDependencyLoad (load is parentLoad) 477 .then(function(depLoad) { 478 479 // adjusted from spec to maintain dependency order 480 // this is due to the System.register internal implementation needs 481 load.dependencies[index] = { 482 key: request, 483 value: depLoad.name 484 }; 485 486 if (depLoad.status != 'linked') { 487 var linkSets = load.linkSets.concat([]); 488 for (var i = 0, l = linkSets.length; i < l; i++) 489 addLoadToLinkSet(linkSets[i], depLoad); 490 } 491 492 // console.log('AddDependencyLoad ' + depLoad.name + ' for ' + load.name); 493 // snapshot(loader); 494 }) 495 ); 496 })(depsList[i], i); 497 498 return Promise.all(loadPromises); 499 }) 500 501 // 15.2.4.6.2 LoadSucceeded 502 .then(function() { 503 // console.log('LoadSucceeded ' + load.name); 504 // snapshot(loader); 505 506 console.assert(load.status == 'loading', 'is loading'); 507 508 load.status = 'loaded'; 509 510 var linkSets = load.linkSets.concat([]); 511 for (var i = 0, l = linkSets.length; i < l; i++) 512 updateLinkSetOnLoad(linkSets[i], load); 513 }); 514 }) 515 // 15.2.4.5.4 LoadFailed 516 ['catch'](function(exc) { 517 load.status = 'failed'; 518 load.exception = exc; 519 520 var linkSets = load.linkSets.concat([]); 521 for (var i = 0, l = linkSets.length; i < l; i++) { 522 linkSetFailed(linkSets[i], load, exc); 523 } 524 525 console.assert(load.linkSets.length == 0, 'linkSets not removed'); 526 }); 527 } 528 529 // 15.2.4.7 PromiseOfStartLoadPartwayThrough absorbed into calling functions 530 531 // 15.2.4.7.1 532 function asyncStartLoadPartwayThrough(stepState) { 533 return function(resolve, reject) { 534 var loader = stepState.loader; 535 var name = stepState.moduleName; 536 var step = stepState.step; 537 538 if (loader.modules[name]) 539 throw new TypeError('"' + name + '" already exists in the module table'); 540 541 // adjusted to pick up existing loads 542 var existingLoad; 543 for (var i = 0, l = loader.loads.length; i < l; i++) { 544 if (loader.loads[i].name == name) { 545 existingLoad = loader.loads[i]; 546 547 if (step == 'translate' && !existingLoad.source) { 548 existingLoad.address = stepState.moduleAddress; 549 proceedToTranslate(loader, existingLoad, Promise.resolve(stepState.moduleSource)); 550 } 551 552 // a primary load -> use that existing linkset if it is for the direct load here 553 // otherwise create a new linkset unit 554 if (existingLoad.linkSets.length && existingLoad.linkSets[0].loads[0].name == existingLoad.name) 555 return existingLoad.linkSets[0].done.then(function() { 556 resolve(existingLoad); 557 }); 558 } 559 } 560 561 var load = existingLoad || createLoad(name); 562 563 load.metadata = stepState.moduleMetadata; 564 565 var linkSet = createLinkSet(loader, load); 566 567 loader.loads.push(load); 568 569 resolve(linkSet.done); 570 571 if (step == 'locate') 572 proceedToLocate(loader, load); 573 574 else if (step == 'fetch') 575 proceedToFetch(loader, load, Promise.resolve(stepState.moduleAddress)); 576 577 else { 578 console.assert(step == 'translate', 'translate step'); 579 load.address = stepState.moduleAddress; 580 proceedToTranslate(loader, load, Promise.resolve(stepState.moduleSource)); 581 } 582 } 583 } 584 585 // Declarative linking functions run through alternative implementation: 586 // 15.2.5.1.1 CreateModuleLinkageRecord not implemented 587 // 15.2.5.1.2 LookupExport not implemented 588 // 15.2.5.1.3 LookupModuleDependency not implemented 589 590 // 15.2.5.2.1 591 function createLinkSet(loader, startingLoad) { 592 var linkSet = { 593 loader: loader, 594 loads: [], 595 startingLoad: startingLoad, // added see spec bug https://bugs.ecmascript.org/show_bug.cgi?id=2995 596 loadingCount: 0 597 }; 598 linkSet.done = new Promise(function(resolve, reject) { 599 linkSet.resolve = resolve; 600 linkSet.reject = reject; 601 }); 602 addLoadToLinkSet(linkSet, startingLoad); 603 return linkSet; 604 } 605 // 15.2.5.2.2 606 function addLoadToLinkSet(linkSet, load) { 607 if (load.status == 'failed') 608 return; 609 610 console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded on link set'); 611 612 for (var i = 0, l = linkSet.loads.length; i < l; i++) 613 if (linkSet.loads[i] == load) 614 return; 615 616 linkSet.loads.push(load); 617 load.linkSets.push(linkSet); 618 619 // adjustment, see https://bugs.ecmascript.org/show_bug.cgi?id=2603 620 if (load.status != 'loaded') { 621 linkSet.loadingCount++; 622 } 623 624 var loader = linkSet.loader; 625 626 for (var i = 0, l = load.dependencies.length; i < l; i++) { 627 if (!load.dependencies[i]) 628 continue; 629 630 var name = load.dependencies[i].value; 631 632 if (loader.modules[name]) 633 continue; 634 635 for (var j = 0, d = loader.loads.length; j < d; j++) { 636 if (loader.loads[j].name != name) 637 continue; 638 639 addLoadToLinkSet(linkSet, loader.loads[j]); 640 break; 641 } 642 } 643 // console.log('add to linkset ' + load.name); 644 // snapshot(linkSet.loader); 645 } 646 647 // linking errors can be generic or load-specific 648 // this is necessary for debugging info 649 function doLink(linkSet) { 650 var error = false;
651 try { 652 link(linkSet, function(load, exc) { 653 linkSetFailed(linkSet, load, exc); 654 error = true; 655 }); 656 } 657 catch(e) { 658 linkSetFailed(linkSet, null, e); 659 error = true; 660 } 661 return error; 662 } 663 664 // 15.2.5.2.3 665 function updateLinkSetOnLoad(linkSet, load) { 666 // console.log('update linkset on load ' + load.name); 667 // snapshot(linkSet.loader); 668 669 console.assert(load.status == 'loaded' || load.status == 'linked', 'loaded or linked'); 670 671 linkSet.loadingCount--; 672 673 if (linkSet.loadingCount > 0) 674 return; 675 676 // adjusted for spec bug https://bugs.ecmascript.org/show_bug.cgi?id=2995 677 var startingLoad = linkSet.startingLoad; 678 679 // non-executing link variation for loader tracing 680 // on the server. Not in spec. 681 /***/ 682 if (linkSet.loader.loaderObj.execute === false) { 683 var loads = [].concat(linkSet.loads); 684 for (var i = 0, l = loads.length; i < l; i++) { 685 var load = loads[i]; 686 load.module = !load.isDeclarative ? { 687 module: _newModule({}) 688 } : { 689 name: load.name, 690 module: _newModule({}), 691 evaluated: true 692 }; 693 load.status = 'linked'; 694 finishLoad(linkSet.loader, load); 695 } 696 return linkSet.resolve(startingLoad); 697 } 698 /***/ 699 700 var abrupt = doLink(linkSet); 701 702 if (abrupt) 703 return; 704 705 console.assert(linkSet.loads.length == 0, 'loads cleared'); 706 707 linkSet.resolve(startingLoad); 708 } 709 710 // 15.2.5.2.4 711 function linkSetFailed(linkSet, load, exc) { 712 var loader = linkSet.loader; 713 var requests; 714 715 checkError: 716 if (load) { 717 if (linkSet.loads[0].name == load.name) { 718 exc = addToError(exc, 'Error loading ' + load.name); 719 } 720 else { 721 for (var i = 0; i < linkSet.loads.length; i++) { 722 var pLoad = linkSet.loads[i]; 723 for (var j = 0; j < pLoad.dependencies.length; j++) { 724 var dep = pLoad.dependencies[j]; 725 if (dep.value == load.name) { 726 exc = addToError(exc, 'Error loading ' + load.name + ' as "' + dep.key + '" from ' + pLoad.name); 727 break checkError; 728 } 729 } 730 } 731 exc = addToError(exc, 'Error loading ' + load.name + ' from ' + linkSet.loads[0].name); 732 } 733 } 734 else { 735 exc = addToError(exc, 'Error linking ' + linkSet.loads[0].name); 736 } 737 738 739 var loads = linkSet.loads.concat([]); 740 for (var i = 0, l = loads.length; i < l; i++) { 741 var load = loads[i]; 742 743 // store all failed load records 744 loader.loaderObj.failed = loader.loaderObj.failed || []; 745 if (indexOf.call(loader.loaderObj.failed, load) == -1) 746 loader.loaderObj.failed.push(load); 747 748 var linkIndex = indexOf.call(load.linkSets, linkSet); 749 console.assert(linkIndex != -1, 'link not present'); 750 load.linkSets.splice(linkIndex, 1); 751 if (load.linkSets.length == 0) { 752 var globalLoadsIndex = indexOf.call(linkSet.loader.loads, load); 753 if (globalLoadsIndex != -1) 754 linkSet.loader.loads.splice(globalLoadsIndex, 1); 755 } 756 } 757 linkSet.reject(exc); 758 } 759 760 // 15.2.5.2.5 761 function finishLoad(loader, load) { 762 // add to global trace if tracing 763 if (loader.loaderObj.trace) { 764 if (!loader.loaderObj.loads) 765 loader.loaderObj.loads = {}; 766 var depMap = {}; 767 load.dependencies.forEach(function(dep) { 768 depMap[dep.key] = dep.value; 769 }); 770 loader.loaderObj.loads[load.name] = { 771 name: load.name, 772 deps: load.dependencies.map(function(dep){ return dep.key }), 773 depMap: depMap, 774 address: load.address, 775 metadata: load.metadata, 776 source: load.source, 777 kind: load.isDeclarative ? 'declarative' : 'dynamic' 778 }; 779 } 780 // if not anonymous, add to the module table 781 if (load.name) { 782 console.assert(!loader.modules[load.name], 'load not in module table'); 783 loader.modules[load.name] = load.module; 784 } 785 var loadIndex = indexOf.call(loader.loads, load); 786 if (loadIndex != -1) 787 loader.loads.splice(loadIndex, 1); 788 for (var i = 0, l = load.linkSets.length; i < l; i++) { 789 loadIndex = indexOf.call(load.linkSets[i].loads, load); 790 if (loadIndex != -1) 791 load.linkSets[i].loads.splice(loadIndex, 1); 792 } 793 load.linkSets.splice(0, load.linkSets.length); 794 } 795 796 function doDynamicExecute(linkSet, load, linkError) { 797 try { 798 var module = load.execute(); 799 } 800 catch(e) { 801 linkError(load, e); 802 return; 803 } 804 if (!module || !(module instanceof Module)) 805 linkError(load, new TypeError('Execution must define a Module instance')); 806 else 807 return module; 808 } 809 810 // 26.3 Loader 811 812 // 26.3.1.1 813 // defined at top 814 815 // importPromises adds ability to import a module twice without error - https://bugs.ecmascript.org/show_bug.cgi?id=2601 816 function createImportPromise(loader, name, promise) { 817 var importPromises = loader._loader.importPromises; 818 return importPromises[name] = promise.then(function(m) { 819 importPromises[name] = undefined; 820 return m; 821 }, function(e) { 822 importPromises[name] = undefined; 823 throw e; 824 }); 825 } 826 827 Loader.prototype = { 828 // 26.3.3.1 829 constructor: Loader, 830 // 26.3.3.2 831 define: function(name, source, options) { 832 // check if already defined 833 if (this._loader.importPromises[name]) 834 throw new TypeError('Module is already loading.'); 835 return createImportPromise(this, name, new Promise(asyncStartLoadPartwayThrough({ 836 step: 'translate', 837 loader: this._loader, 838 moduleName: name, 839 moduleMetadata: options && options.metadata || {}, 840 moduleSource: source, 841 moduleAddress: options && options.address 842 }))); 843 }, 844 // 26.3.3.3 845 'delete': function(name) { 846 var loader = this._loader; 847 delete loader.importPromises[name]; 848 delete loader.moduleRecords[name]; 849 return loader.modules[name] ? delete loader.modules[name] : false;
850 }, 851 // 26.3.3.4 entries not implemented 852 // 26.3.3.5 853 get: function(key) { 854 if (!this._loader.modules[key]) 855 return; 856 doEnsureEvaluated(this._loader.modules[key], [], this); 857 return this._loader.modules[key].module; 858 }, 859 // 26.3.3.7 860 has: function(name) { 861 return !!this._loader.modules[name]; 862 }, 863 // 26.3.3.8 864 'import': function(name, parentName, parentAddress) { 865 if (typeof parentName == 'object') 866 parentName = parentName.name; 867 868 // run normalize first 869 var loaderObj = this; 870 871 // added, see https://bugs.ecmascript.org/show_bug.cgi?id=2659 872 return Promise.resolve(loaderObj.normalize(name, parentName)) 873 .then(function(name) { 874 var loader = loaderObj._loader; 875 876 if (loader.modules[name]) { 877 doEnsureEvaluated(loader.modules[name], [], loader._loader); 878 return loader.modules[name].module; 879 } 880 881 return loader.importPromises[name] || createImportPromise(loaderObj, name, 882 loadModule(loader, name, {}) 883 .then(function(load) { 884 delete loader.importPromises[name]; 885 return evaluateLoadedModule(loader, load); 886 })); 887 }); 888 }, 889 // 26.3.3.9 keys not implemented 890 // 26.3.3.10 891 load: function(name) { 892 var loader = this._loader; 893 if (loader.modules[name]) 894 return Promise.resolve(); 895 return loader.importPromises[name] || createImportPromise(this, name, new Promise(asyncStartLoadPartwayThrough({ 896 step: 'locate', 897 loader: loader, 898 moduleName: name, 899 moduleMetadata: {}, 900 moduleSource: undefined, 901 moduleAddress: undefined 902 })) 903 .then(function() { 904 delete loader.importPromises[name]; 905 })); 906 }, 907 // 26.3.3.11 908 module: function(source, options) { 909 var load = createLoad(); 910 load.address = options && options.address; 911 var linkSet = createLinkSet(this._loader, load); 912 var sourcePromise = Promise.resolve(source); 913 var loader = this._loader; 914 var p = linkSet.done.then(function() { 915 return evaluateLoadedModule(loader, load); 916 }); 917 proceedToTranslate(loader, load, sourcePromise); 918 return p; 919 }, 920 // 26.3.3.12 921 newModule: function (obj) { 922 if (typeof obj != 'object') 923 throw new TypeError('Expected object'); 924 925 var m = new Module(); 926 927 var pNames = []; 928 if (Object.getOwnPropertyNames && obj != null) 929 pNames = Object.getOwnPropertyNames(obj); 930 else 931 for (var key in obj) 932 pNames.push(key); 933 934 for (var i = 0; i < pNames.length; i++) (function(key) { 935 defineProperty(m, key, { 936 configurable: false, 937 enumerable: true, 938 get: function () { 939 return obj[key]; 940 }, 941 set: function() { 942 throw new Error('Module exports cannot be changed externally.'); 943 } 944 }); 945 })(pNames[i]); 946 947 if (Object.freeze) 948 Object.freeze(m); 949 950 return m; 951 }, 952 // 26.3.3.14 953 set: function(name, module) { 954 if (!(module instanceof Module)) 955 throw new TypeError('Loader.set(' + name + ', module) must be a module'); 956 this._loader.modules[name] = { 957 module: module 958 }; 959 }, 960 // 26.3.3.15 values not implemented 961 // 26.3.3.16 @@iterator not implemented 962 // 26.3.3.17 @@toStringTag not implemented 963 964 // 26.3.3.18.1 965 normalize: function(name, referrerName, referrerAddress) { 966 return name; 967 }, 968 // 26.3.3.18.2 969 locate: function(load) { 970 return load.name; 971 }, 972 // 26.3.3.18.3 973 fetch: function(load) { 974 }, 975 // 26.3.3.18.4 976 translate: function(load) { 977 return load.source; 978 }, 979 // 26.3.3.18.5 980 instantiate: function(load) { 981 } 982 }; 983 984 var _newModule = Loader.prototype.newModule; 985/* 986 * ES6 Module Declarative Linking Code - Dev Build Only 987 */ 988 function link(linkSet, linkError) { 989 990 var loader = linkSet.loader; 991 992 if (!linkSet.loads.length) 993 return; 994 995 var loads = linkSet.loads.concat([]); 996 997 for (var i = 0; i < loads.length; i++) { 998 var load = loads[i]; 999 1000 var module = doDynamicExecute(linkSet, load, linkError); 1001 if (!module) 1002 return; 1003 load.module = { 1004 name: load.name, 1005 module: module 1006 }; 1007 load.status = 'linked'; 1008 1009 finishLoad(loader, load); 1010 } 1011 } 1012 1013 function evaluateLoadedModule(loader, load) { 1014 console.assert(load.status == 'linked', 'is linked ' + load.name); 1015 return load.module.module; 1016 } 1017 1018 function doEnsureEvaluated() {} 1019 1020 function transpile() { 1021 throw new TypeError('ES6 transpilation is only provided in the dev module loader build.'); 1022 } 1023})();/* 1024********************************************************************************************* 1025 1026 System Loader Implementation 1027 1028 - Implemented to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js 1029 1030 - <script type="module"> supported 1031 1032********************************************************************************************* 1033*/ 1034 1035var System; 1036 1037function SystemLoader() { 1038 Loader.call(this); 1039 this.paths = {}; 1040} 1041 1042// NB no specification provided for System.paths, used ideas discu
1042ssed in https://github.com/jorendorff/js-loaders/issues/25 1043function applyPaths(paths, name) { 1044 // most specific (most number of slashes in path) match wins 1045 var pathMatch = '', wildcard, maxWildcardPrefixLen = 0; 1046 1047 // check to see if we have a paths entry 1048 for (var p in paths) { 1049 var pathParts = p.split('*'); 1050 if (pathParts.length > 2) 1051 throw new TypeError('Only one wildcard in a path is permitted'); 1052 1053 // exact path match 1054 if (pathParts.length == 1) { 1055 if (name == p) 1056 return paths[p]; 1057 1058 // support trailing / in paths rules 1059 else if (name.substr(0, p.length - 1) == p.substr(0, p.length - 1) && (name.length < p.length || name[p.length - 1] == p[p.length - 1]) && paths[p][paths[p].length - 1] == '/') 1060 return paths[p].substr(0, paths[p].length - 1) + (name.length > p.length ? '/' + name.substr(p.length) : ''); 1061 } 1062 // wildcard path match 1063 else { 1064 var wildcardPrefixLen = pathParts[0].length; 1065 if (wildcardPrefixLen >= maxWildcardPrefixLen && 1066 name.substr(0, pathParts[0].length) == pathParts[0] && 1067 name.substr(name.length - pathParts[1].length) == pathParts[1]) { 1068 maxWildcardPrefixLen = wildcardPrefixLen; 1069 pathMatch = p; 1070 wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length); 1071 } 1072 } 1073 } 1074 1075 var outPath = paths[pathMatch]; 1076 if (typeof wildcard == 'string') 1077 outPath = outPath.replace('*', wildcard); 1078 1079 return outPath; 1080} 1081 1082// inline Object.create-style class extension 1083function LoaderProto() {} 1084LoaderProto.prototype = Loader.prototype; 1085SystemLoader.prototype = new LoaderProto(); 1086 var fetchTextFromURL; 1087 if (typeof XMLHttpRequest != 'undefined') { 1088 fetchTextFromURL = function(url, authorization, fulfill, reject) { 1089 var xhr = new XMLHttpRequest(); 1090 var sameDomain = true; 1091 var doTimeout = false; 1092 if (!('withCredentials' in xhr)) { 1093 // check if same domain 1094 var domainCheck = /^(\w+:)?\/\/([^\/]+)/.exec(url); 1095 if (domainCheck) { 1096 sameDomain = domainCheck[2] === window.location.host; 1097 if (domainCheck[1]) 1098 sameDomain &= domainCheck[1] === window.location.protocol; 1099 } 1100 } 1101 if (!sameDomain && typeof XDomainRequest != 'undefined') { 1102 xhr = new XDomainRequest(); 1103 xhr.onload = load; 1104 xhr.onerror = error; 1105 xhr.ontimeout = error; 1106 xhr.onprogress = function() {}; 1107 xhr.timeout = 0; 1108 doTimeout = true; 1109 } 1110 function load() { 1111 fulfill(xhr.responseText); 1112 } 1113 function error() { 1114 reject(new Error('XHR error' + (xhr.status ? ' (' + xhr.status + (xhr.statusText ? ' ' + xhr.statusText : '') + ')' : '') + ' loading ' + url)); 1115 } 1116 1117 xhr.onreadystatechange = function () { 1118 if (xhr.readyState === 4) { 1119 // in Chrome on file:/// URLs, status is 0 1120 if (xhr.status == 0) { 1121 if (xhr.responseText) { 1122 load(); 1123 } 1124 else { 1125 // when responseText is empty, wait for load or error event 1126 // to inform if it is a 404 or empty file 1127 xhr.addEventListener('error', error); 1128 xhr.addEventListener('load', load); 1129 } 1130 } 1131 else if (xhr.status === 200) { 1132 load(); 1133 } 1134 else { 1135 error(); 1136 } 1137 } 1138 }; 1139 xhr.open("GET", url, true); 1140 1141 if (xhr.setRequestHeader) { 1142 xhr.setRequestHeader('Accept', 'application/x-es-module, */*'); 1143 // can set "authorization: true" to enable withCredentials only 1144 if (authorization) { 1145 if (typeof authorization == 'string') 1146 xhr.setRequestHeader('Authorization', authorization); 1147 xhr.withCredentials = true; 1148 } 1149 } 1150 1151 if (doTimeout) { 1152 setTimeout(function() { 1153 xhr.send(); 1154 }, 0); 1155 } else { 1156 xhr.send(null); 1157 } 1158 }; 1159 } 1160 else if (typeof require != 'undefined' && typeof process != 'undefined') { 1161 var fs; 1162 fetchTextFromURL = function(url, authorization, fulfill, reject) { 1163 if (url.substr(0, 8) != 'file:///') 1164 throw new Error('Unable to fetch "' + url + '". Only file URLs of the form file:/// allowed running in Node.'); 1165 fs = fs || require('fs'); 1166 if (isWindows) 1167 url = url.replace(/\//g, '\\').substr(8); 1168 else 1169 url = url.substr(7); 1170 return fs.readFile(url, function(err, data) { 1171 if (err) { 1172 return reject(err); 1173 } 1174 else { 1175 // Strip Byte Order Mark out if it's the leading char 1176 var dataString = data + ''; 1177 if (dataString[0] === '\ufeff') 1178 dataString = dataString.substr(1); 1179 1180 fulfill(dataString); 1181 } 1182 }); 1183 }; 1184 } 1185 else if (typeof self != 'undefined' && typeof self.fetch != 'undefined') { 1186 fetchTextFromURL = function(url, authorization, fulfill, reject) { 1187 var opts = { 1188 headers: {'Accept': 'application/x-es-module, */*'} 1189 }; 1190 1191 if (authorization) { 1192 if (typeof authorization == 'string') 1193 opts.headers['Authorization'] = authorization; 1194 opts.credentials = 'include'; 1195 } 1196 1197 fetch(url, opts) 1198 .then(function (r) { 1199 if (r.ok) { 1200 return r.text(); 1201 } else { 1202 throw new Error('Fetch error: ' + r.status + ' ' + r.statusText); 1203 } 1204 }) 1205 .then(fulfill, reject); 1206 } 1207 } 1208 else { 1209 throw new TypeError('No environment fetch API available.'); 1210 } 1211 1212 SystemLoader.prototype.fetch = function(load) { 1213 return new Promise(function(resolve, reject) { 1214 fetchTextFromURL(load.address, undefined, resolve, reject); 1215 }); 1216 }; 1217/* 1218 * Traceur, Babel and TypeScript transpile hook for Loader 1219 */ 1220var transpile = (function() { 1221 1222 // use Traceur by default 1223 Loader.prototype.transpiler = 'traceur'; 1224 1225 function transpile(load) { 1226 var self = this; 1227 1228 return Promise.resolve(__global[self.transpiler == 'typescript' ? 'ts' : self.transpiler] 1229 || (self.pluginLoader || self)['import'](self.transpiler)) 1230 .then(function(transpiler) { 1231 if (transpiler.__useDefault) 1232 transpiler = transpiler['default']; 1233 1234 var transpileFunction; 1235 if (transpiler.Compiler) 1236 transpileFunction = traceurTranspile; 1237 else if (transpiler.createLanguageService) 1238 transpileFunction = typescriptTranspile; 1239 else 1240 transpileFunction = babelTranspile; 1241 1242 // note __moduleName will be part of the transformer meta in future when we have the spec for this 1243 return '(function(__moduleName){' + transpileFunction.call(self, load, transpiler) + '\n})("' + load.name + '");\n//# sourceURL=' + load.address + '!transpiled'; 1244 }); 1245 }; 1246 1247 function traceurTranspile(load, traceur) { 1248 var options = this.traceurOptions || {}; 1249 options.modules = 'instantiate'; 1250 options.script = false;
1251 if (options.sourceMaps === undefined) 1252 options.sourceMaps = 'inline'; 1253 options.filename = load.address; 1254 options.inputSourceMap = load.metadata.sourceMap; 1255 options.moduleName = false; 1256 1257 var compiler = new traceur.Compiler(options); 1258 1259 return doTraceurCompile(load.source, compiler, options.filename); 1260 } 1261 function doTraceurCompile(source, compiler, filename) { 1262 try { 1263 return compiler.compile(source, filename); 1264 } 1265 catch(e) { 1266 // on older versions of traceur (<0.9.3), an array of errors is thrown 1267 // rather than a single error. 1268 if (e.length) { 1269 throw e[0]; 1270 } 1271 throw e; 1272 } 1273 } 1274 1275 function babelTranspile(load, babel) { 1276 var options = this.babelOptions || {}; 1277 options.modules = 'system'; 1278 if (options.sourceMap === undefined) 1279 options.sourceMap = 'inline'; 1280 options.inputSourceMap = load.metadata.sourceMap; 1281 options.filename = load.address; 1282 options.code = true; 1283 options.ast = false; 1284 1285 return babel.transform(load.source, options).code; 1286 } 1287 1288 function typescriptTranspile(load, ts) { 1289 var options = this.typescriptOptions || {}; 1290 options.target = options.target || ts.ScriptTarget.ES5; 1291 if (options.sourceMap === undefined) 1292 options.sourceMap = true; 1293 if (options.sourceMap && options.inlineSourceMap !== false) 1294 options.inlineSourceMap = true; 1295 1296 options.module = ts.ModuleKind.System; 1297 1298 return ts.transpile(load.source, options, load.address); 1299 } 1300 1301 return transpile; 1302})(); 1303// SystemJS Loader Class and Extension helpers 1304 1305function SystemJSLoader() { 1306 SystemLoader.call(this); 1307 1308 systemJSConstructor.call(this); 1309} 1310 1311// inline Object.create-style class extension 1312function SystemProto() {}; 1313SystemProto.prototype = SystemLoader.prototype; 1314SystemJSLoader.prototype = new SystemProto(); 1315SystemJSLoader.prototype.constructor = SystemJSLoader; 1316 1317// remove ESML instantiate 1318SystemJSLoader.prototype.instantiate = function() {}; 1319 1320var systemJSConstructor; 1321 1322function hook(name, hook) { 1323 SystemJSLoader.prototype[name] = hook(SystemJSLoader.prototype[name] || function() {}); 1324} 1325function hookConstructor(hook) { 1326 systemJSConstructor = hook(systemJSConstructor || function() {}); 1327} 1328 1329function dedupe(deps) { 1330 var newDeps = []; 1331 for (var i = 0, l = deps.length; i < l; i++) 1332 if (indexOf.call(newDeps, deps[i]) == -1) 1333 newDeps.push(deps[i]) 1334 return newDeps; 1335} 1336 1337function group(deps) { 1338 var names = []; 1339 var indices = []; 1340 for (var i = 0, l = deps.length; i < l; i++) { 1341 var index = indexOf.call(names, deps[i]); 1342 if (index === -1) { 1343 names.push(deps[i]); 1344 indices.push([i]); 1345 } 1346 else { 1347 indices[index].push(i); 1348 } 1349 } 1350 return { names: names, indices: indices }; 1351} 1352 1353var getOwnPropertyDescriptor = true; 1354try { 1355 Object.getOwnPropertyDescriptor({ a: 0 }, 'a'); 1356} 1357catch(e) { 1358 getOwnPropertyDescriptor = false; 1359} 1360 1361// converts any module.exports object into an object ready for SystemJS.newModule 1362function getESModule(exports) { 1363 var esModule = {}; 1364 // don't trigger getters/setters in environments that support them 1365 if (typeof exports == 'object' || typeof exports == 'function') { 1366 var hasOwnProperty = exports && exports.hasOwnProperty; 1367 if (getOwnPropertyDescriptor) { 1368 for (var p in exports) { 1369 if (!trySilentDefineProperty(esModule, exports, p)) 1370 setPropertyIfHasOwnProperty(esModule, exports, p, hasOwnProperty); 1371 } 1372 } 1373 else { 1374 for (var p in exports) 1375 setPropertyIfHasOwnProperty(esModule, exports, p, hasOwnProperty); 1376 } 1377 } 1378 esModule['default'] = exports; 1379 defineProperty(esModule, '__useDefault', { 1380 value: true 1381 }); 1382 return esModule; 1383} 1384 1385function setPropertyIfHasOwnProperty(targetObj, sourceObj, propName, hasOwnProperty) { 1386 if (!hasOwnProperty || sourceObj.hasOwnProperty(propName)) 1387 targetObj[propName] = sourceObj[propName]; 1388} 1389 1390function trySilentDefineProperty(targetObj, sourceObj, propName) { 1391 try { 1392 var d; 1393 if (d = Object.getOwnPropertyDescriptor(sourceObj, propName)) 1394 defineProperty(targetObj, propName, d); 1395 1396 return true; 1397 } catch (ex) { 1398 // Object.getOwnPropertyDescriptor threw an exception, fall back to normal set property. 1399 return false;
1400 } 1401} 1402 1403function extend(a, b, prepend) { 1404 for (var p in b) { 1405 if (!prepend || !(p in a)) 1406 a[p] = b[p]; 1407 } 1408 return a; 1409} 1410 1411// package configuration options 1412var packageProperties = ['main', 'format', 'defaultExtension', 'meta', 'map', 'basePath', 'depCache']; 1413 1414// meta first-level extends where: 1415// array + array appends 1416// object + object extends 1417// other properties replace 1418function extendMeta(a, b, prepend) { 1419 for (var p in b) { 1420 var val = b[p]; 1421 if (!(p in a)) 1422 a[p] = val; 1423 else if (val instanceof Array && a[p] instanceof Array) 1424 a[p] = [].concat(prepend ? val : a[p]).concat(prepend ? a[p] : val); 1425 else if (typeof val == 'object' && val !== null && typeof a[p] == 'object') 1426 a[p] = extend(extend({}, a[p]), val, prepend); 1427 else if (!prepend) 1428 a[p] = val; 1429 } 1430} 1431 1432function warn(msg) { 1433 if (this.warnings && typeof console != 'undefined' && console.warn) 1434 console.warn(msg); 1435} 1436// we define a __exec for globally-scoped execution 1437// used by module format implementations 1438var __exec; 1439 1440(function() { 1441 1442 var hasBtoa = typeof btoa != 'undefined'; 1443 1444 function getSource(load) { 1445 var lastLineIndex = load.source.lastIndexOf('\n'); 1446 1447 // wrap ES formats with a System closure for System global encapsulation 1448 var wrap = load.metadata.format != 'global'; 1449 1450 var sourceMap = load.metadata.sourceMap; 1451 if (sourceMap) { 1452 if (typeof sourceMap != 'object') 1453 throw new TypeError('load.metadata.sourceMap must be set to an object.'); 1454 1455 sourceMap = JSON.stringify(sourceMap); 1456 } 1457 1458 return (wrap ? '(function(System, SystemJS) {' : '') + load.source + (wrap ? '\n})(System, System);' : '') 1459 // adds the sourceURL comment if not already present 1460 + (load.source.substr(lastLineIndex, 15) != '\n//# sourceURL=' 1461 ? '\n//# sourceURL=' + load.address + (sourceMap ? '!transpiled' : '') : '') 1462 // add sourceMappingURL if load.metadata.sourceMap is set 1463 + (sourceMap && hasBtoa && '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(sourceMap))) || ''); 1464 } 1465 1466 var curLoad; 1467 1468 // System.register, System.registerDynamic, AMD define pipeline 1469 // if currently evalling code here, immediately reduce the registered entry against the load record 1470 hook('pushRegister_', function() { 1471 return function(register) { 1472 if (!curLoad) 1473 return false; 1474 1475 this.reduceRegister_(curLoad, register); 1476 return true; 1477 }; 1478 }); 1479 1480 // System clobbering protection (mostly for Traceur) 1481 var curSystem; 1482 var callCounter = 0; 1483 function preExec(loader, load) { 1484 curLoad = load; 1485 if (callCounter++ == 0) 1486 curSystem = __global.System; 1487 __global.System = __global.SystemJS = loader; 1488 } 1489 function postExec() { 1490 if (--callCounter == 0) 1491 __global.System = __global.SystemJS = curSystem; 1492 curLoad = undefined; 1493 } 1494 1495 var vm; 1496 __exec = function(load) { 1497 if (!load.source) 1498 return; 1499 if ((load.metadata.integrity || load.metadata.nonce) && supportsScriptExec) 1500 return scriptExec.call(this, load); 1501 try { 1502 preExec(this, load); 1503 curLoad = load; 1504 // global scoped eval for node (avoids require scope leak) 1505 if (this._nodeRequire) { 1506 vm = vm || this._nodeRequire('vm'); 1507 vm.runInThisContext(getSource(load)); 1508 } 1509 else { 1510 (0, eval)(getSource(load)); 1511 } 1512 postExec(); 1513 } 1514 catch(e) { 1515 postExec(); 1516 throw addToError(e, 'Evaluating ' + load.address); 1517 } 1518 }; 1519 1520 var supportsScriptExec = false; 1521 if (isBrowser && typeof document != 'undefined' && document.getElementsByTagName) { 1522 var scripts = document.getElementsByTagName('script'); 1523 $__curScript = scripts[scripts.length - 1]; 1524 1525 if (!(window.chrome && window.chrome.extension || navigator.userAgent.match(/^Node\.js/))) 1526 supportsScriptExec = true; 1527 } 1528 1529 // script execution via injecting a script tag into the page 1530 // this allows CSP integrity and nonce to be set for CSP environments 1531 var head; 1532 function scriptExec(load) { 1533 if (!head) 1534 head = document.head || document.body || document.documentElement; 1535 1536 var script = document.createElement('script'); 1537 script.text = getSource(load, false); 1538 var onerror = window.onerror; 1539 var e; 1540 window.onerror = function(_e) { 1541 e = addToError(_e, 'Evaluating ' + load.address); 1542 } 1543 preExec(this, load); 1544 1545 if (load.metadata.integrity) 1546 script.setAttribute('integrity', load.metadata.integrity); 1547 if (load.metadata.nonce) 1548 script.setAttribute('nonce', load.metadata.nonce); 1549 1550 head.appendChild(script); 1551 head.removeChild(script); 1552 postExec(); 1553 window.onerror = onerror; 1554 if (e) 1555 throw e; 1556 } 1557 1558})(); 1559var absURLRegEx = /^[^\/]+:\/\//; 1560 1561function readMemberExpression(p, value) { 1562 var pParts = p.split('.'); 1563 while (pParts.length) 1564 value = value[pParts.shift()]; 1565 return value; 1566} 1567 1568var baseURLCache = {}; 1569function getBaseURLObj() { 1570 if (baseURLCache[this.baseURL]) 1571 return baseURLCache[this.baseURL]; 1572 1573 // normalize baseURL if not already 1574 if (this.baseURL[this.baseURL.length - 1] != '/') 1575 this.baseURL += '/'; 1576 1577 var baseURL = new URL(this.baseURL, baseURI); 1578 1579 this.baseURL = baseURL.href; 1580 1581 return (baseURLCache[this.baseURL] = baseURL); 1582} 1583 1584function getMapMatch(map, name) { 1585 var bestMatch, bestMatchLength = 0; 1586 1587 for (var p in map) { 1588 if (name.substr(0, p.length) == p && (name.length == p.length || name[p.length] == '/')) { 1589 var curMatchLength = p.split('/').length; 1590 if (curMatchLength <= bestMatchLength) 1591 continue; 1592 bestMatch = p; 1593 bestMatchLength = curMatchLength; 1594 } 1595 } 1596 1597 return bestMatch; 1598} 1599 1600function setProduction(isProduction) { 1601 this.set('@system-env', this.newModule({ 1602 browser: isBrowser, 1603 node: !!this._nodeRequire, 1604 production: isProduction, 1605 'default': true 1606 })); 1607} 1608 1609var baseURIObj = new URL(baseURI); 1610 1611hookConstructor(function(constructor) { 1612 return function() { 1613 constructor.call(this); 1614 1615 // support baseURL 1616 this.baseURL = baseURI.substr(0, baseURI.lastIndexOf('/') + 1); 1617 1618 // support map and paths 1619 this.map = {}; 1620 this.paths = {}; 1621 1622 // global behaviour flags 1623 this.warnings = false;
1624 this.defaultJSExtensions = false; 1625 this.pluginFirst = false; 1626 this.loaderErrorStack = false; 1627 1628 // by default load ".json" files as json 1629 // leading * meta doesn't need normalization 1630 // NB add this in next breaking release 1631 // this.meta['*.json'] = { format: 'json' }; 1632 1633 // support the empty module, as a concept 1634 this.set('@empty', this.newModule({})); 1635 1636 setProduction.call(this, false); 1637 }; 1638}); 1639 1640// include the node require since we're overriding it 1641if (typeof require != 'undefined' && typeof process != 'undefined' && !process.browser) 1642 SystemJSLoader.prototype._nodeRequire = require; 1643 1644var nodeCoreModules = ['assert', 'buffer', 'child_process', 'cluster', 'console', 'constants', 1645 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'module', 'net', 'os', 'path', 1646 'process', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'sys', 'timers', 1647 'tls', 'tty', 'url', 'util', 'vm', 'zlib']; 1648 1649/* 1650 Core SystemJS Normalization 1651 1652 If a name is relative, we apply URL normalization to the page 1653 If a name is an absolute URL, we leave it as-is 1654 1655 Plain names (neither of the above) run through the map and paths 1656 normalization phases. 1657 1658 The paths normalization phase applies last (paths extension), which 1659 defines the `decanonicalize` function and normalizes everything into 1660 a URL. 1661 */ 1662 1663function isPlain(name) { 1664 return (name[0] != '.' || (!!name[1] && name[1] != '/' && name[1] != '.')) && name[0] != '/' && !name.match(absURLRegEx); 1665} 1666 1667function urlResolve(name, parent) { 1668 if (parent) 1669 parent = parent.replace(/#/g, '%05'); 1670 return new URL(name, parent || baseURIObj).href.replace(/%05/g, '#'); 1671} 1672 1673// only applies to plain names 1674function baseURLResolve(loader, name) { 1675 return new URL(name, getBaseURLObj.call(loader)).href; 1676} 1677 1678function coreResolve(name, parentName) { 1679 // standard URL resolution 1680 if (!isPlain(name)) 1681 return urlResolve(name, parentName); 1682 1683 // plain names not starting with './', '://' and '/' go through custom resolution 1684 var mapMatch = getMapMatch(this.map, name); 1685 1686 if (mapMatch) { 1687 name = this.map[mapMatch] + name.substr(mapMatch.length); 1688 1689 if (!isPlain(name)) 1690 return urlResolve(name); 1691 } 1692 1693 if (this.has(name)) 1694 return name; 1695 // dynamically load node-core modules when requiring `@node/fs` for example 1696 if (name.substr(0, 6) == '@node/' && nodeCoreModules.indexOf(name.substr(6)) != -1) { 1697 if (!this._nodeRequire) 1698 throw new TypeError('Error loading ' + name + '. Can only load node core modules in Node.'); 1699 this.set(name, this.newModule(getESModule(this._nodeRequire(name.substr(6))))); 1700 return name; 1701 } 1702 1703 var pathed = applyPaths(this.paths, name); 1704 1705 if (pathed && !isPlain(pathed)) 1706 return urlResolve(pathed); 1707 1708 return baseURLResolve(this, pathed || name); 1709} 1710 1711hook('normalize', function(normalize) { 1712 return function(name, parentName, skipExt) { 1713 var resolved = coreResolve.call(this, name, parentName); 1714 if (!skipExt && this.defaultJSExtensions && resolved.substr(resolved.length - 3, 3) != '.js' && !isPlain(resolved)) 1715 resolved += '.js'; 1716 return resolved; 1717 }; 1718}); 1719 1720// percent encode just '#' in urls if using HTTP requests 1721var httpRequest = typeof XMLHttpRequest != 'undefined'; 1722hook('locate', function(locate) { 1723 return function(load) { 1724 return Promise.resolve(locate.call(this, load)) 1725 .then(function(address) { 1726 if (httpRequest) 1727 return address.replace(/#/g, '%23'); 1728 return address; 1729 }); 1730 }; 1731}); 1732 1733/* 1734 * Fetch with authorization 1735 */ 1736hook('fetch', function() { 1737 return function(load) { 1738 return new Promise(function(resolve, reject) { 1739 fetchTextFromURL(load.address, load.metadata.authorization, resolve, reject); 1740 }); 1741 }; 1742}); 1743 1744/* 1745 __useDefault 1746 1747 When a module object looks like: 1748 newModule( 1749 __useDefault: true, 1750 default: 'some-module' 1751 }) 1752 1753 Then importing that module provides the 'some-module' 1754 result directly instead of the full module. 1755 1756 Useful for eg module.exports = function() {} 1757*/ 1758hook('import', function(systemImport) { 1759 return function(name, parentName, parentAddress) { 1760 if (parentName && parentName.name) 1761 warn.call(this, 'SystemJS.import(name, { name: parentName }) is deprecated for SystemJS.import(name, parentName), while importing ' + name + ' from ' + parentName.name); 1762 return systemImport.call(this, name, parentName, parentAddress).then(function(module) { 1763 return module.__useDefault ? module['default'] : module; 1764 }); 1765 }; 1766}); 1767 1768/* 1769 * Allow format: 'detect' meta to enable format detection 1770 */ 1771hook('translate', function(systemTranslate) { 1772 return function(load) { 1773 if (load.metadata.format == 'detect') 1774 load.metadata.format = undefined; 1775 return systemTranslate.call(this, load); 1776 }; 1777}); 1778 1779 1780/* 1781 * JSON format support 1782 * 1783 * Supports loading JSON files as a module format itself 1784 * 1785 * Usage: 1786 *
1787 * SystemJS.config({ 1788 * meta: { 1789 * '*.json': { format: 'json' } 1790 * } 1791 * }); 1792 * 1793 * Module is returned as if written: 1794 * 1795 * export default {JSON} 1796 * 1797 * No named exports are provided 1798 * 1799 * Files ending in ".json" are treated as json automatically by SystemJS 1800 */ 1801hook('instantiate', function(instantiate) { 1802 return function(load) { 1803 if (load.metadata.format == 'json' && !this.builder) { 1804 var entry = load.metadata.entry = createEntry(); 1805 entry.deps = []; 1806 entry.execute = function() { 1807 try { 1808 return JSON.parse(load.source); 1809 } 1810 catch(e) { 1811 throw new Error("Invalid JSON file " + load.name); 1812 } 1813 }; 1814 } 1815 }; 1816}) 1817 1818/* 1819 Extend config merging one deep only 1820 1821 loader.config({ 1822 some: 'random', 1823 config: 'here', 1824 deep: { 1825 config: { too: 'too' } 1826 } 1827 }); 1828 1829 <=> 1830 1831 loader.some = 'random'; 1832 loader.config = 'here' 1833 loader.deep = loader.deep || {}; 1834 loader.deep.config = { too: 'too' }; 1835 1836 1837 Normalizes meta and package configs allowing for: 1838 1839 SystemJS.config({ 1840 meta: { 1841 './index.js': {} 1842 } 1843 }); 1844 1845 To become 1846 1847 SystemJS.meta['https://thissite.com/index.js'] = {}; 1848 1849 For easy normalization canonicalization with latest URL support. 1850 1851*/ 1852SystemJSLoader.prototype.env = 'development'; 1853 1854var curCurScript; 1855SystemJSLoader.prototype.config = function(cfg) { 1856 var loader = this; 1857 1858 if ('loaderErrorStack' in cfg) { 1859 curCurScript = $__curScript; 1860 if (cfg.loaderErrorStack) 1861 $__curScript = undefined; 1862 else 1863 $__curScript = curCurScript; 1864 } 1865 1866 if ('warnings' in cfg) 1867 loader.warnings = cfg.warnings; 1868 1869 // transpiler deprecation path 1870 if (cfg.transpilerRuntime === false) 1871 loader._loader.loadedTranspilerRuntime = true; 1872 1873 // always configure baseURL first 1874 if (cfg.baseURL) { 1875 var hasConfig = false; 1876 function checkHasConfig(obj) { 1877 for (var p in obj) 1878 if (hasOwnProperty.call(obj, p)) 1879 return true; 1880 } 1881 if (checkHasConfig(loader.packages) || checkHasConfig(loader.meta) || checkHasConfig(loader.depCache) || checkHasConfig(loader.bundles) || checkHasConfig(loader.packageConfigPaths)) 1882 throw new TypeError('Incorrect configuration order. The baseURL must be configured with the first SystemJS.config call.'); 1883 1884 loader.baseURL = cfg.baseURL; 1885 1886 // sanitize baseURL 1887 getBaseURLObj.call(loader); 1888 } 1889 1890 if (cfg.defaultJSExtensions) { 1891 loader.defaultJSExtensions = cfg.defaultJSExtensions; 1892 warn.call(loader, 'The defaultJSExtensions configuration option is deprecated, use packages configuration instead.'); 1893 } 1894 1895 if (cfg.pluginFirst) 1896 loader.pluginFirst = cfg.pluginFirst; 1897 1898 if (cfg.production) 1899 setProduction.call(loader, true); 1900 1901 if (cfg.paths) { 1902 for (var p in cfg.paths) 1903 loader.paths[p] = cfg.paths[p]; 1904 } 1905 1906 if (cfg.map) { 1907 var objMaps = ''; 1908 for (var p in cfg.map) { 1909 var v = cfg.map[p]; 1910 1911 // object map backwards-compat into packages configuration 1912 if (typeof v !== 'string') { 1913 objMaps += (objMaps.length ? ', ' : '') + '"' + p + '"'; 1914 1915 var defaultJSExtension = loader.defaultJSExtensions && p.substr(p.length - 3, 3) != '.js'; 1916 var prop = loader.decanonicalize(p); 1917 if (defaultJSExtension && prop.substr(prop.length - 3, 3) == '.js') 1918 prop = prop.substr(0, prop.length - 3); 1919 1920 // if a package main, revert it 1921 var pkgMatch = ''; 1922 for (var pkg in loader.packages) { 1923 if (prop.substr(0, pkg.length) == pkg 1924 && (!prop[pkg.length] || prop[pkg.length] == '/') 1925 && pkgMatch.split('/').length < pkg.split('/').length) 1926 pkgMatch = pkg; 1927 } 1928 if (pkgMatch && loader.packages[pkgMatch].main) 1929 prop = prop.substr(0, prop.length - loader.packages[pkgMatch].main.length - 1); 1930 1931 var pkg = loader.packages[prop] = loader.packages[prop] || {}; 1932 pkg.map = v; 1933 } 1934 else { 1935 loader.map[p] = v; 1936 } 1937 } 1938 if (objMaps) 1939 warn.call(loader, 'The map configuration for ' + objMaps + ' uses object submaps, which is deprecated in global map.\nUpdate this to use package contextual map with configs like SystemJS.c
1939onfig({ packages: { "' + p + '": { map: {...} } } }).'); 1940 } 1941 1942 if (cfg.packageConfigPaths) { 1943 var packageConfigPaths = []; 1944 for (var i = 0; i < cfg.packageConfigPaths.length; i++) { 1945 var path = cfg.packageConfigPaths[i]; 1946 var packageLength = Math.max(path.lastIndexOf('*') + 1, path.lastIndexOf('/')); 1947 var defaultJSExtension = loader.defaultJSExtensions && path.substr(packageLength - 3, 3) != '.js'; 1948 var normalized = loader.decanonicalize(path.substr(0, packageLength)); 1949 if (defaultJSExtension && normalized.substr(normalized.length - 3, 3) == '.js') 1950 normalized = normalized.substr(0, normalized.length - 3); 1951 packageConfigPaths[i] = normalized + path.substr(packageLength); 1952 } 1953 loader.packageConfigPaths = packageConfigPaths; 1954 } 1955 1956 if (cfg.bundles) { 1957 for (var p in cfg.bundles) { 1958 var bundle = []; 1959 for (var i = 0; i < cfg.bundles[p].length; i++) { 1960 var defaultJSExtension = loader.defaultJSExtensions && cfg.bundles[p][i].substr(cfg.bundles[p][i].length - 3, 3) != '.js'; 1961 var normalizedBundleDep = loader.decanonicalize(cfg.bundles[p][i]); 1962 if (defaultJSExtension && normalizedBundleDep.substr(normalizedBundleDep.length - 3, 3) == '.js') 1963 normalizedBundleDep = normalizedBundleDep.substr(0, normalizedBundleDep.length - 3); 1964 bundle.push(normalizedBundleDep); 1965 } 1966 loader.bundles[p] = bundle; 1967 } 1968 } 1969 1970 if (cfg.packages) { 1971 for (var p in cfg.packages) { 1972 if (p.match(/^([^\/]+:)?\/\/$/)) 1973 throw new TypeError('"' + p + '" is not a valid package name.'); 1974 1975 var prop = coreResolve.call(loader, p); 1976 1977 // allow trailing slash in packages 1978 if (prop[prop.length - 1] == '/') 1979 prop = prop.substr(0, prop.length - 1); 1980 1981 loader.packages[prop] = loader.packages[prop] || {}; 1982 1983 var pkg = cfg.packages[p]; 1984 1985 // meta backwards compatibility 1986 if (pkg.modules) { 1987 warn.call(loader, 'Package ' + p + ' is configured with "modules", which is deprecated as it has been renamed to "meta".'); 1988 pkg.meta = pkg.modules; 1989 delete pkg.modules; 1990 } 1991 1992 if (typeof pkg.main == 'object') { 1993 pkg.map = pkg.map || {}; 1994 pkg.map['./@main'] = pkg.main; 1995 pkg.main['default'] = pkg.main['default'] || './'; 1996 pkg.main = '@main'; 1997 } 1998 1999 for (var q in pkg) 2000 if (indexOf.call(packageProperties, q) == -1) 2001 warn.call(loader, '"' + q + '" is not a valid package configuration option in package ' + p); 2002 2003 extendMeta(loader.packages[prop], pkg); 2004 } 2005 } 2006 2007 for (var c in cfg) { 2008 var v = cfg[c]; 2009 2010 if (c == 'baseURL' || c == 'map' || c == 'packages' || c == 'bundles' || c == 'paths' || c == 'warnings' || c == 'packageConfigPaths' || c == 'loaderErrorStack') 2011 continue; 2012 2013 if (typeof v != 'object' || v instanceof Array) { 2014 loader[c] = v; 2015 } 2016 else { 2017 loader[c] = loader[c] || {}; 2018 2019 for (var p in v) { 2020 // base-level wildcard meta does not normalize to retain catch-all quality 2021 if (c == 'meta' && p[0] == '*') { 2022 loader[c][p] = v[p]; 2023 } 2024 else if (c == 'meta') { 2025 // meta can go through global map, with defaultJSExtensions adding 2026 var resolved = coreResolve.call(loader, p); 2027 if (loader.defaultJSExtensions && resolved.substr(resolved.length - 3, 3) != '.js' && !isPlain(resolved)) 2028 resolved += '.js'; 2029 loader[c][resolved] = v[p]; 2030 } 2031 else if (c == 'depCache') { 2032 var defaultJSExtension = loader.defaultJSExtensions && p.substr(p.length - 3, 3) != '.js'; 2033 var prop = loader.decanonicalize(p); 2034 if (defaultJSExtension && prop.substr(prop.length - 3, 3) == '.js') 2035 prop = prop.substr(0, prop.length - 3); 2036 loader[c][prop] = v[p]; 2037 } 2038 else { 2039 loader[c][p] = v[p]; 2040 } 2041 } 2042 } 2043 } 2044};/* 2045 * Package Configuration Extension 2046 * 2047 * Example: 2048 * 2049 * SystemJS.packages = { 2050 * jquery: { 2051 * main: 'index.js', // when not set, package name is requested directly 2052 * format: 'amd', 2053 * defaultExtension: 'ts', // defaults to 'js', can be set to false 2054 * modules: { 2055 * '*.ts': { 2056 * loader: 'typescript' 2057 * },
2058 * 'vendor/sizzle.js': { 2059 * format: 'global' 2060 * } 2061 * }, 2062 * map: { 2063 * // map internal require('sizzle') to local require('./vendor/sizzle') 2064 * sizzle: './vendor/sizzle.js', 2065 * // map any internal or external require of 'jquery/vendor/another' to 'another/index.js' 2066 * './vendor/another.js': './another/index.js', 2067 * // test.js / test -> lib/test.js 2068 * './test.js': './lib/test.js', 2069 * 2070 * // environment-specific map configurations 2071 * './index.js': { 2072 * '~browser': './index-node.js' 2073 * } 2074 * }, 2075 * // allows for setting package-prefixed depCache 2076 * // keys are normalized module names relative to the package itself 2077 * depCache: { 2078 * // import 'package/index.js' loads in parallel package/lib/test.js,package/vendor/sizzle.js 2079 * './index.js': ['./test'], 2080 * './test.js': ['external-dep'], 2081 * 'external-dep/path.js': ['./another.js'] 2082 * } 2083 * } 2084 * }; 2085 * 2086 * Then: 2087 * import 'jquery' -> jquery/index.js 2088 * import 'jquery/submodule' -> jquery/submodule.js 2089 * import 'jquery/submodule.ts' -> jquery/submodule.ts loaded as typescript 2090 * import 'jquery/vendor/another' -> another/index.js 2091 * 2092 * Detailed Behaviours 2093 * - main can have a leading "./" can be added optionally 2094 * - map and defaultExtension are applied to the main 2095 * - defaultExtension adds the extension only if the exact extension is not present 2096 * - defaultJSExtensions applies after map when defaultExtension is not set 2097 * - if a meta value is available for a module, map and defaultExtension are skipped 2098 * - like global map, package map also applies to subpaths (sizzle/x, ./vendor/another/sub) 2099 * - condition module map is '@env' module in package or '@system-env' globally 2100 * - map targets support conditional interpolation ('./x': './x.#{|env}.js') 2101 * - internal package map targets cannot use boolean conditionals 2102 * 2103 * Package Configuration Loading 2104 * 2105 * Not all packages may already have their configuration present in the System config 2106 * For these cases, a list of packageConfigPaths can be provided, which when matched against 2107 * a request, will first request a ".json" file by the package name to derive the package 2108 * configuration from. This allows dynamic loading of non-predetermined code, a key use 2109 * case in SystemJS. 2110 * 2111 * Example: 2112 * 2113 * SystemJS.packageConfigPaths = ['packages/test/package.json', 'packages/*.json']; 2114 * 2115 * // will first request 'packages/new-package/package.json' for the package config 2116 * // before completing the package request to 'packages/new-package/path' 2117 * SystemJS.import('packages/new-package/path'); 2118 * 2119 * // will first request 'packages/test/package.json' before the main 2120 * SystemJS.import('packages/test'); 2121 * 2122 * When a package matches packageConfigPaths, it will always send a config request for 2123 * the package configuration. 2124 * The package name itself is taken to be the match up to and including the last wildcard 2125 * or trailing slash. 2126 * The most specific package config path will be used. 2127 * Any existing package configurations for the package will deeply merge with the 2128 * package config, with the existing package configurations taking preference. 2129 * To opt-out of the package configuration request for a package that matches 2130 * packageConfigPaths, use the { configured: true } package config option. 2131 * 2132 */ 2133(function() { 2134 2135 hookConstructor(function(constructor) { 2136 return function() { 2137 constructor.call(this); 2138 this.packages = {}; 2139 this.packageConfigPaths = []; 2140 }; 2141 }); 2142 2143 function getPackage(loader, normalized) { 2144 // use most specific package 2145 var curPkg, curPkgLen = 0, pkgLen; 2146 for (var p in loader.packages) { 2147 if (normalized.substr(0, p.length) === p && (normalized.length === p.length || normalized[p.length] === '/')) { 2148 pkgLen = p.split('/').length; 2149 if (pkgLen > curPkgLen) { 2150 curPkg = p; 2151 curPkgLen = pkgLen; 2152 } 2153 } 2154 } 2155 return curPkg; 2156 } 2157 2158 function addDefaultExtension(loader, pkg, pkgName, subPath, skipExtensions) { 2159 // don't apply extensions to folders or if defaultExtension = false 2160 if (!subPath || subPath[subPath.length - 1] == '/' || skipExtensions || pkg.defaultExtension === false) 2161 return subPath; 2162 2163 // NB are you sure about this? 2164 // skip if we have interpolation conditional syntax in subPath? 2165 if (subPath.match(interpolationRegEx)) 2166 return subPath; 2167 2168 var metaMatch = false;
2169 2170 // exact meta or meta with any content after the last wildcard skips extension 2171 if (pkg.meta) 2172 getMetaMatches(pkg.meta, subPath, function(metaPattern, matchMeta, matchDepth) { 2173 if (matchDepth == 0 || metaPattern.lastIndexOf('*') != metaPattern.length - 1) 2174 return metaMatch = true; 2175 }); 2176 2177 // exact global meta or meta with any content after the last wildcard skips extension 2178 if (!metaMatch && loader.meta) 2179 getMetaMatches(loader.meta, pkgName + '/' + subPath, function(metaPattern, matchMeta, matchDepth) { 2180 if (matchDepth == 0 || metaPattern.lastIndexOf('*') != metaPattern.length - 1) 2181 return metaMatch = true; 2182 }); 2183 2184 if (metaMatch) 2185 return subPath; 2186 2187 // work out what the defaultExtension is and add if not there already 2188 // NB reconsider if default should really be ".js"? 2189 var defaultExtension = '.' + (pkg.defaultExtension || 'js'); 2190 if (subPath.substr(subPath.length - defaultExtension.length) != defaultExtension) 2191 return subPath + defaultExtension; 2192 else 2193 return subPath; 2194 } 2195 2196 function applyPackageConfigSync(loader, pkg, pkgName, subPath, skipExtensions) { 2197 // main 2198 if (!subPath) { 2199 if (pkg.main) 2200 subPath = pkg.main.substr(0, 2) == './' ? pkg.main.substr(2) : pkg.main; 2201 // also no submap if name is package itself (import 'pkg' -> 'path/to/pkg.js') 2202 else 2203 // NB can add a default package main convention here when defaultJSExtensions is deprecated 2204 // if it becomes internal to the package then it would no longer be an exit path 2205 return pkgName + (loader.defaultJSExtensions ? '.js' : ''); 2206 } 2207 2208 // map config checking without then with extensions 2209 if (pkg.map) { 2210 var mapPath = './' + subPath; 2211 2212 var mapMatch = getMapMatch(pkg.map, mapPath); 2213 2214 // we then check map with the default extension adding 2215 if (!mapMatch) { 2216 mapPath = './' + addDefaultExtension(loader, pkg, pkgName, subPath, skipExtensions); 2217 if (mapPath != './' + subPath) 2218 mapMatch = getMapMatch(pkg.map, mapPath); 2219 } 2220 if (mapMatch) 2221 return doMapSync(loader, pkg, pkgName, mapMatch, mapPath, skipExtensions); 2222 } 2223 2224 // normal package resolution 2225 return pkgName + '/' + addDefaultExtension(loader, pkg, pkgName, subPath, skipExtensions); 2226 } 2227 2228 function validateMapping(mapMatch, mapped, pkgName) { 2229 // disallow internal to subpath maps 2230 if (mapMatch == '.') 2231 throw new Error('Package ' + pkgName + ' has a map entry for "." which is not permitted.'); 2232 // disallow internal ./x -> ./x/y recursive maps 2233 else if (mapped.substr(0, mapMatch.length) == mapMatch && (mapMatch[mapMatch.length - 1] != '/' && mapped[mapMatch.length] == '/')) 2234 throw new Error('Package ' + pkgName + ' has a recursive map for "' + mapMatch + '" which is not permitted.'); 2235 } 2236 2237 function doMapSync(loader, pkg, pkgName, mapMatch, path, skipExtensions) { 2238 var mapped = pkg.map[mapMatch]; 2239 2240 if (typeof mapped == 'object') 2241 throw new Error('Synchronous conditional normalization not supported sync normalizing ' + mapMatch + ' in ' + pkgName); 2242 2243 validateMapping(mapMatch, mapped, pkgName); 2244 2245 // ignore conditionals in sync 2246 if (typeof mapped != 'string') 2247 mapped = mapMatch = path; 2248 2249 validateMapping(mapMatch, mapped, pkgName); 2250 2251 // package map to main / base-level 2252 if (mapped == '.') 2253 mapped = pkgName; 2254 2255 // internal package map 2256 else if (mapped.substr(0, 2) == './') 2257 return pkgName + '/' + addDefaultExtension(loader, pkg, pkgName, mapped.substr(2) + path.substr(mapMatch.length), skipExtensions); 2258 2259 // external map reference 2260 return loader.normalizeSync(mapped + path.substr(mapMatch.length), pkgName + '/'); 2261 } 2262 2263 function applyPackageConfig(loader, pkg, pkgName, subPath, skipExtensions) { 2264 // main 2265 if (!subPath) { 2266 if (pkg.main) 2267 subPath = pkg.main.substr(0, 2) == './' ? pkg.main.substr(2) : pkg.main; 2268 // also no submap if name is package itself (import 'pkg' -> 'path/to/pkg.js') 2269 else 2270 // NB can add a default package main convention here when defaultJSExtensions is deprecated 2271 // if it becomes internal to the package then it would no longer be an exit path 2272 return Promise.resolve(pkgName + (loader.defaultJSExtensions ? '.js' : '')); 2273 } 2274 2275 // map config checking without then with extensions 2276 var mapPath, mapMatch; 2277 2278 if (pkg.map) { 2279 mapPath = './' + subPath; 2280 mapMatch = getMapMatch(pkg.map, mapPath); 2281 2282 // we then check map with the default extension adding 2283 if (!mapMatch) { 2284 mapPath = './' + addDefaultExtension(loader, pkg, pkgName, subPath, skipExtensions); 2285 if (mapPath != './' + subPath) 2286 mapMatch = getMapMatch(pkg.map, mapPath); 2287 } 2288 } 2289 2290 return (mapMatch ? doMap(loader, pkg, pkgName, mapMatch, mapPath, skipExtensions) : Promise.resolve()) 2291 .then(function(mapped) { 2292 if (mapped) 2293 return Promise.resolve(mapped); 2294 2295 // normal package resolution / fallback resolution for no conditional match 2296 return Promise.resolve(pkgName + '/' + addDefaultExtension(loader, pkg, pkgName, subPath, skipExtensions)); 2297 }); 2298 } 2299 2300 function doStringMap(loader, pkg, pkgName, mapMatch, mapped, path, skipExtensions) {
2301 // NB the interpolation cases should strictly skip subsequent interpolation 2302 2303 // package map to main / base-level 2304 if (mapped == '.') 2305 mapped = pkgName; 2306 2307 // internal package map 2308 else if (mapped.substr(0, 2) == './') 2309 return Promise.resolve(pkgName + '/' + addDefaultExtension(loader, pkg, pkgName, mapped.substr(2) + path.substr(mapMatch.length), skipExtensions)) 2310 .then(function(name) { 2311 return interpolateConditional.call(loader, name, pkgName + '/'); 2312 }); 2313 2314 // external map reference 2315 return loader.normalize(mapped + path.substr(mapMatch.length), pkgName + '/'); 2316 } 2317 2318 function doMap(loader, pkg, pkgName, mapMatch, path, skipExtensions) { 2319 var mapped = pkg.map[mapMatch]; 2320 2321 if (typeof mapped == 'string') { 2322 validateMapping(mapMatch, mapped, pkgName); 2323 return doStringMap(loader, pkg, pkgName, mapMatch, mapped, path, skipExtensions); 2324 } 2325 2326 // we use a special conditional syntax to allow the builder to handle conditional branch points further 2327 if (loader.builder) 2328 return Promise.resolve(pkgName + '/#:' + path); 2329 2330 // map object -> conditional map 2331 return loader['import'](pkg.map['@env'] || '@system-env', pkgName) 2332 .then(function(env) { 2333 // first map condition to match is used 2334 for (var e in mapped) { 2335 var negate = e[0] == '~'; 2336 2337 var value = readMemberExpression(negate ? e.substr(1) : e, env); 2338 2339 if (!negate && value || negate && !value) 2340 return mapped[e]; 2341 } 2342 }) 2343 .then(function(mapped) { 2344 if (mapped) { 2345 if (typeof mapped != 'string') 2346 throw new Error('Unable to map a package conditional to a package conditional.'); 2347 validateMapping(mapMatch, mapped, pkgName); 2348 return doStringMap(loader, pkg, pkgName, mapMatch, mapped, path, skipExtensions); 2349 } 2350 2351 // no environment match -> fallback to original subPath by returning undefined 2352 }); 2353 } 2354 2355 // normalizeSync = decanonicalize + package resolution 2356 SystemJSLoader.prototype.normalizeSync = SystemJSLoader.prototype.decanonicalize = SystemJSLoader.prototype.normalize; 2357 2358 // decanonicalize must JUST handle package defaultExtension: false case when defaultJSExtensions is set 2359 // to be deprecated! 2360 hook('decanonicalize', function(decanonicalize) { 2361 return function(name, parentName) { 2362 if (this.builder) 2363 return decanonicalize.call(this, name, parentName, true); 2364 2365 var decanonicalized = decanonicalize.call(this, name, parentName); 2366 2367 if (!this.defaultJSExtensions) 2368 return decanonicalized; 2369 2370 var pkgName = getPackage(this, decanonicalized); 2371 2372 var pkg = this.packages[pkgName]; 2373 var defaultExtension = pkg && pkg.defaultExtension; 2374 2375 if (defaultExtension == undefined && pkg && pkg.meta) 2376 getMetaMatches(pkg.meta, decanonicalized.substr(pkgName), function(metaPattern, matchMeta, matchDepth) { 2377 if (matchDepth == 0 || metaPattern.lastIndexOf('*') != metaPattern.length - 1) { 2378 defaultExtension = false; 2379 return true; 2380 } 2381 }); 2382 2383 if ((defaultExtension === false || defaultExtension && defaultExtension != '.js') && name.substr(name.length - 3, 3) != '.js' && decanonicalized.substr(decanonicalized.length - 3, 3) == '.js') 2384 decanonicalized = decanonicalized.substr(0, decanonicalized.length - 3); 2385 2386 return decanonicalized; 2387 }; 2388 }); 2389 2390 hook('normalizeSync', function(normalizeSync) { 2391 return function(name, parentName, isPlugin) { 2392 warn.call(this, 'SystemJS.normalizeSync has been deprecated for SystemJS.decanonicalize.'); 2393 2394 var loader = this; 2395 isPlugin = isPlugin === true; 2396 2397 // apply contextual package map first 2398 // (we assume the parent package config has already been loaded) 2399 if (parentName) 2400 var parentPackageName = getPackage(loader, parentName) || 2401 loader.defaultJSExtensions && parentName.substr(parentName.length - 3, 3) == '.js' && 2402 getPackage(loader, parentName.substr(0, parentName.length - 3)); 2403 2404 var parentPackage = parentPackageName && loader.packages[parentPackageName]; 2405 2406 // ignore . since internal maps handled by standard package resolution 2407 if (parentPackage && name[0] != '.') { 2408 var parentMap = parentPackage.map; 2409 var parentMapMatch = parentMap && getMapMatch(parentMap, name); 2410 2411 if (parentMapMatch && typeof parentMap[parentMapMatch] == 'string') 2412 return doMapSync(loader, parentPackage, parentPackageName, parentMapMatch, name, isPlugin); 2413 } 2414 2415 var defaultJSExtension = loader.defaultJSExtensions && name.substr(name.length - 3, 3) != '.js'; 2416 2417 // apply map, core, paths, contextual package map 2418 var normalized = normalizeSync.call(loader, name, parentName); 2419 2420 // undo defaultJSExtension 2421 if (defaultJSExtension && normalized.substr(normalized.length - 3, 3) != '.js') 2422 defaultJSExtension = false;
2423 if (defaultJSExtension) 2424 normalized = normalized.substr(0, normalized.length - 3); 2425 2426 var pkgConfigMatch = getPackageConfigMatch(loader, normalized); 2427 var pkgName = pkgConfigMatch && pkgConfigMatch.packageName || getPackage(loader, normalized); 2428 2429 if (!pkgName) 2430 return normalized + (defaultJSExtension ? '.js' : ''); 2431 2432 var subPath = normalized.substr(pkgName.length + 1); 2433 2434 return applyPackageConfigSync(loader, loader.packages[pkgName] || {}, pkgName, subPath, isPlugin); 2435 }; 2436 }); 2437 2438 hook('normalize', function(normalize) { 2439 return function(name, parentName, isPlugin) { 2440 var loader = this; 2441 isPlugin = isPlugin === true; 2442 2443 return Promise.resolve() 2444 .then(function() { 2445 // apply contextual package map first 2446 // (we assume the parent package config has already been loaded) 2447 if (parentName) 2448 var parentPackageName = getPackage(loader, parentName) || 2449 loader.defaultJSExtensions && parentName.substr(parentName.length - 3, 3) == '.js' && 2450 getPackage(loader, parentName.substr(0, parentName.length - 3)); 2451 2452 var parentPackage = parentPackageName && loader.packages[parentPackageName]; 2453 2454 // ignore . since internal maps handled by standard package resolution 2455 if (parentPackage && name.substr(0, 2) != './') { 2456 var parentMap = parentPackage.map; 2457 var parentMapMatch = parentMap && getMapMatch(parentMap, name); 2458 2459 if (parentMapMatch) 2460 return doMap(loader, parentPackage, parentPackageName, parentMapMatch, name, isPlugin); 2461 } 2462 2463 return Promise.resolve(); 2464 }) 2465 .then(function(mapped) { 2466 if (mapped) 2467 return mapped; 2468 2469 var defaultJSExtension = loader.defaultJSExtensions && name.substr(name.length - 3, 3) != '.js'; 2470 2471 // apply map, core, paths, contextual package map 2472 var normalized = normalize.call(loader, name, parentName); 2473 2474 // undo defaultJSExtension 2475 if (defaultJSExtension && normalized.substr(normalized.length - 3, 3) != '.js') 2476 defaultJSExtension = false; 2477 if (defaultJSExtension) 2478 normalized = normalized.substr(0, normalized.length - 3); 2479 2480 var pkgConfigMatch = getPackageConfigMatch(loader, normalized); 2481 var pkgName = pkgConfigMatch && pkgConfigMatch.packageName || getPackage(loader, normalized); 2482 2483 if (!pkgName) 2484 return Promise.resolve(normalized + (defaultJSExtension ? '.js' : '')); 2485 2486 var pkg = loader.packages[pkgName]; 2487 2488 // if package is already configured or not a dynamic config package, use existing package config 2489 var isConfigured = pkg && (pkg.configured || !pkgConfigMatch); 2490 return (isConfigured ? Promise.resolve(pkg) : loadPackageConfigPath(loader, pkgName, pkgConfigMatch.configPath)) 2491 .then(function(pkg) { 2492 var subPath = normalized.substr(pkgName.length + 1); 2493 2494 return applyPackageConfig(loader, pkg, pkgName, subPath, isPlugin); 2495 }); 2496 }); 2497 }; 2498 }); 2499 2500 // check if the given normalized name matches a packageConfigPath 2501 // if so, loads the config 2502 var packageConfigPaths = {}; 2503 2504 // data object for quick checks against package paths 2505 function createPkgConfigPathObj(path) { 2506 var lastWildcard = path.lastIndexOf('*'); 2507 var length = Math.max(lastWildcard + 1, path.lastIndexOf('/')); 2508 return { 2509 length: length, 2510 regEx: new RegExp('^(' + path.substr(0, length).replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^\\/]+') + ')(\\/|$)'), 2511 wildcard: lastWildcard != -1 2512 }; 2513 } 2514 2515 // most specific match wins 2516 function getPackageConfigMatch(loader, normalized) { 2517 var pkgName, exactMatch = false, configPath; 2518 for (var i = 0; i < loader.packageConfigPaths.length; i++) { 2519 var packageConfigPath = loader.packageConfigPaths[i]; 2520 var p = packageConfigPaths[packageConfigPath] || (packageConfigPaths[packageConfigPath] = createPkgConfigPathObj(packageConfigPath)); 2521 if (normalized.length < p.length) 2522 continue; 2523 var match = normalized.match(p.regEx); 2524 if (match && (!pkgName || (!(exactMatch && p.wildcard) && pkgName.length < match[1].length))) { 2525 pkgName = match[1]; 2526 exactMatch = !p.wildcard; 2527 configPath = pkgName + packageConfigPath.substr(p.length); 2528 } 2529 } 2530 2531 if (!pkgName) 2532 return; 2533 2534 return { 2535 packageName: pkgName, 2536 configPath: configPath 2537 }; 2538 } 2539 2540 function loadPackageConfigPath(loader, pkgName, pkgConfigPath) { 2541 var configLoader = loader.pluginLoader || loader; 2542 2543 // NB remove this when json is default 2544 (configLoader.meta[pkgConfigPath] = configLoader.meta[pkgConfigPath] || {}).format = 'json'; 2545 configLoader.meta[pkgConfigPath].loader = null; 2546 2547 return configLoader.load(pkgConfigPath) 2548 .then(function() { 2549 var cfg = configLoader.get(pkgConfigPath)['default']; 2550 2551 // support "systemjs" prefixing 2552 if (cfg.systemjs) 2553 cfg = cfg.systemjs; 2554 2555 // modules backwards compatibility 2556 if (cfg.modules) { 2557 cfg.meta = cfg.modules; 2558 warn.call(loader, 'Package config file ' + pkgConfigPath + ' is configured with "modules", which is deprecated as it has been renamed to "meta".'); 2559 } 2560 2561 // remove any non-system properties if generic config file (eg package.json) 2562 for (var p in cfg) { 2563 if (indexOf.call(packageProperties, p) == -1) 2564 delete cfg[p]; 2565 } 2566 2567 // deeply-merge (to first level) config with any existing package config 2568 var pkg = loader.packages[pkgName] = loader.packages[pkgName] || {}; 2569 extendMeta(pkg, cfg, true); 2570 2571 // support external depCache 2572 if (cfg.depCache) { 2573 for (var d in cfg.depCache) { 2574 var dNormalized; 2575 2576 if (d.substr(0, 2) == './') 2577 dNormalized = pkgName + '/' + d.substr(2); 2578 else 2579 dNormalized = coreResolve.call(loader, d); 2580 loader.depCache[dNormalized] = (loader.depCache[dNormalized] || []).concat(cfg.depCache[d]); 2581 } 2582 delete cfg.depCache; 2583 } 2584 2585 // main object becomes main map 2586 if (typeof pkg.main == 'object') { 2587 pkg.map = pkg.map || {}; 2588 pkg.map['./@main'] = pkg.main; 2589 pkg.main['default'] = pkg.main['default'] || './'; 2590 pkg.main = '@main'; 2591 } 2592 2593 return pkg; 2594 }); 2595 } 2596 2597 function getMetaMatches(pkgMeta, subPath, matchFn) { 2598 // wildcard meta 2599 var meta = {}; 2600 var wildcardIndex; 2601 for (var module in pkgMeta) { 2602 // allow meta to start with ./ for flexibility 2603 var dotRel = module.substr(0, 2) == './' ? './' : ''; 2604 if (dotRel) 2605 module = module.substr(2); 2606 2607 wildcardIndex = module.indexOf('*'); 2608 if (wildcardIndex === -1) 2609 continue; 2610 2611 if (module.substr(0, wildcardIndex) == subPath.substr(0, wildcardIndex) 2612 && module.substr(wildcardIndex + 1) == subPath.substr(subPath.length - module.length + wildcardIndex + 1)) { 2613 // alow match function to return true for an exit path 2614 if (matchFn(module, pkgMeta[dotRel + module], module.split('/').length)) 2615 return; 2616 } 2617 } 2618 // exact meta 2619 var exactMeta = pkgMeta[subPath] && pkgMeta.hasOwnProperty && pkgMeta.hasOwnProperty(subPath) ? pkgMeta[subPath] : pkgMeta['./' + subPath]; 2620 if (exactMeta) 2621 matchFn(exactMeta, exactMeta, 0); 2622 } 2623 2624 hook('locate', function(locate) { 2625 return function(load) { 2626 var loader = this; 2627 return Promise.resolve(locate.call(this, load)) 2628 .then(function(address) { 2629 var pkgName = getPackage(loader, load.name); 2630 if (pkgName) { 2631 var pkg = loader.packages[pkgName]; 2632 var subPath = load.name.substr(pkgName.length + 1); 2633 2634 // format 2635 if (pkg.format) 2636 load.metadata.format = load.metadata.format || pkg.format; 2637 2638 var meta = {}; 2639 if (pkg.meta) { 2640 var bestDepth = 0; 2641 2642 // NB support a main shorthand in meta here? 2643 getMetaMatches(pkg.meta, subPath, function(metaPattern, matchMeta, matchDepth) { 2644 if (matchDepth > bestDepth) 2645 bestDepth = matchDepth; 2646 extendMeta(meta, matchMeta, matchDepth && bestDepth >
2646 matchDepth); 2647 }); 2648 2649 extendMeta(load.metadata, meta); 2650 } 2651 } 2652 2653 return address; 2654 }); 2655 }; 2656 }); 2657 2658})(); 2659/* 2660 * Script tag fetch 2661 * 2662 * When load.metadata.scriptLoad is true, we load via script tag injection. 2663 */ 2664(function() { 2665 2666 if (typeof document != 'undefined') 2667 var head = document.getElementsByTagName('head')[0]; 2668 2669 var curSystem; 2670 var curRequire; 2671 2672 // if doing worker executing, this is set to the load record being executed 2673 var workerLoad = null; 2674 2675 // interactive mode handling method courtesy RequireJS 2676 var ieEvents = head && (function() { 2677 var s = document.createElement('script'); 2678 var isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]'; 2679 return s.attachEvent && !(s.attachEvent.toString && s.attachEvent.toString().indexOf('[native code') < 0) && !isOpera; 2680 })(); 2681 2682 // IE interactive-only part 2683 // we store loading scripts array as { script: <script>, load: {...} } 2684 var interactiveLoadingScripts = []; 2685 var interactiveScript; 2686 function getInteractiveScriptLoad() { 2687 if (interactiveScript && interactiveScript.script.readyState === 'interactive') 2688 return interactiveScript.load; 2689 2690 for (var i = 0; i < interactiveLoadingScripts.length; i++) 2691 if (interactiveLoadingScripts[i].script.readyState == 'interactive') { 2692 interactiveScript = interactiveLoadingScripts[i]; 2693 return interactiveScript.load; 2694 } 2695 } 2696 2697 // System.register, System.registerDynamic, AMD define pipeline 2698 // this is called by the above methods when they execute 2699 // we then run the reduceRegister_ collection function either immediately 2700 // if we are in IE and know the currently executing script (interactive) 2701 // or later if we need to wait for the synchronous load callback to know the script 2702 var loadingCnt = 0; 2703 var registerQueue = []; 2704 hook('pushRegister_', function(pushRegister) { 2705 return function(register) { 2706 // if using eval-execution then skip 2707 if (pushRegister.call(this, register)) 2708 return false; 2709 2710 // if using worker execution, then we're done 2711 if (workerLoad) 2712 this.reduceRegister_(workerLoad, register); 2713 2714 // detect if we know the currently executing load (IE) 2715 // if so, immediately call reduceRegister 2716 else if (ieEvents) 2717 this.reduceRegister_(getInteractiveScriptLoad(), register); 2718 2719 // otherwise, add to our execution queue 2720 // to call reduceRegister on sync script load event 2721 else if (loadingCnt) 2722 registerQueue.push(register); 2723 2724 // if we're not currently loading anything though 2725 // then do the reduction against a null load 2726 // (out of band named define or named register) 2727 // note even in non-script environments, this catch is used 2728 else 2729 this.reduceRegister_(null, register); 2730 2731 return true; 2732 }; 2733 }); 2734 2735 function webWorkerImport(loader, load) { 2736 return new Promise(function(resolve, reject) { 2737 if (load.metadata.integrity) 2738 reject(new Error('Subresource integrity checking is not supported in web workers.')); 2739 2740 workerLoad = load; 2741 try { 2742 importScripts(load.address); 2743 } 2744 catch(e) { 2745 workerLoad = null; 2746 reject(e); 2747 } 2748 workerLoad = null; 2749 2750 // if nothing registered, then something went wrong 2751 if (!load.metadata.entry) 2752 reject(new Error(load.address + ' did not call System.register or AMD define')); 2753 2754 resolve(''); 2755 }); 2756 } 2757 2758 // override fetch to use script injection 2759 hook('fetch', function(fetch) { 2760 return function(load) { 2761 var loader = this; 2762 2763 if (load.metadata.format == 'json' || !load.metadata.scriptLoad || (!isBrowser && !isWorker)) 2764 return fetch.call(this, load); 2765 2766 if (isWorker) 2767 return webWorkerImport(loader, load); 2768 2769 return new Promise(function(resolve, reject) { 2770 var s = document.createElement('script'); 2771 2772 s.async = true; 2773 2774 if (load.metadata.crossOrigin) 2775 s.crossOrigin = load.metadata.crossOrigin; 2776 2777 if (load.metadata.integrity) 2778 s.setAttribute('integrity', load.metadata.integrity); 2779 2780 if (ieEvents) { 2781 s.attachEvent('onreadystatechange', complete); 2782 interactiveLoadingScripts.push({ 2783 script: s, 2784 load: load 2785 }); 2786 } 2787 else { 2788 s.addEventListener('load', complete, false); 2789 s.addEventListener('error', error, false); 2790 } 2791 2792 loadingCnt++; 2793 2794 curSystem = __global.System; 2795 curRequire = __global.require; 2796 2797 s.src = load.address; 2798 head.appendChild(s); 2799 2800 function complete(evt) { 2801 if (s.readyState && s.readyState != 'loaded' && s.readyState != 'complete') 2802 return; 2803 2804 loadingCnt--; 2805 2806 // complete call is sync on execution finish 2807 // (in ie already done reductions) 2808 if (!load.metadata.entry && !registerQueue.length) { 2809 loader.reduceRegister_(load); 2810 } 2811 else if (!ieEvents) { 2812 for (var i = 0; i < registerQueue.length; i++) 2813 loader.reduceRegister_(load, registerQueue[i]); 2814 registerQueue = []; 2815 } 2816 2817 cleanup(); 2818 2819 // if nothing registered, then something went wrong 2820 if (!load.metadata.entry && !load.metadata.bundle) 2821 reject(new Error(load.name + ' did not call System.register or AMD define. If loading a global module configure the global name via the meta exports property for script injection support.')); 2822 2823 resolve(''); 2824 } 2825 2826 function error(evt) { 2827 cleanup(); 2828 reject(new Error('Unable to load script ' + load.address)); 2829 } 2830 2831 function cleanup() { 2832 __global.System = curSystem; 2833 __global.require = curRequire; 2834 2835 if (s.detachEvent) { 2836 s.detachEvent('onreadystatechange', complete); 2837 for (var i = 0; i < interactiveLoadingScripts.length; i++) 2838 if (interactiveLoadingScripts[i].script == s) { 2839 if (interactiveScript && interactiveScript.script == s) 2840 interactiveScript = null; 2841 interactiveLoadingScripts.splice(i, 1); 2842 } 2843 } 2844 else { 2845 s.removeEventListener('load', complete, false); 2846 s.removeEventListener('error', error, false); 2847 } 2848 2849 head.removeChild(s); 2850 } 2851 }); 2852 }; 2853 }); 2854})(); 2855/* 2856 * Instantiate registry extension 2857 * 2858 * Supports Traceur System.register 'instantiate' output for loading ES6 as ES5. 2859 * 2860 * - Creates the loader.register function 2861 * - Also supports metadata.format = 'register' in instantiate for anonymous register modules 2862 * - Also supports metadata.deps, metadata.execute and metadata.executingRequire 2863 * for handling dynamic modules alongside register-transformed ES6 modules 2864 * 2865 * 2866 * The code here replicates the ES6 linking groups algorithm to ensure that 2867 * circular ES6 compiled into System.register can work alongside circular AMD 2868 * and CommonJS, identically to the actual ES6 loader. 2869 * 2870 */ 2871 2872 2873/*
2874 * Registry side table entries in loader.defined 2875 * Registry Entry Contains: 2876 * - name 2877 * - deps 2878 * - declare for declarative modules 2879 * - execute for dynamic modules, different to declarative execute on module 2880 * - executingRequire indicates require drives execution for circularity of dynamic modules 2881 * - declarative optional boolean indicating which of the above 2882 * 2883 * Can preload modules directly on SystemJS.defined['my/module'] = { deps, execute, executingRequire } 2884 * 2885 * Then the entry gets populated with derived information during processing: 2886 * - normalizedDeps derived from deps, created in instantiate 2887 * - groupIndex used by group linking algorithm 2888 * - evaluated indicating whether evaluation has happend 2889 * - module the module record object, containing: 2890 * - exports actual module exports 2891 * 2892 * For dynamic we track the es module with: 2893 * - esModule actual es module value 2894 * - esmExports whether to extend the esModule with named exports 2895 * 2896 * Then for declarative only we track dynamic bindings with the 'module' records: 2897 * - name 2898 * - exports 2899 * - setters declarative setter functions 2900 * - dependencies, module records of dependencies 2901 * - importers, module records of dependents 2902 * 2903 * After linked and evaluated, entries are removed, declarative module records remain in separate 2904 * module binding table 2905 * 2906 */ 2907 2908var leadingCommentAndMetaRegEx = /^(\s*\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)*\s*/; 2909function detectRegisterFormat(source) { 2910 var leadingCommentAndMeta = source.match(leadingCommentAndMetaRegEx); 2911 return leadingCommentAndMeta && source.substr(leadingCommentAndMeta[0].length, 15) == 'System.register'; 2912} 2913 2914function createEntry() { 2915 return { 2916 name: null, 2917 deps: null, 2918 originalIndices: null, 2919 declare: null, 2920 execute: null, 2921 executingRequire: false, 2922 declarative: false, 2923 normalizedDeps: null, 2924 groupIndex: null, 2925 evaluated: false, 2926 module: null, 2927 esModule: null, 2928 esmExports: false 2929 }; 2930} 2931 2932(function() { 2933 2934 /* 2935 * There are two variations of System.register: 2936 * 1. System.register for ES6 conversion (2-3 params) - System.register([name, ]deps, declare) 2937 * see https://github.com/ModuleLoader/es6-module-loader/wiki/System.register-Explained 2938 * 2939 * 2. System.registerDynamic for dynamic modules (3-4 params) - System.registerDynamic([name, ]deps, executingRequire, execute) 2940 * the true or false statement 2941 * 2942 * this extension implements the linking algorithm for the two variations identical to the spec 2943 * allowing compiled ES6 circular references to work alongside AMD and CJS circular references. 2944 * 2945 */ 2946 SystemJSLoader.prototype.register = function(name, deps, declare) { 2947 if (typeof name != 'string') { 2948 declare = deps; 2949 deps = name; 2950 name = null; 2951 } 2952 2953 // dynamic backwards-compatibility 2954 // can be deprecated eventually 2955 if (typeof declare == 'boolean') 2956 return this.registerDynamic.apply(this, arguments); 2957 2958 var entry = createEntry(); 2959 // ideally wouldn't apply map config to bundle names but 2960 // dependencies go through map regardless so we can't restrict 2961 // could reconsider in shift to new spec 2962 entry.name = name && (this.decanonicalize || this.normalize).call(this, name); 2963 entry.declarative = true; 2964 entry.deps = deps; 2965 entry.declare = declare; 2966 2967 this.pushRegister_({ 2968 amd: false, 2969 entry: entry 2970 }); 2971 }; 2972 SystemJSLoader.prototype.registerDynamic = function(name, deps, declare, execute) { 2973 if (typeof name != 'string') { 2974 execute = declare; 2975 declare = deps; 2976 deps = name; 2977 name = null; 2978 } 2979 2980 // dynamic 2981 var entry = createEntry(); 2982 entry.name = name && (this.decanonicalize || this.normalize).call(this, name); 2983 entry.deps = deps; 2984 entry.execute = execute; 2985 entry.executingRequire = declare; 2986 2987 this.pushRegister_({ 2988 amd: false, 2989 entry: entry 2990 }); 2991 }; 2992 hook('reduceRegister_', function() { 2993 return function(load, register) { 2994 if (!register) 2995 return; 2996 2997 var entry = register.entry; 2998 var curMeta = load && load.metadata; 2999 3000 // named register 3001 if (entry.name) { 3002 if (!(entry.name in this.defined)) 3003 this.defined[entry.name] = entry; 3004 3005 if (curMeta) 3006 curMeta.bundle = true; 3007 } 3008 // anonymous register 3009 if (!entry.name || load && entry.name == load.name) { 3010 if (!curMeta) 3011 throw new TypeError('Invalid System.register call. Anonymous System.register calls can only be made by modules loaded by SystemJS.import and n
3011ot via script tags.'); 3012 if (curMeta.entry) { 3013 if (curMeta.format == 'register') 3014 throw new Error('Multiple anonymous System.register calls in module ' + load.name + '. If loading a bundle, ensure all the System.register calls are named.'); 3015 else 3016 throw new Error('Module ' + load.name + ' interpreted as ' + curMeta.format + ' module format, but called System.register.'); 3017 } 3018 if (!curMeta.format) 3019 curMeta.format = 'register'; 3020 curMeta.entry = entry; 3021 } 3022 }; 3023 }); 3024 3025 hookConstructor(function(constructor) { 3026 return function() { 3027 constructor.call(this); 3028 3029 this.defined = {}; 3030 this._loader.moduleRecords = {}; 3031 }; 3032 }); 3033 3034 function buildGroups(entry, loader, groups) { 3035 groups[entry.groupIndex] = groups[entry.groupIndex] || []; 3036 3037 if (indexOf.call(groups[entry.groupIndex], entry) != -1) 3038 return; 3039 3040 groups[entry.groupIndex].push(entry); 3041 3042 for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) { 3043 var depName = entry.normalizedDeps[i]; 3044 var depEntry = loader.defined[depName]; 3045 3046 // not in the registry means already linked / ES6 3047 if (!depEntry || depEntry.evaluated) 3048 continue; 3049 3050 // now we know the entry is in our unlinked linkage group 3051 var depGroupIndex = entry.groupIndex + (depEntry.declarative != entry.declarative); 3052 3053 // the group index of an entry is always the maximum 3054 if (depEntry.groupIndex === null || depEntry.groupIndex < depGroupIndex) { 3055 3056 // if already in a group, remove from the old group 3057 if (depEntry.groupIndex !== null) { 3058 groups[depEntry.groupIndex].splice(indexOf.call(groups[depEntry.groupIndex], depEntry), 1); 3059 3060 // if the old group is empty, then we have a mixed depndency cycle 3061 if (groups[depEntry.groupIndex].length == 0) 3062 throw new Error("Mixed dependency cycle detected"); 3063 } 3064 3065 depEntry.groupIndex = depGroupIndex; 3066 } 3067 3068 buildGroups(depEntry, loader, groups); 3069 } 3070 } 3071 3072 function link(name, loader) { 3073 var startEntry = loader.defined[name]; 3074 3075 // skip if already linked 3076 if (startEntry.module) 3077 return; 3078 3079 startEntry.groupIndex = 0; 3080 3081 var groups = []; 3082 3083 buildGroups(startEntry, loader, groups); 3084 3085 var curGroupDeclarative = !!startEntry.declarative == groups.length % 2; 3086 for (var i = groups.length - 1; i >= 0; i--) { 3087 var group = groups[i]; 3088 for (var j = 0; j < group.length; j++) { 3089 var entry = group[j]; 3090 3091 // link each group 3092 if (curGroupDeclarative) 3093 linkDeclarativeModule(entry, loader); 3094 else 3095 linkDynamicModule(entry, loader); 3096 } 3097 curGroupDeclarative = !curGroupDeclarative; 3098 } 3099 } 3100 3101 // module binding records 3102 function ModuleRecord() {} 3103 defineProperty(ModuleRecord, 'toString', { 3104 value: function() { 3105 return 'Module'; 3106 } 3107 }); 3108 3109 function getOrCreateModuleRecord(name, moduleRecords) { 3110 return moduleRecords[name] || (moduleRecords[name] = { 3111 name: name, 3112 dependencies: [], 3113 exports: new ModuleRecord(), // start from an empty module and extend 3114 importers: [] 3115 }); 3116 } 3117 3118 function linkDeclarativeModule(entry, loader) { 3119 // only link if already not already started linking (stops at circular) 3120 if (entry.module) 3121 return; 3122 3123 var moduleRecords = loader._loader.moduleRecords; 3124 var module = entry.module = getOrCreateModuleRecord(entry.name, moduleRecords); 3125 var exports = entry.module.exports; 3126 3127 var declaration = entry.declare.call(__global, function(name, value) { 3128 module.locked = true; 3129 3130 if (typeof name == 'object') { 3131 for (var p in name) 3132 exports[p] = name[p]; 3133 } 3134 else { 3135 exports[name] = value; 3136 } 3137 3138 for (var i = 0, l = module.importers.length; i < l; i++) { 3139 var importerModule = module.importers[i]; 3140 if (!importerModule.locked) { 3141 var importerIndex = indexOf.call(importerModule.dependencies, module); 3142 importerModule.setters[importerIndex](exports); 3143 } 3144 } 3145 3146 module.locked = false;
3147 return value; 3148 }, { id: entry.name }); 3149 3150 module.setters = declaration.setters; 3151 module.execute = declaration.execute; 3152 3153 if (!module.setters || !module.execute) { 3154 throw new TypeError('Invalid System.register form for ' + entry.name); 3155 } 3156 3157 // now link all the module dependencies 3158 for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) { 3159 var depName = entry.normalizedDeps[i]; 3160 var depEntry = loader.defined[depName]; 3161 var depModule = moduleRecords[depName]; 3162 3163 // work out how to set depExports based on scenarios... 3164 var depExports; 3165 3166 if (depModule) { 3167 depExports = depModule.exports; 3168 } 3169 // dynamic, already linked in our registry 3170 else if (depEntry && !depEntry.declarative) { 3171 depExports = depEntry.esModule; 3172 } 3173 // in the loader registry 3174 else if (!depEntry) { 3175 depExports = loader.get(depName); 3176 } 3177 // we have an entry -> link 3178 else { 3179 linkDeclarativeModule(depEntry, loader); 3180 depModule = depEntry.module; 3181 depExports = depModule.exports; 3182 } 3183 3184 // only declarative modules have dynamic bindings 3185 if (depModule && depModule.importers) { 3186 depModule.importers.push(module); 3187 module.dependencies.push(depModule); 3188 } 3189 else { 3190 module.dependencies.push(null); 3191 } 3192 3193 // run setters for all entries with the matching dependency name 3194 var originalIndices = entry.originalIndices[i]; 3195 for (var j = 0, len = originalIndices.length; j < len; ++j) { 3196 var index = originalIndices[j]; 3197 if (module.setters[index]) { 3198 module.setters[index](depExports); 3199 } 3200 } 3201 } 3202 } 3203 3204 // An analog to loader.get covering execution of all three layers (real declarative, simulated declarative, simulated dynamic) 3205 function getModule(name, loader) { 3206 var exports; 3207 var entry = loader.defined[name]; 3208 3209 if (!entry) { 3210 exports = loader.get(name); 3211 if (!exports) 3212 throw new Error('Unable to load dependency ' + name + '.'); 3213 } 3214 3215 else { 3216 if (entry.declarative) 3217 ensureEvaluated(name, [], loader); 3218 3219 else if (!entry.evaluated) 3220 linkDynamicModule(entry, loader); 3221 3222 exports = entry.module.exports; 3223 } 3224 3225 if ((!entry || entry.declarative) && exports && exports.__useDefault) 3226 return exports['default']; 3227 3228 return exports; 3229 } 3230 3231 function linkDynamicModule(entry, loader) { 3232 if (entry.module) 3233 return; 3234 3235 var exports = {}; 3236 3237 var module = entry.module = { exports: exports, id: entry.name }; 3238 3239 // AMD requires execute the tree first 3240 if (!entry.executingRequire) { 3241 for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) { 3242 var depName = entry.normalizedDeps[i]; 3243 // we know we only need to link dynamic due to linking algorithm 3244 var depEntry = loader.defined[depName]; 3245 if (depEntry) 3246 linkDynamicModule(depEntry, loader); 3247 } 3248 } 3249 3250 // now execute 3251 entry.evaluated = true; 3252 var output = entry.execute.call(__global, function(name) { 3253 for (var i = 0, l = entry.deps.length; i < l; i++) { 3254 if (entry.deps[i] != name) 3255 continue; 3256 return getModule(entry.normalizedDeps[i], loader); 3257 } 3258 // try and normalize the dependency to see if we have another form 3259 var nameNormalized = loader.normalizeSync(name, entry.name); 3260 if (indexOf.call(entry.normalizedDeps, nameNormalized) != -1) 3261 return getModule(nameNormalized, loader); 3262 3263 throw new Error('Module ' + name + ' not declared as a dependency of ' + entry.name); 3264 }, exports, module); 3265 3266 if (output) 3267 module.exports = output; 3268 3269 // create the esModule object, which allows ES6 named imports of dynamics 3270 exports = module.exports; 3271 3272 // __esModule flag treats as already-named 3273 if (exports && (exports.__esModule || exports instanceof Module)) 3274 entry.esModule = exports; 3275 // set module as 'default' export, then fake named exports by iterating properties 3276 else if (entry.esmExports && exports !== __global) 3277 entry.esModule = getESModule(exports); 3278 // just use the 'default' export 3279 else 3280 entry.esModule = { 'default': exports }; 3281 } 3282 3283 /* 3284 * Given a module, and the list of modules for this current branch, 3285 * ensure that each of the dependencies of this module is evaluated 3286 * (unless one is a circular dependency already in the list of seen 3287 * modules, in which case we execute it) 3288 * 3289 * Then we evaluate the module itself depth-first left to right 3290 * execution to match ES6 modules 3291 */ 3292 function ensureEvaluated(moduleName, seen, loader) { 3293 var entry = loader.defined[moduleName]; 3294 3295 // if already seen, that means it's an already-evaluated non circular dependency 3296 if (!entry || entry.evaluated || !entry.declarative) 3297 return; 3298 3299 // this only applies to declarative modules which late-execute 3300 3301 seen.push(moduleName); 3302 3303 for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) { 3304 var depName = entry.normalizedDeps[i]; 3305 if (indexOf.call(seen, depName) == -1) { 3306 if (!loader.defined[depName]) 3307 loader.get(depName); 3308 else 3309 ensureEvaluated(depName, seen, loader); 3310 } 3311 } 3312 3313 if (entry.evaluated) 3314 return; 3315 3316 entry.evaluated = true; 3317 entry.module.execute.call(__global); 3318 } 3319 3320 // override the delete method to also clear the register caches 3321 hook('delete', function(del) { 3322 return function(name) { 3323 delete this._loader.moduleRecords[name]; 3324 delete this.defined[name]; 3325 return del.call(this, name); 3326 }; 3327 }); 3328 3329 hook('fetch', function(fetch) { 3330 return function(load) { 3331 if (this.defined[load.name]) { 3332 load.metadata.format = 'defined'; 3333 return ''; 3334 } 3335 3336 load.metadata.deps = load.metadata.deps || []; 3337 3338 return fetch.call(this, load); 3339 }; 3340 }); 3341 3342 hook('translate', function(translate) { 3343 // we run the meta detection here (register is after meta) 3344 return function(load) { 3345 load.metadata.deps = load.metadata.deps || []; 3346 return Promise.resolve(translate.call(this, load)).then(function(source) { 3347 // run detection for register format 3348 if (load.metadata.format == 'register' || !load.metadata.format && detectRegisterFormat(load.source)) 3349 load.metadata.format = 'register'; 3350 return source; 3351 }); 3352 }; 3353 }); 3354 3355 hook('instantiate', function(instantiate) { 3356 return function(load) { 3357 if (load.metadata.format == 'detect') 3358 load.metadata.format = undefined; 3359 3360 // assumes previous instantiate is sync 3361 // (core json support) 3362 instantiate.call(this, load); 3363 3364 var loader = this; 3365 3366 var entry; 3367 3368 // first we check if this module has already been defined in the registry 3369 if (loader.defined[load.name]) { 3370 entry = loader.defined[load.name]; 3371 // don't support deps for ES modules 3372 if (!entry.declarative) 3373 entry.deps = entry.deps.concat(load.metadata.deps); 3374 } 3375 3376 // picked up already by an anonymous System.register script injection 3377 // or via the dynamic formats 3378 else if (load.metadata.entry) { 3379 entry = load.metadata.entry; 3380 entry.deps = entry.deps.concat(load.metadata.deps); 3381 } 3382 3383 // Contains System.register calls 3384 // (dont run bundles in the builder) 3385 else if (!(loader.builder && load.metadata.bundle) 3386 && (load.metadata.format == 'register' || load.metadata.format == 'esm' || load.metadata.format == 'es6')) { 3387 3388 if (typeof __exec != 'undefined') 3389 __exec.call(loader, load); 3390 3391 if (!load.metadata.entry && !load.metadata.bundle) 3392 throw new Error(load.name + ' detected as ' + load.metadata.format + ' but didn\'t execute.'); 3393 3394 entry = load.metadata.entry; 3395 3396 // support metadata deps for System.register 3397 if (entry && load.metadata.deps) 3398 entry.deps = entry.deps.concat(load.metadata.deps); 3399 } 3400 3401 // named bundles are just an empty module 3402 if (!entry) { 3403 entry = createEntry(); 3404 entry.deps = load.metadata.deps; 3405 entry.execute = function() {}; 3406 } 3407 3408 // place this module onto defined for circular references 3409 loader.defined[load.name] = entry; 3410
3411 var grouped = group(entry.deps); 3412 3413 entry.deps = grouped.names; 3414 entry.originalIndices = grouped.indices; 3415 entry.name = load.name; 3416 entry.esmExports = load.metadata.esmExports !== false; 3417 3418 // first, normalize all dependencies 3419 var normalizePromises = []; 3420 for (var i = 0, l = entry.deps.length; i < l; i++) 3421 normalizePromises.push(Promise.resolve(loader.normalize(entry.deps[i], load.name))); 3422 3423 return Promise.all(normalizePromises).then(function(normalizedDeps) { 3424 3425 entry.normalizedDeps = normalizedDeps; 3426 3427 return { 3428 deps: entry.deps, 3429 execute: function() { 3430 // recursively ensure that the module and all its 3431 // dependencies are linked (with dependency group handling) 3432 link(load.name, loader); 3433 3434 // now handle dependency execution in correct order 3435 ensureEvaluated(load.name, [], loader); 3436 3437 // remove from the registry 3438 loader.defined[load.name] = undefined; 3439 3440 // return the defined module object 3441 return loader.newModule(entry.declarative ? entry.module.exports : entry.esModule); 3442 } 3443 }; 3444 }); 3445 }; 3446 }); 3447})(); 3448/* 3449 * Extension to detect ES6 and auto-load Traceur or Babel for processing 3450 */ 3451(function() { 3452 // good enough ES6 module detection regex - format detections not designed to be accurate, but to handle the 99% use case 3453 var esmRegEx = /(^\s*|[}\);\n]\s*)(import\s*(['"]|(\*\s+as\s+)?[^"'\(\)\n;]+\s*from\s*['"]|\{)|export\s+\*\s+from\s+["']|export\s*(\{|default|function|class|var|const|let|async\s+function))/; 3454 3455 var traceurRuntimeRegEx = /\$traceurRuntime\s*\./; 3456 var babelHelpersRegEx = /babelHelpers\s*\./; 3457 3458 hook('translate', function(translate) { 3459 return function(load) { 3460 var loader = this; 3461 return translate.call(loader, load) 3462 .then(function(source) { 3463 // detect & transpile ES6 3464 if (load.metadata.format == 'esm' || load.metadata.format == 'es6' || !load.metadata.format && source.match(esmRegEx)) { 3465 if (load.metadata.format == 'es6') 3466 warn.call(loader, 'Module ' + load.name + ' has metadata setting its format to "es6", which is deprecated.\nThis should be updated to "esm".'); 3467 3468 load.metadata.format = 'esm'; 3469 3470 if (loader.transpiler === false) { 3471 // we accept translation to esm for builds though to enable eg rollup optimizations 3472 if (loader.builder) 3473 return source; 3474 throw new TypeError('Unable to dynamically transpile ES module as SystemJS.transpiler set to false.'); 3475 } 3476 3477 // setting _loader.loadedTranspiler = false tells the next block to 3478 // do checks for setting transpiler metadata 3479 loader._loader.loadedTranspiler = loader._loader.loadedTranspiler || false; 3480 if (loader.pluginLoader) 3481 loader.pluginLoader._loader.loadedTranspiler = loader._loader.loadedTranspiler || false; 3482 3483 // do transpilation 3484 return (loader._loader.transpilerPromise || ( 3485 loader._loader.transpilerPromise = Promise.resolve( 3486 __global[loader.transpiler == 'typescript' ? 'ts' : loader.transpiler] || (loader.pluginLoader || loader)['import'](loader.transpiler) 3487 ))).then(function(transpiler) { 3488 loader._loader.loadedTranspilerRuntime = true; 3489 3490 // translate hooks means this is a transpiler plugin instead of a raw implementation 3491 if (transpiler.translate) { 3492 // if transpiler is the same as the plugin loader, then don't run twice 3493 if (transpiler == load.metadata.loaderModule) 3494 return load.source; 3495 3496 // convert the source map into an object for transpilation chaining 3497 if (typeof load.metadata.sourceMap == 'string') 3498 load.metadata.sourceMap = JSON.parse(load.metadata.sourceMap); 3499 3500 return Promise.resolve(transpiler.translate.call(loader, load)) 3501 .then(function(source) { 3502 // sanitize sourceMap if an object not a JSON string 3503 var sourceMap = load.metadata.sourceMap; 3504 if (sourceMap && typeof sourceMap == 'object') { 3505 var originalName = load.name.split('!')[0]; 3506 3507 // force set the filename of the original file
3508 sourceMap.file = originalName + '!transpiled'; 3509 3510 // force set the sources list if only one source 3511 if (!sourceMap.sources || sourceMap.sources.length <= 1) 3512 sourceMap.sources = [originalName]; 3513 } 3514 3515 if (load.metadata.format == 'esm' && !loader.builder && detectRegisterFormat(source)) 3516 load.metadata.format = 'register'; 3517 return source; 3518 }); 3519 } 3520 3521 // legacy builder support 3522 if (loader.builder) 3523 load.metadata.originalSource = load.source; 3524 3525 // defined in es6-module-loader/src/transpile.js 3526 return transpile.call(loader, load) 3527 .then(function(source) { 3528 // clear sourceMap as transpiler embeds it 3529 load.metadata.sourceMap = undefined; 3530 return source; 3531 }); 3532 }); 3533 } 3534 3535 // skip transpiler and transpiler runtime loading when transpiler is disabled 3536 if (loader.transpiler === false) 3537 return source; 3538 3539 // load the transpiler correctly 3540 if (loader._loader.loadedTranspiler === false && (loader.transpiler == 'traceur' || loader.transpiler == 'typescript' || loader.transpiler == 'babel') 3541 && load.name == loader.normalizeSync(loader.transpiler)) { 3542 3543 // always load transpiler as a global 3544 if (source.length > 100 && !load.metadata.format) { 3545 load.metadata.format = 'global'; 3546 3547 if (loader.transpiler === 'traceur') 3548 load.metadata.exports = 'traceur'; 3549 if (loader.transpiler === 'typescript') 3550 load.metadata.exports = 'ts'; 3551 } 3552 3553 loader._loader.loadedTranspiler = true; 3554 } 3555 3556 // load the transpiler runtime correctly 3557 if (loader._loader.loadedTranspilerRuntime === false) { 3558 if (load.name == loader.normalizeSync('traceur-runtime') 3559 || load.name == loader.normalizeSync('babel/external-helpers*')) { 3560 if (source.length > 100) 3561 load.metadata.format = load.metadata.format || 'global'; 3562 3563 loader._loader.loadedTranspilerRuntime = true; 3564 } 3565 } 3566 3567 // detect transpiler runtime usage to load runtimes 3568 if ((load.metadata.format == 'register' || load.metadata.bundle) && loader._loader.loadedTranspilerRuntime !== true) { 3569 if (!__global.$traceurRuntime && load.source.match(traceurRuntimeRegEx)) { 3570 loader._loader.loadedTranspilerRuntime = loader._loader.loadedTranspilerRuntime || false; 3571 return loader['import']('traceur-runtime').then(function() { 3572 return source; 3573 }); 3574 } 3575 if (!__global.babelHelpers && load.source.match(babelHelpersRegEx)) { 3576 loader._loader.loadedTranspilerRuntime = loader._loader.loadedTranspilerRuntime || false; 3577 return loader['import']('babel/external-helpers').then(function() { 3578 return source; 3579 }); 3580 } 3581 } 3582 3583 return source; 3584 }); 3585 }; 3586 }); 3587 3588})(); 3589/* 3590 SystemJS Global Format 3591 3592 Supports 3593 metadata.deps 3594 metadata.globals 3595 metadata.exports 3596 3597 Without metadata.exports, detects writes to the global object. 3598*/ 3599var __globalName = typeof self != 'undefined' ? 'self' : 'global'; 3600 3601hook('fetch', function(fetch) { 3602 return function(load) { 3603 if (load.metadata.exports && !load.metadata.format) 3604 load.metadata.format = 'global'; 3605 return fetch.call(this, load); 3606 }; 3607}); 3608 3609// ideally we could support script loading for globals, but the issue with that is that 3610// we can't do it with AMD support side-by-side since AMD support means defining the 3611// global define, and global support means not definining it, yet we don't have any hook 3612// into the "pre-execution" phase of a script tag being loaded to handle both cases 3613hook('instantiate', function(instantiate) { 3614 return function(load) { 3615 var loader = this; 3616 3617 if (!load.metadata.format) 3618 load.metadata.format = 'global'; 3619 3620 // global is a fallback module format 3621 if (load.metadata.format == 'global' && !load.metadata.registered) { 3622 3623 var entry = createEntry(); 3624 3625 load.metadata.entry = entry; 3626 3627 entry.deps = []; 3628 3629 for (var g in load.metadata.globals) { 3630 var gl = load.metadata.globals[g]; 3631 if (gl) 3632 entry.deps.push(gl); 3633 } 3634 3635 entry.execute = function(require, exports, module) { 3636 3637 var globals; 3638 if (load.metadata.globals) { 3639 globals = {}; 3640 for (var g in load.metadata.globals) 3641 if (load.metadata.globals[g]) 3642 globals[g] = require(load.metadata.globals[g]); 3643 } 3644 3645 var exportName = load.metadata.exports; 3646 3647 if (exportName) 3648 load.source += '\n' + __globalName + '["' + exportName + '"] = ' + exportName + ';'; 3649 3650 var retrieveGlobal = loader.get('@@global-helpers').prepareGlobal(module.id, exportName, globals); 3651 3652 __exec.call(loader, load); 3653 3654 return retrieveGlobal(); 3655 } 3656 } 3657 return instantiate.call(this, load); 3658 }; 3659}); 3660 3661 3662function getGlobalValue(exports) { 3663 if (typeof exports == 'string') 3664 return readMemberExpression(exports, __global); 3665 3666 if (!(exports instanceof Array)) 3667 throw new Error('Global exports must be a string or array.'); 3668 3669 var globalValue = {}; 3670 var first = true; 3671 for (var i = 0; i < exports.length; i++) { 3672 var val = readMemberExpression(exports[i], __global); 3673 if (first) { 3674 globalValue['default'] = val; 3675 first = false;
3676 } 3677 globalValue[exports[i].split('.').pop()] = val; 3678 } 3679 return globalValue; 3680} 3681 3682hook('reduceRegister_', function(reduceRegister) { 3683 return function(load, register) { 3684 if (register || !load.metadata.exports) 3685 return reduceRegister.call(this, load, register); 3686 3687 load.metadata.format = 'global'; 3688 var entry = load.metadata.entry = createEntry(); 3689 entry.deps = load.metadata.deps; 3690 var globalValue = getGlobalValue(load.metadata.exports); 3691 entry.execute = function() { 3692 return globalValue; 3693 }; 3694 }; 3695}); 3696 3697hookConstructor(function(constructor) { 3698 return function() { 3699 var loader = this; 3700 constructor.call(loader); 3701 3702 var hasOwnProperty = Object.prototype.hasOwnProperty; 3703 3704 // bare minimum ignores 3705 var ignoredGlobalProps = ['_g', 'sessionStorage', 'localStorage', 'clipboardData', 'frames', 'frameElement', 'external', 3706 'mozAnimationStartTime', 'webkitStorageInfo', 'webkitIndexedDB', 'mozInnerScreenY', 'mozInnerScreenX']; 3707 3708 var globalSnapshot; 3709 3710 function forEachGlobal(callback) { 3711 if (Object.keys) 3712 Object.keys(__global).forEach(callback); 3713 else 3714 for (var g in __global) { 3715 if (!hasOwnProperty.call(__global, g)) 3716 continue; 3717 callback(g); 3718 } 3719 } 3720 3721 function forEachGlobalValue(callback) { 3722 forEachGlobal(function(globalName) { 3723 if (indexOf.call(ignoredGlobalProps, globalName) != -1) 3724 return; 3725 try { 3726 var value = __global[globalName]; 3727 } 3728 catch (e) { 3729 ignoredGlobalProps.push(globalName); 3730 } 3731 callback(globalName, value); 3732 }); 3733 } 3734 3735 loader.set('@@global-helpers', loader.newModule({ 3736 prepareGlobal: function(moduleName, exports, globals) { 3737 // disable module detection 3738 var curDefine = __global.define; 3739 3740 __global.define = undefined; 3741 3742 // set globals 3743 var oldGlobals; 3744 if (globals) { 3745 oldGlobals = {}; 3746 for (var g in globals) { 3747 oldGlobals[g] = __global[g]; 3748 __global[g] = globals[g]; 3749 } 3750 } 3751 3752 // store a complete copy of the global object in order to detect changes 3753 if (!exports) { 3754 globalSnapshot = {}; 3755 3756 forEachGlobalValue(function(name, value) { 3757 globalSnapshot[name] = value; 3758 }); 3759 } 3760 3761 // return function to retrieve global 3762 return function() { 3763 var globalValue; 3764 3765 if (exports) { 3766 globalValue = getGlobalValue(exports); 3767 } 3768 else { 3769 globalValue = {}; 3770 var singleGlobal; 3771 var multipleExports; 3772 3773 forEachGlobalValue(function(name, value) { 3774 if (globalSnapshot[name] === value) 3775 return; 3776 if (typeof value == 'undefined') 3777 return; 3778 globalValue[name] = value; 3779 3780 if (typeof singleGlobal != 'undefined') { 3781 if (!multipleExports && singleGlobal !== value) 3782 multipleExports = true; 3783 } 3784 else { 3785 singleGlobal = value; 3786 } 3787 }); 3788 globalValue = multipleExports ? globalValue : singleGlobal; 3789 } 3790 3791 // revert globals 3792 if (oldGlobals) { 3793 for (var g in oldGlobals) 3794 __global[g] = oldGlobals[g]; 3795 } 3796 __global.define = curDefine; 3797 3798 return globalValue; 3799 }; 3800 } 3801 })); 3802 }; 3803}); 3804/* 3805 SystemJS CommonJS Format 3806*/ 3807(function() { 3808 // CJS Module Format 3809 // require('...') || exports[''] = ... || exports.asd = ... || module.exports = ... 3810 var cjsExportsRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])(exports\s*(\[['"]|\.)|module(\.exports|\['exports'\]|\["exports"\])\s*(\[['"]|[=,\.]))/; 3811 // RegEx adjusted from https://github.com/jbrantly/yabble/blob/master/lib/yabble.js#L339 3812 var cjsRequireRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF."'])require\s*\(\s*("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*')\s*\)/g; 3813 var commentRegEx = /(^|[^\\])(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg; 3814 3815 var stringRegEx = /("[^"\\\n\r]*(\\.[^"\\\n\r]*)*"|'[^'\\\n\r]*(\\.[^'\\\n\r]*)*')/g; 3816 3817 // used to support leading #!/usr/bin/env in scripts as supported in Node 3818 var hashBangRegEx = /^\#\!.*/; 3819 3820 function getCJSDeps(source) { 3821 cjsRequireRegEx.lastIndex = commentRegEx.lastIndex = stringRegEx.lastIndex = 0; 3822 3823 var deps = []; 3824 3825 var match; 3826 3827 // track string and comment locations for unminified source 3828 var stringLocations = [], commentLocations = []; 3829 3830 function inLocation(locations, match) { 3831 for (var i = 0; i < locations.length; i++) 3832 if (locations[i][0] < match.index && locations[i][1] > match.index) 3833 return true; 3834 return false;
3835 } 3836 3837 if (source.length / source.split('\n').length < 200) { 3838 while (match = stringRegEx.exec(source)) 3839 stringLocations.push([match.index, match.index + match[0].length]); 3840 3841 while (match = commentRegEx.exec(source)) { 3842 // only track comments not starting in strings 3843 if (!inLocation(stringLocations, match)) 3844 commentLocations.push([match.index, match.index + match[0].length]); 3845 } 3846 } 3847 3848 while (match = cjsRequireRegEx.exec(source)) { 3849 // ensure we're not within a string or comment location 3850 if (!inLocation(stringLocations, match) && !inLocation(commentLocations, match)) { 3851 var dep = match[1].substr(1, match[1].length - 2); 3852 // skip cases like require('" + file + "') 3853 if (dep.match(/"|'/)) 3854 continue; 3855 // trailing slash requires are removed as they don't map mains in SystemJS 3856 if (dep[dep.length - 1] == '/') 3857 dep = dep.substr(0, dep.length - 1); 3858 deps.push(dep); 3859 } 3860 } 3861 3862 return deps; 3863 } 3864 3865 hook('instantiate', function(instantiate) { 3866 return function(load) { 3867 var loader = this; 3868 if (!load.metadata.format) { 3869 cjsExportsRegEx.lastIndex = 0; 3870 cjsRequireRegEx.lastIndex = 0; 3871 if (cjsRequireRegEx.exec(load.source) || cjsExportsRegEx.exec(load.source)) 3872 load.metadata.format = 'cjs'; 3873 } 3874 3875 if (load.metadata.format == 'cjs') { 3876 var metaDeps = load.metadata.deps; 3877 var deps = load.metadata.cjsRequireDetection === false ? [] : getCJSDeps(load.source); 3878 3879 for (var g in load.metadata.globals) 3880 if (load.metadata.globals[g]) 3881 deps.push(load.metadata.globals[g]); 3882 3883 var entry = createEntry(); 3884 3885 load.metadata.entry = entry; 3886 3887 entry.deps = deps; 3888 entry.executingRequire = true; 3889 entry.execute = function(_require, exports, module) { 3890 function require(name) { 3891 if (name[name.length - 1] == '/') 3892 name = name.substr(0, name.length - 1); 3893 return _require.apply(this, arguments); 3894 } 3895 require.resolve = function(name) { 3896 return loader.get('@@cjs-helpers').requireResolve(name, module.id); 3897 }; 3898 3899 // ensure meta deps execute first 3900 if (!load.metadata.cjsDeferDepsExecute) 3901 for (var i = 0; i < metaDeps.length; i++) 3902 require(metaDeps[i]); 3903 3904 var pathVars = loader.get('@@cjs-helpers').getPathVars(module.id); 3905 var __cjsWrapper = { 3906 exports: exports, 3907 args: [require, exports, module, pathVars.filename, pathVars.dirname, __global, __global] 3908 }; 3909 3910 var cjsWrapper = "(function(require, exports, module, __filename, __dirname, global, GLOBAL"; 3911 3912 // add metadata.globals to the wrapper arguments 3913 if (load.metadata.globals) 3914 for (var g in load.metadata.globals) { 3915 __cjsWrapper.args.push(require(load.metadata.globals[g])); 3916 cjsWrapper += ", " + g; 3917 } 3918 3919 // disable AMD detection 3920 var define = __global.define; 3921 __global.define = undefined; 3922 __global.__cjsWrapper = __cjsWrapper; 3923 3924 load.source = cjsWrapper + ") {" + load.source.replace(hashBangRegEx, '') + "\n}).apply(__cjsWrapper.exports, __cjsWrapper.args);"; 3925 3926 __exec.call(loader, load); 3927 3928 __global.__cjsWrapper = undefined; 3929 __global.define = define; 3930 }; 3931 } 3932 3933 return instantiate.call(loader, load); 3934 }; 3935 }); 3936})(); 3937hookConstructor(function(constructor) { 3938 return function() { 3939 var loader = this; 3940 constructor.call(loader); 3941 3942 if (typeof window != 'undefined' && typeof document != 'undefined' && window.location) 3943 var windowOrigin = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : ''); 3944 3945 function stripOrigin(path) { 3946 if (path.substr(0, 8) == 'file:///') 3947 return path.substr(7 + !!isWindows); 3948 3949 if (windowOrigin && path.substr(0, windowOrigin.length) == windowOrigin) 3950 return path.substr(windowOrigin.length); 3951 3952 return path; 3953 } 3954 3955 loader.set('@@cjs-helpers', loader.newModule({ 3956 requireResolve: function(request, parentId) { 3957 return stripOrigin(loader.normalizeSync(request, parentId)); 3958 }, 3959 getPathVars: function(moduleId) { 3960 // remove any plugin syntax 3961 var pluginIndex = moduleId.lastIndexOf('!'); 3962 var filename; 3963 if (pluginIndex != -1) 3964 filename = moduleId.substr(0, pluginIndex); 3965 else 3966 filename = moduleId; 3967 3968 var dirname = filename.split('/'); 3969 dirname.pop(); 3970 dirname = dirname.join('/'); 3971 3972 return { 3973 filename: stripOrigin(filename), 3974 dirname: stripOrigin(dirname) 3975 }; 3976 } 3977 })) 3978 }; 3979});/* 3980 * AMD Helper function module 3981 * Separated into its own file as this is the part needed for full AMD support in SFX builds 3982 * NB since implementations have now diverged this can be merged back with amd.js 3983 */ 3984 3985hook('fetch', function(fetch) { 3986 return function(load) { 3987 // script load implies define global leak 3988 if (load.metadata.scriptLoad && isBrowser) 3989 __global.define = this.amdDefine; 3990 return fetch.call(this, load); 3991 }; 3992}); 3993 3994hookConstructor(function(constructor) { 3995 return function() { 3996 var loader = this; 3997 constructor.call(this); 3998 3999 var commentRegEx = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg; 4000 var cjsRequirePre = "(?:^|[^$_a-zA-Z\\xA0-\\uFFFF.])"; 4001 var cjsRequirePost = "\\s*\\(\\s*(\"([^\"]+)\"|'([^']+)')\\s*\\)"; 4002 var fnBracketRegEx = /\(([^\)]*)\)/; 4003 var wsRegEx = /^\s+|\s+$/g; 4004 4005 var requireRegExs = {}; 4006 4007 function getCJSDeps(source, requireIndex) { 4008 4009 // remove comments 4010 source = source.replace(commentRegEx, ''); 4011 4012 // determine the require alias 4013 var params = source.match(fnBracketRegEx); 4014 var requireAlias = (params[1].split(',')[requireIndex] || 'require').replace(wsRegEx, ''); 4015 4016 // find or generate the regex for this requireAlias 4017 var requireRegEx = requireRegExs[requireAlias] || (requireRegExs[requireAlias] = new RegExp(cjsRequirePre + requireAlias + cjsRequirePost, 'g')); 4018 4019 requireRegEx.lastIndex = 0; 4020 4021 var deps = []; 4022 4023 var match; 4024 while (match = requireRegEx.exec(source)) 4025 deps.push(match[2] || match[3]); 4026 4027 return deps; 4028 } 4029 4030 /* 4031 AMD-compatible require 4032 To copy RequireJS, set window.require = window.requirejs = loader.amdRequire 4033 */ 4034 function require(names, callback, errback, referer) { 4035 // in amd, first arg can be a config object... we just ignore 4036 if (typeof names == 'object' && !(names instanceof Array)) 4037 return require.apply(null, Array.prototype.splice.call(arguments, 1, arguments.length - 1)); 4038 4039 // amd require 4040 if (typeof names == 'string' && typeof callback == 'function') 4041 names = [names]; 4042 if (names instanceof Array) { 4043 var dynamicRequires = []; 4044 for (var i = 0; i < names.length; i++) 4045 dynamicRequires.push(loader['import'](names[i], referer)); 4046 Promise.all(dynamicRequires).then(function(modules) { 4047 if (callback) 4048 callback.apply(null, modules); 4049 }, errback); 4050 } 4051 4052 // commonjs require 4053 else if (typeof names == 'string') { 4054 var defaultJSExtension = loader.defaultJSExtensions && names.substr(names.length - 3, 3) != '.js'; 4055 var normalized = loader.decanonicalize(names, referer); 4056 if (defaultJSExtension && normalized.substr(normalized.length - 3, 3) == '.js') 4057 normalized = normalized.substr(0, normalized.length - 3); 4058 var module = loader.get(normalized); 4059 if (!module) 4060 throw new Error('Module not already loaded loading "' + names + '" as ' + normalized + (referer ? ' from "' + referer + '".' : '.')); 4061 return module.__useDefault ? module['default'] : module; 4062 } 4063 4064 else 4065 throw new TypeError('Invalid require'); 4066 } 4067 4068 function define(name, deps, factory) { 4069 if (typeof name != 'string') { 4070 factory = deps; 4071 deps = name; 4072 name = null; 4073 } 4074 if (!(deps instanceof Array)) { 4075 factory = deps; 4076 deps = ['require', 'exports', 'module'].splice(0, factory.length); 4077 } 4078 4079 if (typeof factory != 'function') 4080 factory = (function(factory) { 4081 return function() { return factory; } 4082 })(factory); 4083 4084 // in IE8, a trailing comma becomes a trailing undefined entry 4085 if (deps[deps.length - 1] === undefined) 4086 deps.pop(); 4087 4088 // remove system dependencies 4089 var requireIndex, exportsIndex, moduleIndex; 4090 4091 if ((requireIndex = indexOf.call(deps, 'require')) != -1) { 4092 4093 deps.splice(requireIndex, 1); 4094 4095 // only trace cjs requires for non-named 4096 // named defines assume the trace has already been done 4097 if (!name) 4098 deps = deps.concat(getCJSDeps(factory.toString(), requireIndex)); 4099 } 4100 4101 if ((exportsIndex = indexOf.call(deps, 'exports')) != -1) 4102 deps.splice(exportsIndex, 1); 4103 4104 if ((moduleIndex = indexOf.call(deps, 'module')) != -1) 4105 deps.splice(moduleIndex, 1); 4106 4107 function execute(req, exports, module) { 4108 var depValues = []; 4109 for (var i = 0; i < deps.length; i++) 4110 depValues.push(req(deps[i])); 4111 4112 module.uri = module.id; 4113 4114 module.config = function() {}; 4115 4116 // add back in system dependencies 4117 if (moduleIndex != -1) 4118 depValues.splice(moduleIndex, 0, module); 4119 4120 if (exportsIndex != -1)
4121 depValues.splice(exportsIndex, 0, exports); 4122 4123 if (requireIndex != -1) { 4124 function contextualRequire(names, callback, errback) { 4125 if (typeof names == 'string' && typeof callback != 'function') 4126 return req(names); 4127 return require.call(loader, names, callback, errback, module.id); 4128 } 4129 contextualRequire.toUrl = function(name) { 4130 // normalize without defaultJSExtensions 4131 var defaultJSExtension = loader.defaultJSExtensions && name.substr(name.length - 3, 3) != '.js'; 4132 var url = loader.decanonicalize(name, module.id); 4133 if (defaultJSExtension && url.substr(url.length - 3, 3) == '.js') 4134 url = url.substr(0, url.length - 3); 4135 return url; 4136 }; 4137 depValues.splice(requireIndex, 0, contextualRequire); 4138 } 4139 4140 // set global require to AMD require 4141 var curRequire = __global.require; 4142 __global.require = require; 4143 4144 var output = factory.apply(exportsIndex == -1 ? __global : exports, depValues); 4145 4146 __global.require = curRequire; 4147 4148 if (typeof output == 'undefined' && module) 4149 output = module.exports; 4150 4151 if (typeof output != 'undefined') 4152 return output; 4153 } 4154 4155 var entry = createEntry(); 4156 entry.name = name && (loader.decanonicalize || loader.normalize).call(loader, name); 4157 entry.deps = deps; 4158 entry.execute = execute; 4159 4160 loader.pushRegister_({ 4161 amd: true, 4162 entry: entry 4163 }); 4164 } 4165 define.amd = {}; 4166 4167 // reduction function to attach defines to a load record 4168 hook('reduceRegister_', function(reduceRegister) { 4169 return function(load, register) { 4170 // only handle AMD registers here 4171 if (!register || !register.amd) 4172 return reduceRegister.call(this, load, register); 4173 4174 var curMeta = load && load.metadata; 4175 var entry = register.entry; 4176 4177 if (curMeta) { 4178 if (!curMeta.format || curMeta.format == 'detect') 4179 curMeta.format = 'amd'; 4180 else if (!entry.name && curMeta.format != 'amd') 4181 throw new Error('AMD define called while executing ' + curMeta.format + ' module ' + load.name); 4182 } 4183 4184 // anonymous define 4185 if (!entry.name) { 4186 if (!curMeta) 4187 throw new TypeError('Unexpected anonymous AMD define.'); 4188 4189 if (curMeta.entry && !curMeta.entry.name) 4190 throw new Error('Multiple anonymous defines in module ' + load.name); 4191 4192 curMeta.entry = entry; 4193 } 4194 // named define 4195 else { 4196 // if we don't have any other defines, 4197 // then let this be an anonymous define
4198 // this is just to support single modules of the form: 4199 // define('jquery') 4200 // still loading anonymously 4201 // because it is done widely enough to be useful 4202 // as soon as there is more than one define, this gets removed though 4203 if (curMeta) { 4204 if (!curMeta.entry && !curMeta.bundle) 4205 curMeta.entry = entry; 4206 else if (curMeta.entry && curMeta.entry.name) 4207 curMeta.entry = undefined; 4208 4209 // note this is now a bundle 4210 curMeta.bundle = true; 4211 } 4212 4213 // define the module through the register registry 4214 if (!(entry.name in this.defined)) 4215 this.defined[entry.name] = entry; 4216 } 4217 }; 4218 }); 4219 4220 loader.amdDefine = define; 4221 loader.amdRequire = require; 4222 }; 4223});/* 4224 SystemJS AMD Format 4225*/ 4226(function() { 4227 // AMD Module Format Detection RegEx 4228 // define([.., .., ..], ...) 4229 // define(varName); || define(function(require, exports) {}); || define({}) 4230 var amdRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])define\s*\(\s*("[^"]+"\s*,\s*|'[^']+'\s*,\s*)?\s*(\[(\s*(("[^"]+"|'[^']+')\s*,|\/\/.*\r?\n|\/\*(.|\s)*?\*\/))*(\s*("[^"]+"|'[^']+')\s*,?)?(\s*(\/\/.*\r?\n|\/\*(.|\s)*?\*\/))*\s*\]|function\s*|{|[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*\))/; 4231 4232 hook('instantiate', function(instantiate) { 4233 return function(load) { 4234 var loader = this; 4235 4236 if (load.metadata.format == 'amd' || !load.metadata.format && load.source.match(amdRegEx)) { 4237 load.metadata.format = 'amd'; 4238 4239 if (!loader.builder && loader.execute !== false) { 4240 var curDefine = __global.define; 4241 __global.define = this.amdDefine; 4242 4243 try { 4244 __exec.call(loader, load); 4245 } 4246 finally { 4247 __global.define = curDefine; 4248 } 4249 4250 if (!load.metadata.entry && !load.metadata.bundle) 4251 throw new TypeError('AMD module ' + load.name + ' did not define'); 4252 } 4253 else { 4254 load.metadata.execute = function() { 4255 return load.metadata.builderExecute.apply(this, arguments); 4256 }; 4257 } 4258 } 4259 4260 return instantiate.call(loader, load); 4261 }; 4262 }); 4263 4264})(); 4265/* 4266 SystemJS Loader Plugin Support 4267 4268 Supports plugin loader syntax with "!", or via metadata.loader 4269 4270 The plugin name is loaded as a module itself, and can override standard loader hooks 4271 for the plugin resource. See the plugin section of the systemjs readme. 4272*/ 4273 4274(function() { 4275 function getParentName(loader, parentName) { 4276 // if parent is a plugin, normalize against the parent plugin argument only 4277 if (parentName) { 4278 var parentPluginIndex; 4279 if (loader.pluginFirst) { 4280 if ((parentPluginIndex = parentName.lastIndexOf('!')) != -1) 4281 return parentName.substr(parentPluginIndex + 1); 4282 } 4283 else { 4284 if ((parentPluginIndex = parentName.indexOf('!')) != -1) 4285 return parentName.substr(0, parentPluginIndex); 4286 } 4287 4288 return parentName; 4289 } 4290 } 4291 4292 function parsePlugin(loader, name) { 4293 var argumentName; 4294 var pluginName; 4295 4296 var pluginIndex = name.lastIndexOf('!'); 4297 4298 if (pluginIndex == -1) 4299 return; 4300 4301 if (loader.pluginFirst) { 4302 argumentName = name.substr(pluginIndex + 1); 4303 pluginName = name.substr(0, pluginIndex); 4304 } 4305 else { 4306 argumentName = name.substr(0, pluginIndex); 4307 pluginName = name.substr(pluginIndex + 1) || argumentName.substr(argumentName.lastIndexOf('.') + 1); 4308 } 4309 4310 return { 4311 argument: argumentName, 4312 plugin: pluginName 4313 }; 4314 } 4315 4316 // put name back together after parts have been normalized 4317 function combinePluginParts(loader, argumentName, pluginName, defaultExtension) { 4318 if (defaultExtension && argumentName.substr(argumentName.length - 3, 3) == '.js') 4319 argumentName = argumentName.substr(0, argumentName.length - 3); 4320 4321 if (loader.pluginFirst) { 4322 return pluginName + '!' + argumentName; 4323 } 4324 else { 4325 return argumentName + '!' + pluginName; 4326 } 4327 } 4328 4329 // note if normalize will add a default js extension 4330 // if so, remove for backwards compat 4331 // this is strange and sucks, but will be deprecated 4332 function checkDefaultExtension(loader, arg) { 4333 return loader.defaultJSExtensions && arg.substr(arg.length - 3, 3) != '.js'; 4334 } 4335 4336 function createNormalizeSync(normalizeSync) { 4337 return function(name, parentName, isPlugin) { 4338 var loader = this; 4339 4340 parentName = getParentName(this, parentName); 4341 var parsed = parsePlugin(loader, name); 4342 4343 if (!parsed) 4344 return normalizeSync.call(this, name, parentName, isPlugin); 4345 4346 // if this is a plugin, normalize the plugin name and the argument 4347 var argumentName = loader.normalizeSync(parsed.argument, parentName, true); 4348 var pluginName = loader.normalizeSync(parsed.plugin, parentName, true); 4349 return combinePluginParts(loader, argumentName, pluginName, checkDefaultExtension(loader, parsed.argument)); 4350 }; 4351 } 4352 4353 hook('decanonicalize', createNormalizeSync); 4354 hook('normalizeSync', createNormalizeSync); 4355 4356 hook('normalize', function(normalize) { 4357 return function(name, parentName, isPlugin) { 4358 var loader = this; 4359 4360 parentName = getParentName(this, parentName); 4361 4362 var parsed = parsePlugin(loader, name); 4363 4364 if (!parsed) 4365 return normalize.call(loader, name, parentName, isPlugin); 4366 4367 return Promise.all([ 4368 loader.normalize(parsed.argument, parentName, true), 4369 loader.normalize(parsed.plugin, parentName) 4370 ]) 4371 .then(function(normalized) { 4372 return combinePluginParts(loader, normalized[0], normalized[1], checkDefaultExtension(loader, parsed.argument)); 4373 }); 4374 } 4375 }); 4376 4377 hook('locate', function(locate) { 4378 return function(load) { 4379 var loader = this; 4380 4381 var name = load.name; 4382 4383 // plugin syntax 4384 var pluginSyntaxIndex; 4385 if (loader.pluginFirst) { 4386 if ((pluginSyntaxIndex = name.indexOf('!')) != -1) { 4387 load.metadata.loader = name.substr(0, pluginSyntaxIndex); 4388 load.name = name.substr(pluginSyntaxIndex + 1); 4389 } 4390 } 4391 else { 4392 if ((pluginSyntaxIndex = name.lastIndexOf('!')) != -1) { 4393 load.metadata.loader = name.substr(pluginSyntaxIndex + 1); 4394 load.name = name.substr(0, pluginSyntaxIndex); 4395 } 4396 } 4397 4398 return locate.call(loader, load) 4399 .then(function(address) { 4400 if (pluginSyntaxIndex != -1 || !load.metadata.loader) 4401 return address; 4402 4403 // normalize plugin relative to parent in locate here when 4404 // using plugin via loader metadata 4405 return loader.normalize(load.metadata.loader, load.name) 4406 .then(function(loaderNormalized) { 4407 load.metadata.loader = loaderNormalized; 4408 return address; 4409 }); 4410 }) 4411 .then(function(address) { 4412 var plugin = load.metadata.loader; 4413 4414 if (!plugin) 4415 return address; 4416 4417 // don't allow a plugin to load itself 4418 if (load.name == plugin) 4419 throw new Error('Plugin ' + plugin + ' cannot load itself, make sure it is excluded from any wildcard meta configuration via a custom loader: false rule.'); 4420 4421 // only fetch the plugin itself if this name isn't defined 4422 if (loader.defined && loader.defined[name]) 4423 return address; 4424 4425 var pluginLoader = loader.pluginLoader || loader; 4426 4427 // load the plugin module and run standard locate 4428 return pluginLoader['import'](plugin) 4429 .then(function(loaderModule) { 4430 // store the plugin module itself on the metadata 4431 load.metadata.loaderModule = loaderModule; 4432 4433 load.address = address; 4434 if (loaderModule.locate) 4435 return loaderModule.locate.call(loader, load); 4436 4437 return address; 4438 }); 4439 }); 4440 }; 4441 }); 4442 4443 hook('fetch', function(fetch) { 4444 return function(load) { 4445 var loader = this; 4446 if (load.metadata.loaderModule && load.metadata.loaderModule.fetch && load.metadata.format != 'defined') { 4447 load.metadata.scriptLoad = false;
4448 return load.metadata.loaderModule.fetch.call(loader, load, function(load) { 4449 return fetch.call(loader, load); 4450 }); 4451 } 4452 else { 4453 return fetch.call(loader, load); 4454 } 4455 }; 4456 }); 4457 4458 hook('translate', function(translate) { 4459 return function(load) { 4460 var loader = this; 4461 if (load.metadata.loaderModule && load.metadata.loaderModule.translate && load.metadata.format != 'defined') { 4462 return Promise.resolve(load.metadata.loaderModule.translate.call(loader, load)).then(function(result) { 4463 var sourceMap = load.metadata.sourceMap; 4464 4465 // sanitize sourceMap if an object not a JSON string 4466 if (sourceMap) { 4467 if (typeof sourceMap != 'object') 4468 throw new Error('load.metadata.sourceMap must be set to an object.'); 4469 4470 var originalName = load.name.split('!')[0]; 4471 4472 // force set the filename of the original file 4473 sourceMap.file = originalName + '!transpiled'; 4474 4475 // force set the sources list if only one source 4476 if (!sourceMap.sources || sourceMap.sources.length <= 1) 4477 sourceMap.sources = [originalName]; 4478 } 4479 4480 // if running on file:/// URLs, sourcesContent is necessary 4481 // load.metadata.sourceMap.sourcesContent = [load.source]; 4482 4483 if (typeof result == 'string') 4484 load.source = result; 4485 else 4486 warn.call(this, 'Plugin ' + load.metadata.loader + ' should return the source in translate, instead of setting load.source directly. This support will be deprecated.'); 4487 4488 return translate.call(loader, load); 4489 }); 4490 } 4491 else { 4492 return translate.call(loader, load); 4493 } 4494 }; 4495 }); 4496 4497 hook('instantiate', function(instantiate) { 4498 return function(load) { 4499 var loader = this; 4500 var calledInstantiate = false; 4501 4502 if (load.metadata.loaderModule && load.metadata.loaderModule.instantiate && !loader.builder && load.metadata.format != 'defined') 4503 return Promise.resolve(load.metadata.loaderModule.instantiate.call(loader, load, function(load) { 4504 if (calledInstantiate) 4505 throw new Error('Instantiate must only be called once.'); 4506 calledInstantiate = true; 4507 return instantiate.call(loader, load); 4508 })).then(function(result) { 4509 if (calledInstantiate) 4510 return result; 4511 4512 load.metadata.entry = createEntry(); 4513 load.metadata.entry.execute = function() { 4514 return result; 4515 } 4516 load.metadata.entry.deps = load.metadata.deps; 4517 load.metadata.format = 'defined'; 4518 return instantiate.call(loader, load); 4519 }); 4520 else 4521 return instantiate.call(loader, load); 4522 }; 4523 }); 4524 4525})();/* 4526 * Conditions Extension 4527 * 4528 * Allows a condition module to alter the resolution of an import via syntax: 4529 * 4530 * import $ from 'jquery/#{browser}'; 4531 * 4532 * Will first load the module 'browser' via `SystemJS.import('browser')` and 4533 * take the default export of that module. 4534 * If the default export is not a string, an error is thrown. 4535 * 4536 * We then substitute the string into the require to get the conditional resolution 4537 * enabling environment-specific variations like: 4538 * 4539 * import $ from 'jquery/ie' 4540 * import $ from 'jquery/firefox' 4541 * import $ from 'jquery/chrome' 4542 * import $ from 'jquery/safari' 4543 * 4544 * It can be useful for a condition module to define multiple conditions. 4545 * This can be done via the `|` modifier to specify an export member expression: 4546 * 4547 * import 'jquery/#{./browser.js|grade.version}' 4548 * 4549 * Where the `grade` export `version` member in the `browser.js` module is substituted. 4550 * 4551 * 4552 * Boolean Conditionals 4553 * 4554 * For polyfill modules, that are used as imports but have no module value, 4555 * a binary conditional allows a module not to be loaded at all if not needed: 4556 * 4557 * import 'es5-shim#?./conditions.js|needs-es5shim' 4558 * 4559 * These conditions can also be negated via: 4560 * 4561 * import 'es5-shim#?~./conditions.js|es6' 4562 * 4563 */ 4564 4565 function parseCondition(condition) { 4566 var conditionExport, conditionModule, negation; 4567 4568 var negation = condition[0] == '~'; 4569 var conditionExportIndex = condition.lastIndexOf('|'); 4570 if (conditionExportIndex != -1) { 4571 conditionExport = condition.substr(conditionExportIndex + 1); 4572 conditionModule = condition.substr(negation, conditionExportIndex - negation) || '@system-env'; 4573 } 4574 else { 4575 conditionExport = null; 4576 conditionModule = condition.substr(negation); 4577 } 4578 4579 return { 4580 module: conditionModule, 4581 prop: conditionExport, 4582 negate: negation 4583 }; 4584 } 4585 4586 function serializeCondition(conditionObj) { 4587 return (conditionObj.negate ? '~' : '') + conditionObj.module + (conditionObj.prop ? '|' + conditionObj.prop : ''); 4588 } 4589
4590 function resolveCondition(conditionObj, parentName, bool) { 4591 return this['import'](conditionObj.module, parentName) 4592 .then(function(m) { 4593 if (conditionObj.prop) 4594 m = readMemberExpression(conditionObj.prop, m); 4595 else if (typeof m == 'object' && m + '' == 'Module') 4596 m = m['default']; 4597 4598 if (bool && typeof m != 'boolean') 4599 throw new TypeError('Condition ' + serializeCondition(conditionObj) + ' did not resolve to a boolean.'); 4600 4601 return conditionObj.negate ? !m : m; 4602 }); 4603 } 4604 4605 var interpolationRegEx = /#\{[^\}]+\}/; 4606 function interpolateConditional(name, parentName) { 4607 // first we normalize the conditional 4608 var conditionalMatch = name.match(interpolationRegEx); 4609 4610 if (!conditionalMatch) 4611 return Promise.resolve(name); 4612 4613 var conditionObj = parseCondition(conditionalMatch[0].substr(2, conditionalMatch[0].length - 3)); 4614 4615 // in builds, return normalized conditional 4616 if (this.builder) 4617 return this['normalize'](conditionObj.module, parentName) 4618 .then(function(conditionModule) { 4619 conditionObj.module = conditionModule; 4620 return name.replace(interpolationRegEx, '#{' + serializeCondition(conditionObj) + '}'); 4621 }); 4622 4623 return resolveCondition.call(this, conditionObj, parentName, false) 4624 .then(function(conditionValue) { 4625 if (typeof conditionValue !== 'string') 4626 throw new TypeError('The condition value for ' + name + ' doesn\'t resolve to a string.'); 4627 4628 if (conditionValue.indexOf('/') != -1) 4629 throw new TypeError('Unabled to interpolate conditional ' + name + (parentName ? ' in ' + parentName : '') + '\n\tThe condition value ' + conditionValue + ' cannot contain a "/" separator.'); 4630 4631 return name.replace(interpolationRegEx, conditionValue); 4632 }); 4633 } 4634 4635 function booleanConditional(name, parentName) { 4636 // first we normalize the conditional 4637 var booleanIndex = name.lastIndexOf('#?'); 4638 4639 if (booleanIndex == -1) 4640 return Promise.resolve(name); 4641 4642 var conditionObj = parseCondition(name.substr(booleanIndex + 2)); 4643 4644 // in builds, return normalized conditional 4645 if (this.builder) 4646 return this['normalize'](conditionObj.module, parentName) 4647 .then(function(conditionModule) { 4648 conditionObj.module = conditionModule; 4649 return name.substr(0, booleanIndex) + '#?' + serializeCondition(conditionObj); 4650 }); 4651 4652 return resolveCondition.call(this, conditionObj, parentName, true) 4653 .then(function(conditionValue) { 4654 return conditionValue ? name.substr(0, booleanIndex) : '@empty'; 4655 }); 4656 } 4657 4658 // normalizeSync does not parse conditionals at all although it could 4659 hook('normalize', function(normalize) { 4660 return function(name, parentName, parentAddress) { 4661 var loader = this; 4662 return booleanConditional.call(loader, name, parentName) 4663 .then(function(name) { 4664 return normalize.call(loader, name, parentName, parentAddress); 4665 }) 4666 .then(function(normalized) { 4667 return interpolateConditional.call(loader, normalized, parentName); 4668 }); 4669 }; 4670 }); 4671/* 4672 * Alias Extension 4673 * 4674 * Allows a module to be a plain copy of another module by module name 4675 * 4676 * SystemJS.meta['mybootstrapalias'] = { alias: 'bootstrap' }; 4677 * 4678 */ 4679(function() { 4680 // aliases 4681 hook('fetch', function(fetch) { 4682 return function(load) { 4683 var alias = load.metadata.alias; 4684 var aliasDeps = load.metadata.deps || []; 4685 if (alias) { 4686 load.metadata.format = 'defined'; 4687 var entry = createEntry(); 4688 this.defined[load.name] = entry; 4689 entry.declarative = true; 4690 entry.deps = aliasDeps.concat([alias]); 4691 entry.declare = function(_export) { 4692 return { 4693 setters: [function(module) { 4694 for (var p in module) 4695 _export(p, module[p]); 4696 if (module.__useDefault) 4697 entry.module.exports.__useDefault = true; 4698 }], 4699 execute: function() {} 4700 }; 4701 }; 4702 return ''; 4703 } 4704 4705 return fetch.call(this, load); 4706 }; 4707 }); 4708})();/* 4709 * Meta Extension 4710 * 4711 * Sets default metadata on a load record (load.metadata) from 4712 * loader.metadata via SystemJS.meta function. 4713 * 4714 * 4715 * Also provides an inline meta syntax for module meta in source. 4716 * 4717 * Eg: 4718 * 4719 * loader.meta({ 4720 * 'my/module': { deps: ['jquery'] } 4721 * 'my/*': { format: 'amd' } 4722 * }); 4723 * 4724 * Which in turn populates loader.metadata. 4725 * 4726 * load.metadata.deps and load.metadata.format will then be set 4727 * for 'my/module' 4728 * 4729 * The same meta could be set with a my/module.js file containing: 4730 * 4731 * my/module.js 4732 * "format amd";
4733 * "deps[] jquery"; 4734 * "globals.some value" 4735 * console.log('this is my/module'); 4736 * 4737 * Configuration meta always takes preference to inline meta. 4738 * 4739 * Multiple matches in wildcards are supported and ammend the meta. 4740 * 4741 * 4742 * The benefits of the function form is that paths are URL-normalized 4743 * supporting say 4744 * 4745 * loader.meta({ './app': { format: 'cjs' } }); 4746 * 4747 * Instead of needing to set against the absolute URL (https://site.com/app.js) 4748 * 4749 */ 4750 4751(function() { 4752 4753 hookConstructor(function(constructor) { 4754 return function() { 4755 this.meta = {}; 4756 constructor.call(this); 4757 }; 4758 }); 4759 4760 hook('locate', function(locate) { 4761 return function(load) { 4762 var meta = this.meta; 4763 var name = load.name; 4764 4765 // NB for perf, maybe introduce a fast-path wildcard lookup cache here 4766 // which is checked first 4767 4768 // apply wildcard metas 4769 var bestDepth = 0; 4770 var wildcardIndex; 4771 for (var module in meta) { 4772 wildcardIndex = module.indexOf('*'); 4773 if (wildcardIndex === -1) 4774 continue; 4775 if (module.substr(0, wildcardIndex) === name.substr(0, wildcardIndex) 4776 && module.substr(wildcardIndex + 1) === name.substr(name.length - module.length + wildcardIndex + 1)) { 4777 var depth = module.split('/').length; 4778 if (depth > bestDepth) 4779 bestDepth = depth; 4780 extendMeta(load.metadata, meta[module], bestDepth != depth); 4781 } 4782 } 4783 4784 // apply exact meta 4785 if (meta[name]) 4786 extendMeta(load.metadata, meta[name]); 4787 4788 return locate.call(this, load); 4789 }; 4790 }); 4791 4792 // detect any meta header syntax 4793 // only set if not already set 4794 var metaRegEx = /^(\s*\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)+/; 4795 var metaPartRegEx = /\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\/\/[^\n]*|"[^"]+"\s*;?|'[^']+'\s*;?/g; 4796 4797 function setMetaProperty(target, p, value) { 4798 var pParts = p.split('.'); 4799 var curPart; 4800 while (pParts.length > 1) { 4801 curPart = pParts.shift(); 4802 target = target[curPart] = target[curPart] || {}; 4803 } 4804 curPart = pParts.shift(); 4805 if (!(curPart in target)) 4806 target[curPart] = value; 4807 } 4808 4809 hook('translate', function(translate) { 4810 return function(load) { 4811 // NB meta will be post-translate pending transpiler conversion to plugins 4812 var meta = load.source.match(metaRegEx); 4813 if (meta) { 4814 var metaParts = meta[0].match(metaPartRegEx); 4815 4816 for (var i = 0; i < metaParts.length; i++) { 4817 var curPart = metaParts[i]; 4818 var len = curPart.length; 4819 4820 var firstChar = curPart.substr(0, 1); 4821 if (curPart.substr(len - 1, 1) == ';') 4822 len--; 4823 4824 if (firstChar != '"' && firstChar != "'") 4825 continue; 4826 4827 var metaString = curPart.substr(1, curPart.length - 3); 4828 var metaName = metaString.substr(0, metaString.indexOf(' ')); 4829 4830 if (metaName) { 4831 var metaValue = metaString.substr(metaName.length + 1, metaString.length - metaName.length - 1); 4832 4833 if (metaName.substr(metaName.length - 2, 2) == '[]') { 4834 metaName = metaName.substr(0, metaName.length - 2); 4835 load.metadata[metaName] = load.metadata[metaName] || []; 4836 load.metadata[metaName].push(metaValue); 4837 } 4838 else if (load.metadata[metaName] instanceof Array) { 4839 // temporary backwards compat for previous "deps" syntax 4840 warn.call(this, 'Module ' + load.name + ' contains deprecated "deps ' + metaValue + '" meta syntax.\nThis should be updated to "deps[] ' + metaValue + '" for pushing to array meta.'); 4841 load.metadata[metaName].push(metaValue); 4842 } 4843 else { 4844 setMetaProperty(load.metadata, metaName, metaValue); 4845 } 4846 } 4847 else { 4848 load.metadata[metaString] = true; 4849 } 4850 } 4851 } 4852 4853 return translate.call(this, load); 4854 }; 4855 }); 4856})(); 4857/* 4858 System bundles 4859 4860 Allows a bundle module to be specified which will be dynamically 4861 loaded before trying to load a given module. 4862 4863 For example: 4864 SystemJS.bundles['mybundle'] = ['jquery', 'bootstrap/js/bootstrap'] 4865 4866 Will result in a load to "mybundle" whenever a load to "jquery" 4867 or "bootstrap/js/bootstrap" is made. 4868 4869 In this way, the bundle becomes the request that provides the module 4870*/ 4871 4872(function() { 4873 // bundles support (just like RequireJS) 4874 // bundle name is module name of bundle itself 4875 // bundle is array of modules defined by the bundle 4876 // when a module in the bundle is requested, the bundle is loaded instead 4877 // of the form SystemJS.bundles['mybundle'] = ['jquery', 'bootstrap/js/bootstrap'] 4878 hookConstructor(function(constructor) { 4879 return function() { 4880 constructor.call(this); 4881 this.bundles = {}; 4882 this._loader.loadedBundles = {}; 4883 }; 4884 }); 4885 4886 // assign bundle metadata for bundle loads 4887 hook('locate', function(locate) { 4888 return function(load) { 4889 var loader = this; 4890 var matched = false;
4891 4892 if (!(load.name in loader.defined)) 4893 for (var b in loader.bundles) { 4894 for (var i = 0; i < loader.bundles[b].length; i++) { 4895 var curModule = loader.bundles[b][i]; 4896 4897 if (curModule == load.name) { 4898 matched = true; 4899 break; 4900 } 4901 4902 // wildcard in bundles does not include / boundaries 4903 if (curModule.indexOf('*') != -1) { 4904 var parts = curModule.split('*'); 4905 if (parts.length != 2) { 4906 loader.bundles[b].splice(i--, 1); 4907 continue; 4908 } 4909 4910 if (load.name.substring(0, parts[0].length) == parts[0] && 4911 load.name.substr(load.name.length - parts[1].length, parts[1].length) == parts[1] && 4912 load.name.substr(parts[0].length, load.name.length - parts[1].length - parts[0].length).indexOf('/') == -1) { 4913 matched = true; 4914 break; 4915 } 4916 } 4917 } 4918 4919 if (matched) 4920 return loader['import'](b) 4921 .then(function() { 4922 return locate.call(loader, load); 4923 }); 4924 } 4925 4926 return locate.call(loader, load); 4927 }; 4928 }); 4929})(); 4930/* 4931 * Dependency Tree Cache 4932 * 4933 * Allows a build to pre-populate a dependency trace tree on the loader of 4934 * the expected dependency tree, to be loaded upfront when requesting the 4935 * module, avoinding the n round trips latency of module loading, where 4936 * n is the dependency tree depth. 4937 * 4938 * eg: 4939 * SystemJS.depCache = { 4940 * 'app': ['normalized', 'deps'], 4941 * 'normalized': ['another'], 4942 * 'deps': ['tree'] 4943 * }; 4944 * 4945 * SystemJS.import('app') 4946 * // simultaneously starts loading all of: 4947 * // 'normalized', 'deps', 'another', 'tree' 4948 * // before "app" source is even loaded 4949 * 4950 */ 4951 4952(function() { 4953 hookConstructor(function(constructor) { 4954 return function() { 4955 constructor.call(this); 4956 this.depCache = {}; 4957 } 4958 }); 4959 4960 hook('locate', function(locate) { 4961 return function(load) { 4962 var loader = this; 4963 // load direct deps, in turn will pick up their trace trees 4964 var deps = loader.depCache[load.name]; 4965 if (deps) 4966 for (var i = 0; i < deps.length; i++) 4967 loader['import'](deps[i], load.name); 4968 4969 return locate.call(loader, load); 4970 }; 4971 }); 4972})(); 4973 4974System = new SystemJSLoader(); 4975 4976__global.SystemJS = System; 4977System.version = '0.19.27 Standard'; 4978 // -- exporting -- 4979 4980 if (typeof exports === 'object') 4981 module.exports = Loader; 4982 4983 __global.Reflect = __global.Reflect || {}; 4984 __global.Reflect.Loader = __global.Reflect.Loader || Loader; 4985 __global.Reflect.global = __global.Reflect.global || __global; 4986 __global.LoaderPolyfill = Loader; 4987 4988 if (!System) { 4989 System = new SystemLoader(); 4990 System.constructor = SystemLoader; 4991 } 4992 4993 if (typeof exports === 'object') 4994 module.exports = System; 4995
4996 __global.System = System; 4997 4998})(typeof self != 'undefined' ? self : global);} 4999 5000// auto-load Promise polyfill if needed in the browser 5001var doPolyfill = typeof Promise === 'undefined'; 5002 5003// document.write 5004if (typeof document !== 'undefined') { 5005 var scripts = document.getElementsByTagName('script'); 5006 $__curScript = scripts[scripts.length - 1]; 5007 if (doPolyfill) { 5008 var curPath = $__curScript.src; 5009 var basePath = curPath.substr(0, curPath.lastIndexOf('/') + 1); 5010 window.systemJSBootstrap = bootstrap; 5011 document.write( 5012 '<' + 'script type="text/javascript" src="' + basePath + 'system-polyfills.js">' + '<' + '/script>' 5013 ); 5014 } 5015 else { 5016 bootstrap(); 5017 } 5018} 5019// importScripts 5020else if (typeof importScripts !== 'undefined') { 5021 var basePath = ''; 5022 try { 5023 throw new Error('_'); 5024 } catch (e) { 5025 e.stack.replace(/(?:at|@).*(http.+):[\d]+:[\d]+/, function(m, url) { 5026 $__curScript = { src: url }; 5027 basePath = url.replace(/\/[^\/]*$/, '/'); 5028 }); 5029 } 5030 if (doPolyfill) 5031 importScripts(basePath + 'system-polyfills.js'); 5032 bootstrap(); 5033} 5034else { 5035 $__curScript = typeof __filename != 'undefined' ? { src: __filename } : null; 5036 bootstrap(); 5037} 5038 5039 5040})();
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.