s.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /*!
  2. * SJS 6.15.1
  3. */
  4. (function () {
  5. function errMsg(errCode, msg) {
  6. return (msg || "") + " (SystemJS https://github.com/systemjs/systemjs/blob/main/docs/errors.md#" + errCode + ")";
  7. }
  8. var hasSymbol = typeof Symbol !== 'undefined';
  9. var hasSelf = typeof self !== 'undefined';
  10. var hasDocument = typeof document !== 'undefined';
  11. var envGlobal = hasSelf ? self : global;
  12. var baseUrl;
  13. if (hasDocument) {
  14. var baseEl = document.querySelector('base[href]');
  15. if (baseEl)
  16. baseUrl = baseEl.href;
  17. }
  18. if (!baseUrl && typeof location !== 'undefined') {
  19. baseUrl = location.href.split('#')[0].split('?')[0];
  20. var lastSepIndex = baseUrl.lastIndexOf('/');
  21. if (lastSepIndex !== -1)
  22. baseUrl = baseUrl.slice(0, lastSepIndex + 1);
  23. }
  24. var backslashRegEx = /\\/g;
  25. function resolveIfNotPlainOrUrl (relUrl, parentUrl) {
  26. if (relUrl.indexOf('\\') !== -1)
  27. relUrl = relUrl.replace(backslashRegEx, '/');
  28. // protocol-relative
  29. if (relUrl[0] === '/' && relUrl[1] === '/') {
  30. return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
  31. }
  32. // relative-url
  33. else if (relUrl[0] === '.' && (relUrl[1] === '/' || relUrl[1] === '.' && (relUrl[2] === '/' || relUrl.length === 2 && (relUrl += '/')) ||
  34. relUrl.length === 1 && (relUrl += '/')) ||
  35. relUrl[0] === '/') {
  36. var parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
  37. // Disabled, but these cases will give inconsistent results for deep backtracking
  38. //if (parentUrl[parentProtocol.length] !== '/')
  39. // throw Error('Cannot resolve');
  40. // read pathname from parent URL
  41. // pathname taken to be part after leading "/"
  42. var pathname;
  43. if (parentUrl[parentProtocol.length + 1] === '/') {
  44. // resolving to a :// so we need to read out the auth and host
  45. if (parentProtocol !== 'file:') {
  46. pathname = parentUrl.slice(parentProtocol.length + 2);
  47. pathname = pathname.slice(pathname.indexOf('/') + 1);
  48. }
  49. else {
  50. pathname = parentUrl.slice(8);
  51. }
  52. }
  53. else {
  54. // resolving to :/ so pathname is the /... part
  55. pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
  56. }
  57. if (relUrl[0] === '/')
  58. return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
  59. // join together and split for removal of .. and . segments
  60. // looping the string instead of anything fancy for perf reasons
  61. // '../../../../../z' resolved to 'x/y' is just 'z'
  62. var segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
  63. var output = [];
  64. var segmentIndex = -1;
  65. for (var i = 0; i < segmented.length; i++) {
  66. // busy reading a segment - only terminate on '/'
  67. if (segmentIndex !== -1) {
  68. if (segmented[i] === '/') {
  69. output.push(segmented.slice(segmentIndex, i + 1));
  70. segmentIndex = -1;
  71. }
  72. }
  73. // new segment - check if it is relative
  74. else if (segmented[i] === '.') {
  75. // ../ segment
  76. if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
  77. output.pop();
  78. i += 2;
  79. }
  80. // ./ segment
  81. else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
  82. i += 1;
  83. }
  84. else {
  85. // the start of a new segment as below
  86. segmentIndex = i;
  87. }
  88. }
  89. // it is the start of a new segment
  90. else {
  91. segmentIndex = i;
  92. }
  93. }
  94. // finish reading out the last segment
  95. if (segmentIndex !== -1)
  96. output.push(segmented.slice(segmentIndex));
  97. return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
  98. }
  99. }
  100. /*
  101. * Import maps implementation
  102. *
  103. * To make lookups fast we pre-resolve the entire import map
  104. * and then match based on backtracked hash lookups
  105. *
  106. */
  107. function resolveUrl (relUrl, parentUrl) {
  108. return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (relUrl.indexOf(':') !== -1 ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
  109. }
  110. function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap, parentUrl) {
  111. for (var p in packages) {
  112. var resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
  113. var rhs = packages[p];
  114. // package fallbacks not currently supported
  115. if (typeof rhs !== 'string')
  116. continue;
  117. var mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(rhs, baseUrl) || rhs, parentUrl);
  118. if (!mapped) {
  119. targetWarning('W1', p, rhs);
  120. }
  121. else
  122. outPackages[resolvedLhs] = mapped;
  123. }
  124. }
  125. function resolveAndComposeImportMap (json, baseUrl, outMap) {
  126. if (json.imports)
  127. resolveAndComposePackages(json.imports, outMap.imports, baseUrl, outMap, null);
  128. var u;
  129. for (u in json.scopes || {}) {
  130. var resolvedScope = resolveUrl(u, baseUrl);
  131. resolveAndComposePackages(json.scopes[u], outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}), baseUrl, outMap, resolvedScope);
  132. }
  133. for (u in json.depcache || {})
  134. outMap.depcache[resolveUrl(u, baseUrl)] = json.depcache[u];
  135. for (u in json.integrity || {})
  136. outMap.integrity[resolveUrl(u, baseUrl)] = json.integrity[u];
  137. }
  138. function getMatch (path, matchObj) {
  139. if (matchObj[path])
  140. return path;
  141. var sepIndex = path.length;
  142. do {
  143. var segment = path.slice(0, sepIndex + 1);
  144. if (segment in matchObj)
  145. return segment;
  146. } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1)
  147. }
  148. function applyPackages (id, packages) {
  149. var pkgName = getMatch(id, packages);
  150. if (pkgName) {
  151. var pkg = packages[pkgName];
  152. if (pkg === null) return;
  153. if (id.length > pkgName.length && pkg[pkg.length - 1] !== '/') {
  154. targetWarning('W2', pkgName, pkg);
  155. }
  156. else
  157. return pkg + id.slice(pkgName.length);
  158. }
  159. }
  160. function targetWarning (code, match, target, msg) {
  161. console.warn(errMsg(code, [target, match].join(', ') ));
  162. }
  163. function resolveImportMap (importMap, resolvedOrPlain, parentUrl) {
  164. var scopes = importMap.scopes;
  165. var scopeUrl = parentUrl && getMatch(parentUrl, scopes);
  166. while (scopeUrl) {
  167. var packageResolution = applyPackages(resolvedOrPlain, scopes[scopeUrl]);
  168. if (packageResolution)
  169. return packageResolution;
  170. scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), scopes);
  171. }
  172. return applyPackages(resolvedOrPlain, importMap.imports) || resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain;
  173. }
  174. /*
  175. * SystemJS Core
  176. *
  177. * Provides
  178. * - System.import
  179. * - System.register support for
  180. * live bindings, function hoisting through circular references,
  181. * reexports, dynamic import, import.meta.url, top-level await
  182. * - System.getRegister to get the registration
  183. * - Symbol.toStringTag support in Module objects
  184. * - Hookable System.createContext to customize import.meta
  185. * - System.onload(err, id, deps) handler for tracing / hot-reloading
  186. *
  187. * Core comes with no System.prototype.resolve or
  188. * System.prototype.instantiate implementations
  189. */
  190. var toStringTag = hasSymbol && Symbol.toStringTag;
  191. var REGISTRY = hasSymbol ? Symbol() : '@';
  192. function SystemJS () {
  193. this[REGISTRY] = {};
  194. }
  195. var systemJSPrototype = SystemJS.prototype;
  196. systemJSPrototype.import = function (id, parentUrl, meta) {
  197. var loader = this;
  198. (parentUrl && typeof parentUrl === 'object') && (meta = parentUrl, parentUrl = undefined);
  199. return Promise.resolve(loader.prepareImport())
  200. .then(function() {
  201. return loader.resolve(id, parentUrl, meta);
  202. })
  203. .then(function (id) {
  204. var load = getOrCreateLoad(loader, id, undefined, meta);
  205. return load.C || topLevelLoad(loader, load);
  206. });
  207. };
  208. // Hookable createContext function -> allowing eg custom import meta
  209. systemJSPrototype.createContext = function (parentId) {
  210. var loader = this;
  211. return {
  212. url: parentId,
  213. resolve: function (id, parentUrl) {
  214. return Promise.resolve(loader.resolve(id, parentUrl || parentId));
  215. }
  216. };
  217. };
  218. function loadToId (load) {
  219. return load.id;
  220. }
  221. function triggerOnload (loader, load, err, isErrSource) {
  222. loader.onload(err, load.id, load.d && load.d.map(loadToId), !!isErrSource);
  223. if (err)
  224. throw err;
  225. }
  226. var lastRegister;
  227. systemJSPrototype.register = function (deps, declare, metas) {
  228. lastRegister = [deps, declare, metas];
  229. };
  230. /*
  231. * getRegister provides the last anonymous System.register call
  232. */
  233. systemJSPrototype.getRegister = function () {
  234. var _lastRegister = lastRegister;
  235. lastRegister = undefined;
  236. return _lastRegister;
  237. };
  238. function getOrCreateLoad (loader, id, firstParentUrl, meta) {
  239. var load = loader[REGISTRY][id];
  240. if (load)
  241. return load;
  242. var importerSetters = [];
  243. var ns = Object.create(null);
  244. if (toStringTag)
  245. Object.defineProperty(ns, toStringTag, { value: 'Module' });
  246. var instantiatePromise = Promise.resolve()
  247. .then(function () {
  248. return loader.instantiate(id, firstParentUrl, meta);
  249. })
  250. .then(function (registration) {
  251. if (!registration)
  252. throw Error(errMsg(2, id ));
  253. function _export (name, value) {
  254. // note if we have hoisted exports (including reexports)
  255. load.h = true;
  256. var changed = false;
  257. if (typeof name === 'string') {
  258. if (!(name in ns) || ns[name] !== value) {
  259. ns[name] = value;
  260. changed = true;
  261. }
  262. }
  263. else {
  264. for (var p in name) {
  265. var value = name[p];
  266. if (!(p in ns) || ns[p] !== value) {
  267. ns[p] = value;
  268. changed = true;
  269. }
  270. }
  271. if (name && name.__esModule) {
  272. ns.__esModule = name.__esModule;
  273. }
  274. }
  275. if (changed)
  276. for (var i = 0; i < importerSetters.length; i++) {
  277. var setter = importerSetters[i];
  278. if (setter) setter(ns);
  279. }
  280. return value;
  281. }
  282. var declared = registration[1](_export, registration[1].length === 2 ? {
  283. import: function (importId, meta) {
  284. return loader.import(importId, id, meta);
  285. },
  286. meta: loader.createContext(id)
  287. } : undefined);
  288. load.e = declared.execute || function () {};
  289. return [registration[0], declared.setters || [], registration[2] || []];
  290. }, function (err) {
  291. load.e = null;
  292. load.er = err;
  293. throw err;
  294. });
  295. var linkPromise = instantiatePromise
  296. .then(function (instantiation) {
  297. return Promise.all(instantiation[0].map(function (dep, i) {
  298. var setter = instantiation[1][i];
  299. var meta = instantiation[2][i];
  300. return Promise.resolve(loader.resolve(dep, id))
  301. .then(function (depId) {
  302. var depLoad = getOrCreateLoad(loader, depId, id, meta);
  303. // depLoad.I may be undefined for already-evaluated
  304. return Promise.resolve(depLoad.I)
  305. .then(function () {
  306. if (setter) {
  307. depLoad.i.push(setter);
  308. // only run early setters when there are hoisted exports of that module
  309. // the timing works here as pending hoisted export calls will trigger through importerSetters
  310. if (depLoad.h || !depLoad.I)
  311. setter(depLoad.n);
  312. }
  313. return depLoad;
  314. });
  315. });
  316. }))
  317. .then(function (depLoads) {
  318. load.d = depLoads;
  319. });
  320. });
  321. // Capital letter = a promise function
  322. return load = loader[REGISTRY][id] = {
  323. id: id,
  324. // importerSetters, the setters functions registered to this dependency
  325. // we retain this to add more later
  326. i: importerSetters,
  327. // module namespace object
  328. n: ns,
  329. // extra module information for import assertion
  330. // shape like: { assert: { type: 'xyz' } }
  331. m: meta,
  332. // instantiate
  333. I: instantiatePromise,
  334. // link
  335. L: linkPromise,
  336. // whether it has hoisted exports
  337. h: false,
  338. // On instantiate completion we have populated:
  339. // dependency load records
  340. d: undefined,
  341. // execution function
  342. e: undefined,
  343. // On execution we have populated:
  344. // the execution error if any
  345. er: undefined,
  346. // in the case of TLA, the execution promise
  347. E: undefined,
  348. // On execution, L, I, E cleared
  349. // Promise for top-level completion
  350. C: undefined,
  351. // parent instantiator / executor
  352. p: undefined
  353. };
  354. }
  355. function instantiateAll (loader, load, parent, loaded) {
  356. if (!loaded[load.id]) {
  357. loaded[load.id] = true;
  358. // load.L may be undefined for already-instantiated
  359. return Promise.resolve(load.L)
  360. .then(function () {
  361. if (!load.p || load.p.e === null)
  362. load.p = parent;
  363. return Promise.all(load.d.map(function (dep) {
  364. return instantiateAll(loader, dep, parent, loaded);
  365. }));
  366. })
  367. .catch(function (err) {
  368. if (load.er)
  369. throw err;
  370. load.e = null;
  371. throw err;
  372. });
  373. }
  374. }
  375. function topLevelLoad (loader, load) {
  376. return load.C = instantiateAll(loader, load, load, {})
  377. .then(function () {
  378. return postOrderExec(loader, load, {});
  379. })
  380. .then(function () {
  381. return load.n;
  382. });
  383. }
  384. // the closest we can get to call(undefined)
  385. var nullContext = Object.freeze(Object.create(null));
  386. // returns a promise if and only if a top-level await subgraph
  387. // throws on sync errors
  388. function postOrderExec (loader, load, seen) {
  389. if (seen[load.id])
  390. return;
  391. seen[load.id] = true;
  392. if (!load.e) {
  393. if (load.er)
  394. throw load.er;
  395. if (load.E)
  396. return load.E;
  397. return;
  398. }
  399. // From here we're about to execute the load.
  400. // Because the execution may be async, we pop the `load.e` first.
  401. // So `load.e === null` always means the load has been executed or is executing.
  402. // To inspect the state:
  403. // - If `load.er` is truthy, the execution has threw or has been rejected;
  404. // - otherwise, either the `load.E` is a promise, means it's under async execution, or
  405. // - the `load.E` is null, means the load has completed the execution or has been async resolved.
  406. var exec = load.e;
  407. load.e = null;
  408. // deps execute first, unless circular
  409. var depLoadPromises;
  410. load.d.forEach(function (depLoad) {
  411. try {
  412. var depLoadPromise = postOrderExec(loader, depLoad, seen);
  413. if (depLoadPromise)
  414. (depLoadPromises = depLoadPromises || []).push(depLoadPromise);
  415. }
  416. catch (err) {
  417. load.er = err;
  418. throw err;
  419. }
  420. });
  421. if (depLoadPromises)
  422. return Promise.all(depLoadPromises).then(doExec);
  423. return doExec();
  424. function doExec () {
  425. try {
  426. var execPromise = exec.call(nullContext);
  427. if (execPromise) {
  428. execPromise = execPromise.then(function () {
  429. load.C = load.n;
  430. load.E = null; // indicates completion
  431. if (!true) ;
  432. }, function (err) {
  433. load.er = err;
  434. load.E = null;
  435. if (!true) ;
  436. throw err;
  437. });
  438. return load.E = execPromise;
  439. }
  440. // (should be a promise, but a minify optimization to leave out Promise.resolve)
  441. load.C = load.n;
  442. load.L = load.I = undefined;
  443. }
  444. catch (err) {
  445. load.er = err;
  446. throw err;
  447. }
  448. finally {
  449. }
  450. }
  451. }
  452. envGlobal.System = new SystemJS();
  453. /*
  454. * SystemJS browser attachments for script and import map processing
  455. */
  456. var importMapPromise = Promise.resolve();
  457. var importMap = { imports: {}, scopes: {}, depcache: {}, integrity: {} };
  458. // Scripts are processed immediately, on the first System.import, and on DOMReady.
  459. // Import map scripts are processed only once (by being marked) and in order for each phase.
  460. // This is to avoid using DOM mutation observers in core, although that would be an alternative.
  461. var processFirst = hasDocument;
  462. systemJSPrototype.prepareImport = function (doProcessScripts) {
  463. if (processFirst || doProcessScripts) {
  464. processScripts();
  465. processFirst = false;
  466. }
  467. return importMapPromise;
  468. };
  469. systemJSPrototype.getImportMap = function () {
  470. return JSON.parse(JSON.stringify(importMap));
  471. };
  472. if (hasDocument) {
  473. processScripts();
  474. window.addEventListener('DOMContentLoaded', processScripts);
  475. }
  476. systemJSPrototype.addImportMap = function (newMap, mapBase) {
  477. resolveAndComposeImportMap(newMap, mapBase || baseUrl, importMap);
  478. };
  479. function processScripts () {
  480. [].forEach.call(document.querySelectorAll('script'), function (script) {
  481. if (script.sp) // sp marker = systemjs processed
  482. return;
  483. // TODO: deprecate systemjs-module in next major now that we have auto import
  484. if (script.type === 'systemjs-module') {
  485. script.sp = true;
  486. if (!script.src)
  487. return;
  488. System.import(script.src.slice(0, 7) === 'import:' ? script.src.slice(7) : resolveUrl(script.src, baseUrl)).catch(function (e) {
  489. // if there is a script load error, dispatch an "error" event
  490. // on the script tag.
  491. if (e.message.indexOf('https://github.com/systemjs/systemjs/blob/main/docs/errors.md#3') > -1) {
  492. var event = document.createEvent('Event');
  493. event.initEvent('error', false, false);
  494. script.dispatchEvent(event);
  495. }
  496. return Promise.reject(e);
  497. });
  498. }
  499. else if (script.type === 'systemjs-importmap') {
  500. script.sp = true;
  501. // The passThrough property is for letting the module types fetch implementation know that this is not a SystemJS module.
  502. var fetchPromise = script.src ? (System.fetch || fetch)(script.src, { integrity: script.integrity, priority: script.fetchPriority, passThrough: true }).then(function (res) {
  503. if (!res.ok)
  504. throw Error(res.status );
  505. return res.text();
  506. }).catch(function (err) {
  507. err.message = errMsg('W4', script.src ) + '\n' + err.message;
  508. console.warn(err);
  509. if (typeof script.onerror === 'function') {
  510. script.onerror();
  511. }
  512. return '{}';
  513. }) : script.innerHTML;
  514. importMapPromise = importMapPromise.then(function () {
  515. return fetchPromise;
  516. }).then(function (text) {
  517. extendImportMap(importMap, text, script.src || baseUrl);
  518. });
  519. }
  520. });
  521. }
  522. function extendImportMap (importMap, newMapText, newMapUrl) {
  523. var newMap = {};
  524. try {
  525. newMap = JSON.parse(newMapText);
  526. } catch (err) {
  527. console.warn(Error((errMsg('W5') )));
  528. }
  529. resolveAndComposeImportMap(newMap, newMapUrl, importMap);
  530. }
  531. /*
  532. * Script instantiation loading
  533. */
  534. if (hasDocument) {
  535. window.addEventListener('error', function (evt) {
  536. lastWindowErrorUrl = evt.filename;
  537. lastWindowError = evt.error;
  538. });
  539. var baseOrigin = location.origin;
  540. }
  541. systemJSPrototype.createScript = function (url) {
  542. var script = document.createElement('script');
  543. script.async = true;
  544. // Only add cross origin for actual cross origin
  545. // this is because Safari triggers for all
  546. // - https://bugs.webkit.org/show_bug.cgi?id=171566
  547. if (url.indexOf(baseOrigin + '/'))
  548. script.crossOrigin = 'anonymous';
  549. var integrity = importMap.integrity[url];
  550. if (integrity)
  551. script.integrity = integrity;
  552. script.src = url;
  553. return script;
  554. };
  555. // Auto imports -> script tags can be inlined directly for load phase
  556. var lastAutoImportDeps, lastAutoImportTimeout;
  557. var autoImportCandidates = {};
  558. var systemRegister = systemJSPrototype.register;
  559. systemJSPrototype.register = function (deps, declare) {
  560. if (hasDocument && document.readyState === 'loading' && typeof deps !== 'string') {
  561. var scripts = document.querySelectorAll('script[src]');
  562. var lastScript = scripts[scripts.length - 1];
  563. if (lastScript) {
  564. lastScript.src;
  565. lastAutoImportDeps = deps;
  566. // if this is already a System load, then the instantiate has already begun
  567. // so this re-import has no consequence
  568. var loader = this;
  569. lastAutoImportTimeout = setTimeout(function () {
  570. autoImportCandidates[lastScript.src] = [deps, declare];
  571. loader.import(lastScript.src);
  572. });
  573. }
  574. }
  575. else {
  576. lastAutoImportDeps = undefined;
  577. }
  578. return systemRegister.call(this, deps, declare);
  579. };
  580. var lastWindowErrorUrl, lastWindowError;
  581. systemJSPrototype.instantiate = function (url, firstParentUrl) {
  582. var autoImportRegistration = autoImportCandidates[url];
  583. if (autoImportRegistration) {
  584. delete autoImportCandidates[url];
  585. return autoImportRegistration;
  586. }
  587. var loader = this;
  588. return Promise.resolve(systemJSPrototype.createScript(url)).then(function (script) {
  589. return new Promise(function (resolve, reject) {
  590. script.addEventListener('error', function () {
  591. reject(Error(errMsg(3, [url, firstParentUrl].join(', ') )));
  592. });
  593. script.addEventListener('load', function () {
  594. document.head.removeChild(script);
  595. // Note that if an error occurs that isn't caught by this if statement,
  596. // that getRegister will return null and a "did not instantiate" error will be thrown.
  597. if (lastWindowErrorUrl === url) {
  598. reject(lastWindowError);
  599. }
  600. else {
  601. var register = loader.getRegister(url);
  602. // Clear any auto import registration for dynamic import scripts during load
  603. if (register && register[0] === lastAutoImportDeps)
  604. clearTimeout(lastAutoImportTimeout);
  605. resolve(register);
  606. }
  607. });
  608. document.head.appendChild(script);
  609. });
  610. });
  611. };
  612. /*
  613. * Fetch loader, sets up shouldFetch and fetch hooks
  614. */
  615. systemJSPrototype.shouldFetch = function () {
  616. return false;
  617. };
  618. if (typeof fetch !== 'undefined')
  619. systemJSPrototype.fetch = fetch;
  620. var instantiate = systemJSPrototype.instantiate;
  621. var jsContentTypeRegEx = /^(text|application)\/(x-)?javascript(;|$)/;
  622. systemJSPrototype.instantiate = function (url, parent, meta) {
  623. var loader = this;
  624. if (!this.shouldFetch(url, parent, meta))
  625. return instantiate.apply(this, arguments);
  626. return this.fetch(url, {
  627. credentials: 'same-origin',
  628. integrity: importMap.integrity[url],
  629. meta: meta,
  630. })
  631. .then(function (res) {
  632. if (!res.ok)
  633. throw Error(errMsg(7, [res.status, res.statusText, url, parent].join(', ') ));
  634. var contentType = res.headers.get('content-type');
  635. if (!contentType || !jsContentTypeRegEx.test(contentType))
  636. throw Error(errMsg(4, contentType ));
  637. return res.text().then(function (source) {
  638. if (source.indexOf('//# sourceURL=') < 0)
  639. source += '\n//# sourceURL=' + url;
  640. (0, eval)(source);
  641. return loader.getRegister(url);
  642. });
  643. });
  644. };
  645. systemJSPrototype.resolve = function (id, parentUrl) {
  646. parentUrl = parentUrl || !true || baseUrl;
  647. return resolveImportMap((importMap), resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) || throwUnresolved(id, parentUrl);
  648. };
  649. function throwUnresolved (id, parentUrl) {
  650. throw Error(errMsg(8, [id, parentUrl].join(', ') ));
  651. }
  652. var systemInstantiate = systemJSPrototype.instantiate;
  653. systemJSPrototype.instantiate = function (url, firstParentUrl, meta) {
  654. var preloads = (importMap).depcache[url];
  655. if (preloads) {
  656. for (var i = 0; i < preloads.length; i++)
  657. getOrCreateLoad(this, this.resolve(preloads[i], url), url);
  658. }
  659. return systemInstantiate.call(this, url, firstParentUrl, meta);
  660. };
  661. /*
  662. * Supports loading System.register in workers
  663. */
  664. if (hasSelf && typeof importScripts === 'function')
  665. systemJSPrototype.instantiate = function (url) {
  666. var loader = this;
  667. return Promise.resolve().then(function () {
  668. importScripts(url);
  669. return loader.getRegister(url);
  670. });
  671. };
  672. })();