system.src.js 144 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605
  1. /*
  2. * SystemJS v0.19.6
  3. */
  4. (function() {
  5. function bootstrap() {(function(__global) {
  6. var isWorker = typeof window == 'undefined' && typeof self != 'undefined' && typeof importScripts != 'undefined';
  7. var isBrowser = typeof window != 'undefined' && typeof document != 'undefined';
  8. var isWindows = typeof process != 'undefined' && !!process.platform.match(/^win/);
  9. if (!__global.console)
  10. __global.console = { assert: function() {} };
  11. // IE8 support
  12. var indexOf = Array.prototype.indexOf || function(item) {
  13. for (var i = 0, thisLen = this.length; i < thisLen; i++) {
  14. if (this[i] === item) {
  15. return i;
  16. }
  17. }
  18. return -1;
  19. };
  20. var defineProperty;
  21. (function () {
  22. try {
  23. if (!!Object.defineProperty({}, 'a', {}))
  24. defineProperty = Object.defineProperty;
  25. }
  26. catch (e) {
  27. defineProperty = function(obj, prop, opt) {
  28. try {
  29. obj[prop] = opt.value || opt.get.call(obj);
  30. }
  31. catch(e) {}
  32. }
  33. }
  34. })();
  35. function addToError(err, msg) {
  36. var newErr;
  37. if (err instanceof Error) {
  38. var newErr = new Error(err.message, err.fileName, err.lineNumber);
  39. if (isBrowser) {
  40. newErr.message = err.message + '\n\t' + msg;
  41. newErr.stack = err.stack;
  42. }
  43. else {
  44. // node errors only look correct with the stack modified
  45. newErr.message = err.message;
  46. newErr.stack = err.stack + '\n\t' + msg;
  47. }
  48. }
  49. else {
  50. newErr = err + '\n\t' + msg;
  51. }
  52. return newErr;
  53. }
  54. function __eval(source, debugName, context) {
  55. try {
  56. new Function(source).call(context);
  57. }
  58. catch(e) {
  59. throw addToError(e, 'Evaluating ' + debugName);
  60. }
  61. }
  62. var baseURI;
  63. // environent baseURI detection
  64. if (typeof document != 'undefined' && document.getElementsByTagName) {
  65. baseURI = document.baseURI;
  66. if (!baseURI) {
  67. var bases = document.getElementsByTagName('base');
  68. baseURI = bases[0] && bases[0].href || window.location.href;
  69. }
  70. // sanitize out the hash and querystring
  71. baseURI = baseURI.split('#')[0].split('?')[0];
  72. baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1);
  73. }
  74. else if (typeof process != 'undefined' && process.cwd) {
  75. baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
  76. if (isWindows)
  77. baseURI = baseURI.replace(/\\/g, '/');
  78. }
  79. else if (typeof location != 'undefined') {
  80. baseURI = __global.location.href;
  81. }
  82. else {
  83. throw new TypeError('No environment baseURI');
  84. }
  85. var URL = __global.URLPolyfill || __global.URL;
  86. /*
  87. *********************************************************************************************
  88. Dynamic Module Loader Polyfill
  89. - Implemented exactly to the former 2014-08-24 ES6 Specification Draft Rev 27, Section 15
  90. http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#august_24_2014_draft_rev_27
  91. - Functions are commented with their spec numbers, with spec differences commented.
  92. - Spec bugs are commented in this code with links.
  93. - Abstract functions have been combined where possible, and their associated functions
  94. commented.
  95. - Realm implementation is entirely omitted.
  96. *********************************************************************************************
  97. */
  98. function Module() {}
  99. // http://www.ecma-international.org/ecma-262/6.0/#sec-@@tostringtag
  100. defineProperty(Module.prototype, 'toString', {
  101. value: function() {
  102. return 'Module';
  103. }
  104. });
  105. function Loader(options) {
  106. this._loader = {
  107. loaderObj: this,
  108. loads: [],
  109. modules: {},
  110. importPromises: {},
  111. moduleRecords: {}
  112. };
  113. // 26.3.3.6
  114. defineProperty(this, 'global', {
  115. get: function() {
  116. return __global;
  117. }
  118. });
  119. // 26.3.3.13 realm not implemented
  120. }
  121. (function() {
  122. // Some Helpers
  123. // logs a linkset snapshot for debugging
  124. /* function snapshot(loader) {
  125. console.log('---Snapshot---');
  126. for (var i = 0; i < loader.loads.length; i++) {
  127. var load = loader.loads[i];
  128. var linkSetLog = ' ' + load.name + ' (' + load.status + '): ';
  129. for (var j = 0; j < load.linkSets.length; j++) {
  130. linkSetLog += '{' + logloads(load.linkSets[j].loads) + '} ';
  131. }
  132. console.log(linkSetLog);
  133. }
  134. console.log('');
  135. }
  136. function logloads(loads) {
  137. var log = '';
  138. for (var k = 0; k < loads.length; k++)
  139. log += loads[k].name + (k != loads.length - 1 ? ' ' : '');
  140. return log;
  141. } */
  142. /* function checkInvariants() {
  143. // see https://bugs.ecmascript.org/show_bug.cgi?id=2603#c1
  144. var loads = System._loader.loads;
  145. var linkSets = [];
  146. for (var i = 0; i < loads.length; i++) {
  147. var load = loads[i];
  148. console.assert(load.status == 'loading' || load.status == 'loaded', 'Each load is loading or loaded');
  149. for (var j = 0; j < load.linkSets.length; j++) {
  150. var linkSet = load.linkSets[j];
  151. for (var k = 0; k < linkSet.loads.length; k++)
  152. console.assert(loads.indexOf(linkSet.loads[k]) != -1, 'linkSet loads are a subset of loader loads');
  153. if (linkSets.indexOf(linkSet) == -1)
  154. linkSets.push(linkSet);
  155. }
  156. }
  157. for (var i = 0; i < loads.length; i++) {
  158. var load = loads[i];
  159. for (var j = 0; j < linkSets.length; j++) {
  160. var linkSet = linkSets[j];
  161. if (linkSet.loads.indexOf(load) != -1)
  162. console.assert(load.linkSets.indexOf(linkSet) != -1, 'linkSet contains load -> load contains linkSet');
  163. if (load.linkSets.indexOf(linkSet) != -1)
  164. console.assert(linkSet.loads.indexOf(load) != -1, 'load contains linkSet -> linkSet contains load');
  165. }
  166. }
  167. for (var i = 0; i < linkSets.length; i++) {
  168. var linkSet = linkSets[i];
  169. for (var j = 0; j < linkSet.loads.length; j++) {
  170. var load = linkSet.loads[j];
  171. for (var k = 0; k < load.dependencies.length; k++) {
  172. var depName = load.dependencies[k].value;
  173. var depLoad;
  174. for (var l = 0; l < loads.length; l++) {
  175. if (loads[l].name != depName)
  176. continue;
  177. depLoad = loads[l];
  178. break;
  179. }
  180. // loading records are allowed not to have their dependencies yet
  181. // if (load.status != 'loading')
  182. // console.assert(depLoad, 'depLoad found');
  183. // console.assert(linkSet.loads.indexOf(depLoad) != -1, 'linkset contains all dependencies');
  184. }
  185. }
  186. }
  187. } */
  188. // 15.2.3 - Runtime Semantics: Loader State
  189. // 15.2.3.11
  190. function createLoaderLoad(object) {
  191. return {
  192. // modules is an object for ES5 implementation
  193. modules: {},
  194. loads: [],
  195. loaderObj: object
  196. };
  197. }
  198. // 15.2.3.2 Load Records and LoadRequest Objects
  199. // 15.2.3.2.1
  200. function createLoad(name) {
  201. return {
  202. status: 'loading',
  203. name: name,
  204. linkSets: [],
  205. dependencies: [],
  206. metadata: {}
  207. };
  208. }
  209. // 15.2.3.2.2 createLoadRequestObject, absorbed into calling functions
  210. // 15.2.4
  211. // 15.2.4.1
  212. function loadModule(loader, name, options) {
  213. return new Promise(asyncStartLoadPartwayThrough({
  214. step: options.address ? 'fetch' : 'locate',
  215. loader: loader,
  216. moduleName: name,
  217. // allow metadata for import https://bugs.ecmascript.org/show_bug.cgi?id=3091
  218. moduleMetadata: options && options.metadata || {},
  219. moduleSource: options.source,
  220. moduleAddress: options.address
  221. }));
  222. }
  223. // 15.2.4.2
  224. function requestLoad(loader, request, refererName, refererAddress) {
  225. // 15.2.4.2.1 CallNormalize
  226. return new Promise(function(resolve, reject) {
  227. resolve(loader.loaderObj.normalize(request, refererName, refererAddress));
  228. })
  229. // 15.2.4.2.2 GetOrCreateLoad
  230. .then(function(name) {
  231. var load;
  232. if (loader.modules[name]) {
  233. load = createLoad(name);
  234. load.status = 'linked';
  235. // https://bugs.ecmascript.org/show_bug.cgi?id=2795
  236. load.module = loader.modules[name];
  237. return load;
  238. }
  239. for (var i = 0, l = loader.loads.length; i < l; i++) {
  240. load = loader.loads[i];
  241. if (load.name != name)
  242. continue;
  243. console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded');
  244. return load;
  245. }
  246. load = createLoad(name);
  247. loader.loads.push(load);
  248. proceedToLocate(loader, load);
  249. return load;
  250. });
  251. }
  252. // 15.2.4.3
  253. function proceedToLocate(loader, load) {
  254. proceedToFetch(loader, load,
  255. Promise.resolve()
  256. // 15.2.4.3.1 CallLocate
  257. .then(function() {
  258. return loader.loaderObj.locate({ name: load.name, metadata: load.metadata });
  259. })
  260. );
  261. }
  262. // 15.2.4.4
  263. function proceedToFetch(loader, load, p) {
  264. proceedToTranslate(loader, load,
  265. p
  266. // 15.2.4.4.1 CallFetch
  267. .then(function(address) {
  268. // adjusted, see https://bugs.ecmascript.org/show_bug.cgi?id=2602
  269. if (load.status != 'loading')
  270. return;
  271. load.address = address;
  272. return loader.loaderObj.fetch({ name: load.name, metadata: load.metadata, address: address });
  273. })
  274. );
  275. }
  276. var anonCnt = 0;
  277. // 15.2.4.5
  278. function proceedToTranslate(loader, load, p) {
  279. p
  280. // 15.2.4.5.1 CallTranslate
  281. .then(function(source) {
  282. if (load.status != 'loading')
  283. return;
  284. return Promise.resolve(loader.loaderObj.translate({ name: load.name, metadata: load.metadata, address: load.address, source: source }))
  285. // 15.2.4.5.2 CallInstantiate
  286. .then(function(source) {
  287. load.source = source;
  288. return loader.loaderObj.instantiate({ name: load.name, metadata: load.metadata, address: load.address, source: source });
  289. })
  290. // 15.2.4.5.3 InstantiateSucceeded
  291. .then(function(instantiateResult) {
  292. if (instantiateResult === undefined) {
  293. load.address = load.address || '<Anonymous Module ' + ++anonCnt + '>';
  294. // instead of load.kind, use load.isDeclarative
  295. load.isDeclarative = true;
  296. return transpile.call(loader.loaderObj, load)
  297. .then(function(transpiled) {
  298. // Hijack System.register to set declare function
  299. var curSystem = __global.System;
  300. var curRegister = curSystem.register;
  301. curSystem.register = function(name, deps, declare) {
  302. if (typeof name != 'string') {
  303. declare = deps;
  304. deps = name;
  305. }
  306. // store the registered declaration as load.declare
  307. // store the deps as load.deps
  308. load.declare = declare;
  309. load.depsList = deps;
  310. }
  311. // empty {} context is closest to undefined 'this' we can get
  312. __eval(transpiled, load.address, {});
  313. curSystem.register = curRegister;
  314. });
  315. }
  316. else if (typeof instantiateResult == 'object') {
  317. load.depsList = instantiateResult.deps || [];
  318. load.execute = instantiateResult.execute;
  319. load.isDeclarative = false;
  320. }
  321. else
  322. throw TypeError('Invalid instantiate return value');
  323. })
  324. // 15.2.4.6 ProcessLoadDependencies
  325. .then(function() {
  326. load.dependencies = [];
  327. var depsList = load.depsList;
  328. var loadPromises = [];
  329. for (var i = 0, l = depsList.length; i < l; i++) (function(request, index) {
  330. loadPromises.push(
  331. requestLoad(loader, request, load.name, load.address)
  332. // 15.2.4.6.1 AddDependencyLoad (load is parentLoad)
  333. .then(function(depLoad) {
  334. // adjusted from spec to maintain dependency order
  335. // this is due to the System.register internal implementation needs
  336. load.dependencies[index] = {
  337. key: request,
  338. value: depLoad.name
  339. };
  340. if (depLoad.status != 'linked') {
  341. var linkSets = load.linkSets.concat([]);
  342. for (var i = 0, l = linkSets.length; i < l; i++)
  343. addLoadToLinkSet(linkSets[i], depLoad);
  344. }
  345. // console.log('AddDependencyLoad ' + depLoad.name + ' for ' + load.name);
  346. // snapshot(loader);
  347. })
  348. );
  349. })(depsList[i], i);
  350. return Promise.all(loadPromises);
  351. })
  352. // 15.2.4.6.2 LoadSucceeded
  353. .then(function() {
  354. // console.log('LoadSucceeded ' + load.name);
  355. // snapshot(loader);
  356. console.assert(load.status == 'loading', 'is loading');
  357. load.status = 'loaded';
  358. var linkSets = load.linkSets.concat([]);
  359. for (var i = 0, l = linkSets.length; i < l; i++)
  360. updateLinkSetOnLoad(linkSets[i], load);
  361. });
  362. })
  363. // 15.2.4.5.4 LoadFailed
  364. ['catch'](function(exc) {
  365. load.status = 'failed';
  366. load.exception = exc;
  367. var linkSets = load.linkSets.concat([]);
  368. for (var i = 0, l = linkSets.length; i < l; i++) {
  369. linkSetFailed(linkSets[i], load, exc);
  370. }
  371. console.assert(load.linkSets.length == 0, 'linkSets not removed');
  372. });
  373. }
  374. // 15.2.4.7 PromiseOfStartLoadPartwayThrough absorbed into calling functions
  375. // 15.2.4.7.1
  376. function asyncStartLoadPartwayThrough(stepState) {
  377. return function(resolve, reject) {
  378. var loader = stepState.loader;
  379. var name = stepState.moduleName;
  380. var step = stepState.step;
  381. if (loader.modules[name])
  382. throw new TypeError('"' + name + '" already exists in the module table');
  383. // adjusted to pick up existing loads
  384. var existingLoad;
  385. for (var i = 0, l = loader.loads.length; i < l; i++) {
  386. if (loader.loads[i].name == name) {
  387. existingLoad = loader.loads[i];
  388. if(step == 'translate' && !existingLoad.source) {
  389. existingLoad.address = stepState.moduleAddress;
  390. proceedToTranslate(loader, existingLoad, Promise.resolve(stepState.moduleSource));
  391. }
  392. // a primary load -> use that existing linkset
  393. if (existingLoad.linkSets.length)
  394. return existingLoad.linkSets[0].done.then(function() {
  395. resolve(existingLoad);
  396. });
  397. }
  398. }
  399. var load = existingLoad || createLoad(name);
  400. load.metadata = stepState.moduleMetadata;
  401. var linkSet = createLinkSet(loader, load);
  402. loader.loads.push(load);
  403. resolve(linkSet.done);
  404. if (step == 'locate')
  405. proceedToLocate(loader, load);
  406. else if (step == 'fetch')
  407. proceedToFetch(loader, load, Promise.resolve(stepState.moduleAddress));
  408. else {
  409. console.assert(step == 'translate', 'translate step');
  410. load.address = stepState.moduleAddress;
  411. proceedToTranslate(loader, load, Promise.resolve(stepState.moduleSource));
  412. }
  413. }
  414. }
  415. // Declarative linking functions run through alternative implementation:
  416. // 15.2.5.1.1 CreateModuleLinkageRecord not implemented
  417. // 15.2.5.1.2 LookupExport not implemented
  418. // 15.2.5.1.3 LookupModuleDependency not implemented
  419. // 15.2.5.2.1
  420. function createLinkSet(loader, startingLoad) {
  421. var linkSet = {
  422. loader: loader,
  423. loads: [],
  424. startingLoad: startingLoad, // added see spec bug https://bugs.ecmascript.org/show_bug.cgi?id=2995
  425. loadingCount: 0
  426. };
  427. linkSet.done = new Promise(function(resolve, reject) {
  428. linkSet.resolve = resolve;
  429. linkSet.reject = reject;
  430. });
  431. addLoadToLinkSet(linkSet, startingLoad);
  432. return linkSet;
  433. }
  434. // 15.2.5.2.2
  435. function addLoadToLinkSet(linkSet, load) {
  436. if (load.status == 'failed')
  437. return;
  438. console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded on link set');
  439. for (var i = 0, l = linkSet.loads.length; i < l; i++)
  440. if (linkSet.loads[i] == load)
  441. return;
  442. linkSet.loads.push(load);
  443. load.linkSets.push(linkSet);
  444. // adjustment, see https://bugs.ecmascript.org/show_bug.cgi?id=2603
  445. if (load.status != 'loaded') {
  446. linkSet.loadingCount++;
  447. }
  448. var loader = linkSet.loader;
  449. for (var i = 0, l = load.dependencies.length; i < l; i++) {
  450. if (!load.dependencies[i])
  451. continue;
  452. var name = load.dependencies[i].value;
  453. if (loader.modules[name])
  454. continue;
  455. for (var j = 0, d = loader.loads.length; j < d; j++) {
  456. if (loader.loads[j].name != name)
  457. continue;
  458. addLoadToLinkSet(linkSet, loader.loads[j]);
  459. break;
  460. }
  461. }
  462. // console.log('add to linkset ' + load.name);
  463. // snapshot(linkSet.loader);
  464. }
  465. // linking errors can be generic or load-specific
  466. // this is necessary for debugging info
  467. function doLink(linkSet) {
  468. var error = false;
  469. try {
  470. link(linkSet, function(load, exc) {
  471. linkSetFailed(linkSet, load, exc);
  472. error = true;
  473. });
  474. }
  475. catch(e) {
  476. linkSetFailed(linkSet, null, e);
  477. error = true;
  478. }
  479. return error;
  480. }
  481. // 15.2.5.2.3
  482. function updateLinkSetOnLoad(linkSet, load) {
  483. // console.log('update linkset on load ' + load.name);
  484. // snapshot(linkSet.loader);
  485. console.assert(load.status == 'loaded' || load.status == 'linked', 'loaded or linked');
  486. linkSet.loadingCount--;
  487. if (linkSet.loadingCount > 0)
  488. return;
  489. // adjusted for spec bug https://bugs.ecmascript.org/show_bug.cgi?id=2995
  490. var startingLoad = linkSet.startingLoad;
  491. // non-executing link variation for loader tracing
  492. // on the server. Not in spec.
  493. /***/
  494. if (linkSet.loader.loaderObj.execute === false) {
  495. var loads = [].concat(linkSet.loads);
  496. for (var i = 0, l = loads.length; i < l; i++) {
  497. var load = loads[i];
  498. load.module = !load.isDeclarative ? {
  499. module: _newModule({})
  500. } : {
  501. name: load.name,
  502. module: _newModule({}),
  503. evaluated: true
  504. };
  505. load.status = 'linked';
  506. finishLoad(linkSet.loader, load);
  507. }
  508. return linkSet.resolve(startingLoad);
  509. }
  510. /***/
  511. var abrupt = doLink(linkSet);
  512. if (abrupt)
  513. return;
  514. console.assert(linkSet.loads.length == 0, 'loads cleared');
  515. linkSet.resolve(startingLoad);
  516. }
  517. // 15.2.5.2.4
  518. function linkSetFailed(linkSet, load, exc) {
  519. var loader = linkSet.loader;
  520. var requests;
  521. checkError:
  522. if (load) {
  523. if (linkSet.loads[0].name == load.name) {
  524. exc = addToError(exc, 'Error loading ' + load.name);
  525. }
  526. else {
  527. for (var i = 0; i < linkSet.loads.length; i++) {
  528. var pLoad = linkSet.loads[i];
  529. for (var j = 0; j < pLoad.dependencies.length; j++) {
  530. var dep = pLoad.dependencies[j];
  531. if (dep.value == load.name) {
  532. exc = addToError(exc, 'Error loading ' + load.name + ' as "' + dep.key + '" from ' + pLoad.name);
  533. break checkError;
  534. }
  535. }
  536. }
  537. exc = addToError(exc, 'Error loading ' + load.name + ' from ' + linkSet.loads[0].name);
  538. }
  539. }
  540. else {
  541. exc = addToError(exc, 'Error linking ' + linkSet.loads[0].name);
  542. }
  543. var loads = linkSet.loads.concat([]);
  544. for (var i = 0, l = loads.length; i < l; i++) {
  545. var load = loads[i];
  546. // store all failed load records
  547. loader.loaderObj.failed = loader.loaderObj.failed || [];
  548. if (indexOf.call(loader.loaderObj.failed, load) == -1)
  549. loader.loaderObj.failed.push(load);
  550. var linkIndex = indexOf.call(load.linkSets, linkSet);
  551. console.assert(linkIndex != -1, 'link not present');
  552. load.linkSets.splice(linkIndex, 1);
  553. if (load.linkSets.length == 0) {
  554. var globalLoadsIndex = indexOf.call(linkSet.loader.loads, load);
  555. if (globalLoadsIndex != -1)
  556. linkSet.loader.loads.splice(globalLoadsIndex, 1);
  557. }
  558. }
  559. linkSet.reject(exc);
  560. }
  561. // 15.2.5.2.5
  562. function finishLoad(loader, load) {
  563. // add to global trace if tracing
  564. if (loader.loaderObj.trace) {
  565. if (!loader.loaderObj.loads)
  566. loader.loaderObj.loads = {};
  567. var depMap = {};
  568. load.dependencies.forEach(function(dep) {
  569. depMap[dep.key] = dep.value;
  570. });
  571. loader.loaderObj.loads[load.name] = {
  572. name: load.name,
  573. deps: load.dependencies.map(function(dep){ return dep.key }),
  574. depMap: depMap,
  575. address: load.address,
  576. metadata: load.metadata,
  577. source: load.source,
  578. kind: load.isDeclarative ? 'declarative' : 'dynamic'
  579. };
  580. }
  581. // if not anonymous, add to the module table
  582. if (load.name) {
  583. console.assert(!loader.modules[load.name], 'load not in module table');
  584. loader.modules[load.name] = load.module;
  585. }
  586. var loadIndex = indexOf.call(loader.loads, load);
  587. if (loadIndex != -1)
  588. loader.loads.splice(loadIndex, 1);
  589. for (var i = 0, l = load.linkSets.length; i < l; i++) {
  590. loadIndex = indexOf.call(load.linkSets[i].loads, load);
  591. if (loadIndex != -1)
  592. load.linkSets[i].loads.splice(loadIndex, 1);
  593. }
  594. load.linkSets.splice(0, load.linkSets.length);
  595. }
  596. function doDynamicExecute(linkSet, load, linkError) {
  597. try {
  598. var module = load.execute();
  599. }
  600. catch(e) {
  601. linkError(load, e);
  602. return;
  603. }
  604. if (!module || !(module instanceof Module))
  605. linkError(load, new TypeError('Execution must define a Module instance'));
  606. else
  607. return module;
  608. }
  609. // 26.3 Loader
  610. // 26.3.1.1
  611. // defined at top
  612. // importPromises adds ability to import a module twice without error - https://bugs.ecmascript.org/show_bug.cgi?id=2601
  613. function createImportPromise(loader, name, promise) {
  614. var importPromises = loader._loader.importPromises;
  615. return importPromises[name] = promise.then(function(m) {
  616. importPromises[name] = undefined;
  617. return m;
  618. }, function(e) {
  619. importPromises[name] = undefined;
  620. throw e;
  621. });
  622. }
  623. Loader.prototype = {
  624. // 26.3.3.1
  625. constructor: Loader,
  626. // 26.3.3.2
  627. define: function(name, source, options) {
  628. // check if already defined
  629. if (this._loader.importPromises[name])
  630. throw new TypeError('Module is already loading.');
  631. return createImportPromise(this, name, new Promise(asyncStartLoadPartwayThrough({
  632. step: 'translate',
  633. loader: this._loader,
  634. moduleName: name,
  635. moduleMetadata: options && options.metadata || {},
  636. moduleSource: source,
  637. moduleAddress: options && options.address
  638. })));
  639. },
  640. // 26.3.3.3
  641. 'delete': function(name) {
  642. var loader = this._loader;
  643. delete loader.importPromises[name];
  644. delete loader.moduleRecords[name];
  645. return loader.modules[name] ? delete loader.modules[name] : false;
  646. },
  647. // 26.3.3.4 entries not implemented
  648. // 26.3.3.5
  649. get: function(key) {
  650. if (!this._loader.modules[key])
  651. return;
  652. doEnsureEvaluated(this._loader.modules[key], [], this);
  653. return this._loader.modules[key].module;
  654. },
  655. // 26.3.3.7
  656. has: function(name) {
  657. return !!this._loader.modules[name];
  658. },
  659. // 26.3.3.8
  660. 'import': function(name, parentName, parentAddress) {
  661. if (typeof parentName == 'object')
  662. parentName = parentName.name;
  663. // run normalize first
  664. var loaderObj = this;
  665. // added, see https://bugs.ecmascript.org/show_bug.cgi?id=2659
  666. return Promise.resolve(loaderObj.normalize(name, parentName))
  667. .then(function(name) {
  668. var loader = loaderObj._loader;
  669. if (loader.modules[name]) {
  670. doEnsureEvaluated(loader.modules[name], [], loader._loader);
  671. return loader.modules[name].module;
  672. }
  673. return loader.importPromises[name] || createImportPromise(loaderObj, name,
  674. loadModule(loader, name, {})
  675. .then(function(load) {
  676. delete loader.importPromises[name];
  677. return evaluateLoadedModule(loader, load);
  678. }));
  679. });
  680. },
  681. // 26.3.3.9 keys not implemented
  682. // 26.3.3.10
  683. load: function(name, options) {
  684. var loader = this._loader;
  685. if (loader.modules[name]) {
  686. doEnsureEvaluated(loader.modules[name], [], loader);
  687. return Promise.resolve(loader.modules[name].module);
  688. }
  689. return loader.importPromises[name] || createImportPromise(this, name,
  690. loadModule(loader, name, {})
  691. .then(function(load) {
  692. delete loader.importPromises[name];
  693. return evaluateLoadedModule(loader, load);
  694. }));
  695. },
  696. // 26.3.3.11
  697. module: function(source, options) {
  698. var load = createLoad();
  699. load.address = options && options.address;
  700. var linkSet = createLinkSet(this._loader, load);
  701. var sourcePromise = Promise.resolve(source);
  702. var loader = this._loader;
  703. var p = linkSet.done.then(function() {
  704. return evaluateLoadedModule(loader, load);
  705. });
  706. proceedToTranslate(loader, load, sourcePromise);
  707. return p;
  708. },
  709. // 26.3.3.12
  710. newModule: function (obj) {
  711. if (typeof obj != 'object')
  712. throw new TypeError('Expected object');
  713. var m = new Module();
  714. var pNames = [];
  715. if (Object.getOwnPropertyNames && obj != null)
  716. pNames = Object.getOwnPropertyNames(obj);
  717. else
  718. for (var key in obj)
  719. pNames.push(key);
  720. for (var i = 0; i < pNames.length; i++) (function(key) {
  721. defineProperty(m, key, {
  722. configurable: false,
  723. enumerable: true,
  724. get: function () {
  725. return obj[key];
  726. }
  727. });
  728. })(pNames[i]);
  729. return m;
  730. },
  731. // 26.3.3.14
  732. set: function(name, module) {
  733. if (!(module instanceof Module))
  734. throw new TypeError('Loader.set(' + name + ', module) must be a module');
  735. this._loader.modules[name] = {
  736. module: module
  737. };
  738. },
  739. // 26.3.3.15 values not implemented
  740. // 26.3.3.16 @@iterator not implemented
  741. // 26.3.3.17 @@toStringTag not implemented
  742. // 26.3.3.18.1
  743. normalize: function(name, referrerName, referrerAddress) {
  744. return name;
  745. },
  746. // 26.3.3.18.2
  747. locate: function(load) {
  748. return load.name;
  749. },
  750. // 26.3.3.18.3
  751. fetch: function(load) {
  752. },
  753. // 26.3.3.18.4
  754. translate: function(load) {
  755. return load.source;
  756. },
  757. // 26.3.3.18.5
  758. instantiate: function(load) {
  759. }
  760. };
  761. var _newModule = Loader.prototype.newModule;
  762. /*
  763. * ES6 Module Declarative Linking Code - Dev Build Only
  764. */
  765. function link(linkSet, linkError) {
  766. var loader = linkSet.loader;
  767. if (!linkSet.loads.length)
  768. return;
  769. var loads = linkSet.loads.concat([]);
  770. for (var i = 0; i < loads.length; i++) {
  771. var load = loads[i];
  772. var module = doDynamicExecute(linkSet, load, linkError);
  773. if (!module)
  774. return;
  775. load.module = {
  776. name: load.name,
  777. module: module
  778. };
  779. load.status = 'linked';
  780. finishLoad(loader, load);
  781. }
  782. }
  783. function evaluateLoadedModule(loader, load) {
  784. console.assert(load.status == 'linked', 'is linked ' + load.name);
  785. return load.module.module;
  786. }
  787. function doEnsureEvaluated() {}
  788. function transpile() {
  789. throw new TypeError('ES6 transpilation is only provided in the dev module loader build.');
  790. }
  791. })();/*
  792. *********************************************************************************************
  793. System Loader Implementation
  794. - Implemented to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js
  795. - <script type="module"> supported
  796. *********************************************************************************************
  797. */
  798. var System;
  799. function SystemLoader() {
  800. Loader.call(this);
  801. this.paths = {};
  802. }
  803. // NB no specification provided for System.paths, used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
  804. function applyPaths(paths, name) {
  805. // most specific (most number of slashes in path) match wins
  806. var pathMatch = '', wildcard, maxWildcardPrefixLen = 0;
  807. // check to see if we have a paths entry
  808. for (var p in paths) {
  809. var pathParts = p.split('*');
  810. if (pathParts.length > 2)
  811. throw new TypeError('Only one wildcard in a path is permitted');
  812. // exact path match
  813. if (pathParts.length == 1) {
  814. if (name == p) {
  815. pathMatch = p;
  816. break;
  817. }
  818. }
  819. // wildcard path match
  820. else {
  821. var wildcardPrefixLen = pathParts[0].length;
  822. if (wildcardPrefixLen >= maxWildcardPrefixLen &&
  823. name.substr(0, pathParts[0].length) == pathParts[0] &&
  824. name.substr(name.length - pathParts[1].length) == pathParts[1]) {
  825. maxWildcardPrefixLen = wildcardPrefixLen;
  826. pathMatch = p;
  827. wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length);
  828. }
  829. }
  830. }
  831. var outPath = paths[pathMatch] || name;
  832. if (typeof wildcard == 'string')
  833. outPath = outPath.replace('*', wildcard);
  834. return outPath;
  835. }
  836. // inline Object.create-style class extension
  837. function LoaderProto() {}
  838. LoaderProto.prototype = Loader.prototype;
  839. SystemLoader.prototype = new LoaderProto();
  840. var fetchTextFromURL;
  841. if (typeof XMLHttpRequest != 'undefined') {
  842. fetchTextFromURL = function(url, authorization, fulfill, reject) {
  843. var xhr = new XMLHttpRequest();
  844. var sameDomain = true;
  845. var doTimeout = false;
  846. if (!('withCredentials' in xhr)) {
  847. // check if same domain
  848. var domainCheck = /^(\w+:)?\/\/([^\/]+)/.exec(url);
  849. if (domainCheck) {
  850. sameDomain = domainCheck[2] === window.location.host;
  851. if (domainCheck[1])
  852. sameDomain &= domainCheck[1] === window.location.protocol;
  853. }
  854. }
  855. if (!sameDomain && typeof XDomainRequest != 'undefined') {
  856. xhr = new XDomainRequest();
  857. xhr.onload = load;
  858. xhr.onerror = error;
  859. xhr.ontimeout = error;
  860. xhr.onprogress = function() {};
  861. xhr.timeout = 0;
  862. doTimeout = true;
  863. }
  864. function load() {
  865. fulfill(xhr.responseText);
  866. }
  867. function error() {
  868. reject(new Error('XHR error' + (xhr.status ? ' (' + xhr.status + (xhr.statusText ? ' ' + xhr.statusText : '') + ')' : '') + ' loading ' + url));
  869. }
  870. xhr.onreadystatechange = function () {
  871. if (xhr.readyState === 4) {
  872. if (xhr.status === 200 || (xhr.status == 0 && xhr.responseText)) {
  873. load();
  874. } else {
  875. error();
  876. }
  877. }
  878. };
  879. xhr.open("GET", url, true);
  880. if (xhr.setRequestHeader) {
  881. xhr.setRequestHeader('Accept', 'application/x-es-module, */*');
  882. // can set "authorization: true" to enable withCredentials only
  883. if (authorization) {
  884. if (typeof authorization == 'string')
  885. xhr.setRequestHeader('Authorization', authorization);
  886. xhr.withCredentials = true;
  887. }
  888. }
  889. if (doTimeout) {
  890. setTimeout(function() {
  891. xhr.send();
  892. }, 0);
  893. } else {
  894. xhr.send(null);
  895. }
  896. };
  897. }
  898. else if (typeof require != 'undefined') {
  899. var fs;
  900. fetchTextFromURL = function(url, authorization, fulfill, reject) {
  901. if (url.substr(0, 8) != 'file:///')
  902. throw new Error('Unable to fetch "' + url + '". Only file URLs of the form file:/// allowed running in Node.');
  903. fs = fs || require('fs');
  904. if (isWindows)
  905. url = url.replace(/\//g, '\\').substr(8);
  906. else
  907. url = url.substr(7);
  908. return fs.readFile(url, function(err, data) {
  909. if (err) {
  910. return reject(err);
  911. }
  912. else {
  913. // Strip Byte Order Mark out if it's the leading char
  914. var dataString = data + '';
  915. if (dataString[0] === '\ufeff')
  916. dataString = dataString.substr(1);
  917. fulfill(dataString);
  918. }
  919. });
  920. };
  921. }
  922. else {
  923. throw new TypeError('No environment fetch API available.');
  924. }
  925. SystemLoader.prototype.fetch = function(load) {
  926. return new Promise(function(resolve, reject) {
  927. fetchTextFromURL(load.address, undefined, resolve, reject);
  928. });
  929. };
  930. /*
  931. * Traceur, Babel and TypeScript transpile hook for Loader
  932. */
  933. var transpile = (function() {
  934. // use Traceur by default
  935. Loader.prototype.transpiler = 'traceur';
  936. function transpile(load) {
  937. var self = this;
  938. return Promise.resolve(__global[self.transpiler == 'typescript' ? 'ts' : self.transpiler]
  939. || (self.pluginLoader || self)['import'](self.transpiler))
  940. .then(function(transpiler) {
  941. if (transpiler.__useDefault)
  942. transpiler = transpiler['default'];
  943. var transpileFunction;
  944. if (transpiler.Compiler)
  945. transpileFunction = traceurTranspile;
  946. else if (transpiler.createLanguageService)
  947. transpileFunction = typescriptTranspile;
  948. else
  949. transpileFunction = babelTranspile;
  950. // note __moduleName will be part of the transformer meta in future when we have the spec for this
  951. return '(function(__moduleName){' + transpileFunction.call(self, load, transpiler) + '\n})("' + load.name + '");\n//# sourceURL=' + load.address + '!transpiled';
  952. });
  953. };
  954. function traceurTranspile(load, traceur) {
  955. var options = this.traceurOptions || {};
  956. options.modules = 'instantiate';
  957. options.script = false;
  958. if (options.sourceMaps === undefined)
  959. options.sourceMaps = 'inline';
  960. options.filename = load.address;
  961. options.inputSourceMap = load.metadata.sourceMap;
  962. options.moduleName = false;
  963. var compiler = new traceur.Compiler(options);
  964. return doTraceurCompile(load.source, compiler, options.filename);
  965. }
  966. function doTraceurCompile(source, compiler, filename) {
  967. try {
  968. return compiler.compile(source, filename);
  969. }
  970. catch(e) {
  971. // traceur throws an error array
  972. throw e[0];
  973. }
  974. }
  975. function babelTranspile(load, babel) {
  976. var options = this.babelOptions || {};
  977. options.modules = 'system';
  978. if (options.sourceMap === undefined)
  979. options.sourceMap = 'inline';
  980. options.inputSourceMap = load.metadata.sourceMap;
  981. options.filename = load.address;
  982. options.code = true;
  983. options.ast = false;
  984. return babel.transform(load.source, options).code;
  985. }
  986. function typescriptTranspile(load, ts) {
  987. var options = this.typescriptOptions || {};
  988. options.target = options.target || ts.ScriptTarget.ES5;
  989. if (options.sourceMap === undefined)
  990. options.sourceMap = true;
  991. if (options.sourceMap)
  992. options.inlineSourceMap = true;
  993. options.module = ts.ModuleKind.System;
  994. return ts.transpile(load.source, options, load.address);
  995. }
  996. return transpile;
  997. })();
  998. // SystemJS Loader Class and Extension helpers
  999. function SystemJSLoader() {
  1000. SystemLoader.call(this);
  1001. systemJSConstructor.call(this);
  1002. }
  1003. // inline Object.create-style class extension
  1004. function SystemProto() {};
  1005. SystemProto.prototype = SystemLoader.prototype;
  1006. SystemJSLoader.prototype = new SystemProto();
  1007. SystemJSLoader.prototype.constructor = SystemJSLoader;
  1008. var systemJSConstructor;
  1009. function hook(name, hook) {
  1010. SystemJSLoader.prototype[name] = hook(SystemJSLoader.prototype[name] || function() {});
  1011. }
  1012. function hookConstructor(hook) {
  1013. systemJSConstructor = hook(systemJSConstructor || function() {});
  1014. }
  1015. function dedupe(deps) {
  1016. var newDeps = [];
  1017. for (var i = 0, l = deps.length; i < l; i++)
  1018. if (indexOf.call(newDeps, deps[i]) == -1)
  1019. newDeps.push(deps[i])
  1020. return newDeps;
  1021. }
  1022. function group(deps) {
  1023. var names = [];
  1024. var indices = [];
  1025. for (var i = 0, l = deps.length; i < l; i++) {
  1026. var index = indexOf.call(names, deps[i]);
  1027. if (index === -1) {
  1028. names.push(deps[i]);
  1029. indices.push([i]);
  1030. }
  1031. else {
  1032. indices[index].push(i);
  1033. }
  1034. }
  1035. return { names: names, indices: indices };
  1036. }
  1037. var getOwnPropertyDescriptor = true;
  1038. try {
  1039. Object.getOwnPropertyDescriptor({ a: 0 }, 'a');
  1040. }
  1041. catch(e) {
  1042. getOwnPropertyDescriptor = false;
  1043. }
  1044. // converts any module.exports object into an object ready for System.newModule
  1045. function getESModule(exports) {
  1046. var esModule = {};
  1047. // don't trigger getters/setters in environments that support them
  1048. if (typeof exports == 'object' || typeof exports == 'function') {
  1049. if (getOwnPropertyDescriptor) {
  1050. var d;
  1051. for (var p in exports)
  1052. if (d = Object.getOwnPropertyDescriptor(exports, p))
  1053. defineProperty(esModule, p, d);
  1054. }
  1055. else {
  1056. var hasOwnProperty = exports && exports.hasOwnProperty;
  1057. for (var p in exports) {
  1058. if (!hasOwnProperty || exports.hasOwnProperty(p))
  1059. esModule[p] = exports[p];
  1060. }
  1061. }
  1062. }
  1063. esModule['default'] = exports;
  1064. defineProperty(esModule, '__useDefault', {
  1065. value: true
  1066. });
  1067. return esModule;
  1068. }
  1069. function extend(a, b, prepend) {
  1070. for (var p in b) {
  1071. if (!prepend || !(p in a))
  1072. a[p] = b[p];
  1073. }
  1074. return a;
  1075. }
  1076. // package configuration options
  1077. var packageProperties = ['main', 'format', 'defaultExtension', 'modules', 'map', 'basePath', 'depCache'];
  1078. // meta first-level extends where:
  1079. // array + array appends
  1080. // object + object extends
  1081. // other properties replace
  1082. function extendMeta(a, b, prepend) {
  1083. for (var p in b) {
  1084. var val = b[p];
  1085. if (!(p in a))
  1086. a[p] = val;
  1087. else if (val instanceof Array && a[p] instanceof Array)
  1088. a[p] = [].concat(prepend ? val : a[p]).concat(prepend ? a[p] : val);
  1089. else if (typeof val == 'object' && typeof a[p] == 'object')
  1090. a[p] = extend(extend({}, a[p]), val, prepend);
  1091. else if (!prepend)
  1092. a[p] = val;
  1093. }
  1094. }
  1095. function warn(msg) {
  1096. if (this.warnings && typeof console != 'undefined' && console.warn)
  1097. console.warn(msg);
  1098. }// we define a __exec for globally-scoped execution
  1099. // used by module format implementations
  1100. var __exec;
  1101. (function() {
  1102. // System clobbering protection (mostly for Traceur)
  1103. var curSystem;
  1104. var callCounter = 0;
  1105. var curLoad;
  1106. function preExec(loader, load) {
  1107. if (callCounter++ == 0)
  1108. curSystem = __global.System;
  1109. __global.System = loader;
  1110. curLoad = load;
  1111. }
  1112. function postExec() {
  1113. if (--callCounter == 0)
  1114. __global.System = curSystem;
  1115. curLoad = undefined;
  1116. }
  1117. // System.register, System.registerDynamic, AMD define pipeline
  1118. // if currently evalling code here, immediately reduce the registered entry against the load record
  1119. hook('pushRegister_', function() {
  1120. return function(register) {
  1121. if (!curLoad)
  1122. return false;
  1123. this.reduceRegister_(curLoad, register);
  1124. return true;
  1125. };
  1126. });
  1127. var hasBtoa = typeof btoa != 'undefined';
  1128. function getSource(load) {
  1129. var lastLineIndex = load.source.lastIndexOf('\n');
  1130. // wrap ES formats with a System closure for System global encapsulation
  1131. var wrap = load.metadata.format == 'esm' || load.metadata.format == 'register' || load.metadata.bundle;
  1132. return (wrap ? '(function(System) {' : '') + load.source + (wrap ? '\n})(System);' : '')
  1133. // adds the sourceURL comment if not already present
  1134. + (load.source.substr(lastLineIndex, 15) != '\n//# sourceURL='
  1135. ? '\n//# sourceURL=' + load.address + (load.metadata.sourceMap ? '!transpiled' : '') : '')
  1136. // add sourceMappingURL if load.metadata.sourceMap is set
  1137. + (load.metadata.sourceMap && hasBtoa &&
  1138. '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(load.metadata.sourceMap))) || '')
  1139. }
  1140. function evalExec(load) {
  1141. if (load.metadata.integrity)
  1142. throw new TypeError('Subresource integrity checking is not supported in Web Workers or Chrome Extensions.');
  1143. try {
  1144. preExec(this, load);
  1145. new Function(getSource(load)).call(__global);
  1146. postExec();
  1147. }
  1148. catch(e) {
  1149. postExec();
  1150. throw addToError(e, 'Evaluating ' + load.address);
  1151. }
  1152. }
  1153. // use script injection eval to get identical global script behaviour
  1154. if (typeof document != 'undefined' && document.getElementsByTagName) {
  1155. var head;
  1156. var scripts = document.getElementsByTagName('script');
  1157. $__curScript = scripts[scripts.length - 1];
  1158. __exec = function(load) {
  1159. if (!this.globalEvaluationScope)
  1160. return evalExec.call(this, load);
  1161. if (!head)
  1162. head = document.head || document.body || document.documentElement;
  1163. var script = document.createElement('script');
  1164. script.text = getSource(load);
  1165. var onerror = window.onerror;
  1166. var e;
  1167. window.onerror = function(_e) {
  1168. e = addToError(_e, 'Evaluating ' + load.address);
  1169. }
  1170. preExec(this, load);
  1171. if (load.metadata.integrity)
  1172. script.setAttribute('integrity', load.metadata.integrity);
  1173. if (load.metadata.nonce)
  1174. script.setAttribute('nonce', load.metadata.nonce);
  1175. head.appendChild(script);
  1176. head.removeChild(script);
  1177. postExec();
  1178. window.onerror = onerror;
  1179. if (e)
  1180. throw e;
  1181. };
  1182. }
  1183. // global scoped eval for node
  1184. else if (typeof require != 'undefined') {
  1185. var vmModule = 'vm';
  1186. var vm = require(vmModule);
  1187. __exec = function vmExec(load) {
  1188. if (!this.globalEvaluationScope)
  1189. return evalExec.call(this, load);
  1190. if (load.metadata.integrity)
  1191. throw new TypeError('Subresource integrity checking is unavailable in Node.');
  1192. try {
  1193. preExec(this, load);
  1194. vm.runInThisContext(getSource(load));
  1195. postExec();
  1196. }
  1197. catch(e) {
  1198. postExec();
  1199. throw addToError(e.toString(), 'Evaluating ' + load.address);
  1200. }
  1201. };
  1202. }
  1203. else {
  1204. __exec = evalExec;
  1205. }
  1206. })();/*
  1207. SystemJS map support
  1208. Provides map configuration through
  1209. System.map['jquery'] = 'some/module/map'
  1210. Note that this applies for subpaths, just like RequireJS:
  1211. jquery -> 'some/module/map'
  1212. jquery/path -> 'some/module/map/path'
  1213. bootstrap -> 'bootstrap'
  1214. The most specific map is always taken, as longest path length
  1215. */
  1216. hookConstructor(function(constructor) {
  1217. return function() {
  1218. constructor.call(this);
  1219. this.map = {};
  1220. };
  1221. });
  1222. hook('normalize', function() {
  1223. return function(name, parentName) {
  1224. if (name.substr(0, 1) != '.' && name.substr(0, 1) != '/' && !name.match(absURLRegEx)) {
  1225. var bestMatch, bestMatchLength = 0;
  1226. // now do the global map
  1227. for (var p in this.map) {
  1228. if (name.substr(0, p.length) == p && (name.length == p.length || name[p.length] == '/')) {
  1229. var curMatchLength = p.split('/').length;
  1230. if (curMatchLength <= bestMatchLength)
  1231. continue;
  1232. bestMatch = p;
  1233. bestMatchLength = curMatchLength;
  1234. }
  1235. }
  1236. if (bestMatch)
  1237. name = this.map[bestMatch] + name.substr(bestMatch.length);
  1238. }
  1239. // map is the first normalizer
  1240. return name;
  1241. };
  1242. });
  1243. var absURLRegEx = /^[^\/]+:\/\//;
  1244. function readMemberExpression(p, value) {
  1245. var pParts = p.split('.');
  1246. while (pParts.length)
  1247. value = value[pParts.shift()];
  1248. return value;
  1249. }
  1250. var baseURLCache = {};
  1251. function getBaseURLObj() {
  1252. if (baseURLCache[this.baseURL])
  1253. return baseURLCache[this.baseURL];
  1254. // normalize baseURL if not already
  1255. if (this.baseURL[this.baseURL.length - 1] != '/')
  1256. this.baseURL += '/';
  1257. var baseURL = new URL(this.baseURL, baseURI);
  1258. this.baseURL = baseURL.href;
  1259. return (baseURLCache[this.baseURL] = baseURL);
  1260. }
  1261. var baseURIObj = new URL(baseURI);
  1262. hookConstructor(function(constructor) {
  1263. return function() {
  1264. constructor.call(this);
  1265. // support baseURL
  1266. this.baseURL = baseURI.substr(0, baseURI.lastIndexOf('/') + 1);
  1267. // global behaviour flags
  1268. this.warnings = false;
  1269. this.defaultJSExtensions = false;
  1270. this.globalEvaluationScope = true;
  1271. this.pluginFirst = false;
  1272. // Default settings for globalEvaluationScope:
  1273. // Disabled for WebWorker, Chrome Extensions and jsdom
  1274. if (isWorker
  1275. || isBrowser && window.chrome && window.chrome.extension
  1276. || isBrowser && navigator.userAgent.match(/^Node\.js/))
  1277. this.globalEvaluationScope = false;
  1278. // support the empty module, as a concept
  1279. this.set('@empty', this.newModule({}));
  1280. };
  1281. });
  1282. /*
  1283. Normalization
  1284. If a name is relative, we apply URL normalization to the page
  1285. If a name is an absolute URL, we leave it as-is
  1286. Plain names (neither of the above) run through the map and package
  1287. normalization phases (applying before and after this one).
  1288. The paths normalization phase applies last (paths extension), which
  1289. defines the `normalizeSync` function and normalizes everything into
  1290. a URL.
  1291. The final normalization
  1292. */
  1293. hook('normalize', function(normalize) {
  1294. return function(name, parentName) {
  1295. // first run map config
  1296. name = normalize.apply(this, arguments);
  1297. // relative URL-normalization
  1298. if (name[0] == '.' || name[0] == '/') {
  1299. if (parentName)
  1300. return new URL(name, parentName.replace(/#/g, '%05')).href.replace(/%05/g, '#');
  1301. else
  1302. return new URL(name, baseURIObj).href;
  1303. }
  1304. return name;
  1305. };
  1306. });
  1307. // percent encode just '#' in urls if using HTTP requests
  1308. var httpRequest = typeof XMLHttpRequest != 'undefined';
  1309. hook('locate', function(locate) {
  1310. return function(load) {
  1311. return Promise.resolve(locate.call(this, load))
  1312. .then(function(address) {
  1313. if (httpRequest)
  1314. return address.replace(/#/g, '%23');
  1315. return address;
  1316. });
  1317. };
  1318. });
  1319. /*
  1320. * Fetch with authorization
  1321. */
  1322. hook('fetch', function() {
  1323. return function(load) {
  1324. return new Promise(function(resolve, reject) {
  1325. fetchTextFromURL(load.address, load.metadata.authorization, resolve, reject);
  1326. });
  1327. };
  1328. });
  1329. /*
  1330. __useDefault
  1331. When a module object looks like:
  1332. newModule(
  1333. __useDefault: true,
  1334. default: 'some-module'
  1335. })
  1336. Then importing that module provides the 'some-module'
  1337. result directly instead of the full module.
  1338. Useful for eg module.exports = function() {}
  1339. */
  1340. hook('import', function(systemImport) {
  1341. return function(name, parentName, parentAddress) {
  1342. if (parentName && parentName.name)
  1343. warn.call(this, 'System.import(name, { name: parentName }) is deprecated for System.import(name, parentName), while importing ' + name + ' from ' + parentName.name);
  1344. return systemImport.call(this, name, parentName, parentAddress).then(function(module) {
  1345. return module.__useDefault ? module['default'] : module;
  1346. });
  1347. };
  1348. });
  1349. /*
  1350. Extend config merging one deep only
  1351. loader.config({
  1352. some: 'random',
  1353. config: 'here',
  1354. deep: {
  1355. config: { too: 'too' }
  1356. }
  1357. });
  1358. <=>
  1359. loader.some = 'random';
  1360. loader.config = 'here'
  1361. loader.deep = loader.deep || {};
  1362. loader.deep.config = { too: 'too' };
  1363. Normalizes meta and package configs allowing for:
  1364. System.config({
  1365. meta: {
  1366. './index.js': {}
  1367. }
  1368. });
  1369. To become
  1370. System.meta['https://thissite.com/index.js'] = {};
  1371. For easy normalization canonicalization with latest URL support.
  1372. */
  1373. SystemJSLoader.prototype.config = function(cfg) {
  1374. if ('warnings' in cfg)
  1375. this.warnings = cfg.warnings;
  1376. // always configure baseURL first
  1377. if (cfg.baseURL) {
  1378. var hasConfig = false;
  1379. function checkHasConfig(obj) {
  1380. for (var p in obj)
  1381. return true;
  1382. }
  1383. if (checkHasConfig(this.packages) || checkHasConfig(this.meta) || checkHasConfig(this.depCache) || checkHasConfig(this.bundles) || checkHasConfig(this.packageConfigPaths))
  1384. throw new TypeError('baseURL should only be configured once and must be configured first.');
  1385. this.baseURL = cfg.baseURL;
  1386. // sanitize baseURL
  1387. getBaseURLObj.call(this);
  1388. }
  1389. if (cfg.defaultJSExtensions) {
  1390. this.defaultJSExtensions = cfg.defaultJSExtensions;
  1391. warn.call(this, 'The defaultJSExtensions configuration option is deprecated, use packages configuration instead.');
  1392. }
  1393. if (cfg.pluginFirst)
  1394. this.pluginFirst = cfg.pluginFirst;
  1395. if (cfg.paths) {
  1396. for (var p in cfg.paths)
  1397. this.paths[p] = cfg.paths[p];
  1398. }
  1399. if (cfg.map) {
  1400. var objMaps = '';
  1401. for (var p in cfg.map) {
  1402. var v = cfg.map[p];
  1403. // object map backwards-compat into packages configuration
  1404. if (typeof v !== 'string') {
  1405. objMaps += (objMaps.length ? ', ' : '') + '"' + p + '"';
  1406. var normalized = this.normalizeSync(p);
  1407. // if doing default js extensions, undo to get package name
  1408. if (this.defaultJSExtensions && p.substr(p.length - 3, 3) != '.js')
  1409. normalized = normalized.substr(0, normalized.length - 3);
  1410. // if a package main, revert it
  1411. var pkgMatch = '';
  1412. for (var pkg in this.packages) {
  1413. if (normalized.substr(0, pkg.length) == pkg
  1414. && (!normalized[pkg.length] || normalized[pkg.length] == '/')
  1415. && pkgMatch.split('/').length < pkg.split('/').length)
  1416. pkgMatch = pkg;
  1417. }
  1418. if (pkgMatch && this.packages[pkgMatch].main)
  1419. normalized = normalized.substr(0, normalized.length - this.packages[pkgMatch].main.length - 1);
  1420. var pkg = this.packages[normalized] = this.packages[normalized] || {};
  1421. pkg.map = v;
  1422. }
  1423. else {
  1424. this.map[p] = v;
  1425. }
  1426. }
  1427. if (objMaps)
  1428. warn.call(this, 'The map configuration for ' + objMaps + ' uses object submaps, which is deprecated in global map.\nUpdate this to use package contextual map with configs like System.config({ packages: { "' + p + '": { map: {...} } } }).');
  1429. }
  1430. if (cfg.packageConfigPaths) {
  1431. var packageConfigPaths = [];
  1432. for (var i = 0; i < cfg.packageConfigPaths.length; i++) {
  1433. var path = cfg.packageConfigPaths[i];
  1434. var packageLength = Math.max(path.lastIndexOf('*') + 1, path.lastIndexOf('/'));
  1435. var normalized = this.normalizeSync(path.substr(0, packageLength) + '/');
  1436. if (this.defaultJSExtensions && path.substr(path.length - 3, 3) != '.js')
  1437. normalized = normalized.substr(0, normalized.length - 3);
  1438. packageConfigPaths[i] = normalized.substr(0, normalized.length - 1) + path.substr(packageLength);
  1439. }
  1440. this.packageConfigPaths = packageConfigPaths;
  1441. }
  1442. if (cfg.packages) {
  1443. for (var p in cfg.packages) {
  1444. if (p.match(/^([^\/]+:)?\/\/$/))
  1445. throw new TypeError('"' + p + '" is not a valid package name.');
  1446. // request with trailing "/" to get package name exactly
  1447. var prop = this.normalizeSync(p + (p[p.length - 1] != '/' ? '/' : ''));
  1448. prop = prop.substr(0, prop.length - 1);
  1449. // if doing default js extensions, undo to get package name
  1450. // (unless already a package which would have skipped extension)
  1451. if (!this.packages[prop] && this.defaultJSExtensions && p.substr(p.length - 3, 3) != '.js')
  1452. prop = prop.substr(0, prop.length - 3);
  1453. this.packages[prop] = this.packages[prop] || {};
  1454. // meta backwards compatibility
  1455. if (cfg.packages[p].meta) {
  1456. warn.call(this, 'Package ' + p + ' is configured with meta, which is deprecated as it has been renamed to modules.');
  1457. cfg.packages[p].modules = cfg.packages[p].meta;
  1458. delete cfg.packages[p].meta;
  1459. }
  1460. for (var q in cfg.packages[p])
  1461. if (indexOf.call(packageProperties, q) == -1)
  1462. warn.call(this, '"' + q + '" is not a valid package configuration option in package ' + p);
  1463. extendMeta(this.packages[prop], cfg.packages[p]);
  1464. }
  1465. }
  1466. if (cfg.bundles) {
  1467. for (var p in cfg.bundles) {
  1468. var bundle = [];
  1469. for (var i = 0; i < cfg.bundles[p].length; i++)
  1470. bundle.push(this.normalizeSync(cfg.bundles[p][i]));
  1471. this.bundles[p] = bundle;
  1472. }
  1473. }
  1474. for (var c in cfg) {
  1475. var v = cfg[c];
  1476. var normalizeProp = false, normalizeValArray = false;
  1477. if (c == 'baseURL' || c == 'map' || c == 'packages' || c == 'bundles' || c == 'paths' || c == 'warnings' || c == 'packageConfigPaths')
  1478. continue;
  1479. if (typeof v != 'object' || v instanceof Array) {
  1480. this[c] = v;
  1481. }
  1482. else {
  1483. this[c] = this[c] || {};
  1484. if (c == 'meta' || c == 'depCache')
  1485. normalizeProp = true;
  1486. for (var p in v) {
  1487. if (c == 'meta' && p[0] == '*')
  1488. this[c][p] = v[p];
  1489. else if (normalizeProp)
  1490. this[c][this.normalizeSync(p)] = v[p];
  1491. else
  1492. this[c][p] = v[p];
  1493. }
  1494. }
  1495. }
  1496. };/*
  1497. * Paths extension
  1498. *
  1499. * Applies paths and normalizes to a full URL
  1500. */
  1501. hook('normalize', function(normalize) {
  1502. return function(name, parentName) {
  1503. var normalized = normalize.apply(this, arguments);
  1504. // if the module is in the registry already, use that
  1505. if (this.has(normalized))
  1506. return normalized;
  1507. if (normalized.match(absURLRegEx)) {
  1508. // defaultJSExtensions backwards compatibility
  1509. if (this.defaultJSExtensions && normalized.substr(normalized.length - 3, 3) != '.js')
  1510. normalized += '.js';
  1511. return normalized;
  1512. }
  1513. // applyPaths implementation provided from ModuleLoader system.js source
  1514. normalized = applyPaths(this.paths, normalized) || normalized;
  1515. // defaultJSExtensions backwards compatibility
  1516. if (this.defaultJSExtensions && normalized.substr(normalized.length - 3, 3) != '.js')
  1517. normalized += '.js';
  1518. // ./x, /x -> page-relative
  1519. if (normalized[0] == '.' || normalized[0] == '/')
  1520. return new URL(normalized, baseURIObj).href;
  1521. // x -> baseURL-relative
  1522. else
  1523. return new URL(normalized, getBaseURLObj.call(this)).href;
  1524. };
  1525. });/*
  1526. * Package Configuration Extension
  1527. *
  1528. * Example:
  1529. *
  1530. * System.packages = {
  1531. * jquery: {
  1532. * basePath: 'lib', // optionally only use a subdirectory within the package
  1533. * main: 'index.js', // when not set, package name is requested directly
  1534. * format: 'amd',
  1535. * defaultExtension: 'ts', // defaults to 'js', can be set to false
  1536. * modules: {
  1537. * '*.ts': {
  1538. * loader: 'typescript'
  1539. * },
  1540. * 'vendor/sizzle.js': {
  1541. * format: 'global'
  1542. * }
  1543. * },
  1544. * map: {
  1545. * // map internal require('sizzle') to local require('./vendor/sizzle')
  1546. * sizzle: './vendor/sizzle.js',
  1547. * // map any internal or external require of 'jquery/vendor/another' to 'another/index.js'
  1548. * './vendor/another.js': './another/index.js',
  1549. * // test.js / test -> lib/test.js
  1550. * './test.js': './lib/test.js',
  1551. *
  1552. * // environment-specific map configurations
  1553. * './index.js': {
  1554. * '~browser': './index-node.js'
  1555. * }
  1556. * },
  1557. * // allows for setting package-prefixed depCache
  1558. * // keys are normalized module names relative to the package itself
  1559. * depCache: {
  1560. * // import 'package/index.js' loads in parallel package/lib/test.js,package/vendor/sizzle.js
  1561. * './index.js': ['./test'],
  1562. * './test.js': ['sizzle']
  1563. * }
  1564. * }
  1565. * };
  1566. *
  1567. * Then:
  1568. * import 'jquery' -> jquery/index.js
  1569. * import 'jquery/submodule' -> jquery/submodule.js
  1570. * import 'jquery/submodule.ts' -> jquery/submodule.ts loaded as typescript
  1571. * import 'jquery/vendor/another' -> another/index.js
  1572. *
  1573. * Detailed Behaviours
  1574. * - main can have a leading "./" can be added optionally
  1575. * - map and defaultExtension are applied to the main
  1576. * - defaultExtension adds the extension only if the exact extension is not present
  1577. * - defaultJSExtensions applies after map when defaultExtension is not set
  1578. * - if a modules value is available for a module, map and defaultExtension are skipped
  1579. * - like global map, package map also applies to subpaths (sizzle/x, ./vendor/another/sub)
  1580. * - condition module map is '@env' module in package or '@system-env' globally
  1581. *
  1582. * In addition, the following modules properties will be allowed to be package
  1583. * -relative as well in the package module config:
  1584. *
  1585. * - loader
  1586. * - alias
  1587. *
  1588. *
  1589. * Package Configuration Loading
  1590. *
  1591. * Not all packages may already have their configuration present in the System config
  1592. * For these cases, a list of packageConfigPaths can be provided, which when matched against
  1593. * a request, will first request a ".json" file by the package name to derive the package
  1594. * configuration from. This allows dynamic loading of non-predetermined code, a key use
  1595. * case in SystemJS.
  1596. *
  1597. * Example:
  1598. *
  1599. * System.packageConfigPaths = ['packages/test/package.json', 'packages/*.json'];
  1600. *
  1601. * // will first request 'packages/new-package/package.json' for the package config
  1602. * // before completing the package request to 'packages/new-package/path'
  1603. * System.import('packages/new-package/path');
  1604. *
  1605. * // will first request 'packages/test/package.json' before the main
  1606. * System.import('packages/test');
  1607. *
  1608. * When a package matches packageConfigPaths, it will always send a config request for
  1609. * the package configuration.
  1610. * The package name itself is taken to be the match up to and including the last wildcard
  1611. * or trailing slash.
  1612. * Package config paths are ordered - matching is done based on the first match found.
  1613. * Any existing package configurations for the package will deeply merge with the
  1614. * package config, with the existing package configurations taking preference.
  1615. * To opt-out of the package configuration request for a package that matches
  1616. * packageConfigPaths, use the { configured: true } package config option.
  1617. *
  1618. */
  1619. (function() {
  1620. hookConstructor(function(constructor) {
  1621. return function() {
  1622. constructor.call(this);
  1623. this.packages = {};
  1624. this.packageConfigPaths = {};
  1625. };
  1626. });
  1627. function getPackage(name) {
  1628. // use most specific package
  1629. var curPkg, curPkgLen = 0, pkgLen;
  1630. for (var p in this.packages) {
  1631. if (name.substr(0, p.length) === p && (name.length === p.length || name[p.length] === '/')) {
  1632. pkgLen = p.split('/').length;
  1633. if (pkgLen > curPkgLen) {
  1634. curPkg = p;
  1635. curPkgLen = pkgLen;
  1636. }
  1637. }
  1638. }
  1639. return curPkg;
  1640. }
  1641. function applyMap(map, name) {
  1642. var bestMatch, bestMatchLength = 0;
  1643. for (var p in map) {
  1644. if (name.substr(0, p.length) == p && (name.length == p.length || name[p.length] == '/')) {
  1645. var curMatchLength = p.split('/').length;
  1646. if (curMatchLength <= bestMatchLength)
  1647. continue;
  1648. bestMatch = p;
  1649. bestMatchLength = curMatchLength;
  1650. }
  1651. }
  1652. return bestMatch;
  1653. }
  1654. function getBasePath(pkg) {
  1655. // sanitize basePath
  1656. var basePath = pkg.basePath && pkg.basePath != '.' ? pkg.basePath : '';
  1657. if (basePath) {
  1658. if (basePath.substr(0, 2) == './')
  1659. basePath = basePath.substr(2);
  1660. if (basePath[basePath.length - 1] != '/')
  1661. basePath += '/';
  1662. }
  1663. return basePath;
  1664. }
  1665. // given the package subpath, return the resultant combined path
  1666. // defaultExtension is only added if the path does not have
  1667. // loader package meta or exact package meta
  1668. // We also re-incorporate package-level conditional syntax at this point
  1669. // allowing package map and package mains to point to conditionals
  1670. // when conditionals are present,
  1671. function toPackagePath(loader, pkgName, pkg, basePath, subPath, sync, isPlugin) {
  1672. // skip if its a plugin call already, or we have boolean / interpolation conditional syntax in subPath
  1673. var skipExtension = !!(isPlugin || subPath.indexOf('#?') != -1 || subPath.match(interpolationRegEx));
  1674. // exact meta or meta with any content after the last wildcard skips extension
  1675. if (!skipExtension && pkg.modules)
  1676. getMetaMatches(pkg.modules, pkgName, subPath, function(metaPattern, matchMeta, matchDepth) {
  1677. if (matchDepth == 0 || metaPattern.lastIndexOf('*') != metaPattern.length - 1)
  1678. skipExtension = true;
  1679. });
  1680. var normalized = pkgName + '/' + basePath + subPath + (skipExtension ? '' : getDefaultExtension(pkg, subPath));
  1681. return sync ? normalized : booleanConditional.call(loader, normalized, pkgName + '/').then(function(name) {
  1682. return interpolateConditional.call(loader, name, pkgName + '/');
  1683. });
  1684. }
  1685. function getDefaultExtension(pkg, subPath) {
  1686. // don't apply extensions to folders or if defaultExtension = false
  1687. if (subPath[subPath.length - 1] != '/' && pkg.defaultExtension !== false) {
  1688. // work out what the defaultExtension is and add if not there already
  1689. var defaultExtension = '.' + (pkg.defaultExtension || 'js');
  1690. if (subPath.substr(subPath.length - defaultExtension.length) != defaultExtension)
  1691. return defaultExtension;
  1692. }
  1693. return '';
  1694. }
  1695. function applyPackageConfig(normalized, pkgName, pkg, sync, isPlugin) {
  1696. var loader = this;
  1697. var basePath = getBasePath(pkg);
  1698. // main
  1699. // NB can add a default package main convention here
  1700. if (pkgName === normalized && pkg.main)
  1701. normalized += '/' + (pkg.main.substr(0, 2) == './' ? pkg.main.substr(2) : pkg.main);
  1702. // allow for direct package name normalization with trailling "/" (no main)
  1703. if (normalized.length == pkgName.length + 1 && normalized[pkgName.length] == '/')
  1704. return normalized;
  1705. // also no submap if name is package itself (import 'pkg' -> 'path/to/pkg.js')
  1706. if (normalized.length == pkgName.length)
  1707. return normalized + (loader.defaultJSExtensions && normalized.substr(normalized.length - 3, 3) != '.js' ? '.js' : '');
  1708. // apply map, checking without then with defaultExtension
  1709. if (pkg.map) {
  1710. var subPath = '.' + normalized.substr(pkgName.length);
  1711. var map = applyMap(pkg.map, subPath) || !isPlugin && applyMap(pkg.map, (subPath += getDefaultExtension(pkg, subPath.substr(2))));
  1712. var mapped = pkg.map[map];
  1713. }
  1714. function doMap(mapped) {
  1715. // '.' as a target is the package itself (with package main check)
  1716. if (mapped == '.')
  1717. return pkgName;
  1718. // internal package map
  1719. else if (mapped.substr(0, 2) == './')
  1720. return toPackagePath(loader, pkgName, pkg, basePath, mapped.substr(2), sync, isPlugin);
  1721. // global package map
  1722. else
  1723. return (sync ? loader.normalizeSync : loader.normalize).call(loader, mapped);
  1724. }
  1725. // apply non-environment map match
  1726. if (typeof mapped == 'string')
  1727. return doMap(mapped + subPath.substr(map.length));
  1728. // sync normalize does not apply environment map
  1729. if (sync || !mapped)
  1730. return toPackagePath(loader, pkgName, pkg, basePath, normalized.substr(pkgName.length + 1), sync, isPlugin);
  1731. // environment map build support
  1732. // -> we return [package-name]#[conditional-map] ("jquery#:index.js" in example above)
  1733. // to indicate this unique conditional branch to builder in all of its possibilities
  1734. if (loader.builder)
  1735. return pkgName + '#:' + map.substr(2);
  1736. // environment map
  1737. return loader['import'](pkg.map['@env'] || '@system-env', pkgName)
  1738. .then(function(env) {
  1739. // first map condition to match is used
  1740. for (var e in mapped) {
  1741. var negate = e[0] == '~';
  1742. var value = readMemberExpression(negate ? e.substr(1) : e, env);
  1743. if (!negate && value || negate && !value)
  1744. return mapped[e] + subPath.substr(map.length);
  1745. }
  1746. })
  1747. .then(function(mapped) {
  1748. // no environment match
  1749. if (!mapped)
  1750. return toPackagePath(loader, pkgName, pkg, basePath, normalized.substr(pkgName.length + 1), sync, isPlugin);
  1751. else
  1752. return doMap(mapped);
  1753. });
  1754. }
  1755. function createPackageNormalize(normalize, sync) {
  1756. return function(name, parentName, isPlugin) {
  1757. isPlugin = isPlugin === true;
  1758. // apply contextual package map first
  1759. if (parentName)
  1760. var parentPackage = getPackage.call(this, parentName) ||
  1761. this.defaultJSExtensions && parentName.substr(parentName.length - 3, 3) == '.js' &&
  1762. getPackage.call(this, parentName.substr(0, parentName.length - 3));
  1763. if (parentPackage) {
  1764. // remove any parent package base path for normalization
  1765. var parentBasePath = getBasePath(this.packages[parentPackage]);
  1766. if (parentBasePath && parentName.substr(parentPackage.length + 1, parentBasePath.length) == parentBasePath)
  1767. parentName = parentPackage + parentName.substr(parentPackage.length + parentBasePath.length);
  1768. if (name[0] !== '.') {
  1769. var parentMap = this.packages[parentPackage].map;
  1770. if (parentMap) {
  1771. var map = applyMap(parentMap, name);
  1772. if (map) {
  1773. name = parentMap[map] + name.substr(map.length);
  1774. // relative maps are package-relative
  1775. if (name[0] === '.')
  1776. parentName = parentPackage + '/';
  1777. }
  1778. }
  1779. }
  1780. }
  1781. var defaultJSExtension = this.defaultJSExtensions && name.substr(name.length - 3, 3) != '.js';
  1782. // apply map, core, paths
  1783. var normalized = normalize.call(this, name, parentName);
  1784. // undo defaultJSExtension
  1785. if (defaultJSExtension && normalized.substr(normalized.length - 3, 3) != '.js')
  1786. defaultJSExtension = false;
  1787. if (defaultJSExtension)
  1788. normalized = normalized.substr(0, normalized.length - 3);
  1789. // if we requested a relative path, and got the package name, remove the trailing '/' to apply main
  1790. // that is normalize('pkg/') does not apply main, while normalize('./', 'pkg/') does
  1791. if (parentPackage && name[0] == '.' && normalized == parentPackage + '/')
  1792. normalized = parentPackage;
  1793. var loader = this;
  1794. function packageResolution(normalized, pkgName, pkg) {
  1795. // check if we are inside a package
  1796. pkgName = pkgName || getPackage.call(loader, normalized);
  1797. var pkg = pkg || pkgName && loader.packages[pkgName];
  1798. if (pkg)
  1799. return applyPackageConfig.call(loader, normalized, pkgName, pkg, sync, isPlugin);
  1800. else
  1801. return normalized + (defaultJSExtension ? '.js' : '');
  1802. }
  1803. // do direct resolution if sync
  1804. if (sync)
  1805. return packageResolution(normalized);
  1806. // first check if we are in a package
  1807. var pkgName = getPackage.call(this, normalized);
  1808. var pkg = pkgName && this.packages[pkgName];
  1809. // if so, and the package is configured, then do direct resolution
  1810. if (pkg && pkg.configured)
  1811. return packageResolution(normalized, pkgName, pkg);
  1812. var pkgConfigMatch = pkgConfigPathMatch(loader, normalized);
  1813. if (!pkgConfigMatch.pkgName)
  1814. return packageResolution(normalized, pkgName, pkg);
  1815. // if we're within a known package path, then halt on
  1816. // further package configuration steps from bundles and config files
  1817. return Promise.resolve(getBundleFor(loader, normalized))
  1818. // ensure that any bundles in this package are triggered, and
  1819. // all that are triggered block any further loads in the package
  1820. .then(function(bundle) {
  1821. if (bundle || pkgBundlePromises[pkgConfigMatch.pkgName]) {
  1822. var pkgBundleLoads = pkgBundlePromises[pkgConfigMatch.pkgName] = pkgBundlePromises[pkgConfigMatch.pkgName] || { bundles: [], promise: Promise.resolve() };
  1823. if (bundle && indexOf.call(pkgBundleLoads.bundles, bundle) == -1) {
  1824. pkgBundleLoads.bundles.push(bundle);
  1825. pkgBundleLoads.promise = Promise.all([pkgBundleLoads.promise, loader.load(bundle)]);
  1826. }
  1827. return pkgBundleLoads.promise;
  1828. }
  1829. })
  1830. // having loaded any bundles, attempt a package resolution now
  1831. .then(function() {
  1832. return packageResolution(normalized, pkgConfigMatch.pkgName);
  1833. })
  1834. .then(function(curResolution) {
  1835. // if that resolution is defined in the registry use it
  1836. if (curResolution in loader.defined)
  1837. return curResolution;
  1838. // otherwise revert to loading configuration dynamically
  1839. return loadPackageConfigPaths(loader, pkgConfigMatch)
  1840. .then(function() {
  1841. // before doing a final resolution
  1842. return packageResolution(normalized);
  1843. });
  1844. });
  1845. };
  1846. }
  1847. var pkgBundlePromises = {};
  1848. // check if the given normalized name matches a packageConfigPath
  1849. // if so, loads the config
  1850. var packageConfigPathsRegExps = {};
  1851. var pkgConfigPromises = {};
  1852. function pkgConfigPathMatch(loader, normalized) {
  1853. var pkgPath, pkgConfigPaths = [];
  1854. for (var i = 0; i < loader.packageConfigPaths.length; i++) {
  1855. var p = loader.packageConfigPaths[i];
  1856. var pPkgLen = Math.max(p.lastIndexOf('*') + 1, p.lastIndexOf('/'));
  1857. var match = normalized.match(packageConfigPathsRegExps[p] ||
  1858. (packageConfigPathsRegExps[p] = new RegExp('^(' + p.substr(0, pPkgLen).replace(/\*/g, '[^\\/]+') + ')(\/|$)')));
  1859. if (match && (!pkgPath || pkgPath == match[1])) {
  1860. pkgPath = match[1];
  1861. pkgConfigPaths.push(pkgPath + p.substr(pPkgLen));
  1862. }
  1863. }
  1864. return {
  1865. pkgName: pkgPath,
  1866. configPaths: pkgConfigPaths
  1867. };
  1868. }
  1869. function loadPackageConfigPaths(loader, pkgConfigMatch) {
  1870. var curPkgConfig = loader.packages[pkgConfigMatch.pkgName];
  1871. if (curPkgConfig && curPkgConfig.configured)
  1872. return Promise.resolve();
  1873. return pkgConfigPromises[pkgConfigMatch.pkgName] || (
  1874. pkgConfigPromises[pkgConfigMatch.pkgName] = Promise.resolve()
  1875. .then(function() {
  1876. var pkgConfigPromises = [];
  1877. for (var i = 0; i < pkgConfigMatch.configPaths.length; i++) (function(pkgConfigPath) {
  1878. pkgConfigPromises.push(loader['fetch']({ name: pkgConfigPath, address: pkgConfigPath, metadata: {} })
  1879. .then(function(source) {
  1880. try {
  1881. return JSON.parse(source);
  1882. }
  1883. catch(e) {
  1884. throw new Error('Invalid JSON in package configuration file ' + pkgConfigPath);
  1885. }
  1886. })
  1887. .then(function(cfg) {
  1888. // support "systemjs" prefixing
  1889. if (cfg.systemjs)
  1890. cfg = cfg.systemjs;
  1891. // meta backwards compatibility
  1892. if (cfg.meta) {
  1893. cfg.modules = cfg.meta;
  1894. warn.call(loader, 'Package config file ' + pkgConfigPath + ' is configured with meta, which is deprecated as it has been renamed to modules.');
  1895. }
  1896. // remove any non-system properties if generic config file (eg package.json)
  1897. for (var p in cfg) {
  1898. if (indexOf.call(packageProperties, p) == -1)
  1899. delete cfg[p];
  1900. }
  1901. // support main array
  1902. if (cfg.main instanceof Array)
  1903. cfg.main = cfg.main[0];
  1904. // deeply-merge (to first level) config with any existing package config
  1905. if (curPkgConfig)
  1906. extendMeta(cfg, curPkgConfig);
  1907. // support external depCache
  1908. if (cfg.depCache)
  1909. for (var d in cfg.depCache) {
  1910. if (d.substr(0, 2) == './')
  1911. continue;
  1912. var dNormalized = loader.normalizeSync(d);
  1913. loader.depCache[dNormalized] = (loader.depCache[dNormalized] || []).concat(cfg.depCache[d]);
  1914. }
  1915. curPkgConfig = loader.packages[pkgConfigMatch.pkgName] = cfg;
  1916. }));
  1917. })(pkgConfigMatch.configPaths[i]);
  1918. return Promise.all(pkgConfigPromises);
  1919. })
  1920. );
  1921. }
  1922. SystemJSLoader.prototype.normalizeSync = SystemJSLoader.prototype.normalize;
  1923. hook('normalizeSync', function(normalize) {
  1924. return createPackageNormalize(normalize, true);
  1925. });
  1926. hook('normalize', function(normalize) {
  1927. return createPackageNormalize(normalize, false);
  1928. });
  1929. function getMetaMatches(pkgMeta, pkgName, subPath, matchFn) {
  1930. // wildcard meta
  1931. var meta = {};
  1932. var wildcardIndex;
  1933. for (var module in pkgMeta) {
  1934. // allow meta to start with ./ for flexibility
  1935. var dotRel = module.substr(0, 2) == './' ? './' : '';
  1936. if (dotRel)
  1937. module = module.substr(2);
  1938. wildcardIndex = module.indexOf('*');
  1939. if (wildcardIndex === -1)
  1940. continue;
  1941. if (module.substr(0, wildcardIndex) == subPath.substr(0, wildcardIndex)
  1942. && module.substr(wildcardIndex + 1) == subPath.substr(subPath.length - module.length + wildcardIndex + 1)) {
  1943. matchFn(module, pkgMeta[dotRel + module], module.split('/').length);
  1944. }
  1945. }
  1946. // exact meta
  1947. var exactMeta = pkgMeta[subPath] || pkgMeta['./' + subPath];
  1948. if (exactMeta)
  1949. matchFn(exactMeta, exactMeta, 0);
  1950. }
  1951. hook('locate', function(locate) {
  1952. return function(load) {
  1953. var loader = this;
  1954. return Promise.resolve(locate.call(this, load))
  1955. .then(function(address) {
  1956. var pkgName = getPackage.call(loader, load.name);
  1957. if (pkgName) {
  1958. var pkg = loader.packages[pkgName];
  1959. var basePath = getBasePath(pkg);
  1960. var subPath = load.name.substr(pkgName.length + basePath.length + 1);
  1961. // format
  1962. if (pkg.format)
  1963. load.metadata.format = load.metadata.format || pkg.format;
  1964. // depCache for packages
  1965. if (pkg.depCache) {
  1966. for (var d in pkg.depCache) {
  1967. if (d != './' + subPath)
  1968. continue;
  1969. var deps = pkg.depCache[d];
  1970. for (var i = 0; i < deps.length; i++)
  1971. loader['import'](deps[i], pkgName + '/');
  1972. }
  1973. }
  1974. var meta = {};
  1975. if (pkg.modules) {
  1976. var bestDepth = 0;
  1977. getMetaMatches(pkg.modules, pkgName, subPath, function(metaPattern, matchMeta, matchDepth) {
  1978. if (matchDepth > bestDepth)
  1979. bestDepth = matchDepth;
  1980. extendMeta(meta, matchMeta, matchDepth && bestDepth > matchDepth);
  1981. });
  1982. // allow alias and loader to be package-relative
  1983. if (meta.alias && meta.alias.substr(0, 2) == './')
  1984. meta.alias = pkgName + meta.alias.substr(1);
  1985. if (meta.loader && meta.loader.substr(0, 2) == './')
  1986. meta.loader = pkgName + meta.loader.substr(1);
  1987. extendMeta(load.metadata, meta);
  1988. }
  1989. }
  1990. return address;
  1991. });
  1992. };
  1993. });
  1994. })();/*
  1995. * Script tag fetch
  1996. *
  1997. * When load.metadata.scriptLoad is true, we load via script tag injection.
  1998. */
  1999. (function() {
  2000. if (typeof document != 'undefined')
  2001. var head = document.getElementsByTagName('head')[0];
  2002. var curSystem;
  2003. // if doing worker executing, this is set to the load record being executed
  2004. var workerLoad = null;
  2005. // interactive mode handling method courtesy RequireJS
  2006. var ieEvents = head && (function() {
  2007. var s = document.createElement('script');
  2008. var isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]';
  2009. return s.attachEvent && !(s.attachEvent.toString && s.attachEvent.toString().indexOf('[native code') < 0) && !isOpera;
  2010. })();
  2011. // IE interactive-only part
  2012. // we store loading scripts array as { script: <script>, load: {...} }
  2013. var interactiveLoadingScripts = [];
  2014. var interactiveScript;
  2015. function getInteractiveScriptLoad() {
  2016. if (interactiveScript && interactiveScript.script.readyState === 'interactive')
  2017. return interactiveScript.load;
  2018. for (var i = 0; i < interactiveLoadingScripts.length; i++)
  2019. if (interactiveLoadingScripts[i].script.readyState == 'interactive') {
  2020. interactiveScript = interactiveLoadingScripts[i];
  2021. return interactiveScript.load;
  2022. }
  2023. }
  2024. // System.register, System.registerDynamic, AMD define pipeline
  2025. // this is called by the above methods when they execute
  2026. // we then run the reduceRegister_ collection function either immediately
  2027. // if we are in IE and know the currently executing script (interactive)
  2028. // or later if we need to wait for the synchronous load callback to know the script
  2029. var loadingCnt = 0;
  2030. var registerQueue = [];
  2031. hook('pushRegister_', function(pushRegister) {
  2032. return function(register) {
  2033. // if using eval-execution then skip
  2034. if (pushRegister.call(this, register))
  2035. return false;
  2036. // if using worker execution, then we're done
  2037. if (workerLoad)
  2038. this.reduceRegister_(workerLoad, register);
  2039. // detect if we know the currently executing load (IE)
  2040. // if so, immediately call reduceRegister
  2041. else if (ieEvents)
  2042. this.reduceRegister_(getInteractiveScriptLoad(), register);
  2043. // otherwise, add to our execution queue
  2044. // to call reduceRegister on sync script load event
  2045. else if (loadingCnt)
  2046. registerQueue.push(register);
  2047. // if we're not currently loading anything though
  2048. // then do the reduction against a null load
  2049. // (out of band named define or named register)
  2050. // note even in non-script environments, this catch is used
  2051. else
  2052. this.reduceRegister_(null, register);
  2053. return true;
  2054. };
  2055. });
  2056. function webWorkerImport(loader, load) {
  2057. return new Promise(function(resolve, reject) {
  2058. if (load.metadata.integrity)
  2059. reject(new Error('Subresource integrity checking is not supported in web workers.'));
  2060. workerLoad = load;
  2061. try {
  2062. importScripts(load.address);
  2063. }
  2064. catch(e) {
  2065. workerLoad = null;
  2066. reject(e);
  2067. }
  2068. workerLoad = null;
  2069. // if nothing registered, then something went wrong
  2070. if (!load.metadata.entry)
  2071. reject(new Error(load.address + ' did not call System.register or AMD define'));
  2072. resolve('');
  2073. });
  2074. }
  2075. // override fetch to use script injection
  2076. hook('fetch', function(fetch) {
  2077. return function(load) {
  2078. var loader = this;
  2079. if (!load.metadata.scriptLoad || (!isBrowser && !isWorker))
  2080. return fetch.call(this, load);
  2081. if (isWorker)
  2082. return webWorkerImport(loader, load);
  2083. return new Promise(function(resolve, reject) {
  2084. var s = document.createElement('script');
  2085. s.async = true;
  2086. if (load.metadata.integrity)
  2087. s.setAttribute('integrity', load.metadata.integrity);
  2088. if (ieEvents) {
  2089. s.attachEvent('onreadystatechange', complete);
  2090. interactiveLoadingScripts.push({
  2091. script: s,
  2092. load: load
  2093. });
  2094. }
  2095. else {
  2096. s.addEventListener('load', complete, false);
  2097. s.addEventListener('error', error, false);
  2098. }
  2099. loadingCnt++;
  2100. curSystem = __global.System;
  2101. s.src = load.address;
  2102. head.appendChild(s);
  2103. function complete(evt) {
  2104. if (s.readyState && s.readyState != 'loaded' && s.readyState != 'complete')
  2105. return;
  2106. loadingCnt--;
  2107. // complete call is sync on execution finish
  2108. // (in ie already done reductions)
  2109. if (!load.metadata.entry && !registerQueue.length) {
  2110. loader.reduceRegister_(load);
  2111. }
  2112. else if (!ieEvents) {
  2113. for (var i = 0; i < registerQueue.length; i++)
  2114. loader.reduceRegister_(load, registerQueue[i]);
  2115. registerQueue = [];
  2116. }
  2117. cleanup();
  2118. // if nothing registered, then something went wrong
  2119. if (!load.metadata.entry && !load.metadata.bundle)
  2120. reject(new Error(load.name + ' did not call System.register or AMD define'));
  2121. resolve('');
  2122. }
  2123. function error(evt) {
  2124. cleanup();
  2125. reject(new Error('Unable to load script ' + load.address));
  2126. }
  2127. function cleanup() {
  2128. __global.System = curSystem;
  2129. if (s.detachEvent) {
  2130. s.detachEvent('onreadystatechange', complete);
  2131. for (var i = 0; i < interactiveLoadingScripts.length; i++)
  2132. if (interactiveLoadingScripts[i].script == s) {
  2133. if (interactiveScript && interactiveScript.script == s)
  2134. interactiveScript = null;
  2135. interactiveLoadingScripts.splice(i, 1);
  2136. }
  2137. }
  2138. else {
  2139. s.removeEventListener('load', complete, false);
  2140. s.removeEventListener('error', error, false);
  2141. }
  2142. head.removeChild(s);
  2143. }
  2144. });
  2145. };
  2146. });
  2147. })();
  2148. /*
  2149. * Instantiate registry extension
  2150. *
  2151. * Supports Traceur System.register 'instantiate' output for loading ES6 as ES5.
  2152. *
  2153. * - Creates the loader.register function
  2154. * - Also supports metadata.format = 'register' in instantiate for anonymous register modules
  2155. * - Also supports metadata.deps, metadata.execute and metadata.executingRequire
  2156. * for handling dynamic modules alongside register-transformed ES6 modules
  2157. *
  2158. *
  2159. * The code here replicates the ES6 linking groups algorithm to ensure that
  2160. * circular ES6 compiled into System.register can work alongside circular AMD
  2161. * and CommonJS, identically to the actual ES6 loader.
  2162. *
  2163. */
  2164. /*
  2165. * Registry side table entries in loader.defined
  2166. * Registry Entry Contains:
  2167. * - name
  2168. * - deps
  2169. * - declare for declarative modules
  2170. * - execute for dynamic modules, different to declarative execute on module
  2171. * - executingRequire indicates require drives execution for circularity of dynamic modules
  2172. * - declarative optional boolean indicating which of the above
  2173. *
  2174. * Can preload modules directly on System.defined['my/module'] = { deps, execute, executingRequire }
  2175. *
  2176. * Then the entry gets populated with derived information during processing:
  2177. * - normalizedDeps derived from deps, created in instantiate
  2178. * - groupIndex used by group linking algorithm
  2179. * - evaluated indicating whether evaluation has happend
  2180. * - module the module record object, containing:
  2181. * - exports actual module exports
  2182. *
  2183. * For dynamic we track the es module with:
  2184. * - esModule actual es module value
  2185. * - esmExports whether to extend the esModule with named exports
  2186. *
  2187. * Then for declarative only we track dynamic bindings with the 'module' records:
  2188. * - name
  2189. * - exports
  2190. * - setters declarative setter functions
  2191. * - dependencies, module records of dependencies
  2192. * - importers, module records of dependents
  2193. *
  2194. * After linked and evaluated, entries are removed, declarative module records remain in separate
  2195. * module binding table
  2196. *
  2197. */
  2198. function createEntry() {
  2199. return {
  2200. name: null,
  2201. deps: null,
  2202. declare: null,
  2203. execute: null,
  2204. executingRequire: false,
  2205. declarative: false,
  2206. normalizedDeps: null,
  2207. groupIndex: null,
  2208. evaluated: false,
  2209. module: null,
  2210. esModule: null,
  2211. esmExports: false
  2212. };
  2213. }
  2214. (function() {
  2215. /*
  2216. * There are two variations of System.register:
  2217. * 1. System.register for ES6 conversion (2-3 params) - System.register([name, ]deps, declare)
  2218. * see https://github.com/ModuleLoader/es6-module-loader/wiki/System.register-Explained
  2219. *
  2220. * 2. System.registerDynamic for dynamic modules (3-4 params) - System.registerDynamic([name, ]deps, executingRequire, execute)
  2221. * the true or false statement
  2222. *
  2223. * this extension implements the linking algorithm for the two variations identical to the spec
  2224. * allowing compiled ES6 circular references to work alongside AMD and CJS circular references.
  2225. *
  2226. */
  2227. SystemJSLoader.prototype.register = function(name, deps, declare) {
  2228. if (typeof name != 'string') {
  2229. declare = deps;
  2230. deps = name;
  2231. name = null;
  2232. }
  2233. // dynamic backwards-compatibility
  2234. // can be deprecated eventually
  2235. if (typeof declare == 'boolean')
  2236. return this.registerDynamic.apply(this, arguments);
  2237. var entry = createEntry();
  2238. // ideally wouldn't apply map config to bundle names but
  2239. // dependencies go through map regardless so we can't restrict
  2240. // could reconsider in shift to new spec
  2241. entry.name = name && (this.normalizeSync || this.normalize).call(this, name);
  2242. entry.declarative = true;
  2243. entry.deps = deps;
  2244. entry.declare = declare;
  2245. this.pushRegister_({
  2246. amd: false,
  2247. entry: entry
  2248. });
  2249. };
  2250. SystemJSLoader.prototype.registerDynamic = function(name, deps, declare, execute) {
  2251. if (typeof name != 'string') {
  2252. execute = declare;
  2253. declare = deps;
  2254. deps = name;
  2255. name = null;
  2256. }
  2257. // dynamic
  2258. var entry = createEntry();
  2259. entry.name = name && (this.normalizeSync || this.normalize).call(this, name);
  2260. entry.deps = deps;
  2261. entry.execute = execute;
  2262. entry.executingRequire = declare;
  2263. this.pushRegister_({
  2264. amd: false,
  2265. entry: entry
  2266. });
  2267. };
  2268. hook('reduceRegister_', function() {
  2269. return function(load, register) {
  2270. if (!register)
  2271. return;
  2272. var entry = register.entry;
  2273. var curMeta = load && load.metadata;
  2274. // named register
  2275. if (entry.name) {
  2276. if (!(entry.name in this.defined))
  2277. this.defined[entry.name] = entry;
  2278. if (curMeta)
  2279. curMeta.bundle = true;
  2280. }
  2281. // anonymous register
  2282. if (!entry.name || load && entry.name == load.name) {
  2283. if (!curMeta)
  2284. throw new TypeError('Unexpected anonymous System.register call.');
  2285. if (curMeta.entry) {
  2286. if (curMeta.format == 'register')
  2287. throw new Error('Multiple anonymous System.register calls in module ' + load.name + '. If loading a bundle, ensure all the System.register calls are named.');
  2288. else
  2289. throw new Error('Module ' + load.name + ' interpreted as ' + curMeta.format + ' module format, but called System.register.');
  2290. }
  2291. if (!curMeta.format)
  2292. curMeta.format = 'register';
  2293. curMeta.entry = entry;
  2294. }
  2295. };
  2296. });
  2297. hookConstructor(function(constructor) {
  2298. return function() {
  2299. constructor.call(this);
  2300. this.defined = {};
  2301. this._loader.moduleRecords = {};
  2302. };
  2303. });
  2304. function buildGroups(entry, loader, groups) {
  2305. groups[entry.groupIndex] = groups[entry.groupIndex] || [];
  2306. if (indexOf.call(groups[entry.groupIndex], entry) != -1)
  2307. return;
  2308. groups[entry.groupIndex].push(entry);
  2309. for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) {
  2310. var depName = entry.normalizedDeps[i];
  2311. var depEntry = loader.defined[depName];
  2312. // not in the registry means already linked / ES6
  2313. if (!depEntry || depEntry.evaluated)
  2314. continue;
  2315. // now we know the entry is in our unlinked linkage group
  2316. var depGroupIndex = entry.groupIndex + (depEntry.declarative != entry.declarative);
  2317. // the group index of an entry is always the maximum
  2318. if (depEntry.groupIndex === null || depEntry.groupIndex < depGroupIndex) {
  2319. // if already in a group, remove from the old group
  2320. if (depEntry.groupIndex !== null) {
  2321. groups[depEntry.groupIndex].splice(indexOf.call(groups[depEntry.groupIndex], depEntry), 1);
  2322. // if the old group is empty, then we have a mixed depndency cycle
  2323. if (groups[depEntry.groupIndex].length == 0)
  2324. throw new Error("Mixed dependency cycle detected");
  2325. }
  2326. depEntry.groupIndex = depGroupIndex;
  2327. }
  2328. buildGroups(depEntry, loader, groups);
  2329. }
  2330. }
  2331. function link(name, loader) {
  2332. var startEntry = loader.defined[name];
  2333. // skip if already linked
  2334. if (startEntry.module)
  2335. return;
  2336. startEntry.groupIndex = 0;
  2337. var groups = [];
  2338. buildGroups(startEntry, loader, groups);
  2339. var curGroupDeclarative = !!startEntry.declarative == groups.length % 2;
  2340. for (var i = groups.length - 1; i >= 0; i--) {
  2341. var group = groups[i];
  2342. for (var j = 0; j < group.length; j++) {
  2343. var entry = group[j];
  2344. // link each group
  2345. if (curGroupDeclarative)
  2346. linkDeclarativeModule(entry, loader);
  2347. else
  2348. linkDynamicModule(entry, loader);
  2349. }
  2350. curGroupDeclarative = !curGroupDeclarative;
  2351. }
  2352. }
  2353. // module binding records
  2354. function Module() {}
  2355. defineProperty(Module, 'toString', {
  2356. value: function() {
  2357. return 'Module';
  2358. }
  2359. });
  2360. function getOrCreateModuleRecord(name, moduleRecords) {
  2361. return moduleRecords[name] || (moduleRecords[name] = {
  2362. name: name,
  2363. dependencies: [],
  2364. exports: new Module(), // start from an empty module and extend
  2365. importers: []
  2366. });
  2367. }
  2368. function linkDeclarativeModule(entry, loader) {
  2369. // only link if already not already started linking (stops at circular)
  2370. if (entry.module)
  2371. return;
  2372. var moduleRecords = loader._loader.moduleRecords;
  2373. var module = entry.module = getOrCreateModuleRecord(entry.name, moduleRecords);
  2374. var exports = entry.module.exports;
  2375. var declaration = entry.declare.call(__global, function(name, value) {
  2376. module.locked = true;
  2377. if (typeof name == 'object') {
  2378. for (var p in name)
  2379. exports[p] = name[p];
  2380. }
  2381. else {
  2382. exports[name] = value;
  2383. }
  2384. for (var i = 0, l = module.importers.length; i < l; i++) {
  2385. var importerModule = module.importers[i];
  2386. if (!importerModule.locked) {
  2387. var importerIndex = indexOf.call(importerModule.dependencies, module);
  2388. importerModule.setters[importerIndex](exports);
  2389. }
  2390. }
  2391. module.locked = false;
  2392. return value;
  2393. });
  2394. module.setters = declaration.setters;
  2395. module.execute = declaration.execute;
  2396. if (!module.setters || !module.execute) {
  2397. throw new TypeError('Invalid System.register form for ' + entry.name);
  2398. }
  2399. // now link all the module dependencies
  2400. for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) {
  2401. var depName = entry.normalizedDeps[i];
  2402. var depEntry = loader.defined[depName];
  2403. var depModule = moduleRecords[depName];
  2404. // work out how to set depExports based on scenarios...
  2405. var depExports;
  2406. if (depModule) {
  2407. depExports = depModule.exports;
  2408. }
  2409. // dynamic, already linked in our registry
  2410. else if (depEntry && !depEntry.declarative) {
  2411. depExports = depEntry.esModule;
  2412. }
  2413. // in the loader registry
  2414. else if (!depEntry) {
  2415. depExports = loader.get(depName);
  2416. }
  2417. // we have an entry -> link
  2418. else {
  2419. linkDeclarativeModule(depEntry, loader);
  2420. depModule = depEntry.module;
  2421. depExports = depModule.exports;
  2422. }
  2423. // only declarative modules have dynamic bindings
  2424. if (depModule && depModule.importers) {
  2425. depModule.importers.push(module);
  2426. module.dependencies.push(depModule);
  2427. }
  2428. else {
  2429. module.dependencies.push(null);
  2430. }
  2431. // run setters for all entries with the matching dependency name
  2432. var originalIndices = entry.originalIndices[i];
  2433. for (var j = 0, len = originalIndices.length; j < len; ++j) {
  2434. var index = originalIndices[j];
  2435. if (module.setters[index]) {
  2436. module.setters[index](depExports);
  2437. }
  2438. }
  2439. }
  2440. }
  2441. // An analog to loader.get covering execution of all three layers (real declarative, simulated declarative, simulated dynamic)
  2442. function getModule(name, loader) {
  2443. var exports;
  2444. var entry = loader.defined[name];
  2445. if (!entry) {
  2446. exports = loader.get(name);
  2447. if (!exports)
  2448. throw new Error('Unable to load dependency ' + name + '.');
  2449. }
  2450. else {
  2451. if (entry.declarative)
  2452. ensureEvaluated(name, [], loader);
  2453. else if (!entry.evaluated)
  2454. linkDynamicModule(entry, loader);
  2455. exports = entry.module.exports;
  2456. }
  2457. if ((!entry || entry.declarative) && exports && exports.__useDefault)
  2458. return exports['default'];
  2459. return exports;
  2460. }
  2461. function linkDynamicModule(entry, loader) {
  2462. if (entry.module)
  2463. return;
  2464. var exports = {};
  2465. var module = entry.module = { exports: exports, id: entry.name };
  2466. // AMD requires execute the tree first
  2467. if (!entry.executingRequire) {
  2468. for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) {
  2469. var depName = entry.normalizedDeps[i];
  2470. // we know we only need to link dynamic due to linking algorithm
  2471. var depEntry = loader.defined[depName];
  2472. if (depEntry)
  2473. linkDynamicModule(depEntry, loader);
  2474. }
  2475. }
  2476. // now execute
  2477. entry.evaluated = true;
  2478. var output = entry.execute.call(__global, function(name) {
  2479. for (var i = 0, l = entry.deps.length; i < l; i++) {
  2480. if (entry.deps[i] != name)
  2481. continue;
  2482. return getModule(entry.normalizedDeps[i], loader);
  2483. }
  2484. throw new Error('Module ' + name + ' not declared as a dependency.');
  2485. }, exports, module);
  2486. if (output)
  2487. module.exports = output;
  2488. // create the esModule object, which allows ES6 named imports of dynamics
  2489. exports = module.exports;
  2490. // __esModule flag treats as already-named
  2491. if (exports && exports.__esModule)
  2492. entry.esModule = exports;
  2493. // set module as 'default' export, then fake named exports by iterating properties
  2494. else if (entry.esmExports && exports !== __global)
  2495. entry.esModule = getESModule(exports);
  2496. // just use the 'default' export
  2497. else
  2498. entry.esModule = { 'default': exports };
  2499. }
  2500. /*
  2501. * Given a module, and the list of modules for this current branch,
  2502. * ensure that each of the dependencies of this module is evaluated
  2503. * (unless one is a circular dependency already in the list of seen
  2504. * modules, in which case we execute it)
  2505. *
  2506. * Then we evaluate the module itself depth-first left to right
  2507. * execution to match ES6 modules
  2508. */
  2509. function ensureEvaluated(moduleName, seen, loader) {
  2510. var entry = loader.defined[moduleName];
  2511. // if already seen, that means it's an already-evaluated non circular dependency
  2512. if (!entry || entry.evaluated || !entry.declarative)
  2513. return;
  2514. // this only applies to declarative modules which late-execute
  2515. seen.push(moduleName);
  2516. for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) {
  2517. var depName = entry.normalizedDeps[i];
  2518. if (indexOf.call(seen, depName) == -1) {
  2519. if (!loader.defined[depName])
  2520. loader.get(depName);
  2521. else
  2522. ensureEvaluated(depName, seen, loader);
  2523. }
  2524. }
  2525. if (entry.evaluated)
  2526. return;
  2527. entry.evaluated = true;
  2528. entry.module.execute.call(__global);
  2529. }
  2530. // override the delete method to also clear the register caches
  2531. hook('delete', function(del) {
  2532. return function(name) {
  2533. delete this._loader.moduleRecords[name];
  2534. delete this.defined[name];
  2535. return del.call(this, name);
  2536. };
  2537. });
  2538. var leadingCommentAndMetaRegEx = /^\s*(\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)*\s*/;
  2539. function detectRegisterFormat(source) {
  2540. var leadingCommentAndMeta = source.match(leadingCommentAndMetaRegEx);
  2541. return leadingCommentAndMeta && source.substr(leadingCommentAndMeta[0].length, 15) == 'System.register';
  2542. }
  2543. hook('fetch', function(fetch) {
  2544. return function(load) {
  2545. if (this.defined[load.name]) {
  2546. load.metadata.format = 'defined';
  2547. return '';
  2548. }
  2549. if (load.metadata.format == 'register' && !load.metadata.authorization && load.metadata.scriptLoad !== false)
  2550. load.metadata.scriptLoad = true;
  2551. load.metadata.deps = load.metadata.deps || [];
  2552. return fetch.call(this, load);
  2553. };
  2554. });
  2555. hook('translate', function(translate) {
  2556. // we run the meta detection here (register is after meta)
  2557. return function(load) {
  2558. load.metadata.deps = load.metadata.deps || [];
  2559. return Promise.resolve(translate.call(this, load)).then(function(source) {
  2560. // run detection for register format
  2561. if (load.metadata.format == 'register' || !load.metadata.format && detectRegisterFormat(load.source))
  2562. load.metadata.format = 'register';
  2563. return source;
  2564. });
  2565. };
  2566. });
  2567. hook('instantiate', function(instantiate) {
  2568. return function(load) {
  2569. var loader = this;
  2570. var entry;
  2571. // first we check if this module has already been defined in the registry
  2572. if (loader.defined[load.name]) {
  2573. entry = loader.defined[load.name];
  2574. entry.deps = entry.deps.concat(load.metadata.deps);
  2575. }
  2576. // picked up already by an anonymous System.register script injection
  2577. // or via the dynamic formats
  2578. else if (load.metadata.entry) {
  2579. entry = load.metadata.entry;
  2580. entry.deps = entry.deps.concat(load.metadata.deps);
  2581. }
  2582. // Contains System.register calls
  2583. // (dont run bundles in the builder)
  2584. else if (!(loader.builder && load.metadata.bundle)
  2585. && (load.metadata.format == 'register' || load.metadata.format == 'esm' || load.metadata.format == 'es6')) {
  2586. if (typeof __exec != 'undefined')
  2587. __exec.call(loader, load);
  2588. if (!load.metadata.entry && !load.metadata.bundle)
  2589. throw new Error(load.name + ' detected as ' + load.metadata.format + ' but didn\'t execute.');
  2590. entry = load.metadata.entry;
  2591. // support metadata deps for System.register
  2592. if (entry && load.metadata.deps)
  2593. entry.deps = entry.deps.concat(load.metadata.deps);
  2594. }
  2595. // named bundles are just an empty module
  2596. if (!entry) {
  2597. entry = createEntry();
  2598. entry.deps = load.metadata.deps;
  2599. entry.execute = function() {};
  2600. }
  2601. // place this module onto defined for circular references
  2602. loader.defined[load.name] = entry;
  2603. var grouped = group(entry.deps);
  2604. entry.deps = grouped.names;
  2605. entry.originalIndices = grouped.indices;
  2606. entry.name = load.name;
  2607. entry.esmExports = load.metadata.esmExports !== false;
  2608. // first, normalize all dependencies
  2609. var normalizePromises = [];
  2610. for (var i = 0, l = entry.deps.length; i < l; i++)
  2611. normalizePromises.push(Promise.resolve(loader.normalize(entry.deps[i], load.name)));
  2612. return Promise.all(normalizePromises).then(function(normalizedDeps) {
  2613. entry.normalizedDeps = normalizedDeps;
  2614. return {
  2615. deps: entry.deps,
  2616. execute: function() {
  2617. // recursively ensure that the module and all its
  2618. // dependencies are linked (with dependency group handling)
  2619. link(load.name, loader);
  2620. // now handle dependency execution in correct order
  2621. ensureEvaluated(load.name, [], loader);
  2622. // remove from the registry
  2623. loader.defined[load.name] = undefined;
  2624. // return the defined module object
  2625. return loader.newModule(entry.declarative ? entry.module.exports : entry.esModule);
  2626. }
  2627. };
  2628. });
  2629. };
  2630. });
  2631. })();
  2632. /*
  2633. * Extension to detect ES6 and auto-load Traceur or Babel for processing
  2634. */
  2635. (function() {
  2636. // good enough ES6 module detection regex - format detections not designed to be accurate, but to handle the 99% use case
  2637. var esmRegEx = /(^\s*|[}\);\n]\s*)(import\s+(['"]|(\*\s+as\s+)?[^"'\(\)\n;]+\s+from\s+['"]|\{)|export\s+\*\s+from\s+["']|export\s+(\{|default|function|class|var|const|let|async\s+function))/;
  2638. var traceurRuntimeRegEx = /\$traceurRuntime\s*\./;
  2639. var babelHelpersRegEx = /babelHelpers\s*\./;
  2640. hook('translate', function(translate) {
  2641. return function(load) {
  2642. var loader = this;
  2643. return translate.call(loader, load)
  2644. .then(function(source) {
  2645. // detect & transpile ES6
  2646. if (load.metadata.format == 'esm' || load.metadata.format == 'es6' || !load.metadata.format && source.match(esmRegEx)) {
  2647. if (load.metadata.format == 'es6')
  2648. warn.call(loader, 'Module ' + load.name + ' has metadata setting its format to "es6", which is deprecated.\nThis should be updated to "esm".');
  2649. load.metadata.format = 'esm';
  2650. if (loader.transpiler === false)
  2651. throw new TypeError('Unable to dynamically transpile ES module as System.transpiler set to false.');
  2652. // setting loadedTranspiler_ = false tells the next block to
  2653. // do checks for setting transpiler metadata
  2654. loader.loadedTranspiler_ = loader.loadedTranspiler_ || false;
  2655. if (loader.pluginLoader)
  2656. loader.pluginLoader.loadedTranspiler_ = loader.loadedTranspiler_ || false;
  2657. // builder support
  2658. if (loader.builder)
  2659. load.metadata.originalSource = load.source;
  2660. // defined in es6-module-loader/src/transpile.js
  2661. return transpile.call(loader, load)
  2662. .then(function(source) {
  2663. // clear sourceMap as transpiler embeds it
  2664. load.metadata.sourceMap = undefined;
  2665. return source;
  2666. });
  2667. }
  2668. // load the transpiler correctly
  2669. if (loader.loadedTranspiler_ === false && load.name == loader.normalizeSync(loader.transpiler)) {
  2670. warn.call(loader, 'Note that internal transpilation via System.transpiler has been deprecated for transpiler plugins.');
  2671. // always load transpiler as a global
  2672. if (source.length > 100) {
  2673. load.metadata.format = load.metadata.format || 'global';
  2674. if (loader.transpiler === 'traceur')
  2675. load.metadata.exports = 'traceur';
  2676. if (loader.transpiler === 'typescript')
  2677. load.metadata.exports = 'ts';
  2678. }
  2679. loader.loadedTranspiler_ = true;
  2680. }
  2681. // load the transpiler runtime correctly
  2682. if (loader.loadedTranspilerRuntime_ === false) {
  2683. if (load.name == loader.normalizeSync('traceur-runtime')
  2684. || load.name == loader.normalizeSync('babel/external-helpers*')) {
  2685. if (source.length > 100)
  2686. load.metadata.format = load.metadata.format || 'global';
  2687. loader.loadedTranspilerRuntime_ = true;
  2688. }
  2689. }
  2690. // detect transpiler runtime usage to load runtimes
  2691. if ((load.metadata.format == 'register' || load.metadata.bundle) && loader.loadedTranspilerRuntime_ !== true) {
  2692. if (!__global.$traceurRuntime && load.source.match(traceurRuntimeRegEx)) {
  2693. loader.loadedTranspilerRuntime_ = loader.loadedTranspilerRuntime_ || false;
  2694. return loader['import']('traceur-runtime').then(function() {
  2695. return source;
  2696. });
  2697. }
  2698. if (!__global.babelHelpers && load.source.match(babelHelpersRegEx)) {
  2699. loader.loadedTranspilerRuntime_ = loader.loadedTranspilerRuntime_ || false;
  2700. return loader['import']('babel/external-helpers').then(function() {
  2701. return source;
  2702. });
  2703. }
  2704. }
  2705. return source;
  2706. });
  2707. };
  2708. });
  2709. })();
  2710. /*
  2711. SystemJS Global Format
  2712. Supports
  2713. metadata.deps
  2714. metadata.globals
  2715. metadata.exports
  2716. Without metadata.exports, detects writes to the global object.
  2717. */
  2718. var __globalName = typeof self != 'undefined' ? 'self' : 'global';
  2719. hook('reduceRegister_', function(reduceRegister) {
  2720. return function(load, register) {
  2721. if (register)
  2722. return reduceRegister.call(this, load, register);
  2723. load.metadata.format = 'global';
  2724. var entry = load.metadata.entry = createEntry();
  2725. var globalValue = readMemberExpression(load.metadata.exports, __global);
  2726. entry.execute = function() {
  2727. return globalValue;
  2728. };
  2729. };
  2730. });
  2731. hook('fetch', function(fetch) {
  2732. return function(load) {
  2733. if (load.metadata.exports && !load.metadata.format)
  2734. load.metadata.format = 'global';
  2735. // A global with exports, no globals and no deps
  2736. // can be loaded via a script tag
  2737. if (load.metadata.format == 'global' && !load.metadata.authorization
  2738. && load.metadata.exports && !load.metadata.globals
  2739. && (!load.metadata.deps || load.metadata.deps.length == 0)
  2740. && load.metadata.scriptLoad !== false)
  2741. load.metadata.scriptLoad = true;
  2742. return fetch.call(this, load);
  2743. };
  2744. });
  2745. // ideally we could support script loading for globals, but the issue with that is that
  2746. // we can't do it with AMD support side-by-side since AMD support means defining the
  2747. // global define, and global support means not definining it, yet we don't have any hook
  2748. // into the "pre-execution" phase of a script tag being loaded to handle both cases
  2749. hook('instantiate', function(instantiate) {
  2750. return function(load) {
  2751. var loader = this;
  2752. if (!load.metadata.format)
  2753. load.metadata.format = 'global';
  2754. // globals shorthand support for:
  2755. // globals = ['Buffer'] where we just require 'Buffer' in the current context
  2756. if (load.metadata.globals) {
  2757. if (load.metadata.globals instanceof Array) {
  2758. var globals = {};
  2759. for (var i = 0; i < load.metadata.globals.length; i++)
  2760. globals[load.metadata.globals[i]] = load.metadata.globals[i];
  2761. load.metadata.globals = globals;
  2762. }
  2763. }
  2764. // global is a fallback module format
  2765. if (load.metadata.format == 'global' && !load.metadata.registered) {
  2766. var entry = createEntry();
  2767. load.metadata.entry = entry;
  2768. entry.deps = [];
  2769. for (var g in load.metadata.globals)
  2770. entry.deps.push(load.metadata.globals[g]);
  2771. entry.execute = function(require, exports, module) {
  2772. var globals;
  2773. if (load.metadata.globals) {
  2774. globals = {};
  2775. for (var g in load.metadata.globals)
  2776. globals[g] = require(load.metadata.globals[g]);
  2777. }
  2778. var exportName = load.metadata.exports;
  2779. if (exportName)
  2780. load.source += '\n' + __globalName + '["' + exportName + '"] = ' + exportName + ';';
  2781. var retrieveGlobal = loader.get('@@global-helpers').prepareGlobal(module.id, exportName, globals);
  2782. __exec.call(loader, load);
  2783. return retrieveGlobal();
  2784. }
  2785. }
  2786. return instantiate.call(this, load);
  2787. };
  2788. });
  2789. hookConstructor(function(constructor) {
  2790. return function() {
  2791. var loader = this;
  2792. constructor.call(loader);
  2793. var hasOwnProperty = Object.prototype.hasOwnProperty;
  2794. // bare minimum ignores for IE8
  2795. var ignoredGlobalProps = ['_g', 'sessionStorage', 'localStorage', 'clipboardData', 'frames', 'frameElement', 'external', 'mozAnimationStartTime', 'webkitStorageInfo', 'webkitIndexedDB'];
  2796. var globalSnapshot;
  2797. function forEachGlobal(callback) {
  2798. if (Object.keys)
  2799. Object.keys(__global).forEach(callback);
  2800. else
  2801. for (var g in __global) {
  2802. if (!hasOwnProperty.call(__global, g))
  2803. continue;
  2804. callback(g);
  2805. }
  2806. }
  2807. function forEachGlobalValue(callback) {
  2808. forEachGlobal(function(globalName) {
  2809. if (indexOf.call(ignoredGlobalProps, globalName) != -1)
  2810. return;
  2811. try {
  2812. var value = __global[globalName];
  2813. }
  2814. catch (e) {
  2815. ignoredGlobalProps.push(globalName);
  2816. }
  2817. callback(globalName, value);
  2818. });
  2819. }
  2820. loader.set('@@global-helpers', loader.newModule({
  2821. prepareGlobal: function(moduleName, exportName, globals) {
  2822. // disable module detection
  2823. var curDefine = __global.define;
  2824. __global.define = undefined;
  2825. __global.exports = undefined;
  2826. if (__global.module && __global.module.exports)
  2827. __global.module = undefined;
  2828. // set globals
  2829. var oldGlobals;
  2830. if (globals) {
  2831. oldGlobals = {};
  2832. for (var g in globals) {
  2833. oldGlobals[g] = __global[g];
  2834. __global[g] = globals[g];
  2835. }
  2836. }
  2837. // store a complete copy of the global object in order to detect changes
  2838. if (!exportName) {
  2839. globalSnapshot = {};
  2840. forEachGlobalValue(function(name, value) {
  2841. globalSnapshot[name] = value;
  2842. });
  2843. }
  2844. // return function to retrieve global
  2845. return function() {
  2846. var globalValue;
  2847. if (exportName) {
  2848. globalValue = readMemberExpression(exportName, __global);
  2849. }
  2850. else {
  2851. var singleGlobal;
  2852. var multipleExports;
  2853. var exports = {};
  2854. forEachGlobalValue(function(name, value) {
  2855. if (globalSnapshot[name] === value)
  2856. return;
  2857. if (typeof value == 'undefined')
  2858. return;
  2859. exports[name] = value;
  2860. if (typeof singleGlobal != 'undefined') {
  2861. if (!multipleExports && singleGlobal !== value)
  2862. multipleExports = true;
  2863. }
  2864. else {
  2865. singleGlobal = value;
  2866. }
  2867. });
  2868. globalValue = multipleExports ? exports : singleGlobal;
  2869. }
  2870. // revert globals
  2871. if (oldGlobals) {
  2872. for (var g in oldGlobals)
  2873. __global[g] = oldGlobals[g];
  2874. }
  2875. __global.define = curDefine;
  2876. return globalValue;
  2877. };
  2878. }
  2879. }));
  2880. };
  2881. });
  2882. /*
  2883. SystemJS CommonJS Format
  2884. */
  2885. (function() {
  2886. // CJS Module Format
  2887. // require('...') || exports[''] = ... || exports.asd = ... || module.exports = ...
  2888. var cjsExportsRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.]|module\.)exports\s*(\[['"]|\.)|(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])module\.exports\s*[=,]/;
  2889. // RegEx adjusted from https://github.com/jbrantly/yabble/blob/master/lib/yabble.js#L339
  2890. var cjsRequireRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF."'])require\s*\(\s*("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*')\s*\)/g;
  2891. var commentRegEx = /(^|[^\\])(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
  2892. var stringRegEx = /(?:"[^"\\\n\r]*(?:\\.[^"\\\n\r]*)*"|'[^'\\\n\r]*(?:\\.[^'\\\n\r]*)*')/g;
  2893. function getCJSDeps(source) {
  2894. cjsRequireRegEx.lastIndex = commentRegEx.lastIndex = stringRegEx.lastIndex = 0;
  2895. var deps = [];
  2896. var match;
  2897. // track string and comment locations for unminified source
  2898. var stringLocations = [], commentLocations = [];
  2899. function inLocation(locations, match, starts) {
  2900. var inLocation = false;
  2901. for (var i = 0; i < locations.length; i++)
  2902. if (locations[i][0] < match.index && locations[i][1] > match.index + (!starts ? match[0].length : 0))
  2903. return true;
  2904. return false;
  2905. }
  2906. if (source.length / source.split('\n').length < 200) {
  2907. while (match = stringRegEx.exec(source))
  2908. stringLocations.push([match.index, match.index + match[0].length]);
  2909. while (match = commentRegEx.exec(source)) {
  2910. // only track comments not starting in strings
  2911. if (!inLocation(stringLocations, match, true))
  2912. commentLocations.push([match.index, match.index + match[0].length]);
  2913. }
  2914. }
  2915. while (match = cjsRequireRegEx.exec(source)) {
  2916. // ensure we're not within a string or comment location
  2917. if (!inLocation(stringLocations, match) && !inLocation(commentLocations, match))
  2918. deps.push(match[1].substr(1, match[1].length - 2));
  2919. }
  2920. return deps;
  2921. }
  2922. if (typeof window != 'undefined' && typeof document != 'undefined' && window.location)
  2923. var windowOrigin = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
  2924. // include the node require since we're overriding it
  2925. if (typeof require != 'undefined' && require.resolve && typeof process != 'undefined')
  2926. SystemJSLoader.prototype._nodeRequire = require;
  2927. var nodeCoreModules = ['assert', 'buffer', 'child_process', 'cluster', 'console', 'constants',
  2928. 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'module', 'net', 'os', 'path',
  2929. 'process', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'sys', 'timers',
  2930. 'tls', 'tty', 'url', 'util', 'vm', 'zlib'];
  2931. hook('normalize', function(normalize) {
  2932. return function(name, parentName) {
  2933. // dynamically load node-core modules when requiring `@node/fs` for example
  2934. if (name.substr(0, 6) == '@node/' && nodeCoreModules.indexOf(name.substr(6)) != -1) {
  2935. if (!this._nodeRequire)
  2936. throw new TypeError('Can only load node core modules in Node.');
  2937. this.set(name, this.newModule(getESModule(this._nodeRequire(name.substr(6)))));
  2938. }
  2939. return normalize.apply(this, arguments);
  2940. };
  2941. });
  2942. hook('instantiate', function(instantiate) {
  2943. return function(load) {
  2944. var loader = this;
  2945. if (!load.metadata.format) {
  2946. cjsExportsRegEx.lastIndex = 0;
  2947. cjsRequireRegEx.lastIndex = 0;
  2948. if (cjsRequireRegEx.exec(load.source) || cjsExportsRegEx.exec(load.source))
  2949. load.metadata.format = 'cjs';
  2950. }
  2951. if (load.metadata.format == 'cjs') {
  2952. var metaDeps = load.metadata.deps;
  2953. var deps = getCJSDeps(load.source);
  2954. for (var g in load.metadata.globals)
  2955. deps.push(load.metadata.globals[g]);
  2956. var entry = createEntry();
  2957. load.metadata.entry = entry;
  2958. entry.deps = deps;
  2959. entry.executingRequire = true;
  2960. entry.execute = function(require, exports, module) {
  2961. // ensure meta deps execute first
  2962. for (var i = 0; i < metaDeps.length; i++)
  2963. require(metaDeps[i]);
  2964. var address = load.address || '';
  2965. var dirname = address.split('/');
  2966. dirname.pop();
  2967. dirname = dirname.join('/');
  2968. if (address.substr(0, 8) == 'file:///') {
  2969. address = address.substr(7);
  2970. dirname = dirname.substr(7);
  2971. // on windows remove leading '/'
  2972. if (isWindows) {
  2973. address = address.substr(1);
  2974. dirname = dirname.substr(1);
  2975. }
  2976. }
  2977. else if (windowOrigin && address.substr(0, windowOrigin.length) === windowOrigin) {
  2978. address = address.substr(windowOrigin.length);
  2979. dirname = dirname.substr(windowOrigin.length);
  2980. }
  2981. // disable AMD detection
  2982. var define = __global.define;
  2983. __global.define = undefined;
  2984. __global.__cjsWrapper = {
  2985. exports: exports,
  2986. args: [require, exports, module, address, dirname, __global, __global]
  2987. };
  2988. var globals = '';
  2989. if (load.metadata.globals) {
  2990. for (var g in load.metadata.globals)
  2991. globals += 'var ' + g + ' = require("' + load.metadata.globals[g] + '");';
  2992. }
  2993. load.source = "(function(require, exports, module, __filename, __dirname, global, GLOBAL) {" + globals
  2994. + load.source + "\n}).apply(__cjsWrapper.exports, __cjsWrapper.args);";
  2995. __exec.call(loader, load);
  2996. __global.__cjsWrapper = undefined;
  2997. __global.define = define;
  2998. };
  2999. }
  3000. return instantiate.call(loader, load);
  3001. };
  3002. });
  3003. })();
  3004. /*
  3005. * AMD Helper function module
  3006. * Separated into its own file as this is the part needed for full AMD support in SFX builds
  3007. * NB since implementations have now diverged this can be merged back with amd.js
  3008. */
  3009. hookConstructor(function(constructor) {
  3010. return function() {
  3011. var loader = this;
  3012. constructor.call(this);
  3013. var commentRegEx = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
  3014. var cjsRequirePre = "(?:^|[^$_a-zA-Z\\xA0-\\uFFFF.])";
  3015. var cjsRequirePost = "\\s*\\(\\s*(\"([^\"]+)\"|'([^']+)')\\s*\\)";
  3016. var fnBracketRegEx = /\(([^\)]*)\)/;
  3017. var wsRegEx = /^\s+|\s+$/g;
  3018. var requireRegExs = {};
  3019. function getCJSDeps(source, requireIndex) {
  3020. // remove comments
  3021. source = source.replace(commentRegEx, '');
  3022. // determine the require alias
  3023. var params = source.match(fnBracketRegEx);
  3024. var requireAlias = (params[1].split(',')[requireIndex] || 'require').replace(wsRegEx, '');
  3025. // find or generate the regex for this requireAlias
  3026. var requireRegEx = requireRegExs[requireAlias] || (requireRegExs[requireAlias] = new RegExp(cjsRequirePre + requireAlias + cjsRequirePost, 'g'));
  3027. requireRegEx.lastIndex = 0;
  3028. var deps = [];
  3029. var match;
  3030. while (match = requireRegEx.exec(source))
  3031. deps.push(match[2] || match[3]);
  3032. return deps;
  3033. }
  3034. /*
  3035. AMD-compatible require
  3036. To copy RequireJS, set window.require = window.requirejs = loader.amdRequire
  3037. */
  3038. function require(names, callback, errback, referer) {
  3039. // in amd, first arg can be a config object... we just ignore
  3040. if (typeof names == 'object' && !(names instanceof Array))
  3041. return require.apply(null, Array.prototype.splice.call(arguments, 1, arguments.length - 1));
  3042. // amd require
  3043. if (typeof names == 'string' && typeof callback == 'function')
  3044. names = [names];
  3045. if (names instanceof Array) {
  3046. var dynamicRequires = [];
  3047. for (var i = 0; i < names.length; i++)
  3048. dynamicRequires.push(loader['import'](names[i], referer));
  3049. Promise.all(dynamicRequires).then(function(modules) {
  3050. if (callback)
  3051. callback.apply(null, modules);
  3052. }, errback);
  3053. }
  3054. // commonjs require
  3055. else if (typeof names == 'string') {
  3056. var module = loader.get(loader.normalizeSync(names, referer));
  3057. if (!module)
  3058. throw new Error('Module not already loaded loading "' + names + '" from "' + referer + '".');
  3059. return module.__useDefault ? module['default'] : module;
  3060. }
  3061. else
  3062. throw new TypeError('Invalid require');
  3063. }
  3064. function define(name, deps, factory) {
  3065. if (typeof name != 'string') {
  3066. factory = deps;
  3067. deps = name;
  3068. name = null;
  3069. }
  3070. if (!(deps instanceof Array)) {
  3071. factory = deps;
  3072. deps = ['require', 'exports', 'module'].splice(0, factory.length);
  3073. }
  3074. if (typeof factory != 'function')
  3075. factory = (function(factory) {
  3076. return function() { return factory; }
  3077. })(factory);
  3078. // in IE8, a trailing comma becomes a trailing undefined entry
  3079. if (deps[deps.length - 1] === undefined)
  3080. deps.pop();
  3081. // remove system dependencies
  3082. var requireIndex, exportsIndex, moduleIndex;
  3083. if ((requireIndex = indexOf.call(deps, 'require')) != -1) {
  3084. deps.splice(requireIndex, 1);
  3085. // only trace cjs requires for non-named
  3086. // named defines assume the trace has already been done
  3087. if (!name)
  3088. deps = deps.concat(getCJSDeps(factory.toString(), requireIndex));
  3089. }
  3090. if ((exportsIndex = indexOf.call(deps, 'exports')) != -1)
  3091. deps.splice(exportsIndex, 1);
  3092. if ((moduleIndex = indexOf.call(deps, 'module')) != -1)
  3093. deps.splice(moduleIndex, 1);
  3094. function execute(req, exports, module) {
  3095. var depValues = [];
  3096. for (var i = 0; i < deps.length; i++)
  3097. depValues.push(req(deps[i]));
  3098. module.uri = module.id;
  3099. module.config = function() {};
  3100. // add back in system dependencies
  3101. if (moduleIndex != -1)
  3102. depValues.splice(moduleIndex, 0, module);
  3103. if (exportsIndex != -1)
  3104. depValues.splice(exportsIndex, 0, exports);
  3105. if (requireIndex != -1) {
  3106. function contextualRequire(names, callback, errback) {
  3107. if (typeof names == 'string' && typeof callback != 'function')
  3108. return req(names);
  3109. return require.call(loader, names, callback, errback, module.id);
  3110. }
  3111. contextualRequire.toUrl = function(name) {
  3112. // normalize without defaultJSExtensions
  3113. var defaultJSExtension = loader.defaultJSExtensions && name.substr(name.length - 3, 3) != '.js';
  3114. var url = loader.normalizeSync(name, module.id);
  3115. if (defaultJSExtension && url.substr(url.length - 3, 3) == '.js')
  3116. url = url.substr(0, url.length - 3);
  3117. return url;
  3118. };
  3119. depValues.splice(requireIndex, 0, contextualRequire);
  3120. }
  3121. // set global require to AMD require
  3122. var curRequire = __global.require;
  3123. __global.require = require;
  3124. var output = factory.apply(exportsIndex == -1 ? __global : exports, depValues);
  3125. __global.require = curRequire;
  3126. if (typeof output == 'undefined' && module)
  3127. output = module.exports;
  3128. if (typeof output != 'undefined')
  3129. return output;
  3130. }
  3131. var entry = createEntry();
  3132. entry.name = name && (loader.normalizeSync || loader.normalize).call(loader, name);
  3133. entry.deps = deps;
  3134. entry.execute = execute;
  3135. loader.pushRegister_({
  3136. amd: true,
  3137. entry: entry
  3138. });
  3139. }
  3140. define.amd = {};
  3141. // reduction function to attach defines to a load record
  3142. hook('reduceRegister_', function(reduceRegister) {
  3143. return function(load, register) {
  3144. // only handle AMD registers here
  3145. if (!register || !register.amd)
  3146. return reduceRegister.call(this, load, register);
  3147. var curMeta = load && load.metadata;
  3148. var entry = register.entry;
  3149. if (curMeta)
  3150. curMeta.format = 'amd';
  3151. // anonymous define
  3152. if (!entry.name) {
  3153. if (!curMeta)
  3154. throw new TypeError('Unexpected anonymous AMD define.');
  3155. // already defined anonymously -> throw
  3156. if (curMeta.entry)
  3157. throw new TypeError('Multiple defines for anonymous module ' + load.name);
  3158. curMeta.entry = entry;
  3159. }
  3160. // named define
  3161. else {
  3162. // if we don't have any other defines,
  3163. // then let this be an anonymous define
  3164. // this is just to support single modules of the form:
  3165. // define('jquery')
  3166. // still loading anonymously
  3167. // because it is done widely enough to be useful
  3168. // as soon as there is more than one define, this gets removed though
  3169. if (curMeta) {
  3170. if (!curMeta.entry && !curMeta.bundle)
  3171. curMeta.entry = entry;
  3172. else
  3173. curMeta.entry = undefined;
  3174. // note this is now a bundle
  3175. curMeta.bundle = true;
  3176. }
  3177. // define the module through the register registry
  3178. if (!(entry.name in this.defined))
  3179. this.defined[entry.name] = entry;
  3180. }
  3181. };
  3182. });
  3183. // adds define as a global (potentially just temporarily)
  3184. function createDefine() {
  3185. // ensure no NodeJS environment detection
  3186. var oldModule = __global.module;
  3187. var oldExports = __global.exports;
  3188. var oldDefine = __global.define;
  3189. __global.module = undefined;
  3190. __global.exports = undefined;
  3191. __global.define = define;
  3192. return function() {
  3193. __global.define = oldDefine;
  3194. __global.module = oldModule;
  3195. __global.exports = oldExports;
  3196. };
  3197. }
  3198. loader.set('@@amd-helpers', loader.newModule({
  3199. createDefine: createDefine,
  3200. require: require,
  3201. define: define
  3202. }));
  3203. loader.amdDefine = define;
  3204. loader.amdRequire = require;
  3205. };
  3206. });/*
  3207. SystemJS AMD Format
  3208. Provides the AMD module format definition at System.format.amd
  3209. as well as a RequireJS-style require on System.require
  3210. */
  3211. (function() {
  3212. // AMD Module Format Detection RegEx
  3213. // define([.., .., ..], ...)
  3214. // define(varName); || define(function(require, exports) {}); || define({})
  3215. 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]*\))/;
  3216. hook('fetch', function(fetch) {
  3217. return function(load) {
  3218. if (load.metadata.format === 'amd'
  3219. && !load.metadata.authorization
  3220. && load.metadata.scriptLoad !== false)
  3221. load.metadata.scriptLoad = true;
  3222. // script load implies define global leak
  3223. if (load.metadata.scriptLoad && isBrowser)
  3224. this.get('@@amd-helpers').createDefine();
  3225. return fetch.call(this, load);
  3226. };
  3227. });
  3228. hook('instantiate', function(instantiate) {
  3229. return function(load) {
  3230. var loader = this;
  3231. if (load.metadata.format == 'amd' || !load.metadata.format && load.source.match(amdRegEx)) {
  3232. load.metadata.format = 'amd';
  3233. if (!loader.builder && loader.execute !== false) {
  3234. var removeDefine = this.get('@@amd-helpers').createDefine();
  3235. try {
  3236. __exec.call(loader, load);
  3237. }
  3238. finally {
  3239. removeDefine();
  3240. }
  3241. if (!load.metadata.entry && !load.metadata.bundle)
  3242. throw new TypeError('AMD module ' + load.name + ' did not define');
  3243. }
  3244. else {
  3245. load.metadata.execute = function() {
  3246. return load.metadata.builderExecute.apply(this, arguments);
  3247. };
  3248. }
  3249. }
  3250. return instantiate.call(loader, load);
  3251. };
  3252. });
  3253. })();
  3254. /*
  3255. SystemJS Loader Plugin Support
  3256. Supports plugin loader syntax with "!", or via metadata.loader
  3257. The plugin name is loaded as a module itself, and can override standard loader hooks
  3258. for the plugin resource. See the plugin section of the systemjs readme.
  3259. */
  3260. (function() {
  3261. // sync or async plugin normalize function
  3262. function normalizePlugin(normalize, name, parentName, isPlugin, sync) {
  3263. var loader = this;
  3264. // if parent is a plugin, normalize against the parent plugin argument only
  3265. if (parentName) {
  3266. var parentPluginIndex;
  3267. if (loader.pluginFirst) {
  3268. if ((parentPluginIndex = parentName.lastIndexOf('!')) != -1)
  3269. parentName = parentName.substr(parentPluginIndex + 1);
  3270. }
  3271. else {
  3272. if ((parentPluginIndex = parentName.indexOf('!')) != -1)
  3273. parentName = parentName.substr(0, parentPluginIndex);
  3274. }
  3275. }
  3276. // if this is a plugin, normalize the plugin name and the argument
  3277. var pluginIndex = name.lastIndexOf('!');
  3278. if (pluginIndex != -1) {
  3279. var argumentName;
  3280. var pluginName;
  3281. if (loader.pluginFirst) {
  3282. argumentName = name.substr(pluginIndex + 1);
  3283. pluginName = name.substr(0, pluginIndex);
  3284. }
  3285. else {
  3286. argumentName = name.substr(0, pluginIndex);
  3287. pluginName = name.substr(pluginIndex + 1) || argumentName.substr(argumentName.lastIndexOf('.') + 1);
  3288. }
  3289. // note if normalize will add a default js extension
  3290. // if so, remove for backwards compat
  3291. // this is strange and sucks, but will be deprecated
  3292. var defaultExtension = loader.defaultJSExtensions && argumentName.substr(argumentName.length - 3, 3) != '.js';
  3293. // put name back together after parts have been normalized
  3294. function normalizePluginParts(argumentName, pluginName) {
  3295. if (defaultExtension && argumentName.substr(argumentName.length - 3, 3) == '.js')
  3296. argumentName = argumentName.substr(0, argumentName.length - 3);
  3297. if (loader.pluginFirst) {
  3298. return pluginName + '!' + argumentName;
  3299. }
  3300. else {
  3301. return argumentName + '!' + pluginName;
  3302. }
  3303. }
  3304. if (sync) {
  3305. argumentName = loader.normalizeSync(argumentName, parentName);
  3306. pluginName = loader.normalizeSync(pluginName, parentName);
  3307. return normalizePluginParts(argumentName, pluginName);
  3308. }
  3309. else {
  3310. // third argument represents that this is a plugin call
  3311. // which in turn will skip default extension adding within packages
  3312. return Promise.all([
  3313. loader.normalize(argumentName, parentName, true),
  3314. loader.normalize(pluginName, parentName, true)
  3315. ])
  3316. .then(function(normalized) {
  3317. return normalizePluginParts(normalized[0], normalized[1]);
  3318. });
  3319. }
  3320. }
  3321. else {
  3322. return normalize.call(loader, name, parentName, isPlugin);
  3323. }
  3324. }
  3325. // async plugin normalize
  3326. hook('normalize', function(normalize) {
  3327. return function(name, parentName, isPlugin) {
  3328. return normalizePlugin.call(this, normalize, name, parentName, isPlugin, false);
  3329. };
  3330. });
  3331. hook('normalizeSync', function(normalizeSync) {
  3332. return function(name, parentName, isPlugin) {
  3333. return normalizePlugin.call(this, normalizeSync, name, parentName, isPlugin, true);
  3334. };
  3335. });
  3336. hook('locate', function(locate) {
  3337. return function(load) {
  3338. var loader = this;
  3339. var name = load.name;
  3340. // plugin syntax
  3341. var pluginSyntaxIndex;
  3342. if (loader.pluginFirst) {
  3343. if ((pluginSyntaxIndex = name.indexOf('!')) != -1) {
  3344. load.metadata.loader = name.substr(0, pluginSyntaxIndex);
  3345. load.name = name.substr(pluginSyntaxIndex + 1);
  3346. }
  3347. }
  3348. else {
  3349. if ((pluginSyntaxIndex = name.lastIndexOf('!')) != -1) {
  3350. load.metadata.loader = name.substr(pluginSyntaxIndex + 1);
  3351. load.name = name.substr(0, pluginSyntaxIndex);
  3352. }
  3353. }
  3354. return locate.call(loader, load)
  3355. .then(function(address) {
  3356. var plugin = load.metadata.loader;
  3357. if (!plugin)
  3358. return address;
  3359. // only fetch the plugin itself if this name isn't defined
  3360. if (loader.defined && loader.defined[name])
  3361. return address;
  3362. var pluginLoader = loader.pluginLoader || loader;
  3363. // load the plugin module and run standard locate
  3364. return pluginLoader['import'](plugin)
  3365. .then(function(loaderModule) {
  3366. // store the plugin module itself on the metadata
  3367. load.metadata.loaderModule = loaderModule;
  3368. load.address = address;
  3369. if (loaderModule.locate)
  3370. return loaderModule.locate.call(loader, load);
  3371. return address;
  3372. });
  3373. });
  3374. };
  3375. });
  3376. hook('fetch', function(fetch) {
  3377. return function(load) {
  3378. var loader = this;
  3379. if (load.metadata.loaderModule && load.metadata.loaderModule.fetch) {
  3380. load.metadata.scriptLoad = false;
  3381. return load.metadata.loaderModule.fetch.call(loader, load, function(load) {
  3382. return fetch.call(loader, load);
  3383. });
  3384. }
  3385. else {
  3386. return fetch.call(loader, load);
  3387. }
  3388. };
  3389. });
  3390. hook('translate', function(translate) {
  3391. return function(load) {
  3392. var loader = this;
  3393. if (load.metadata.loaderModule && load.metadata.loaderModule.translate)
  3394. return Promise.resolve(load.metadata.loaderModule.translate.call(loader, load)).then(function(result) {
  3395. if (typeof result == 'string')
  3396. load.source = result;
  3397. return translate.call(loader, load);
  3398. });
  3399. else
  3400. return translate.call(loader, load);
  3401. };
  3402. });
  3403. hook('instantiate', function(instantiate) {
  3404. return function(load) {
  3405. var loader = this;
  3406. /*
  3407. * Source map sanitization for load.metadata.sourceMap
  3408. * Used to set browser and build-level source maps for
  3409. * translated sources in a general way.
  3410. */
  3411. var sourceMap = load.metadata.sourceMap;
  3412. // if an object not a JSON string do sanitizing
  3413. if (sourceMap && typeof sourceMap == 'object') {
  3414. var originalName = load.name.split('!')[0];
  3415. // force set the filename of the original file
  3416. sourceMap.file = originalName + '!transpiled';
  3417. // force set the sources list if only one source
  3418. if (!sourceMap.sources || sourceMap.sources.length == 1)
  3419. sourceMap.sources = [originalName];
  3420. load.metadata.sourceMap = JSON.stringify(sourceMap);
  3421. }
  3422. if (load.metadata.loaderModule && load.metadata.loaderModule.instantiate)
  3423. return Promise.resolve(load.metadata.loaderModule.instantiate.call(loader, load)).then(function(result) {
  3424. load.metadata.entry = createEntry();
  3425. load.metadata.entry.execute = function() {
  3426. return result;
  3427. }
  3428. load.metadata.entry.deps = load.metadata.deps;
  3429. load.metadata.format = 'defined';
  3430. return instantiate.call(loader, load);
  3431. });
  3432. else
  3433. return instantiate.call(loader, load);
  3434. };
  3435. });
  3436. })();
  3437. /*
  3438. * Conditions Extension
  3439. *
  3440. * Allows a condition module to alter the resolution of an import via syntax:
  3441. *
  3442. * import $ from 'jquery/#{browser}';
  3443. *
  3444. * Will first load the module 'browser' via `System.import('browser')` and
  3445. * take the default export of that module.
  3446. * If the default export is not a string, an error is thrown.
  3447. *
  3448. * We then substitute the string into the require to get the conditional resolution
  3449. * enabling environment-specific variations like:
  3450. *
  3451. * import $ from 'jquery/ie'
  3452. * import $ from 'jquery/firefox'
  3453. * import $ from 'jquery/chrome'
  3454. * import $ from 'jquery/safari'
  3455. *
  3456. * It can be useful for a condition module to define multiple conditions.
  3457. * This can be done via the `|` modifier to specify an export member expression:
  3458. *
  3459. * import 'jquery/#{./browser.js|grade.version}'
  3460. *
  3461. * Where the `grade` export `version` member in the `browser.js` module is substituted.
  3462. *
  3463. *
  3464. * Boolean Conditionals
  3465. *
  3466. * For polyfill modules, that are used as imports but have no module value,
  3467. * a binary conditional allows a module not to be loaded at all if not needed:
  3468. *
  3469. * import 'es5-shim#?./conditions.js|needs-es5shim'
  3470. *
  3471. * These conditions can also be negated via:
  3472. *
  3473. * import 'es5-shim#?~./conditions.js|es6'
  3474. *
  3475. */
  3476. function parseCondition(condition) {
  3477. var conditionExport, conditionModule, negation;
  3478. var negation = condition[0] == '~';
  3479. var conditionExportIndex = condition.lastIndexOf('|');
  3480. if (conditionExportIndex != -1) {
  3481. conditionExport = condition.substr(conditionExportIndex + 1);
  3482. conditionModule = condition.substr(negation, conditionExportIndex - negation) || '@system-env';
  3483. }
  3484. else {
  3485. conditionExport = null;
  3486. conditionModule = condition.substr(negation);
  3487. }
  3488. return {
  3489. module: conditionModule,
  3490. prop: conditionExport,
  3491. negate: negation
  3492. };
  3493. }
  3494. function serializeCondition(conditionObj) {
  3495. return (conditionObj.negate ? '~' : '') + conditionObj.module + (conditionObj.prop ? '|' + conditionObj.prop : '');
  3496. }
  3497. function resolveCondition(conditionObj, parentName, bool) {
  3498. return this['import'](conditionObj.module, parentName)
  3499. .then(function(m) {
  3500. if (conditionObj.prop)
  3501. m = readMemberExpression(conditionObj.prop, m);
  3502. else if (typeof m == 'object' && m + '' == 'Module')
  3503. m = m['default'];
  3504. return conditionObj.negate ? !m : m;
  3505. });
  3506. }
  3507. var interpolationRegEx = /#\{[^\}]+\}/;
  3508. function interpolateConditional(name, parentName) {
  3509. // first we normalize the conditional
  3510. var conditionalMatch = name.match(interpolationRegEx);
  3511. if (!conditionalMatch)
  3512. return Promise.resolve(name);
  3513. var conditionObj = parseCondition(conditionalMatch[0].substr(2, conditionalMatch[0].length - 3));
  3514. // in builds, return normalized conditional
  3515. if (this.builder)
  3516. return this['normalize'](conditionObj.module, parentName)
  3517. .then(function(conditionModule) {
  3518. conditionObj.module = conditionModule;
  3519. return name.replace(interpolationRegEx, '#{' + serializeCondition(conditionObj) + '}');
  3520. });
  3521. return resolveCondition.call(this, conditionObj, parentName, false)
  3522. .then(function(conditionValue) {
  3523. if (typeof conditionValue !== 'string')
  3524. throw new TypeError('The condition value for ' + name + ' doesn\'t resolve to a string.');
  3525. if (conditionValue.indexOf('/') != -1)
  3526. throw new TypeError('Unabled to interpolate conditional ' + name + (parentName ? ' in ' + parentName : '') + '\n\tThe condition value ' + conditionValue + ' cannot contain a "/" separator.');
  3527. return name.replace(interpolationRegEx, conditionValue);
  3528. });
  3529. }
  3530. function booleanConditional(name, parentName) {
  3531. // first we normalize the conditional
  3532. var booleanIndex = name.lastIndexOf('#?');
  3533. if (booleanIndex == -1)
  3534. return Promise.resolve(name);
  3535. var conditionObj = parseCondition(name.substr(booleanIndex + 2));
  3536. // in builds, return normalized conditional
  3537. if (this.builder)
  3538. return this['normalize'](conditionObj.module, parentName)
  3539. .then(function(conditionModule) {
  3540. conditionObj.module = conditionModule;
  3541. return name.substr(0, booleanIndex) + '#?' + serializeCondition(conditionObj);
  3542. });
  3543. return resolveCondition.call(this, conditionObj, parentName, true)
  3544. .then(function(conditionValue) {
  3545. return conditionValue ? name.substr(0, booleanIndex) : '@empty';
  3546. });
  3547. }
  3548. hookConstructor(function(constructor) {
  3549. return function() {
  3550. constructor.call(this);
  3551. // standard environment module, starting small as backwards-compat matters!
  3552. this.set('@system-env', this.newModule({
  3553. browser: isBrowser,
  3554. node: !!this._nodeRequire
  3555. }));
  3556. };
  3557. });
  3558. // no normalizeSync
  3559. hook('normalize', function(normalize) {
  3560. return function(name, parentName, parentAddress) {
  3561. var loader = this;
  3562. return booleanConditional.call(loader, name, parentName)
  3563. .then(function(name) {
  3564. return normalize.call(loader, name, parentName, parentAddress);
  3565. })
  3566. .then(function(normalized) {
  3567. return interpolateConditional.call(loader, normalized, parentName);
  3568. });
  3569. };
  3570. });
  3571. /*
  3572. * Alias Extension
  3573. *
  3574. * Allows a module to be a plain copy of another module by module name
  3575. *
  3576. * System.meta['mybootstrapalias'] = { alias: 'bootstrap' };
  3577. *
  3578. */
  3579. (function() {
  3580. // aliases
  3581. hook('fetch', function(fetch) {
  3582. return function(load) {
  3583. var alias = load.metadata.alias;
  3584. var aliasDeps = load.metadata.deps || [];
  3585. if (alias) {
  3586. load.metadata.format = 'defined';
  3587. this.defined[load.name] = {
  3588. declarative: true,
  3589. deps: aliasDeps.concat([alias]),
  3590. declare: function(_export) {
  3591. return {
  3592. setters: [function(module) {
  3593. for (var p in module)
  3594. _export(p, module[p]);
  3595. }],
  3596. execute: function() {}
  3597. };
  3598. }
  3599. };
  3600. return '';
  3601. }
  3602. return fetch.call(this, load);
  3603. };
  3604. });
  3605. })();/*
  3606. * Meta Extension
  3607. *
  3608. * Sets default metadata on a load record (load.metadata) from
  3609. * loader.metadata via System.meta function.
  3610. *
  3611. *
  3612. * Also provides an inline meta syntax for module meta in source.
  3613. *
  3614. * Eg:
  3615. *
  3616. * loader.meta({
  3617. * 'my/module': { deps: ['jquery'] }
  3618. * 'my/*': { format: 'amd' }
  3619. * });
  3620. *
  3621. * Which in turn populates loader.metadata.
  3622. *
  3623. * load.metadata.deps and load.metadata.format will then be set
  3624. * for 'my/module'
  3625. *
  3626. * The same meta could be set with a my/module.js file containing:
  3627. *
  3628. * my/module.js
  3629. * "format amd";
  3630. * "deps[] jquery";
  3631. * "globals.some value"
  3632. * console.log('this is my/module');
  3633. *
  3634. * Configuration meta always takes preference to inline meta.
  3635. *
  3636. * Multiple matches in wildcards are supported and ammend the meta.
  3637. *
  3638. *
  3639. * The benefits of the function form is that paths are URL-normalized
  3640. * supporting say
  3641. *
  3642. * loader.meta({ './app': { format: 'cjs' } });
  3643. *
  3644. * Instead of needing to set against the absolute URL (https://site.com/app.js)
  3645. *
  3646. */
  3647. (function() {
  3648. hookConstructor(function(constructor) {
  3649. return function() {
  3650. this.meta = {};
  3651. constructor.call(this);
  3652. };
  3653. });
  3654. hook('locate', function(locate) {
  3655. return function(load) {
  3656. var meta = this.meta;
  3657. var name = load.name;
  3658. // NB for perf, maybe introduce a fast-path wildcard lookup cache here
  3659. // which is checked first
  3660. // apply wildcard metas
  3661. var bestDepth = 0;
  3662. var wildcardIndex;
  3663. for (var module in meta) {
  3664. wildcardIndex = module.indexOf('*');
  3665. if (wildcardIndex === -1)
  3666. continue;
  3667. if (module.substr(0, wildcardIndex) === name.substr(0, wildcardIndex)
  3668. && module.substr(wildcardIndex + 1) === name.substr(name.length - module.length + wildcardIndex + 1)) {
  3669. var depth = module.split('/').length;
  3670. if (depth > bestDepth)
  3671. bestDepth = depth;
  3672. extendMeta(load.metadata, meta[module], bestDepth != depth);
  3673. }
  3674. }
  3675. // apply exact meta
  3676. if (meta[name])
  3677. extendMeta(load.metadata, meta[name]);
  3678. return locate.call(this, load);
  3679. };
  3680. });
  3681. // detect any meta header syntax
  3682. // only set if not already set
  3683. var metaRegEx = /^(\s*\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)+/;
  3684. var metaPartRegEx = /\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\/\/[^\n]*|"[^"]+"\s*;?|'[^']+'\s*;?/g;
  3685. function setMetaProperty(target, p, value) {
  3686. var pParts = p.split('.');
  3687. var curPart;
  3688. while (pParts.length > 1) {
  3689. curPart = pParts.shift();
  3690. target = target[curPart] = target[curPart] || {};
  3691. }
  3692. curPart = pParts.shift();
  3693. if (!(curPart in target))
  3694. target[curPart] = value;
  3695. }
  3696. hook('translate', function(translate) {
  3697. return function(load) {
  3698. // NB meta will be post-translate pending transpiler conversion to plugins
  3699. var meta = load.source.match(metaRegEx);
  3700. if (meta) {
  3701. var metaParts = meta[0].match(metaPartRegEx);
  3702. for (var i = 0; i < metaParts.length; i++) {
  3703. var curPart = metaParts[i];
  3704. var len = curPart.length;
  3705. var firstChar = curPart.substr(0, 1);
  3706. if (curPart.substr(len - 1, 1) == ';')
  3707. len--;
  3708. if (firstChar != '"' && firstChar != "'")
  3709. continue;
  3710. var metaString = curPart.substr(1, curPart.length - 3);
  3711. var metaName = metaString.substr(0, metaString.indexOf(' '));
  3712. if (metaName) {
  3713. var metaValue = metaString.substr(metaName.length + 1, metaString.length - metaName.length - 1);
  3714. if (metaName.substr(metaName.length - 2, 2) == '[]') {
  3715. metaName = metaName.substr(0, metaName.length - 2);
  3716. load.metadata[metaName] = load.metadata[metaName] || [];
  3717. load.metadata[metaName].push(metaValue);
  3718. }
  3719. else if (load.metadata[metaName] instanceof Array) {
  3720. // temporary backwards compat for previous "deps" syntax
  3721. warn.call(this, 'Module ' + load.name + ' contains deprecated "deps ' + metaValue + '" meta syntax.\nThis should be updated to "deps[] ' + metaValue + '" for pushing to array meta.');
  3722. load.metadata[metaName].push(metaValue);
  3723. }
  3724. else {
  3725. setMetaProperty(load.metadata, metaName, metaValue);
  3726. }
  3727. }
  3728. else {
  3729. load.metadata[metaString] = true;
  3730. }
  3731. }
  3732. }
  3733. return translate.call(this, load);
  3734. };
  3735. });
  3736. })();
  3737. /*
  3738. System bundles
  3739. Allows a bundle module to be specified which will be dynamically
  3740. loaded before trying to load a given module.
  3741. For example:
  3742. System.bundles['mybundle'] = ['jquery', 'bootstrap/js/bootstrap']
  3743. Will result in a load to "mybundle" whenever a load to "jquery"
  3744. or "bootstrap/js/bootstrap" is made.
  3745. In this way, the bundle becomes the request that provides the module
  3746. */
  3747. function getBundleFor(loader, name) {
  3748. // check if it is in an already-loaded bundle
  3749. for (var b in loader.loadedBundles_)
  3750. if (indexOf.call(loader.bundles[b], name) != -1)
  3751. return Promise.resolve(b);
  3752. // check if it is a new bundle
  3753. for (var b in loader.bundles)
  3754. if (indexOf.call(loader.bundles[b], name) != -1)
  3755. return loader.normalize(b)
  3756. .then(function(normalized) {
  3757. loader.bundles[normalized] = loader.bundles[b];
  3758. loader.loadedBundles_[normalized] = true;
  3759. return normalized;
  3760. });
  3761. return Promise.resolve();
  3762. }
  3763. (function() {
  3764. // bundles support (just like RequireJS)
  3765. // bundle name is module name of bundle itself
  3766. // bundle is array of modules defined by the bundle
  3767. // when a module in the bundle is requested, the bundle is loaded instead
  3768. // of the form System.bundles['mybundle'] = ['jquery', 'bootstrap/js/bootstrap']
  3769. hookConstructor(function(constructor) {
  3770. return function() {
  3771. constructor.call(this);
  3772. this.bundles = {};
  3773. this.loadedBundles_ = {};
  3774. };
  3775. });
  3776. // assign bundle metadata for bundle loads
  3777. hook('locate', function(locate) {
  3778. return function(load) {
  3779. var loader = this;
  3780. if (load.name in loader.loadedBundles_ || load.name in loader.bundles)
  3781. load.metadata.bundle = true;
  3782. // if not already defined, check if we need to load a bundle
  3783. if (!(load.name in loader.defined))
  3784. return getBundleFor(loader, load.name)
  3785. .then(function(bundleName) {
  3786. if (bundleName)
  3787. return loader.load(bundleName);
  3788. })
  3789. .then(function() {
  3790. return locate.call(loader, load);
  3791. });
  3792. return locate.call(this, load);
  3793. };
  3794. });
  3795. })();
  3796. /*
  3797. * Dependency Tree Cache
  3798. *
  3799. * Allows a build to pre-populate a dependency trace tree on the loader of
  3800. * the expected dependency tree, to be loaded upfront when requesting the
  3801. * module, avoinding the n round trips latency of module loading, where
  3802. * n is the dependency tree depth.
  3803. *
  3804. * eg:
  3805. * System.depCache = {
  3806. * 'app': ['normalized', 'deps'],
  3807. * 'normalized': ['another'],
  3808. * 'deps': ['tree']
  3809. * };
  3810. *
  3811. * System.import('app')
  3812. * // simultaneously starts loading all of:
  3813. * // 'normalized', 'deps', 'another', 'tree'
  3814. * // before "app" source is even loaded
  3815. */
  3816. (function() {
  3817. hookConstructor(function(constructor) {
  3818. return function() {
  3819. constructor.call(this);
  3820. this.depCache = {};
  3821. }
  3822. });
  3823. hook('locate', function(locate) {
  3824. return function(load) {
  3825. var loader = this;
  3826. // load direct deps, in turn will pick up their trace trees
  3827. var deps = loader.depCache[load.name];
  3828. if (deps)
  3829. for (var i = 0; i < deps.length; i++)
  3830. loader['import'](deps[i]);
  3831. return locate.call(loader, load);
  3832. };
  3833. });
  3834. })();
  3835. System = new SystemJSLoader();
  3836. System.version = '0.19.6 Standard';
  3837. // -- exporting --
  3838. if (typeof exports === 'object')
  3839. module.exports = Loader;
  3840. __global.Reflect = __global.Reflect || {};
  3841. __global.Reflect.Loader = __global.Reflect.Loader || Loader;
  3842. __global.Reflect.global = __global.Reflect.global || __global;
  3843. __global.LoaderPolyfill = Loader;
  3844. if (!System) {
  3845. System = new SystemLoader();
  3846. System.constructor = SystemLoader;
  3847. }
  3848. if (typeof exports === 'object')
  3849. module.exports = System;
  3850. __global.System = System;
  3851. })(typeof self != 'undefined' ? self : global);}
  3852. // auto-load Promise and URL polyfills if needed in the browser
  3853. try {
  3854. var hasURL = typeof URLPolyfill != 'undefined' || new URL('test:///').protocol == 'test:';
  3855. }
  3856. catch(e) {}
  3857. if (typeof Promise === 'undefined' || !hasURL) {
  3858. // document.write
  3859. if (typeof document !== 'undefined') {
  3860. var scripts = document.getElementsByTagName('script');
  3861. $__curScript = scripts[scripts.length - 1];
  3862. var curPath = $__curScript.src;
  3863. var basePath = curPath.substr(0, curPath.lastIndexOf('/') + 1);
  3864. window.systemJSBootstrap = bootstrap;
  3865. document.write(
  3866. '<' + 'script type="text/javascript" src="' + basePath + 'system-polyfills.js">' + '<' + '/script>'
  3867. );
  3868. }
  3869. // importScripts
  3870. else if (typeof importScripts !== 'undefined') {
  3871. var basePath = '';
  3872. try {
  3873. throw new Error('_');
  3874. } catch (e) {
  3875. e.stack.replace(/(?:at|@).*(http.+):[\d]+:[\d]+/, function(m, url) {
  3876. basePath = url.replace(/\/[^\/]*$/, '/');
  3877. });
  3878. }
  3879. importScripts(basePath + 'system-polyfills.js');
  3880. bootstrap();
  3881. }
  3882. else {
  3883. bootstrap();
  3884. }
  3885. }
  3886. else {
  3887. bootstrap();
  3888. }
  3889. })();