system.src.js 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049
  1. /*
  2. * SystemJS v0.21.6 Dev
  3. */
  4. (function () {
  5. 'use strict';
  6. /*
  7. * Environment
  8. */
  9. var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
  10. var isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
  11. var isWindows = typeof process !== 'undefined' && typeof process.platform === 'string' && process.platform.match(/^win/);
  12. var envGlobal = typeof self !== 'undefined' ? self : global;
  13. /*
  14. * Simple Symbol() shim
  15. */
  16. var hasSymbol = typeof Symbol !== 'undefined';
  17. function createSymbol (name) {
  18. return hasSymbol ? Symbol() : '@@' + name;
  19. }
  20. var toStringTag = hasSymbol && Symbol.toStringTag;
  21. /*
  22. * Environment baseURI
  23. */
  24. var baseURI;
  25. // environent baseURI detection
  26. if (typeof document != 'undefined' && document.getElementsByTagName) {
  27. baseURI = document.baseURI;
  28. if (!baseURI) {
  29. var bases = document.getElementsByTagName('base');
  30. baseURI = bases[0] && bases[0].href || window.location.href;
  31. }
  32. }
  33. else if (typeof location != 'undefined') {
  34. baseURI = location.href;
  35. }
  36. // sanitize out the hash and querystring
  37. if (baseURI) {
  38. baseURI = baseURI.split('#')[0].split('?')[0];
  39. var slashIndex = baseURI.lastIndexOf('/');
  40. if (slashIndex !== -1)
  41. baseURI = baseURI.substr(0, slashIndex + 1);
  42. }
  43. else if (typeof process !== 'undefined' && process.cwd) {
  44. baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd();
  45. if (isWindows)
  46. baseURI = baseURI.replace(/\\/g, '/');
  47. }
  48. else {
  49. throw new TypeError('No environment baseURI');
  50. }
  51. // ensure baseURI has trailing "/"
  52. if (baseURI[baseURI.length - 1] !== '/')
  53. baseURI += '/';
  54. /*
  55. * LoaderError with chaining for loader stacks
  56. */
  57. var errArgs = new Error(0, '_').fileName == '_';
  58. function LoaderError__Check_error_message_for_loader_stack (childErr, newMessage) {
  59. // Convert file:/// URLs to paths in Node
  60. if (!isBrowser)
  61. newMessage = newMessage.replace(isWindows ? /file:\/\/\//g : /file:\/\//g, '');
  62. var message = (childErr.message || childErr) + '\n ' + newMessage;
  63. var err;
  64. if (errArgs && childErr.fileName)
  65. err = new Error(message, childErr.fileName, childErr.lineNumber);
  66. else
  67. err = new Error(message);
  68. var stack = childErr.originalErr ? childErr.originalErr.stack : childErr.stack;
  69. if (isNode)
  70. // node doesn't show the message otherwise
  71. err.stack = message + '\n ' + stack;
  72. else
  73. err.stack = stack;
  74. err.originalErr = childErr.originalErr || childErr;
  75. return err;
  76. }
  77. /*
  78. * Optimized URL normalization assuming a syntax-valid URL parent
  79. */
  80. function throwResolveError (relUrl, parentUrl) {
  81. throw new RangeError('Unable to resolve "' + relUrl + '" to ' + parentUrl);
  82. }
  83. var backslashRegEx = /\\/g;
  84. function resolveIfNotPlain (relUrl, parentUrl) {
  85. if (relUrl[0] === ' ' || relUrl[relUrl.length - 1] === ' ')
  86. relUrl = relUrl.trim();
  87. var parentProtocol = parentUrl && parentUrl.substr(0, parentUrl.indexOf(':') + 1);
  88. var firstChar = relUrl[0];
  89. var secondChar = relUrl[1];
  90. // protocol-relative
  91. if (firstChar === '/' && secondChar === '/') {
  92. if (!parentProtocol)
  93. throwResolveError(relUrl, parentUrl);
  94. if (relUrl.indexOf('\\') !== -1)
  95. relUrl = relUrl.replace(backslashRegEx, '/');
  96. return parentProtocol + relUrl;
  97. }
  98. // relative-url
  99. else if (firstChar === '.' && (secondChar === '/' || secondChar === '.' && (relUrl[2] === '/' || relUrl.length === 2 && (relUrl += '/')) ||
  100. relUrl.length === 1 && (relUrl += '/')) ||
  101. firstChar === '/') {
  102. if (relUrl.indexOf('\\') !== -1)
  103. relUrl = relUrl.replace(backslashRegEx, '/');
  104. var parentIsPlain = !parentProtocol || parentUrl[parentProtocol.length] !== '/';
  105. // read pathname from parent if a URL
  106. // pathname taken to be part after leading "/"
  107. var pathname;
  108. if (parentIsPlain) {
  109. // resolving to a plain parent -> skip standard URL prefix, and treat entire parent as pathname
  110. if (parentUrl === undefined)
  111. throwResolveError(relUrl, parentUrl);
  112. pathname = parentUrl;
  113. }
  114. else if (parentUrl[parentProtocol.length + 1] === '/') {
  115. // resolving to a :// so we need to read out the auth and host
  116. if (parentProtocol !== 'file:') {
  117. pathname = parentUrl.substr(parentProtocol.length + 2);
  118. pathname = pathname.substr(pathname.indexOf('/') + 1);
  119. }
  120. else {
  121. pathname = parentUrl.substr(8);
  122. }
  123. }
  124. else {
  125. // resolving to :/ so pathname is the /... part
  126. pathname = parentUrl.substr(parentProtocol.length + 1);
  127. }
  128. if (firstChar === '/') {
  129. if (parentIsPlain)
  130. throwResolveError(relUrl, parentUrl);
  131. else
  132. return parentUrl.substr(0, parentUrl.length - pathname.length - 1) + relUrl;
  133. }
  134. // join together and split for removal of .. and . segments
  135. // looping the string instead of anything fancy for perf reasons
  136. // '../../../../../z' resolved to 'x/y' is just 'z' regardless of parentIsPlain
  137. var segmented = pathname.substr(0, pathname.lastIndexOf('/') + 1) + relUrl;
  138. var output = [];
  139. var segmentIndex = -1;
  140. for (var i = 0; i < segmented.length; i++) {
  141. // busy reading a segment - only terminate on '/'
  142. if (segmentIndex !== -1) {
  143. if (segmented[i] === '/') {
  144. output.push(segmented.substring(segmentIndex, i + 1));
  145. segmentIndex = -1;
  146. }
  147. continue;
  148. }
  149. // new segment - check if it is relative
  150. if (segmented[i] === '.') {
  151. // ../ segment
  152. if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
  153. output.pop();
  154. i += 2;
  155. }
  156. // ./ segment
  157. else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
  158. i += 1;
  159. }
  160. else {
  161. // the start of a new segment as below
  162. segmentIndex = i;
  163. continue;
  164. }
  165. // this is the plain URI backtracking error (../, package:x -> error)
  166. if (parentIsPlain && output.length === 0)
  167. throwResolveError(relUrl, parentUrl);
  168. continue;
  169. }
  170. // it is the start of a new segment
  171. segmentIndex = i;
  172. }
  173. // finish reading out the last segment
  174. if (segmentIndex !== -1)
  175. output.push(segmented.substr(segmentIndex));
  176. return parentUrl.substr(0, parentUrl.length - pathname.length) + output.join('');
  177. }
  178. // sanitizes and verifies (by returning undefined if not a valid URL-like form)
  179. // Windows filepath compatibility is an added convenience here
  180. var protocolIndex = relUrl.indexOf(':');
  181. if (protocolIndex !== -1) {
  182. if (isNode) {
  183. // C:\x becomes file:///c:/x (we don't support C|\x)
  184. if (relUrl[1] === ':' && relUrl[2] === '\\' && relUrl[0].match(/[a-z]/i))
  185. return 'file:///' + relUrl.replace(backslashRegEx, '/');
  186. }
  187. return relUrl;
  188. }
  189. }
  190. var resolvedPromise = Promise.resolve();
  191. /*
  192. * Simple Array values shim
  193. */
  194. function arrayValues (arr) {
  195. if (arr.values)
  196. return arr.values();
  197. if (typeof Symbol === 'undefined' || !Symbol.iterator)
  198. throw new Error('Symbol.iterator not supported in this browser');
  199. var iterable = {};
  200. iterable[Symbol.iterator] = function () {
  201. var keys = Object.keys(arr);
  202. var keyIndex = 0;
  203. return {
  204. next: function () {
  205. if (keyIndex < keys.length)
  206. return {
  207. value: arr[keys[keyIndex++]],
  208. done: false
  209. };
  210. else
  211. return {
  212. value: undefined,
  213. done: true
  214. };
  215. }
  216. };
  217. };
  218. return iterable;
  219. }
  220. /*
  221. * 3. Reflect.Loader
  222. *
  223. * We skip the entire native internal pipeline, just providing the bare API
  224. */
  225. // 3.1.1
  226. function Loader () {
  227. this.registry = new Registry();
  228. }
  229. // 3.3.1
  230. Loader.prototype.constructor = Loader;
  231. function ensureInstantiated (module) {
  232. if (module === undefined)
  233. return;
  234. if (module instanceof ModuleNamespace === false && module[toStringTag] !== 'module')
  235. throw new TypeError('Module instantiation did not return a valid namespace object.');
  236. return module;
  237. }
  238. // 3.3.2
  239. Loader.prototype.import = function (key, parent) {
  240. if (typeof key !== 'string')
  241. throw new TypeError('Loader import method must be passed a module key string');
  242. // custom resolveInstantiate combined hook for better perf
  243. var loader = this;
  244. return resolvedPromise
  245. .then(function () {
  246. return loader[RESOLVE_INSTANTIATE](key, parent);
  247. })
  248. .then(ensureInstantiated)
  249. //.then(Module.evaluate)
  250. .catch(function (err) {
  251. throw LoaderError__Check_error_message_for_loader_stack(err, 'Loading ' + key + (parent ? ' from ' + parent : ''));
  252. });
  253. };
  254. // 3.3.3
  255. var RESOLVE = Loader.resolve = createSymbol('resolve');
  256. /*
  257. * Combined resolve / instantiate hook
  258. *
  259. * Not in current reduced spec, but necessary to separate RESOLVE from RESOLVE + INSTANTIATE as described
  260. * in the spec notes of this repo to ensure that loader.resolve doesn't instantiate when not wanted.
  261. *
  262. * We implement RESOLVE_INSTANTIATE as a single hook instead of a separate INSTANTIATE in order to avoid
  263. * the need for double registry lookups as a performance optimization.
  264. */
  265. var RESOLVE_INSTANTIATE = Loader.resolveInstantiate = createSymbol('resolveInstantiate');
  266. // default resolveInstantiate is just to call resolve and then get from the registry
  267. // this provides compatibility for the resolveInstantiate optimization
  268. Loader.prototype[RESOLVE_INSTANTIATE] = function (key, parent) {
  269. var loader = this;
  270. return loader.resolve(key, parent)
  271. .then(function (resolved) {
  272. return loader.registry.get(resolved);
  273. });
  274. };
  275. function ensureResolution (resolvedKey) {
  276. if (resolvedKey === undefined)
  277. throw new RangeError('No resolution found.');
  278. return resolvedKey;
  279. }
  280. Loader.prototype.resolve = function (key, parent) {
  281. var loader = this;
  282. return resolvedPromise
  283. .then(function() {
  284. return loader[RESOLVE](key, parent);
  285. })
  286. .then(ensureResolution)
  287. .catch(function (err) {
  288. throw LoaderError__Check_error_message_for_loader_stack(err, 'Resolving ' + key + (parent ? ' to ' + parent : ''));
  289. });
  290. };
  291. // 3.3.4 (import without evaluate)
  292. // this is not documented because the use of deferred evaluation as in Module.evaluate is not
  293. // documented, as it is not considered a stable feature to be encouraged
  294. // Loader.prototype.load may well be deprecated if this stays disabled
  295. /* Loader.prototype.load = function (key, parent) {
  296. return Promise.resolve(this[RESOLVE_INSTANTIATE](key, parent || this.key))
  297. .catch(function (err) {
  298. throw addToError(err, 'Loading ' + key + (parent ? ' from ' + parent : ''));
  299. });
  300. }; */
  301. /*
  302. * 4. Registry
  303. *
  304. * Instead of structuring through a Map, just use a dictionary object
  305. * We throw for construction attempts so this doesn't affect the public API
  306. *
  307. * Registry has been adjusted to use Namespace objects over ModuleStatus objects
  308. * as part of simplifying loader API implementation
  309. */
  310. var iteratorSupport = typeof Symbol !== 'undefined' && Symbol.iterator;
  311. var REGISTRY = createSymbol('registry');
  312. function Registry() {
  313. this[REGISTRY] = {};
  314. }
  315. // 4.4.1
  316. if (iteratorSupport) {
  317. // 4.4.2
  318. Registry.prototype[Symbol.iterator] = function () {
  319. return this.entries()[Symbol.iterator]();
  320. };
  321. // 4.4.3
  322. Registry.prototype.entries = function () {
  323. var registry = this[REGISTRY];
  324. return arrayValues(Object.keys(registry).map(function (key) {
  325. return [key, registry[key]];
  326. }));
  327. };
  328. }
  329. // 4.4.4
  330. Registry.prototype.keys = function () {
  331. return arrayValues(Object.keys(this[REGISTRY]));
  332. };
  333. // 4.4.5
  334. Registry.prototype.values = function () {
  335. var registry = this[REGISTRY];
  336. return arrayValues(Object.keys(registry).map(function (key) {
  337. return registry[key];
  338. }));
  339. };
  340. // 4.4.6
  341. Registry.prototype.get = function (key) {
  342. return this[REGISTRY][key];
  343. };
  344. // 4.4.7
  345. Registry.prototype.set = function (key, namespace) {
  346. if (!(namespace instanceof ModuleNamespace || namespace[toStringTag] === 'module'))
  347. throw new Error('Registry must be set with an instance of Module Namespace');
  348. this[REGISTRY][key] = namespace;
  349. return this;
  350. };
  351. // 4.4.8
  352. Registry.prototype.has = function (key) {
  353. return Object.hasOwnProperty.call(this[REGISTRY], key);
  354. };
  355. // 4.4.9
  356. Registry.prototype.delete = function (key) {
  357. if (Object.hasOwnProperty.call(this[REGISTRY], key)) {
  358. delete this[REGISTRY][key];
  359. return true;
  360. }
  361. return false;
  362. };
  363. /*
  364. * Simple ModuleNamespace Exotic object based on a baseObject
  365. * We export this for allowing a fast-path for module namespace creation over Module descriptors
  366. */
  367. // var EVALUATE = createSymbol('evaluate');
  368. var BASE_OBJECT = createSymbol('baseObject');
  369. // 8.3.1 Reflect.Module
  370. /*
  371. * Best-effort simplified non-spec implementation based on
  372. * a baseObject referenced via getters.
  373. *
  374. * Allows:
  375. *
  376. * loader.registry.set('x', new Module({ default: 'x' }));
  377. *
  378. * Optional evaluation function provides experimental Module.evaluate
  379. * support for non-executed modules in registry.
  380. */
  381. function ModuleNamespace (baseObject/*, evaluate*/) {
  382. Object.defineProperty(this, BASE_OBJECT, {
  383. value: baseObject
  384. });
  385. // evaluate defers namespace population
  386. /* if (evaluate) {
  387. Object.defineProperty(this, EVALUATE, {
  388. value: evaluate,
  389. configurable: true,
  390. writable: true
  391. });
  392. }
  393. else { */
  394. Object.keys(baseObject).forEach(extendNamespace, this);
  395. //}
  396. }// 8.4.2
  397. ModuleNamespace.prototype = Object.create(null);
  398. if (toStringTag)
  399. Object.defineProperty(ModuleNamespace.prototype, toStringTag, {
  400. value: 'Module'
  401. });
  402. function extendNamespace (key) {
  403. Object.defineProperty(this, key, {
  404. enumerable: true,
  405. get: function () {
  406. return this[BASE_OBJECT][key];
  407. }
  408. });
  409. }
  410. /* function doEvaluate (evaluate, context) {
  411. try {
  412. evaluate.call(context);
  413. }
  414. catch (e) {
  415. return e;
  416. }
  417. }
  418. // 8.4.1 Module.evaluate... not documented or used because this is potentially unstable
  419. Module.evaluate = function (ns) {
  420. var evaluate = ns[EVALUATE];
  421. if (evaluate) {
  422. ns[EVALUATE] = undefined;
  423. var err = doEvaluate(evaluate);
  424. if (err) {
  425. // cache the error
  426. ns[EVALUATE] = function () {
  427. throw err;
  428. };
  429. throw err;
  430. }
  431. Object.keys(ns[BASE_OBJECT]).forEach(extendNamespace, ns);
  432. }
  433. // make chainable
  434. return ns;
  435. }; */
  436. var resolvedPromise$1 = Promise.resolve();
  437. /*
  438. * Register Loader
  439. *
  440. * Builds directly on top of loader polyfill to provide:
  441. * - loader.register support
  442. * - hookable higher-level resolve
  443. * - instantiate hook returning a ModuleNamespace or undefined for es module loading
  444. * - loader error behaviour as in HTML and loader specs, caching load and eval errors separately
  445. * - build tracing support by providing a .trace=true and .loads object format
  446. */
  447. var REGISTER_INTERNAL = createSymbol('register-internal');
  448. function RegisterLoader () {
  449. Loader.call(this);
  450. var registryDelete = this.registry.delete;
  451. this.registry.delete = function (key) {
  452. var deleted = registryDelete.call(this, key);
  453. // also delete from register registry if linked
  454. if (records.hasOwnProperty(key) && !records[key].linkRecord) {
  455. delete records[key];
  456. deleted = true;
  457. }
  458. return deleted;
  459. };
  460. var records = {};
  461. this[REGISTER_INTERNAL] = {
  462. // last anonymous System.register call
  463. lastRegister: undefined,
  464. // in-flight es module load records
  465. records: records
  466. };
  467. // tracing
  468. this.trace = false;
  469. }
  470. RegisterLoader.prototype = Object.create(Loader.prototype);
  471. RegisterLoader.prototype.constructor = RegisterLoader;
  472. var INSTANTIATE = RegisterLoader.instantiate = createSymbol('instantiate');
  473. // default normalize is the WhatWG style normalizer
  474. RegisterLoader.prototype[RegisterLoader.resolve = Loader.resolve] = function (key, parentKey) {
  475. return resolveIfNotPlain(key, parentKey || baseURI);
  476. };
  477. RegisterLoader.prototype[INSTANTIATE] = function (key, processAnonRegister) {};
  478. // once evaluated, the linkRecord is set to undefined leaving just the other load record properties
  479. // this allows tracking new binding listeners for es modules through importerSetters
  480. // for dynamic modules, the load record is removed entirely.
  481. function createLoadRecord (state, key, registration) {
  482. return state.records[key] = {
  483. key: key,
  484. // defined System.register cache
  485. registration: registration,
  486. // module namespace object
  487. module: undefined,
  488. // es-only
  489. // this sticks around so new module loads can listen to binding changes
  490. // for already-loaded modules by adding themselves to their importerSetters
  491. importerSetters: undefined,
  492. loadError: undefined,
  493. evalError: undefined,
  494. // in-flight linking record
  495. linkRecord: {
  496. // promise for instantiated
  497. instantiatePromise: undefined,
  498. dependencies: undefined,
  499. execute: undefined,
  500. executingRequire: false,
  501. // underlying module object bindings
  502. moduleObj: undefined,
  503. // es only, also indicates if es or not
  504. setters: undefined,
  505. // promise for instantiated dependencies (dependencyInstantiations populated)
  506. depsInstantiatePromise: undefined,
  507. // will be the array of dependency load record or a module namespace
  508. dependencyInstantiations: undefined,
  509. // top-level await!
  510. evaluatePromise: undefined,
  511. // NB optimization and way of ensuring module objects in setters
  512. // indicates setters which should run pre-execution of that dependency
  513. // setters is then just for completely executed module objects
  514. // alternatively we just pass the partially filled module objects as
  515. // arguments into the execute function
  516. // hoisted: undefined
  517. }
  518. };
  519. }
  520. RegisterLoader.prototype[Loader.resolveInstantiate] = function (key, parentKey) {
  521. var loader = this;
  522. var state = this[REGISTER_INTERNAL];
  523. var registry = this.registry[REGISTRY];
  524. return resolveInstantiate(loader, key, parentKey, registry, state)
  525. .then(function (instantiated) {
  526. if (instantiated instanceof ModuleNamespace || instantiated[toStringTag] === 'module')
  527. return instantiated;
  528. // resolveInstantiate always returns a load record with a link record and no module value
  529. var link = instantiated.linkRecord;
  530. // if already beaten to done, return
  531. if (!link) {
  532. if (instantiated.module)
  533. return instantiated.module;
  534. throw instantiated.evalError;
  535. }
  536. return deepInstantiateDeps(loader, instantiated, link, registry, state)
  537. .then(function () {
  538. return ensureEvaluate(loader, instantiated, link, registry, state);
  539. });
  540. });
  541. };
  542. function resolveInstantiate (loader, key, parentKey, registry, state) {
  543. // normalization shortpath for already-normalized key
  544. // could add a plain name filter, but doesn't yet seem necessary for perf
  545. var module = registry[key];
  546. if (module)
  547. return Promise.resolve(module);
  548. var load = state.records[key];
  549. // already linked but not in main registry is ignored
  550. if (load && !load.module) {
  551. if (load.loadError)
  552. return Promise.reject(load.loadError);
  553. return instantiate(loader, load, load.linkRecord, registry, state);
  554. }
  555. return loader.resolve(key, parentKey)
  556. .then(function (resolvedKey) {
  557. // main loader registry always takes preference
  558. module = registry[resolvedKey];
  559. if (module)
  560. return module;
  561. load = state.records[resolvedKey];
  562. // already has a module value but not already in the registry (load.module)
  563. // means it was removed by registry.delete, so we should
  564. // disgard the current load record creating a new one over it
  565. // but keep any existing registration
  566. if (!load || load.module)
  567. load = createLoadRecord(state, resolvedKey, load && load.registration);
  568. if (load.loadError)
  569. return Promise.reject(load.loadError);
  570. var link = load.linkRecord;
  571. if (!link)
  572. return load;
  573. return instantiate(loader, load, link, registry, state);
  574. });
  575. }
  576. function createProcessAnonRegister (loader, load, state) {
  577. return function () {
  578. var lastRegister = state.lastRegister;
  579. if (!lastRegister)
  580. return !!load.registration;
  581. state.lastRegister = undefined;
  582. load.registration = lastRegister;
  583. return true;
  584. };
  585. }
  586. function instantiate (loader, load, link, registry, state) {
  587. return link.instantiatePromise || (link.instantiatePromise =
  588. // if there is already an existing registration, skip running instantiate
  589. (load.registration ? resolvedPromise$1 : resolvedPromise$1.then(function () {
  590. state.lastRegister = undefined;
  591. return loader[INSTANTIATE](load.key, loader[INSTANTIATE].length > 1 && createProcessAnonRegister(loader, load, state));
  592. }))
  593. .then(function (instantiation) {
  594. // direct module return from instantiate -> we're done
  595. if (instantiation !== undefined) {
  596. if (!(instantiation instanceof ModuleNamespace || instantiation[toStringTag] === 'module'))
  597. throw new TypeError('Instantiate did not return a valid Module object.');
  598. delete state.records[load.key];
  599. if (loader.trace)
  600. traceLoad(loader, load, link);
  601. return registry[load.key] = instantiation;
  602. }
  603. // run the cached loader.register declaration if there is one
  604. var registration = load.registration;
  605. // clear to allow new registrations for future loads (combined with registry delete)
  606. load.registration = undefined;
  607. if (!registration)
  608. throw new TypeError('Module instantiation did not call an anonymous or correctly named System.register.');
  609. link.dependencies = registration[0];
  610. load.importerSetters = [];
  611. link.moduleObj = {};
  612. // process System.registerDynamic declaration
  613. if (registration[2]) {
  614. link.moduleObj.default = link.moduleObj.__useDefault = {};
  615. link.executingRequire = registration[1];
  616. link.execute = registration[2];
  617. }
  618. // process System.register declaration
  619. else {
  620. registerDeclarative(loader, load, link, registration[1]);
  621. }
  622. return load;
  623. })
  624. .catch(function (err) {
  625. load.linkRecord = undefined;
  626. throw load.loadError = load.loadError || LoaderError__Check_error_message_for_loader_stack(err, 'Instantiating ' + load.key);
  627. }));
  628. }
  629. // like resolveInstantiate, but returning load records for linking
  630. function resolveInstantiateDep (loader, key, parentKey, registry, state, traceDepMap) {
  631. // normalization shortpaths for already-normalized key
  632. // DISABLED to prioritise consistent resolver calls
  633. // could add a plain name filter, but doesn't yet seem necessary for perf
  634. /* var load = state.records[key];
  635. var module = registry[key];
  636. if (module) {
  637. if (traceDepMap)
  638. traceDepMap[key] = key;
  639. // registry authority check in case module was deleted or replaced in main registry
  640. if (load && load.module && load.module === module)
  641. return load;
  642. else
  643. return module;
  644. }
  645. // already linked but not in main registry is ignored
  646. if (load && !load.module) {
  647. if (traceDepMap)
  648. traceDepMap[key] = key;
  649. return instantiate(loader, load, load.linkRecord, registry, state);
  650. } */
  651. return loader.resolve(key, parentKey)
  652. .then(function (resolvedKey) {
  653. if (traceDepMap)
  654. traceDepMap[key] = resolvedKey;
  655. // normalization shortpaths for already-normalized key
  656. var load = state.records[resolvedKey];
  657. var module = registry[resolvedKey];
  658. // main loader registry always takes preference
  659. if (module && (!load || load.module && module !== load.module))
  660. return module;
  661. if (load && load.loadError)
  662. throw load.loadError;
  663. // already has a module value but not already in the registry (load.module)
  664. // means it was removed by registry.delete, so we should
  665. // disgard the current load record creating a new one over it
  666. // but keep any existing registration
  667. if (!load || !module && load.module)
  668. load = createLoadRecord(state, resolvedKey, load && load.registration);
  669. var link = load.linkRecord;
  670. if (!link)
  671. return load;
  672. return instantiate(loader, load, link, registry, state);
  673. });
  674. }
  675. function traceLoad (loader, load, link) {
  676. loader.loads = loader.loads || {};
  677. loader.loads[load.key] = {
  678. key: load.key,
  679. deps: link.dependencies,
  680. dynamicDeps: [],
  681. depMap: link.depMap || {}
  682. };
  683. }
  684. /*
  685. * Convert a CJS module.exports into a valid object for new Module:
  686. *
  687. * new Module(getEsModule(module.exports))
  688. *
  689. * Sets the default value to the module, while also reading off named exports carefully.
  690. */
  691. function registerDeclarative (loader, load, link, declare) {
  692. var moduleObj = link.moduleObj;
  693. var importerSetters = load.importerSetters;
  694. var definedExports = false;
  695. // closure especially not based on link to allow link record disposal
  696. var declared = declare.call(envGlobal, function (name, value) {
  697. if (typeof name === 'object') {
  698. var changed = false;
  699. for (var p in name) {
  700. value = name[p];
  701. if (p !== '__useDefault' && (!(p in moduleObj) || moduleObj[p] !== value)) {
  702. changed = true;
  703. moduleObj[p] = value;
  704. }
  705. }
  706. if (changed === false)
  707. return value;
  708. }
  709. else {
  710. if ((definedExports || name in moduleObj) && moduleObj[name] === value)
  711. return value;
  712. moduleObj[name] = value;
  713. }
  714. for (var i = 0; i < importerSetters.length; i++)
  715. importerSetters[i](moduleObj);
  716. return value;
  717. }, new ContextualLoader(loader, load.key));
  718. link.setters = declared.setters || [];
  719. link.execute = declared.execute;
  720. if (declared.exports) {
  721. link.moduleObj = moduleObj = declared.exports;
  722. definedExports = true;
  723. }
  724. }
  725. function instantiateDeps (loader, load, link, registry, state) {
  726. if (link.depsInstantiatePromise)
  727. return link.depsInstantiatePromise;
  728. var depsInstantiatePromises = Array(link.dependencies.length);
  729. for (var i = 0; i < link.dependencies.length; i++)
  730. depsInstantiatePromises[i] = resolveInstantiateDep(loader, link.dependencies[i], load.key, registry, state, loader.trace && link.depMap || (link.depMap = {}));
  731. var depsInstantiatePromise = Promise.all(depsInstantiatePromises)
  732. .then(function (dependencyInstantiations) {
  733. link.dependencyInstantiations = dependencyInstantiations;
  734. // run setters to set up bindings to instantiated dependencies
  735. if (link.setters) {
  736. for (var i = 0; i < dependencyInstantiations.length; i++) {
  737. var setter = link.setters[i];
  738. if (setter) {
  739. var instantiation = dependencyInstantiations[i];
  740. if (instantiation instanceof ModuleNamespace || instantiation[toStringTag] === 'module') {
  741. setter(instantiation);
  742. }
  743. else {
  744. if (instantiation.loadError)
  745. throw instantiation.loadError;
  746. setter(instantiation.module || instantiation.linkRecord.moduleObj);
  747. // this applies to both es and dynamic registrations
  748. if (instantiation.importerSetters)
  749. instantiation.importerSetters.push(setter);
  750. }
  751. }
  752. }
  753. }
  754. return load;
  755. });
  756. if (loader.trace)
  757. depsInstantiatePromise = depsInstantiatePromise.then(function () {
  758. traceLoad(loader, load, link);
  759. return load;
  760. });
  761. depsInstantiatePromise = depsInstantiatePromise.catch(function (err) {
  762. // throw up the instantiateDeps stack
  763. link.depsInstantiatePromise = undefined;
  764. throw LoaderError__Check_error_message_for_loader_stack(err, 'Loading ' + load.key);
  765. });
  766. depsInstantiatePromise.catch(function () {});
  767. return link.depsInstantiatePromise = depsInstantiatePromise;
  768. }
  769. function deepInstantiateDeps (loader, load, link, registry, state) {
  770. var seen = [];
  771. function addDeps (load, link) {
  772. if (!link)
  773. return resolvedPromise$1;
  774. if (seen.indexOf(load) !== -1)
  775. return resolvedPromise$1;
  776. seen.push(load);
  777. return instantiateDeps(loader, load, link, registry, state)
  778. .then(function () {
  779. var depPromises;
  780. for (var i = 0; i < link.dependencies.length; i++) {
  781. var depLoad = link.dependencyInstantiations[i];
  782. if (!(depLoad instanceof ModuleNamespace || depLoad[toStringTag] === 'module')) {
  783. depPromises = depPromises || [];
  784. depPromises.push(addDeps(depLoad, depLoad.linkRecord));
  785. }
  786. }
  787. if (depPromises)
  788. return Promise.all(depPromises);
  789. });
  790. }
  791. return addDeps(load, link);
  792. }
  793. /*
  794. * System.register
  795. */
  796. RegisterLoader.prototype.register = function (key, deps, declare) {
  797. var state = this[REGISTER_INTERNAL];
  798. // anonymous modules get stored as lastAnon
  799. if (declare === undefined) {
  800. state.lastRegister = [key, deps, undefined];
  801. }
  802. // everything else registers into the register cache
  803. else {
  804. var load = state.records[key] || createLoadRecord(state, key, undefined);
  805. load.registration = [deps, declare, undefined];
  806. }
  807. };
  808. /*
  809. * System.registerDyanmic
  810. */
  811. RegisterLoader.prototype.registerDynamic = function (key, deps, executingRequire, execute) {
  812. var state = this[REGISTER_INTERNAL];
  813. // anonymous modules get stored as lastAnon
  814. if (typeof key !== 'string') {
  815. state.lastRegister = [key, deps, executingRequire];
  816. }
  817. // everything else registers into the register cache
  818. else {
  819. var load = state.records[key] || createLoadRecord(state, key, undefined);
  820. load.registration = [deps, executingRequire, execute];
  821. }
  822. };
  823. // ContextualLoader class
  824. // backwards-compatible with previous System.register context argument by exposing .id, .key
  825. function ContextualLoader (loader, key) {
  826. this.loader = loader;
  827. this.key = this.id = key;
  828. this.meta = {
  829. url: key
  830. // scriptElement: null
  831. };
  832. }
  833. /*ContextualLoader.prototype.constructor = function () {
  834. throw new TypeError('Cannot subclass the contextual loader only Reflect.Loader.');
  835. };*/
  836. ContextualLoader.prototype.import = function (key) {
  837. if (this.loader.trace)
  838. this.loader.loads[this.key].dynamicDeps.push(key);
  839. return this.loader.import(key, this.key);
  840. };
  841. /*ContextualLoader.prototype.resolve = function (key) {
  842. return this.loader.resolve(key, this.key);
  843. };*/
  844. function ensureEvaluate (loader, load, link, registry, state) {
  845. if (load.module)
  846. return load.module;
  847. if (load.evalError)
  848. throw load.evalError;
  849. if (link.evaluatePromise)
  850. return link.evaluatePromise;
  851. if (link.setters) {
  852. var evaluatePromise = doEvaluateDeclarative(loader, load, link, registry, state, [load]);
  853. if (evaluatePromise)
  854. return evaluatePromise;
  855. }
  856. else {
  857. doEvaluateDynamic(loader, load, link, registry, state, [load]);
  858. }
  859. return load.module;
  860. }
  861. function makeDynamicRequire (loader, key, dependencies, dependencyInstantiations, registry, state, seen) {
  862. // we can only require from already-known dependencies
  863. return function (name) {
  864. for (var i = 0; i < dependencies.length; i++) {
  865. if (dependencies[i] === name) {
  866. var depLoad = dependencyInstantiations[i];
  867. var module;
  868. if (depLoad instanceof ModuleNamespace || depLoad[toStringTag] === 'module') {
  869. module = depLoad;
  870. }
  871. else {
  872. if (depLoad.evalError)
  873. throw depLoad.evalError;
  874. if (depLoad.module === undefined && seen.indexOf(depLoad) === -1 && !depLoad.linkRecord.evaluatePromise) {
  875. if (depLoad.linkRecord.setters) {
  876. doEvaluateDeclarative(loader, depLoad, depLoad.linkRecord, registry, state, [depLoad]);
  877. }
  878. else {
  879. seen.push(depLoad);
  880. doEvaluateDynamic(loader, depLoad, depLoad.linkRecord, registry, state, seen);
  881. }
  882. }
  883. module = depLoad.module || depLoad.linkRecord.moduleObj;
  884. }
  885. return '__useDefault' in module ? module.__useDefault : module;
  886. }
  887. }
  888. throw new Error('Module ' + name + ' not declared as a System.registerDynamic dependency of ' + key);
  889. };
  890. }
  891. function evalError (load, err) {
  892. load.linkRecord = undefined;
  893. var evalError = LoaderError__Check_error_message_for_loader_stack(err, 'Evaluating ' + load.key);
  894. if (load.evalError === undefined)
  895. load.evalError = evalError;
  896. throw evalError;
  897. }
  898. // es modules evaluate dependencies first
  899. // returns the error if any
  900. function doEvaluateDeclarative (loader, load, link, registry, state, seen) {
  901. var depLoad, depLink;
  902. var depLoadPromises;
  903. for (var i = 0; i < link.dependencies.length; i++) {
  904. var depLoad = link.dependencyInstantiations[i];
  905. if (depLoad instanceof ModuleNamespace || depLoad[toStringTag] === 'module')
  906. continue;
  907. // custom Module returned from instantiate
  908. depLink = depLoad.linkRecord;
  909. if (depLink) {
  910. if (depLoad.evalError) {
  911. evalError(load, depLoad.evalError);
  912. }
  913. else if (depLink.setters) {
  914. if (seen.indexOf(depLoad) === -1) {
  915. seen.push(depLoad);
  916. try {
  917. var depLoadPromise = doEvaluateDeclarative(loader, depLoad, depLink, registry, state, seen);
  918. }
  919. catch (e) {
  920. evalError(load, e);
  921. }
  922. if (depLoadPromise) {
  923. depLoadPromises = depLoadPromises || [];
  924. depLoadPromises.push(depLoadPromise.catch(function (err) {
  925. evalError(load, err);
  926. }));
  927. }
  928. }
  929. }
  930. else {
  931. try {
  932. doEvaluateDynamic(loader, depLoad, depLink, registry, state, [depLoad]);
  933. }
  934. catch (e) {
  935. evalError(load, e);
  936. }
  937. }
  938. }
  939. }
  940. if (depLoadPromises)
  941. return link.evaluatePromise = Promise.all(depLoadPromises)
  942. .then(function () {
  943. if (link.execute) {
  944. // ES System.register execute
  945. // "this" is null in ES
  946. try {
  947. var execPromise = link.execute.call(nullContext);
  948. }
  949. catch (e) {
  950. evalError(load, e);
  951. }
  952. if (execPromise)
  953. return execPromise.catch(function (e) {
  954. evalError(load, e);
  955. })
  956. .then(function () {
  957. load.linkRecord = undefined;
  958. return registry[load.key] = load.module = new ModuleNamespace(link.moduleObj);
  959. });
  960. }
  961. // dispose link record
  962. load.linkRecord = undefined;
  963. registry[load.key] = load.module = new ModuleNamespace(link.moduleObj);
  964. });
  965. if (link.execute) {
  966. // ES System.register execute
  967. // "this" is null in ES
  968. try {
  969. var execPromise = link.execute.call(nullContext);
  970. }
  971. catch (e) {
  972. evalError(load, e);
  973. }
  974. if (execPromise)
  975. return link.evaluatePromise = execPromise.catch(function (e) {
  976. evalError(load, e);
  977. })
  978. .then(function () {
  979. load.linkRecord = undefined;
  980. return registry[load.key] = load.module = new ModuleNamespace(link.moduleObj);
  981. });
  982. }
  983. // dispose link record
  984. load.linkRecord = undefined;
  985. registry[load.key] = load.module = new ModuleNamespace(link.moduleObj);
  986. }
  987. // non es modules explicitly call moduleEvaluate through require
  988. function doEvaluateDynamic (loader, load, link, registry, state, seen) {
  989. // System.registerDynamic execute
  990. // "this" is "exports" in CJS
  991. var module = { id: load.key };
  992. var moduleObj = link.moduleObj;
  993. Object.defineProperty(module, 'exports', {
  994. configurable: true,
  995. set: function (exports) {
  996. moduleObj.default = moduleObj.__useDefault = exports;
  997. },
  998. get: function () {
  999. return moduleObj.__useDefault;
  1000. }
  1001. });
  1002. var require = makeDynamicRequire(loader, load.key, link.dependencies, link.dependencyInstantiations, registry, state, seen);
  1003. // evaluate deps first
  1004. if (!link.executingRequire)
  1005. for (var i = 0; i < link.dependencies.length; i++)
  1006. require(link.dependencies[i]);
  1007. try {
  1008. var output = link.execute.call(envGlobal, require, moduleObj.default, module);
  1009. if (output !== undefined)
  1010. module.exports = output;
  1011. }
  1012. catch (e) {
  1013. evalError(load, e);
  1014. }
  1015. load.linkRecord = undefined;
  1016. // pick up defineProperty calls to module.exports when we can
  1017. if (module.exports !== moduleObj.__useDefault)
  1018. moduleObj.default = moduleObj.__useDefault = module.exports;
  1019. var moduleDefault = moduleObj.default;
  1020. // __esModule flag extension support via lifting
  1021. if (moduleDefault && moduleDefault.__esModule) {
  1022. for (var p in moduleDefault) {
  1023. if (Object.hasOwnProperty.call(moduleDefault, p))
  1024. moduleObj[p] = moduleDefault[p];
  1025. }
  1026. }
  1027. registry[load.key] = load.module = new ModuleNamespace(link.moduleObj);
  1028. // run importer setters and clear them
  1029. // this allows dynamic modules to update themselves into es modules
  1030. // as soon as execution has completed
  1031. if (load.importerSetters)
  1032. for (var i = 0; i < load.importerSetters.length; i++)
  1033. load.importerSetters[i](load.module);
  1034. load.importerSetters = undefined;
  1035. }
  1036. // the closest we can get to call(undefined)
  1037. var nullContext = Object.create(null);
  1038. if (Object.freeze)
  1039. Object.freeze(nullContext);
  1040. var resolvedPromise$2 = Promise.resolve();
  1041. function noop () {}
  1042. var emptyModule = new ModuleNamespace({});
  1043. function protectedCreateNamespace (bindings) {
  1044. if (bindings) {
  1045. if (bindings instanceof ModuleNamespace || bindings[toStringTag] === 'module')
  1046. return bindings;
  1047. if (bindings.__esModule)
  1048. return new ModuleNamespace(bindings);
  1049. }
  1050. return new ModuleNamespace({ default: bindings, __useDefault: bindings });
  1051. }
  1052. function isModule (m) {
  1053. return m instanceof ModuleNamespace || m[toStringTag] === 'module';
  1054. }
  1055. var CONFIG = createSymbol('loader-config');
  1056. var METADATA = createSymbol('metadata');
  1057. var isWorker = typeof window === 'undefined' && typeof self !== 'undefined' && typeof importScripts !== 'undefined';
  1058. function warn (msg, force) {
  1059. if (force || this.warnings && typeof console !== 'undefined' && console.warn)
  1060. console.warn(msg);
  1061. }
  1062. function checkInstantiateWasm (loader, wasmBuffer, processAnonRegister) {
  1063. var bytes = new Uint8Array(wasmBuffer);
  1064. // detect by leading bytes
  1065. // Can be (new Uint32Array(fetched))[0] === 0x6D736100 when working in Node
  1066. if (bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115) {
  1067. return WebAssembly.compile(wasmBuffer).then(function (m) {
  1068. var deps = [];
  1069. var setters = [];
  1070. var importObj = {};
  1071. // we can only set imports if supported (eg Safari doesnt support)
  1072. if (WebAssembly.Module.imports)
  1073. WebAssembly.Module.imports(m).forEach(function (i) {
  1074. var key = i.module;
  1075. setters.push(function (m) {
  1076. importObj[key] = m;
  1077. });
  1078. if (deps.indexOf(key) === -1)
  1079. deps.push(key);
  1080. });
  1081. loader.register(deps, function (_export) {
  1082. return {
  1083. setters: setters,
  1084. execute: function () {
  1085. _export(new WebAssembly.Instance(m, importObj).exports);
  1086. }
  1087. };
  1088. });
  1089. processAnonRegister();
  1090. return true;
  1091. });
  1092. }
  1093. return Promise.resolve(false);
  1094. }
  1095. var parentModuleContext;
  1096. function loadNodeModule (key, baseURL) {
  1097. if (key[0] === '.')
  1098. throw new Error('Node module ' + key + ' can\'t be loaded as it is not a package require.');
  1099. if (!parentModuleContext) {
  1100. var Module = this._nodeRequire('module');
  1101. var base = decodeURI(baseURL.substr(isWindows ? 8 : 7));
  1102. parentModuleContext = new Module(base);
  1103. parentModuleContext.paths = Module._nodeModulePaths(base);
  1104. }
  1105. return parentModuleContext.require(key);
  1106. }
  1107. function extend (a, b) {
  1108. for (var p in b) {
  1109. if (!Object.hasOwnProperty.call(b, p))
  1110. continue;
  1111. a[p] = b[p];
  1112. }
  1113. return a;
  1114. }
  1115. function prepend (a, b) {
  1116. for (var p in b) {
  1117. if (!Object.hasOwnProperty.call(b, p))
  1118. continue;
  1119. if (a[p] === undefined)
  1120. a[p] = b[p];
  1121. }
  1122. return a;
  1123. }
  1124. // meta first-level extends where:
  1125. // array + array appends
  1126. // object + object extends
  1127. // other properties replace
  1128. function extendMeta (a, b, _prepend) {
  1129. for (var p in b) {
  1130. if (!Object.hasOwnProperty.call(b, p))
  1131. continue;
  1132. var val = b[p];
  1133. if (a[p] === undefined)
  1134. a[p] = val;
  1135. else if (val instanceof Array && a[p] instanceof Array)
  1136. a[p] = [].concat(_prepend ? val : a[p]).concat(_prepend ? a[p] : val);
  1137. else if (typeof val == 'object' && val !== null && typeof a[p] == 'object')
  1138. a[p] = (_prepend ? prepend : extend)(extend({}, a[p]), val);
  1139. else if (!_prepend)
  1140. a[p] = val;
  1141. }
  1142. }
  1143. var supportsPreload = false, supportsPrefetch = false;
  1144. if (isBrowser)
  1145. (function () {
  1146. var relList = document.createElement('link').relList;
  1147. if (relList && relList.supports) {
  1148. supportsPrefetch = true;
  1149. try {
  1150. supportsPreload = relList.supports('preload');
  1151. }
  1152. catch (e) {}
  1153. }
  1154. })();
  1155. function preloadScript (url) {
  1156. // fallback to old fashioned image technique which still works in safari
  1157. if (!supportsPreload && !supportsPrefetch) {
  1158. var preloadImage = new Image();
  1159. preloadImage.src = url;
  1160. return;
  1161. }
  1162. var link = document.createElement('link');
  1163. if (supportsPreload) {
  1164. link.rel = 'preload';
  1165. link.as = 'script';
  1166. }
  1167. else {
  1168. // this works for all except Safari (detected by relList.supports lacking)
  1169. link.rel = 'prefetch';
  1170. }
  1171. link.href = url;
  1172. document.head.appendChild(link);
  1173. }
  1174. function workerImport (src, resolve, reject) {
  1175. try {
  1176. importScripts(src);
  1177. }
  1178. catch (e) {
  1179. reject(e);
  1180. }
  1181. resolve();
  1182. }
  1183. if (isBrowser) {
  1184. var onerror = window.onerror;
  1185. window.onerror = function globalOnerror (msg, src) {
  1186. if (onerror)
  1187. onerror.apply(this, arguments);
  1188. };
  1189. }
  1190. function scriptLoad (src, crossOrigin, integrity, resolve, reject) {
  1191. // percent encode just "#" for HTTP requests
  1192. src = src.replace(/#/g, '%23');
  1193. // subresource integrity is not supported in web workers
  1194. if (isWorker)
  1195. return workerImport(src, resolve, reject);
  1196. var script = document.createElement('script');
  1197. script.type = 'text/javascript';
  1198. script.charset = 'utf-8';
  1199. script.async = true;
  1200. if (crossOrigin)
  1201. script.crossOrigin = crossOrigin;
  1202. if (integrity)
  1203. script.integrity = integrity;
  1204. script.addEventListener('load', load, false);
  1205. script.addEventListener('error', error, false);
  1206. script.src = src;
  1207. document.head.appendChild(script);
  1208. function load () {
  1209. resolve();
  1210. cleanup();
  1211. }
  1212. // note this does not catch execution errors
  1213. function error (err) {
  1214. cleanup();
  1215. reject(new Error('Fetching ' + src));
  1216. }
  1217. function cleanup () {
  1218. script.removeEventListener('load', load, false);
  1219. script.removeEventListener('error', error, false);
  1220. document.head.removeChild(script);
  1221. }
  1222. }
  1223. function readMemberExpression (p, value) {
  1224. var pParts = p.split('.');
  1225. while (pParts.length)
  1226. value = value[pParts.shift()];
  1227. return value;
  1228. }
  1229. // separate out paths cache as a baseURL lock process
  1230. function applyPaths (baseURL, paths, key) {
  1231. var mapMatch = getMapMatch(paths, key);
  1232. if (mapMatch) {
  1233. var target = paths[mapMatch] + key.substr(mapMatch.length);
  1234. var resolved = resolveIfNotPlain(target, baseURI);
  1235. if (resolved !== undefined)
  1236. return resolved;
  1237. return baseURL + target;
  1238. }
  1239. else if (key.indexOf(':') !== -1) {
  1240. return key;
  1241. }
  1242. else {
  1243. return baseURL + key;
  1244. }
  1245. }
  1246. function checkMap (p) {
  1247. var name = this.name;
  1248. // can add ':' here if we want paths to match the behaviour of map
  1249. if (name.substr(0, p.length) === p && (name.length === p.length || name[p.length] === '/' || p[p.length - 1] === '/' || p[p.length - 1] === ':')) {
  1250. var curLen = p.split('/').length;
  1251. if (curLen > this.len) {
  1252. this.match = p;
  1253. this.len = curLen;
  1254. }
  1255. }
  1256. }
  1257. function getMapMatch (map, name) {
  1258. if (Object.hasOwnProperty.call(map, name))
  1259. return name;
  1260. var bestMatch = {
  1261. name: name,
  1262. match: undefined,
  1263. len: 0
  1264. };
  1265. Object.keys(map).forEach(checkMap, bestMatch);
  1266. return bestMatch.match;
  1267. }
  1268. // RegEx adjusted from https://github.com/jbrantly/yabble/blob/master/lib/yabble.js#L339
  1269. var cjsRequireRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF."'])require\s*\(\s*("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|`[^`\\]*(?:\\.[^`\\]*)*`)\s*\)/g;
  1270. /*
  1271. * Source loading
  1272. */
  1273. function fetchFetch (url, authorization, integrity, asBuffer) {
  1274. // fetch doesn't support file:/// urls
  1275. if (url.substr(0, 8) === 'file:///') {
  1276. if (hasXhr)
  1277. return xhrFetch(url, authorization, integrity, asBuffer);
  1278. else
  1279. throw new Error('Unable to fetch file URLs in this environment.');
  1280. }
  1281. // percent encode just "#" for HTTP requests
  1282. url = url.replace(/#/g, '%23');
  1283. var opts = {
  1284. // NB deprecate
  1285. headers: { Accept: 'application/x-es-module, */*' }
  1286. };
  1287. if (integrity)
  1288. opts.integrity = integrity;
  1289. if (authorization) {
  1290. if (typeof authorization == 'string')
  1291. opts.headers['Authorization'] = authorization;
  1292. opts.credentials = 'include';
  1293. }
  1294. return fetch(url, opts)
  1295. .then(function(res) {
  1296. if (res.ok)
  1297. return asBuffer ? res.arrayBuffer() : res.text();
  1298. else
  1299. throw new Error('Fetch error: ' + res.status + ' ' + res.statusText);
  1300. });
  1301. }
  1302. function xhrFetch (url, authorization, integrity, asBuffer) {
  1303. return new Promise(function (resolve, reject) {
  1304. // percent encode just "#" for HTTP requests
  1305. url = url.replace(/#/g, '%23');
  1306. var xhr = new XMLHttpRequest();
  1307. if (asBuffer)
  1308. xhr.responseType = 'arraybuffer';
  1309. function load() {
  1310. resolve(asBuffer ? xhr.response : xhr.responseText);
  1311. }
  1312. function error() {
  1313. reject(new Error('XHR error: ' + (xhr.status ? ' (' + xhr.status + (xhr.statusText ? ' ' + xhr.statusText : '') + ')' : '') + ' loading ' + url));
  1314. }
  1315. xhr.onreadystatechange = function () {
  1316. if (xhr.readyState === 4) {
  1317. // in Chrome on file:/// URLs, status is 0
  1318. if (xhr.status == 0) {
  1319. if (xhr.response) {
  1320. load();
  1321. }
  1322. else {
  1323. // when responseText is empty, wait for load or error event
  1324. // to inform if it is a 404 or empty file
  1325. xhr.addEventListener('error', error);
  1326. xhr.addEventListener('load', load);
  1327. }
  1328. }
  1329. else if (xhr.status === 200) {
  1330. load();
  1331. }
  1332. else {
  1333. error();
  1334. }
  1335. }
  1336. };
  1337. xhr.open("GET", url, true);
  1338. if (xhr.setRequestHeader) {
  1339. xhr.setRequestHeader('Accept', 'application/x-es-module, */*');
  1340. // can set "authorization: true" to enable withCredentials only
  1341. if (authorization) {
  1342. if (typeof authorization == 'string')
  1343. xhr.setRequestHeader('Authorization', authorization);
  1344. xhr.withCredentials = true;
  1345. }
  1346. }
  1347. xhr.send(null);
  1348. });
  1349. }
  1350. var fs;
  1351. function nodeFetch (url, authorization, integrity, asBuffer) {
  1352. if (url.substr(0, 8) != 'file:///') {
  1353. if (hasFetch)
  1354. return fetchFetch(url, authorization, integrity, asBuffer);
  1355. else
  1356. return Promise.reject(new Error('Unable to fetch "' + url + '". Only file URLs of the form file:/// supported running in Node without fetch.'));
  1357. }
  1358. fs = fs || require('fs');
  1359. if (isWindows)
  1360. url = url.replace(/\//g, '\\').substr(8);
  1361. else
  1362. url = url.substr(7);
  1363. return new Promise(function (resolve, reject) {
  1364. fs.readFile(url, function(err, data) {
  1365. if (err) {
  1366. return reject(err);
  1367. }
  1368. else {
  1369. if (asBuffer) {
  1370. resolve(data);
  1371. }
  1372. else {
  1373. // Strip Byte Order Mark out if it's the leading char
  1374. var dataString = data + '';
  1375. if (dataString[0] === '\ufeff')
  1376. dataString = dataString.substr(1);
  1377. resolve(dataString);
  1378. }
  1379. }
  1380. });
  1381. });
  1382. }
  1383. function noFetch () {
  1384. throw new Error('No fetch method is defined for this environment.');
  1385. }
  1386. var fetchFunction;
  1387. var hasXhr = typeof XMLHttpRequest !== 'undefined';
  1388. var hasFetch = typeof fetch !== 'undefined';
  1389. if (typeof self !== 'undefined' && typeof self.fetch !== 'undefined')
  1390. fetchFunction = fetchFetch;
  1391. else if (hasXhr)
  1392. fetchFunction = xhrFetch;
  1393. else if (typeof require !== 'undefined' && typeof process !== 'undefined')
  1394. fetchFunction = nodeFetch;
  1395. else
  1396. fetchFunction = noFetch;
  1397. var fetch$1 = fetchFunction;
  1398. function createMetadata () {
  1399. return {
  1400. pluginKey: undefined,
  1401. pluginArgument: undefined,
  1402. pluginModule: undefined,
  1403. packageKey: undefined,
  1404. packageConfig: undefined,
  1405. load: undefined
  1406. };
  1407. }
  1408. function getParentMetadata (loader, config, parentKey) {
  1409. var parentMetadata = createMetadata();
  1410. if (parentKey) {
  1411. // detect parent plugin
  1412. // we just need pluginKey to be truthy for package configurations
  1413. // so we duplicate it as pluginArgument - although not correct its not used
  1414. var parentPluginIndex;
  1415. if (config.pluginFirst) {
  1416. if ((parentPluginIndex = parentKey.lastIndexOf('!')) !== -1)
  1417. parentMetadata.pluginArgument = parentMetadata.pluginKey = parentKey.substr(0, parentPluginIndex);
  1418. }
  1419. else {
  1420. if ((parentPluginIndex = parentKey.indexOf('!')) !== -1)
  1421. parentMetadata.pluginArgument = parentMetadata.pluginKey = parentKey.substr(parentPluginIndex + 1);
  1422. }
  1423. // detect parent package
  1424. parentMetadata.packageKey = getMapMatch(config.packages, parentKey);
  1425. if (parentMetadata.packageKey)
  1426. parentMetadata.packageConfig = config.packages[parentMetadata.packageKey];
  1427. }
  1428. return parentMetadata;
  1429. }
  1430. function normalize (key, parentKey) {
  1431. var config = this[CONFIG];
  1432. var metadata = createMetadata();
  1433. var parentMetadata = getParentMetadata(this, config, parentKey);
  1434. var loader = this;
  1435. return Promise.resolve()
  1436. // boolean conditional
  1437. .then(function () {
  1438. // first we normalize the conditional
  1439. var booleanIndex = key.lastIndexOf('#?');
  1440. if (booleanIndex === -1)
  1441. return Promise.resolve(key);
  1442. var conditionObj = parseCondition.call(loader, key.substr(booleanIndex + 2));
  1443. // in builds, return normalized conditional
  1444. /*if (this.builder)
  1445. return this.resolve(conditionObj.module, parentKey)
  1446. .then(function (conditionModule) {
  1447. conditionObj.module = conditionModule;
  1448. return key.substr(0, booleanIndex) + '#?' + serializeCondition(conditionObj);
  1449. });*/
  1450. return resolveCondition.call(loader, conditionObj, parentKey, true)
  1451. .then(function (conditionValue) {
  1452. return conditionValue ? key.substr(0, booleanIndex) : '@empty';
  1453. });
  1454. })
  1455. // plugin
  1456. .then(function (key) {
  1457. var parsed = parsePlugin(config.pluginFirst, key);
  1458. if (!parsed)
  1459. return packageResolve.call(loader, config, key, parentMetadata && parentMetadata.pluginArgument || parentKey, metadata, parentMetadata, false);
  1460. metadata.pluginKey = parsed.plugin;
  1461. return Promise.all([
  1462. packageResolve.call(loader, config, parsed.argument, parentMetadata && parentMetadata.pluginArgument || parentKey, metadata, parentMetadata, true),
  1463. loader.resolve(parsed.plugin, parentKey)
  1464. ])
  1465. .then(function (normalized) {
  1466. metadata.pluginArgument = normalized[0];
  1467. metadata.pluginKey = normalized[1];
  1468. // don't allow a plugin to load itself
  1469. if (metadata.pluginArgument === metadata.pluginKey)
  1470. throw new Error('Plugin ' + metadata.pluginArgument + ' cannot load itself, make sure it is excluded from any wildcard meta configuration via a custom loader: false rule.');
  1471. return combinePluginParts(config.pluginFirst, normalized[0], normalized[1]);
  1472. });
  1473. })
  1474. .then(function (normalized) {
  1475. return interpolateConditional.call(loader, normalized, parentKey, parentMetadata);
  1476. })
  1477. .then(function (normalized) {
  1478. setMeta.call(loader, config, normalized, metadata);
  1479. if (metadata.pluginKey || !metadata.load.loader)
  1480. return normalized;
  1481. // loader by configuration
  1482. // normalizes to parent to support package loaders
  1483. return loader.resolve(metadata.load.loader, normalized)
  1484. .then(function (pluginKey) {
  1485. metadata.pluginKey = pluginKey;
  1486. metadata.pluginArgument = normalized;
  1487. return normalized;
  1488. });
  1489. })
  1490. .then(function (normalized) {
  1491. loader[METADATA][normalized] = metadata;
  1492. return normalized;
  1493. });
  1494. }
  1495. // normalization function used for registry keys
  1496. // just does coreResolve without map
  1497. function decanonicalize (config, key) {
  1498. var parsed = parsePlugin(config.pluginFirst, key);
  1499. // plugin
  1500. if (parsed) {
  1501. var pluginKey = decanonicalize.call(this, config, parsed.plugin);
  1502. return combinePluginParts(config.pluginFirst, coreResolve.call(this, config, parsed.argument, undefined, false, false), pluginKey);
  1503. }
  1504. return coreResolve.call(this, config, key, undefined, false, false);
  1505. }
  1506. function normalizeSync (key, parentKey) {
  1507. var config = this[CONFIG];
  1508. // normalizeSync is metadataless, so create metadata
  1509. var metadata = createMetadata();
  1510. var parentMetadata = parentMetadata || getParentMetadata(this, config, parentKey);
  1511. var parsed = parsePlugin(config.pluginFirst, key);
  1512. // plugin
  1513. if (parsed) {
  1514. metadata.pluginKey = normalizeSync.call(this, parsed.plugin, parentKey);
  1515. return combinePluginParts(config.pluginFirst,
  1516. packageResolveSync.call(this, config, parsed.argument, parentMetadata.pluginArgument || parentKey, metadata, parentMetadata, !!metadata.pluginKey),
  1517. metadata.pluginKey);
  1518. }
  1519. return packageResolveSync.call(this, config, key, parentMetadata.pluginArgument || parentKey, metadata, parentMetadata, !!metadata.pluginKey);
  1520. }
  1521. function coreResolve (config, key, parentKey, doMap, packageName) {
  1522. var relativeResolved = resolveIfNotPlain(key, parentKey || baseURI);
  1523. // standard URL resolution
  1524. if (relativeResolved)
  1525. return applyPaths(config.baseURL, config.paths, relativeResolved);
  1526. // plain keys not starting with './', 'x://' and '/' go through custom resolution
  1527. if (doMap) {
  1528. var mapMatch = getMapMatch(config.map, key);
  1529. if (mapMatch) {
  1530. key = config.map[mapMatch] + key.substr(mapMatch.length);
  1531. relativeResolved = resolveIfNotPlain(key, baseURI);
  1532. if (relativeResolved)
  1533. return applyPaths(config.baseURL, config.paths, relativeResolved);
  1534. }
  1535. }
  1536. if (this.registry.has(key))
  1537. return key;
  1538. if (key.substr(0, 6) === '@node/')
  1539. return key;
  1540. var trailingSlash = packageName && key[key.length - 1] !== '/';
  1541. var resolved = applyPaths(config.baseURL, config.paths, trailingSlash ? key + '/' : key);
  1542. if (trailingSlash)
  1543. return resolved.substr(0, resolved.length - 1);
  1544. return resolved;
  1545. }
  1546. function packageResolveSync (config, key, parentKey, metadata, parentMetadata, skipExtensions) {
  1547. // ignore . since internal maps handled by standard package resolution
  1548. if (parentMetadata && parentMetadata.packageConfig && key[0] !== '.') {
  1549. var parentMap = parentMetadata.packageConfig.map;
  1550. var parentMapMatch = parentMap && getMapMatch(parentMap, key);
  1551. if (parentMapMatch && typeof parentMap[parentMapMatch] === 'string') {
  1552. var mapped = doMapSync(this, config, parentMetadata.packageConfig, parentMetadata.packageKey, parentMapMatch, key, metadata, skipExtensions);
  1553. if (mapped)
  1554. return mapped;
  1555. }
  1556. }
  1557. var normalized = coreResolve.call(this, config, key, parentKey, true, true);
  1558. var pkgConfigMatch = getPackageConfigMatch(config, normalized);
  1559. metadata.packageKey = pkgConfigMatch && pkgConfigMatch.packageKey || getMapMatch(config.packages, normalized);
  1560. if (!metadata.packageKey)
  1561. return normalized;
  1562. if (config.packageConfigKeys.indexOf(normalized) !== -1) {
  1563. metadata.packageKey = undefined;
  1564. return normalized;
  1565. }
  1566. metadata.packageConfig = config.packages[metadata.packageKey] || (config.packages[metadata.packageKey] = createPackage());
  1567. var subPath = normalized.substr(metadata.packageKey.length + 1);
  1568. return applyPackageConfigSync(this, config, metadata.packageConfig, metadata.packageKey, subPath, metadata, skipExtensions);
  1569. }
  1570. function packageResolve (config, key, parentKey, metadata, parentMetadata, skipExtensions) {
  1571. var loader = this;
  1572. return resolvedPromise$2
  1573. .then(function () {
  1574. // ignore . since internal maps handled by standard package resolution
  1575. if (parentMetadata && parentMetadata.packageConfig && key.substr(0, 2) !== './') {
  1576. var parentMap = parentMetadata.packageConfig.map;
  1577. var parentMapMatch = parentMap && getMapMatch(parentMap, key);
  1578. if (parentMapMatch)
  1579. return doMap(loader, config, parentMetadata.packageConfig, parentMetadata.packageKey, parentMapMatch, key, metadata, skipExtensions);
  1580. }
  1581. return resolvedPromise$2;
  1582. })
  1583. .then(function (mapped) {
  1584. if (mapped)
  1585. return mapped;
  1586. // apply map, core, paths, contextual package map
  1587. var normalized = coreResolve.call(loader, config, key, parentKey, true, true);
  1588. var pkgConfigMatch = getPackageConfigMatch(config, normalized);
  1589. metadata.packageKey = pkgConfigMatch && pkgConfigMatch.packageKey || getMapMatch(config.packages, normalized);
  1590. if (!metadata.packageKey)
  1591. return Promise.resolve(normalized);
  1592. if (config.packageConfigKeys.indexOf(normalized) !== -1) {
  1593. metadata.packageKey = undefined;
  1594. metadata.load = createMeta();
  1595. metadata.load.format = 'json';
  1596. // ensure no loader
  1597. metadata.load.loader = '';
  1598. return Promise.resolve(normalized);
  1599. }
  1600. metadata.packageConfig = config.packages[metadata.packageKey] || (config.packages[metadata.packageKey] = createPackage());
  1601. // load configuration when it matches packageConfigPaths, not already configured, and not the config itself
  1602. var loadConfig = pkgConfigMatch && !metadata.packageConfig.configured;
  1603. return (loadConfig ? loadPackageConfigPath(loader, config, pkgConfigMatch.configPath, metadata) : resolvedPromise$2)
  1604. .then(function () {
  1605. var subPath = normalized.substr(metadata.packageKey.length + 1);
  1606. return applyPackageConfig(loader, config, metadata.packageConfig, metadata.packageKey, subPath, metadata, skipExtensions);
  1607. });
  1608. });
  1609. }
  1610. function createMeta () {
  1611. return {
  1612. extension: '',
  1613. deps: undefined,
  1614. format: undefined,
  1615. loader: undefined,
  1616. scriptLoad: undefined,
  1617. globals: undefined,
  1618. nonce: undefined,
  1619. integrity: undefined,
  1620. sourceMap: undefined,
  1621. exports: undefined,
  1622. encapsulateGlobal: false,
  1623. crossOrigin: undefined,
  1624. cjsRequireDetection: true,
  1625. cjsDeferDepsExecute: false,
  1626. esModule: false
  1627. };
  1628. }
  1629. function setMeta (config, key, metadata) {
  1630. metadata.load = metadata.load || createMeta();
  1631. // apply wildcard metas
  1632. var bestDepth = 0;
  1633. var wildcardIndex;
  1634. for (var module in config.meta) {
  1635. wildcardIndex = module.indexOf('*');
  1636. if (wildcardIndex === -1)
  1637. continue;
  1638. if (module.substr(0, wildcardIndex) === key.substr(0, wildcardIndex)
  1639. && module.substr(wildcardIndex + 1) === key.substr(key.length - module.length + wildcardIndex + 1)) {
  1640. var depth = module.split('/').length;
  1641. if (depth > bestDepth)
  1642. bestDepth = depth;
  1643. extendMeta(metadata.load, config.meta[module], bestDepth !== depth);
  1644. }
  1645. }
  1646. // apply exact meta
  1647. if (config.meta[key])
  1648. extendMeta(metadata.load, config.meta[key], false);
  1649. // apply package meta
  1650. if (metadata.packageKey) {
  1651. var subPath = key.substr(metadata.packageKey.length + 1);
  1652. var meta = {};
  1653. if (metadata.packageConfig.meta) {
  1654. var bestDepth = 0;
  1655. getMetaMatches(metadata.packageConfig.meta, subPath, function (metaPattern, matchMeta, matchDepth) {
  1656. if (matchDepth > bestDepth)
  1657. bestDepth = matchDepth;
  1658. extendMeta(meta, matchMeta, matchDepth && bestDepth > matchDepth);
  1659. });
  1660. extendMeta(metadata.load, meta, false);
  1661. }
  1662. // format
  1663. if (metadata.packageConfig.format && !metadata.pluginKey && !metadata.load.loader)
  1664. metadata.load.format = metadata.load.format || metadata.packageConfig.format;
  1665. }
  1666. }
  1667. function parsePlugin (pluginFirst, key) {
  1668. var argumentKey;
  1669. var pluginKey;
  1670. var pluginIndex = pluginFirst ? key.indexOf('!') : key.lastIndexOf('!');
  1671. if (pluginIndex === -1)
  1672. return;
  1673. if (pluginFirst) {
  1674. argumentKey = key.substr(pluginIndex + 1);
  1675. pluginKey = key.substr(0, pluginIndex);
  1676. }
  1677. else {
  1678. argumentKey = key.substr(0, pluginIndex);
  1679. pluginKey = key.substr(pluginIndex + 1) || argumentKey.substr(argumentKey.lastIndexOf('.') + 1);
  1680. }
  1681. return {
  1682. argument: argumentKey,
  1683. plugin: pluginKey
  1684. };
  1685. }
  1686. // put key back together after parts have been normalized
  1687. function combinePluginParts (pluginFirst, argumentKey, pluginKey) {
  1688. if (pluginFirst)
  1689. return pluginKey + '!' + argumentKey;
  1690. else
  1691. return argumentKey + '!' + pluginKey;
  1692. }
  1693. /*
  1694. * Package Configuration Extension
  1695. *
  1696. * Example:
  1697. *
  1698. * SystemJS.packages = {
  1699. * jquery: {
  1700. * main: 'index.js', // when not set, package key is requested directly
  1701. * format: 'amd',
  1702. * defaultExtension: 'ts', // defaults to 'js', can be set to false
  1703. * modules: {
  1704. * '*.ts': {
  1705. * loader: 'typescript'
  1706. * },
  1707. * 'vendor/sizzle.js': {
  1708. * format: 'global'
  1709. * }
  1710. * },
  1711. * map: {
  1712. * // map internal require('sizzle') to local require('./vendor/sizzle')
  1713. * sizzle: './vendor/sizzle.js',
  1714. * // map any internal or external require of 'jquery/vendor/another' to 'another/index.js'
  1715. * './vendor/another.js': './another/index.js',
  1716. * // test.js / test -> lib/test.js
  1717. * './test.js': './lib/test.js',
  1718. *
  1719. * // environment-specific map configurations
  1720. * './index.js': {
  1721. * '~browser': './index-node.js',
  1722. * './custom-condition.js|~export': './index-custom.js'
  1723. * }
  1724. * },
  1725. * // allows for setting package-prefixed depCache
  1726. * // keys are normalized module keys relative to the package itself
  1727. * depCache: {
  1728. * // import 'package/index.js' loads in parallel package/lib/test.js,package/vendor/sizzle.js
  1729. * './index.js': ['./test'],
  1730. * './test.js': ['external-dep'],
  1731. * 'external-dep/path.js': ['./another.js']
  1732. * }
  1733. * }
  1734. * };
  1735. *
  1736. * Then:
  1737. * import 'jquery' -> jquery/index.js
  1738. * import 'jquery/submodule' -> jquery/submodule.js
  1739. * import 'jquery/submodule.ts' -> jquery/submodule.ts loaded as typescript
  1740. * import 'jquery/vendor/another' -> another/index.js
  1741. *
  1742. * Detailed Behaviours
  1743. * - main can have a leading "./" can be added optionally
  1744. * - map and defaultExtension are applied to the main
  1745. * - defaultExtension adds the extension only if the exact extension is not present
  1746. * - if a meta value is available for a module, map and defaultExtension are skipped
  1747. * - like global map, package map also applies to subpaths (sizzle/x, ./vendor/another/sub)
  1748. * - condition module map is '@env' module in package or '@system-env' globally
  1749. * - map targets support conditional interpolation ('./x': './x.#{|env}.js')
  1750. * - internal package map targets cannot use boolean conditionals
  1751. *
  1752. * Package Configuration Loading
  1753. *
  1754. * Not all packages may already have their configuration present in the System config
  1755. * For these cases, a list of packageConfigPaths can be provided, which when matched against
  1756. * a request, will first request a ".json" file by the package key to derive the package
  1757. * configuration from. This allows dynamic loading of non-predetermined code, a key use
  1758. * case in SystemJS.
  1759. *
  1760. * Example:
  1761. *
  1762. * SystemJS.packageConfigPaths = ['packages/test/package.json', 'packages/*.json'];
  1763. *
  1764. * // will first request 'packages/new-package/package.json' for the package config
  1765. * // before completing the package request to 'packages/new-package/path'
  1766. * SystemJS.import('packages/new-package/path');
  1767. *
  1768. * // will first request 'packages/test/package.json' before the main
  1769. * SystemJS.import('packages/test');
  1770. *
  1771. * When a package matches packageConfigPaths, it will always send a config request for
  1772. * the package configuration.
  1773. * The package key itself is taken to be the match up to and including the last wildcard
  1774. * or trailing slash.
  1775. * The most specific package config path will be used.
  1776. * Any existing package configurations for the package will deeply merge with the
  1777. * package config, with the existing package configurations taking preference.
  1778. * To opt-out of the package configuration request for a package that matches
  1779. * packageConfigPaths, use the { configured: true } package config option.
  1780. *
  1781. */
  1782. function addDefaultExtension (config, pkg, pkgKey, subPath, skipExtensions) {
  1783. // don't apply extensions to folders or if defaultExtension = false
  1784. if (!subPath || !pkg.defaultExtension || subPath[subPath.length - 1] === '/' || skipExtensions)
  1785. return subPath;
  1786. var metaMatch = false;
  1787. // exact meta or meta with any content after the last wildcard skips extension
  1788. if (pkg.meta)
  1789. getMetaMatches(pkg.meta, subPath, function (metaPattern, matchMeta, matchDepth) {
  1790. if (matchDepth === 0 || metaPattern.lastIndexOf('*') !== metaPattern.length - 1)
  1791. return metaMatch = true;
  1792. });
  1793. // exact global meta or meta with any content after the last wildcard skips extension
  1794. if (!metaMatch && config.meta)
  1795. getMetaMatches(config.meta, pkgKey + '/' + subPath, function (metaPattern, matchMeta, matchDepth) {
  1796. if (matchDepth === 0 || metaPattern.lastIndexOf('*') !== metaPattern.length - 1)
  1797. return metaMatch = true;
  1798. });
  1799. if (metaMatch)
  1800. return subPath;
  1801. // work out what the defaultExtension is and add if not there already
  1802. var defaultExtension = '.' + pkg.defaultExtension;
  1803. if (subPath.substr(subPath.length - defaultExtension.length) !== defaultExtension)
  1804. return subPath + defaultExtension;
  1805. else
  1806. return subPath;
  1807. }
  1808. function applyPackageConfigSync (loader, config, pkg, pkgKey, subPath, metadata, skipExtensions) {
  1809. // main
  1810. if (!subPath) {
  1811. if (pkg.main)
  1812. subPath = pkg.main.substr(0, 2) === './' ? pkg.main.substr(2) : pkg.main;
  1813. else
  1814. // also no submap if key is package itself (import 'pkg' -> 'path/to/pkg.js')
  1815. // NB can add a default package main convention here
  1816. // if it becomes internal to the package then it would no longer be an exit path
  1817. return pkgKey;
  1818. }
  1819. // map config checking without then with extensions
  1820. if (pkg.map) {
  1821. var mapPath = './' + subPath;
  1822. var mapMatch = getMapMatch(pkg.map, mapPath);
  1823. // we then check map with the default extension adding
  1824. if (!mapMatch) {
  1825. mapPath = './' + addDefaultExtension(config, pkg, pkgKey, subPath, skipExtensions);
  1826. if (mapPath !== './' + subPath)
  1827. mapMatch = getMapMatch(pkg.map, mapPath);
  1828. }
  1829. if (mapMatch) {
  1830. var mapped = doMapSync(loader, config, pkg, pkgKey, mapMatch, mapPath, metadata, skipExtensions);
  1831. if (mapped)
  1832. return mapped;
  1833. }
  1834. }
  1835. // normal package resolution
  1836. return pkgKey + '/' + addDefaultExtension(config, pkg, pkgKey, subPath, skipExtensions);
  1837. }
  1838. function validMapping (mapMatch, mapped, path) {
  1839. // allow internal ./x -> ./x/y or ./x/ -> ./x/y recursive maps
  1840. // but only if the path is exactly ./x and not ./x/z
  1841. if (mapped.substr(0, mapMatch.length) === mapMatch && path.length > mapMatch.length)
  1842. return false;
  1843. return true;
  1844. }
  1845. function doMapSync (loader, config, pkg, pkgKey, mapMatch, path, metadata, skipExtensions) {
  1846. if (path[path.length - 1] === '/')
  1847. path = path.substr(0, path.length - 1);
  1848. var mapped = pkg.map[mapMatch];
  1849. if (typeof mapped === 'object')
  1850. throw new Error('Synchronous conditional normalization not supported sync normalizing ' + mapMatch + ' in ' + pkgKey);
  1851. if (!validMapping(mapMatch, mapped, path) || typeof mapped !== 'string')
  1852. return;
  1853. return packageResolveSync.call(loader, config, mapped + path.substr(mapMatch.length), pkgKey + '/', metadata, metadata, skipExtensions);
  1854. }
  1855. function applyPackageConfig (loader, config, pkg, pkgKey, subPath, metadata, skipExtensions) {
  1856. // main
  1857. if (!subPath) {
  1858. if (pkg.main)
  1859. subPath = pkg.main.substr(0, 2) === './' ? pkg.main.substr(2) : pkg.main;
  1860. // also no submap if key is package itself (import 'pkg' -> 'path/to/pkg.js')
  1861. else
  1862. // NB can add a default package main convention here
  1863. // if it becomes internal to the package then it would no longer be an exit path
  1864. return Promise.resolve(pkgKey);
  1865. }
  1866. // map config checking without then with extensions
  1867. var mapPath, mapMatch;
  1868. if (pkg.map) {
  1869. mapPath = './' + subPath;
  1870. mapMatch = getMapMatch(pkg.map, mapPath);
  1871. // we then check map with the default extension adding
  1872. if (!mapMatch) {
  1873. mapPath = './' + addDefaultExtension(config, pkg, pkgKey, subPath, skipExtensions);
  1874. if (mapPath !== './' + subPath)
  1875. mapMatch = getMapMatch(pkg.map, mapPath);
  1876. }
  1877. }
  1878. return (mapMatch ? doMap(loader, config, pkg, pkgKey, mapMatch, mapPath, metadata, skipExtensions) : resolvedPromise$2)
  1879. .then(function (mapped) {
  1880. if (mapped)
  1881. return Promise.resolve(mapped);
  1882. // normal package resolution / fallback resolution for no conditional match
  1883. return Promise.resolve(pkgKey + '/' + addDefaultExtension(config, pkg, pkgKey, subPath, skipExtensions));
  1884. });
  1885. }
  1886. function doMap (loader, config, pkg, pkgKey, mapMatch, path, metadata, skipExtensions) {
  1887. if (path[path.length - 1] === '/')
  1888. path = path.substr(0, path.length - 1);
  1889. var mapped = pkg.map[mapMatch];
  1890. if (typeof mapped === 'string') {
  1891. if (!validMapping(mapMatch, mapped, path))
  1892. return resolvedPromise$2;
  1893. return packageResolve.call(loader, config, mapped + path.substr(mapMatch.length), pkgKey + '/', metadata, metadata, skipExtensions)
  1894. .then(function (normalized) {
  1895. return interpolateConditional.call(loader, normalized, pkgKey + '/', metadata);
  1896. });
  1897. }
  1898. // we use a special conditional syntax to allow the builder to handle conditional branch points further
  1899. /*if (loader.builder)
  1900. return Promise.resolve(pkgKey + '/#:' + path);*/
  1901. // we load all conditions upfront
  1902. var conditionPromises = [];
  1903. var conditions = [];
  1904. for (var e in mapped) {
  1905. var c = parseCondition(e);
  1906. conditions.push({
  1907. condition: c,
  1908. map: mapped[e]
  1909. });
  1910. conditionPromises.push(RegisterLoader.prototype.import.call(loader, c.module, pkgKey));
  1911. }
  1912. // map object -> conditional map
  1913. return Promise.all(conditionPromises)
  1914. .then(function (conditionValues) {
  1915. // first map condition to match is used
  1916. for (var i = 0; i < conditions.length; i++) {
  1917. var c = conditions[i].condition;
  1918. var value = readMemberExpression(c.prop, '__useDefault' in conditionValues[i] ? conditionValues[i].__useDefault : conditionValues[i]);
  1919. if (!c.negate && value || c.negate && !value)
  1920. return conditions[i].map;
  1921. }
  1922. })
  1923. .then(function (mapped) {
  1924. if (mapped) {
  1925. if (!validMapping(mapMatch, mapped, path))
  1926. return resolvedPromise$2;
  1927. return packageResolve.call(loader, config, mapped + path.substr(mapMatch.length), pkgKey + '/', metadata, metadata, skipExtensions)
  1928. .then(function (normalized) {
  1929. return interpolateConditional.call(loader, normalized, pkgKey + '/', metadata);
  1930. });
  1931. }
  1932. // no environment match -> fallback to original subPath by returning undefined
  1933. });
  1934. }
  1935. // check if the given normalized key matches a packageConfigPath
  1936. // if so, loads the config
  1937. var packageConfigPaths = {};
  1938. // data object for quick checks against package paths
  1939. function createPkgConfigPathObj (path) {
  1940. var lastWildcard = path.lastIndexOf('*');
  1941. var length = Math.max(lastWildcard + 1, path.lastIndexOf('/'));
  1942. return {
  1943. length: length,
  1944. regEx: new RegExp('^(' + path.substr(0, length).replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^\\/]+') + ')(\\/|$)'),
  1945. wildcard: lastWildcard !== -1
  1946. };
  1947. }
  1948. // most specific match wins
  1949. function getPackageConfigMatch (config, normalized) {
  1950. var pkgKey, exactMatch = false, configPath;
  1951. for (var i = 0; i < config.packageConfigPaths.length; i++) {
  1952. var packageConfigPath = config.packageConfigPaths[i];
  1953. var p = packageConfigPaths[packageConfigPath] || (packageConfigPaths[packageConfigPath] = createPkgConfigPathObj(packageConfigPath));
  1954. if (normalized.length < p.length)
  1955. continue;
  1956. var match = normalized.match(p.regEx);
  1957. if (match && (!pkgKey || (!(exactMatch && p.wildcard) && pkgKey.length < match[1].length))) {
  1958. pkgKey = match[1];
  1959. exactMatch = !p.wildcard;
  1960. configPath = pkgKey + packageConfigPath.substr(p.length);
  1961. }
  1962. }
  1963. if (!pkgKey)
  1964. return;
  1965. return {
  1966. packageKey: pkgKey,
  1967. configPath: configPath
  1968. };
  1969. }
  1970. function loadPackageConfigPath (loader, config, pkgConfigPath, metadata, normalized) {
  1971. var configLoader = loader.pluginLoader || loader;
  1972. // ensure we note this is a package config file path
  1973. // it will then be skipped from getting other normalizations itself to ensure idempotency
  1974. if (config.packageConfigKeys.indexOf(pkgConfigPath) === -1)
  1975. config.packageConfigKeys.push(pkgConfigPath);
  1976. return configLoader.import(pkgConfigPath)
  1977. .then(function (pkgConfig) {
  1978. setPkgConfig(metadata.packageConfig, pkgConfig, metadata.packageKey, true, config);
  1979. metadata.packageConfig.configured = true;
  1980. })
  1981. .catch(function (err) {
  1982. throw LoaderError__Check_error_message_for_loader_stack(err, 'Unable to fetch package configuration file ' + pkgConfigPath);
  1983. });
  1984. }
  1985. function getMetaMatches (pkgMeta, subPath, matchFn) {
  1986. // wildcard meta
  1987. var wildcardIndex;
  1988. for (var module in pkgMeta) {
  1989. // allow meta to start with ./ for flexibility
  1990. var dotRel = module.substr(0, 2) === './' ? './' : '';
  1991. if (dotRel)
  1992. module = module.substr(2);
  1993. wildcardIndex = module.indexOf('*');
  1994. if (wildcardIndex === -1)
  1995. continue;
  1996. if (module.substr(0, wildcardIndex) === subPath.substr(0, wildcardIndex)
  1997. && module.substr(wildcardIndex + 1) === subPath.substr(subPath.length - module.length + wildcardIndex + 1)) {
  1998. // alow match function to return true for an exit path
  1999. if (matchFn(module, pkgMeta[dotRel + module], module.split('/').length))
  2000. return;
  2001. }
  2002. }
  2003. // exact meta
  2004. var exactMeta = pkgMeta[subPath] && Object.hasOwnProperty.call(pkgMeta, subPath) ? pkgMeta[subPath] : pkgMeta['./' + subPath];
  2005. if (exactMeta)
  2006. matchFn(exactMeta, exactMeta, 0);
  2007. }
  2008. /*
  2009. * Conditions Extension
  2010. *
  2011. * Allows a condition module to alter the resolution of an import via syntax:
  2012. *
  2013. * import $ from 'jquery/#{browser}';
  2014. *
  2015. * Will first load the module 'browser' via `SystemJS.import('browser')` and
  2016. * take the default export of that module.
  2017. * If the default export is not a string, an error is thrown.
  2018. *
  2019. * We then substitute the string into the require to get the conditional resolution
  2020. * enabling environment-specific variations like:
  2021. *
  2022. * import $ from 'jquery/ie'
  2023. * import $ from 'jquery/firefox'
  2024. * import $ from 'jquery/chrome'
  2025. * import $ from 'jquery/safari'
  2026. *
  2027. * It can be useful for a condition module to define multiple conditions.
  2028. * This can be done via the `|` modifier to specify an export member expression:
  2029. *
  2030. * import 'jquery/#{./browser.js|grade.version}'
  2031. *
  2032. * Where the `grade` export `version` member in the `browser.js` module is substituted.
  2033. *
  2034. *
  2035. * Boolean Conditionals
  2036. *
  2037. * For polyfill modules, that are used as imports but have no module value,
  2038. * a binary conditional allows a module not to be loaded at all if not needed:
  2039. *
  2040. * import 'es5-shim#?./conditions.js|needs-es5shim'
  2041. *
  2042. * These conditions can also be negated via:
  2043. *
  2044. * import 'es5-shim#?./conditions.js|~es6'
  2045. *
  2046. */
  2047. var sysConditions = ['browser', 'node', 'dev', 'build', 'production', 'default'];
  2048. function parseCondition (condition) {
  2049. var conditionExport, conditionModule, negation;
  2050. var negation;
  2051. var conditionExportIndex = condition.lastIndexOf('|');
  2052. if (conditionExportIndex !== -1) {
  2053. conditionExport = condition.substr(conditionExportIndex + 1);
  2054. conditionModule = condition.substr(0, conditionExportIndex);
  2055. if (conditionExport[0] === '~') {
  2056. negation = true;
  2057. conditionExport = conditionExport.substr(1);
  2058. }
  2059. }
  2060. else {
  2061. negation = condition[0] === '~';
  2062. conditionExport = 'default';
  2063. conditionModule = condition.substr(negation);
  2064. if (sysConditions.indexOf(conditionModule) !== -1) {
  2065. conditionExport = conditionModule;
  2066. conditionModule = null;
  2067. }
  2068. }
  2069. return {
  2070. module: conditionModule || '@system-env',
  2071. prop: conditionExport,
  2072. negate: negation
  2073. };
  2074. }
  2075. function resolveCondition (conditionObj, parentKey, bool) {
  2076. // import without __useDefault handling here
  2077. return RegisterLoader.prototype.import.call(this, conditionObj.module, parentKey)
  2078. .then(function (condition) {
  2079. var m = readMemberExpression(conditionObj.prop, condition);
  2080. if (bool && typeof m !== 'boolean')
  2081. throw new TypeError('Condition did not resolve to a boolean.');
  2082. return conditionObj.negate ? !m : m;
  2083. });
  2084. }
  2085. var interpolationRegEx = /#\{[^\}]+\}/;
  2086. function interpolateConditional (key, parentKey, parentMetadata) {
  2087. // first we normalize the conditional
  2088. var conditionalMatch = key.match(interpolationRegEx);
  2089. if (!conditionalMatch)
  2090. return Promise.resolve(key);
  2091. var conditionObj = parseCondition.call(this, conditionalMatch[0].substr(2, conditionalMatch[0].length - 3));
  2092. // in builds, return normalized conditional
  2093. /*if (this.builder)
  2094. return this.normalize(conditionObj.module, parentKey, createMetadata(), parentMetadata)
  2095. .then(function (conditionModule) {
  2096. conditionObj.module = conditionModule;
  2097. return key.replace(interpolationRegEx, '#{' + serializeCondition(conditionObj) + '}');
  2098. });*/
  2099. return resolveCondition.call(this, conditionObj, parentKey, false)
  2100. .then(function (conditionValue) {
  2101. if (typeof conditionValue !== 'string')
  2102. throw new TypeError('The condition value for ' + key + ' doesn\'t resolve to a string.');
  2103. if (conditionValue.indexOf('/') !== -1)
  2104. throw new TypeError('Unabled to interpolate conditional ' + key + (parentKey ? ' in ' + parentKey : '') + '\n\tThe condition value ' + conditionValue + ' cannot contain a "/" separator.');
  2105. return key.replace(interpolationRegEx, conditionValue);
  2106. });
  2107. }
  2108. /*
  2109. Extend config merging one deep only
  2110. loader.config({
  2111. some: 'random',
  2112. config: 'here',
  2113. deep: {
  2114. config: { too: 'too' }
  2115. }
  2116. });
  2117. <=>
  2118. loader.some = 'random';
  2119. loader.config = 'here'
  2120. loader.deep = loader.deep || {};
  2121. loader.deep.config = { too: 'too' };
  2122. Normalizes meta and package configs allowing for:
  2123. SystemJS.config({
  2124. meta: {
  2125. './index.js': {}
  2126. }
  2127. });
  2128. To become
  2129. SystemJS.meta['https://thissite.com/index.js'] = {};
  2130. For easy normalization canonicalization with latest URL support.
  2131. */
  2132. var envConfigNames = ['browserConfig', 'nodeConfig', 'devConfig', 'buildConfig', 'productionConfig'];
  2133. function envSet(loader, cfg, envCallback) {
  2134. for (var i = 0; i < envConfigNames.length; i++) {
  2135. var envConfig = envConfigNames[i];
  2136. if (cfg[envConfig] && envModule[envConfig.substr(0, envConfig.length - 6)])
  2137. envCallback(cfg[envConfig]);
  2138. }
  2139. }
  2140. function cloneObj (obj, maxDepth) {
  2141. var clone = {};
  2142. for (var p in obj) {
  2143. var prop = obj[p];
  2144. if (maxDepth > 1) {
  2145. if (prop instanceof Array)
  2146. clone[p] = [].concat(prop);
  2147. else if (typeof prop === 'object')
  2148. clone[p] = cloneObj(prop, maxDepth - 1);
  2149. else if (p !== 'packageConfig')
  2150. clone[p] = prop;
  2151. }
  2152. else {
  2153. clone[p] = prop;
  2154. }
  2155. }
  2156. return clone;
  2157. }
  2158. function getConfigItem (config, p) {
  2159. var cfgItem = config[p];
  2160. // getConfig must return an unmodifiable clone of the configuration
  2161. if (cfgItem instanceof Array)
  2162. return config[p].concat([]);
  2163. else if (typeof cfgItem === 'object')
  2164. return cloneObj(cfgItem, 3)
  2165. else
  2166. return config[p];
  2167. }
  2168. function getConfig (configName) {
  2169. if (configName) {
  2170. if (configNames.indexOf(configName) !== -1)
  2171. return getConfigItem(this[CONFIG], configName);
  2172. throw new Error('"' + configName + '" is not a valid configuration name. Must be one of ' + configNames.join(', ') + '.');
  2173. }
  2174. var cfg = {};
  2175. for (var i = 0; i < configNames.length; i++) {
  2176. var p = configNames[i];
  2177. var configItem = getConfigItem(this[CONFIG], p);
  2178. if (configItem !== undefined)
  2179. cfg[p] = configItem;
  2180. }
  2181. return cfg;
  2182. }
  2183. function setConfig (cfg, isEnvConfig) {
  2184. var loader = this;
  2185. var config = this[CONFIG];
  2186. if ('warnings' in cfg)
  2187. config.warnings = cfg.warnings;
  2188. if ('wasm' in cfg)
  2189. config.wasm = typeof WebAssembly !== 'undefined' && cfg.wasm;
  2190. if ('production' in cfg || 'build' in cfg)
  2191. setProduction.call(loader, !!cfg.production, !!(cfg.build || envModule && envModule.build));
  2192. if (!isEnvConfig) {
  2193. // if using nodeConfig / browserConfig / productionConfig, take baseURL from there
  2194. // these exceptions will be unnecessary when we can properly implement config queuings
  2195. var baseURL;
  2196. envSet(loader, cfg, function(cfg) {
  2197. baseURL = baseURL || cfg.baseURL;
  2198. });
  2199. baseURL = baseURL || cfg.baseURL;
  2200. // always configure baseURL first
  2201. if (baseURL) {
  2202. config.baseURL = resolveIfNotPlain(baseURL, baseURI) || resolveIfNotPlain('./' + baseURL, baseURI);
  2203. if (config.baseURL[config.baseURL.length - 1] !== '/')
  2204. config.baseURL += '/';
  2205. }
  2206. if (cfg.paths)
  2207. extend(config.paths, cfg.paths);
  2208. envSet(loader, cfg, function(cfg) {
  2209. if (cfg.paths)
  2210. extend(config.paths, cfg.paths);
  2211. });
  2212. for (var p in config.paths) {
  2213. if (config.paths[p].indexOf('*') === -1)
  2214. continue;
  2215. warn.call(config, 'Path config ' + p + ' -> ' + config.paths[p] + ' is no longer supported as wildcards are deprecated.');
  2216. delete config.paths[p];
  2217. }
  2218. }
  2219. if (cfg.defaultJSExtensions)
  2220. warn.call(config, 'The defaultJSExtensions configuration option is deprecated.\n Use packages defaultExtension instead.', true);
  2221. if (typeof cfg.pluginFirst === 'boolean')
  2222. config.pluginFirst = cfg.pluginFirst;
  2223. if (cfg.map) {
  2224. for (var p in cfg.map) {
  2225. var v = cfg.map[p];
  2226. if (typeof v === 'string') {
  2227. var mapped = coreResolve.call(loader, config, v, undefined, false, false);
  2228. if (mapped[mapped.length -1] === '/' && p[p.length - 1] !== ':' && p[p.length - 1] !== '/')
  2229. mapped = mapped.substr(0, mapped.length - 1);
  2230. config.map[p] = mapped;
  2231. }
  2232. // object map
  2233. else {
  2234. var pkgName = coreResolve.call(loader, config, p[p.length - 1] !== '/' ? p + '/' : p, undefined, true, true);
  2235. pkgName = pkgName.substr(0, pkgName.length - 1);
  2236. var pkg = config.packages[pkgName];
  2237. if (!pkg) {
  2238. pkg = config.packages[pkgName] = createPackage();
  2239. // use '' instead of false to keep type consistent
  2240. pkg.defaultExtension = '';
  2241. }
  2242. setPkgConfig(pkg, { map: v }, pkgName, false, config);
  2243. }
  2244. }
  2245. }
  2246. if (cfg.packageConfigPaths) {
  2247. var packageConfigPaths = [];
  2248. for (var i = 0; i < cfg.packageConfigPaths.length; i++) {
  2249. var path = cfg.packageConfigPaths[i];
  2250. var packageLength = Math.max(path.lastIndexOf('*') + 1, path.lastIndexOf('/'));
  2251. var normalized = coreResolve.call(loader, config, path.substr(0, packageLength), undefined, false, false);
  2252. packageConfigPaths[i] = normalized + path.substr(packageLength);
  2253. }
  2254. config.packageConfigPaths = packageConfigPaths;
  2255. }
  2256. if (cfg.bundles) {
  2257. for (var p in cfg.bundles) {
  2258. var bundle = [];
  2259. for (var i = 0; i < cfg.bundles[p].length; i++)
  2260. bundle.push(loader.normalizeSync(cfg.bundles[p][i]));
  2261. config.bundles[p] = bundle;
  2262. }
  2263. }
  2264. if (cfg.packages) {
  2265. for (var p in cfg.packages) {
  2266. if (p.match(/^([^\/]+:)?\/\/$/))
  2267. throw new TypeError('"' + p + '" is not a valid package name.');
  2268. var pkgName = coreResolve.call(loader, config, p[p.length - 1] !== '/' ? p + '/' : p, undefined, true, true);
  2269. pkgName = pkgName.substr(0, pkgName.length - 1);
  2270. setPkgConfig(config.packages[pkgName] = config.packages[pkgName] || createPackage(), cfg.packages[p], pkgName, false, config);
  2271. }
  2272. }
  2273. if (cfg.depCache) {
  2274. for (var p in cfg.depCache)
  2275. config.depCache[loader.normalizeSync(p)] = [].concat(cfg.depCache[p]);
  2276. }
  2277. if (cfg.meta) {
  2278. for (var p in cfg.meta) {
  2279. // base wildcard stays base
  2280. if (p[0] === '*') {
  2281. extend(config.meta[p] = config.meta[p] || {}, cfg.meta[p]);
  2282. }
  2283. else {
  2284. var resolved = coreResolve.call(loader, config, p, undefined, true, true);
  2285. extend(config.meta[resolved] = config.meta[resolved] || {}, cfg.meta[p]);
  2286. }
  2287. }
  2288. }
  2289. if ('transpiler' in cfg)
  2290. config.transpiler = cfg.transpiler;
  2291. // copy any remaining non-standard configuration properties
  2292. for (var c in cfg) {
  2293. if (configNames.indexOf(c) !== -1)
  2294. continue;
  2295. if (envConfigNames.indexOf(c) !== -1)
  2296. continue;
  2297. // warn.call(config, 'Setting custom config option `System.config({ ' + c + ': ... })` is deprecated. Avoid custom config options or set SystemJS.' + c + ' = ... directly.');
  2298. loader[c] = cfg[c];
  2299. }
  2300. envSet(loader, cfg, function(cfg) {
  2301. loader.config(cfg, true);
  2302. });
  2303. }
  2304. function createPackage () {
  2305. return {
  2306. defaultExtension: undefined,
  2307. main: undefined,
  2308. format: undefined,
  2309. meta: undefined,
  2310. map: undefined,
  2311. packageConfig: undefined,
  2312. configured: false
  2313. };
  2314. }
  2315. // deeply-merge (to first level) config with any existing package config
  2316. function setPkgConfig (pkg, cfg, pkgName, prependConfig, config) {
  2317. for (var prop in cfg) {
  2318. if (prop === 'main' || prop === 'format' || prop === 'defaultExtension' || prop === 'configured') {
  2319. if (!prependConfig || pkg[prop] === undefined)
  2320. pkg[prop] = cfg[prop];
  2321. }
  2322. else if (prop === 'map') {
  2323. (prependConfig ? prepend : extend)(pkg.map = pkg.map || {}, cfg.map);
  2324. }
  2325. else if (prop === 'meta') {
  2326. (prependConfig ? prepend : extend)(pkg.meta = pkg.meta || {}, cfg.meta);
  2327. }
  2328. else if (Object.hasOwnProperty.call(cfg, prop)) {
  2329. warn.call(config, '"' + prop + '" is not a valid package configuration option in package ' + pkgName);
  2330. }
  2331. }
  2332. // default defaultExtension for packages only
  2333. if (pkg.defaultExtension === undefined)
  2334. pkg.defaultExtension = 'js';
  2335. if (pkg.main === undefined && pkg.map && pkg.map['.']) {
  2336. pkg.main = pkg.map['.'];
  2337. delete pkg.map['.'];
  2338. }
  2339. // main object becomes main map
  2340. else if (typeof pkg.main === 'object') {
  2341. pkg.map = pkg.map || {};
  2342. pkg.map['./@main'] = pkg.main;
  2343. pkg.main['default'] = pkg.main['default'] || './';
  2344. pkg.main = '@main';
  2345. }
  2346. return pkg;
  2347. }
  2348. var hasBuffer = typeof Buffer !== 'undefined';
  2349. try {
  2350. if (hasBuffer && new Buffer('a').toString('base64') !== 'YQ==')
  2351. hasBuffer = false;
  2352. }
  2353. catch (e) {
  2354. hasBuffer = false;
  2355. }
  2356. var sourceMapPrefix = '\n//# sourceMapping' + 'URL=data:application/json;base64,';
  2357. function inlineSourceMap (sourceMapString) {
  2358. if (hasBuffer)
  2359. return sourceMapPrefix + new Buffer(sourceMapString).toString('base64');
  2360. else if (typeof btoa !== 'undefined')
  2361. return sourceMapPrefix + btoa(unescape(encodeURIComponent(sourceMapString)));
  2362. else
  2363. return '';
  2364. }
  2365. function getSource(source, sourceMap, address, wrap) {
  2366. var lastLineIndex = source.lastIndexOf('\n');
  2367. if (sourceMap) {
  2368. if (typeof sourceMap != 'object')
  2369. throw new TypeError('load.metadata.sourceMap must be set to an object.');
  2370. sourceMap = JSON.stringify(sourceMap);
  2371. }
  2372. return (wrap ? '(function(System, SystemJS) {' : '') + source + (wrap ? '\n})(System, System);' : '')
  2373. // adds the sourceURL comment if not already present
  2374. + (source.substr(lastLineIndex, 15) != '\n//# sourceURL='
  2375. ? '\n//# sourceURL=' + address + (sourceMap ? '!transpiled' : '') : '')
  2376. // add sourceMappingURL if load.metadata.sourceMap is set
  2377. + (sourceMap && inlineSourceMap(sourceMap) || '');
  2378. }
  2379. // script execution via injecting a script tag into the page
  2380. // this allows CSP nonce to be set for CSP environments
  2381. var head;
  2382. function scriptExec(loader, source, sourceMap, address, nonce) {
  2383. if (!head)
  2384. head = document.head || document.body || document.documentElement;
  2385. var script = document.createElement('script');
  2386. script.text = getSource(source, sourceMap, address, false);
  2387. var onerror = window.onerror;
  2388. var e;
  2389. window.onerror = function(_e) {
  2390. e = addToError(_e, 'Evaluating ' + address);
  2391. if (onerror)
  2392. onerror.apply(this, arguments);
  2393. };
  2394. preExec(loader);
  2395. if (nonce)
  2396. script.setAttribute('nonce', nonce);
  2397. head.appendChild(script);
  2398. head.removeChild(script);
  2399. postExec();
  2400. window.onerror = onerror;
  2401. if (e)
  2402. return e;
  2403. }
  2404. var vm;
  2405. var useVm;
  2406. var curSystem;
  2407. var callCounter = 0;
  2408. function preExec (loader) {
  2409. if (callCounter++ == 0)
  2410. curSystem = envGlobal.System;
  2411. envGlobal.System = envGlobal.SystemJS = loader;
  2412. }
  2413. function postExec () {
  2414. if (--callCounter == 0)
  2415. envGlobal.System = envGlobal.SystemJS = curSystem;
  2416. }
  2417. var supportsScriptExec = false;
  2418. if (isBrowser && typeof document != 'undefined' && document.getElementsByTagName) {
  2419. if (!(window.chrome && window.chrome.extension || navigator.userAgent.match(/^Node\.js/)))
  2420. supportsScriptExec = true;
  2421. }
  2422. function evaluate (loader, source, sourceMap, address, integrity, nonce, noWrap) {
  2423. if (!source)
  2424. return;
  2425. if (nonce && supportsScriptExec)
  2426. return scriptExec(loader, source, sourceMap, address, nonce);
  2427. try {
  2428. preExec(loader);
  2429. // global scoped eval for node (avoids require scope leak)
  2430. if (!vm && loader._nodeRequire) {
  2431. vm = loader._nodeRequire('vm');
  2432. useVm = vm.runInThisContext("typeof System !== 'undefined' && System") === loader;
  2433. }
  2434. if (useVm)
  2435. vm.runInThisContext(getSource(source, sourceMap, address, !noWrap), { filename: address + (sourceMap ? '!transpiled' : '') });
  2436. else
  2437. (0, eval)(getSource(source, sourceMap, address, !noWrap));
  2438. postExec();
  2439. }
  2440. catch (e) {
  2441. postExec();
  2442. return e;
  2443. }
  2444. }
  2445. function setHelpers (loader) {
  2446. loader.set('@@cjs-helpers', loader.newModule({
  2447. requireResolve: requireResolve.bind(loader),
  2448. getPathVars: getPathVars
  2449. }));
  2450. loader.set('@@global-helpers', loader.newModule({
  2451. prepareGlobal: prepareGlobal
  2452. }));
  2453. }
  2454. function setAmdHelper (loader) {
  2455. /*
  2456. AMD-compatible require
  2457. To copy RequireJS, set window.require = window.requirejs = loader.amdRequire
  2458. */
  2459. function require (names, callback, errback, referer) {
  2460. // in amd, first arg can be a config object... we just ignore
  2461. if (typeof names === 'object' && !(names instanceof Array))
  2462. return require.apply(null, Array.prototype.splice.call(arguments, 1, arguments.length - 1));
  2463. // amd require
  2464. if (typeof names === 'string' && typeof callback === 'function')
  2465. names = [names];
  2466. if (names instanceof Array) {
  2467. var dynamicRequires = [];
  2468. for (var i = 0; i < names.length; i++)
  2469. dynamicRequires.push(loader.import(names[i], referer));
  2470. Promise.all(dynamicRequires).then(function (modules) {
  2471. if (callback)
  2472. callback.apply(null, modules);
  2473. }, errback);
  2474. }
  2475. // commonjs require
  2476. else if (typeof names === 'string') {
  2477. var normalized = loader.decanonicalize(names, referer);
  2478. var module = loader.get(normalized);
  2479. if (!module)
  2480. throw new Error('Module not already loaded loading "' + names + '" as ' + normalized + (referer ? ' from "' + referer + '".' : '.'));
  2481. return '__useDefault' in module ? module.__useDefault : module;
  2482. }
  2483. else
  2484. throw new TypeError('Invalid require');
  2485. }
  2486. function define (name, deps, factory) {
  2487. if (typeof name !== 'string') {
  2488. factory = deps;
  2489. deps = name;
  2490. name = null;
  2491. }
  2492. if (!(deps instanceof Array)) {
  2493. factory = deps;
  2494. deps = ['require', 'exports', 'module'].splice(0, factory.length);
  2495. }
  2496. if (typeof factory !== 'function')
  2497. factory = (function (factory) {
  2498. return function() { return factory; }
  2499. })(factory);
  2500. if (!name) {
  2501. if (curMetaDeps) {
  2502. deps = deps.concat(curMetaDeps);
  2503. curMetaDeps = undefined;
  2504. }
  2505. }
  2506. // remove system dependencies
  2507. var requireIndex, exportsIndex, moduleIndex;
  2508. if ((requireIndex = deps.indexOf('require')) !== -1) {
  2509. deps.splice(requireIndex, 1);
  2510. // only trace cjs requires for non-named
  2511. // named defines assume the trace has already been done
  2512. if (!name)
  2513. deps = deps.concat(amdGetCJSDeps(factory.toString(), requireIndex));
  2514. }
  2515. if ((exportsIndex = deps.indexOf('exports')) !== -1)
  2516. deps.splice(exportsIndex, 1);
  2517. if ((moduleIndex = deps.indexOf('module')) !== -1)
  2518. deps.splice(moduleIndex, 1);
  2519. function execute (req, exports, module) {
  2520. var depValues = [];
  2521. for (var i = 0; i < deps.length; i++)
  2522. depValues.push(req(deps[i]));
  2523. module.uri = module.id;
  2524. module.config = noop;
  2525. // add back in system dependencies
  2526. if (moduleIndex !== -1)
  2527. depValues.splice(moduleIndex, 0, module);
  2528. if (exportsIndex !== -1)
  2529. depValues.splice(exportsIndex, 0, exports);
  2530. if (requireIndex !== -1) {
  2531. var contextualRequire = function (names, callback, errback) {
  2532. if (typeof names === 'string' && typeof callback !== 'function')
  2533. return req(names);
  2534. return require.call(loader, names, callback, errback, module.id);
  2535. };
  2536. contextualRequire.toUrl = function (name) {
  2537. return loader.normalizeSync(name, module.id);
  2538. };
  2539. depValues.splice(requireIndex, 0, contextualRequire);
  2540. }
  2541. // set global require to AMD require
  2542. var curRequire = envGlobal.require;
  2543. envGlobal.require = require;
  2544. var output = factory.apply(exportsIndex === -1 ? envGlobal : exports, depValues);
  2545. envGlobal.require = curRequire;
  2546. if (typeof output !== 'undefined')
  2547. module.exports = output;
  2548. }
  2549. // anonymous define
  2550. if (!name) {
  2551. loader.registerDynamic(deps, false, curEsModule ? wrapEsModuleExecute(execute) : execute);
  2552. }
  2553. else {
  2554. loader.registerDynamic(name, deps, false, execute);
  2555. // if we don't have any other defines,
  2556. // then let this be an anonymous define
  2557. // this is just to support single modules of the form:
  2558. // define('jquery')
  2559. // still loading anonymously
  2560. // because it is done widely enough to be useful
  2561. // as soon as there is more than one define, this gets removed though
  2562. if (lastNamedDefine) {
  2563. lastNamedDefine = undefined;
  2564. multipleNamedDefines = true;
  2565. }
  2566. else if (!multipleNamedDefines) {
  2567. lastNamedDefine = [deps, execute];
  2568. }
  2569. }
  2570. }
  2571. define.amd = {};
  2572. loader.amdDefine = define;
  2573. loader.amdRequire = require;
  2574. }
  2575. // CJS
  2576. var windowOrigin;
  2577. if (typeof window !== 'undefined' && typeof document !== 'undefined' && window.location)
  2578. windowOrigin = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
  2579. function stripOrigin(path) {
  2580. if (path.substr(0, 8) === 'file:///')
  2581. return path.substr(7 + !!isWindows);
  2582. if (windowOrigin && path.substr(0, windowOrigin.length) === windowOrigin)
  2583. return path.substr(windowOrigin.length);
  2584. return path;
  2585. }
  2586. function requireResolve (request, parentId) {
  2587. return stripOrigin(this.normalizeSync(request, parentId));
  2588. }
  2589. function getPathVars (moduleId) {
  2590. // remove any plugin syntax
  2591. var pluginIndex = moduleId.lastIndexOf('!');
  2592. var filename;
  2593. if (pluginIndex !== -1)
  2594. filename = moduleId.substr(0, pluginIndex);
  2595. else
  2596. filename = moduleId;
  2597. var dirname = filename.split('/');
  2598. dirname.pop();
  2599. dirname = dirname.join('/');
  2600. return {
  2601. filename: stripOrigin(filename),
  2602. dirname: stripOrigin(dirname)
  2603. };
  2604. }
  2605. var commentRegEx = /(^|[^\\])(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
  2606. var stringRegEx = /("[^"\\\n\r]*(\\.[^"\\\n\r]*)*"|'[^'\\\n\r]*(\\.[^'\\\n\r]*)*')/g;
  2607. // extract CJS dependencies from source text via regex static analysis
  2608. // read require('x') statements not in comments or strings
  2609. function getCJSDeps (source) {
  2610. cjsRequireRegEx.lastIndex = commentRegEx.lastIndex = stringRegEx.lastIndex = 0;
  2611. var deps = [];
  2612. var match;
  2613. // track string and comment locations for unminified source
  2614. var stringLocations = [], commentLocations = [];
  2615. function inLocation (locations, match) {
  2616. for (var i = 0; i < locations.length; i++)
  2617. if (locations[i][0] < match.index && locations[i][1] > match.index)
  2618. return true;
  2619. return false;
  2620. }
  2621. if (source.length / source.split('\n').length < 200) {
  2622. while (match = stringRegEx.exec(source))
  2623. stringLocations.push([match.index, match.index + match[0].length]);
  2624. // TODO: track template literals here before comments
  2625. while (match = commentRegEx.exec(source)) {
  2626. // only track comments not starting in strings
  2627. if (!inLocation(stringLocations, match))
  2628. commentLocations.push([match.index + match[1].length, match.index + match[0].length - 1]);
  2629. }
  2630. }
  2631. while (match = cjsRequireRegEx.exec(source)) {
  2632. // ensure we're not within a string or comment location
  2633. if (!inLocation(stringLocations, match) && !inLocation(commentLocations, match)) {
  2634. var dep = match[1].substr(1, match[1].length - 2);
  2635. // skip cases like require('" + file + "')
  2636. if (dep.match(/"|'/))
  2637. continue;
  2638. deps.push(dep);
  2639. }
  2640. }
  2641. return deps;
  2642. }
  2643. // Global
  2644. // bare minimum ignores
  2645. var ignoredGlobalProps = ['_g', 'sessionStorage', 'localStorage', 'clipboardData', 'frames', 'frameElement', 'external',
  2646. 'mozAnimationStartTime', 'mozPaintCount', 'webkitStorageInfo', 'webkitIndexedDB', 'mozInnerScreenY', 'mozInnerScreenX'];
  2647. var globalSnapshot;
  2648. function globalIterator (globalName) {
  2649. if (ignoredGlobalProps.indexOf(globalName) !== -1)
  2650. return;
  2651. try {
  2652. var value = envGlobal[globalName];
  2653. }
  2654. catch (e) {
  2655. ignoredGlobalProps.push(globalName);
  2656. }
  2657. this(globalName, value);
  2658. }
  2659. function getGlobalValue (exports) {
  2660. if (typeof exports === 'string')
  2661. return readMemberExpression(exports, envGlobal);
  2662. if (!(exports instanceof Array))
  2663. throw new Error('Global exports must be a string or array.');
  2664. var globalValue = {};
  2665. for (var i = 0; i < exports.length; i++)
  2666. globalValue[exports[i].split('.').pop()] = readMemberExpression(exports[i], envGlobal);
  2667. return globalValue;
  2668. }
  2669. function prepareGlobal (moduleName, exports, globals, encapsulate) {
  2670. // disable module detection
  2671. var curDefine = envGlobal.define;
  2672. envGlobal.define = undefined;
  2673. // set globals
  2674. var oldGlobals;
  2675. if (globals) {
  2676. oldGlobals = {};
  2677. for (var g in globals) {
  2678. oldGlobals[g] = envGlobal[g];
  2679. envGlobal[g] = globals[g];
  2680. }
  2681. }
  2682. // store a complete copy of the global object in order to detect changes
  2683. if (!exports) {
  2684. globalSnapshot = {};
  2685. Object.keys(envGlobal).forEach(globalIterator, function (name, value) {
  2686. globalSnapshot[name] = value;
  2687. });
  2688. }
  2689. // return function to retrieve global
  2690. return function () {
  2691. var globalValue = exports ? getGlobalValue(exports) : {};
  2692. var singleGlobal;
  2693. var multipleExports = !!exports;
  2694. if (!exports || encapsulate)
  2695. Object.keys(envGlobal).forEach(globalIterator, function (name, value) {
  2696. if (globalSnapshot[name] === value)
  2697. return;
  2698. if (value === undefined)
  2699. return;
  2700. // allow global encapsulation where globals are removed
  2701. if (encapsulate)
  2702. envGlobal[name] = undefined;
  2703. if (!exports) {
  2704. globalValue[name] = value;
  2705. if (singleGlobal !== undefined) {
  2706. if (!multipleExports && singleGlobal !== value)
  2707. multipleExports = true;
  2708. }
  2709. else {
  2710. singleGlobal = value;
  2711. }
  2712. }
  2713. });
  2714. globalValue = multipleExports ? globalValue : singleGlobal;
  2715. // revert globals
  2716. if (oldGlobals) {
  2717. for (var g in oldGlobals)
  2718. envGlobal[g] = oldGlobals[g];
  2719. }
  2720. envGlobal.define = curDefine;
  2721. return globalValue;
  2722. };
  2723. }
  2724. // AMD
  2725. var cjsRequirePre = "(?:^|[^$_a-zA-Z\\xA0-\\uFFFF.])";
  2726. var cjsRequirePost = "\\s*\\(\\s*(\"([^\"]+)\"|'([^']+)')\\s*\\)";
  2727. var fnBracketRegEx = /\(([^\)]*)\)/;
  2728. var wsRegEx = /^\s+|\s+$/g;
  2729. var requireRegExs = {};
  2730. function amdGetCJSDeps(source, requireIndex) {
  2731. // remove comments
  2732. source = source.replace(commentRegEx, '');
  2733. // determine the require alias
  2734. var params = source.match(fnBracketRegEx);
  2735. var requireAlias = (params[1].split(',')[requireIndex] || 'require').replace(wsRegEx, '');
  2736. // find or generate the regex for this requireAlias
  2737. var requireRegEx = requireRegExs[requireAlias] || (requireRegExs[requireAlias] = new RegExp(cjsRequirePre + requireAlias + cjsRequirePost, 'g'));
  2738. requireRegEx.lastIndex = 0;
  2739. var deps = [];
  2740. var match;
  2741. while (match = requireRegEx.exec(source))
  2742. deps.push(match[2] || match[3]);
  2743. return deps;
  2744. }
  2745. function wrapEsModuleExecute (execute) {
  2746. return function (require, exports, module) {
  2747. execute(require, exports, module);
  2748. exports = module.exports;
  2749. if ((typeof exports === 'object' || typeof exports === 'function') && !('__esModule' in exports))
  2750. Object.defineProperty(module.exports, '__esModule', {
  2751. value: true
  2752. });
  2753. };
  2754. }
  2755. // generate anonymous define from singular named define
  2756. var multipleNamedDefines = false;
  2757. var lastNamedDefine;
  2758. var curMetaDeps;
  2759. var curEsModule = false;
  2760. function clearLastDefine (metaDeps, esModule) {
  2761. curMetaDeps = metaDeps;
  2762. curEsModule = esModule;
  2763. lastNamedDefine = undefined;
  2764. multipleNamedDefines = false;
  2765. }
  2766. function registerLastDefine (loader) {
  2767. if (lastNamedDefine)
  2768. loader.registerDynamic(curMetaDeps ? lastNamedDefine[0].concat(curMetaDeps) : lastNamedDefine[0],
  2769. false, curEsModule ? wrapEsModuleExecute(lastNamedDefine[1]) : lastNamedDefine[1]);
  2770. // bundles are an empty module
  2771. else if (multipleNamedDefines)
  2772. loader.registerDynamic([], false, noop);
  2773. }
  2774. var supportsScriptLoad = (isBrowser || isWorker) && typeof navigator !== 'undefined' && navigator.userAgent && !navigator.userAgent.match(/MSIE (9|10).0/);
  2775. // include the node require since we're overriding it
  2776. var nodeRequire;
  2777. if (typeof require !== 'undefined' && typeof process !== 'undefined' && !process.browser)
  2778. nodeRequire = require;
  2779. function setMetaEsModule (metadata, moduleValue) {
  2780. if (metadata.load.esModule && (typeof moduleValue === 'object' || typeof moduleValue === 'function') &&
  2781. !('__esModule' in moduleValue))
  2782. Object.defineProperty(moduleValue, '__esModule', {
  2783. value: true
  2784. });
  2785. }
  2786. function instantiate$1 (key, processAnonRegister) {
  2787. var loader = this;
  2788. var config = this[CONFIG];
  2789. // first do bundles and depCache
  2790. return (loadBundlesAndDepCache(config, this, key) || resolvedPromise$2)
  2791. .then(function () {
  2792. if (processAnonRegister())
  2793. return;
  2794. var metadata = loader[METADATA][key];
  2795. // node module loading
  2796. if (key.substr(0, 6) === '@node/') {
  2797. if (!loader._nodeRequire)
  2798. throw new TypeError('Error loading ' + key + '. Can only load node core modules in Node.');
  2799. loader.registerDynamic([], false, function () {
  2800. return loadNodeModule.call(loader, key.substr(6), loader.baseURL);
  2801. });
  2802. processAnonRegister();
  2803. return;
  2804. }
  2805. if (metadata.load.scriptLoad ) {
  2806. if (metadata.pluginKey || !supportsScriptLoad) {
  2807. metadata.load.scriptLoad = false;
  2808. warn.call(config, 'scriptLoad not supported for "' + key + '"');
  2809. }
  2810. }
  2811. else if (metadata.load.scriptLoad !== false && !metadata.pluginKey && supportsScriptLoad) {
  2812. // auto script load AMD, global without deps
  2813. if (!metadata.load.deps && !metadata.load.globals &&
  2814. (metadata.load.format === 'system' || metadata.load.format === 'register' || metadata.load.format === 'global' && metadata.load.exports))
  2815. metadata.load.scriptLoad = true;
  2816. }
  2817. // fetch / translate / instantiate pipeline
  2818. if (!metadata.load.scriptLoad)
  2819. return initializePlugin(loader, key, metadata)
  2820. .then(function () {
  2821. return runFetchPipeline(loader, key, metadata, processAnonRegister, config.wasm);
  2822. })
  2823. // just script loading
  2824. return new Promise(function (resolve, reject) {
  2825. if (metadata.load.format === 'amd' && envGlobal.define !== loader.amdDefine)
  2826. throw new Error('Loading AMD with scriptLoad requires setting the global `' + globalName + '.define = SystemJS.amdDefine`');
  2827. scriptLoad(key, metadata.load.crossOrigin, metadata.load.integrity, function () {
  2828. if (!processAnonRegister()) {
  2829. metadata.load.format = 'global';
  2830. var globalValue = metadata.load.exports && getGlobalValue(metadata.load.exports);
  2831. loader.registerDynamic([], false, function () {
  2832. setMetaEsModule(metadata, globalValue);
  2833. return globalValue;
  2834. });
  2835. processAnonRegister();
  2836. }
  2837. resolve();
  2838. }, reject);
  2839. });
  2840. })
  2841. .then(function (instantiated) {
  2842. delete loader[METADATA][key];
  2843. return instantiated;
  2844. });
  2845. }
  2846. function initializePlugin (loader, key, metadata) {
  2847. if (!metadata.pluginKey)
  2848. return resolvedPromise$2;
  2849. return loader.import(metadata.pluginKey).then(function (plugin) {
  2850. metadata.pluginModule = plugin;
  2851. metadata.pluginLoad = {
  2852. name: key,
  2853. address: metadata.pluginArgument,
  2854. source: undefined,
  2855. metadata: metadata.load
  2856. };
  2857. metadata.load.deps = metadata.load.deps || [];
  2858. });
  2859. }
  2860. function loadBundlesAndDepCache (config, loader, key) {
  2861. // load direct deps, in turn will pick up their trace trees
  2862. var deps;
  2863. if (isBrowser && (deps = config.depCache[key])) {
  2864. for (var i = 0; i < deps.length; i++)
  2865. loader.normalize(deps[i], key).then(preloadScript);
  2866. }
  2867. else {
  2868. var matched = false;
  2869. for (var b in config.bundles) {
  2870. for (var i = 0; i < config.bundles[b].length; i++) {
  2871. var curModule = config.bundles[b][i];
  2872. if (curModule === key) {
  2873. matched = true;
  2874. break;
  2875. }
  2876. // wildcard in bundles includes / boundaries
  2877. if (curModule.indexOf('*') !== -1) {
  2878. var parts = curModule.split('*');
  2879. if (parts.length !== 2) {
  2880. config.bundles[b].splice(i--, 1);
  2881. continue;
  2882. }
  2883. if (key.substr(0, parts[0].length) === parts[0] &&
  2884. key.substr(key.length - parts[1].length, parts[1].length) === parts[1]) {
  2885. matched = true;
  2886. break;
  2887. }
  2888. }
  2889. }
  2890. if (matched)
  2891. return loader.import(b);
  2892. }
  2893. }
  2894. }
  2895. function runFetchPipeline (loader, key, metadata, processAnonRegister, wasm) {
  2896. if (metadata.load.exports && !metadata.load.format)
  2897. metadata.load.format = 'global';
  2898. return resolvedPromise$2
  2899. // locate
  2900. .then(function () {
  2901. if (!metadata.pluginModule || !metadata.pluginModule.locate)
  2902. return;
  2903. return Promise.resolve(metadata.pluginModule.locate.call(loader, metadata.pluginLoad))
  2904. .then(function (address) {
  2905. if (address)
  2906. metadata.pluginLoad.address = address;
  2907. });
  2908. })
  2909. // fetch
  2910. .then(function () {
  2911. if (!metadata.pluginModule)
  2912. return fetch$1(key, metadata.load.authorization, metadata.load.integrity, wasm);
  2913. wasm = false;
  2914. if (!metadata.pluginModule.fetch)
  2915. return fetch$1(metadata.pluginLoad.address, metadata.load.authorization, metadata.load.integrity, false);
  2916. return metadata.pluginModule.fetch.call(loader, metadata.pluginLoad, function (load) {
  2917. return fetch$1(load.address, metadata.load.authorization, metadata.load.integrity, false);
  2918. });
  2919. })
  2920. .then(function (fetched) {
  2921. // fetch is already a utf-8 string if not doing wasm detection
  2922. if (!wasm || typeof fetched === 'string')
  2923. return translateAndInstantiate(loader, key, fetched, metadata, processAnonRegister);
  2924. return checkInstantiateWasm(loader, fetched, processAnonRegister)
  2925. .then(function (wasmInstantiated) {
  2926. if (wasmInstantiated)
  2927. return;
  2928. // not wasm -> convert buffer into utf-8 string to execute as a module
  2929. // TextDecoder compatibility matches WASM currently. Need to keep checking this.
  2930. // The TextDecoder interface is documented at http://encoding.spec.whatwg.org/#interface-textdecoder
  2931. var stringSource = isBrowser ? new TextDecoder('utf-8').decode(new Uint8Array(fetched)) : fetched.toString();
  2932. return translateAndInstantiate(loader, key, stringSource, metadata, processAnonRegister);
  2933. });
  2934. });
  2935. }
  2936. function translateAndInstantiate (loader, key, source, metadata, processAnonRegister) {
  2937. return Promise.resolve(source)
  2938. // translate
  2939. .then(function (source) {
  2940. if (metadata.load.format === 'detect')
  2941. metadata.load.format = undefined;
  2942. readMetaSyntax(source, metadata);
  2943. if (!metadata.pluginModule)
  2944. return source;
  2945. metadata.pluginLoad.source = source;
  2946. if (!metadata.pluginModule.translate)
  2947. return source;
  2948. return Promise.resolve(metadata.pluginModule.translate.call(loader, metadata.pluginLoad, metadata.traceOpts))
  2949. .then(function (translated) {
  2950. if (metadata.load.sourceMap) {
  2951. if (typeof metadata.load.sourceMap !== 'object')
  2952. throw new Error('metadata.load.sourceMap must be set to an object.');
  2953. sanitizeSourceMap(metadata.pluginLoad.address, metadata.load.sourceMap);
  2954. }
  2955. if (typeof translated === 'string')
  2956. return translated;
  2957. else
  2958. return metadata.pluginLoad.source;
  2959. });
  2960. })
  2961. .then(function (source) {
  2962. if (!metadata.load.format && source.substring(0, 8) === '"bundle"') {
  2963. metadata.load.format = 'system';
  2964. return source;
  2965. }
  2966. if (metadata.load.format === 'register' || !metadata.load.format && detectRegisterFormat(source)) {
  2967. metadata.load.format = 'register';
  2968. return source;
  2969. }
  2970. if (metadata.load.format !== 'esm' && (metadata.load.format || !source.match(esmRegEx))) {
  2971. return source;
  2972. }
  2973. metadata.load.format = 'esm';
  2974. return transpile(loader, source, key, metadata, processAnonRegister);
  2975. })
  2976. // instantiate
  2977. .then(function (translated) {
  2978. if (typeof translated !== 'string' || !metadata.pluginModule || !metadata.pluginModule.instantiate)
  2979. return translated;
  2980. var calledInstantiate = false;
  2981. metadata.pluginLoad.source = translated;
  2982. return Promise.resolve(metadata.pluginModule.instantiate.call(loader, metadata.pluginLoad, function (load) {
  2983. translated = load.source;
  2984. metadata.load = load.metadata;
  2985. if (calledInstantiate)
  2986. throw new Error('Instantiate must only be called once.');
  2987. calledInstantiate = true;
  2988. }))
  2989. .then(function (result) {
  2990. if (calledInstantiate)
  2991. return translated;
  2992. return protectedCreateNamespace(result);
  2993. });
  2994. })
  2995. .then(function (source) {
  2996. // plugin instantiate result case
  2997. if (typeof source !== 'string')
  2998. return source;
  2999. if (!metadata.load.format)
  3000. metadata.load.format = detectLegacyFormat(source);
  3001. var registered = false;
  3002. switch (metadata.load.format) {
  3003. case 'esm':
  3004. case 'register':
  3005. case 'system':
  3006. var err = evaluate(loader, source, metadata.load.sourceMap, key, metadata.load.integrity, metadata.load.nonce, false);
  3007. if (err)
  3008. throw err;
  3009. if (!processAnonRegister())
  3010. return emptyModule;
  3011. return;
  3012. break;
  3013. case 'json':
  3014. // warn.call(config, '"json" module format is deprecated.');
  3015. var parsed = JSON.parse(source);
  3016. return loader.newModule({ default: parsed, __useDefault: parsed });
  3017. case 'amd':
  3018. var curDefine = envGlobal.define;
  3019. envGlobal.define = loader.amdDefine;
  3020. clearLastDefine(metadata.load.deps, metadata.load.esModule);
  3021. var err = evaluate(loader, source, metadata.load.sourceMap, key, metadata.load.integrity, metadata.load.nonce, false);
  3022. // if didn't register anonymously, use the last named define if only one
  3023. registered = processAnonRegister();
  3024. if (!registered) {
  3025. registerLastDefine(loader);
  3026. registered = processAnonRegister();
  3027. }
  3028. envGlobal.define = curDefine;
  3029. if (err)
  3030. throw err;
  3031. break;
  3032. case 'cjs':
  3033. var metaDeps = metadata.load.deps;
  3034. var deps = (metadata.load.deps || []).concat(metadata.load.cjsRequireDetection ? getCJSDeps(source) : []);
  3035. for (var g in metadata.load.globals)
  3036. if (metadata.load.globals[g])
  3037. deps.push(metadata.load.globals[g]);
  3038. loader.registerDynamic(deps, true, function (require, exports, module) {
  3039. require.resolve = function (key) {
  3040. return requireResolve.call(loader, key, module.id);
  3041. };
  3042. // support module.paths ish
  3043. module.paths = [];
  3044. module.require = require;
  3045. // ensure meta deps execute first
  3046. if (!metadata.load.cjsDeferDepsExecute && metaDeps)
  3047. for (var i = 0; i < metaDeps.length; i++)
  3048. require(metaDeps[i]);
  3049. var pathVars = getPathVars(module.id);
  3050. var __cjsWrapper = {
  3051. exports: exports,
  3052. args: [require, exports, module, pathVars.filename, pathVars.dirname, envGlobal, envGlobal]
  3053. };
  3054. var cjsWrapper = "(function (require, exports, module, __filename, __dirname, global, GLOBAL";
  3055. // add metadata.globals to the wrapper arguments
  3056. if (metadata.load.globals)
  3057. for (var g in metadata.load.globals) {
  3058. __cjsWrapper.args.push(require(metadata.load.globals[g]));
  3059. cjsWrapper += ", " + g;
  3060. }
  3061. // disable AMD detection
  3062. var define = envGlobal.define;
  3063. envGlobal.define = undefined;
  3064. envGlobal.__cjsWrapper = __cjsWrapper;
  3065. source = cjsWrapper + ") {" + source.replace(hashBangRegEx$1, '') + "\n}).apply(__cjsWrapper.exports, __cjsWrapper.args);";
  3066. var err = evaluate(loader, source, metadata.load.sourceMap, key, metadata.load.integrity, metadata.load.nonce, false);
  3067. if (err)
  3068. throw err;
  3069. setMetaEsModule(metadata, exports);
  3070. envGlobal.__cjsWrapper = undefined;
  3071. envGlobal.define = define;
  3072. });
  3073. registered = processAnonRegister();
  3074. break;
  3075. case 'global':
  3076. var deps = metadata.load.deps || [];
  3077. for (var g in metadata.load.globals) {
  3078. var gl = metadata.load.globals[g];
  3079. if (gl)
  3080. deps.push(gl);
  3081. }
  3082. loader.registerDynamic(deps, false, function (require, exports, module) {
  3083. var globals;
  3084. if (metadata.load.globals) {
  3085. globals = {};
  3086. for (var g in metadata.load.globals)
  3087. if (metadata.load.globals[g])
  3088. globals[g] = require(metadata.load.globals[g]);
  3089. }
  3090. var exportName = metadata.load.exports;
  3091. if (exportName)
  3092. source += '\n' + globalName + '["' + exportName + '"] = ' + exportName + ';';
  3093. var retrieveGlobal = prepareGlobal(module.id, exportName, globals, metadata.load.encapsulateGlobal);
  3094. var err = evaluate(loader, source, metadata.load.sourceMap, key, metadata.load.integrity, metadata.load.nonce, true);
  3095. if (err)
  3096. throw err;
  3097. var output = retrieveGlobal();
  3098. setMetaEsModule(metadata, output);
  3099. return output;
  3100. });
  3101. registered = processAnonRegister();
  3102. break;
  3103. default:
  3104. throw new TypeError('Unknown module format "' + metadata.load.format + '" for "' + key + '".' + (metadata.load.format === 'es6' ? ' Use "esm" instead here.' : ''));
  3105. }
  3106. if (!registered)
  3107. throw new Error('Module ' + key + ' detected as ' + metadata.load.format + ' but didn\'t execute correctly.');
  3108. });
  3109. }
  3110. var globalName = typeof self != 'undefined' ? 'self' : 'global';
  3111. // good enough ES6 module detection regex - format detections not designed to be accurate, but to handle the 99% use case
  3112. var esmRegEx = /(^\s*|[}\);\n]\s*)(import\s*(['"]|(\*\s+as\s+)?(?!type)([^"'\(\)\n; ]+)\s*from\s*['"]|\{)|export\s+\*\s+from\s+["']|export\s*(\{|default|function|class|var|const|let|async\s+function))/;
  3113. var leadingCommentAndMetaRegEx = /^(\s*\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)*\s*/;
  3114. function detectRegisterFormat(source) {
  3115. var leadingCommentAndMeta = source.match(leadingCommentAndMetaRegEx);
  3116. if (!leadingCommentAndMeta)
  3117. return false;
  3118. var codeStart = leadingCommentAndMeta[0].length;
  3119. return source.substr(codeStart, 17) === 'SystemJS.register' || source.substr(codeStart, 15) === 'System.register';
  3120. }
  3121. // AMD Module Format Detection RegEx
  3122. // define([.., .., ..], ...)
  3123. // define(varName); || define(function(require, exports) {}); || define({})
  3124. 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]*\))/;
  3125. /// require('...') || exports[''] = ... || exports.asd = ... || module.exports = ...
  3126. var cjsExportsRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])(exports\s*(\[['"]|\.)|module(\.exports|\['exports'\]|\["exports"\])\s*(\[['"]|[=,\.]))/;
  3127. // used to support leading #!/usr/bin/env in scripts as supported in Node
  3128. var hashBangRegEx$1 = /^\#\!.*/;
  3129. function detectLegacyFormat (source) {
  3130. if (source.match(amdRegEx))
  3131. return 'amd';
  3132. cjsExportsRegEx.lastIndex = 0;
  3133. cjsRequireRegEx.lastIndex = 0;
  3134. if (cjsRequireRegEx.exec(source) || cjsExportsRegEx.exec(source))
  3135. return 'cjs';
  3136. // global is the fallback format
  3137. return 'global';
  3138. }
  3139. function sanitizeSourceMap (address, sourceMap) {
  3140. var originalName = address.split('!')[0];
  3141. // force set the filename of the original file
  3142. if (!sourceMap.file || sourceMap.file == address)
  3143. sourceMap.file = originalName + '!transpiled';
  3144. // force set the sources list if only one source
  3145. if (!sourceMap.sources || sourceMap.sources.length <= 1 && (!sourceMap.sources[0] || sourceMap.sources[0] === address))
  3146. sourceMap.sources = [originalName];
  3147. }
  3148. function transpile (loader, source, key, metadata, processAnonRegister) {
  3149. if (!loader.transpiler)
  3150. throw new TypeError('Unable to dynamically transpile ES module\n A loader plugin needs to be configured via `SystemJS.config({ transpiler: \'transpiler-module\' })`.');
  3151. // deps support for es transpile
  3152. if (metadata.load.deps) {
  3153. var depsPrefix = '';
  3154. for (var i = 0; i < metadata.load.deps.length; i++)
  3155. depsPrefix += 'import "' + metadata.load.deps[i] + '"; ';
  3156. source = depsPrefix + source;
  3157. }
  3158. // do transpilation
  3159. return loader.import.call(loader, loader.transpiler)
  3160. .then(function (transpiler) {
  3161. transpiler = transpiler.__useDefault || transpiler;
  3162. // translate hooks means this is a transpiler plugin instead of a raw implementation
  3163. if (!transpiler.translate)
  3164. throw new Error(loader.transpiler + ' is not a valid transpiler plugin.');
  3165. // if transpiler is the same as the plugin loader, then don't run twice
  3166. if (transpiler === metadata.pluginModule)
  3167. return source;
  3168. // convert the source map into an object for transpilation chaining
  3169. if (typeof metadata.load.sourceMap === 'string')
  3170. metadata.load.sourceMap = JSON.parse(metadata.load.sourceMap);
  3171. metadata.pluginLoad = metadata.pluginLoad || {
  3172. name: key,
  3173. address: key,
  3174. source: source,
  3175. metadata: metadata.load
  3176. };
  3177. metadata.load.deps = metadata.load.deps || [];
  3178. return Promise.resolve(transpiler.translate.call(loader, metadata.pluginLoad, metadata.traceOpts))
  3179. .then(function (source) {
  3180. // sanitize sourceMap if an object not a JSON string
  3181. var sourceMap = metadata.load.sourceMap;
  3182. if (sourceMap && typeof sourceMap === 'object')
  3183. sanitizeSourceMap(key, sourceMap);
  3184. if (metadata.load.format === 'esm' && detectRegisterFormat(source))
  3185. metadata.load.format = 'register';
  3186. return source;
  3187. });
  3188. }, function (err) {
  3189. throw LoaderError__Check_error_message_for_loader_stack(err, 'Unable to load transpiler to transpile ' + key);
  3190. });
  3191. }
  3192. // detect any meta header syntax
  3193. // only set if not already set
  3194. var metaRegEx = /^(\s*\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)+/;
  3195. var metaPartRegEx = /\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\/\/[^\n]*|"[^"]+"\s*;?|'[^']+'\s*;?/g;
  3196. function setMetaProperty(target, p, value) {
  3197. var pParts = p.split('.');
  3198. var curPart;
  3199. while (pParts.length > 1) {
  3200. curPart = pParts.shift();
  3201. target = target[curPart] = target[curPart] || {};
  3202. }
  3203. curPart = pParts.shift();
  3204. if (target[curPart] === undefined)
  3205. target[curPart] = value;
  3206. }
  3207. function readMetaSyntax (source, metadata) {
  3208. var meta = source.match(metaRegEx);
  3209. if (!meta)
  3210. return;
  3211. var metaParts = meta[0].match(metaPartRegEx);
  3212. for (var i = 0; i < metaParts.length; i++) {
  3213. var curPart = metaParts[i];
  3214. var len = curPart.length;
  3215. var firstChar = curPart.substr(0, 1);
  3216. if (curPart.substr(len - 1, 1) == ';')
  3217. len--;
  3218. if (firstChar != '"' && firstChar != "'")
  3219. continue;
  3220. var metaString = curPart.substr(1, curPart.length - 3);
  3221. var metaName = metaString.substr(0, metaString.indexOf(' '));
  3222. if (metaName) {
  3223. var metaValue = metaString.substr(metaName.length + 1, metaString.length - metaName.length - 1);
  3224. if (metaName === 'deps')
  3225. metaName = 'deps[]';
  3226. if (metaName.substr(metaName.length - 2, 2) === '[]') {
  3227. metaName = metaName.substr(0, metaName.length - 2);
  3228. metadata.load[metaName] = metadata.load[metaName] || [];
  3229. metadata.load[metaName].push(metaValue);
  3230. }
  3231. // "use strict" is not meta
  3232. else if (metaName !== 'use') {
  3233. setMetaProperty(metadata.load, metaName, metaValue);
  3234. }
  3235. }
  3236. else {
  3237. metadata.load[metaString] = true;
  3238. }
  3239. }
  3240. }
  3241. var scriptSrc;
  3242. // Promise detection and error message
  3243. if (typeof Promise === 'undefined')
  3244. throw new Error('SystemJS needs a Promise polyfill.');
  3245. if (typeof document !== 'undefined') {
  3246. var scripts = document.getElementsByTagName('script');
  3247. var curScript = scripts[scripts.length - 1];
  3248. if (document.currentScript && (curScript.defer || curScript.async))
  3249. curScript = document.currentScript;
  3250. scriptSrc = curScript && curScript.src;
  3251. }
  3252. // worker
  3253. else if (typeof importScripts !== 'undefined') {
  3254. try {
  3255. throw new Error('_');
  3256. }
  3257. catch (e) {
  3258. e.stack.replace(/(?:at|@).*(http.+):[\d]+:[\d]+/, function(m, url) {
  3259. scriptSrc = url;
  3260. });
  3261. }
  3262. }
  3263. // node
  3264. else if (typeof __filename !== 'undefined') {
  3265. scriptSrc = __filename;
  3266. }
  3267. function SystemJSLoader () {
  3268. RegisterLoader.call(this);
  3269. // NB deprecate
  3270. this._loader = {};
  3271. // internal metadata store
  3272. this[METADATA] = {};
  3273. // internal configuration
  3274. this[CONFIG] = {
  3275. baseURL: baseURI,
  3276. paths: {},
  3277. packageConfigPaths: [],
  3278. packageConfigKeys: [],
  3279. map: {},
  3280. packages: {},
  3281. depCache: {},
  3282. meta: {},
  3283. bundles: {},
  3284. production: false,
  3285. transpiler: undefined,
  3286. loadedBundles: {},
  3287. // global behaviour flags
  3288. warnings: false,
  3289. pluginFirst: false,
  3290. // enable wasm loading and detection when supported
  3291. wasm: false
  3292. };
  3293. // make the location of the system.js script accessible (if any)
  3294. this.scriptSrc = scriptSrc;
  3295. this._nodeRequire = nodeRequire;
  3296. // support the empty module, as a concept
  3297. this.registry.set('@empty', emptyModule);
  3298. setProduction.call(this, false, false);
  3299. // add module format helpers
  3300. setHelpers(this);
  3301. setAmdHelper(this);
  3302. }
  3303. var envModule;
  3304. function setProduction (isProduction, isBuilder) {
  3305. this[CONFIG].production = isProduction;
  3306. this.registry.set('@system-env', envModule = this.newModule({
  3307. browser: isBrowser,
  3308. node: !!this._nodeRequire,
  3309. production: !isBuilder && isProduction,
  3310. dev: isBuilder || !isProduction,
  3311. build: isBuilder,
  3312. 'default': true
  3313. }));
  3314. }
  3315. SystemJSLoader.prototype = Object.create(RegisterLoader.prototype);
  3316. SystemJSLoader.prototype.constructor = SystemJSLoader;
  3317. // NB deprecate normalize
  3318. SystemJSLoader.prototype[SystemJSLoader.resolve = RegisterLoader.resolve] = SystemJSLoader.prototype.normalize = normalize;
  3319. SystemJSLoader.prototype.load = function (key, parentKey) {
  3320. warn.call(this[CONFIG], 'System.load is deprecated.');
  3321. return this.import(key, parentKey);
  3322. };
  3323. // NB deprecate decanonicalize, normalizeSync
  3324. SystemJSLoader.prototype.decanonicalize = SystemJSLoader.prototype.normalizeSync = SystemJSLoader.prototype.resolveSync = normalizeSync;
  3325. SystemJSLoader.prototype[SystemJSLoader.instantiate = RegisterLoader.instantiate] = instantiate$1;
  3326. SystemJSLoader.prototype.config = setConfig;
  3327. SystemJSLoader.prototype.getConfig = getConfig;
  3328. SystemJSLoader.prototype.global = envGlobal;
  3329. SystemJSLoader.prototype.import = function () {
  3330. return RegisterLoader.prototype.import.apply(this, arguments)
  3331. .then(function (m) {
  3332. return '__useDefault' in m ? m.__useDefault : m;
  3333. });
  3334. };
  3335. var configNames = ['baseURL', 'map', 'paths', 'packages', 'packageConfigPaths', 'depCache', 'meta', 'bundles', 'transpiler', 'warnings', 'pluginFirst', 'production', 'wasm'];
  3336. var hasProxy = typeof Proxy !== 'undefined';
  3337. for (var i = 0; i < configNames.length; i++) (function (configName) {
  3338. Object.defineProperty(SystemJSLoader.prototype, configName, {
  3339. get: function () {
  3340. var cfg = getConfigItem(this[CONFIG], configName);
  3341. if (hasProxy && typeof cfg === 'object')
  3342. cfg = new Proxy(cfg, {
  3343. set: function (target, option) {
  3344. throw new Error('Cannot set SystemJS.' + configName + '["' + option + '"] directly. Use SystemJS.config({ ' + configName + ': { "' + option + '": ... } }) rather.');
  3345. }
  3346. });
  3347. //if (typeof cfg === 'object')
  3348. // warn.call(this[CONFIG], 'Referencing `SystemJS.' + configName + '` is deprecated. Use the config getter `SystemJS.getConfig(\'' + configName + '\')`');
  3349. return cfg;
  3350. },
  3351. set: function (name) {
  3352. throw new Error('Setting `SystemJS.' + configName + '` directly is no longer supported. Use `SystemJS.config({ ' + configName + ': ... })`.');
  3353. }
  3354. });
  3355. })(configNames[i]);
  3356. /*
  3357. * Backwards-compatible registry API, to be deprecated
  3358. */
  3359. function registryWarn(loader, method) {
  3360. warn.call(loader[CONFIG], 'SystemJS.' + method + ' is deprecated for SystemJS.registry.' + method);
  3361. }
  3362. SystemJSLoader.prototype.delete = function (key) {
  3363. registryWarn(this, 'delete');
  3364. return this.registry.delete(key);
  3365. };
  3366. SystemJSLoader.prototype.get = function (key) {
  3367. registryWarn(this, 'get');
  3368. return this.registry.get(key);
  3369. };
  3370. SystemJSLoader.prototype.has = function (key) {
  3371. registryWarn(this, 'has');
  3372. return this.registry.has(key);
  3373. };
  3374. SystemJSLoader.prototype.set = function (key, module) {
  3375. registryWarn(this, 'set');
  3376. return this.registry.set(key, module);
  3377. };
  3378. SystemJSLoader.prototype.newModule = function (bindings) {
  3379. return new ModuleNamespace(bindings);
  3380. };
  3381. SystemJSLoader.prototype.isModule = isModule;
  3382. // ensure System.register and System.registerDynamic decanonicalize
  3383. SystemJSLoader.prototype.register = function (key, deps, declare) {
  3384. if (typeof key === 'string')
  3385. key = decanonicalize.call(this, this[CONFIG], key);
  3386. return RegisterLoader.prototype.register.call(this, key, deps, declare);
  3387. };
  3388. SystemJSLoader.prototype.registerDynamic = function (key, deps, executingRequire, execute) {
  3389. if (typeof key === 'string')
  3390. key = decanonicalize.call(this, this[CONFIG], key);
  3391. return RegisterLoader.prototype.registerDynamic.call(this, key, deps, executingRequire, execute);
  3392. };
  3393. SystemJSLoader.prototype.version = "0.21.6 Dev";
  3394. var System = new SystemJSLoader();
  3395. // only set the global System on the global in browsers
  3396. if (isBrowser || isWorker)
  3397. envGlobal.SystemJS = envGlobal.System = System;
  3398. if (typeof module !== 'undefined' && module.exports)
  3399. module.exports = System;
  3400. }());
  3401. //# sourceMappingURL=system.src.js.map