12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049 |
- /*
- * SystemJS v0.21.6 Dev
- */
- (function () {
- 'use strict';
- /*
- * Environment
- */
- var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
- var isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
- var isWindows = typeof process !== 'undefined' && typeof process.platform === 'string' && process.platform.match(/^win/);
- var envGlobal = typeof self !== 'undefined' ? self : global;
- /*
- * Simple Symbol() shim
- */
- var hasSymbol = typeof Symbol !== 'undefined';
- function createSymbol (name) {
- return hasSymbol ? Symbol() : '@@' + name;
- }
- var toStringTag = hasSymbol && Symbol.toStringTag;
- /*
- * Environment baseURI
- */
- 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;
- }
- }
- else if (typeof location != 'undefined') {
- baseURI = location.href;
- }
- // sanitize out the hash and querystring
- if (baseURI) {
- baseURI = baseURI.split('#')[0].split('?')[0];
- var slashIndex = baseURI.lastIndexOf('/');
- if (slashIndex !== -1)
- baseURI = baseURI.substr(0, slashIndex + 1);
- }
- else if (typeof process !== 'undefined' && process.cwd) {
- baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd();
- if (isWindows)
- baseURI = baseURI.replace(/\\/g, '/');
- }
- else {
- throw new TypeError('No environment baseURI');
- }
- // ensure baseURI has trailing "/"
- if (baseURI[baseURI.length - 1] !== '/')
- baseURI += '/';
- /*
- * LoaderError with chaining for loader stacks
- */
- var errArgs = new Error(0, '_').fileName == '_';
- function LoaderError__Check_error_message_for_loader_stack (childErr, newMessage) {
- // Convert file:/// URLs to paths in Node
- if (!isBrowser)
- newMessage = newMessage.replace(isWindows ? /file:\/\/\//g : /file:\/\//g, '');
- var message = (childErr.message || childErr) + '\n ' + newMessage;
- var err;
- if (errArgs && childErr.fileName)
- err = new Error(message, childErr.fileName, childErr.lineNumber);
- else
- err = new Error(message);
- var stack = childErr.originalErr ? childErr.originalErr.stack : childErr.stack;
- if (isNode)
- // node doesn't show the message otherwise
- err.stack = message + '\n ' + stack;
- else
- err.stack = stack;
- err.originalErr = childErr.originalErr || childErr;
- return err;
- }
- /*
- * Optimized URL normalization assuming a syntax-valid URL parent
- */
- function throwResolveError (relUrl, parentUrl) {
- throw new RangeError('Unable to resolve "' + relUrl + '" to ' + parentUrl);
- }
- var backslashRegEx = /\\/g;
- function resolveIfNotPlain (relUrl, parentUrl) {
- if (relUrl[0] === ' ' || relUrl[relUrl.length - 1] === ' ')
- relUrl = relUrl.trim();
- var parentProtocol = parentUrl && parentUrl.substr(0, parentUrl.indexOf(':') + 1);
- var firstChar = relUrl[0];
- var secondChar = relUrl[1];
- // protocol-relative
- if (firstChar === '/' && secondChar === '/') {
- if (!parentProtocol)
- throwResolveError(relUrl, parentUrl);
- if (relUrl.indexOf('\\') !== -1)
- relUrl = relUrl.replace(backslashRegEx, '/');
- return parentProtocol + relUrl;
- }
- // relative-url
- else if (firstChar === '.' && (secondChar === '/' || secondChar === '.' && (relUrl[2] === '/' || relUrl.length === 2 && (relUrl += '/')) ||
- relUrl.length === 1 && (relUrl += '/')) ||
- firstChar === '/') {
- if (relUrl.indexOf('\\') !== -1)
- relUrl = relUrl.replace(backslashRegEx, '/');
- var parentIsPlain = !parentProtocol || parentUrl[parentProtocol.length] !== '/';
- // read pathname from parent if a URL
- // pathname taken to be part after leading "/"
- var pathname;
- if (parentIsPlain) {
- // resolving to a plain parent -> skip standard URL prefix, and treat entire parent as pathname
- if (parentUrl === undefined)
- throwResolveError(relUrl, parentUrl);
- pathname = parentUrl;
- }
- else if (parentUrl[parentProtocol.length + 1] === '/') {
- // resolving to a :// so we need to read out the auth and host
- if (parentProtocol !== 'file:') {
- pathname = parentUrl.substr(parentProtocol.length + 2);
- pathname = pathname.substr(pathname.indexOf('/') + 1);
- }
- else {
- pathname = parentUrl.substr(8);
- }
- }
- else {
- // resolving to :/ so pathname is the /... part
- pathname = parentUrl.substr(parentProtocol.length + 1);
- }
- if (firstChar === '/') {
- if (parentIsPlain)
- throwResolveError(relUrl, parentUrl);
- else
- return parentUrl.substr(0, parentUrl.length - pathname.length - 1) + relUrl;
- }
- // join together and split for removal of .. and . segments
- // looping the string instead of anything fancy for perf reasons
- // '../../../../../z' resolved to 'x/y' is just 'z' regardless of parentIsPlain
- var segmented = pathname.substr(0, pathname.lastIndexOf('/') + 1) + relUrl;
- var output = [];
- var segmentIndex = -1;
- for (var i = 0; i < segmented.length; i++) {
- // busy reading a segment - only terminate on '/'
- if (segmentIndex !== -1) {
- if (segmented[i] === '/') {
- output.push(segmented.substring(segmentIndex, i + 1));
- segmentIndex = -1;
- }
- continue;
- }
- // new segment - check if it is relative
- if (segmented[i] === '.') {
- // ../ segment
- if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
- output.pop();
- i += 2;
- }
- // ./ segment
- else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
- i += 1;
- }
- else {
- // the start of a new segment as below
- segmentIndex = i;
- continue;
- }
- // this is the plain URI backtracking error (../, package:x -> error)
- if (parentIsPlain && output.length === 0)
- throwResolveError(relUrl, parentUrl);
- continue;
- }
- // it is the start of a new segment
- segmentIndex = i;
- }
- // finish reading out the last segment
- if (segmentIndex !== -1)
- output.push(segmented.substr(segmentIndex));
- return parentUrl.substr(0, parentUrl.length - pathname.length) + output.join('');
- }
- // sanitizes and verifies (by returning undefined if not a valid URL-like form)
- // Windows filepath compatibility is an added convenience here
- var protocolIndex = relUrl.indexOf(':');
- if (protocolIndex !== -1) {
- if (isNode) {
- // C:\x becomes file:///c:/x (we don't support C|\x)
- if (relUrl[1] === ':' && relUrl[2] === '\\' && relUrl[0].match(/[a-z]/i))
- return 'file:///' + relUrl.replace(backslashRegEx, '/');
- }
- return relUrl;
- }
- }
- var resolvedPromise = Promise.resolve();
- /*
- * Simple Array values shim
- */
- function arrayValues (arr) {
- if (arr.values)
- return arr.values();
- if (typeof Symbol === 'undefined' || !Symbol.iterator)
- throw new Error('Symbol.iterator not supported in this browser');
- var iterable = {};
- iterable[Symbol.iterator] = function () {
- var keys = Object.keys(arr);
- var keyIndex = 0;
- return {
- next: function () {
- if (keyIndex < keys.length)
- return {
- value: arr[keys[keyIndex++]],
- done: false
- };
- else
- return {
- value: undefined,
- done: true
- };
- }
- };
- };
- return iterable;
- }
- /*
- * 3. Reflect.Loader
- *
- * We skip the entire native internal pipeline, just providing the bare API
- */
- // 3.1.1
- function Loader () {
- this.registry = new Registry();
- }
- // 3.3.1
- Loader.prototype.constructor = Loader;
- function ensureInstantiated (module) {
- if (module === undefined)
- return;
- if (module instanceof ModuleNamespace === false && module[toStringTag] !== 'module')
- throw new TypeError('Module instantiation did not return a valid namespace object.');
- return module;
- }
- // 3.3.2
- Loader.prototype.import = function (key, parent) {
- if (typeof key !== 'string')
- throw new TypeError('Loader import method must be passed a module key string');
- // custom resolveInstantiate combined hook for better perf
- var loader = this;
- return resolvedPromise
- .then(function () {
- return loader[RESOLVE_INSTANTIATE](key, parent);
- })
- .then(ensureInstantiated)
- //.then(Module.evaluate)
- .catch(function (err) {
- throw LoaderError__Check_error_message_for_loader_stack(err, 'Loading ' + key + (parent ? ' from ' + parent : ''));
- });
- };
- // 3.3.3
- var RESOLVE = Loader.resolve = createSymbol('resolve');
- /*
- * Combined resolve / instantiate hook
- *
- * Not in current reduced spec, but necessary to separate RESOLVE from RESOLVE + INSTANTIATE as described
- * in the spec notes of this repo to ensure that loader.resolve doesn't instantiate when not wanted.
- *
- * We implement RESOLVE_INSTANTIATE as a single hook instead of a separate INSTANTIATE in order to avoid
- * the need for double registry lookups as a performance optimization.
- */
- var RESOLVE_INSTANTIATE = Loader.resolveInstantiate = createSymbol('resolveInstantiate');
- // default resolveInstantiate is just to call resolve and then get from the registry
- // this provides compatibility for the resolveInstantiate optimization
- Loader.prototype[RESOLVE_INSTANTIATE] = function (key, parent) {
- var loader = this;
- return loader.resolve(key, parent)
- .then(function (resolved) {
- return loader.registry.get(resolved);
- });
- };
- function ensureResolution (resolvedKey) {
- if (resolvedKey === undefined)
- throw new RangeError('No resolution found.');
- return resolvedKey;
- }
- Loader.prototype.resolve = function (key, parent) {
- var loader = this;
- return resolvedPromise
- .then(function() {
- return loader[RESOLVE](key, parent);
- })
- .then(ensureResolution)
- .catch(function (err) {
- throw LoaderError__Check_error_message_for_loader_stack(err, 'Resolving ' + key + (parent ? ' to ' + parent : ''));
- });
- };
- // 3.3.4 (import without evaluate)
- // this is not documented because the use of deferred evaluation as in Module.evaluate is not
- // documented, as it is not considered a stable feature to be encouraged
- // Loader.prototype.load may well be deprecated if this stays disabled
- /* Loader.prototype.load = function (key, parent) {
- return Promise.resolve(this[RESOLVE_INSTANTIATE](key, parent || this.key))
- .catch(function (err) {
- throw addToError(err, 'Loading ' + key + (parent ? ' from ' + parent : ''));
- });
- }; */
- /*
- * 4. Registry
- *
- * Instead of structuring through a Map, just use a dictionary object
- * We throw for construction attempts so this doesn't affect the public API
- *
- * Registry has been adjusted to use Namespace objects over ModuleStatus objects
- * as part of simplifying loader API implementation
- */
- var iteratorSupport = typeof Symbol !== 'undefined' && Symbol.iterator;
- var REGISTRY = createSymbol('registry');
- function Registry() {
- this[REGISTRY] = {};
- }
- // 4.4.1
- if (iteratorSupport) {
- // 4.4.2
- Registry.prototype[Symbol.iterator] = function () {
- return this.entries()[Symbol.iterator]();
- };
- // 4.4.3
- Registry.prototype.entries = function () {
- var registry = this[REGISTRY];
- return arrayValues(Object.keys(registry).map(function (key) {
- return [key, registry[key]];
- }));
- };
- }
- // 4.4.4
- Registry.prototype.keys = function () {
- return arrayValues(Object.keys(this[REGISTRY]));
- };
- // 4.4.5
- Registry.prototype.values = function () {
- var registry = this[REGISTRY];
- return arrayValues(Object.keys(registry).map(function (key) {
- return registry[key];
- }));
- };
- // 4.4.6
- Registry.prototype.get = function (key) {
- return this[REGISTRY][key];
- };
- // 4.4.7
- Registry.prototype.set = function (key, namespace) {
- if (!(namespace instanceof ModuleNamespace || namespace[toStringTag] === 'module'))
- throw new Error('Registry must be set with an instance of Module Namespace');
- this[REGISTRY][key] = namespace;
- return this;
- };
- // 4.4.8
- Registry.prototype.has = function (key) {
- return Object.hasOwnProperty.call(this[REGISTRY], key);
- };
- // 4.4.9
- Registry.prototype.delete = function (key) {
- if (Object.hasOwnProperty.call(this[REGISTRY], key)) {
- delete this[REGISTRY][key];
- return true;
- }
- return false;
- };
- /*
- * Simple ModuleNamespace Exotic object based on a baseObject
- * We export this for allowing a fast-path for module namespace creation over Module descriptors
- */
- // var EVALUATE = createSymbol('evaluate');
- var BASE_OBJECT = createSymbol('baseObject');
- // 8.3.1 Reflect.Module
- /*
- * Best-effort simplified non-spec implementation based on
- * a baseObject referenced via getters.
- *
- * Allows:
- *
- * loader.registry.set('x', new Module({ default: 'x' }));
- *
- * Optional evaluation function provides experimental Module.evaluate
- * support for non-executed modules in registry.
- */
- function ModuleNamespace (baseObject/*, evaluate*/) {
- Object.defineProperty(this, BASE_OBJECT, {
- value: baseObject
- });
- // evaluate defers namespace population
- /* if (evaluate) {
- Object.defineProperty(this, EVALUATE, {
- value: evaluate,
- configurable: true,
- writable: true
- });
- }
- else { */
- Object.keys(baseObject).forEach(extendNamespace, this);
- //}
- }// 8.4.2
- ModuleNamespace.prototype = Object.create(null);
- if (toStringTag)
- Object.defineProperty(ModuleNamespace.prototype, toStringTag, {
- value: 'Module'
- });
- function extendNamespace (key) {
- Object.defineProperty(this, key, {
- enumerable: true,
- get: function () {
- return this[BASE_OBJECT][key];
- }
- });
- }
- /* function doEvaluate (evaluate, context) {
- try {
- evaluate.call(context);
- }
- catch (e) {
- return e;
- }
- }
- // 8.4.1 Module.evaluate... not documented or used because this is potentially unstable
- Module.evaluate = function (ns) {
- var evaluate = ns[EVALUATE];
- if (evaluate) {
- ns[EVALUATE] = undefined;
- var err = doEvaluate(evaluate);
- if (err) {
- // cache the error
- ns[EVALUATE] = function () {
- throw err;
- };
- throw err;
- }
- Object.keys(ns[BASE_OBJECT]).forEach(extendNamespace, ns);
- }
- // make chainable
- return ns;
- }; */
- var resolvedPromise$1 = Promise.resolve();
- /*
- * Register Loader
- *
- * Builds directly on top of loader polyfill to provide:
- * - loader.register support
- * - hookable higher-level resolve
- * - instantiate hook returning a ModuleNamespace or undefined for es module loading
- * - loader error behaviour as in HTML and loader specs, caching load and eval errors separately
- * - build tracing support by providing a .trace=true and .loads object format
- */
- var REGISTER_INTERNAL = createSymbol('register-internal');
- function RegisterLoader () {
- Loader.call(this);
- var registryDelete = this.registry.delete;
- this.registry.delete = function (key) {
- var deleted = registryDelete.call(this, key);
- // also delete from register registry if linked
- if (records.hasOwnProperty(key) && !records[key].linkRecord) {
- delete records[key];
- deleted = true;
- }
- return deleted;
- };
- var records = {};
- this[REGISTER_INTERNAL] = {
- // last anonymous System.register call
- lastRegister: undefined,
- // in-flight es module load records
- records: records
- };
- // tracing
- this.trace = false;
- }
- RegisterLoader.prototype = Object.create(Loader.prototype);
- RegisterLoader.prototype.constructor = RegisterLoader;
- var INSTANTIATE = RegisterLoader.instantiate = createSymbol('instantiate');
- // default normalize is the WhatWG style normalizer
- RegisterLoader.prototype[RegisterLoader.resolve = Loader.resolve] = function (key, parentKey) {
- return resolveIfNotPlain(key, parentKey || baseURI);
- };
- RegisterLoader.prototype[INSTANTIATE] = function (key, processAnonRegister) {};
- // once evaluated, the linkRecord is set to undefined leaving just the other load record properties
- // this allows tracking new binding listeners for es modules through importerSetters
- // for dynamic modules, the load record is removed entirely.
- function createLoadRecord (state, key, registration) {
- return state.records[key] = {
- key: key,
- // defined System.register cache
- registration: registration,
- // module namespace object
- module: undefined,
- // es-only
- // this sticks around so new module loads can listen to binding changes
- // for already-loaded modules by adding themselves to their importerSetters
- importerSetters: undefined,
- loadError: undefined,
- evalError: undefined,
- // in-flight linking record
- linkRecord: {
- // promise for instantiated
- instantiatePromise: undefined,
- dependencies: undefined,
- execute: undefined,
- executingRequire: false,
- // underlying module object bindings
- moduleObj: undefined,
- // es only, also indicates if es or not
- setters: undefined,
- // promise for instantiated dependencies (dependencyInstantiations populated)
- depsInstantiatePromise: undefined,
- // will be the array of dependency load record or a module namespace
- dependencyInstantiations: undefined,
- // top-level await!
- evaluatePromise: undefined,
- // NB optimization and way of ensuring module objects in setters
- // indicates setters which should run pre-execution of that dependency
- // setters is then just for completely executed module objects
- // alternatively we just pass the partially filled module objects as
- // arguments into the execute function
- // hoisted: undefined
- }
- };
- }
- RegisterLoader.prototype[Loader.resolveInstantiate] = function (key, parentKey) {
- var loader = this;
- var state = this[REGISTER_INTERNAL];
- var registry = this.registry[REGISTRY];
- return resolveInstantiate(loader, key, parentKey, registry, state)
- .then(function (instantiated) {
- if (instantiated instanceof ModuleNamespace || instantiated[toStringTag] === 'module')
- return instantiated;
- // resolveInstantiate always returns a load record with a link record and no module value
- var link = instantiated.linkRecord;
- // if already beaten to done, return
- if (!link) {
- if (instantiated.module)
- return instantiated.module;
- throw instantiated.evalError;
- }
- return deepInstantiateDeps(loader, instantiated, link, registry, state)
- .then(function () {
- return ensureEvaluate(loader, instantiated, link, registry, state);
- });
- });
- };
- function resolveInstantiate (loader, key, parentKey, registry, state) {
- // normalization shortpath for already-normalized key
- // could add a plain name filter, but doesn't yet seem necessary for perf
- var module = registry[key];
- if (module)
- return Promise.resolve(module);
- var load = state.records[key];
- // already linked but not in main registry is ignored
- if (load && !load.module) {
- if (load.loadError)
- return Promise.reject(load.loadError);
- return instantiate(loader, load, load.linkRecord, registry, state);
- }
- return loader.resolve(key, parentKey)
- .then(function (resolvedKey) {
- // main loader registry always takes preference
- module = registry[resolvedKey];
- if (module)
- return module;
- load = state.records[resolvedKey];
- // already has a module value but not already in the registry (load.module)
- // means it was removed by registry.delete, so we should
- // disgard the current load record creating a new one over it
- // but keep any existing registration
- if (!load || load.module)
- load = createLoadRecord(state, resolvedKey, load && load.registration);
- if (load.loadError)
- return Promise.reject(load.loadError);
- var link = load.linkRecord;
- if (!link)
- return load;
- return instantiate(loader, load, link, registry, state);
- });
- }
- function createProcessAnonRegister (loader, load, state) {
- return function () {
- var lastRegister = state.lastRegister;
- if (!lastRegister)
- return !!load.registration;
- state.lastRegister = undefined;
- load.registration = lastRegister;
- return true;
- };
- }
- function instantiate (loader, load, link, registry, state) {
- return link.instantiatePromise || (link.instantiatePromise =
- // if there is already an existing registration, skip running instantiate
- (load.registration ? resolvedPromise$1 : resolvedPromise$1.then(function () {
- state.lastRegister = undefined;
- return loader[INSTANTIATE](load.key, loader[INSTANTIATE].length > 1 && createProcessAnonRegister(loader, load, state));
- }))
- .then(function (instantiation) {
- // direct module return from instantiate -> we're done
- if (instantiation !== undefined) {
- if (!(instantiation instanceof ModuleNamespace || instantiation[toStringTag] === 'module'))
- throw new TypeError('Instantiate did not return a valid Module object.');
- delete state.records[load.key];
- if (loader.trace)
- traceLoad(loader, load, link);
- return registry[load.key] = instantiation;
- }
- // run the cached loader.register declaration if there is one
- var registration = load.registration;
- // clear to allow new registrations for future loads (combined with registry delete)
- load.registration = undefined;
- if (!registration)
- throw new TypeError('Module instantiation did not call an anonymous or correctly named System.register.');
- link.dependencies = registration[0];
- load.importerSetters = [];
- link.moduleObj = {};
- // process System.registerDynamic declaration
- if (registration[2]) {
- link.moduleObj.default = link.moduleObj.__useDefault = {};
- link.executingRequire = registration[1];
- link.execute = registration[2];
- }
- // process System.register declaration
- else {
- registerDeclarative(loader, load, link, registration[1]);
- }
- return load;
- })
- .catch(function (err) {
- load.linkRecord = undefined;
- throw load.loadError = load.loadError || LoaderError__Check_error_message_for_loader_stack(err, 'Instantiating ' + load.key);
- }));
- }
- // like resolveInstantiate, but returning load records for linking
- function resolveInstantiateDep (loader, key, parentKey, registry, state, traceDepMap) {
- // normalization shortpaths for already-normalized key
- // DISABLED to prioritise consistent resolver calls
- // could add a plain name filter, but doesn't yet seem necessary for perf
- /* var load = state.records[key];
- var module = registry[key];
- if (module) {
- if (traceDepMap)
- traceDepMap[key] = key;
- // registry authority check in case module was deleted or replaced in main registry
- if (load && load.module && load.module === module)
- return load;
- else
- return module;
- }
- // already linked but not in main registry is ignored
- if (load && !load.module) {
- if (traceDepMap)
- traceDepMap[key] = key;
- return instantiate(loader, load, load.linkRecord, registry, state);
- } */
- return loader.resolve(key, parentKey)
- .then(function (resolvedKey) {
- if (traceDepMap)
- traceDepMap[key] = resolvedKey;
- // normalization shortpaths for already-normalized key
- var load = state.records[resolvedKey];
- var module = registry[resolvedKey];
- // main loader registry always takes preference
- if (module && (!load || load.module && module !== load.module))
- return module;
- if (load && load.loadError)
- throw load.loadError;
- // already has a module value but not already in the registry (load.module)
- // means it was removed by registry.delete, so we should
- // disgard the current load record creating a new one over it
- // but keep any existing registration
- if (!load || !module && load.module)
- load = createLoadRecord(state, resolvedKey, load && load.registration);
- var link = load.linkRecord;
- if (!link)
- return load;
- return instantiate(loader, load, link, registry, state);
- });
- }
- function traceLoad (loader, load, link) {
- loader.loads = loader.loads || {};
- loader.loads[load.key] = {
- key: load.key,
- deps: link.dependencies,
- dynamicDeps: [],
- depMap: link.depMap || {}
- };
- }
- /*
- * Convert a CJS module.exports into a valid object for new Module:
- *
- * new Module(getEsModule(module.exports))
- *
- * Sets the default value to the module, while also reading off named exports carefully.
- */
- function registerDeclarative (loader, load, link, declare) {
- var moduleObj = link.moduleObj;
- var importerSetters = load.importerSetters;
- var definedExports = false;
- // closure especially not based on link to allow link record disposal
- var declared = declare.call(envGlobal, function (name, value) {
- if (typeof name === 'object') {
- var changed = false;
- for (var p in name) {
- value = name[p];
- if (p !== '__useDefault' && (!(p in moduleObj) || moduleObj[p] !== value)) {
- changed = true;
- moduleObj[p] = value;
- }
- }
- if (changed === false)
- return value;
- }
- else {
- if ((definedExports || name in moduleObj) && moduleObj[name] === value)
- return value;
- moduleObj[name] = value;
- }
- for (var i = 0; i < importerSetters.length; i++)
- importerSetters[i](moduleObj);
- return value;
- }, new ContextualLoader(loader, load.key));
- link.setters = declared.setters || [];
- link.execute = declared.execute;
- if (declared.exports) {
- link.moduleObj = moduleObj = declared.exports;
- definedExports = true;
- }
- }
- function instantiateDeps (loader, load, link, registry, state) {
- if (link.depsInstantiatePromise)
- return link.depsInstantiatePromise;
- var depsInstantiatePromises = Array(link.dependencies.length);
- for (var i = 0; i < link.dependencies.length; i++)
- depsInstantiatePromises[i] = resolveInstantiateDep(loader, link.dependencies[i], load.key, registry, state, loader.trace && link.depMap || (link.depMap = {}));
- var depsInstantiatePromise = Promise.all(depsInstantiatePromises)
- .then(function (dependencyInstantiations) {
- link.dependencyInstantiations = dependencyInstantiations;
- // run setters to set up bindings to instantiated dependencies
- if (link.setters) {
- for (var i = 0; i < dependencyInstantiations.length; i++) {
- var setter = link.setters[i];
- if (setter) {
- var instantiation = dependencyInstantiations[i];
- if (instantiation instanceof ModuleNamespace || instantiation[toStringTag] === 'module') {
- setter(instantiation);
- }
- else {
- if (instantiation.loadError)
- throw instantiation.loadError;
- setter(instantiation.module || instantiation.linkRecord.moduleObj);
- // this applies to both es and dynamic registrations
- if (instantiation.importerSetters)
- instantiation.importerSetters.push(setter);
- }
- }
- }
- }
- return load;
- });
- if (loader.trace)
- depsInstantiatePromise = depsInstantiatePromise.then(function () {
- traceLoad(loader, load, link);
- return load;
- });
- depsInstantiatePromise = depsInstantiatePromise.catch(function (err) {
- // throw up the instantiateDeps stack
- link.depsInstantiatePromise = undefined;
- throw LoaderError__Check_error_message_for_loader_stack(err, 'Loading ' + load.key);
- });
- depsInstantiatePromise.catch(function () {});
- return link.depsInstantiatePromise = depsInstantiatePromise;
- }
- function deepInstantiateDeps (loader, load, link, registry, state) {
- var seen = [];
- function addDeps (load, link) {
- if (!link)
- return resolvedPromise$1;
- if (seen.indexOf(load) !== -1)
- return resolvedPromise$1;
- seen.push(load);
-
- return instantiateDeps(loader, load, link, registry, state)
- .then(function () {
- var depPromises;
- for (var i = 0; i < link.dependencies.length; i++) {
- var depLoad = link.dependencyInstantiations[i];
- if (!(depLoad instanceof ModuleNamespace || depLoad[toStringTag] === 'module')) {
- depPromises = depPromises || [];
- depPromises.push(addDeps(depLoad, depLoad.linkRecord));
- }
- }
- if (depPromises)
- return Promise.all(depPromises);
- });
- }
- return addDeps(load, link);
- }
- /*
- * System.register
- */
- RegisterLoader.prototype.register = function (key, deps, declare) {
- var state = this[REGISTER_INTERNAL];
- // anonymous modules get stored as lastAnon
- if (declare === undefined) {
- state.lastRegister = [key, deps, undefined];
- }
- // everything else registers into the register cache
- else {
- var load = state.records[key] || createLoadRecord(state, key, undefined);
- load.registration = [deps, declare, undefined];
- }
- };
- /*
- * System.registerDyanmic
- */
- RegisterLoader.prototype.registerDynamic = function (key, deps, executingRequire, execute) {
- var state = this[REGISTER_INTERNAL];
- // anonymous modules get stored as lastAnon
- if (typeof key !== 'string') {
- state.lastRegister = [key, deps, executingRequire];
- }
- // everything else registers into the register cache
- else {
- var load = state.records[key] || createLoadRecord(state, key, undefined);
- load.registration = [deps, executingRequire, execute];
- }
- };
- // ContextualLoader class
- // backwards-compatible with previous System.register context argument by exposing .id, .key
- function ContextualLoader (loader, key) {
- this.loader = loader;
- this.key = this.id = key;
- this.meta = {
- url: key
- // scriptElement: null
- };
- }
- /*ContextualLoader.prototype.constructor = function () {
- throw new TypeError('Cannot subclass the contextual loader only Reflect.Loader.');
- };*/
- ContextualLoader.prototype.import = function (key) {
- if (this.loader.trace)
- this.loader.loads[this.key].dynamicDeps.push(key);
- return this.loader.import(key, this.key);
- };
- /*ContextualLoader.prototype.resolve = function (key) {
- return this.loader.resolve(key, this.key);
- };*/
- function ensureEvaluate (loader, load, link, registry, state) {
- if (load.module)
- return load.module;
- if (load.evalError)
- throw load.evalError;
- if (link.evaluatePromise)
- return link.evaluatePromise;
- if (link.setters) {
- var evaluatePromise = doEvaluateDeclarative(loader, load, link, registry, state, [load]);
- if (evaluatePromise)
- return evaluatePromise;
- }
- else {
- doEvaluateDynamic(loader, load, link, registry, state, [load]);
- }
- return load.module;
- }
- function makeDynamicRequire (loader, key, dependencies, dependencyInstantiations, registry, state, seen) {
- // we can only require from already-known dependencies
- return function (name) {
- for (var i = 0; i < dependencies.length; i++) {
- if (dependencies[i] === name) {
- var depLoad = dependencyInstantiations[i];
- var module;
- if (depLoad instanceof ModuleNamespace || depLoad[toStringTag] === 'module') {
- module = depLoad;
- }
- else {
- if (depLoad.evalError)
- throw depLoad.evalError;
- if (depLoad.module === undefined && seen.indexOf(depLoad) === -1 && !depLoad.linkRecord.evaluatePromise) {
- if (depLoad.linkRecord.setters) {
- doEvaluateDeclarative(loader, depLoad, depLoad.linkRecord, registry, state, [depLoad]);
- }
- else {
- seen.push(depLoad);
- doEvaluateDynamic(loader, depLoad, depLoad.linkRecord, registry, state, seen);
- }
- }
- module = depLoad.module || depLoad.linkRecord.moduleObj;
- }
- return '__useDefault' in module ? module.__useDefault : module;
- }
- }
- throw new Error('Module ' + name + ' not declared as a System.registerDynamic dependency of ' + key);
- };
- }
- function evalError (load, err) {
- load.linkRecord = undefined;
- var evalError = LoaderError__Check_error_message_for_loader_stack(err, 'Evaluating ' + load.key);
- if (load.evalError === undefined)
- load.evalError = evalError;
- throw evalError;
- }
- // es modules evaluate dependencies first
- // returns the error if any
- function doEvaluateDeclarative (loader, load, link, registry, state, seen) {
- var depLoad, depLink;
- var depLoadPromises;
- for (var i = 0; i < link.dependencies.length; i++) {
- var depLoad = link.dependencyInstantiations[i];
- if (depLoad instanceof ModuleNamespace || depLoad[toStringTag] === 'module')
- continue;
- // custom Module returned from instantiate
- depLink = depLoad.linkRecord;
- if (depLink) {
- if (depLoad.evalError) {
- evalError(load, depLoad.evalError);
- }
- else if (depLink.setters) {
- if (seen.indexOf(depLoad) === -1) {
- seen.push(depLoad);
- try {
- var depLoadPromise = doEvaluateDeclarative(loader, depLoad, depLink, registry, state, seen);
- }
- catch (e) {
- evalError(load, e);
- }
- if (depLoadPromise) {
- depLoadPromises = depLoadPromises || [];
- depLoadPromises.push(depLoadPromise.catch(function (err) {
- evalError(load, err);
- }));
- }
- }
- }
- else {
- try {
- doEvaluateDynamic(loader, depLoad, depLink, registry, state, [depLoad]);
- }
- catch (e) {
- evalError(load, e);
- }
- }
- }
- }
- if (depLoadPromises)
- return link.evaluatePromise = Promise.all(depLoadPromises)
- .then(function () {
- if (link.execute) {
- // ES System.register execute
- // "this" is null in ES
- try {
- var execPromise = link.execute.call(nullContext);
- }
- catch (e) {
- evalError(load, e);
- }
- if (execPromise)
- return execPromise.catch(function (e) {
- evalError(load, e);
- })
- .then(function () {
- load.linkRecord = undefined;
- return registry[load.key] = load.module = new ModuleNamespace(link.moduleObj);
- });
- }
-
- // dispose link record
- load.linkRecord = undefined;
- registry[load.key] = load.module = new ModuleNamespace(link.moduleObj);
- });
- if (link.execute) {
- // ES System.register execute
- // "this" is null in ES
- try {
- var execPromise = link.execute.call(nullContext);
- }
- catch (e) {
- evalError(load, e);
- }
- if (execPromise)
- return link.evaluatePromise = execPromise.catch(function (e) {
- evalError(load, e);
- })
- .then(function () {
- load.linkRecord = undefined;
- return registry[load.key] = load.module = new ModuleNamespace(link.moduleObj);
- });
- }
- // dispose link record
- load.linkRecord = undefined;
- registry[load.key] = load.module = new ModuleNamespace(link.moduleObj);
- }
- // non es modules explicitly call moduleEvaluate through require
- function doEvaluateDynamic (loader, load, link, registry, state, seen) {
- // System.registerDynamic execute
- // "this" is "exports" in CJS
- var module = { id: load.key };
- var moduleObj = link.moduleObj;
- Object.defineProperty(module, 'exports', {
- configurable: true,
- set: function (exports) {
- moduleObj.default = moduleObj.__useDefault = exports;
- },
- get: function () {
- return moduleObj.__useDefault;
- }
- });
- var require = makeDynamicRequire(loader, load.key, link.dependencies, link.dependencyInstantiations, registry, state, seen);
- // evaluate deps first
- if (!link.executingRequire)
- for (var i = 0; i < link.dependencies.length; i++)
- require(link.dependencies[i]);
- try {
- var output = link.execute.call(envGlobal, require, moduleObj.default, module);
- if (output !== undefined)
- module.exports = output;
- }
- catch (e) {
- evalError(load, e);
- }
- load.linkRecord = undefined;
- // pick up defineProperty calls to module.exports when we can
- if (module.exports !== moduleObj.__useDefault)
- moduleObj.default = moduleObj.__useDefault = module.exports;
- var moduleDefault = moduleObj.default;
- // __esModule flag extension support via lifting
- if (moduleDefault && moduleDefault.__esModule) {
- for (var p in moduleDefault) {
- if (Object.hasOwnProperty.call(moduleDefault, p))
- moduleObj[p] = moduleDefault[p];
- }
- }
- registry[load.key] = load.module = new ModuleNamespace(link.moduleObj);
- // run importer setters and clear them
- // this allows dynamic modules to update themselves into es modules
- // as soon as execution has completed
- if (load.importerSetters)
- for (var i = 0; i < load.importerSetters.length; i++)
- load.importerSetters[i](load.module);
- load.importerSetters = undefined;
- }
- // the closest we can get to call(undefined)
- var nullContext = Object.create(null);
- if (Object.freeze)
- Object.freeze(nullContext);
- var resolvedPromise$2 = Promise.resolve();
- function noop () {}
- var emptyModule = new ModuleNamespace({});
- function protectedCreateNamespace (bindings) {
- if (bindings) {
- if (bindings instanceof ModuleNamespace || bindings[toStringTag] === 'module')
- return bindings;
- if (bindings.__esModule)
- return new ModuleNamespace(bindings);
- }
- return new ModuleNamespace({ default: bindings, __useDefault: bindings });
- }
- function isModule (m) {
- return m instanceof ModuleNamespace || m[toStringTag] === 'module';
- }
- var CONFIG = createSymbol('loader-config');
- var METADATA = createSymbol('metadata');
- var isWorker = typeof window === 'undefined' && typeof self !== 'undefined' && typeof importScripts !== 'undefined';
- function warn (msg, force) {
- if (force || this.warnings && typeof console !== 'undefined' && console.warn)
- console.warn(msg);
- }
- function checkInstantiateWasm (loader, wasmBuffer, processAnonRegister) {
- var bytes = new Uint8Array(wasmBuffer);
- // detect by leading bytes
- // Can be (new Uint32Array(fetched))[0] === 0x6D736100 when working in Node
- if (bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115) {
- return WebAssembly.compile(wasmBuffer).then(function (m) {
- var deps = [];
- var setters = [];
- var importObj = {};
- // we can only set imports if supported (eg Safari doesnt support)
- if (WebAssembly.Module.imports)
- WebAssembly.Module.imports(m).forEach(function (i) {
- var key = i.module;
- setters.push(function (m) {
- importObj[key] = m;
- });
- if (deps.indexOf(key) === -1)
- deps.push(key);
- });
- loader.register(deps, function (_export) {
- return {
- setters: setters,
- execute: function () {
- _export(new WebAssembly.Instance(m, importObj).exports);
- }
- };
- });
- processAnonRegister();
- return true;
- });
- }
- return Promise.resolve(false);
- }
- var parentModuleContext;
- function loadNodeModule (key, baseURL) {
- if (key[0] === '.')
- throw new Error('Node module ' + key + ' can\'t be loaded as it is not a package require.');
- if (!parentModuleContext) {
- var Module = this._nodeRequire('module');
- var base = decodeURI(baseURL.substr(isWindows ? 8 : 7));
- parentModuleContext = new Module(base);
- parentModuleContext.paths = Module._nodeModulePaths(base);
- }
- return parentModuleContext.require(key);
- }
- function extend (a, b) {
- for (var p in b) {
- if (!Object.hasOwnProperty.call(b, p))
- continue;
- a[p] = b[p];
- }
- return a;
- }
- function prepend (a, b) {
- for (var p in b) {
- if (!Object.hasOwnProperty.call(b, p))
- continue;
- if (a[p] === undefined)
- a[p] = b[p];
- }
- return a;
- }
- // meta first-level extends where:
- // array + array appends
- // object + object extends
- // other properties replace
- function extendMeta (a, b, _prepend) {
- for (var p in b) {
- if (!Object.hasOwnProperty.call(b, p))
- continue;
- var val = b[p];
- if (a[p] === undefined)
- 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' && val !== null && typeof a[p] == 'object')
- a[p] = (_prepend ? prepend : extend)(extend({}, a[p]), val);
- else if (!_prepend)
- a[p] = val;
- }
- }
- var supportsPreload = false, supportsPrefetch = false;
- if (isBrowser)
- (function () {
- var relList = document.createElement('link').relList;
- if (relList && relList.supports) {
- supportsPrefetch = true;
- try {
- supportsPreload = relList.supports('preload');
- }
- catch (e) {}
- }
- })();
- function preloadScript (url) {
- // fallback to old fashioned image technique which still works in safari
- if (!supportsPreload && !supportsPrefetch) {
- var preloadImage = new Image();
- preloadImage.src = url;
- return;
- }
- var link = document.createElement('link');
- if (supportsPreload) {
- link.rel = 'preload';
- link.as = 'script';
- }
- else {
- // this works for all except Safari (detected by relList.supports lacking)
- link.rel = 'prefetch';
- }
- link.href = url;
- document.head.appendChild(link);
- }
- function workerImport (src, resolve, reject) {
- try {
- importScripts(src);
- }
- catch (e) {
- reject(e);
- }
- resolve();
- }
- if (isBrowser) {
- var onerror = window.onerror;
- window.onerror = function globalOnerror (msg, src) {
- if (onerror)
- onerror.apply(this, arguments);
- };
- }
- function scriptLoad (src, crossOrigin, integrity, resolve, reject) {
- // percent encode just "#" for HTTP requests
- src = src.replace(/#/g, '%23');
- // subresource integrity is not supported in web workers
- if (isWorker)
- return workerImport(src, resolve, reject);
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.charset = 'utf-8';
- script.async = true;
- if (crossOrigin)
- script.crossOrigin = crossOrigin;
- if (integrity)
- script.integrity = integrity;
- script.addEventListener('load', load, false);
- script.addEventListener('error', error, false);
- script.src = src;
- document.head.appendChild(script);
- function load () {
- resolve();
- cleanup();
- }
- // note this does not catch execution errors
- function error (err) {
- cleanup();
- reject(new Error('Fetching ' + src));
- }
- function cleanup () {
- script.removeEventListener('load', load, false);
- script.removeEventListener('error', error, false);
- document.head.removeChild(script);
- }
- }
- function readMemberExpression (p, value) {
- var pParts = p.split('.');
- while (pParts.length)
- value = value[pParts.shift()];
- return value;
- }
- // separate out paths cache as a baseURL lock process
- function applyPaths (baseURL, paths, key) {
- var mapMatch = getMapMatch(paths, key);
- if (mapMatch) {
- var target = paths[mapMatch] + key.substr(mapMatch.length);
- var resolved = resolveIfNotPlain(target, baseURI);
- if (resolved !== undefined)
- return resolved;
- return baseURL + target;
- }
- else if (key.indexOf(':') !== -1) {
- return key;
- }
- else {
- return baseURL + key;
- }
- }
- function checkMap (p) {
- var name = this.name;
- // can add ':' here if we want paths to match the behaviour of map
- if (name.substr(0, p.length) === p && (name.length === p.length || name[p.length] === '/' || p[p.length - 1] === '/' || p[p.length - 1] === ':')) {
- var curLen = p.split('/').length;
- if (curLen > this.len) {
- this.match = p;
- this.len = curLen;
- }
- }
- }
- function getMapMatch (map, name) {
- if (Object.hasOwnProperty.call(map, name))
- return name;
- var bestMatch = {
- name: name,
- match: undefined,
- len: 0
- };
- Object.keys(map).forEach(checkMap, bestMatch);
- return bestMatch.match;
- }
- // 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;
- /*
- * Source loading
- */
- function fetchFetch (url, authorization, integrity, asBuffer) {
- // fetch doesn't support file:/// urls
- if (url.substr(0, 8) === 'file:///') {
- if (hasXhr)
- return xhrFetch(url, authorization, integrity, asBuffer);
- else
- throw new Error('Unable to fetch file URLs in this environment.');
- }
- // percent encode just "#" for HTTP requests
- url = url.replace(/#/g, '%23');
- var opts = {
- // NB deprecate
- headers: { Accept: 'application/x-es-module, */*' }
- };
- if (integrity)
- opts.integrity = integrity;
- if (authorization) {
- if (typeof authorization == 'string')
- opts.headers['Authorization'] = authorization;
- opts.credentials = 'include';
- }
- return fetch(url, opts)
- .then(function(res) {
- if (res.ok)
- return asBuffer ? res.arrayBuffer() : res.text();
- else
- throw new Error('Fetch error: ' + res.status + ' ' + res.statusText);
- });
- }
- function xhrFetch (url, authorization, integrity, asBuffer) {
- return new Promise(function (resolve, reject) {
- // percent encode just "#" for HTTP requests
- url = url.replace(/#/g, '%23');
- var xhr = new XMLHttpRequest();
- if (asBuffer)
- xhr.responseType = 'arraybuffer';
- function load() {
- resolve(asBuffer ? xhr.response : 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) {
- // in Chrome on file:/// URLs, status is 0
- if (xhr.status == 0) {
- if (xhr.response) {
- load();
- }
- else {
- // when responseText is empty, wait for load or error event
- // to inform if it is a 404 or empty file
- xhr.addEventListener('error', error);
- xhr.addEventListener('load', load);
- }
- }
- else if (xhr.status === 200) {
- 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;
- }
- }
- xhr.send(null);
- });
- }
- var fs;
- function nodeFetch (url, authorization, integrity, asBuffer) {
- if (url.substr(0, 8) != 'file:///') {
- if (hasFetch)
- return fetchFetch(url, authorization, integrity, asBuffer);
- else
- return Promise.reject(new Error('Unable to fetch "' + url + '". Only file URLs of the form file:/// supported running in Node without fetch.'));
- }
-
- fs = fs || require('fs');
- if (isWindows)
- url = url.replace(/\//g, '\\').substr(8);
- else
- url = url.substr(7);
- return new Promise(function (resolve, reject) {
- fs.readFile(url, function(err, data) {
- if (err) {
- return reject(err);
- }
- else {
- if (asBuffer) {
- resolve(data);
- }
- else {
- // Strip Byte Order Mark out if it's the leading char
- var dataString = data + '';
- if (dataString[0] === '\ufeff')
- dataString = dataString.substr(1);
- resolve(dataString);
- }
- }
- });
- });
- }
- function noFetch () {
- throw new Error('No fetch method is defined for this environment.');
- }
- var fetchFunction;
- var hasXhr = typeof XMLHttpRequest !== 'undefined';
- var hasFetch = typeof fetch !== 'undefined';
- if (typeof self !== 'undefined' && typeof self.fetch !== 'undefined')
- fetchFunction = fetchFetch;
- else if (hasXhr)
- fetchFunction = xhrFetch;
- else if (typeof require !== 'undefined' && typeof process !== 'undefined')
- fetchFunction = nodeFetch;
- else
- fetchFunction = noFetch;
- var fetch$1 = fetchFunction;
- function createMetadata () {
- return {
- pluginKey: undefined,
- pluginArgument: undefined,
- pluginModule: undefined,
- packageKey: undefined,
- packageConfig: undefined,
- load: undefined
- };
- }
- function getParentMetadata (loader, config, parentKey) {
- var parentMetadata = createMetadata();
- if (parentKey) {
- // detect parent plugin
- // we just need pluginKey to be truthy for package configurations
- // so we duplicate it as pluginArgument - although not correct its not used
- var parentPluginIndex;
- if (config.pluginFirst) {
- if ((parentPluginIndex = parentKey.lastIndexOf('!')) !== -1)
- parentMetadata.pluginArgument = parentMetadata.pluginKey = parentKey.substr(0, parentPluginIndex);
- }
- else {
- if ((parentPluginIndex = parentKey.indexOf('!')) !== -1)
- parentMetadata.pluginArgument = parentMetadata.pluginKey = parentKey.substr(parentPluginIndex + 1);
- }
- // detect parent package
- parentMetadata.packageKey = getMapMatch(config.packages, parentKey);
- if (parentMetadata.packageKey)
- parentMetadata.packageConfig = config.packages[parentMetadata.packageKey];
- }
- return parentMetadata;
- }
- function normalize (key, parentKey) {
- var config = this[CONFIG];
- var metadata = createMetadata();
- var parentMetadata = getParentMetadata(this, config, parentKey);
- var loader = this;
- return Promise.resolve()
- // boolean conditional
- .then(function () {
- // first we normalize the conditional
- var booleanIndex = key.lastIndexOf('#?');
- if (booleanIndex === -1)
- return Promise.resolve(key);
- var conditionObj = parseCondition.call(loader, key.substr(booleanIndex + 2));
- // in builds, return normalized conditional
- /*if (this.builder)
- return this.resolve(conditionObj.module, parentKey)
- .then(function (conditionModule) {
- conditionObj.module = conditionModule;
- return key.substr(0, booleanIndex) + '#?' + serializeCondition(conditionObj);
- });*/
- return resolveCondition.call(loader, conditionObj, parentKey, true)
- .then(function (conditionValue) {
- return conditionValue ? key.substr(0, booleanIndex) : '@empty';
- });
- })
- // plugin
- .then(function (key) {
- var parsed = parsePlugin(config.pluginFirst, key);
- if (!parsed)
- return packageResolve.call(loader, config, key, parentMetadata && parentMetadata.pluginArgument || parentKey, metadata, parentMetadata, false);
- metadata.pluginKey = parsed.plugin;
- return Promise.all([
- packageResolve.call(loader, config, parsed.argument, parentMetadata && parentMetadata.pluginArgument || parentKey, metadata, parentMetadata, true),
- loader.resolve(parsed.plugin, parentKey)
- ])
- .then(function (normalized) {
- metadata.pluginArgument = normalized[0];
- metadata.pluginKey = normalized[1];
- // don't allow a plugin to load itself
- if (metadata.pluginArgument === metadata.pluginKey)
- throw new Error('Plugin ' + metadata.pluginArgument + ' cannot load itself, make sure it is excluded from any wildcard meta configuration via a custom loader: false rule.');
- return combinePluginParts(config.pluginFirst, normalized[0], normalized[1]);
- });
- })
- .then(function (normalized) {
- return interpolateConditional.call(loader, normalized, parentKey, parentMetadata);
- })
- .then(function (normalized) {
- setMeta.call(loader, config, normalized, metadata);
- if (metadata.pluginKey || !metadata.load.loader)
- return normalized;
- // loader by configuration
- // normalizes to parent to support package loaders
- return loader.resolve(metadata.load.loader, normalized)
- .then(function (pluginKey) {
- metadata.pluginKey = pluginKey;
- metadata.pluginArgument = normalized;
- return normalized;
- });
- })
- .then(function (normalized) {
- loader[METADATA][normalized] = metadata;
- return normalized;
- });
- }
- // normalization function used for registry keys
- // just does coreResolve without map
- function decanonicalize (config, key) {
- var parsed = parsePlugin(config.pluginFirst, key);
- // plugin
- if (parsed) {
- var pluginKey = decanonicalize.call(this, config, parsed.plugin);
- return combinePluginParts(config.pluginFirst, coreResolve.call(this, config, parsed.argument, undefined, false, false), pluginKey);
- }
- return coreResolve.call(this, config, key, undefined, false, false);
- }
- function normalizeSync (key, parentKey) {
- var config = this[CONFIG];
- // normalizeSync is metadataless, so create metadata
- var metadata = createMetadata();
- var parentMetadata = parentMetadata || getParentMetadata(this, config, parentKey);
- var parsed = parsePlugin(config.pluginFirst, key);
- // plugin
- if (parsed) {
- metadata.pluginKey = normalizeSync.call(this, parsed.plugin, parentKey);
- return combinePluginParts(config.pluginFirst,
- packageResolveSync.call(this, config, parsed.argument, parentMetadata.pluginArgument || parentKey, metadata, parentMetadata, !!metadata.pluginKey),
- metadata.pluginKey);
- }
- return packageResolveSync.call(this, config, key, parentMetadata.pluginArgument || parentKey, metadata, parentMetadata, !!metadata.pluginKey);
- }
- function coreResolve (config, key, parentKey, doMap, packageName) {
- var relativeResolved = resolveIfNotPlain(key, parentKey || baseURI);
- // standard URL resolution
- if (relativeResolved)
- return applyPaths(config.baseURL, config.paths, relativeResolved);
- // plain keys not starting with './', 'x://' and '/' go through custom resolution
- if (doMap) {
- var mapMatch = getMapMatch(config.map, key);
- if (mapMatch) {
- key = config.map[mapMatch] + key.substr(mapMatch.length);
- relativeResolved = resolveIfNotPlain(key, baseURI);
- if (relativeResolved)
- return applyPaths(config.baseURL, config.paths, relativeResolved);
- }
- }
- if (this.registry.has(key))
- return key;
- if (key.substr(0, 6) === '@node/')
- return key;
- var trailingSlash = packageName && key[key.length - 1] !== '/';
- var resolved = applyPaths(config.baseURL, config.paths, trailingSlash ? key + '/' : key);
- if (trailingSlash)
- return resolved.substr(0, resolved.length - 1);
- return resolved;
- }
- function packageResolveSync (config, key, parentKey, metadata, parentMetadata, skipExtensions) {
- // ignore . since internal maps handled by standard package resolution
- if (parentMetadata && parentMetadata.packageConfig && key[0] !== '.') {
- var parentMap = parentMetadata.packageConfig.map;
- var parentMapMatch = parentMap && getMapMatch(parentMap, key);
- if (parentMapMatch && typeof parentMap[parentMapMatch] === 'string') {
- var mapped = doMapSync(this, config, parentMetadata.packageConfig, parentMetadata.packageKey, parentMapMatch, key, metadata, skipExtensions);
- if (mapped)
- return mapped;
- }
- }
- var normalized = coreResolve.call(this, config, key, parentKey, true, true);
- var pkgConfigMatch = getPackageConfigMatch(config, normalized);
- metadata.packageKey = pkgConfigMatch && pkgConfigMatch.packageKey || getMapMatch(config.packages, normalized);
- if (!metadata.packageKey)
- return normalized;
- if (config.packageConfigKeys.indexOf(normalized) !== -1) {
- metadata.packageKey = undefined;
- return normalized;
- }
- metadata.packageConfig = config.packages[metadata.packageKey] || (config.packages[metadata.packageKey] = createPackage());
- var subPath = normalized.substr(metadata.packageKey.length + 1);
- return applyPackageConfigSync(this, config, metadata.packageConfig, metadata.packageKey, subPath, metadata, skipExtensions);
- }
- function packageResolve (config, key, parentKey, metadata, parentMetadata, skipExtensions) {
- var loader = this;
- return resolvedPromise$2
- .then(function () {
- // ignore . since internal maps handled by standard package resolution
- if (parentMetadata && parentMetadata.packageConfig && key.substr(0, 2) !== './') {
- var parentMap = parentMetadata.packageConfig.map;
- var parentMapMatch = parentMap && getMapMatch(parentMap, key);
- if (parentMapMatch)
- return doMap(loader, config, parentMetadata.packageConfig, parentMetadata.packageKey, parentMapMatch, key, metadata, skipExtensions);
- }
- return resolvedPromise$2;
- })
- .then(function (mapped) {
- if (mapped)
- return mapped;
- // apply map, core, paths, contextual package map
- var normalized = coreResolve.call(loader, config, key, parentKey, true, true);
- var pkgConfigMatch = getPackageConfigMatch(config, normalized);
- metadata.packageKey = pkgConfigMatch && pkgConfigMatch.packageKey || getMapMatch(config.packages, normalized);
- if (!metadata.packageKey)
- return Promise.resolve(normalized);
- if (config.packageConfigKeys.indexOf(normalized) !== -1) {
- metadata.packageKey = undefined;
- metadata.load = createMeta();
- metadata.load.format = 'json';
- // ensure no loader
- metadata.load.loader = '';
- return Promise.resolve(normalized);
- }
- metadata.packageConfig = config.packages[metadata.packageKey] || (config.packages[metadata.packageKey] = createPackage());
- // load configuration when it matches packageConfigPaths, not already configured, and not the config itself
- var loadConfig = pkgConfigMatch && !metadata.packageConfig.configured;
- return (loadConfig ? loadPackageConfigPath(loader, config, pkgConfigMatch.configPath, metadata) : resolvedPromise$2)
- .then(function () {
- var subPath = normalized.substr(metadata.packageKey.length + 1);
- return applyPackageConfig(loader, config, metadata.packageConfig, metadata.packageKey, subPath, metadata, skipExtensions);
- });
- });
- }
- function createMeta () {
- return {
- extension: '',
- deps: undefined,
- format: undefined,
- loader: undefined,
- scriptLoad: undefined,
- globals: undefined,
- nonce: undefined,
- integrity: undefined,
- sourceMap: undefined,
- exports: undefined,
- encapsulateGlobal: false,
- crossOrigin: undefined,
- cjsRequireDetection: true,
- cjsDeferDepsExecute: false,
- esModule: false
- };
- }
- function setMeta (config, key, metadata) {
- metadata.load = metadata.load || createMeta();
- // apply wildcard metas
- var bestDepth = 0;
- var wildcardIndex;
- for (var module in config.meta) {
- wildcardIndex = module.indexOf('*');
- if (wildcardIndex === -1)
- continue;
- if (module.substr(0, wildcardIndex) === key.substr(0, wildcardIndex)
- && module.substr(wildcardIndex + 1) === key.substr(key.length - module.length + wildcardIndex + 1)) {
- var depth = module.split('/').length;
- if (depth > bestDepth)
- bestDepth = depth;
- extendMeta(metadata.load, config.meta[module], bestDepth !== depth);
- }
- }
- // apply exact meta
- if (config.meta[key])
- extendMeta(metadata.load, config.meta[key], false);
- // apply package meta
- if (metadata.packageKey) {
- var subPath = key.substr(metadata.packageKey.length + 1);
- var meta = {};
- if (metadata.packageConfig.meta) {
- var bestDepth = 0;
- getMetaMatches(metadata.packageConfig.meta, subPath, function (metaPattern, matchMeta, matchDepth) {
- if (matchDepth > bestDepth)
- bestDepth = matchDepth;
- extendMeta(meta, matchMeta, matchDepth && bestDepth > matchDepth);
- });
- extendMeta(metadata.load, meta, false);
- }
- // format
- if (metadata.packageConfig.format && !metadata.pluginKey && !metadata.load.loader)
- metadata.load.format = metadata.load.format || metadata.packageConfig.format;
- }
- }
- function parsePlugin (pluginFirst, key) {
- var argumentKey;
- var pluginKey;
- var pluginIndex = pluginFirst ? key.indexOf('!') : key.lastIndexOf('!');
- if (pluginIndex === -1)
- return;
- if (pluginFirst) {
- argumentKey = key.substr(pluginIndex + 1);
- pluginKey = key.substr(0, pluginIndex);
- }
- else {
- argumentKey = key.substr(0, pluginIndex);
- pluginKey = key.substr(pluginIndex + 1) || argumentKey.substr(argumentKey.lastIndexOf('.') + 1);
- }
- return {
- argument: argumentKey,
- plugin: pluginKey
- };
- }
- // put key back together after parts have been normalized
- function combinePluginParts (pluginFirst, argumentKey, pluginKey) {
- if (pluginFirst)
- return pluginKey + '!' + argumentKey;
- else
- return argumentKey + '!' + pluginKey;
- }
- /*
- * Package Configuration Extension
- *
- * Example:
- *
- * SystemJS.packages = {
- * jquery: {
- * main: 'index.js', // when not set, package key 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',
- * './custom-condition.js|~export': './index-custom.js'
- * }
- * },
- * // allows for setting package-prefixed depCache
- * // keys are normalized module keys 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': ['external-dep'],
- * 'external-dep/path.js': ['./another.js']
- * }
- * }
- * };
- *
- * 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
- * - if a meta 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
- * - map targets support conditional interpolation ('./x': './x.#{|env}.js')
- * - internal package map targets cannot use boolean conditionals
- *
- * 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 key to derive the package
- * configuration from. This allows dynamic loading of non-predetermined code, a key use
- * case in SystemJS.
- *
- * Example:
- *
- * SystemJS.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'
- * SystemJS.import('packages/new-package/path');
- *
- * // will first request 'packages/test/package.json' before the main
- * SystemJS.import('packages/test');
- *
- * When a package matches packageConfigPaths, it will always send a config request for
- * the package configuration.
- * The package key itself is taken to be the match up to and including the last wildcard
- * or trailing slash.
- * The most specific package config path will be used.
- * 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 addDefaultExtension (config, pkg, pkgKey, subPath, skipExtensions) {
- // don't apply extensions to folders or if defaultExtension = false
- if (!subPath || !pkg.defaultExtension || subPath[subPath.length - 1] === '/' || skipExtensions)
- return subPath;
- var metaMatch = false;
- // exact meta or meta with any content after the last wildcard skips extension
- if (pkg.meta)
- getMetaMatches(pkg.meta, subPath, function (metaPattern, matchMeta, matchDepth) {
- if (matchDepth === 0 || metaPattern.lastIndexOf('*') !== metaPattern.length - 1)
- return metaMatch = true;
- });
- // exact global meta or meta with any content after the last wildcard skips extension
- if (!metaMatch && config.meta)
- getMetaMatches(config.meta, pkgKey + '/' + subPath, function (metaPattern, matchMeta, matchDepth) {
- if (matchDepth === 0 || metaPattern.lastIndexOf('*') !== metaPattern.length - 1)
- return metaMatch = true;
- });
- if (metaMatch)
- return subPath;
- // work out what the defaultExtension is and add if not there already
- var defaultExtension = '.' + pkg.defaultExtension;
- if (subPath.substr(subPath.length - defaultExtension.length) !== defaultExtension)
- return subPath + defaultExtension;
- else
- return subPath;
- }
- function applyPackageConfigSync (loader, config, pkg, pkgKey, subPath, metadata, skipExtensions) {
- // main
- if (!subPath) {
- if (pkg.main)
- subPath = pkg.main.substr(0, 2) === './' ? pkg.main.substr(2) : pkg.main;
- else
- // also no submap if key is package itself (import 'pkg' -> 'path/to/pkg.js')
- // NB can add a default package main convention here
- // if it becomes internal to the package then it would no longer be an exit path
- return pkgKey;
- }
- // map config checking without then with extensions
- if (pkg.map) {
- var mapPath = './' + subPath;
- var mapMatch = getMapMatch(pkg.map, mapPath);
- // we then check map with the default extension adding
- if (!mapMatch) {
- mapPath = './' + addDefaultExtension(config, pkg, pkgKey, subPath, skipExtensions);
- if (mapPath !== './' + subPath)
- mapMatch = getMapMatch(pkg.map, mapPath);
- }
- if (mapMatch) {
- var mapped = doMapSync(loader, config, pkg, pkgKey, mapMatch, mapPath, metadata, skipExtensions);
- if (mapped)
- return mapped;
- }
- }
- // normal package resolution
- return pkgKey + '/' + addDefaultExtension(config, pkg, pkgKey, subPath, skipExtensions);
- }
- function validMapping (mapMatch, mapped, path) {
- // allow internal ./x -> ./x/y or ./x/ -> ./x/y recursive maps
- // but only if the path is exactly ./x and not ./x/z
- if (mapped.substr(0, mapMatch.length) === mapMatch && path.length > mapMatch.length)
- return false;
- return true;
- }
- function doMapSync (loader, config, pkg, pkgKey, mapMatch, path, metadata, skipExtensions) {
- if (path[path.length - 1] === '/')
- path = path.substr(0, path.length - 1);
- var mapped = pkg.map[mapMatch];
- if (typeof mapped === 'object')
- throw new Error('Synchronous conditional normalization not supported sync normalizing ' + mapMatch + ' in ' + pkgKey);
- if (!validMapping(mapMatch, mapped, path) || typeof mapped !== 'string')
- return;
- return packageResolveSync.call(loader, config, mapped + path.substr(mapMatch.length), pkgKey + '/', metadata, metadata, skipExtensions);
- }
- function applyPackageConfig (loader, config, pkg, pkgKey, subPath, metadata, skipExtensions) {
- // main
- if (!subPath) {
- if (pkg.main)
- subPath = pkg.main.substr(0, 2) === './' ? pkg.main.substr(2) : pkg.main;
- // also no submap if key is package itself (import 'pkg' -> 'path/to/pkg.js')
- else
- // NB can add a default package main convention here
- // if it becomes internal to the package then it would no longer be an exit path
- return Promise.resolve(pkgKey);
- }
- // map config checking without then with extensions
- var mapPath, mapMatch;
- if (pkg.map) {
- mapPath = './' + subPath;
- mapMatch = getMapMatch(pkg.map, mapPath);
- // we then check map with the default extension adding
- if (!mapMatch) {
- mapPath = './' + addDefaultExtension(config, pkg, pkgKey, subPath, skipExtensions);
- if (mapPath !== './' + subPath)
- mapMatch = getMapMatch(pkg.map, mapPath);
- }
- }
- return (mapMatch ? doMap(loader, config, pkg, pkgKey, mapMatch, mapPath, metadata, skipExtensions) : resolvedPromise$2)
- .then(function (mapped) {
- if (mapped)
- return Promise.resolve(mapped);
- // normal package resolution / fallback resolution for no conditional match
- return Promise.resolve(pkgKey + '/' + addDefaultExtension(config, pkg, pkgKey, subPath, skipExtensions));
- });
- }
- function doMap (loader, config, pkg, pkgKey, mapMatch, path, metadata, skipExtensions) {
- if (path[path.length - 1] === '/')
- path = path.substr(0, path.length - 1);
- var mapped = pkg.map[mapMatch];
- if (typeof mapped === 'string') {
- if (!validMapping(mapMatch, mapped, path))
- return resolvedPromise$2;
- return packageResolve.call(loader, config, mapped + path.substr(mapMatch.length), pkgKey + '/', metadata, metadata, skipExtensions)
- .then(function (normalized) {
- return interpolateConditional.call(loader, normalized, pkgKey + '/', metadata);
- });
- }
- // we use a special conditional syntax to allow the builder to handle conditional branch points further
- /*if (loader.builder)
- return Promise.resolve(pkgKey + '/#:' + path);*/
- // we load all conditions upfront
- var conditionPromises = [];
- var conditions = [];
- for (var e in mapped) {
- var c = parseCondition(e);
- conditions.push({
- condition: c,
- map: mapped[e]
- });
- conditionPromises.push(RegisterLoader.prototype.import.call(loader, c.module, pkgKey));
- }
- // map object -> conditional map
- return Promise.all(conditionPromises)
- .then(function (conditionValues) {
- // first map condition to match is used
- for (var i = 0; i < conditions.length; i++) {
- var c = conditions[i].condition;
- var value = readMemberExpression(c.prop, '__useDefault' in conditionValues[i] ? conditionValues[i].__useDefault : conditionValues[i]);
- if (!c.negate && value || c.negate && !value)
- return conditions[i].map;
- }
- })
- .then(function (mapped) {
- if (mapped) {
- if (!validMapping(mapMatch, mapped, path))
- return resolvedPromise$2;
- return packageResolve.call(loader, config, mapped + path.substr(mapMatch.length), pkgKey + '/', metadata, metadata, skipExtensions)
- .then(function (normalized) {
- return interpolateConditional.call(loader, normalized, pkgKey + '/', metadata);
- });
- }
- // no environment match -> fallback to original subPath by returning undefined
- });
- }
- // check if the given normalized key matches a packageConfigPath
- // if so, loads the config
- var packageConfigPaths = {};
- // data object for quick checks against package paths
- function createPkgConfigPathObj (path) {
- var lastWildcard = path.lastIndexOf('*');
- var length = Math.max(lastWildcard + 1, path.lastIndexOf('/'));
- return {
- length: length,
- regEx: new RegExp('^(' + path.substr(0, length).replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^\\/]+') + ')(\\/|$)'),
- wildcard: lastWildcard !== -1
- };
- }
- // most specific match wins
- function getPackageConfigMatch (config, normalized) {
- var pkgKey, exactMatch = false, configPath;
- for (var i = 0; i < config.packageConfigPaths.length; i++) {
- var packageConfigPath = config.packageConfigPaths[i];
- var p = packageConfigPaths[packageConfigPath] || (packageConfigPaths[packageConfigPath] = createPkgConfigPathObj(packageConfigPath));
- if (normalized.length < p.length)
- continue;
- var match = normalized.match(p.regEx);
- if (match && (!pkgKey || (!(exactMatch && p.wildcard) && pkgKey.length < match[1].length))) {
- pkgKey = match[1];
- exactMatch = !p.wildcard;
- configPath = pkgKey + packageConfigPath.substr(p.length);
- }
- }
- if (!pkgKey)
- return;
- return {
- packageKey: pkgKey,
- configPath: configPath
- };
- }
- function loadPackageConfigPath (loader, config, pkgConfigPath, metadata, normalized) {
- var configLoader = loader.pluginLoader || loader;
- // ensure we note this is a package config file path
- // it will then be skipped from getting other normalizations itself to ensure idempotency
- if (config.packageConfigKeys.indexOf(pkgConfigPath) === -1)
- config.packageConfigKeys.push(pkgConfigPath);
- return configLoader.import(pkgConfigPath)
- .then(function (pkgConfig) {
- setPkgConfig(metadata.packageConfig, pkgConfig, metadata.packageKey, true, config);
- metadata.packageConfig.configured = true;
- })
- .catch(function (err) {
- throw LoaderError__Check_error_message_for_loader_stack(err, 'Unable to fetch package configuration file ' + pkgConfigPath);
- });
- }
- function getMetaMatches (pkgMeta, subPath, matchFn) {
- // wildcard 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)) {
- // alow match function to return true for an exit path
- if (matchFn(module, pkgMeta[dotRel + module], module.split('/').length))
- return;
- }
- }
- // exact meta
- var exactMeta = pkgMeta[subPath] && Object.hasOwnProperty.call(pkgMeta, subPath) ? pkgMeta[subPath] : pkgMeta['./' + subPath];
- if (exactMeta)
- matchFn(exactMeta, exactMeta, 0);
- }
- /*
- * 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 `SystemJS.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'
- *
- */
- var sysConditions = ['browser', 'node', 'dev', 'build', 'production', 'default'];
- function parseCondition (condition) {
- var conditionExport, conditionModule, negation;
- var negation;
- var conditionExportIndex = condition.lastIndexOf('|');
- if (conditionExportIndex !== -1) {
- conditionExport = condition.substr(conditionExportIndex + 1);
- conditionModule = condition.substr(0, conditionExportIndex);
- if (conditionExport[0] === '~') {
- negation = true;
- conditionExport = conditionExport.substr(1);
- }
- }
- else {
- negation = condition[0] === '~';
- conditionExport = 'default';
- conditionModule = condition.substr(negation);
- if (sysConditions.indexOf(conditionModule) !== -1) {
- conditionExport = conditionModule;
- conditionModule = null;
- }
- }
- return {
- module: conditionModule || '@system-env',
- prop: conditionExport,
- negate: negation
- };
- }
- function resolveCondition (conditionObj, parentKey, bool) {
- // import without __useDefault handling here
- return RegisterLoader.prototype.import.call(this, conditionObj.module, parentKey)
- .then(function (condition) {
- var m = readMemberExpression(conditionObj.prop, condition);
- if (bool && typeof m !== 'boolean')
- throw new TypeError('Condition did not resolve to a boolean.');
- return conditionObj.negate ? !m : m;
- });
- }
- var interpolationRegEx = /#\{[^\}]+\}/;
- function interpolateConditional (key, parentKey, parentMetadata) {
- // first we normalize the conditional
- var conditionalMatch = key.match(interpolationRegEx);
- if (!conditionalMatch)
- return Promise.resolve(key);
- var conditionObj = parseCondition.call(this, conditionalMatch[0].substr(2, conditionalMatch[0].length - 3));
- // in builds, return normalized conditional
- /*if (this.builder)
- return this.normalize(conditionObj.module, parentKey, createMetadata(), parentMetadata)
- .then(function (conditionModule) {
- conditionObj.module = conditionModule;
- return key.replace(interpolationRegEx, '#{' + serializeCondition(conditionObj) + '}');
- });*/
- return resolveCondition.call(this, conditionObj, parentKey, false)
- .then(function (conditionValue) {
- if (typeof conditionValue !== 'string')
- throw new TypeError('The condition value for ' + key + ' doesn\'t resolve to a string.');
- if (conditionValue.indexOf('/') !== -1)
- throw new TypeError('Unabled to interpolate conditional ' + key + (parentKey ? ' in ' + parentKey : '') + '\n\tThe condition value ' + conditionValue + ' cannot contain a "/" separator.');
- return key.replace(interpolationRegEx, conditionValue);
- });
- }
- /*
- 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:
- SystemJS.config({
- meta: {
- './index.js': {}
- }
- });
- To become
- SystemJS.meta['https://thissite.com/index.js'] = {};
- For easy normalization canonicalization with latest URL support.
- */
- var envConfigNames = ['browserConfig', 'nodeConfig', 'devConfig', 'buildConfig', 'productionConfig'];
- function envSet(loader, cfg, envCallback) {
- for (var i = 0; i < envConfigNames.length; i++) {
- var envConfig = envConfigNames[i];
- if (cfg[envConfig] && envModule[envConfig.substr(0, envConfig.length - 6)])
- envCallback(cfg[envConfig]);
- }
- }
- function cloneObj (obj, maxDepth) {
- var clone = {};
- for (var p in obj) {
- var prop = obj[p];
- if (maxDepth > 1) {
- if (prop instanceof Array)
- clone[p] = [].concat(prop);
- else if (typeof prop === 'object')
- clone[p] = cloneObj(prop, maxDepth - 1);
- else if (p !== 'packageConfig')
- clone[p] = prop;
- }
- else {
- clone[p] = prop;
- }
- }
- return clone;
- }
- function getConfigItem (config, p) {
- var cfgItem = config[p];
- // getConfig must return an unmodifiable clone of the configuration
- if (cfgItem instanceof Array)
- return config[p].concat([]);
- else if (typeof cfgItem === 'object')
- return cloneObj(cfgItem, 3)
- else
- return config[p];
- }
- function getConfig (configName) {
- if (configName) {
- if (configNames.indexOf(configName) !== -1)
- return getConfigItem(this[CONFIG], configName);
- throw new Error('"' + configName + '" is not a valid configuration name. Must be one of ' + configNames.join(', ') + '.');
- }
- var cfg = {};
- for (var i = 0; i < configNames.length; i++) {
- var p = configNames[i];
- var configItem = getConfigItem(this[CONFIG], p);
- if (configItem !== undefined)
- cfg[p] = configItem;
- }
- return cfg;
- }
- function setConfig (cfg, isEnvConfig) {
- var loader = this;
- var config = this[CONFIG];
- if ('warnings' in cfg)
- config.warnings = cfg.warnings;
- if ('wasm' in cfg)
- config.wasm = typeof WebAssembly !== 'undefined' && cfg.wasm;
- if ('production' in cfg || 'build' in cfg)
- setProduction.call(loader, !!cfg.production, !!(cfg.build || envModule && envModule.build));
- if (!isEnvConfig) {
- // if using nodeConfig / browserConfig / productionConfig, take baseURL from there
- // these exceptions will be unnecessary when we can properly implement config queuings
- var baseURL;
- envSet(loader, cfg, function(cfg) {
- baseURL = baseURL || cfg.baseURL;
- });
- baseURL = baseURL || cfg.baseURL;
- // always configure baseURL first
- if (baseURL) {
- config.baseURL = resolveIfNotPlain(baseURL, baseURI) || resolveIfNotPlain('./' + baseURL, baseURI);
- if (config.baseURL[config.baseURL.length - 1] !== '/')
- config.baseURL += '/';
- }
- if (cfg.paths)
- extend(config.paths, cfg.paths);
- envSet(loader, cfg, function(cfg) {
- if (cfg.paths)
- extend(config.paths, cfg.paths);
- });
- for (var p in config.paths) {
- if (config.paths[p].indexOf('*') === -1)
- continue;
- warn.call(config, 'Path config ' + p + ' -> ' + config.paths[p] + ' is no longer supported as wildcards are deprecated.');
- delete config.paths[p];
- }
- }
- if (cfg.defaultJSExtensions)
- warn.call(config, 'The defaultJSExtensions configuration option is deprecated.\n Use packages defaultExtension instead.', true);
- if (typeof cfg.pluginFirst === 'boolean')
- config.pluginFirst = cfg.pluginFirst;
- if (cfg.map) {
- for (var p in cfg.map) {
- var v = cfg.map[p];
- if (typeof v === 'string') {
- var mapped = coreResolve.call(loader, config, v, undefined, false, false);
- if (mapped[mapped.length -1] === '/' && p[p.length - 1] !== ':' && p[p.length - 1] !== '/')
- mapped = mapped.substr(0, mapped.length - 1);
- config.map[p] = mapped;
- }
- // object map
- else {
- var pkgName = coreResolve.call(loader, config, p[p.length - 1] !== '/' ? p + '/' : p, undefined, true, true);
- pkgName = pkgName.substr(0, pkgName.length - 1);
- var pkg = config.packages[pkgName];
- if (!pkg) {
- pkg = config.packages[pkgName] = createPackage();
- // use '' instead of false to keep type consistent
- pkg.defaultExtension = '';
- }
- setPkgConfig(pkg, { map: v }, pkgName, false, config);
- }
- }
- }
- 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 = coreResolve.call(loader, config, path.substr(0, packageLength), undefined, false, false);
- packageConfigPaths[i] = normalized + path.substr(packageLength);
- }
- config.packageConfigPaths = packageConfigPaths;
- }
- if (cfg.bundles) {
- for (var p in cfg.bundles) {
- var bundle = [];
- for (var i = 0; i < cfg.bundles[p].length; i++)
- bundle.push(loader.normalizeSync(cfg.bundles[p][i]));
- config.bundles[p] = bundle;
- }
- }
- if (cfg.packages) {
- for (var p in cfg.packages) {
- if (p.match(/^([^\/]+:)?\/\/$/))
- throw new TypeError('"' + p + '" is not a valid package name.');
- var pkgName = coreResolve.call(loader, config, p[p.length - 1] !== '/' ? p + '/' : p, undefined, true, true);
- pkgName = pkgName.substr(0, pkgName.length - 1);
- setPkgConfig(config.packages[pkgName] = config.packages[pkgName] || createPackage(), cfg.packages[p], pkgName, false, config);
- }
- }
- if (cfg.depCache) {
- for (var p in cfg.depCache)
- config.depCache[loader.normalizeSync(p)] = [].concat(cfg.depCache[p]);
- }
- if (cfg.meta) {
- for (var p in cfg.meta) {
- // base wildcard stays base
- if (p[0] === '*') {
- extend(config.meta[p] = config.meta[p] || {}, cfg.meta[p]);
- }
- else {
- var resolved = coreResolve.call(loader, config, p, undefined, true, true);
- extend(config.meta[resolved] = config.meta[resolved] || {}, cfg.meta[p]);
- }
- }
- }
- if ('transpiler' in cfg)
- config.transpiler = cfg.transpiler;
- // copy any remaining non-standard configuration properties
- for (var c in cfg) {
- if (configNames.indexOf(c) !== -1)
- continue;
- if (envConfigNames.indexOf(c) !== -1)
- continue;
- // warn.call(config, 'Setting custom config option `System.config({ ' + c + ': ... })` is deprecated. Avoid custom config options or set SystemJS.' + c + ' = ... directly.');
- loader[c] = cfg[c];
- }
- envSet(loader, cfg, function(cfg) {
- loader.config(cfg, true);
- });
- }
- function createPackage () {
- return {
- defaultExtension: undefined,
- main: undefined,
- format: undefined,
- meta: undefined,
- map: undefined,
- packageConfig: undefined,
- configured: false
- };
- }
- // deeply-merge (to first level) config with any existing package config
- function setPkgConfig (pkg, cfg, pkgName, prependConfig, config) {
- for (var prop in cfg) {
- if (prop === 'main' || prop === 'format' || prop === 'defaultExtension' || prop === 'configured') {
- if (!prependConfig || pkg[prop] === undefined)
- pkg[prop] = cfg[prop];
- }
- else if (prop === 'map') {
- (prependConfig ? prepend : extend)(pkg.map = pkg.map || {}, cfg.map);
- }
- else if (prop === 'meta') {
- (prependConfig ? prepend : extend)(pkg.meta = pkg.meta || {}, cfg.meta);
- }
- else if (Object.hasOwnProperty.call(cfg, prop)) {
- warn.call(config, '"' + prop + '" is not a valid package configuration option in package ' + pkgName);
- }
- }
- // default defaultExtension for packages only
- if (pkg.defaultExtension === undefined)
- pkg.defaultExtension = 'js';
- if (pkg.main === undefined && pkg.map && pkg.map['.']) {
- pkg.main = pkg.map['.'];
- delete pkg.map['.'];
- }
- // main object becomes main map
- else if (typeof pkg.main === 'object') {
- pkg.map = pkg.map || {};
- pkg.map['./@main'] = pkg.main;
- pkg.main['default'] = pkg.main['default'] || './';
- pkg.main = '@main';
- }
- return pkg;
- }
- var hasBuffer = typeof Buffer !== 'undefined';
- try {
- if (hasBuffer && new Buffer('a').toString('base64') !== 'YQ==')
- hasBuffer = false;
- }
- catch (e) {
- hasBuffer = false;
- }
- var sourceMapPrefix = '\n//# sourceMapping' + 'URL=data:application/json;base64,';
- function inlineSourceMap (sourceMapString) {
- if (hasBuffer)
- return sourceMapPrefix + new Buffer(sourceMapString).toString('base64');
- else if (typeof btoa !== 'undefined')
- return sourceMapPrefix + btoa(unescape(encodeURIComponent(sourceMapString)));
- else
- return '';
- }
- function getSource(source, sourceMap, address, wrap) {
- var lastLineIndex = source.lastIndexOf('\n');
- if (sourceMap) {
- if (typeof sourceMap != 'object')
- throw new TypeError('load.metadata.sourceMap must be set to an object.');
- sourceMap = JSON.stringify(sourceMap);
- }
- return (wrap ? '(function(System, SystemJS) {' : '') + source + (wrap ? '\n})(System, System);' : '')
- // adds the sourceURL comment if not already present
- + (source.substr(lastLineIndex, 15) != '\n//# sourceURL='
- ? '\n//# sourceURL=' + address + (sourceMap ? '!transpiled' : '') : '')
- // add sourceMappingURL if load.metadata.sourceMap is set
- + (sourceMap && inlineSourceMap(sourceMap) || '');
- }
- // script execution via injecting a script tag into the page
- // this allows CSP nonce to be set for CSP environments
- var head;
- function scriptExec(loader, source, sourceMap, address, nonce) {
- if (!head)
- head = document.head || document.body || document.documentElement;
- var script = document.createElement('script');
- script.text = getSource(source, sourceMap, address, false);
- var onerror = window.onerror;
- var e;
- window.onerror = function(_e) {
- e = addToError(_e, 'Evaluating ' + address);
- if (onerror)
- onerror.apply(this, arguments);
- };
- preExec(loader);
- if (nonce)
- script.setAttribute('nonce', nonce);
- head.appendChild(script);
- head.removeChild(script);
- postExec();
- window.onerror = onerror;
- if (e)
- return e;
- }
- var vm;
- var useVm;
- var curSystem;
- var callCounter = 0;
- function preExec (loader) {
- if (callCounter++ == 0)
- curSystem = envGlobal.System;
- envGlobal.System = envGlobal.SystemJS = loader;
- }
- function postExec () {
- if (--callCounter == 0)
- envGlobal.System = envGlobal.SystemJS = curSystem;
- }
- var supportsScriptExec = false;
- if (isBrowser && typeof document != 'undefined' && document.getElementsByTagName) {
- if (!(window.chrome && window.chrome.extension || navigator.userAgent.match(/^Node\.js/)))
- supportsScriptExec = true;
- }
- function evaluate (loader, source, sourceMap, address, integrity, nonce, noWrap) {
- if (!source)
- return;
- if (nonce && supportsScriptExec)
- return scriptExec(loader, source, sourceMap, address, nonce);
- try {
- preExec(loader);
- // global scoped eval for node (avoids require scope leak)
- if (!vm && loader._nodeRequire) {
- vm = loader._nodeRequire('vm');
- useVm = vm.runInThisContext("typeof System !== 'undefined' && System") === loader;
- }
- if (useVm)
- vm.runInThisContext(getSource(source, sourceMap, address, !noWrap), { filename: address + (sourceMap ? '!transpiled' : '') });
- else
- (0, eval)(getSource(source, sourceMap, address, !noWrap));
- postExec();
- }
- catch (e) {
- postExec();
- return e;
- }
- }
- function setHelpers (loader) {
- loader.set('@@cjs-helpers', loader.newModule({
- requireResolve: requireResolve.bind(loader),
- getPathVars: getPathVars
- }));
- loader.set('@@global-helpers', loader.newModule({
- prepareGlobal: prepareGlobal
- }));
- }
- function setAmdHelper (loader) {
- /*
- 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 normalized = loader.decanonicalize(names, referer);
- var module = loader.get(normalized);
- if (!module)
- throw new Error('Module not already loaded loading "' + names + '" as ' + normalized + (referer ? ' from "' + referer + '".' : '.'));
- return '__useDefault' in module ? module.__useDefault : 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);
- if (!name) {
- if (curMetaDeps) {
- deps = deps.concat(curMetaDeps);
- curMetaDeps = undefined;
- }
- }
- // remove system dependencies
- var requireIndex, exportsIndex, moduleIndex;
- if ((requireIndex = deps.indexOf('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(amdGetCJSDeps(factory.toString(), requireIndex));
- }
- if ((exportsIndex = deps.indexOf('exports')) !== -1)
- deps.splice(exportsIndex, 1);
- if ((moduleIndex = deps.indexOf('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 = noop;
- // add back in system dependencies
- if (moduleIndex !== -1)
- depValues.splice(moduleIndex, 0, module);
- if (exportsIndex !== -1)
- depValues.splice(exportsIndex, 0, exports);
- if (requireIndex !== -1) {
- var contextualRequire = function (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) {
- return loader.normalizeSync(name, module.id);
- };
- depValues.splice(requireIndex, 0, contextualRequire);
- }
- // set global require to AMD require
- var curRequire = envGlobal.require;
- envGlobal.require = require;
- var output = factory.apply(exportsIndex === -1 ? envGlobal : exports, depValues);
- envGlobal.require = curRequire;
- if (typeof output !== 'undefined')
- module.exports = output;
- }
- // anonymous define
- if (!name) {
- loader.registerDynamic(deps, false, curEsModule ? wrapEsModuleExecute(execute) : execute);
- }
- else {
- loader.registerDynamic(name, deps, false, execute);
- // 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 (lastNamedDefine) {
- lastNamedDefine = undefined;
- multipleNamedDefines = true;
- }
- else if (!multipleNamedDefines) {
- lastNamedDefine = [deps, execute];
- }
- }
- }
- define.amd = {};
- loader.amdDefine = define;
- loader.amdRequire = require;
- }
- // CJS
- var windowOrigin;
- if (typeof window !== 'undefined' && typeof document !== 'undefined' && window.location)
- windowOrigin = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
- function stripOrigin(path) {
- if (path.substr(0, 8) === 'file:///')
- return path.substr(7 + !!isWindows);
- if (windowOrigin && path.substr(0, windowOrigin.length) === windowOrigin)
- return path.substr(windowOrigin.length);
- return path;
- }
- function requireResolve (request, parentId) {
- return stripOrigin(this.normalizeSync(request, parentId));
- }
- function getPathVars (moduleId) {
- // remove any plugin syntax
- var pluginIndex = moduleId.lastIndexOf('!');
- var filename;
- if (pluginIndex !== -1)
- filename = moduleId.substr(0, pluginIndex);
- else
- filename = moduleId;
- var dirname = filename.split('/');
- dirname.pop();
- dirname = dirname.join('/');
- return {
- filename: stripOrigin(filename),
- dirname: stripOrigin(dirname)
- };
- }
- var commentRegEx = /(^|[^\\])(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
- var stringRegEx = /("[^"\\\n\r]*(\\.[^"\\\n\r]*)*"|'[^'\\\n\r]*(\\.[^'\\\n\r]*)*')/g;
- // extract CJS dependencies from source text via regex static analysis
- // read require('x') statements not in comments or strings
- 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) {
- for (var i = 0; i < locations.length; i++)
- if (locations[i][0] < match.index && locations[i][1] > match.index)
- 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]);
- // TODO: track template literals here before comments
- while (match = commentRegEx.exec(source)) {
- // only track comments not starting in strings
- if (!inLocation(stringLocations, match))
- commentLocations.push([match.index + match[1].length, match.index + match[0].length - 1]);
- }
- }
- while (match = cjsRequireRegEx.exec(source)) {
- // ensure we're not within a string or comment location
- if (!inLocation(stringLocations, match) && !inLocation(commentLocations, match)) {
- var dep = match[1].substr(1, match[1].length - 2);
- // skip cases like require('" + file + "')
- if (dep.match(/"|'/))
- continue;
- deps.push(dep);
- }
- }
- return deps;
- }
- // Global
- // bare minimum ignores
- var ignoredGlobalProps = ['_g', 'sessionStorage', 'localStorage', 'clipboardData', 'frames', 'frameElement', 'external',
- 'mozAnimationStartTime', 'mozPaintCount', 'webkitStorageInfo', 'webkitIndexedDB', 'mozInnerScreenY', 'mozInnerScreenX'];
- var globalSnapshot;
- function globalIterator (globalName) {
- if (ignoredGlobalProps.indexOf(globalName) !== -1)
- return;
- try {
- var value = envGlobal[globalName];
- }
- catch (e) {
- ignoredGlobalProps.push(globalName);
- }
- this(globalName, value);
- }
- function getGlobalValue (exports) {
- if (typeof exports === 'string')
- return readMemberExpression(exports, envGlobal);
- if (!(exports instanceof Array))
- throw new Error('Global exports must be a string or array.');
- var globalValue = {};
- for (var i = 0; i < exports.length; i++)
- globalValue[exports[i].split('.').pop()] = readMemberExpression(exports[i], envGlobal);
- return globalValue;
- }
- function prepareGlobal (moduleName, exports, globals, encapsulate) {
- // disable module detection
- var curDefine = envGlobal.define;
- envGlobal.define = undefined;
- // set globals
- var oldGlobals;
- if (globals) {
- oldGlobals = {};
- for (var g in globals) {
- oldGlobals[g] = envGlobal[g];
- envGlobal[g] = globals[g];
- }
- }
- // store a complete copy of the global object in order to detect changes
- if (!exports) {
- globalSnapshot = {};
- Object.keys(envGlobal).forEach(globalIterator, function (name, value) {
- globalSnapshot[name] = value;
- });
- }
- // return function to retrieve global
- return function () {
- var globalValue = exports ? getGlobalValue(exports) : {};
- var singleGlobal;
- var multipleExports = !!exports;
- if (!exports || encapsulate)
- Object.keys(envGlobal).forEach(globalIterator, function (name, value) {
- if (globalSnapshot[name] === value)
- return;
- if (value === undefined)
- return;
- // allow global encapsulation where globals are removed
- if (encapsulate)
- envGlobal[name] = undefined;
- if (!exports) {
- globalValue[name] = value;
- if (singleGlobal !== undefined) {
- if (!multipleExports && singleGlobal !== value)
- multipleExports = true;
- }
- else {
- singleGlobal = value;
- }
- }
- });
- globalValue = multipleExports ? globalValue : singleGlobal;
- // revert globals
- if (oldGlobals) {
- for (var g in oldGlobals)
- envGlobal[g] = oldGlobals[g];
- }
- envGlobal.define = curDefine;
- return globalValue;
- };
- }
- // AMD
- var cjsRequirePre = "(?:^|[^$_a-zA-Z\\xA0-\\uFFFF.])";
- var cjsRequirePost = "\\s*\\(\\s*(\"([^\"]+)\"|'([^']+)')\\s*\\)";
- var fnBracketRegEx = /\(([^\)]*)\)/;
- var wsRegEx = /^\s+|\s+$/g;
- var requireRegExs = {};
- function amdGetCJSDeps(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;
- }
- function wrapEsModuleExecute (execute) {
- return function (require, exports, module) {
- execute(require, exports, module);
- exports = module.exports;
- if ((typeof exports === 'object' || typeof exports === 'function') && !('__esModule' in exports))
- Object.defineProperty(module.exports, '__esModule', {
- value: true
- });
- };
- }
- // generate anonymous define from singular named define
- var multipleNamedDefines = false;
- var lastNamedDefine;
- var curMetaDeps;
- var curEsModule = false;
- function clearLastDefine (metaDeps, esModule) {
- curMetaDeps = metaDeps;
- curEsModule = esModule;
- lastNamedDefine = undefined;
- multipleNamedDefines = false;
- }
- function registerLastDefine (loader) {
- if (lastNamedDefine)
- loader.registerDynamic(curMetaDeps ? lastNamedDefine[0].concat(curMetaDeps) : lastNamedDefine[0],
- false, curEsModule ? wrapEsModuleExecute(lastNamedDefine[1]) : lastNamedDefine[1]);
- // bundles are an empty module
- else if (multipleNamedDefines)
- loader.registerDynamic([], false, noop);
- }
- var supportsScriptLoad = (isBrowser || isWorker) && typeof navigator !== 'undefined' && navigator.userAgent && !navigator.userAgent.match(/MSIE (9|10).0/);
- // include the node require since we're overriding it
- var nodeRequire;
- if (typeof require !== 'undefined' && typeof process !== 'undefined' && !process.browser)
- nodeRequire = require;
- function setMetaEsModule (metadata, moduleValue) {
- if (metadata.load.esModule && (typeof moduleValue === 'object' || typeof moduleValue === 'function') &&
- !('__esModule' in moduleValue))
- Object.defineProperty(moduleValue, '__esModule', {
- value: true
- });
- }
- function instantiate$1 (key, processAnonRegister) {
- var loader = this;
- var config = this[CONFIG];
- // first do bundles and depCache
- return (loadBundlesAndDepCache(config, this, key) || resolvedPromise$2)
- .then(function () {
- if (processAnonRegister())
- return;
- var metadata = loader[METADATA][key];
- // node module loading
- if (key.substr(0, 6) === '@node/') {
- if (!loader._nodeRequire)
- throw new TypeError('Error loading ' + key + '. Can only load node core modules in Node.');
- loader.registerDynamic([], false, function () {
- return loadNodeModule.call(loader, key.substr(6), loader.baseURL);
- });
- processAnonRegister();
- return;
- }
- if (metadata.load.scriptLoad ) {
- if (metadata.pluginKey || !supportsScriptLoad) {
- metadata.load.scriptLoad = false;
- warn.call(config, 'scriptLoad not supported for "' + key + '"');
- }
- }
- else if (metadata.load.scriptLoad !== false && !metadata.pluginKey && supportsScriptLoad) {
- // auto script load AMD, global without deps
- if (!metadata.load.deps && !metadata.load.globals &&
- (metadata.load.format === 'system' || metadata.load.format === 'register' || metadata.load.format === 'global' && metadata.load.exports))
- metadata.load.scriptLoad = true;
- }
- // fetch / translate / instantiate pipeline
- if (!metadata.load.scriptLoad)
- return initializePlugin(loader, key, metadata)
- .then(function () {
- return runFetchPipeline(loader, key, metadata, processAnonRegister, config.wasm);
- })
- // just script loading
- return new Promise(function (resolve, reject) {
- if (metadata.load.format === 'amd' && envGlobal.define !== loader.amdDefine)
- throw new Error('Loading AMD with scriptLoad requires setting the global `' + globalName + '.define = SystemJS.amdDefine`');
- scriptLoad(key, metadata.load.crossOrigin, metadata.load.integrity, function () {
- if (!processAnonRegister()) {
- metadata.load.format = 'global';
- var globalValue = metadata.load.exports && getGlobalValue(metadata.load.exports);
- loader.registerDynamic([], false, function () {
- setMetaEsModule(metadata, globalValue);
- return globalValue;
- });
- processAnonRegister();
- }
- resolve();
- }, reject);
- });
- })
- .then(function (instantiated) {
- delete loader[METADATA][key];
- return instantiated;
- });
- }
- function initializePlugin (loader, key, metadata) {
- if (!metadata.pluginKey)
- return resolvedPromise$2;
- return loader.import(metadata.pluginKey).then(function (plugin) {
- metadata.pluginModule = plugin;
- metadata.pluginLoad = {
- name: key,
- address: metadata.pluginArgument,
- source: undefined,
- metadata: metadata.load
- };
- metadata.load.deps = metadata.load.deps || [];
- });
- }
- function loadBundlesAndDepCache (config, loader, key) {
- // load direct deps, in turn will pick up their trace trees
- var deps;
- if (isBrowser && (deps = config.depCache[key])) {
- for (var i = 0; i < deps.length; i++)
- loader.normalize(deps[i], key).then(preloadScript);
- }
- else {
- var matched = false;
- for (var b in config.bundles) {
- for (var i = 0; i < config.bundles[b].length; i++) {
- var curModule = config.bundles[b][i];
- if (curModule === key) {
- matched = true;
- break;
- }
- // wildcard in bundles includes / boundaries
- if (curModule.indexOf('*') !== -1) {
- var parts = curModule.split('*');
- if (parts.length !== 2) {
- config.bundles[b].splice(i--, 1);
- continue;
- }
- if (key.substr(0, parts[0].length) === parts[0] &&
- key.substr(key.length - parts[1].length, parts[1].length) === parts[1]) {
- matched = true;
- break;
- }
- }
- }
- if (matched)
- return loader.import(b);
- }
- }
- }
- function runFetchPipeline (loader, key, metadata, processAnonRegister, wasm) {
- if (metadata.load.exports && !metadata.load.format)
- metadata.load.format = 'global';
- return resolvedPromise$2
- // locate
- .then(function () {
- if (!metadata.pluginModule || !metadata.pluginModule.locate)
- return;
- return Promise.resolve(metadata.pluginModule.locate.call(loader, metadata.pluginLoad))
- .then(function (address) {
- if (address)
- metadata.pluginLoad.address = address;
- });
- })
- // fetch
- .then(function () {
- if (!metadata.pluginModule)
- return fetch$1(key, metadata.load.authorization, metadata.load.integrity, wasm);
- wasm = false;
- if (!metadata.pluginModule.fetch)
- return fetch$1(metadata.pluginLoad.address, metadata.load.authorization, metadata.load.integrity, false);
- return metadata.pluginModule.fetch.call(loader, metadata.pluginLoad, function (load) {
- return fetch$1(load.address, metadata.load.authorization, metadata.load.integrity, false);
- });
- })
- .then(function (fetched) {
- // fetch is already a utf-8 string if not doing wasm detection
- if (!wasm || typeof fetched === 'string')
- return translateAndInstantiate(loader, key, fetched, metadata, processAnonRegister);
- return checkInstantiateWasm(loader, fetched, processAnonRegister)
- .then(function (wasmInstantiated) {
- if (wasmInstantiated)
- return;
- // not wasm -> convert buffer into utf-8 string to execute as a module
- // TextDecoder compatibility matches WASM currently. Need to keep checking this.
- // The TextDecoder interface is documented at http://encoding.spec.whatwg.org/#interface-textdecoder
- var stringSource = isBrowser ? new TextDecoder('utf-8').decode(new Uint8Array(fetched)) : fetched.toString();
- return translateAndInstantiate(loader, key, stringSource, metadata, processAnonRegister);
- });
- });
- }
- function translateAndInstantiate (loader, key, source, metadata, processAnonRegister) {
- return Promise.resolve(source)
- // translate
- .then(function (source) {
- if (metadata.load.format === 'detect')
- metadata.load.format = undefined;
- readMetaSyntax(source, metadata);
- if (!metadata.pluginModule)
- return source;
- metadata.pluginLoad.source = source;
- if (!metadata.pluginModule.translate)
- return source;
- return Promise.resolve(metadata.pluginModule.translate.call(loader, metadata.pluginLoad, metadata.traceOpts))
- .then(function (translated) {
- if (metadata.load.sourceMap) {
- if (typeof metadata.load.sourceMap !== 'object')
- throw new Error('metadata.load.sourceMap must be set to an object.');
- sanitizeSourceMap(metadata.pluginLoad.address, metadata.load.sourceMap);
- }
- if (typeof translated === 'string')
- return translated;
- else
- return metadata.pluginLoad.source;
- });
- })
- .then(function (source) {
- if (!metadata.load.format && source.substring(0, 8) === '"bundle"') {
- metadata.load.format = 'system';
- return source;
- }
- if (metadata.load.format === 'register' || !metadata.load.format && detectRegisterFormat(source)) {
- metadata.load.format = 'register';
- return source;
- }
- if (metadata.load.format !== 'esm' && (metadata.load.format || !source.match(esmRegEx))) {
- return source;
- }
- metadata.load.format = 'esm';
- return transpile(loader, source, key, metadata, processAnonRegister);
- })
- // instantiate
- .then(function (translated) {
- if (typeof translated !== 'string' || !metadata.pluginModule || !metadata.pluginModule.instantiate)
- return translated;
- var calledInstantiate = false;
- metadata.pluginLoad.source = translated;
- return Promise.resolve(metadata.pluginModule.instantiate.call(loader, metadata.pluginLoad, function (load) {
- translated = load.source;
- metadata.load = load.metadata;
- if (calledInstantiate)
- throw new Error('Instantiate must only be called once.');
- calledInstantiate = true;
- }))
- .then(function (result) {
- if (calledInstantiate)
- return translated;
- return protectedCreateNamespace(result);
- });
- })
- .then(function (source) {
- // plugin instantiate result case
- if (typeof source !== 'string')
- return source;
- if (!metadata.load.format)
- metadata.load.format = detectLegacyFormat(source);
- var registered = false;
- switch (metadata.load.format) {
- case 'esm':
- case 'register':
- case 'system':
- var err = evaluate(loader, source, metadata.load.sourceMap, key, metadata.load.integrity, metadata.load.nonce, false);
- if (err)
- throw err;
- if (!processAnonRegister())
- return emptyModule;
- return;
- break;
- case 'json':
- // warn.call(config, '"json" module format is deprecated.');
- var parsed = JSON.parse(source);
- return loader.newModule({ default: parsed, __useDefault: parsed });
- case 'amd':
- var curDefine = envGlobal.define;
- envGlobal.define = loader.amdDefine;
- clearLastDefine(metadata.load.deps, metadata.load.esModule);
- var err = evaluate(loader, source, metadata.load.sourceMap, key, metadata.load.integrity, metadata.load.nonce, false);
- // if didn't register anonymously, use the last named define if only one
- registered = processAnonRegister();
- if (!registered) {
- registerLastDefine(loader);
- registered = processAnonRegister();
- }
- envGlobal.define = curDefine;
- if (err)
- throw err;
- break;
- case 'cjs':
- var metaDeps = metadata.load.deps;
- var deps = (metadata.load.deps || []).concat(metadata.load.cjsRequireDetection ? getCJSDeps(source) : []);
- for (var g in metadata.load.globals)
- if (metadata.load.globals[g])
- deps.push(metadata.load.globals[g]);
- loader.registerDynamic(deps, true, function (require, exports, module) {
- require.resolve = function (key) {
- return requireResolve.call(loader, key, module.id);
- };
- // support module.paths ish
- module.paths = [];
- module.require = require;
- // ensure meta deps execute first
- if (!metadata.load.cjsDeferDepsExecute && metaDeps)
- for (var i = 0; i < metaDeps.length; i++)
- require(metaDeps[i]);
- var pathVars = getPathVars(module.id);
- var __cjsWrapper = {
- exports: exports,
- args: [require, exports, module, pathVars.filename, pathVars.dirname, envGlobal, envGlobal]
- };
- var cjsWrapper = "(function (require, exports, module, __filename, __dirname, global, GLOBAL";
- // add metadata.globals to the wrapper arguments
- if (metadata.load.globals)
- for (var g in metadata.load.globals) {
- __cjsWrapper.args.push(require(metadata.load.globals[g]));
- cjsWrapper += ", " + g;
- }
- // disable AMD detection
- var define = envGlobal.define;
- envGlobal.define = undefined;
- envGlobal.__cjsWrapper = __cjsWrapper;
- source = cjsWrapper + ") {" + source.replace(hashBangRegEx$1, '') + "\n}).apply(__cjsWrapper.exports, __cjsWrapper.args);";
- var err = evaluate(loader, source, metadata.load.sourceMap, key, metadata.load.integrity, metadata.load.nonce, false);
- if (err)
- throw err;
- setMetaEsModule(metadata, exports);
- envGlobal.__cjsWrapper = undefined;
- envGlobal.define = define;
- });
- registered = processAnonRegister();
- break;
- case 'global':
- var deps = metadata.load.deps || [];
- for (var g in metadata.load.globals) {
- var gl = metadata.load.globals[g];
- if (gl)
- deps.push(gl);
- }
- loader.registerDynamic(deps, false, function (require, exports, module) {
- var globals;
- if (metadata.load.globals) {
- globals = {};
- for (var g in metadata.load.globals)
- if (metadata.load.globals[g])
- globals[g] = require(metadata.load.globals[g]);
- }
- var exportName = metadata.load.exports;
- if (exportName)
- source += '\n' + globalName + '["' + exportName + '"] = ' + exportName + ';';
- var retrieveGlobal = prepareGlobal(module.id, exportName, globals, metadata.load.encapsulateGlobal);
- var err = evaluate(loader, source, metadata.load.sourceMap, key, metadata.load.integrity, metadata.load.nonce, true);
- if (err)
- throw err;
- var output = retrieveGlobal();
- setMetaEsModule(metadata, output);
- return output;
- });
- registered = processAnonRegister();
- break;
- default:
- throw new TypeError('Unknown module format "' + metadata.load.format + '" for "' + key + '".' + (metadata.load.format === 'es6' ? ' Use "esm" instead here.' : ''));
- }
- if (!registered)
- throw new Error('Module ' + key + ' detected as ' + metadata.load.format + ' but didn\'t execute correctly.');
- });
- }
- var globalName = typeof self != 'undefined' ? 'self' : 'global';
- // 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+)?(?!type)([^"'\(\)\n; ]+)\s*from\s*['"]|\{)|export\s+\*\s+from\s+["']|export\s*(\{|default|function|class|var|const|let|async\s+function))/;
- var leadingCommentAndMetaRegEx = /^(\s*\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)*\s*/;
- function detectRegisterFormat(source) {
- var leadingCommentAndMeta = source.match(leadingCommentAndMetaRegEx);
- if (!leadingCommentAndMeta)
- return false;
- var codeStart = leadingCommentAndMeta[0].length;
- return source.substr(codeStart, 17) === 'SystemJS.register' || source.substr(codeStart, 15) === 'System.register';
- }
- // 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]*\))/;
- /// require('...') || exports[''] = ... || exports.asd = ... || module.exports = ...
- var cjsExportsRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])(exports\s*(\[['"]|\.)|module(\.exports|\['exports'\]|\["exports"\])\s*(\[['"]|[=,\.]))/;
- // used to support leading #!/usr/bin/env in scripts as supported in Node
- var hashBangRegEx$1 = /^\#\!.*/;
- function detectLegacyFormat (source) {
- if (source.match(amdRegEx))
- return 'amd';
- cjsExportsRegEx.lastIndex = 0;
- cjsRequireRegEx.lastIndex = 0;
- if (cjsRequireRegEx.exec(source) || cjsExportsRegEx.exec(source))
- return 'cjs';
- // global is the fallback format
- return 'global';
- }
- function sanitizeSourceMap (address, sourceMap) {
- var originalName = address.split('!')[0];
- // force set the filename of the original file
- if (!sourceMap.file || sourceMap.file == address)
- sourceMap.file = originalName + '!transpiled';
- // force set the sources list if only one source
- if (!sourceMap.sources || sourceMap.sources.length <= 1 && (!sourceMap.sources[0] || sourceMap.sources[0] === address))
- sourceMap.sources = [originalName];
- }
- function transpile (loader, source, key, metadata, processAnonRegister) {
- if (!loader.transpiler)
- throw new TypeError('Unable to dynamically transpile ES module\n A loader plugin needs to be configured via `SystemJS.config({ transpiler: \'transpiler-module\' })`.');
- // deps support for es transpile
- if (metadata.load.deps) {
- var depsPrefix = '';
- for (var i = 0; i < metadata.load.deps.length; i++)
- depsPrefix += 'import "' + metadata.load.deps[i] + '"; ';
- source = depsPrefix + source;
- }
- // do transpilation
- return loader.import.call(loader, loader.transpiler)
- .then(function (transpiler) {
- transpiler = transpiler.__useDefault || transpiler;
- // translate hooks means this is a transpiler plugin instead of a raw implementation
- if (!transpiler.translate)
- throw new Error(loader.transpiler + ' is not a valid transpiler plugin.');
- // if transpiler is the same as the plugin loader, then don't run twice
- if (transpiler === metadata.pluginModule)
- return source;
- // convert the source map into an object for transpilation chaining
- if (typeof metadata.load.sourceMap === 'string')
- metadata.load.sourceMap = JSON.parse(metadata.load.sourceMap);
- metadata.pluginLoad = metadata.pluginLoad || {
- name: key,
- address: key,
- source: source,
- metadata: metadata.load
- };
- metadata.load.deps = metadata.load.deps || [];
- return Promise.resolve(transpiler.translate.call(loader, metadata.pluginLoad, metadata.traceOpts))
- .then(function (source) {
- // sanitize sourceMap if an object not a JSON string
- var sourceMap = metadata.load.sourceMap;
- if (sourceMap && typeof sourceMap === 'object')
- sanitizeSourceMap(key, sourceMap);
- if (metadata.load.format === 'esm' && detectRegisterFormat(source))
- metadata.load.format = 'register';
- return source;
- });
- }, function (err) {
- throw LoaderError__Check_error_message_for_loader_stack(err, 'Unable to load transpiler to transpile ' + key);
- });
- }
- // 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 (target[curPart] === undefined)
- target[curPart] = value;
- }
- function readMetaSyntax (source, metadata) {
- var meta = source.match(metaRegEx);
- if (!meta)
- return;
- 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 === 'deps')
- metaName = 'deps[]';
- if (metaName.substr(metaName.length - 2, 2) === '[]') {
- metaName = metaName.substr(0, metaName.length - 2);
- metadata.load[metaName] = metadata.load[metaName] || [];
- metadata.load[metaName].push(metaValue);
- }
- // "use strict" is not meta
- else if (metaName !== 'use') {
- setMetaProperty(metadata.load, metaName, metaValue);
- }
- }
- else {
- metadata.load[metaString] = true;
- }
- }
- }
- var scriptSrc;
- // Promise detection and error message
- if (typeof Promise === 'undefined')
- throw new Error('SystemJS needs a Promise polyfill.');
- if (typeof document !== 'undefined') {
- var scripts = document.getElementsByTagName('script');
- var curScript = scripts[scripts.length - 1];
- if (document.currentScript && (curScript.defer || curScript.async))
- curScript = document.currentScript;
- scriptSrc = curScript && curScript.src;
- }
- // worker
- else if (typeof importScripts !== 'undefined') {
- try {
- throw new Error('_');
- }
- catch (e) {
- e.stack.replace(/(?:at|@).*(http.+):[\d]+:[\d]+/, function(m, url) {
- scriptSrc = url;
- });
- }
- }
- // node
- else if (typeof __filename !== 'undefined') {
- scriptSrc = __filename;
- }
- function SystemJSLoader () {
- RegisterLoader.call(this);
- // NB deprecate
- this._loader = {};
- // internal metadata store
- this[METADATA] = {};
- // internal configuration
- this[CONFIG] = {
- baseURL: baseURI,
- paths: {},
- packageConfigPaths: [],
- packageConfigKeys: [],
- map: {},
- packages: {},
- depCache: {},
- meta: {},
- bundles: {},
- production: false,
- transpiler: undefined,
- loadedBundles: {},
- // global behaviour flags
- warnings: false,
- pluginFirst: false,
- // enable wasm loading and detection when supported
- wasm: false
- };
- // make the location of the system.js script accessible (if any)
- this.scriptSrc = scriptSrc;
- this._nodeRequire = nodeRequire;
- // support the empty module, as a concept
- this.registry.set('@empty', emptyModule);
- setProduction.call(this, false, false);
- // add module format helpers
- setHelpers(this);
- setAmdHelper(this);
- }
- var envModule;
- function setProduction (isProduction, isBuilder) {
- this[CONFIG].production = isProduction;
- this.registry.set('@system-env', envModule = this.newModule({
- browser: isBrowser,
- node: !!this._nodeRequire,
- production: !isBuilder && isProduction,
- dev: isBuilder || !isProduction,
- build: isBuilder,
- 'default': true
- }));
- }
- SystemJSLoader.prototype = Object.create(RegisterLoader.prototype);
- SystemJSLoader.prototype.constructor = SystemJSLoader;
- // NB deprecate normalize
- SystemJSLoader.prototype[SystemJSLoader.resolve = RegisterLoader.resolve] = SystemJSLoader.prototype.normalize = normalize;
- SystemJSLoader.prototype.load = function (key, parentKey) {
- warn.call(this[CONFIG], 'System.load is deprecated.');
- return this.import(key, parentKey);
- };
- // NB deprecate decanonicalize, normalizeSync
- SystemJSLoader.prototype.decanonicalize = SystemJSLoader.prototype.normalizeSync = SystemJSLoader.prototype.resolveSync = normalizeSync;
- SystemJSLoader.prototype[SystemJSLoader.instantiate = RegisterLoader.instantiate] = instantiate$1;
- SystemJSLoader.prototype.config = setConfig;
- SystemJSLoader.prototype.getConfig = getConfig;
- SystemJSLoader.prototype.global = envGlobal;
- SystemJSLoader.prototype.import = function () {
- return RegisterLoader.prototype.import.apply(this, arguments)
- .then(function (m) {
- return '__useDefault' in m ? m.__useDefault : m;
- });
- };
- var configNames = ['baseURL', 'map', 'paths', 'packages', 'packageConfigPaths', 'depCache', 'meta', 'bundles', 'transpiler', 'warnings', 'pluginFirst', 'production', 'wasm'];
- var hasProxy = typeof Proxy !== 'undefined';
- for (var i = 0; i < configNames.length; i++) (function (configName) {
- Object.defineProperty(SystemJSLoader.prototype, configName, {
- get: function () {
- var cfg = getConfigItem(this[CONFIG], configName);
- if (hasProxy && typeof cfg === 'object')
- cfg = new Proxy(cfg, {
- set: function (target, option) {
- throw new Error('Cannot set SystemJS.' + configName + '["' + option + '"] directly. Use SystemJS.config({ ' + configName + ': { "' + option + '": ... } }) rather.');
- }
- });
- //if (typeof cfg === 'object')
- // warn.call(this[CONFIG], 'Referencing `SystemJS.' + configName + '` is deprecated. Use the config getter `SystemJS.getConfig(\'' + configName + '\')`');
- return cfg;
- },
- set: function (name) {
- throw new Error('Setting `SystemJS.' + configName + '` directly is no longer supported. Use `SystemJS.config({ ' + configName + ': ... })`.');
- }
- });
- })(configNames[i]);
- /*
- * Backwards-compatible registry API, to be deprecated
- */
- function registryWarn(loader, method) {
- warn.call(loader[CONFIG], 'SystemJS.' + method + ' is deprecated for SystemJS.registry.' + method);
- }
- SystemJSLoader.prototype.delete = function (key) {
- registryWarn(this, 'delete');
- return this.registry.delete(key);
- };
- SystemJSLoader.prototype.get = function (key) {
- registryWarn(this, 'get');
- return this.registry.get(key);
- };
- SystemJSLoader.prototype.has = function (key) {
- registryWarn(this, 'has');
- return this.registry.has(key);
- };
- SystemJSLoader.prototype.set = function (key, module) {
- registryWarn(this, 'set');
- return this.registry.set(key, module);
- };
- SystemJSLoader.prototype.newModule = function (bindings) {
- return new ModuleNamespace(bindings);
- };
- SystemJSLoader.prototype.isModule = isModule;
- // ensure System.register and System.registerDynamic decanonicalize
- SystemJSLoader.prototype.register = function (key, deps, declare) {
- if (typeof key === 'string')
- key = decanonicalize.call(this, this[CONFIG], key);
- return RegisterLoader.prototype.register.call(this, key, deps, declare);
- };
- SystemJSLoader.prototype.registerDynamic = function (key, deps, executingRequire, execute) {
- if (typeof key === 'string')
- key = decanonicalize.call(this, this[CONFIG], key);
- return RegisterLoader.prototype.registerDynamic.call(this, key, deps, executingRequire, execute);
- };
- SystemJSLoader.prototype.version = "0.21.6 Dev";
- var System = new SystemJSLoader();
- // only set the global System on the global in browsers
- if (isBrowser || isWorker)
- envGlobal.SystemJS = envGlobal.System = System;
- if (typeof module !== 'undefined' && module.exports)
- module.exports = System;
- }());
- //# sourceMappingURL=system.src.js.map
|