| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605 |
- /*
- * SystemJS v0.19.6
- */
- (function() {
- function bootstrap() {(function(__global) {
- var isWorker = typeof window == 'undefined' && typeof self != 'undefined' && typeof importScripts != 'undefined';
- var isBrowser = typeof window != 'undefined' && typeof document != 'undefined';
- var isWindows = typeof process != 'undefined' && !!process.platform.match(/^win/);
- if (!__global.console)
- __global.console = { assert: function() {} };
- // IE8 support
- var indexOf = Array.prototype.indexOf || function(item) {
- for (var i = 0, thisLen = this.length; i < thisLen; i++) {
- if (this[i] === item) {
- return i;
- }
- }
- return -1;
- };
- var defineProperty;
- (function () {
- try {
- if (!!Object.defineProperty({}, 'a', {}))
- defineProperty = Object.defineProperty;
- }
- catch (e) {
- defineProperty = function(obj, prop, opt) {
- try {
- obj[prop] = opt.value || opt.get.call(obj);
- }
- catch(e) {}
- }
- }
- })();
- function addToError(err, msg) {
- var newErr;
- if (err instanceof Error) {
- var newErr = new Error(err.message, err.fileName, err.lineNumber);
- if (isBrowser) {
- newErr.message = err.message + '\n\t' + msg;
- newErr.stack = err.stack;
- }
- else {
- // node errors only look correct with the stack modified
- newErr.message = err.message;
- newErr.stack = err.stack + '\n\t' + msg;
- }
- }
- else {
- newErr = err + '\n\t' + msg;
- }
- return newErr;
- }
- function __eval(source, debugName, context) {
- try {
- new Function(source).call(context);
- }
- catch(e) {
- throw addToError(e, 'Evaluating ' + debugName);
- }
- }
- var baseURI;
- // environent baseURI detection
- if (typeof document != 'undefined' && document.getElementsByTagName) {
- baseURI = document.baseURI;
- if (!baseURI) {
- var bases = document.getElementsByTagName('base');
- baseURI = bases[0] && bases[0].href || window.location.href;
- }
- // sanitize out the hash and querystring
- baseURI = baseURI.split('#')[0].split('?')[0];
- baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1);
- }
- else if (typeof process != 'undefined' && process.cwd) {
- baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
- if (isWindows)
- baseURI = baseURI.replace(/\\/g, '/');
- }
- else if (typeof location != 'undefined') {
- baseURI = __global.location.href;
- }
- else {
- throw new TypeError('No environment baseURI');
- }
- var URL = __global.URLPolyfill || __global.URL;
- /*
- *********************************************************************************************
- Dynamic Module Loader Polyfill
- - Implemented exactly to the former 2014-08-24 ES6 Specification Draft Rev 27, Section 15
- http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#august_24_2014_draft_rev_27
- - Functions are commented with their spec numbers, with spec differences commented.
- - Spec bugs are commented in this code with links.
- - Abstract functions have been combined where possible, and their associated functions
- commented.
- - Realm implementation is entirely omitted.
- *********************************************************************************************
- */
- function Module() {}
- // http://www.ecma-international.org/ecma-262/6.0/#sec-@@tostringtag
- defineProperty(Module.prototype, 'toString', {
- value: function() {
- return 'Module';
- }
- });
- function Loader(options) {
- this._loader = {
- loaderObj: this,
- loads: [],
- modules: {},
- importPromises: {},
- moduleRecords: {}
- };
- // 26.3.3.6
- defineProperty(this, 'global', {
- get: function() {
- return __global;
- }
- });
- // 26.3.3.13 realm not implemented
- }
- (function() {
- // Some Helpers
- // logs a linkset snapshot for debugging
- /* function snapshot(loader) {
- console.log('---Snapshot---');
- for (var i = 0; i < loader.loads.length; i++) {
- var load = loader.loads[i];
- var linkSetLog = ' ' + load.name + ' (' + load.status + '): ';
- for (var j = 0; j < load.linkSets.length; j++) {
- linkSetLog += '{' + logloads(load.linkSets[j].loads) + '} ';
- }
- console.log(linkSetLog);
- }
- console.log('');
- }
- function logloads(loads) {
- var log = '';
- for (var k = 0; k < loads.length; k++)
- log += loads[k].name + (k != loads.length - 1 ? ' ' : '');
- return log;
- } */
- /* function checkInvariants() {
- // see https://bugs.ecmascript.org/show_bug.cgi?id=2603#c1
- var loads = System._loader.loads;
- var linkSets = [];
- for (var i = 0; i < loads.length; i++) {
- var load = loads[i];
- console.assert(load.status == 'loading' || load.status == 'loaded', 'Each load is loading or loaded');
- for (var j = 0; j < load.linkSets.length; j++) {
- var linkSet = load.linkSets[j];
- for (var k = 0; k < linkSet.loads.length; k++)
- console.assert(loads.indexOf(linkSet.loads[k]) != -1, 'linkSet loads are a subset of loader loads');
- if (linkSets.indexOf(linkSet) == -1)
- linkSets.push(linkSet);
- }
- }
- for (var i = 0; i < loads.length; i++) {
- var load = loads[i];
- for (var j = 0; j < linkSets.length; j++) {
- var linkSet = linkSets[j];
- if (linkSet.loads.indexOf(load) != -1)
- console.assert(load.linkSets.indexOf(linkSet) != -1, 'linkSet contains load -> load contains linkSet');
- if (load.linkSets.indexOf(linkSet) != -1)
- console.assert(linkSet.loads.indexOf(load) != -1, 'load contains linkSet -> linkSet contains load');
- }
- }
- for (var i = 0; i < linkSets.length; i++) {
- var linkSet = linkSets[i];
- for (var j = 0; j < linkSet.loads.length; j++) {
- var load = linkSet.loads[j];
- for (var k = 0; k < load.dependencies.length; k++) {
- var depName = load.dependencies[k].value;
- var depLoad;
- for (var l = 0; l < loads.length; l++) {
- if (loads[l].name != depName)
- continue;
- depLoad = loads[l];
- break;
- }
- // loading records are allowed not to have their dependencies yet
- // if (load.status != 'loading')
- // console.assert(depLoad, 'depLoad found');
- // console.assert(linkSet.loads.indexOf(depLoad) != -1, 'linkset contains all dependencies');
- }
- }
- }
- } */
- // 15.2.3 - Runtime Semantics: Loader State
- // 15.2.3.11
- function createLoaderLoad(object) {
- return {
- // modules is an object for ES5 implementation
- modules: {},
- loads: [],
- loaderObj: object
- };
- }
- // 15.2.3.2 Load Records and LoadRequest Objects
- // 15.2.3.2.1
- function createLoad(name) {
- return {
- status: 'loading',
- name: name,
- linkSets: [],
- dependencies: [],
- metadata: {}
- };
- }
- // 15.2.3.2.2 createLoadRequestObject, absorbed into calling functions
- // 15.2.4
- // 15.2.4.1
- function loadModule(loader, name, options) {
- return new Promise(asyncStartLoadPartwayThrough({
- step: options.address ? 'fetch' : 'locate',
- loader: loader,
- moduleName: name,
- // allow metadata for import https://bugs.ecmascript.org/show_bug.cgi?id=3091
- moduleMetadata: options && options.metadata || {},
- moduleSource: options.source,
- moduleAddress: options.address
- }));
- }
- // 15.2.4.2
- function requestLoad(loader, request, refererName, refererAddress) {
- // 15.2.4.2.1 CallNormalize
- return new Promise(function(resolve, reject) {
- resolve(loader.loaderObj.normalize(request, refererName, refererAddress));
- })
- // 15.2.4.2.2 GetOrCreateLoad
- .then(function(name) {
- var load;
- if (loader.modules[name]) {
- load = createLoad(name);
- load.status = 'linked';
- // https://bugs.ecmascript.org/show_bug.cgi?id=2795
- load.module = loader.modules[name];
- return load;
- }
- for (var i = 0, l = loader.loads.length; i < l; i++) {
- load = loader.loads[i];
- if (load.name != name)
- continue;
- console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded');
- return load;
- }
- load = createLoad(name);
- loader.loads.push(load);
- proceedToLocate(loader, load);
- return load;
- });
- }
- // 15.2.4.3
- function proceedToLocate(loader, load) {
- proceedToFetch(loader, load,
- Promise.resolve()
- // 15.2.4.3.1 CallLocate
- .then(function() {
- return loader.loaderObj.locate({ name: load.name, metadata: load.metadata });
- })
- );
- }
- // 15.2.4.4
- function proceedToFetch(loader, load, p) {
- proceedToTranslate(loader, load,
- p
- // 15.2.4.4.1 CallFetch
- .then(function(address) {
- // adjusted, see https://bugs.ecmascript.org/show_bug.cgi?id=2602
- if (load.status != 'loading')
- return;
- load.address = address;
- return loader.loaderObj.fetch({ name: load.name, metadata: load.metadata, address: address });
- })
- );
- }
- var anonCnt = 0;
- // 15.2.4.5
- function proceedToTranslate(loader, load, p) {
- p
- // 15.2.4.5.1 CallTranslate
- .then(function(source) {
- if (load.status != 'loading')
- return;
- return Promise.resolve(loader.loaderObj.translate({ name: load.name, metadata: load.metadata, address: load.address, source: source }))
- // 15.2.4.5.2 CallInstantiate
- .then(function(source) {
- load.source = source;
- return loader.loaderObj.instantiate({ name: load.name, metadata: load.metadata, address: load.address, source: source });
- })
- // 15.2.4.5.3 InstantiateSucceeded
- .then(function(instantiateResult) {
- if (instantiateResult === undefined) {
- load.address = load.address || '<Anonymous Module ' + ++anonCnt + '>';
- // instead of load.kind, use load.isDeclarative
- load.isDeclarative = true;
- return transpile.call(loader.loaderObj, load)
- .then(function(transpiled) {
- // Hijack System.register to set declare function
- var curSystem = __global.System;
- var curRegister = curSystem.register;
- curSystem.register = function(name, deps, declare) {
- if (typeof name != 'string') {
- declare = deps;
- deps = name;
- }
- // store the registered declaration as load.declare
- // store the deps as load.deps
- load.declare = declare;
- load.depsList = deps;
- }
- // empty {} context is closest to undefined 'this' we can get
- __eval(transpiled, load.address, {});
- curSystem.register = curRegister;
- });
- }
- else if (typeof instantiateResult == 'object') {
- load.depsList = instantiateResult.deps || [];
- load.execute = instantiateResult.execute;
- load.isDeclarative = false;
- }
- else
- throw TypeError('Invalid instantiate return value');
- })
- // 15.2.4.6 ProcessLoadDependencies
- .then(function() {
- load.dependencies = [];
- var depsList = load.depsList;
- var loadPromises = [];
- for (var i = 0, l = depsList.length; i < l; i++) (function(request, index) {
- loadPromises.push(
- requestLoad(loader, request, load.name, load.address)
- // 15.2.4.6.1 AddDependencyLoad (load is parentLoad)
- .then(function(depLoad) {
- // adjusted from spec to maintain dependency order
- // this is due to the System.register internal implementation needs
- load.dependencies[index] = {
- key: request,
- value: depLoad.name
- };
- if (depLoad.status != 'linked') {
- var linkSets = load.linkSets.concat([]);
- for (var i = 0, l = linkSets.length; i < l; i++)
- addLoadToLinkSet(linkSets[i], depLoad);
- }
- // console.log('AddDependencyLoad ' + depLoad.name + ' for ' + load.name);
- // snapshot(loader);
- })
- );
- })(depsList[i], i);
- return Promise.all(loadPromises);
- })
- // 15.2.4.6.2 LoadSucceeded
- .then(function() {
- // console.log('LoadSucceeded ' + load.name);
- // snapshot(loader);
- console.assert(load.status == 'loading', 'is loading');
- load.status = 'loaded';
- var linkSets = load.linkSets.concat([]);
- for (var i = 0, l = linkSets.length; i < l; i++)
- updateLinkSetOnLoad(linkSets[i], load);
- });
- })
- // 15.2.4.5.4 LoadFailed
- ['catch'](function(exc) {
- load.status = 'failed';
- load.exception = exc;
- var linkSets = load.linkSets.concat([]);
- for (var i = 0, l = linkSets.length; i < l; i++) {
- linkSetFailed(linkSets[i], load, exc);
- }
- console.assert(load.linkSets.length == 0, 'linkSets not removed');
- });
- }
- // 15.2.4.7 PromiseOfStartLoadPartwayThrough absorbed into calling functions
- // 15.2.4.7.1
- function asyncStartLoadPartwayThrough(stepState) {
- return function(resolve, reject) {
- var loader = stepState.loader;
- var name = stepState.moduleName;
- var step = stepState.step;
- if (loader.modules[name])
- throw new TypeError('"' + name + '" already exists in the module table');
- // adjusted to pick up existing loads
- var existingLoad;
- for (var i = 0, l = loader.loads.length; i < l; i++) {
- if (loader.loads[i].name == name) {
- existingLoad = loader.loads[i];
- if(step == 'translate' && !existingLoad.source) {
- existingLoad.address = stepState.moduleAddress;
- proceedToTranslate(loader, existingLoad, Promise.resolve(stepState.moduleSource));
- }
- // a primary load -> use that existing linkset
- if (existingLoad.linkSets.length)
- return existingLoad.linkSets[0].done.then(function() {
- resolve(existingLoad);
- });
- }
- }
- var load = existingLoad || createLoad(name);
- load.metadata = stepState.moduleMetadata;
- var linkSet = createLinkSet(loader, load);
- loader.loads.push(load);
- resolve(linkSet.done);
- if (step == 'locate')
- proceedToLocate(loader, load);
- else if (step == 'fetch')
- proceedToFetch(loader, load, Promise.resolve(stepState.moduleAddress));
- else {
- console.assert(step == 'translate', 'translate step');
- load.address = stepState.moduleAddress;
- proceedToTranslate(loader, load, Promise.resolve(stepState.moduleSource));
- }
- }
- }
- // Declarative linking functions run through alternative implementation:
- // 15.2.5.1.1 CreateModuleLinkageRecord not implemented
- // 15.2.5.1.2 LookupExport not implemented
- // 15.2.5.1.3 LookupModuleDependency not implemented
- // 15.2.5.2.1
- function createLinkSet(loader, startingLoad) {
- var linkSet = {
- loader: loader,
- loads: [],
- startingLoad: startingLoad, // added see spec bug https://bugs.ecmascript.org/show_bug.cgi?id=2995
- loadingCount: 0
- };
- linkSet.done = new Promise(function(resolve, reject) {
- linkSet.resolve = resolve;
- linkSet.reject = reject;
- });
- addLoadToLinkSet(linkSet, startingLoad);
- return linkSet;
- }
- // 15.2.5.2.2
- function addLoadToLinkSet(linkSet, load) {
- if (load.status == 'failed')
- return;
- console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded on link set');
- for (var i = 0, l = linkSet.loads.length; i < l; i++)
- if (linkSet.loads[i] == load)
- return;
- linkSet.loads.push(load);
- load.linkSets.push(linkSet);
- // adjustment, see https://bugs.ecmascript.org/show_bug.cgi?id=2603
- if (load.status != 'loaded') {
- linkSet.loadingCount++;
- }
- var loader = linkSet.loader;
- for (var i = 0, l = load.dependencies.length; i < l; i++) {
- if (!load.dependencies[i])
- continue;
- var name = load.dependencies[i].value;
- if (loader.modules[name])
- continue;
- for (var j = 0, d = loader.loads.length; j < d; j++) {
- if (loader.loads[j].name != name)
- continue;
- addLoadToLinkSet(linkSet, loader.loads[j]);
- break;
- }
- }
- // console.log('add to linkset ' + load.name);
- // snapshot(linkSet.loader);
- }
- // linking errors can be generic or load-specific
- // this is necessary for debugging info
- function doLink(linkSet) {
- var error = false;
- try {
- link(linkSet, function(load, exc) {
- linkSetFailed(linkSet, load, exc);
- error = true;
- });
- }
- catch(e) {
- linkSetFailed(linkSet, null, e);
- error = true;
- }
- return error;
- }
- // 15.2.5.2.3
- function updateLinkSetOnLoad(linkSet, load) {
- // console.log('update linkset on load ' + load.name);
- // snapshot(linkSet.loader);
- console.assert(load.status == 'loaded' || load.status == 'linked', 'loaded or linked');
- linkSet.loadingCount--;
- if (linkSet.loadingCount > 0)
- return;
- // adjusted for spec bug https://bugs.ecmascript.org/show_bug.cgi?id=2995
- var startingLoad = linkSet.startingLoad;
- // non-executing link variation for loader tracing
- // on the server. Not in spec.
- /***/
- if (linkSet.loader.loaderObj.execute === false) {
- var loads = [].concat(linkSet.loads);
- for (var i = 0, l = loads.length; i < l; i++) {
- var load = loads[i];
- load.module = !load.isDeclarative ? {
- module: _newModule({})
- } : {
- name: load.name,
- module: _newModule({}),
- evaluated: true
- };
- load.status = 'linked';
- finishLoad(linkSet.loader, load);
- }
- return linkSet.resolve(startingLoad);
- }
- /***/
- var abrupt = doLink(linkSet);
- if (abrupt)
- return;
- console.assert(linkSet.loads.length == 0, 'loads cleared');
- linkSet.resolve(startingLoad);
- }
- // 15.2.5.2.4
- function linkSetFailed(linkSet, load, exc) {
- var loader = linkSet.loader;
- var requests;
- checkError:
- if (load) {
- if (linkSet.loads[0].name == load.name) {
- exc = addToError(exc, 'Error loading ' + load.name);
- }
- else {
- for (var i = 0; i < linkSet.loads.length; i++) {
- var pLoad = linkSet.loads[i];
- for (var j = 0; j < pLoad.dependencies.length; j++) {
- var dep = pLoad.dependencies[j];
- if (dep.value == load.name) {
- exc = addToError(exc, 'Error loading ' + load.name + ' as "' + dep.key + '" from ' + pLoad.name);
- break checkError;
- }
- }
- }
- exc = addToError(exc, 'Error loading ' + load.name + ' from ' + linkSet.loads[0].name);
- }
- }
- else {
- exc = addToError(exc, 'Error linking ' + linkSet.loads[0].name);
- }
- var loads = linkSet.loads.concat([]);
- for (var i = 0, l = loads.length; i < l; i++) {
- var load = loads[i];
- // store all failed load records
- loader.loaderObj.failed = loader.loaderObj.failed || [];
- if (indexOf.call(loader.loaderObj.failed, load) == -1)
- loader.loaderObj.failed.push(load);
- var linkIndex = indexOf.call(load.linkSets, linkSet);
- console.assert(linkIndex != -1, 'link not present');
- load.linkSets.splice(linkIndex, 1);
- if (load.linkSets.length == 0) {
- var globalLoadsIndex = indexOf.call(linkSet.loader.loads, load);
- if (globalLoadsIndex != -1)
- linkSet.loader.loads.splice(globalLoadsIndex, 1);
- }
- }
- linkSet.reject(exc);
- }
- // 15.2.5.2.5
- function finishLoad(loader, load) {
- // add to global trace if tracing
- if (loader.loaderObj.trace) {
- if (!loader.loaderObj.loads)
- loader.loaderObj.loads = {};
- var depMap = {};
- load.dependencies.forEach(function(dep) {
- depMap[dep.key] = dep.value;
- });
- loader.loaderObj.loads[load.name] = {
- name: load.name,
- deps: load.dependencies.map(function(dep){ return dep.key }),
- depMap: depMap,
- address: load.address,
- metadata: load.metadata,
- source: load.source,
- kind: load.isDeclarative ? 'declarative' : 'dynamic'
- };
- }
- // if not anonymous, add to the module table
- if (load.name) {
- console.assert(!loader.modules[load.name], 'load not in module table');
- loader.modules[load.name] = load.module;
- }
- var loadIndex = indexOf.call(loader.loads, load);
- if (loadIndex != -1)
- loader.loads.splice(loadIndex, 1);
- for (var i = 0, l = load.linkSets.length; i < l; i++) {
- loadIndex = indexOf.call(load.linkSets[i].loads, load);
- if (loadIndex != -1)
- load.linkSets[i].loads.splice(loadIndex, 1);
- }
- load.linkSets.splice(0, load.linkSets.length);
- }
- function doDynamicExecute(linkSet, load, linkError) {
- try {
- var module = load.execute();
- }
- catch(e) {
- linkError(load, e);
- return;
- }
- if (!module || !(module instanceof Module))
- linkError(load, new TypeError('Execution must define a Module instance'));
- else
- return module;
- }
- // 26.3 Loader
- // 26.3.1.1
- // defined at top
- // importPromises adds ability to import a module twice without error - https://bugs.ecmascript.org/show_bug.cgi?id=2601
- function createImportPromise(loader, name, promise) {
- var importPromises = loader._loader.importPromises;
- return importPromises[name] = promise.then(function(m) {
- importPromises[name] = undefined;
- return m;
- }, function(e) {
- importPromises[name] = undefined;
- throw e;
- });
- }
- Loader.prototype = {
- // 26.3.3.1
- constructor: Loader,
- // 26.3.3.2
- define: function(name, source, options) {
- // check if already defined
- if (this._loader.importPromises[name])
- throw new TypeError('Module is already loading.');
- return createImportPromise(this, name, new Promise(asyncStartLoadPartwayThrough({
- step: 'translate',
- loader: this._loader,
- moduleName: name,
- moduleMetadata: options && options.metadata || {},
- moduleSource: source,
- moduleAddress: options && options.address
- })));
- },
- // 26.3.3.3
- 'delete': function(name) {
- var loader = this._loader;
- delete loader.importPromises[name];
- delete loader.moduleRecords[name];
- return loader.modules[name] ? delete loader.modules[name] : false;
- },
- // 26.3.3.4 entries not implemented
- // 26.3.3.5
- get: function(key) {
- if (!this._loader.modules[key])
- return;
- doEnsureEvaluated(this._loader.modules[key], [], this);
- return this._loader.modules[key].module;
- },
- // 26.3.3.7
- has: function(name) {
- return !!this._loader.modules[name];
- },
- // 26.3.3.8
- 'import': function(name, parentName, parentAddress) {
- if (typeof parentName == 'object')
- parentName = parentName.name;
- // run normalize first
- var loaderObj = this;
- // added, see https://bugs.ecmascript.org/show_bug.cgi?id=2659
- return Promise.resolve(loaderObj.normalize(name, parentName))
- .then(function(name) {
- var loader = loaderObj._loader;
- if (loader.modules[name]) {
- doEnsureEvaluated(loader.modules[name], [], loader._loader);
- return loader.modules[name].module;
- }
- return loader.importPromises[name] || createImportPromise(loaderObj, name,
- loadModule(loader, name, {})
- .then(function(load) {
- delete loader.importPromises[name];
- return evaluateLoadedModule(loader, load);
- }));
- });
- },
- // 26.3.3.9 keys not implemented
- // 26.3.3.10
- load: function(name, options) {
- var loader = this._loader;
- if (loader.modules[name]) {
- doEnsureEvaluated(loader.modules[name], [], loader);
- return Promise.resolve(loader.modules[name].module);
- }
- return loader.importPromises[name] || createImportPromise(this, name,
- loadModule(loader, name, {})
- .then(function(load) {
- delete loader.importPromises[name];
- return evaluateLoadedModule(loader, load);
- }));
- },
- // 26.3.3.11
- module: function(source, options) {
- var load = createLoad();
- load.address = options && options.address;
- var linkSet = createLinkSet(this._loader, load);
- var sourcePromise = Promise.resolve(source);
- var loader = this._loader;
- var p = linkSet.done.then(function() {
- return evaluateLoadedModule(loader, load);
- });
- proceedToTranslate(loader, load, sourcePromise);
- return p;
- },
- // 26.3.3.12
- newModule: function (obj) {
- if (typeof obj != 'object')
- throw new TypeError('Expected object');
- var m = new Module();
- var pNames = [];
- if (Object.getOwnPropertyNames && obj != null)
- pNames = Object.getOwnPropertyNames(obj);
- else
- for (var key in obj)
- pNames.push(key);
- for (var i = 0; i < pNames.length; i++) (function(key) {
- defineProperty(m, key, {
- configurable: false,
- enumerable: true,
- get: function () {
- return obj[key];
- }
- });
- })(pNames[i]);
- return m;
- },
- // 26.3.3.14
- set: function(name, module) {
- if (!(module instanceof Module))
- throw new TypeError('Loader.set(' + name + ', module) must be a module');
- this._loader.modules[name] = {
- module: module
- };
- },
- // 26.3.3.15 values not implemented
- // 26.3.3.16 @@iterator not implemented
- // 26.3.3.17 @@toStringTag not implemented
- // 26.3.3.18.1
- normalize: function(name, referrerName, referrerAddress) {
- return name;
- },
- // 26.3.3.18.2
- locate: function(load) {
- return load.name;
- },
- // 26.3.3.18.3
- fetch: function(load) {
- },
- // 26.3.3.18.4
- translate: function(load) {
- return load.source;
- },
- // 26.3.3.18.5
- instantiate: function(load) {
- }
- };
- var _newModule = Loader.prototype.newModule;
- /*
- * ES6 Module Declarative Linking Code - Dev Build Only
- */
- function link(linkSet, linkError) {
- var loader = linkSet.loader;
- if (!linkSet.loads.length)
- return;
- var loads = linkSet.loads.concat([]);
- for (var i = 0; i < loads.length; i++) {
- var load = loads[i];
- var module = doDynamicExecute(linkSet, load, linkError);
- if (!module)
- return;
- load.module = {
- name: load.name,
- module: module
- };
- load.status = 'linked';
- finishLoad(loader, load);
- }
- }
- function evaluateLoadedModule(loader, load) {
- console.assert(load.status == 'linked', 'is linked ' + load.name);
- return load.module.module;
- }
- function doEnsureEvaluated() {}
- function transpile() {
- throw new TypeError('ES6 transpilation is only provided in the dev module loader build.');
- }
- })();/*
- *********************************************************************************************
- System Loader Implementation
- - Implemented to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js
- - <script type="module"> supported
- *********************************************************************************************
- */
- var System;
- function SystemLoader() {
- Loader.call(this);
- this.paths = {};
- }
- // NB no specification provided for System.paths, used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
- function applyPaths(paths, name) {
- // most specific (most number of slashes in path) match wins
- var pathMatch = '', wildcard, maxWildcardPrefixLen = 0;
- // check to see if we have a paths entry
- for (var p in paths) {
- var pathParts = p.split('*');
- if (pathParts.length > 2)
- throw new TypeError('Only one wildcard in a path is permitted');
- // exact path match
- if (pathParts.length == 1) {
- if (name == p) {
- pathMatch = p;
- break;
- }
- }
- // wildcard path match
- else {
- var wildcardPrefixLen = pathParts[0].length;
- if (wildcardPrefixLen >= maxWildcardPrefixLen &&
- name.substr(0, pathParts[0].length) == pathParts[0] &&
- name.substr(name.length - pathParts[1].length) == pathParts[1]) {
- maxWildcardPrefixLen = wildcardPrefixLen;
- pathMatch = p;
- wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length);
- }
- }
- }
- var outPath = paths[pathMatch] || name;
- if (typeof wildcard == 'string')
- outPath = outPath.replace('*', wildcard);
- return outPath;
- }
- // inline Object.create-style class extension
- function LoaderProto() {}
- LoaderProto.prototype = Loader.prototype;
- SystemLoader.prototype = new LoaderProto();
- var fetchTextFromURL;
- if (typeof XMLHttpRequest != 'undefined') {
- fetchTextFromURL = function(url, authorization, fulfill, reject) {
- var xhr = new XMLHttpRequest();
- var sameDomain = true;
- var doTimeout = false;
- if (!('withCredentials' in xhr)) {
- // check if same domain
- var domainCheck = /^(\w+:)?\/\/([^\/]+)/.exec(url);
- if (domainCheck) {
- sameDomain = domainCheck[2] === window.location.host;
- if (domainCheck[1])
- sameDomain &= domainCheck[1] === window.location.protocol;
- }
- }
- if (!sameDomain && typeof XDomainRequest != 'undefined') {
- xhr = new XDomainRequest();
- xhr.onload = load;
- xhr.onerror = error;
- xhr.ontimeout = error;
- xhr.onprogress = function() {};
- xhr.timeout = 0;
- doTimeout = true;
- }
- function load() {
- fulfill(xhr.responseText);
- }
- function error() {
- reject(new Error('XHR error' + (xhr.status ? ' (' + xhr.status + (xhr.statusText ? ' ' + xhr.statusText : '') + ')' : '') + ' loading ' + url));
- }
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4) {
- if (xhr.status === 200 || (xhr.status == 0 && xhr.responseText)) {
- load();
- } else {
- error();
- }
- }
- };
- xhr.open("GET", url, true);
- if (xhr.setRequestHeader) {
- xhr.setRequestHeader('Accept', 'application/x-es-module, */*');
- // can set "authorization: true" to enable withCredentials only
- if (authorization) {
- if (typeof authorization == 'string')
- xhr.setRequestHeader('Authorization', authorization);
- xhr.withCredentials = true;
- }
- }
- if (doTimeout) {
- setTimeout(function() {
- xhr.send();
- }, 0);
- } else {
- xhr.send(null);
- }
- };
- }
- else if (typeof require != 'undefined') {
- var fs;
- fetchTextFromURL = function(url, authorization, fulfill, reject) {
- if (url.substr(0, 8) != 'file:///')
- throw new Error('Unable to fetch "' + url + '". Only file URLs of the form file:/// allowed running in Node.');
- fs = fs || require('fs');
- if (isWindows)
- url = url.replace(/\//g, '\\').substr(8);
- else
- url = url.substr(7);
- return fs.readFile(url, function(err, data) {
- if (err) {
- return reject(err);
- }
- else {
- // Strip Byte Order Mark out if it's the leading char
- var dataString = data + '';
- if (dataString[0] === '\ufeff')
- dataString = dataString.substr(1);
- fulfill(dataString);
- }
- });
- };
- }
- else {
- throw new TypeError('No environment fetch API available.');
- }
- SystemLoader.prototype.fetch = function(load) {
- return new Promise(function(resolve, reject) {
- fetchTextFromURL(load.address, undefined, resolve, reject);
- });
- };
- /*
- * Traceur, Babel and TypeScript transpile hook for Loader
- */
- var transpile = (function() {
- // use Traceur by default
- Loader.prototype.transpiler = 'traceur';
- function transpile(load) {
- var self = this;
- return Promise.resolve(__global[self.transpiler == 'typescript' ? 'ts' : self.transpiler]
- || (self.pluginLoader || self)['import'](self.transpiler))
- .then(function(transpiler) {
- if (transpiler.__useDefault)
- transpiler = transpiler['default'];
- var transpileFunction;
- if (transpiler.Compiler)
- transpileFunction = traceurTranspile;
- else if (transpiler.createLanguageService)
- transpileFunction = typescriptTranspile;
- else
- transpileFunction = babelTranspile;
- // note __moduleName will be part of the transformer meta in future when we have the spec for this
- return '(function(__moduleName){' + transpileFunction.call(self, load, transpiler) + '\n})("' + load.name + '");\n//# sourceURL=' + load.address + '!transpiled';
- });
- };
- function traceurTranspile(load, traceur) {
- var options = this.traceurOptions || {};
- options.modules = 'instantiate';
- options.script = false;
- if (options.sourceMaps === undefined)
- options.sourceMaps = 'inline';
- options.filename = load.address;
- options.inputSourceMap = load.metadata.sourceMap;
- options.moduleName = false;
- var compiler = new traceur.Compiler(options);
- return doTraceurCompile(load.source, compiler, options.filename);
- }
- function doTraceurCompile(source, compiler, filename) {
- try {
- return compiler.compile(source, filename);
- }
- catch(e) {
- // traceur throws an error array
- throw e[0];
- }
- }
- function babelTranspile(load, babel) {
- var options = this.babelOptions || {};
- options.modules = 'system';
- if (options.sourceMap === undefined)
- options.sourceMap = 'inline';
- options.inputSourceMap = load.metadata.sourceMap;
- options.filename = load.address;
- options.code = true;
- options.ast = false;
- return babel.transform(load.source, options).code;
- }
- function typescriptTranspile(load, ts) {
- var options = this.typescriptOptions || {};
- options.target = options.target || ts.ScriptTarget.ES5;
- if (options.sourceMap === undefined)
- options.sourceMap = true;
- if (options.sourceMap)
- options.inlineSourceMap = true;
- options.module = ts.ModuleKind.System;
- return ts.transpile(load.source, options, load.address);
- }
- return transpile;
- })();
- // SystemJS Loader Class and Extension helpers
- function SystemJSLoader() {
- SystemLoader.call(this);
- systemJSConstructor.call(this);
- }
- // inline Object.create-style class extension
- function SystemProto() {};
- SystemProto.prototype = SystemLoader.prototype;
- SystemJSLoader.prototype = new SystemProto();
- SystemJSLoader.prototype.constructor = SystemJSLoader;
- var systemJSConstructor;
- function hook(name, hook) {
- SystemJSLoader.prototype[name] = hook(SystemJSLoader.prototype[name] || function() {});
- }
- function hookConstructor(hook) {
- systemJSConstructor = hook(systemJSConstructor || function() {});
- }
- function dedupe(deps) {
- var newDeps = [];
- for (var i = 0, l = deps.length; i < l; i++)
- if (indexOf.call(newDeps, deps[i]) == -1)
- newDeps.push(deps[i])
- return newDeps;
- }
- function group(deps) {
- var names = [];
- var indices = [];
- for (var i = 0, l = deps.length; i < l; i++) {
- var index = indexOf.call(names, deps[i]);
- if (index === -1) {
- names.push(deps[i]);
- indices.push([i]);
- }
- else {
- indices[index].push(i);
- }
- }
- return { names: names, indices: indices };
- }
- var getOwnPropertyDescriptor = true;
- try {
- Object.getOwnPropertyDescriptor({ a: 0 }, 'a');
- }
- catch(e) {
- getOwnPropertyDescriptor = false;
- }
- // converts any module.exports object into an object ready for System.newModule
- function getESModule(exports) {
- var esModule = {};
- // don't trigger getters/setters in environments that support them
- if (typeof exports == 'object' || typeof exports == 'function') {
- if (getOwnPropertyDescriptor) {
- var d;
- for (var p in exports)
- if (d = Object.getOwnPropertyDescriptor(exports, p))
- defineProperty(esModule, p, d);
- }
- else {
- var hasOwnProperty = exports && exports.hasOwnProperty;
- for (var p in exports) {
- if (!hasOwnProperty || exports.hasOwnProperty(p))
- esModule[p] = exports[p];
- }
- }
- }
- esModule['default'] = exports;
- defineProperty(esModule, '__useDefault', {
- value: true
- });
- return esModule;
- }
- function extend(a, b, prepend) {
- for (var p in b) {
- if (!prepend || !(p in a))
- a[p] = b[p];
- }
- return a;
- }
- // package configuration options
- var packageProperties = ['main', 'format', 'defaultExtension', 'modules', 'map', 'basePath', 'depCache'];
- // meta first-level extends where:
- // array + array appends
- // object + object extends
- // other properties replace
- function extendMeta(a, b, prepend) {
- for (var p in b) {
- var val = b[p];
- if (!(p in a))
- a[p] = val;
- else if (val instanceof Array && a[p] instanceof Array)
- a[p] = [].concat(prepend ? val : a[p]).concat(prepend ? a[p] : val);
- else if (typeof val == 'object' && typeof a[p] == 'object')
- a[p] = extend(extend({}, a[p]), val, prepend);
- else if (!prepend)
- a[p] = val;
- }
- }
- function warn(msg) {
- if (this.warnings && typeof console != 'undefined' && console.warn)
- console.warn(msg);
- }// we define a __exec for globally-scoped execution
- // used by module format implementations
- var __exec;
- (function() {
- // System clobbering protection (mostly for Traceur)
- var curSystem;
- var callCounter = 0;
- var curLoad;
- function preExec(loader, load) {
- if (callCounter++ == 0)
- curSystem = __global.System;
- __global.System = loader;
- curLoad = load;
- }
- function postExec() {
- if (--callCounter == 0)
- __global.System = curSystem;
- curLoad = undefined;
- }
- // System.register, System.registerDynamic, AMD define pipeline
- // if currently evalling code here, immediately reduce the registered entry against the load record
- hook('pushRegister_', function() {
- return function(register) {
- if (!curLoad)
- return false;
- this.reduceRegister_(curLoad, register);
- return true;
- };
- });
- var hasBtoa = typeof btoa != 'undefined';
- function getSource(load) {
- var lastLineIndex = load.source.lastIndexOf('\n');
- // wrap ES formats with a System closure for System global encapsulation
- var wrap = load.metadata.format == 'esm' || load.metadata.format == 'register' || load.metadata.bundle;
- return (wrap ? '(function(System) {' : '') + load.source + (wrap ? '\n})(System);' : '')
- // adds the sourceURL comment if not already present
- + (load.source.substr(lastLineIndex, 15) != '\n//# sourceURL='
- ? '\n//# sourceURL=' + load.address + (load.metadata.sourceMap ? '!transpiled' : '') : '')
- // add sourceMappingURL if load.metadata.sourceMap is set
- + (load.metadata.sourceMap && hasBtoa &&
- '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(load.metadata.sourceMap))) || '')
- }
- function evalExec(load) {
- if (load.metadata.integrity)
- throw new TypeError('Subresource integrity checking is not supported in Web Workers or Chrome Extensions.');
- try {
- preExec(this, load);
- new Function(getSource(load)).call(__global);
- postExec();
- }
- catch(e) {
- postExec();
- throw addToError(e, 'Evaluating ' + load.address);
- }
- }
- // use script injection eval to get identical global script behaviour
- if (typeof document != 'undefined' && document.getElementsByTagName) {
- var head;
- var scripts = document.getElementsByTagName('script');
- $__curScript = scripts[scripts.length - 1];
- __exec = function(load) {
- if (!this.globalEvaluationScope)
- return evalExec.call(this, load);
- if (!head)
- head = document.head || document.body || document.documentElement;
- var script = document.createElement('script');
- script.text = getSource(load);
- var onerror = window.onerror;
- var e;
- window.onerror = function(_e) {
- e = addToError(_e, 'Evaluating ' + load.address);
- }
- preExec(this, load);
- if (load.metadata.integrity)
- script.setAttribute('integrity', load.metadata.integrity);
- if (load.metadata.nonce)
- script.setAttribute('nonce', load.metadata.nonce);
- head.appendChild(script);
- head.removeChild(script);
- postExec();
- window.onerror = onerror;
- if (e)
- throw e;
- };
- }
- // global scoped eval for node
- else if (typeof require != 'undefined') {
- var vmModule = 'vm';
- var vm = require(vmModule);
- __exec = function vmExec(load) {
- if (!this.globalEvaluationScope)
- return evalExec.call(this, load);
- if (load.metadata.integrity)
- throw new TypeError('Subresource integrity checking is unavailable in Node.');
- try {
- preExec(this, load);
- vm.runInThisContext(getSource(load));
- postExec();
- }
- catch(e) {
- postExec();
- throw addToError(e.toString(), 'Evaluating ' + load.address);
- }
- };
- }
- else {
- __exec = evalExec;
- }
- })();/*
- SystemJS map support
- Provides map configuration through
- System.map['jquery'] = 'some/module/map'
- Note that this applies for subpaths, just like RequireJS:
- jquery -> 'some/module/map'
- jquery/path -> 'some/module/map/path'
- bootstrap -> 'bootstrap'
- The most specific map is always taken, as longest path length
- */
- hookConstructor(function(constructor) {
- return function() {
- constructor.call(this);
- this.map = {};
- };
- });
- hook('normalize', function() {
- return function(name, parentName) {
- if (name.substr(0, 1) != '.' && name.substr(0, 1) != '/' && !name.match(absURLRegEx)) {
- var bestMatch, bestMatchLength = 0;
- // now do the global map
- for (var p in this.map) {
- if (name.substr(0, p.length) == p && (name.length == p.length || name[p.length] == '/')) {
- var curMatchLength = p.split('/').length;
- if (curMatchLength <= bestMatchLength)
- continue;
- bestMatch = p;
- bestMatchLength = curMatchLength;
- }
- }
- if (bestMatch)
- name = this.map[bestMatch] + name.substr(bestMatch.length);
- }
- // map is the first normalizer
- return name;
- };
- });
- var absURLRegEx = /^[^\/]+:\/\//;
- function readMemberExpression(p, value) {
- var pParts = p.split('.');
- while (pParts.length)
- value = value[pParts.shift()];
- return value;
- }
- var baseURLCache = {};
- function getBaseURLObj() {
- if (baseURLCache[this.baseURL])
- return baseURLCache[this.baseURL];
- // normalize baseURL if not already
- if (this.baseURL[this.baseURL.length - 1] != '/')
- this.baseURL += '/';
- var baseURL = new URL(this.baseURL, baseURI);
- this.baseURL = baseURL.href;
- return (baseURLCache[this.baseURL] = baseURL);
- }
- var baseURIObj = new URL(baseURI);
- hookConstructor(function(constructor) {
- return function() {
- constructor.call(this);
- // support baseURL
- this.baseURL = baseURI.substr(0, baseURI.lastIndexOf('/') + 1);
- // global behaviour flags
- this.warnings = false;
- this.defaultJSExtensions = false;
- this.globalEvaluationScope = true;
- this.pluginFirst = false;
- // Default settings for globalEvaluationScope:
- // Disabled for WebWorker, Chrome Extensions and jsdom
- if (isWorker
- || isBrowser && window.chrome && window.chrome.extension
- || isBrowser && navigator.userAgent.match(/^Node\.js/))
- this.globalEvaluationScope = false;
- // support the empty module, as a concept
- this.set('@empty', this.newModule({}));
- };
- });
- /*
- Normalization
- If a name is relative, we apply URL normalization to the page
- If a name is an absolute URL, we leave it as-is
- Plain names (neither of the above) run through the map and package
- normalization phases (applying before and after this one).
- The paths normalization phase applies last (paths extension), which
- defines the `normalizeSync` function and normalizes everything into
- a URL.
- The final normalization
- */
- hook('normalize', function(normalize) {
- return function(name, parentName) {
- // first run map config
- name = normalize.apply(this, arguments);
- // relative URL-normalization
- if (name[0] == '.' || name[0] == '/') {
- if (parentName)
- return new URL(name, parentName.replace(/#/g, '%05')).href.replace(/%05/g, '#');
- else
- return new URL(name, baseURIObj).href;
- }
- return name;
- };
- });
- // percent encode just '#' in urls if using HTTP requests
- var httpRequest = typeof XMLHttpRequest != 'undefined';
- hook('locate', function(locate) {
- return function(load) {
- return Promise.resolve(locate.call(this, load))
- .then(function(address) {
- if (httpRequest)
- return address.replace(/#/g, '%23');
- return address;
- });
- };
- });
- /*
- * Fetch with authorization
- */
- hook('fetch', function() {
- return function(load) {
- return new Promise(function(resolve, reject) {
- fetchTextFromURL(load.address, load.metadata.authorization, resolve, reject);
- });
- };
- });
- /*
- __useDefault
- When a module object looks like:
- newModule(
- __useDefault: true,
- default: 'some-module'
- })
- Then importing that module provides the 'some-module'
- result directly instead of the full module.
- Useful for eg module.exports = function() {}
- */
- hook('import', function(systemImport) {
- return function(name, parentName, parentAddress) {
- if (parentName && parentName.name)
- warn.call(this, 'System.import(name, { name: parentName }) is deprecated for System.import(name, parentName), while importing ' + name + ' from ' + parentName.name);
- return systemImport.call(this, name, parentName, parentAddress).then(function(module) {
- return module.__useDefault ? module['default'] : module;
- });
- };
- });
- /*
- Extend config merging one deep only
- loader.config({
- some: 'random',
- config: 'here',
- deep: {
- config: { too: 'too' }
- }
- });
- <=>
- loader.some = 'random';
- loader.config = 'here'
- loader.deep = loader.deep || {};
- loader.deep.config = { too: 'too' };
- Normalizes meta and package configs allowing for:
- System.config({
- meta: {
- './index.js': {}
- }
- });
- To become
- System.meta['https://thissite.com/index.js'] = {};
- For easy normalization canonicalization with latest URL support.
- */
- SystemJSLoader.prototype.config = function(cfg) {
- if ('warnings' in cfg)
- this.warnings = cfg.warnings;
- // always configure baseURL first
- if (cfg.baseURL) {
- var hasConfig = false;
- function checkHasConfig(obj) {
- for (var p in obj)
- return true;
- }
- if (checkHasConfig(this.packages) || checkHasConfig(this.meta) || checkHasConfig(this.depCache) || checkHasConfig(this.bundles) || checkHasConfig(this.packageConfigPaths))
- throw new TypeError('baseURL should only be configured once and must be configured first.');
- this.baseURL = cfg.baseURL;
- // sanitize baseURL
- getBaseURLObj.call(this);
- }
- if (cfg.defaultJSExtensions) {
- this.defaultJSExtensions = cfg.defaultJSExtensions;
- warn.call(this, 'The defaultJSExtensions configuration option is deprecated, use packages configuration instead.');
- }
- if (cfg.pluginFirst)
- this.pluginFirst = cfg.pluginFirst;
- if (cfg.paths) {
- for (var p in cfg.paths)
- this.paths[p] = cfg.paths[p];
- }
- if (cfg.map) {
- var objMaps = '';
- for (var p in cfg.map) {
- var v = cfg.map[p];
- // object map backwards-compat into packages configuration
- if (typeof v !== 'string') {
- objMaps += (objMaps.length ? ', ' : '') + '"' + p + '"';
- var normalized = this.normalizeSync(p);
- // if doing default js extensions, undo to get package name
- if (this.defaultJSExtensions && p.substr(p.length - 3, 3) != '.js')
- normalized = normalized.substr(0, normalized.length - 3);
- // if a package main, revert it
- var pkgMatch = '';
- for (var pkg in this.packages) {
- if (normalized.substr(0, pkg.length) == pkg
- && (!normalized[pkg.length] || normalized[pkg.length] == '/')
- && pkgMatch.split('/').length < pkg.split('/').length)
- pkgMatch = pkg;
- }
- if (pkgMatch && this.packages[pkgMatch].main)
- normalized = normalized.substr(0, normalized.length - this.packages[pkgMatch].main.length - 1);
- var pkg = this.packages[normalized] = this.packages[normalized] || {};
- pkg.map = v;
- }
- else {
- this.map[p] = v;
- }
- }
- if (objMaps)
- 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: {...} } } }).');
- }
- if (cfg.packageConfigPaths) {
- var packageConfigPaths = [];
- for (var i = 0; i < cfg.packageConfigPaths.length; i++) {
- var path = cfg.packageConfigPaths[i];
- var packageLength = Math.max(path.lastIndexOf('*') + 1, path.lastIndexOf('/'));
- var normalized = this.normalizeSync(path.substr(0, packageLength) + '/');
- if (this.defaultJSExtensions && path.substr(path.length - 3, 3) != '.js')
- normalized = normalized.substr(0, normalized.length - 3);
- packageConfigPaths[i] = normalized.substr(0, normalized.length - 1) + path.substr(packageLength);
- }
- this.packageConfigPaths = packageConfigPaths;
- }
- if (cfg.packages) {
- for (var p in cfg.packages) {
- if (p.match(/^([^\/]+:)?\/\/$/))
- throw new TypeError('"' + p + '" is not a valid package name.');
- // request with trailing "/" to get package name exactly
- var prop = this.normalizeSync(p + (p[p.length - 1] != '/' ? '/' : ''));
- prop = prop.substr(0, prop.length - 1);
- // if doing default js extensions, undo to get package name
- // (unless already a package which would have skipped extension)
- if (!this.packages[prop] && this.defaultJSExtensions && p.substr(p.length - 3, 3) != '.js')
- prop = prop.substr(0, prop.length - 3);
- this.packages[prop] = this.packages[prop] || {};
- // meta backwards compatibility
- if (cfg.packages[p].meta) {
- warn.call(this, 'Package ' + p + ' is configured with meta, which is deprecated as it has been renamed to modules.');
- cfg.packages[p].modules = cfg.packages[p].meta;
- delete cfg.packages[p].meta;
- }
- for (var q in cfg.packages[p])
- if (indexOf.call(packageProperties, q) == -1)
- warn.call(this, '"' + q + '" is not a valid package configuration option in package ' + p);
- extendMeta(this.packages[prop], cfg.packages[p]);
- }
- }
- if (cfg.bundles) {
- for (var p in cfg.bundles) {
- var bundle = [];
- for (var i = 0; i < cfg.bundles[p].length; i++)
- bundle.push(this.normalizeSync(cfg.bundles[p][i]));
- this.bundles[p] = bundle;
- }
- }
- for (var c in cfg) {
- var v = cfg[c];
- var normalizeProp = false, normalizeValArray = false;
- if (c == 'baseURL' || c == 'map' || c == 'packages' || c == 'bundles' || c == 'paths' || c == 'warnings' || c == 'packageConfigPaths')
- continue;
- if (typeof v != 'object' || v instanceof Array) {
- this[c] = v;
- }
- else {
- this[c] = this[c] || {};
- if (c == 'meta' || c == 'depCache')
- normalizeProp = true;
- for (var p in v) {
- if (c == 'meta' && p[0] == '*')
- this[c][p] = v[p];
- else if (normalizeProp)
- this[c][this.normalizeSync(p)] = v[p];
- else
- this[c][p] = v[p];
- }
- }
- }
- };/*
- * Paths extension
- *
- * Applies paths and normalizes to a full URL
- */
- hook('normalize', function(normalize) {
- return function(name, parentName) {
- var normalized = normalize.apply(this, arguments);
- // if the module is in the registry already, use that
- if (this.has(normalized))
- return normalized;
- if (normalized.match(absURLRegEx)) {
- // defaultJSExtensions backwards compatibility
- if (this.defaultJSExtensions && normalized.substr(normalized.length - 3, 3) != '.js')
- normalized += '.js';
- return normalized;
- }
- // applyPaths implementation provided from ModuleLoader system.js source
- normalized = applyPaths(this.paths, normalized) || normalized;
- // defaultJSExtensions backwards compatibility
- if (this.defaultJSExtensions && normalized.substr(normalized.length - 3, 3) != '.js')
- normalized += '.js';
- // ./x, /x -> page-relative
- if (normalized[0] == '.' || normalized[0] == '/')
- return new URL(normalized, baseURIObj).href;
- // x -> baseURL-relative
- else
- return new URL(normalized, getBaseURLObj.call(this)).href;
- };
- });/*
- * Package Configuration Extension
- *
- * Example:
- *
- * System.packages = {
- * jquery: {
- * basePath: 'lib', // optionally only use a subdirectory within the package
- * main: 'index.js', // when not set, package name is requested directly
- * format: 'amd',
- * defaultExtension: 'ts', // defaults to 'js', can be set to false
- * modules: {
- * '*.ts': {
- * loader: 'typescript'
- * },
- * 'vendor/sizzle.js': {
- * format: 'global'
- * }
- * },
- * map: {
- * // map internal require('sizzle') to local require('./vendor/sizzle')
- * sizzle: './vendor/sizzle.js',
- * // map any internal or external require of 'jquery/vendor/another' to 'another/index.js'
- * './vendor/another.js': './another/index.js',
- * // test.js / test -> lib/test.js
- * './test.js': './lib/test.js',
- *
- * // environment-specific map configurations
- * './index.js': {
- * '~browser': './index-node.js'
- * }
- * },
- * // allows for setting package-prefixed depCache
- * // keys are normalized module names relative to the package itself
- * depCache: {
- * // import 'package/index.js' loads in parallel package/lib/test.js,package/vendor/sizzle.js
- * './index.js': ['./test'],
- * './test.js': ['sizzle']
- * }
- * }
- * };
- *
- * Then:
- * import 'jquery' -> jquery/index.js
- * import 'jquery/submodule' -> jquery/submodule.js
- * import 'jquery/submodule.ts' -> jquery/submodule.ts loaded as typescript
- * import 'jquery/vendor/another' -> another/index.js
- *
- * Detailed Behaviours
- * - main can have a leading "./" can be added optionally
- * - map and defaultExtension are applied to the main
- * - defaultExtension adds the extension only if the exact extension is not present
- * - defaultJSExtensions applies after map when defaultExtension is not set
- * - if a modules value is available for a module, map and defaultExtension are skipped
- * - like global map, package map also applies to subpaths (sizzle/x, ./vendor/another/sub)
- * - condition module map is '@env' module in package or '@system-env' globally
- *
- * In addition, the following modules properties will be allowed to be package
- * -relative as well in the package module config:
- *
- * - loader
- * - alias
- *
- *
- * Package Configuration Loading
- *
- * Not all packages may already have their configuration present in the System config
- * For these cases, a list of packageConfigPaths can be provided, which when matched against
- * a request, will first request a ".json" file by the package name to derive the package
- * configuration from. This allows dynamic loading of non-predetermined code, a key use
- * case in SystemJS.
- *
- * Example:
- *
- * System.packageConfigPaths = ['packages/test/package.json', 'packages/*.json'];
- *
- * // will first request 'packages/new-package/package.json' for the package config
- * // before completing the package request to 'packages/new-package/path'
- * System.import('packages/new-package/path');
- *
- * // will first request 'packages/test/package.json' before the main
- * System.import('packages/test');
- *
- * When a package matches packageConfigPaths, it will always send a config request for
- * the package configuration.
- * The package name itself is taken to be the match up to and including the last wildcard
- * or trailing slash.
- * Package config paths are ordered - matching is done based on the first match found.
- * Any existing package configurations for the package will deeply merge with the
- * package config, with the existing package configurations taking preference.
- * To opt-out of the package configuration request for a package that matches
- * packageConfigPaths, use the { configured: true } package config option.
- *
- */
- (function() {
- hookConstructor(function(constructor) {
- return function() {
- constructor.call(this);
- this.packages = {};
- this.packageConfigPaths = {};
- };
- });
- function getPackage(name) {
- // use most specific package
- var curPkg, curPkgLen = 0, pkgLen;
- for (var p in this.packages) {
- if (name.substr(0, p.length) === p && (name.length === p.length || name[p.length] === '/')) {
- pkgLen = p.split('/').length;
- if (pkgLen > curPkgLen) {
- curPkg = p;
- curPkgLen = pkgLen;
- }
- }
- }
- return curPkg;
- }
- function applyMap(map, name) {
- var bestMatch, bestMatchLength = 0;
- for (var p in map) {
- if (name.substr(0, p.length) == p && (name.length == p.length || name[p.length] == '/')) {
- var curMatchLength = p.split('/').length;
- if (curMatchLength <= bestMatchLength)
- continue;
- bestMatch = p;
- bestMatchLength = curMatchLength;
- }
- }
- return bestMatch;
- }
- function getBasePath(pkg) {
- // sanitize basePath
- var basePath = pkg.basePath && pkg.basePath != '.' ? pkg.basePath : '';
- if (basePath) {
- if (basePath.substr(0, 2) == './')
- basePath = basePath.substr(2);
- if (basePath[basePath.length - 1] != '/')
- basePath += '/';
- }
- return basePath;
- }
- // given the package subpath, return the resultant combined path
- // defaultExtension is only added if the path does not have
- // loader package meta or exact package meta
- // We also re-incorporate package-level conditional syntax at this point
- // allowing package map and package mains to point to conditionals
- // when conditionals are present,
- function toPackagePath(loader, pkgName, pkg, basePath, subPath, sync, isPlugin) {
- // skip if its a plugin call already, or we have boolean / interpolation conditional syntax in subPath
- var skipExtension = !!(isPlugin || subPath.indexOf('#?') != -1 || subPath.match(interpolationRegEx));
- // exact meta or meta with any content after the last wildcard skips extension
- if (!skipExtension && pkg.modules)
- getMetaMatches(pkg.modules, pkgName, subPath, function(metaPattern, matchMeta, matchDepth) {
- if (matchDepth == 0 || metaPattern.lastIndexOf('*') != metaPattern.length - 1)
- skipExtension = true;
- });
- var normalized = pkgName + '/' + basePath + subPath + (skipExtension ? '' : getDefaultExtension(pkg, subPath));
- return sync ? normalized : booleanConditional.call(loader, normalized, pkgName + '/').then(function(name) {
- return interpolateConditional.call(loader, name, pkgName + '/');
- });
- }
- function getDefaultExtension(pkg, subPath) {
- // don't apply extensions to folders or if defaultExtension = false
- if (subPath[subPath.length - 1] != '/' && pkg.defaultExtension !== false) {
- // work out what the defaultExtension is and add if not there already
- var defaultExtension = '.' + (pkg.defaultExtension || 'js');
- if (subPath.substr(subPath.length - defaultExtension.length) != defaultExtension)
- return defaultExtension;
- }
- return '';
- }
- function applyPackageConfig(normalized, pkgName, pkg, sync, isPlugin) {
- var loader = this;
- var basePath = getBasePath(pkg);
- // main
- // NB can add a default package main convention here
- if (pkgName === normalized && pkg.main)
- normalized += '/' + (pkg.main.substr(0, 2) == './' ? pkg.main.substr(2) : pkg.main);
- // allow for direct package name normalization with trailling "/" (no main)
- if (normalized.length == pkgName.length + 1 && normalized[pkgName.length] == '/')
- return normalized;
- // also no submap if name is package itself (import 'pkg' -> 'path/to/pkg.js')
- if (normalized.length == pkgName.length)
- return normalized + (loader.defaultJSExtensions && normalized.substr(normalized.length - 3, 3) != '.js' ? '.js' : '');
- // apply map, checking without then with defaultExtension
- if (pkg.map) {
- var subPath = '.' + normalized.substr(pkgName.length);
- var map = applyMap(pkg.map, subPath) || !isPlugin && applyMap(pkg.map, (subPath += getDefaultExtension(pkg, subPath.substr(2))));
- var mapped = pkg.map[map];
- }
- function doMap(mapped) {
- // '.' as a target is the package itself (with package main check)
- if (mapped == '.')
- return pkgName;
- // internal package map
- else if (mapped.substr(0, 2) == './')
- return toPackagePath(loader, pkgName, pkg, basePath, mapped.substr(2), sync, isPlugin);
- // global package map
- else
- return (sync ? loader.normalizeSync : loader.normalize).call(loader, mapped);
- }
- // apply non-environment map match
- if (typeof mapped == 'string')
- return doMap(mapped + subPath.substr(map.length));
- // sync normalize does not apply environment map
- if (sync || !mapped)
- return toPackagePath(loader, pkgName, pkg, basePath, normalized.substr(pkgName.length + 1), sync, isPlugin);
- // environment map build support
- // -> we return [package-name]#[conditional-map] ("jquery#:index.js" in example above)
- // to indicate this unique conditional branch to builder in all of its possibilities
- if (loader.builder)
- return pkgName + '#:' + map.substr(2);
- // environment map
- return loader['import'](pkg.map['@env'] || '@system-env', pkgName)
- .then(function(env) {
- // first map condition to match is used
- for (var e in mapped) {
- var negate = e[0] == '~';
- var value = readMemberExpression(negate ? e.substr(1) : e, env);
- if (!negate && value || negate && !value)
- return mapped[e] + subPath.substr(map.length);
- }
- })
- .then(function(mapped) {
- // no environment match
- if (!mapped)
- return toPackagePath(loader, pkgName, pkg, basePath, normalized.substr(pkgName.length + 1), sync, isPlugin);
- else
- return doMap(mapped);
- });
- }
- function createPackageNormalize(normalize, sync) {
- return function(name, parentName, isPlugin) {
- isPlugin = isPlugin === true;
- // apply contextual package map first
- if (parentName)
- var parentPackage = getPackage.call(this, parentName) ||
- this.defaultJSExtensions && parentName.substr(parentName.length - 3, 3) == '.js' &&
- getPackage.call(this, parentName.substr(0, parentName.length - 3));
- if (parentPackage) {
- // remove any parent package base path for normalization
- var parentBasePath = getBasePath(this.packages[parentPackage]);
- if (parentBasePath && parentName.substr(parentPackage.length + 1, parentBasePath.length) == parentBasePath)
- parentName = parentPackage + parentName.substr(parentPackage.length + parentBasePath.length);
- if (name[0] !== '.') {
- var parentMap = this.packages[parentPackage].map;
- if (parentMap) {
- var map = applyMap(parentMap, name);
- if (map) {
- name = parentMap[map] + name.substr(map.length);
- // relative maps are package-relative
- if (name[0] === '.')
- parentName = parentPackage + '/';
- }
- }
- }
- }
- var defaultJSExtension = this.defaultJSExtensions && name.substr(name.length - 3, 3) != '.js';
- // apply map, core, paths
- var normalized = normalize.call(this, name, parentName);
- // undo defaultJSExtension
- if (defaultJSExtension && normalized.substr(normalized.length - 3, 3) != '.js')
- defaultJSExtension = false;
- if (defaultJSExtension)
- normalized = normalized.substr(0, normalized.length - 3);
- // if we requested a relative path, and got the package name, remove the trailing '/' to apply main
- // that is normalize('pkg/') does not apply main, while normalize('./', 'pkg/') does
- if (parentPackage && name[0] == '.' && normalized == parentPackage + '/')
- normalized = parentPackage;
- var loader = this;
- function packageResolution(normalized, pkgName, pkg) {
- // check if we are inside a package
- pkgName = pkgName || getPackage.call(loader, normalized);
- var pkg = pkg || pkgName && loader.packages[pkgName];
- if (pkg)
- return applyPackageConfig.call(loader, normalized, pkgName, pkg, sync, isPlugin);
- else
- return normalized + (defaultJSExtension ? '.js' : '');
- }
- // do direct resolution if sync
- if (sync)
- return packageResolution(normalized);
- // first check if we are in a package
- var pkgName = getPackage.call(this, normalized);
- var pkg = pkgName && this.packages[pkgName];
- // if so, and the package is configured, then do direct resolution
- if (pkg && pkg.configured)
- return packageResolution(normalized, pkgName, pkg);
- var pkgConfigMatch = pkgConfigPathMatch(loader, normalized);
- if (!pkgConfigMatch.pkgName)
- return packageResolution(normalized, pkgName, pkg);
- // if we're within a known package path, then halt on
- // further package configuration steps from bundles and config files
- return Promise.resolve(getBundleFor(loader, normalized))
- // ensure that any bundles in this package are triggered, and
- // all that are triggered block any further loads in the package
- .then(function(bundle) {
- if (bundle || pkgBundlePromises[pkgConfigMatch.pkgName]) {
- var pkgBundleLoads = pkgBundlePromises[pkgConfigMatch.pkgName] = pkgBundlePromises[pkgConfigMatch.pkgName] || { bundles: [], promise: Promise.resolve() };
- if (bundle && indexOf.call(pkgBundleLoads.bundles, bundle) == -1) {
- pkgBundleLoads.bundles.push(bundle);
- pkgBundleLoads.promise = Promise.all([pkgBundleLoads.promise, loader.load(bundle)]);
- }
- return pkgBundleLoads.promise;
- }
- })
- // having loaded any bundles, attempt a package resolution now
- .then(function() {
- return packageResolution(normalized, pkgConfigMatch.pkgName);
- })
- .then(function(curResolution) {
- // if that resolution is defined in the registry use it
- if (curResolution in loader.defined)
- return curResolution;
- // otherwise revert to loading configuration dynamically
- return loadPackageConfigPaths(loader, pkgConfigMatch)
- .then(function() {
- // before doing a final resolution
- return packageResolution(normalized);
- });
- });
- };
- }
- var pkgBundlePromises = {};
- // check if the given normalized name matches a packageConfigPath
- // if so, loads the config
- var packageConfigPathsRegExps = {};
- var pkgConfigPromises = {};
- function pkgConfigPathMatch(loader, normalized) {
- var pkgPath, pkgConfigPaths = [];
- for (var i = 0; i < loader.packageConfigPaths.length; i++) {
- var p = loader.packageConfigPaths[i];
- var pPkgLen = Math.max(p.lastIndexOf('*') + 1, p.lastIndexOf('/'));
- var match = normalized.match(packageConfigPathsRegExps[p] ||
- (packageConfigPathsRegExps[p] = new RegExp('^(' + p.substr(0, pPkgLen).replace(/\*/g, '[^\\/]+') + ')(\/|$)')));
- if (match && (!pkgPath || pkgPath == match[1])) {
- pkgPath = match[1];
- pkgConfigPaths.push(pkgPath + p.substr(pPkgLen));
- }
- }
- return {
- pkgName: pkgPath,
- configPaths: pkgConfigPaths
- };
- }
- function loadPackageConfigPaths(loader, pkgConfigMatch) {
- var curPkgConfig = loader.packages[pkgConfigMatch.pkgName];
- if (curPkgConfig && curPkgConfig.configured)
- return Promise.resolve();
- return pkgConfigPromises[pkgConfigMatch.pkgName] || (
- pkgConfigPromises[pkgConfigMatch.pkgName] = Promise.resolve()
- .then(function() {
- var pkgConfigPromises = [];
- for (var i = 0; i < pkgConfigMatch.configPaths.length; i++) (function(pkgConfigPath) {
- pkgConfigPromises.push(loader['fetch']({ name: pkgConfigPath, address: pkgConfigPath, metadata: {} })
- .then(function(source) {
- try {
- return JSON.parse(source);
- }
- catch(e) {
- throw new Error('Invalid JSON in package configuration file ' + pkgConfigPath);
- }
- })
- .then(function(cfg) {
- // support "systemjs" prefixing
- if (cfg.systemjs)
- cfg = cfg.systemjs;
- // meta backwards compatibility
- if (cfg.meta) {
- cfg.modules = cfg.meta;
- warn.call(loader, 'Package config file ' + pkgConfigPath + ' is configured with meta, which is deprecated as it has been renamed to modules.');
- }
- // remove any non-system properties if generic config file (eg package.json)
- for (var p in cfg) {
- if (indexOf.call(packageProperties, p) == -1)
- delete cfg[p];
- }
- // support main array
- if (cfg.main instanceof Array)
- cfg.main = cfg.main[0];
- // deeply-merge (to first level) config with any existing package config
- if (curPkgConfig)
- extendMeta(cfg, curPkgConfig);
- // support external depCache
- if (cfg.depCache)
- for (var d in cfg.depCache) {
- if (d.substr(0, 2) == './')
- continue;
- var dNormalized = loader.normalizeSync(d);
- loader.depCache[dNormalized] = (loader.depCache[dNormalized] || []).concat(cfg.depCache[d]);
- }
- curPkgConfig = loader.packages[pkgConfigMatch.pkgName] = cfg;
- }));
- })(pkgConfigMatch.configPaths[i]);
- return Promise.all(pkgConfigPromises);
- })
- );
- }
- SystemJSLoader.prototype.normalizeSync = SystemJSLoader.prototype.normalize;
- hook('normalizeSync', function(normalize) {
- return createPackageNormalize(normalize, true);
- });
- hook('normalize', function(normalize) {
- return createPackageNormalize(normalize, false);
- });
- function getMetaMatches(pkgMeta, pkgName, subPath, matchFn) {
- // wildcard meta
- var meta = {};
- var wildcardIndex;
- for (var module in pkgMeta) {
- // allow meta to start with ./ for flexibility
- var dotRel = module.substr(0, 2) == './' ? './' : '';
- if (dotRel)
- module = module.substr(2);
- wildcardIndex = module.indexOf('*');
- if (wildcardIndex === -1)
- continue;
- if (module.substr(0, wildcardIndex) == subPath.substr(0, wildcardIndex)
- && module.substr(wildcardIndex + 1) == subPath.substr(subPath.length - module.length + wildcardIndex + 1)) {
- matchFn(module, pkgMeta[dotRel + module], module.split('/').length);
- }
- }
- // exact meta
- var exactMeta = pkgMeta[subPath] || pkgMeta['./' + subPath];
- if (exactMeta)
- matchFn(exactMeta, exactMeta, 0);
- }
- hook('locate', function(locate) {
- return function(load) {
- var loader = this;
- return Promise.resolve(locate.call(this, load))
- .then(function(address) {
- var pkgName = getPackage.call(loader, load.name);
- if (pkgName) {
- var pkg = loader.packages[pkgName];
- var basePath = getBasePath(pkg);
- var subPath = load.name.substr(pkgName.length + basePath.length + 1);
- // format
- if (pkg.format)
- load.metadata.format = load.metadata.format || pkg.format;
- // depCache for packages
- if (pkg.depCache) {
- for (var d in pkg.depCache) {
- if (d != './' + subPath)
- continue;
- var deps = pkg.depCache[d];
- for (var i = 0; i < deps.length; i++)
- loader['import'](deps[i], pkgName + '/');
- }
- }
- var meta = {};
- if (pkg.modules) {
- var bestDepth = 0;
- getMetaMatches(pkg.modules, pkgName, subPath, function(metaPattern, matchMeta, matchDepth) {
- if (matchDepth > bestDepth)
- bestDepth = matchDepth;
- extendMeta(meta, matchMeta, matchDepth && bestDepth > matchDepth);
- });
- // allow alias and loader to be package-relative
- if (meta.alias && meta.alias.substr(0, 2) == './')
- meta.alias = pkgName + meta.alias.substr(1);
- if (meta.loader && meta.loader.substr(0, 2) == './')
- meta.loader = pkgName + meta.loader.substr(1);
- extendMeta(load.metadata, meta);
- }
- }
- return address;
- });
- };
- });
- })();/*
- * Script tag fetch
- *
- * When load.metadata.scriptLoad is true, we load via script tag injection.
- */
- (function() {
- if (typeof document != 'undefined')
- var head = document.getElementsByTagName('head')[0];
- var curSystem;
- // if doing worker executing, this is set to the load record being executed
- var workerLoad = null;
- // interactive mode handling method courtesy RequireJS
- var ieEvents = head && (function() {
- var s = document.createElement('script');
- var isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]';
- return s.attachEvent && !(s.attachEvent.toString && s.attachEvent.toString().indexOf('[native code') < 0) && !isOpera;
- })();
- // IE interactive-only part
- // we store loading scripts array as { script: <script>, load: {...} }
- var interactiveLoadingScripts = [];
- var interactiveScript;
- function getInteractiveScriptLoad() {
- if (interactiveScript && interactiveScript.script.readyState === 'interactive')
- return interactiveScript.load;
- for (var i = 0; i < interactiveLoadingScripts.length; i++)
- if (interactiveLoadingScripts[i].script.readyState == 'interactive') {
- interactiveScript = interactiveLoadingScripts[i];
- return interactiveScript.load;
- }
- }
- // System.register, System.registerDynamic, AMD define pipeline
- // this is called by the above methods when they execute
- // we then run the reduceRegister_ collection function either immediately
- // if we are in IE and know the currently executing script (interactive)
- // or later if we need to wait for the synchronous load callback to know the script
- var loadingCnt = 0;
- var registerQueue = [];
- hook('pushRegister_', function(pushRegister) {
- return function(register) {
- // if using eval-execution then skip
- if (pushRegister.call(this, register))
- return false;
- // if using worker execution, then we're done
- if (workerLoad)
- this.reduceRegister_(workerLoad, register);
- // detect if we know the currently executing load (IE)
- // if so, immediately call reduceRegister
- else if (ieEvents)
- this.reduceRegister_(getInteractiveScriptLoad(), register);
- // otherwise, add to our execution queue
- // to call reduceRegister on sync script load event
- else if (loadingCnt)
- registerQueue.push(register);
- // if we're not currently loading anything though
- // then do the reduction against a null load
- // (out of band named define or named register)
- // note even in non-script environments, this catch is used
- else
- this.reduceRegister_(null, register);
- return true;
- };
- });
- function webWorkerImport(loader, load) {
- return new Promise(function(resolve, reject) {
- if (load.metadata.integrity)
- reject(new Error('Subresource integrity checking is not supported in web workers.'));
- workerLoad = load;
- try {
- importScripts(load.address);
- }
- catch(e) {
- workerLoad = null;
- reject(e);
- }
- workerLoad = null;
- // if nothing registered, then something went wrong
- if (!load.metadata.entry)
- reject(new Error(load.address + ' did not call System.register or AMD define'));
- resolve('');
- });
- }
- // override fetch to use script injection
- hook('fetch', function(fetch) {
- return function(load) {
- var loader = this;
- if (!load.metadata.scriptLoad || (!isBrowser && !isWorker))
- return fetch.call(this, load);
- if (isWorker)
- return webWorkerImport(loader, load);
- return new Promise(function(resolve, reject) {
- var s = document.createElement('script');
- s.async = true;
- if (load.metadata.integrity)
- s.setAttribute('integrity', load.metadata.integrity);
- if (ieEvents) {
- s.attachEvent('onreadystatechange', complete);
- interactiveLoadingScripts.push({
- script: s,
- load: load
- });
- }
- else {
- s.addEventListener('load', complete, false);
- s.addEventListener('error', error, false);
- }
- loadingCnt++;
- curSystem = __global.System;
- s.src = load.address;
- head.appendChild(s);
- function complete(evt) {
- if (s.readyState && s.readyState != 'loaded' && s.readyState != 'complete')
- return;
- loadingCnt--;
- // complete call is sync on execution finish
- // (in ie already done reductions)
- if (!load.metadata.entry && !registerQueue.length) {
- loader.reduceRegister_(load);
- }
- else if (!ieEvents) {
- for (var i = 0; i < registerQueue.length; i++)
- loader.reduceRegister_(load, registerQueue[i]);
- registerQueue = [];
- }
- cleanup();
- // if nothing registered, then something went wrong
- if (!load.metadata.entry && !load.metadata.bundle)
- reject(new Error(load.name + ' did not call System.register or AMD define'));
- resolve('');
- }
- function error(evt) {
- cleanup();
- reject(new Error('Unable to load script ' + load.address));
- }
- function cleanup() {
- __global.System = curSystem;
- if (s.detachEvent) {
- s.detachEvent('onreadystatechange', complete);
- for (var i = 0; i < interactiveLoadingScripts.length; i++)
- if (interactiveLoadingScripts[i].script == s) {
- if (interactiveScript && interactiveScript.script == s)
- interactiveScript = null;
- interactiveLoadingScripts.splice(i, 1);
- }
- }
- else {
- s.removeEventListener('load', complete, false);
- s.removeEventListener('error', error, false);
- }
- head.removeChild(s);
- }
- });
- };
- });
- })();
- /*
- * Instantiate registry extension
- *
- * Supports Traceur System.register 'instantiate' output for loading ES6 as ES5.
- *
- * - Creates the loader.register function
- * - Also supports metadata.format = 'register' in instantiate for anonymous register modules
- * - Also supports metadata.deps, metadata.execute and metadata.executingRequire
- * for handling dynamic modules alongside register-transformed ES6 modules
- *
- *
- * The code here replicates the ES6 linking groups algorithm to ensure that
- * circular ES6 compiled into System.register can work alongside circular AMD
- * and CommonJS, identically to the actual ES6 loader.
- *
- */
- /*
- * Registry side table entries in loader.defined
- * Registry Entry Contains:
- * - name
- * - deps
- * - declare for declarative modules
- * - execute for dynamic modules, different to declarative execute on module
- * - executingRequire indicates require drives execution for circularity of dynamic modules
- * - declarative optional boolean indicating which of the above
- *
- * Can preload modules directly on System.defined['my/module'] = { deps, execute, executingRequire }
- *
- * Then the entry gets populated with derived information during processing:
- * - normalizedDeps derived from deps, created in instantiate
- * - groupIndex used by group linking algorithm
- * - evaluated indicating whether evaluation has happend
- * - module the module record object, containing:
- * - exports actual module exports
- *
- * For dynamic we track the es module with:
- * - esModule actual es module value
- * - esmExports whether to extend the esModule with named exports
- *
- * Then for declarative only we track dynamic bindings with the 'module' records:
- * - name
- * - exports
- * - setters declarative setter functions
- * - dependencies, module records of dependencies
- * - importers, module records of dependents
- *
- * After linked and evaluated, entries are removed, declarative module records remain in separate
- * module binding table
- *
- */
- function createEntry() {
- return {
- name: null,
- deps: null,
- declare: null,
- execute: null,
- executingRequire: false,
- declarative: false,
- normalizedDeps: null,
- groupIndex: null,
- evaluated: false,
- module: null,
- esModule: null,
- esmExports: false
- };
- }
- (function() {
- /*
- * There are two variations of System.register:
- * 1. System.register for ES6 conversion (2-3 params) - System.register([name, ]deps, declare)
- * see https://github.com/ModuleLoader/es6-module-loader/wiki/System.register-Explained
- *
- * 2. System.registerDynamic for dynamic modules (3-4 params) - System.registerDynamic([name, ]deps, executingRequire, execute)
- * the true or false statement
- *
- * this extension implements the linking algorithm for the two variations identical to the spec
- * allowing compiled ES6 circular references to work alongside AMD and CJS circular references.
- *
- */
- SystemJSLoader.prototype.register = function(name, deps, declare) {
- if (typeof name != 'string') {
- declare = deps;
- deps = name;
- name = null;
- }
- // dynamic backwards-compatibility
- // can be deprecated eventually
- if (typeof declare == 'boolean')
- return this.registerDynamic.apply(this, arguments);
- var entry = createEntry();
- // ideally wouldn't apply map config to bundle names but
- // dependencies go through map regardless so we can't restrict
- // could reconsider in shift to new spec
- entry.name = name && (this.normalizeSync || this.normalize).call(this, name);
- entry.declarative = true;
- entry.deps = deps;
- entry.declare = declare;
- this.pushRegister_({
- amd: false,
- entry: entry
- });
- };
- SystemJSLoader.prototype.registerDynamic = function(name, deps, declare, execute) {
- if (typeof name != 'string') {
- execute = declare;
- declare = deps;
- deps = name;
- name = null;
- }
- // dynamic
- var entry = createEntry();
- entry.name = name && (this.normalizeSync || this.normalize).call(this, name);
- entry.deps = deps;
- entry.execute = execute;
- entry.executingRequire = declare;
- this.pushRegister_({
- amd: false,
- entry: entry
- });
- };
- hook('reduceRegister_', function() {
- return function(load, register) {
- if (!register)
- return;
- var entry = register.entry;
- var curMeta = load && load.metadata;
- // named register
- if (entry.name) {
- if (!(entry.name in this.defined))
- this.defined[entry.name] = entry;
- if (curMeta)
- curMeta.bundle = true;
- }
- // anonymous register
- if (!entry.name || load && entry.name == load.name) {
- if (!curMeta)
- throw new TypeError('Unexpected anonymous System.register call.');
- if (curMeta.entry) {
- if (curMeta.format == 'register')
- throw new Error('Multiple anonymous System.register calls in module ' + load.name + '. If loading a bundle, ensure all the System.register calls are named.');
- else
- throw new Error('Module ' + load.name + ' interpreted as ' + curMeta.format + ' module format, but called System.register.');
- }
- if (!curMeta.format)
- curMeta.format = 'register';
- curMeta.entry = entry;
- }
- };
- });
- hookConstructor(function(constructor) {
- return function() {
- constructor.call(this);
- this.defined = {};
- this._loader.moduleRecords = {};
- };
- });
- function buildGroups(entry, loader, groups) {
- groups[entry.groupIndex] = groups[entry.groupIndex] || [];
- if (indexOf.call(groups[entry.groupIndex], entry) != -1)
- return;
- groups[entry.groupIndex].push(entry);
- for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) {
- var depName = entry.normalizedDeps[i];
- var depEntry = loader.defined[depName];
- // not in the registry means already linked / ES6
- if (!depEntry || depEntry.evaluated)
- continue;
- // now we know the entry is in our unlinked linkage group
- var depGroupIndex = entry.groupIndex + (depEntry.declarative != entry.declarative);
- // the group index of an entry is always the maximum
- if (depEntry.groupIndex === null || depEntry.groupIndex < depGroupIndex) {
- // if already in a group, remove from the old group
- if (depEntry.groupIndex !== null) {
- groups[depEntry.groupIndex].splice(indexOf.call(groups[depEntry.groupIndex], depEntry), 1);
- // if the old group is empty, then we have a mixed depndency cycle
- if (groups[depEntry.groupIndex].length == 0)
- throw new Error("Mixed dependency cycle detected");
- }
- depEntry.groupIndex = depGroupIndex;
- }
- buildGroups(depEntry, loader, groups);
- }
- }
- function link(name, loader) {
- var startEntry = loader.defined[name];
- // skip if already linked
- if (startEntry.module)
- return;
- startEntry.groupIndex = 0;
- var groups = [];
- buildGroups(startEntry, loader, groups);
- var curGroupDeclarative = !!startEntry.declarative == groups.length % 2;
- for (var i = groups.length - 1; i >= 0; i--) {
- var group = groups[i];
- for (var j = 0; j < group.length; j++) {
- var entry = group[j];
- // link each group
- if (curGroupDeclarative)
- linkDeclarativeModule(entry, loader);
- else
- linkDynamicModule(entry, loader);
- }
- curGroupDeclarative = !curGroupDeclarative;
- }
- }
- // module binding records
- function Module() {}
- defineProperty(Module, 'toString', {
- value: function() {
- return 'Module';
- }
- });
- function getOrCreateModuleRecord(name, moduleRecords) {
- return moduleRecords[name] || (moduleRecords[name] = {
- name: name,
- dependencies: [],
- exports: new Module(), // start from an empty module and extend
- importers: []
- });
- }
- function linkDeclarativeModule(entry, loader) {
- // only link if already not already started linking (stops at circular)
- if (entry.module)
- return;
- var moduleRecords = loader._loader.moduleRecords;
- var module = entry.module = getOrCreateModuleRecord(entry.name, moduleRecords);
- var exports = entry.module.exports;
- var declaration = entry.declare.call(__global, function(name, value) {
- module.locked = true;
- if (typeof name == 'object') {
- for (var p in name)
- exports[p] = name[p];
- }
- else {
- exports[name] = value;
- }
- for (var i = 0, l = module.importers.length; i < l; i++) {
- var importerModule = module.importers[i];
- if (!importerModule.locked) {
- var importerIndex = indexOf.call(importerModule.dependencies, module);
- importerModule.setters[importerIndex](exports);
- }
- }
- module.locked = false;
- return value;
- });
- module.setters = declaration.setters;
- module.execute = declaration.execute;
- if (!module.setters || !module.execute) {
- throw new TypeError('Invalid System.register form for ' + entry.name);
- }
- // now link all the module dependencies
- for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) {
- var depName = entry.normalizedDeps[i];
- var depEntry = loader.defined[depName];
- var depModule = moduleRecords[depName];
- // work out how to set depExports based on scenarios...
- var depExports;
- if (depModule) {
- depExports = depModule.exports;
- }
- // dynamic, already linked in our registry
- else if (depEntry && !depEntry.declarative) {
- depExports = depEntry.esModule;
- }
- // in the loader registry
- else if (!depEntry) {
- depExports = loader.get(depName);
- }
- // we have an entry -> link
- else {
- linkDeclarativeModule(depEntry, loader);
- depModule = depEntry.module;
- depExports = depModule.exports;
- }
- // only declarative modules have dynamic bindings
- if (depModule && depModule.importers) {
- depModule.importers.push(module);
- module.dependencies.push(depModule);
- }
- else {
- module.dependencies.push(null);
- }
- // run setters for all entries with the matching dependency name
- var originalIndices = entry.originalIndices[i];
- for (var j = 0, len = originalIndices.length; j < len; ++j) {
- var index = originalIndices[j];
- if (module.setters[index]) {
- module.setters[index](depExports);
- }
- }
- }
- }
- // An analog to loader.get covering execution of all three layers (real declarative, simulated declarative, simulated dynamic)
- function getModule(name, loader) {
- var exports;
- var entry = loader.defined[name];
- if (!entry) {
- exports = loader.get(name);
- if (!exports)
- throw new Error('Unable to load dependency ' + name + '.');
- }
- else {
- if (entry.declarative)
- ensureEvaluated(name, [], loader);
- else if (!entry.evaluated)
- linkDynamicModule(entry, loader);
- exports = entry.module.exports;
- }
- if ((!entry || entry.declarative) && exports && exports.__useDefault)
- return exports['default'];
- return exports;
- }
- function linkDynamicModule(entry, loader) {
- if (entry.module)
- return;
- var exports = {};
- var module = entry.module = { exports: exports, id: entry.name };
- // AMD requires execute the tree first
- if (!entry.executingRequire) {
- for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) {
- var depName = entry.normalizedDeps[i];
- // we know we only need to link dynamic due to linking algorithm
- var depEntry = loader.defined[depName];
- if (depEntry)
- linkDynamicModule(depEntry, loader);
- }
- }
- // now execute
- entry.evaluated = true;
- var output = entry.execute.call(__global, function(name) {
- for (var i = 0, l = entry.deps.length; i < l; i++) {
- if (entry.deps[i] != name)
- continue;
- return getModule(entry.normalizedDeps[i], loader);
- }
- throw new Error('Module ' + name + ' not declared as a dependency.');
- }, exports, module);
- if (output)
- module.exports = output;
- // create the esModule object, which allows ES6 named imports of dynamics
- exports = module.exports;
- // __esModule flag treats as already-named
- if (exports && exports.__esModule)
- entry.esModule = exports;
- // set module as 'default' export, then fake named exports by iterating properties
- else if (entry.esmExports && exports !== __global)
- entry.esModule = getESModule(exports);
- // just use the 'default' export
- else
- entry.esModule = { 'default': exports };
- }
- /*
- * Given a module, and the list of modules for this current branch,
- * ensure that each of the dependencies of this module is evaluated
- * (unless one is a circular dependency already in the list of seen
- * modules, in which case we execute it)
- *
- * Then we evaluate the module itself depth-first left to right
- * execution to match ES6 modules
- */
- function ensureEvaluated(moduleName, seen, loader) {
- var entry = loader.defined[moduleName];
- // if already seen, that means it's an already-evaluated non circular dependency
- if (!entry || entry.evaluated || !entry.declarative)
- return;
- // this only applies to declarative modules which late-execute
- seen.push(moduleName);
- for (var i = 0, l = entry.normalizedDeps.length; i < l; i++) {
- var depName = entry.normalizedDeps[i];
- if (indexOf.call(seen, depName) == -1) {
- if (!loader.defined[depName])
- loader.get(depName);
- else
- ensureEvaluated(depName, seen, loader);
- }
- }
- if (entry.evaluated)
- return;
- entry.evaluated = true;
- entry.module.execute.call(__global);
- }
- // override the delete method to also clear the register caches
- hook('delete', function(del) {
- return function(name) {
- delete this._loader.moduleRecords[name];
- delete this.defined[name];
- return del.call(this, name);
- };
- });
- var leadingCommentAndMetaRegEx = /^\s*(\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)*\s*/;
- function detectRegisterFormat(source) {
- var leadingCommentAndMeta = source.match(leadingCommentAndMetaRegEx);
- return leadingCommentAndMeta && source.substr(leadingCommentAndMeta[0].length, 15) == 'System.register';
- }
- hook('fetch', function(fetch) {
- return function(load) {
- if (this.defined[load.name]) {
- load.metadata.format = 'defined';
- return '';
- }
- if (load.metadata.format == 'register' && !load.metadata.authorization && load.metadata.scriptLoad !== false)
- load.metadata.scriptLoad = true;
- load.metadata.deps = load.metadata.deps || [];
- return fetch.call(this, load);
- };
- });
- hook('translate', function(translate) {
- // we run the meta detection here (register is after meta)
- return function(load) {
- load.metadata.deps = load.metadata.deps || [];
- return Promise.resolve(translate.call(this, load)).then(function(source) {
- // run detection for register format
- if (load.metadata.format == 'register' || !load.metadata.format && detectRegisterFormat(load.source))
- load.metadata.format = 'register';
- return source;
- });
- };
- });
- hook('instantiate', function(instantiate) {
- return function(load) {
- var loader = this;
- var entry;
- // first we check if this module has already been defined in the registry
- if (loader.defined[load.name]) {
- entry = loader.defined[load.name];
- entry.deps = entry.deps.concat(load.metadata.deps);
- }
- // picked up already by an anonymous System.register script injection
- // or via the dynamic formats
- else if (load.metadata.entry) {
- entry = load.metadata.entry;
- entry.deps = entry.deps.concat(load.metadata.deps);
- }
- // Contains System.register calls
- // (dont run bundles in the builder)
- else if (!(loader.builder && load.metadata.bundle)
- && (load.metadata.format == 'register' || load.metadata.format == 'esm' || load.metadata.format == 'es6')) {
- if (typeof __exec != 'undefined')
- __exec.call(loader, load);
- if (!load.metadata.entry && !load.metadata.bundle)
- throw new Error(load.name + ' detected as ' + load.metadata.format + ' but didn\'t execute.');
- entry = load.metadata.entry;
- // support metadata deps for System.register
- if (entry && load.metadata.deps)
- entry.deps = entry.deps.concat(load.metadata.deps);
- }
- // named bundles are just an empty module
- if (!entry) {
- entry = createEntry();
- entry.deps = load.metadata.deps;
- entry.execute = function() {};
- }
- // place this module onto defined for circular references
- loader.defined[load.name] = entry;
- var grouped = group(entry.deps);
- entry.deps = grouped.names;
- entry.originalIndices = grouped.indices;
- entry.name = load.name;
- entry.esmExports = load.metadata.esmExports !== false;
- // first, normalize all dependencies
- var normalizePromises = [];
- for (var i = 0, l = entry.deps.length; i < l; i++)
- normalizePromises.push(Promise.resolve(loader.normalize(entry.deps[i], load.name)));
- return Promise.all(normalizePromises).then(function(normalizedDeps) {
- entry.normalizedDeps = normalizedDeps;
- return {
- deps: entry.deps,
- execute: function() {
- // recursively ensure that the module and all its
- // dependencies are linked (with dependency group handling)
- link(load.name, loader);
- // now handle dependency execution in correct order
- ensureEvaluated(load.name, [], loader);
- // remove from the registry
- loader.defined[load.name] = undefined;
- // return the defined module object
- return loader.newModule(entry.declarative ? entry.module.exports : entry.esModule);
- }
- };
- });
- };
- });
- })();
- /*
- * Extension to detect ES6 and auto-load Traceur or Babel for processing
- */
- (function() {
- // good enough ES6 module detection regex - format detections not designed to be accurate, but to handle the 99% use case
- 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))/;
- var traceurRuntimeRegEx = /\$traceurRuntime\s*\./;
- var babelHelpersRegEx = /babelHelpers\s*\./;
- hook('translate', function(translate) {
- return function(load) {
- var loader = this;
- return translate.call(loader, load)
- .then(function(source) {
- // detect & transpile ES6
- if (load.metadata.format == 'esm' || load.metadata.format == 'es6' || !load.metadata.format && source.match(esmRegEx)) {
- if (load.metadata.format == 'es6')
- warn.call(loader, 'Module ' + load.name + ' has metadata setting its format to "es6", which is deprecated.\nThis should be updated to "esm".');
- load.metadata.format = 'esm';
- if (loader.transpiler === false)
- throw new TypeError('Unable to dynamically transpile ES module as System.transpiler set to false.');
- // setting loadedTranspiler_ = false tells the next block to
- // do checks for setting transpiler metadata
- loader.loadedTranspiler_ = loader.loadedTranspiler_ || false;
- if (loader.pluginLoader)
- loader.pluginLoader.loadedTranspiler_ = loader.loadedTranspiler_ || false;
- // builder support
- if (loader.builder)
- load.metadata.originalSource = load.source;
- // defined in es6-module-loader/src/transpile.js
- return transpile.call(loader, load)
- .then(function(source) {
- // clear sourceMap as transpiler embeds it
- load.metadata.sourceMap = undefined;
- return source;
- });
- }
- // load the transpiler correctly
- if (loader.loadedTranspiler_ === false && load.name == loader.normalizeSync(loader.transpiler)) {
- warn.call(loader, 'Note that internal transpilation via System.transpiler has been deprecated for transpiler plugins.');
- // always load transpiler as a global
- if (source.length > 100) {
- load.metadata.format = load.metadata.format || 'global';
- if (loader.transpiler === 'traceur')
- load.metadata.exports = 'traceur';
- if (loader.transpiler === 'typescript')
- load.metadata.exports = 'ts';
- }
- loader.loadedTranspiler_ = true;
- }
- // load the transpiler runtime correctly
- if (loader.loadedTranspilerRuntime_ === false) {
- if (load.name == loader.normalizeSync('traceur-runtime')
- || load.name == loader.normalizeSync('babel/external-helpers*')) {
- if (source.length > 100)
- load.metadata.format = load.metadata.format || 'global';
- loader.loadedTranspilerRuntime_ = true;
- }
- }
- // detect transpiler runtime usage to load runtimes
- if ((load.metadata.format == 'register' || load.metadata.bundle) && loader.loadedTranspilerRuntime_ !== true) {
- if (!__global.$traceurRuntime && load.source.match(traceurRuntimeRegEx)) {
- loader.loadedTranspilerRuntime_ = loader.loadedTranspilerRuntime_ || false;
- return loader['import']('traceur-runtime').then(function() {
- return source;
- });
- }
- if (!__global.babelHelpers && load.source.match(babelHelpersRegEx)) {
- loader.loadedTranspilerRuntime_ = loader.loadedTranspilerRuntime_ || false;
- return loader['import']('babel/external-helpers').then(function() {
- return source;
- });
- }
- }
- return source;
- });
- };
- });
- })();
- /*
- SystemJS Global Format
- Supports
- metadata.deps
- metadata.globals
- metadata.exports
- Without metadata.exports, detects writes to the global object.
- */
- var __globalName = typeof self != 'undefined' ? 'self' : 'global';
- hook('reduceRegister_', function(reduceRegister) {
- return function(load, register) {
- if (register)
- return reduceRegister.call(this, load, register);
- load.metadata.format = 'global';
- var entry = load.metadata.entry = createEntry();
- var globalValue = readMemberExpression(load.metadata.exports, __global);
- entry.execute = function() {
- return globalValue;
- };
- };
- });
- hook('fetch', function(fetch) {
- return function(load) {
- if (load.metadata.exports && !load.metadata.format)
- load.metadata.format = 'global';
- // A global with exports, no globals and no deps
- // can be loaded via a script tag
- if (load.metadata.format == 'global' && !load.metadata.authorization
- && load.metadata.exports && !load.metadata.globals
- && (!load.metadata.deps || load.metadata.deps.length == 0)
- && load.metadata.scriptLoad !== false)
- load.metadata.scriptLoad = true;
- return fetch.call(this, load);
- };
- });
- // ideally we could support script loading for globals, but the issue with that is that
- // we can't do it with AMD support side-by-side since AMD support means defining the
- // global define, and global support means not definining it, yet we don't have any hook
- // into the "pre-execution" phase of a script tag being loaded to handle both cases
- hook('instantiate', function(instantiate) {
- return function(load) {
- var loader = this;
- if (!load.metadata.format)
- load.metadata.format = 'global';
- // globals shorthand support for:
- // globals = ['Buffer'] where we just require 'Buffer' in the current context
- if (load.metadata.globals) {
- if (load.metadata.globals instanceof Array) {
- var globals = {};
- for (var i = 0; i < load.metadata.globals.length; i++)
- globals[load.metadata.globals[i]] = load.metadata.globals[i];
- load.metadata.globals = globals;
- }
- }
- // global is a fallback module format
- if (load.metadata.format == 'global' && !load.metadata.registered) {
- var entry = createEntry();
- load.metadata.entry = entry;
- entry.deps = [];
- for (var g in load.metadata.globals)
- entry.deps.push(load.metadata.globals[g]);
- entry.execute = function(require, exports, module) {
- var globals;
- if (load.metadata.globals) {
- globals = {};
- for (var g in load.metadata.globals)
- globals[g] = require(load.metadata.globals[g]);
- }
- var exportName = load.metadata.exports;
- if (exportName)
- load.source += '\n' + __globalName + '["' + exportName + '"] = ' + exportName + ';';
- var retrieveGlobal = loader.get('@@global-helpers').prepareGlobal(module.id, exportName, globals);
- __exec.call(loader, load);
- return retrieveGlobal();
- }
- }
- return instantiate.call(this, load);
- };
- });
- hookConstructor(function(constructor) {
- return function() {
- var loader = this;
- constructor.call(loader);
- var hasOwnProperty = Object.prototype.hasOwnProperty;
- // bare minimum ignores for IE8
- var ignoredGlobalProps = ['_g', 'sessionStorage', 'localStorage', 'clipboardData', 'frames', 'frameElement', 'external', 'mozAnimationStartTime', 'webkitStorageInfo', 'webkitIndexedDB'];
- var globalSnapshot;
- function forEachGlobal(callback) {
- if (Object.keys)
- Object.keys(__global).forEach(callback);
- else
- for (var g in __global) {
- if (!hasOwnProperty.call(__global, g))
- continue;
- callback(g);
- }
- }
- function forEachGlobalValue(callback) {
- forEachGlobal(function(globalName) {
- if (indexOf.call(ignoredGlobalProps, globalName) != -1)
- return;
- try {
- var value = __global[globalName];
- }
- catch (e) {
- ignoredGlobalProps.push(globalName);
- }
- callback(globalName, value);
- });
- }
- loader.set('@@global-helpers', loader.newModule({
- prepareGlobal: function(moduleName, exportName, globals) {
- // disable module detection
- var curDefine = __global.define;
- __global.define = undefined;
- __global.exports = undefined;
- if (__global.module && __global.module.exports)
- __global.module = undefined;
- // set globals
- var oldGlobals;
- if (globals) {
- oldGlobals = {};
- for (var g in globals) {
- oldGlobals[g] = __global[g];
- __global[g] = globals[g];
- }
- }
- // store a complete copy of the global object in order to detect changes
- if (!exportName) {
- globalSnapshot = {};
- forEachGlobalValue(function(name, value) {
- globalSnapshot[name] = value;
- });
- }
- // return function to retrieve global
- return function() {
- var globalValue;
- if (exportName) {
- globalValue = readMemberExpression(exportName, __global);
- }
- else {
- var singleGlobal;
- var multipleExports;
- var exports = {};
- forEachGlobalValue(function(name, value) {
- if (globalSnapshot[name] === value)
- return;
- if (typeof value == 'undefined')
- return;
- exports[name] = value;
- if (typeof singleGlobal != 'undefined') {
- if (!multipleExports && singleGlobal !== value)
- multipleExports = true;
- }
- else {
- singleGlobal = value;
- }
- });
- globalValue = multipleExports ? exports : singleGlobal;
- }
- // revert globals
- if (oldGlobals) {
- for (var g in oldGlobals)
- __global[g] = oldGlobals[g];
- }
- __global.define = curDefine;
- return globalValue;
- };
- }
- }));
- };
- });
- /*
- SystemJS CommonJS Format
- */
- (function() {
- // CJS Module Format
- // require('...') || exports[''] = ... || exports.asd = ... || module.exports = ...
- var cjsExportsRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.]|module\.)exports\s*(\[['"]|\.)|(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])module\.exports\s*[=,]/;
- // RegEx adjusted from https://github.com/jbrantly/yabble/blob/master/lib/yabble.js#L339
- var cjsRequireRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF."'])require\s*\(\s*("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*')\s*\)/g;
- var commentRegEx = /(^|[^\\])(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
- var stringRegEx = /(?:"[^"\\\n\r]*(?:\\.[^"\\\n\r]*)*"|'[^'\\\n\r]*(?:\\.[^'\\\n\r]*)*')/g;
- function getCJSDeps(source) {
- cjsRequireRegEx.lastIndex = commentRegEx.lastIndex = stringRegEx.lastIndex = 0;
- var deps = [];
- var match;
- // track string and comment locations for unminified source
- var stringLocations = [], commentLocations = [];
- function inLocation(locations, match, starts) {
- var inLocation = false;
- for (var i = 0; i < locations.length; i++)
- if (locations[i][0] < match.index && locations[i][1] > match.index + (!starts ? match[0].length : 0))
- return true;
- return false;
- }
- if (source.length / source.split('\n').length < 200) {
- while (match = stringRegEx.exec(source))
- stringLocations.push([match.index, match.index + match[0].length]);
- while (match = commentRegEx.exec(source)) {
- // only track comments not starting in strings
- if (!inLocation(stringLocations, match, true))
- commentLocations.push([match.index, match.index + match[0].length]);
- }
- }
- while (match = cjsRequireRegEx.exec(source)) {
- // ensure we're not within a string or comment location
- if (!inLocation(stringLocations, match) && !inLocation(commentLocations, match))
- deps.push(match[1].substr(1, match[1].length - 2));
- }
- return deps;
- }
- if (typeof window != 'undefined' && typeof document != 'undefined' && window.location)
- var windowOrigin = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
- // include the node require since we're overriding it
- if (typeof require != 'undefined' && require.resolve && typeof process != 'undefined')
- SystemJSLoader.prototype._nodeRequire = require;
- var nodeCoreModules = ['assert', 'buffer', 'child_process', 'cluster', 'console', 'constants',
- 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'module', 'net', 'os', 'path',
- 'process', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'sys', 'timers',
- 'tls', 'tty', 'url', 'util', 'vm', 'zlib'];
- hook('normalize', function(normalize) {
- return function(name, parentName) {
- // dynamically load node-core modules when requiring `@node/fs` for example
- if (name.substr(0, 6) == '@node/' && nodeCoreModules.indexOf(name.substr(6)) != -1) {
- if (!this._nodeRequire)
- throw new TypeError('Can only load node core modules in Node.');
- this.set(name, this.newModule(getESModule(this._nodeRequire(name.substr(6)))));
- }
- return normalize.apply(this, arguments);
- };
- });
- hook('instantiate', function(instantiate) {
- return function(load) {
- var loader = this;
- if (!load.metadata.format) {
- cjsExportsRegEx.lastIndex = 0;
- cjsRequireRegEx.lastIndex = 0;
- if (cjsRequireRegEx.exec(load.source) || cjsExportsRegEx.exec(load.source))
- load.metadata.format = 'cjs';
- }
- if (load.metadata.format == 'cjs') {
- var metaDeps = load.metadata.deps;
- var deps = getCJSDeps(load.source);
- for (var g in load.metadata.globals)
- deps.push(load.metadata.globals[g]);
- var entry = createEntry();
- load.metadata.entry = entry;
- entry.deps = deps;
- entry.executingRequire = true;
- entry.execute = function(require, exports, module) {
- // ensure meta deps execute first
- for (var i = 0; i < metaDeps.length; i++)
- require(metaDeps[i]);
- var address = load.address || '';
- var dirname = address.split('/');
- dirname.pop();
- dirname = dirname.join('/');
- if (address.substr(0, 8) == 'file:///') {
- address = address.substr(7);
- dirname = dirname.substr(7);
- // on windows remove leading '/'
- if (isWindows) {
- address = address.substr(1);
- dirname = dirname.substr(1);
- }
- }
- else if (windowOrigin && address.substr(0, windowOrigin.length) === windowOrigin) {
- address = address.substr(windowOrigin.length);
- dirname = dirname.substr(windowOrigin.length);
- }
- // disable AMD detection
- var define = __global.define;
- __global.define = undefined;
- __global.__cjsWrapper = {
- exports: exports,
- args: [require, exports, module, address, dirname, __global, __global]
- };
- var globals = '';
- if (load.metadata.globals) {
- for (var g in load.metadata.globals)
- globals += 'var ' + g + ' = require("' + load.metadata.globals[g] + '");';
- }
- load.source = "(function(require, exports, module, __filename, __dirname, global, GLOBAL) {" + globals
- + load.source + "\n}).apply(__cjsWrapper.exports, __cjsWrapper.args);";
- __exec.call(loader, load);
- __global.__cjsWrapper = undefined;
- __global.define = define;
- };
- }
- return instantiate.call(loader, load);
- };
- });
- })();
- /*
- * AMD Helper function module
- * Separated into its own file as this is the part needed for full AMD support in SFX builds
- * NB since implementations have now diverged this can be merged back with amd.js
- */
- hookConstructor(function(constructor) {
- return function() {
- var loader = this;
- constructor.call(this);
- var commentRegEx = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
- var cjsRequirePre = "(?:^|[^$_a-zA-Z\\xA0-\\uFFFF.])";
- var cjsRequirePost = "\\s*\\(\\s*(\"([^\"]+)\"|'([^']+)')\\s*\\)";
- var fnBracketRegEx = /\(([^\)]*)\)/;
- var wsRegEx = /^\s+|\s+$/g;
- var requireRegExs = {};
- function getCJSDeps(source, requireIndex) {
- // remove comments
- source = source.replace(commentRegEx, '');
- // determine the require alias
- var params = source.match(fnBracketRegEx);
- var requireAlias = (params[1].split(',')[requireIndex] || 'require').replace(wsRegEx, '');
- // find or generate the regex for this requireAlias
- var requireRegEx = requireRegExs[requireAlias] || (requireRegExs[requireAlias] = new RegExp(cjsRequirePre + requireAlias + cjsRequirePost, 'g'));
- requireRegEx.lastIndex = 0;
- var deps = [];
- var match;
- while (match = requireRegEx.exec(source))
- deps.push(match[2] || match[3]);
- return deps;
- }
- /*
- AMD-compatible require
- To copy RequireJS, set window.require = window.requirejs = loader.amdRequire
- */
- function require(names, callback, errback, referer) {
- // in amd, first arg can be a config object... we just ignore
- if (typeof names == 'object' && !(names instanceof Array))
- return require.apply(null, Array.prototype.splice.call(arguments, 1, arguments.length - 1));
- // amd require
- if (typeof names == 'string' && typeof callback == 'function')
- names = [names];
- if (names instanceof Array) {
- var dynamicRequires = [];
- for (var i = 0; i < names.length; i++)
- dynamicRequires.push(loader['import'](names[i], referer));
- Promise.all(dynamicRequires).then(function(modules) {
- if (callback)
- callback.apply(null, modules);
- }, errback);
- }
- // commonjs require
- else if (typeof names == 'string') {
- var module = loader.get(loader.normalizeSync(names, referer));
- if (!module)
- throw new Error('Module not already loaded loading "' + names + '" from "' + referer + '".');
- return module.__useDefault ? module['default'] : module;
- }
- else
- throw new TypeError('Invalid require');
- }
- function define(name, deps, factory) {
- if (typeof name != 'string') {
- factory = deps;
- deps = name;
- name = null;
- }
- if (!(deps instanceof Array)) {
- factory = deps;
- deps = ['require', 'exports', 'module'].splice(0, factory.length);
- }
- if (typeof factory != 'function')
- factory = (function(factory) {
- return function() { return factory; }
- })(factory);
- // in IE8, a trailing comma becomes a trailing undefined entry
- if (deps[deps.length - 1] === undefined)
- deps.pop();
- // remove system dependencies
- var requireIndex, exportsIndex, moduleIndex;
- if ((requireIndex = indexOf.call(deps, 'require')) != -1) {
- deps.splice(requireIndex, 1);
- // only trace cjs requires for non-named
- // named defines assume the trace has already been done
- if (!name)
- deps = deps.concat(getCJSDeps(factory.toString(), requireIndex));
- }
- if ((exportsIndex = indexOf.call(deps, 'exports')) != -1)
- deps.splice(exportsIndex, 1);
- if ((moduleIndex = indexOf.call(deps, 'module')) != -1)
- deps.splice(moduleIndex, 1);
- function execute(req, exports, module) {
- var depValues = [];
- for (var i = 0; i < deps.length; i++)
- depValues.push(req(deps[i]));
- module.uri = module.id;
- module.config = function() {};
- // add back in system dependencies
- if (moduleIndex != -1)
- depValues.splice(moduleIndex, 0, module);
- if (exportsIndex != -1)
- depValues.splice(exportsIndex, 0, exports);
- if (requireIndex != -1) {
- function contextualRequire(names, callback, errback) {
- if (typeof names == 'string' && typeof callback != 'function')
- return req(names);
- return require.call(loader, names, callback, errback, module.id);
- }
- contextualRequire.toUrl = function(name) {
- // normalize without defaultJSExtensions
- var defaultJSExtension = loader.defaultJSExtensions && name.substr(name.length - 3, 3) != '.js';
- var url = loader.normalizeSync(name, module.id);
- if (defaultJSExtension && url.substr(url.length - 3, 3) == '.js')
- url = url.substr(0, url.length - 3);
- return url;
- };
- depValues.splice(requireIndex, 0, contextualRequire);
- }
- // set global require to AMD require
- var curRequire = __global.require;
- __global.require = require;
- var output = factory.apply(exportsIndex == -1 ? __global : exports, depValues);
- __global.require = curRequire;
- if (typeof output == 'undefined' && module)
- output = module.exports;
- if (typeof output != 'undefined')
- return output;
- }
- var entry = createEntry();
- entry.name = name && (loader.normalizeSync || loader.normalize).call(loader, name);
- entry.deps = deps;
- entry.execute = execute;
- loader.pushRegister_({
- amd: true,
- entry: entry
- });
- }
- define.amd = {};
- // reduction function to attach defines to a load record
- hook('reduceRegister_', function(reduceRegister) {
- return function(load, register) {
- // only handle AMD registers here
- if (!register || !register.amd)
- return reduceRegister.call(this, load, register);
- var curMeta = load && load.metadata;
- var entry = register.entry;
- if (curMeta)
- curMeta.format = 'amd';
- // anonymous define
- if (!entry.name) {
- if (!curMeta)
- throw new TypeError('Unexpected anonymous AMD define.');
- // already defined anonymously -> throw
- if (curMeta.entry)
- throw new TypeError('Multiple defines for anonymous module ' + load.name);
- curMeta.entry = entry;
- }
- // named define
- else {
- // if we don't have any other defines,
- // then let this be an anonymous define
- // this is just to support single modules of the form:
- // define('jquery')
- // still loading anonymously
- // because it is done widely enough to be useful
- // as soon as there is more than one define, this gets removed though
- if (curMeta) {
- if (!curMeta.entry && !curMeta.bundle)
- curMeta.entry = entry;
- else
- curMeta.entry = undefined;
- // note this is now a bundle
- curMeta.bundle = true;
- }
- // define the module through the register registry
- if (!(entry.name in this.defined))
- this.defined[entry.name] = entry;
- }
- };
- });
- // adds define as a global (potentially just temporarily)
- function createDefine() {
- // ensure no NodeJS environment detection
- var oldModule = __global.module;
- var oldExports = __global.exports;
- var oldDefine = __global.define;
- __global.module = undefined;
- __global.exports = undefined;
- __global.define = define;
- return function() {
- __global.define = oldDefine;
- __global.module = oldModule;
- __global.exports = oldExports;
- };
- }
- loader.set('@@amd-helpers', loader.newModule({
- createDefine: createDefine,
- require: require,
- define: define
- }));
- loader.amdDefine = define;
- loader.amdRequire = require;
- };
- });/*
- SystemJS AMD Format
- Provides the AMD module format definition at System.format.amd
- as well as a RequireJS-style require on System.require
- */
- (function() {
- // AMD Module Format Detection RegEx
- // define([.., .., ..], ...)
- // define(varName); || define(function(require, exports) {}); || define({})
- 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]*\))/;
- hook('fetch', function(fetch) {
- return function(load) {
- if (load.metadata.format === 'amd'
- && !load.metadata.authorization
- && load.metadata.scriptLoad !== false)
- load.metadata.scriptLoad = true;
- // script load implies define global leak
- if (load.metadata.scriptLoad && isBrowser)
- this.get('@@amd-helpers').createDefine();
- return fetch.call(this, load);
- };
- });
- hook('instantiate', function(instantiate) {
- return function(load) {
- var loader = this;
- if (load.metadata.format == 'amd' || !load.metadata.format && load.source.match(amdRegEx)) {
- load.metadata.format = 'amd';
- if (!loader.builder && loader.execute !== false) {
- var removeDefine = this.get('@@amd-helpers').createDefine();
- try {
- __exec.call(loader, load);
- }
- finally {
- removeDefine();
- }
- if (!load.metadata.entry && !load.metadata.bundle)
- throw new TypeError('AMD module ' + load.name + ' did not define');
- }
- else {
- load.metadata.execute = function() {
- return load.metadata.builderExecute.apply(this, arguments);
- };
- }
- }
- return instantiate.call(loader, load);
- };
- });
- })();
- /*
- SystemJS Loader Plugin Support
- Supports plugin loader syntax with "!", or via metadata.loader
- The plugin name is loaded as a module itself, and can override standard loader hooks
- for the plugin resource. See the plugin section of the systemjs readme.
- */
- (function() {
- // sync or async plugin normalize function
- function normalizePlugin(normalize, name, parentName, isPlugin, sync) {
- var loader = this;
- // if parent is a plugin, normalize against the parent plugin argument only
- if (parentName) {
- var parentPluginIndex;
- if (loader.pluginFirst) {
- if ((parentPluginIndex = parentName.lastIndexOf('!')) != -1)
- parentName = parentName.substr(parentPluginIndex + 1);
- }
- else {
- if ((parentPluginIndex = parentName.indexOf('!')) != -1)
- parentName = parentName.substr(0, parentPluginIndex);
- }
- }
- // if this is a plugin, normalize the plugin name and the argument
- var pluginIndex = name.lastIndexOf('!');
- if (pluginIndex != -1) {
- var argumentName;
- var pluginName;
- if (loader.pluginFirst) {
- argumentName = name.substr(pluginIndex + 1);
- pluginName = name.substr(0, pluginIndex);
- }
- else {
- argumentName = name.substr(0, pluginIndex);
- pluginName = name.substr(pluginIndex + 1) || argumentName.substr(argumentName.lastIndexOf('.') + 1);
- }
- // note if normalize will add a default js extension
- // if so, remove for backwards compat
- // this is strange and sucks, but will be deprecated
- var defaultExtension = loader.defaultJSExtensions && argumentName.substr(argumentName.length - 3, 3) != '.js';
- // put name back together after parts have been normalized
- function normalizePluginParts(argumentName, pluginName) {
- if (defaultExtension && argumentName.substr(argumentName.length - 3, 3) == '.js')
- argumentName = argumentName.substr(0, argumentName.length - 3);
- if (loader.pluginFirst) {
- return pluginName + '!' + argumentName;
- }
- else {
- return argumentName + '!' + pluginName;
- }
- }
- if (sync) {
- argumentName = loader.normalizeSync(argumentName, parentName);
- pluginName = loader.normalizeSync(pluginName, parentName);
- return normalizePluginParts(argumentName, pluginName);
- }
- else {
- // third argument represents that this is a plugin call
- // which in turn will skip default extension adding within packages
- return Promise.all([
- loader.normalize(argumentName, parentName, true),
- loader.normalize(pluginName, parentName, true)
- ])
- .then(function(normalized) {
- return normalizePluginParts(normalized[0], normalized[1]);
- });
- }
- }
- else {
- return normalize.call(loader, name, parentName, isPlugin);
- }
- }
- // async plugin normalize
- hook('normalize', function(normalize) {
- return function(name, parentName, isPlugin) {
- return normalizePlugin.call(this, normalize, name, parentName, isPlugin, false);
- };
- });
- hook('normalizeSync', function(normalizeSync) {
- return function(name, parentName, isPlugin) {
- return normalizePlugin.call(this, normalizeSync, name, parentName, isPlugin, true);
- };
- });
- hook('locate', function(locate) {
- return function(load) {
- var loader = this;
- var name = load.name;
- // plugin syntax
- var pluginSyntaxIndex;
- if (loader.pluginFirst) {
- if ((pluginSyntaxIndex = name.indexOf('!')) != -1) {
- load.metadata.loader = name.substr(0, pluginSyntaxIndex);
- load.name = name.substr(pluginSyntaxIndex + 1);
- }
- }
- else {
- if ((pluginSyntaxIndex = name.lastIndexOf('!')) != -1) {
- load.metadata.loader = name.substr(pluginSyntaxIndex + 1);
- load.name = name.substr(0, pluginSyntaxIndex);
- }
- }
- return locate.call(loader, load)
- .then(function(address) {
- var plugin = load.metadata.loader;
- if (!plugin)
- return address;
- // only fetch the plugin itself if this name isn't defined
- if (loader.defined && loader.defined[name])
- return address;
- var pluginLoader = loader.pluginLoader || loader;
- // load the plugin module and run standard locate
- return pluginLoader['import'](plugin)
- .then(function(loaderModule) {
- // store the plugin module itself on the metadata
- load.metadata.loaderModule = loaderModule;
- load.address = address;
- if (loaderModule.locate)
- return loaderModule.locate.call(loader, load);
- return address;
- });
- });
- };
- });
- hook('fetch', function(fetch) {
- return function(load) {
- var loader = this;
- if (load.metadata.loaderModule && load.metadata.loaderModule.fetch) {
- load.metadata.scriptLoad = false;
- return load.metadata.loaderModule.fetch.call(loader, load, function(load) {
- return fetch.call(loader, load);
- });
- }
- else {
- return fetch.call(loader, load);
- }
- };
- });
- hook('translate', function(translate) {
- return function(load) {
- var loader = this;
- if (load.metadata.loaderModule && load.metadata.loaderModule.translate)
- return Promise.resolve(load.metadata.loaderModule.translate.call(loader, load)).then(function(result) {
- if (typeof result == 'string')
- load.source = result;
- return translate.call(loader, load);
- });
- else
- return translate.call(loader, load);
- };
- });
- hook('instantiate', function(instantiate) {
- return function(load) {
- var loader = this;
- /*
- * Source map sanitization for load.metadata.sourceMap
- * Used to set browser and build-level source maps for
- * translated sources in a general way.
- */
- var sourceMap = load.metadata.sourceMap;
- // if an object not a JSON string do sanitizing
- if (sourceMap && typeof sourceMap == 'object') {
- var originalName = load.name.split('!')[0];
- // force set the filename of the original file
- sourceMap.file = originalName + '!transpiled';
- // force set the sources list if only one source
- if (!sourceMap.sources || sourceMap.sources.length == 1)
- sourceMap.sources = [originalName];
- load.metadata.sourceMap = JSON.stringify(sourceMap);
- }
- if (load.metadata.loaderModule && load.metadata.loaderModule.instantiate)
- return Promise.resolve(load.metadata.loaderModule.instantiate.call(loader, load)).then(function(result) {
- load.metadata.entry = createEntry();
- load.metadata.entry.execute = function() {
- return result;
- }
- load.metadata.entry.deps = load.metadata.deps;
- load.metadata.format = 'defined';
- return instantiate.call(loader, load);
- });
- else
- return instantiate.call(loader, load);
- };
- });
- })();
- /*
- * Conditions Extension
- *
- * Allows a condition module to alter the resolution of an import via syntax:
- *
- * import $ from 'jquery/#{browser}';
- *
- * Will first load the module 'browser' via `System.import('browser')` and
- * take the default export of that module.
- * If the default export is not a string, an error is thrown.
- *
- * We then substitute the string into the require to get the conditional resolution
- * enabling environment-specific variations like:
- *
- * import $ from 'jquery/ie'
- * import $ from 'jquery/firefox'
- * import $ from 'jquery/chrome'
- * import $ from 'jquery/safari'
- *
- * It can be useful for a condition module to define multiple conditions.
- * This can be done via the `|` modifier to specify an export member expression:
- *
- * import 'jquery/#{./browser.js|grade.version}'
- *
- * Where the `grade` export `version` member in the `browser.js` module is substituted.
- *
- *
- * Boolean Conditionals
- *
- * For polyfill modules, that are used as imports but have no module value,
- * a binary conditional allows a module not to be loaded at all if not needed:
- *
- * import 'es5-shim#?./conditions.js|needs-es5shim'
- *
- * These conditions can also be negated via:
- *
- * import 'es5-shim#?~./conditions.js|es6'
- *
- */
- function parseCondition(condition) {
- var conditionExport, conditionModule, negation;
- var negation = condition[0] == '~';
- var conditionExportIndex = condition.lastIndexOf('|');
- if (conditionExportIndex != -1) {
- conditionExport = condition.substr(conditionExportIndex + 1);
- conditionModule = condition.substr(negation, conditionExportIndex - negation) || '@system-env';
- }
- else {
- conditionExport = null;
- conditionModule = condition.substr(negation);
- }
- return {
- module: conditionModule,
- prop: conditionExport,
- negate: negation
- };
- }
- function serializeCondition(conditionObj) {
- return (conditionObj.negate ? '~' : '') + conditionObj.module + (conditionObj.prop ? '|' + conditionObj.prop : '');
- }
- function resolveCondition(conditionObj, parentName, bool) {
- return this['import'](conditionObj.module, parentName)
- .then(function(m) {
- if (conditionObj.prop)
- m = readMemberExpression(conditionObj.prop, m);
- else if (typeof m == 'object' && m + '' == 'Module')
- m = m['default'];
- return conditionObj.negate ? !m : m;
- });
- }
- var interpolationRegEx = /#\{[^\}]+\}/;
- function interpolateConditional(name, parentName) {
- // first we normalize the conditional
- var conditionalMatch = name.match(interpolationRegEx);
- if (!conditionalMatch)
- return Promise.resolve(name);
- var conditionObj = parseCondition(conditionalMatch[0].substr(2, conditionalMatch[0].length - 3));
- // in builds, return normalized conditional
- if (this.builder)
- return this['normalize'](conditionObj.module, parentName)
- .then(function(conditionModule) {
- conditionObj.module = conditionModule;
- return name.replace(interpolationRegEx, '#{' + serializeCondition(conditionObj) + '}');
- });
- return resolveCondition.call(this, conditionObj, parentName, false)
- .then(function(conditionValue) {
- if (typeof conditionValue !== 'string')
- throw new TypeError('The condition value for ' + name + ' doesn\'t resolve to a string.');
- if (conditionValue.indexOf('/') != -1)
- throw new TypeError('Unabled to interpolate conditional ' + name + (parentName ? ' in ' + parentName : '') + '\n\tThe condition value ' + conditionValue + ' cannot contain a "/" separator.');
- return name.replace(interpolationRegEx, conditionValue);
- });
- }
- function booleanConditional(name, parentName) {
- // first we normalize the conditional
- var booleanIndex = name.lastIndexOf('#?');
- if (booleanIndex == -1)
- return Promise.resolve(name);
- var conditionObj = parseCondition(name.substr(booleanIndex + 2));
- // in builds, return normalized conditional
- if (this.builder)
- return this['normalize'](conditionObj.module, parentName)
- .then(function(conditionModule) {
- conditionObj.module = conditionModule;
- return name.substr(0, booleanIndex) + '#?' + serializeCondition(conditionObj);
- });
- return resolveCondition.call(this, conditionObj, parentName, true)
- .then(function(conditionValue) {
- return conditionValue ? name.substr(0, booleanIndex) : '@empty';
- });
- }
- hookConstructor(function(constructor) {
- return function() {
- constructor.call(this);
- // standard environment module, starting small as backwards-compat matters!
- this.set('@system-env', this.newModule({
- browser: isBrowser,
- node: !!this._nodeRequire
- }));
- };
- });
- // no normalizeSync
- hook('normalize', function(normalize) {
- return function(name, parentName, parentAddress) {
- var loader = this;
- return booleanConditional.call(loader, name, parentName)
- .then(function(name) {
- return normalize.call(loader, name, parentName, parentAddress);
- })
- .then(function(normalized) {
- return interpolateConditional.call(loader, normalized, parentName);
- });
- };
- });
- /*
- * Alias Extension
- *
- * Allows a module to be a plain copy of another module by module name
- *
- * System.meta['mybootstrapalias'] = { alias: 'bootstrap' };
- *
- */
- (function() {
- // aliases
- hook('fetch', function(fetch) {
- return function(load) {
- var alias = load.metadata.alias;
- var aliasDeps = load.metadata.deps || [];
- if (alias) {
- load.metadata.format = 'defined';
- this.defined[load.name] = {
- declarative: true,
- deps: aliasDeps.concat([alias]),
- declare: function(_export) {
- return {
- setters: [function(module) {
- for (var p in module)
- _export(p, module[p]);
- }],
- execute: function() {}
- };
- }
- };
- return '';
- }
- return fetch.call(this, load);
- };
- });
- })();/*
- * Meta Extension
- *
- * Sets default metadata on a load record (load.metadata) from
- * loader.metadata via System.meta function.
- *
- *
- * Also provides an inline meta syntax for module meta in source.
- *
- * Eg:
- *
- * loader.meta({
- * 'my/module': { deps: ['jquery'] }
- * 'my/*': { format: 'amd' }
- * });
- *
- * Which in turn populates loader.metadata.
- *
- * load.metadata.deps and load.metadata.format will then be set
- * for 'my/module'
- *
- * The same meta could be set with a my/module.js file containing:
- *
- * my/module.js
- * "format amd";
- * "deps[] jquery";
- * "globals.some value"
- * console.log('this is my/module');
- *
- * Configuration meta always takes preference to inline meta.
- *
- * Multiple matches in wildcards are supported and ammend the meta.
- *
- *
- * The benefits of the function form is that paths are URL-normalized
- * supporting say
- *
- * loader.meta({ './app': { format: 'cjs' } });
- *
- * Instead of needing to set against the absolute URL (https://site.com/app.js)
- *
- */
- (function() {
- hookConstructor(function(constructor) {
- return function() {
- this.meta = {};
- constructor.call(this);
- };
- });
- hook('locate', function(locate) {
- return function(load) {
- var meta = this.meta;
- var name = load.name;
- // NB for perf, maybe introduce a fast-path wildcard lookup cache here
- // which is checked first
- // apply wildcard metas
- var bestDepth = 0;
- var wildcardIndex;
- for (var module in meta) {
- wildcardIndex = module.indexOf('*');
- if (wildcardIndex === -1)
- continue;
- if (module.substr(0, wildcardIndex) === name.substr(0, wildcardIndex)
- && module.substr(wildcardIndex + 1) === name.substr(name.length - module.length + wildcardIndex + 1)) {
- var depth = module.split('/').length;
- if (depth > bestDepth)
- bestDepth = depth;
- extendMeta(load.metadata, meta[module], bestDepth != depth);
- }
- }
- // apply exact meta
- if (meta[name])
- extendMeta(load.metadata, meta[name]);
- return locate.call(this, load);
- };
- });
- // detect any meta header syntax
- // only set if not already set
- var metaRegEx = /^(\s*\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)+/;
- var metaPartRegEx = /\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\/\/[^\n]*|"[^"]+"\s*;?|'[^']+'\s*;?/g;
- function setMetaProperty(target, p, value) {
- var pParts = p.split('.');
- var curPart;
- while (pParts.length > 1) {
- curPart = pParts.shift();
- target = target[curPart] = target[curPart] || {};
- }
- curPart = pParts.shift();
- if (!(curPart in target))
- target[curPart] = value;
- }
- hook('translate', function(translate) {
- return function(load) {
- // NB meta will be post-translate pending transpiler conversion to plugins
- var meta = load.source.match(metaRegEx);
- if (meta) {
- var metaParts = meta[0].match(metaPartRegEx);
- for (var i = 0; i < metaParts.length; i++) {
- var curPart = metaParts[i];
- var len = curPart.length;
- var firstChar = curPart.substr(0, 1);
- if (curPart.substr(len - 1, 1) == ';')
- len--;
- if (firstChar != '"' && firstChar != "'")
- continue;
- var metaString = curPart.substr(1, curPart.length - 3);
- var metaName = metaString.substr(0, metaString.indexOf(' '));
- if (metaName) {
- var metaValue = metaString.substr(metaName.length + 1, metaString.length - metaName.length - 1);
- if (metaName.substr(metaName.length - 2, 2) == '[]') {
- metaName = metaName.substr(0, metaName.length - 2);
- load.metadata[metaName] = load.metadata[metaName] || [];
- load.metadata[metaName].push(metaValue);
- }
- else if (load.metadata[metaName] instanceof Array) {
- // temporary backwards compat for previous "deps" syntax
- warn.call(this, 'Module ' + load.name + ' contains deprecated "deps ' + metaValue + '" meta syntax.\nThis should be updated to "deps[] ' + metaValue + '" for pushing to array meta.');
- load.metadata[metaName].push(metaValue);
- }
- else {
- setMetaProperty(load.metadata, metaName, metaValue);
- }
- }
- else {
- load.metadata[metaString] = true;
- }
- }
- }
- return translate.call(this, load);
- };
- });
- })();
- /*
- System bundles
- Allows a bundle module to be specified which will be dynamically
- loaded before trying to load a given module.
- For example:
- System.bundles['mybundle'] = ['jquery', 'bootstrap/js/bootstrap']
- Will result in a load to "mybundle" whenever a load to "jquery"
- or "bootstrap/js/bootstrap" is made.
- In this way, the bundle becomes the request that provides the module
- */
- function getBundleFor(loader, name) {
- // check if it is in an already-loaded bundle
- for (var b in loader.loadedBundles_)
- if (indexOf.call(loader.bundles[b], name) != -1)
- return Promise.resolve(b);
- // check if it is a new bundle
- for (var b in loader.bundles)
- if (indexOf.call(loader.bundles[b], name) != -1)
- return loader.normalize(b)
- .then(function(normalized) {
- loader.bundles[normalized] = loader.bundles[b];
- loader.loadedBundles_[normalized] = true;
- return normalized;
- });
- return Promise.resolve();
- }
- (function() {
- // bundles support (just like RequireJS)
- // bundle name is module name of bundle itself
- // bundle is array of modules defined by the bundle
- // when a module in the bundle is requested, the bundle is loaded instead
- // of the form System.bundles['mybundle'] = ['jquery', 'bootstrap/js/bootstrap']
- hookConstructor(function(constructor) {
- return function() {
- constructor.call(this);
- this.bundles = {};
- this.loadedBundles_ = {};
- };
- });
- // assign bundle metadata for bundle loads
- hook('locate', function(locate) {
- return function(load) {
- var loader = this;
- if (load.name in loader.loadedBundles_ || load.name in loader.bundles)
- load.metadata.bundle = true;
- // if not already defined, check if we need to load a bundle
- if (!(load.name in loader.defined))
- return getBundleFor(loader, load.name)
- .then(function(bundleName) {
- if (bundleName)
- return loader.load(bundleName);
- })
- .then(function() {
- return locate.call(loader, load);
- });
- return locate.call(this, load);
- };
- });
- })();
- /*
- * Dependency Tree Cache
- *
- * Allows a build to pre-populate a dependency trace tree on the loader of
- * the expected dependency tree, to be loaded upfront when requesting the
- * module, avoinding the n round trips latency of module loading, where
- * n is the dependency tree depth.
- *
- * eg:
- * System.depCache = {
- * 'app': ['normalized', 'deps'],
- * 'normalized': ['another'],
- * 'deps': ['tree']
- * };
- *
- * System.import('app')
- * // simultaneously starts loading all of:
- * // 'normalized', 'deps', 'another', 'tree'
- * // before "app" source is even loaded
- */
- (function() {
- hookConstructor(function(constructor) {
- return function() {
- constructor.call(this);
- this.depCache = {};
- }
- });
- hook('locate', function(locate) {
- return function(load) {
- var loader = this;
- // load direct deps, in turn will pick up their trace trees
- var deps = loader.depCache[load.name];
- if (deps)
- for (var i = 0; i < deps.length; i++)
- loader['import'](deps[i]);
- return locate.call(loader, load);
- };
- });
- })();
- System = new SystemJSLoader();
- System.version = '0.19.6 Standard';
- // -- exporting --
- if (typeof exports === 'object')
- module.exports = Loader;
- __global.Reflect = __global.Reflect || {};
- __global.Reflect.Loader = __global.Reflect.Loader || Loader;
- __global.Reflect.global = __global.Reflect.global || __global;
- __global.LoaderPolyfill = Loader;
- if (!System) {
- System = new SystemLoader();
- System.constructor = SystemLoader;
- }
- if (typeof exports === 'object')
- module.exports = System;
- __global.System = System;
- })(typeof self != 'undefined' ? self : global);}
- // auto-load Promise and URL polyfills if needed in the browser
- try {
- var hasURL = typeof URLPolyfill != 'undefined' || new URL('test:///').protocol == 'test:';
- }
- catch(e) {}
- if (typeof Promise === 'undefined' || !hasURL) {
- // document.write
- if (typeof document !== 'undefined') {
- var scripts = document.getElementsByTagName('script');
- $__curScript = scripts[scripts.length - 1];
- var curPath = $__curScript.src;
- var basePath = curPath.substr(0, curPath.lastIndexOf('/') + 1);
- window.systemJSBootstrap = bootstrap;
- document.write(
- '<' + 'script type="text/javascript" src="' + basePath + 'system-polyfills.js">' + '<' + '/script>'
- );
- }
- // importScripts
- else if (typeof importScripts !== 'undefined') {
- var basePath = '';
- try {
- throw new Error('_');
- } catch (e) {
- e.stack.replace(/(?:at|@).*(http.+):[\d]+:[\d]+/, function(m, url) {
- basePath = url.replace(/\/[^\/]*$/, '/');
- });
- }
- importScripts(basePath + 'system-polyfills.js');
- bootstrap();
- }
- else {
- bootstrap();
- }
- }
- else {
- bootstrap();
- }
- })();
|