svelte.js 810 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (factory((global.svelte = {})));
  5. }(this, (function (exports) { 'use strict';
  6. function assign(tar, src) {
  7. for (var k in src) tar[k] = src[k];
  8. return tar;
  9. }
  10. // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
  11. const now = (typeof process !== 'undefined' && process.hrtime)
  12. ? () => {
  13. const t = process.hrtime();
  14. return t[0] * 1e3 + t[1] / 1e6;
  15. }
  16. : () => self.performance.now();
  17. function collapseTimings(timings) {
  18. const result = {};
  19. timings.forEach(timing => {
  20. result[timing.label] = Object.assign({
  21. total: timing.end - timing.start
  22. }, timing.children && collapseTimings(timing.children));
  23. });
  24. return result;
  25. }
  26. class Stats {
  27. constructor({ onwarn }) {
  28. this.startTime = now();
  29. this.stack = [];
  30. this.currentChildren = this.timings = [];
  31. this.onwarn = onwarn;
  32. this.warnings = [];
  33. }
  34. start(label) {
  35. const timing = {
  36. label,
  37. start: now(),
  38. end: null,
  39. children: []
  40. };
  41. this.currentChildren.push(timing);
  42. this.stack.push(timing);
  43. this.currentTiming = timing;
  44. this.currentChildren = timing.children;
  45. }
  46. stop(label) {
  47. if (label !== this.currentTiming.label) {
  48. throw new Error(`Mismatched timing labels (expected ${this.currentTiming.label}, got ${label})`);
  49. }
  50. this.currentTiming.end = now();
  51. this.stack.pop();
  52. this.currentTiming = this.stack[this.stack.length - 1];
  53. this.currentChildren = this.currentTiming ? this.currentTiming.children : this.timings;
  54. }
  55. render(component) {
  56. const timings = Object.assign({
  57. total: now() - this.startTime
  58. }, collapseTimings(this.timings));
  59. // TODO would be good to have this info even
  60. // if options.generate is false
  61. const imports = component && component.imports.map(node => {
  62. return {
  63. source: node.source.value,
  64. specifiers: node.specifiers.map(specifier => {
  65. return {
  66. name: (specifier.type === 'ImportDefaultSpecifier' ? 'default' :
  67. specifier.type === 'ImportNamespaceSpecifier' ? '*' :
  68. specifier.imported.name),
  69. as: specifier.local.name
  70. };
  71. })
  72. };
  73. });
  74. const hooks = component && {
  75. oncreate: !!component.templateProperties.oncreate,
  76. ondestroy: !!component.templateProperties.ondestroy,
  77. onstate: !!component.templateProperties.onstate,
  78. onupdate: !!component.templateProperties.onupdate
  79. };
  80. const computed = new Set(component.computations.map(c => c.key));
  81. return {
  82. props: Array.from(component.expectedProperties).filter(key => !computed.has(key)),
  83. timings,
  84. warnings: this.warnings,
  85. imports,
  86. hooks
  87. };
  88. }
  89. warn(warning) {
  90. this.warnings.push(warning);
  91. this.onwarn(warning);
  92. }
  93. }
  94. // Reserved word lists for various dialects of the language
  95. var reservedWords = {
  96. 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
  97. 5: "class enum extends super const export import",
  98. 6: "enum",
  99. strict: "implements interface let package private protected public static yield",
  100. strictBind: "eval arguments"
  101. };
  102. // And the keywords
  103. var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
  104. var keywords = {
  105. 5: ecma5AndLessKeywords,
  106. 6: ecma5AndLessKeywords + " const class extends export import super"
  107. };
  108. var keywordRelationalOperator = /^in(stanceof)?$/;
  109. // ## Character categories
  110. // Big ugly regular expressions that match characters in the
  111. // whitespace, identifier, and identifier-start categories. These
  112. // are only applied when a character is found to actually have a
  113. // code point above 128.
  114. // Generated by `bin/generate-identifier-regex.js`.
  115. var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7b9\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  116. var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
  117. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  118. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  119. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  120. // These are a run-length and offset encoded representation of the
  121. // >0xffff code points that are a valid part of identifiers. The
  122. // offset starts at 0x10000, and each pair of numbers represents an
  123. // offset to the next range, and then a size of the range. They were
  124. // generated by bin/generate-identifier-regex.js
  125. // eslint-disable-next-line comma-spacing
  126. var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,190,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,26,230,43,117,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,68,12,0,67,12,65,1,31,6129,15,754,9486,286,82,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541];
  127. // eslint-disable-next-line comma-spacing
  128. var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,280,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239];
  129. // This has a complexity linear to the value of the code. The
  130. // assumption is that looking up astral identifier characters is
  131. // rare.
  132. function isInAstralSet(code, set) {
  133. var pos = 0x10000;
  134. for (var i = 0; i < set.length; i += 2) {
  135. pos += set[i];
  136. if (pos > code) { return false }
  137. pos += set[i + 1];
  138. if (pos >= code) { return true }
  139. }
  140. }
  141. // Test whether a given character code starts an identifier.
  142. function isIdentifierStart(code, astral) {
  143. if (code < 65) { return code === 36 }
  144. if (code < 91) { return true }
  145. if (code < 97) { return code === 95 }
  146. if (code < 123) { return true }
  147. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  148. if (astral === false) { return false }
  149. return isInAstralSet(code, astralIdentifierStartCodes)
  150. }
  151. // Test whether a given character is part of an identifier.
  152. function isIdentifierChar(code, astral) {
  153. if (code < 48) { return code === 36 }
  154. if (code < 58) { return true }
  155. if (code < 65) { return false }
  156. if (code < 91) { return true }
  157. if (code < 97) { return code === 95 }
  158. if (code < 123) { return true }
  159. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  160. if (astral === false) { return false }
  161. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  162. }
  163. // ## Token types
  164. // The assignment of fine-grained, information-carrying type objects
  165. // allows the tokenizer to store the information it has about a
  166. // token in a way that is very cheap for the parser to look up.
  167. // All token type variables start with an underscore, to make them
  168. // easy to recognize.
  169. // The `beforeExpr` property is used to disambiguate between regular
  170. // expressions and divisions. It is set on all token types that can
  171. // be followed by an expression (thus, a slash after them would be a
  172. // regular expression).
  173. //
  174. // The `startsExpr` property is used to check if the token ends a
  175. // `yield` expression. It is set on all token types that either can
  176. // directly start an expression (like a quotation mark) or can
  177. // continue an expression (like the body of a string).
  178. //
  179. // `isLoop` marks a keyword as starting a loop, which is important
  180. // to know when parsing a label, in order to allow or disallow
  181. // continue jumps to that label.
  182. var TokenType = function TokenType(label, conf) {
  183. if ( conf === void 0 ) conf = {};
  184. this.label = label;
  185. this.keyword = conf.keyword;
  186. this.beforeExpr = !!conf.beforeExpr;
  187. this.startsExpr = !!conf.startsExpr;
  188. this.isLoop = !!conf.isLoop;
  189. this.isAssign = !!conf.isAssign;
  190. this.prefix = !!conf.prefix;
  191. this.postfix = !!conf.postfix;
  192. this.binop = conf.binop || null;
  193. this.updateContext = null;
  194. };
  195. function binop(name, prec) {
  196. return new TokenType(name, {beforeExpr: true, binop: prec})
  197. }
  198. var beforeExpr = {beforeExpr: true};
  199. var startsExpr = {startsExpr: true};
  200. // Map keyword names to token types.
  201. var keywords$1 = {};
  202. // Succinct definitions of keyword token types
  203. function kw(name, options) {
  204. if ( options === void 0 ) options = {};
  205. options.keyword = name;
  206. return keywords$1[name] = new TokenType(name, options)
  207. }
  208. var types = {
  209. num: new TokenType("num", startsExpr),
  210. regexp: new TokenType("regexp", startsExpr),
  211. string: new TokenType("string", startsExpr),
  212. name: new TokenType("name", startsExpr),
  213. eof: new TokenType("eof"),
  214. // Punctuation token types.
  215. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  216. bracketR: new TokenType("]"),
  217. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  218. braceR: new TokenType("}"),
  219. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  220. parenR: new TokenType(")"),
  221. comma: new TokenType(",", beforeExpr),
  222. semi: new TokenType(";", beforeExpr),
  223. colon: new TokenType(":", beforeExpr),
  224. dot: new TokenType("."),
  225. question: new TokenType("?", beforeExpr),
  226. arrow: new TokenType("=>", beforeExpr),
  227. template: new TokenType("template"),
  228. invalidTemplate: new TokenType("invalidTemplate"),
  229. ellipsis: new TokenType("...", beforeExpr),
  230. backQuote: new TokenType("`", startsExpr),
  231. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  232. // Operators. These carry several kinds of properties to help the
  233. // parser use them properly (the presence of these properties is
  234. // what categorizes them as operators).
  235. //
  236. // `binop`, when present, specifies that this operator is a binary
  237. // operator, and will refer to its precedence.
  238. //
  239. // `prefix` and `postfix` mark the operator as a prefix or postfix
  240. // unary operator.
  241. //
  242. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  243. // binary operators with a very low precedence, that should result
  244. // in AssignmentExpression nodes.
  245. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  246. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  247. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  248. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  249. logicalOR: binop("||", 1),
  250. logicalAND: binop("&&", 2),
  251. bitwiseOR: binop("|", 3),
  252. bitwiseXOR: binop("^", 4),
  253. bitwiseAND: binop("&", 5),
  254. equality: binop("==/!=/===/!==", 6),
  255. relational: binop("</>/<=/>=", 7),
  256. bitShift: binop("<</>>/>>>", 8),
  257. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  258. modulo: binop("%", 10),
  259. star: binop("*", 10),
  260. slash: binop("/", 10),
  261. starstar: new TokenType("**", {beforeExpr: true}),
  262. // Keyword token types.
  263. _break: kw("break"),
  264. _case: kw("case", beforeExpr),
  265. _catch: kw("catch"),
  266. _continue: kw("continue"),
  267. _debugger: kw("debugger"),
  268. _default: kw("default", beforeExpr),
  269. _do: kw("do", {isLoop: true, beforeExpr: true}),
  270. _else: kw("else", beforeExpr),
  271. _finally: kw("finally"),
  272. _for: kw("for", {isLoop: true}),
  273. _function: kw("function", startsExpr),
  274. _if: kw("if"),
  275. _return: kw("return", beforeExpr),
  276. _switch: kw("switch"),
  277. _throw: kw("throw", beforeExpr),
  278. _try: kw("try"),
  279. _var: kw("var"),
  280. _const: kw("const"),
  281. _while: kw("while", {isLoop: true}),
  282. _with: kw("with"),
  283. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  284. _this: kw("this", startsExpr),
  285. _super: kw("super", startsExpr),
  286. _class: kw("class", startsExpr),
  287. _extends: kw("extends", beforeExpr),
  288. _export: kw("export"),
  289. _import: kw("import"),
  290. _null: kw("null", startsExpr),
  291. _true: kw("true", startsExpr),
  292. _false: kw("false", startsExpr),
  293. _in: kw("in", {beforeExpr: true, binop: 7}),
  294. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  295. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  296. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  297. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  298. };
  299. // Matches a whole line break (where CRLF is considered a single
  300. // line break). Used to count lines.
  301. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  302. var lineBreakG = new RegExp(lineBreak.source, "g");
  303. function isNewLine(code, ecma2019String) {
  304. return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029))
  305. }
  306. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  307. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  308. var ref = Object.prototype;
  309. var hasOwnProperty = ref.hasOwnProperty;
  310. var toString = ref.toString;
  311. // Checks if an object has a property.
  312. function has(obj, propName) {
  313. return hasOwnProperty.call(obj, propName)
  314. }
  315. var isArray = Array.isArray || (function (obj) { return (
  316. toString.call(obj) === "[object Array]"
  317. ); });
  318. // These are used when `options.locations` is on, for the
  319. // `startLoc` and `endLoc` properties.
  320. var Position = function Position(line, col) {
  321. this.line = line;
  322. this.column = col;
  323. };
  324. Position.prototype.offset = function offset (n) {
  325. return new Position(this.line, this.column + n)
  326. };
  327. var SourceLocation = function SourceLocation(p, start, end) {
  328. this.start = start;
  329. this.end = end;
  330. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  331. };
  332. // The `getLineInfo` function is mostly useful when the
  333. // `locations` option is off (for performance reasons) and you
  334. // want to find the line/column position for a given character
  335. // offset. `input` should be the code string that the offset refers
  336. // into.
  337. function getLineInfo(input, offset) {
  338. for (var line = 1, cur = 0;;) {
  339. lineBreakG.lastIndex = cur;
  340. var match = lineBreakG.exec(input);
  341. if (match && match.index < offset) {
  342. ++line;
  343. cur = match.index + match[0].length;
  344. } else {
  345. return new Position(line, offset - cur)
  346. }
  347. }
  348. }
  349. // A second optional argument can be given to further configure
  350. // the parser process. These options are recognized:
  351. var defaultOptions = {
  352. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  353. // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
  354. // for strict mode, the set of reserved words, and support for
  355. // new syntax features. The default is 7.
  356. ecmaVersion: 7,
  357. // `sourceType` indicates the mode the code should be parsed in.
  358. // Can be either `"script"` or `"module"`. This influences global
  359. // strict mode and parsing of `import` and `export` declarations.
  360. sourceType: "script",
  361. // `onInsertedSemicolon` can be a callback that will be called
  362. // when a semicolon is automatically inserted. It will be passed
  363. // th position of the comma as an offset, and if `locations` is
  364. // enabled, it is given the location as a `{line, column}` object
  365. // as second argument.
  366. onInsertedSemicolon: null,
  367. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  368. // trailing commas.
  369. onTrailingComma: null,
  370. // By default, reserved words are only enforced if ecmaVersion >= 5.
  371. // Set `allowReserved` to a boolean value to explicitly turn this on
  372. // an off. When this option has the value "never", reserved words
  373. // and keywords can also not be used as property names.
  374. allowReserved: null,
  375. // When enabled, a return at the top level is not considered an
  376. // error.
  377. allowReturnOutsideFunction: false,
  378. // When enabled, import/export statements are not constrained to
  379. // appearing at the top of the program.
  380. allowImportExportEverywhere: false,
  381. // When enabled, await identifiers are allowed to appear at the top-level scope,
  382. // but they are still not allowed in non-async functions.
  383. allowAwaitOutsideFunction: false,
  384. // When enabled, hashbang directive in the beginning of file
  385. // is allowed and treated as a line comment.
  386. allowHashBang: false,
  387. // When `locations` is on, `loc` properties holding objects with
  388. // `start` and `end` properties in `{line, column}` form (with
  389. // line being 1-based and column 0-based) will be attached to the
  390. // nodes.
  391. locations: false,
  392. // A function can be passed as `onToken` option, which will
  393. // cause Acorn to call that function with object in the same
  394. // format as tokens returned from `tokenizer().getToken()`. Note
  395. // that you are not allowed to call the parser from the
  396. // callback—that will corrupt its internal state.
  397. onToken: null,
  398. // A function can be passed as `onComment` option, which will
  399. // cause Acorn to call that function with `(block, text, start,
  400. // end)` parameters whenever a comment is skipped. `block` is a
  401. // boolean indicating whether this is a block (`/* */`) comment,
  402. // `text` is the content of the comment, and `start` and `end` are
  403. // character offsets that denote the start and end of the comment.
  404. // When the `locations` option is on, two more parameters are
  405. // passed, the full `{line, column}` locations of the start and
  406. // end of the comments. Note that you are not allowed to call the
  407. // parser from the callback—that will corrupt its internal state.
  408. onComment: null,
  409. // Nodes have their start and end characters offsets recorded in
  410. // `start` and `end` properties (directly on the node, rather than
  411. // the `loc` object, which holds line/column data. To also add a
  412. // [semi-standardized][range] `range` property holding a `[start,
  413. // end]` array with the same numbers, set the `ranges` option to
  414. // `true`.
  415. //
  416. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  417. ranges: false,
  418. // It is possible to parse multiple files into a single AST by
  419. // passing the tree produced by parsing the first file as
  420. // `program` option in subsequent parses. This will add the
  421. // toplevel forms of the parsed file to the `Program` (top) node
  422. // of an existing parse tree.
  423. program: null,
  424. // When `locations` is on, you can pass this to record the source
  425. // file in every node's `loc` object.
  426. sourceFile: null,
  427. // This value, if given, is stored in every node, whether
  428. // `locations` is on or off.
  429. directSourceFile: null,
  430. // When enabled, parenthesized expressions are represented by
  431. // (non-standard) ParenthesizedExpression nodes
  432. preserveParens: false,
  433. plugins: {}
  434. };
  435. // Interpret and default an options object
  436. function getOptions(opts) {
  437. var options = {};
  438. for (var opt in defaultOptions)
  439. { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  440. if (options.ecmaVersion >= 2015)
  441. { options.ecmaVersion -= 2009; }
  442. if (options.allowReserved == null)
  443. { options.allowReserved = options.ecmaVersion < 5; }
  444. if (isArray(options.onToken)) {
  445. var tokens = options.onToken;
  446. options.onToken = function (token) { return tokens.push(token); };
  447. }
  448. if (isArray(options.onComment))
  449. { options.onComment = pushComment(options, options.onComment); }
  450. return options
  451. }
  452. function pushComment(options, array) {
  453. return function(block, text, start, end, startLoc, endLoc) {
  454. var comment = {
  455. type: block ? "Block" : "Line",
  456. value: text,
  457. start: start,
  458. end: end
  459. };
  460. if (options.locations)
  461. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  462. if (options.ranges)
  463. { comment.range = [start, end]; }
  464. array.push(comment);
  465. }
  466. }
  467. // Registered plugins
  468. var plugins = {};
  469. function keywordRegexp(words) {
  470. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  471. }
  472. var Parser = function Parser(options, input, startPos) {
  473. this.options = options = getOptions(options);
  474. this.sourceFile = options.sourceFile;
  475. this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
  476. var reserved = "";
  477. if (!options.allowReserved) {
  478. for (var v = options.ecmaVersion;; v--)
  479. { if (reserved = reservedWords[v]) { break } }
  480. if (options.sourceType === "module") { reserved += " await"; }
  481. }
  482. this.reservedWords = keywordRegexp(reserved);
  483. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  484. this.reservedWordsStrict = keywordRegexp(reservedStrict);
  485. this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
  486. this.input = String(input);
  487. // Used to signal to callers of `readWord1` whether the word
  488. // contained any escape sequences. This is needed because words with
  489. // escape sequences must not be interpreted as keywords.
  490. this.containsEsc = false;
  491. // Load plugins
  492. this.loadPlugins(options.plugins);
  493. // Set up token state
  494. // The current position of the tokenizer in the input.
  495. if (startPos) {
  496. this.pos = startPos;
  497. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  498. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  499. } else {
  500. this.pos = this.lineStart = 0;
  501. this.curLine = 1;
  502. }
  503. // Properties of the current token:
  504. // Its type
  505. this.type = types.eof;
  506. // For tokens that include more information than their type, the value
  507. this.value = null;
  508. // Its start and end offset
  509. this.start = this.end = this.pos;
  510. // And, if locations are used, the {line, column} object
  511. // corresponding to those offsets
  512. this.startLoc = this.endLoc = this.curPosition();
  513. // Position information for the previous token
  514. this.lastTokEndLoc = this.lastTokStartLoc = null;
  515. this.lastTokStart = this.lastTokEnd = this.pos;
  516. // The context stack is used to superficially track syntactic
  517. // context to predict whether a regular expression is allowed in a
  518. // given position.
  519. this.context = this.initialContext();
  520. this.exprAllowed = true;
  521. // Figure out if it's a module code.
  522. this.inModule = options.sourceType === "module";
  523. this.strict = this.inModule || this.strictDirective(this.pos);
  524. // Used to signify the start of a potential arrow function
  525. this.potentialArrowAt = -1;
  526. // Flags to track whether we are in a function, a generator, an async function.
  527. this.inFunction = this.inGenerator = this.inAsync = false;
  528. // Positions to delayed-check that yield/await does not exist in default parameters.
  529. this.yieldPos = this.awaitPos = 0;
  530. // Labels in scope.
  531. this.labels = [];
  532. // If enabled, skip leading hashbang line.
  533. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  534. { this.skipLineComment(2); }
  535. // Scope tracking for duplicate variable names (see scope.js)
  536. this.scopeStack = [];
  537. this.enterFunctionScope();
  538. // For RegExp validation
  539. this.regexpState = null;
  540. };
  541. // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  542. Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
  543. Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
  544. Parser.prototype.extend = function extend (name, f) {
  545. this[name] = f(this[name]);
  546. };
  547. Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
  548. var this$1 = this;
  549. for (var name in pluginConfigs) {
  550. var plugin = plugins[name];
  551. if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
  552. plugin(this$1, pluginConfigs[name]);
  553. }
  554. };
  555. Parser.prototype.parse = function parse () {
  556. var node = this.options.program || this.startNode();
  557. this.nextToken();
  558. return this.parseTopLevel(node)
  559. };
  560. var pp = Parser.prototype;
  561. // ## Parser utilities
  562. var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
  563. pp.strictDirective = function(start) {
  564. var this$1 = this;
  565. for (;;) {
  566. skipWhiteSpace.lastIndex = start;
  567. start += skipWhiteSpace.exec(this$1.input)[0].length;
  568. var match = literal.exec(this$1.input.slice(start));
  569. if (!match) { return false }
  570. if ((match[1] || match[2]) === "use strict") { return true }
  571. start += match[0].length;
  572. }
  573. };
  574. // Predicate that tests whether the next token is of the given
  575. // type, and if yes, consumes it as a side effect.
  576. pp.eat = function(type) {
  577. if (this.type === type) {
  578. this.next();
  579. return true
  580. } else {
  581. return false
  582. }
  583. };
  584. // Tests whether parsed token is a contextual keyword.
  585. pp.isContextual = function(name) {
  586. return this.type === types.name && this.value === name && !this.containsEsc
  587. };
  588. // Consumes contextual keyword if possible.
  589. pp.eatContextual = function(name) {
  590. if (!this.isContextual(name)) { return false }
  591. this.next();
  592. return true
  593. };
  594. // Asserts that following token is given contextual keyword.
  595. pp.expectContextual = function(name) {
  596. if (!this.eatContextual(name)) { this.unexpected(); }
  597. };
  598. // Test whether a semicolon can be inserted at the current position.
  599. pp.canInsertSemicolon = function() {
  600. return this.type === types.eof ||
  601. this.type === types.braceR ||
  602. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  603. };
  604. pp.insertSemicolon = function() {
  605. if (this.canInsertSemicolon()) {
  606. if (this.options.onInsertedSemicolon)
  607. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  608. return true
  609. }
  610. };
  611. // Consume a semicolon, or, failing that, see if we are allowed to
  612. // pretend that there is a semicolon at this position.
  613. pp.semicolon = function() {
  614. if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
  615. };
  616. pp.afterTrailingComma = function(tokType, notNext) {
  617. if (this.type === tokType) {
  618. if (this.options.onTrailingComma)
  619. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  620. if (!notNext)
  621. { this.next(); }
  622. return true
  623. }
  624. };
  625. // Expect a token of a given type. If found, consume it, otherwise,
  626. // raise an unexpected token error.
  627. pp.expect = function(type) {
  628. this.eat(type) || this.unexpected();
  629. };
  630. // Raise an unexpected token error.
  631. pp.unexpected = function(pos) {
  632. this.raise(pos != null ? pos : this.start, "Unexpected token");
  633. };
  634. function DestructuringErrors() {
  635. this.shorthandAssign =
  636. this.trailingComma =
  637. this.parenthesizedAssign =
  638. this.parenthesizedBind =
  639. this.doubleProto =
  640. -1;
  641. }
  642. pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  643. if (!refDestructuringErrors) { return }
  644. if (refDestructuringErrors.trailingComma > -1)
  645. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  646. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  647. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  648. };
  649. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  650. if (!refDestructuringErrors) { return false }
  651. var shorthandAssign = refDestructuringErrors.shorthandAssign;
  652. var doubleProto = refDestructuringErrors.doubleProto;
  653. if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
  654. if (shorthandAssign >= 0)
  655. { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
  656. if (doubleProto >= 0)
  657. { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
  658. };
  659. pp.checkYieldAwaitInDefaultParams = function() {
  660. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  661. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  662. if (this.awaitPos)
  663. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  664. };
  665. pp.isSimpleAssignTarget = function(expr) {
  666. if (expr.type === "ParenthesizedExpression")
  667. { return this.isSimpleAssignTarget(expr.expression) }
  668. return expr.type === "Identifier" || expr.type === "MemberExpression"
  669. };
  670. var pp$1 = Parser.prototype;
  671. // ### Statement parsing
  672. // Parse a program. Initializes the parser, reads any number of
  673. // statements, and wraps them in a Program node. Optionally takes a
  674. // `program` argument. If present, the statements will be appended
  675. // to its body instead of creating a new node.
  676. pp$1.parseTopLevel = function(node) {
  677. var this$1 = this;
  678. var exports = {};
  679. if (!node.body) { node.body = []; }
  680. while (this.type !== types.eof) {
  681. var stmt = this$1.parseStatement(true, true, exports);
  682. node.body.push(stmt);
  683. }
  684. this.adaptDirectivePrologue(node.body);
  685. this.next();
  686. if (this.options.ecmaVersion >= 6) {
  687. node.sourceType = this.options.sourceType;
  688. }
  689. return this.finishNode(node, "Program")
  690. };
  691. var loopLabel = {kind: "loop"};
  692. var switchLabel = {kind: "switch"};
  693. pp$1.isLet = function() {
  694. if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
  695. skipWhiteSpace.lastIndex = this.pos;
  696. var skip = skipWhiteSpace.exec(this.input);
  697. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  698. if (nextCh === 91 || nextCh === 123) { return true } // '{' and '['
  699. if (isIdentifierStart(nextCh, true)) {
  700. var pos = next + 1;
  701. while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
  702. var ident = this.input.slice(next, pos);
  703. if (!keywordRelationalOperator.test(ident)) { return true }
  704. }
  705. return false
  706. };
  707. // check 'async [no LineTerminator here] function'
  708. // - 'async /*foo*/ function' is OK.
  709. // - 'async /*\n*/ function' is invalid.
  710. pp$1.isAsyncFunction = function() {
  711. if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
  712. { return false }
  713. skipWhiteSpace.lastIndex = this.pos;
  714. var skip = skipWhiteSpace.exec(this.input);
  715. var next = this.pos + skip[0].length;
  716. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  717. this.input.slice(next, next + 8) === "function" &&
  718. (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
  719. };
  720. // Parse a single statement.
  721. //
  722. // If expecting a statement and finding a slash operator, parse a
  723. // regular expression literal. This is to handle cases like
  724. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  725. // does not help.
  726. pp$1.parseStatement = function(declaration, topLevel, exports) {
  727. var starttype = this.type, node = this.startNode(), kind;
  728. if (this.isLet()) {
  729. starttype = types._var;
  730. kind = "let";
  731. }
  732. // Most types of statements are recognized by the keyword they
  733. // start with. Many are trivial to parse, some require a bit of
  734. // complexity.
  735. switch (starttype) {
  736. case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  737. case types._debugger: return this.parseDebuggerStatement(node)
  738. case types._do: return this.parseDoStatement(node)
  739. case types._for: return this.parseForStatement(node)
  740. case types._function:
  741. if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
  742. return this.parseFunctionStatement(node, false)
  743. case types._class:
  744. if (!declaration) { this.unexpected(); }
  745. return this.parseClass(node, true)
  746. case types._if: return this.parseIfStatement(node)
  747. case types._return: return this.parseReturnStatement(node)
  748. case types._switch: return this.parseSwitchStatement(node)
  749. case types._throw: return this.parseThrowStatement(node)
  750. case types._try: return this.parseTryStatement(node)
  751. case types._const: case types._var:
  752. kind = kind || this.value;
  753. if (!declaration && kind !== "var") { this.unexpected(); }
  754. return this.parseVarStatement(node, kind)
  755. case types._while: return this.parseWhileStatement(node)
  756. case types._with: return this.parseWithStatement(node)
  757. case types.braceL: return this.parseBlock()
  758. case types.semi: return this.parseEmptyStatement(node)
  759. case types._export:
  760. case types._import:
  761. if (!this.options.allowImportExportEverywhere) {
  762. if (!topLevel)
  763. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  764. if (!this.inModule)
  765. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  766. }
  767. return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
  768. // If the statement does not start with a statement keyword or a
  769. // brace, it's an ExpressionStatement or LabeledStatement. We
  770. // simply start parsing an expression, and afterwards, if the
  771. // next token is a colon and the expression was a simple
  772. // Identifier node, we switch to interpreting it as a label.
  773. default:
  774. if (this.isAsyncFunction()) {
  775. if (!declaration) { this.unexpected(); }
  776. this.next();
  777. return this.parseFunctionStatement(node, true)
  778. }
  779. var maybeName = this.value, expr = this.parseExpression();
  780. if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
  781. { return this.parseLabeledStatement(node, maybeName, expr) }
  782. else { return this.parseExpressionStatement(node, expr) }
  783. }
  784. };
  785. pp$1.parseBreakContinueStatement = function(node, keyword) {
  786. var this$1 = this;
  787. var isBreak = keyword === "break";
  788. this.next();
  789. if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
  790. else if (this.type !== types.name) { this.unexpected(); }
  791. else {
  792. node.label = this.parseIdent();
  793. this.semicolon();
  794. }
  795. // Verify that there is an actual destination to break or
  796. // continue to.
  797. var i = 0;
  798. for (; i < this.labels.length; ++i) {
  799. var lab = this$1.labels[i];
  800. if (node.label == null || lab.name === node.label.name) {
  801. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  802. if (node.label && isBreak) { break }
  803. }
  804. }
  805. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  806. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  807. };
  808. pp$1.parseDebuggerStatement = function(node) {
  809. this.next();
  810. this.semicolon();
  811. return this.finishNode(node, "DebuggerStatement")
  812. };
  813. pp$1.parseDoStatement = function(node) {
  814. this.next();
  815. this.labels.push(loopLabel);
  816. node.body = this.parseStatement(false);
  817. this.labels.pop();
  818. this.expect(types._while);
  819. node.test = this.parseParenExpression();
  820. if (this.options.ecmaVersion >= 6)
  821. { this.eat(types.semi); }
  822. else
  823. { this.semicolon(); }
  824. return this.finishNode(node, "DoWhileStatement")
  825. };
  826. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  827. // loop is non-trivial. Basically, we have to parse the init `var`
  828. // statement or expression, disallowing the `in` operator (see
  829. // the second parameter to `parseExpression`), and then check
  830. // whether the next token is `in` or `of`. When there is no init
  831. // part (semicolon immediately after the opening parenthesis), it
  832. // is a regular `for` loop.
  833. pp$1.parseForStatement = function(node) {
  834. this.next();
  835. var awaitAt = (this.options.ecmaVersion >= 9 && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction)) && this.eatContextual("await")) ? this.lastTokStart : -1;
  836. this.labels.push(loopLabel);
  837. this.enterLexicalScope();
  838. this.expect(types.parenL);
  839. if (this.type === types.semi) {
  840. if (awaitAt > -1) { this.unexpected(awaitAt); }
  841. return this.parseFor(node, null)
  842. }
  843. var isLet = this.isLet();
  844. if (this.type === types._var || this.type === types._const || isLet) {
  845. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  846. this.next();
  847. this.parseVar(init$1, true, kind);
  848. this.finishNode(init$1, "VariableDeclaration");
  849. if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
  850. !(kind !== "var" && init$1.declarations[0].init)) {
  851. if (this.options.ecmaVersion >= 9) {
  852. if (this.type === types._in) {
  853. if (awaitAt > -1) { this.unexpected(awaitAt); }
  854. } else { node.await = awaitAt > -1; }
  855. }
  856. return this.parseForIn(node, init$1)
  857. }
  858. if (awaitAt > -1) { this.unexpected(awaitAt); }
  859. return this.parseFor(node, init$1)
  860. }
  861. var refDestructuringErrors = new DestructuringErrors;
  862. var init = this.parseExpression(true, refDestructuringErrors);
  863. if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  864. if (this.options.ecmaVersion >= 9) {
  865. if (this.type === types._in) {
  866. if (awaitAt > -1) { this.unexpected(awaitAt); }
  867. } else { node.await = awaitAt > -1; }
  868. }
  869. this.toAssignable(init, false, refDestructuringErrors);
  870. this.checkLVal(init);
  871. return this.parseForIn(node, init)
  872. } else {
  873. this.checkExpressionErrors(refDestructuringErrors, true);
  874. }
  875. if (awaitAt > -1) { this.unexpected(awaitAt); }
  876. return this.parseFor(node, init)
  877. };
  878. pp$1.parseFunctionStatement = function(node, isAsync) {
  879. this.next();
  880. return this.parseFunction(node, true, false, isAsync)
  881. };
  882. pp$1.parseIfStatement = function(node) {
  883. this.next();
  884. node.test = this.parseParenExpression();
  885. // allow function declarations in branches, but only in non-strict mode
  886. node.consequent = this.parseStatement(!this.strict && this.type === types._function);
  887. node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.type === types._function) : null;
  888. return this.finishNode(node, "IfStatement")
  889. };
  890. pp$1.parseReturnStatement = function(node) {
  891. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  892. { this.raise(this.start, "'return' outside of function"); }
  893. this.next();
  894. // In `return` (and `break`/`continue`), the keywords with
  895. // optional arguments, we eagerly look for a semicolon or the
  896. // possibility to insert one.
  897. if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
  898. else { node.argument = this.parseExpression(); this.semicolon(); }
  899. return this.finishNode(node, "ReturnStatement")
  900. };
  901. pp$1.parseSwitchStatement = function(node) {
  902. var this$1 = this;
  903. this.next();
  904. node.discriminant = this.parseParenExpression();
  905. node.cases = [];
  906. this.expect(types.braceL);
  907. this.labels.push(switchLabel);
  908. this.enterLexicalScope();
  909. // Statements under must be grouped (by label) in SwitchCase
  910. // nodes. `cur` is used to keep the node that we are currently
  911. // adding statements to.
  912. var cur;
  913. for (var sawDefault = false; this.type !== types.braceR;) {
  914. if (this$1.type === types._case || this$1.type === types._default) {
  915. var isCase = this$1.type === types._case;
  916. if (cur) { this$1.finishNode(cur, "SwitchCase"); }
  917. node.cases.push(cur = this$1.startNode());
  918. cur.consequent = [];
  919. this$1.next();
  920. if (isCase) {
  921. cur.test = this$1.parseExpression();
  922. } else {
  923. if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
  924. sawDefault = true;
  925. cur.test = null;
  926. }
  927. this$1.expect(types.colon);
  928. } else {
  929. if (!cur) { this$1.unexpected(); }
  930. cur.consequent.push(this$1.parseStatement(true));
  931. }
  932. }
  933. this.exitLexicalScope();
  934. if (cur) { this.finishNode(cur, "SwitchCase"); }
  935. this.next(); // Closing brace
  936. this.labels.pop();
  937. return this.finishNode(node, "SwitchStatement")
  938. };
  939. pp$1.parseThrowStatement = function(node) {
  940. this.next();
  941. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  942. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  943. node.argument = this.parseExpression();
  944. this.semicolon();
  945. return this.finishNode(node, "ThrowStatement")
  946. };
  947. // Reused empty array added for node fields that are always empty.
  948. var empty = [];
  949. pp$1.parseTryStatement = function(node) {
  950. this.next();
  951. node.block = this.parseBlock();
  952. node.handler = null;
  953. if (this.type === types._catch) {
  954. var clause = this.startNode();
  955. this.next();
  956. if (this.eat(types.parenL)) {
  957. clause.param = this.parseBindingAtom();
  958. this.enterLexicalScope();
  959. this.checkLVal(clause.param, "let");
  960. this.expect(types.parenR);
  961. } else {
  962. if (this.options.ecmaVersion < 10) { this.unexpected(); }
  963. clause.param = null;
  964. this.enterLexicalScope();
  965. }
  966. clause.body = this.parseBlock(false);
  967. this.exitLexicalScope();
  968. node.handler = this.finishNode(clause, "CatchClause");
  969. }
  970. node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
  971. if (!node.handler && !node.finalizer)
  972. { this.raise(node.start, "Missing catch or finally clause"); }
  973. return this.finishNode(node, "TryStatement")
  974. };
  975. pp$1.parseVarStatement = function(node, kind) {
  976. this.next();
  977. this.parseVar(node, false, kind);
  978. this.semicolon();
  979. return this.finishNode(node, "VariableDeclaration")
  980. };
  981. pp$1.parseWhileStatement = function(node) {
  982. this.next();
  983. node.test = this.parseParenExpression();
  984. this.labels.push(loopLabel);
  985. node.body = this.parseStatement(false);
  986. this.labels.pop();
  987. return this.finishNode(node, "WhileStatement")
  988. };
  989. pp$1.parseWithStatement = function(node) {
  990. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  991. this.next();
  992. node.object = this.parseParenExpression();
  993. node.body = this.parseStatement(false);
  994. return this.finishNode(node, "WithStatement")
  995. };
  996. pp$1.parseEmptyStatement = function(node) {
  997. this.next();
  998. return this.finishNode(node, "EmptyStatement")
  999. };
  1000. pp$1.parseLabeledStatement = function(node, maybeName, expr) {
  1001. var this$1 = this;
  1002. for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
  1003. {
  1004. var label = list[i$1];
  1005. if (label.name === maybeName)
  1006. { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
  1007. } }
  1008. var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
  1009. for (var i = this.labels.length - 1; i >= 0; i--) {
  1010. var label$1 = this$1.labels[i];
  1011. if (label$1.statementStart === node.start) {
  1012. // Update information about previous labels on this node
  1013. label$1.statementStart = this$1.start;
  1014. label$1.kind = kind;
  1015. } else { break }
  1016. }
  1017. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  1018. node.body = this.parseStatement(true);
  1019. if (node.body.type === "ClassDeclaration" ||
  1020. node.body.type === "VariableDeclaration" && node.body.kind !== "var" ||
  1021. node.body.type === "FunctionDeclaration" && (this.strict || node.body.generator || node.body.async))
  1022. { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
  1023. this.labels.pop();
  1024. node.label = expr;
  1025. return this.finishNode(node, "LabeledStatement")
  1026. };
  1027. pp$1.parseExpressionStatement = function(node, expr) {
  1028. node.expression = expr;
  1029. this.semicolon();
  1030. return this.finishNode(node, "ExpressionStatement")
  1031. };
  1032. // Parse a semicolon-enclosed block of statements, handling `"use
  1033. // strict"` declarations when `allowStrict` is true (used for
  1034. // function bodies).
  1035. pp$1.parseBlock = function(createNewLexicalScope) {
  1036. var this$1 = this;
  1037. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  1038. var node = this.startNode();
  1039. node.body = [];
  1040. this.expect(types.braceL);
  1041. if (createNewLexicalScope) {
  1042. this.enterLexicalScope();
  1043. }
  1044. while (!this.eat(types.braceR)) {
  1045. var stmt = this$1.parseStatement(true);
  1046. node.body.push(stmt);
  1047. }
  1048. if (createNewLexicalScope) {
  1049. this.exitLexicalScope();
  1050. }
  1051. return this.finishNode(node, "BlockStatement")
  1052. };
  1053. // Parse a regular `for` loop. The disambiguation code in
  1054. // `parseStatement` will already have parsed the init statement or
  1055. // expression.
  1056. pp$1.parseFor = function(node, init) {
  1057. node.init = init;
  1058. this.expect(types.semi);
  1059. node.test = this.type === types.semi ? null : this.parseExpression();
  1060. this.expect(types.semi);
  1061. node.update = this.type === types.parenR ? null : this.parseExpression();
  1062. this.expect(types.parenR);
  1063. this.exitLexicalScope();
  1064. node.body = this.parseStatement(false);
  1065. this.labels.pop();
  1066. return this.finishNode(node, "ForStatement")
  1067. };
  1068. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  1069. // same from parser's perspective.
  1070. pp$1.parseForIn = function(node, init) {
  1071. var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
  1072. this.next();
  1073. if (type === "ForInStatement") {
  1074. if (init.type === "AssignmentPattern" ||
  1075. (init.type === "VariableDeclaration" && init.declarations[0].init != null &&
  1076. (this.strict || init.declarations[0].id.type !== "Identifier")))
  1077. { this.raise(init.start, "Invalid assignment in for-in loop head"); }
  1078. }
  1079. node.left = init;
  1080. node.right = type === "ForInStatement" ? this.parseExpression() : this.parseMaybeAssign();
  1081. this.expect(types.parenR);
  1082. this.exitLexicalScope();
  1083. node.body = this.parseStatement(false);
  1084. this.labels.pop();
  1085. return this.finishNode(node, type)
  1086. };
  1087. // Parse a list of variable declarations.
  1088. pp$1.parseVar = function(node, isFor, kind) {
  1089. var this$1 = this;
  1090. node.declarations = [];
  1091. node.kind = kind;
  1092. for (;;) {
  1093. var decl = this$1.startNode();
  1094. this$1.parseVarId(decl, kind);
  1095. if (this$1.eat(types.eq)) {
  1096. decl.init = this$1.parseMaybeAssign(isFor);
  1097. } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
  1098. this$1.unexpected();
  1099. } else if (decl.id.type !== "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
  1100. this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
  1101. } else {
  1102. decl.init = null;
  1103. }
  1104. node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
  1105. if (!this$1.eat(types.comma)) { break }
  1106. }
  1107. return node
  1108. };
  1109. pp$1.parseVarId = function(decl, kind) {
  1110. decl.id = this.parseBindingAtom(kind);
  1111. this.checkLVal(decl.id, kind, false);
  1112. };
  1113. // Parse a function declaration or literal (depending on the
  1114. // `isStatement` parameter).
  1115. pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
  1116. this.initFunction(node);
  1117. if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync)
  1118. { node.generator = this.eat(types.star); }
  1119. if (this.options.ecmaVersion >= 8)
  1120. { node.async = !!isAsync; }
  1121. if (isStatement) {
  1122. node.id = isStatement === "nullableID" && this.type !== types.name ? null : this.parseIdent();
  1123. if (node.id) {
  1124. this.checkLVal(node.id, this.inModule && !this.inFunction ? "let" : "var");
  1125. }
  1126. }
  1127. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  1128. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  1129. this.inGenerator = node.generator;
  1130. this.inAsync = node.async;
  1131. this.yieldPos = 0;
  1132. this.awaitPos = 0;
  1133. this.inFunction = true;
  1134. this.enterFunctionScope();
  1135. if (!isStatement)
  1136. { node.id = this.type === types.name ? this.parseIdent() : null; }
  1137. this.parseFunctionParams(node);
  1138. this.parseFunctionBody(node, allowExpressionBody);
  1139. this.inGenerator = oldInGen;
  1140. this.inAsync = oldInAsync;
  1141. this.yieldPos = oldYieldPos;
  1142. this.awaitPos = oldAwaitPos;
  1143. this.inFunction = oldInFunc;
  1144. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
  1145. };
  1146. pp$1.parseFunctionParams = function(node) {
  1147. this.expect(types.parenL);
  1148. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  1149. this.checkYieldAwaitInDefaultParams();
  1150. };
  1151. // Parse a class declaration or literal (depending on the
  1152. // `isStatement` parameter).
  1153. pp$1.parseClass = function(node, isStatement) {
  1154. var this$1 = this;
  1155. this.next();
  1156. this.parseClassId(node, isStatement);
  1157. this.parseClassSuper(node);
  1158. var classBody = this.startNode();
  1159. var hadConstructor = false;
  1160. classBody.body = [];
  1161. this.expect(types.braceL);
  1162. while (!this.eat(types.braceR)) {
  1163. var member = this$1.parseClassMember(classBody);
  1164. if (member && member.type === "MethodDefinition" && member.kind === "constructor") {
  1165. if (hadConstructor) { this$1.raise(member.start, "Duplicate constructor in the same class"); }
  1166. hadConstructor = true;
  1167. }
  1168. }
  1169. node.body = this.finishNode(classBody, "ClassBody");
  1170. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1171. };
  1172. pp$1.parseClassMember = function(classBody) {
  1173. var this$1 = this;
  1174. if (this.eat(types.semi)) { return null }
  1175. var method = this.startNode();
  1176. var tryContextual = function (k, noLineBreak) {
  1177. if ( noLineBreak === void 0 ) noLineBreak = false;
  1178. var start = this$1.start, startLoc = this$1.startLoc;
  1179. if (!this$1.eatContextual(k)) { return false }
  1180. if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
  1181. if (method.key) { this$1.unexpected(); }
  1182. method.computed = false;
  1183. method.key = this$1.startNodeAt(start, startLoc);
  1184. method.key.name = k;
  1185. this$1.finishNode(method.key, "Identifier");
  1186. return false
  1187. };
  1188. method.kind = "method";
  1189. method.static = tryContextual("static");
  1190. var isGenerator = this.eat(types.star);
  1191. var isAsync = false;
  1192. if (!isGenerator) {
  1193. if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
  1194. isAsync = true;
  1195. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  1196. } else if (tryContextual("get")) {
  1197. method.kind = "get";
  1198. } else if (tryContextual("set")) {
  1199. method.kind = "set";
  1200. }
  1201. }
  1202. if (!method.key) { this.parsePropertyName(method); }
  1203. var key = method.key;
  1204. if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
  1205. key.type === "Literal" && key.value === "constructor")) {
  1206. if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
  1207. if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
  1208. if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
  1209. method.kind = "constructor";
  1210. } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
  1211. this.raise(key.start, "Classes may not have a static property named prototype");
  1212. }
  1213. this.parseClassMethod(classBody, method, isGenerator, isAsync);
  1214. if (method.kind === "get" && method.value.params.length !== 0)
  1215. { this.raiseRecoverable(method.value.start, "getter should have no params"); }
  1216. if (method.kind === "set" && method.value.params.length !== 1)
  1217. { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
  1218. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  1219. { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
  1220. return method
  1221. };
  1222. pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
  1223. method.value = this.parseMethod(isGenerator, isAsync);
  1224. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  1225. };
  1226. pp$1.parseClassId = function(node, isStatement) {
  1227. node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
  1228. };
  1229. pp$1.parseClassSuper = function(node) {
  1230. node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
  1231. };
  1232. // Parses module export declaration.
  1233. pp$1.parseExport = function(node, exports) {
  1234. var this$1 = this;
  1235. this.next();
  1236. // export * from '...'
  1237. if (this.eat(types.star)) {
  1238. this.expectContextual("from");
  1239. if (this.type !== types.string) { this.unexpected(); }
  1240. node.source = this.parseExprAtom();
  1241. this.semicolon();
  1242. return this.finishNode(node, "ExportAllDeclaration")
  1243. }
  1244. if (this.eat(types._default)) { // export default ...
  1245. this.checkExport(exports, "default", this.lastTokStart);
  1246. var isAsync;
  1247. if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
  1248. var fNode = this.startNode();
  1249. this.next();
  1250. if (isAsync) { this.next(); }
  1251. node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
  1252. } else if (this.type === types._class) {
  1253. var cNode = this.startNode();
  1254. node.declaration = this.parseClass(cNode, "nullableID");
  1255. } else {
  1256. node.declaration = this.parseMaybeAssign();
  1257. this.semicolon();
  1258. }
  1259. return this.finishNode(node, "ExportDefaultDeclaration")
  1260. }
  1261. // export var|const|let|function|class ...
  1262. if (this.shouldParseExportStatement()) {
  1263. node.declaration = this.parseStatement(true);
  1264. if (node.declaration.type === "VariableDeclaration")
  1265. { this.checkVariableExport(exports, node.declaration.declarations); }
  1266. else
  1267. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  1268. node.specifiers = [];
  1269. node.source = null;
  1270. } else { // export { x, y as z } [from '...']
  1271. node.declaration = null;
  1272. node.specifiers = this.parseExportSpecifiers(exports);
  1273. if (this.eatContextual("from")) {
  1274. if (this.type !== types.string) { this.unexpected(); }
  1275. node.source = this.parseExprAtom();
  1276. } else {
  1277. // check for keywords used as local names
  1278. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1279. var spec = list[i];
  1280. this$1.checkUnreserved(spec.local);
  1281. }
  1282. node.source = null;
  1283. }
  1284. this.semicolon();
  1285. }
  1286. return this.finishNode(node, "ExportNamedDeclaration")
  1287. };
  1288. pp$1.checkExport = function(exports, name, pos) {
  1289. if (!exports) { return }
  1290. if (has(exports, name))
  1291. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1292. exports[name] = true;
  1293. };
  1294. pp$1.checkPatternExport = function(exports, pat) {
  1295. var this$1 = this;
  1296. var type = pat.type;
  1297. if (type === "Identifier")
  1298. { this.checkExport(exports, pat.name, pat.start); }
  1299. else if (type === "ObjectPattern")
  1300. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1301. {
  1302. var prop = list[i];
  1303. this$1.checkPatternExport(exports, prop);
  1304. } }
  1305. else if (type === "ArrayPattern")
  1306. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1307. var elt = list$1[i$1];
  1308. if (elt) { this$1.checkPatternExport(exports, elt); }
  1309. } }
  1310. else if (type === "Property")
  1311. { this.checkPatternExport(exports, pat.value); }
  1312. else if (type === "AssignmentPattern")
  1313. { this.checkPatternExport(exports, pat.left); }
  1314. else if (type === "RestElement")
  1315. { this.checkPatternExport(exports, pat.argument); }
  1316. else if (type === "ParenthesizedExpression")
  1317. { this.checkPatternExport(exports, pat.expression); }
  1318. };
  1319. pp$1.checkVariableExport = function(exports, decls) {
  1320. var this$1 = this;
  1321. if (!exports) { return }
  1322. for (var i = 0, list = decls; i < list.length; i += 1)
  1323. {
  1324. var decl = list[i];
  1325. this$1.checkPatternExport(exports, decl.id);
  1326. }
  1327. };
  1328. pp$1.shouldParseExportStatement = function() {
  1329. return this.type.keyword === "var" ||
  1330. this.type.keyword === "const" ||
  1331. this.type.keyword === "class" ||
  1332. this.type.keyword === "function" ||
  1333. this.isLet() ||
  1334. this.isAsyncFunction()
  1335. };
  1336. // Parses a comma-separated list of module exports.
  1337. pp$1.parseExportSpecifiers = function(exports) {
  1338. var this$1 = this;
  1339. var nodes = [], first = true;
  1340. // export { x, y as z } [from '...']
  1341. this.expect(types.braceL);
  1342. while (!this.eat(types.braceR)) {
  1343. if (!first) {
  1344. this$1.expect(types.comma);
  1345. if (this$1.afterTrailingComma(types.braceR)) { break }
  1346. } else { first = false; }
  1347. var node = this$1.startNode();
  1348. node.local = this$1.parseIdent(true);
  1349. node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
  1350. this$1.checkExport(exports, node.exported.name, node.exported.start);
  1351. nodes.push(this$1.finishNode(node, "ExportSpecifier"));
  1352. }
  1353. return nodes
  1354. };
  1355. // Parses import declaration.
  1356. pp$1.parseImport = function(node) {
  1357. this.next();
  1358. // import '...'
  1359. if (this.type === types.string) {
  1360. node.specifiers = empty;
  1361. node.source = this.parseExprAtom();
  1362. } else {
  1363. node.specifiers = this.parseImportSpecifiers();
  1364. this.expectContextual("from");
  1365. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1366. }
  1367. this.semicolon();
  1368. return this.finishNode(node, "ImportDeclaration")
  1369. };
  1370. // Parses a comma-separated list of module imports.
  1371. pp$1.parseImportSpecifiers = function() {
  1372. var this$1 = this;
  1373. var nodes = [], first = true;
  1374. if (this.type === types.name) {
  1375. // import defaultObj, { x, y as z } from '...'
  1376. var node = this.startNode();
  1377. node.local = this.parseIdent();
  1378. this.checkLVal(node.local, "let");
  1379. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1380. if (!this.eat(types.comma)) { return nodes }
  1381. }
  1382. if (this.type === types.star) {
  1383. var node$1 = this.startNode();
  1384. this.next();
  1385. this.expectContextual("as");
  1386. node$1.local = this.parseIdent();
  1387. this.checkLVal(node$1.local, "let");
  1388. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1389. return nodes
  1390. }
  1391. this.expect(types.braceL);
  1392. while (!this.eat(types.braceR)) {
  1393. if (!first) {
  1394. this$1.expect(types.comma);
  1395. if (this$1.afterTrailingComma(types.braceR)) { break }
  1396. } else { first = false; }
  1397. var node$2 = this$1.startNode();
  1398. node$2.imported = this$1.parseIdent(true);
  1399. if (this$1.eatContextual("as")) {
  1400. node$2.local = this$1.parseIdent();
  1401. } else {
  1402. this$1.checkUnreserved(node$2.imported);
  1403. node$2.local = node$2.imported;
  1404. }
  1405. this$1.checkLVal(node$2.local, "let");
  1406. nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
  1407. }
  1408. return nodes
  1409. };
  1410. // Set `ExpressionStatement#directive` property for directive prologues.
  1411. pp$1.adaptDirectivePrologue = function(statements) {
  1412. for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
  1413. statements[i].directive = statements[i].expression.raw.slice(1, -1);
  1414. }
  1415. };
  1416. pp$1.isDirectiveCandidate = function(statement) {
  1417. return (
  1418. statement.type === "ExpressionStatement" &&
  1419. statement.expression.type === "Literal" &&
  1420. typeof statement.expression.value === "string" &&
  1421. // Reject parenthesized strings.
  1422. (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
  1423. )
  1424. };
  1425. var pp$2 = Parser.prototype;
  1426. // Convert existing expression atom to assignable pattern
  1427. // if possible.
  1428. pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
  1429. var this$1 = this;
  1430. if (this.options.ecmaVersion >= 6 && node) {
  1431. switch (node.type) {
  1432. case "Identifier":
  1433. if (this.inAsync && node.name === "await")
  1434. { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
  1435. break
  1436. case "ObjectPattern":
  1437. case "ArrayPattern":
  1438. case "RestElement":
  1439. break
  1440. case "ObjectExpression":
  1441. node.type = "ObjectPattern";
  1442. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1443. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1444. var prop = list[i];
  1445. this$1.toAssignable(prop, isBinding);
  1446. // Early error:
  1447. // AssignmentRestProperty[Yield, Await] :
  1448. // `...` DestructuringAssignmentTarget[Yield, Await]
  1449. //
  1450. // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
  1451. if (
  1452. prop.type === "RestElement" &&
  1453. (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
  1454. ) {
  1455. this$1.raise(prop.argument.start, "Unexpected token");
  1456. }
  1457. }
  1458. break
  1459. case "Property":
  1460. // AssignmentProperty has type === "Property"
  1461. if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
  1462. this.toAssignable(node.value, isBinding);
  1463. break
  1464. case "ArrayExpression":
  1465. node.type = "ArrayPattern";
  1466. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1467. this.toAssignableList(node.elements, isBinding);
  1468. break
  1469. case "SpreadElement":
  1470. node.type = "RestElement";
  1471. this.toAssignable(node.argument, isBinding);
  1472. if (node.argument.type === "AssignmentPattern")
  1473. { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
  1474. break
  1475. case "AssignmentExpression":
  1476. if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
  1477. node.type = "AssignmentPattern";
  1478. delete node.operator;
  1479. this.toAssignable(node.left, isBinding);
  1480. // falls through to AssignmentPattern
  1481. case "AssignmentPattern":
  1482. break
  1483. case "ParenthesizedExpression":
  1484. this.toAssignable(node.expression, isBinding);
  1485. break
  1486. case "MemberExpression":
  1487. if (!isBinding) { break }
  1488. default:
  1489. this.raise(node.start, "Assigning to rvalue");
  1490. }
  1491. } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1492. return node
  1493. };
  1494. // Convert list of expression atoms to binding list.
  1495. pp$2.toAssignableList = function(exprList, isBinding) {
  1496. var this$1 = this;
  1497. var end = exprList.length;
  1498. for (var i = 0; i < end; i++) {
  1499. var elt = exprList[i];
  1500. if (elt) { this$1.toAssignable(elt, isBinding); }
  1501. }
  1502. if (end) {
  1503. var last = exprList[end - 1];
  1504. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1505. { this.unexpected(last.argument.start); }
  1506. }
  1507. return exprList
  1508. };
  1509. // Parses spread element.
  1510. pp$2.parseSpread = function(refDestructuringErrors) {
  1511. var node = this.startNode();
  1512. this.next();
  1513. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1514. return this.finishNode(node, "SpreadElement")
  1515. };
  1516. pp$2.parseRestBinding = function() {
  1517. var node = this.startNode();
  1518. this.next();
  1519. // RestElement inside of a function parameter must be an identifier
  1520. if (this.options.ecmaVersion === 6 && this.type !== types.name)
  1521. { this.unexpected(); }
  1522. node.argument = this.parseBindingAtom();
  1523. return this.finishNode(node, "RestElement")
  1524. };
  1525. // Parses lvalue (assignable) atom.
  1526. pp$2.parseBindingAtom = function() {
  1527. if (this.options.ecmaVersion >= 6) {
  1528. switch (this.type) {
  1529. case types.bracketL:
  1530. var node = this.startNode();
  1531. this.next();
  1532. node.elements = this.parseBindingList(types.bracketR, true, true);
  1533. return this.finishNode(node, "ArrayPattern")
  1534. case types.braceL:
  1535. return this.parseObj(true)
  1536. }
  1537. }
  1538. return this.parseIdent()
  1539. };
  1540. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1541. var this$1 = this;
  1542. var elts = [], first = true;
  1543. while (!this.eat(close)) {
  1544. if (first) { first = false; }
  1545. else { this$1.expect(types.comma); }
  1546. if (allowEmpty && this$1.type === types.comma) {
  1547. elts.push(null);
  1548. } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
  1549. break
  1550. } else if (this$1.type === types.ellipsis) {
  1551. var rest = this$1.parseRestBinding();
  1552. this$1.parseBindingListItem(rest);
  1553. elts.push(rest);
  1554. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1555. this$1.expect(close);
  1556. break
  1557. } else {
  1558. var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
  1559. this$1.parseBindingListItem(elem);
  1560. elts.push(elem);
  1561. }
  1562. }
  1563. return elts
  1564. };
  1565. pp$2.parseBindingListItem = function(param) {
  1566. return param
  1567. };
  1568. // Parses assignment pattern around given atom if possible.
  1569. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  1570. left = left || this.parseBindingAtom();
  1571. if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
  1572. var node = this.startNodeAt(startPos, startLoc);
  1573. node.left = left;
  1574. node.right = this.parseMaybeAssign();
  1575. return this.finishNode(node, "AssignmentPattern")
  1576. };
  1577. // Verify that a node is an lval — something that can be assigned
  1578. // to.
  1579. // bindingType can be either:
  1580. // 'var' indicating that the lval creates a 'var' binding
  1581. // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
  1582. // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
  1583. pp$2.checkLVal = function(expr, bindingType, checkClashes) {
  1584. var this$1 = this;
  1585. switch (expr.type) {
  1586. case "Identifier":
  1587. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1588. { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1589. if (checkClashes) {
  1590. if (has(checkClashes, expr.name))
  1591. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1592. checkClashes[expr.name] = true;
  1593. }
  1594. if (bindingType && bindingType !== "none") {
  1595. if (
  1596. bindingType === "var" && !this.canDeclareVarName(expr.name) ||
  1597. bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
  1598. ) {
  1599. this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
  1600. }
  1601. if (bindingType === "var") {
  1602. this.declareVarName(expr.name);
  1603. } else {
  1604. this.declareLexicalName(expr.name);
  1605. }
  1606. }
  1607. break
  1608. case "MemberExpression":
  1609. if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
  1610. break
  1611. case "ObjectPattern":
  1612. for (var i = 0, list = expr.properties; i < list.length; i += 1)
  1613. {
  1614. var prop = list[i];
  1615. this$1.checkLVal(prop, bindingType, checkClashes);
  1616. }
  1617. break
  1618. case "Property":
  1619. // AssignmentProperty has type === "Property"
  1620. this.checkLVal(expr.value, bindingType, checkClashes);
  1621. break
  1622. case "ArrayPattern":
  1623. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1624. var elem = list$1[i$1];
  1625. if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
  1626. }
  1627. break
  1628. case "AssignmentPattern":
  1629. this.checkLVal(expr.left, bindingType, checkClashes);
  1630. break
  1631. case "RestElement":
  1632. this.checkLVal(expr.argument, bindingType, checkClashes);
  1633. break
  1634. case "ParenthesizedExpression":
  1635. this.checkLVal(expr.expression, bindingType, checkClashes);
  1636. break
  1637. default:
  1638. this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
  1639. }
  1640. };
  1641. // A recursive descent parser operates by defining functions for all
  1642. // syntactic elements, and recursively calling those, each function
  1643. // advancing the input stream and returning an AST node. Precedence
  1644. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  1645. // instead of `(!x)[1]` is handled by the fact that the parser
  1646. // function that parses unary prefix operators is called first, and
  1647. // in turn calls the function that parses `[]` subscripts — that
  1648. // way, it'll receive the node for `x[1]` already parsed, and wraps
  1649. // *that* in the unary operator node.
  1650. //
  1651. // Acorn uses an [operator precedence parser][opp] to handle binary
  1652. // operator precedence, because it is much more compact than using
  1653. // the technique outlined above, which uses different, nesting
  1654. // functions to specify precedence, for all of the ten binary
  1655. // precedence levels that JavaScript defines.
  1656. //
  1657. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  1658. var pp$3 = Parser.prototype;
  1659. // Check if property name clashes with already added.
  1660. // Object/class getters and setters are not allowed to clash —
  1661. // either with each other or with an init property — and in
  1662. // strict mode, init properties are also not allowed to be repeated.
  1663. pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
  1664. if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
  1665. { return }
  1666. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  1667. { return }
  1668. var key = prop.key;
  1669. var name;
  1670. switch (key.type) {
  1671. case "Identifier": name = key.name; break
  1672. case "Literal": name = String(key.value); break
  1673. default: return
  1674. }
  1675. var kind = prop.kind;
  1676. if (this.options.ecmaVersion >= 6) {
  1677. if (name === "__proto__" && kind === "init") {
  1678. if (propHash.proto) {
  1679. if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) { refDestructuringErrors.doubleProto = key.start; }
  1680. // Backwards-compat kludge. Can be removed in version 6.0
  1681. else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
  1682. }
  1683. propHash.proto = true;
  1684. }
  1685. return
  1686. }
  1687. name = "$" + name;
  1688. var other = propHash[name];
  1689. if (other) {
  1690. var redefinition;
  1691. if (kind === "init") {
  1692. redefinition = this.strict && other.init || other.get || other.set;
  1693. } else {
  1694. redefinition = other.init || other[kind];
  1695. }
  1696. if (redefinition)
  1697. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  1698. } else {
  1699. other = propHash[name] = {
  1700. init: false,
  1701. get: false,
  1702. set: false
  1703. };
  1704. }
  1705. other[kind] = true;
  1706. };
  1707. // ### Expression parsing
  1708. // These nest, from the most general expression type at the top to
  1709. // 'atomic', nondivisible expression types at the bottom. Most of
  1710. // the functions will simply let the function(s) below them parse,
  1711. // and, *if* the syntactic construct they handle is present, wrap
  1712. // the AST node that the inner parser gave them in another node.
  1713. // Parse a full expression. The optional arguments are used to
  1714. // forbid the `in` operator (in for loops initalization expressions)
  1715. // and provide reference for storing '=' operator inside shorthand
  1716. // property assignment in contexts where both object expression
  1717. // and object pattern might appear (so it's possible to raise
  1718. // delayed syntax error at correct position).
  1719. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  1720. var this$1 = this;
  1721. var startPos = this.start, startLoc = this.startLoc;
  1722. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  1723. if (this.type === types.comma) {
  1724. var node = this.startNodeAt(startPos, startLoc);
  1725. node.expressions = [expr];
  1726. while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
  1727. return this.finishNode(node, "SequenceExpression")
  1728. }
  1729. return expr
  1730. };
  1731. // Parse an assignment expression. This includes applications of
  1732. // operators like `+=`.
  1733. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  1734. if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
  1735. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
  1736. if (refDestructuringErrors) {
  1737. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  1738. oldTrailingComma = refDestructuringErrors.trailingComma;
  1739. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  1740. } else {
  1741. refDestructuringErrors = new DestructuringErrors;
  1742. ownDestructuringErrors = true;
  1743. }
  1744. var startPos = this.start, startLoc = this.startLoc;
  1745. if (this.type === types.parenL || this.type === types.name)
  1746. { this.potentialArrowAt = this.start; }
  1747. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  1748. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  1749. if (this.type.isAssign) {
  1750. var node = this.startNodeAt(startPos, startLoc);
  1751. node.operator = this.value;
  1752. node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
  1753. if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
  1754. refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
  1755. this.checkLVal(left);
  1756. this.next();
  1757. node.right = this.parseMaybeAssign(noIn);
  1758. return this.finishNode(node, "AssignmentExpression")
  1759. } else {
  1760. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  1761. }
  1762. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  1763. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  1764. return left
  1765. };
  1766. // Parse a ternary conditional (`?:`) operator.
  1767. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  1768. var startPos = this.start, startLoc = this.startLoc;
  1769. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  1770. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1771. if (this.eat(types.question)) {
  1772. var node = this.startNodeAt(startPos, startLoc);
  1773. node.test = expr;
  1774. node.consequent = this.parseMaybeAssign();
  1775. this.expect(types.colon);
  1776. node.alternate = this.parseMaybeAssign(noIn);
  1777. return this.finishNode(node, "ConditionalExpression")
  1778. }
  1779. return expr
  1780. };
  1781. // Start the precedence parser.
  1782. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  1783. var startPos = this.start, startLoc = this.startLoc;
  1784. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  1785. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1786. return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  1787. };
  1788. // Parse binary operators with the operator precedence parsing
  1789. // algorithm. `left` is the left-hand side of the operator.
  1790. // `minPrec` provides context that allows the function to stop and
  1791. // defer further parser to one of its callers when it encounters an
  1792. // operator that has a lower precedence than the set it is parsing.
  1793. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  1794. var prec = this.type.binop;
  1795. if (prec != null && (!noIn || this.type !== types._in)) {
  1796. if (prec > minPrec) {
  1797. var logical = this.type === types.logicalOR || this.type === types.logicalAND;
  1798. var op = this.value;
  1799. this.next();
  1800. var startPos = this.start, startLoc = this.startLoc;
  1801. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  1802. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  1803. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  1804. }
  1805. }
  1806. return left
  1807. };
  1808. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  1809. var node = this.startNodeAt(startPos, startLoc);
  1810. node.left = left;
  1811. node.operator = op;
  1812. node.right = right;
  1813. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  1814. };
  1815. // Parse unary operators, both prefix and postfix.
  1816. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  1817. var this$1 = this;
  1818. var startPos = this.start, startLoc = this.startLoc, expr;
  1819. if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) {
  1820. expr = this.parseAwait();
  1821. sawUnary = true;
  1822. } else if (this.type.prefix) {
  1823. var node = this.startNode(), update = this.type === types.incDec;
  1824. node.operator = this.value;
  1825. node.prefix = true;
  1826. this.next();
  1827. node.argument = this.parseMaybeUnary(null, true);
  1828. this.checkExpressionErrors(refDestructuringErrors, true);
  1829. if (update) { this.checkLVal(node.argument); }
  1830. else if (this.strict && node.operator === "delete" &&
  1831. node.argument.type === "Identifier")
  1832. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  1833. else { sawUnary = true; }
  1834. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  1835. } else {
  1836. expr = this.parseExprSubscripts(refDestructuringErrors);
  1837. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1838. while (this.type.postfix && !this.canInsertSemicolon()) {
  1839. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1840. node$1.operator = this$1.value;
  1841. node$1.prefix = false;
  1842. node$1.argument = expr;
  1843. this$1.checkLVal(expr);
  1844. this$1.next();
  1845. expr = this$1.finishNode(node$1, "UpdateExpression");
  1846. }
  1847. }
  1848. if (!sawUnary && this.eat(types.starstar))
  1849. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
  1850. else
  1851. { return expr }
  1852. };
  1853. // Parse call, dot, and `[]`-subscript expressions.
  1854. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  1855. var startPos = this.start, startLoc = this.startLoc;
  1856. var expr = this.parseExprAtom(refDestructuringErrors);
  1857. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  1858. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
  1859. var result = this.parseSubscripts(expr, startPos, startLoc);
  1860. if (refDestructuringErrors && result.type === "MemberExpression") {
  1861. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  1862. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  1863. }
  1864. return result
  1865. };
  1866. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  1867. var this$1 = this;
  1868. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  1869. this.lastTokEnd === base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async";
  1870. for (var computed = (void 0);;) {
  1871. if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
  1872. var node = this$1.startNodeAt(startPos, startLoc);
  1873. node.object = base;
  1874. node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
  1875. node.computed = !!computed;
  1876. if (computed) { this$1.expect(types.bracketR); }
  1877. base = this$1.finishNode(node, "MemberExpression");
  1878. } else if (!noCalls && this$1.eat(types.parenL)) {
  1879. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
  1880. this$1.yieldPos = 0;
  1881. this$1.awaitPos = 0;
  1882. var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
  1883. if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
  1884. this$1.checkPatternErrors(refDestructuringErrors, false);
  1885. this$1.checkYieldAwaitInDefaultParams();
  1886. this$1.yieldPos = oldYieldPos;
  1887. this$1.awaitPos = oldAwaitPos;
  1888. return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
  1889. }
  1890. this$1.checkExpressionErrors(refDestructuringErrors, true);
  1891. this$1.yieldPos = oldYieldPos || this$1.yieldPos;
  1892. this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
  1893. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1894. node$1.callee = base;
  1895. node$1.arguments = exprList;
  1896. base = this$1.finishNode(node$1, "CallExpression");
  1897. } else if (this$1.type === types.backQuote) {
  1898. var node$2 = this$1.startNodeAt(startPos, startLoc);
  1899. node$2.tag = base;
  1900. node$2.quasi = this$1.parseTemplate({isTagged: true});
  1901. base = this$1.finishNode(node$2, "TaggedTemplateExpression");
  1902. } else {
  1903. return base
  1904. }
  1905. }
  1906. };
  1907. // Parse an atomic expression — either a single token that is an
  1908. // expression, an expression started by a keyword like `function` or
  1909. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  1910. // or `{}`.
  1911. pp$3.parseExprAtom = function(refDestructuringErrors) {
  1912. var node, canBeArrow = this.potentialArrowAt === this.start;
  1913. switch (this.type) {
  1914. case types._super:
  1915. if (!this.inFunction)
  1916. { this.raise(this.start, "'super' outside of function or class"); }
  1917. node = this.startNode();
  1918. this.next();
  1919. // The `super` keyword can appear at below:
  1920. // SuperProperty:
  1921. // super [ Expression ]
  1922. // super . IdentifierName
  1923. // SuperCall:
  1924. // super Arguments
  1925. if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
  1926. { this.unexpected(); }
  1927. return this.finishNode(node, "Super")
  1928. case types._this:
  1929. node = this.startNode();
  1930. this.next();
  1931. return this.finishNode(node, "ThisExpression")
  1932. case types.name:
  1933. var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
  1934. var id = this.parseIdent(this.type !== types.name);
  1935. if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
  1936. { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
  1937. if (canBeArrow && !this.canInsertSemicolon()) {
  1938. if (this.eat(types.arrow))
  1939. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
  1940. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
  1941. id = this.parseIdent();
  1942. if (this.canInsertSemicolon() || !this.eat(types.arrow))
  1943. { this.unexpected(); }
  1944. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
  1945. }
  1946. }
  1947. return id
  1948. case types.regexp:
  1949. var value = this.value;
  1950. node = this.parseLiteral(value.value);
  1951. node.regex = {pattern: value.pattern, flags: value.flags};
  1952. return node
  1953. case types.num: case types.string:
  1954. return this.parseLiteral(this.value)
  1955. case types._null: case types._true: case types._false:
  1956. node = this.startNode();
  1957. node.value = this.type === types._null ? null : this.type === types._true;
  1958. node.raw = this.type.keyword;
  1959. this.next();
  1960. return this.finishNode(node, "Literal")
  1961. case types.parenL:
  1962. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
  1963. if (refDestructuringErrors) {
  1964. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  1965. { refDestructuringErrors.parenthesizedAssign = start; }
  1966. if (refDestructuringErrors.parenthesizedBind < 0)
  1967. { refDestructuringErrors.parenthesizedBind = start; }
  1968. }
  1969. return expr
  1970. case types.bracketL:
  1971. node = this.startNode();
  1972. this.next();
  1973. node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
  1974. return this.finishNode(node, "ArrayExpression")
  1975. case types.braceL:
  1976. return this.parseObj(false, refDestructuringErrors)
  1977. case types._function:
  1978. node = this.startNode();
  1979. this.next();
  1980. return this.parseFunction(node, false)
  1981. case types._class:
  1982. return this.parseClass(this.startNode(), false)
  1983. case types._new:
  1984. return this.parseNew()
  1985. case types.backQuote:
  1986. return this.parseTemplate()
  1987. default:
  1988. this.unexpected();
  1989. }
  1990. };
  1991. pp$3.parseLiteral = function(value) {
  1992. var node = this.startNode();
  1993. node.value = value;
  1994. node.raw = this.input.slice(this.start, this.end);
  1995. this.next();
  1996. return this.finishNode(node, "Literal")
  1997. };
  1998. pp$3.parseParenExpression = function() {
  1999. this.expect(types.parenL);
  2000. var val = this.parseExpression();
  2001. this.expect(types.parenR);
  2002. return val
  2003. };
  2004. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  2005. var this$1 = this;
  2006. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  2007. if (this.options.ecmaVersion >= 6) {
  2008. this.next();
  2009. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  2010. var exprList = [], first = true, lastIsComma = false;
  2011. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
  2012. this.yieldPos = 0;
  2013. this.awaitPos = 0;
  2014. while (this.type !== types.parenR) {
  2015. first ? first = false : this$1.expect(types.comma);
  2016. if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
  2017. lastIsComma = true;
  2018. break
  2019. } else if (this$1.type === types.ellipsis) {
  2020. spreadStart = this$1.start;
  2021. exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
  2022. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  2023. break
  2024. } else {
  2025. exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
  2026. }
  2027. }
  2028. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  2029. this.expect(types.parenR);
  2030. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  2031. this.checkPatternErrors(refDestructuringErrors, false);
  2032. this.checkYieldAwaitInDefaultParams();
  2033. this.yieldPos = oldYieldPos;
  2034. this.awaitPos = oldAwaitPos;
  2035. return this.parseParenArrowList(startPos, startLoc, exprList)
  2036. }
  2037. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  2038. if (spreadStart) { this.unexpected(spreadStart); }
  2039. this.checkExpressionErrors(refDestructuringErrors, true);
  2040. this.yieldPos = oldYieldPos || this.yieldPos;
  2041. this.awaitPos = oldAwaitPos || this.awaitPos;
  2042. if (exprList.length > 1) {
  2043. val = this.startNodeAt(innerStartPos, innerStartLoc);
  2044. val.expressions = exprList;
  2045. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  2046. } else {
  2047. val = exprList[0];
  2048. }
  2049. } else {
  2050. val = this.parseParenExpression();
  2051. }
  2052. if (this.options.preserveParens) {
  2053. var par = this.startNodeAt(startPos, startLoc);
  2054. par.expression = val;
  2055. return this.finishNode(par, "ParenthesizedExpression")
  2056. } else {
  2057. return val
  2058. }
  2059. };
  2060. pp$3.parseParenItem = function(item) {
  2061. return item
  2062. };
  2063. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  2064. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  2065. };
  2066. // New's precedence is slightly tricky. It must allow its argument to
  2067. // be a `[]` or dot subscript expression, but not a call — at least,
  2068. // not without wrapping it in parentheses. Thus, it uses the noCalls
  2069. // argument to parseSubscripts to prevent it from consuming the
  2070. // argument list.
  2071. var empty$1 = [];
  2072. pp$3.parseNew = function() {
  2073. var node = this.startNode();
  2074. var meta = this.parseIdent(true);
  2075. if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
  2076. node.meta = meta;
  2077. var containsEsc = this.containsEsc;
  2078. node.property = this.parseIdent(true);
  2079. if (node.property.name !== "target" || containsEsc)
  2080. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
  2081. if (!this.inFunction)
  2082. { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
  2083. return this.finishNode(node, "MetaProperty")
  2084. }
  2085. var startPos = this.start, startLoc = this.startLoc;
  2086. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  2087. if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
  2088. else { node.arguments = empty$1; }
  2089. return this.finishNode(node, "NewExpression")
  2090. };
  2091. // Parse template expression.
  2092. pp$3.parseTemplateElement = function(ref) {
  2093. var isTagged = ref.isTagged;
  2094. var elem = this.startNode();
  2095. if (this.type === types.invalidTemplate) {
  2096. if (!isTagged) {
  2097. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  2098. }
  2099. elem.value = {
  2100. raw: this.value,
  2101. cooked: null
  2102. };
  2103. } else {
  2104. elem.value = {
  2105. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  2106. cooked: this.value
  2107. };
  2108. }
  2109. this.next();
  2110. elem.tail = this.type === types.backQuote;
  2111. return this.finishNode(elem, "TemplateElement")
  2112. };
  2113. pp$3.parseTemplate = function(ref) {
  2114. var this$1 = this;
  2115. if ( ref === void 0 ) ref = {};
  2116. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  2117. var node = this.startNode();
  2118. this.next();
  2119. node.expressions = [];
  2120. var curElt = this.parseTemplateElement({isTagged: isTagged});
  2121. node.quasis = [curElt];
  2122. while (!curElt.tail) {
  2123. if (this$1.type === types.eof) { this$1.raise(this$1.pos, "Unterminated template literal"); }
  2124. this$1.expect(types.dollarBraceL);
  2125. node.expressions.push(this$1.parseExpression());
  2126. this$1.expect(types.braceR);
  2127. node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
  2128. }
  2129. this.next();
  2130. return this.finishNode(node, "TemplateLiteral")
  2131. };
  2132. pp$3.isAsyncProp = function(prop) {
  2133. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  2134. (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) &&
  2135. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2136. };
  2137. // Parse an object literal or binding pattern.
  2138. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  2139. var this$1 = this;
  2140. var node = this.startNode(), first = true, propHash = {};
  2141. node.properties = [];
  2142. this.next();
  2143. while (!this.eat(types.braceR)) {
  2144. if (!first) {
  2145. this$1.expect(types.comma);
  2146. if (this$1.afterTrailingComma(types.braceR)) { break }
  2147. } else { first = false; }
  2148. var prop = this$1.parseProperty(isPattern, refDestructuringErrors);
  2149. if (!isPattern) { this$1.checkPropClash(prop, propHash, refDestructuringErrors); }
  2150. node.properties.push(prop);
  2151. }
  2152. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  2153. };
  2154. pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
  2155. var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
  2156. if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
  2157. if (isPattern) {
  2158. prop.argument = this.parseIdent(false);
  2159. if (this.type === types.comma) {
  2160. this.raise(this.start, "Comma is not permitted after the rest element");
  2161. }
  2162. return this.finishNode(prop, "RestElement")
  2163. }
  2164. // To disallow parenthesized identifier via `this.toAssignable()`.
  2165. if (this.type === types.parenL && refDestructuringErrors) {
  2166. if (refDestructuringErrors.parenthesizedAssign < 0) {
  2167. refDestructuringErrors.parenthesizedAssign = this.start;
  2168. }
  2169. if (refDestructuringErrors.parenthesizedBind < 0) {
  2170. refDestructuringErrors.parenthesizedBind = this.start;
  2171. }
  2172. }
  2173. // Parse argument.
  2174. prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2175. // To disallow trailing comma via `this.toAssignable()`.
  2176. if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
  2177. refDestructuringErrors.trailingComma = this.start;
  2178. }
  2179. // Finish
  2180. return this.finishNode(prop, "SpreadElement")
  2181. }
  2182. if (this.options.ecmaVersion >= 6) {
  2183. prop.method = false;
  2184. prop.shorthand = false;
  2185. if (isPattern || refDestructuringErrors) {
  2186. startPos = this.start;
  2187. startLoc = this.startLoc;
  2188. }
  2189. if (!isPattern)
  2190. { isGenerator = this.eat(types.star); }
  2191. }
  2192. var containsEsc = this.containsEsc;
  2193. this.parsePropertyName(prop);
  2194. if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
  2195. isAsync = true;
  2196. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  2197. this.parsePropertyName(prop, refDestructuringErrors);
  2198. } else {
  2199. isAsync = false;
  2200. }
  2201. this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
  2202. return this.finishNode(prop, "Property")
  2203. };
  2204. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
  2205. if ((isGenerator || isAsync) && this.type === types.colon)
  2206. { this.unexpected(); }
  2207. if (this.eat(types.colon)) {
  2208. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  2209. prop.kind = "init";
  2210. } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
  2211. if (isPattern) { this.unexpected(); }
  2212. prop.kind = "init";
  2213. prop.method = true;
  2214. prop.value = this.parseMethod(isGenerator, isAsync);
  2215. } else if (!isPattern && !containsEsc &&
  2216. this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2217. (prop.key.name === "get" || prop.key.name === "set") &&
  2218. (this.type !== types.comma && this.type !== types.braceR)) {
  2219. if (isGenerator || isAsync) { this.unexpected(); }
  2220. prop.kind = prop.key.name;
  2221. this.parsePropertyName(prop);
  2222. prop.value = this.parseMethod(false);
  2223. var paramCount = prop.kind === "get" ? 0 : 1;
  2224. if (prop.value.params.length !== paramCount) {
  2225. var start = prop.value.start;
  2226. if (prop.kind === "get")
  2227. { this.raiseRecoverable(start, "getter should have no params"); }
  2228. else
  2229. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2230. } else {
  2231. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2232. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2233. }
  2234. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2235. this.checkUnreserved(prop.key);
  2236. prop.kind = "init";
  2237. if (isPattern) {
  2238. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2239. } else if (this.type === types.eq && refDestructuringErrors) {
  2240. if (refDestructuringErrors.shorthandAssign < 0)
  2241. { refDestructuringErrors.shorthandAssign = this.start; }
  2242. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2243. } else {
  2244. prop.value = prop.key;
  2245. }
  2246. prop.shorthand = true;
  2247. } else { this.unexpected(); }
  2248. };
  2249. pp$3.parsePropertyName = function(prop) {
  2250. if (this.options.ecmaVersion >= 6) {
  2251. if (this.eat(types.bracketL)) {
  2252. prop.computed = true;
  2253. prop.key = this.parseMaybeAssign();
  2254. this.expect(types.bracketR);
  2255. return prop.key
  2256. } else {
  2257. prop.computed = false;
  2258. }
  2259. }
  2260. return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
  2261. };
  2262. // Initialize empty function node.
  2263. pp$3.initFunction = function(node) {
  2264. node.id = null;
  2265. if (this.options.ecmaVersion >= 6) {
  2266. node.generator = false;
  2267. node.expression = false;
  2268. }
  2269. if (this.options.ecmaVersion >= 8)
  2270. { node.async = false; }
  2271. };
  2272. // Parse object or class method.
  2273. pp$3.parseMethod = function(isGenerator, isAsync) {
  2274. var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2275. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2276. this.initFunction(node);
  2277. if (this.options.ecmaVersion >= 6)
  2278. { node.generator = isGenerator; }
  2279. if (this.options.ecmaVersion >= 8)
  2280. { node.async = !!isAsync; }
  2281. this.inGenerator = node.generator;
  2282. this.inAsync = node.async;
  2283. this.yieldPos = 0;
  2284. this.awaitPos = 0;
  2285. this.inFunction = true;
  2286. this.enterFunctionScope();
  2287. this.expect(types.parenL);
  2288. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  2289. this.checkYieldAwaitInDefaultParams();
  2290. this.parseFunctionBody(node, false);
  2291. this.inGenerator = oldInGen;
  2292. this.inAsync = oldInAsync;
  2293. this.yieldPos = oldYieldPos;
  2294. this.awaitPos = oldAwaitPos;
  2295. this.inFunction = oldInFunc;
  2296. return this.finishNode(node, "FunctionExpression")
  2297. };
  2298. // Parse arrow function expression with given parameters.
  2299. pp$3.parseArrowExpression = function(node, params, isAsync) {
  2300. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2301. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2302. this.enterFunctionScope();
  2303. this.initFunction(node);
  2304. if (this.options.ecmaVersion >= 8)
  2305. { node.async = !!isAsync; }
  2306. this.inGenerator = false;
  2307. this.inAsync = node.async;
  2308. this.yieldPos = 0;
  2309. this.awaitPos = 0;
  2310. this.inFunction = true;
  2311. node.params = this.toAssignableList(params, true);
  2312. this.parseFunctionBody(node, true);
  2313. this.inGenerator = oldInGen;
  2314. this.inAsync = oldInAsync;
  2315. this.yieldPos = oldYieldPos;
  2316. this.awaitPos = oldAwaitPos;
  2317. this.inFunction = oldInFunc;
  2318. return this.finishNode(node, "ArrowFunctionExpression")
  2319. };
  2320. // Parse function body and check parameters.
  2321. pp$3.parseFunctionBody = function(node, isArrowFunction) {
  2322. var isExpression = isArrowFunction && this.type !== types.braceL;
  2323. var oldStrict = this.strict, useStrict = false;
  2324. if (isExpression) {
  2325. node.body = this.parseMaybeAssign();
  2326. node.expression = true;
  2327. this.checkParams(node, false);
  2328. } else {
  2329. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2330. if (!oldStrict || nonSimple) {
  2331. useStrict = this.strictDirective(this.end);
  2332. // If this is a strict mode function, verify that argument names
  2333. // are not repeated, and it does not try to bind the words `eval`
  2334. // or `arguments`.
  2335. if (useStrict && nonSimple)
  2336. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2337. }
  2338. // Start a new scope with regard to labels and the `inFunction`
  2339. // flag (restore them to their old value afterwards).
  2340. var oldLabels = this.labels;
  2341. this.labels = [];
  2342. if (useStrict) { this.strict = true; }
  2343. // Add the params to varDeclaredNames to ensure that an error is thrown
  2344. // if a let/const declaration in the function clashes with one of the params.
  2345. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
  2346. node.body = this.parseBlock(false);
  2347. node.expression = false;
  2348. this.adaptDirectivePrologue(node.body.body);
  2349. this.labels = oldLabels;
  2350. }
  2351. this.exitFunctionScope();
  2352. if (this.strict && node.id) {
  2353. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2354. this.checkLVal(node.id, "none");
  2355. }
  2356. this.strict = oldStrict;
  2357. };
  2358. pp$3.isSimpleParamList = function(params) {
  2359. for (var i = 0, list = params; i < list.length; i += 1)
  2360. {
  2361. var param = list[i];
  2362. if (param.type !== "Identifier") { return false
  2363. } }
  2364. return true
  2365. };
  2366. // Checks function params for various disallowed patterns such as using "eval"
  2367. // or "arguments" and duplicate parameters.
  2368. pp$3.checkParams = function(node, allowDuplicates) {
  2369. var this$1 = this;
  2370. var nameHash = {};
  2371. for (var i = 0, list = node.params; i < list.length; i += 1)
  2372. {
  2373. var param = list[i];
  2374. this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
  2375. }
  2376. };
  2377. // Parses a comma-separated list of expressions, and returns them as
  2378. // an array. `close` is the token type that ends the list, and
  2379. // `allowEmpty` can be turned on to allow subsequent commas with
  2380. // nothing in between them to be parsed as `null` (which is needed
  2381. // for array literals).
  2382. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2383. var this$1 = this;
  2384. var elts = [], first = true;
  2385. while (!this.eat(close)) {
  2386. if (!first) {
  2387. this$1.expect(types.comma);
  2388. if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
  2389. } else { first = false; }
  2390. var elt = (void 0);
  2391. if (allowEmpty && this$1.type === types.comma)
  2392. { elt = null; }
  2393. else if (this$1.type === types.ellipsis) {
  2394. elt = this$1.parseSpread(refDestructuringErrors);
  2395. if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
  2396. { refDestructuringErrors.trailingComma = this$1.start; }
  2397. } else {
  2398. elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
  2399. }
  2400. elts.push(elt);
  2401. }
  2402. return elts
  2403. };
  2404. pp$3.checkUnreserved = function(ref) {
  2405. var start = ref.start;
  2406. var end = ref.end;
  2407. var name = ref.name;
  2408. if (this.inGenerator && name === "yield")
  2409. { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
  2410. if (this.inAsync && name === "await")
  2411. { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
  2412. if (this.isKeyword(name))
  2413. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2414. if (this.options.ecmaVersion < 6 &&
  2415. this.input.slice(start, end).indexOf("\\") !== -1) { return }
  2416. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2417. if (re.test(name)) {
  2418. if (!this.inAsync && name === "await")
  2419. { this.raiseRecoverable(start, "Can not use keyword 'await' outside an async function"); }
  2420. this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
  2421. }
  2422. };
  2423. // Parse the next token as an identifier. If `liberal` is true (used
  2424. // when parsing properties), it will also convert keywords into
  2425. // identifiers.
  2426. pp$3.parseIdent = function(liberal, isBinding) {
  2427. var node = this.startNode();
  2428. if (liberal && this.options.allowReserved === "never") { liberal = false; }
  2429. if (this.type === types.name) {
  2430. node.name = this.value;
  2431. } else if (this.type.keyword) {
  2432. node.name = this.type.keyword;
  2433. // To fix https://github.com/acornjs/acorn/issues/575
  2434. // `class` and `function` keywords push new context into this.context.
  2435. // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
  2436. // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
  2437. if ((node.name === "class" || node.name === "function") &&
  2438. (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
  2439. this.context.pop();
  2440. }
  2441. } else {
  2442. this.unexpected();
  2443. }
  2444. this.next();
  2445. this.finishNode(node, "Identifier");
  2446. if (!liberal) { this.checkUnreserved(node); }
  2447. return node
  2448. };
  2449. // Parses yield expression inside generator.
  2450. pp$3.parseYield = function() {
  2451. if (!this.yieldPos) { this.yieldPos = this.start; }
  2452. var node = this.startNode();
  2453. this.next();
  2454. if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
  2455. node.delegate = false;
  2456. node.argument = null;
  2457. } else {
  2458. node.delegate = this.eat(types.star);
  2459. node.argument = this.parseMaybeAssign();
  2460. }
  2461. return this.finishNode(node, "YieldExpression")
  2462. };
  2463. pp$3.parseAwait = function() {
  2464. if (!this.awaitPos) { this.awaitPos = this.start; }
  2465. var node = this.startNode();
  2466. this.next();
  2467. node.argument = this.parseMaybeUnary(null, true);
  2468. return this.finishNode(node, "AwaitExpression")
  2469. };
  2470. var pp$4 = Parser.prototype;
  2471. // This function is used to raise exceptions on parse errors. It
  2472. // takes an offset integer (into the current `input`) to indicate
  2473. // the location of the error, attaches the position to the end
  2474. // of the error message, and then raises a `SyntaxError` with that
  2475. // message.
  2476. pp$4.raise = function(pos, message) {
  2477. var loc = getLineInfo(this.input, pos);
  2478. message += " (" + loc.line + ":" + loc.column + ")";
  2479. var err = new SyntaxError(message);
  2480. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  2481. throw err
  2482. };
  2483. pp$4.raiseRecoverable = pp$4.raise;
  2484. pp$4.curPosition = function() {
  2485. if (this.options.locations) {
  2486. return new Position(this.curLine, this.pos - this.lineStart)
  2487. }
  2488. };
  2489. var pp$5 = Parser.prototype;
  2490. // Object.assign polyfill
  2491. var assign$1 = Object.assign || function(target) {
  2492. var sources = [], len = arguments.length - 1;
  2493. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  2494. for (var i = 0, list = sources; i < list.length; i += 1) {
  2495. var source = list[i];
  2496. for (var key in source) {
  2497. if (has(source, key)) {
  2498. target[key] = source[key];
  2499. }
  2500. }
  2501. }
  2502. return target
  2503. };
  2504. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  2505. pp$5.enterFunctionScope = function() {
  2506. // var: a hash of var-declared names in the current lexical scope
  2507. // lexical: a hash of lexically-declared names in the current lexical scope
  2508. // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
  2509. // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
  2510. this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
  2511. };
  2512. pp$5.exitFunctionScope = function() {
  2513. this.scopeStack.pop();
  2514. };
  2515. pp$5.enterLexicalScope = function() {
  2516. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2517. var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
  2518. this.scopeStack.push(childScope);
  2519. assign$1(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
  2520. };
  2521. pp$5.exitLexicalScope = function() {
  2522. var childScope = this.scopeStack.pop();
  2523. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2524. assign$1(parentScope.childVar, childScope.var, childScope.childVar);
  2525. };
  2526. /**
  2527. * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
  2528. * in the current lexical scope or any of the parent lexical scopes in this function.
  2529. */
  2530. pp$5.canDeclareVarName = function(name) {
  2531. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2532. return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
  2533. };
  2534. /**
  2535. * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
  2536. * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
  2537. * any child lexical scopes in this function.
  2538. */
  2539. pp$5.canDeclareLexicalName = function(name) {
  2540. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2541. return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
  2542. };
  2543. pp$5.declareVarName = function(name) {
  2544. this.scopeStack[this.scopeStack.length - 1].var[name] = true;
  2545. };
  2546. pp$5.declareLexicalName = function(name) {
  2547. this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
  2548. };
  2549. var Node = function Node(parser, pos, loc) {
  2550. this.type = "";
  2551. this.start = pos;
  2552. this.end = 0;
  2553. if (parser.options.locations)
  2554. { this.loc = new SourceLocation(parser, loc); }
  2555. if (parser.options.directSourceFile)
  2556. { this.sourceFile = parser.options.directSourceFile; }
  2557. if (parser.options.ranges)
  2558. { this.range = [pos, 0]; }
  2559. };
  2560. // Start an AST node, attaching a start offset.
  2561. var pp$6 = Parser.prototype;
  2562. pp$6.startNode = function() {
  2563. return new Node(this, this.start, this.startLoc)
  2564. };
  2565. pp$6.startNodeAt = function(pos, loc) {
  2566. return new Node(this, pos, loc)
  2567. };
  2568. // Finish an AST node, adding `type` and `end` properties.
  2569. function finishNodeAt(node, type, pos, loc) {
  2570. node.type = type;
  2571. node.end = pos;
  2572. if (this.options.locations)
  2573. { node.loc.end = loc; }
  2574. if (this.options.ranges)
  2575. { node.range[1] = pos; }
  2576. return node
  2577. }
  2578. pp$6.finishNode = function(node, type) {
  2579. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  2580. };
  2581. // Finish node at given position
  2582. pp$6.finishNodeAt = function(node, type, pos, loc) {
  2583. return finishNodeAt.call(this, node, type, pos, loc)
  2584. };
  2585. // The algorithm used to determine whether a regexp can appear at a
  2586. // given point in the program is loosely based on sweet.js' approach.
  2587. // See https://github.com/mozilla/sweet.js/wiki/design
  2588. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  2589. this.token = token;
  2590. this.isExpr = !!isExpr;
  2591. this.preserveSpace = !!preserveSpace;
  2592. this.override = override;
  2593. this.generator = !!generator;
  2594. };
  2595. var types$1 = {
  2596. b_stat: new TokContext("{", false),
  2597. b_expr: new TokContext("{", true),
  2598. b_tmpl: new TokContext("${", false),
  2599. p_stat: new TokContext("(", false),
  2600. p_expr: new TokContext("(", true),
  2601. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  2602. f_stat: new TokContext("function", false),
  2603. f_expr: new TokContext("function", true),
  2604. f_expr_gen: new TokContext("function", true, false, null, true),
  2605. f_gen: new TokContext("function", false, false, null, true)
  2606. };
  2607. var pp$7 = Parser.prototype;
  2608. pp$7.initialContext = function() {
  2609. return [types$1.b_stat]
  2610. };
  2611. pp$7.braceIsBlock = function(prevType) {
  2612. var parent = this.curContext();
  2613. if (parent === types$1.f_expr || parent === types$1.f_stat)
  2614. { return true }
  2615. if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
  2616. { return !parent.isExpr }
  2617. // The check for `tt.name && exprAllowed` detects whether we are
  2618. // after a `yield` or `of` construct. See the `updateContext` for
  2619. // `tt.name`.
  2620. if (prevType === types._return || prevType === types.name && this.exprAllowed)
  2621. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2622. if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow)
  2623. { return true }
  2624. if (prevType === types.braceL)
  2625. { return parent === types$1.b_stat }
  2626. if (prevType === types._var || prevType === types.name)
  2627. { return false }
  2628. return !this.exprAllowed
  2629. };
  2630. pp$7.inGeneratorContext = function() {
  2631. var this$1 = this;
  2632. for (var i = this.context.length - 1; i >= 1; i--) {
  2633. var context = this$1.context[i];
  2634. if (context.token === "function")
  2635. { return context.generator }
  2636. }
  2637. return false
  2638. };
  2639. pp$7.updateContext = function(prevType) {
  2640. var update, type = this.type;
  2641. if (type.keyword && prevType === types.dot)
  2642. { this.exprAllowed = false; }
  2643. else if (update = type.updateContext)
  2644. { update.call(this, prevType); }
  2645. else
  2646. { this.exprAllowed = type.beforeExpr; }
  2647. };
  2648. // Token-specific context update code
  2649. types.parenR.updateContext = types.braceR.updateContext = function() {
  2650. if (this.context.length === 1) {
  2651. this.exprAllowed = true;
  2652. return
  2653. }
  2654. var out = this.context.pop();
  2655. if (out === types$1.b_stat && this.curContext().token === "function") {
  2656. out = this.context.pop();
  2657. }
  2658. this.exprAllowed = !out.isExpr;
  2659. };
  2660. types.braceL.updateContext = function(prevType) {
  2661. this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
  2662. this.exprAllowed = true;
  2663. };
  2664. types.dollarBraceL.updateContext = function() {
  2665. this.context.push(types$1.b_tmpl);
  2666. this.exprAllowed = true;
  2667. };
  2668. types.parenL.updateContext = function(prevType) {
  2669. var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
  2670. this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
  2671. this.exprAllowed = true;
  2672. };
  2673. types.incDec.updateContext = function() {
  2674. // tokExprAllowed stays unchanged
  2675. };
  2676. types._function.updateContext = types._class.updateContext = function(prevType) {
  2677. if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
  2678. !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
  2679. { this.context.push(types$1.f_expr); }
  2680. else
  2681. { this.context.push(types$1.f_stat); }
  2682. this.exprAllowed = false;
  2683. };
  2684. types.backQuote.updateContext = function() {
  2685. if (this.curContext() === types$1.q_tmpl)
  2686. { this.context.pop(); }
  2687. else
  2688. { this.context.push(types$1.q_tmpl); }
  2689. this.exprAllowed = false;
  2690. };
  2691. types.star.updateContext = function(prevType) {
  2692. if (prevType === types._function) {
  2693. var index = this.context.length - 1;
  2694. if (this.context[index] === types$1.f_expr)
  2695. { this.context[index] = types$1.f_expr_gen; }
  2696. else
  2697. { this.context[index] = types$1.f_gen; }
  2698. }
  2699. this.exprAllowed = true;
  2700. };
  2701. types.name.updateContext = function(prevType) {
  2702. var allowed = false;
  2703. if (this.options.ecmaVersion >= 6 && prevType !== types.dot) {
  2704. if (this.value === "of" && !this.exprAllowed ||
  2705. this.value === "yield" && this.inGeneratorContext())
  2706. { allowed = true; }
  2707. }
  2708. this.exprAllowed = allowed;
  2709. };
  2710. var data = {
  2711. "$LONE": [
  2712. "ASCII",
  2713. "ASCII_Hex_Digit",
  2714. "AHex",
  2715. "Alphabetic",
  2716. "Alpha",
  2717. "Any",
  2718. "Assigned",
  2719. "Bidi_Control",
  2720. "Bidi_C",
  2721. "Bidi_Mirrored",
  2722. "Bidi_M",
  2723. "Case_Ignorable",
  2724. "CI",
  2725. "Cased",
  2726. "Changes_When_Casefolded",
  2727. "CWCF",
  2728. "Changes_When_Casemapped",
  2729. "CWCM",
  2730. "Changes_When_Lowercased",
  2731. "CWL",
  2732. "Changes_When_NFKC_Casefolded",
  2733. "CWKCF",
  2734. "Changes_When_Titlecased",
  2735. "CWT",
  2736. "Changes_When_Uppercased",
  2737. "CWU",
  2738. "Dash",
  2739. "Default_Ignorable_Code_Point",
  2740. "DI",
  2741. "Deprecated",
  2742. "Dep",
  2743. "Diacritic",
  2744. "Dia",
  2745. "Emoji",
  2746. "Emoji_Component",
  2747. "Emoji_Modifier",
  2748. "Emoji_Modifier_Base",
  2749. "Emoji_Presentation",
  2750. "Extender",
  2751. "Ext",
  2752. "Grapheme_Base",
  2753. "Gr_Base",
  2754. "Grapheme_Extend",
  2755. "Gr_Ext",
  2756. "Hex_Digit",
  2757. "Hex",
  2758. "IDS_Binary_Operator",
  2759. "IDSB",
  2760. "IDS_Trinary_Operator",
  2761. "IDST",
  2762. "ID_Continue",
  2763. "IDC",
  2764. "ID_Start",
  2765. "IDS",
  2766. "Ideographic",
  2767. "Ideo",
  2768. "Join_Control",
  2769. "Join_C",
  2770. "Logical_Order_Exception",
  2771. "LOE",
  2772. "Lowercase",
  2773. "Lower",
  2774. "Math",
  2775. "Noncharacter_Code_Point",
  2776. "NChar",
  2777. "Pattern_Syntax",
  2778. "Pat_Syn",
  2779. "Pattern_White_Space",
  2780. "Pat_WS",
  2781. "Quotation_Mark",
  2782. "QMark",
  2783. "Radical",
  2784. "Regional_Indicator",
  2785. "RI",
  2786. "Sentence_Terminal",
  2787. "STerm",
  2788. "Soft_Dotted",
  2789. "SD",
  2790. "Terminal_Punctuation",
  2791. "Term",
  2792. "Unified_Ideograph",
  2793. "UIdeo",
  2794. "Uppercase",
  2795. "Upper",
  2796. "Variation_Selector",
  2797. "VS",
  2798. "White_Space",
  2799. "space",
  2800. "XID_Continue",
  2801. "XIDC",
  2802. "XID_Start",
  2803. "XIDS"
  2804. ],
  2805. "General_Category": [
  2806. "Cased_Letter",
  2807. "LC",
  2808. "Close_Punctuation",
  2809. "Pe",
  2810. "Connector_Punctuation",
  2811. "Pc",
  2812. "Control",
  2813. "Cc",
  2814. "cntrl",
  2815. "Currency_Symbol",
  2816. "Sc",
  2817. "Dash_Punctuation",
  2818. "Pd",
  2819. "Decimal_Number",
  2820. "Nd",
  2821. "digit",
  2822. "Enclosing_Mark",
  2823. "Me",
  2824. "Final_Punctuation",
  2825. "Pf",
  2826. "Format",
  2827. "Cf",
  2828. "Initial_Punctuation",
  2829. "Pi",
  2830. "Letter",
  2831. "L",
  2832. "Letter_Number",
  2833. "Nl",
  2834. "Line_Separator",
  2835. "Zl",
  2836. "Lowercase_Letter",
  2837. "Ll",
  2838. "Mark",
  2839. "M",
  2840. "Combining_Mark",
  2841. "Math_Symbol",
  2842. "Sm",
  2843. "Modifier_Letter",
  2844. "Lm",
  2845. "Modifier_Symbol",
  2846. "Sk",
  2847. "Nonspacing_Mark",
  2848. "Mn",
  2849. "Number",
  2850. "N",
  2851. "Open_Punctuation",
  2852. "Ps",
  2853. "Other",
  2854. "C",
  2855. "Other_Letter",
  2856. "Lo",
  2857. "Other_Number",
  2858. "No",
  2859. "Other_Punctuation",
  2860. "Po",
  2861. "Other_Symbol",
  2862. "So",
  2863. "Paragraph_Separator",
  2864. "Zp",
  2865. "Private_Use",
  2866. "Co",
  2867. "Punctuation",
  2868. "P",
  2869. "punct",
  2870. "Separator",
  2871. "Z",
  2872. "Space_Separator",
  2873. "Zs",
  2874. "Spacing_Mark",
  2875. "Mc",
  2876. "Surrogate",
  2877. "Cs",
  2878. "Symbol",
  2879. "S",
  2880. "Titlecase_Letter",
  2881. "Lt",
  2882. "Unassigned",
  2883. "Cn",
  2884. "Uppercase_Letter",
  2885. "Lu"
  2886. ],
  2887. "Script": [
  2888. "Adlam",
  2889. "Adlm",
  2890. "Ahom",
  2891. "Anatolian_Hieroglyphs",
  2892. "Hluw",
  2893. "Arabic",
  2894. "Arab",
  2895. "Armenian",
  2896. "Armn",
  2897. "Avestan",
  2898. "Avst",
  2899. "Balinese",
  2900. "Bali",
  2901. "Bamum",
  2902. "Bamu",
  2903. "Bassa_Vah",
  2904. "Bass",
  2905. "Batak",
  2906. "Batk",
  2907. "Bengali",
  2908. "Beng",
  2909. "Bhaiksuki",
  2910. "Bhks",
  2911. "Bopomofo",
  2912. "Bopo",
  2913. "Brahmi",
  2914. "Brah",
  2915. "Braille",
  2916. "Brai",
  2917. "Buginese",
  2918. "Bugi",
  2919. "Buhid",
  2920. "Buhd",
  2921. "Canadian_Aboriginal",
  2922. "Cans",
  2923. "Carian",
  2924. "Cari",
  2925. "Caucasian_Albanian",
  2926. "Aghb",
  2927. "Chakma",
  2928. "Cakm",
  2929. "Cham",
  2930. "Cherokee",
  2931. "Cher",
  2932. "Common",
  2933. "Zyyy",
  2934. "Coptic",
  2935. "Copt",
  2936. "Qaac",
  2937. "Cuneiform",
  2938. "Xsux",
  2939. "Cypriot",
  2940. "Cprt",
  2941. "Cyrillic",
  2942. "Cyrl",
  2943. "Deseret",
  2944. "Dsrt",
  2945. "Devanagari",
  2946. "Deva",
  2947. "Duployan",
  2948. "Dupl",
  2949. "Egyptian_Hieroglyphs",
  2950. "Egyp",
  2951. "Elbasan",
  2952. "Elba",
  2953. "Ethiopic",
  2954. "Ethi",
  2955. "Georgian",
  2956. "Geor",
  2957. "Glagolitic",
  2958. "Glag",
  2959. "Gothic",
  2960. "Goth",
  2961. "Grantha",
  2962. "Gran",
  2963. "Greek",
  2964. "Grek",
  2965. "Gujarati",
  2966. "Gujr",
  2967. "Gurmukhi",
  2968. "Guru",
  2969. "Han",
  2970. "Hani",
  2971. "Hangul",
  2972. "Hang",
  2973. "Hanunoo",
  2974. "Hano",
  2975. "Hatran",
  2976. "Hatr",
  2977. "Hebrew",
  2978. "Hebr",
  2979. "Hiragana",
  2980. "Hira",
  2981. "Imperial_Aramaic",
  2982. "Armi",
  2983. "Inherited",
  2984. "Zinh",
  2985. "Qaai",
  2986. "Inscriptional_Pahlavi",
  2987. "Phli",
  2988. "Inscriptional_Parthian",
  2989. "Prti",
  2990. "Javanese",
  2991. "Java",
  2992. "Kaithi",
  2993. "Kthi",
  2994. "Kannada",
  2995. "Knda",
  2996. "Katakana",
  2997. "Kana",
  2998. "Kayah_Li",
  2999. "Kali",
  3000. "Kharoshthi",
  3001. "Khar",
  3002. "Khmer",
  3003. "Khmr",
  3004. "Khojki",
  3005. "Khoj",
  3006. "Khudawadi",
  3007. "Sind",
  3008. "Lao",
  3009. "Laoo",
  3010. "Latin",
  3011. "Latn",
  3012. "Lepcha",
  3013. "Lepc",
  3014. "Limbu",
  3015. "Limb",
  3016. "Linear_A",
  3017. "Lina",
  3018. "Linear_B",
  3019. "Linb",
  3020. "Lisu",
  3021. "Lycian",
  3022. "Lyci",
  3023. "Lydian",
  3024. "Lydi",
  3025. "Mahajani",
  3026. "Mahj",
  3027. "Malayalam",
  3028. "Mlym",
  3029. "Mandaic",
  3030. "Mand",
  3031. "Manichaean",
  3032. "Mani",
  3033. "Marchen",
  3034. "Marc",
  3035. "Masaram_Gondi",
  3036. "Gonm",
  3037. "Meetei_Mayek",
  3038. "Mtei",
  3039. "Mende_Kikakui",
  3040. "Mend",
  3041. "Meroitic_Cursive",
  3042. "Merc",
  3043. "Meroitic_Hieroglyphs",
  3044. "Mero",
  3045. "Miao",
  3046. "Plrd",
  3047. "Modi",
  3048. "Mongolian",
  3049. "Mong",
  3050. "Mro",
  3051. "Mroo",
  3052. "Multani",
  3053. "Mult",
  3054. "Myanmar",
  3055. "Mymr",
  3056. "Nabataean",
  3057. "Nbat",
  3058. "New_Tai_Lue",
  3059. "Talu",
  3060. "Newa",
  3061. "Nko",
  3062. "Nkoo",
  3063. "Nushu",
  3064. "Nshu",
  3065. "Ogham",
  3066. "Ogam",
  3067. "Ol_Chiki",
  3068. "Olck",
  3069. "Old_Hungarian",
  3070. "Hung",
  3071. "Old_Italic",
  3072. "Ital",
  3073. "Old_North_Arabian",
  3074. "Narb",
  3075. "Old_Permic",
  3076. "Perm",
  3077. "Old_Persian",
  3078. "Xpeo",
  3079. "Old_South_Arabian",
  3080. "Sarb",
  3081. "Old_Turkic",
  3082. "Orkh",
  3083. "Oriya",
  3084. "Orya",
  3085. "Osage",
  3086. "Osge",
  3087. "Osmanya",
  3088. "Osma",
  3089. "Pahawh_Hmong",
  3090. "Hmng",
  3091. "Palmyrene",
  3092. "Palm",
  3093. "Pau_Cin_Hau",
  3094. "Pauc",
  3095. "Phags_Pa",
  3096. "Phag",
  3097. "Phoenician",
  3098. "Phnx",
  3099. "Psalter_Pahlavi",
  3100. "Phlp",
  3101. "Rejang",
  3102. "Rjng",
  3103. "Runic",
  3104. "Runr",
  3105. "Samaritan",
  3106. "Samr",
  3107. "Saurashtra",
  3108. "Saur",
  3109. "Sharada",
  3110. "Shrd",
  3111. "Shavian",
  3112. "Shaw",
  3113. "Siddham",
  3114. "Sidd",
  3115. "SignWriting",
  3116. "Sgnw",
  3117. "Sinhala",
  3118. "Sinh",
  3119. "Sora_Sompeng",
  3120. "Sora",
  3121. "Soyombo",
  3122. "Soyo",
  3123. "Sundanese",
  3124. "Sund",
  3125. "Syloti_Nagri",
  3126. "Sylo",
  3127. "Syriac",
  3128. "Syrc",
  3129. "Tagalog",
  3130. "Tglg",
  3131. "Tagbanwa",
  3132. "Tagb",
  3133. "Tai_Le",
  3134. "Tale",
  3135. "Tai_Tham",
  3136. "Lana",
  3137. "Tai_Viet",
  3138. "Tavt",
  3139. "Takri",
  3140. "Takr",
  3141. "Tamil",
  3142. "Taml",
  3143. "Tangut",
  3144. "Tang",
  3145. "Telugu",
  3146. "Telu",
  3147. "Thaana",
  3148. "Thaa",
  3149. "Thai",
  3150. "Tibetan",
  3151. "Tibt",
  3152. "Tifinagh",
  3153. "Tfng",
  3154. "Tirhuta",
  3155. "Tirh",
  3156. "Ugaritic",
  3157. "Ugar",
  3158. "Vai",
  3159. "Vaii",
  3160. "Warang_Citi",
  3161. "Wara",
  3162. "Yi",
  3163. "Yiii",
  3164. "Zanabazar_Square",
  3165. "Zanb"
  3166. ]
  3167. };
  3168. Array.prototype.push.apply(data.$LONE, data.General_Category);
  3169. data.gc = data.General_Category;
  3170. data.sc = data.Script_Extensions = data.scx = data.Script;
  3171. var pp$9 = Parser.prototype;
  3172. var RegExpValidationState = function RegExpValidationState(parser) {
  3173. this.parser = parser;
  3174. this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
  3175. this.source = "";
  3176. this.flags = "";
  3177. this.start = 0;
  3178. this.switchU = false;
  3179. this.switchN = false;
  3180. this.pos = 0;
  3181. this.lastIntValue = 0;
  3182. this.lastStringValue = "";
  3183. this.lastAssertionIsQuantifiable = false;
  3184. this.numCapturingParens = 0;
  3185. this.maxBackReference = 0;
  3186. this.groupNames = [];
  3187. this.backReferenceNames = [];
  3188. };
  3189. RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
  3190. var unicode = flags.indexOf("u") !== -1;
  3191. this.start = start | 0;
  3192. this.source = pattern + "";
  3193. this.flags = flags;
  3194. this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
  3195. this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
  3196. };
  3197. RegExpValidationState.prototype.raise = function raise (message) {
  3198. this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
  3199. };
  3200. // If u flag is given, this returns the code point at the index (it combines a surrogate pair).
  3201. // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
  3202. RegExpValidationState.prototype.at = function at (i) {
  3203. var s = this.source;
  3204. var l = s.length;
  3205. if (i >= l) {
  3206. return -1
  3207. }
  3208. var c = s.charCodeAt(i);
  3209. if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3210. return c
  3211. }
  3212. return (c << 10) + s.charCodeAt(i + 1) - 0x35FDC00
  3213. };
  3214. RegExpValidationState.prototype.nextIndex = function nextIndex (i) {
  3215. var s = this.source;
  3216. var l = s.length;
  3217. if (i >= l) {
  3218. return l
  3219. }
  3220. var c = s.charCodeAt(i);
  3221. if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3222. return i + 1
  3223. }
  3224. return i + 2
  3225. };
  3226. RegExpValidationState.prototype.current = function current () {
  3227. return this.at(this.pos)
  3228. };
  3229. RegExpValidationState.prototype.lookahead = function lookahead () {
  3230. return this.at(this.nextIndex(this.pos))
  3231. };
  3232. RegExpValidationState.prototype.advance = function advance () {
  3233. this.pos = this.nextIndex(this.pos);
  3234. };
  3235. RegExpValidationState.prototype.eat = function eat (ch) {
  3236. if (this.current() === ch) {
  3237. this.advance();
  3238. return true
  3239. }
  3240. return false
  3241. };
  3242. function codePointToString$1(ch) {
  3243. if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
  3244. ch -= 0x10000;
  3245. return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
  3246. }
  3247. /**
  3248. * Validate the flags part of a given RegExpLiteral.
  3249. *
  3250. * @param {RegExpValidationState} state The state to validate RegExp.
  3251. * @returns {void}
  3252. */
  3253. pp$9.validateRegExpFlags = function(state) {
  3254. var this$1 = this;
  3255. var validFlags = state.validFlags;
  3256. var flags = state.flags;
  3257. for (var i = 0; i < flags.length; i++) {
  3258. var flag = flags.charAt(i);
  3259. if (validFlags.indexOf(flag) === -1) {
  3260. this$1.raise(state.start, "Invalid regular expression flag");
  3261. }
  3262. if (flags.indexOf(flag, i + 1) > -1) {
  3263. this$1.raise(state.start, "Duplicate regular expression flag");
  3264. }
  3265. }
  3266. };
  3267. /**
  3268. * Validate the pattern part of a given RegExpLiteral.
  3269. *
  3270. * @param {RegExpValidationState} state The state to validate RegExp.
  3271. * @returns {void}
  3272. */
  3273. pp$9.validateRegExpPattern = function(state) {
  3274. this.regexp_pattern(state);
  3275. // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
  3276. // parsing contains a |GroupName|, reparse with the goal symbol
  3277. // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
  3278. // exception if _P_ did not conform to the grammar, if any elements of _P_
  3279. // were not matched by the parse, or if any Early Error conditions exist.
  3280. if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
  3281. state.switchN = true;
  3282. this.regexp_pattern(state);
  3283. }
  3284. };
  3285. // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
  3286. pp$9.regexp_pattern = function(state) {
  3287. state.pos = 0;
  3288. state.lastIntValue = 0;
  3289. state.lastStringValue = "";
  3290. state.lastAssertionIsQuantifiable = false;
  3291. state.numCapturingParens = 0;
  3292. state.maxBackReference = 0;
  3293. state.groupNames.length = 0;
  3294. state.backReferenceNames.length = 0;
  3295. this.regexp_disjunction(state);
  3296. if (state.pos !== state.source.length) {
  3297. // Make the same messages as V8.
  3298. if (state.eat(0x29 /* ) */)) {
  3299. state.raise("Unmatched ')'");
  3300. }
  3301. if (state.eat(0x5D /* [ */) || state.eat(0x7D /* } */)) {
  3302. state.raise("Lone quantifier brackets");
  3303. }
  3304. }
  3305. if (state.maxBackReference > state.numCapturingParens) {
  3306. state.raise("Invalid escape");
  3307. }
  3308. for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
  3309. var name = list[i];
  3310. if (state.groupNames.indexOf(name) === -1) {
  3311. state.raise("Invalid named capture referenced");
  3312. }
  3313. }
  3314. };
  3315. // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
  3316. pp$9.regexp_disjunction = function(state) {
  3317. var this$1 = this;
  3318. this.regexp_alternative(state);
  3319. while (state.eat(0x7C /* | */)) {
  3320. this$1.regexp_alternative(state);
  3321. }
  3322. // Make the same message as V8.
  3323. if (this.regexp_eatQuantifier(state, true)) {
  3324. state.raise("Nothing to repeat");
  3325. }
  3326. if (state.eat(0x7B /* { */)) {
  3327. state.raise("Lone quantifier brackets");
  3328. }
  3329. };
  3330. // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
  3331. pp$9.regexp_alternative = function(state) {
  3332. while (state.pos < state.source.length && this.regexp_eatTerm(state))
  3333. { }
  3334. };
  3335. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
  3336. pp$9.regexp_eatTerm = function(state) {
  3337. if (this.regexp_eatAssertion(state)) {
  3338. // Handle `QuantifiableAssertion Quantifier` alternative.
  3339. // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
  3340. // is a QuantifiableAssertion.
  3341. if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
  3342. // Make the same message as V8.
  3343. if (state.switchU) {
  3344. state.raise("Invalid quantifier");
  3345. }
  3346. }
  3347. return true
  3348. }
  3349. if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
  3350. this.regexp_eatQuantifier(state);
  3351. return true
  3352. }
  3353. return false
  3354. };
  3355. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
  3356. pp$9.regexp_eatAssertion = function(state) {
  3357. var start = state.pos;
  3358. state.lastAssertionIsQuantifiable = false;
  3359. // ^, $
  3360. if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
  3361. return true
  3362. }
  3363. // \b \B
  3364. if (state.eat(0x5C /* \ */)) {
  3365. if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
  3366. return true
  3367. }
  3368. state.pos = start;
  3369. }
  3370. // Lookahead / Lookbehind
  3371. if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
  3372. var lookbehind = false;
  3373. if (this.options.ecmaVersion >= 9) {
  3374. lookbehind = state.eat(0x3C /* < */);
  3375. }
  3376. if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
  3377. this.regexp_disjunction(state);
  3378. if (!state.eat(0x29 /* ) */)) {
  3379. state.raise("Unterminated group");
  3380. }
  3381. state.lastAssertionIsQuantifiable = !lookbehind;
  3382. return true
  3383. }
  3384. }
  3385. state.pos = start;
  3386. return false
  3387. };
  3388. // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
  3389. pp$9.regexp_eatQuantifier = function(state, noError) {
  3390. if ( noError === void 0 ) noError = false;
  3391. if (this.regexp_eatQuantifierPrefix(state, noError)) {
  3392. state.eat(0x3F /* ? */);
  3393. return true
  3394. }
  3395. return false
  3396. };
  3397. // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
  3398. pp$9.regexp_eatQuantifierPrefix = function(state, noError) {
  3399. return (
  3400. state.eat(0x2A /* * */) ||
  3401. state.eat(0x2B /* + */) ||
  3402. state.eat(0x3F /* ? */) ||
  3403. this.regexp_eatBracedQuantifier(state, noError)
  3404. )
  3405. };
  3406. pp$9.regexp_eatBracedQuantifier = function(state, noError) {
  3407. var start = state.pos;
  3408. if (state.eat(0x7B /* { */)) {
  3409. var min = 0, max = -1;
  3410. if (this.regexp_eatDecimalDigits(state)) {
  3411. min = state.lastIntValue;
  3412. if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
  3413. max = state.lastIntValue;
  3414. }
  3415. if (state.eat(0x7D /* } */)) {
  3416. // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
  3417. if (max !== -1 && max < min && !noError) {
  3418. state.raise("numbers out of order in {} quantifier");
  3419. }
  3420. return true
  3421. }
  3422. }
  3423. if (state.switchU && !noError) {
  3424. state.raise("Incomplete quantifier");
  3425. }
  3426. state.pos = start;
  3427. }
  3428. return false
  3429. };
  3430. // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
  3431. pp$9.regexp_eatAtom = function(state) {
  3432. return (
  3433. this.regexp_eatPatternCharacters(state) ||
  3434. state.eat(0x2E /* . */) ||
  3435. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3436. this.regexp_eatCharacterClass(state) ||
  3437. this.regexp_eatUncapturingGroup(state) ||
  3438. this.regexp_eatCapturingGroup(state)
  3439. )
  3440. };
  3441. pp$9.regexp_eatReverseSolidusAtomEscape = function(state) {
  3442. var start = state.pos;
  3443. if (state.eat(0x5C /* \ */)) {
  3444. if (this.regexp_eatAtomEscape(state)) {
  3445. return true
  3446. }
  3447. state.pos = start;
  3448. }
  3449. return false
  3450. };
  3451. pp$9.regexp_eatUncapturingGroup = function(state) {
  3452. var start = state.pos;
  3453. if (state.eat(0x28 /* ( */)) {
  3454. if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
  3455. this.regexp_disjunction(state);
  3456. if (state.eat(0x29 /* ) */)) {
  3457. return true
  3458. }
  3459. state.raise("Unterminated group");
  3460. }
  3461. state.pos = start;
  3462. }
  3463. return false
  3464. };
  3465. pp$9.regexp_eatCapturingGroup = function(state) {
  3466. if (state.eat(0x28 /* ( */)) {
  3467. if (this.options.ecmaVersion >= 9) {
  3468. this.regexp_groupSpecifier(state);
  3469. } else if (state.current() === 0x3F /* ? */) {
  3470. state.raise("Invalid group");
  3471. }
  3472. this.regexp_disjunction(state);
  3473. if (state.eat(0x29 /* ) */)) {
  3474. state.numCapturingParens += 1;
  3475. return true
  3476. }
  3477. state.raise("Unterminated group");
  3478. }
  3479. return false
  3480. };
  3481. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
  3482. pp$9.regexp_eatExtendedAtom = function(state) {
  3483. return (
  3484. state.eat(0x2E /* . */) ||
  3485. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3486. this.regexp_eatCharacterClass(state) ||
  3487. this.regexp_eatUncapturingGroup(state) ||
  3488. this.regexp_eatCapturingGroup(state) ||
  3489. this.regexp_eatInvalidBracedQuantifier(state) ||
  3490. this.regexp_eatExtendedPatternCharacter(state)
  3491. )
  3492. };
  3493. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
  3494. pp$9.regexp_eatInvalidBracedQuantifier = function(state) {
  3495. if (this.regexp_eatBracedQuantifier(state, true)) {
  3496. state.raise("Nothing to repeat");
  3497. }
  3498. return false
  3499. };
  3500. // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
  3501. pp$9.regexp_eatSyntaxCharacter = function(state) {
  3502. var ch = state.current();
  3503. if (isSyntaxCharacter(ch)) {
  3504. state.lastIntValue = ch;
  3505. state.advance();
  3506. return true
  3507. }
  3508. return false
  3509. };
  3510. function isSyntaxCharacter(ch) {
  3511. return (
  3512. ch === 0x24 /* $ */ ||
  3513. ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
  3514. ch === 0x2E /* . */ ||
  3515. ch === 0x3F /* ? */ ||
  3516. ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
  3517. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  3518. )
  3519. }
  3520. // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
  3521. // But eat eager.
  3522. pp$9.regexp_eatPatternCharacters = function(state) {
  3523. var start = state.pos;
  3524. var ch = 0;
  3525. while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
  3526. state.advance();
  3527. }
  3528. return state.pos !== start
  3529. };
  3530. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
  3531. pp$9.regexp_eatExtendedPatternCharacter = function(state) {
  3532. var ch = state.current();
  3533. if (
  3534. ch !== -1 &&
  3535. ch !== 0x24 /* $ */ &&
  3536. !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
  3537. ch !== 0x2E /* . */ &&
  3538. ch !== 0x3F /* ? */ &&
  3539. ch !== 0x5B /* [ */ &&
  3540. ch !== 0x5E /* ^ */ &&
  3541. ch !== 0x7C /* | */
  3542. ) {
  3543. state.advance();
  3544. return true
  3545. }
  3546. return false
  3547. };
  3548. // GroupSpecifier[U] ::
  3549. // [empty]
  3550. // `?` GroupName[?U]
  3551. pp$9.regexp_groupSpecifier = function(state) {
  3552. if (state.eat(0x3F /* ? */)) {
  3553. if (this.regexp_eatGroupName(state)) {
  3554. if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
  3555. state.raise("Duplicate capture group name");
  3556. }
  3557. state.groupNames.push(state.lastStringValue);
  3558. return
  3559. }
  3560. state.raise("Invalid group");
  3561. }
  3562. };
  3563. // GroupName[U] ::
  3564. // `<` RegExpIdentifierName[?U] `>`
  3565. // Note: this updates `state.lastStringValue` property with the eaten name.
  3566. pp$9.regexp_eatGroupName = function(state) {
  3567. state.lastStringValue = "";
  3568. if (state.eat(0x3C /* < */)) {
  3569. if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
  3570. return true
  3571. }
  3572. state.raise("Invalid capture group name");
  3573. }
  3574. return false
  3575. };
  3576. // RegExpIdentifierName[U] ::
  3577. // RegExpIdentifierStart[?U]
  3578. // RegExpIdentifierName[?U] RegExpIdentifierPart[?U]
  3579. // Note: this updates `state.lastStringValue` property with the eaten name.
  3580. pp$9.regexp_eatRegExpIdentifierName = function(state) {
  3581. state.lastStringValue = "";
  3582. if (this.regexp_eatRegExpIdentifierStart(state)) {
  3583. state.lastStringValue += codePointToString$1(state.lastIntValue);
  3584. while (this.regexp_eatRegExpIdentifierPart(state)) {
  3585. state.lastStringValue += codePointToString$1(state.lastIntValue);
  3586. }
  3587. return true
  3588. }
  3589. return false
  3590. };
  3591. // RegExpIdentifierStart[U] ::
  3592. // UnicodeIDStart
  3593. // `$`
  3594. // `_`
  3595. // `\` RegExpUnicodeEscapeSequence[?U]
  3596. pp$9.regexp_eatRegExpIdentifierStart = function(state) {
  3597. var start = state.pos;
  3598. var ch = state.current();
  3599. state.advance();
  3600. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
  3601. ch = state.lastIntValue;
  3602. }
  3603. if (isRegExpIdentifierStart(ch)) {
  3604. state.lastIntValue = ch;
  3605. return true
  3606. }
  3607. state.pos = start;
  3608. return false
  3609. };
  3610. function isRegExpIdentifierStart(ch) {
  3611. return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
  3612. }
  3613. // RegExpIdentifierPart[U] ::
  3614. // UnicodeIDContinue
  3615. // `$`
  3616. // `_`
  3617. // `\` RegExpUnicodeEscapeSequence[?U]
  3618. // <ZWNJ>
  3619. // <ZWJ>
  3620. pp$9.regexp_eatRegExpIdentifierPart = function(state) {
  3621. var start = state.pos;
  3622. var ch = state.current();
  3623. state.advance();
  3624. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
  3625. ch = state.lastIntValue;
  3626. }
  3627. if (isRegExpIdentifierPart(ch)) {
  3628. state.lastIntValue = ch;
  3629. return true
  3630. }
  3631. state.pos = start;
  3632. return false
  3633. };
  3634. function isRegExpIdentifierPart(ch) {
  3635. return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
  3636. }
  3637. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
  3638. pp$9.regexp_eatAtomEscape = function(state) {
  3639. if (
  3640. this.regexp_eatBackReference(state) ||
  3641. this.regexp_eatCharacterClassEscape(state) ||
  3642. this.regexp_eatCharacterEscape(state) ||
  3643. (state.switchN && this.regexp_eatKGroupName(state))
  3644. ) {
  3645. return true
  3646. }
  3647. if (state.switchU) {
  3648. // Make the same message as V8.
  3649. if (state.current() === 0x63 /* c */) {
  3650. state.raise("Invalid unicode escape");
  3651. }
  3652. state.raise("Invalid escape");
  3653. }
  3654. return false
  3655. };
  3656. pp$9.regexp_eatBackReference = function(state) {
  3657. var start = state.pos;
  3658. if (this.regexp_eatDecimalEscape(state)) {
  3659. var n = state.lastIntValue;
  3660. if (state.switchU) {
  3661. // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
  3662. if (n > state.maxBackReference) {
  3663. state.maxBackReference = n;
  3664. }
  3665. return true
  3666. }
  3667. if (n <= state.numCapturingParens) {
  3668. return true
  3669. }
  3670. state.pos = start;
  3671. }
  3672. return false
  3673. };
  3674. pp$9.regexp_eatKGroupName = function(state) {
  3675. if (state.eat(0x6B /* k */)) {
  3676. if (this.regexp_eatGroupName(state)) {
  3677. state.backReferenceNames.push(state.lastStringValue);
  3678. return true
  3679. }
  3680. state.raise("Invalid named reference");
  3681. }
  3682. return false
  3683. };
  3684. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
  3685. pp$9.regexp_eatCharacterEscape = function(state) {
  3686. return (
  3687. this.regexp_eatControlEscape(state) ||
  3688. this.regexp_eatCControlLetter(state) ||
  3689. this.regexp_eatZero(state) ||
  3690. this.regexp_eatHexEscapeSequence(state) ||
  3691. this.regexp_eatRegExpUnicodeEscapeSequence(state) ||
  3692. (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
  3693. this.regexp_eatIdentityEscape(state)
  3694. )
  3695. };
  3696. pp$9.regexp_eatCControlLetter = function(state) {
  3697. var start = state.pos;
  3698. if (state.eat(0x63 /* c */)) {
  3699. if (this.regexp_eatControlLetter(state)) {
  3700. return true
  3701. }
  3702. state.pos = start;
  3703. }
  3704. return false
  3705. };
  3706. pp$9.regexp_eatZero = function(state) {
  3707. if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
  3708. state.lastIntValue = 0;
  3709. state.advance();
  3710. return true
  3711. }
  3712. return false
  3713. };
  3714. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
  3715. pp$9.regexp_eatControlEscape = function(state) {
  3716. var ch = state.current();
  3717. if (ch === 0x74 /* t */) {
  3718. state.lastIntValue = 0x09; /* \t */
  3719. state.advance();
  3720. return true
  3721. }
  3722. if (ch === 0x6E /* n */) {
  3723. state.lastIntValue = 0x0A; /* \n */
  3724. state.advance();
  3725. return true
  3726. }
  3727. if (ch === 0x76 /* v */) {
  3728. state.lastIntValue = 0x0B; /* \v */
  3729. state.advance();
  3730. return true
  3731. }
  3732. if (ch === 0x66 /* f */) {
  3733. state.lastIntValue = 0x0C; /* \f */
  3734. state.advance();
  3735. return true
  3736. }
  3737. if (ch === 0x72 /* r */) {
  3738. state.lastIntValue = 0x0D; /* \r */
  3739. state.advance();
  3740. return true
  3741. }
  3742. return false
  3743. };
  3744. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
  3745. pp$9.regexp_eatControlLetter = function(state) {
  3746. var ch = state.current();
  3747. if (isControlLetter(ch)) {
  3748. state.lastIntValue = ch % 0x20;
  3749. state.advance();
  3750. return true
  3751. }
  3752. return false
  3753. };
  3754. function isControlLetter(ch) {
  3755. return (
  3756. (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
  3757. (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
  3758. )
  3759. }
  3760. // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
  3761. pp$9.regexp_eatRegExpUnicodeEscapeSequence = function(state) {
  3762. var start = state.pos;
  3763. if (state.eat(0x75 /* u */)) {
  3764. if (this.regexp_eatFixedHexDigits(state, 4)) {
  3765. var lead = state.lastIntValue;
  3766. if (state.switchU && lead >= 0xD800 && lead <= 0xDBFF) {
  3767. var leadSurrogateEnd = state.pos;
  3768. if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
  3769. var trail = state.lastIntValue;
  3770. if (trail >= 0xDC00 && trail <= 0xDFFF) {
  3771. state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  3772. return true
  3773. }
  3774. }
  3775. state.pos = leadSurrogateEnd;
  3776. state.lastIntValue = lead;
  3777. }
  3778. return true
  3779. }
  3780. if (
  3781. state.switchU &&
  3782. state.eat(0x7B /* { */) &&
  3783. this.regexp_eatHexDigits(state) &&
  3784. state.eat(0x7D /* } */) &&
  3785. isValidUnicode(state.lastIntValue)
  3786. ) {
  3787. return true
  3788. }
  3789. if (state.switchU) {
  3790. state.raise("Invalid unicode escape");
  3791. }
  3792. state.pos = start;
  3793. }
  3794. return false
  3795. };
  3796. function isValidUnicode(ch) {
  3797. return ch >= 0 && ch <= 0x10FFFF
  3798. }
  3799. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
  3800. pp$9.regexp_eatIdentityEscape = function(state) {
  3801. if (state.switchU) {
  3802. if (this.regexp_eatSyntaxCharacter(state)) {
  3803. return true
  3804. }
  3805. if (state.eat(0x2F /* / */)) {
  3806. state.lastIntValue = 0x2F; /* / */
  3807. return true
  3808. }
  3809. return false
  3810. }
  3811. var ch = state.current();
  3812. if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
  3813. state.lastIntValue = ch;
  3814. state.advance();
  3815. return true
  3816. }
  3817. return false
  3818. };
  3819. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
  3820. pp$9.regexp_eatDecimalEscape = function(state) {
  3821. state.lastIntValue = 0;
  3822. var ch = state.current();
  3823. if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
  3824. do {
  3825. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3826. state.advance();
  3827. } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
  3828. return true
  3829. }
  3830. return false
  3831. };
  3832. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
  3833. pp$9.regexp_eatCharacterClassEscape = function(state) {
  3834. var ch = state.current();
  3835. if (isCharacterClassEscape(ch)) {
  3836. state.lastIntValue = -1;
  3837. state.advance();
  3838. return true
  3839. }
  3840. if (
  3841. state.switchU &&
  3842. this.options.ecmaVersion >= 9 &&
  3843. (ch === 0x50 /* P */ || ch === 0x70 /* p */)
  3844. ) {
  3845. state.lastIntValue = -1;
  3846. state.advance();
  3847. if (
  3848. state.eat(0x7B /* { */) &&
  3849. this.regexp_eatUnicodePropertyValueExpression(state) &&
  3850. state.eat(0x7D /* } */)
  3851. ) {
  3852. return true
  3853. }
  3854. state.raise("Invalid property name");
  3855. }
  3856. return false
  3857. };
  3858. function isCharacterClassEscape(ch) {
  3859. return (
  3860. ch === 0x64 /* d */ ||
  3861. ch === 0x44 /* D */ ||
  3862. ch === 0x73 /* s */ ||
  3863. ch === 0x53 /* S */ ||
  3864. ch === 0x77 /* w */ ||
  3865. ch === 0x57 /* W */
  3866. )
  3867. }
  3868. // UnicodePropertyValueExpression ::
  3869. // UnicodePropertyName `=` UnicodePropertyValue
  3870. // LoneUnicodePropertyNameOrValue
  3871. pp$9.regexp_eatUnicodePropertyValueExpression = function(state) {
  3872. var start = state.pos;
  3873. // UnicodePropertyName `=` UnicodePropertyValue
  3874. if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
  3875. var name = state.lastStringValue;
  3876. if (this.regexp_eatUnicodePropertyValue(state)) {
  3877. var value = state.lastStringValue;
  3878. this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
  3879. return true
  3880. }
  3881. }
  3882. state.pos = start;
  3883. // LoneUnicodePropertyNameOrValue
  3884. if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
  3885. var nameOrValue = state.lastStringValue;
  3886. this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
  3887. return true
  3888. }
  3889. return false
  3890. };
  3891. pp$9.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
  3892. if (!data.hasOwnProperty(name) || data[name].indexOf(value) === -1) {
  3893. state.raise("Invalid property name");
  3894. }
  3895. };
  3896. pp$9.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
  3897. if (data.$LONE.indexOf(nameOrValue) === -1) {
  3898. state.raise("Invalid property name");
  3899. }
  3900. };
  3901. // UnicodePropertyName ::
  3902. // UnicodePropertyNameCharacters
  3903. pp$9.regexp_eatUnicodePropertyName = function(state) {
  3904. var ch = 0;
  3905. state.lastStringValue = "";
  3906. while (isUnicodePropertyNameCharacter(ch = state.current())) {
  3907. state.lastStringValue += codePointToString$1(ch);
  3908. state.advance();
  3909. }
  3910. return state.lastStringValue !== ""
  3911. };
  3912. function isUnicodePropertyNameCharacter(ch) {
  3913. return isControlLetter(ch) || ch === 0x5F /* _ */
  3914. }
  3915. // UnicodePropertyValue ::
  3916. // UnicodePropertyValueCharacters
  3917. pp$9.regexp_eatUnicodePropertyValue = function(state) {
  3918. var ch = 0;
  3919. state.lastStringValue = "";
  3920. while (isUnicodePropertyValueCharacter(ch = state.current())) {
  3921. state.lastStringValue += codePointToString$1(ch);
  3922. state.advance();
  3923. }
  3924. return state.lastStringValue !== ""
  3925. };
  3926. function isUnicodePropertyValueCharacter(ch) {
  3927. return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
  3928. }
  3929. // LoneUnicodePropertyNameOrValue ::
  3930. // UnicodePropertyValueCharacters
  3931. pp$9.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
  3932. return this.regexp_eatUnicodePropertyValue(state)
  3933. };
  3934. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
  3935. pp$9.regexp_eatCharacterClass = function(state) {
  3936. if (state.eat(0x5B /* [ */)) {
  3937. state.eat(0x5E /* ^ */);
  3938. this.regexp_classRanges(state);
  3939. if (state.eat(0x5D /* [ */)) {
  3940. return true
  3941. }
  3942. // Unreachable since it threw "unterminated regular expression" error before.
  3943. state.raise("Unterminated character class");
  3944. }
  3945. return false
  3946. };
  3947. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
  3948. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
  3949. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
  3950. pp$9.regexp_classRanges = function(state) {
  3951. var this$1 = this;
  3952. while (this.regexp_eatClassAtom(state)) {
  3953. var left = state.lastIntValue;
  3954. if (state.eat(0x2D /* - */) && this$1.regexp_eatClassAtom(state)) {
  3955. var right = state.lastIntValue;
  3956. if (state.switchU && (left === -1 || right === -1)) {
  3957. state.raise("Invalid character class");
  3958. }
  3959. if (left !== -1 && right !== -1 && left > right) {
  3960. state.raise("Range out of order in character class");
  3961. }
  3962. }
  3963. }
  3964. };
  3965. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
  3966. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
  3967. pp$9.regexp_eatClassAtom = function(state) {
  3968. var start = state.pos;
  3969. if (state.eat(0x5C /* \ */)) {
  3970. if (this.regexp_eatClassEscape(state)) {
  3971. return true
  3972. }
  3973. if (state.switchU) {
  3974. // Make the same message as V8.
  3975. var ch$1 = state.current();
  3976. if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
  3977. state.raise("Invalid class escape");
  3978. }
  3979. state.raise("Invalid escape");
  3980. }
  3981. state.pos = start;
  3982. }
  3983. var ch = state.current();
  3984. if (ch !== 0x5D /* [ */) {
  3985. state.lastIntValue = ch;
  3986. state.advance();
  3987. return true
  3988. }
  3989. return false
  3990. };
  3991. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
  3992. pp$9.regexp_eatClassEscape = function(state) {
  3993. var start = state.pos;
  3994. if (state.eat(0x62 /* b */)) {
  3995. state.lastIntValue = 0x08; /* <BS> */
  3996. return true
  3997. }
  3998. if (state.switchU && state.eat(0x2D /* - */)) {
  3999. state.lastIntValue = 0x2D; /* - */
  4000. return true
  4001. }
  4002. if (!state.switchU && state.eat(0x63 /* c */)) {
  4003. if (this.regexp_eatClassControlLetter(state)) {
  4004. return true
  4005. }
  4006. state.pos = start;
  4007. }
  4008. return (
  4009. this.regexp_eatCharacterClassEscape(state) ||
  4010. this.regexp_eatCharacterEscape(state)
  4011. )
  4012. };
  4013. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
  4014. pp$9.regexp_eatClassControlLetter = function(state) {
  4015. var ch = state.current();
  4016. if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
  4017. state.lastIntValue = ch % 0x20;
  4018. state.advance();
  4019. return true
  4020. }
  4021. return false
  4022. };
  4023. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4024. pp$9.regexp_eatHexEscapeSequence = function(state) {
  4025. var start = state.pos;
  4026. if (state.eat(0x78 /* x */)) {
  4027. if (this.regexp_eatFixedHexDigits(state, 2)) {
  4028. return true
  4029. }
  4030. if (state.switchU) {
  4031. state.raise("Invalid escape");
  4032. }
  4033. state.pos = start;
  4034. }
  4035. return false
  4036. };
  4037. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
  4038. pp$9.regexp_eatDecimalDigits = function(state) {
  4039. var start = state.pos;
  4040. var ch = 0;
  4041. state.lastIntValue = 0;
  4042. while (isDecimalDigit(ch = state.current())) {
  4043. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  4044. state.advance();
  4045. }
  4046. return state.pos !== start
  4047. };
  4048. function isDecimalDigit(ch) {
  4049. return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
  4050. }
  4051. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
  4052. pp$9.regexp_eatHexDigits = function(state) {
  4053. var start = state.pos;
  4054. var ch = 0;
  4055. state.lastIntValue = 0;
  4056. while (isHexDigit(ch = state.current())) {
  4057. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4058. state.advance();
  4059. }
  4060. return state.pos !== start
  4061. };
  4062. function isHexDigit(ch) {
  4063. return (
  4064. (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
  4065. (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
  4066. (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
  4067. )
  4068. }
  4069. function hexToInt(ch) {
  4070. if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
  4071. return 10 + (ch - 0x41 /* A */)
  4072. }
  4073. if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
  4074. return 10 + (ch - 0x61 /* a */)
  4075. }
  4076. return ch - 0x30 /* 0 */
  4077. }
  4078. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
  4079. // Allows only 0-377(octal) i.e. 0-255(decimal).
  4080. pp$9.regexp_eatLegacyOctalEscapeSequence = function(state) {
  4081. if (this.regexp_eatOctalDigit(state)) {
  4082. var n1 = state.lastIntValue;
  4083. if (this.regexp_eatOctalDigit(state)) {
  4084. var n2 = state.lastIntValue;
  4085. if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
  4086. state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
  4087. } else {
  4088. state.lastIntValue = n1 * 8 + n2;
  4089. }
  4090. } else {
  4091. state.lastIntValue = n1;
  4092. }
  4093. return true
  4094. }
  4095. return false
  4096. };
  4097. // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
  4098. pp$9.regexp_eatOctalDigit = function(state) {
  4099. var ch = state.current();
  4100. if (isOctalDigit(ch)) {
  4101. state.lastIntValue = ch - 0x30; /* 0 */
  4102. state.advance();
  4103. return true
  4104. }
  4105. state.lastIntValue = 0;
  4106. return false
  4107. };
  4108. function isOctalDigit(ch) {
  4109. return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
  4110. }
  4111. // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
  4112. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
  4113. // And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4114. pp$9.regexp_eatFixedHexDigits = function(state, length) {
  4115. var start = state.pos;
  4116. state.lastIntValue = 0;
  4117. for (var i = 0; i < length; ++i) {
  4118. var ch = state.current();
  4119. if (!isHexDigit(ch)) {
  4120. state.pos = start;
  4121. return false
  4122. }
  4123. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4124. state.advance();
  4125. }
  4126. return true
  4127. };
  4128. // Object type used to represent tokens. Note that normally, tokens
  4129. // simply exist as properties on the parser object. This is only
  4130. // used for the onToken callback and the external tokenizer.
  4131. var Token = function Token(p) {
  4132. this.type = p.type;
  4133. this.value = p.value;
  4134. this.start = p.start;
  4135. this.end = p.end;
  4136. if (p.options.locations)
  4137. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  4138. if (p.options.ranges)
  4139. { this.range = [p.start, p.end]; }
  4140. };
  4141. // ## Tokenizer
  4142. var pp$8 = Parser.prototype;
  4143. // Move to the next token
  4144. pp$8.next = function() {
  4145. if (this.options.onToken)
  4146. { this.options.onToken(new Token(this)); }
  4147. this.lastTokEnd = this.end;
  4148. this.lastTokStart = this.start;
  4149. this.lastTokEndLoc = this.endLoc;
  4150. this.lastTokStartLoc = this.startLoc;
  4151. this.nextToken();
  4152. };
  4153. pp$8.getToken = function() {
  4154. this.next();
  4155. return new Token(this)
  4156. };
  4157. // If we're in an ES6 environment, make parsers iterable
  4158. if (typeof Symbol !== "undefined")
  4159. { pp$8[Symbol.iterator] = function() {
  4160. var this$1 = this;
  4161. return {
  4162. next: function () {
  4163. var token = this$1.getToken();
  4164. return {
  4165. done: token.type === types.eof,
  4166. value: token
  4167. }
  4168. }
  4169. }
  4170. }; }
  4171. // Toggle strict mode. Re-reads the next number or string to please
  4172. // pedantic tests (`"use strict"; 010;` should fail).
  4173. pp$8.curContext = function() {
  4174. return this.context[this.context.length - 1]
  4175. };
  4176. // Read a single token, updating the parser object's token-related
  4177. // properties.
  4178. pp$8.nextToken = function() {
  4179. var curContext = this.curContext();
  4180. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  4181. this.start = this.pos;
  4182. if (this.options.locations) { this.startLoc = this.curPosition(); }
  4183. if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
  4184. if (curContext.override) { return curContext.override(this) }
  4185. else { this.readToken(this.fullCharCodeAtPos()); }
  4186. };
  4187. pp$8.readToken = function(code) {
  4188. // Identifier or keyword. '\uXXXX' sequences are allowed in
  4189. // identifiers, so '\' also dispatches to that.
  4190. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  4191. { return this.readWord() }
  4192. return this.getTokenFromCode(code)
  4193. };
  4194. pp$8.fullCharCodeAtPos = function() {
  4195. var code = this.input.charCodeAt(this.pos);
  4196. if (code <= 0xd7ff || code >= 0xe000) { return code }
  4197. var next = this.input.charCodeAt(this.pos + 1);
  4198. return (code << 10) + next - 0x35fdc00
  4199. };
  4200. pp$8.skipBlockComment = function() {
  4201. var this$1 = this;
  4202. var startLoc = this.options.onComment && this.curPosition();
  4203. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  4204. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  4205. this.pos = end + 2;
  4206. if (this.options.locations) {
  4207. lineBreakG.lastIndex = start;
  4208. var match;
  4209. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  4210. ++this$1.curLine;
  4211. this$1.lineStart = match.index + match[0].length;
  4212. }
  4213. }
  4214. if (this.options.onComment)
  4215. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  4216. startLoc, this.curPosition()); }
  4217. };
  4218. pp$8.skipLineComment = function(startSkip) {
  4219. var this$1 = this;
  4220. var start = this.pos;
  4221. var startLoc = this.options.onComment && this.curPosition();
  4222. var ch = this.input.charCodeAt(this.pos += startSkip);
  4223. while (this.pos < this.input.length && !isNewLine(ch)) {
  4224. ch = this$1.input.charCodeAt(++this$1.pos);
  4225. }
  4226. if (this.options.onComment)
  4227. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  4228. startLoc, this.curPosition()); }
  4229. };
  4230. // Called at the start of the parse and after every token. Skips
  4231. // whitespace and comments, and.
  4232. pp$8.skipSpace = function() {
  4233. var this$1 = this;
  4234. loop: while (this.pos < this.input.length) {
  4235. var ch = this$1.input.charCodeAt(this$1.pos);
  4236. switch (ch) {
  4237. case 32: case 160: // ' '
  4238. ++this$1.pos;
  4239. break
  4240. case 13:
  4241. if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
  4242. ++this$1.pos;
  4243. }
  4244. case 10: case 8232: case 8233:
  4245. ++this$1.pos;
  4246. if (this$1.options.locations) {
  4247. ++this$1.curLine;
  4248. this$1.lineStart = this$1.pos;
  4249. }
  4250. break
  4251. case 47: // '/'
  4252. switch (this$1.input.charCodeAt(this$1.pos + 1)) {
  4253. case 42: // '*'
  4254. this$1.skipBlockComment();
  4255. break
  4256. case 47:
  4257. this$1.skipLineComment(2);
  4258. break
  4259. default:
  4260. break loop
  4261. }
  4262. break
  4263. default:
  4264. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  4265. ++this$1.pos;
  4266. } else {
  4267. break loop
  4268. }
  4269. }
  4270. }
  4271. };
  4272. // Called at the end of every token. Sets `end`, `val`, and
  4273. // maintains `context` and `exprAllowed`, and skips the space after
  4274. // the token, so that the next one's `start` will point at the
  4275. // right position.
  4276. pp$8.finishToken = function(type, val) {
  4277. this.end = this.pos;
  4278. if (this.options.locations) { this.endLoc = this.curPosition(); }
  4279. var prevType = this.type;
  4280. this.type = type;
  4281. this.value = val;
  4282. this.updateContext(prevType);
  4283. };
  4284. // ### Token reading
  4285. // This is the function that is called to fetch the next token. It
  4286. // is somewhat obscure, because it works in character codes rather
  4287. // than characters, and because operator parsing has been inlined
  4288. // into it.
  4289. //
  4290. // All in the name of speed.
  4291. //
  4292. pp$8.readToken_dot = function() {
  4293. var next = this.input.charCodeAt(this.pos + 1);
  4294. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  4295. var next2 = this.input.charCodeAt(this.pos + 2);
  4296. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  4297. this.pos += 3;
  4298. return this.finishToken(types.ellipsis)
  4299. } else {
  4300. ++this.pos;
  4301. return this.finishToken(types.dot)
  4302. }
  4303. };
  4304. pp$8.readToken_slash = function() { // '/'
  4305. var next = this.input.charCodeAt(this.pos + 1);
  4306. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  4307. if (next === 61) { return this.finishOp(types.assign, 2) }
  4308. return this.finishOp(types.slash, 1)
  4309. };
  4310. pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
  4311. var next = this.input.charCodeAt(this.pos + 1);
  4312. var size = 1;
  4313. var tokentype = code === 42 ? types.star : types.modulo;
  4314. // exponentiation operator ** and **=
  4315. if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
  4316. ++size;
  4317. tokentype = types.starstar;
  4318. next = this.input.charCodeAt(this.pos + 2);
  4319. }
  4320. if (next === 61) { return this.finishOp(types.assign, size + 1) }
  4321. return this.finishOp(tokentype, size)
  4322. };
  4323. pp$8.readToken_pipe_amp = function(code) { // '|&'
  4324. var next = this.input.charCodeAt(this.pos + 1);
  4325. if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
  4326. if (next === 61) { return this.finishOp(types.assign, 2) }
  4327. return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
  4328. };
  4329. pp$8.readToken_caret = function() { // '^'
  4330. var next = this.input.charCodeAt(this.pos + 1);
  4331. if (next === 61) { return this.finishOp(types.assign, 2) }
  4332. return this.finishOp(types.bitwiseXOR, 1)
  4333. };
  4334. pp$8.readToken_plus_min = function(code) { // '+-'
  4335. var next = this.input.charCodeAt(this.pos + 1);
  4336. if (next === code) {
  4337. if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
  4338. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  4339. // A `-->` line comment
  4340. this.skipLineComment(3);
  4341. this.skipSpace();
  4342. return this.nextToken()
  4343. }
  4344. return this.finishOp(types.incDec, 2)
  4345. }
  4346. if (next === 61) { return this.finishOp(types.assign, 2) }
  4347. return this.finishOp(types.plusMin, 1)
  4348. };
  4349. pp$8.readToken_lt_gt = function(code) { // '<>'
  4350. var next = this.input.charCodeAt(this.pos + 1);
  4351. var size = 1;
  4352. if (next === code) {
  4353. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  4354. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
  4355. return this.finishOp(types.bitShift, size)
  4356. }
  4357. if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
  4358. this.input.charCodeAt(this.pos + 3) === 45) {
  4359. // `<!--`, an XML-style comment that should be interpreted as a line comment
  4360. this.skipLineComment(4);
  4361. this.skipSpace();
  4362. return this.nextToken()
  4363. }
  4364. if (next === 61) { size = 2; }
  4365. return this.finishOp(types.relational, size)
  4366. };
  4367. pp$8.readToken_eq_excl = function(code) { // '=!'
  4368. var next = this.input.charCodeAt(this.pos + 1);
  4369. if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  4370. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  4371. this.pos += 2;
  4372. return this.finishToken(types.arrow)
  4373. }
  4374. return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
  4375. };
  4376. pp$8.getTokenFromCode = function(code) {
  4377. switch (code) {
  4378. // The interpretation of a dot depends on whether it is followed
  4379. // by a digit or another two dots.
  4380. case 46: // '.'
  4381. return this.readToken_dot()
  4382. // Punctuation tokens.
  4383. case 40: ++this.pos; return this.finishToken(types.parenL)
  4384. case 41: ++this.pos; return this.finishToken(types.parenR)
  4385. case 59: ++this.pos; return this.finishToken(types.semi)
  4386. case 44: ++this.pos; return this.finishToken(types.comma)
  4387. case 91: ++this.pos; return this.finishToken(types.bracketL)
  4388. case 93: ++this.pos; return this.finishToken(types.bracketR)
  4389. case 123: ++this.pos; return this.finishToken(types.braceL)
  4390. case 125: ++this.pos; return this.finishToken(types.braceR)
  4391. case 58: ++this.pos; return this.finishToken(types.colon)
  4392. case 63: ++this.pos; return this.finishToken(types.question)
  4393. case 96: // '`'
  4394. if (this.options.ecmaVersion < 6) { break }
  4395. ++this.pos;
  4396. return this.finishToken(types.backQuote)
  4397. case 48: // '0'
  4398. var next = this.input.charCodeAt(this.pos + 1);
  4399. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  4400. if (this.options.ecmaVersion >= 6) {
  4401. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  4402. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  4403. }
  4404. // Anything else beginning with a digit is an integer, octal
  4405. // number, or float.
  4406. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  4407. return this.readNumber(false)
  4408. // Quotes produce strings.
  4409. case 34: case 39: // '"', "'"
  4410. return this.readString(code)
  4411. // Operators are parsed inline in tiny state machines. '=' (61) is
  4412. // often referred to. `finishOp` simply skips the amount of
  4413. // characters it is given as second argument, and returns a token
  4414. // of the type given by its first argument.
  4415. case 47: // '/'
  4416. return this.readToken_slash()
  4417. case 37: case 42: // '%*'
  4418. return this.readToken_mult_modulo_exp(code)
  4419. case 124: case 38: // '|&'
  4420. return this.readToken_pipe_amp(code)
  4421. case 94: // '^'
  4422. return this.readToken_caret()
  4423. case 43: case 45: // '+-'
  4424. return this.readToken_plus_min(code)
  4425. case 60: case 62: // '<>'
  4426. return this.readToken_lt_gt(code)
  4427. case 61: case 33: // '=!'
  4428. return this.readToken_eq_excl(code)
  4429. case 126: // '~'
  4430. return this.finishOp(types.prefix, 1)
  4431. }
  4432. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  4433. };
  4434. pp$8.finishOp = function(type, size) {
  4435. var str = this.input.slice(this.pos, this.pos + size);
  4436. this.pos += size;
  4437. return this.finishToken(type, str)
  4438. };
  4439. pp$8.readRegexp = function() {
  4440. var this$1 = this;
  4441. var escaped, inClass, start = this.pos;
  4442. for (;;) {
  4443. if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
  4444. var ch = this$1.input.charAt(this$1.pos);
  4445. if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
  4446. if (!escaped) {
  4447. if (ch === "[") { inClass = true; }
  4448. else if (ch === "]" && inClass) { inClass = false; }
  4449. else if (ch === "/" && !inClass) { break }
  4450. escaped = ch === "\\";
  4451. } else { escaped = false; }
  4452. ++this$1.pos;
  4453. }
  4454. var pattern = this.input.slice(start, this.pos);
  4455. ++this.pos;
  4456. var flagsStart = this.pos;
  4457. var flags = this.readWord1();
  4458. if (this.containsEsc) { this.unexpected(flagsStart); }
  4459. // Validate pattern
  4460. var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
  4461. state.reset(start, pattern, flags);
  4462. this.validateRegExpFlags(state);
  4463. this.validateRegExpPattern(state);
  4464. // Create Literal#value property value.
  4465. var value = null;
  4466. try {
  4467. value = new RegExp(pattern, flags);
  4468. } catch (e) {
  4469. // ESTree requires null if it failed to instantiate RegExp object.
  4470. // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
  4471. }
  4472. return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
  4473. };
  4474. // Read an integer in the given radix. Return null if zero digits
  4475. // were read, the integer value otherwise. When `len` is given, this
  4476. // will return `null` unless the integer has exactly `len` digits.
  4477. pp$8.readInt = function(radix, len) {
  4478. var this$1 = this;
  4479. var start = this.pos, total = 0;
  4480. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  4481. var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
  4482. if (code >= 97) { val = code - 97 + 10; } // a
  4483. else if (code >= 65) { val = code - 65 + 10; } // A
  4484. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  4485. else { val = Infinity; }
  4486. if (val >= radix) { break }
  4487. ++this$1.pos;
  4488. total = total * radix + val;
  4489. }
  4490. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  4491. return total
  4492. };
  4493. pp$8.readRadixNumber = function(radix) {
  4494. this.pos += 2; // 0x
  4495. var val = this.readInt(radix);
  4496. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  4497. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4498. return this.finishToken(types.num, val)
  4499. };
  4500. // Read an integer, octal integer, or floating-point number.
  4501. pp$8.readNumber = function(startsWithDot) {
  4502. var start = this.pos;
  4503. if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4504. var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  4505. if (octal && this.strict) { this.raise(start, "Invalid number"); }
  4506. if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
  4507. var next = this.input.charCodeAt(this.pos);
  4508. if (next === 46 && !octal) { // '.'
  4509. ++this.pos;
  4510. this.readInt(10);
  4511. next = this.input.charCodeAt(this.pos);
  4512. }
  4513. if ((next === 69 || next === 101) && !octal) { // 'eE'
  4514. next = this.input.charCodeAt(++this.pos);
  4515. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  4516. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4517. }
  4518. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4519. var str = this.input.slice(start, this.pos);
  4520. var val = octal ? parseInt(str, 8) : parseFloat(str);
  4521. return this.finishToken(types.num, val)
  4522. };
  4523. // Read a string value, interpreting backslash-escapes.
  4524. pp$8.readCodePoint = function() {
  4525. var ch = this.input.charCodeAt(this.pos), code;
  4526. if (ch === 123) { // '{'
  4527. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  4528. var codePos = ++this.pos;
  4529. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  4530. ++this.pos;
  4531. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  4532. } else {
  4533. code = this.readHexChar(4);
  4534. }
  4535. return code
  4536. };
  4537. function codePointToString(code) {
  4538. // UTF-16 Decoding
  4539. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  4540. code -= 0x10000;
  4541. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  4542. }
  4543. pp$8.readString = function(quote) {
  4544. var this$1 = this;
  4545. var out = "", chunkStart = ++this.pos;
  4546. for (;;) {
  4547. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
  4548. var ch = this$1.input.charCodeAt(this$1.pos);
  4549. if (ch === quote) { break }
  4550. if (ch === 92) { // '\'
  4551. out += this$1.input.slice(chunkStart, this$1.pos);
  4552. out += this$1.readEscapedChar(false);
  4553. chunkStart = this$1.pos;
  4554. } else {
  4555. if (isNewLine(ch, this$1.options.ecmaVersion >= 10)) { this$1.raise(this$1.start, "Unterminated string constant"); }
  4556. ++this$1.pos;
  4557. }
  4558. }
  4559. out += this.input.slice(chunkStart, this.pos++);
  4560. return this.finishToken(types.string, out)
  4561. };
  4562. // Reads template string tokens.
  4563. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  4564. pp$8.tryReadTemplateToken = function() {
  4565. this.inTemplateElement = true;
  4566. try {
  4567. this.readTmplToken();
  4568. } catch (err) {
  4569. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  4570. this.readInvalidTemplateToken();
  4571. } else {
  4572. throw err
  4573. }
  4574. }
  4575. this.inTemplateElement = false;
  4576. };
  4577. pp$8.invalidStringToken = function(position, message) {
  4578. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  4579. throw INVALID_TEMPLATE_ESCAPE_ERROR
  4580. } else {
  4581. this.raise(position, message);
  4582. }
  4583. };
  4584. pp$8.readTmplToken = function() {
  4585. var this$1 = this;
  4586. var out = "", chunkStart = this.pos;
  4587. for (;;) {
  4588. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
  4589. var ch = this$1.input.charCodeAt(this$1.pos);
  4590. if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
  4591. if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
  4592. if (ch === 36) {
  4593. this$1.pos += 2;
  4594. return this$1.finishToken(types.dollarBraceL)
  4595. } else {
  4596. ++this$1.pos;
  4597. return this$1.finishToken(types.backQuote)
  4598. }
  4599. }
  4600. out += this$1.input.slice(chunkStart, this$1.pos);
  4601. return this$1.finishToken(types.template, out)
  4602. }
  4603. if (ch === 92) { // '\'
  4604. out += this$1.input.slice(chunkStart, this$1.pos);
  4605. out += this$1.readEscapedChar(true);
  4606. chunkStart = this$1.pos;
  4607. } else if (isNewLine(ch)) {
  4608. out += this$1.input.slice(chunkStart, this$1.pos);
  4609. ++this$1.pos;
  4610. switch (ch) {
  4611. case 13:
  4612. if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
  4613. case 10:
  4614. out += "\n";
  4615. break
  4616. default:
  4617. out += String.fromCharCode(ch);
  4618. break
  4619. }
  4620. if (this$1.options.locations) {
  4621. ++this$1.curLine;
  4622. this$1.lineStart = this$1.pos;
  4623. }
  4624. chunkStart = this$1.pos;
  4625. } else {
  4626. ++this$1.pos;
  4627. }
  4628. }
  4629. };
  4630. // Reads a template token to search for the end, without validating any escape sequences
  4631. pp$8.readInvalidTemplateToken = function() {
  4632. var this$1 = this;
  4633. for (; this.pos < this.input.length; this.pos++) {
  4634. switch (this$1.input[this$1.pos]) {
  4635. case "\\":
  4636. ++this$1.pos;
  4637. break
  4638. case "$":
  4639. if (this$1.input[this$1.pos + 1] !== "{") {
  4640. break
  4641. }
  4642. // falls through
  4643. case "`":
  4644. return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
  4645. // no default
  4646. }
  4647. }
  4648. this.raise(this.start, "Unterminated template");
  4649. };
  4650. // Used to read escaped characters
  4651. pp$8.readEscapedChar = function(inTemplate) {
  4652. var ch = this.input.charCodeAt(++this.pos);
  4653. ++this.pos;
  4654. switch (ch) {
  4655. case 110: return "\n" // 'n' -> '\n'
  4656. case 114: return "\r" // 'r' -> '\r'
  4657. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  4658. case 117: return codePointToString(this.readCodePoint()) // 'u'
  4659. case 116: return "\t" // 't' -> '\t'
  4660. case 98: return "\b" // 'b' -> '\b'
  4661. case 118: return "\u000b" // 'v' -> '\u000b'
  4662. case 102: return "\f" // 'f' -> '\f'
  4663. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  4664. case 10: // ' \n'
  4665. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  4666. return ""
  4667. default:
  4668. if (ch >= 48 && ch <= 55) {
  4669. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  4670. var octal = parseInt(octalStr, 8);
  4671. if (octal > 255) {
  4672. octalStr = octalStr.slice(0, -1);
  4673. octal = parseInt(octalStr, 8);
  4674. }
  4675. this.pos += octalStr.length - 1;
  4676. ch = this.input.charCodeAt(this.pos);
  4677. if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
  4678. this.invalidStringToken(
  4679. this.pos - 1 - octalStr.length,
  4680. inTemplate
  4681. ? "Octal literal in template string"
  4682. : "Octal literal in strict mode"
  4683. );
  4684. }
  4685. return String.fromCharCode(octal)
  4686. }
  4687. return String.fromCharCode(ch)
  4688. }
  4689. };
  4690. // Used to read character escape sequences ('\x', '\u', '\U').
  4691. pp$8.readHexChar = function(len) {
  4692. var codePos = this.pos;
  4693. var n = this.readInt(16, len);
  4694. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  4695. return n
  4696. };
  4697. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  4698. // to whether the word contained a '\u' escape.
  4699. //
  4700. // Incrementally adds only escaped chars, adding other chunks as-is
  4701. // as a micro-optimization.
  4702. pp$8.readWord1 = function() {
  4703. var this$1 = this;
  4704. this.containsEsc = false;
  4705. var word = "", first = true, chunkStart = this.pos;
  4706. var astral = this.options.ecmaVersion >= 6;
  4707. while (this.pos < this.input.length) {
  4708. var ch = this$1.fullCharCodeAtPos();
  4709. if (isIdentifierChar(ch, astral)) {
  4710. this$1.pos += ch <= 0xffff ? 1 : 2;
  4711. } else if (ch === 92) { // "\"
  4712. this$1.containsEsc = true;
  4713. word += this$1.input.slice(chunkStart, this$1.pos);
  4714. var escStart = this$1.pos;
  4715. if (this$1.input.charCodeAt(++this$1.pos) !== 117) // "u"
  4716. { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  4717. ++this$1.pos;
  4718. var esc = this$1.readCodePoint();
  4719. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  4720. { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
  4721. word += codePointToString(esc);
  4722. chunkStart = this$1.pos;
  4723. } else {
  4724. break
  4725. }
  4726. first = false;
  4727. }
  4728. return word + this.input.slice(chunkStart, this.pos)
  4729. };
  4730. // Read an identifier or keyword token. Will check for reserved
  4731. // words when necessary.
  4732. pp$8.readWord = function() {
  4733. var word = this.readWord1();
  4734. var type = types.name;
  4735. if (this.keywords.test(word)) {
  4736. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
  4737. type = keywords$1[word];
  4738. }
  4739. return this.finishToken(type, word)
  4740. };
  4741. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  4742. //
  4743. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  4744. // various contributors and released under an MIT license.
  4745. //
  4746. // Git repositories for Acorn are available at
  4747. //
  4748. // http://marijnhaverbeke.nl/git/acorn
  4749. // https://github.com/acornjs/acorn.git
  4750. //
  4751. // Please use the [github bug tracker][ghbt] to report issues.
  4752. //
  4753. // [ghbt]: https://github.com/acornjs/acorn/issues
  4754. //
  4755. // This file defines the main parser interface. The library also comes
  4756. // with a [error-tolerant parser][dammit] and an
  4757. // [abstract syntax tree walker][walk], defined in other files.
  4758. //
  4759. // [dammit]: acorn_loose.js
  4760. // [walk]: util/walk.js
  4761. var version = "5.7.3";
  4762. // The main exported interface (under `self.acorn` when in the
  4763. // browser) is a `parse` function that takes a code string and
  4764. // returns an abstract syntax tree as specified by [Mozilla parser
  4765. // API][api].
  4766. //
  4767. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  4768. function parse(input, options) {
  4769. return new Parser(options, input).parse()
  4770. }
  4771. // This function tries to parse a single expression at a given
  4772. // offset in a string. Useful for parsing mixed-language formats
  4773. // that embed JavaScript expressions.
  4774. function parseExpressionAt(input, pos, options) {
  4775. var p = new Parser(options, input, pos);
  4776. p.nextToken();
  4777. return p.parseExpression()
  4778. }
  4779. // Acorn is organized as a tokenizer and a recursive-descent parser.
  4780. // The `tokenizer` export provides an interface to the tokenizer.
  4781. function tokenizer(input, options) {
  4782. return new Parser(options, input)
  4783. }
  4784. // This is a terrible kludge to support the existing, pre-ES6
  4785. // interface where the loose parser module retroactively adds exports
  4786. // to this module.
  4787. var parse_dammit;
  4788. var LooseParser;
  4789. var pluginsLoose; // eslint-disable-line camelcase
  4790. function addLooseExports(parse, Parser$$1, plugins$$1) {
  4791. parse_dammit = parse; // eslint-disable-line camelcase
  4792. LooseParser = Parser$$1;
  4793. pluginsLoose = plugins$$1;
  4794. }
  4795. var acorn = /*#__PURE__*/Object.freeze({
  4796. version: version,
  4797. parse: parse,
  4798. parseExpressionAt: parseExpressionAt,
  4799. tokenizer: tokenizer,
  4800. get parse_dammit () { return parse_dammit; },
  4801. get LooseParser () { return LooseParser; },
  4802. get pluginsLoose () { return pluginsLoose; },
  4803. addLooseExports: addLooseExports,
  4804. Parser: Parser,
  4805. plugins: plugins,
  4806. defaultOptions: defaultOptions,
  4807. Position: Position,
  4808. SourceLocation: SourceLocation,
  4809. getLineInfo: getLineInfo,
  4810. Node: Node,
  4811. TokenType: TokenType,
  4812. tokTypes: types,
  4813. keywordTypes: keywords$1,
  4814. TokContext: TokContext,
  4815. tokContexts: types$1,
  4816. isIdentifierChar: isIdentifierChar,
  4817. isIdentifierStart: isIdentifierStart,
  4818. Token: Token,
  4819. isNewLine: isNewLine,
  4820. lineBreak: lineBreak,
  4821. lineBreakG: lineBreakG,
  4822. nonASCIIwhitespace: nonASCIIwhitespace
  4823. });
  4824. const literals = new Map([['true', true], ['false', false], ['null', null]]);
  4825. function readExpression(parser) {
  4826. const start = parser.index;
  4827. const name = parser.readUntil(/\s*}/);
  4828. if (name && /^[a-z]+$/.test(name)) {
  4829. const end = start + name.length;
  4830. if (literals.has(name)) {
  4831. return {
  4832. type: 'Literal',
  4833. start,
  4834. end,
  4835. value: literals.get(name),
  4836. raw: name,
  4837. };
  4838. }
  4839. return {
  4840. type: 'Identifier',
  4841. start,
  4842. end: start + name.length,
  4843. name,
  4844. };
  4845. }
  4846. parser.index = start;
  4847. try {
  4848. const node = parseExpressionAt(parser.template, parser.index, {
  4849. ecmaVersion: 9,
  4850. preserveParens: true,
  4851. plugins: {
  4852. dynamicImport: true
  4853. }
  4854. });
  4855. parser.index = node.end;
  4856. return node;
  4857. }
  4858. catch (err) {
  4859. parser.acornError(err);
  4860. }
  4861. }
  4862. /* eslint-disable no-underscore-dangle */
  4863. const DynamicImportKey = 'Import';
  4864. function injectDynamicImport(acorn) {
  4865. const tt = acorn.tokTypes;
  4866. // NOTE: This allows `yield import()` to parse correctly.
  4867. tt._import.startsExpr = true;
  4868. function parseDynamicImport() {
  4869. const node = this.startNode();
  4870. this.next();
  4871. if (this.type !== tt.parenL) {
  4872. this.unexpected();
  4873. }
  4874. return this.finishNode(node, DynamicImportKey);
  4875. }
  4876. function peekNext() {
  4877. return this.input[this.pos];
  4878. }
  4879. // eslint-disable-next-line no-param-reassign
  4880. acorn.plugins.dynamicImport = function dynamicImportPlugin(instance) {
  4881. instance.extend('parseStatement', nextMethod => (
  4882. function parseStatement(...args) {
  4883. const node = this.startNode();
  4884. if (this.type === tt._import) {
  4885. const nextToken = peekNext.call(this);
  4886. if (nextToken === tt.parenL.label) {
  4887. const expr = this.parseExpression();
  4888. return this.parseExpressionStatement(node, expr);
  4889. }
  4890. }
  4891. return nextMethod.apply(this, args);
  4892. }
  4893. ));
  4894. instance.extend('parseExprAtom', nextMethod => (
  4895. function parseExprAtom(refDestructuringErrors) {
  4896. if (this.type === tt._import) {
  4897. return parseDynamicImport.call(this);
  4898. }
  4899. return nextMethod.call(this, refDestructuringErrors);
  4900. }
  4901. ));
  4902. };
  4903. return acorn;
  4904. }
  4905. function repeat(str, i) {
  4906. let result = '';
  4907. while (i--)
  4908. result += str;
  4909. return result;
  4910. }
  4911. const scriptClosingTag = '</script>';
  4912. injectDynamicImport(acorn);
  4913. function readScript(parser, start, attributes) {
  4914. const scriptStart = parser.index;
  4915. const scriptEnd = parser.template.indexOf(scriptClosingTag, scriptStart);
  4916. if (scriptEnd === -1)
  4917. parser.error({
  4918. code: `unclosed-script`,
  4919. message: `<script> must have a closing tag`
  4920. });
  4921. const source = repeat(' ', scriptStart) + parser.template.slice(scriptStart, scriptEnd);
  4922. parser.index = scriptEnd + scriptClosingTag.length;
  4923. let ast;
  4924. try {
  4925. ast = parse(source, {
  4926. ecmaVersion: 9,
  4927. sourceType: 'module',
  4928. plugins: {
  4929. dynamicImport: true
  4930. }
  4931. });
  4932. }
  4933. catch (err) {
  4934. parser.acornError(err);
  4935. }
  4936. if (!ast.body.length)
  4937. return null;
  4938. ast.start = scriptStart;
  4939. return {
  4940. start,
  4941. end: parser.index,
  4942. attributes,
  4943. content: ast,
  4944. };
  4945. }
  4946. var MAX_LINE_LENGTH = 100;
  4947. var OFFSET_CORRECTION = 60;
  4948. var TAB_REPLACEMENT = ' ';
  4949. function sourceFragment(error, extraLines) {
  4950. function processLines(start, end) {
  4951. return lines.slice(start, end).map(function(line, idx) {
  4952. var num = String(start + idx + 1);
  4953. while (num.length < maxNumLength) {
  4954. num = ' ' + num;
  4955. }
  4956. return num + ' |' + line;
  4957. }).join('\n');
  4958. }
  4959. var lines = error.source.split(/\n|\r\n?|\f/);
  4960. var line = error.line;
  4961. var column = error.column;
  4962. var startLine = Math.max(1, line - extraLines) - 1;
  4963. var endLine = Math.min(line + extraLines, lines.length + 1);
  4964. var maxNumLength = Math.max(4, String(endLine).length) + 1;
  4965. var cutLeft = 0;
  4966. // correct column according to replaced tab before column
  4967. column += (TAB_REPLACEMENT.length - 1) * (lines[line - 1].substr(0, column - 1).match(/\t/g) || []).length;
  4968. if (column > MAX_LINE_LENGTH) {
  4969. cutLeft = column - OFFSET_CORRECTION + 3;
  4970. column = OFFSET_CORRECTION - 2;
  4971. }
  4972. for (var i = startLine; i <= endLine; i++) {
  4973. if (i >= 0 && i < lines.length) {
  4974. lines[i] = lines[i].replace(/\t/g, TAB_REPLACEMENT);
  4975. lines[i] =
  4976. (cutLeft > 0 && lines[i].length > cutLeft ? '\u2026' : '') +
  4977. lines[i].substr(cutLeft, MAX_LINE_LENGTH - 2) +
  4978. (lines[i].length > cutLeft + MAX_LINE_LENGTH - 1 ? '\u2026' : '');
  4979. }
  4980. }
  4981. return [
  4982. processLines(startLine, line),
  4983. new Array(column + maxNumLength + 2).join('-') + '^',
  4984. processLines(line, endLine)
  4985. ].join('\n');
  4986. }
  4987. var CssSyntaxError = function(message, source, offset, line, column) {
  4988. // some VMs prevent setting line/column otherwise (iOS Safari 10 even throw an exception)
  4989. var error = Object.create(SyntaxError.prototype);
  4990. error.name = 'CssSyntaxError';
  4991. error.message = message;
  4992. error.stack = (new Error().stack || '').replace(/^.+\n/, error.name + ': ' + error.message + '\n');
  4993. error.source = source;
  4994. error.offset = offset;
  4995. error.line = line;
  4996. error.column = column;
  4997. error.sourceFragment = function(extraLines) {
  4998. return sourceFragment(error, isNaN(extraLines) ? 0 : extraLines);
  4999. };
  5000. Object.defineProperty(error, 'formattedMessage', {
  5001. get: function() {
  5002. return (
  5003. 'Parse error: ' + error.message + '\n' +
  5004. sourceFragment(error, 2)
  5005. );
  5006. }
  5007. });
  5008. // for backward capability
  5009. error.parseError = {
  5010. offset: offset,
  5011. line: line,
  5012. column: column
  5013. };
  5014. return error;
  5015. };
  5016. var error = CssSyntaxError;
  5017. // token types (note: value shouldn't intersect with used char codes)
  5018. var WHITESPACE = 1;
  5019. var IDENTIFIER = 2;
  5020. var NUMBER = 3;
  5021. var STRING = 4;
  5022. var COMMENT = 5;
  5023. var PUNCTUATOR = 6;
  5024. var CDO = 7;
  5025. var CDC = 8;
  5026. var ATRULE = 14;
  5027. var FUNCTION = 15;
  5028. var URL = 16;
  5029. var RAW = 17;
  5030. var TAB = 9;
  5031. var N = 10;
  5032. var F = 12;
  5033. var R = 13;
  5034. var SPACE = 32;
  5035. var TYPE = {
  5036. WhiteSpace: WHITESPACE,
  5037. Identifier: IDENTIFIER,
  5038. Number: NUMBER,
  5039. String: STRING,
  5040. Comment: COMMENT,
  5041. Punctuator: PUNCTUATOR,
  5042. CDO: CDO,
  5043. CDC: CDC,
  5044. Atrule: ATRULE,
  5045. Function: FUNCTION,
  5046. Url: URL,
  5047. Raw: RAW,
  5048. ExclamationMark: 33, // !
  5049. QuotationMark: 34, // "
  5050. NumberSign: 35, // #
  5051. DollarSign: 36, // $
  5052. PercentSign: 37, // %
  5053. Ampersand: 38, // &
  5054. Apostrophe: 39, // '
  5055. LeftParenthesis: 40, // (
  5056. RightParenthesis: 41, // )
  5057. Asterisk: 42, // *
  5058. PlusSign: 43, // +
  5059. Comma: 44, // ,
  5060. HyphenMinus: 45, // -
  5061. FullStop: 46, // .
  5062. Solidus: 47, // /
  5063. Colon: 58, // :
  5064. Semicolon: 59, // ;
  5065. LessThanSign: 60, // <
  5066. EqualsSign: 61, // =
  5067. GreaterThanSign: 62, // >
  5068. QuestionMark: 63, // ?
  5069. CommercialAt: 64, // @
  5070. LeftSquareBracket: 91, // [
  5071. Backslash: 92, // \
  5072. RightSquareBracket: 93, // ]
  5073. CircumflexAccent: 94, // ^
  5074. LowLine: 95, // _
  5075. GraveAccent: 96, // `
  5076. LeftCurlyBracket: 123, // {
  5077. VerticalLine: 124, // |
  5078. RightCurlyBracket: 125, // }
  5079. Tilde: 126 // ~
  5080. };
  5081. var NAME = Object.keys(TYPE).reduce(function(result, key) {
  5082. result[TYPE[key]] = key;
  5083. return result;
  5084. }, {});
  5085. // https://drafts.csswg.org/css-syntax/#tokenizer-definitions
  5086. // > non-ASCII code point
  5087. // > A code point with a value equal to or greater than U+0080 <control>
  5088. // > name-start code point
  5089. // > A letter, a non-ASCII code point, or U+005F LOW LINE (_).
  5090. // > name code point
  5091. // > A name-start code point, a digit, or U+002D HYPHEN-MINUS (-)
  5092. // That means only ASCII code points has a special meaning and we a maps for 0..127 codes only
  5093. var SafeUint32Array = typeof Uint32Array !== 'undefined' ? Uint32Array : Array; // fallback on Array when TypedArray is not supported
  5094. var SYMBOL_TYPE = new SafeUint32Array(0x80);
  5095. var PUNCTUATION = new SafeUint32Array(0x80);
  5096. var STOP_URL_RAW = new SafeUint32Array(0x80);
  5097. for (var i = 0; i < SYMBOL_TYPE.length; i++) {
  5098. SYMBOL_TYPE[i] = IDENTIFIER;
  5099. }
  5100. // fill categories
  5101. [
  5102. TYPE.ExclamationMark, // !
  5103. TYPE.QuotationMark, // "
  5104. TYPE.NumberSign, // #
  5105. TYPE.DollarSign, // $
  5106. TYPE.PercentSign, // %
  5107. TYPE.Ampersand, // &
  5108. TYPE.Apostrophe, // '
  5109. TYPE.LeftParenthesis, // (
  5110. TYPE.RightParenthesis, // )
  5111. TYPE.Asterisk, // *
  5112. TYPE.PlusSign, // +
  5113. TYPE.Comma, // ,
  5114. TYPE.HyphenMinus, // -
  5115. TYPE.FullStop, // .
  5116. TYPE.Solidus, // /
  5117. TYPE.Colon, // :
  5118. TYPE.Semicolon, // ;
  5119. TYPE.LessThanSign, // <
  5120. TYPE.EqualsSign, // =
  5121. TYPE.GreaterThanSign, // >
  5122. TYPE.QuestionMark, // ?
  5123. TYPE.CommercialAt, // @
  5124. TYPE.LeftSquareBracket, // [
  5125. // TYPE.Backslash, // \
  5126. TYPE.RightSquareBracket, // ]
  5127. TYPE.CircumflexAccent, // ^
  5128. // TYPE.LowLine, // _
  5129. TYPE.GraveAccent, // `
  5130. TYPE.LeftCurlyBracket, // {
  5131. TYPE.VerticalLine, // |
  5132. TYPE.RightCurlyBracket, // }
  5133. TYPE.Tilde // ~
  5134. ].forEach(function(key) {
  5135. SYMBOL_TYPE[Number(key)] = PUNCTUATOR;
  5136. PUNCTUATION[Number(key)] = PUNCTUATOR;
  5137. });
  5138. for (var i = 48; i <= 57; i++) {
  5139. SYMBOL_TYPE[i] = NUMBER;
  5140. }
  5141. SYMBOL_TYPE[SPACE] = WHITESPACE;
  5142. SYMBOL_TYPE[TAB] = WHITESPACE;
  5143. SYMBOL_TYPE[N] = WHITESPACE;
  5144. SYMBOL_TYPE[R] = WHITESPACE;
  5145. SYMBOL_TYPE[F] = WHITESPACE;
  5146. SYMBOL_TYPE[TYPE.Apostrophe] = STRING;
  5147. SYMBOL_TYPE[TYPE.QuotationMark] = STRING;
  5148. STOP_URL_RAW[SPACE] = 1;
  5149. STOP_URL_RAW[TAB] = 1;
  5150. STOP_URL_RAW[N] = 1;
  5151. STOP_URL_RAW[R] = 1;
  5152. STOP_URL_RAW[F] = 1;
  5153. STOP_URL_RAW[TYPE.Apostrophe] = 1;
  5154. STOP_URL_RAW[TYPE.QuotationMark] = 1;
  5155. STOP_URL_RAW[TYPE.LeftParenthesis] = 1;
  5156. STOP_URL_RAW[TYPE.RightParenthesis] = 1;
  5157. // whitespace is punctuation ...
  5158. PUNCTUATION[SPACE] = PUNCTUATOR;
  5159. PUNCTUATION[TAB] = PUNCTUATOR;
  5160. PUNCTUATION[N] = PUNCTUATOR;
  5161. PUNCTUATION[R] = PUNCTUATOR;
  5162. PUNCTUATION[F] = PUNCTUATOR;
  5163. // ... hyper minus is not
  5164. PUNCTUATION[TYPE.HyphenMinus] = 0;
  5165. var _const = {
  5166. TYPE: TYPE,
  5167. NAME: NAME,
  5168. SYMBOL_TYPE: SYMBOL_TYPE,
  5169. PUNCTUATION: PUNCTUATION,
  5170. STOP_URL_RAW: STOP_URL_RAW
  5171. };
  5172. var PUNCTUATION$1 = _const.PUNCTUATION;
  5173. var STOP_URL_RAW$1 = _const.STOP_URL_RAW;
  5174. var TYPE$1 = _const.TYPE;
  5175. var FULLSTOP = TYPE$1.FullStop;
  5176. var PLUSSIGN = TYPE$1.PlusSign;
  5177. var HYPHENMINUS = TYPE$1.HyphenMinus;
  5178. var PUNCTUATOR$1 = TYPE$1.Punctuator;
  5179. var TAB$1 = 9;
  5180. var N$1 = 10;
  5181. var F$1 = 12;
  5182. var R$1 = 13;
  5183. var SPACE$1 = 32;
  5184. var BACK_SLASH = 92;
  5185. var E = 101; // 'e'.charCodeAt(0)
  5186. function firstCharOffset(source) {
  5187. // detect BOM (https://en.wikipedia.org/wiki/Byte_order_mark)
  5188. if (source.charCodeAt(0) === 0xFEFF || // UTF-16BE
  5189. source.charCodeAt(0) === 0xFFFE) { // UTF-16LE
  5190. return 1;
  5191. }
  5192. return 0;
  5193. }
  5194. function isHex(code) {
  5195. return (code >= 48 && code <= 57) || // 0 .. 9
  5196. (code >= 65 && code <= 70) || // A .. F
  5197. (code >= 97 && code <= 102); // a .. f
  5198. }
  5199. function isNumber(code) {
  5200. return code >= 48 && code <= 57;
  5201. }
  5202. function isNewline(source, offset, code) {
  5203. if (code === N$1 || code === F$1 || code === R$1) {
  5204. if (code === R$1 && offset + 1 < source.length && source.charCodeAt(offset + 1) === N$1) {
  5205. return 2;
  5206. }
  5207. return 1;
  5208. }
  5209. return 0;
  5210. }
  5211. function cmpChar(testStr, offset, referenceCode) {
  5212. var code = testStr.charCodeAt(offset);
  5213. // code.toLowerCase()
  5214. if (code >= 65 && code <= 90) {
  5215. code = code | 32;
  5216. }
  5217. return code === referenceCode;
  5218. }
  5219. function cmpStr(testStr, start, end, referenceStr) {
  5220. if (end - start !== referenceStr.length) {
  5221. return false;
  5222. }
  5223. if (start < 0 || end > testStr.length) {
  5224. return false;
  5225. }
  5226. for (var i = start; i < end; i++) {
  5227. var testCode = testStr.charCodeAt(i);
  5228. var refCode = referenceStr.charCodeAt(i - start);
  5229. // testStr[i].toLowerCase()
  5230. if (testCode >= 65 && testCode <= 90) {
  5231. testCode = testCode | 32;
  5232. }
  5233. if (testCode !== refCode) {
  5234. return false;
  5235. }
  5236. }
  5237. return true;
  5238. }
  5239. function endsWith(testStr, referenceStr) {
  5240. return cmpStr(testStr, testStr.length - referenceStr.length, testStr.length, referenceStr);
  5241. }
  5242. function findLastNonSpaceLocation(scanner) {
  5243. for (var i = scanner.source.length - 1; i >= 0; i--) {
  5244. var code = scanner.source.charCodeAt(i);
  5245. if (code !== SPACE$1 && code !== TAB$1 && code !== R$1 && code !== N$1 && code !== F$1) {
  5246. break;
  5247. }
  5248. }
  5249. return scanner.getLocation(i + 1);
  5250. }
  5251. function findWhiteSpaceEnd(source, offset) {
  5252. for (; offset < source.length; offset++) {
  5253. var code = source.charCodeAt(offset);
  5254. if (code !== SPACE$1 && code !== TAB$1 && code !== R$1 && code !== N$1 && code !== F$1) {
  5255. break;
  5256. }
  5257. }
  5258. return offset;
  5259. }
  5260. function findCommentEnd(source, offset) {
  5261. var commentEnd = source.indexOf('*/', offset);
  5262. if (commentEnd === -1) {
  5263. return source.length;
  5264. }
  5265. return commentEnd + 2;
  5266. }
  5267. function findStringEnd(source, offset, quote) {
  5268. for (; offset < source.length; offset++) {
  5269. var code = source.charCodeAt(offset);
  5270. // TODO: bad string
  5271. if (code === BACK_SLASH) {
  5272. offset++;
  5273. } else if (code === quote) {
  5274. offset++;
  5275. break;
  5276. }
  5277. }
  5278. return offset;
  5279. }
  5280. function findDecimalNumberEnd(source, offset) {
  5281. for (; offset < source.length; offset++) {
  5282. var code = source.charCodeAt(offset);
  5283. if (code < 48 || code > 57) { // not a 0 .. 9
  5284. break;
  5285. }
  5286. }
  5287. return offset;
  5288. }
  5289. function findNumberEnd(source, offset, allowFraction) {
  5290. var code;
  5291. offset = findDecimalNumberEnd(source, offset);
  5292. // fraction: .\d+
  5293. if (allowFraction && offset + 1 < source.length && source.charCodeAt(offset) === FULLSTOP) {
  5294. code = source.charCodeAt(offset + 1);
  5295. if (isNumber(code)) {
  5296. offset = findDecimalNumberEnd(source, offset + 1);
  5297. }
  5298. }
  5299. // exponent: e[+-]\d+
  5300. if (offset + 1 < source.length) {
  5301. if ((source.charCodeAt(offset) | 32) === E) { // case insensitive check for `e`
  5302. code = source.charCodeAt(offset + 1);
  5303. if (code === PLUSSIGN || code === HYPHENMINUS) {
  5304. if (offset + 2 < source.length) {
  5305. code = source.charCodeAt(offset + 2);
  5306. }
  5307. }
  5308. if (isNumber(code)) {
  5309. offset = findDecimalNumberEnd(source, offset + 2);
  5310. }
  5311. }
  5312. }
  5313. return offset;
  5314. }
  5315. // skip escaped unicode sequence that can ends with space
  5316. // [0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
  5317. function findEscaseEnd(source, offset) {
  5318. for (var i = 0; i < 7 && offset + i < source.length; i++) {
  5319. var code = source.charCodeAt(offset + i);
  5320. if (i !== 6 && isHex(code)) {
  5321. continue;
  5322. }
  5323. if (i > 0) {
  5324. offset += i - 1 + isNewline(source, offset + i, code);
  5325. if (code === SPACE$1 || code === TAB$1) {
  5326. offset++;
  5327. }
  5328. }
  5329. break;
  5330. }
  5331. return offset;
  5332. }
  5333. function findIdentifierEnd(source, offset) {
  5334. for (; offset < source.length; offset++) {
  5335. var code = source.charCodeAt(offset);
  5336. if (code === BACK_SLASH) {
  5337. offset = findEscaseEnd(source, offset + 1);
  5338. } else if (code < 0x80 && PUNCTUATION$1[code] === PUNCTUATOR$1) {
  5339. break;
  5340. }
  5341. }
  5342. return offset;
  5343. }
  5344. function findUrlRawEnd(source, offset) {
  5345. for (; offset < source.length; offset++) {
  5346. var code = source.charCodeAt(offset);
  5347. if (code === BACK_SLASH) {
  5348. offset = findEscaseEnd(source, offset + 1);
  5349. } else if (code < 0x80 && STOP_URL_RAW$1[code] === 1) {
  5350. break;
  5351. }
  5352. }
  5353. return offset;
  5354. }
  5355. var utils = {
  5356. firstCharOffset: firstCharOffset,
  5357. isHex: isHex,
  5358. isNumber: isNumber,
  5359. isNewline: isNewline,
  5360. cmpChar: cmpChar,
  5361. cmpStr: cmpStr,
  5362. endsWith: endsWith,
  5363. findLastNonSpaceLocation: findLastNonSpaceLocation,
  5364. findWhiteSpaceEnd: findWhiteSpaceEnd,
  5365. findCommentEnd: findCommentEnd,
  5366. findStringEnd: findStringEnd,
  5367. findDecimalNumberEnd: findDecimalNumberEnd,
  5368. findNumberEnd: findNumberEnd,
  5369. findEscaseEnd: findEscaseEnd,
  5370. findIdentifierEnd: findIdentifierEnd,
  5371. findUrlRawEnd: findUrlRawEnd
  5372. };
  5373. var TYPE$2 = _const.TYPE;
  5374. var NAME$1 = _const.NAME;
  5375. var SYMBOL_TYPE$1 = _const.SYMBOL_TYPE;
  5376. var firstCharOffset$1 = utils.firstCharOffset;
  5377. var cmpStr$1 = utils.cmpStr;
  5378. var isNumber$1 = utils.isNumber;
  5379. var findLastNonSpaceLocation$1 = utils.findLastNonSpaceLocation;
  5380. var findWhiteSpaceEnd$1 = utils.findWhiteSpaceEnd;
  5381. var findCommentEnd$1 = utils.findCommentEnd;
  5382. var findStringEnd$1 = utils.findStringEnd;
  5383. var findNumberEnd$1 = utils.findNumberEnd;
  5384. var findIdentifierEnd$1 = utils.findIdentifierEnd;
  5385. var findUrlRawEnd$1 = utils.findUrlRawEnd;
  5386. var NULL = 0;
  5387. var WHITESPACE$1 = TYPE$2.WhiteSpace;
  5388. var IDENTIFIER$1 = TYPE$2.Identifier;
  5389. var NUMBER$1 = TYPE$2.Number;
  5390. var STRING$1 = TYPE$2.String;
  5391. var COMMENT$1 = TYPE$2.Comment;
  5392. var PUNCTUATOR$2 = TYPE$2.Punctuator;
  5393. var CDO$1 = TYPE$2.CDO;
  5394. var CDC$1 = TYPE$2.CDC;
  5395. var ATRULE$1 = TYPE$2.Atrule;
  5396. var FUNCTION$1 = TYPE$2.Function;
  5397. var URL$1 = TYPE$2.Url;
  5398. var RAW$1 = TYPE$2.Raw;
  5399. var N$2 = 10;
  5400. var F$2 = 12;
  5401. var R$2 = 13;
  5402. var STAR = TYPE$2.Asterisk;
  5403. var SLASH = TYPE$2.Solidus;
  5404. var FULLSTOP$1 = TYPE$2.FullStop;
  5405. var PLUSSIGN$1 = TYPE$2.PlusSign;
  5406. var HYPHENMINUS$1 = TYPE$2.HyphenMinus;
  5407. var GREATERTHANSIGN = TYPE$2.GreaterThanSign;
  5408. var LESSTHANSIGN = TYPE$2.LessThanSign;
  5409. var EXCLAMATIONMARK = TYPE$2.ExclamationMark;
  5410. var COMMERCIALAT = TYPE$2.CommercialAt;
  5411. var QUOTATIONMARK = TYPE$2.QuotationMark;
  5412. var APOSTROPHE = TYPE$2.Apostrophe;
  5413. var LEFTPARENTHESIS = TYPE$2.LeftParenthesis;
  5414. var RIGHTPARENTHESIS = TYPE$2.RightParenthesis;
  5415. var LEFTCURLYBRACKET = TYPE$2.LeftCurlyBracket;
  5416. var RIGHTCURLYBRACKET = TYPE$2.RightCurlyBracket;
  5417. var LEFTSQUAREBRACKET = TYPE$2.LeftSquareBracket;
  5418. var RIGHTSQUAREBRACKET = TYPE$2.RightSquareBracket;
  5419. var MIN_BUFFER_SIZE = 16 * 1024;
  5420. var OFFSET_MASK = 0x00FFFFFF;
  5421. var TYPE_SHIFT = 24;
  5422. var SafeUint32Array$1 = typeof Uint32Array !== 'undefined' ? Uint32Array : Array; // fallback on Array when TypedArray is not supported
  5423. function computeLinesAndColumns(tokenizer, source) {
  5424. var sourceLength = source.length;
  5425. var start = firstCharOffset$1(source);
  5426. var lines = tokenizer.lines;
  5427. var line = tokenizer.startLine;
  5428. var columns = tokenizer.columns;
  5429. var column = tokenizer.startColumn;
  5430. if (lines === null || lines.length < sourceLength + 1) {
  5431. lines = new SafeUint32Array$1(Math.max(sourceLength + 1024, MIN_BUFFER_SIZE));
  5432. columns = new SafeUint32Array$1(lines.length);
  5433. }
  5434. for (var i = start; i < sourceLength; i++) {
  5435. var code = source.charCodeAt(i);
  5436. lines[i] = line;
  5437. columns[i] = column++;
  5438. if (code === N$2 || code === R$2 || code === F$2) {
  5439. if (code === R$2 && i + 1 < sourceLength && source.charCodeAt(i + 1) === N$2) {
  5440. i++;
  5441. lines[i] = line;
  5442. columns[i] = column;
  5443. }
  5444. line++;
  5445. column = 1;
  5446. }
  5447. }
  5448. lines[i] = line;
  5449. columns[i] = column;
  5450. tokenizer.linesAnsColumnsComputed = true;
  5451. tokenizer.lines = lines;
  5452. tokenizer.columns = columns;
  5453. }
  5454. function tokenLayout(tokenizer, source, startPos) {
  5455. var sourceLength = source.length;
  5456. var offsetAndType = tokenizer.offsetAndType;
  5457. var balance = tokenizer.balance;
  5458. var tokenCount = 0;
  5459. var prevType = 0;
  5460. var offset = startPos;
  5461. var anchor = 0;
  5462. var balanceCloseCode = 0;
  5463. var balanceStart = 0;
  5464. var balancePrev = 0;
  5465. if (offsetAndType === null || offsetAndType.length < sourceLength + 1) {
  5466. offsetAndType = new SafeUint32Array$1(sourceLength + 1024);
  5467. balance = new SafeUint32Array$1(sourceLength + 1024);
  5468. }
  5469. while (offset < sourceLength) {
  5470. var code = source.charCodeAt(offset);
  5471. var type = code < 0x80 ? SYMBOL_TYPE$1[code] : IDENTIFIER$1;
  5472. balance[tokenCount] = sourceLength;
  5473. switch (type) {
  5474. case WHITESPACE$1:
  5475. offset = findWhiteSpaceEnd$1(source, offset + 1);
  5476. break;
  5477. case PUNCTUATOR$2:
  5478. switch (code) {
  5479. case balanceCloseCode:
  5480. balancePrev = balanceStart & OFFSET_MASK;
  5481. balanceStart = balance[balancePrev];
  5482. balanceCloseCode = balanceStart >> TYPE_SHIFT;
  5483. balance[tokenCount] = balancePrev;
  5484. balance[balancePrev++] = tokenCount;
  5485. for (; balancePrev < tokenCount; balancePrev++) {
  5486. if (balance[balancePrev] === sourceLength) {
  5487. balance[balancePrev] = tokenCount;
  5488. }
  5489. }
  5490. break;
  5491. case LEFTSQUAREBRACKET:
  5492. balance[tokenCount] = balanceStart;
  5493. balanceCloseCode = RIGHTSQUAREBRACKET;
  5494. balanceStart = (balanceCloseCode << TYPE_SHIFT) | tokenCount;
  5495. break;
  5496. case LEFTCURLYBRACKET:
  5497. balance[tokenCount] = balanceStart;
  5498. balanceCloseCode = RIGHTCURLYBRACKET;
  5499. balanceStart = (balanceCloseCode << TYPE_SHIFT) | tokenCount;
  5500. break;
  5501. case LEFTPARENTHESIS:
  5502. balance[tokenCount] = balanceStart;
  5503. balanceCloseCode = RIGHTPARENTHESIS;
  5504. balanceStart = (balanceCloseCode << TYPE_SHIFT) | tokenCount;
  5505. break;
  5506. }
  5507. // /*
  5508. if (code === STAR && prevType === SLASH) {
  5509. type = COMMENT$1;
  5510. offset = findCommentEnd$1(source, offset + 1);
  5511. tokenCount--; // rewrite prev token
  5512. break;
  5513. }
  5514. // edge case for -.123 and +.123
  5515. if (code === FULLSTOP$1 && (prevType === PLUSSIGN$1 || prevType === HYPHENMINUS$1)) {
  5516. if (offset + 1 < sourceLength && isNumber$1(source.charCodeAt(offset + 1))) {
  5517. type = NUMBER$1;
  5518. offset = findNumberEnd$1(source, offset + 2, false);
  5519. tokenCount--; // rewrite prev token
  5520. break;
  5521. }
  5522. }
  5523. // <!--
  5524. if (code === EXCLAMATIONMARK && prevType === LESSTHANSIGN) {
  5525. if (offset + 2 < sourceLength &&
  5526. source.charCodeAt(offset + 1) === HYPHENMINUS$1 &&
  5527. source.charCodeAt(offset + 2) === HYPHENMINUS$1) {
  5528. type = CDO$1;
  5529. offset = offset + 3;
  5530. tokenCount--; // rewrite prev token
  5531. break;
  5532. }
  5533. }
  5534. // -->
  5535. if (code === HYPHENMINUS$1 && prevType === HYPHENMINUS$1) {
  5536. if (offset + 1 < sourceLength && source.charCodeAt(offset + 1) === GREATERTHANSIGN) {
  5537. type = CDC$1;
  5538. offset = offset + 2;
  5539. tokenCount--; // rewrite prev token
  5540. break;
  5541. }
  5542. }
  5543. // ident(
  5544. if (code === LEFTPARENTHESIS && prevType === IDENTIFIER$1) {
  5545. offset = offset + 1;
  5546. tokenCount--; // rewrite prev token
  5547. balance[tokenCount] = balance[tokenCount + 1];
  5548. balanceStart--;
  5549. // 4 char length identifier and equal to `url(` (case insensitive)
  5550. if (offset - anchor === 4 && cmpStr$1(source, anchor, offset, 'url(')) {
  5551. // special case for url() because it can contain any symbols sequence with few exceptions
  5552. anchor = findWhiteSpaceEnd$1(source, offset);
  5553. code = source.charCodeAt(anchor);
  5554. if (code !== LEFTPARENTHESIS &&
  5555. code !== RIGHTPARENTHESIS &&
  5556. code !== QUOTATIONMARK &&
  5557. code !== APOSTROPHE) {
  5558. // url(
  5559. offsetAndType[tokenCount++] = (URL$1 << TYPE_SHIFT) | offset;
  5560. balance[tokenCount] = sourceLength;
  5561. // ws*
  5562. if (anchor !== offset) {
  5563. offsetAndType[tokenCount++] = (WHITESPACE$1 << TYPE_SHIFT) | anchor;
  5564. balance[tokenCount] = sourceLength;
  5565. }
  5566. // raw
  5567. type = RAW$1;
  5568. offset = findUrlRawEnd$1(source, anchor);
  5569. } else {
  5570. type = URL$1;
  5571. }
  5572. } else {
  5573. type = FUNCTION$1;
  5574. }
  5575. break;
  5576. }
  5577. type = code;
  5578. offset = offset + 1;
  5579. break;
  5580. case NUMBER$1:
  5581. offset = findNumberEnd$1(source, offset + 1, prevType !== FULLSTOP$1);
  5582. // merge number with a preceding dot, dash or plus
  5583. if (prevType === FULLSTOP$1 ||
  5584. prevType === HYPHENMINUS$1 ||
  5585. prevType === PLUSSIGN$1) {
  5586. tokenCount--; // rewrite prev token
  5587. }
  5588. break;
  5589. case STRING$1:
  5590. offset = findStringEnd$1(source, offset + 1, code);
  5591. break;
  5592. default:
  5593. anchor = offset;
  5594. offset = findIdentifierEnd$1(source, offset);
  5595. // merge identifier with a preceding dash
  5596. if (prevType === HYPHENMINUS$1) {
  5597. // rewrite prev token
  5598. tokenCount--;
  5599. // restore prev prev token type
  5600. // for case @-prefix-ident
  5601. prevType = tokenCount === 0 ? 0 : offsetAndType[tokenCount - 1] >> TYPE_SHIFT;
  5602. }
  5603. if (prevType === COMMERCIALAT) {
  5604. // rewrite prev token and change type to <at-keyword-token>
  5605. tokenCount--;
  5606. type = ATRULE$1;
  5607. }
  5608. }
  5609. offsetAndType[tokenCount++] = (type << TYPE_SHIFT) | offset;
  5610. prevType = type;
  5611. }
  5612. // finalize arrays
  5613. offsetAndType[tokenCount] = offset;
  5614. balance[tokenCount] = sourceLength;
  5615. while (balanceStart !== 0) {
  5616. balancePrev = balanceStart & OFFSET_MASK;
  5617. balanceStart = balance[balancePrev];
  5618. balance[balancePrev] = sourceLength;
  5619. }
  5620. tokenizer.offsetAndType = offsetAndType;
  5621. tokenizer.tokenCount = tokenCount;
  5622. tokenizer.balance = balance;
  5623. }
  5624. //
  5625. // tokenizer
  5626. //
  5627. var Tokenizer = function(source, startOffset, startLine, startColumn) {
  5628. this.offsetAndType = null;
  5629. this.balance = null;
  5630. this.lines = null;
  5631. this.columns = null;
  5632. this.setSource(source, startOffset, startLine, startColumn);
  5633. };
  5634. Tokenizer.prototype = {
  5635. setSource: function(source, startOffset, startLine, startColumn) {
  5636. var safeSource = String(source || '');
  5637. var start = firstCharOffset$1(safeSource);
  5638. this.source = safeSource;
  5639. this.firstCharOffset = start;
  5640. this.startOffset = typeof startOffset === 'undefined' ? 0 : startOffset;
  5641. this.startLine = typeof startLine === 'undefined' ? 1 : startLine;
  5642. this.startColumn = typeof startColumn === 'undefined' ? 1 : startColumn;
  5643. this.linesAnsColumnsComputed = false;
  5644. this.eof = false;
  5645. this.currentToken = -1;
  5646. this.tokenType = 0;
  5647. this.tokenStart = start;
  5648. this.tokenEnd = start;
  5649. tokenLayout(this, safeSource, start);
  5650. this.next();
  5651. },
  5652. lookupType: function(offset) {
  5653. offset += this.currentToken;
  5654. if (offset < this.tokenCount) {
  5655. return this.offsetAndType[offset] >> TYPE_SHIFT;
  5656. }
  5657. return NULL;
  5658. },
  5659. lookupNonWSType: function(offset) {
  5660. offset += this.currentToken;
  5661. for (var type; offset < this.tokenCount; offset++) {
  5662. type = this.offsetAndType[offset] >> TYPE_SHIFT;
  5663. if (type !== WHITESPACE$1) {
  5664. return type;
  5665. }
  5666. }
  5667. return NULL;
  5668. },
  5669. lookupValue: function(offset, referenceStr) {
  5670. offset += this.currentToken;
  5671. if (offset < this.tokenCount) {
  5672. return cmpStr$1(
  5673. this.source,
  5674. this.offsetAndType[offset - 1] & OFFSET_MASK,
  5675. this.offsetAndType[offset] & OFFSET_MASK,
  5676. referenceStr
  5677. );
  5678. }
  5679. return false;
  5680. },
  5681. getTokenStart: function(tokenNum) {
  5682. if (tokenNum === this.currentToken) {
  5683. return this.tokenStart;
  5684. }
  5685. if (tokenNum > 0) {
  5686. return tokenNum < this.tokenCount
  5687. ? this.offsetAndType[tokenNum - 1] & OFFSET_MASK
  5688. : this.offsetAndType[this.tokenCount] & OFFSET_MASK;
  5689. }
  5690. return this.firstCharOffset;
  5691. },
  5692. getOffsetExcludeWS: function() {
  5693. if (this.currentToken > 0) {
  5694. if ((this.offsetAndType[this.currentToken - 1] >> TYPE_SHIFT) === WHITESPACE$1) {
  5695. return this.currentToken > 1
  5696. ? this.offsetAndType[this.currentToken - 2] & OFFSET_MASK
  5697. : this.firstCharOffset;
  5698. }
  5699. }
  5700. return this.tokenStart;
  5701. },
  5702. getRawLength: function(startToken, endTokenType1, endTokenType2, includeTokenType2) {
  5703. var cursor = startToken;
  5704. var balanceEnd;
  5705. loop:
  5706. for (; cursor < this.tokenCount; cursor++) {
  5707. balanceEnd = this.balance[cursor];
  5708. // belance end points to offset before start
  5709. if (balanceEnd < startToken) {
  5710. break loop;
  5711. }
  5712. // check token is stop type
  5713. switch (this.offsetAndType[cursor] >> TYPE_SHIFT) {
  5714. case endTokenType1:
  5715. break loop;
  5716. case endTokenType2:
  5717. if (includeTokenType2) {
  5718. cursor++;
  5719. }
  5720. break loop;
  5721. default:
  5722. // fast forward to the end of balanced block
  5723. if (this.balance[balanceEnd] === cursor) {
  5724. cursor = balanceEnd;
  5725. }
  5726. }
  5727. }
  5728. return cursor - this.currentToken;
  5729. },
  5730. getTokenValue: function() {
  5731. return this.source.substring(this.tokenStart, this.tokenEnd);
  5732. },
  5733. substrToCursor: function(start) {
  5734. return this.source.substring(start, this.tokenStart);
  5735. },
  5736. skipWS: function() {
  5737. for (var i = this.currentToken, skipTokenCount = 0; i < this.tokenCount; i++, skipTokenCount++) {
  5738. if ((this.offsetAndType[i] >> TYPE_SHIFT) !== WHITESPACE$1) {
  5739. break;
  5740. }
  5741. }
  5742. if (skipTokenCount > 0) {
  5743. this.skip(skipTokenCount);
  5744. }
  5745. },
  5746. skipSC: function() {
  5747. while (this.tokenType === WHITESPACE$1 || this.tokenType === COMMENT$1) {
  5748. this.next();
  5749. }
  5750. },
  5751. skip: function(tokenCount) {
  5752. var next = this.currentToken + tokenCount;
  5753. if (next < this.tokenCount) {
  5754. this.currentToken = next;
  5755. this.tokenStart = this.offsetAndType[next - 1] & OFFSET_MASK;
  5756. next = this.offsetAndType[next];
  5757. this.tokenType = next >> TYPE_SHIFT;
  5758. this.tokenEnd = next & OFFSET_MASK;
  5759. } else {
  5760. this.currentToken = this.tokenCount;
  5761. this.next();
  5762. }
  5763. },
  5764. next: function() {
  5765. var next = this.currentToken + 1;
  5766. if (next < this.tokenCount) {
  5767. this.currentToken = next;
  5768. this.tokenStart = this.tokenEnd;
  5769. next = this.offsetAndType[next];
  5770. this.tokenType = next >> TYPE_SHIFT;
  5771. this.tokenEnd = next & OFFSET_MASK;
  5772. } else {
  5773. this.currentToken = this.tokenCount;
  5774. this.eof = true;
  5775. this.tokenType = NULL;
  5776. this.tokenStart = this.tokenEnd = this.source.length;
  5777. }
  5778. },
  5779. eat: function(tokenType) {
  5780. if (this.tokenType !== tokenType) {
  5781. var offset = this.tokenStart;
  5782. var message = NAME$1[tokenType] + ' is expected';
  5783. // tweak message and offset
  5784. if (tokenType === IDENTIFIER$1) {
  5785. // when identifier is expected but there is a function or url
  5786. if (this.tokenType === FUNCTION$1 || this.tokenType === URL$1) {
  5787. offset = this.tokenEnd - 1;
  5788. message += ' but function found';
  5789. }
  5790. } else {
  5791. // when test type is part of another token show error for current position + 1
  5792. // e.g. eat(HYPHENMINUS) will fail on "-foo", but pointing on "-" is odd
  5793. if (this.source.charCodeAt(this.tokenStart) === tokenType) {
  5794. offset = offset + 1;
  5795. }
  5796. }
  5797. this.error(message, offset);
  5798. }
  5799. this.next();
  5800. },
  5801. eatNonWS: function(tokenType) {
  5802. this.skipWS();
  5803. this.eat(tokenType);
  5804. },
  5805. consume: function(tokenType) {
  5806. var value = this.getTokenValue();
  5807. this.eat(tokenType);
  5808. return value;
  5809. },
  5810. consumeFunctionName: function() {
  5811. var name = this.source.substring(this.tokenStart, this.tokenEnd - 1);
  5812. this.eat(FUNCTION$1);
  5813. return name;
  5814. },
  5815. consumeNonWS: function(tokenType) {
  5816. this.skipWS();
  5817. return this.consume(tokenType);
  5818. },
  5819. expectIdentifier: function(name) {
  5820. if (this.tokenType !== IDENTIFIER$1 || cmpStr$1(this.source, this.tokenStart, this.tokenEnd, name) === false) {
  5821. this.error('Identifier `' + name + '` is expected');
  5822. }
  5823. this.next();
  5824. },
  5825. getLocation: function(offset, filename) {
  5826. if (!this.linesAnsColumnsComputed) {
  5827. computeLinesAndColumns(this, this.source);
  5828. }
  5829. return {
  5830. source: filename,
  5831. offset: this.startOffset + offset,
  5832. line: this.lines[offset],
  5833. column: this.columns[offset]
  5834. };
  5835. },
  5836. getLocationRange: function(start, end, filename) {
  5837. if (!this.linesAnsColumnsComputed) {
  5838. computeLinesAndColumns(this, this.source);
  5839. }
  5840. return {
  5841. source: filename,
  5842. start: {
  5843. offset: this.startOffset + start,
  5844. line: this.lines[start],
  5845. column: this.columns[start]
  5846. },
  5847. end: {
  5848. offset: this.startOffset + end,
  5849. line: this.lines[end],
  5850. column: this.columns[end]
  5851. }
  5852. };
  5853. },
  5854. error: function(message, offset) {
  5855. var location = typeof offset !== 'undefined' && offset < this.source.length
  5856. ? this.getLocation(offset)
  5857. : this.eof
  5858. ? findLastNonSpaceLocation$1(this)
  5859. : this.getLocation(this.tokenStart);
  5860. throw new error(
  5861. message || 'Unexpected input',
  5862. this.source,
  5863. location.offset,
  5864. location.line,
  5865. location.column
  5866. );
  5867. },
  5868. dump: function() {
  5869. var offset = 0;
  5870. return Array.prototype.slice.call(this.offsetAndType, 0, this.tokenCount).map(function(item, idx) {
  5871. var start = offset;
  5872. var end = item & OFFSET_MASK;
  5873. offset = end;
  5874. return {
  5875. idx: idx,
  5876. type: NAME$1[item >> TYPE_SHIFT],
  5877. chunk: this.source.substring(start, end),
  5878. balance: this.balance[idx]
  5879. };
  5880. }, this);
  5881. }
  5882. };
  5883. // extend with error class
  5884. Tokenizer.CssSyntaxError = error;
  5885. // extend tokenizer with constants
  5886. Object.keys(_const).forEach(function(key) {
  5887. Tokenizer[key] = _const[key];
  5888. });
  5889. // extend tokenizer with static methods from utils
  5890. Object.keys(utils).forEach(function(key) {
  5891. Tokenizer[key] = utils[key];
  5892. });
  5893. // warm up tokenizer to elimitate code branches that never execute
  5894. // fix soft deoptimizations (insufficient type feedback)
  5895. new Tokenizer('\n\r\r\n\f<!---->//""\'\'/*\r\n\f*/1a;.\\31\t\+2{url(a);func();+1.2e3 -.4e-5 .6e+7}').getLocation();
  5896. var Tokenizer_1 = Tokenizer;
  5897. var tokenizer$1 = Tokenizer_1;
  5898. //
  5899. // item item item item
  5900. // /------\ /------\ /------\ /------\
  5901. // | data | | data | | data | | data |
  5902. // null <--+-prev |<---+-prev |<---+-prev |<---+-prev |
  5903. // | next-+--->| next-+--->| next-+--->| next-+--> null
  5904. // \------/ \------/ \------/ \------/
  5905. // ^ ^
  5906. // | list |
  5907. // | /------\ |
  5908. // \--------------+-head | |
  5909. // | tail-+--------------/
  5910. // \------/
  5911. //
  5912. function createItem(data) {
  5913. return {
  5914. prev: null,
  5915. next: null,
  5916. data: data
  5917. };
  5918. }
  5919. var cursors = null;
  5920. var List = function() {
  5921. this.cursor = null;
  5922. this.head = null;
  5923. this.tail = null;
  5924. };
  5925. List.createItem = createItem;
  5926. List.prototype.createItem = createItem;
  5927. List.prototype.getSize = function() {
  5928. var size = 0;
  5929. var cursor = this.head;
  5930. while (cursor) {
  5931. size++;
  5932. cursor = cursor.next;
  5933. }
  5934. return size;
  5935. };
  5936. List.prototype.fromArray = function(array) {
  5937. var cursor = null;
  5938. this.head = null;
  5939. for (var i = 0; i < array.length; i++) {
  5940. var item = createItem(array[i]);
  5941. if (cursor !== null) {
  5942. cursor.next = item;
  5943. } else {
  5944. this.head = item;
  5945. }
  5946. item.prev = cursor;
  5947. cursor = item;
  5948. }
  5949. this.tail = cursor;
  5950. return this;
  5951. };
  5952. List.prototype.toArray = function() {
  5953. var cursor = this.head;
  5954. var result = [];
  5955. while (cursor) {
  5956. result.push(cursor.data);
  5957. cursor = cursor.next;
  5958. }
  5959. return result;
  5960. };
  5961. List.prototype.toJSON = List.prototype.toArray;
  5962. List.prototype.isEmpty = function() {
  5963. return this.head === null;
  5964. };
  5965. List.prototype.first = function() {
  5966. return this.head && this.head.data;
  5967. };
  5968. List.prototype.last = function() {
  5969. return this.tail && this.tail.data;
  5970. };
  5971. function allocateCursor(node, prev, next) {
  5972. var cursor;
  5973. if (cursors !== null) {
  5974. cursor = cursors;
  5975. cursors = cursors.cursor;
  5976. cursor.prev = prev;
  5977. cursor.next = next;
  5978. cursor.cursor = node.cursor;
  5979. } else {
  5980. cursor = {
  5981. prev: prev,
  5982. next: next,
  5983. cursor: node.cursor
  5984. };
  5985. }
  5986. node.cursor = cursor;
  5987. return cursor;
  5988. }
  5989. function releaseCursor(node) {
  5990. var cursor = node.cursor;
  5991. node.cursor = cursor.cursor;
  5992. cursor.prev = null;
  5993. cursor.next = null;
  5994. cursor.cursor = cursors;
  5995. cursors = cursor;
  5996. }
  5997. List.prototype.each = function(fn, context) {
  5998. var item;
  5999. if (context === undefined) {
  6000. context = this;
  6001. }
  6002. // push cursor
  6003. var cursor = allocateCursor(this, null, this.head);
  6004. while (cursor.next !== null) {
  6005. item = cursor.next;
  6006. cursor.next = item.next;
  6007. fn.call(context, item.data, item, this);
  6008. }
  6009. // pop cursor
  6010. releaseCursor(this);
  6011. };
  6012. List.prototype.eachRight = function(fn, context) {
  6013. var item;
  6014. if (context === undefined) {
  6015. context = this;
  6016. }
  6017. // push cursor
  6018. var cursor = allocateCursor(this, this.tail, null);
  6019. while (cursor.prev !== null) {
  6020. item = cursor.prev;
  6021. cursor.prev = item.prev;
  6022. fn.call(context, item.data, item, this);
  6023. }
  6024. // pop cursor
  6025. releaseCursor(this);
  6026. };
  6027. List.prototype.nextUntil = function(start, fn, context) {
  6028. if (start === null) {
  6029. return;
  6030. }
  6031. var item;
  6032. if (context === undefined) {
  6033. context = this;
  6034. }
  6035. // push cursor
  6036. var cursor = allocateCursor(this, null, start);
  6037. while (cursor.next !== null) {
  6038. item = cursor.next;
  6039. cursor.next = item.next;
  6040. if (fn.call(context, item.data, item, this)) {
  6041. break;
  6042. }
  6043. }
  6044. // pop cursor
  6045. releaseCursor(this);
  6046. };
  6047. List.prototype.prevUntil = function(start, fn, context) {
  6048. if (start === null) {
  6049. return;
  6050. }
  6051. var item;
  6052. if (context === undefined) {
  6053. context = this;
  6054. }
  6055. // push cursor
  6056. var cursor = allocateCursor(this, start, null);
  6057. while (cursor.prev !== null) {
  6058. item = cursor.prev;
  6059. cursor.prev = item.prev;
  6060. if (fn.call(context, item.data, item, this)) {
  6061. break;
  6062. }
  6063. }
  6064. // pop cursor
  6065. releaseCursor(this);
  6066. };
  6067. List.prototype.some = function(fn, context) {
  6068. var cursor = this.head;
  6069. if (context === undefined) {
  6070. context = this;
  6071. }
  6072. while (cursor !== null) {
  6073. if (fn.call(context, cursor.data, cursor, this)) {
  6074. return true;
  6075. }
  6076. cursor = cursor.next;
  6077. }
  6078. return false;
  6079. };
  6080. List.prototype.map = function(fn, context) {
  6081. var result = [];
  6082. var cursor = this.head;
  6083. if (context === undefined) {
  6084. context = this;
  6085. }
  6086. while (cursor !== null) {
  6087. result.push(fn.call(context, cursor.data, cursor, this));
  6088. cursor = cursor.next;
  6089. }
  6090. return result;
  6091. };
  6092. List.prototype.clear = function() {
  6093. this.head = null;
  6094. this.tail = null;
  6095. };
  6096. List.prototype.copy = function() {
  6097. var result = new List();
  6098. var cursor = this.head;
  6099. while (cursor !== null) {
  6100. result.insert(createItem(cursor.data));
  6101. cursor = cursor.next;
  6102. }
  6103. return result;
  6104. };
  6105. List.prototype.updateCursors = function(prevOld, prevNew, nextOld, nextNew) {
  6106. var cursor = this.cursor;
  6107. while (cursor !== null) {
  6108. if (cursor.prev === prevOld) {
  6109. cursor.prev = prevNew;
  6110. }
  6111. if (cursor.next === nextOld) {
  6112. cursor.next = nextNew;
  6113. }
  6114. cursor = cursor.cursor;
  6115. }
  6116. };
  6117. List.prototype.prepend = function(item) {
  6118. // head
  6119. // ^
  6120. // item
  6121. this.updateCursors(null, item, this.head, item);
  6122. // insert to the beginning of the list
  6123. if (this.head !== null) {
  6124. // new item <- first item
  6125. this.head.prev = item;
  6126. // new item -> first item
  6127. item.next = this.head;
  6128. } else {
  6129. // if list has no head, then it also has no tail
  6130. // in this case tail points to the new item
  6131. this.tail = item;
  6132. }
  6133. // head always points to new item
  6134. this.head = item;
  6135. return this;
  6136. };
  6137. List.prototype.prependData = function(data) {
  6138. return this.prepend(createItem(data));
  6139. };
  6140. List.prototype.append = function(item) {
  6141. // tail
  6142. // ^
  6143. // item
  6144. this.updateCursors(this.tail, item, null, item);
  6145. // insert to the ending of the list
  6146. if (this.tail !== null) {
  6147. // last item -> new item
  6148. this.tail.next = item;
  6149. // last item <- new item
  6150. item.prev = this.tail;
  6151. } else {
  6152. // if list has no tail, then it also has no head
  6153. // in this case head points to new item
  6154. this.head = item;
  6155. }
  6156. // tail always points to new item
  6157. this.tail = item;
  6158. return this;
  6159. };
  6160. List.prototype.appendData = function(data) {
  6161. return this.append(createItem(data));
  6162. };
  6163. List.prototype.insert = function(item, before) {
  6164. if (before !== undefined && before !== null) {
  6165. // prev before
  6166. // ^
  6167. // item
  6168. this.updateCursors(before.prev, item, before, item);
  6169. if (before.prev === null) {
  6170. // insert to the beginning of list
  6171. if (this.head !== before) {
  6172. throw new Error('before doesn\'t belong to list');
  6173. }
  6174. // since head points to before therefore list doesn't empty
  6175. // no need to check tail
  6176. this.head = item;
  6177. before.prev = item;
  6178. item.next = before;
  6179. this.updateCursors(null, item);
  6180. } else {
  6181. // insert between two items
  6182. before.prev.next = item;
  6183. item.prev = before.prev;
  6184. before.prev = item;
  6185. item.next = before;
  6186. }
  6187. } else {
  6188. this.append(item);
  6189. }
  6190. };
  6191. List.prototype.insertData = function(data, before) {
  6192. this.insert(createItem(data), before);
  6193. };
  6194. List.prototype.remove = function(item) {
  6195. // item
  6196. // ^
  6197. // prev next
  6198. this.updateCursors(item, item.prev, item, item.next);
  6199. if (item.prev !== null) {
  6200. item.prev.next = item.next;
  6201. } else {
  6202. if (this.head !== item) {
  6203. throw new Error('item doesn\'t belong to list');
  6204. }
  6205. this.head = item.next;
  6206. }
  6207. if (item.next !== null) {
  6208. item.next.prev = item.prev;
  6209. } else {
  6210. if (this.tail !== item) {
  6211. throw new Error('item doesn\'t belong to list');
  6212. }
  6213. this.tail = item.prev;
  6214. }
  6215. item.prev = null;
  6216. item.next = null;
  6217. return item;
  6218. };
  6219. List.prototype.appendList = function(list) {
  6220. // ignore empty lists
  6221. if (list.head === null) {
  6222. return;
  6223. }
  6224. this.updateCursors(this.tail, list.tail, null, list.head);
  6225. // insert to end of the list
  6226. if (this.tail !== null) {
  6227. // if destination list has a tail, then it also has a head,
  6228. // but head doesn't change
  6229. // dest tail -> source head
  6230. this.tail.next = list.head;
  6231. // dest tail <- source head
  6232. list.head.prev = this.tail;
  6233. } else {
  6234. // if list has no a tail, then it also has no a head
  6235. // in this case points head to new item
  6236. this.head = list.head;
  6237. }
  6238. // tail always start point to new item
  6239. this.tail = list.tail;
  6240. list.head = null;
  6241. list.tail = null;
  6242. };
  6243. List.prototype.insertList = function(list, before) {
  6244. if (before !== undefined && before !== null) {
  6245. // ignore empty lists
  6246. if (list.head === null) {
  6247. return;
  6248. }
  6249. this.updateCursors(before.prev, list.tail, before, list.head);
  6250. // insert in the middle of dist list
  6251. if (before.prev !== null) {
  6252. // before.prev <-> list.head
  6253. before.prev.next = list.head;
  6254. list.head.prev = before.prev;
  6255. } else {
  6256. this.head = list.head;
  6257. }
  6258. before.prev = list.tail;
  6259. list.tail.next = before;
  6260. list.head = null;
  6261. list.tail = null;
  6262. } else {
  6263. this.appendList(list);
  6264. }
  6265. };
  6266. List.prototype.replace = function(oldItem, newItemOrList) {
  6267. if ('head' in newItemOrList) {
  6268. this.insertList(newItemOrList, oldItem);
  6269. } else {
  6270. this.insert(newItemOrList, oldItem);
  6271. }
  6272. this.remove(oldItem);
  6273. };
  6274. var list = List;
  6275. var TYPE$3 = tokenizer$1.TYPE;
  6276. var WHITESPACE$2 = TYPE$3.WhiteSpace;
  6277. var COMMENT$2 = TYPE$3.Comment;
  6278. var sequence = function readSequence(recognizer) {
  6279. var children = new list();
  6280. var child = null;
  6281. var context = {
  6282. recognizer: recognizer,
  6283. space: null,
  6284. ignoreWS: false,
  6285. ignoreWSAfter: false
  6286. };
  6287. this.scanner.skipSC();
  6288. while (!this.scanner.eof) {
  6289. switch (this.scanner.tokenType) {
  6290. case COMMENT$2:
  6291. this.scanner.next();
  6292. continue;
  6293. case WHITESPACE$2:
  6294. if (context.ignoreWS) {
  6295. this.scanner.next();
  6296. } else {
  6297. context.space = this.WhiteSpace();
  6298. }
  6299. continue;
  6300. }
  6301. child = recognizer.getNode.call(this, context);
  6302. if (child === undefined) {
  6303. break;
  6304. }
  6305. if (context.space !== null) {
  6306. children.appendData(context.space);
  6307. context.space = null;
  6308. }
  6309. children.appendData(child);
  6310. if (context.ignoreWSAfter) {
  6311. context.ignoreWSAfter = false;
  6312. context.ignoreWS = true;
  6313. } else {
  6314. context.ignoreWS = false;
  6315. }
  6316. }
  6317. return children;
  6318. };
  6319. var noop$1 = function() {};
  6320. function createParseContext(name) {
  6321. return function() {
  6322. return this[name]();
  6323. };
  6324. }
  6325. function processConfig(config) {
  6326. var parserConfig = {
  6327. context: {},
  6328. scope: {},
  6329. atrule: {},
  6330. pseudo: {}
  6331. };
  6332. if (config.parseContext) {
  6333. for (var name in config.parseContext) {
  6334. switch (typeof config.parseContext[name]) {
  6335. case 'function':
  6336. parserConfig.context[name] = config.parseContext[name];
  6337. break;
  6338. case 'string':
  6339. parserConfig.context[name] = createParseContext(config.parseContext[name]);
  6340. break;
  6341. }
  6342. }
  6343. }
  6344. if (config.scope) {
  6345. for (var name in config.scope) {
  6346. parserConfig.scope[name] = config.scope[name];
  6347. }
  6348. }
  6349. if (config.atrule) {
  6350. for (var name in config.atrule) {
  6351. var atrule = config.atrule[name];
  6352. if (atrule.parse) {
  6353. parserConfig.atrule[name] = atrule.parse;
  6354. }
  6355. }
  6356. }
  6357. if (config.pseudo) {
  6358. for (var name in config.pseudo) {
  6359. var pseudo = config.pseudo[name];
  6360. if (pseudo.parse) {
  6361. parserConfig.pseudo[name] = pseudo.parse;
  6362. }
  6363. }
  6364. }
  6365. if (config.node) {
  6366. for (var name in config.node) {
  6367. parserConfig[name] = config.node[name].parse;
  6368. }
  6369. }
  6370. return parserConfig;
  6371. }
  6372. var create = function createParser(config) {
  6373. var parser = {
  6374. scanner: new tokenizer$1(),
  6375. filename: '<unknown>',
  6376. needPositions: false,
  6377. tolerant: false,
  6378. onParseError: noop$1,
  6379. parseAtruleExpression: true,
  6380. parseSelector: true,
  6381. parseValue: true,
  6382. parseCustomProperty: false,
  6383. readSequence: sequence,
  6384. tolerantParse: function(consumer, fallback) {
  6385. if (this.tolerant) {
  6386. var start = this.scanner.currentToken;
  6387. try {
  6388. return consumer.call(this);
  6389. } catch (e) {
  6390. this.onParseError(e);
  6391. return fallback.call(this, start);
  6392. }
  6393. } else {
  6394. return consumer.call(this);
  6395. }
  6396. },
  6397. getLocation: function(start, end) {
  6398. if (this.needPositions) {
  6399. return this.scanner.getLocationRange(
  6400. start,
  6401. end,
  6402. this.filename
  6403. );
  6404. }
  6405. return null;
  6406. },
  6407. getLocationFromList: function(list) {
  6408. if (this.needPositions) {
  6409. return this.scanner.getLocationRange(
  6410. list.head !== null ? list.first().loc.start.offset - this.scanner.startOffset : this.scanner.tokenStart,
  6411. list.head !== null ? list.last().loc.end.offset - this.scanner.startOffset : this.scanner.tokenStart,
  6412. this.filename
  6413. );
  6414. }
  6415. return null;
  6416. }
  6417. };
  6418. config = processConfig(config || {});
  6419. for (var key in config) {
  6420. parser[key] = config[key];
  6421. }
  6422. return function(source, options) {
  6423. options = options || {};
  6424. var context = options.context || 'default';
  6425. var ast;
  6426. parser.scanner.setSource(source, options.offset, options.line, options.column);
  6427. parser.filename = options.filename || '<unknown>';
  6428. parser.needPositions = Boolean(options.positions);
  6429. parser.tolerant = Boolean(options.tolerant);
  6430. parser.onParseError = typeof options.onParseError === 'function' ? options.onParseError : noop$1;
  6431. parser.parseAtruleExpression = 'parseAtruleExpression' in options ? Boolean(options.parseAtruleExpression) : true;
  6432. parser.parseSelector = 'parseSelector' in options ? Boolean(options.parseSelector) : true;
  6433. parser.parseValue = 'parseValue' in options ? Boolean(options.parseValue) : true;
  6434. parser.parseCustomProperty = 'parseCustomProperty' in options ? Boolean(options.parseCustomProperty) : false;
  6435. if (!parser.context.hasOwnProperty(context)) {
  6436. throw new Error('Unknown context `' + context + '`');
  6437. }
  6438. ast = parser.context[context].call(parser, options);
  6439. if (!parser.scanner.eof) {
  6440. parser.scanner.error();
  6441. }
  6442. // console.log(JSON.stringify(ast, null, 4));
  6443. return ast;
  6444. };
  6445. };
  6446. var cmpChar$1 = tokenizer$1.cmpChar;
  6447. var TYPE$4 = tokenizer$1.TYPE;
  6448. var IDENTIFIER$2 = TYPE$4.Identifier;
  6449. var STRING$2 = TYPE$4.String;
  6450. var NUMBER$2 = TYPE$4.Number;
  6451. var FUNCTION$2 = TYPE$4.Function;
  6452. var URL$2 = TYPE$4.Url;
  6453. var NUMBERSIGN = TYPE$4.NumberSign;
  6454. var LEFTPARENTHESIS$1 = TYPE$4.LeftParenthesis;
  6455. var LEFTSQUAREBRACKET$1 = TYPE$4.LeftSquareBracket;
  6456. var PLUSSIGN$2 = TYPE$4.PlusSign;
  6457. var HYPHENMINUS$2 = TYPE$4.HyphenMinus;
  6458. var COMMA = TYPE$4.Comma;
  6459. var SOLIDUS = TYPE$4.Solidus;
  6460. var ASTERISK = TYPE$4.Asterisk;
  6461. var PERCENTSIGN = TYPE$4.PercentSign;
  6462. var BACKSLASH = TYPE$4.Backslash;
  6463. var U = 117; // 'u'.charCodeAt(0)
  6464. var _default = function defaultRecognizer(context) {
  6465. switch (this.scanner.tokenType) {
  6466. case NUMBERSIGN:
  6467. return this.HexColor();
  6468. case COMMA:
  6469. context.space = null;
  6470. context.ignoreWSAfter = true;
  6471. return this.Operator();
  6472. case SOLIDUS:
  6473. case ASTERISK:
  6474. case PLUSSIGN$2:
  6475. case HYPHENMINUS$2:
  6476. return this.Operator();
  6477. case LEFTPARENTHESIS$1:
  6478. return this.Parentheses(this.readSequence, context.recognizer);
  6479. case LEFTSQUAREBRACKET$1:
  6480. return this.Brackets(this.readSequence, context.recognizer);
  6481. case STRING$2:
  6482. return this.String();
  6483. case NUMBER$2:
  6484. switch (this.scanner.lookupType(1)) {
  6485. case PERCENTSIGN:
  6486. return this.Percentage();
  6487. case IDENTIFIER$2:
  6488. // edge case: number with folowing \0 and \9 hack shouldn't to be a Dimension
  6489. if (cmpChar$1(this.scanner.source, this.scanner.tokenEnd, BACKSLASH)) {
  6490. return this.Number();
  6491. } else {
  6492. return this.Dimension();
  6493. }
  6494. default:
  6495. return this.Number();
  6496. }
  6497. case FUNCTION$2:
  6498. return this.Function(this.readSequence, context.recognizer);
  6499. case URL$2:
  6500. return this.Url();
  6501. case IDENTIFIER$2:
  6502. // check for unicode range, it should start with u+ or U+
  6503. if (cmpChar$1(this.scanner.source, this.scanner.tokenStart, U) &&
  6504. cmpChar$1(this.scanner.source, this.scanner.tokenStart + 1, PLUSSIGN$2)) {
  6505. return this.UnicodeRange();
  6506. } else {
  6507. return this.Identifier();
  6508. }
  6509. }
  6510. };
  6511. var atruleExpression = {
  6512. getNode: _default
  6513. };
  6514. var TYPE$5 = tokenizer$1.TYPE;
  6515. var IDENTIFIER$3 = TYPE$5.Identifier;
  6516. var NUMBER$3 = TYPE$5.Number;
  6517. var NUMBERSIGN$1 = TYPE$5.NumberSign;
  6518. var LEFTSQUAREBRACKET$2 = TYPE$5.LeftSquareBracket;
  6519. var PLUSSIGN$3 = TYPE$5.PlusSign;
  6520. var SOLIDUS$1 = TYPE$5.Solidus;
  6521. var ASTERISK$1 = TYPE$5.Asterisk;
  6522. var FULLSTOP$2 = TYPE$5.FullStop;
  6523. var COLON = TYPE$5.Colon;
  6524. var GREATERTHANSIGN$1 = TYPE$5.GreaterThanSign;
  6525. var VERTICALLINE = TYPE$5.VerticalLine;
  6526. var TILDE = TYPE$5.Tilde;
  6527. function getNode(context) {
  6528. switch (this.scanner.tokenType) {
  6529. case PLUSSIGN$3:
  6530. case GREATERTHANSIGN$1:
  6531. case TILDE:
  6532. context.space = null;
  6533. context.ignoreWSAfter = true;
  6534. return this.Combinator();
  6535. case SOLIDUS$1: // /deep/
  6536. return this.Combinator();
  6537. case FULLSTOP$2:
  6538. return this.ClassSelector();
  6539. case LEFTSQUAREBRACKET$2:
  6540. return this.AttributeSelector();
  6541. case NUMBERSIGN$1:
  6542. return this.IdSelector();
  6543. case COLON:
  6544. if (this.scanner.lookupType(1) === COLON) {
  6545. return this.PseudoElementSelector();
  6546. } else {
  6547. return this.PseudoClassSelector();
  6548. }
  6549. case IDENTIFIER$3:
  6550. case ASTERISK$1:
  6551. case VERTICALLINE:
  6552. return this.TypeSelector();
  6553. case NUMBER$3:
  6554. return this.Percentage();
  6555. }
  6556. }
  6557. var selector = {
  6558. getNode: getNode
  6559. };
  6560. // https://drafts.csswg.org/css-images-4/#element-notation
  6561. // https://developer.mozilla.org/en-US/docs/Web/CSS/element
  6562. var element = function() {
  6563. this.scanner.skipSC();
  6564. var id = this.IdSelector();
  6565. this.scanner.skipSC();
  6566. return new list().appendData(
  6567. id
  6568. );
  6569. };
  6570. // legacy IE function
  6571. // expression '(' raw ')'
  6572. var expression = function() {
  6573. return new list().appendData(
  6574. this.Raw(this.scanner.currentToken, 0, 0, false, false)
  6575. );
  6576. };
  6577. var TYPE$6 = tokenizer$1.TYPE;
  6578. var IDENTIFIER$4 = TYPE$6.Identifier;
  6579. var COMMA$1 = TYPE$6.Comma;
  6580. var SEMICOLON = TYPE$6.Semicolon;
  6581. var HYPHENMINUS$3 = TYPE$6.HyphenMinus;
  6582. var EXCLAMATIONMARK$1 = TYPE$6.ExclamationMark;
  6583. // var '(' ident (',' <value>? )? ')'
  6584. var _var = function() {
  6585. var children = new list();
  6586. this.scanner.skipSC();
  6587. var identStart = this.scanner.tokenStart;
  6588. this.scanner.eat(HYPHENMINUS$3);
  6589. if (this.scanner.source.charCodeAt(this.scanner.tokenStart) !== HYPHENMINUS$3) {
  6590. this.scanner.error('HyphenMinus is expected');
  6591. }
  6592. this.scanner.eat(IDENTIFIER$4);
  6593. children.appendData({
  6594. type: 'Identifier',
  6595. loc: this.getLocation(identStart, this.scanner.tokenStart),
  6596. name: this.scanner.substrToCursor(identStart)
  6597. });
  6598. this.scanner.skipSC();
  6599. if (this.scanner.tokenType === COMMA$1) {
  6600. children.appendData(this.Operator());
  6601. children.appendData(this.parseCustomProperty
  6602. ? this.Value(null)
  6603. : this.Raw(this.scanner.currentToken, EXCLAMATIONMARK$1, SEMICOLON, false, false)
  6604. );
  6605. }
  6606. return children;
  6607. };
  6608. var value = {
  6609. getNode: _default,
  6610. '-moz-element': element,
  6611. 'element': element,
  6612. 'expression': expression,
  6613. 'var': _var
  6614. };
  6615. var scope = {
  6616. AtruleExpression: atruleExpression,
  6617. Selector: selector,
  6618. Value: value
  6619. };
  6620. var fontFace = {
  6621. parse: {
  6622. expression: null,
  6623. block: function() {
  6624. return this.Block(this.Declaration);
  6625. }
  6626. }
  6627. };
  6628. var TYPE$7 = tokenizer$1.TYPE;
  6629. var STRING$3 = TYPE$7.String;
  6630. var IDENTIFIER$5 = TYPE$7.Identifier;
  6631. var URL$3 = TYPE$7.Url;
  6632. var LEFTPARENTHESIS$2 = TYPE$7.LeftParenthesis;
  6633. var _import = {
  6634. parse: {
  6635. expression: function() {
  6636. var children = new list();
  6637. this.scanner.skipSC();
  6638. switch (this.scanner.tokenType) {
  6639. case STRING$3:
  6640. children.appendData(this.String());
  6641. break;
  6642. case URL$3:
  6643. children.appendData(this.Url());
  6644. break;
  6645. default:
  6646. this.scanner.error('String or url() is expected');
  6647. }
  6648. if (this.scanner.lookupNonWSType(0) === IDENTIFIER$5 ||
  6649. this.scanner.lookupNonWSType(0) === LEFTPARENTHESIS$2) {
  6650. children.appendData(this.WhiteSpace());
  6651. children.appendData(this.MediaQueryList());
  6652. }
  6653. return children;
  6654. },
  6655. block: null
  6656. }
  6657. };
  6658. var media = {
  6659. parse: {
  6660. expression: function() {
  6661. return new list().appendData(
  6662. this.MediaQueryList()
  6663. );
  6664. },
  6665. block: function() {
  6666. return this.Block(this.Rule);
  6667. }
  6668. }
  6669. };
  6670. var TYPE$8 = tokenizer$1.TYPE;
  6671. var LEFTCURLYBRACKET$1 = TYPE$8.LeftCurlyBracket;
  6672. var page = {
  6673. parse: {
  6674. expression: function() {
  6675. if (this.scanner.lookupNonWSType(0) === LEFTCURLYBRACKET$1) {
  6676. return null;
  6677. }
  6678. return new list().appendData(
  6679. this.SelectorList()
  6680. );
  6681. },
  6682. block: function() {
  6683. return this.Block(this.Declaration);
  6684. }
  6685. }
  6686. };
  6687. var TYPE$9 = tokenizer$1.TYPE;
  6688. var WHITESPACE$3 = TYPE$9.WhiteSpace;
  6689. var COMMENT$3 = TYPE$9.Comment;
  6690. var IDENTIFIER$6 = TYPE$9.Identifier;
  6691. var FUNCTION$3 = TYPE$9.Function;
  6692. var LEFTPARENTHESIS$3 = TYPE$9.LeftParenthesis;
  6693. var HYPHENMINUS$4 = TYPE$9.HyphenMinus;
  6694. var COLON$1 = TYPE$9.Colon;
  6695. function consumeRaw() {
  6696. return new list().appendData(
  6697. this.Raw(this.scanner.currentToken, 0, 0, false, false)
  6698. );
  6699. }
  6700. function parentheses() {
  6701. var index = 0;
  6702. this.scanner.skipSC();
  6703. // TODO: make it simplier
  6704. if (this.scanner.tokenType === IDENTIFIER$6) {
  6705. index = 1;
  6706. } else if (this.scanner.tokenType === HYPHENMINUS$4 &&
  6707. this.scanner.lookupType(1) === IDENTIFIER$6) {
  6708. index = 2;
  6709. }
  6710. if (index !== 0 && this.scanner.lookupNonWSType(index) === COLON$1) {
  6711. return new list().appendData(
  6712. this.Declaration()
  6713. );
  6714. }
  6715. return readSequence.call(this);
  6716. }
  6717. function readSequence() {
  6718. var children = new list();
  6719. var space = null;
  6720. var child;
  6721. this.scanner.skipSC();
  6722. scan:
  6723. while (!this.scanner.eof) {
  6724. switch (this.scanner.tokenType) {
  6725. case WHITESPACE$3:
  6726. space = this.WhiteSpace();
  6727. continue;
  6728. case COMMENT$3:
  6729. this.scanner.next();
  6730. continue;
  6731. case FUNCTION$3:
  6732. child = this.Function(consumeRaw, this.scope.AtruleExpression);
  6733. break;
  6734. case IDENTIFIER$6:
  6735. child = this.Identifier();
  6736. break;
  6737. case LEFTPARENTHESIS$3:
  6738. child = this.Parentheses(parentheses, this.scope.AtruleExpression);
  6739. break;
  6740. default:
  6741. break scan;
  6742. }
  6743. if (space !== null) {
  6744. children.appendData(space);
  6745. space = null;
  6746. }
  6747. children.appendData(child);
  6748. }
  6749. return children;
  6750. }
  6751. var supports = {
  6752. parse: {
  6753. expression: function() {
  6754. var children = readSequence.call(this);
  6755. if (children.isEmpty()) {
  6756. this.scanner.error('Condition is expected');
  6757. }
  6758. return children;
  6759. },
  6760. block: function() {
  6761. return this.Block(this.Rule);
  6762. }
  6763. }
  6764. };
  6765. var atrule = {
  6766. 'font-face': fontFace,
  6767. 'import': _import,
  6768. 'media': media,
  6769. 'page': page,
  6770. 'supports': supports
  6771. };
  6772. var dir = {
  6773. parse: function() {
  6774. return new list().appendData(
  6775. this.Identifier()
  6776. );
  6777. }
  6778. };
  6779. var has$1 = {
  6780. parse: function() {
  6781. return new list().appendData(
  6782. this.SelectorList()
  6783. );
  6784. }
  6785. };
  6786. var lang = {
  6787. parse: function() {
  6788. return new list().appendData(
  6789. this.Identifier()
  6790. );
  6791. }
  6792. };
  6793. var selectorList = {
  6794. parse: function selectorList() {
  6795. return new list().appendData(
  6796. this.SelectorList()
  6797. );
  6798. }
  6799. };
  6800. var matches = selectorList;
  6801. var not = selectorList;
  6802. var ALLOW_OF_CLAUSE = true;
  6803. var nthWithOfClause = {
  6804. parse: function() {
  6805. return new list().appendData(
  6806. this.Nth(ALLOW_OF_CLAUSE)
  6807. );
  6808. }
  6809. };
  6810. var nthChild = nthWithOfClause;
  6811. var nthLastChild = nthWithOfClause;
  6812. var DISALLOW_OF_CLAUSE = false;
  6813. var nth = {
  6814. parse: function nth() {
  6815. return new list().appendData(
  6816. this.Nth(DISALLOW_OF_CLAUSE)
  6817. );
  6818. }
  6819. };
  6820. var nthLastOfType = nth;
  6821. var nthOfType = nth;
  6822. var slotted = {
  6823. parse: function compoundSelector() {
  6824. return new list().appendData(
  6825. this.Selector()
  6826. );
  6827. }
  6828. };
  6829. var pseudo = {
  6830. 'dir': dir,
  6831. 'has': has$1,
  6832. 'lang': lang,
  6833. 'matches': matches,
  6834. 'not': not,
  6835. 'nth-child': nthChild,
  6836. 'nth-last-child': nthLastChild,
  6837. 'nth-last-of-type': nthLastOfType,
  6838. 'nth-of-type': nthOfType,
  6839. 'slotted': slotted
  6840. };
  6841. var cmpChar$2 = tokenizer$1.cmpChar;
  6842. var isNumber$2 = tokenizer$1.isNumber;
  6843. var TYPE$a = tokenizer$1.TYPE;
  6844. var IDENTIFIER$7 = TYPE$a.Identifier;
  6845. var NUMBER$4 = TYPE$a.Number;
  6846. var PLUSSIGN$4 = TYPE$a.PlusSign;
  6847. var HYPHENMINUS$5 = TYPE$a.HyphenMinus;
  6848. var N$3 = 110; // 'n'.charCodeAt(0)
  6849. var DISALLOW_SIGN = true;
  6850. var ALLOW_SIGN = false;
  6851. function checkTokenIsInteger(scanner, disallowSign) {
  6852. var pos = scanner.tokenStart;
  6853. if (scanner.source.charCodeAt(pos) === PLUSSIGN$4 ||
  6854. scanner.source.charCodeAt(pos) === HYPHENMINUS$5) {
  6855. if (disallowSign) {
  6856. scanner.error();
  6857. }
  6858. pos++;
  6859. }
  6860. for (; pos < scanner.tokenEnd; pos++) {
  6861. if (!isNumber$2(scanner.source.charCodeAt(pos))) {
  6862. scanner.error('Unexpected input', pos);
  6863. }
  6864. }
  6865. }
  6866. // An+B microsyntax https://www.w3.org/TR/css-syntax-3/#anb
  6867. var AnPlusB = {
  6868. name: 'AnPlusB',
  6869. structure: {
  6870. a: [String, null],
  6871. b: [String, null]
  6872. },
  6873. parse: function() {
  6874. var start = this.scanner.tokenStart;
  6875. var end = start;
  6876. var prefix = '';
  6877. var a = null;
  6878. var b = null;
  6879. if (this.scanner.tokenType === NUMBER$4 ||
  6880. this.scanner.tokenType === PLUSSIGN$4) {
  6881. checkTokenIsInteger(this.scanner, ALLOW_SIGN);
  6882. prefix = this.scanner.getTokenValue();
  6883. this.scanner.next();
  6884. end = this.scanner.tokenStart;
  6885. }
  6886. if (this.scanner.tokenType === IDENTIFIER$7) {
  6887. var bStart = this.scanner.tokenStart;
  6888. if (cmpChar$2(this.scanner.source, bStart, HYPHENMINUS$5)) {
  6889. if (prefix === '') {
  6890. prefix = '-';
  6891. bStart++;
  6892. } else {
  6893. this.scanner.error('Unexpected hyphen minus');
  6894. }
  6895. }
  6896. if (!cmpChar$2(this.scanner.source, bStart, N$3)) {
  6897. this.scanner.error();
  6898. }
  6899. a = prefix === '' ? '1' :
  6900. prefix === '+' ? '+1' :
  6901. prefix === '-' ? '-1' :
  6902. prefix;
  6903. var len = this.scanner.tokenEnd - bStart;
  6904. if (len > 1) {
  6905. // ..n-..
  6906. if (this.scanner.source.charCodeAt(bStart + 1) !== HYPHENMINUS$5) {
  6907. this.scanner.error('Unexpected input', bStart + 1);
  6908. }
  6909. if (len > 2) {
  6910. // ..n-{number}..
  6911. this.scanner.tokenStart = bStart + 2;
  6912. } else {
  6913. // ..n- {number}
  6914. this.scanner.next();
  6915. this.scanner.skipSC();
  6916. }
  6917. checkTokenIsInteger(this.scanner, DISALLOW_SIGN);
  6918. b = '-' + this.scanner.getTokenValue();
  6919. this.scanner.next();
  6920. end = this.scanner.tokenStart;
  6921. } else {
  6922. prefix = '';
  6923. this.scanner.next();
  6924. end = this.scanner.tokenStart;
  6925. this.scanner.skipSC();
  6926. if (this.scanner.tokenType === HYPHENMINUS$5 ||
  6927. this.scanner.tokenType === PLUSSIGN$4) {
  6928. prefix = this.scanner.getTokenValue();
  6929. this.scanner.next();
  6930. this.scanner.skipSC();
  6931. }
  6932. if (this.scanner.tokenType === NUMBER$4) {
  6933. checkTokenIsInteger(this.scanner, prefix !== '');
  6934. if (!isNumber$2(this.scanner.source.charCodeAt(this.scanner.tokenStart))) {
  6935. prefix = this.scanner.source.charAt(this.scanner.tokenStart);
  6936. this.scanner.tokenStart++;
  6937. }
  6938. if (prefix === '') {
  6939. // should be an operator before number
  6940. this.scanner.error();
  6941. } else if (prefix === '+') {
  6942. // plus is using by default
  6943. prefix = '';
  6944. }
  6945. b = prefix + this.scanner.getTokenValue();
  6946. this.scanner.next();
  6947. end = this.scanner.tokenStart;
  6948. } else {
  6949. if (prefix) {
  6950. this.scanner.eat(NUMBER$4);
  6951. }
  6952. }
  6953. }
  6954. } else {
  6955. if (prefix === '' || prefix === '+') { // no number
  6956. this.scanner.error(
  6957. 'Number or identifier is expected',
  6958. this.scanner.tokenStart + (
  6959. this.scanner.tokenType === PLUSSIGN$4 ||
  6960. this.scanner.tokenType === HYPHENMINUS$5
  6961. )
  6962. );
  6963. }
  6964. b = prefix;
  6965. }
  6966. return {
  6967. type: 'AnPlusB',
  6968. loc: this.getLocation(start, end),
  6969. a: a,
  6970. b: b
  6971. };
  6972. },
  6973. generate: function(processChunk, node) {
  6974. var a = node.a !== null && node.a !== undefined;
  6975. var b = node.b !== null && node.b !== undefined;
  6976. if (a) {
  6977. processChunk(
  6978. node.a === '+1' ? '+n' :
  6979. node.a === '1' ? 'n' :
  6980. node.a === '-1' ? '-n' :
  6981. node.a + 'n'
  6982. );
  6983. if (b) {
  6984. b = String(node.b);
  6985. if (b.charAt(0) === '-' || b.charAt(0) === '+') {
  6986. processChunk(b.charAt(0));
  6987. processChunk(b.substr(1));
  6988. } else {
  6989. processChunk('+');
  6990. processChunk(b);
  6991. }
  6992. }
  6993. } else {
  6994. processChunk(String(node.b));
  6995. }
  6996. }
  6997. };
  6998. var TYPE$b = tokenizer$1.TYPE;
  6999. var ATRULE$2 = TYPE$b.Atrule;
  7000. var SEMICOLON$1 = TYPE$b.Semicolon;
  7001. var LEFTCURLYBRACKET$2 = TYPE$b.LeftCurlyBracket;
  7002. var RIGHTCURLYBRACKET$1 = TYPE$b.RightCurlyBracket;
  7003. function isBlockAtrule() {
  7004. for (var offset = 1, type; type = this.scanner.lookupType(offset); offset++) {
  7005. if (type === RIGHTCURLYBRACKET$1) {
  7006. return true;
  7007. }
  7008. if (type === LEFTCURLYBRACKET$2 ||
  7009. type === ATRULE$2) {
  7010. return false;
  7011. }
  7012. }
  7013. this.scanner.skip(offset);
  7014. this.scanner.eat(RIGHTCURLYBRACKET$1);
  7015. }
  7016. var Atrule = {
  7017. name: 'Atrule',
  7018. structure: {
  7019. name: String,
  7020. expression: ['AtruleExpression', null],
  7021. block: ['Block', null]
  7022. },
  7023. parse: function() {
  7024. var start = this.scanner.tokenStart;
  7025. var name;
  7026. var nameLowerCase;
  7027. var expression = null;
  7028. var block = null;
  7029. this.scanner.eat(ATRULE$2);
  7030. name = this.scanner.substrToCursor(start + 1);
  7031. nameLowerCase = name.toLowerCase();
  7032. this.scanner.skipSC();
  7033. expression = this.AtruleExpression(name);
  7034. // turn empty AtruleExpression into null
  7035. if (expression.children.head === null) {
  7036. expression = null;
  7037. }
  7038. this.scanner.skipSC();
  7039. if (this.atrule.hasOwnProperty(nameLowerCase)) {
  7040. if (typeof this.atrule[nameLowerCase].block === 'function') {
  7041. if (this.scanner.tokenType !== LEFTCURLYBRACKET$2) {
  7042. // FIXME: make tolerant
  7043. this.scanner.error('Curly bracket is expected');
  7044. }
  7045. block = this.atrule[nameLowerCase].block.call(this);
  7046. } else {
  7047. if (!this.tolerant || !this.scanner.eof) {
  7048. this.scanner.eat(SEMICOLON$1);
  7049. }
  7050. }
  7051. } else {
  7052. switch (this.scanner.tokenType) {
  7053. case SEMICOLON$1:
  7054. this.scanner.next();
  7055. break;
  7056. case LEFTCURLYBRACKET$2:
  7057. // TODO: should consume block content as Raw?
  7058. block = this.Block(isBlockAtrule.call(this) ? this.Declaration : this.Rule);
  7059. break;
  7060. default:
  7061. if (!this.tolerant) {
  7062. this.scanner.error('Semicolon or block is expected');
  7063. }
  7064. }
  7065. }
  7066. return {
  7067. type: 'Atrule',
  7068. loc: this.getLocation(start, this.scanner.tokenStart),
  7069. name: name,
  7070. expression: expression,
  7071. block: block
  7072. };
  7073. },
  7074. generate: function(processChunk, node) {
  7075. processChunk('@');
  7076. processChunk(node.name);
  7077. if (node.expression !== null) {
  7078. processChunk(' ');
  7079. this.generate(processChunk, node.expression);
  7080. }
  7081. if (node.block) {
  7082. this.generate(processChunk, node.block);
  7083. } else {
  7084. processChunk(';');
  7085. }
  7086. },
  7087. walkContext: 'atrule'
  7088. };
  7089. var TYPE$c = tokenizer$1.TYPE;
  7090. var SEMICOLON$2 = TYPE$c.Semicolon;
  7091. var LEFTCURLYBRACKET$3 = TYPE$c.LeftCurlyBracket;
  7092. function consumeRaw$1(startToken) {
  7093. return new list().appendData(
  7094. this.Raw(startToken, SEMICOLON$2, LEFTCURLYBRACKET$3, false, true)
  7095. );
  7096. }
  7097. function consumeDefaultSequence() {
  7098. return this.readSequence(this.scope.AtruleExpression);
  7099. }
  7100. var AtruleExpression = {
  7101. name: 'AtruleExpression',
  7102. structure: {
  7103. children: [[]]
  7104. },
  7105. parse: function(name) {
  7106. var children = null;
  7107. var startToken = this.scanner.currentToken;
  7108. if (name !== null) {
  7109. name = name.toLowerCase();
  7110. }
  7111. if (this.parseAtruleExpression) {
  7112. // custom consumer
  7113. if (this.atrule.hasOwnProperty(name)) {
  7114. if (typeof this.atrule[name].expression === 'function') {
  7115. children = this.tolerantParse(this.atrule[name].expression, consumeRaw$1);
  7116. }
  7117. } else {
  7118. // default consumer
  7119. this.scanner.skipSC();
  7120. children = this.tolerantParse(consumeDefaultSequence, consumeRaw$1);
  7121. }
  7122. if (this.tolerant) {
  7123. if (this.scanner.eof || (this.scanner.tokenType !== SEMICOLON$2 && this.scanner.tokenType !== LEFTCURLYBRACKET$3)) {
  7124. children = consumeRaw$1.call(this, startToken);
  7125. }
  7126. }
  7127. } else {
  7128. children = consumeRaw$1.call(this, startToken);
  7129. }
  7130. if (children === null) {
  7131. children = new list();
  7132. }
  7133. return {
  7134. type: 'AtruleExpression',
  7135. loc: this.getLocationFromList(children),
  7136. children: children
  7137. };
  7138. },
  7139. generate: function(processChunk, node) {
  7140. this.each(processChunk, node);
  7141. },
  7142. walkContext: 'atruleExpression'
  7143. };
  7144. var TYPE$d = tokenizer$1.TYPE;
  7145. var IDENTIFIER$8 = TYPE$d.Identifier;
  7146. var STRING$4 = TYPE$d.String;
  7147. var DOLLARSIGN = TYPE$d.DollarSign;
  7148. var ASTERISK$2 = TYPE$d.Asterisk;
  7149. var COLON$2 = TYPE$d.Colon;
  7150. var EQUALSSIGN = TYPE$d.EqualsSign;
  7151. var LEFTSQUAREBRACKET$3 = TYPE$d.LeftSquareBracket;
  7152. var RIGHTSQUAREBRACKET$1 = TYPE$d.RightSquareBracket;
  7153. var CIRCUMFLEXACCENT = TYPE$d.CircumflexAccent;
  7154. var VERTICALLINE$1 = TYPE$d.VerticalLine;
  7155. var TILDE$1 = TYPE$d.Tilde;
  7156. function getAttributeName() {
  7157. if (this.scanner.eof) {
  7158. this.scanner.error('Unexpected end of input');
  7159. }
  7160. var start = this.scanner.tokenStart;
  7161. var expectIdentifier = false;
  7162. var checkColon = true;
  7163. if (this.scanner.tokenType === ASTERISK$2) {
  7164. expectIdentifier = true;
  7165. checkColon = false;
  7166. this.scanner.next();
  7167. } else if (this.scanner.tokenType !== VERTICALLINE$1) {
  7168. this.scanner.eat(IDENTIFIER$8);
  7169. }
  7170. if (this.scanner.tokenType === VERTICALLINE$1) {
  7171. if (this.scanner.lookupType(1) !== EQUALSSIGN) {
  7172. this.scanner.next();
  7173. this.scanner.eat(IDENTIFIER$8);
  7174. } else if (expectIdentifier) {
  7175. this.scanner.error('Identifier is expected', this.scanner.tokenEnd);
  7176. }
  7177. } else if (expectIdentifier) {
  7178. this.scanner.error('Vertical line is expected');
  7179. }
  7180. if (checkColon && this.scanner.tokenType === COLON$2) {
  7181. this.scanner.next();
  7182. this.scanner.eat(IDENTIFIER$8);
  7183. }
  7184. return {
  7185. type: 'Identifier',
  7186. loc: this.getLocation(start, this.scanner.tokenStart),
  7187. name: this.scanner.substrToCursor(start)
  7188. };
  7189. }
  7190. function getOperator() {
  7191. var start = this.scanner.tokenStart;
  7192. var tokenType = this.scanner.tokenType;
  7193. if (tokenType !== EQUALSSIGN && // =
  7194. tokenType !== TILDE$1 && // ~=
  7195. tokenType !== CIRCUMFLEXACCENT && // ^=
  7196. tokenType !== DOLLARSIGN && // $=
  7197. tokenType !== ASTERISK$2 && // *=
  7198. tokenType !== VERTICALLINE$1 // |=
  7199. ) {
  7200. this.scanner.error('Attribute selector (=, ~=, ^=, $=, *=, |=) is expected');
  7201. }
  7202. if (tokenType === EQUALSSIGN) {
  7203. this.scanner.next();
  7204. } else {
  7205. this.scanner.next();
  7206. this.scanner.eat(EQUALSSIGN);
  7207. }
  7208. return this.scanner.substrToCursor(start);
  7209. }
  7210. // '[' S* attrib_name ']'
  7211. // '[' S* attrib_name S* attrib_matcher S* [ IDENT | STRING ] S* attrib_flags? S* ']'
  7212. var AttributeSelector = {
  7213. name: 'AttributeSelector',
  7214. structure: {
  7215. name: 'Identifier',
  7216. matcher: [String, null],
  7217. value: ['String', 'Identifier', null],
  7218. flags: [String, null]
  7219. },
  7220. parse: function() {
  7221. var start = this.scanner.tokenStart;
  7222. var name;
  7223. var matcher = null;
  7224. var value = null;
  7225. var flags = null;
  7226. this.scanner.eat(LEFTSQUAREBRACKET$3);
  7227. this.scanner.skipSC();
  7228. name = getAttributeName.call(this);
  7229. this.scanner.skipSC();
  7230. if (this.scanner.tokenType !== RIGHTSQUAREBRACKET$1) {
  7231. // avoid case `[name i]`
  7232. if (this.scanner.tokenType !== IDENTIFIER$8) {
  7233. matcher = getOperator.call(this);
  7234. this.scanner.skipSC();
  7235. value = this.scanner.tokenType === STRING$4
  7236. ? this.String()
  7237. : this.Identifier();
  7238. this.scanner.skipSC();
  7239. }
  7240. // attribute flags
  7241. if (this.scanner.tokenType === IDENTIFIER$8) {
  7242. flags = this.scanner.getTokenValue();
  7243. this.scanner.next();
  7244. this.scanner.skipSC();
  7245. }
  7246. }
  7247. this.scanner.eat(RIGHTSQUAREBRACKET$1);
  7248. return {
  7249. type: 'AttributeSelector',
  7250. loc: this.getLocation(start, this.scanner.tokenStart),
  7251. name: name,
  7252. matcher: matcher,
  7253. value: value,
  7254. flags: flags
  7255. };
  7256. },
  7257. generate: function(processChunk, node) {
  7258. var flagsPrefix = ' ';
  7259. processChunk('[');
  7260. this.generate(processChunk, node.name);
  7261. if (node.matcher !== null) {
  7262. processChunk(node.matcher);
  7263. if (node.value !== null) {
  7264. this.generate(processChunk, node.value);
  7265. // space between string and flags is not required
  7266. if (node.value.type === 'String') {
  7267. flagsPrefix = '';
  7268. }
  7269. }
  7270. }
  7271. if (node.flags !== null) {
  7272. processChunk(flagsPrefix);
  7273. processChunk(node.flags);
  7274. }
  7275. processChunk(']');
  7276. }
  7277. };
  7278. var TYPE$e = tokenizer$1.TYPE;
  7279. var WHITESPACE$4 = TYPE$e.WhiteSpace;
  7280. var COMMENT$4 = TYPE$e.Comment;
  7281. var SEMICOLON$3 = TYPE$e.Semicolon;
  7282. var ATRULE$3 = TYPE$e.Atrule;
  7283. var LEFTCURLYBRACKET$4 = TYPE$e.LeftCurlyBracket;
  7284. var RIGHTCURLYBRACKET$2 = TYPE$e.RightCurlyBracket;
  7285. function consumeRaw$2(startToken) {
  7286. return this.Raw(startToken, 0, SEMICOLON$3, true, true);
  7287. }
  7288. var Block = {
  7289. name: 'Block',
  7290. structure: {
  7291. children: [['Atrule', 'Rule', 'Declaration']]
  7292. },
  7293. parse: function(defaultConsumer) {
  7294. if (!defaultConsumer) {
  7295. defaultConsumer = this.Declaration;
  7296. }
  7297. var start = this.scanner.tokenStart;
  7298. var children = new list();
  7299. this.scanner.eat(LEFTCURLYBRACKET$4);
  7300. scan:
  7301. while (!this.scanner.eof) {
  7302. switch (this.scanner.tokenType) {
  7303. case RIGHTCURLYBRACKET$2:
  7304. break scan;
  7305. case WHITESPACE$4:
  7306. case COMMENT$4:
  7307. case SEMICOLON$3:
  7308. this.scanner.next();
  7309. break;
  7310. case ATRULE$3:
  7311. children.appendData(this.tolerantParse(this.Atrule, consumeRaw$2));
  7312. break;
  7313. default:
  7314. children.appendData(this.tolerantParse(defaultConsumer, consumeRaw$2));
  7315. }
  7316. }
  7317. if (!this.tolerant || !this.scanner.eof) {
  7318. this.scanner.eat(RIGHTCURLYBRACKET$2);
  7319. }
  7320. return {
  7321. type: 'Block',
  7322. loc: this.getLocation(start, this.scanner.tokenStart),
  7323. children: children
  7324. };
  7325. },
  7326. generate: function(processChunk, node) {
  7327. processChunk('{');
  7328. this.each(processChunk, node);
  7329. processChunk('}');
  7330. },
  7331. walkContext: 'block'
  7332. };
  7333. var TYPE$f = tokenizer$1.TYPE;
  7334. var LEFTSQUAREBRACKET$4 = TYPE$f.LeftSquareBracket;
  7335. var RIGHTSQUAREBRACKET$2 = TYPE$f.RightSquareBracket;
  7336. // currently only Grid Layout uses square brackets, but left it universal
  7337. // https://drafts.csswg.org/css-grid/#track-sizing
  7338. // [ ident* ]
  7339. var Brackets = {
  7340. name: 'Brackets',
  7341. structure: {
  7342. children: [[]]
  7343. },
  7344. parse: function(readSequence, recognizer) {
  7345. var start = this.scanner.tokenStart;
  7346. var children = null;
  7347. this.scanner.eat(LEFTSQUAREBRACKET$4);
  7348. children = readSequence.call(this, recognizer);
  7349. this.scanner.eat(RIGHTSQUAREBRACKET$2);
  7350. return {
  7351. type: 'Brackets',
  7352. loc: this.getLocation(start, this.scanner.tokenStart),
  7353. children: children
  7354. };
  7355. },
  7356. generate: function(processChunk, node) {
  7357. processChunk('[');
  7358. this.each(processChunk, node);
  7359. processChunk(']');
  7360. }
  7361. };
  7362. var CDC$2 = tokenizer$1.TYPE.CDC;
  7363. var CDC_1 = {
  7364. name: 'CDC',
  7365. structure: [],
  7366. parse: function() {
  7367. var start = this.scanner.tokenStart;
  7368. this.scanner.eat(CDC$2); // -->
  7369. return {
  7370. type: 'CDC',
  7371. loc: this.getLocation(start, this.scanner.tokenStart)
  7372. };
  7373. },
  7374. generate: function(processChunk) {
  7375. processChunk('-->');
  7376. }
  7377. };
  7378. var CDO$2 = tokenizer$1.TYPE.CDO;
  7379. var CDO_1 = {
  7380. name: 'CDO',
  7381. structure: [],
  7382. parse: function() {
  7383. var start = this.scanner.tokenStart;
  7384. this.scanner.eat(CDO$2); // <!--
  7385. return {
  7386. type: 'CDO',
  7387. loc: this.getLocation(start, this.scanner.tokenStart)
  7388. };
  7389. },
  7390. generate: function(processChunk) {
  7391. processChunk('<!--');
  7392. }
  7393. };
  7394. var TYPE$g = tokenizer$1.TYPE;
  7395. var IDENTIFIER$9 = TYPE$g.Identifier;
  7396. var FULLSTOP$3 = TYPE$g.FullStop;
  7397. // '.' ident
  7398. var ClassSelector = {
  7399. name: 'ClassSelector',
  7400. structure: {
  7401. name: String
  7402. },
  7403. parse: function() {
  7404. this.scanner.eat(FULLSTOP$3);
  7405. return {
  7406. type: 'ClassSelector',
  7407. loc: this.getLocation(this.scanner.tokenStart - 1, this.scanner.tokenEnd),
  7408. name: this.scanner.consume(IDENTIFIER$9)
  7409. };
  7410. },
  7411. generate: function(processChunk, node) {
  7412. processChunk('.');
  7413. processChunk(node.name);
  7414. }
  7415. };
  7416. var TYPE$h = tokenizer$1.TYPE;
  7417. var PLUSSIGN$5 = TYPE$h.PlusSign;
  7418. var SOLIDUS$2 = TYPE$h.Solidus;
  7419. var GREATERTHANSIGN$2 = TYPE$h.GreaterThanSign;
  7420. var TILDE$2 = TYPE$h.Tilde;
  7421. // + | > | ~ | /deep/
  7422. var Combinator = {
  7423. name: 'Combinator',
  7424. structure: {
  7425. name: String
  7426. },
  7427. parse: function() {
  7428. var start = this.scanner.tokenStart;
  7429. switch (this.scanner.tokenType) {
  7430. case GREATERTHANSIGN$2:
  7431. case PLUSSIGN$5:
  7432. case TILDE$2:
  7433. this.scanner.next();
  7434. break;
  7435. case SOLIDUS$2:
  7436. this.scanner.next();
  7437. this.scanner.expectIdentifier('deep');
  7438. this.scanner.eat(SOLIDUS$2);
  7439. break;
  7440. default:
  7441. this.scanner.error('Combinator is expected');
  7442. }
  7443. return {
  7444. type: 'Combinator',
  7445. loc: this.getLocation(start, this.scanner.tokenStart),
  7446. name: this.scanner.substrToCursor(start)
  7447. };
  7448. },
  7449. generate: function(processChunk, node) {
  7450. processChunk(node.name);
  7451. }
  7452. };
  7453. var TYPE$i = tokenizer$1.TYPE;
  7454. var ASTERISK$3 = TYPE$i.Asterisk;
  7455. var SOLIDUS$3 = TYPE$i.Solidus;
  7456. // '/*' .* '*/'
  7457. var Comment = {
  7458. name: 'Comment',
  7459. structure: {
  7460. value: String
  7461. },
  7462. parse: function() {
  7463. var start = this.scanner.tokenStart;
  7464. var end = this.scanner.tokenEnd;
  7465. if ((end - start + 2) >= 2 &&
  7466. this.scanner.source.charCodeAt(end - 2) === ASTERISK$3 &&
  7467. this.scanner.source.charCodeAt(end - 1) === SOLIDUS$3) {
  7468. end -= 2;
  7469. }
  7470. this.scanner.next();
  7471. return {
  7472. type: 'Comment',
  7473. loc: this.getLocation(start, this.scanner.tokenStart),
  7474. value: this.scanner.source.substring(start + 2, end)
  7475. };
  7476. },
  7477. generate: function(processChunk, node) {
  7478. processChunk('/*');
  7479. processChunk(node.value);
  7480. processChunk('*/');
  7481. }
  7482. };
  7483. var TYPE$j = tokenizer$1.TYPE;
  7484. var IDENTIFIER$a = TYPE$j.Identifier;
  7485. var COLON$3 = TYPE$j.Colon;
  7486. var EXCLAMATIONMARK$2 = TYPE$j.ExclamationMark;
  7487. var SOLIDUS$4 = TYPE$j.Solidus;
  7488. var ASTERISK$4 = TYPE$j.Asterisk;
  7489. var DOLLARSIGN$1 = TYPE$j.DollarSign;
  7490. var HYPHENMINUS$6 = TYPE$j.HyphenMinus;
  7491. var SEMICOLON$4 = TYPE$j.Semicolon;
  7492. var RIGHTCURLYBRACKET$3 = TYPE$j.RightCurlyBracket;
  7493. var RIGHTPARENTHESIS$1 = TYPE$j.RightParenthesis;
  7494. var PLUSSIGN$6 = TYPE$j.PlusSign;
  7495. var NUMBERSIGN$2 = TYPE$j.NumberSign;
  7496. var Declaration = {
  7497. name: 'Declaration',
  7498. structure: {
  7499. important: [Boolean, String],
  7500. property: String,
  7501. value: ['Value', 'Raw']
  7502. },
  7503. parse: function() {
  7504. var start = this.scanner.tokenStart;
  7505. var property = readProperty.call(this);
  7506. var important = false;
  7507. var value;
  7508. this.scanner.skipSC();
  7509. this.scanner.eat(COLON$3);
  7510. if (isCustomProperty(property) ? this.parseCustomProperty : this.parseValue) {
  7511. value = this.Value(property);
  7512. } else {
  7513. value = this.Raw(this.scanner.currentToken, EXCLAMATIONMARK$2, SEMICOLON$4, false, false);
  7514. }
  7515. if (this.scanner.tokenType === EXCLAMATIONMARK$2) {
  7516. important = getImportant(this.scanner);
  7517. this.scanner.skipSC();
  7518. }
  7519. // TODO: include or not to include semicolon to range?
  7520. // if (this.scanner.tokenType === SEMICOLON) {
  7521. // this.scanner.next();
  7522. // }
  7523. if (!this.scanner.eof &&
  7524. this.scanner.tokenType !== SEMICOLON$4 &&
  7525. this.scanner.tokenType !== RIGHTPARENTHESIS$1 &&
  7526. this.scanner.tokenType !== RIGHTCURLYBRACKET$3) {
  7527. this.scanner.error();
  7528. }
  7529. return {
  7530. type: 'Declaration',
  7531. loc: this.getLocation(start, this.scanner.tokenStart),
  7532. important: important,
  7533. property: property,
  7534. value: value
  7535. };
  7536. },
  7537. generate: function(processChunk, node, item) {
  7538. processChunk(node.property);
  7539. processChunk(':');
  7540. this.generate(processChunk, node.value);
  7541. if (node.important) {
  7542. processChunk(node.important === true ? '!important' : '!' + node.important);
  7543. }
  7544. if (item && item.next) {
  7545. processChunk(';');
  7546. }
  7547. },
  7548. walkContext: 'declaration'
  7549. };
  7550. function isCustomProperty(name) {
  7551. return name.length >= 2 &&
  7552. name.charCodeAt(0) === HYPHENMINUS$6 &&
  7553. name.charCodeAt(1) === HYPHENMINUS$6;
  7554. }
  7555. function readProperty() {
  7556. var start = this.scanner.tokenStart;
  7557. var prefix = 0;
  7558. // hacks
  7559. switch (this.scanner.tokenType) {
  7560. case ASTERISK$4:
  7561. case DOLLARSIGN$1:
  7562. case PLUSSIGN$6:
  7563. case NUMBERSIGN$2:
  7564. prefix = 1;
  7565. break;
  7566. // TODO: not sure we should support this hack
  7567. case SOLIDUS$4:
  7568. prefix = this.scanner.lookupType(1) === SOLIDUS$4 ? 2 : 1;
  7569. break;
  7570. }
  7571. if (this.scanner.lookupType(prefix) === HYPHENMINUS$6) {
  7572. prefix++;
  7573. }
  7574. if (prefix) {
  7575. this.scanner.skip(prefix);
  7576. }
  7577. this.scanner.eat(IDENTIFIER$a);
  7578. return this.scanner.substrToCursor(start);
  7579. }
  7580. // ! ws* important
  7581. function getImportant(scanner) {
  7582. scanner.eat(EXCLAMATIONMARK$2);
  7583. scanner.skipSC();
  7584. var important = scanner.consume(IDENTIFIER$a);
  7585. // store original value in case it differ from `important`
  7586. // for better original source restoring and hacks like `!ie` support
  7587. return important === 'important' ? true : important;
  7588. }
  7589. var TYPE$k = tokenizer$1.TYPE;
  7590. var WHITESPACE$5 = TYPE$k.WhiteSpace;
  7591. var COMMENT$5 = TYPE$k.Comment;
  7592. var SEMICOLON$5 = TYPE$k.Semicolon;
  7593. function consumeRaw$3(startToken) {
  7594. return this.Raw(startToken, 0, SEMICOLON$5, true, true);
  7595. }
  7596. var DeclarationList = {
  7597. name: 'DeclarationList',
  7598. structure: {
  7599. children: [['Declaration']]
  7600. },
  7601. parse: function() {
  7602. var children = new list();
  7603. scan:
  7604. while (!this.scanner.eof) {
  7605. switch (this.scanner.tokenType) {
  7606. case WHITESPACE$5:
  7607. case COMMENT$5:
  7608. case SEMICOLON$5:
  7609. this.scanner.next();
  7610. break;
  7611. default:
  7612. children.appendData(this.tolerantParse(this.Declaration, consumeRaw$3));
  7613. }
  7614. }
  7615. return {
  7616. type: 'DeclarationList',
  7617. loc: this.getLocationFromList(children),
  7618. children: children
  7619. };
  7620. },
  7621. generate: function(processChunk, node) {
  7622. this.each(processChunk, node);
  7623. }
  7624. };
  7625. var NUMBER$5 = tokenizer$1.TYPE.Number;
  7626. // special reader for units to avoid adjoined IE hacks (i.e. '1px\9')
  7627. function readUnit(scanner) {
  7628. var unit = scanner.getTokenValue();
  7629. var backSlashPos = unit.indexOf('\\');
  7630. if (backSlashPos > 0) {
  7631. // patch token offset
  7632. scanner.tokenStart += backSlashPos;
  7633. // return part before backslash
  7634. return unit.substring(0, backSlashPos);
  7635. }
  7636. // no backslash in unit name
  7637. scanner.next();
  7638. return unit;
  7639. }
  7640. // number ident
  7641. var Dimension = {
  7642. name: 'Dimension',
  7643. structure: {
  7644. value: String,
  7645. unit: String
  7646. },
  7647. parse: function() {
  7648. var start = this.scanner.tokenStart;
  7649. var value = this.scanner.consume(NUMBER$5);
  7650. var unit = readUnit(this.scanner);
  7651. return {
  7652. type: 'Dimension',
  7653. loc: this.getLocation(start, this.scanner.tokenStart),
  7654. value: value,
  7655. unit: unit
  7656. };
  7657. },
  7658. generate: function(processChunk, node) {
  7659. processChunk(node.value);
  7660. processChunk(node.unit);
  7661. }
  7662. };
  7663. var TYPE$l = tokenizer$1.TYPE;
  7664. var RIGHTPARENTHESIS$2 = TYPE$l.RightParenthesis;
  7665. // <function-token> <sequence> ')'
  7666. var _Function = {
  7667. name: 'Function',
  7668. structure: {
  7669. name: String,
  7670. children: [[]]
  7671. },
  7672. parse: function(readSequence, recognizer) {
  7673. var start = this.scanner.tokenStart;
  7674. var name = this.scanner.consumeFunctionName();
  7675. var nameLowerCase = name.toLowerCase();
  7676. var children;
  7677. children = recognizer.hasOwnProperty(nameLowerCase)
  7678. ? recognizer[nameLowerCase].call(this, recognizer)
  7679. : readSequence.call(this, recognizer);
  7680. this.scanner.eat(RIGHTPARENTHESIS$2);
  7681. return {
  7682. type: 'Function',
  7683. loc: this.getLocation(start, this.scanner.tokenStart),
  7684. name: name,
  7685. children: children
  7686. };
  7687. },
  7688. generate: function(processChunk, node) {
  7689. processChunk(node.name);
  7690. processChunk('(');
  7691. this.each(processChunk, node);
  7692. processChunk(')');
  7693. },
  7694. walkContext: 'function'
  7695. };
  7696. var isHex$1 = tokenizer$1.isHex;
  7697. var TYPE$m = tokenizer$1.TYPE;
  7698. var IDENTIFIER$b = TYPE$m.Identifier;
  7699. var NUMBER$6 = TYPE$m.Number;
  7700. var NUMBERSIGN$3 = TYPE$m.NumberSign;
  7701. function consumeHexSequence(scanner, required) {
  7702. if (!isHex$1(scanner.source.charCodeAt(scanner.tokenStart))) {
  7703. if (required) {
  7704. scanner.error('Unexpected input', scanner.tokenStart);
  7705. } else {
  7706. return;
  7707. }
  7708. }
  7709. for (var pos = scanner.tokenStart + 1; pos < scanner.tokenEnd; pos++) {
  7710. var code = scanner.source.charCodeAt(pos);
  7711. // break on non-hex char
  7712. if (!isHex$1(code)) {
  7713. // break token, exclude symbol
  7714. scanner.tokenStart = pos;
  7715. return;
  7716. }
  7717. }
  7718. // token is full hex sequence, go to next token
  7719. scanner.next();
  7720. }
  7721. // # ident
  7722. var HexColor = {
  7723. name: 'HexColor',
  7724. structure: {
  7725. value: String
  7726. },
  7727. parse: function() {
  7728. var start = this.scanner.tokenStart;
  7729. this.scanner.eat(NUMBERSIGN$3);
  7730. scan:
  7731. switch (this.scanner.tokenType) {
  7732. case NUMBER$6:
  7733. consumeHexSequence(this.scanner, true);
  7734. // if token is identifier then number consists of hex only,
  7735. // try to add identifier to result
  7736. if (this.scanner.tokenType === IDENTIFIER$b) {
  7737. consumeHexSequence(this.scanner, false);
  7738. }
  7739. break;
  7740. case IDENTIFIER$b:
  7741. consumeHexSequence(this.scanner, true);
  7742. break;
  7743. default:
  7744. this.scanner.error('Number or identifier is expected');
  7745. }
  7746. return {
  7747. type: 'HexColor',
  7748. loc: this.getLocation(start, this.scanner.tokenStart),
  7749. value: this.scanner.substrToCursor(start + 1) // skip #
  7750. };
  7751. },
  7752. generate: function(processChunk, node) {
  7753. processChunk('#');
  7754. processChunk(node.value);
  7755. }
  7756. };
  7757. var TYPE$n = tokenizer$1.TYPE;
  7758. var IDENTIFIER$c = TYPE$n.Identifier;
  7759. var Identifier = {
  7760. name: 'Identifier',
  7761. structure: {
  7762. name: String
  7763. },
  7764. parse: function() {
  7765. return {
  7766. type: 'Identifier',
  7767. loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  7768. name: this.scanner.consume(IDENTIFIER$c)
  7769. };
  7770. },
  7771. generate: function(processChunk, node) {
  7772. processChunk(node.name);
  7773. }
  7774. };
  7775. var TYPE$o = tokenizer$1.TYPE;
  7776. var IDENTIFIER$d = TYPE$o.Identifier;
  7777. var NUMBERSIGN$4 = TYPE$o.NumberSign;
  7778. // '#' ident
  7779. var IdSelector = {
  7780. name: 'IdSelector',
  7781. structure: {
  7782. name: String
  7783. },
  7784. parse: function() {
  7785. this.scanner.eat(NUMBERSIGN$4);
  7786. return {
  7787. type: 'IdSelector',
  7788. loc: this.getLocation(this.scanner.tokenStart - 1, this.scanner.tokenEnd),
  7789. name: this.scanner.consume(IDENTIFIER$d)
  7790. };
  7791. },
  7792. generate: function(processChunk, node) {
  7793. processChunk('#');
  7794. processChunk(node.name);
  7795. }
  7796. };
  7797. var TYPE$p = tokenizer$1.TYPE;
  7798. var IDENTIFIER$e = TYPE$p.Identifier;
  7799. var NUMBER$7 = TYPE$p.Number;
  7800. var LEFTPARENTHESIS$4 = TYPE$p.LeftParenthesis;
  7801. var RIGHTPARENTHESIS$3 = TYPE$p.RightParenthesis;
  7802. var COLON$4 = TYPE$p.Colon;
  7803. var SOLIDUS$5 = TYPE$p.Solidus;
  7804. var MediaFeature = {
  7805. name: 'MediaFeature',
  7806. structure: {
  7807. name: String,
  7808. value: ['Identifier', 'Number', 'Dimension', 'Ratio', null]
  7809. },
  7810. parse: function() {
  7811. var start = this.scanner.tokenStart;
  7812. var name;
  7813. var value = null;
  7814. this.scanner.eat(LEFTPARENTHESIS$4);
  7815. this.scanner.skipSC();
  7816. name = this.scanner.consume(IDENTIFIER$e);
  7817. this.scanner.skipSC();
  7818. if (this.scanner.tokenType !== RIGHTPARENTHESIS$3) {
  7819. this.scanner.eat(COLON$4);
  7820. this.scanner.skipSC();
  7821. switch (this.scanner.tokenType) {
  7822. case NUMBER$7:
  7823. if (this.scanner.lookupType(1) === IDENTIFIER$e) {
  7824. value = this.Dimension();
  7825. } else if (this.scanner.lookupNonWSType(1) === SOLIDUS$5) {
  7826. value = this.Ratio();
  7827. } else {
  7828. value = this.Number();
  7829. }
  7830. break;
  7831. case IDENTIFIER$e:
  7832. value = this.Identifier();
  7833. break;
  7834. default:
  7835. this.scanner.error('Number, dimension, ratio or identifier is expected');
  7836. }
  7837. this.scanner.skipSC();
  7838. }
  7839. this.scanner.eat(RIGHTPARENTHESIS$3);
  7840. return {
  7841. type: 'MediaFeature',
  7842. loc: this.getLocation(start, this.scanner.tokenStart),
  7843. name: name,
  7844. value: value
  7845. };
  7846. },
  7847. generate: function(processChunk, node) {
  7848. processChunk('(');
  7849. processChunk(node.name);
  7850. if (node.value !== null) {
  7851. processChunk(':');
  7852. this.generate(processChunk, node.value);
  7853. }
  7854. processChunk(')');
  7855. }
  7856. };
  7857. var TYPE$q = tokenizer$1.TYPE;
  7858. var WHITESPACE$6 = TYPE$q.WhiteSpace;
  7859. var COMMENT$6 = TYPE$q.Comment;
  7860. var IDENTIFIER$f = TYPE$q.Identifier;
  7861. var LEFTPARENTHESIS$5 = TYPE$q.LeftParenthesis;
  7862. var MediaQuery = {
  7863. name: 'MediaQuery',
  7864. structure: {
  7865. children: [['Identifier', 'MediaFeature', 'WhiteSpace']]
  7866. },
  7867. parse: function() {
  7868. this.scanner.skipSC();
  7869. var children = new list();
  7870. var child = null;
  7871. var space = null;
  7872. scan:
  7873. while (!this.scanner.eof) {
  7874. switch (this.scanner.tokenType) {
  7875. case COMMENT$6:
  7876. this.scanner.next();
  7877. continue;
  7878. case WHITESPACE$6:
  7879. space = this.WhiteSpace();
  7880. continue;
  7881. case IDENTIFIER$f:
  7882. child = this.Identifier();
  7883. break;
  7884. case LEFTPARENTHESIS$5:
  7885. child = this.MediaFeature();
  7886. break;
  7887. default:
  7888. break scan;
  7889. }
  7890. if (space !== null) {
  7891. children.appendData(space);
  7892. space = null;
  7893. }
  7894. children.appendData(child);
  7895. }
  7896. if (child === null) {
  7897. this.scanner.error('Identifier or parenthesis is expected');
  7898. }
  7899. return {
  7900. type: 'MediaQuery',
  7901. loc: this.getLocationFromList(children),
  7902. children: children
  7903. };
  7904. },
  7905. generate: function(processChunk, node) {
  7906. this.each(processChunk, node);
  7907. }
  7908. };
  7909. var COMMA$2 = tokenizer$1.TYPE.Comma;
  7910. var MediaQueryList = {
  7911. name: 'MediaQueryList',
  7912. structure: {
  7913. children: [['MediaQuery']]
  7914. },
  7915. parse: function(relative) {
  7916. var children = new list();
  7917. this.scanner.skipSC();
  7918. while (!this.scanner.eof) {
  7919. children.appendData(this.MediaQuery(relative));
  7920. if (this.scanner.tokenType !== COMMA$2) {
  7921. break;
  7922. }
  7923. this.scanner.next();
  7924. }
  7925. return {
  7926. type: 'MediaQueryList',
  7927. loc: this.getLocationFromList(children),
  7928. children: children
  7929. };
  7930. },
  7931. generate: function(processChunk, node) {
  7932. this.eachComma(processChunk, node);
  7933. }
  7934. };
  7935. // https://drafts.csswg.org/css-syntax-3/#the-anb-type
  7936. var Nth = {
  7937. name: 'Nth',
  7938. structure: {
  7939. nth: ['AnPlusB', 'Identifier'],
  7940. selector: ['SelectorList', null]
  7941. },
  7942. parse: function(allowOfClause) {
  7943. this.scanner.skipSC();
  7944. var start = this.scanner.tokenStart;
  7945. var end = start;
  7946. var selector = null;
  7947. var query;
  7948. if (this.scanner.lookupValue(0, 'odd') || this.scanner.lookupValue(0, 'even')) {
  7949. query = this.Identifier();
  7950. } else {
  7951. query = this.AnPlusB();
  7952. }
  7953. this.scanner.skipSC();
  7954. if (allowOfClause && this.scanner.lookupValue(0, 'of')) {
  7955. this.scanner.next();
  7956. selector = this.SelectorList();
  7957. if (this.needPositions) {
  7958. end = selector.children.last().loc.end.offset;
  7959. }
  7960. } else {
  7961. if (this.needPositions) {
  7962. end = query.loc.end.offset;
  7963. }
  7964. }
  7965. return {
  7966. type: 'Nth',
  7967. loc: this.getLocation(start, end),
  7968. nth: query,
  7969. selector: selector
  7970. };
  7971. },
  7972. generate: function(processChunk, node) {
  7973. this.generate(processChunk, node.nth);
  7974. if (node.selector !== null) {
  7975. processChunk(' of ');
  7976. this.generate(processChunk, node.selector);
  7977. }
  7978. }
  7979. };
  7980. var NUMBER$8 = tokenizer$1.TYPE.Number;
  7981. var _Number = {
  7982. name: 'Number',
  7983. structure: {
  7984. value: String
  7985. },
  7986. parse: function() {
  7987. return {
  7988. type: 'Number',
  7989. loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  7990. value: this.scanner.consume(NUMBER$8)
  7991. };
  7992. },
  7993. generate: function(processChunk, node) {
  7994. processChunk(node.value);
  7995. }
  7996. };
  7997. // '/' | '*' | ',' | ':' | '+' | '-'
  7998. var Operator = {
  7999. name: 'Operator',
  8000. structure: {
  8001. value: String
  8002. },
  8003. parse: function() {
  8004. var start = this.scanner.tokenStart;
  8005. this.scanner.next();
  8006. return {
  8007. type: 'Operator',
  8008. loc: this.getLocation(start, this.scanner.tokenStart),
  8009. value: this.scanner.substrToCursor(start)
  8010. };
  8011. },
  8012. generate: function(processChunk, node) {
  8013. processChunk(node.value);
  8014. }
  8015. };
  8016. var TYPE$r = tokenizer$1.TYPE;
  8017. var LEFTPARENTHESIS$6 = TYPE$r.LeftParenthesis;
  8018. var RIGHTPARENTHESIS$4 = TYPE$r.RightParenthesis;
  8019. var Parentheses = {
  8020. name: 'Parentheses',
  8021. structure: {
  8022. children: [[]]
  8023. },
  8024. parse: function(readSequence, recognizer) {
  8025. var start = this.scanner.tokenStart;
  8026. var children = null;
  8027. this.scanner.eat(LEFTPARENTHESIS$6);
  8028. children = readSequence.call(this, recognizer);
  8029. this.scanner.eat(RIGHTPARENTHESIS$4);
  8030. return {
  8031. type: 'Parentheses',
  8032. loc: this.getLocation(start, this.scanner.tokenStart),
  8033. children: children
  8034. };
  8035. },
  8036. generate: function(processChunk, node) {
  8037. processChunk('(');
  8038. this.each(processChunk, node);
  8039. processChunk(')');
  8040. }
  8041. };
  8042. var TYPE$s = tokenizer$1.TYPE;
  8043. var NUMBER$9 = TYPE$s.Number;
  8044. var PERCENTSIGN$1 = TYPE$s.PercentSign;
  8045. var Percentage = {
  8046. name: 'Percentage',
  8047. structure: {
  8048. value: String
  8049. },
  8050. parse: function() {
  8051. var start = this.scanner.tokenStart;
  8052. var number = this.scanner.consume(NUMBER$9);
  8053. this.scanner.eat(PERCENTSIGN$1);
  8054. return {
  8055. type: 'Percentage',
  8056. loc: this.getLocation(start, this.scanner.tokenStart),
  8057. value: number
  8058. };
  8059. },
  8060. generate: function(processChunk, node) {
  8061. processChunk(node.value);
  8062. processChunk('%');
  8063. }
  8064. };
  8065. var TYPE$t = tokenizer$1.TYPE;
  8066. var IDENTIFIER$g = TYPE$t.Identifier;
  8067. var FUNCTION$4 = TYPE$t.Function;
  8068. var COLON$5 = TYPE$t.Colon;
  8069. var RIGHTPARENTHESIS$5 = TYPE$t.RightParenthesis;
  8070. // : ident [ '(' .. ')' ]?
  8071. var PseudoClassSelector = {
  8072. name: 'PseudoClassSelector',
  8073. structure: {
  8074. name: String,
  8075. children: [['Raw'], null]
  8076. },
  8077. parse: function() {
  8078. var start = this.scanner.tokenStart;
  8079. var children = null;
  8080. var name;
  8081. var nameLowerCase;
  8082. this.scanner.eat(COLON$5);
  8083. if (this.scanner.tokenType === FUNCTION$4) {
  8084. name = this.scanner.consumeFunctionName();
  8085. nameLowerCase = name.toLowerCase();
  8086. if (this.pseudo.hasOwnProperty(nameLowerCase)) {
  8087. this.scanner.skipSC();
  8088. children = this.pseudo[nameLowerCase].call(this);
  8089. this.scanner.skipSC();
  8090. } else {
  8091. children = new list().appendData(
  8092. this.Raw(this.scanner.currentToken, 0, 0, false, false)
  8093. );
  8094. }
  8095. this.scanner.eat(RIGHTPARENTHESIS$5);
  8096. } else {
  8097. name = this.scanner.consume(IDENTIFIER$g);
  8098. }
  8099. return {
  8100. type: 'PseudoClassSelector',
  8101. loc: this.getLocation(start, this.scanner.tokenStart),
  8102. name: name,
  8103. children: children
  8104. };
  8105. },
  8106. generate: function(processChunk, node) {
  8107. processChunk(':');
  8108. processChunk(node.name);
  8109. if (node.children !== null) {
  8110. processChunk('(');
  8111. this.each(processChunk, node);
  8112. processChunk(')');
  8113. }
  8114. },
  8115. walkContext: 'function'
  8116. };
  8117. var TYPE$u = tokenizer$1.TYPE;
  8118. var IDENTIFIER$h = TYPE$u.Identifier;
  8119. var FUNCTION$5 = TYPE$u.Function;
  8120. var COLON$6 = TYPE$u.Colon;
  8121. var RIGHTPARENTHESIS$6 = TYPE$u.RightParenthesis;
  8122. // :: ident [ '(' .. ')' ]?
  8123. var PseudoElementSelector = {
  8124. name: 'PseudoElementSelector',
  8125. structure: {
  8126. name: String,
  8127. children: [['Raw'], null]
  8128. },
  8129. parse: function() {
  8130. var start = this.scanner.tokenStart;
  8131. var children = null;
  8132. var name;
  8133. var nameLowerCase;
  8134. this.scanner.eat(COLON$6);
  8135. this.scanner.eat(COLON$6);
  8136. if (this.scanner.tokenType === FUNCTION$5) {
  8137. name = this.scanner.consumeFunctionName();
  8138. nameLowerCase = name.toLowerCase();
  8139. if (this.pseudo.hasOwnProperty(nameLowerCase)) {
  8140. this.scanner.skipSC();
  8141. children = this.pseudo[nameLowerCase].call(this);
  8142. this.scanner.skipSC();
  8143. } else {
  8144. children = new list().appendData(
  8145. this.Raw(this.scanner.currentToken, 0, 0, false, false)
  8146. );
  8147. }
  8148. this.scanner.eat(RIGHTPARENTHESIS$6);
  8149. } else {
  8150. name = this.scanner.consume(IDENTIFIER$h);
  8151. }
  8152. return {
  8153. type: 'PseudoElementSelector',
  8154. loc: this.getLocation(start, this.scanner.tokenStart),
  8155. name: name,
  8156. children: children
  8157. };
  8158. },
  8159. generate: function(processChunk, node) {
  8160. processChunk('::');
  8161. processChunk(node.name);
  8162. if (node.children !== null) {
  8163. processChunk('(');
  8164. this.each(processChunk, node);
  8165. processChunk(')');
  8166. }
  8167. },
  8168. walkContext: 'function'
  8169. };
  8170. var isNumber$3 = tokenizer$1.isNumber;
  8171. var TYPE$v = tokenizer$1.TYPE;
  8172. var NUMBER$a = TYPE$v.Number;
  8173. var SOLIDUS$6 = TYPE$v.Solidus;
  8174. var FULLSTOP$4 = TYPE$v.FullStop;
  8175. // Terms of <ratio> should to be a positive number (not zero or negative)
  8176. // (see https://drafts.csswg.org/mediaqueries-3/#values)
  8177. // However, -o-min-device-pixel-ratio takes fractional values as a ratio's term
  8178. // and this is using by various sites. Therefore we relax checking on parse
  8179. // to test a term is unsigned number without exponent part.
  8180. // Additional checks may to be applied on lexer validation.
  8181. function consumeNumber(scanner) {
  8182. var value = scanner.consumeNonWS(NUMBER$a);
  8183. for (var i = 0; i < value.length; i++) {
  8184. var code = value.charCodeAt(i);
  8185. if (!isNumber$3(code) && code !== FULLSTOP$4) {
  8186. scanner.error('Unsigned number is expected', scanner.tokenStart - value.length + i);
  8187. }
  8188. }
  8189. if (Number(value) === 0) {
  8190. scanner.error('Zero number is not allowed', scanner.tokenStart - value.length);
  8191. }
  8192. return value;
  8193. }
  8194. // <positive-integer> S* '/' S* <positive-integer>
  8195. var Ratio = {
  8196. name: 'Ratio',
  8197. structure: {
  8198. left: String,
  8199. right: String
  8200. },
  8201. parse: function() {
  8202. var start = this.scanner.tokenStart;
  8203. var left = consumeNumber(this.scanner);
  8204. var right;
  8205. this.scanner.eatNonWS(SOLIDUS$6);
  8206. right = consumeNumber(this.scanner);
  8207. return {
  8208. type: 'Ratio',
  8209. loc: this.getLocation(start, this.scanner.tokenStart),
  8210. left: left,
  8211. right: right
  8212. };
  8213. },
  8214. generate: function(processChunk, node) {
  8215. processChunk(node.left);
  8216. processChunk('/');
  8217. processChunk(node.right);
  8218. }
  8219. };
  8220. var Raw = {
  8221. name: 'Raw',
  8222. structure: {
  8223. value: String
  8224. },
  8225. parse: function(startToken, endTokenType1, endTokenType2, includeTokenType2, excludeWhiteSpace) {
  8226. var startOffset = this.scanner.getTokenStart(startToken);
  8227. var endOffset;
  8228. this.scanner.skip(
  8229. this.scanner.getRawLength(
  8230. startToken,
  8231. endTokenType1,
  8232. endTokenType2,
  8233. includeTokenType2
  8234. )
  8235. );
  8236. if (excludeWhiteSpace && this.scanner.tokenStart > startOffset) {
  8237. endOffset = this.scanner.getOffsetExcludeWS();
  8238. } else {
  8239. endOffset = this.scanner.tokenStart;
  8240. }
  8241. return {
  8242. type: 'Raw',
  8243. loc: this.getLocation(startOffset, endOffset),
  8244. value: this.scanner.source.substring(startOffset, endOffset)
  8245. };
  8246. },
  8247. generate: function(processChunk, node) {
  8248. processChunk(node.value);
  8249. }
  8250. };
  8251. var TYPE$w = tokenizer$1.TYPE;
  8252. var LEFTCURLYBRACKET$5 = TYPE$w.LeftCurlyBracket;
  8253. function consumeRaw$4(startToken) {
  8254. return this.Raw(startToken, LEFTCURLYBRACKET$5, 0, false, true);
  8255. }
  8256. var Rule = {
  8257. name: 'Rule',
  8258. structure: {
  8259. selector: ['SelectorList', 'Raw'],
  8260. block: ['Block']
  8261. },
  8262. parse: function() {
  8263. var startToken = this.scanner.currentToken;
  8264. var startOffset = this.scanner.tokenStart;
  8265. var selector = this.parseSelector
  8266. ? this.tolerantParse(this.SelectorList, consumeRaw$4)
  8267. : consumeRaw$4.call(this, startToken);
  8268. var block = this.Block(this.Declaration);
  8269. return {
  8270. type: 'Rule',
  8271. loc: this.getLocation(startOffset, this.scanner.tokenStart),
  8272. selector: selector,
  8273. block: block
  8274. };
  8275. },
  8276. generate: function(processChunk, node) {
  8277. this.generate(processChunk, node.selector);
  8278. this.generate(processChunk, node.block);
  8279. },
  8280. walkContext: 'rule'
  8281. };
  8282. var Selector = {
  8283. name: 'Selector',
  8284. structure: {
  8285. children: [[
  8286. 'TypeSelector',
  8287. 'IdSelector',
  8288. 'ClassSelector',
  8289. 'AttributeSelector',
  8290. 'PseudoClassSelector',
  8291. 'PseudoElementSelector',
  8292. 'Combinator',
  8293. 'WhiteSpace'
  8294. ]]
  8295. },
  8296. parse: function() {
  8297. var children = this.readSequence(this.scope.Selector);
  8298. // nothing were consumed
  8299. if (children.isEmpty()) {
  8300. this.scanner.error('Selector is expected');
  8301. }
  8302. return {
  8303. type: 'Selector',
  8304. loc: this.getLocationFromList(children),
  8305. children: children
  8306. };
  8307. },
  8308. generate: function(processChunk, node) {
  8309. this.each(processChunk, node);
  8310. }
  8311. };
  8312. var TYPE$x = tokenizer$1.TYPE;
  8313. var COMMA$3 = TYPE$x.Comma;
  8314. var LEFTCURLYBRACKET$6 = TYPE$x.LeftCurlyBracket;
  8315. var SelectorList = {
  8316. name: 'SelectorList',
  8317. structure: {
  8318. children: [['Selector', 'Raw']]
  8319. },
  8320. parse: function() {
  8321. var children = new list();
  8322. while (!this.scanner.eof) {
  8323. children.appendData(this.parseSelector
  8324. ? this.Selector()
  8325. : this.Raw(this.scanner.currentToken, COMMA$3, LEFTCURLYBRACKET$6, false, false)
  8326. );
  8327. if (this.scanner.tokenType === COMMA$3) {
  8328. this.scanner.next();
  8329. continue;
  8330. }
  8331. break;
  8332. }
  8333. return {
  8334. type: 'SelectorList',
  8335. loc: this.getLocationFromList(children),
  8336. children: children
  8337. };
  8338. },
  8339. generate: function(processChunk, node) {
  8340. this.eachComma(processChunk, node);
  8341. },
  8342. walkContext: 'selector'
  8343. };
  8344. var STRING$5 = tokenizer$1.TYPE.String;
  8345. var _String = {
  8346. name: 'String',
  8347. structure: {
  8348. value: String
  8349. },
  8350. parse: function() {
  8351. return {
  8352. type: 'String',
  8353. loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  8354. value: this.scanner.consume(STRING$5)
  8355. };
  8356. },
  8357. generate: function(processChunk, node) {
  8358. processChunk(node.value);
  8359. }
  8360. };
  8361. var TYPE$y = tokenizer$1.TYPE;
  8362. var WHITESPACE$7 = TYPE$y.WhiteSpace;
  8363. var COMMENT$7 = TYPE$y.Comment;
  8364. var EXCLAMATIONMARK$3 = TYPE$y.ExclamationMark;
  8365. var ATRULE$4 = TYPE$y.Atrule;
  8366. var CDO$3 = TYPE$y.CDO;
  8367. var CDC$3 = TYPE$y.CDC;
  8368. function consumeRaw$5(startToken) {
  8369. return this.Raw(startToken, 0, 0, false, false);
  8370. }
  8371. var StyleSheet = {
  8372. name: 'StyleSheet',
  8373. structure: {
  8374. children: [['Comment', 'Atrule', 'Rule', 'Raw']]
  8375. },
  8376. parse: function() {
  8377. var start = this.scanner.tokenStart;
  8378. var children = new list();
  8379. var child;
  8380. scan:
  8381. while (!this.scanner.eof) {
  8382. switch (this.scanner.tokenType) {
  8383. case WHITESPACE$7:
  8384. this.scanner.next();
  8385. continue;
  8386. case COMMENT$7:
  8387. // ignore comments except exclamation comments (i.e. /*! .. */) on top level
  8388. if (this.scanner.source.charCodeAt(this.scanner.tokenStart + 2) !== EXCLAMATIONMARK$3) {
  8389. this.scanner.next();
  8390. continue;
  8391. }
  8392. child = this.Comment();
  8393. break;
  8394. case CDO$3: // <!--
  8395. child = this.CDO();
  8396. break;
  8397. case CDC$3: // -->
  8398. child = this.CDC();
  8399. break;
  8400. // CSS Syntax Module Level 3
  8401. // §2.2 Error handling
  8402. // At the "top level" of a stylesheet, an <at-keyword-token> starts an at-rule.
  8403. case ATRULE$4:
  8404. child = this.Atrule();
  8405. break;
  8406. // Anything else starts a qualified rule ...
  8407. default:
  8408. child = this.tolerantParse(this.Rule, consumeRaw$5);
  8409. }
  8410. children.appendData(child);
  8411. }
  8412. return {
  8413. type: 'StyleSheet',
  8414. loc: this.getLocation(start, this.scanner.tokenStart),
  8415. children: children
  8416. };
  8417. },
  8418. generate: function(processChunk, node) {
  8419. this.each(processChunk, node);
  8420. },
  8421. walkContext: 'stylesheet'
  8422. };
  8423. var TYPE$z = tokenizer$1.TYPE;
  8424. var IDENTIFIER$i = TYPE$z.Identifier;
  8425. var ASTERISK$5 = TYPE$z.Asterisk;
  8426. var VERTICALLINE$2 = TYPE$z.VerticalLine;
  8427. function eatIdentifierOrAsterisk() {
  8428. if (this.scanner.tokenType !== IDENTIFIER$i &&
  8429. this.scanner.tokenType !== ASTERISK$5) {
  8430. this.scanner.error('Identifier or asterisk is expected');
  8431. }
  8432. this.scanner.next();
  8433. }
  8434. // ident
  8435. // ident|ident
  8436. // ident|*
  8437. // *
  8438. // *|ident
  8439. // *|*
  8440. // |ident
  8441. // |*
  8442. var TypeSelector = {
  8443. name: 'TypeSelector',
  8444. structure: {
  8445. name: String
  8446. },
  8447. parse: function() {
  8448. var start = this.scanner.tokenStart;
  8449. if (this.scanner.tokenType === VERTICALLINE$2) {
  8450. this.scanner.next();
  8451. eatIdentifierOrAsterisk.call(this);
  8452. } else {
  8453. eatIdentifierOrAsterisk.call(this);
  8454. if (this.scanner.tokenType === VERTICALLINE$2) {
  8455. this.scanner.next();
  8456. eatIdentifierOrAsterisk.call(this);
  8457. }
  8458. }
  8459. return {
  8460. type: 'TypeSelector',
  8461. loc: this.getLocation(start, this.scanner.tokenStart),
  8462. name: this.scanner.substrToCursor(start)
  8463. };
  8464. },
  8465. generate: function(processChunk, node) {
  8466. processChunk(node.name);
  8467. }
  8468. };
  8469. var isHex$2 = tokenizer$1.isHex;
  8470. var TYPE$A = tokenizer$1.TYPE;
  8471. var IDENTIFIER$j = TYPE$A.Identifier;
  8472. var NUMBER$b = TYPE$A.Number;
  8473. var PLUSSIGN$7 = TYPE$A.PlusSign;
  8474. var HYPHENMINUS$7 = TYPE$A.HyphenMinus;
  8475. var FULLSTOP$5 = TYPE$A.FullStop;
  8476. var QUESTIONMARK = TYPE$A.QuestionMark;
  8477. function scanUnicodeNumber(scanner) {
  8478. for (var pos = scanner.tokenStart + 1; pos < scanner.tokenEnd; pos++) {
  8479. var code = scanner.source.charCodeAt(pos);
  8480. // break on fullstop or hyperminus/plussign after exponent
  8481. if (code === FULLSTOP$5 || code === PLUSSIGN$7) {
  8482. // break token, exclude symbol
  8483. scanner.tokenStart = pos;
  8484. return false;
  8485. }
  8486. }
  8487. return true;
  8488. }
  8489. // https://drafts.csswg.org/css-syntax-3/#urange
  8490. function scanUnicodeRange(scanner) {
  8491. var hexStart = scanner.tokenStart + 1; // skip +
  8492. var hexLength = 0;
  8493. scan: {
  8494. if (scanner.tokenType === NUMBER$b) {
  8495. if (scanner.source.charCodeAt(scanner.tokenStart) !== FULLSTOP$5 && scanUnicodeNumber(scanner)) {
  8496. scanner.next();
  8497. } else if (scanner.source.charCodeAt(scanner.tokenStart) !== HYPHENMINUS$7) {
  8498. break scan;
  8499. }
  8500. } else {
  8501. scanner.next(); // PLUSSIGN
  8502. }
  8503. if (scanner.tokenType === HYPHENMINUS$7) {
  8504. scanner.next();
  8505. }
  8506. if (scanner.tokenType === NUMBER$b) {
  8507. scanner.next();
  8508. }
  8509. if (scanner.tokenType === IDENTIFIER$j) {
  8510. scanner.next();
  8511. }
  8512. if (scanner.tokenStart === hexStart) {
  8513. scanner.error('Unexpected input', hexStart);
  8514. }
  8515. }
  8516. // validate for U+x{1,6} or U+x{1,6}-x{1,6}
  8517. // where x is [0-9a-fA-F]
  8518. for (var i = hexStart, wasHyphenMinus = false; i < scanner.tokenStart; i++) {
  8519. var code = scanner.source.charCodeAt(i);
  8520. if (isHex$2(code) === false && (code !== HYPHENMINUS$7 || wasHyphenMinus)) {
  8521. scanner.error('Unexpected input', i);
  8522. }
  8523. if (code === HYPHENMINUS$7) {
  8524. // hex sequence shouldn't be an empty
  8525. if (hexLength === 0) {
  8526. scanner.error('Unexpected input', i);
  8527. }
  8528. wasHyphenMinus = true;
  8529. hexLength = 0;
  8530. } else {
  8531. hexLength++;
  8532. // too long hex sequence
  8533. if (hexLength > 6) {
  8534. scanner.error('Too long hex sequence', i);
  8535. }
  8536. }
  8537. }
  8538. // check we have a non-zero sequence
  8539. if (hexLength === 0) {
  8540. scanner.error('Unexpected input', i - 1);
  8541. }
  8542. // U+abc???
  8543. if (!wasHyphenMinus) {
  8544. // consume as many U+003F QUESTION MARK (?) code points as possible
  8545. for (; hexLength < 6 && !scanner.eof; scanner.next()) {
  8546. if (scanner.tokenType !== QUESTIONMARK) {
  8547. break;
  8548. }
  8549. hexLength++;
  8550. }
  8551. }
  8552. }
  8553. var UnicodeRange = {
  8554. name: 'UnicodeRange',
  8555. structure: {
  8556. value: String
  8557. },
  8558. parse: function() {
  8559. var start = this.scanner.tokenStart;
  8560. this.scanner.next(); // U or u
  8561. scanUnicodeRange(this.scanner);
  8562. return {
  8563. type: 'UnicodeRange',
  8564. loc: this.getLocation(start, this.scanner.tokenStart),
  8565. value: this.scanner.substrToCursor(start)
  8566. };
  8567. },
  8568. generate: function(processChunk, node) {
  8569. processChunk(node.value);
  8570. }
  8571. };
  8572. var TYPE$B = tokenizer$1.TYPE;
  8573. var STRING$6 = TYPE$B.String;
  8574. var URL$4 = TYPE$B.Url;
  8575. var RAW$2 = TYPE$B.Raw;
  8576. var RIGHTPARENTHESIS$7 = TYPE$B.RightParenthesis;
  8577. // url '(' S* (string | raw) S* ')'
  8578. var Url = {
  8579. name: 'Url',
  8580. structure: {
  8581. value: ['String', 'Raw']
  8582. },
  8583. parse: function() {
  8584. var start = this.scanner.tokenStart;
  8585. var value;
  8586. this.scanner.eat(URL$4);
  8587. this.scanner.skipSC();
  8588. switch (this.scanner.tokenType) {
  8589. case STRING$6:
  8590. value = this.String();
  8591. break;
  8592. case RAW$2:
  8593. value = this.Raw(this.scanner.currentToken, 0, RAW$2, true, false);
  8594. break;
  8595. default:
  8596. this.scanner.error('String or Raw is expected');
  8597. }
  8598. this.scanner.skipSC();
  8599. this.scanner.eat(RIGHTPARENTHESIS$7);
  8600. return {
  8601. type: 'Url',
  8602. loc: this.getLocation(start, this.scanner.tokenStart),
  8603. value: value
  8604. };
  8605. },
  8606. generate: function(processChunk, node) {
  8607. processChunk('url');
  8608. processChunk('(');
  8609. this.generate(processChunk, node.value);
  8610. processChunk(')');
  8611. }
  8612. };
  8613. var endsWith$1 = tokenizer$1.endsWith;
  8614. var TYPE$C = tokenizer$1.TYPE;
  8615. var WHITESPACE$8 = TYPE$C.WhiteSpace;
  8616. var COMMENT$8 = TYPE$C.Comment;
  8617. var FUNCTION$6 = TYPE$C.Function;
  8618. var COLON$7 = TYPE$C.Colon;
  8619. var SEMICOLON$6 = TYPE$C.Semicolon;
  8620. var EXCLAMATIONMARK$4 = TYPE$C.ExclamationMark;
  8621. // 'progid:' ws* 'DXImageTransform.Microsoft.' ident ws* '(' .* ')'
  8622. function checkProgid(scanner) {
  8623. var offset = 0;
  8624. for (var type; type = scanner.lookupType(offset); offset++) {
  8625. if (type !== WHITESPACE$8 && type !== COMMENT$8) {
  8626. break;
  8627. }
  8628. }
  8629. if (scanner.lookupValue(offset, 'alpha(') ||
  8630. scanner.lookupValue(offset, 'chroma(') ||
  8631. scanner.lookupValue(offset, 'dropshadow(')) {
  8632. if (scanner.lookupType(offset) !== FUNCTION$6) {
  8633. return false;
  8634. }
  8635. } else {
  8636. if (scanner.lookupValue(offset, 'progid') === false ||
  8637. scanner.lookupType(offset + 1) !== COLON$7) {
  8638. return false;
  8639. }
  8640. }
  8641. return true;
  8642. }
  8643. var Value = {
  8644. name: 'Value',
  8645. structure: {
  8646. children: [[]]
  8647. },
  8648. parse: function(property) {
  8649. // special parser for filter property since it can contains non-standart syntax for old IE
  8650. if (property !== null && endsWith$1(property, 'filter') && checkProgid(this.scanner)) {
  8651. this.scanner.skipSC();
  8652. return this.Raw(this.scanner.currentToken, EXCLAMATIONMARK$4, SEMICOLON$6, false, false);
  8653. }
  8654. var start = this.scanner.tokenStart;
  8655. var children = this.readSequence(this.scope.Value);
  8656. return {
  8657. type: 'Value',
  8658. loc: this.getLocation(start, this.scanner.tokenStart),
  8659. children: children
  8660. };
  8661. },
  8662. generate: function(processChunk, node) {
  8663. this.each(processChunk, node);
  8664. }
  8665. };
  8666. var WHITESPACE$9 = tokenizer$1.TYPE.WhiteSpace;
  8667. var SPACE$2 = Object.freeze({
  8668. type: 'WhiteSpace',
  8669. loc: null,
  8670. value: ' '
  8671. });
  8672. var WhiteSpace = {
  8673. name: 'WhiteSpace',
  8674. structure: {
  8675. value: String
  8676. },
  8677. parse: function() {
  8678. this.scanner.eat(WHITESPACE$9);
  8679. return SPACE$2;
  8680. // return {
  8681. // type: 'WhiteSpace',
  8682. // loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  8683. // value: this.scanner.consume(WHITESPACE)
  8684. // };
  8685. },
  8686. generate: function(processChunk, node) {
  8687. processChunk(node.value);
  8688. }
  8689. };
  8690. var node = {
  8691. AnPlusB: AnPlusB,
  8692. Atrule: Atrule,
  8693. AtruleExpression: AtruleExpression,
  8694. AttributeSelector: AttributeSelector,
  8695. Block: Block,
  8696. Brackets: Brackets,
  8697. CDC: CDC_1,
  8698. CDO: CDO_1,
  8699. ClassSelector: ClassSelector,
  8700. Combinator: Combinator,
  8701. Comment: Comment,
  8702. Declaration: Declaration,
  8703. DeclarationList: DeclarationList,
  8704. Dimension: Dimension,
  8705. Function: _Function,
  8706. HexColor: HexColor,
  8707. Identifier: Identifier,
  8708. IdSelector: IdSelector,
  8709. MediaFeature: MediaFeature,
  8710. MediaQuery: MediaQuery,
  8711. MediaQueryList: MediaQueryList,
  8712. Nth: Nth,
  8713. Number: _Number,
  8714. Operator: Operator,
  8715. Parentheses: Parentheses,
  8716. Percentage: Percentage,
  8717. PseudoClassSelector: PseudoClassSelector,
  8718. PseudoElementSelector: PseudoElementSelector,
  8719. Ratio: Ratio,
  8720. Raw: Raw,
  8721. Rule: Rule,
  8722. Selector: Selector,
  8723. SelectorList: SelectorList,
  8724. String: _String,
  8725. StyleSheet: StyleSheet,
  8726. TypeSelector: TypeSelector,
  8727. UnicodeRange: UnicodeRange,
  8728. Url: Url,
  8729. Value: Value,
  8730. WhiteSpace: WhiteSpace
  8731. };
  8732. var parser = {
  8733. parseContext: {
  8734. default: 'StyleSheet',
  8735. stylesheet: 'StyleSheet',
  8736. atrule: 'Atrule',
  8737. atruleExpression: function(options) {
  8738. return this.AtruleExpression(options.atrule ? String(options.atrule) : null);
  8739. },
  8740. mediaQueryList: 'MediaQueryList',
  8741. mediaQuery: 'MediaQuery',
  8742. rule: 'Rule',
  8743. selectorList: 'SelectorList',
  8744. selector: 'Selector',
  8745. block: function() {
  8746. return this.Block(this.Declaration);
  8747. },
  8748. declarationList: 'DeclarationList',
  8749. declaration: 'Declaration',
  8750. value: function(options) {
  8751. return this.Value(options.property ? String(options.property) : null);
  8752. }
  8753. },
  8754. scope: scope,
  8755. atrule: atrule,
  8756. pseudo: pseudo,
  8757. node: node
  8758. };
  8759. var parser$1 = create(parser);
  8760. function walk ( ast, ref) {
  8761. var enter = ref.enter;
  8762. var leave = ref.leave;
  8763. visit( ast, null, enter, leave );
  8764. }
  8765. var shouldSkip = false;
  8766. var context = { skip: function () { return shouldSkip = true; } };
  8767. var childKeys = {};
  8768. var toString$1 = Object.prototype.toString;
  8769. function isArray$1 ( thing ) {
  8770. return toString$1.call( thing ) === '[object Array]';
  8771. }
  8772. function visit ( node, parent, enter, leave, prop, index ) {
  8773. if ( !node ) { return; }
  8774. if ( enter ) {
  8775. var _shouldSkip = shouldSkip;
  8776. shouldSkip = false;
  8777. enter.call( context, node, parent, prop, index );
  8778. var skipped = shouldSkip;
  8779. shouldSkip = _shouldSkip;
  8780. if ( skipped ) { return; }
  8781. }
  8782. var keys = childKeys[ node.type ] || (
  8783. childKeys[ node.type ] = Object.keys( node ).filter( function (key) { return typeof node[ key ] === 'object'; } )
  8784. );
  8785. for ( var i = 0; i < keys.length; i += 1 ) {
  8786. var key = keys[i];
  8787. var value = node[ key ];
  8788. if ( isArray$1( value ) ) {
  8789. for ( var j = 0; j < value.length; j += 1 ) {
  8790. visit( value[j], node, enter, leave, key, j );
  8791. }
  8792. }
  8793. else if ( value && value.type ) {
  8794. visit( value, node, enter, leave, key, null );
  8795. }
  8796. }
  8797. if ( leave ) {
  8798. leave( node, parent, prop, index );
  8799. }
  8800. }
  8801. function readStyle(parser, start, attributes) {
  8802. const contentStart = parser.index;
  8803. const styles = parser.readUntil(/<\/style>/);
  8804. const contentEnd = parser.index;
  8805. let ast;
  8806. try {
  8807. ast = parser$1(styles, {
  8808. positions: true,
  8809. offset: contentStart,
  8810. });
  8811. }
  8812. catch (err) {
  8813. if (err.name === 'CssSyntaxError') {
  8814. parser.error({
  8815. code: `css-syntax-error`,
  8816. message: err.message
  8817. }, err.offset);
  8818. }
  8819. else {
  8820. throw err;
  8821. }
  8822. }
  8823. ast = JSON.parse(JSON.stringify(ast));
  8824. // tidy up AST
  8825. walk(ast, {
  8826. enter: (node) => {
  8827. // replace `ref:a` nodes
  8828. if (node.type === 'Selector') {
  8829. for (let i = 0; i < node.children.length; i += 1) {
  8830. const a = node.children[i];
  8831. const b = node.children[i + 1];
  8832. if (isRefSelector(a, b)) {
  8833. node.children.splice(i, 2, {
  8834. type: 'RefSelector',
  8835. start: a.loc.start.offset,
  8836. end: b.loc.end.offset,
  8837. name: b.name
  8838. });
  8839. }
  8840. }
  8841. }
  8842. if (node.loc) {
  8843. node.start = node.loc.start.offset;
  8844. node.end = node.loc.end.offset;
  8845. delete node.loc;
  8846. }
  8847. }
  8848. });
  8849. parser.eat('</style>', true);
  8850. const end = parser.index;
  8851. return {
  8852. start,
  8853. end,
  8854. attributes,
  8855. children: ast.children,
  8856. content: {
  8857. start: contentStart,
  8858. end: contentEnd,
  8859. styles,
  8860. },
  8861. };
  8862. }
  8863. function isRefSelector(a, b) {
  8864. if (!b)
  8865. return false;
  8866. return (a.type === 'TypeSelector' &&
  8867. a.name === 'ref' &&
  8868. b.type === 'PseudoClassSelector');
  8869. }
  8870. const DIRECTIVES = {
  8871. Ref: {
  8872. names: ['ref'],
  8873. attribute(start, end, type, name) {
  8874. return { start, end, type, name };
  8875. },
  8876. allowedExpressionTypes: [],
  8877. error: 'ref directives cannot have a value'
  8878. },
  8879. EventHandler: {
  8880. names: ['on'],
  8881. attribute(start, end, type, lhs, expression) {
  8882. const [name, ...modifiers] = lhs.split('|');
  8883. return { start, end, type, name, modifiers, expression };
  8884. },
  8885. allowedExpressionTypes: ['CallExpression'],
  8886. error: 'Expected a method call'
  8887. },
  8888. Binding: {
  8889. names: ['bind'],
  8890. attribute(start, end, type, name, expression) {
  8891. return {
  8892. start, end, type, name,
  8893. value: expression || {
  8894. type: 'Identifier',
  8895. start: start + 5,
  8896. end,
  8897. name,
  8898. }
  8899. };
  8900. },
  8901. allowedExpressionTypes: ['Identifier', 'MemberExpression'],
  8902. error: 'Can only bind to an identifier (e.g. `foo`) or a member expression (e.g. `foo.bar` or `foo[baz]`)'
  8903. },
  8904. Transition: {
  8905. names: ['in', 'out', 'transition'],
  8906. attribute(start, end, type, name, expression, directiveName) {
  8907. return {
  8908. start, end, type, name, expression,
  8909. intro: directiveName === 'in' || directiveName === 'transition',
  8910. outro: directiveName === 'out' || directiveName === 'transition',
  8911. };
  8912. },
  8913. allowedExpressionTypes: ['ObjectExpression'],
  8914. error: 'Transition argument must be an object literal, e.g. `{ duration: 400 }`'
  8915. },
  8916. Animation: {
  8917. names: ['animate'],
  8918. attribute(start, end, type, name, expression) {
  8919. return { start, end, type, name, expression };
  8920. },
  8921. allowedExpressionTypes: ['ObjectExpression'],
  8922. error: 'Animation argument must be an object literal, e.g. `{ duration: 400 }`'
  8923. },
  8924. Action: {
  8925. names: ['use'],
  8926. attribute(start, end, type, name, expression) {
  8927. return { start, end, type, name, expression };
  8928. },
  8929. allowedExpressionTypes: ['*'],
  8930. error: 'Data passed to actions must be an identifier (e.g. `foo`), a member expression ' +
  8931. '(e.g. `foo.bar` or `foo[baz]`), a method call (e.g. `foo()`), or a literal (e.g. `true` or `\'a string\'`'
  8932. },
  8933. Class: {
  8934. names: ['class'],
  8935. attribute(start, end, type, name, expression) {
  8936. return { start, end, type, name, expression };
  8937. },
  8938. allowedExpressionTypes: ['*'],
  8939. error: 'Data passed to class directives must be an expression'
  8940. },
  8941. };
  8942. const lookupByName = {};
  8943. Object.keys(DIRECTIVES).forEach(name => {
  8944. const directive = DIRECTIVES[name];
  8945. directive.names.forEach(type => lookupByName[type] = name);
  8946. });
  8947. function readExpression$1(parser, start, quoteMark) {
  8948. let i = start;
  8949. let escaped = false;
  8950. for (; i < parser.template.length; i += 1) {
  8951. const char = parser.template[i];
  8952. if (quoteMark) {
  8953. if (char === quoteMark) {
  8954. if (!escaped)
  8955. break;
  8956. }
  8957. else if (escaped) {
  8958. escaped = false;
  8959. }
  8960. else if (char === '\\') {
  8961. escaped = true;
  8962. }
  8963. }
  8964. else if (/[\s\/>]/.test(char)) {
  8965. break;
  8966. }
  8967. }
  8968. const expression = parseExpressionAt(parser.template.slice(0, i), start, {
  8969. ecmaVersion: 9,
  8970. });
  8971. parser.index = expression.end;
  8972. parser.allowWhitespace();
  8973. if (quoteMark)
  8974. parser.eat(quoteMark, true);
  8975. return expression;
  8976. }
  8977. function readDirective(parser, start, attrName) {
  8978. const [directiveName, name] = attrName.split(':');
  8979. if (name === undefined)
  8980. return; // No colon in the name
  8981. if (directiveName === '') {
  8982. // not a directive — :foo is short for foo={{foo}}
  8983. return {
  8984. start: start,
  8985. end: start + name.length + 1,
  8986. type: 'Attribute',
  8987. name,
  8988. value: getShorthandValue(start + 1, name)
  8989. };
  8990. }
  8991. const type = lookupByName[directiveName];
  8992. if (!type)
  8993. return; // not a registered directive
  8994. const directive = DIRECTIVES[type];
  8995. let expression = null;
  8996. if (parser.eat('=')) {
  8997. const quoteMark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null;
  8998. const expressionStart = parser.index;
  8999. try {
  9000. expression = readExpression$1(parser, expressionStart, quoteMark);
  9001. const allowed = directive.allowedExpressionTypes;
  9002. if (allowed[0] !== '*' && allowed.indexOf(expression.type) === -1) {
  9003. parser.error({
  9004. code: `invalid-directive-value`,
  9005. message: directive.error
  9006. }, expressionStart);
  9007. }
  9008. }
  9009. catch (err) {
  9010. if (parser.template[expressionStart] === '{') {
  9011. // assume the mistake was wrapping the directive arguments.
  9012. // this could yield false positives! but hopefully not too many
  9013. let message = 'directive values should not be wrapped';
  9014. const expressionEnd = parser.template.indexOf('}', expressionStart);
  9015. if (expressionEnd !== -1) {
  9016. const value = parser.template.slice(expressionStart + 1, expressionEnd);
  9017. message += ` — use '${value}', not '{${value}}'`;
  9018. }
  9019. parser.error({
  9020. code: `invalid-directive-value`,
  9021. message
  9022. }, expressionStart);
  9023. }
  9024. throw err;
  9025. }
  9026. }
  9027. return directive.attribute(start, parser.index, type, name, expression, directiveName);
  9028. }
  9029. function getShorthandValue(start, name) {
  9030. const end = start + name.length;
  9031. return [
  9032. {
  9033. type: 'AttributeShorthand',
  9034. start,
  9035. end,
  9036. expression: {
  9037. type: 'Identifier',
  9038. start,
  9039. end,
  9040. name,
  9041. },
  9042. },
  9043. ];
  9044. }
  9045. // https://dev.w3.org/html5/html-author/charref
  9046. var htmlEntities = {
  9047. CounterClockwiseContourIntegral: 8755,
  9048. ClockwiseContourIntegral: 8754,
  9049. DoubleLongLeftRightArrow: 10234,
  9050. DiacriticalDoubleAcute: 733,
  9051. NotSquareSupersetEqual: 8931,
  9052. CloseCurlyDoubleQuote: 8221,
  9053. DoubleContourIntegral: 8751,
  9054. FilledVerySmallSquare: 9642,
  9055. NegativeVeryThinSpace: 8203,
  9056. NotPrecedesSlantEqual: 8928,
  9057. NotRightTriangleEqual: 8941,
  9058. NotSucceedsSlantEqual: 8929,
  9059. CapitalDifferentialD: 8517,
  9060. DoubleLeftRightArrow: 8660,
  9061. DoubleLongRightArrow: 10233,
  9062. EmptyVerySmallSquare: 9643,
  9063. NestedGreaterGreater: 8811,
  9064. NotDoubleVerticalBar: 8742,
  9065. NotLeftTriangleEqual: 8940,
  9066. NotSquareSubsetEqual: 8930,
  9067. OpenCurlyDoubleQuote: 8220,
  9068. ReverseUpEquilibrium: 10607,
  9069. DoubleLongLeftArrow: 10232,
  9070. DownLeftRightVector: 10576,
  9071. LeftArrowRightArrow: 8646,
  9072. NegativeMediumSpace: 8203,
  9073. RightArrowLeftArrow: 8644,
  9074. SquareSupersetEqual: 8850,
  9075. leftrightsquigarrow: 8621,
  9076. DownRightTeeVector: 10591,
  9077. DownRightVectorBar: 10583,
  9078. LongLeftRightArrow: 10231,
  9079. Longleftrightarrow: 10234,
  9080. NegativeThickSpace: 8203,
  9081. PrecedesSlantEqual: 8828,
  9082. ReverseEquilibrium: 8651,
  9083. RightDoubleBracket: 10215,
  9084. RightDownTeeVector: 10589,
  9085. RightDownVectorBar: 10581,
  9086. RightTriangleEqual: 8885,
  9087. SquareIntersection: 8851,
  9088. SucceedsSlantEqual: 8829,
  9089. blacktriangleright: 9656,
  9090. longleftrightarrow: 10231,
  9091. DoubleUpDownArrow: 8661,
  9092. DoubleVerticalBar: 8741,
  9093. DownLeftTeeVector: 10590,
  9094. DownLeftVectorBar: 10582,
  9095. FilledSmallSquare: 9724,
  9096. GreaterSlantEqual: 10878,
  9097. LeftDoubleBracket: 10214,
  9098. LeftDownTeeVector: 10593,
  9099. LeftDownVectorBar: 10585,
  9100. LeftTriangleEqual: 8884,
  9101. NegativeThinSpace: 8203,
  9102. NotReverseElement: 8716,
  9103. NotTildeFullEqual: 8775,
  9104. RightAngleBracket: 10217,
  9105. RightUpDownVector: 10575,
  9106. SquareSubsetEqual: 8849,
  9107. VerticalSeparator: 10072,
  9108. blacktriangledown: 9662,
  9109. blacktriangleleft: 9666,
  9110. leftrightharpoons: 8651,
  9111. rightleftharpoons: 8652,
  9112. twoheadrightarrow: 8608,
  9113. DiacriticalAcute: 180,
  9114. DiacriticalGrave: 96,
  9115. DiacriticalTilde: 732,
  9116. DoubleRightArrow: 8658,
  9117. DownArrowUpArrow: 8693,
  9118. EmptySmallSquare: 9723,
  9119. GreaterEqualLess: 8923,
  9120. GreaterFullEqual: 8807,
  9121. LeftAngleBracket: 10216,
  9122. LeftUpDownVector: 10577,
  9123. LessEqualGreater: 8922,
  9124. NonBreakingSpace: 160,
  9125. NotRightTriangle: 8939,
  9126. NotSupersetEqual: 8841,
  9127. RightTriangleBar: 10704,
  9128. RightUpTeeVector: 10588,
  9129. RightUpVectorBar: 10580,
  9130. UnderParenthesis: 9181,
  9131. UpArrowDownArrow: 8645,
  9132. circlearrowright: 8635,
  9133. downharpoonright: 8642,
  9134. ntrianglerighteq: 8941,
  9135. rightharpoondown: 8641,
  9136. rightrightarrows: 8649,
  9137. twoheadleftarrow: 8606,
  9138. vartriangleright: 8883,
  9139. CloseCurlyQuote: 8217,
  9140. ContourIntegral: 8750,
  9141. DoubleDownArrow: 8659,
  9142. DoubleLeftArrow: 8656,
  9143. DownRightVector: 8641,
  9144. LeftRightVector: 10574,
  9145. LeftTriangleBar: 10703,
  9146. LeftUpTeeVector: 10592,
  9147. LeftUpVectorBar: 10584,
  9148. LowerRightArrow: 8600,
  9149. NotGreaterEqual: 8817,
  9150. NotGreaterTilde: 8821,
  9151. NotLeftTriangle: 8938,
  9152. OverParenthesis: 9180,
  9153. RightDownVector: 8642,
  9154. ShortRightArrow: 8594,
  9155. UpperRightArrow: 8599,
  9156. bigtriangledown: 9661,
  9157. circlearrowleft: 8634,
  9158. curvearrowright: 8631,
  9159. downharpoonleft: 8643,
  9160. leftharpoondown: 8637,
  9161. leftrightarrows: 8646,
  9162. nLeftrightarrow: 8654,
  9163. nleftrightarrow: 8622,
  9164. ntrianglelefteq: 8940,
  9165. rightleftarrows: 8644,
  9166. rightsquigarrow: 8605,
  9167. rightthreetimes: 8908,
  9168. straightepsilon: 1013,
  9169. trianglerighteq: 8885,
  9170. vartriangleleft: 8882,
  9171. DiacriticalDot: 729,
  9172. DoubleRightTee: 8872,
  9173. DownLeftVector: 8637,
  9174. GreaterGreater: 10914,
  9175. HorizontalLine: 9472,
  9176. InvisibleComma: 8291,
  9177. InvisibleTimes: 8290,
  9178. LeftDownVector: 8643,
  9179. LeftRightArrow: 8596,
  9180. Leftrightarrow: 8660,
  9181. LessSlantEqual: 10877,
  9182. LongRightArrow: 10230,
  9183. Longrightarrow: 10233,
  9184. LowerLeftArrow: 8601,
  9185. NestedLessLess: 8810,
  9186. NotGreaterLess: 8825,
  9187. NotLessGreater: 8824,
  9188. NotSubsetEqual: 8840,
  9189. NotVerticalBar: 8740,
  9190. OpenCurlyQuote: 8216,
  9191. ReverseElement: 8715,
  9192. RightTeeVector: 10587,
  9193. RightVectorBar: 10579,
  9194. ShortDownArrow: 8595,
  9195. ShortLeftArrow: 8592,
  9196. SquareSuperset: 8848,
  9197. TildeFullEqual: 8773,
  9198. UpperLeftArrow: 8598,
  9199. ZeroWidthSpace: 8203,
  9200. curvearrowleft: 8630,
  9201. doublebarwedge: 8966,
  9202. downdownarrows: 8650,
  9203. hookrightarrow: 8618,
  9204. leftleftarrows: 8647,
  9205. leftrightarrow: 8596,
  9206. leftthreetimes: 8907,
  9207. longrightarrow: 10230,
  9208. looparrowright: 8620,
  9209. nshortparallel: 8742,
  9210. ntriangleright: 8939,
  9211. rightarrowtail: 8611,
  9212. rightharpoonup: 8640,
  9213. trianglelefteq: 8884,
  9214. upharpoonright: 8638,
  9215. ApplyFunction: 8289,
  9216. DifferentialD: 8518,
  9217. DoubleLeftTee: 10980,
  9218. DoubleUpArrow: 8657,
  9219. LeftTeeVector: 10586,
  9220. LeftVectorBar: 10578,
  9221. LessFullEqual: 8806,
  9222. LongLeftArrow: 10229,
  9223. Longleftarrow: 10232,
  9224. NotTildeEqual: 8772,
  9225. NotTildeTilde: 8777,
  9226. Poincareplane: 8460,
  9227. PrecedesEqual: 10927,
  9228. PrecedesTilde: 8830,
  9229. RightArrowBar: 8677,
  9230. RightTeeArrow: 8614,
  9231. RightTriangle: 8883,
  9232. RightUpVector: 8638,
  9233. SucceedsEqual: 10928,
  9234. SucceedsTilde: 8831,
  9235. SupersetEqual: 8839,
  9236. UpEquilibrium: 10606,
  9237. VerticalTilde: 8768,
  9238. VeryThinSpace: 8202,
  9239. bigtriangleup: 9651,
  9240. blacktriangle: 9652,
  9241. divideontimes: 8903,
  9242. fallingdotseq: 8786,
  9243. hookleftarrow: 8617,
  9244. leftarrowtail: 8610,
  9245. leftharpoonup: 8636,
  9246. longleftarrow: 10229,
  9247. looparrowleft: 8619,
  9248. measuredangle: 8737,
  9249. ntriangleleft: 8938,
  9250. shortparallel: 8741,
  9251. smallsetminus: 8726,
  9252. triangleright: 9657,
  9253. upharpoonleft: 8639,
  9254. DownArrowBar: 10515,
  9255. DownTeeArrow: 8615,
  9256. ExponentialE: 8519,
  9257. GreaterEqual: 8805,
  9258. GreaterTilde: 8819,
  9259. HilbertSpace: 8459,
  9260. HumpDownHump: 8782,
  9261. Intersection: 8898,
  9262. LeftArrowBar: 8676,
  9263. LeftTeeArrow: 8612,
  9264. LeftTriangle: 8882,
  9265. LeftUpVector: 8639,
  9266. NotCongruent: 8802,
  9267. NotLessEqual: 8816,
  9268. NotLessTilde: 8820,
  9269. Proportional: 8733,
  9270. RightCeiling: 8969,
  9271. RoundImplies: 10608,
  9272. ShortUpArrow: 8593,
  9273. SquareSubset: 8847,
  9274. UnderBracket: 9141,
  9275. VerticalLine: 124,
  9276. blacklozenge: 10731,
  9277. exponentiale: 8519,
  9278. risingdotseq: 8787,
  9279. triangledown: 9663,
  9280. triangleleft: 9667,
  9281. CircleMinus: 8854,
  9282. CircleTimes: 8855,
  9283. Equilibrium: 8652,
  9284. GreaterLess: 8823,
  9285. LeftCeiling: 8968,
  9286. LessGreater: 8822,
  9287. MediumSpace: 8287,
  9288. NotPrecedes: 8832,
  9289. NotSucceeds: 8833,
  9290. OverBracket: 9140,
  9291. RightVector: 8640,
  9292. Rrightarrow: 8667,
  9293. RuleDelayed: 10740,
  9294. SmallCircle: 8728,
  9295. SquareUnion: 8852,
  9296. SubsetEqual: 8838,
  9297. UpDownArrow: 8597,
  9298. Updownarrow: 8661,
  9299. VerticalBar: 8739,
  9300. backepsilon: 1014,
  9301. blacksquare: 9642,
  9302. circledcirc: 8858,
  9303. circleddash: 8861,
  9304. curlyeqprec: 8926,
  9305. curlyeqsucc: 8927,
  9306. diamondsuit: 9830,
  9307. eqslantless: 10901,
  9308. expectation: 8496,
  9309. nRightarrow: 8655,
  9310. nrightarrow: 8603,
  9311. preccurlyeq: 8828,
  9312. precnapprox: 10937,
  9313. quaternions: 8461,
  9314. straightphi: 981,
  9315. succcurlyeq: 8829,
  9316. succnapprox: 10938,
  9317. thickapprox: 8776,
  9318. updownarrow: 8597,
  9319. Bernoullis: 8492,
  9320. CirclePlus: 8853,
  9321. EqualTilde: 8770,
  9322. Fouriertrf: 8497,
  9323. ImaginaryI: 8520,
  9324. Laplacetrf: 8466,
  9325. LeftVector: 8636,
  9326. Lleftarrow: 8666,
  9327. NotElement: 8713,
  9328. NotGreater: 8815,
  9329. Proportion: 8759,
  9330. RightArrow: 8594,
  9331. RightFloor: 8971,
  9332. Rightarrow: 8658,
  9333. TildeEqual: 8771,
  9334. TildeTilde: 8776,
  9335. UnderBrace: 9183,
  9336. UpArrowBar: 10514,
  9337. UpTeeArrow: 8613,
  9338. circledast: 8859,
  9339. complement: 8705,
  9340. curlywedge: 8911,
  9341. eqslantgtr: 10902,
  9342. gtreqqless: 10892,
  9343. lessapprox: 10885,
  9344. lesseqqgtr: 10891,
  9345. lmoustache: 9136,
  9346. longmapsto: 10236,
  9347. mapstodown: 8615,
  9348. mapstoleft: 8612,
  9349. nLeftarrow: 8653,
  9350. nleftarrow: 8602,
  9351. precapprox: 10935,
  9352. rightarrow: 8594,
  9353. rmoustache: 9137,
  9354. sqsubseteq: 8849,
  9355. sqsupseteq: 8850,
  9356. subsetneqq: 10955,
  9357. succapprox: 10936,
  9358. supsetneqq: 10956,
  9359. upuparrows: 8648,
  9360. varepsilon: 949,
  9361. varnothing: 8709,
  9362. Backslash: 8726,
  9363. CenterDot: 183,
  9364. CircleDot: 8857,
  9365. Congruent: 8801,
  9366. Coproduct: 8720,
  9367. DoubleDot: 168,
  9368. DownArrow: 8595,
  9369. DownBreve: 785,
  9370. Downarrow: 8659,
  9371. HumpEqual: 8783,
  9372. LeftArrow: 8592,
  9373. LeftFloor: 8970,
  9374. Leftarrow: 8656,
  9375. LessTilde: 8818,
  9376. Mellintrf: 8499,
  9377. MinusPlus: 8723,
  9378. NotCupCap: 8813,
  9379. NotExists: 8708,
  9380. OverBrace: 9182,
  9381. PlusMinus: 177,
  9382. Therefore: 8756,
  9383. ThinSpace: 8201,
  9384. TripleDot: 8411,
  9385. UnionPlus: 8846,
  9386. backprime: 8245,
  9387. backsimeq: 8909,
  9388. bigotimes: 10754,
  9389. centerdot: 183,
  9390. checkmark: 10003,
  9391. complexes: 8450,
  9392. dotsquare: 8865,
  9393. downarrow: 8595,
  9394. gtrapprox: 10886,
  9395. gtreqless: 8923,
  9396. heartsuit: 9829,
  9397. leftarrow: 8592,
  9398. lesseqgtr: 8922,
  9399. nparallel: 8742,
  9400. nshortmid: 8740,
  9401. nsubseteq: 8840,
  9402. nsupseteq: 8841,
  9403. pitchfork: 8916,
  9404. rationals: 8474,
  9405. spadesuit: 9824,
  9406. subseteqq: 10949,
  9407. subsetneq: 8842,
  9408. supseteqq: 10950,
  9409. supsetneq: 8843,
  9410. therefore: 8756,
  9411. triangleq: 8796,
  9412. varpropto: 8733,
  9413. DDotrahd: 10513,
  9414. DotEqual: 8784,
  9415. Integral: 8747,
  9416. LessLess: 10913,
  9417. NotEqual: 8800,
  9418. NotTilde: 8769,
  9419. PartialD: 8706,
  9420. Precedes: 8826,
  9421. RightTee: 8866,
  9422. Succeeds: 8827,
  9423. SuchThat: 8715,
  9424. Superset: 8835,
  9425. Uarrocir: 10569,
  9426. UnderBar: 818,
  9427. andslope: 10840,
  9428. angmsdaa: 10664,
  9429. angmsdab: 10665,
  9430. angmsdac: 10666,
  9431. angmsdad: 10667,
  9432. angmsdae: 10668,
  9433. angmsdaf: 10669,
  9434. angmsdag: 10670,
  9435. angmsdah: 10671,
  9436. angrtvbd: 10653,
  9437. approxeq: 8778,
  9438. awconint: 8755,
  9439. backcong: 8780,
  9440. barwedge: 8965,
  9441. bbrktbrk: 9142,
  9442. bigoplus: 10753,
  9443. bigsqcup: 10758,
  9444. biguplus: 10756,
  9445. bigwedge: 8896,
  9446. boxminus: 8863,
  9447. boxtimes: 8864,
  9448. capbrcup: 10825,
  9449. circledR: 174,
  9450. circledS: 9416,
  9451. cirfnint: 10768,
  9452. clubsuit: 9827,
  9453. cupbrcap: 10824,
  9454. curlyvee: 8910,
  9455. cwconint: 8754,
  9456. doteqdot: 8785,
  9457. dotminus: 8760,
  9458. drbkarow: 10512,
  9459. dzigrarr: 10239,
  9460. elinters: 9191,
  9461. emptyset: 8709,
  9462. eqvparsl: 10725,
  9463. fpartint: 10765,
  9464. geqslant: 10878,
  9465. gesdotol: 10884,
  9466. gnapprox: 10890,
  9467. hksearow: 10533,
  9468. hkswarow: 10534,
  9469. imagline: 8464,
  9470. imagpart: 8465,
  9471. infintie: 10717,
  9472. integers: 8484,
  9473. intercal: 8890,
  9474. intlarhk: 10775,
  9475. laemptyv: 10676,
  9476. ldrushar: 10571,
  9477. leqslant: 10877,
  9478. lesdotor: 10883,
  9479. llcorner: 8990,
  9480. lnapprox: 10889,
  9481. lrcorner: 8991,
  9482. lurdshar: 10570,
  9483. mapstoup: 8613,
  9484. multimap: 8888,
  9485. naturals: 8469,
  9486. otimesas: 10806,
  9487. parallel: 8741,
  9488. plusacir: 10787,
  9489. pointint: 10773,
  9490. precneqq: 10933,
  9491. precnsim: 8936,
  9492. profalar: 9006,
  9493. profline: 8978,
  9494. profsurf: 8979,
  9495. raemptyv: 10675,
  9496. realpart: 8476,
  9497. rppolint: 10770,
  9498. rtriltri: 10702,
  9499. scpolint: 10771,
  9500. setminus: 8726,
  9501. shortmid: 8739,
  9502. smeparsl: 10724,
  9503. sqsubset: 8847,
  9504. sqsupset: 8848,
  9505. subseteq: 8838,
  9506. succneqq: 10934,
  9507. succnsim: 8937,
  9508. supseteq: 8839,
  9509. thetasym: 977,
  9510. thicksim: 8764,
  9511. timesbar: 10801,
  9512. triangle: 9653,
  9513. triminus: 10810,
  9514. trpezium: 9186,
  9515. ulcorner: 8988,
  9516. urcorner: 8989,
  9517. varkappa: 1008,
  9518. varsigma: 962,
  9519. vartheta: 977,
  9520. Because: 8757,
  9521. Cayleys: 8493,
  9522. Cconint: 8752,
  9523. Cedilla: 184,
  9524. Diamond: 8900,
  9525. DownTee: 8868,
  9526. Element: 8712,
  9527. Epsilon: 917,
  9528. Implies: 8658,
  9529. LeftTee: 8867,
  9530. NewLine: 10,
  9531. NoBreak: 8288,
  9532. NotLess: 8814,
  9533. Omicron: 927,
  9534. OverBar: 175,
  9535. Product: 8719,
  9536. UpArrow: 8593,
  9537. Uparrow: 8657,
  9538. Upsilon: 933,
  9539. alefsym: 8501,
  9540. angrtvb: 8894,
  9541. angzarr: 9084,
  9542. asympeq: 8781,
  9543. backsim: 8765,
  9544. because: 8757,
  9545. bemptyv: 10672,
  9546. between: 8812,
  9547. bigcirc: 9711,
  9548. bigodot: 10752,
  9549. bigstar: 9733,
  9550. boxplus: 8862,
  9551. ccupssm: 10832,
  9552. cemptyv: 10674,
  9553. cirscir: 10690,
  9554. coloneq: 8788,
  9555. congdot: 10861,
  9556. cudarrl: 10552,
  9557. cudarrr: 10549,
  9558. cularrp: 10557,
  9559. curarrm: 10556,
  9560. dbkarow: 10511,
  9561. ddagger: 8225,
  9562. ddotseq: 10871,
  9563. demptyv: 10673,
  9564. diamond: 8900,
  9565. digamma: 989,
  9566. dotplus: 8724,
  9567. dwangle: 10662,
  9568. epsilon: 949,
  9569. eqcolon: 8789,
  9570. equivDD: 10872,
  9571. gesdoto: 10882,
  9572. gtquest: 10876,
  9573. gtrless: 8823,
  9574. harrcir: 10568,
  9575. intprod: 10812,
  9576. isindot: 8949,
  9577. larrbfs: 10527,
  9578. larrsim: 10611,
  9579. lbrksld: 10639,
  9580. lbrkslu: 10637,
  9581. ldrdhar: 10599,
  9582. lesdoto: 10881,
  9583. lessdot: 8918,
  9584. lessgtr: 8822,
  9585. lesssim: 8818,
  9586. lotimes: 10804,
  9587. lozenge: 9674,
  9588. ltquest: 10875,
  9589. luruhar: 10598,
  9590. maltese: 10016,
  9591. minusdu: 10794,
  9592. napprox: 8777,
  9593. natural: 9838,
  9594. nearrow: 8599,
  9595. nexists: 8708,
  9596. notinva: 8713,
  9597. notinvb: 8951,
  9598. notinvc: 8950,
  9599. notniva: 8716,
  9600. notnivb: 8958,
  9601. notnivc: 8957,
  9602. npolint: 10772,
  9603. nsqsube: 8930,
  9604. nsqsupe: 8931,
  9605. nvinfin: 10718,
  9606. nwarrow: 8598,
  9607. olcross: 10683,
  9608. omicron: 959,
  9609. orderof: 8500,
  9610. orslope: 10839,
  9611. pertenk: 8241,
  9612. planckh: 8462,
  9613. pluscir: 10786,
  9614. plussim: 10790,
  9615. plustwo: 10791,
  9616. precsim: 8830,
  9617. quatint: 10774,
  9618. questeq: 8799,
  9619. rarrbfs: 10528,
  9620. rarrsim: 10612,
  9621. rbrksld: 10638,
  9622. rbrkslu: 10640,
  9623. rdldhar: 10601,
  9624. realine: 8475,
  9625. rotimes: 10805,
  9626. ruluhar: 10600,
  9627. searrow: 8600,
  9628. simplus: 10788,
  9629. simrarr: 10610,
  9630. subedot: 10947,
  9631. submult: 10945,
  9632. subplus: 10943,
  9633. subrarr: 10617,
  9634. succsim: 8831,
  9635. supdsub: 10968,
  9636. supedot: 10948,
  9637. suphsub: 10967,
  9638. suplarr: 10619,
  9639. supmult: 10946,
  9640. supplus: 10944,
  9641. swarrow: 8601,
  9642. topfork: 10970,
  9643. triplus: 10809,
  9644. tritime: 10811,
  9645. uparrow: 8593,
  9646. upsilon: 965,
  9647. uwangle: 10663,
  9648. vzigzag: 10650,
  9649. zigrarr: 8669,
  9650. Aacute: 193,
  9651. Abreve: 258,
  9652. Agrave: 192,
  9653. Assign: 8788,
  9654. Atilde: 195,
  9655. Barwed: 8966,
  9656. Bumpeq: 8782,
  9657. Cacute: 262,
  9658. Ccaron: 268,
  9659. Ccedil: 199,
  9660. Colone: 10868,
  9661. Conint: 8751,
  9662. CupCap: 8781,
  9663. Dagger: 8225,
  9664. Dcaron: 270,
  9665. DotDot: 8412,
  9666. Dstrok: 272,
  9667. Eacute: 201,
  9668. Ecaron: 282,
  9669. Egrave: 200,
  9670. Exists: 8707,
  9671. ForAll: 8704,
  9672. Gammad: 988,
  9673. Gbreve: 286,
  9674. Gcedil: 290,
  9675. HARDcy: 1066,
  9676. Hstrok: 294,
  9677. Iacute: 205,
  9678. Igrave: 204,
  9679. Itilde: 296,
  9680. Jsercy: 1032,
  9681. Kcedil: 310,
  9682. Lacute: 313,
  9683. Lambda: 923,
  9684. Lcaron: 317,
  9685. Lcedil: 315,
  9686. Lmidot: 319,
  9687. Lstrok: 321,
  9688. Nacute: 323,
  9689. Ncaron: 327,
  9690. Ncedil: 325,
  9691. Ntilde: 209,
  9692. Oacute: 211,
  9693. Odblac: 336,
  9694. Ograve: 210,
  9695. Oslash: 216,
  9696. Otilde: 213,
  9697. Otimes: 10807,
  9698. Racute: 340,
  9699. Rarrtl: 10518,
  9700. Rcaron: 344,
  9701. Rcedil: 342,
  9702. SHCHcy: 1065,
  9703. SOFTcy: 1068,
  9704. Sacute: 346,
  9705. Scaron: 352,
  9706. Scedil: 350,
  9707. Square: 9633,
  9708. Subset: 8912,
  9709. Supset: 8913,
  9710. Tcaron: 356,
  9711. Tcedil: 354,
  9712. Tstrok: 358,
  9713. Uacute: 218,
  9714. Ubreve: 364,
  9715. Udblac: 368,
  9716. Ugrave: 217,
  9717. Utilde: 360,
  9718. Vdashl: 10982,
  9719. Verbar: 8214,
  9720. Vvdash: 8874,
  9721. Yacute: 221,
  9722. Zacute: 377,
  9723. Zcaron: 381,
  9724. aacute: 225,
  9725. abreve: 259,
  9726. agrave: 224,
  9727. andand: 10837,
  9728. angmsd: 8737,
  9729. angsph: 8738,
  9730. apacir: 10863,
  9731. approx: 8776,
  9732. atilde: 227,
  9733. barvee: 8893,
  9734. barwed: 8965,
  9735. becaus: 8757,
  9736. bernou: 8492,
  9737. bigcap: 8898,
  9738. bigcup: 8899,
  9739. bigvee: 8897,
  9740. bkarow: 10509,
  9741. bottom: 8869,
  9742. bowtie: 8904,
  9743. boxbox: 10697,
  9744. bprime: 8245,
  9745. brvbar: 166,
  9746. bullet: 8226,
  9747. bumpeq: 8783,
  9748. cacute: 263,
  9749. capand: 10820,
  9750. capcap: 10827,
  9751. capcup: 10823,
  9752. capdot: 10816,
  9753. ccaron: 269,
  9754. ccedil: 231,
  9755. circeq: 8791,
  9756. cirmid: 10991,
  9757. colone: 8788,
  9758. commat: 64,
  9759. compfn: 8728,
  9760. conint: 8750,
  9761. coprod: 8720,
  9762. copysr: 8471,
  9763. cularr: 8630,
  9764. cupcap: 10822,
  9765. cupcup: 10826,
  9766. cupdot: 8845,
  9767. curarr: 8631,
  9768. curren: 164,
  9769. cylcty: 9005,
  9770. dagger: 8224,
  9771. daleth: 8504,
  9772. dcaron: 271,
  9773. dfisht: 10623,
  9774. divide: 247,
  9775. divonx: 8903,
  9776. dlcorn: 8990,
  9777. dlcrop: 8973,
  9778. dollar: 36,
  9779. drcorn: 8991,
  9780. drcrop: 8972,
  9781. dstrok: 273,
  9782. eacute: 233,
  9783. easter: 10862,
  9784. ecaron: 283,
  9785. ecolon: 8789,
  9786. egrave: 232,
  9787. egsdot: 10904,
  9788. elsdot: 10903,
  9789. emptyv: 8709,
  9790. emsp13: 8196,
  9791. emsp14: 8197,
  9792. eparsl: 10723,
  9793. eqcirc: 8790,
  9794. equals: 61,
  9795. equest: 8799,
  9796. female: 9792,
  9797. ffilig: 64259,
  9798. ffllig: 64260,
  9799. forall: 8704,
  9800. frac12: 189,
  9801. frac13: 8531,
  9802. frac14: 188,
  9803. frac15: 8533,
  9804. frac16: 8537,
  9805. frac18: 8539,
  9806. frac23: 8532,
  9807. frac25: 8534,
  9808. frac34: 190,
  9809. frac35: 8535,
  9810. frac38: 8540,
  9811. frac45: 8536,
  9812. frac56: 8538,
  9813. frac58: 8541,
  9814. frac78: 8542,
  9815. gacute: 501,
  9816. gammad: 989,
  9817. gbreve: 287,
  9818. gesdot: 10880,
  9819. gesles: 10900,
  9820. gtlPar: 10645,
  9821. gtrarr: 10616,
  9822. gtrdot: 8919,
  9823. gtrsim: 8819,
  9824. hairsp: 8202,
  9825. hamilt: 8459,
  9826. hardcy: 1098,
  9827. hearts: 9829,
  9828. hellip: 8230,
  9829. hercon: 8889,
  9830. homtht: 8763,
  9831. horbar: 8213,
  9832. hslash: 8463,
  9833. hstrok: 295,
  9834. hybull: 8259,
  9835. hyphen: 8208,
  9836. iacute: 237,
  9837. igrave: 236,
  9838. iiiint: 10764,
  9839. iinfin: 10716,
  9840. incare: 8453,
  9841. inodot: 305,
  9842. intcal: 8890,
  9843. iquest: 191,
  9844. isinsv: 8947,
  9845. itilde: 297,
  9846. jsercy: 1112,
  9847. kappav: 1008,
  9848. kcedil: 311,
  9849. kgreen: 312,
  9850. lAtail: 10523,
  9851. lacute: 314,
  9852. lagran: 8466,
  9853. lambda: 955,
  9854. langle: 10216,
  9855. larrfs: 10525,
  9856. larrhk: 8617,
  9857. larrlp: 8619,
  9858. larrpl: 10553,
  9859. larrtl: 8610,
  9860. latail: 10521,
  9861. lbrace: 123,
  9862. lbrack: 91,
  9863. lcaron: 318,
  9864. lcedil: 316,
  9865. ldquor: 8222,
  9866. lesdot: 10879,
  9867. lesges: 10899,
  9868. lfisht: 10620,
  9869. lfloor: 8970,
  9870. lharul: 10602,
  9871. llhard: 10603,
  9872. lmidot: 320,
  9873. lmoust: 9136,
  9874. loplus: 10797,
  9875. lowast: 8727,
  9876. lowbar: 95,
  9877. lparlt: 10643,
  9878. lrhard: 10605,
  9879. lsaquo: 8249,
  9880. lsquor: 8218,
  9881. lstrok: 322,
  9882. lthree: 8907,
  9883. ltimes: 8905,
  9884. ltlarr: 10614,
  9885. ltrPar: 10646,
  9886. mapsto: 8614,
  9887. marker: 9646,
  9888. mcomma: 10793,
  9889. midast: 42,
  9890. midcir: 10992,
  9891. middot: 183,
  9892. minusb: 8863,
  9893. minusd: 8760,
  9894. mnplus: 8723,
  9895. models: 8871,
  9896. mstpos: 8766,
  9897. nVDash: 8879,
  9898. nVdash: 8878,
  9899. nacute: 324,
  9900. ncaron: 328,
  9901. ncedil: 326,
  9902. nearhk: 10532,
  9903. nequiv: 8802,
  9904. nesear: 10536,
  9905. nexist: 8708,
  9906. nltrie: 8940,
  9907. nprcue: 8928,
  9908. nrtrie: 8941,
  9909. nsccue: 8929,
  9910. nsimeq: 8772,
  9911. ntilde: 241,
  9912. numero: 8470,
  9913. nvDash: 8877,
  9914. nvHarr: 10500,
  9915. nvdash: 8876,
  9916. nvlArr: 10498,
  9917. nvrArr: 10499,
  9918. nwarhk: 10531,
  9919. nwnear: 10535,
  9920. oacute: 243,
  9921. odblac: 337,
  9922. odsold: 10684,
  9923. ograve: 242,
  9924. ominus: 8854,
  9925. origof: 8886,
  9926. oslash: 248,
  9927. otilde: 245,
  9928. otimes: 8855,
  9929. parsim: 10995,
  9930. percnt: 37,
  9931. period: 46,
  9932. permil: 8240,
  9933. phmmat: 8499,
  9934. planck: 8463,
  9935. plankv: 8463,
  9936. plusdo: 8724,
  9937. plusdu: 10789,
  9938. plusmn: 177,
  9939. preceq: 10927,
  9940. primes: 8473,
  9941. prnsim: 8936,
  9942. propto: 8733,
  9943. prurel: 8880,
  9944. puncsp: 8200,
  9945. qprime: 8279,
  9946. rAtail: 10524,
  9947. racute: 341,
  9948. rangle: 10217,
  9949. rarrap: 10613,
  9950. rarrfs: 10526,
  9951. rarrhk: 8618,
  9952. rarrlp: 8620,
  9953. rarrpl: 10565,
  9954. rarrtl: 8611,
  9955. ratail: 10522,
  9956. rbrace: 125,
  9957. rbrack: 93,
  9958. rcaron: 345,
  9959. rcedil: 343,
  9960. rdquor: 8221,
  9961. rfisht: 10621,
  9962. rfloor: 8971,
  9963. rharul: 10604,
  9964. rmoust: 9137,
  9965. roplus: 10798,
  9966. rpargt: 10644,
  9967. rsaquo: 8250,
  9968. rsquor: 8217,
  9969. rthree: 8908,
  9970. rtimes: 8906,
  9971. sacute: 347,
  9972. scaron: 353,
  9973. scedil: 351,
  9974. scnsim: 8937,
  9975. searhk: 10533,
  9976. seswar: 10537,
  9977. sfrown: 8994,
  9978. shchcy: 1097,
  9979. sigmaf: 962,
  9980. sigmav: 962,
  9981. simdot: 10858,
  9982. smashp: 10803,
  9983. softcy: 1100,
  9984. solbar: 9023,
  9985. spades: 9824,
  9986. sqsube: 8849,
  9987. sqsupe: 8850,
  9988. square: 9633,
  9989. squarf: 9642,
  9990. ssetmn: 8726,
  9991. ssmile: 8995,
  9992. sstarf: 8902,
  9993. subdot: 10941,
  9994. subset: 8834,
  9995. subsim: 10951,
  9996. subsub: 10965,
  9997. subsup: 10963,
  9998. succeq: 10928,
  9999. supdot: 10942,
  10000. supset: 8835,
  10001. supsim: 10952,
  10002. supsub: 10964,
  10003. supsup: 10966,
  10004. swarhk: 10534,
  10005. swnwar: 10538,
  10006. target: 8982,
  10007. tcaron: 357,
  10008. tcedil: 355,
  10009. telrec: 8981,
  10010. there4: 8756,
  10011. thetav: 977,
  10012. thinsp: 8201,
  10013. thksim: 8764,
  10014. timesb: 8864,
  10015. timesd: 10800,
  10016. topbot: 9014,
  10017. topcir: 10993,
  10018. tprime: 8244,
  10019. tridot: 9708,
  10020. tstrok: 359,
  10021. uacute: 250,
  10022. ubreve: 365,
  10023. udblac: 369,
  10024. ufisht: 10622,
  10025. ugrave: 249,
  10026. ulcorn: 8988,
  10027. ulcrop: 8975,
  10028. urcorn: 8989,
  10029. urcrop: 8974,
  10030. utilde: 361,
  10031. vangrt: 10652,
  10032. varphi: 966,
  10033. varrho: 1009,
  10034. veebar: 8891,
  10035. vellip: 8942,
  10036. verbar: 124,
  10037. wedbar: 10847,
  10038. wedgeq: 8793,
  10039. weierp: 8472,
  10040. wreath: 8768,
  10041. xoplus: 10753,
  10042. xotime: 10754,
  10043. xsqcup: 10758,
  10044. xuplus: 10756,
  10045. xwedge: 8896,
  10046. yacute: 253,
  10047. zacute: 378,
  10048. zcaron: 382,
  10049. zeetrf: 8488,
  10050. AElig: 198,
  10051. Acirc: 194,
  10052. Alpha: 913,
  10053. Amacr: 256,
  10054. Aogon: 260,
  10055. Aring: 197,
  10056. Breve: 728,
  10057. Ccirc: 264,
  10058. Colon: 8759,
  10059. Cross: 10799,
  10060. Dashv: 10980,
  10061. Delta: 916,
  10062. Ecirc: 202,
  10063. Emacr: 274,
  10064. Eogon: 280,
  10065. Equal: 10869,
  10066. Gamma: 915,
  10067. Gcirc: 284,
  10068. Hacek: 711,
  10069. Hcirc: 292,
  10070. IJlig: 306,
  10071. Icirc: 206,
  10072. Imacr: 298,
  10073. Iogon: 302,
  10074. Iukcy: 1030,
  10075. Jcirc: 308,
  10076. Jukcy: 1028,
  10077. Kappa: 922,
  10078. OElig: 338,
  10079. Ocirc: 212,
  10080. Omacr: 332,
  10081. Omega: 937,
  10082. Prime: 8243,
  10083. RBarr: 10512,
  10084. Scirc: 348,
  10085. Sigma: 931,
  10086. THORN: 222,
  10087. TRADE: 8482,
  10088. TSHcy: 1035,
  10089. Theta: 920,
  10090. Tilde: 8764,
  10091. Ubrcy: 1038,
  10092. Ucirc: 219,
  10093. Umacr: 362,
  10094. Union: 8899,
  10095. Uogon: 370,
  10096. UpTee: 8869,
  10097. Uring: 366,
  10098. VDash: 8875,
  10099. Vdash: 8873,
  10100. Wcirc: 372,
  10101. Wedge: 8896,
  10102. Ycirc: 374,
  10103. acirc: 226,
  10104. acute: 180,
  10105. aelig: 230,
  10106. aleph: 8501,
  10107. alpha: 945,
  10108. amacr: 257,
  10109. amalg: 10815,
  10110. angle: 8736,
  10111. angrt: 8735,
  10112. angst: 8491,
  10113. aogon: 261,
  10114. aring: 229,
  10115. asymp: 8776,
  10116. awint: 10769,
  10117. bcong: 8780,
  10118. bdquo: 8222,
  10119. bepsi: 1014,
  10120. blank: 9251,
  10121. blk12: 9618,
  10122. blk14: 9617,
  10123. blk34: 9619,
  10124. block: 9608,
  10125. boxDL: 9559,
  10126. boxDR: 9556,
  10127. boxDl: 9558,
  10128. boxDr: 9555,
  10129. boxHD: 9574,
  10130. boxHU: 9577,
  10131. boxHd: 9572,
  10132. boxHu: 9575,
  10133. boxUL: 9565,
  10134. boxUR: 9562,
  10135. boxUl: 9564,
  10136. boxUr: 9561,
  10137. boxVH: 9580,
  10138. boxVL: 9571,
  10139. boxVR: 9568,
  10140. boxVh: 9579,
  10141. boxVl: 9570,
  10142. boxVr: 9567,
  10143. boxdL: 9557,
  10144. boxdR: 9554,
  10145. boxdl: 9488,
  10146. boxdr: 9484,
  10147. boxhD: 9573,
  10148. boxhU: 9576,
  10149. boxhd: 9516,
  10150. boxhu: 9524,
  10151. boxuL: 9563,
  10152. boxuR: 9560,
  10153. boxul: 9496,
  10154. boxur: 9492,
  10155. boxvH: 9578,
  10156. boxvL: 9569,
  10157. boxvR: 9566,
  10158. boxvh: 9532,
  10159. boxvl: 9508,
  10160. boxvr: 9500,
  10161. breve: 728,
  10162. bsemi: 8271,
  10163. bsime: 8909,
  10164. bsolb: 10693,
  10165. bumpE: 10926,
  10166. bumpe: 8783,
  10167. caret: 8257,
  10168. caron: 711,
  10169. ccaps: 10829,
  10170. ccirc: 265,
  10171. ccups: 10828,
  10172. cedil: 184,
  10173. check: 10003,
  10174. clubs: 9827,
  10175. colon: 58,
  10176. comma: 44,
  10177. crarr: 8629,
  10178. cross: 10007,
  10179. csube: 10961,
  10180. csupe: 10962,
  10181. ctdot: 8943,
  10182. cuepr: 8926,
  10183. cuesc: 8927,
  10184. cupor: 10821,
  10185. cuvee: 8910,
  10186. cuwed: 8911,
  10187. cwint: 8753,
  10188. dashv: 8867,
  10189. dblac: 733,
  10190. ddarr: 8650,
  10191. delta: 948,
  10192. dharl: 8643,
  10193. dharr: 8642,
  10194. diams: 9830,
  10195. disin: 8946,
  10196. doteq: 8784,
  10197. dtdot: 8945,
  10198. dtrif: 9662,
  10199. duarr: 8693,
  10200. duhar: 10607,
  10201. eDDot: 10871,
  10202. ecirc: 234,
  10203. efDot: 8786,
  10204. emacr: 275,
  10205. empty: 8709,
  10206. eogon: 281,
  10207. eplus: 10865,
  10208. epsiv: 949,
  10209. eqsim: 8770,
  10210. equiv: 8801,
  10211. erDot: 8787,
  10212. erarr: 10609,
  10213. esdot: 8784,
  10214. exist: 8707,
  10215. fflig: 64256,
  10216. filig: 64257,
  10217. fllig: 64258,
  10218. fltns: 9649,
  10219. forkv: 10969,
  10220. frasl: 8260,
  10221. frown: 8994,
  10222. gamma: 947,
  10223. gcirc: 285,
  10224. gescc: 10921,
  10225. gimel: 8503,
  10226. gneqq: 8809,
  10227. gnsim: 8935,
  10228. grave: 96,
  10229. gsime: 10894,
  10230. gsiml: 10896,
  10231. gtcir: 10874,
  10232. gtdot: 8919,
  10233. harrw: 8621,
  10234. hcirc: 293,
  10235. hoarr: 8703,
  10236. icirc: 238,
  10237. iexcl: 161,
  10238. iiint: 8749,
  10239. iiota: 8489,
  10240. ijlig: 307,
  10241. imacr: 299,
  10242. image: 8465,
  10243. imath: 305,
  10244. imped: 437,
  10245. infin: 8734,
  10246. iogon: 303,
  10247. iprod: 10812,
  10248. isinE: 8953,
  10249. isins: 8948,
  10250. isinv: 8712,
  10251. iukcy: 1110,
  10252. jcirc: 309,
  10253. jmath: 567,
  10254. jukcy: 1108,
  10255. kappa: 954,
  10256. lAarr: 8666,
  10257. lBarr: 10510,
  10258. langd: 10641,
  10259. laquo: 171,
  10260. larrb: 8676,
  10261. lbarr: 10508,
  10262. lbbrk: 10098,
  10263. lbrke: 10635,
  10264. lceil: 8968,
  10265. ldquo: 8220,
  10266. lescc: 10920,
  10267. lhard: 8637,
  10268. lharu: 8636,
  10269. lhblk: 9604,
  10270. llarr: 8647,
  10271. lltri: 9722,
  10272. lneqq: 8808,
  10273. lnsim: 8934,
  10274. loang: 10220,
  10275. loarr: 8701,
  10276. lobrk: 10214,
  10277. lopar: 10629,
  10278. lrarr: 8646,
  10279. lrhar: 8651,
  10280. lrtri: 8895,
  10281. lsime: 10893,
  10282. lsimg: 10895,
  10283. lsquo: 8216,
  10284. ltcir: 10873,
  10285. ltdot: 8918,
  10286. ltrie: 8884,
  10287. ltrif: 9666,
  10288. mDDot: 8762,
  10289. mdash: 8212,
  10290. micro: 181,
  10291. minus: 8722,
  10292. mumap: 8888,
  10293. nabla: 8711,
  10294. napos: 329,
  10295. natur: 9838,
  10296. ncong: 8775,
  10297. ndash: 8211,
  10298. neArr: 8663,
  10299. nearr: 8599,
  10300. ngsim: 8821,
  10301. nhArr: 8654,
  10302. nharr: 8622,
  10303. nhpar: 10994,
  10304. nlArr: 8653,
  10305. nlarr: 8602,
  10306. nless: 8814,
  10307. nlsim: 8820,
  10308. nltri: 8938,
  10309. notin: 8713,
  10310. notni: 8716,
  10311. nprec: 8832,
  10312. nrArr: 8655,
  10313. nrarr: 8603,
  10314. nrtri: 8939,
  10315. nsime: 8772,
  10316. nsmid: 8740,
  10317. nspar: 8742,
  10318. nsube: 8840,
  10319. nsucc: 8833,
  10320. nsupe: 8841,
  10321. numsp: 8199,
  10322. nwArr: 8662,
  10323. nwarr: 8598,
  10324. ocirc: 244,
  10325. odash: 8861,
  10326. oelig: 339,
  10327. ofcir: 10687,
  10328. ohbar: 10677,
  10329. olarr: 8634,
  10330. olcir: 10686,
  10331. oline: 8254,
  10332. omacr: 333,
  10333. omega: 969,
  10334. operp: 10681,
  10335. oplus: 8853,
  10336. orarr: 8635,
  10337. order: 8500,
  10338. ovbar: 9021,
  10339. parsl: 11005,
  10340. phone: 9742,
  10341. plusb: 8862,
  10342. pluse: 10866,
  10343. pound: 163,
  10344. prcue: 8828,
  10345. prime: 8242,
  10346. prnap: 10937,
  10347. prsim: 8830,
  10348. quest: 63,
  10349. rAarr: 8667,
  10350. rBarr: 10511,
  10351. radic: 8730,
  10352. rangd: 10642,
  10353. range: 10661,
  10354. raquo: 187,
  10355. rarrb: 8677,
  10356. rarrc: 10547,
  10357. rarrw: 8605,
  10358. ratio: 8758,
  10359. rbarr: 10509,
  10360. rbbrk: 10099,
  10361. rbrke: 10636,
  10362. rceil: 8969,
  10363. rdquo: 8221,
  10364. reals: 8477,
  10365. rhard: 8641,
  10366. rharu: 8640,
  10367. rlarr: 8644,
  10368. rlhar: 8652,
  10369. rnmid: 10990,
  10370. roang: 10221,
  10371. roarr: 8702,
  10372. robrk: 10215,
  10373. ropar: 10630,
  10374. rrarr: 8649,
  10375. rsquo: 8217,
  10376. rtrie: 8885,
  10377. rtrif: 9656,
  10378. sbquo: 8218,
  10379. sccue: 8829,
  10380. scirc: 349,
  10381. scnap: 10938,
  10382. scsim: 8831,
  10383. sdotb: 8865,
  10384. sdote: 10854,
  10385. seArr: 8664,
  10386. searr: 8600,
  10387. setmn: 8726,
  10388. sharp: 9839,
  10389. sigma: 963,
  10390. simeq: 8771,
  10391. simgE: 10912,
  10392. simlE: 10911,
  10393. simne: 8774,
  10394. slarr: 8592,
  10395. smile: 8995,
  10396. sqcap: 8851,
  10397. sqcup: 8852,
  10398. sqsub: 8847,
  10399. sqsup: 8848,
  10400. srarr: 8594,
  10401. starf: 9733,
  10402. strns: 175,
  10403. subnE: 10955,
  10404. subne: 8842,
  10405. supnE: 10956,
  10406. supne: 8843,
  10407. swArr: 8665,
  10408. swarr: 8601,
  10409. szlig: 223,
  10410. theta: 952,
  10411. thkap: 8776,
  10412. thorn: 254,
  10413. tilde: 732,
  10414. times: 215,
  10415. trade: 8482,
  10416. trisb: 10701,
  10417. tshcy: 1115,
  10418. twixt: 8812,
  10419. ubrcy: 1118,
  10420. ucirc: 251,
  10421. udarr: 8645,
  10422. udhar: 10606,
  10423. uharl: 8639,
  10424. uharr: 8638,
  10425. uhblk: 9600,
  10426. ultri: 9720,
  10427. umacr: 363,
  10428. uogon: 371,
  10429. uplus: 8846,
  10430. upsih: 978,
  10431. uring: 367,
  10432. urtri: 9721,
  10433. utdot: 8944,
  10434. utrif: 9652,
  10435. uuarr: 8648,
  10436. vBarv: 10985,
  10437. vDash: 8872,
  10438. varpi: 982,
  10439. vdash: 8866,
  10440. veeeq: 8794,
  10441. vltri: 8882,
  10442. vprop: 8733,
  10443. vrtri: 8883,
  10444. wcirc: 373,
  10445. wedge: 8743,
  10446. xcirc: 9711,
  10447. xdtri: 9661,
  10448. xhArr: 10234,
  10449. xharr: 10231,
  10450. xlArr: 10232,
  10451. xlarr: 10229,
  10452. xodot: 10752,
  10453. xrArr: 10233,
  10454. xrarr: 10230,
  10455. xutri: 9651,
  10456. ycirc: 375,
  10457. Aopf: 120120,
  10458. Ascr: 119964,
  10459. Auml: 196,
  10460. Barv: 10983,
  10461. Beta: 914,
  10462. Bopf: 120121,
  10463. Bscr: 8492,
  10464. CHcy: 1063,
  10465. COPY: 169,
  10466. Cdot: 266,
  10467. Copf: 8450,
  10468. Cscr: 119966,
  10469. DJcy: 1026,
  10470. DScy: 1029,
  10471. DZcy: 1039,
  10472. Darr: 8609,
  10473. Dopf: 120123,
  10474. Dscr: 119967,
  10475. Edot: 278,
  10476. Eopf: 120124,
  10477. Escr: 8496,
  10478. Esim: 10867,
  10479. Euml: 203,
  10480. Fopf: 120125,
  10481. Fscr: 8497,
  10482. GJcy: 1027,
  10483. Gdot: 288,
  10484. Gopf: 120126,
  10485. Gscr: 119970,
  10486. Hopf: 8461,
  10487. Hscr: 8459,
  10488. IEcy: 1045,
  10489. IOcy: 1025,
  10490. Idot: 304,
  10491. Iopf: 120128,
  10492. Iota: 921,
  10493. Iscr: 8464,
  10494. Iuml: 207,
  10495. Jopf: 120129,
  10496. Jscr: 119973,
  10497. KHcy: 1061,
  10498. KJcy: 1036,
  10499. Kopf: 120130,
  10500. Kscr: 119974,
  10501. LJcy: 1033,
  10502. Lang: 10218,
  10503. Larr: 8606,
  10504. Lopf: 120131,
  10505. Lscr: 8466,
  10506. Mopf: 120132,
  10507. Mscr: 8499,
  10508. NJcy: 1034,
  10509. Nopf: 8469,
  10510. Nscr: 119977,
  10511. Oopf: 120134,
  10512. Oscr: 119978,
  10513. Ouml: 214,
  10514. Popf: 8473,
  10515. Pscr: 119979,
  10516. QUOT: 34,
  10517. Qopf: 8474,
  10518. Qscr: 119980,
  10519. Rang: 10219,
  10520. Rarr: 8608,
  10521. Ropf: 8477,
  10522. Rscr: 8475,
  10523. SHcy: 1064,
  10524. Sopf: 120138,
  10525. Sqrt: 8730,
  10526. Sscr: 119982,
  10527. Star: 8902,
  10528. TScy: 1062,
  10529. Topf: 120139,
  10530. Tscr: 119983,
  10531. Uarr: 8607,
  10532. Uopf: 120140,
  10533. Upsi: 978,
  10534. Uscr: 119984,
  10535. Uuml: 220,
  10536. Vbar: 10987,
  10537. Vert: 8214,
  10538. Vopf: 120141,
  10539. Vscr: 119985,
  10540. Wopf: 120142,
  10541. Wscr: 119986,
  10542. Xopf: 120143,
  10543. Xscr: 119987,
  10544. YAcy: 1071,
  10545. YIcy: 1031,
  10546. YUcy: 1070,
  10547. Yopf: 120144,
  10548. Yscr: 119988,
  10549. Yuml: 376,
  10550. ZHcy: 1046,
  10551. Zdot: 379,
  10552. Zeta: 918,
  10553. Zopf: 8484,
  10554. Zscr: 119989,
  10555. andd: 10844,
  10556. andv: 10842,
  10557. ange: 10660,
  10558. aopf: 120146,
  10559. apid: 8779,
  10560. apos: 39,
  10561. ascr: 119990,
  10562. auml: 228,
  10563. bNot: 10989,
  10564. bbrk: 9141,
  10565. beta: 946,
  10566. beth: 8502,
  10567. bnot: 8976,
  10568. bopf: 120147,
  10569. boxH: 9552,
  10570. boxV: 9553,
  10571. boxh: 9472,
  10572. boxv: 9474,
  10573. bscr: 119991,
  10574. bsim: 8765,
  10575. bsol: 92,
  10576. bull: 8226,
  10577. bump: 8782,
  10578. cdot: 267,
  10579. cent: 162,
  10580. chcy: 1095,
  10581. cirE: 10691,
  10582. circ: 710,
  10583. cire: 8791,
  10584. comp: 8705,
  10585. cong: 8773,
  10586. copf: 120148,
  10587. copy: 169,
  10588. cscr: 119992,
  10589. csub: 10959,
  10590. csup: 10960,
  10591. dArr: 8659,
  10592. dHar: 10597,
  10593. darr: 8595,
  10594. dash: 8208,
  10595. diam: 8900,
  10596. djcy: 1106,
  10597. dopf: 120149,
  10598. dscr: 119993,
  10599. dscy: 1109,
  10600. dsol: 10742,
  10601. dtri: 9663,
  10602. dzcy: 1119,
  10603. eDot: 8785,
  10604. ecir: 8790,
  10605. edot: 279,
  10606. emsp: 8195,
  10607. ensp: 8194,
  10608. eopf: 120150,
  10609. epar: 8917,
  10610. epsi: 1013,
  10611. escr: 8495,
  10612. esim: 8770,
  10613. euml: 235,
  10614. euro: 8364,
  10615. excl: 33,
  10616. flat: 9837,
  10617. fnof: 402,
  10618. fopf: 120151,
  10619. fork: 8916,
  10620. fscr: 119995,
  10621. gdot: 289,
  10622. geqq: 8807,
  10623. gjcy: 1107,
  10624. gnap: 10890,
  10625. gneq: 10888,
  10626. gopf: 120152,
  10627. gscr: 8458,
  10628. gsim: 8819,
  10629. gtcc: 10919,
  10630. hArr: 8660,
  10631. half: 189,
  10632. harr: 8596,
  10633. hbar: 8463,
  10634. hopf: 120153,
  10635. hscr: 119997,
  10636. iecy: 1077,
  10637. imof: 8887,
  10638. iocy: 1105,
  10639. iopf: 120154,
  10640. iota: 953,
  10641. iscr: 119998,
  10642. isin: 8712,
  10643. iuml: 239,
  10644. jopf: 120155,
  10645. jscr: 119999,
  10646. khcy: 1093,
  10647. kjcy: 1116,
  10648. kopf: 120156,
  10649. kscr: 120000,
  10650. lArr: 8656,
  10651. lHar: 10594,
  10652. lang: 10216,
  10653. larr: 8592,
  10654. late: 10925,
  10655. lcub: 123,
  10656. ldca: 10550,
  10657. ldsh: 8626,
  10658. leqq: 8806,
  10659. ljcy: 1113,
  10660. lnap: 10889,
  10661. lneq: 10887,
  10662. lopf: 120157,
  10663. lozf: 10731,
  10664. lpar: 40,
  10665. lscr: 120001,
  10666. lsim: 8818,
  10667. lsqb: 91,
  10668. ltcc: 10918,
  10669. ltri: 9667,
  10670. macr: 175,
  10671. male: 9794,
  10672. malt: 10016,
  10673. mlcp: 10971,
  10674. mldr: 8230,
  10675. mopf: 120158,
  10676. mscr: 120002,
  10677. nbsp: 160,
  10678. ncap: 10819,
  10679. ncup: 10818,
  10680. ngeq: 8817,
  10681. ngtr: 8815,
  10682. nisd: 8954,
  10683. njcy: 1114,
  10684. nldr: 8229,
  10685. nleq: 8816,
  10686. nmid: 8740,
  10687. nopf: 120159,
  10688. npar: 8742,
  10689. nscr: 120003,
  10690. nsim: 8769,
  10691. nsub: 8836,
  10692. nsup: 8837,
  10693. ntgl: 8825,
  10694. ntlg: 8824,
  10695. oast: 8859,
  10696. ocir: 8858,
  10697. odiv: 10808,
  10698. odot: 8857,
  10699. ogon: 731,
  10700. oint: 8750,
  10701. omid: 10678,
  10702. oopf: 120160,
  10703. opar: 10679,
  10704. ordf: 170,
  10705. ordm: 186,
  10706. oror: 10838,
  10707. oscr: 8500,
  10708. osol: 8856,
  10709. ouml: 246,
  10710. para: 182,
  10711. part: 8706,
  10712. perp: 8869,
  10713. phiv: 966,
  10714. plus: 43,
  10715. popf: 120161,
  10716. prap: 10935,
  10717. prec: 8826,
  10718. prnE: 10933,
  10719. prod: 8719,
  10720. prop: 8733,
  10721. pscr: 120005,
  10722. qint: 10764,
  10723. qopf: 120162,
  10724. qscr: 120006,
  10725. quot: 34,
  10726. rArr: 8658,
  10727. rHar: 10596,
  10728. race: 10714,
  10729. rang: 10217,
  10730. rarr: 8594,
  10731. rcub: 125,
  10732. rdca: 10551,
  10733. rdsh: 8627,
  10734. real: 8476,
  10735. rect: 9645,
  10736. rhov: 1009,
  10737. ring: 730,
  10738. ropf: 120163,
  10739. rpar: 41,
  10740. rscr: 120007,
  10741. rsqb: 93,
  10742. rtri: 9657,
  10743. scap: 10936,
  10744. scnE: 10934,
  10745. sdot: 8901,
  10746. sect: 167,
  10747. semi: 59,
  10748. sext: 10038,
  10749. shcy: 1096,
  10750. sime: 8771,
  10751. simg: 10910,
  10752. siml: 10909,
  10753. smid: 8739,
  10754. smte: 10924,
  10755. solb: 10692,
  10756. sopf: 120164,
  10757. spar: 8741,
  10758. squf: 9642,
  10759. sscr: 120008,
  10760. star: 9734,
  10761. subE: 10949,
  10762. sube: 8838,
  10763. succ: 8827,
  10764. sung: 9834,
  10765. sup1: 185,
  10766. sup2: 178,
  10767. sup3: 179,
  10768. supE: 10950,
  10769. supe: 8839,
  10770. tbrk: 9140,
  10771. tdot: 8411,
  10772. tint: 8749,
  10773. toea: 10536,
  10774. topf: 120165,
  10775. tosa: 10537,
  10776. trie: 8796,
  10777. tscr: 120009,
  10778. tscy: 1094,
  10779. uArr: 8657,
  10780. uHar: 10595,
  10781. uarr: 8593,
  10782. uopf: 120166,
  10783. upsi: 965,
  10784. uscr: 120010,
  10785. utri: 9653,
  10786. uuml: 252,
  10787. vArr: 8661,
  10788. vBar: 10984,
  10789. varr: 8597,
  10790. vert: 124,
  10791. vopf: 120167,
  10792. vscr: 120011,
  10793. wopf: 120168,
  10794. wscr: 120012,
  10795. xcap: 8898,
  10796. xcup: 8899,
  10797. xmap: 10236,
  10798. xnis: 8955,
  10799. xopf: 120169,
  10800. xscr: 120013,
  10801. xvee: 8897,
  10802. yacy: 1103,
  10803. yicy: 1111,
  10804. yopf: 120170,
  10805. yscr: 120014,
  10806. yucy: 1102,
  10807. yuml: 255,
  10808. zdot: 380,
  10809. zeta: 950,
  10810. zhcy: 1078,
  10811. zopf: 120171,
  10812. zscr: 120015,
  10813. zwnj: 8204,
  10814. AMP: 38,
  10815. Acy: 1040,
  10816. Afr: 120068,
  10817. And: 10835,
  10818. Bcy: 1041,
  10819. Bfr: 120069,
  10820. Cap: 8914,
  10821. Cfr: 8493,
  10822. Chi: 935,
  10823. Cup: 8915,
  10824. Dcy: 1044,
  10825. Del: 8711,
  10826. Dfr: 120071,
  10827. Dot: 168,
  10828. ENG: 330,
  10829. ETH: 208,
  10830. Ecy: 1069,
  10831. Efr: 120072,
  10832. Eta: 919,
  10833. Fcy: 1060,
  10834. Ffr: 120073,
  10835. Gcy: 1043,
  10836. Gfr: 120074,
  10837. Hat: 94,
  10838. Hfr: 8460,
  10839. Icy: 1048,
  10840. Ifr: 8465,
  10841. Int: 8748,
  10842. Jcy: 1049,
  10843. Jfr: 120077,
  10844. Kcy: 1050,
  10845. Kfr: 120078,
  10846. Lcy: 1051,
  10847. Lfr: 120079,
  10848. Lsh: 8624,
  10849. Map: 10501,
  10850. Mcy: 1052,
  10851. Mfr: 120080,
  10852. Ncy: 1053,
  10853. Nfr: 120081,
  10854. Not: 10988,
  10855. Ocy: 1054,
  10856. Ofr: 120082,
  10857. Pcy: 1055,
  10858. Pfr: 120083,
  10859. Phi: 934,
  10860. Psi: 936,
  10861. Qfr: 120084,
  10862. REG: 174,
  10863. Rcy: 1056,
  10864. Rfr: 8476,
  10865. Rho: 929,
  10866. Rsh: 8625,
  10867. Scy: 1057,
  10868. Sfr: 120086,
  10869. Sub: 8912,
  10870. Sum: 8721,
  10871. Sup: 8913,
  10872. Tab: 9,
  10873. Tau: 932,
  10874. Tcy: 1058,
  10875. Tfr: 120087,
  10876. Ucy: 1059,
  10877. Ufr: 120088,
  10878. Vcy: 1042,
  10879. Vee: 8897,
  10880. Vfr: 120089,
  10881. Wfr: 120090,
  10882. Xfr: 120091,
  10883. Ycy: 1067,
  10884. Yfr: 120092,
  10885. Zcy: 1047,
  10886. Zfr: 8488,
  10887. acd: 8767,
  10888. acy: 1072,
  10889. afr: 120094,
  10890. amp: 38,
  10891. and: 8743,
  10892. ang: 8736,
  10893. apE: 10864,
  10894. ape: 8778,
  10895. ast: 42,
  10896. bcy: 1073,
  10897. bfr: 120095,
  10898. bot: 8869,
  10899. cap: 8745,
  10900. cfr: 120096,
  10901. chi: 967,
  10902. cir: 9675,
  10903. cup: 8746,
  10904. dcy: 1076,
  10905. deg: 176,
  10906. dfr: 120097,
  10907. die: 168,
  10908. div: 247,
  10909. dot: 729,
  10910. ecy: 1101,
  10911. efr: 120098,
  10912. egs: 10902,
  10913. ell: 8467,
  10914. els: 10901,
  10915. eng: 331,
  10916. eta: 951,
  10917. eth: 240,
  10918. fcy: 1092,
  10919. ffr: 120099,
  10920. gEl: 10892,
  10921. gap: 10886,
  10922. gcy: 1075,
  10923. gel: 8923,
  10924. geq: 8805,
  10925. ges: 10878,
  10926. gfr: 120100,
  10927. ggg: 8921,
  10928. glE: 10898,
  10929. gla: 10917,
  10930. glj: 10916,
  10931. gnE: 8809,
  10932. gne: 10888,
  10933. hfr: 120101,
  10934. icy: 1080,
  10935. iff: 8660,
  10936. ifr: 120102,
  10937. int: 8747,
  10938. jcy: 1081,
  10939. jfr: 120103,
  10940. kcy: 1082,
  10941. kfr: 120104,
  10942. lEg: 10891,
  10943. lap: 10885,
  10944. lat: 10923,
  10945. lcy: 1083,
  10946. leg: 8922,
  10947. leq: 8804,
  10948. les: 10877,
  10949. lfr: 120105,
  10950. lgE: 10897,
  10951. lnE: 8808,
  10952. lne: 10887,
  10953. loz: 9674,
  10954. lrm: 8206,
  10955. lsh: 8624,
  10956. map: 8614,
  10957. mcy: 1084,
  10958. mfr: 120106,
  10959. mho: 8487,
  10960. mid: 8739,
  10961. nap: 8777,
  10962. ncy: 1085,
  10963. nfr: 120107,
  10964. nge: 8817,
  10965. ngt: 8815,
  10966. nis: 8956,
  10967. niv: 8715,
  10968. nle: 8816,
  10969. nlt: 8814,
  10970. not: 172,
  10971. npr: 8832,
  10972. nsc: 8833,
  10973. num: 35,
  10974. ocy: 1086,
  10975. ofr: 120108,
  10976. ogt: 10689,
  10977. ohm: 8486,
  10978. olt: 10688,
  10979. ord: 10845,
  10980. orv: 10843,
  10981. par: 8741,
  10982. pcy: 1087,
  10983. pfr: 120109,
  10984. phi: 966,
  10985. piv: 982,
  10986. prE: 10931,
  10987. pre: 10927,
  10988. psi: 968,
  10989. qfr: 120110,
  10990. rcy: 1088,
  10991. reg: 174,
  10992. rfr: 120111,
  10993. rho: 961,
  10994. rlm: 8207,
  10995. rsh: 8625,
  10996. scE: 10932,
  10997. sce: 10928,
  10998. scy: 1089,
  10999. sfr: 120112,
  11000. shy: 173,
  11001. sim: 8764,
  11002. smt: 10922,
  11003. sol: 47,
  11004. squ: 9633,
  11005. sub: 8834,
  11006. sum: 8721,
  11007. sup: 8835,
  11008. tau: 964,
  11009. tcy: 1090,
  11010. tfr: 120113,
  11011. top: 8868,
  11012. ucy: 1091,
  11013. ufr: 120114,
  11014. uml: 168,
  11015. vcy: 1074,
  11016. vee: 8744,
  11017. vfr: 120115,
  11018. wfr: 120116,
  11019. xfr: 120117,
  11020. ycy: 1099,
  11021. yen: 165,
  11022. yfr: 120118,
  11023. zcy: 1079,
  11024. zfr: 120119,
  11025. zwj: 8205,
  11026. DD: 8517,
  11027. GT: 62,
  11028. Gg: 8921,
  11029. Gt: 8811,
  11030. Im: 8465,
  11031. LT: 60,
  11032. Ll: 8920,
  11033. Lt: 8810,
  11034. Mu: 924,
  11035. Nu: 925,
  11036. Or: 10836,
  11037. Pi: 928,
  11038. Pr: 10939,
  11039. Re: 8476,
  11040. Sc: 10940,
  11041. Xi: 926,
  11042. ac: 8766,
  11043. af: 8289,
  11044. ap: 8776,
  11045. dd: 8518,
  11046. ee: 8519,
  11047. eg: 10906,
  11048. el: 10905,
  11049. gE: 8807,
  11050. ge: 8805,
  11051. gg: 8811,
  11052. gl: 8823,
  11053. gt: 62,
  11054. ic: 8291,
  11055. ii: 8520,
  11056. in: 8712,
  11057. it: 8290,
  11058. lE: 8806,
  11059. le: 8804,
  11060. lg: 8822,
  11061. ll: 8810,
  11062. lt: 60,
  11063. mp: 8723,
  11064. mu: 956,
  11065. ne: 8800,
  11066. ni: 8715,
  11067. nu: 957,
  11068. oS: 9416,
  11069. or: 8744,
  11070. pi: 960,
  11071. pm: 177,
  11072. pr: 8826,
  11073. rx: 8478,
  11074. sc: 8827,
  11075. wp: 8472,
  11076. wr: 8768,
  11077. xi: 958,
  11078. };
  11079. const windows1252 = [
  11080. 8364,
  11081. 129,
  11082. 8218,
  11083. 402,
  11084. 8222,
  11085. 8230,
  11086. 8224,
  11087. 8225,
  11088. 710,
  11089. 8240,
  11090. 352,
  11091. 8249,
  11092. 338,
  11093. 141,
  11094. 381,
  11095. 143,
  11096. 144,
  11097. 8216,
  11098. 8217,
  11099. 8220,
  11100. 8221,
  11101. 8226,
  11102. 8211,
  11103. 8212,
  11104. 732,
  11105. 8482,
  11106. 353,
  11107. 8250,
  11108. 339,
  11109. 157,
  11110. 382,
  11111. 376,
  11112. ];
  11113. const entityPattern = new RegExp(`&(#?(?:x[\\w\\d]+|\\d+|${Object.keys(htmlEntities).join('|')}));?`, 'g');
  11114. function decodeCharacterReferences(html) {
  11115. return html.replace(entityPattern, (match, entity) => {
  11116. let code;
  11117. // Handle named entities
  11118. if (entity[0] !== '#') {
  11119. code = htmlEntities[entity];
  11120. }
  11121. else if (entity[1] === 'x') {
  11122. code = parseInt(entity.substring(2), 16);
  11123. }
  11124. else {
  11125. code = parseInt(entity.substring(1), 10);
  11126. }
  11127. if (!code) {
  11128. return match;
  11129. }
  11130. return String.fromCodePoint(validateCode(code));
  11131. });
  11132. }
  11133. const NUL = 0;
  11134. // some code points are verboten. If we were inserting HTML, the browser would replace the illegal
  11135. // code points with alternatives in some cases - since we're bypassing that mechanism, we need
  11136. // to replace them ourselves
  11137. //
  11138. // Source: http://en.wikipedia.org/wiki/Character_encodings_in_HTML#Illegal_characters
  11139. function validateCode(code) {
  11140. // line feed becomes generic whitespace
  11141. if (code === 10) {
  11142. return 32;
  11143. }
  11144. // ASCII range. (Why someone would use HTML entities for ASCII characters I don't know, but...)
  11145. if (code < 128) {
  11146. return code;
  11147. }
  11148. // code points 128-159 are dealt with leniently by browsers, but they're incorrect. We need
  11149. // to correct the mistake or we'll end up with missing € signs and so on
  11150. if (code <= 159) {
  11151. return windows1252[code - 128];
  11152. }
  11153. // basic multilingual plane
  11154. if (code < 55296) {
  11155. return code;
  11156. }
  11157. // UTF-16 surrogate halves
  11158. if (code <= 57343) {
  11159. return NUL;
  11160. }
  11161. // rest of the basic multilingual plane
  11162. if (code <= 65535) {
  11163. return code;
  11164. }
  11165. // supplementary multilingual plane 0x10000 - 0x1ffff
  11166. if (code >= 65536 && code <= 131071) {
  11167. return code;
  11168. }
  11169. // supplementary ideographic plane 0x20000 - 0x2ffff
  11170. if (code >= 131072 && code <= 196607) {
  11171. return code;
  11172. }
  11173. return NUL;
  11174. }
  11175. const voidElementNames = /^(?:area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/;
  11176. function isVoidElementName(name) {
  11177. return voidElementNames.test(name) || name.toLowerCase() === '!doctype';
  11178. }
  11179. const validTagName = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/;
  11180. const metaTags = new Map([
  11181. ['svelte:document', 'Document'],
  11182. ['svelte:window', 'Window'],
  11183. ['svelte:head', 'Head']
  11184. ]);
  11185. const specials = new Map([
  11186. [
  11187. 'script',
  11188. {
  11189. read: readScript,
  11190. property: 'js',
  11191. },
  11192. ],
  11193. [
  11194. 'style',
  11195. {
  11196. read: readStyle,
  11197. property: 'css',
  11198. },
  11199. ],
  11200. ]);
  11201. const SELF = 'svelte:self';
  11202. const COMPONENT = 'svelte:component';
  11203. // based on http://developers.whatwg.org/syntax.html#syntax-tag-omission
  11204. const disallowedContents = new Map([
  11205. ['li', new Set(['li'])],
  11206. ['dt', new Set(['dt', 'dd'])],
  11207. ['dd', new Set(['dt', 'dd'])],
  11208. [
  11209. 'p',
  11210. new Set('address article aside blockquote div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr main menu nav ol p pre section table ul'.split(' ')),
  11211. ],
  11212. ['rt', new Set(['rt', 'rp'])],
  11213. ['rp', new Set(['rt', 'rp'])],
  11214. ['optgroup', new Set(['optgroup'])],
  11215. ['option', new Set(['option', 'optgroup'])],
  11216. ['thead', new Set(['tbody', 'tfoot'])],
  11217. ['tbody', new Set(['tbody', 'tfoot'])],
  11218. ['tfoot', new Set(['tbody'])],
  11219. ['tr', new Set(['tr', 'tbody'])],
  11220. ['td', new Set(['td', 'th', 'tr'])],
  11221. ['th', new Set(['td', 'th', 'tr'])],
  11222. ]);
  11223. function parentIsHead(stack) {
  11224. let i = stack.length;
  11225. while (i--) {
  11226. const { type } = stack[i];
  11227. if (type === 'Head')
  11228. return true;
  11229. if (type === 'Element' || type === 'InlineComponent')
  11230. return false;
  11231. }
  11232. return false;
  11233. }
  11234. function tag(parser) {
  11235. const start = parser.index++;
  11236. let parent = parser.current();
  11237. if (parser.eat('!--')) {
  11238. const data = parser.readUntil(/-->/);
  11239. parser.eat('-->', true, 'comment was left open, expected -->');
  11240. parser.current().children.push({
  11241. start,
  11242. end: parser.index,
  11243. type: 'Comment',
  11244. data,
  11245. });
  11246. return;
  11247. }
  11248. const isClosingTag = parser.eat('/');
  11249. const name = readTagName(parser);
  11250. if (metaTags.has(name)) {
  11251. const slug = metaTags.get(name).toLowerCase();
  11252. if (isClosingTag) {
  11253. if ((name === 'svelte:window' || name === 'svelte:document') &&
  11254. parser.current().children.length) {
  11255. parser.error({
  11256. code: `invalid-${name.slice(7)}-content`,
  11257. message: `<${name}> cannot have children`
  11258. }, parser.current().children[0].start);
  11259. }
  11260. }
  11261. else {
  11262. if (name in parser.metaTags) {
  11263. parser.error({
  11264. code: `duplicate-${slug}`,
  11265. message: `A component can only have one <${name}> tag`
  11266. }, start);
  11267. }
  11268. if (parser.stack.length > 1) {
  11269. parser.error({
  11270. code: `invalid-${slug}-placement`,
  11271. message: `<${name}> tags cannot be inside elements or blocks`
  11272. }, start);
  11273. }
  11274. parser.metaTags[name] = true;
  11275. }
  11276. }
  11277. const type = metaTags.has(name)
  11278. ? metaTags.get(name)
  11279. : (/[A-Z]/.test(name[0]) || name === 'svelte:self' || name === 'svelte:component') ? 'InlineComponent'
  11280. : name === 'title' && parentIsHead(parser.stack) ? 'Title'
  11281. : name === 'slot' && !parser.customElement ? 'Slot' : 'Element';
  11282. const element = {
  11283. start,
  11284. end: null,
  11285. type,
  11286. name,
  11287. attributes: [],
  11288. children: [],
  11289. };
  11290. parser.allowWhitespace();
  11291. if (isClosingTag) {
  11292. if (isVoidElementName(name)) {
  11293. parser.error({
  11294. code: `invalid-void-content`,
  11295. message: `<${name}> is a void element and cannot have children, or a closing tag`
  11296. }, start);
  11297. }
  11298. parser.eat('>', true);
  11299. // close any elements that don't have their own closing tags, e.g. <div><p></div>
  11300. while (parent.name !== name) {
  11301. if (parent.type !== 'Element')
  11302. parser.error({
  11303. code: `invalid-closing-tag`,
  11304. message: `</${name}> attempted to close an element that was not open`
  11305. }, start);
  11306. parent.end = start;
  11307. parser.stack.pop();
  11308. parent = parser.current();
  11309. }
  11310. parent.end = parser.index;
  11311. parser.stack.pop();
  11312. return;
  11313. }
  11314. else if (disallowedContents.has(parent.name)) {
  11315. // can this be a child of the parent element, or does it implicitly
  11316. // close it, like `<li>one<li>two`?
  11317. if (disallowedContents.get(parent.name).has(name)) {
  11318. parent.end = start;
  11319. parser.stack.pop();
  11320. }
  11321. }
  11322. if (name === 'slot') {
  11323. let i = parser.stack.length;
  11324. while (i--) {
  11325. const item = parser.stack[i];
  11326. if (item.type === 'EachBlock') {
  11327. parser.error({
  11328. code: `invalid-slot-placement`,
  11329. message: `<slot> cannot be a child of an each-block`
  11330. }, start);
  11331. }
  11332. }
  11333. }
  11334. const uniqueNames = new Set();
  11335. let attribute;
  11336. while ((attribute = readAttribute(parser, uniqueNames))) {
  11337. if (attribute.type === 'Binding' && !parser.allowBindings) {
  11338. parser.error({
  11339. code: `binding-disabled`,
  11340. message: `Two-way binding is disabled`
  11341. }, attribute.start);
  11342. }
  11343. element.attributes.push(attribute);
  11344. parser.allowWhitespace();
  11345. }
  11346. if (name === 'svelte:component') {
  11347. // TODO post v2, treat this just as any other attribute
  11348. const index = element.attributes.findIndex(attr => attr.name === 'this');
  11349. if (!~index) {
  11350. parser.error({
  11351. code: `missing-component-definition`,
  11352. message: `<svelte:component> must have a 'this' attribute`
  11353. }, start);
  11354. }
  11355. const definition = element.attributes.splice(index, 1)[0];
  11356. if (definition.value === true || definition.value.length !== 1 || definition.value[0].type === 'Text') {
  11357. parser.error({
  11358. code: `invalid-component-definition`,
  11359. message: `invalid component definition`
  11360. }, definition.start);
  11361. }
  11362. element.expression = definition.value[0].expression;
  11363. }
  11364. // special cases – top-level <script> and <style>
  11365. if (specials.has(name) && parser.stack.length === 1) {
  11366. const special = specials.get(name);
  11367. if (parser[special.property]) {
  11368. parser.index = start;
  11369. parser.error({
  11370. code: `duplicate-${name}`,
  11371. message: `You can only have one top-level <${name}> tag per component`
  11372. });
  11373. }
  11374. parser.eat('>', true);
  11375. parser[special.property] = special.read(parser, start, element.attributes);
  11376. return;
  11377. }
  11378. parser.current().children.push(element);
  11379. const selfClosing = parser.eat('/') || isVoidElementName(name);
  11380. parser.eat('>', true);
  11381. if (selfClosing) {
  11382. // don't push self-closing elements onto the stack
  11383. element.end = parser.index;
  11384. }
  11385. else if (name === 'textarea') {
  11386. // special case
  11387. element.children = readSequence$1(parser, () => parser.template.slice(parser.index, parser.index + 11) === '</textarea>');
  11388. parser.read(/<\/textarea>/);
  11389. element.end = parser.index;
  11390. }
  11391. else if (name === 'script') {
  11392. // special case
  11393. const start = parser.index;
  11394. const data = parser.readUntil(/<\/script>/);
  11395. const end = parser.index;
  11396. element.children.push({ start, end, type: 'Text', data });
  11397. parser.eat('</script>', true);
  11398. element.end = parser.index;
  11399. }
  11400. else if (name === 'style') {
  11401. // special case
  11402. const start = parser.index;
  11403. const data = parser.readUntil(/<\/style>/);
  11404. const end = parser.index;
  11405. element.children.push({ start, end, type: 'Text', data });
  11406. parser.eat('</style>', true);
  11407. }
  11408. else {
  11409. parser.stack.push(element);
  11410. }
  11411. }
  11412. function readTagName(parser) {
  11413. const start = parser.index;
  11414. if (parser.eat(SELF)) {
  11415. // check we're inside a block, otherwise this
  11416. // will cause infinite recursion
  11417. let i = parser.stack.length;
  11418. let legal = false;
  11419. while (i--) {
  11420. const fragment = parser.stack[i];
  11421. if (fragment.type === 'IfBlock' || fragment.type === 'EachBlock') {
  11422. legal = true;
  11423. break;
  11424. }
  11425. }
  11426. if (!legal) {
  11427. parser.error({
  11428. code: `invalid-self-placement`,
  11429. message: `<${SELF}> components can only exist inside if-blocks or each-blocks`
  11430. }, start);
  11431. }
  11432. return SELF;
  11433. }
  11434. if (parser.eat(COMPONENT))
  11435. return COMPONENT;
  11436. const name = parser.readUntil(/(\s|\/|>)/);
  11437. if (metaTags.has(name))
  11438. return name;
  11439. if (!validTagName.test(name)) {
  11440. parser.error({
  11441. code: `invalid-tag-name`,
  11442. message: `Expected valid tag name`
  11443. }, start);
  11444. }
  11445. return name;
  11446. }
  11447. function readAttribute(parser, uniqueNames) {
  11448. const start = parser.index;
  11449. if (parser.eat('{')) {
  11450. parser.allowWhitespace();
  11451. if (parser.eat('...')) {
  11452. const expression = readExpression(parser);
  11453. parser.allowWhitespace();
  11454. parser.eat('}', true);
  11455. return {
  11456. start,
  11457. end: parser.index,
  11458. type: 'Spread',
  11459. expression
  11460. };
  11461. }
  11462. else {
  11463. const valueStart = parser.index;
  11464. const name = parser.readIdentifier();
  11465. parser.allowWhitespace();
  11466. parser.eat('}', true);
  11467. return {
  11468. start,
  11469. end: parser.index,
  11470. type: 'Attribute',
  11471. name,
  11472. value: [{
  11473. start: valueStart,
  11474. end: valueStart + name.length,
  11475. type: 'AttributeShorthand',
  11476. expression: {
  11477. start: valueStart,
  11478. end: valueStart + name.length,
  11479. type: 'Identifier',
  11480. name
  11481. }
  11482. }]
  11483. };
  11484. }
  11485. }
  11486. let name = parser.readUntil(/(\s|=|\/|>)/);
  11487. if (!name)
  11488. return null;
  11489. if (uniqueNames.has(name)) {
  11490. parser.error({
  11491. code: `duplicate-attribute`,
  11492. message: 'Attributes need to be unique'
  11493. }, start);
  11494. }
  11495. uniqueNames.add(name);
  11496. parser.allowWhitespace();
  11497. const directive = readDirective(parser, start, name);
  11498. if (directive)
  11499. return directive;
  11500. let value = parser.eat('=') ? readAttributeValue(parser) : true;
  11501. return {
  11502. start,
  11503. end: parser.index,
  11504. type: 'Attribute',
  11505. name,
  11506. value,
  11507. };
  11508. }
  11509. function readAttributeValue(parser) {
  11510. const quoteMark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null;
  11511. const regex = (quoteMark === `'` ? /'/ :
  11512. quoteMark === `"` ? /"/ :
  11513. /(\/>|[\s"'=<>`])/);
  11514. const value = readSequence$1(parser, () => !!parser.matchRegex(regex));
  11515. if (quoteMark)
  11516. parser.index += 1;
  11517. return value;
  11518. }
  11519. function readSequence$1(parser, done) {
  11520. let currentChunk = {
  11521. start: parser.index,
  11522. end: null,
  11523. type: 'Text',
  11524. data: '',
  11525. };
  11526. const chunks = [];
  11527. while (parser.index < parser.template.length) {
  11528. const index = parser.index;
  11529. if (done()) {
  11530. currentChunk.end = parser.index;
  11531. if (currentChunk.data)
  11532. chunks.push(currentChunk);
  11533. chunks.forEach(chunk => {
  11534. if (chunk.type === 'Text')
  11535. chunk.data = decodeCharacterReferences(chunk.data);
  11536. });
  11537. return chunks;
  11538. }
  11539. else if (parser.eat('{')) {
  11540. if (currentChunk.data) {
  11541. currentChunk.end = index;
  11542. chunks.push(currentChunk);
  11543. }
  11544. parser.allowWhitespace();
  11545. const expression = readExpression(parser);
  11546. parser.allowWhitespace();
  11547. parser.eat('}', true);
  11548. chunks.push({
  11549. start: index,
  11550. end: parser.index,
  11551. type: 'MustacheTag',
  11552. expression,
  11553. });
  11554. currentChunk = {
  11555. start: parser.index,
  11556. end: null,
  11557. type: 'Text',
  11558. data: '',
  11559. };
  11560. }
  11561. else {
  11562. currentChunk.data += parser.template[parser.index++];
  11563. }
  11564. }
  11565. parser.error({
  11566. code: `unexpected-eof`,
  11567. message: `Unexpected end of input`
  11568. });
  11569. }
  11570. function errorOnAssignmentPattern(parser) {
  11571. if (parser.eat('=')) {
  11572. parser.error({
  11573. code: 'invalid-assignment-pattern',
  11574. message: 'Assignment patterns are not supported'
  11575. }, parser.index - 1);
  11576. }
  11577. }
  11578. function readContext(parser) {
  11579. const context = {
  11580. start: parser.index,
  11581. end: null,
  11582. type: null
  11583. };
  11584. if (parser.eat('[')) {
  11585. context.type = 'ArrayPattern';
  11586. context.elements = [];
  11587. do {
  11588. parser.allowWhitespace();
  11589. if (parser.template[parser.index] === ',') {
  11590. context.elements.push(null);
  11591. }
  11592. else {
  11593. context.elements.push(readContext(parser));
  11594. parser.allowWhitespace();
  11595. }
  11596. } while (parser.eat(','));
  11597. errorOnAssignmentPattern(parser);
  11598. parser.eat(']', true);
  11599. context.end = parser.index;
  11600. }
  11601. else if (parser.eat('{')) {
  11602. context.type = 'ObjectPattern';
  11603. context.properties = [];
  11604. do {
  11605. parser.allowWhitespace();
  11606. const start = parser.index;
  11607. const name = parser.readIdentifier();
  11608. const key = {
  11609. start,
  11610. end: parser.index,
  11611. type: 'Identifier',
  11612. name
  11613. };
  11614. parser.allowWhitespace();
  11615. const value = parser.eat(':')
  11616. ? (parser.allowWhitespace(), readContext(parser))
  11617. : key;
  11618. const property = {
  11619. start,
  11620. end: value.end,
  11621. type: 'Property',
  11622. kind: 'init',
  11623. shorthand: value.type === 'Identifier' && value.name === name,
  11624. key,
  11625. value
  11626. };
  11627. context.properties.push(property);
  11628. parser.allowWhitespace();
  11629. } while (parser.eat(','));
  11630. errorOnAssignmentPattern(parser);
  11631. parser.eat('}', true);
  11632. context.end = parser.index;
  11633. }
  11634. else {
  11635. const name = parser.readIdentifier();
  11636. if (name) {
  11637. context.type = 'Identifier';
  11638. context.end = parser.index;
  11639. context.name = name;
  11640. }
  11641. else {
  11642. parser.error({
  11643. code: 'invalid-context',
  11644. message: 'Expected a name, array pattern or object pattern'
  11645. });
  11646. }
  11647. errorOnAssignmentPattern(parser);
  11648. }
  11649. return context;
  11650. }
  11651. const whitespace = /[ \t\r\n]/;
  11652. const dimensions = /^(?:offset|client)(?:Width|Height)$/;
  11653. function trimStart(str) {
  11654. let i = 0;
  11655. while (whitespace.test(str[i]))
  11656. i += 1;
  11657. return str.slice(i);
  11658. }
  11659. function trimEnd(str) {
  11660. let i = str.length;
  11661. while (whitespace.test(str[i - 1]))
  11662. i -= 1;
  11663. return str.slice(0, i);
  11664. }
  11665. function trimWhitespace(block, trimBefore, trimAfter) {
  11666. if (!block.children || block.children.length === 0)
  11667. return; // AwaitBlock
  11668. const firstChild = block.children[0];
  11669. const lastChild = block.children[block.children.length - 1];
  11670. if (firstChild.type === 'Text' && trimBefore) {
  11671. firstChild.data = trimStart(firstChild.data);
  11672. if (!firstChild.data)
  11673. block.children.shift();
  11674. }
  11675. if (lastChild.type === 'Text' && trimAfter) {
  11676. lastChild.data = trimEnd(lastChild.data);
  11677. if (!lastChild.data)
  11678. block.children.pop();
  11679. }
  11680. if (block.else) {
  11681. trimWhitespace(block.else, trimBefore, trimAfter);
  11682. }
  11683. if (firstChild.elseif) {
  11684. trimWhitespace(firstChild, trimBefore, trimAfter);
  11685. }
  11686. }
  11687. function mustache(parser) {
  11688. const start = parser.index;
  11689. parser.index += 1;
  11690. parser.allowWhitespace();
  11691. // {/if} or {/each}
  11692. if (parser.eat('/')) {
  11693. let block = parser.current();
  11694. let expected;
  11695. if (block.type === 'ElseBlock' || block.type === 'PendingBlock' || block.type === 'ThenBlock' || block.type === 'CatchBlock') {
  11696. block.end = start;
  11697. parser.stack.pop();
  11698. block = parser.current();
  11699. expected = 'await';
  11700. }
  11701. if (block.type === 'IfBlock') {
  11702. expected = 'if';
  11703. }
  11704. else if (block.type === 'EachBlock') {
  11705. expected = 'each';
  11706. }
  11707. else if (block.type === 'AwaitBlock') {
  11708. expected = 'await';
  11709. }
  11710. else {
  11711. parser.error({
  11712. code: `unexpected-block-close`,
  11713. message: `Unexpected block closing tag`
  11714. });
  11715. }
  11716. parser.eat(expected, true);
  11717. parser.allowWhitespace();
  11718. parser.eat('}', true);
  11719. while (block.elseif) {
  11720. block.end = parser.index;
  11721. parser.stack.pop();
  11722. block = parser.current();
  11723. if (block.else) {
  11724. block.else.end = start;
  11725. }
  11726. }
  11727. // strip leading/trailing whitespace as necessary
  11728. const charBefore = parser.template[block.start - 1];
  11729. const charAfter = parser.template[parser.index];
  11730. const trimBefore = !charBefore || whitespace.test(charBefore);
  11731. const trimAfter = !charAfter || whitespace.test(charAfter);
  11732. trimWhitespace(block, trimBefore, trimAfter);
  11733. block.end = parser.index;
  11734. parser.stack.pop();
  11735. }
  11736. else if (parser.eat(':elseif')) {
  11737. const block = parser.current();
  11738. if (block.type !== 'IfBlock')
  11739. parser.error({
  11740. code: `invalid-elseif-placement`,
  11741. message: 'Cannot have an {:elseif ...} block outside an {#if ...} block'
  11742. });
  11743. parser.requireWhitespace();
  11744. const expression = readExpression(parser);
  11745. parser.allowWhitespace();
  11746. parser.eat('}', true);
  11747. block.else = {
  11748. start: parser.index,
  11749. end: null,
  11750. type: 'ElseBlock',
  11751. children: [
  11752. {
  11753. start: parser.index,
  11754. end: null,
  11755. type: 'IfBlock',
  11756. elseif: true,
  11757. expression,
  11758. children: [],
  11759. },
  11760. ],
  11761. };
  11762. parser.stack.push(block.else.children[0]);
  11763. }
  11764. else if (parser.eat(':else')) {
  11765. const block = parser.current();
  11766. if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
  11767. parser.error({
  11768. code: `invalid-else-placement`,
  11769. message: 'Cannot have an {:else} block outside an {#if ...} or {#each ...} block'
  11770. });
  11771. }
  11772. parser.allowWhitespace();
  11773. parser.eat('}', true);
  11774. block.else = {
  11775. start: parser.index,
  11776. end: null,
  11777. type: 'ElseBlock',
  11778. children: [],
  11779. };
  11780. parser.stack.push(block.else);
  11781. }
  11782. else if (parser.eat(':then')) {
  11783. // TODO DRY out this and the next section
  11784. const pendingBlock = parser.current();
  11785. if (pendingBlock.type === 'PendingBlock') {
  11786. pendingBlock.end = start;
  11787. parser.stack.pop();
  11788. const awaitBlock = parser.current();
  11789. if (!parser.eat('}')) {
  11790. parser.requireWhitespace();
  11791. awaitBlock.value = parser.readIdentifier();
  11792. parser.allowWhitespace();
  11793. parser.eat('}', true);
  11794. }
  11795. const thenBlock = {
  11796. start,
  11797. end: null,
  11798. type: 'ThenBlock',
  11799. children: []
  11800. };
  11801. awaitBlock.then = thenBlock;
  11802. parser.stack.push(thenBlock);
  11803. }
  11804. }
  11805. else if (parser.eat(':catch')) {
  11806. const thenBlock = parser.current();
  11807. if (thenBlock.type === 'ThenBlock') {
  11808. thenBlock.end = start;
  11809. parser.stack.pop();
  11810. const awaitBlock = parser.current();
  11811. if (!parser.eat('}')) {
  11812. parser.requireWhitespace();
  11813. awaitBlock.error = parser.readIdentifier();
  11814. parser.allowWhitespace();
  11815. parser.eat('}', true);
  11816. }
  11817. const catchBlock = {
  11818. start,
  11819. end: null,
  11820. type: 'CatchBlock',
  11821. children: []
  11822. };
  11823. awaitBlock.catch = catchBlock;
  11824. parser.stack.push(catchBlock);
  11825. }
  11826. }
  11827. else if (parser.eat('#')) {
  11828. // {#if foo}, {#each foo} or {#await foo}
  11829. let type;
  11830. if (parser.eat('if')) {
  11831. type = 'IfBlock';
  11832. }
  11833. else if (parser.eat('each')) {
  11834. type = 'EachBlock';
  11835. }
  11836. else if (parser.eat('await')) {
  11837. type = 'AwaitBlock';
  11838. }
  11839. else {
  11840. parser.error({
  11841. code: `expected-block-type`,
  11842. message: `Expected if, each or await`
  11843. });
  11844. }
  11845. parser.requireWhitespace();
  11846. const expression = readExpression(parser);
  11847. const block = type === 'AwaitBlock' ?
  11848. {
  11849. start,
  11850. end: null,
  11851. type,
  11852. expression,
  11853. value: null,
  11854. error: null,
  11855. pending: {
  11856. start: null,
  11857. end: null,
  11858. type: 'PendingBlock',
  11859. children: []
  11860. },
  11861. then: {
  11862. start: null,
  11863. end: null,
  11864. type: 'ThenBlock',
  11865. children: []
  11866. },
  11867. catch: {
  11868. start: null,
  11869. end: null,
  11870. type: 'CatchBlock',
  11871. children: []
  11872. },
  11873. } :
  11874. {
  11875. start,
  11876. end: null,
  11877. type,
  11878. expression,
  11879. children: [],
  11880. };
  11881. parser.allowWhitespace();
  11882. // {#each} blocks must declare a context – {#each list as item}
  11883. if (type === 'EachBlock') {
  11884. parser.eat('as', true);
  11885. parser.requireWhitespace();
  11886. block.context = readContext(parser);
  11887. parser.allowWhitespace();
  11888. if (parser.eat(',')) {
  11889. parser.allowWhitespace();
  11890. block.index = parser.readIdentifier();
  11891. if (!block.index)
  11892. parser.error({
  11893. code: `expected-name`,
  11894. message: `Expected name`
  11895. });
  11896. parser.allowWhitespace();
  11897. }
  11898. if (parser.eat('(')) {
  11899. parser.allowWhitespace();
  11900. block.key = readExpression(parser);
  11901. parser.allowWhitespace();
  11902. parser.eat(')', true);
  11903. parser.allowWhitespace();
  11904. }
  11905. else if (parser.eat('@')) {
  11906. block.key = parser.readIdentifier();
  11907. if (!block.key)
  11908. parser.error({
  11909. code: `expected-name`,
  11910. message: `Expected name`
  11911. });
  11912. parser.allowWhitespace();
  11913. }
  11914. }
  11915. let awaitBlockShorthand = type === 'AwaitBlock' && parser.eat('then');
  11916. if (awaitBlockShorthand) {
  11917. parser.requireWhitespace();
  11918. block.value = parser.readIdentifier();
  11919. parser.allowWhitespace();
  11920. }
  11921. parser.eat('}', true);
  11922. parser.current().children.push(block);
  11923. parser.stack.push(block);
  11924. if (type === 'AwaitBlock') {
  11925. const childBlock = awaitBlockShorthand ? block.then : block.pending;
  11926. childBlock.start = parser.index;
  11927. parser.stack.push(childBlock);
  11928. }
  11929. }
  11930. else if (parser.eat('@html')) {
  11931. // {@html content} tag
  11932. const expression = readExpression(parser);
  11933. parser.allowWhitespace();
  11934. parser.eat('}', true);
  11935. parser.current().children.push({
  11936. start,
  11937. end: parser.index,
  11938. type: 'RawMustacheTag',
  11939. expression,
  11940. });
  11941. }
  11942. else if (parser.eat('@debug')) {
  11943. let identifiers;
  11944. // Implies {@debug} which indicates "debug all"
  11945. if (parser.read(/\s*}/)) {
  11946. identifiers = [];
  11947. }
  11948. else {
  11949. const expression = readExpression(parser);
  11950. identifiers = expression.type === 'SequenceExpression'
  11951. ? expression.expressions
  11952. : [expression];
  11953. identifiers.forEach(node => {
  11954. if (node.type !== 'Identifier') {
  11955. parser.error({
  11956. code: 'invalid-debug-args',
  11957. message: '{@debug ...} arguments must be identifiers, not arbitrary expressions'
  11958. }, node.start);
  11959. }
  11960. });
  11961. parser.allowWhitespace();
  11962. parser.eat('}', true);
  11963. }
  11964. parser.current().children.push({
  11965. start,
  11966. end: parser.index,
  11967. type: 'DebugTag',
  11968. identifiers
  11969. });
  11970. }
  11971. else {
  11972. const expression = readExpression(parser);
  11973. parser.allowWhitespace();
  11974. parser.eat('}', true);
  11975. parser.current().children.push({
  11976. start,
  11977. end: parser.index,
  11978. type: 'MustacheTag',
  11979. expression,
  11980. });
  11981. }
  11982. }
  11983. function text(parser) {
  11984. const start = parser.index;
  11985. let data = '';
  11986. while (parser.index < parser.template.length &&
  11987. !parser.match('<') &&
  11988. !parser.match('{')) {
  11989. data += parser.template[parser.index++];
  11990. }
  11991. parser.current().children.push({
  11992. start,
  11993. end: parser.index,
  11994. type: 'Text',
  11995. data: decodeCharacterReferences(data),
  11996. });
  11997. }
  11998. function fragment(parser) {
  11999. if (parser.match('<')) {
  12000. return tag;
  12001. }
  12002. if (parser.match('{')) {
  12003. return mustache;
  12004. }
  12005. return text;
  12006. }
  12007. const reservedNames = new Set([
  12008. 'arguments',
  12009. 'await',
  12010. 'break',
  12011. 'case',
  12012. 'catch',
  12013. 'class',
  12014. 'const',
  12015. 'continue',
  12016. 'debugger',
  12017. 'default',
  12018. 'delete',
  12019. 'do',
  12020. 'else',
  12021. 'enum',
  12022. 'eval',
  12023. 'export',
  12024. 'extends',
  12025. 'false',
  12026. 'finally',
  12027. 'for',
  12028. 'function',
  12029. 'if',
  12030. 'implements',
  12031. 'import',
  12032. 'in',
  12033. 'instanceof',
  12034. 'interface',
  12035. 'let',
  12036. 'new',
  12037. 'null',
  12038. 'package',
  12039. 'private',
  12040. 'protected',
  12041. 'public',
  12042. 'return',
  12043. 'static',
  12044. 'super',
  12045. 'switch',
  12046. 'this',
  12047. 'throw',
  12048. 'true',
  12049. 'try',
  12050. 'typeof',
  12051. 'var',
  12052. 'void',
  12053. 'while',
  12054. 'with',
  12055. 'yield',
  12056. ]);
  12057. // Adapted from https://github.com/acornjs/acorn/blob/6584815dca7440e00de841d1dad152302fdd7ca5/src/tokenize.js
  12058. // Reproduced under MIT License https://github.com/acornjs/acorn/blob/master/LICENSE
  12059. function fullCharCodeAt(str, i) {
  12060. let code = str.charCodeAt(i);
  12061. if (code <= 0xd7ff || code >= 0xe000)
  12062. return code;
  12063. let next = str.charCodeAt(i + 1);
  12064. return (code << 10) + next - 0x35fdc00;
  12065. }
  12066. function getLocator(source, options) {
  12067. if (options === void 0) { options = {}; }
  12068. var offsetLine = options.offsetLine || 0;
  12069. var offsetColumn = options.offsetColumn || 0;
  12070. var originalLines = source.split('\n');
  12071. var start = 0;
  12072. var lineRanges = originalLines.map(function (line, i) {
  12073. var end = start + line.length + 1;
  12074. var range = { start: start, end: end, line: i };
  12075. start = end;
  12076. return range;
  12077. });
  12078. var i = 0;
  12079. function rangeContains(range, index) {
  12080. return range.start <= index && index < range.end;
  12081. }
  12082. function getLocation(range, index) {
  12083. return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };
  12084. }
  12085. function locate(search, startIndex) {
  12086. if (typeof search === 'string') {
  12087. search = source.indexOf(search, startIndex || 0);
  12088. }
  12089. var range = lineRanges[i];
  12090. var d = search >= range.end ? 1 : -1;
  12091. while (range) {
  12092. if (rangeContains(range, search))
  12093. return getLocation(range, search);
  12094. i += d;
  12095. range = lineRanges[i];
  12096. }
  12097. }
  12098. return locate;
  12099. }
  12100. function locate(source, search, options) {
  12101. if (typeof options === 'number') {
  12102. throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument');
  12103. }
  12104. return getLocator(source, options)(search, options && options.startIndex);
  12105. }
  12106. function tabsToSpaces(str) {
  12107. return str.replace(/^\t+/, match => match.split('\t').join(' '));
  12108. }
  12109. function getCodeFrame(source, line, column) {
  12110. const lines = source.split('\n');
  12111. const frameStart = Math.max(0, line - 2);
  12112. const frameEnd = Math.min(line + 3, lines.length);
  12113. const digits = String(frameEnd + 1).length;
  12114. return lines
  12115. .slice(frameStart, frameEnd)
  12116. .map((str, i) => {
  12117. const isErrorLine = frameStart + i === line;
  12118. let lineNum = String(i + frameStart + 1);
  12119. while (lineNum.length < digits)
  12120. lineNum = ` ${lineNum}`;
  12121. if (isErrorLine) {
  12122. const indicator = repeat(' ', digits + 2 + tabsToSpaces(str.slice(0, column)).length) + '^';
  12123. return `${lineNum}: ${tabsToSpaces(str)}\n${indicator}`;
  12124. }
  12125. return `${lineNum}: ${tabsToSpaces(str)}`;
  12126. })
  12127. .join('\n');
  12128. }
  12129. class CompileError extends Error {
  12130. toString() {
  12131. return `${this.message} (${this.start.line}:${this.start.column})\n${this.frame}`;
  12132. }
  12133. }
  12134. function error$1(message, props) {
  12135. const error = new CompileError(message);
  12136. error.name = props.name;
  12137. const start = locate(props.source, props.start, { offsetLine: 1 });
  12138. const end = locate(props.source, props.end || props.start, { offsetLine: 1 });
  12139. error.code = props.code;
  12140. error.start = start;
  12141. error.end = end;
  12142. error.pos = props.start;
  12143. error.filename = props.filename;
  12144. error.frame = getCodeFrame(props.source, start.line - 1, start.column);
  12145. throw error;
  12146. }
  12147. class Parser$1 {
  12148. constructor(template, options) {
  12149. if (typeof template !== 'string') {
  12150. throw new TypeError('Template must be a string');
  12151. }
  12152. this.template = template.replace(/\s+$/, '');
  12153. this.filename = options.filename;
  12154. this.customElement = options.customElement;
  12155. this.allowBindings = options.bind !== false;
  12156. this.index = 0;
  12157. this.stack = [];
  12158. this.metaTags = {};
  12159. this.html = {
  12160. start: null,
  12161. end: null,
  12162. type: 'Fragment',
  12163. children: [],
  12164. };
  12165. this.css = null;
  12166. this.js = null;
  12167. this.stack.push(this.html);
  12168. let state = fragment;
  12169. while (this.index < this.template.length) {
  12170. state = state(this) || fragment;
  12171. }
  12172. if (this.stack.length > 1) {
  12173. const current = this.current();
  12174. const type = current.type === 'Element' ? `<${current.name}>` : 'Block';
  12175. const slug = current.type === 'Element' ? 'element' : 'block';
  12176. this.error({
  12177. code: `unclosed-${slug}`,
  12178. message: `${type} was left open`
  12179. }, current.start);
  12180. }
  12181. if (state !== fragment) {
  12182. this.error({
  12183. code: `unexpected-eof`,
  12184. message: 'Unexpected end of input'
  12185. });
  12186. }
  12187. if (this.html.children.length) {
  12188. let start = this.html.children[0] && this.html.children[0].start;
  12189. while (/\s/.test(template[start]))
  12190. start += 1;
  12191. let end = this.html.children[this.html.children.length - 1] && this.html.children[this.html.children.length - 1].end;
  12192. while (/\s/.test(template[end - 1]))
  12193. end -= 1;
  12194. this.html.start = start;
  12195. this.html.end = end;
  12196. }
  12197. else {
  12198. this.html.start = this.html.end = null;
  12199. }
  12200. }
  12201. current() {
  12202. return this.stack[this.stack.length - 1];
  12203. }
  12204. acornError(err) {
  12205. this.error({
  12206. code: `parse-error`,
  12207. message: err.message.replace(/ \(\d+:\d+\)$/, '')
  12208. }, err.pos);
  12209. }
  12210. error({ code, message }, index = this.index) {
  12211. error$1(message, {
  12212. name: 'ParseError',
  12213. code,
  12214. source: this.template,
  12215. start: index,
  12216. filename: this.filename
  12217. });
  12218. }
  12219. eat(str, required, message) {
  12220. if (this.match(str)) {
  12221. this.index += str.length;
  12222. return true;
  12223. }
  12224. if (required) {
  12225. this.error({
  12226. code: `unexpected-${this.index === this.template.length ? 'eof' : 'token'}`,
  12227. message: message || `Expected ${str}`
  12228. });
  12229. }
  12230. return false;
  12231. }
  12232. match(str) {
  12233. return this.template.slice(this.index, this.index + str.length) === str;
  12234. }
  12235. matchRegex(pattern) {
  12236. const match = pattern.exec(this.template.slice(this.index));
  12237. if (!match || match.index !== 0)
  12238. return null;
  12239. return match[0];
  12240. }
  12241. allowWhitespace() {
  12242. while (this.index < this.template.length &&
  12243. whitespace.test(this.template[this.index])) {
  12244. this.index++;
  12245. }
  12246. }
  12247. read(pattern) {
  12248. const result = this.matchRegex(pattern);
  12249. if (result)
  12250. this.index += result.length;
  12251. return result;
  12252. }
  12253. readIdentifier() {
  12254. const start = this.index;
  12255. let i = this.index;
  12256. const code = fullCharCodeAt(this.template, i);
  12257. if (!isIdentifierStart(code, true))
  12258. return null;
  12259. i += code <= 0xffff ? 1 : 2;
  12260. while (i < this.template.length) {
  12261. const code = fullCharCodeAt(this.template, i);
  12262. if (!isIdentifierChar(code, true))
  12263. break;
  12264. i += code <= 0xffff ? 1 : 2;
  12265. }
  12266. const identifier = this.template.slice(this.index, this.index = i);
  12267. if (reservedNames.has(identifier)) {
  12268. this.error({
  12269. code: `unexpected-reserved-word`,
  12270. message: `'${identifier}' is a reserved word in JavaScript and cannot be used here`
  12271. }, start);
  12272. }
  12273. return identifier;
  12274. }
  12275. readUntil(pattern) {
  12276. if (this.index >= this.template.length)
  12277. this.error({
  12278. code: `unexpected-eof`,
  12279. message: 'Unexpected end of input'
  12280. });
  12281. const start = this.index;
  12282. const match = pattern.exec(this.template.slice(start));
  12283. if (match) {
  12284. this.index = start + match.index;
  12285. return this.template.slice(start, this.index);
  12286. }
  12287. this.index = this.template.length;
  12288. return this.template.slice(start);
  12289. }
  12290. remaining() {
  12291. return this.template.slice(this.index);
  12292. }
  12293. requireWhitespace() {
  12294. if (!whitespace.test(this.template[this.index])) {
  12295. this.error({
  12296. code: `missing-whitespace`,
  12297. message: `Expected whitespace`
  12298. });
  12299. }
  12300. this.allowWhitespace();
  12301. }
  12302. }
  12303. function parse$1(template, options = {}) {
  12304. const parser = new Parser$1(template, options);
  12305. return {
  12306. html: parser.html,
  12307. css: parser.css,
  12308. js: parser.js,
  12309. };
  12310. }
  12311. const start = /\n(\t+)/;
  12312. function deindent(strings, ...values) {
  12313. const indentation = start.exec(strings[0])[1];
  12314. const pattern = new RegExp(`^${indentation}`, 'gm');
  12315. let result = strings[0].replace(start, '').replace(pattern, '');
  12316. let trailingIndentation = getTrailingIndentation(result);
  12317. for (let i = 1; i < strings.length; i += 1) {
  12318. let expression = values[i - 1];
  12319. const string = strings[i].replace(pattern, '');
  12320. if (Array.isArray(expression)) {
  12321. expression = expression.length ? expression.join('\n') : null;
  12322. }
  12323. if (expression || expression === '') {
  12324. const value = String(expression).replace(/\n/g, `\n${trailingIndentation}`);
  12325. result += value + string;
  12326. }
  12327. else {
  12328. let c = result.length;
  12329. while (/\s/.test(result[c - 1]))
  12330. c -= 1;
  12331. result = result.slice(0, c) + string;
  12332. }
  12333. trailingIndentation = getTrailingIndentation(result);
  12334. }
  12335. return result.trim().replace(/\t+$/gm, '');
  12336. }
  12337. function getTrailingIndentation(str) {
  12338. let i = str.length;
  12339. while (str[i - 1] === ' ' || str[i - 1] === '\t')
  12340. i -= 1;
  12341. return str.slice(i, str.length);
  12342. }
  12343. function stringify(data, options = {}) {
  12344. return JSON.stringify(escape$1(data, options));
  12345. }
  12346. function escape$1(data, { onlyEscapeAtSymbol = false } = {}) {
  12347. return data.replace(onlyEscapeAtSymbol ? /(%+|@+)/g : /(%+|@+|#+)/g, (match) => {
  12348. return match + match[0];
  12349. });
  12350. }
  12351. const escaped$1 = {
  12352. '&': '&amp;',
  12353. '<': '&lt;',
  12354. '>': '&gt;',
  12355. };
  12356. function escapeHTML(html) {
  12357. return String(html).replace(/[&<>]/g, match => escaped$1[match]);
  12358. }
  12359. function escapeTemplate(str) {
  12360. return str.replace(/(\${|`|\\)/g, '\\$1');
  12361. }
  12362. var ChunkType;
  12363. (function (ChunkType) {
  12364. ChunkType[ChunkType["Line"] = 0] = "Line";
  12365. ChunkType[ChunkType["Block"] = 1] = "Block";
  12366. })(ChunkType || (ChunkType = {}));
  12367. class CodeBuilder {
  12368. constructor(str = '') {
  12369. this.result = str;
  12370. const initial = str
  12371. ? /\n/.test(str) ? ChunkType.Block : ChunkType.Line
  12372. : null;
  12373. this.first = initial;
  12374. this.last = initial;
  12375. this.lastCondition = null;
  12376. this.conditionStack = [];
  12377. this.indent = '';
  12378. }
  12379. addConditional(condition, body) {
  12380. this.reifyConditions();
  12381. body = body.replace(/^/gm, `${this.indent}\t`);
  12382. if (condition === this.lastCondition) {
  12383. this.result += `\n${body}`;
  12384. }
  12385. else {
  12386. if (this.lastCondition) {
  12387. this.result += `\n${this.indent}}`;
  12388. }
  12389. this.result += `${this.last === ChunkType.Block ? '\n\n' : '\n'}${this.indent}if (${condition}) {\n${body}`;
  12390. this.lastCondition = condition;
  12391. }
  12392. this.last = ChunkType.Block;
  12393. }
  12394. addLine(line) {
  12395. this.reifyConditions();
  12396. if (this.lastCondition) {
  12397. this.result += `\n${this.indent}}`;
  12398. this.lastCondition = null;
  12399. }
  12400. if (this.last === ChunkType.Block) {
  12401. this.result += `\n\n${this.indent}${line}`;
  12402. }
  12403. else if (this.last === ChunkType.Line) {
  12404. this.result += `\n${this.indent}${line}`;
  12405. }
  12406. else {
  12407. this.result += line;
  12408. }
  12409. this.last = ChunkType.Line;
  12410. if (!this.first)
  12411. this.first = ChunkType.Line;
  12412. }
  12413. addLineAtStart(line) {
  12414. this.reifyConditions();
  12415. if (this.first === ChunkType.Block) {
  12416. this.result = `${line}\n\n${this.indent}${this.result}`;
  12417. }
  12418. else if (this.first === ChunkType.Line) {
  12419. this.result = `${line}\n${this.indent}${this.result}`;
  12420. }
  12421. else {
  12422. this.result += line;
  12423. }
  12424. this.first = ChunkType.Line;
  12425. if (!this.last)
  12426. this.last = ChunkType.Line;
  12427. }
  12428. addBlock(block) {
  12429. this.reifyConditions();
  12430. if (this.indent)
  12431. block = block.replace(/^/gm, `${this.indent}`);
  12432. if (this.lastCondition) {
  12433. this.result += `\n${this.indent}}`;
  12434. this.lastCondition = null;
  12435. }
  12436. if (this.result) {
  12437. this.result += `\n\n${this.indent}${block}`;
  12438. }
  12439. else {
  12440. this.result += block;
  12441. }
  12442. this.last = ChunkType.Block;
  12443. if (!this.first)
  12444. this.first = ChunkType.Block;
  12445. }
  12446. addBlockAtStart(block) {
  12447. this.reifyConditions();
  12448. if (this.result) {
  12449. this.result = `${block}\n\n${this.indent}${this.result}`;
  12450. }
  12451. else {
  12452. this.result += block;
  12453. }
  12454. this.first = ChunkType.Block;
  12455. if (!this.last)
  12456. this.last = ChunkType.Block;
  12457. }
  12458. isEmpty() {
  12459. return this.result === '';
  12460. }
  12461. pushCondition(condition) {
  12462. this.conditionStack.push({ condition, used: false });
  12463. }
  12464. popCondition() {
  12465. const { used } = this.conditionStack.pop();
  12466. this.indent = repeat('\t', this.conditionStack.length);
  12467. if (used)
  12468. this.addLine('}');
  12469. }
  12470. reifyConditions() {
  12471. for (let i = 0; i < this.conditionStack.length; i += 1) {
  12472. const condition = this.conditionStack[i];
  12473. if (!condition.used) {
  12474. const line = `if (${condition.condition}) {`;
  12475. if (this.last === ChunkType.Block) {
  12476. this.result += `\n\n${this.indent}${line}`;
  12477. }
  12478. else if (this.last === ChunkType.Line) {
  12479. this.result += `\n${this.indent}${line}`;
  12480. }
  12481. else {
  12482. this.result += line;
  12483. }
  12484. this.last = ChunkType.Line;
  12485. if (!this.first)
  12486. this.first = ChunkType.Line;
  12487. this.indent = repeat('\t', this.conditionStack.length);
  12488. condition.used = true;
  12489. }
  12490. }
  12491. }
  12492. toString() {
  12493. return this.result.trim() + (this.lastCondition ? `\n}` : ``);
  12494. }
  12495. }
  12496. var globalWhitelist = new Set([
  12497. 'Array',
  12498. 'Boolean',
  12499. 'console',
  12500. 'Date',
  12501. 'decodeURI',
  12502. 'decodeURIComponent',
  12503. 'encodeURI',
  12504. 'encodeURIComponent',
  12505. 'Infinity',
  12506. 'Intl',
  12507. 'isFinite',
  12508. 'isNaN',
  12509. 'JSON',
  12510. 'Map',
  12511. 'Math',
  12512. 'NaN',
  12513. 'Number',
  12514. 'Object',
  12515. 'parseFloat',
  12516. 'parseInt',
  12517. 'Promise',
  12518. 'RegExp',
  12519. 'Set',
  12520. 'String',
  12521. 'undefined',
  12522. ]);
  12523. class Block$1 {
  12524. constructor(options) {
  12525. this.parent = options.parent;
  12526. this.renderer = options.renderer;
  12527. this.name = options.name;
  12528. this.comment = options.comment;
  12529. this.wrappers = [];
  12530. // for keyed each blocks
  12531. this.key = options.key;
  12532. this.first = null;
  12533. this.dependencies = new Set();
  12534. this.bindings = options.bindings;
  12535. this.contextOwners = options.contextOwners;
  12536. this.builders = {
  12537. init: new CodeBuilder(),
  12538. create: new CodeBuilder(),
  12539. claim: new CodeBuilder(),
  12540. hydrate: new CodeBuilder(),
  12541. mount: new CodeBuilder(),
  12542. measure: new CodeBuilder(),
  12543. fix: new CodeBuilder(),
  12544. animate: new CodeBuilder(),
  12545. intro: new CodeBuilder(),
  12546. update: new CodeBuilder(),
  12547. outro: new CodeBuilder(),
  12548. destroy: new CodeBuilder(),
  12549. };
  12550. this.hasAnimation = false;
  12551. this.hasIntroMethod = false; // a block could have an intro method but not intro transitions, e.g. if a sibling block has intros
  12552. this.hasOutroMethod = false;
  12553. this.outros = 0;
  12554. this.getUniqueName = this.renderer.component.getUniqueNameMaker();
  12555. this.variables = new Map();
  12556. this.aliases = new Map()
  12557. .set('component', this.getUniqueName('component'))
  12558. .set('ctx', this.getUniqueName('ctx'));
  12559. if (this.key)
  12560. this.aliases.set('key', this.getUniqueName('key'));
  12561. this.hasUpdateMethod = false; // determined later
  12562. }
  12563. assignVariableNames() {
  12564. const seen = new Set();
  12565. const dupes = new Set();
  12566. let i = this.wrappers.length;
  12567. while (i--) {
  12568. const wrapper = this.wrappers[i];
  12569. if (!wrapper.var)
  12570. continue;
  12571. if (wrapper.parent && wrapper.parent.canUseInnerHTML)
  12572. continue;
  12573. if (seen.has(wrapper.var)) {
  12574. dupes.add(wrapper.var);
  12575. }
  12576. seen.add(wrapper.var);
  12577. }
  12578. const counts = new Map();
  12579. i = this.wrappers.length;
  12580. while (i--) {
  12581. const wrapper = this.wrappers[i];
  12582. if (!wrapper.var)
  12583. continue;
  12584. if (dupes.has(wrapper.var)) {
  12585. const i = counts.get(wrapper.var) || 0;
  12586. counts.set(wrapper.var, i + 1);
  12587. wrapper.var = this.getUniqueName(wrapper.var + i);
  12588. }
  12589. else {
  12590. wrapper.var = this.getUniqueName(wrapper.var);
  12591. }
  12592. }
  12593. }
  12594. addDependencies(dependencies) {
  12595. dependencies.forEach(dependency => {
  12596. this.dependencies.add(dependency);
  12597. });
  12598. }
  12599. addElement(name, renderStatement, claimStatement, parentNode, noDetach) {
  12600. this.addVariable(name);
  12601. this.builders.create.addLine(`${name} = ${renderStatement};`);
  12602. this.builders.claim.addLine(`${name} = ${claimStatement || renderStatement};`);
  12603. if (parentNode) {
  12604. this.builders.mount.addLine(`@append(${parentNode}, ${name});`);
  12605. if (parentNode === 'document.head')
  12606. this.builders.destroy.addLine(`@detachNode(${name});`);
  12607. }
  12608. else {
  12609. this.builders.mount.addLine(`@insert(#target, ${name}, anchor);`);
  12610. if (!noDetach)
  12611. this.builders.destroy.addConditional('detach', `@detachNode(${name});`);
  12612. }
  12613. }
  12614. addIntro() {
  12615. this.hasIntros = this.hasIntroMethod = this.renderer.hasIntroTransitions = true;
  12616. }
  12617. addOutro() {
  12618. this.hasOutros = this.hasOutroMethod = this.renderer.hasOutroTransitions = true;
  12619. this.outros += 1;
  12620. }
  12621. addAnimation() {
  12622. this.hasAnimation = true;
  12623. }
  12624. addVariable(name, init) {
  12625. if (name[0] === '#') {
  12626. name = this.alias(name.slice(1));
  12627. }
  12628. if (this.variables.has(name) && this.variables.get(name) !== init) {
  12629. throw new Error(`Variable '${name}' already initialised with a different value`);
  12630. }
  12631. this.variables.set(name, init);
  12632. }
  12633. alias(name) {
  12634. if (!this.aliases.has(name)) {
  12635. this.aliases.set(name, this.getUniqueName(name));
  12636. }
  12637. return this.aliases.get(name);
  12638. }
  12639. child(options) {
  12640. return new Block$1(Object.assign({}, this, { key: null }, options, { parent: this }));
  12641. }
  12642. toString() {
  12643. const { dev } = this.renderer.options;
  12644. if (this.hasIntroMethod || this.hasOutroMethod) {
  12645. this.addVariable('#current');
  12646. if (!this.builders.mount.isEmpty()) {
  12647. this.builders.mount.addLine(`#current = true;`);
  12648. }
  12649. if (!this.builders.outro.isEmpty()) {
  12650. this.builders.outro.addLine(`#current = false;`);
  12651. }
  12652. }
  12653. if (this.autofocus) {
  12654. this.builders.mount.addLine(`${this.autofocus}.focus();`);
  12655. }
  12656. const properties = new CodeBuilder();
  12657. let localKey;
  12658. if (this.key) {
  12659. localKey = this.getUniqueName('key');
  12660. properties.addBlock(`key: ${localKey},`);
  12661. }
  12662. if (this.first) {
  12663. properties.addBlock(`first: null,`);
  12664. this.builders.hydrate.addLine(`this.first = ${this.first};`);
  12665. }
  12666. if (this.builders.create.isEmpty() && this.builders.hydrate.isEmpty()) {
  12667. properties.addBlock(`c: @noop,`);
  12668. }
  12669. else {
  12670. const hydrate = !this.builders.hydrate.isEmpty() && (this.renderer.options.hydratable
  12671. ? `this.h()`
  12672. : this.builders.hydrate);
  12673. properties.addBlock(deindent `
  12674. ${dev ? 'c: function create' : 'c'}() {
  12675. ${this.builders.create}
  12676. ${hydrate}
  12677. },
  12678. `);
  12679. }
  12680. if (this.renderer.options.hydratable) {
  12681. if (this.builders.claim.isEmpty() && this.builders.hydrate.isEmpty()) {
  12682. properties.addBlock(`l: @noop,`);
  12683. }
  12684. else {
  12685. properties.addBlock(deindent `
  12686. ${dev ? 'l: function claim' : 'l'}(nodes) {
  12687. ${this.builders.claim}
  12688. ${!this.builders.hydrate.isEmpty() && `this.h();`}
  12689. },
  12690. `);
  12691. }
  12692. }
  12693. if (this.renderer.options.hydratable && !this.builders.hydrate.isEmpty()) {
  12694. properties.addBlock(deindent `
  12695. ${dev ? 'h: function hydrate' : 'h'}() {
  12696. ${this.builders.hydrate}
  12697. },
  12698. `);
  12699. }
  12700. if (this.builders.mount.isEmpty()) {
  12701. properties.addBlock(`m: @noop,`);
  12702. }
  12703. else {
  12704. properties.addBlock(deindent `
  12705. ${dev ? 'm: function mount' : 'm'}(#target, anchor) {
  12706. ${this.builders.mount}
  12707. },
  12708. `);
  12709. }
  12710. if (this.hasUpdateMethod || this.maintainContext) {
  12711. if (this.builders.update.isEmpty() && !this.maintainContext) {
  12712. properties.addBlock(`p: @noop,`);
  12713. }
  12714. else {
  12715. properties.addBlock(deindent `
  12716. ${dev ? 'p: function update' : 'p'}(changed, ${this.maintainContext ? '_ctx' : 'ctx'}) {
  12717. ${this.maintainContext && `ctx = _ctx;`}
  12718. ${this.builders.update}
  12719. },
  12720. `);
  12721. }
  12722. }
  12723. if (this.hasAnimation) {
  12724. properties.addBlock(deindent `
  12725. ${dev ? `r: function measure` : `r`}() {
  12726. ${this.builders.measure}
  12727. },
  12728. ${dev ? `f: function fix` : `f`}() {
  12729. ${this.builders.fix}
  12730. },
  12731. ${dev ? `a: function animate` : `a`}() {
  12732. ${this.builders.animate}
  12733. },
  12734. `);
  12735. }
  12736. if (this.hasIntroMethod || this.hasOutroMethod) {
  12737. if (this.builders.mount.isEmpty()) {
  12738. properties.addBlock(`i: @noop,`);
  12739. }
  12740. else {
  12741. properties.addBlock(deindent `
  12742. ${dev ? 'i: function intro' : 'i'}(#target, anchor) {
  12743. if (#current) return;
  12744. ${this.builders.intro}
  12745. this.m(#target, anchor);
  12746. },
  12747. `);
  12748. }
  12749. if (this.builders.outro.isEmpty()) {
  12750. properties.addBlock(`o: @run,`);
  12751. }
  12752. else {
  12753. properties.addBlock(deindent `
  12754. ${dev ? 'o: function outro' : 'o'}(#outrocallback) {
  12755. if (!#current) return;
  12756. ${this.outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${this.outros});`}
  12757. ${this.builders.outro}
  12758. },
  12759. `);
  12760. }
  12761. }
  12762. if (this.builders.destroy.isEmpty()) {
  12763. properties.addBlock(`d: @noop`);
  12764. }
  12765. else {
  12766. properties.addBlock(deindent `
  12767. ${dev ? 'd: function destroy' : 'd'}(detach) {
  12768. ${this.builders.destroy}
  12769. }
  12770. `);
  12771. }
  12772. return deindent `
  12773. ${this.comment && `// ${escape$1(this.comment)}`}
  12774. function ${this.name}(#component${this.key ? `, ${localKey}` : ''}, ctx) {
  12775. ${this.variables.size > 0 &&
  12776. `var ${Array.from(this.variables.keys())
  12777. .map(key => {
  12778. const init = this.variables.get(key);
  12779. return init !== undefined ? `${key} = ${init}` : key;
  12780. })
  12781. .join(', ')};`}
  12782. ${!this.builders.init.isEmpty() && this.builders.init}
  12783. return {
  12784. ${properties}
  12785. };
  12786. }
  12787. `.replace(/(#+)(\w*)/g, (match, sigil, name) => {
  12788. return sigil === '#' ? this.alias(name) : sigil.slice(1) + name;
  12789. });
  12790. }
  12791. }
  12792. class Wrapper {
  12793. constructor(renderer, block, parent, node) {
  12794. this.node = node;
  12795. // make these non-enumerable so that they can be logged sensibly
  12796. // (TODO in dev only?)
  12797. Object.defineProperties(this, {
  12798. renderer: {
  12799. value: renderer
  12800. },
  12801. parent: {
  12802. value: parent
  12803. }
  12804. });
  12805. this.canUseInnerHTML = !renderer.options.hydratable;
  12806. block.wrappers.push(this);
  12807. }
  12808. cannotUseInnerHTML() {
  12809. this.canUseInnerHTML = false;
  12810. if (this.parent)
  12811. this.parent.cannotUseInnerHTML();
  12812. }
  12813. // TODO do we still need equivalent method on Node?
  12814. findNearest(pattern) {
  12815. if (pattern.test(this.node.type))
  12816. return this;
  12817. return this.parent && this.parent.findNearest(pattern);
  12818. }
  12819. getOrCreateAnchor(block, parentNode, parentNodes) {
  12820. // TODO use this in EachBlock and IfBlock — tricky because
  12821. // children need to be created first
  12822. const needsAnchor = this.next ? !this.next.isDomNode() : !parentNode || !this.parent.isDomNode();
  12823. const anchor = needsAnchor
  12824. ? block.getUniqueName(`${this.var}_anchor`)
  12825. : (this.next && this.next.var) || 'null';
  12826. if (needsAnchor) {
  12827. block.addElement(anchor, `@createComment()`, parentNodes && `@createComment()`, parentNode);
  12828. }
  12829. return anchor;
  12830. }
  12831. getUpdateMountNode(anchor) {
  12832. return (this.parent && this.parent.isDomNode())
  12833. ? this.parent.var
  12834. : `${anchor}.parentNode`;
  12835. }
  12836. isDomNode() {
  12837. return (this.node.type === 'Element' ||
  12838. this.node.type === 'Text' ||
  12839. this.node.type === 'MustacheTag');
  12840. }
  12841. render(block, parentNode, parentNodes) {
  12842. throw new Error(`render method not implemented by subclass ${this.node.type}`);
  12843. }
  12844. remount(name) {
  12845. return `${this.var}.m(${name}._slotted.default, null);`;
  12846. }
  12847. }
  12848. function createDebuggingComment(node, component) {
  12849. const { locate, source } = component;
  12850. let c = node.start;
  12851. if (node.type === 'ElseBlock') {
  12852. while (source[c - 1] !== '{')
  12853. c -= 1;
  12854. while (source[c - 1] === '{')
  12855. c -= 1;
  12856. }
  12857. let d = node.expression ? node.expression.node.end : c;
  12858. while (source[d] !== '}')
  12859. d += 1;
  12860. while (source[d] === '}')
  12861. d += 1;
  12862. const start = locate(c);
  12863. const loc = `(${start.line + 1}:${start.column})`;
  12864. return `${loc} ${source.slice(c, d)}`.replace(/\s/g, ' ');
  12865. }
  12866. class AwaitBlockBranch extends Wrapper {
  12867. constructor(status, renderer, block, parent, node, stripWhitespace, nextSibling) {
  12868. super(renderer, block, parent, node);
  12869. this.var = null;
  12870. this.block = block.child({
  12871. comment: createDebuggingComment(node, this.renderer.component),
  12872. name: this.renderer.component.getUniqueName(`create_${status}_block`)
  12873. });
  12874. this.fragment = new FragmentWrapper(renderer, this.block, this.node.children, parent, stripWhitespace, nextSibling);
  12875. this.isDynamic = this.block.dependencies.size > 0;
  12876. }
  12877. }
  12878. class AwaitBlockWrapper extends Wrapper {
  12879. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  12880. super(renderer, block, parent, node);
  12881. this.var = 'await_block';
  12882. this.cannotUseInnerHTML();
  12883. block.addDependencies(this.node.expression.dependencies);
  12884. let isDynamic = false;
  12885. let hasIntros = false;
  12886. let hasOutros = false;
  12887. ['pending', 'then', 'catch'].forEach(status => {
  12888. const child = this.node[status];
  12889. const branch = new AwaitBlockBranch(status, renderer, block, parent, child, stripWhitespace, nextSibling);
  12890. renderer.blocks.push(branch.block);
  12891. if (branch.isDynamic) {
  12892. isDynamic = true;
  12893. // TODO should blocks update their own parents?
  12894. block.addDependencies(branch.block.dependencies);
  12895. }
  12896. if (branch.block.hasIntros)
  12897. hasIntros = true;
  12898. if (branch.block.hasOutros)
  12899. hasOutros = true;
  12900. this[status] = branch;
  12901. });
  12902. this.pending.block.hasUpdateMethod = isDynamic;
  12903. this.then.block.hasUpdateMethod = isDynamic;
  12904. this.catch.block.hasUpdateMethod = isDynamic;
  12905. this.pending.block.hasIntroMethod = hasIntros;
  12906. this.then.block.hasIntroMethod = hasIntros;
  12907. this.catch.block.hasIntroMethod = hasIntros;
  12908. this.pending.block.hasOutroMethod = hasOutros;
  12909. this.then.block.hasOutroMethod = hasOutros;
  12910. this.catch.block.hasOutroMethod = hasOutros;
  12911. if (hasOutros && this.renderer.options.nestedTransitions) {
  12912. block.addOutro();
  12913. }
  12914. }
  12915. render(block, parentNode, parentNodes) {
  12916. const anchor = this.getOrCreateAnchor(block, parentNode, parentNodes);
  12917. const updateMountNode = this.getUpdateMountNode(anchor);
  12918. const { snippet } = this.node.expression;
  12919. const info = block.getUniqueName(`info`);
  12920. const promise = block.getUniqueName(`promise`);
  12921. block.addVariable(promise);
  12922. block.maintainContext = true;
  12923. const infoProps = [
  12924. block.alias('component') === 'component' ? 'component' : `component: #component`,
  12925. 'ctx',
  12926. 'current: null',
  12927. this.pending.block.name && `pending: ${this.pending.block.name}`,
  12928. this.then.block.name && `then: ${this.then.block.name}`,
  12929. this.catch.block.name && `catch: ${this.catch.block.name}`,
  12930. this.then.block.name && `value: '${this.node.value}'`,
  12931. this.catch.block.name && `error: '${this.node.error}'`,
  12932. this.pending.block.hasOutroMethod && `blocks: Array(3)`
  12933. ].filter(Boolean);
  12934. block.builders.init.addBlock(deindent `
  12935. let ${info} = {
  12936. ${infoProps.join(',\n')}
  12937. };
  12938. `);
  12939. block.builders.init.addBlock(deindent `
  12940. @handlePromise(${promise} = ${snippet}, ${info});
  12941. `);
  12942. block.builders.create.addBlock(deindent `
  12943. ${info}.block.c();
  12944. `);
  12945. if (parentNodes) {
  12946. block.builders.claim.addBlock(deindent `
  12947. ${info}.block.l(${parentNodes});
  12948. `);
  12949. }
  12950. const initialMountNode = parentNode || '#target';
  12951. const anchorNode = parentNode ? 'null' : 'anchor';
  12952. const hasTransitions = this.pending.block.hasIntroMethod || this.pending.block.hasOutroMethod;
  12953. block.builders.mount.addBlock(deindent `
  12954. ${info}.block.${hasTransitions ? 'i' : 'm'}(${initialMountNode}, ${info}.anchor = ${anchorNode});
  12955. ${info}.mount = () => ${updateMountNode};
  12956. `);
  12957. const conditions = [];
  12958. if (this.node.expression.dependencies.size > 0) {
  12959. conditions.push(`(${[...this.node.expression.dependencies].map(dep => `'${dep}' in changed`).join(' || ')})`);
  12960. }
  12961. conditions.push(`${promise} !== (${promise} = ${snippet})`, `@handlePromise(${promise}, ${info})`);
  12962. block.builders.update.addLine(`${info}.ctx = ctx;`);
  12963. if (this.pending.block.hasUpdateMethod) {
  12964. block.builders.update.addBlock(deindent `
  12965. if (${conditions.join(' && ')}) {
  12966. // nothing
  12967. } else {
  12968. ${info}.block.p(changed, @assign(@assign({}, ctx), ${info}.resolved));
  12969. }
  12970. `);
  12971. }
  12972. else {
  12973. block.builders.update.addBlock(deindent `
  12974. ${conditions.join(' && ')}
  12975. `);
  12976. }
  12977. if (this.pending.block.hasOutroMethod && this.renderer.options.nestedTransitions) {
  12978. const countdown = block.getUniqueName('countdown');
  12979. block.builders.outro.addBlock(deindent `
  12980. const ${countdown} = @callAfter(#outrocallback, 3);
  12981. for (let #i = 0; #i < 3; #i += 1) {
  12982. const block = ${info}.blocks[#i];
  12983. if (block) block.o(${countdown});
  12984. else ${countdown}();
  12985. }
  12986. `);
  12987. }
  12988. block.builders.destroy.addBlock(deindent `
  12989. ${info}.block.d(${parentNode ? '' : 'detach'});
  12990. ${info} = null;
  12991. `);
  12992. [this.pending, this.then, this.catch].forEach(branch => {
  12993. branch.fragment.render(branch.block, null, 'nodes');
  12994. });
  12995. }
  12996. }
  12997. function addToSet(a, b) {
  12998. b.forEach(item => {
  12999. a.add(item);
  13000. });
  13001. }
  13002. class DebugTagWrapper extends Wrapper {
  13003. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  13004. super(renderer, block, parent, node);
  13005. }
  13006. render(block, parentNode, parentNodes) {
  13007. const { renderer } = this;
  13008. const { component } = renderer;
  13009. if (!renderer.options.dev)
  13010. return;
  13011. const { code } = component;
  13012. if (this.node.expressions.length === 0) {
  13013. // Debug all
  13014. code.overwrite(this.node.start + 1, this.node.start + 7, 'debugger', {
  13015. storeName: true
  13016. });
  13017. const statement = `[✂${this.node.start + 1}-${this.node.start + 7}✂];`;
  13018. block.builders.create.addLine(statement);
  13019. block.builders.update.addLine(statement);
  13020. }
  13021. else {
  13022. const { code } = component;
  13023. code.overwrite(this.node.start + 1, this.node.start + 7, 'log', {
  13024. storeName: true
  13025. });
  13026. const log = `[✂${this.node.start + 1}-${this.node.start + 7}✂]`;
  13027. const dependencies = new Set();
  13028. this.node.expressions.forEach(expression => {
  13029. addToSet(dependencies, expression.dependencies);
  13030. });
  13031. const condition = [...dependencies].map(d => `changed.${d}`).join(' || ');
  13032. const identifiers = this.node.expressions.map(e => e.node.name).join(', ');
  13033. block.builders.update.addBlock(deindent `
  13034. if (${condition}) {
  13035. const { ${identifiers} } = ctx;
  13036. console.${log}({ ${identifiers} });
  13037. debugger;
  13038. }
  13039. `);
  13040. block.builders.create.addBlock(deindent `
  13041. {
  13042. const { ${identifiers} } = ctx;
  13043. console.${log}({ ${identifiers} });
  13044. debugger;
  13045. }
  13046. `);
  13047. }
  13048. }
  13049. }
  13050. class DocumentWrapper extends Wrapper {
  13051. constructor(renderer, block, parent, node) {
  13052. super(renderer, block, parent, node);
  13053. }
  13054. render(block, parentNode, parentNodes) {
  13055. const { renderer } = this;
  13056. const { component } = renderer;
  13057. this.node.handlers.forEach(handler => {
  13058. // TODO verify that it's a valid callee (i.e. built-in or declared method)
  13059. component.addSourcemapLocations(handler.expression);
  13060. const isCustomEvent = component.events.has(handler.name);
  13061. let usesState = handler.dependencies.size > 0;
  13062. handler.render(component, block, 'document', false); // TODO hoist?
  13063. const handlerName = block.getUniqueName(`onwindow${handler.name}`);
  13064. const handlerBody = deindent `
  13065. ${usesState && `var ctx = #component.get();`}
  13066. ${handler.snippet};
  13067. `;
  13068. if (isCustomEvent) {
  13069. // TODO dry this out
  13070. block.addVariable(handlerName);
  13071. block.builders.hydrate.addBlock(deindent `
  13072. ${handlerName} = %events-${handler.name}.call(#component, document, function(event) {
  13073. ${handlerBody}
  13074. });
  13075. `);
  13076. block.builders.destroy.addLine(deindent `
  13077. ${handlerName}.destroy();
  13078. `);
  13079. }
  13080. else {
  13081. block.builders.init.addBlock(deindent `
  13082. function ${handlerName}(event) {
  13083. ${handlerBody}
  13084. }
  13085. document.addEventListener("${handler.name}", ${handlerName});
  13086. `);
  13087. block.builders.destroy.addBlock(deindent `
  13088. document.removeEventListener("${handler.name}", ${handlerName});
  13089. `);
  13090. }
  13091. });
  13092. }
  13093. }
  13094. class ElseBlockWrapper extends Wrapper {
  13095. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  13096. super(renderer, block, parent, node);
  13097. this.var = null;
  13098. this.block = block.child({
  13099. comment: createDebuggingComment(node, this.renderer.component),
  13100. name: this.renderer.component.getUniqueName(`create_else_block`)
  13101. });
  13102. this.fragment = new FragmentWrapper(renderer, this.block, this.node.children, parent, stripWhitespace, nextSibling);
  13103. this.isDynamic = this.block.dependencies.size > 0;
  13104. if (this.isDynamic) {
  13105. // TODO this can't be right
  13106. this.block.hasUpdateMethod = true;
  13107. }
  13108. }
  13109. }
  13110. class EachBlockWrapper extends Wrapper {
  13111. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  13112. super(renderer, block, parent, node);
  13113. this.var = 'each';
  13114. this.hasBinding = false;
  13115. this.cannotUseInnerHTML();
  13116. const { dependencies } = node.expression;
  13117. block.addDependencies(dependencies);
  13118. this.block = block.child({
  13119. comment: createDebuggingComment(this.node, this.renderer.component),
  13120. name: renderer.component.getUniqueName('create_each_block'),
  13121. key: node.key,
  13122. bindings: new Map(block.bindings),
  13123. contextOwners: new Map(block.contextOwners)
  13124. });
  13125. // TODO this seems messy
  13126. this.block.hasAnimation = this.node.hasAnimation;
  13127. this.indexName = this.node.index || renderer.component.getUniqueName(`${this.node.context}_index`);
  13128. node.contexts.forEach(prop => {
  13129. this.block.contextOwners.set(prop.key.name, this);
  13130. // TODO this doesn't feel great
  13131. this.block.bindings.set(prop.key.name, () => `ctx.${this.vars.each_block_value}[ctx.${this.indexName}]${prop.tail}`);
  13132. });
  13133. if (this.node.index) {
  13134. this.block.getUniqueName(this.node.index); // this prevents name collisions (#1254)
  13135. }
  13136. renderer.blocks.push(this.block);
  13137. this.fragment = new FragmentWrapper(renderer, this.block, node.children, this, stripWhitespace, nextSibling);
  13138. if (this.node.else) {
  13139. this.else = new ElseBlockWrapper(renderer, block, this, this.node.else, stripWhitespace, nextSibling);
  13140. renderer.blocks.push(this.else.block);
  13141. if (this.else.isDynamic) {
  13142. this.block.addDependencies(this.else.block.dependencies);
  13143. }
  13144. }
  13145. block.addDependencies(this.block.dependencies);
  13146. this.block.hasUpdateMethod = this.block.dependencies.size > 0; // TODO should this logic be in Block?
  13147. if (this.block.hasOutros || (this.else && this.else.block.hasOutros)) {
  13148. block.addOutro();
  13149. }
  13150. }
  13151. render(block, parentNode, parentNodes) {
  13152. if (this.fragment.nodes.length === 0)
  13153. return;
  13154. const { renderer } = this;
  13155. const { component } = renderer;
  13156. // hack the sourcemap, so that if data is missing the bug
  13157. // is easy to find
  13158. let c = this.node.start + 2;
  13159. while (component.source[c] !== 'e')
  13160. c += 1;
  13161. component.code.overwrite(c, c + 4, 'length');
  13162. const length = `[✂${c}-${c + 4}✂]`;
  13163. const needsAnchor = this.next
  13164. ? !this.next.isDomNode() :
  13165. !parentNode || !this.parent.isDomNode();
  13166. this.vars = {
  13167. anchor: needsAnchor
  13168. ? block.getUniqueName(`${this.var}_anchor`)
  13169. : (this.next && this.next.var) || 'null',
  13170. create_each_block: this.block.name,
  13171. each_block_value: renderer.component.getUniqueName(`${this.var}_value`),
  13172. get_each_context: renderer.component.getUniqueName(`get_${this.var}_context`),
  13173. iterations: block.getUniqueName(`${this.var}_blocks`),
  13174. length: `[✂${c}-${c + 4}✂]`,
  13175. mountOrIntro: (this.block.hasIntroMethod || this.block.hasOutroMethod)
  13176. ? 'i'
  13177. : 'm'
  13178. };
  13179. this.contextProps = this.node.contexts.map(prop => `child_ctx.${prop.key.name} = list[i]${prop.tail};`);
  13180. if (this.hasBinding)
  13181. this.contextProps.push(`child_ctx.${this.vars.each_block_value} = list;`);
  13182. if (this.hasBinding || this.node.index)
  13183. this.contextProps.push(`child_ctx.${this.indexName} = i;`);
  13184. const { snippet } = this.node.expression;
  13185. block.builders.init.addLine(`var ${this.vars.each_block_value} = ${snippet};`);
  13186. renderer.blocks.push(deindent `
  13187. function ${this.vars.get_each_context}(ctx, list, i) {
  13188. const child_ctx = Object.create(ctx);
  13189. ${this.contextProps}
  13190. return child_ctx;
  13191. }
  13192. `);
  13193. if (this.node.key) {
  13194. this.renderKeyed(block, parentNode, parentNodes, snippet);
  13195. }
  13196. else {
  13197. this.renderUnkeyed(block, parentNode, parentNodes, snippet);
  13198. }
  13199. if (needsAnchor) {
  13200. block.addElement(this.vars.anchor, `@createComment()`, parentNodes && `@createComment()`, parentNode);
  13201. }
  13202. if (this.else) {
  13203. const each_block_else = component.getUniqueName(`${this.var}_else`);
  13204. const mountOrIntro = (this.else.block.hasIntroMethod || this.else.block.hasOutroMethod) ? 'i' : 'm';
  13205. block.builders.init.addLine(`var ${each_block_else} = null;`);
  13206. // TODO neaten this up... will end up with an empty line in the block
  13207. block.builders.init.addBlock(deindent `
  13208. if (!${this.vars.each_block_value}.${length}) {
  13209. ${each_block_else} = ${this.else.block.name}(#component, ctx);
  13210. ${each_block_else}.c();
  13211. }
  13212. `);
  13213. block.builders.mount.addBlock(deindent `
  13214. if (${each_block_else}) {
  13215. ${each_block_else}.${mountOrIntro}(${parentNode || '#target'}, null);
  13216. }
  13217. `);
  13218. const initialMountNode = parentNode || `${this.vars.anchor}.parentNode`;
  13219. if (this.else.block.hasUpdateMethod) {
  13220. block.builders.update.addBlock(deindent `
  13221. if (!${this.vars.each_block_value}.${length} && ${each_block_else}) {
  13222. ${each_block_else}.p(changed, ctx);
  13223. } else if (!${this.vars.each_block_value}.${length}) {
  13224. ${each_block_else} = ${this.else.block.name}(#component, ctx);
  13225. ${each_block_else}.c();
  13226. ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${this.vars.anchor});
  13227. } else if (${each_block_else}) {
  13228. ${each_block_else}.d(1);
  13229. ${each_block_else} = null;
  13230. }
  13231. `);
  13232. }
  13233. else {
  13234. block.builders.update.addBlock(deindent `
  13235. if (${this.vars.each_block_value}.${length}) {
  13236. if (${each_block_else}) {
  13237. ${each_block_else}.d(1);
  13238. ${each_block_else} = null;
  13239. }
  13240. } else if (!${each_block_else}) {
  13241. ${each_block_else} = ${this.else.block.name}(#component, ctx);
  13242. ${each_block_else}.c();
  13243. ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${this.vars.anchor});
  13244. }
  13245. `);
  13246. }
  13247. block.builders.destroy.addBlock(deindent `
  13248. if (${each_block_else}) ${each_block_else}.d(${parentNode ? '' : 'detach'});
  13249. `);
  13250. }
  13251. this.fragment.render(this.block, null, 'nodes');
  13252. if (this.else) {
  13253. this.else.fragment.render(this.else.block, null, 'nodes');
  13254. }
  13255. }
  13256. renderKeyed(block, parentNode, parentNodes, snippet) {
  13257. const { create_each_block, length, anchor, mountOrIntro, } = this.vars;
  13258. const get_key = block.getUniqueName('get_key');
  13259. const blocks = block.getUniqueName(`${this.var}_blocks`);
  13260. const lookup = block.getUniqueName(`${this.var}_lookup`);
  13261. block.addVariable(blocks, '[]');
  13262. block.addVariable(lookup, `@blankObject()`);
  13263. if (this.fragment.nodes[0].isDomNode()) {
  13264. this.block.first = this.fragment.nodes[0].var;
  13265. }
  13266. else {
  13267. this.block.first = this.block.getUniqueName('first');
  13268. this.block.addElement(this.block.first, `@createComment()`, parentNodes && `@createComment()`, null);
  13269. }
  13270. block.builders.init.addBlock(deindent `
  13271. const ${get_key} = ctx => ${this.node.key.snippet};
  13272. for (var #i = 0; #i < ${this.vars.each_block_value}.${length}; #i += 1) {
  13273. let child_ctx = ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i);
  13274. let key = ${get_key}(child_ctx);
  13275. ${blocks}[#i] = ${lookup}[key] = ${create_each_block}(#component, key, child_ctx);
  13276. }
  13277. `);
  13278. const initialMountNode = parentNode || '#target';
  13279. const updateMountNode = this.getUpdateMountNode(anchor);
  13280. const anchorNode = parentNode ? 'null' : 'anchor';
  13281. block.builders.create.addBlock(deindent `
  13282. for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].c();
  13283. `);
  13284. if (parentNodes) {
  13285. block.builders.claim.addBlock(deindent `
  13286. for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].l(${parentNodes});
  13287. `);
  13288. }
  13289. block.builders.mount.addBlock(deindent `
  13290. for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode});
  13291. `);
  13292. const dynamic = this.block.hasUpdateMethod;
  13293. const rects = block.getUniqueName('rects');
  13294. const destroy = this.node.hasAnimation
  13295. ? `@fixAndOutroAndDestroyBlock`
  13296. : this.block.hasOutros
  13297. ? `@outroAndDestroyBlock`
  13298. : `@destroyBlock`;
  13299. block.builders.update.addBlock(deindent `
  13300. const ${this.vars.each_block_value} = ${snippet};
  13301. ${this.block.hasOutros && `@groupOutros();`}
  13302. ${this.node.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].r();`}
  13303. ${blocks} = @updateKeyedEach(${blocks}, #component, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.vars.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, "${mountOrIntro}", ${anchor}, ${this.vars.get_each_context});
  13304. ${this.node.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].a();`}
  13305. `);
  13306. if (this.block.hasOutros && this.renderer.component.options.nestedTransitions) {
  13307. const countdown = block.getUniqueName('countdown');
  13308. block.builders.outro.addBlock(deindent `
  13309. const ${countdown} = @callAfter(#outrocallback, ${blocks}.length);
  13310. for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].o(${countdown});
  13311. `);
  13312. }
  13313. block.builders.destroy.addBlock(deindent `
  13314. for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].d(${parentNode ? '' : 'detach'});
  13315. `);
  13316. }
  13317. renderUnkeyed(block, parentNode, parentNodes, snippet) {
  13318. const { create_each_block, length, iterations, anchor, mountOrIntro, } = this.vars;
  13319. block.builders.init.addBlock(deindent `
  13320. var ${iterations} = [];
  13321. for (var #i = 0; #i < ${this.vars.each_block_value}.${length}; #i += 1) {
  13322. ${iterations}[#i] = ${create_each_block}(#component, ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i));
  13323. }
  13324. `);
  13325. const initialMountNode = parentNode || '#target';
  13326. const updateMountNode = this.getUpdateMountNode(anchor);
  13327. const anchorNode = parentNode ? 'null' : 'anchor';
  13328. block.builders.create.addBlock(deindent `
  13329. for (var #i = 0; #i < ${iterations}.length; #i += 1) {
  13330. ${iterations}[#i].c();
  13331. }
  13332. `);
  13333. if (parentNodes) {
  13334. block.builders.claim.addBlock(deindent `
  13335. for (var #i = 0; #i < ${iterations}.length; #i += 1) {
  13336. ${iterations}[#i].l(${parentNodes});
  13337. }
  13338. `);
  13339. }
  13340. block.builders.mount.addBlock(deindent `
  13341. for (var #i = 0; #i < ${iterations}.length; #i += 1) {
  13342. ${iterations}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode});
  13343. }
  13344. `);
  13345. const allDependencies = new Set(this.block.dependencies);
  13346. const { dependencies } = this.node.expression;
  13347. dependencies.forEach((dependency) => {
  13348. allDependencies.add(dependency);
  13349. });
  13350. const outroBlock = this.block.hasOutros && block.getUniqueName('outroBlock');
  13351. if (outroBlock) {
  13352. block.builders.init.addBlock(deindent `
  13353. function ${outroBlock}(i, detach, fn) {
  13354. if (${iterations}[i]) {
  13355. ${iterations}[i].o(() => {
  13356. if (detach) {
  13357. ${iterations}[i].d(detach);
  13358. ${iterations}[i] = null;
  13359. }
  13360. if (fn) fn();
  13361. });
  13362. }
  13363. }
  13364. `);
  13365. }
  13366. // TODO do this for keyed blocks as well
  13367. const condition = Array.from(allDependencies)
  13368. .map(dependency => `changed.${dependency}`)
  13369. .join(' || ');
  13370. if (condition !== '') {
  13371. const forLoopBody = this.block.hasUpdateMethod
  13372. ? (this.block.hasIntros || this.block.hasOutros)
  13373. ? deindent `
  13374. if (${iterations}[#i]) {
  13375. ${iterations}[#i].p(changed, child_ctx);
  13376. } else {
  13377. ${iterations}[#i] = ${create_each_block}(#component, child_ctx);
  13378. ${iterations}[#i].c();
  13379. }
  13380. ${iterations}[#i].i(${updateMountNode}, ${anchor});
  13381. `
  13382. : deindent `
  13383. if (${iterations}[#i]) {
  13384. ${iterations}[#i].p(changed, child_ctx);
  13385. } else {
  13386. ${iterations}[#i] = ${create_each_block}(#component, child_ctx);
  13387. ${iterations}[#i].c();
  13388. ${iterations}[#i].m(${updateMountNode}, ${anchor});
  13389. }
  13390. `
  13391. : deindent `
  13392. ${iterations}[#i] = ${create_each_block}(#component, child_ctx);
  13393. ${iterations}[#i].c();
  13394. ${iterations}[#i].${mountOrIntro}(${updateMountNode}, ${anchor});
  13395. `;
  13396. const start = this.block.hasUpdateMethod ? '0' : `${iterations}.length`;
  13397. let destroy;
  13398. if (this.block.hasOutros) {
  13399. destroy = deindent `
  13400. @groupOutros();
  13401. for (; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 1);
  13402. `;
  13403. }
  13404. else {
  13405. destroy = deindent `
  13406. for (${this.block.hasUpdateMethod ? `` : `#i = ${this.vars.each_block_value}.${length}`}; #i < ${iterations}.length; #i += 1) {
  13407. ${iterations}[#i].d(1);
  13408. }
  13409. ${iterations}.length = ${this.vars.each_block_value}.${length};
  13410. `;
  13411. }
  13412. block.builders.update.addBlock(deindent `
  13413. if (${condition}) {
  13414. ${this.vars.each_block_value} = ${snippet};
  13415. for (var #i = ${start}; #i < ${this.vars.each_block_value}.${length}; #i += 1) {
  13416. const child_ctx = ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i);
  13417. ${forLoopBody}
  13418. }
  13419. ${destroy}
  13420. }
  13421. `);
  13422. }
  13423. if (outroBlock && this.renderer.component.options.nestedTransitions) {
  13424. const countdown = block.getUniqueName('countdown');
  13425. block.builders.outro.addBlock(deindent `
  13426. ${iterations} = ${iterations}.filter(Boolean);
  13427. const ${countdown} = @callAfter(#outrocallback, ${iterations}.length);
  13428. for (let #i = 0; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 0, ${countdown});`);
  13429. }
  13430. block.builders.destroy.addBlock(`@destroyEach(${iterations}, detach);`);
  13431. }
  13432. remount(name) {
  13433. // TODO consider keyed blocks
  13434. return `for (var #i = 0; #i < ${this.vars.iterations}.length; #i += 1) ${this.vars.iterations}[#i].m(${name}._slotted.default, null);`;
  13435. }
  13436. }
  13437. function isValidIdentifier(str) {
  13438. let i = 0;
  13439. while (i < str.length) {
  13440. const code = fullCharCodeAt(str, i);
  13441. if (!(i === 0 ? isIdentifierStart : isIdentifierChar)(code, true))
  13442. return false;
  13443. i += code <= 0xffff ? 1 : 2;
  13444. }
  13445. return true;
  13446. }
  13447. function quoteNameIfNecessary(name) {
  13448. if (!isValidIdentifier(name))
  13449. return `"${name}"`;
  13450. return name;
  13451. }
  13452. function quotePropIfNecessary(name) {
  13453. if (!isValidIdentifier(name))
  13454. return `["${name}"]`;
  13455. return `.${name}`;
  13456. }
  13457. const svgAttributes = 'accent-height accumulate additive alignment-baseline allowReorder alphabetic amplitude arabic-form ascent attributeName attributeType autoReverse azimuth baseFrequency baseline-shift baseProfile bbox begin bias by calcMode cap-height class clip clipPathUnits clip-path clip-rule color color-interpolation color-interpolation-filters color-profile color-rendering contentScriptType contentStyleType cursor cx cy d decelerate descent diffuseConstant direction display divisor dominant-baseline dur dx dy edgeMode elevation enable-background end exponent externalResourcesRequired fill fill-opacity fill-rule filter filterRes filterUnits flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight format from fr fx fy g1 g2 glyph-name glyph-orientation-horizontal glyph-orientation-vertical glyphRef gradientTransform gradientUnits hanging height href horiz-adv-x horiz-origin-x id ideographic image-rendering in in2 intercept k k1 k2 k3 k4 kernelMatrix kernelUnitLength kerning keyPoints keySplines keyTimes lang lengthAdjust letter-spacing lighting-color limitingConeAngle local marker-end marker-mid marker-start markerHeight markerUnits markerWidth mask maskContentUnits maskUnits mathematical max media method min mode name numOctaves offset onabort onactivate onbegin onclick onend onerror onfocusin onfocusout onload onmousedown onmousemove onmouseout onmouseover onmouseup onrepeat onresize onscroll onunload opacity operator order orient orientation origin overflow overline-position overline-thickness panose-1 paint-order pathLength patternContentUnits patternTransform patternUnits pointer-events points pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits r radius refX refY rendering-intent repeatCount repeatDur requiredExtensions requiredFeatures restart result rotate rx ry scale seed shape-rendering slope spacing specularConstant specularExponent speed spreadMethod startOffset stdDeviation stemh stemv stitchTiles stop-color stop-opacity strikethrough-position strikethrough-thickness string stroke stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width style surfaceScale systemLanguage tabindex tableValues target targetX targetY text-anchor text-decoration text-rendering textLength to transform type u1 u2 underline-position underline-thickness unicode unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical values version vert-adv-y vert-origin-x vert-origin-y viewBox viewTarget visibility width widths word-spacing writing-mode x x-height x1 x2 xChannelSelector xlink:actuate xlink:arcrole xlink:href xlink:role xlink:show xlink:title xlink:type xml:base xml:lang xml:space y y1 y2 yChannelSelector z zoomAndPan'.split(' ');
  13458. const svgAttributeLookup = new Map();
  13459. svgAttributes.forEach(name => {
  13460. svgAttributeLookup.set(name.toLowerCase(), name);
  13461. });
  13462. function fixAttributeCasing(name) {
  13463. name = name.toLowerCase();
  13464. return svgAttributeLookup.get(name) || name;
  13465. }
  13466. const html = 'http://www.w3.org/1999/xhtml';
  13467. const mathml = 'http://www.w3.org/1998/Math/MathML';
  13468. const svg = 'http://www.w3.org/2000/svg';
  13469. const xlink = 'http://www.w3.org/1999/xlink';
  13470. const xml = 'http://www.w3.org/XML/1998/namespace';
  13471. const xmlns = 'http://www.w3.org/2000/xmlns';
  13472. const validNamespaces = [
  13473. 'html',
  13474. 'mathml',
  13475. 'svg',
  13476. 'xlink',
  13477. 'xml',
  13478. 'xmlns',
  13479. html,
  13480. mathml,
  13481. svg,
  13482. xlink,
  13483. xml,
  13484. xmlns,
  13485. ];
  13486. const namespaces = { html, mathml, svg, xlink, xml, xmlns };
  13487. class AttributeWrapper {
  13488. constructor(parent, block, node) {
  13489. this.node = node;
  13490. this.parent = parent;
  13491. if (node.dependencies.size > 0) {
  13492. parent.cannotUseInnerHTML();
  13493. block.addDependencies(node.dependencies);
  13494. // special case — <option value={foo}> — see below
  13495. if (this.parent.node.name === 'option' && node.name === 'value') {
  13496. let select = this.parent;
  13497. while (select && (select.node.type !== 'Element' || select.node.name !== 'select'))
  13498. select = select.parent;
  13499. if (select && select.selectBindingDependencies) {
  13500. select.selectBindingDependencies.forEach(prop => {
  13501. this.node.dependencies.forEach((dependency) => {
  13502. this.parent.renderer.component.indirectDependencies.get(prop).add(dependency);
  13503. });
  13504. });
  13505. }
  13506. }
  13507. }
  13508. }
  13509. render(block) {
  13510. const element = this.parent;
  13511. const name = fixAttributeCasing(this.node.name);
  13512. let metadata = element.node.namespace ? null : attributeLookup[name];
  13513. if (metadata && metadata.appliesTo && !~metadata.appliesTo.indexOf(element.node.name))
  13514. metadata = null;
  13515. const isIndirectlyBoundValue = name === 'value' &&
  13516. (element.node.name === 'option' || // TODO check it's actually bound
  13517. (element.node.name === 'input' &&
  13518. element.node.bindings.find((binding) => /checked|group/.test(binding.name))));
  13519. const propertyName = isIndirectlyBoundValue
  13520. ? '__value'
  13521. : metadata && metadata.propertyName;
  13522. // xlink is a special case... we could maybe extend this to generic
  13523. // namespaced attributes but I'm not sure that's applicable in
  13524. // HTML5?
  13525. const method = /-/.test(element.node.name)
  13526. ? '@setCustomElementData'
  13527. : name.slice(0, 6) === 'xlink:'
  13528. ? '@setXlinkAttribute'
  13529. : '@setAttribute';
  13530. const isLegacyInputType = element.renderer.component.options.legacy && name === 'type' && this.parent.node.name === 'input';
  13531. const isDataSet = /^data-/.test(name) && !element.renderer.component.options.legacy && !element.node.namespace;
  13532. const camelCaseName = isDataSet ? name.replace('data-', '').replace(/(-\w)/g, function (m) {
  13533. return m[1].toUpperCase();
  13534. }) : name;
  13535. if (this.node.isDynamic) {
  13536. let value;
  13537. // TODO some of this code is repeated in Tag.ts — would be good to
  13538. // DRY it out if that's possible without introducing crazy indirection
  13539. if (this.node.chunks.length === 1) {
  13540. // single {tag} — may be a non-string
  13541. value = this.node.chunks[0].snippet;
  13542. }
  13543. else {
  13544. // '{foo} {bar}' — treat as string concatenation
  13545. value =
  13546. (this.node.chunks[0].type === 'Text' ? '' : `"" + `) +
  13547. this.node.chunks
  13548. .map((chunk) => {
  13549. if (chunk.type === 'Text') {
  13550. return stringify(chunk.data);
  13551. }
  13552. else {
  13553. return chunk.getPrecedence() <= 13
  13554. ? `(${chunk.snippet})`
  13555. : chunk.snippet;
  13556. }
  13557. })
  13558. .join(' + ');
  13559. }
  13560. const isSelectValueAttribute = name === 'value' && element.node.name === 'select';
  13561. const shouldCache = this.node.shouldCache || isSelectValueAttribute;
  13562. const last = shouldCache && block.getUniqueName(`${element.var}_${name.replace(/[^a-zA-Z_$]/g, '_')}_value`);
  13563. if (shouldCache)
  13564. block.addVariable(last);
  13565. let updater;
  13566. const init = shouldCache ? `${last} = ${value}` : value;
  13567. if (isLegacyInputType) {
  13568. block.builders.hydrate.addLine(`@setInputType(${element.var}, ${init});`);
  13569. updater = `@setInputType(${element.var}, ${shouldCache ? last : value});`;
  13570. }
  13571. else if (isSelectValueAttribute) {
  13572. // annoying special case
  13573. const isMultipleSelect = element.getStaticAttributeValue('multiple');
  13574. const i = block.getUniqueName('i');
  13575. const option = block.getUniqueName('option');
  13576. const ifStatement = isMultipleSelect
  13577. ? deindent `
  13578. ${option}.selected = ~${last}.indexOf(${option}.__value);`
  13579. : deindent `
  13580. if (${option}.__value === ${last}) {
  13581. ${option}.selected = true;
  13582. break;
  13583. }`;
  13584. updater = deindent `
  13585. for (var ${i} = 0; ${i} < ${element.var}.options.length; ${i} += 1) {
  13586. var ${option} = ${element.var}.options[${i}];
  13587. ${ifStatement}
  13588. }
  13589. `;
  13590. block.builders.mount.addBlock(deindent `
  13591. ${last} = ${value};
  13592. ${updater}
  13593. `);
  13594. }
  13595. else if (propertyName) {
  13596. block.builders.hydrate.addLine(`${element.var}.${propertyName} = ${init};`);
  13597. updater = `${element.var}.${propertyName} = ${shouldCache ? last : value};`;
  13598. }
  13599. else if (isDataSet) {
  13600. block.builders.hydrate.addLine(`${element.var}.dataset.${camelCaseName} = ${init};`);
  13601. updater = `${element.var}.dataset.${camelCaseName} = ${shouldCache ? last : value};`;
  13602. }
  13603. else {
  13604. block.builders.hydrate.addLine(`${method}(${element.var}, "${name}", ${init});`);
  13605. updater = `${method}(${element.var}, "${name}", ${shouldCache ? last : value});`;
  13606. }
  13607. if (this.node.dependencies.size || isSelectValueAttribute) {
  13608. const dependencies = Array.from(this.node.dependencies);
  13609. const changedCheck = ((block.hasOutros ? `!#current || ` : '') +
  13610. dependencies.map(dependency => `changed.${dependency}`).join(' || '));
  13611. const updateCachedValue = `${last} !== (${last} = ${value})`;
  13612. const condition = shouldCache ?
  13613. (dependencies.length ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue) :
  13614. changedCheck;
  13615. block.builders.update.addConditional(condition, updater);
  13616. }
  13617. }
  13618. else {
  13619. const value = this.node.getValue();
  13620. const statement = (isLegacyInputType
  13621. ? `@setInputType(${element.var}, ${value});`
  13622. : propertyName
  13623. ? `${element.var}.${propertyName} = ${value};`
  13624. : isDataSet
  13625. ? `${element.var}.dataset.${camelCaseName} = ${value};`
  13626. : `${method}(${element.var}, "${name}", ${value});`);
  13627. block.builders.hydrate.addLine(statement);
  13628. // special case – autofocus. has to be handled in a bit of a weird way
  13629. if (this.node.isTrue && name === 'autofocus') {
  13630. block.autofocus = element.var;
  13631. }
  13632. }
  13633. if (isIndirectlyBoundValue) {
  13634. const updateValue = `${element.var}.value = ${element.var}.__value;`;
  13635. block.builders.hydrate.addLine(updateValue);
  13636. if (this.node.isDynamic)
  13637. block.builders.update.addLine(updateValue);
  13638. }
  13639. }
  13640. stringify() {
  13641. const value = this.node.chunks;
  13642. if (value === true)
  13643. return '';
  13644. if (value.length === 0)
  13645. return `=""`;
  13646. return `="${value.map(chunk => {
  13647. return chunk.type === 'Text'
  13648. ? chunk.data.replace(/"/g, '\\"')
  13649. : `\${${chunk.snippet}}`;
  13650. })}"`;
  13651. }
  13652. }
  13653. // source: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
  13654. const attributeLookup = {
  13655. accept: { appliesTo: ['form', 'input'] },
  13656. 'accept-charset': { propertyName: 'acceptCharset', appliesTo: ['form'] },
  13657. accesskey: { propertyName: 'accessKey' },
  13658. action: { appliesTo: ['form'] },
  13659. align: {
  13660. appliesTo: [
  13661. 'applet',
  13662. 'caption',
  13663. 'col',
  13664. 'colgroup',
  13665. 'hr',
  13666. 'iframe',
  13667. 'img',
  13668. 'table',
  13669. 'tbody',
  13670. 'td',
  13671. 'tfoot',
  13672. 'th',
  13673. 'thead',
  13674. 'tr',
  13675. ],
  13676. },
  13677. allowfullscreen: { propertyName: 'allowFullscreen', appliesTo: ['iframe'] },
  13678. alt: { appliesTo: ['applet', 'area', 'img', 'input'] },
  13679. async: { appliesTo: ['script'] },
  13680. autocomplete: { appliesTo: ['form', 'input'] },
  13681. autofocus: { appliesTo: ['button', 'input', 'keygen', 'select', 'textarea'] },
  13682. autoplay: { appliesTo: ['audio', 'video'] },
  13683. autosave: { appliesTo: ['input'] },
  13684. bgcolor: {
  13685. propertyName: 'bgColor',
  13686. appliesTo: [
  13687. 'body',
  13688. 'col',
  13689. 'colgroup',
  13690. 'marquee',
  13691. 'table',
  13692. 'tbody',
  13693. 'tfoot',
  13694. 'td',
  13695. 'th',
  13696. 'tr',
  13697. ],
  13698. },
  13699. border: { appliesTo: ['img', 'object', 'table'] },
  13700. buffered: { appliesTo: ['audio', 'video'] },
  13701. challenge: { appliesTo: ['keygen'] },
  13702. charset: { appliesTo: ['meta', 'script'] },
  13703. checked: { appliesTo: ['command', 'input'] },
  13704. cite: { appliesTo: ['blockquote', 'del', 'ins', 'q'] },
  13705. class: { propertyName: 'className' },
  13706. code: { appliesTo: ['applet'] },
  13707. codebase: { propertyName: 'codeBase', appliesTo: ['applet'] },
  13708. color: { appliesTo: ['basefont', 'font', 'hr'] },
  13709. cols: { appliesTo: ['textarea'] },
  13710. colspan: { propertyName: 'colSpan', appliesTo: ['td', 'th'] },
  13711. content: { appliesTo: ['meta'] },
  13712. contenteditable: { propertyName: 'contentEditable' },
  13713. contextmenu: {},
  13714. controls: { appliesTo: ['audio', 'video'] },
  13715. coords: { appliesTo: ['area'] },
  13716. data: { appliesTo: ['object'] },
  13717. datetime: { propertyName: 'dateTime', appliesTo: ['del', 'ins', 'time'] },
  13718. default: { appliesTo: ['track'] },
  13719. defer: { appliesTo: ['script'] },
  13720. dir: {},
  13721. dirname: { propertyName: 'dirName', appliesTo: ['input', 'textarea'] },
  13722. disabled: {
  13723. appliesTo: [
  13724. 'button',
  13725. 'command',
  13726. 'fieldset',
  13727. 'input',
  13728. 'keygen',
  13729. 'optgroup',
  13730. 'option',
  13731. 'select',
  13732. 'textarea',
  13733. ],
  13734. },
  13735. download: { appliesTo: ['a', 'area'] },
  13736. draggable: {},
  13737. dropzone: {},
  13738. enctype: { appliesTo: ['form'] },
  13739. for: { propertyName: 'htmlFor', appliesTo: ['label', 'output'] },
  13740. form: {
  13741. appliesTo: [
  13742. 'button',
  13743. 'fieldset',
  13744. 'input',
  13745. 'keygen',
  13746. 'label',
  13747. 'meter',
  13748. 'object',
  13749. 'output',
  13750. 'progress',
  13751. 'select',
  13752. 'textarea',
  13753. ],
  13754. },
  13755. formaction: { appliesTo: ['input', 'button'] },
  13756. headers: { appliesTo: ['td', 'th'] },
  13757. height: {
  13758. appliesTo: ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video'],
  13759. },
  13760. hidden: {},
  13761. high: { appliesTo: ['meter'] },
  13762. href: { appliesTo: ['a', 'area', 'base', 'link'] },
  13763. hreflang: { appliesTo: ['a', 'area', 'link'] },
  13764. 'http-equiv': { propertyName: 'httpEquiv', appliesTo: ['meta'] },
  13765. icon: { appliesTo: ['command'] },
  13766. id: {},
  13767. indeterminate: { appliesTo: ['input'] },
  13768. ismap: { propertyName: 'isMap', appliesTo: ['img'] },
  13769. itemprop: {},
  13770. keytype: { appliesTo: ['keygen'] },
  13771. kind: { appliesTo: ['track'] },
  13772. label: { appliesTo: ['track'] },
  13773. lang: {},
  13774. language: { appliesTo: ['script'] },
  13775. loop: { appliesTo: ['audio', 'bgsound', 'marquee', 'video'] },
  13776. low: { appliesTo: ['meter'] },
  13777. manifest: { appliesTo: ['html'] },
  13778. max: { appliesTo: ['input', 'meter', 'progress'] },
  13779. maxlength: { propertyName: 'maxLength', appliesTo: ['input', 'textarea'] },
  13780. media: { appliesTo: ['a', 'area', 'link', 'source', 'style'] },
  13781. method: { appliesTo: ['form'] },
  13782. min: { appliesTo: ['input', 'meter'] },
  13783. multiple: { appliesTo: ['input', 'select'] },
  13784. muted: { appliesTo: ['audio', 'video'] },
  13785. name: {
  13786. appliesTo: [
  13787. 'button',
  13788. 'form',
  13789. 'fieldset',
  13790. 'iframe',
  13791. 'input',
  13792. 'keygen',
  13793. 'object',
  13794. 'output',
  13795. 'select',
  13796. 'textarea',
  13797. 'map',
  13798. 'meta',
  13799. 'param',
  13800. ],
  13801. },
  13802. novalidate: { propertyName: 'noValidate', appliesTo: ['form'] },
  13803. open: { appliesTo: ['details'] },
  13804. optimum: { appliesTo: ['meter'] },
  13805. pattern: { appliesTo: ['input'] },
  13806. ping: { appliesTo: ['a', 'area'] },
  13807. placeholder: { appliesTo: ['input', 'textarea'] },
  13808. poster: { appliesTo: ['video'] },
  13809. preload: { appliesTo: ['audio', 'video'] },
  13810. radiogroup: { appliesTo: ['command'] },
  13811. readonly: { propertyName: 'readOnly', appliesTo: ['input', 'textarea'] },
  13812. rel: { appliesTo: ['a', 'area', 'link'] },
  13813. required: { appliesTo: ['input', 'select', 'textarea'] },
  13814. reversed: { appliesTo: ['ol'] },
  13815. rows: { appliesTo: ['textarea'] },
  13816. rowspan: { propertyName: 'rowSpan', appliesTo: ['td', 'th'] },
  13817. sandbox: { appliesTo: ['iframe'] },
  13818. scope: { appliesTo: ['th'] },
  13819. scoped: { appliesTo: ['style'] },
  13820. seamless: { appliesTo: ['iframe'] },
  13821. selected: { appliesTo: ['option'] },
  13822. shape: { appliesTo: ['a', 'area'] },
  13823. size: { appliesTo: ['input', 'select'] },
  13824. sizes: { appliesTo: ['link', 'img', 'source'] },
  13825. span: { appliesTo: ['col', 'colgroup'] },
  13826. spellcheck: {},
  13827. src: {
  13828. appliesTo: [
  13829. 'audio',
  13830. 'embed',
  13831. 'iframe',
  13832. 'img',
  13833. 'input',
  13834. 'script',
  13835. 'source',
  13836. 'track',
  13837. 'video',
  13838. ],
  13839. },
  13840. srcdoc: { appliesTo: ['iframe'] },
  13841. srclang: { appliesTo: ['track'] },
  13842. srcset: { appliesTo: ['img'] },
  13843. start: { appliesTo: ['ol'] },
  13844. step: { appliesTo: ['input'] },
  13845. style: { propertyName: 'style.cssText' },
  13846. summary: { appliesTo: ['table'] },
  13847. tabindex: { propertyName: 'tabIndex' },
  13848. target: { appliesTo: ['a', 'area', 'base', 'form'] },
  13849. title: {},
  13850. type: {
  13851. appliesTo: [
  13852. 'button',
  13853. 'command',
  13854. 'embed',
  13855. 'object',
  13856. 'script',
  13857. 'source',
  13858. 'style',
  13859. 'menu',
  13860. ],
  13861. },
  13862. usemap: { propertyName: 'useMap', appliesTo: ['img', 'input', 'object'] },
  13863. value: {
  13864. appliesTo: [
  13865. 'button',
  13866. 'option',
  13867. 'input',
  13868. 'li',
  13869. 'meter',
  13870. 'progress',
  13871. 'param',
  13872. 'select',
  13873. 'textarea',
  13874. ],
  13875. },
  13876. volume: { appliesTo: ['audio', 'video'] },
  13877. width: {
  13878. appliesTo: ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video'],
  13879. },
  13880. wrap: { appliesTo: ['textarea'] },
  13881. };
  13882. Object.keys(attributeLookup).forEach(name => {
  13883. const metadata = attributeLookup[name];
  13884. if (!metadata.propertyName)
  13885. metadata.propertyName = name;
  13886. });
  13887. class StyleAttributeWrapper extends AttributeWrapper {
  13888. render(block) {
  13889. const styleProps = optimizeStyle(this.node.chunks);
  13890. if (!styleProps)
  13891. return super.render(block);
  13892. styleProps.forEach((prop) => {
  13893. let value;
  13894. if (isDynamic(prop.value)) {
  13895. const propDependencies = new Set();
  13896. value =
  13897. ((prop.value.length === 1 || prop.value[0].type === 'Text') ? '' : `"" + `) +
  13898. prop.value
  13899. .map((chunk) => {
  13900. if (chunk.type === 'Text') {
  13901. return stringify(chunk.data);
  13902. }
  13903. else {
  13904. const { dependencies, snippet } = chunk;
  13905. dependencies.forEach(d => {
  13906. propDependencies.add(d);
  13907. });
  13908. return chunk.getPrecedence() <= 13 ? `(${snippet})` : snippet;
  13909. }
  13910. })
  13911. .join(' + ');
  13912. if (propDependencies.size) {
  13913. const dependencies = Array.from(propDependencies);
  13914. const condition = ((block.hasOutros ? `!#current || ` : '') +
  13915. dependencies.map(dependency => `changed.${dependency}`).join(' || '));
  13916. block.builders.update.addConditional(condition, `@setStyle(${this.parent.var}, "${prop.key}", ${value});`);
  13917. }
  13918. }
  13919. else {
  13920. value = stringify(prop.value[0].data);
  13921. }
  13922. block.builders.hydrate.addLine(`@setStyle(${this.parent.var}, "${prop.key}", ${value});`);
  13923. });
  13924. }
  13925. }
  13926. function optimizeStyle(value) {
  13927. const props = [];
  13928. let chunks = value.slice();
  13929. while (chunks.length) {
  13930. const chunk = chunks[0];
  13931. if (chunk.type !== 'Text')
  13932. return null;
  13933. const keyMatch = /^\s*([\w-]+):\s*/.exec(chunk.data);
  13934. if (!keyMatch)
  13935. return null;
  13936. const key = keyMatch[1];
  13937. const offset = keyMatch.index + keyMatch[0].length;
  13938. const remainingData = chunk.data.slice(offset);
  13939. if (remainingData) {
  13940. chunks[0] = {
  13941. start: chunk.start + offset,
  13942. end: chunk.end,
  13943. type: 'Text',
  13944. data: remainingData
  13945. };
  13946. }
  13947. else {
  13948. chunks.shift();
  13949. }
  13950. const result = getStyleValue(chunks);
  13951. if (!result)
  13952. return null;
  13953. props.push({ key, value: result.value });
  13954. chunks = result.chunks;
  13955. }
  13956. return props;
  13957. }
  13958. function getStyleValue(chunks) {
  13959. const value = [];
  13960. let inUrl = false;
  13961. let quoteMark = null;
  13962. let escaped = false;
  13963. while (chunks.length) {
  13964. const chunk = chunks.shift();
  13965. if (chunk.type === 'Text') {
  13966. let c = 0;
  13967. while (c < chunk.data.length) {
  13968. const char = chunk.data[c];
  13969. if (escaped) {
  13970. escaped = false;
  13971. }
  13972. else if (char === '\\') {
  13973. escaped = true;
  13974. }
  13975. else if (char === quoteMark) ;
  13976. else if (char === '"' || char === "'") {
  13977. quoteMark = char;
  13978. }
  13979. else if (char === ')' && inUrl) {
  13980. inUrl = false;
  13981. }
  13982. else if (char === 'u' && chunk.data.slice(c, c + 4) === 'url(') {
  13983. inUrl = true;
  13984. }
  13985. else if (char === ';' && !inUrl && !quoteMark) {
  13986. break;
  13987. }
  13988. c += 1;
  13989. }
  13990. if (c > 0) {
  13991. value.push({
  13992. type: 'Text',
  13993. start: chunk.start,
  13994. end: chunk.start + c,
  13995. data: chunk.data.slice(0, c)
  13996. });
  13997. }
  13998. while (/[;\s]/.test(chunk.data[c]))
  13999. c += 1;
  14000. const remainingData = chunk.data.slice(c);
  14001. if (remainingData) {
  14002. chunks.unshift({
  14003. start: chunk.start + c,
  14004. end: chunk.end,
  14005. type: 'Text',
  14006. data: remainingData
  14007. });
  14008. break;
  14009. }
  14010. }
  14011. else {
  14012. value.push(chunk);
  14013. }
  14014. }
  14015. return {
  14016. chunks,
  14017. value
  14018. };
  14019. }
  14020. function isDynamic(value) {
  14021. return value.length > 1 || value[0].type !== 'Text';
  14022. }
  14023. function getObject(node) {
  14024. while (node.type === 'MemberExpression')
  14025. node = node.object;
  14026. return node;
  14027. }
  14028. function flattenReference(node) {
  14029. if (node.type === 'Expression')
  14030. throw new Error('bad');
  14031. const nodes = [];
  14032. const parts = [];
  14033. const propEnd = node.end;
  14034. while (node.type === 'MemberExpression') {
  14035. if (node.computed)
  14036. return null;
  14037. nodes.unshift(node.property);
  14038. parts.unshift(node.property.name);
  14039. node = node.object;
  14040. }
  14041. const propStart = node.end;
  14042. const name = node.type === 'Identifier'
  14043. ? node.name
  14044. : node.type === 'ThisExpression' ? 'this' : null;
  14045. if (!name)
  14046. return null;
  14047. parts.unshift(name);
  14048. nodes.unshift(node);
  14049. return { name, nodes, parts, keypath: `${name}[✂${propStart}-${propEnd}✂]` };
  14050. }
  14051. function getTailSnippet(node) {
  14052. const end = node.end;
  14053. while (node.type === 'MemberExpression')
  14054. node = node.object;
  14055. const start = node.end;
  14056. return `[✂${start}-${end}✂]`;
  14057. }
  14058. // TODO this should live in a specific binding
  14059. const readOnlyMediaAttributes = new Set([
  14060. 'duration',
  14061. 'buffered',
  14062. 'seekable',
  14063. 'played'
  14064. ]);
  14065. class BindingWrapper {
  14066. constructor(block, node, parent) {
  14067. this.node = node;
  14068. this.parent = parent;
  14069. const { dependencies } = this.node.value;
  14070. block.addDependencies(dependencies);
  14071. // TODO does this also apply to e.g. `<input type='checkbox' bind:group='foo'>`?
  14072. if (parent.node.name === 'select') {
  14073. parent.selectBindingDependencies = dependencies;
  14074. dependencies.forEach((prop) => {
  14075. parent.renderer.component.indirectDependencies.set(prop, new Set());
  14076. });
  14077. }
  14078. if (node.isContextual) {
  14079. // we need to ensure that the each block creates a context including
  14080. // the list and the index, if they're not otherwise referenced
  14081. const { name } = getObject(this.node.value.node);
  14082. const eachBlock = block.contextOwners.get(name);
  14083. eachBlock.hasBinding = true;
  14084. }
  14085. }
  14086. isReadOnlyMediaAttribute() {
  14087. return readOnlyMediaAttributes.has(this.node.name);
  14088. }
  14089. munge(block) {
  14090. const { parent } = this;
  14091. const { renderer } = parent;
  14092. const needsLock = (parent.node.name !== 'input' ||
  14093. !/radio|checkbox|range|color/.test(parent.node.getStaticAttributeValue('type')));
  14094. const isReadOnly = ((parent.node.isMediaNode() && readOnlyMediaAttributes.has(this.node.name)) ||
  14095. dimensions.test(this.node.name));
  14096. let updateConditions = [];
  14097. const { name } = getObject(this.node.value.node);
  14098. const { snippet } = this.node.value;
  14099. // special case: if you have e.g. `<input type=checkbox bind:checked=selected.done>`
  14100. // and `selected` is an object chosen with a <select>, then when `checked` changes,
  14101. // we need to tell the component to update all the values `selected` might be
  14102. // pointing to
  14103. // TODO should this happen in preprocess?
  14104. const dependencies = new Set(this.node.value.dependencies);
  14105. this.node.value.dependencies.forEach((prop) => {
  14106. const indirectDependencies = renderer.component.indirectDependencies.get(prop);
  14107. if (indirectDependencies) {
  14108. indirectDependencies.forEach(indirectDependency => {
  14109. dependencies.add(indirectDependency);
  14110. });
  14111. }
  14112. });
  14113. // view to model
  14114. const valueFromDom = getValueFromDom(renderer, this.parent, this);
  14115. const handler = getEventHandler(this, renderer, block, name, snippet, dependencies, valueFromDom);
  14116. // model to view
  14117. let updateDom = getDomUpdater(parent, this, snippet);
  14118. let initialUpdate = updateDom;
  14119. // special cases
  14120. if (this.node.name === 'group') {
  14121. const bindingGroup = getBindingGroup(renderer, this.node.value.node);
  14122. block.builders.hydrate.addLine(`#component._bindingGroups[${bindingGroup}].push(${parent.var});`);
  14123. block.builders.destroy.addLine(`#component._bindingGroups[${bindingGroup}].splice(#component._bindingGroups[${bindingGroup}].indexOf(${parent.var}), 1);`);
  14124. }
  14125. if (this.node.name === 'currentTime' || this.node.name === 'volume') {
  14126. updateConditions.push(`!isNaN(${snippet})`);
  14127. if (this.node.name === 'currentTime')
  14128. initialUpdate = null;
  14129. }
  14130. if (this.node.name === 'paused') {
  14131. // this is necessary to prevent audio restarting by itself
  14132. const last = block.getUniqueName(`${parent.var}_is_paused`);
  14133. block.addVariable(last, 'true');
  14134. updateConditions.push(`${last} !== (${last} = ${snippet})`);
  14135. updateDom = `${parent.var}[${last} ? "pause" : "play"]();`;
  14136. initialUpdate = null;
  14137. }
  14138. // bind:offsetWidth and bind:offsetHeight
  14139. if (dimensions.test(this.node.name)) {
  14140. initialUpdate = null;
  14141. updateDom = null;
  14142. }
  14143. const dependencyArray = [...this.node.value.dependencies];
  14144. if (dependencyArray.length === 1) {
  14145. updateConditions.push(`changed.${dependencyArray[0]}`);
  14146. }
  14147. else if (dependencyArray.length > 1) {
  14148. updateConditions.push(`(${dependencyArray.map(prop => `changed.${prop}`).join(' || ')})`);
  14149. }
  14150. return {
  14151. name: this.node.name,
  14152. object: name,
  14153. handler: handler,
  14154. usesContext: handler.usesContext,
  14155. updateDom: updateDom,
  14156. initialUpdate: initialUpdate,
  14157. needsLock: !isReadOnly && needsLock,
  14158. updateCondition: updateConditions.length ? updateConditions.join(' && ') : undefined,
  14159. isReadOnlyMediaAttribute: this.isReadOnlyMediaAttribute()
  14160. };
  14161. }
  14162. }
  14163. function getDomUpdater(element, binding, snippet) {
  14164. const { node } = element;
  14165. if (binding.isReadOnlyMediaAttribute()) {
  14166. return null;
  14167. }
  14168. if (node.name === 'select') {
  14169. return node.getStaticAttributeValue('multiple') === true ?
  14170. `@selectOptions(${element.var}, ${snippet})` :
  14171. `@selectOption(${element.var}, ${snippet})`;
  14172. }
  14173. if (binding.node.name === 'group') {
  14174. const type = node.getStaticAttributeValue('type');
  14175. const condition = type === 'checkbox'
  14176. ? `~${snippet}.indexOf(${element.var}.__value)`
  14177. : `${element.var}.__value === ${snippet}`;
  14178. return `${element.var}.checked = ${condition};`;
  14179. }
  14180. return `${element.var}.${binding.node.name} = ${snippet};`;
  14181. }
  14182. function getBindingGroup(renderer, value) {
  14183. const { parts } = flattenReference(value); // TODO handle cases involving computed member expressions
  14184. const keypath = parts.join('.');
  14185. // TODO handle contextual bindings — `keypath` should include unique ID of
  14186. // each block that provides context
  14187. let index = renderer.bindingGroups.indexOf(keypath);
  14188. if (index === -1) {
  14189. index = renderer.bindingGroups.length;
  14190. renderer.bindingGroups.push(keypath);
  14191. }
  14192. return index;
  14193. }
  14194. function getEventHandler(binding, renderer, block, name, snippet, dependencies, value) {
  14195. const storeDependencies = [...dependencies].filter(prop => prop[0] === '$').map(prop => prop.slice(1));
  14196. let dependenciesArray = [...dependencies].filter(prop => prop[0] !== '$');
  14197. if (binding.node.isContextual) {
  14198. const tail = binding.node.value.node.type === 'MemberExpression'
  14199. ? getTailSnippet(binding.node.value.node)
  14200. : '';
  14201. const head = block.bindings.get(name);
  14202. return {
  14203. usesContext: true,
  14204. usesState: true,
  14205. usesStore: storeDependencies.length > 0,
  14206. mutation: `${head()}${tail} = ${value};`,
  14207. props: dependenciesArray.map(prop => `${prop}: ctx.${prop}`),
  14208. storeProps: storeDependencies.map(prop => `${prop}: $.${prop}`)
  14209. };
  14210. }
  14211. if (binding.node.value.node.type === 'MemberExpression') {
  14212. // This is a little confusing, and should probably be tidied up
  14213. // at some point. It addresses a tricky bug (#893), wherein
  14214. // Svelte tries to `set()` a computed property, which throws an
  14215. // error in dev mode. a) it's possible that we should be
  14216. // replacing computations with *their* dependencies, and b)
  14217. // we should probably populate `component.target.readonly` sooner so
  14218. // that we don't have to do the `.some()` here
  14219. dependenciesArray = dependenciesArray.filter(prop => !renderer.component.computations.some(computation => computation.key === prop));
  14220. return {
  14221. usesContext: false,
  14222. usesState: true,
  14223. usesStore: storeDependencies.length > 0,
  14224. mutation: `${snippet} = ${value}`,
  14225. props: dependenciesArray.map((prop) => `${prop}: ctx.${prop}`),
  14226. storeProps: storeDependencies.map(prop => `${prop}: $.${prop}`)
  14227. };
  14228. }
  14229. let props;
  14230. let storeProps;
  14231. if (name[0] === '$') {
  14232. props = [];
  14233. storeProps = [`${name.slice(1)}: ${value}`];
  14234. }
  14235. else {
  14236. props = [`${name}: ${value}`];
  14237. storeProps = [];
  14238. }
  14239. return {
  14240. usesContext: false,
  14241. usesState: false,
  14242. usesStore: false,
  14243. mutation: null,
  14244. props,
  14245. storeProps
  14246. };
  14247. }
  14248. function getValueFromDom(renderer, element, binding) {
  14249. const { node } = element;
  14250. const { name } = binding.node;
  14251. // <select bind:value='selected>
  14252. if (node.name === 'select') {
  14253. return node.getStaticAttributeValue('multiple') === true ?
  14254. `@selectMultipleValue(${element.var})` :
  14255. `@selectValue(${element.var})`;
  14256. }
  14257. const type = node.getStaticAttributeValue('type');
  14258. // <input type='checkbox' bind:group='foo'>
  14259. if (name === 'group') {
  14260. const bindingGroup = getBindingGroup(renderer, binding.node.value.node);
  14261. if (type === 'checkbox') {
  14262. return `@getBindingGroupValue(#component._bindingGroups[${bindingGroup}])`;
  14263. }
  14264. return `${element.var}.__value`;
  14265. }
  14266. // <input type='range|number' bind:value>
  14267. if (type === 'range' || type === 'number') {
  14268. return `@toNumber(${element.var}.${name})`;
  14269. }
  14270. if ((name === 'buffered' || name === 'seekable' || name === 'played')) {
  14271. return `@timeRangesToArray(${element.var}.${name})`;
  14272. }
  14273. // everything else
  14274. return `${element.var}.${name}`;
  14275. }
  14276. const events = [
  14277. {
  14278. eventNames: ['input'],
  14279. filter: (node, name) => node.name === 'textarea' ||
  14280. node.name === 'input' && !/radio|checkbox|range/.test(node.getStaticAttributeValue('type'))
  14281. },
  14282. {
  14283. eventNames: ['change'],
  14284. filter: (node, name) => node.name === 'select' ||
  14285. node.name === 'input' && /radio|checkbox/.test(node.getStaticAttributeValue('type'))
  14286. },
  14287. {
  14288. eventNames: ['change', 'input'],
  14289. filter: (node, name) => node.name === 'input' && node.getStaticAttributeValue('type') === 'range'
  14290. },
  14291. {
  14292. eventNames: ['resize'],
  14293. filter: (node, name) => dimensions.test(name)
  14294. },
  14295. // media events
  14296. {
  14297. eventNames: ['timeupdate'],
  14298. filter: (node, name) => node.isMediaNode() &&
  14299. (name === 'currentTime' || name === 'played')
  14300. },
  14301. {
  14302. eventNames: ['durationchange'],
  14303. filter: (node, name) => node.isMediaNode() &&
  14304. name === 'duration'
  14305. },
  14306. {
  14307. eventNames: ['play', 'pause'],
  14308. filter: (node, name) => node.isMediaNode() &&
  14309. name === 'paused'
  14310. },
  14311. {
  14312. eventNames: ['progress'],
  14313. filter: (node, name) => node.isMediaNode() &&
  14314. name === 'buffered'
  14315. },
  14316. {
  14317. eventNames: ['loadedmetadata'],
  14318. filter: (node, name) => node.isMediaNode() &&
  14319. (name === 'buffered' || name === 'seekable')
  14320. },
  14321. {
  14322. eventNames: ['volumechange'],
  14323. filter: (node, name) => node.isMediaNode() &&
  14324. name === 'volume'
  14325. }
  14326. ];
  14327. class ElementWrapper extends Wrapper {
  14328. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  14329. super(renderer, block, parent, node);
  14330. this.var = node.name.replace(/[^a-zA-Z0-9_$]/g, '_');
  14331. this.classDependencies = [];
  14332. this.attributes = this.node.attributes.map(attribute => {
  14333. if (attribute.name === 'slot') {
  14334. // TODO make separate subclass for this?
  14335. let owner = this.parent;
  14336. while (owner) {
  14337. if (owner.node.type === 'InlineComponent') {
  14338. break;
  14339. }
  14340. if (owner.node.type === 'Element' && /-/.test(owner.node.name)) {
  14341. break;
  14342. }
  14343. owner = owner.parent;
  14344. }
  14345. if (owner && owner.node.type === 'InlineComponent') {
  14346. this.slotOwner = owner;
  14347. owner._slots.add(attribute.getStaticValue());
  14348. }
  14349. }
  14350. if (attribute.name === 'style') {
  14351. return new StyleAttributeWrapper(this, block, attribute);
  14352. }
  14353. return new AttributeWrapper(this, block, attribute);
  14354. });
  14355. let has_bindings;
  14356. const binding_lookup = {};
  14357. this.node.bindings.forEach(binding => {
  14358. binding_lookup[binding.name] = binding;
  14359. has_bindings = true;
  14360. });
  14361. const type = this.node.getStaticAttributeValue('type');
  14362. // ordinarily, there'll only be one... but we need to handle
  14363. // the rare case where an element can have multiple bindings,
  14364. // e.g. <audio bind:paused bind:currentTime>
  14365. this.bindings = this.node.bindings.map(binding => new BindingWrapper(block, binding, this));
  14366. // TODO remove this, it's just useful during refactoring
  14367. if (has_bindings && !this.bindings.length) {
  14368. throw new Error(`no binding was created`);
  14369. }
  14370. if (node.intro || node.outro) {
  14371. if (node.intro)
  14372. block.addIntro();
  14373. if (node.outro)
  14374. block.addOutro();
  14375. }
  14376. if (node.animation) {
  14377. block.addAnimation();
  14378. }
  14379. // add directive and handler dependencies
  14380. [node.animation, node.outro, ...node.actions, ...node.classes].forEach(directive => {
  14381. if (directive && directive.expression) {
  14382. block.addDependencies(directive.expression.dependencies);
  14383. }
  14384. });
  14385. node.handlers.forEach(handler => {
  14386. block.addDependencies(handler.dependencies);
  14387. });
  14388. if (this.parent) {
  14389. if (node.actions.length > 0)
  14390. this.parent.cannotUseInnerHTML();
  14391. if (node.animation)
  14392. this.parent.cannotUseInnerHTML();
  14393. if (node.bindings.length > 0)
  14394. this.parent.cannotUseInnerHTML();
  14395. if (node.classes.length > 0)
  14396. this.parent.cannotUseInnerHTML();
  14397. if (node.intro || node.outro)
  14398. this.parent.cannotUseInnerHTML();
  14399. if (node.handlers.length > 0)
  14400. this.parent.cannotUseInnerHTML();
  14401. if (node.ref)
  14402. this.parent.cannotUseInnerHTML();
  14403. if (this.node.name === 'option')
  14404. this.parent.cannotUseInnerHTML();
  14405. if (renderer.options.dev) {
  14406. this.parent.cannotUseInnerHTML(); // need to use addLoc
  14407. }
  14408. }
  14409. this.fragment = new FragmentWrapper(renderer, block, node.children, this, stripWhitespace, nextSibling);
  14410. }
  14411. render(block, parentNode, parentNodes) {
  14412. const { renderer } = this;
  14413. if (this.node.name === 'slot') {
  14414. const slotName = this.getStaticAttributeValue('name') || 'default';
  14415. renderer.slots.add(slotName);
  14416. }
  14417. if (this.node.name === 'noscript')
  14418. return;
  14419. const node = this.var;
  14420. const nodes = parentNodes && block.getUniqueName(`${this.var}_nodes`); // if we're in unclaimable territory, i.e. <head>, parentNodes is null
  14421. const slot = this.node.attributes.find((attribute) => attribute.name === 'slot');
  14422. const prop = slot && quotePropIfNecessary(slot.chunks[0].data);
  14423. let initialMountNode;
  14424. if (this.slotOwner) {
  14425. initialMountNode = `${this.slotOwner.var}._slotted${prop}`;
  14426. }
  14427. else {
  14428. initialMountNode = parentNode;
  14429. }
  14430. block.addVariable(node);
  14431. const renderStatement = this.getRenderStatement();
  14432. block.builders.create.addLine(`${node} = ${renderStatement};`);
  14433. if (renderer.options.hydratable) {
  14434. if (parentNodes) {
  14435. block.builders.claim.addBlock(deindent `
  14436. ${node} = ${this.getClaimStatement(parentNodes)};
  14437. var ${nodes} = @children(${this.node.name === 'template' ? `${node}.content` : node});
  14438. `);
  14439. }
  14440. else {
  14441. block.builders.claim.addLine(`${node} = ${renderStatement};`);
  14442. }
  14443. }
  14444. if (initialMountNode) {
  14445. block.builders.mount.addLine(`@append(${initialMountNode}, ${node});`);
  14446. if (initialMountNode === 'document.head') {
  14447. block.builders.destroy.addLine(`@detachNode(${node});`);
  14448. }
  14449. }
  14450. else {
  14451. block.builders.mount.addLine(`@insert(#target, ${node}, anchor);`);
  14452. // TODO we eventually need to consider what happens to elements
  14453. // that belong to the same outgroup as an outroing element...
  14454. block.builders.destroy.addConditional('detach', `@detachNode(${node});`);
  14455. }
  14456. // insert static children with textContent or innerHTML
  14457. if (!this.node.namespace && this.canUseInnerHTML && this.fragment.nodes.length > 0) {
  14458. if (this.fragment.nodes.length === 1 && this.fragment.nodes[0].node.type === 'Text') {
  14459. block.builders.create.addLine(`${node}.textContent = ${stringify(this.fragment.nodes[0].data)};`);
  14460. }
  14461. else {
  14462. const innerHTML = escape$1(this.fragment.nodes
  14463. .map(toHTML)
  14464. .join(''));
  14465. block.builders.create.addLine(`${node}.innerHTML = \`${innerHTML}\`;`);
  14466. }
  14467. }
  14468. else {
  14469. this.fragment.nodes.forEach((child) => {
  14470. child.render(block, this.node.name === 'template' ? `${node}.content` : node, nodes);
  14471. });
  14472. }
  14473. let hasHoistedEventHandlerOrBinding = (
  14474. //(this.hasAncestor('EachBlock') && this.bindings.length > 0) ||
  14475. this.node.handlers.some(handler => handler.shouldHoist));
  14476. const eventHandlerOrBindingUsesComponent = (this.bindings.length > 0 ||
  14477. this.node.handlers.some(handler => handler.usesComponent));
  14478. const eventHandlerOrBindingUsesContext = (this.bindings.some(binding => binding.node.usesContext) ||
  14479. this.node.handlers.some(handler => handler.usesContext));
  14480. if (hasHoistedEventHandlerOrBinding) {
  14481. const initialProps = [];
  14482. if (eventHandlerOrBindingUsesComponent) {
  14483. const component = block.alias('component');
  14484. initialProps.push(component === 'component' ? 'component' : `component: ${component}`);
  14485. }
  14486. if (eventHandlerOrBindingUsesContext) {
  14487. initialProps.push(`ctx`);
  14488. block.builders.update.addLine(`${node}._svelte.ctx = ctx;`);
  14489. block.maintainContext = true;
  14490. }
  14491. if (initialProps.length) {
  14492. block.builders.hydrate.addBlock(deindent `
  14493. ${node}._svelte = { ${initialProps.join(', ')} };
  14494. `);
  14495. }
  14496. }
  14497. else {
  14498. if (eventHandlerOrBindingUsesContext) {
  14499. block.maintainContext = true;
  14500. }
  14501. }
  14502. this.addBindings(block);
  14503. this.addEventHandlers(block);
  14504. if (this.node.ref)
  14505. this.addRef(block);
  14506. this.addAttributes(block);
  14507. this.addTransitions(block);
  14508. this.addAnimation(block);
  14509. this.addActions(block);
  14510. this.addClasses(block);
  14511. if (this.initialUpdate) {
  14512. block.builders.mount.addBlock(this.initialUpdate);
  14513. }
  14514. if (nodes) {
  14515. block.builders.claim.addLine(`${nodes}.forEach(@detachNode);`);
  14516. }
  14517. function toHTML(wrapper) {
  14518. if (wrapper.node.type === 'Text') {
  14519. const { parent } = wrapper.node;
  14520. const raw = parent && (parent.name === 'script' ||
  14521. parent.name === 'style');
  14522. return raw
  14523. ? wrapper.node.data
  14524. : escapeHTML(wrapper.node.data)
  14525. .replace(/\\/g, '\\\\')
  14526. .replace(/`/g, '\\`')
  14527. .replace(/\$/g, '\\$');
  14528. }
  14529. if (wrapper.node.name === 'noscript')
  14530. return '';
  14531. let open = `<${wrapper.node.name}`;
  14532. wrapper.attributes.forEach((attr) => {
  14533. open += ` ${fixAttributeCasing(attr.node.name)}${attr.stringify()}`;
  14534. });
  14535. if (isVoidElementName(wrapper.node.name))
  14536. return open + '>';
  14537. return `${open}>${wrapper.fragment.nodes.map(toHTML).join('')}</${wrapper.node.name}>`;
  14538. }
  14539. if (renderer.options.dev) {
  14540. const loc = renderer.locate(this.node.start);
  14541. block.builders.hydrate.addLine(`@addLoc(${this.var}, ${renderer.fileVar}, ${loc.line}, ${loc.column}, ${this.node.start});`);
  14542. }
  14543. }
  14544. getRenderStatement() {
  14545. const { name, namespace } = this.node;
  14546. if (namespace === 'http://www.w3.org/2000/svg') {
  14547. return `@createSvgElement("${name}")`;
  14548. }
  14549. if (namespace) {
  14550. return `document.createElementNS("${namespace}", "${name}")`;
  14551. }
  14552. return `@createElement("${name}")`;
  14553. }
  14554. getClaimStatement(nodes) {
  14555. const attributes = this.node.attributes
  14556. .filter((attr) => attr.type === 'Attribute')
  14557. .map((attr) => `${quoteNameIfNecessary(attr.name)}: true`)
  14558. .join(', ');
  14559. const name = this.node.namespace
  14560. ? this.node.name
  14561. : this.node.name.toUpperCase();
  14562. return `@claimElement(${nodes}, "${name}", ${attributes
  14563. ? `{ ${attributes} }`
  14564. : `{}`}, ${this.node.namespace === namespaces.svg ? true : false})`;
  14565. }
  14566. addBindings(block) {
  14567. const { renderer } = this;
  14568. if (this.bindings.length === 0)
  14569. return;
  14570. if (this.node.name === 'select' || this.isMediaNode()) {
  14571. this.renderer.hasComplexBindings = true;
  14572. }
  14573. const needsLock = this.node.name !== 'input' || !/radio|checkbox|range|color/.test(this.getStaticAttributeValue('type'));
  14574. // TODO munge in constructor
  14575. const mungedBindings = this.bindings.map(binding => binding.munge(block));
  14576. const lock = mungedBindings.some(binding => binding.needsLock) ?
  14577. block.getUniqueName(`${this.var}_updating`) :
  14578. null;
  14579. if (lock)
  14580. block.addVariable(lock, 'false');
  14581. const groups = events
  14582. .map(event => {
  14583. return {
  14584. events: event.eventNames,
  14585. bindings: mungedBindings.filter(binding => event.filter(this.node, binding.name))
  14586. };
  14587. })
  14588. .filter(group => group.bindings.length);
  14589. groups.forEach(group => {
  14590. const handler = block.getUniqueName(`${this.var}_${group.events.join('_')}_handler`);
  14591. const needsLock = group.bindings.some(binding => binding.needsLock);
  14592. group.bindings.forEach(binding => {
  14593. if (!binding.updateDom)
  14594. return;
  14595. const updateConditions = needsLock ? [`!${lock}`] : [];
  14596. if (binding.updateCondition)
  14597. updateConditions.push(binding.updateCondition);
  14598. block.builders.update.addLine(updateConditions.length ? `if (${updateConditions.join(' && ')}) ${binding.updateDom}` : binding.updateDom);
  14599. });
  14600. const usesStore = group.bindings.some(binding => binding.handler.usesStore);
  14601. const mutations = group.bindings.map(binding => binding.handler.mutation).filter(Boolean).join('\n');
  14602. const props = new Set();
  14603. const storeProps = new Set();
  14604. group.bindings.forEach(binding => {
  14605. binding.handler.props.forEach(prop => {
  14606. props.add(prop);
  14607. });
  14608. binding.handler.storeProps.forEach(prop => {
  14609. storeProps.add(prop);
  14610. });
  14611. }); // TODO use stringifyProps here, once indenting is fixed
  14612. // media bindings — awkward special case. The native timeupdate events
  14613. // fire too infrequently, so we need to take matters into our
  14614. // own hands
  14615. let animation_frame;
  14616. if (group.events[0] === 'timeupdate') {
  14617. animation_frame = block.getUniqueName(`${this.var}_animationframe`);
  14618. block.addVariable(animation_frame);
  14619. }
  14620. block.builders.init.addBlock(deindent `
  14621. function ${handler}() {
  14622. ${animation_frame && deindent `
  14623. cancelAnimationFrame(${animation_frame});
  14624. if (!${this.var}.paused) ${animation_frame} = requestAnimationFrame(${handler});`}
  14625. ${usesStore && `var $ = #component.store.get();`}
  14626. ${needsLock && `${lock} = true;`}
  14627. ${mutations.length > 0 && mutations}
  14628. ${props.size > 0 && `#component.set({ ${Array.from(props).join(', ')} });`}
  14629. ${storeProps.size > 0 && `#component.store.set({ ${Array.from(storeProps).join(', ')} });`}
  14630. ${needsLock && `${lock} = false;`}
  14631. }
  14632. `);
  14633. group.events.forEach(name => {
  14634. if (name === 'resize') {
  14635. // special case
  14636. const resize_listener = block.getUniqueName(`${this.var}_resize_listener`);
  14637. block.addVariable(resize_listener);
  14638. block.builders.mount.addLine(`${resize_listener} = @addResizeListener(${this.var}, ${handler});`);
  14639. block.builders.destroy.addLine(`${resize_listener}.cancel();`);
  14640. }
  14641. else {
  14642. block.builders.hydrate.addLine(`@addListener(${this.var}, "${name}", ${handler});`);
  14643. block.builders.destroy.addLine(`@removeListener(${this.var}, "${name}", ${handler});`);
  14644. }
  14645. });
  14646. const allInitialStateIsDefined = group.bindings
  14647. .map(binding => `'${binding.object}' in ctx`)
  14648. .join(' && ');
  14649. if (this.node.name === 'select' || group.bindings.find(binding => binding.name === 'indeterminate' || binding.isReadOnlyMediaAttribute)) {
  14650. renderer.hasComplexBindings = true;
  14651. block.builders.hydrate.addLine(`if (!(${allInitialStateIsDefined})) #component.root._beforecreate.push(${handler});`);
  14652. }
  14653. if (group.events[0] === 'resize') {
  14654. renderer.hasComplexBindings = true;
  14655. block.builders.hydrate.addLine(`#component.root._beforecreate.push(${handler});`);
  14656. }
  14657. });
  14658. this.initialUpdate = mungedBindings.map(binding => binding.initialUpdate).filter(Boolean).join('\n');
  14659. }
  14660. addAttributes(block) {
  14661. if (this.node.attributes.find(attr => attr.type === 'Spread')) {
  14662. this.addSpreadAttributes(block);
  14663. return;
  14664. }
  14665. this.attributes.forEach((attribute) => {
  14666. if (attribute.node.name === 'class' && attribute.node.isDynamic) {
  14667. this.classDependencies.push(...attribute.node.dependencies);
  14668. }
  14669. attribute.render(block);
  14670. });
  14671. }
  14672. addSpreadAttributes(block) {
  14673. const levels = block.getUniqueName(`${this.var}_levels`);
  14674. const data = block.getUniqueName(`${this.var}_data`);
  14675. const initialProps = [];
  14676. const updates = [];
  14677. this.node.attributes
  14678. .filter(attr => attr.type === 'Attribute' || attr.type === 'Spread')
  14679. .forEach(attr => {
  14680. const condition = attr.dependencies.size > 0
  14681. ? `(${[...attr.dependencies].map(d => `changed.${d}`).join(' || ')})`
  14682. : null;
  14683. if (attr.isSpread) {
  14684. const { snippet, dependencies } = attr.expression;
  14685. initialProps.push(snippet);
  14686. updates.push(condition ? `${condition} && ${snippet}` : snippet);
  14687. }
  14688. else {
  14689. const snippet = `{ ${quoteNameIfNecessary(attr.name)}: ${attr.getValue()} }`;
  14690. initialProps.push(snippet);
  14691. updates.push(condition ? `${condition} && ${snippet}` : snippet);
  14692. }
  14693. });
  14694. block.builders.init.addBlock(deindent `
  14695. var ${levels} = [
  14696. ${initialProps.join(',\n')}
  14697. ];
  14698. var ${data} = {};
  14699. for (var #i = 0; #i < ${levels}.length; #i += 1) {
  14700. ${data} = @assign(${data}, ${levels}[#i]);
  14701. }
  14702. `);
  14703. block.builders.hydrate.addLine(`@setAttributes(${this.var}, ${data});`);
  14704. block.builders.update.addBlock(deindent `
  14705. @setAttributes(${this.var}, @getSpreadUpdate(${levels}, [
  14706. ${updates.join(',\n')}
  14707. ]));
  14708. `);
  14709. }
  14710. addEventHandlers(block) {
  14711. const { renderer } = this;
  14712. const { component } = renderer;
  14713. this.node.handlers.forEach(handler => {
  14714. const isCustomEvent = component.events.has(handler.name);
  14715. if (handler.callee) {
  14716. // TODO move handler render method into a wrapper
  14717. handler.render(this.renderer.component, block, this.var, handler.shouldHoist);
  14718. }
  14719. const target = handler.shouldHoist ? 'this' : this.var;
  14720. // get a name for the event handler that is globally unique
  14721. // if hoisted, locally unique otherwise
  14722. const handlerName = (handler.shouldHoist ? component : block).getUniqueName(`${handler.name.replace(/[^a-zA-Z0-9_$]/g, '_')}_handler`);
  14723. const component_name = block.alias('component'); // can't use #component, might be hoisted
  14724. // create the handler body
  14725. const handlerBody = deindent `
  14726. ${handler.shouldHoist && (handler.usesComponent || handler.usesContext
  14727. ? `const { ${[handler.usesComponent && 'component', handler.usesContext && 'ctx'].filter(Boolean).join(', ')} } = ${target}._svelte;`
  14728. : null)}
  14729. ${handler.snippet ?
  14730. handler.snippet :
  14731. `${component_name}.fire("${handler.name}", event);`}
  14732. `;
  14733. if (isCustomEvent) {
  14734. block.addVariable(handlerName);
  14735. block.builders.hydrate.addBlock(deindent `
  14736. ${handlerName} = %events-${handler.name}.call(${component_name}, ${this.var}, function(event) {
  14737. ${handlerBody}
  14738. });
  14739. `);
  14740. block.builders.destroy.addLine(deindent `
  14741. ${handlerName}.destroy();
  14742. `);
  14743. }
  14744. else {
  14745. const modifiers = [];
  14746. if (handler.modifiers.has('preventDefault'))
  14747. modifiers.push('event.preventDefault();');
  14748. if (handler.modifiers.has('stopPropagation'))
  14749. modifiers.push('event.stopPropagation();');
  14750. const handlerFunction = deindent `
  14751. function ${handlerName}(event) {
  14752. ${modifiers}
  14753. ${handlerBody}
  14754. }
  14755. `;
  14756. if (handler.shouldHoist) {
  14757. renderer.blocks.push(handlerFunction);
  14758. }
  14759. else {
  14760. block.builders.init.addBlock(handlerFunction);
  14761. }
  14762. const opts = ['passive', 'once', 'capture'].filter(mod => handler.modifiers.has(mod));
  14763. if (opts.length) {
  14764. const optString = (opts.length === 1 && opts[0] === 'capture')
  14765. ? 'true'
  14766. : `{ ${opts.map(opt => `${opt}: true`).join(', ')} }`;
  14767. block.builders.hydrate.addLine(`@addListener(${this.var}, "${handler.name}", ${handlerName}, ${optString});`);
  14768. block.builders.destroy.addLine(`@removeListener(${this.var}, "${handler.name}", ${handlerName}, ${optString});`);
  14769. }
  14770. else {
  14771. block.builders.hydrate.addLine(`@addListener(${this.var}, "${handler.name}", ${handlerName});`);
  14772. block.builders.destroy.addLine(`@removeListener(${this.var}, "${handler.name}", ${handlerName});`);
  14773. }
  14774. }
  14775. });
  14776. }
  14777. addRef(block) {
  14778. const ref = `#component.refs.${this.node.ref.name}`;
  14779. block.builders.mount.addLine(`${ref} = ${this.var};`);
  14780. block.builders.destroy.addLine(`if (${ref} === ${this.var}) ${ref} = null;`);
  14781. }
  14782. addTransitions(block) {
  14783. const { intro, outro } = this.node;
  14784. if (!intro && !outro)
  14785. return;
  14786. if (intro === outro) {
  14787. const name = block.getUniqueName(`${this.var}_transition`);
  14788. const snippet = intro.expression
  14789. ? intro.expression.snippet
  14790. : '{}';
  14791. block.addVariable(name);
  14792. const fn = `%transitions-${intro.name}`;
  14793. block.builders.intro.addConditional(`#component.root._intro`, deindent `
  14794. if (${name}) ${name}.invalidate();
  14795. #component.root._aftercreate.push(() => {
  14796. if (!${name}) ${name} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true);
  14797. ${name}.run(1);
  14798. });
  14799. `);
  14800. block.builders.outro.addBlock(deindent `
  14801. if (!${name}) ${name} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, false);
  14802. ${name}.run(0, () => {
  14803. #outrocallback();
  14804. ${name} = null;
  14805. });
  14806. `);
  14807. block.builders.destroy.addConditional('detach', `if (${name}) ${name}.abort();`);
  14808. }
  14809. else {
  14810. const introName = intro && block.getUniqueName(`${this.var}_intro`);
  14811. const outroName = outro && block.getUniqueName(`${this.var}_outro`);
  14812. if (intro) {
  14813. block.addVariable(introName);
  14814. const snippet = intro.expression
  14815. ? intro.expression.snippet
  14816. : '{}';
  14817. const fn = `%transitions-${intro.name}`; // TODO add built-in transitions?
  14818. if (outro) {
  14819. block.builders.intro.addBlock(deindent `
  14820. if (${introName}) ${introName}.abort(1);
  14821. if (${outroName}) ${outroName}.abort(1);
  14822. `);
  14823. }
  14824. block.builders.intro.addConditional(`#component.root._intro`, deindent `
  14825. #component.root._aftercreate.push(() => {
  14826. ${introName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true);
  14827. ${introName}.run(1);
  14828. });
  14829. `);
  14830. }
  14831. if (outro) {
  14832. block.addVariable(outroName);
  14833. const snippet = outro.expression
  14834. ? outro.expression.snippet
  14835. : '{}';
  14836. const fn = `%transitions-${outro.name}`;
  14837. block.builders.intro.addBlock(deindent `
  14838. if (${outroName}) ${outroName}.abort(1);
  14839. `);
  14840. // TODO hide elements that have outro'd (unless they belong to a still-outroing
  14841. // group) prior to their removal from the DOM
  14842. block.builders.outro.addBlock(deindent `
  14843. ${outroName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, false);
  14844. ${outroName}.run(0, #outrocallback);
  14845. `);
  14846. block.builders.destroy.addConditional('detach', `if (${outroName}) ${outroName}.abort();`);
  14847. }
  14848. }
  14849. }
  14850. addAnimation(block) {
  14851. if (!this.node.animation)
  14852. return;
  14853. const rect = block.getUniqueName('rect');
  14854. const animation = block.getUniqueName('animation');
  14855. block.addVariable(rect);
  14856. block.addVariable(animation);
  14857. block.builders.measure.addBlock(deindent `
  14858. ${rect} = ${this.var}.getBoundingClientRect();
  14859. `);
  14860. block.builders.fix.addBlock(deindent `
  14861. @fixPosition(${this.var});
  14862. if (${animation}) ${animation}.stop();
  14863. `);
  14864. const params = this.node.animation.expression ? this.node.animation.expression.snippet : '{}';
  14865. block.builders.animate.addBlock(deindent `
  14866. if (${animation}) ${animation}.stop();
  14867. ${animation} = @wrapAnimation(${this.var}, ${rect}, %animations-${this.node.animation.name}, ${params});
  14868. `);
  14869. }
  14870. addActions(block) {
  14871. this.node.actions.forEach(action => {
  14872. const { expression } = action;
  14873. let snippet, dependencies;
  14874. if (expression) {
  14875. snippet = expression.snippet;
  14876. dependencies = expression.dependencies;
  14877. }
  14878. const name = block.getUniqueName(`${action.name.replace(/[^a-zA-Z0-9_$]/g, '_')}_action`);
  14879. block.addVariable(name);
  14880. const fn = `%actions-${action.name}`;
  14881. block.builders.mount.addLine(`${name} = ${fn}.call(#component, ${this.var}${snippet ? `, ${snippet}` : ''}) || {};`);
  14882. if (dependencies && dependencies.size > 0) {
  14883. let conditional = `typeof ${name}.update === 'function' && `;
  14884. const deps = [...dependencies].map(dependency => `changed.${dependency}`).join(' || ');
  14885. conditional += dependencies.size > 1 ? `(${deps})` : deps;
  14886. block.builders.update.addConditional(conditional, `${name}.update.call(#component, ${snippet});`);
  14887. }
  14888. block.builders.destroy.addLine(`if (${name} && typeof ${name}.destroy === 'function') ${name}.destroy.call(#component);`);
  14889. });
  14890. }
  14891. addClasses(block) {
  14892. this.node.classes.forEach(classDir => {
  14893. const { expression, name } = classDir;
  14894. let snippet, dependencies;
  14895. if (expression) {
  14896. snippet = expression.snippet;
  14897. dependencies = expression.dependencies;
  14898. }
  14899. else {
  14900. snippet = `ctx${quotePropIfNecessary(name)}`;
  14901. dependencies = new Set([name]);
  14902. }
  14903. const updater = `@toggleClass(${this.var}, "${name}", ${snippet});`;
  14904. block.builders.hydrate.addLine(updater);
  14905. if ((dependencies && dependencies.size > 0) || this.classDependencies.length) {
  14906. const allDeps = this.classDependencies.concat(...dependencies);
  14907. const deps = allDeps.map(dependency => `changed${quotePropIfNecessary(dependency)}`).join(' || ');
  14908. const condition = allDeps.length > 1 ? `(${deps})` : deps;
  14909. block.builders.update.addConditional(condition, updater);
  14910. }
  14911. });
  14912. }
  14913. getStaticAttributeValue(name) {
  14914. const attribute = this.node.attributes.find((attr) => attr.type === 'Attribute' && attr.name.toLowerCase() === name);
  14915. if (!attribute)
  14916. return null;
  14917. if (attribute.isTrue)
  14918. return true;
  14919. if (attribute.chunks.length === 0)
  14920. return '';
  14921. if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
  14922. return attribute.chunks[0].data;
  14923. }
  14924. return null;
  14925. }
  14926. isMediaNode() {
  14927. return this.node.name === 'audio' || this.node.name === 'video';
  14928. }
  14929. remount(name) {
  14930. const slot = this.attributes.find(attribute => attribute.name === 'slot');
  14931. if (slot) {
  14932. const prop = quotePropIfNecessary(slot.chunks[0].data);
  14933. return `@append(${name}._slotted${prop}, ${this.var});`;
  14934. }
  14935. return `@append(${name}._slotted.default, ${this.var});`;
  14936. }
  14937. addCssClass(className = this.component.stylesheet.id) {
  14938. const classAttribute = this.attributes.find(a => a.name === 'class');
  14939. if (classAttribute && !classAttribute.isTrue) {
  14940. if (classAttribute.chunks.length === 1 && classAttribute.chunks[0].type === 'Text') {
  14941. classAttribute.chunks[0].data += ` ${className}`;
  14942. }
  14943. else {
  14944. classAttribute.chunks.push(new Text(this.component, this, this.scope, {
  14945. type: 'Text',
  14946. data: ` ${className}`
  14947. }));
  14948. }
  14949. }
  14950. else {
  14951. this.attributes.push(new Attribute(this.component, this, this.scope, {
  14952. type: 'Attribute',
  14953. name: 'class',
  14954. value: [{ type: 'Text', data: className }]
  14955. }));
  14956. }
  14957. }
  14958. }
  14959. class HeadWrapper extends Wrapper {
  14960. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  14961. super(renderer, block, parent, node);
  14962. this.canUseInnerHTML = false;
  14963. this.fragment = new FragmentWrapper(renderer, block, node.children, this, stripWhitespace, nextSibling);
  14964. }
  14965. render(block, parentNode, parentNodes) {
  14966. this.fragment.render(block, 'document.head', null);
  14967. }
  14968. }
  14969. function isElseIf(node) {
  14970. return (node && node.children.length === 1 && node.children[0].type === 'IfBlock');
  14971. }
  14972. class IfBlockBranch extends Wrapper {
  14973. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  14974. super(renderer, block, parent, node);
  14975. this.var = null;
  14976. this.condition = node.expression && node.expression.snippet;
  14977. this.block = block.child({
  14978. comment: createDebuggingComment(node, parent.renderer.component),
  14979. name: parent.renderer.component.getUniqueName(node.expression ? `create_if_block` : `create_else_block`)
  14980. });
  14981. this.fragment = new FragmentWrapper(renderer, this.block, node.children, parent, stripWhitespace, nextSibling);
  14982. this.isDynamic = this.block.dependencies.size > 0;
  14983. }
  14984. }
  14985. class IfBlockWrapper extends Wrapper {
  14986. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  14987. super(renderer, block, parent, node);
  14988. this.var = 'if_block';
  14989. const { component } = renderer;
  14990. this.cannotUseInnerHTML();
  14991. this.branches = [];
  14992. const blocks = [];
  14993. let isDynamic = false;
  14994. let hasIntros = false;
  14995. let hasOutros = false;
  14996. const createBranches = (node) => {
  14997. const branch = new IfBlockBranch(renderer, block, this, node, stripWhitespace, nextSibling);
  14998. this.branches.push(branch);
  14999. blocks.push(branch.block);
  15000. block.addDependencies(node.expression.dependencies);
  15001. if (branch.block.dependencies.size > 0) {
  15002. isDynamic = true;
  15003. block.addDependencies(branch.block.dependencies);
  15004. }
  15005. if (branch.block.hasIntros)
  15006. hasIntros = true;
  15007. if (branch.block.hasOutros)
  15008. hasOutros = true;
  15009. if (isElseIf(node.else)) {
  15010. createBranches(node.else.children[0]);
  15011. }
  15012. else if (node.else) {
  15013. const branch = new IfBlockBranch(renderer, block, this, node.else, stripWhitespace, nextSibling);
  15014. this.branches.push(branch);
  15015. blocks.push(branch.block);
  15016. if (branch.block.dependencies.size > 0) {
  15017. isDynamic = true;
  15018. block.addDependencies(branch.block.dependencies);
  15019. }
  15020. if (branch.block.hasIntros)
  15021. hasIntros = true;
  15022. if (branch.block.hasOutros)
  15023. hasOutros = true;
  15024. }
  15025. };
  15026. createBranches(this.node);
  15027. if (component.options.nestedTransitions) {
  15028. if (hasIntros)
  15029. block.addIntro();
  15030. if (hasOutros)
  15031. block.addOutro();
  15032. }
  15033. blocks.forEach(block => {
  15034. block.hasUpdateMethod = isDynamic;
  15035. block.hasIntroMethod = hasIntros;
  15036. block.hasOutroMethod = hasOutros;
  15037. });
  15038. renderer.blocks.push(...blocks);
  15039. }
  15040. render(block, parentNode, parentNodes) {
  15041. const name = this.var;
  15042. const needsAnchor = this.next ? !this.next.isDomNode() : !parentNode || !this.parent.isDomNode();
  15043. const anchor = needsAnchor
  15044. ? block.getUniqueName(`${name}_anchor`)
  15045. : (this.next && this.next.var) || 'null';
  15046. const hasElse = !(this.branches[this.branches.length - 1].condition);
  15047. const if_name = hasElse ? '' : `if (${name}) `;
  15048. const dynamic = this.branches[0].block.hasUpdateMethod; // can use [0] as proxy for all, since they necessarily have the same value
  15049. const hasOutros = this.branches[0].block.hasOutroMethod;
  15050. const vars = { name, anchor, if_name, hasElse };
  15051. if (this.node.else) {
  15052. if (hasOutros) {
  15053. this.renderCompoundWithOutros(block, parentNode, parentNodes, dynamic, vars);
  15054. if (this.renderer.options.nestedTransitions) {
  15055. block.builders.outro.addBlock(deindent `
  15056. if (${name}) ${name}.o(#outrocallback);
  15057. else #outrocallback();
  15058. `);
  15059. }
  15060. }
  15061. else {
  15062. this.renderCompound(block, parentNode, parentNodes, dynamic, vars);
  15063. }
  15064. }
  15065. else {
  15066. this.renderSimple(block, parentNode, parentNodes, dynamic, vars);
  15067. if (hasOutros && this.renderer.options.nestedTransitions) {
  15068. block.builders.outro.addBlock(deindent `
  15069. if (${name}) ${name}.o(#outrocallback);
  15070. else #outrocallback();
  15071. `);
  15072. }
  15073. }
  15074. block.builders.create.addLine(`${if_name}${name}.c();`);
  15075. if (parentNodes) {
  15076. block.builders.claim.addLine(`${if_name}${name}.l(${parentNodes});`);
  15077. }
  15078. if (needsAnchor) {
  15079. block.addElement(anchor, `@createComment()`, parentNodes && `@createComment()`, parentNode);
  15080. }
  15081. this.branches.forEach(branch => {
  15082. branch.fragment.render(branch.block, null, 'nodes');
  15083. });
  15084. }
  15085. renderCompound(block, parentNode, parentNodes, dynamic, { name, anchor, hasElse, if_name }) {
  15086. const select_block_type = this.renderer.component.getUniqueName(`select_block_type`);
  15087. const current_block_type = block.getUniqueName(`current_block_type`);
  15088. const current_block_type_and = hasElse ? '' : `${current_block_type} && `;
  15089. block.builders.init.addBlock(deindent `
  15090. function ${select_block_type}(ctx) {
  15091. ${this.branches
  15092. .map(({ condition, block }) => `${condition ? `if (${condition}) ` : ''}return ${block.name};`)
  15093. .join('\n')}
  15094. }
  15095. `);
  15096. block.builders.init.addBlock(deindent `
  15097. var ${current_block_type} = ${select_block_type}(ctx);
  15098. var ${name} = ${current_block_type_and}${current_block_type}(#component, ctx);
  15099. `);
  15100. const mountOrIntro = this.branches[0].block.hasIntroMethod ? 'i' : 'm';
  15101. const initialMountNode = parentNode || '#target';
  15102. const anchorNode = parentNode ? 'null' : 'anchor';
  15103. block.builders.mount.addLine(`${if_name}${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode});`);
  15104. const updateMountNode = this.getUpdateMountNode(anchor);
  15105. const changeBlock = deindent `
  15106. ${if_name}${name}.d(1);
  15107. ${name} = ${current_block_type_and}${current_block_type}(#component, ctx);
  15108. ${if_name}${name}.c();
  15109. ${if_name}${name}.${mountOrIntro}(${updateMountNode}, ${anchor});
  15110. `;
  15111. if (dynamic) {
  15112. block.builders.update.addBlock(deindent `
  15113. if (${current_block_type} === (${current_block_type} = ${select_block_type}(ctx)) && ${name}) {
  15114. ${name}.p(changed, ctx);
  15115. } else {
  15116. ${changeBlock}
  15117. }
  15118. `);
  15119. }
  15120. else {
  15121. block.builders.update.addBlock(deindent `
  15122. if (${current_block_type} !== (${current_block_type} = ${select_block_type}(ctx))) {
  15123. ${changeBlock}
  15124. }
  15125. `);
  15126. }
  15127. block.builders.destroy.addLine(`${if_name}${name}.d(${parentNode ? '' : 'detach'});`);
  15128. }
  15129. // if any of the siblings have outros, we need to keep references to the blocks
  15130. // (TODO does this only apply to bidi transitions?)
  15131. renderCompoundWithOutros(block, parentNode, parentNodes, dynamic, { name, anchor, hasElse }) {
  15132. const select_block_type = this.renderer.component.getUniqueName(`select_block_type`);
  15133. const current_block_type_index = block.getUniqueName(`current_block_type_index`);
  15134. const previous_block_index = block.getUniqueName(`previous_block_index`);
  15135. const if_block_creators = block.getUniqueName(`if_block_creators`);
  15136. const if_blocks = block.getUniqueName(`if_blocks`);
  15137. const if_current_block_type_index = hasElse
  15138. ? ''
  15139. : `if (~${current_block_type_index}) `;
  15140. block.addVariable(current_block_type_index);
  15141. block.addVariable(name);
  15142. block.builders.init.addBlock(deindent `
  15143. var ${if_block_creators} = [
  15144. ${this.branches.map(branch => branch.block.name).join(',\n')}
  15145. ];
  15146. var ${if_blocks} = [];
  15147. function ${select_block_type}(ctx) {
  15148. ${this.branches
  15149. .map(({ condition }, i) => `${condition ? `if (${condition}) ` : ''}return ${i};`)
  15150. .join('\n')}
  15151. ${!hasElse && `return -1;`}
  15152. }
  15153. `);
  15154. if (hasElse) {
  15155. block.builders.init.addBlock(deindent `
  15156. ${current_block_type_index} = ${select_block_type}(ctx);
  15157. ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx);
  15158. `);
  15159. }
  15160. else {
  15161. block.builders.init.addBlock(deindent `
  15162. if (~(${current_block_type_index} = ${select_block_type}(ctx))) {
  15163. ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx);
  15164. }
  15165. `);
  15166. }
  15167. const mountOrIntro = this.branches[0].block.hasIntroMethod ? 'i' : 'm';
  15168. const initialMountNode = parentNode || '#target';
  15169. const anchorNode = parentNode ? 'null' : 'anchor';
  15170. block.builders.mount.addLine(`${if_current_block_type_index}${if_blocks}[${current_block_type_index}].${mountOrIntro}(${initialMountNode}, ${anchorNode});`);
  15171. const updateMountNode = this.getUpdateMountNode(anchor);
  15172. const destroyOldBlock = deindent `
  15173. @groupOutros();
  15174. ${name}.o(function() {
  15175. ${if_blocks}[${previous_block_index}].d(1);
  15176. ${if_blocks}[${previous_block_index}] = null;
  15177. });
  15178. `;
  15179. const createNewBlock = deindent `
  15180. ${name} = ${if_blocks}[${current_block_type_index}];
  15181. if (!${name}) {
  15182. ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx);
  15183. ${name}.c();
  15184. }
  15185. ${name}.${mountOrIntro}(${updateMountNode}, ${anchor});
  15186. `;
  15187. const changeBlock = hasElse
  15188. ? deindent `
  15189. ${destroyOldBlock}
  15190. ${createNewBlock}
  15191. `
  15192. : deindent `
  15193. if (${name}) {
  15194. ${destroyOldBlock}
  15195. }
  15196. if (~${current_block_type_index}) {
  15197. ${createNewBlock}
  15198. } else {
  15199. ${name} = null;
  15200. }
  15201. `;
  15202. if (dynamic) {
  15203. block.builders.update.addBlock(deindent `
  15204. var ${previous_block_index} = ${current_block_type_index};
  15205. ${current_block_type_index} = ${select_block_type}(ctx);
  15206. if (${current_block_type_index} === ${previous_block_index}) {
  15207. ${if_current_block_type_index}${if_blocks}[${current_block_type_index}].p(changed, ctx);
  15208. } else {
  15209. ${changeBlock}
  15210. }
  15211. `);
  15212. }
  15213. else {
  15214. block.builders.update.addBlock(deindent `
  15215. var ${previous_block_index} = ${current_block_type_index};
  15216. ${current_block_type_index} = ${select_block_type}(ctx);
  15217. if (${current_block_type_index} !== ${previous_block_index}) {
  15218. ${changeBlock}
  15219. }
  15220. `);
  15221. }
  15222. block.builders.destroy.addLine(deindent `
  15223. ${if_current_block_type_index}${if_blocks}[${current_block_type_index}].d(${parentNode ? '' : 'detach'});
  15224. `);
  15225. }
  15226. renderSimple(block, parentNode, parentNodes, dynamic, { name, anchor, if_name }) {
  15227. const branch = this.branches[0];
  15228. block.builders.init.addBlock(deindent `
  15229. var ${name} = (${branch.condition}) && ${branch.block.name}(#component, ctx);
  15230. `);
  15231. const mountOrIntro = branch.block.hasIntroMethod ? 'i' : 'm';
  15232. const initialMountNode = parentNode || '#target';
  15233. const anchorNode = parentNode ? 'null' : 'anchor';
  15234. block.builders.mount.addLine(`if (${name}) ${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode});`);
  15235. const updateMountNode = this.getUpdateMountNode(anchor);
  15236. const enter = dynamic
  15237. ? (branch.block.hasIntroMethod || branch.block.hasOutroMethod)
  15238. ? deindent `
  15239. if (${name}) {
  15240. ${name}.p(changed, ctx);
  15241. } else {
  15242. ${name} = ${branch.block.name}(#component, ctx);
  15243. if (${name}) ${name}.c();
  15244. }
  15245. ${name}.i(${updateMountNode}, ${anchor});
  15246. `
  15247. : deindent `
  15248. if (${name}) {
  15249. ${name}.p(changed, ctx);
  15250. } else {
  15251. ${name} = ${branch.block.name}(#component, ctx);
  15252. ${name}.c();
  15253. ${name}.m(${updateMountNode}, ${anchor});
  15254. }
  15255. `
  15256. : (branch.block.hasIntroMethod || branch.block.hasOutroMethod)
  15257. ? deindent `
  15258. if (!${name}) {
  15259. ${name} = ${branch.block.name}(#component, ctx);
  15260. ${name}.c();
  15261. }
  15262. ${name}.i(${updateMountNode}, ${anchor});
  15263. `
  15264. : deindent `
  15265. if (!${name}) {
  15266. ${name} = ${branch.block.name}(#component, ctx);
  15267. ${name}.c();
  15268. ${name}.m(${updateMountNode}, ${anchor});
  15269. }
  15270. `;
  15271. // no `p()` here — we don't want to update outroing nodes,
  15272. // as that will typically result in glitching
  15273. const exit = branch.block.hasOutroMethod
  15274. ? deindent `
  15275. @groupOutros();
  15276. ${name}.o(function() {
  15277. ${name}.d(1);
  15278. ${name} = null;
  15279. });
  15280. `
  15281. : deindent `
  15282. ${name}.d(1);
  15283. ${name} = null;
  15284. `;
  15285. block.builders.update.addBlock(deindent `
  15286. if (${branch.condition}) {
  15287. ${enter}
  15288. } else if (${name}) {
  15289. ${exit}
  15290. }
  15291. `);
  15292. block.builders.destroy.addLine(`${if_name}${name}.d(${parentNode ? '' : 'detach'});`);
  15293. }
  15294. }
  15295. function stringifyProps(props) {
  15296. if (!props.length)
  15297. return '{}';
  15298. const joined = props.join(', ');
  15299. if (joined.length > 40) {
  15300. // make larger data objects readable
  15301. return `{\n\t${props.join(',\n\t')}\n}`;
  15302. }
  15303. return `{ ${joined} }`;
  15304. }
  15305. class InlineComponentWrapper extends Wrapper {
  15306. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  15307. super(renderer, block, parent, node);
  15308. this.cannotUseInnerHTML();
  15309. if (this.node.expression) {
  15310. block.addDependencies(this.node.expression.dependencies);
  15311. }
  15312. this.node.attributes.forEach(attr => {
  15313. block.addDependencies(attr.dependencies);
  15314. });
  15315. this.node.bindings.forEach(binding => {
  15316. if (binding.isContextual) {
  15317. // we need to ensure that the each block creates a context including
  15318. // the list and the index, if they're not otherwise referenced
  15319. const { name } = getObject(binding.value.node);
  15320. const eachBlock = block.contextOwners.get(name);
  15321. eachBlock.hasBinding = true;
  15322. }
  15323. block.addDependencies(binding.value.dependencies);
  15324. });
  15325. this.node.handlers.forEach(handler => {
  15326. block.addDependencies(handler.dependencies);
  15327. });
  15328. this.var = (this.node.name === 'svelte:self' ? renderer.component.name :
  15329. this.node.name === 'svelte:component' ? 'switch_instance' :
  15330. this.node.name).toLowerCase();
  15331. if (this.node.children.length) {
  15332. this._slots = new Set(['default']);
  15333. this.fragment = new FragmentWrapper(renderer, block, node.children, this, stripWhitespace, nextSibling);
  15334. }
  15335. if (renderer.component.options.nestedTransitions) {
  15336. block.addOutro();
  15337. }
  15338. }
  15339. render(block, parentNode, parentNodes) {
  15340. const { renderer } = this;
  15341. const { component } = renderer;
  15342. const name = this.var;
  15343. const componentInitProperties = [
  15344. `root: #component.root`,
  15345. `store: #component.store`
  15346. ];
  15347. if (this.fragment) {
  15348. const slots = Array.from(this._slots).map(name => `${quoteNameIfNecessary(name)}: @createFragment()`);
  15349. componentInitProperties.push(`slots: { ${slots.join(', ')} }`);
  15350. this.fragment.nodes.forEach((child) => {
  15351. child.render(block, `${this.var}._slotted.default`, 'nodes');
  15352. });
  15353. }
  15354. const statements = [];
  15355. const name_initial_data = block.getUniqueName(`${name}_initial_data`);
  15356. const name_changes = block.getUniqueName(`${name}_changes`);
  15357. let name_updating;
  15358. let beforecreate = null;
  15359. const updates = [];
  15360. const usesSpread = !!this.node.attributes.find(a => a.isSpread);
  15361. const attributeObject = usesSpread
  15362. ? '{}'
  15363. : stringifyProps(this.node.attributes.map(attr => `${quoteNameIfNecessary(attr.name)}: ${attr.getValue()}`));
  15364. if (this.node.attributes.length || this.node.bindings.length) {
  15365. componentInitProperties.push(`data: ${name_initial_data}`);
  15366. }
  15367. if (!usesSpread && (this.node.attributes.filter(a => a.isDynamic).length || this.node.bindings.length)) {
  15368. updates.push(`var ${name_changes} = {};`);
  15369. }
  15370. if (this.node.attributes.length) {
  15371. if (usesSpread) {
  15372. const levels = block.getUniqueName(`${this.var}_spread_levels`);
  15373. const initialProps = [];
  15374. const changes = [];
  15375. const allDependencies = new Set();
  15376. this.node.attributes.forEach(attr => {
  15377. addToSet(allDependencies, attr.dependencies);
  15378. });
  15379. this.node.attributes.forEach(attr => {
  15380. const { name, dependencies } = attr;
  15381. const condition = dependencies.size > 0 && (dependencies.size !== allDependencies.size)
  15382. ? `(${[...dependencies].map(d => `changed.${d}`).join(' || ')})`
  15383. : null;
  15384. if (attr.isSpread) {
  15385. const value = attr.expression.snippet;
  15386. initialProps.push(value);
  15387. changes.push(condition ? `${condition} && ${value}` : value);
  15388. }
  15389. else {
  15390. const obj = `{ ${quoteNameIfNecessary(name)}: ${attr.getValue()} }`;
  15391. initialProps.push(obj);
  15392. changes.push(condition ? `${condition} && ${obj}` : obj);
  15393. }
  15394. });
  15395. block.builders.init.addBlock(deindent `
  15396. var ${levels} = [
  15397. ${initialProps.join(',\n')}
  15398. ];
  15399. `);
  15400. statements.push(deindent `
  15401. for (var #i = 0; #i < ${levels}.length; #i += 1) {
  15402. ${name_initial_data} = @assign(${name_initial_data}, ${levels}[#i]);
  15403. }
  15404. `);
  15405. const conditions = [...allDependencies].map(dep => `changed.${dep}`).join(' || ');
  15406. updates.push(deindent `
  15407. var ${name_changes} = ${allDependencies.size === 1 ? `${conditions}` : `(${conditions})`} ? @getSpreadUpdate(${levels}, [
  15408. ${changes.join(',\n')}
  15409. ]) : {};
  15410. `);
  15411. }
  15412. else {
  15413. this.node.attributes
  15414. .filter((attribute) => attribute.isDynamic)
  15415. .forEach((attribute) => {
  15416. if (attribute.dependencies.size > 0) {
  15417. updates.push(deindent `
  15418. if (${[...attribute.dependencies]
  15419. .map(dependency => `changed.${dependency}`)
  15420. .join(' || ')}) ${name_changes}${quotePropIfNecessary(attribute.name)} = ${attribute.getValue()};
  15421. `);
  15422. }
  15423. });
  15424. }
  15425. }
  15426. if (this.node.bindings.length) {
  15427. renderer.hasComplexBindings = true;
  15428. name_updating = block.alias(`${name}_updating`);
  15429. block.addVariable(name_updating, '{}');
  15430. let hasLocalBindings = false;
  15431. let hasStoreBindings = false;
  15432. const builder = new CodeBuilder();
  15433. this.node.bindings.forEach((binding) => {
  15434. let { name: key } = getObject(binding.value.node);
  15435. let setFromChild;
  15436. if (binding.isContextual) {
  15437. const computed = isComputed(binding.value.node);
  15438. const tail = binding.value.node.type === 'MemberExpression' ? getTailSnippet(binding.value.node) : '';
  15439. const head = block.bindings.get(key);
  15440. const lhs = binding.value.node.type === 'MemberExpression'
  15441. ? binding.value.snippet
  15442. : `${head()}${tail} = childState${quotePropIfNecessary(binding.name)}`;
  15443. setFromChild = deindent `
  15444. ${lhs} = childState${quotePropIfNecessary(binding.name)};
  15445. ${[...binding.value.dependencies]
  15446. .map((name) => {
  15447. const isStoreProp = name[0] === '$';
  15448. const prop = isStoreProp ? name.slice(1) : name;
  15449. const newState = isStoreProp ? 'newStoreState' : 'newState';
  15450. if (isStoreProp)
  15451. hasStoreBindings = true;
  15452. else
  15453. hasLocalBindings = true;
  15454. return `${newState}${quotePropIfNecessary(prop)} = ctx${quotePropIfNecessary(name)};`;
  15455. })}
  15456. `;
  15457. }
  15458. else {
  15459. const isStoreProp = key[0] === '$';
  15460. const prop = isStoreProp ? key.slice(1) : key;
  15461. const newState = isStoreProp ? 'newStoreState' : 'newState';
  15462. if (isStoreProp)
  15463. hasStoreBindings = true;
  15464. else
  15465. hasLocalBindings = true;
  15466. if (binding.value.node.type === 'MemberExpression') {
  15467. setFromChild = deindent `
  15468. ${binding.value.snippet} = childState${quotePropIfNecessary(binding.name)};
  15469. ${newState}${quotePropIfNecessary(prop)} = ctx${quotePropIfNecessary(key)};
  15470. `;
  15471. }
  15472. else {
  15473. setFromChild = `${newState}${quotePropIfNecessary(prop)} = childState${quotePropIfNecessary(binding.name)};`;
  15474. }
  15475. }
  15476. statements.push(deindent `
  15477. if (${binding.value.snippet} !== void 0) {
  15478. ${name_initial_data}${quotePropIfNecessary(binding.name)} = ${binding.value.snippet};
  15479. ${name_updating}${quotePropIfNecessary(binding.name)} = true;
  15480. }`);
  15481. builder.addConditional(`!${name_updating}${quotePropIfNecessary(binding.name)} && changed${quotePropIfNecessary(binding.name)}`, setFromChild);
  15482. updates.push(deindent `
  15483. if (!${name_updating}${quotePropIfNecessary(binding.name)} && ${[...binding.value.dependencies].map((dependency) => `changed.${dependency}`).join(' || ')}) {
  15484. ${name_changes}${quotePropIfNecessary(binding.name)} = ${binding.value.snippet};
  15485. ${name_updating}${quotePropIfNecessary(binding.name)} = ${binding.value.snippet} !== void 0;
  15486. }
  15487. `);
  15488. });
  15489. block.maintainContext = true; // TODO put this somewhere more logical
  15490. const initialisers = [
  15491. hasLocalBindings && 'newState = {}',
  15492. hasStoreBindings && 'newStoreState = {}',
  15493. ].filter(Boolean).join(', ');
  15494. // TODO use component.on('state', ...) instead of _bind
  15495. componentInitProperties.push(deindent `
  15496. _bind(changed, childState) {
  15497. var ${initialisers};
  15498. ${builder}
  15499. ${hasStoreBindings && `#component.store.set(newStoreState);`}
  15500. ${hasLocalBindings && `#component._set(newState);`}
  15501. ${name_updating} = {};
  15502. }
  15503. `);
  15504. beforecreate = deindent `
  15505. #component.root._beforecreate.push(() => {
  15506. ${name}._bind({ ${this.node.bindings.map(b => `${quoteNameIfNecessary(b.name)}: 1`).join(', ')} }, ${name}.get());
  15507. });
  15508. `;
  15509. }
  15510. this.node.handlers.forEach(handler => {
  15511. handler.var = block.getUniqueName(`${this.var}_${handler.name}`); // TODO this is hacky
  15512. handler.render(component, block, this.var, false); // TODO hoist when possible
  15513. if (handler.usesContext)
  15514. block.maintainContext = true; // TODO is there a better place to put this?
  15515. });
  15516. if (this.node.name === 'svelte:component') {
  15517. const switch_value = block.getUniqueName('switch_value');
  15518. const switch_props = block.getUniqueName('switch_props');
  15519. const { snippet } = this.node.expression;
  15520. block.builders.init.addBlock(deindent `
  15521. var ${switch_value} = ${snippet};
  15522. function ${switch_props}(ctx) {
  15523. ${(this.node.attributes.length || this.node.bindings.length) && deindent `
  15524. var ${name_initial_data} = ${attributeObject};`}
  15525. ${statements}
  15526. return {
  15527. ${componentInitProperties.join(',\n')}
  15528. };
  15529. }
  15530. if (${switch_value}) {
  15531. var ${name} = new ${switch_value}(${switch_props}(ctx));
  15532. ${beforecreate}
  15533. }
  15534. ${this.node.handlers.map(handler => deindent `
  15535. function ${handler.var}(event) {
  15536. ${handler.snippet || `#component.fire("${handler.name}", event);`}
  15537. }
  15538. if (${name}) ${name}.on("${handler.name}", ${handler.var});
  15539. `)}
  15540. `);
  15541. block.builders.create.addLine(`if (${name}) ${name}._fragment.c();`);
  15542. if (parentNodes) {
  15543. block.builders.claim.addLine(`if (${name}) ${name}._fragment.l(${parentNodes});`);
  15544. }
  15545. block.builders.mount.addBlock(deindent `
  15546. if (${name}) {
  15547. ${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});
  15548. ${this.node.ref && `#component.refs.${this.node.ref.name} = ${name};`}
  15549. }
  15550. `);
  15551. const anchor = this.getOrCreateAnchor(block, parentNode, parentNodes);
  15552. const updateMountNode = this.getUpdateMountNode(anchor);
  15553. if (updates.length) {
  15554. block.builders.update.addBlock(deindent `
  15555. ${updates}
  15556. `);
  15557. }
  15558. block.builders.update.addBlock(deindent `
  15559. if (${switch_value} !== (${switch_value} = ${snippet})) {
  15560. if (${name}) {
  15561. ${component.options.nestedTransitions
  15562. ? deindent `
  15563. @groupOutros();
  15564. const old_component = ${name};
  15565. old_component._fragment.o(() => {
  15566. old_component.destroy();
  15567. });`
  15568. : `${name}.destroy();`}
  15569. }
  15570. if (${switch_value}) {
  15571. ${name} = new ${switch_value}(${switch_props}(ctx));
  15572. ${this.node.bindings.length > 0 && deindent `
  15573. #component.root._beforecreate.push(() => {
  15574. const changed = {};
  15575. ${this.node.bindings.map(binding => deindent `
  15576. if (${binding.value.snippet} === void 0) changed.${binding.name} = 1;`)}
  15577. ${name}._bind(changed, ${name}.get());
  15578. });`}
  15579. ${name}._fragment.c();
  15580. ${this.fragment && this.fragment.nodes.map(child => child.remount(name))}
  15581. ${name}._mount(${updateMountNode}, ${anchor});
  15582. ${this.node.handlers.map(handler => deindent `
  15583. ${name}.on("${handler.name}", ${handler.var});
  15584. `)}
  15585. ${this.node.ref && `#component.refs.${this.node.ref.name} = ${name};`}
  15586. } else {
  15587. ${name} = null;
  15588. ${this.node.ref && deindent `
  15589. if (#component.refs.${this.node.ref.name} === ${name}) {
  15590. #component.refs.${this.node.ref.name} = null;
  15591. }`}
  15592. }
  15593. }
  15594. `);
  15595. if (updates.length) {
  15596. block.builders.update.addBlock(deindent `
  15597. else if (${switch_value}) {
  15598. ${name}._set(${name_changes});
  15599. ${this.node.bindings.length && `${name_updating} = {};`}
  15600. }
  15601. `);
  15602. }
  15603. block.builders.destroy.addLine(`if (${name}) ${name}.destroy(${parentNode ? '' : 'detach'});`);
  15604. }
  15605. else {
  15606. const expression = this.node.name === 'svelte:self'
  15607. ? component.name
  15608. : `%components-${this.node.name}`;
  15609. block.builders.init.addBlock(deindent `
  15610. ${(this.node.attributes.length || this.node.bindings.length) && deindent `
  15611. var ${name_initial_data} = ${attributeObject};`}
  15612. ${statements}
  15613. var ${name} = new ${expression}({
  15614. ${componentInitProperties.join(',\n')}
  15615. });
  15616. ${beforecreate}
  15617. ${this.node.handlers.map(handler => deindent `
  15618. ${name}.on("${handler.name}", function(event) {
  15619. ${handler.snippet || `#component.fire("${handler.name}", event);`}
  15620. });
  15621. `)}
  15622. ${this.node.ref && `#component.refs.${this.node.ref.name} = ${name};`}
  15623. `);
  15624. block.builders.create.addLine(`${name}._fragment.c();`);
  15625. if (parentNodes) {
  15626. block.builders.claim.addLine(`${name}._fragment.l(${parentNodes});`);
  15627. }
  15628. block.builders.mount.addLine(`${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});`);
  15629. if (updates.length) {
  15630. block.builders.update.addBlock(deindent `
  15631. ${updates}
  15632. ${name}._set(${name_changes});
  15633. ${this.node.bindings.length && `${name_updating} = {};`}
  15634. `);
  15635. }
  15636. block.builders.destroy.addLine(deindent `
  15637. ${name}.destroy(${parentNode ? '' : 'detach'});
  15638. ${this.node.ref && `if (#component.refs.${this.node.ref.name} === ${name}) #component.refs.${this.node.ref.name} = null;`}
  15639. `);
  15640. }
  15641. if (component.options.nestedTransitions) {
  15642. block.builders.outro.addLine(`if (${name}) ${name}._fragment.o(#outrocallback);`);
  15643. }
  15644. }
  15645. remount(name) {
  15646. return `${this.var}._mount(${name}._slotted.default, null);`;
  15647. }
  15648. }
  15649. function isComputed(node) {
  15650. while (node.type === 'MemberExpression') {
  15651. if (node.computed)
  15652. return true;
  15653. node = node.object;
  15654. }
  15655. return false;
  15656. }
  15657. class Tag extends Wrapper {
  15658. constructor(renderer, block, parent, node) {
  15659. super(renderer, block, parent, node);
  15660. this.cannotUseInnerHTML();
  15661. block.addDependencies(node.expression.dependencies);
  15662. }
  15663. render(block, parentNode, parentNodes) {
  15664. const { init } = this.renameThisMethod(block, value => `@setData(${this.var}, ${value});`);
  15665. block.addElement(this.var, `@createText(${init})`, parentNodes && `@claimText(${parentNodes}, ${init})`, parentNode);
  15666. }
  15667. renameThisMethod(block, update) {
  15668. const { snippet, dependencies } = this.node.expression;
  15669. const value = this.node.shouldCache && block.getUniqueName(`${this.var}_value`);
  15670. const content = this.node.shouldCache ? value : snippet;
  15671. if (this.node.shouldCache)
  15672. block.addVariable(value, snippet);
  15673. if (dependencies.size) {
  15674. const changedCheck = ((block.hasOutros ? `!#current || ` : '') +
  15675. [...dependencies].map((dependency) => `changed.${dependency}`).join(' || '));
  15676. const updateCachedValue = `${value} !== (${value} = ${snippet})`;
  15677. const condition = this.node.shouldCache ?
  15678. (dependencies.size ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue) :
  15679. changedCheck;
  15680. block.builders.update.addConditional(condition, update(content));
  15681. }
  15682. return { init: content };
  15683. }
  15684. remount(name) {
  15685. return `@append(${name}._slotted.default, ${this.var});`;
  15686. }
  15687. }
  15688. class MustacheTagWrapper extends Tag {
  15689. constructor(renderer, block, parent, node) {
  15690. super(renderer, block, parent, node);
  15691. this.var = 'text';
  15692. this.cannotUseInnerHTML();
  15693. }
  15694. render(block, parentNode, parentNodes) {
  15695. const { init } = this.renameThisMethod(block, value => `@setData(${this.var}, ${value});`);
  15696. block.addElement(this.var, `@createText(${init})`, parentNodes && `@claimText(${parentNodes}, ${init})`, parentNode);
  15697. }
  15698. }
  15699. class RawMustacheTagWrapper extends Tag {
  15700. constructor(renderer, block, parent, node) {
  15701. super(renderer, block, parent, node);
  15702. this.var = 'raw';
  15703. this.cannotUseInnerHTML();
  15704. }
  15705. render(block, parentNode, parentNodes) {
  15706. const name = this.var;
  15707. // TODO use isDomNode instead of type === 'Element'?
  15708. const needsAnchorBefore = this.prev ? this.prev.node.type !== 'Element' : !parentNode;
  15709. const needsAnchorAfter = this.next ? this.next.node.type !== 'Element' : !parentNode;
  15710. const anchorBefore = needsAnchorBefore
  15711. ? block.getUniqueName(`${name}_before`)
  15712. : (this.prev && this.prev.var) || 'null';
  15713. const anchorAfter = needsAnchorAfter
  15714. ? block.getUniqueName(`${name}_after`)
  15715. : (this.next && this.next.var) || 'null';
  15716. let detach;
  15717. let insert;
  15718. let useInnerHTML = false;
  15719. if (anchorBefore === 'null' && anchorAfter === 'null') {
  15720. useInnerHTML = true;
  15721. detach = `${parentNode}.innerHTML = '';`;
  15722. insert = content => `${parentNode}.innerHTML = ${content};`;
  15723. }
  15724. else if (anchorBefore === 'null') {
  15725. detach = `@detachBefore(${anchorAfter});`;
  15726. insert = content => `${anchorAfter}.insertAdjacentHTML("beforebegin", ${content});`;
  15727. }
  15728. else if (anchorAfter === 'null') {
  15729. detach = `@detachAfter(${anchorBefore});`;
  15730. insert = content => `${anchorBefore}.insertAdjacentHTML("afterend", ${content});`;
  15731. }
  15732. else {
  15733. detach = `@detachBetween(${anchorBefore}, ${anchorAfter});`;
  15734. insert = content => `${anchorBefore}.insertAdjacentHTML("afterend", ${content});`;
  15735. }
  15736. const { init } = this.renameThisMethod(block, content => deindent `
  15737. ${!useInnerHTML && detach}
  15738. ${insert(content)}
  15739. `);
  15740. // we would have used comments here, but the `insertAdjacentHTML` api only
  15741. // exists for `Element`s.
  15742. if (needsAnchorBefore) {
  15743. block.addElement(anchorBefore, `@createElement('noscript')`, parentNodes && `@createElement('noscript')`, parentNode, true);
  15744. }
  15745. function addAnchorAfter() {
  15746. block.addElement(anchorAfter, `@createElement('noscript')`, parentNodes && `@createElement('noscript')`, parentNode);
  15747. }
  15748. if (needsAnchorAfter && anchorBefore === 'null') {
  15749. // anchorAfter needs to be in the DOM before we
  15750. // insert the HTML...
  15751. addAnchorAfter();
  15752. }
  15753. block.builders.mount.addLine(insert(init));
  15754. if (!parentNode) {
  15755. block.builders.destroy.addConditional('detach', needsAnchorBefore
  15756. ? `${detach}\n@detachNode(${anchorBefore});`
  15757. : detach);
  15758. }
  15759. if (needsAnchorAfter && anchorBefore !== 'null') {
  15760. // ...otherwise it should go afterwards
  15761. addAnchorAfter();
  15762. }
  15763. }
  15764. }
  15765. function sanitize(name) {
  15766. return name.replace(/[^a-zA-Z]+/g, '_').replace(/^_/, '').replace(/_$/, '');
  15767. }
  15768. class SlotWrapper extends Wrapper {
  15769. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  15770. super(renderer, block, parent, node);
  15771. this.var = 'slot';
  15772. this.cannotUseInnerHTML();
  15773. this.fragment = new FragmentWrapper(renderer, block, node.children, parent, stripWhitespace, nextSibling);
  15774. }
  15775. render(block, parentNode, parentNodes) {
  15776. const { renderer } = this;
  15777. const slotName = this.node.getStaticAttributeValue('name') || 'default';
  15778. renderer.slots.add(slotName);
  15779. const content_name = block.getUniqueName(`slot_content_${sanitize(slotName)}`);
  15780. const prop = quotePropIfNecessary(slotName);
  15781. block.addVariable(content_name, `#component._slotted${prop}`);
  15782. // TODO can we use isDomNode instead of type === 'Element'?
  15783. const needsAnchorBefore = this.prev ? this.prev.node.type !== 'Element' : !parentNode;
  15784. const needsAnchorAfter = this.next ? this.next.node.type !== 'Element' : !parentNode;
  15785. const anchorBefore = needsAnchorBefore
  15786. ? block.getUniqueName(`${content_name}_before`)
  15787. : (this.prev && this.prev.var) || 'null';
  15788. const anchorAfter = needsAnchorAfter
  15789. ? block.getUniqueName(`${content_name}_after`)
  15790. : (this.next && this.next.var) || 'null';
  15791. if (needsAnchorBefore)
  15792. block.addVariable(anchorBefore);
  15793. if (needsAnchorAfter)
  15794. block.addVariable(anchorAfter);
  15795. let mountBefore = block.builders.mount.toString();
  15796. let destroyBefore = block.builders.destroy.toString();
  15797. block.builders.create.pushCondition(`!${content_name}`);
  15798. block.builders.hydrate.pushCondition(`!${content_name}`);
  15799. block.builders.mount.pushCondition(`!${content_name}`);
  15800. block.builders.update.pushCondition(`!${content_name}`);
  15801. block.builders.destroy.pushCondition(`!${content_name}`);
  15802. this.fragment.render(block, parentNode, parentNodes);
  15803. block.builders.create.popCondition();
  15804. block.builders.hydrate.popCondition();
  15805. block.builders.mount.popCondition();
  15806. block.builders.update.popCondition();
  15807. block.builders.destroy.popCondition();
  15808. const mountLeadin = block.builders.mount.toString() !== mountBefore
  15809. ? `else`
  15810. : `if (${content_name})`;
  15811. if (parentNode) {
  15812. block.builders.mount.addBlock(deindent `
  15813. ${mountLeadin} {
  15814. ${needsAnchorBefore && `@append(${parentNode}, ${anchorBefore} || (${anchorBefore} = @createComment()));`}
  15815. @append(${parentNode}, ${content_name});
  15816. ${needsAnchorAfter && `@append(${parentNode}, ${anchorAfter} || (${anchorAfter} = @createComment()));`}
  15817. }
  15818. `);
  15819. }
  15820. else {
  15821. block.builders.mount.addBlock(deindent `
  15822. ${mountLeadin} {
  15823. ${needsAnchorBefore && `@insert(#target, ${anchorBefore} || (${anchorBefore} = @createComment()), anchor);`}
  15824. @insert(#target, ${content_name}, anchor);
  15825. ${needsAnchorAfter && `@insert(#target, ${anchorAfter} || (${anchorAfter} = @createComment()), anchor);`}
  15826. }
  15827. `);
  15828. }
  15829. // if the slot is unmounted, move nodes back into the document fragment,
  15830. // so that it can be reinserted later
  15831. // TODO so that this can work with public API, component._slotted should
  15832. // be all fragments, derived from options.slots. Not === options.slots
  15833. const unmountLeadin = block.builders.destroy.toString() !== destroyBefore
  15834. ? `else`
  15835. : `if (${content_name})`;
  15836. if (anchorBefore === 'null' && anchorAfter === 'null') {
  15837. block.builders.destroy.addBlock(deindent `
  15838. ${unmountLeadin} {
  15839. @reinsertChildren(${parentNode}, ${content_name});
  15840. }
  15841. `);
  15842. }
  15843. else if (anchorBefore === 'null') {
  15844. block.builders.destroy.addBlock(deindent `
  15845. ${unmountLeadin} {
  15846. @reinsertBefore(${anchorAfter}, ${content_name});
  15847. }
  15848. `);
  15849. }
  15850. else if (anchorAfter === 'null') {
  15851. block.builders.destroy.addBlock(deindent `
  15852. ${unmountLeadin} {
  15853. @reinsertAfter(${anchorBefore}, ${content_name});
  15854. }
  15855. `);
  15856. }
  15857. else {
  15858. block.builders.destroy.addBlock(deindent `
  15859. ${unmountLeadin} {
  15860. @reinsertBetween(${anchorBefore}, ${anchorAfter}, ${content_name});
  15861. @detachNode(${anchorBefore});
  15862. @detachNode(${anchorAfter});
  15863. }
  15864. `);
  15865. }
  15866. }
  15867. }
  15868. // Whitespace inside one of these elements will not result in
  15869. // a whitespace node being created in any circumstances. (This
  15870. // list is almost certainly very incomplete)
  15871. const elementsWithoutText = new Set([
  15872. 'audio',
  15873. 'datalist',
  15874. 'dl',
  15875. 'optgroup',
  15876. 'select',
  15877. 'video',
  15878. ]);
  15879. // TODO this should probably be in Fragment
  15880. function shouldSkip$1(node) {
  15881. if (/\S/.test(node.data))
  15882. return false;
  15883. const parentElement = node.findNearest(/(?:Element|InlineComponent|Head)/);
  15884. if (!parentElement)
  15885. return false;
  15886. if (parentElement.type === 'Head')
  15887. return true;
  15888. if (parentElement.type === 'InlineComponent')
  15889. return parentElement.children.length === 1 && node === parentElement.children[0];
  15890. return parentElement.namespace || elementsWithoutText.has(parentElement.name);
  15891. }
  15892. class TextWrapper extends Wrapper {
  15893. constructor(renderer, block, parent, node, data) {
  15894. super(renderer, block, parent, node);
  15895. this.skip = shouldSkip$1(this.node);
  15896. this.data = data;
  15897. this.var = this.skip ? null : 'text';
  15898. }
  15899. render(block, parentNode, parentNodes) {
  15900. if (this.skip)
  15901. return;
  15902. block.addElement(this.var, `@createText(${stringify(this.data)})`, parentNodes && `@claimText(${parentNodes}, ${stringify(this.data)})`, parentNode);
  15903. }
  15904. remount(name) {
  15905. return `@append(${name}._slotted.default, ${this.var});`;
  15906. }
  15907. }
  15908. class TitleWrapper extends Wrapper {
  15909. constructor(renderer, block, parent, node, stripWhitespace, nextSibling) {
  15910. super(renderer, block, parent, node);
  15911. }
  15912. render(block, parentNode, parentNodes) {
  15913. const isDynamic = !!this.node.children.find(node => node.type !== 'Text');
  15914. if (isDynamic) {
  15915. let value;
  15916. const allDependencies = new Set();
  15917. // TODO some of this code is repeated in Tag.ts — would be good to
  15918. // DRY it out if that's possible without introducing crazy indirection
  15919. if (this.node.children.length === 1) {
  15920. // single {tag} — may be a non-string
  15921. const { expression } = this.node.children[0];
  15922. const { dependencies, snippet } = this.node.children[0].expression;
  15923. value = snippet;
  15924. dependencies.forEach(d => {
  15925. allDependencies.add(d);
  15926. });
  15927. }
  15928. else {
  15929. // '{foo} {bar}' — treat as string concatenation
  15930. value =
  15931. (this.node.children[0].type === 'Text' ? '' : `"" + `) +
  15932. this.node.children
  15933. .map((chunk) => {
  15934. if (chunk.type === 'Text') {
  15935. return stringify(chunk.data);
  15936. }
  15937. else {
  15938. const { dependencies, snippet } = chunk.expression;
  15939. dependencies.forEach(d => {
  15940. allDependencies.add(d);
  15941. });
  15942. return chunk.expression.getPrecedence() <= 13 ? `(${snippet})` : snippet;
  15943. }
  15944. })
  15945. .join(' + ');
  15946. }
  15947. const last = this.node.shouldCache && block.getUniqueName(`title_value`);
  15948. if (this.node.shouldCache)
  15949. block.addVariable(last);
  15950. let updater;
  15951. const init = this.node.shouldCache ? `${last} = ${value}` : value;
  15952. block.builders.init.addLine(`document.title = ${init};`);
  15953. updater = `document.title = ${this.node.shouldCache ? last : value};`;
  15954. if (allDependencies.size) {
  15955. const dependencies = Array.from(allDependencies);
  15956. const changedCheck = ((block.hasOutros ? `!#current || ` : '') +
  15957. dependencies.map(dependency => `changed.${dependency}`).join(' || '));
  15958. const updateCachedValue = `${last} !== (${last} = ${value})`;
  15959. const condition = this.node.shouldCache ?
  15960. (dependencies.length ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue) :
  15961. changedCheck;
  15962. block.builders.update.addConditional(condition, updater);
  15963. }
  15964. }
  15965. else {
  15966. const value = stringify(this.node.children[0].data);
  15967. block.builders.hydrate.addLine(`document.title = ${value};`);
  15968. }
  15969. }
  15970. }
  15971. const associatedEvents = {
  15972. innerWidth: 'resize',
  15973. innerHeight: 'resize',
  15974. outerWidth: 'resize',
  15975. outerHeight: 'resize',
  15976. scrollX: 'scroll',
  15977. scrollY: 'scroll',
  15978. };
  15979. const properties = {
  15980. scrollX: 'pageXOffset',
  15981. scrollY: 'pageYOffset'
  15982. };
  15983. const readonly = new Set([
  15984. 'innerWidth',
  15985. 'innerHeight',
  15986. 'outerWidth',
  15987. 'outerHeight',
  15988. 'online',
  15989. ]);
  15990. class WindowWrapper extends Wrapper {
  15991. constructor(renderer, block, parent, node) {
  15992. super(renderer, block, parent, node);
  15993. }
  15994. render(block, parentNode, parentNodes) {
  15995. const { renderer } = this;
  15996. const { component } = renderer;
  15997. const events = {};
  15998. const bindings = {};
  15999. this.node.handlers.forEach(handler => {
  16000. // TODO verify that it's a valid callee (i.e. built-in or declared method)
  16001. component.addSourcemapLocations(handler.expression);
  16002. const isCustomEvent = component.events.has(handler.name);
  16003. let usesState = handler.dependencies.size > 0;
  16004. handler.render(component, block, 'window', false); // TODO hoist?
  16005. const handlerName = block.getUniqueName(`onwindow${handler.name}`);
  16006. const handlerBody = deindent `
  16007. ${usesState && `var ctx = #component.get();`}
  16008. ${handler.snippet};
  16009. `;
  16010. if (isCustomEvent) {
  16011. // TODO dry this out
  16012. block.addVariable(handlerName);
  16013. block.builders.hydrate.addBlock(deindent `
  16014. ${handlerName} = %events-${handler.name}.call(#component, window, function(event) {
  16015. ${handlerBody}
  16016. });
  16017. `);
  16018. block.builders.destroy.addLine(deindent `
  16019. ${handlerName}.destroy();
  16020. `);
  16021. }
  16022. else {
  16023. block.builders.init.addBlock(deindent `
  16024. function ${handlerName}(event) {
  16025. ${handlerBody}
  16026. }
  16027. window.addEventListener("${handler.name}", ${handlerName});
  16028. `);
  16029. block.builders.destroy.addBlock(deindent `
  16030. window.removeEventListener("${handler.name}", ${handlerName});
  16031. `);
  16032. }
  16033. });
  16034. this.node.bindings.forEach(binding => {
  16035. // in dev mode, throw if read-only values are written to
  16036. if (readonly.has(binding.name)) {
  16037. renderer.readonly.add(binding.value.node.name);
  16038. }
  16039. bindings[binding.name] = binding.value.node.name;
  16040. // bind:online is a special case, we need to listen for two separate events
  16041. if (binding.name === 'online')
  16042. return;
  16043. const associatedEvent = associatedEvents[binding.name];
  16044. const property = properties[binding.name] || binding.name;
  16045. if (!events[associatedEvent])
  16046. events[associatedEvent] = [];
  16047. events[associatedEvent].push({
  16048. name: binding.value.node.name,
  16049. value: property
  16050. });
  16051. });
  16052. const lock = block.getUniqueName(`window_updating`);
  16053. const clear = block.getUniqueName(`clear_window_updating`);
  16054. const timeout = block.getUniqueName(`window_updating_timeout`);
  16055. Object.keys(events).forEach(event => {
  16056. const handlerName = block.getUniqueName(`onwindow${event}`);
  16057. const props = events[event];
  16058. if (event === 'scroll') {
  16059. // TODO other bidirectional bindings...
  16060. block.addVariable(lock, 'false');
  16061. block.addVariable(clear, `function() { ${lock} = false; }`);
  16062. block.addVariable(timeout);
  16063. const condition = [
  16064. bindings.scrollX && `"${bindings.scrollX}" in this._state`,
  16065. bindings.scrollY && `"${bindings.scrollY}" in this._state`
  16066. ].filter(Boolean).join(' || ');
  16067. const x = bindings.scrollX && `this._state.${bindings.scrollX}`;
  16068. const y = bindings.scrollY && `this._state.${bindings.scrollY}`;
  16069. renderer.metaBindings.addBlock(deindent `
  16070. if (${condition}) {
  16071. window.scrollTo(${x || 'window.pageXOffset'}, ${y || 'window.pageYOffset'});
  16072. }
  16073. ${x && `${x} = window.pageXOffset;`}
  16074. ${y && `${y} = window.pageYOffset;`}
  16075. `);
  16076. }
  16077. else {
  16078. props.forEach(prop => {
  16079. renderer.metaBindings.addLine(`this._state.${prop.name} = window.${prop.value};`);
  16080. });
  16081. }
  16082. const handlerBody = deindent `
  16083. ${event === 'scroll' && deindent `
  16084. if (${lock}) return;
  16085. ${lock} = true;
  16086. `}
  16087. ${component.options.dev && `component._updatingReadonlyProperty = true;`}
  16088. #component.set({
  16089. ${props.map(prop => `${prop.name}: this.${prop.value}`)}
  16090. });
  16091. ${component.options.dev && `component._updatingReadonlyProperty = false;`}
  16092. ${event === 'scroll' && `${lock} = false;`}
  16093. `;
  16094. block.builders.init.addBlock(deindent `
  16095. function ${handlerName}(event) {
  16096. ${handlerBody}
  16097. }
  16098. window.addEventListener("${event}", ${handlerName});
  16099. `);
  16100. block.builders.destroy.addBlock(deindent `
  16101. window.removeEventListener("${event}", ${handlerName});
  16102. `);
  16103. });
  16104. // special case... might need to abstract this out if we add more special cases
  16105. if (bindings.scrollX || bindings.scrollY) {
  16106. block.builders.init.addBlock(deindent `
  16107. #component.on("state", ({ changed, current }) => {
  16108. if (${[bindings.scrollX, bindings.scrollY].map(binding => binding && `changed["${binding}"]`).filter(Boolean).join(' || ')} && !${lock}) {
  16109. ${lock} = true;
  16110. clearTimeout(${timeout});
  16111. window.scrollTo(${bindings.scrollX ? `current["${bindings.scrollX}"]` : `window.pageXOffset`}, ${bindings.scrollY ? `current["${bindings.scrollY}"]` : `window.pageYOffset`});
  16112. ${timeout} = setTimeout(${clear}, 100);
  16113. }
  16114. });
  16115. `);
  16116. }
  16117. // another special case. (I'm starting to think these are all special cases.)
  16118. if (bindings.online) {
  16119. const handlerName = block.getUniqueName(`onlinestatuschanged`);
  16120. block.builders.init.addBlock(deindent `
  16121. function ${handlerName}(event) {
  16122. ${component.options.dev && `component._updatingReadonlyProperty = true;`}
  16123. #component.set({ ${bindings.online}: navigator.onLine });
  16124. ${component.options.dev && `component._updatingReadonlyProperty = false;`}
  16125. }
  16126. window.addEventListener("online", ${handlerName});
  16127. window.addEventListener("offline", ${handlerName});
  16128. `);
  16129. // add initial value
  16130. renderer.metaBindings.addLine(`this._state.${bindings.online} = navigator.onLine;`);
  16131. block.builders.destroy.addBlock(deindent `
  16132. window.removeEventListener("online", ${handlerName});
  16133. window.removeEventListener("offline", ${handlerName});
  16134. `);
  16135. }
  16136. }
  16137. }
  16138. const wrappers = {
  16139. AwaitBlock: AwaitBlockWrapper,
  16140. Comment: null,
  16141. Document: DocumentWrapper,
  16142. DebugTag: DebugTagWrapper,
  16143. EachBlock: EachBlockWrapper,
  16144. Element: ElementWrapper,
  16145. Head: HeadWrapper,
  16146. IfBlock: IfBlockWrapper,
  16147. InlineComponent: InlineComponentWrapper,
  16148. MustacheTag: MustacheTagWrapper,
  16149. RawMustacheTag: RawMustacheTagWrapper,
  16150. Slot: SlotWrapper,
  16151. Text: TextWrapper,
  16152. Title: TitleWrapper,
  16153. Window: WindowWrapper
  16154. };
  16155. function link(next, prev) {
  16156. prev.next = next;
  16157. if (next)
  16158. next.prev = prev;
  16159. }
  16160. class FragmentWrapper {
  16161. constructor(renderer, block, nodes, parent, stripWhitespace, nextSibling) {
  16162. this.nodes = [];
  16163. let lastChild;
  16164. let windowWrapper;
  16165. let i = nodes.length;
  16166. while (i--) {
  16167. const child = nodes[i];
  16168. if (!(child.type in wrappers)) {
  16169. throw new Error(`TODO implement ${child.type}`);
  16170. }
  16171. // special case — this is an easy way to remove whitespace surrounding
  16172. // <svelte:window/>. lil hacky but it works
  16173. if (child.type === 'Window') {
  16174. windowWrapper = new WindowWrapper(renderer, block, parent, child);
  16175. continue;
  16176. }
  16177. if (child.type === 'Text') {
  16178. let { data } = child;
  16179. // We want to remove trailing whitespace inside an element/component/block,
  16180. // *unless* there is no whitespace between this node and its next sibling
  16181. if (this.nodes.length === 0) {
  16182. const shouldTrim = (nextSibling ? (nextSibling.node.type === 'Text' && /^\s/.test(nextSibling.data)) : !child.hasAncestor('EachBlock'));
  16183. if (shouldTrim) {
  16184. data = trimEnd(data);
  16185. if (!data)
  16186. continue;
  16187. }
  16188. }
  16189. // glue text nodes (which could e.g. be separated by comments) together
  16190. if (lastChild && lastChild.node.type === 'Text') {
  16191. lastChild.data = data + lastChild.data;
  16192. continue;
  16193. }
  16194. const wrapper = new TextWrapper(renderer, block, parent, child, data);
  16195. if (wrapper.skip)
  16196. continue;
  16197. this.nodes.unshift(wrapper);
  16198. link(lastChild, lastChild = wrapper);
  16199. }
  16200. else {
  16201. const Wrapper = wrappers[child.type];
  16202. if (!Wrapper)
  16203. continue;
  16204. const wrapper = new Wrapper(renderer, block, parent, child, stripWhitespace, lastChild || nextSibling);
  16205. this.nodes.unshift(wrapper);
  16206. link(lastChild, lastChild = wrapper);
  16207. }
  16208. }
  16209. if (stripWhitespace) {
  16210. const first = this.nodes[0];
  16211. if (first && first.node.type === 'Text') {
  16212. first.data = trimStart(first.data);
  16213. if (!first.data) {
  16214. first.var = null;
  16215. this.nodes.shift();
  16216. if (this.nodes[0]) {
  16217. this.nodes[0].prev = null;
  16218. }
  16219. }
  16220. }
  16221. }
  16222. if (windowWrapper) {
  16223. this.nodes.unshift(windowWrapper);
  16224. link(lastChild, windowWrapper);
  16225. }
  16226. }
  16227. render(block, parentNode, parentNodes) {
  16228. for (let i = 0; i < this.nodes.length; i += 1) {
  16229. this.nodes[i].render(block, parentNode, parentNodes);
  16230. }
  16231. }
  16232. }
  16233. class Renderer {
  16234. constructor(component, options) {
  16235. this.component = component;
  16236. this.options = options;
  16237. this.locate = component.locate; // TODO messy
  16238. this.readonly = new Set();
  16239. this.slots = new Set();
  16240. this.usedNames = new Set();
  16241. this.fileVar = options.dev && this.component.getUniqueName('file');
  16242. // initial values for e.g. window.innerWidth, if there's a <svelte:window> meta tag
  16243. this.metaBindings = new CodeBuilder();
  16244. this.bindingGroups = [];
  16245. // main block
  16246. this.block = new Block$1({
  16247. renderer: this,
  16248. name: '@create_main_fragment',
  16249. key: null,
  16250. bindings: new Map(),
  16251. contextOwners: new Map(),
  16252. dependencies: new Set(),
  16253. });
  16254. this.block.hasUpdateMethod = true;
  16255. this.blocks = [];
  16256. this.fragment = new FragmentWrapper(this, this.block, component.fragment.children, null, true, null);
  16257. this.blocks.push(this.block);
  16258. this.blocks.forEach(block => {
  16259. if (typeof block !== 'string') {
  16260. block.assignVariableNames();
  16261. }
  16262. });
  16263. this.fragment.render(this.block, null, 'nodes');
  16264. }
  16265. }
  16266. function dom(component, options) {
  16267. const format = options.format || 'es';
  16268. const { computations, name, templateProperties } = component;
  16269. const renderer = new Renderer(component, options);
  16270. const { block } = renderer;
  16271. if (component.options.nestedTransitions) {
  16272. block.hasOutroMethod = true;
  16273. }
  16274. // prevent fragment being created twice (#1063)
  16275. if (options.customElement)
  16276. block.builders.create.addLine(`this.c = @noop;`);
  16277. const builder = new CodeBuilder();
  16278. const computationBuilder = new CodeBuilder();
  16279. const computationDeps = new Set();
  16280. if (computations.length) {
  16281. computations.forEach(({ key, deps, hasRestParam }) => {
  16282. if (renderer.readonly.has(key)) {
  16283. // <svelte:window> bindings
  16284. throw new Error(`Cannot have a computed value '${key}' that clashes with a read-only property`);
  16285. }
  16286. renderer.readonly.add(key);
  16287. if (deps) {
  16288. deps.forEach(dep => {
  16289. computationDeps.add(dep);
  16290. });
  16291. const condition = `${deps.map(dep => `changed.${dep}`).join(' || ')}`;
  16292. const statement = `if (this._differs(state.${key}, (state.${key} = %computed-${key}(state)))) changed.${key} = true;`;
  16293. computationBuilder.addConditional(condition, statement);
  16294. }
  16295. else {
  16296. // computed property depends on entire state object —
  16297. // these must go at the end
  16298. computationBuilder.addLine(`if (this._differs(state.${key}, (state.${key} = %computed-${key}(@exclude(state, "${key}"))))) changed.${key} = true;`);
  16299. }
  16300. });
  16301. }
  16302. if (component.javascript) {
  16303. const componentDefinition = new CodeBuilder();
  16304. component.declarations.forEach(declaration => {
  16305. componentDefinition.addBlock(declaration.block);
  16306. });
  16307. const js = (component.javascript[0] +
  16308. componentDefinition +
  16309. component.javascript[1]);
  16310. builder.addBlock(js);
  16311. }
  16312. if (component.options.dev) {
  16313. builder.addLine(`const ${renderer.fileVar} = ${JSON.stringify(component.file)};`);
  16314. }
  16315. const css = component.stylesheet.render(options.filename, !component.customElement);
  16316. const styles = component.stylesheet.hasStyles && stringify(options.dev ?
  16317. `${css.code}\n/*# sourceMappingURL=${css.map.toUrl()} */` :
  16318. css.code, { onlyEscapeAtSymbol: true });
  16319. if (styles && component.options.css !== false && !component.customElement) {
  16320. builder.addBlock(deindent `
  16321. function @add_css() {
  16322. var style = @createElement("style");
  16323. style.id = '${component.stylesheet.id}-style';
  16324. style.textContent = ${styles};
  16325. @append(document.head, style);
  16326. }
  16327. `);
  16328. }
  16329. // fix order
  16330. // TODO the deconflicted names of blocks are reversed... should set them here
  16331. const blocks = renderer.blocks.slice().reverse();
  16332. blocks.forEach(block => {
  16333. builder.addBlock(block.toString());
  16334. });
  16335. const sharedPath = options.shared === true
  16336. ? 'svelte/shared.js'
  16337. : options.shared || '';
  16338. const proto = sharedPath
  16339. ? `@proto`
  16340. : deindent `
  16341. {
  16342. ${['destroy', 'get', 'fire', 'on', 'set', '_set', '_stage', '_mount', '_differs']
  16343. .map(n => `${n}: @${n}`)
  16344. .join(',\n')}
  16345. }`;
  16346. const debugName = `<${component.customElement ? component.tag : name}>`;
  16347. // generate initial state object
  16348. const expectedProperties = Array.from(component.expectedProperties);
  16349. const globals = expectedProperties.filter(prop => globalWhitelist.has(prop));
  16350. const storeProps = expectedProperties.filter(prop => prop[0] === '$');
  16351. const initialState = [];
  16352. if (globals.length > 0) {
  16353. initialState.push(`{ ${globals.map(prop => `${prop} : ${prop}`).join(', ')} }`);
  16354. }
  16355. if (storeProps.length > 0) {
  16356. initialState.push(`this.store._init([${storeProps.map(prop => `"${prop.slice(1)}"`)}])`);
  16357. }
  16358. if (templateProperties.data) {
  16359. initialState.push(`%data()`);
  16360. }
  16361. else if (globals.length === 0 && storeProps.length === 0) {
  16362. initialState.push('{}');
  16363. }
  16364. initialState.push(`options.data`);
  16365. const hasInitHooks = !!(templateProperties.oncreate || templateProperties.onstate || templateProperties.onupdate);
  16366. const constructorBody = deindent `
  16367. ${options.dev && deindent `
  16368. this._debugName = '${debugName}';
  16369. ${!component.customElement && deindent `
  16370. if (!options || (!options.target && !options.root)) {
  16371. throw new Error("'target' is a required option");
  16372. }`}
  16373. ${storeProps.length > 0 && !templateProperties.store && deindent `
  16374. if (!options.store) {
  16375. throw new Error("${debugName} references store properties, but no store was provided");
  16376. }`}
  16377. `}
  16378. @init(this, options);
  16379. ${templateProperties.store && `this.store = %store();`}
  16380. ${component.refs.size > 0 && `this.refs = {};`}
  16381. this._state = ${initialState.reduce((state, piece) => `@assign(${state}, ${piece})`)};
  16382. ${storeProps.length > 0 && `this.store._add(this, [${storeProps.map(prop => `"${prop.slice(1)}"`)}]);`}
  16383. ${renderer.metaBindings}
  16384. ${computations.length && `this._recompute({ ${Array.from(computationDeps).map(dep => `${dep}: 1`).join(', ')} }, this._state);`}
  16385. ${options.dev &&
  16386. Array.from(component.expectedProperties).map(prop => {
  16387. if (globalWhitelist.has(prop))
  16388. return;
  16389. if (computations.find(c => c.key === prop))
  16390. return;
  16391. const message = component.components.has(prop) ?
  16392. `${debugName} expected to find '${prop}' in \`data\`, but found it in \`components\` instead` :
  16393. `${debugName} was created without expected data property '${prop}'`;
  16394. const conditions = [`!('${prop}' in this._state)`];
  16395. if (component.customElement)
  16396. conditions.push(`!('${prop}' in this.attributes)`);
  16397. return `if (${conditions.join(' && ')}) console.warn("${message}");`;
  16398. })}
  16399. ${renderer.bindingGroups.length &&
  16400. `this._bindingGroups = [${Array(renderer.bindingGroups.length).fill('[]').join(', ')}];`}
  16401. this._intro = ${component.options.skipIntroByDefault ? '!!options.intro' : 'true'};
  16402. ${templateProperties.onstate && `this._handlers.state = [%onstate];`}
  16403. ${templateProperties.onupdate && `this._handlers.update = [%onupdate];`}
  16404. ${(templateProperties.ondestroy || storeProps.length) && (`this._handlers.destroy = [${[templateProperties.ondestroy && `%ondestroy`, storeProps.length && `@removeFromStore`].filter(Boolean).join(', ')}];`)}
  16405. ${renderer.slots.size && `this._slotted = options.slots || {};`}
  16406. ${component.customElement ?
  16407. deindent `
  16408. this.attachShadow({ mode: 'open' });
  16409. ${css.code && `this.shadowRoot.innerHTML = \`<style>${escape$1(css.code, { onlyEscapeAtSymbol: true }).replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
  16410. ` :
  16411. (component.stylesheet.hasStyles && options.css !== false &&
  16412. `if (!document.getElementById("${component.stylesheet.id}-style")) @add_css();`)}
  16413. ${templateProperties.onstate && `%onstate.call(this, { changed: @assignTrue({}, this._state), current: this._state });`}
  16414. this._fragment = @create_main_fragment(this, this._state);
  16415. ${hasInitHooks && deindent `
  16416. this.root._oncreate.push(() => {
  16417. ${templateProperties.oncreate && `%oncreate.call(this);`}
  16418. this.fire("update", { changed: @assignTrue({}, this._state), current: this._state });
  16419. });
  16420. `}
  16421. ${component.customElement ? deindent `
  16422. this._fragment.c();
  16423. this._fragment.${block.hasIntroMethod ? 'i' : 'm'}(this.shadowRoot, null);
  16424. if (options.target) this._mount(options.target, options.anchor);
  16425. ` : deindent `
  16426. if (options.target) {
  16427. ${component.options.hydratable
  16428. ? deindent `
  16429. var nodes = @children(options.target);
  16430. options.hydrate ? this._fragment.l(nodes) : this._fragment.c();
  16431. nodes.forEach(@detachNode);` :
  16432. deindent `
  16433. ${options.dev &&
  16434. `if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the \`hydratable: true\` option");`}
  16435. this._fragment.c();`}
  16436. this._mount(options.target, options.anchor);
  16437. ${(component.hasComponents || renderer.hasComplexBindings || hasInitHooks || renderer.hasIntroTransitions) &&
  16438. `@flush(this);`}
  16439. }
  16440. `}
  16441. ${component.options.skipIntroByDefault && `this._intro = true;`}
  16442. `;
  16443. if (component.customElement) {
  16444. const props = component.props || Array.from(component.expectedProperties);
  16445. builder.addBlock(deindent `
  16446. class ${name} extends HTMLElement {
  16447. constructor(options = {}) {
  16448. super();
  16449. ${constructorBody}
  16450. }
  16451. static get observedAttributes() {
  16452. return ${JSON.stringify(props)};
  16453. }
  16454. ${props.map(prop => deindent `
  16455. get ${prop}() {
  16456. return this.get().${prop};
  16457. }
  16458. set ${prop}(value) {
  16459. this.set({ ${prop}: value });
  16460. }
  16461. `).join('\n\n')}
  16462. ${renderer.slots.size && deindent `
  16463. connectedCallback() {
  16464. Object.keys(this._slotted).forEach(key => {
  16465. this.appendChild(this._slotted[key]);
  16466. });
  16467. }`}
  16468. attributeChangedCallback(attr, oldValue, newValue) {
  16469. this.set({ [attr]: newValue });
  16470. }
  16471. ${(component.hasComponents || renderer.hasComplexBindings || templateProperties.oncreate || renderer.hasIntroTransitions) && deindent `
  16472. connectedCallback() {
  16473. @flush(this);
  16474. }
  16475. `}
  16476. }
  16477. @assign(${name}.prototype, ${proto});
  16478. ${templateProperties.methods && `@assign(${name}.prototype, %methods);`}
  16479. @assign(${name}.prototype, {
  16480. _mount(target, anchor) {
  16481. target.insertBefore(this, anchor);
  16482. }
  16483. });
  16484. customElements.define("${component.tag}", ${name});
  16485. `);
  16486. }
  16487. else {
  16488. builder.addBlock(deindent `
  16489. function ${name}(options) {
  16490. ${constructorBody}
  16491. }
  16492. @assign(${name}.prototype, ${proto});
  16493. ${templateProperties.methods && `@assign(${name}.prototype, %methods);`}
  16494. `);
  16495. }
  16496. const immutable = templateProperties.immutable ? templateProperties.immutable.value.value : options.immutable;
  16497. builder.addBlock(deindent `
  16498. ${options.dev && deindent `
  16499. ${name}.prototype._checkReadOnly = function _checkReadOnly(newState) {
  16500. ${Array.from(renderer.readonly).map(prop => `if ('${prop}' in newState && !this._updatingReadonlyProperty) throw new Error("${debugName}: Cannot set read-only property '${prop}'");`)}
  16501. };
  16502. `}
  16503. ${computations.length ? deindent `
  16504. ${name}.prototype._recompute = function _recompute(changed, state) {
  16505. ${computationBuilder}
  16506. }
  16507. ` : (!sharedPath && `${name}.prototype._recompute = @noop;`)}
  16508. ${templateProperties.setup && `%setup(${name});`}
  16509. ${templateProperties.preload && `${name}.preload = %preload;`}
  16510. ${immutable && `${name}.prototype._differs = @_differsImmutable;`}
  16511. `);
  16512. let result = builder.toString();
  16513. return component.generate(result, options, {
  16514. banner: `/* ${component.file ? `${component.file} ` : ``}generated by Svelte v${"2.15.3"} */`,
  16515. sharedPath,
  16516. name,
  16517. format,
  16518. });
  16519. }
  16520. function AwaitBlock (node, renderer, options) {
  16521. const { snippet } = node.expression;
  16522. renderer.append('${(function(__value) { if(@isPromise(__value)) return `');
  16523. renderer.render(node.pending.children, options);
  16524. renderer.append('`; return function(ctx) { return `');
  16525. renderer.render(node.then.children, options);
  16526. renderer.append(`\`;}(Object.assign({}, ctx, { ${node.value}: __value }));}(${snippet})) }`);
  16527. }
  16528. function Comment$1 (node, renderer, options) {
  16529. if (options.preserveComments) {
  16530. renderer.append(`<!--${node.data}-->`);
  16531. }
  16532. }
  16533. function DebugTag (node, renderer, options) {
  16534. if (!options.dev)
  16535. return;
  16536. const filename = options.file || null;
  16537. const { line, column } = options.locate(node.start + 1);
  16538. const obj = node.expressions.length === 0
  16539. ? `ctx`
  16540. : `{ ${node.expressions
  16541. .map(e => e.node.name)
  16542. .map(name => `${name}: ctx.${name}`)
  16543. .join(', ')} }`;
  16544. const str = '${@debug(' + `${filename && stringify(filename)}, ${line}, ${column}, ${obj})}`;
  16545. renderer.append(str);
  16546. }
  16547. function EachBlock (node, renderer, options) {
  16548. const { snippet } = node.expression;
  16549. const props = node.contexts.map(prop => `${prop.key.name}: item${prop.tail}`);
  16550. const getContext = node.index
  16551. ? `(item, i) => Object.assign({}, ctx, { ${props.join(', ')}, ${node.index}: i })`
  16552. : `item => Object.assign({}, ctx, { ${props.join(', ')} })`;
  16553. const open = `\${ ${node.else ? `${snippet}.length ? ` : ''}@each(${snippet}, ${getContext}, ctx => \``;
  16554. renderer.append(open);
  16555. renderer.render(node.children, options);
  16556. const close = `\`)`;
  16557. renderer.append(close);
  16558. if (node.else) {
  16559. renderer.append(` : \``);
  16560. renderer.render(node.else.children, options);
  16561. renderer.append(`\``);
  16562. }
  16563. renderer.append('}');
  16564. }
  16565. // source: https://gist.github.com/ArjanSchouten/0b8574a6ad7f5065a5e7
  16566. const boolean_attributes = new Set([
  16567. 'async',
  16568. 'autocomplete',
  16569. 'autofocus',
  16570. 'autoplay',
  16571. 'border',
  16572. 'challenge',
  16573. 'checked',
  16574. 'compact',
  16575. 'contenteditable',
  16576. 'controls',
  16577. 'default',
  16578. 'defer',
  16579. 'disabled',
  16580. 'formnovalidate',
  16581. 'frameborder',
  16582. 'hidden',
  16583. 'indeterminate',
  16584. 'ismap',
  16585. 'loop',
  16586. 'multiple',
  16587. 'muted',
  16588. 'nohref',
  16589. 'noresize',
  16590. 'noshade',
  16591. 'novalidate',
  16592. 'nowrap',
  16593. 'open',
  16594. 'readonly',
  16595. 'required',
  16596. 'reversed',
  16597. 'scoped',
  16598. 'scrolling',
  16599. 'seamless',
  16600. 'selected',
  16601. 'sortable',
  16602. 'spellcheck',
  16603. 'translate'
  16604. ]);
  16605. function Element (node, renderer, options) {
  16606. let openingTag = `<${node.name}`;
  16607. let textareaContents; // awkward special case
  16608. const slot = node.getStaticAttributeValue('slot');
  16609. if (slot && node.hasAncestor('InlineComponent')) {
  16610. const slot = node.attributes.find((attribute) => attribute.name === 'slot');
  16611. const slotName = slot.chunks[0].data;
  16612. const target = renderer.targets[renderer.targets.length - 1];
  16613. target.slotStack.push(slotName);
  16614. target.slots[slotName] = '';
  16615. }
  16616. const classExpr = node.classes.map((classDir) => {
  16617. const { expression, name } = classDir;
  16618. const snippet = expression ? expression.snippet : `ctx${quotePropIfNecessary(name)}`;
  16619. return `${snippet} ? "${name}" : ""`;
  16620. }).join(', ');
  16621. let addClassAttribute = classExpr ? true : false;
  16622. if (node.attributes.find(attr => attr.isSpread)) {
  16623. // TODO dry this out
  16624. const args = [];
  16625. node.attributes.forEach(attribute => {
  16626. if (attribute.isSpread) {
  16627. args.push(attribute.expression.snippet);
  16628. }
  16629. else {
  16630. if (attribute.name === 'value' && node.name === 'textarea') {
  16631. textareaContents = stringifyAttribute(attribute);
  16632. }
  16633. else if (attribute.isTrue) {
  16634. args.push(`{ ${quoteNameIfNecessary(attribute.name)}: true }`);
  16635. }
  16636. else if (boolean_attributes.has(attribute.name) &&
  16637. attribute.chunks.length === 1 &&
  16638. attribute.chunks[0].type !== 'Text') {
  16639. // a boolean attribute with one non-Text chunk
  16640. args.push(`{ ${quoteNameIfNecessary(attribute.name)}: ${attribute.chunks[0].snippet} }`);
  16641. }
  16642. else {
  16643. args.push(`{ ${quoteNameIfNecessary(attribute.name)}: \`${stringifyAttribute(attribute)}\` }`);
  16644. }
  16645. }
  16646. });
  16647. openingTag += "${@spread([" + args.join(', ') + "])}";
  16648. }
  16649. else {
  16650. node.attributes.forEach((attribute) => {
  16651. if (attribute.type !== 'Attribute')
  16652. return;
  16653. if (attribute.name === 'value' && node.name === 'textarea') {
  16654. textareaContents = stringifyAttribute(attribute);
  16655. }
  16656. else if (attribute.isTrue) {
  16657. openingTag += ` ${attribute.name}`;
  16658. }
  16659. else if (boolean_attributes.has(attribute.name) &&
  16660. attribute.chunks.length === 1 &&
  16661. attribute.chunks[0].type !== 'Text') {
  16662. // a boolean attribute with one non-Text chunk
  16663. openingTag += '${' + attribute.chunks[0].snippet + ' ? " ' + attribute.name + '" : "" }';
  16664. }
  16665. else if (attribute.name === 'class' && classExpr) {
  16666. addClassAttribute = false;
  16667. openingTag += ` class="\${[\`${stringifyAttribute(attribute)}\`, ${classExpr}].join(' ').trim() }"`;
  16668. }
  16669. else if (attribute.chunks.length === 1 && attribute.chunks[0].type !== 'Text') {
  16670. const { name } = attribute;
  16671. const { snippet } = attribute.chunks[0];
  16672. openingTag += '${(v => v == null ? "" : ` ' + name + '="${@escape(' + snippet + ')}"`)(' + snippet + ')}';
  16673. }
  16674. else {
  16675. openingTag += ` ${attribute.name}="${stringifyAttribute(attribute)}"`;
  16676. }
  16677. });
  16678. }
  16679. node.bindings.forEach(binding => {
  16680. const { name, value: { snippet } } = binding;
  16681. if (name === 'group') ;
  16682. else {
  16683. openingTag += ' ${(v => v ? ("' + name + '" + (v === true ? "" : "=" + JSON.stringify(v))) : "")(' + snippet + ')}';
  16684. }
  16685. });
  16686. if (addClassAttribute) {
  16687. openingTag += `\${((v) => v ? ' class="' + v + '"' : '')([${classExpr}].join(' ').trim())}`;
  16688. }
  16689. openingTag += '>';
  16690. renderer.append(openingTag);
  16691. if (node.name === 'textarea' && textareaContents !== undefined) {
  16692. renderer.append(textareaContents);
  16693. }
  16694. else {
  16695. renderer.render(node.children, options);
  16696. }
  16697. if (!isVoidElementName(node.name)) {
  16698. renderer.append(`</${node.name}>`);
  16699. }
  16700. }
  16701. function stringifyAttribute(attribute) {
  16702. return attribute.chunks
  16703. .map((chunk) => {
  16704. if (chunk.type === 'Text') {
  16705. return escapeTemplate(escape$1(chunk.data).replace(/"/g, '&quot;'));
  16706. }
  16707. return '${@escape(' + chunk.snippet + ')}';
  16708. })
  16709. .join('');
  16710. }
  16711. function Head (node, renderer, options) {
  16712. renderer.append('${(__result.head += `');
  16713. renderer.render(node.children, options);
  16714. renderer.append('`, "")}');
  16715. }
  16716. function HtmlTag (node, renderer, options) {
  16717. renderer.append('${' + node.expression.snippet + '}');
  16718. }
  16719. function IfBlock (node, renderer, options) {
  16720. const { snippet } = node.expression;
  16721. renderer.append('${ ' + snippet + ' ? `');
  16722. renderer.render(node.children, options);
  16723. renderer.append('` : `');
  16724. if (node.else) {
  16725. renderer.render(node.else.children, options);
  16726. }
  16727. renderer.append('` }');
  16728. }
  16729. function InlineComponent (node, renderer, options) {
  16730. function stringifyAttribute(chunk) {
  16731. if (chunk.type === 'Text') {
  16732. return escapeTemplate(escape$1(chunk.data));
  16733. }
  16734. return '${@escape( ' + chunk.snippet + ')}';
  16735. }
  16736. const bindingProps = node.bindings.map(binding => {
  16737. const { name } = getObject(binding.value.node);
  16738. const tail = binding.value.node.type === 'MemberExpression'
  16739. ? getTailSnippet(binding.value.node)
  16740. : '';
  16741. return `${quoteNameIfNecessary(binding.name)}: ctx${quotePropIfNecessary(name)}${tail}`;
  16742. });
  16743. function getAttributeValue(attribute) {
  16744. if (attribute.isTrue)
  16745. return `true`;
  16746. if (attribute.chunks.length === 0)
  16747. return `''`;
  16748. if (attribute.chunks.length === 1) {
  16749. const chunk = attribute.chunks[0];
  16750. if (chunk.type === 'Text') {
  16751. return stringify(chunk.data);
  16752. }
  16753. return chunk.snippet;
  16754. }
  16755. return '`' + attribute.chunks.map(stringifyAttribute).join('') + '`';
  16756. }
  16757. const usesSpread = node.attributes.find(attr => attr.isSpread);
  16758. const props = usesSpread
  16759. ? `Object.assign(${node.attributes
  16760. .map(attribute => {
  16761. if (attribute.isSpread) {
  16762. return attribute.expression.snippet;
  16763. }
  16764. else {
  16765. return `{ ${quoteNameIfNecessary(attribute.name)}: ${getAttributeValue(attribute)} }`;
  16766. }
  16767. })
  16768. .concat(bindingProps.map(p => `{ ${p} }`))
  16769. .join(', ')})`
  16770. : `{ ${node.attributes
  16771. .map(attribute => `${quoteNameIfNecessary(attribute.name)}: ${getAttributeValue(attribute)}`)
  16772. .concat(bindingProps)
  16773. .join(', ')} }`;
  16774. const expression = (node.name === 'svelte:self'
  16775. ? node.component.name
  16776. : node.name === 'svelte:component'
  16777. ? `((${node.expression.snippet}) || @missingComponent)`
  16778. : `%components-${node.name}`);
  16779. node.bindings.forEach(binding => {
  16780. const conditions = [];
  16781. let parent = node;
  16782. while (parent = parent.parent) {
  16783. if (parent.type === 'IfBlock') {
  16784. // TODO handle contextual bindings...
  16785. conditions.push(`(${parent.expression.snippet})`);
  16786. }
  16787. }
  16788. conditions.push(`!('${binding.name}' in ctx)`, `${expression}.data`);
  16789. const { name } = getObject(binding.value.node);
  16790. renderer.bindings.push(deindent `
  16791. if (${conditions.reverse().join('&&')}) {
  16792. tmp = ${expression}.data();
  16793. if ('${name}' in tmp) {
  16794. ctx${quotePropIfNecessary(binding.name)} = tmp.${name};
  16795. settled = false;
  16796. }
  16797. }
  16798. `);
  16799. });
  16800. let open = `\${@validateSsrComponent(${expression}, '${node.name}')._render(__result, ${props}`;
  16801. const component_options = [];
  16802. component_options.push(`store: options.store`);
  16803. if (node.children.length) {
  16804. const target = {
  16805. slots: { default: '' },
  16806. slotStack: ['default']
  16807. };
  16808. renderer.targets.push(target);
  16809. renderer.render(node.children, options);
  16810. const slotted = Object.keys(target.slots)
  16811. .map(name => `${quoteNameIfNecessary(name)}: () => \`${target.slots[name]}\``)
  16812. .join(', ');
  16813. component_options.push(`slotted: { ${slotted} }`);
  16814. renderer.targets.pop();
  16815. }
  16816. if (component_options.length) {
  16817. open += `, { ${component_options.join(', ')} }`;
  16818. }
  16819. renderer.append(open);
  16820. renderer.append(')}');
  16821. }
  16822. function Slot (node, renderer, options) {
  16823. const name = node.attributes.find(attribute => attribute.name === 'name');
  16824. const slotName = name && name.chunks[0].data || 'default';
  16825. const prop = quotePropIfNecessary(slotName);
  16826. renderer.append(`\${options && options.slotted && options.slotted${prop} ? options.slotted${prop}() : \``);
  16827. renderer.render(node.children, options);
  16828. renderer.append(`\`}`);
  16829. }
  16830. function Tag$1 (node, renderer, options) {
  16831. renderer.append(node.parent &&
  16832. node.parent.type === 'Element' &&
  16833. node.parent.name === 'style'
  16834. ? '${' + node.expression.snippet + '}'
  16835. : '${@escape(' + node.expression.snippet + ')}');
  16836. }
  16837. function Text$1 (node, renderer, options) {
  16838. let text = node.data;
  16839. if (!node.parent ||
  16840. node.parent.type !== 'Element' ||
  16841. (node.parent.name !== 'script' && node.parent.name !== 'style')) {
  16842. // unless this Text node is inside a <script> or <style> element, escape &,<,>
  16843. text = escapeHTML(text);
  16844. }
  16845. renderer.append(escape$1(escapeTemplate(text)));
  16846. }
  16847. function Title (node, renderer, options) {
  16848. renderer.append(`<title>`);
  16849. renderer.render(node.children, options);
  16850. renderer.append(`</title>`);
  16851. }
  16852. function noop$2() { }
  16853. const handlers = {
  16854. AwaitBlock,
  16855. Comment: Comment$1,
  16856. DebugTag,
  16857. Document: noop$2,
  16858. EachBlock,
  16859. Element,
  16860. Head,
  16861. IfBlock,
  16862. InlineComponent,
  16863. MustacheTag: Tag$1,
  16864. RawMustacheTag: HtmlTag,
  16865. Slot,
  16866. Text: Text$1,
  16867. Title,
  16868. Window: noop$2
  16869. };
  16870. class Renderer$1 {
  16871. constructor() {
  16872. this.bindings = [];
  16873. this.code = '';
  16874. this.targets = [];
  16875. }
  16876. append(code) {
  16877. if (this.targets.length) {
  16878. const target = this.targets[this.targets.length - 1];
  16879. const slotName = target.slotStack[target.slotStack.length - 1];
  16880. target.slots[slotName] += code;
  16881. }
  16882. else {
  16883. this.code += code;
  16884. }
  16885. }
  16886. render(nodes, options) {
  16887. nodes.forEach(node => {
  16888. const handler = handlers[node.type];
  16889. if (!handler) {
  16890. throw new Error(`No handler for '${node.type}' nodes`);
  16891. }
  16892. handler(node, this, options);
  16893. });
  16894. }
  16895. }
  16896. function ssr(component, options) {
  16897. const renderer = new Renderer$1();
  16898. const format = options.format || 'cjs';
  16899. const { computations, name, templateProperties } = component;
  16900. // create main render() function
  16901. renderer.render(trim(component.fragment.children), Object.assign({
  16902. locate: component.locate
  16903. }, options));
  16904. const css = component.customElement ?
  16905. { code: null, map: null } :
  16906. component.stylesheet.render(options.filename, true);
  16907. // generate initial state object
  16908. const expectedProperties = Array.from(component.expectedProperties);
  16909. const globals = expectedProperties.filter(prop => globalWhitelist.has(prop));
  16910. const storeProps = expectedProperties.filter(prop => prop[0] === '$');
  16911. const initialState = [];
  16912. if (globals.length > 0) {
  16913. initialState.push(`{ ${globals.map(prop => `${prop} : ${prop}`).join(', ')} }`);
  16914. }
  16915. if (storeProps.length > 0) {
  16916. const initialize = `_init([${storeProps.map(prop => `"${prop.slice(1)}"`)}])`;
  16917. initialState.push(`options.store.${initialize}`);
  16918. }
  16919. if (templateProperties.data) {
  16920. initialState.push(`%data()`);
  16921. }
  16922. else if (globals.length === 0 && storeProps.length === 0) {
  16923. initialState.push('{}');
  16924. }
  16925. initialState.push('ctx');
  16926. let js = null;
  16927. if (component.javascript) {
  16928. const componentDefinition = new CodeBuilder();
  16929. // not all properties are relevant to SSR (e.g. lifecycle hooks)
  16930. const relevant = new Set([
  16931. 'data',
  16932. 'components',
  16933. 'computed',
  16934. 'helpers',
  16935. 'preload',
  16936. 'store'
  16937. ]);
  16938. component.declarations.forEach(declaration => {
  16939. if (relevant.has(declaration.type)) {
  16940. componentDefinition.addBlock(declaration.block);
  16941. }
  16942. });
  16943. js = (component.javascript[0] +
  16944. componentDefinition +
  16945. component.javascript[1]);
  16946. }
  16947. const debugName = `<${component.customElement ? component.tag : name}>`;
  16948. // TODO concatenate CSS maps
  16949. const result = (deindent `
  16950. ${js}
  16951. var ${name} = {};
  16952. ${options.filename && `${name}.filename = ${stringify(options.filename)}`};
  16953. ${name}.data = function() {
  16954. return ${templateProperties.data ? `%data()` : `{}`};
  16955. };
  16956. ${name}.render = function(state, options = {}) {
  16957. var components = new Set();
  16958. function addComponent(component) {
  16959. components.add(component);
  16960. }
  16961. var result = { head: '', addComponent };
  16962. var html = ${name}._render(result, state, options);
  16963. var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\\n');
  16964. return {
  16965. html,
  16966. head: result.head,
  16967. css: { code: cssCode, map: null },
  16968. toString() {
  16969. return html;
  16970. }
  16971. };
  16972. }
  16973. ${name}._render = function(__result, ctx, options) {
  16974. ${templateProperties.store && `options.store = %store();`}
  16975. __result.addComponent(${name});
  16976. ${options.dev && storeProps.length > 0 && !templateProperties.store && deindent `
  16977. if (!options.store) {
  16978. throw new Error("${debugName} references store properties, but no store was provided");
  16979. }
  16980. `}
  16981. ctx = Object.assign(${initialState.join(', ')});
  16982. ${computations.map(({ key }) => `ctx.${key} = %computed-${key}(ctx);`)}
  16983. ${renderer.bindings.length &&
  16984. deindent `
  16985. var settled = false;
  16986. var tmp;
  16987. while (!settled) {
  16988. settled = true;
  16989. ${renderer.bindings.join('\n\n')}
  16990. }
  16991. `}
  16992. return \`${renderer.code}\`;
  16993. };
  16994. ${name}.css = {
  16995. code: ${css.code ? stringify(css.code) : `''`},
  16996. map: ${css.map ? stringify(css.map.toString()) : 'null'}
  16997. };
  16998. var warned = false;
  16999. ${templateProperties.preload && `${name}.preload = %preload;`}
  17000. `).trim();
  17001. return component.generate(result, options, { name, format });
  17002. }
  17003. function trim(nodes) {
  17004. let start = 0;
  17005. for (; start < nodes.length; start += 1) {
  17006. const node = nodes[start];
  17007. if (node.type !== 'Text')
  17008. break;
  17009. node.data = node.data.replace(/^\s+/, '');
  17010. if (node.data)
  17011. break;
  17012. }
  17013. let end = nodes.length;
  17014. for (; end > start; end -= 1) {
  17015. const node = nodes[end - 1];
  17016. if (node.type !== 'Text')
  17017. break;
  17018. node.data = node.data.replace(/\s+$/, '');
  17019. if (node.data)
  17020. break;
  17021. }
  17022. return nodes.slice(start, end);
  17023. }
  17024. var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  17025. function encode(decoded) {
  17026. var sourceFileIndex = 0; // second field
  17027. var sourceCodeLine = 0; // third field
  17028. var sourceCodeColumn = 0; // fourth field
  17029. var nameIndex = 0; // fifth field
  17030. var mappings = '';
  17031. for (var i = 0; i < decoded.length; i++) {
  17032. var line = decoded[i];
  17033. if (i > 0)
  17034. mappings += ';';
  17035. if (line.length === 0)
  17036. continue;
  17037. var generatedCodeColumn = 0; // first field
  17038. var lineMappings = [];
  17039. for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
  17040. var segment = line_1[_i];
  17041. var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
  17042. generatedCodeColumn = segment[0];
  17043. if (segment.length > 1) {
  17044. segmentMappings +=
  17045. encodeInteger(segment[1] - sourceFileIndex) +
  17046. encodeInteger(segment[2] - sourceCodeLine) +
  17047. encodeInteger(segment[3] - sourceCodeColumn);
  17048. sourceFileIndex = segment[1];
  17049. sourceCodeLine = segment[2];
  17050. sourceCodeColumn = segment[3];
  17051. }
  17052. if (segment.length === 5) {
  17053. segmentMappings += encodeInteger(segment[4] - nameIndex);
  17054. nameIndex = segment[4];
  17055. }
  17056. lineMappings.push(segmentMappings);
  17057. }
  17058. mappings += lineMappings.join(',');
  17059. }
  17060. return mappings;
  17061. }
  17062. function encodeInteger(num) {
  17063. var result = '';
  17064. num = num < 0 ? (-num << 1) | 1 : num << 1;
  17065. do {
  17066. var clamped = num & 31;
  17067. num >>= 5;
  17068. if (num > 0) {
  17069. clamped |= 32;
  17070. }
  17071. result += chars[clamped];
  17072. } while (num > 0);
  17073. return result;
  17074. }
  17075. var Chunk = function Chunk(start, end, content) {
  17076. this.start = start;
  17077. this.end = end;
  17078. this.original = content;
  17079. this.intro = '';
  17080. this.outro = '';
  17081. this.content = content;
  17082. this.storeName = false;
  17083. this.edited = false;
  17084. // we make these non-enumerable, for sanity while debugging
  17085. Object.defineProperties(this, {
  17086. previous: { writable: true, value: null },
  17087. next: { writable: true, value: null }
  17088. });
  17089. };
  17090. Chunk.prototype.appendLeft = function appendLeft (content) {
  17091. this.outro += content;
  17092. };
  17093. Chunk.prototype.appendRight = function appendRight (content) {
  17094. this.intro = this.intro + content;
  17095. };
  17096. Chunk.prototype.clone = function clone () {
  17097. var chunk = new Chunk(this.start, this.end, this.original);
  17098. chunk.intro = this.intro;
  17099. chunk.outro = this.outro;
  17100. chunk.content = this.content;
  17101. chunk.storeName = this.storeName;
  17102. chunk.edited = this.edited;
  17103. return chunk;
  17104. };
  17105. Chunk.prototype.contains = function contains (index) {
  17106. return this.start < index && index < this.end;
  17107. };
  17108. Chunk.prototype.eachNext = function eachNext (fn) {
  17109. var chunk = this;
  17110. while (chunk) {
  17111. fn(chunk);
  17112. chunk = chunk.next;
  17113. }
  17114. };
  17115. Chunk.prototype.eachPrevious = function eachPrevious (fn) {
  17116. var chunk = this;
  17117. while (chunk) {
  17118. fn(chunk);
  17119. chunk = chunk.previous;
  17120. }
  17121. };
  17122. Chunk.prototype.edit = function edit (content, storeName, contentOnly) {
  17123. this.content = content;
  17124. if (!contentOnly) {
  17125. this.intro = '';
  17126. this.outro = '';
  17127. }
  17128. this.storeName = storeName;
  17129. this.edited = true;
  17130. return this;
  17131. };
  17132. Chunk.prototype.prependLeft = function prependLeft (content) {
  17133. this.outro = content + this.outro;
  17134. };
  17135. Chunk.prototype.prependRight = function prependRight (content) {
  17136. this.intro = content + this.intro;
  17137. };
  17138. Chunk.prototype.split = function split (index) {
  17139. var sliceIndex = index - this.start;
  17140. var originalBefore = this.original.slice(0, sliceIndex);
  17141. var originalAfter = this.original.slice(sliceIndex);
  17142. this.original = originalBefore;
  17143. var newChunk = new Chunk(index, this.end, originalAfter);
  17144. newChunk.outro = this.outro;
  17145. this.outro = '';
  17146. this.end = index;
  17147. if (this.edited) {
  17148. // TODO is this block necessary?...
  17149. newChunk.edit('', false);
  17150. this.content = '';
  17151. } else {
  17152. this.content = originalBefore;
  17153. }
  17154. newChunk.next = this.next;
  17155. if (newChunk.next) { newChunk.next.previous = newChunk; }
  17156. newChunk.previous = this;
  17157. this.next = newChunk;
  17158. return newChunk;
  17159. };
  17160. Chunk.prototype.toString = function toString () {
  17161. return this.intro + this.content + this.outro;
  17162. };
  17163. Chunk.prototype.trimEnd = function trimEnd (rx) {
  17164. this.outro = this.outro.replace(rx, '');
  17165. if (this.outro.length) { return true; }
  17166. var trimmed = this.content.replace(rx, '');
  17167. if (trimmed.length) {
  17168. if (trimmed !== this.content) {
  17169. this.split(this.start + trimmed.length).edit('', undefined, true);
  17170. }
  17171. return true;
  17172. } else {
  17173. this.edit('', undefined, true);
  17174. this.intro = this.intro.replace(rx, '');
  17175. if (this.intro.length) { return true; }
  17176. }
  17177. };
  17178. Chunk.prototype.trimStart = function trimStart (rx) {
  17179. this.intro = this.intro.replace(rx, '');
  17180. if (this.intro.length) { return true; }
  17181. var trimmed = this.content.replace(rx, '');
  17182. if (trimmed.length) {
  17183. if (trimmed !== this.content) {
  17184. this.split(this.end - trimmed.length);
  17185. this.edit('', undefined, true);
  17186. }
  17187. return true;
  17188. } else {
  17189. this.edit('', undefined, true);
  17190. this.outro = this.outro.replace(rx, '');
  17191. if (this.outro.length) { return true; }
  17192. }
  17193. };
  17194. var btoa = function () {
  17195. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  17196. };
  17197. if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
  17198. btoa = window.btoa;
  17199. } else if (typeof Buffer === 'function') {
  17200. btoa = function (str) { return new Buffer(str).toString('base64'); };
  17201. }
  17202. var SourceMap = function SourceMap(properties) {
  17203. this.version = 3;
  17204. this.file = properties.file;
  17205. this.sources = properties.sources;
  17206. this.sourcesContent = properties.sourcesContent;
  17207. this.names = properties.names;
  17208. this.mappings = encode(properties.mappings);
  17209. };
  17210. SourceMap.prototype.toString = function toString () {
  17211. return JSON.stringify(this);
  17212. };
  17213. SourceMap.prototype.toUrl = function toUrl () {
  17214. return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
  17215. };
  17216. function guessIndent(code) {
  17217. var lines = code.split('\n');
  17218. var tabbed = lines.filter(function (line) { return /^\t+/.test(line); });
  17219. var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); });
  17220. if (tabbed.length === 0 && spaced.length === 0) {
  17221. return null;
  17222. }
  17223. // More lines tabbed than spaced? Assume tabs, and
  17224. // default to tabs in the case of a tie (or nothing
  17225. // to go on)
  17226. if (tabbed.length >= spaced.length) {
  17227. return '\t';
  17228. }
  17229. // Otherwise, we need to guess the multiple
  17230. var min = spaced.reduce(function (previous, current) {
  17231. var numSpaces = /^ +/.exec(current)[0].length;
  17232. return Math.min(numSpaces, previous);
  17233. }, Infinity);
  17234. return new Array(min + 1).join(' ');
  17235. }
  17236. function getRelativePath(from, to) {
  17237. var fromParts = from.split(/[/\\]/);
  17238. var toParts = to.split(/[/\\]/);
  17239. fromParts.pop(); // get dirname
  17240. while (fromParts[0] === toParts[0]) {
  17241. fromParts.shift();
  17242. toParts.shift();
  17243. }
  17244. if (fromParts.length) {
  17245. var i = fromParts.length;
  17246. while (i--) { fromParts[i] = '..'; }
  17247. }
  17248. return fromParts.concat(toParts).join('/');
  17249. }
  17250. var toString$2 = Object.prototype.toString;
  17251. function isObject(thing) {
  17252. return toString$2.call(thing) === '[object Object]';
  17253. }
  17254. function getLocator$1(source) {
  17255. var originalLines = source.split('\n');
  17256. var lineOffsets = [];
  17257. for (var i = 0, pos = 0; i < originalLines.length; i++) {
  17258. lineOffsets.push(pos);
  17259. pos += originalLines[i].length + 1;
  17260. }
  17261. return function locate(index) {
  17262. var i = 0;
  17263. var j = lineOffsets.length;
  17264. while (i < j) {
  17265. var m = (i + j) >> 1;
  17266. if (index < lineOffsets[m]) {
  17267. j = m;
  17268. } else {
  17269. i = m + 1;
  17270. }
  17271. }
  17272. var line = i - 1;
  17273. var column = index - lineOffsets[line];
  17274. return { line: line, column: column };
  17275. };
  17276. }
  17277. var Mappings = function Mappings(hires) {
  17278. this.hires = hires;
  17279. this.generatedCodeLine = 0;
  17280. this.generatedCodeColumn = 0;
  17281. this.raw = [];
  17282. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  17283. this.pending = null;
  17284. };
  17285. Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) {
  17286. if (content.length) {
  17287. var segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  17288. if (nameIndex >= 0) {
  17289. segment.push(nameIndex);
  17290. }
  17291. this.rawSegments.push(segment);
  17292. } else if (this.pending) {
  17293. this.rawSegments.push(this.pending);
  17294. }
  17295. this.advance(content);
  17296. this.pending = null;
  17297. };
  17298. Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) {
  17299. var this$1 = this;
  17300. var originalCharIndex = chunk.start;
  17301. var first = true;
  17302. while (originalCharIndex < chunk.end) {
  17303. if (this$1.hires || first || sourcemapLocations[originalCharIndex]) {
  17304. this$1.rawSegments.push([this$1.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
  17305. }
  17306. if (original[originalCharIndex] === '\n') {
  17307. loc.line += 1;
  17308. loc.column = 0;
  17309. this$1.generatedCodeLine += 1;
  17310. this$1.raw[this$1.generatedCodeLine] = this$1.rawSegments = [];
  17311. this$1.generatedCodeColumn = 0;
  17312. } else {
  17313. loc.column += 1;
  17314. this$1.generatedCodeColumn += 1;
  17315. }
  17316. originalCharIndex += 1;
  17317. first = false;
  17318. }
  17319. this.pending = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  17320. };
  17321. Mappings.prototype.advance = function advance (str) {
  17322. var this$1 = this;
  17323. if (!str) { return; }
  17324. var lines = str.split('\n');
  17325. if (lines.length > 1) {
  17326. for (var i = 0; i < lines.length - 1; i++) {
  17327. this$1.generatedCodeLine++;
  17328. this$1.raw[this$1.generatedCodeLine] = this$1.rawSegments = [];
  17329. }
  17330. this.generatedCodeColumn = 0;
  17331. }
  17332. this.generatedCodeColumn += lines[lines.length - 1].length;
  17333. };
  17334. var n = '\n';
  17335. var warned = {
  17336. insertLeft: false,
  17337. insertRight: false,
  17338. storeName: false
  17339. };
  17340. var MagicString = function MagicString(string, options) {
  17341. if ( options === void 0 ) options = {};
  17342. var chunk = new Chunk(0, string.length, string);
  17343. Object.defineProperties(this, {
  17344. original: { writable: true, value: string },
  17345. outro: { writable: true, value: '' },
  17346. intro: { writable: true, value: '' },
  17347. firstChunk: { writable: true, value: chunk },
  17348. lastChunk: { writable: true, value: chunk },
  17349. lastSearchedChunk: { writable: true, value: chunk },
  17350. byStart: { writable: true, value: {} },
  17351. byEnd: { writable: true, value: {} },
  17352. filename: { writable: true, value: options.filename },
  17353. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  17354. sourcemapLocations: { writable: true, value: {} },
  17355. storedNames: { writable: true, value: {} },
  17356. indentStr: { writable: true, value: guessIndent(string) }
  17357. });
  17358. this.byStart[0] = chunk;
  17359. this.byEnd[string.length] = chunk;
  17360. };
  17361. MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
  17362. this.sourcemapLocations[char] = true;
  17363. };
  17364. MagicString.prototype.append = function append (content) {
  17365. if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
  17366. this.outro += content;
  17367. return this;
  17368. };
  17369. MagicString.prototype.appendLeft = function appendLeft (index, content) {
  17370. if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
  17371. this._split(index);
  17372. var chunk = this.byEnd[index];
  17373. if (chunk) {
  17374. chunk.appendLeft(content);
  17375. } else {
  17376. this.intro += content;
  17377. }
  17378. return this;
  17379. };
  17380. MagicString.prototype.appendRight = function appendRight (index, content) {
  17381. if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
  17382. this._split(index);
  17383. var chunk = this.byStart[index];
  17384. if (chunk) {
  17385. chunk.appendRight(content);
  17386. } else {
  17387. this.outro += content;
  17388. }
  17389. return this;
  17390. };
  17391. MagicString.prototype.clone = function clone () {
  17392. var cloned = new MagicString(this.original, { filename: this.filename });
  17393. var originalChunk = this.firstChunk;
  17394. var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  17395. while (originalChunk) {
  17396. cloned.byStart[clonedChunk.start] = clonedChunk;
  17397. cloned.byEnd[clonedChunk.end] = clonedChunk;
  17398. var nextOriginalChunk = originalChunk.next;
  17399. var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  17400. if (nextClonedChunk) {
  17401. clonedChunk.next = nextClonedChunk;
  17402. nextClonedChunk.previous = clonedChunk;
  17403. clonedChunk = nextClonedChunk;
  17404. }
  17405. originalChunk = nextOriginalChunk;
  17406. }
  17407. cloned.lastChunk = clonedChunk;
  17408. if (this.indentExclusionRanges) {
  17409. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  17410. }
  17411. Object.keys(this.sourcemapLocations).forEach(function (loc) {
  17412. cloned.sourcemapLocations[loc] = true;
  17413. });
  17414. return cloned;
  17415. };
  17416. MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
  17417. var this$1 = this;
  17418. options = options || {};
  17419. var sourceIndex = 0;
  17420. var names = Object.keys(this.storedNames);
  17421. var mappings = new Mappings(options.hires);
  17422. var locate = getLocator$1(this.original);
  17423. if (this.intro) {
  17424. mappings.advance(this.intro);
  17425. }
  17426. this.firstChunk.eachNext(function (chunk) {
  17427. var loc = locate(chunk.start);
  17428. if (chunk.intro.length) { mappings.advance(chunk.intro); }
  17429. if (chunk.edited) {
  17430. mappings.addEdit(
  17431. sourceIndex,
  17432. chunk.content,
  17433. loc,
  17434. chunk.storeName ? names.indexOf(chunk.original) : -1
  17435. );
  17436. } else {
  17437. mappings.addUneditedChunk(sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations);
  17438. }
  17439. if (chunk.outro.length) { mappings.advance(chunk.outro); }
  17440. });
  17441. return {
  17442. file: options.file ? options.file.split(/[/\\]/).pop() : null,
  17443. sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
  17444. sourcesContent: options.includeContent ? [this.original] : [null],
  17445. names: names,
  17446. mappings: mappings.raw
  17447. };
  17448. };
  17449. MagicString.prototype.generateMap = function generateMap (options) {
  17450. return new SourceMap(this.generateDecodedMap(options));
  17451. };
  17452. MagicString.prototype.getIndentString = function getIndentString () {
  17453. return this.indentStr === null ? '\t' : this.indentStr;
  17454. };
  17455. MagicString.prototype.indent = function indent (indentStr, options) {
  17456. var this$1 = this;
  17457. var pattern = /^[^\r\n]/gm;
  17458. if (isObject(indentStr)) {
  17459. options = indentStr;
  17460. indentStr = undefined;
  17461. }
  17462. indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
  17463. if (indentStr === '') { return this; } // noop
  17464. options = options || {};
  17465. // Process exclusion ranges
  17466. var isExcluded = {};
  17467. if (options.exclude) {
  17468. var exclusions =
  17469. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  17470. exclusions.forEach(function (exclusion) {
  17471. for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
  17472. isExcluded[i] = true;
  17473. }
  17474. });
  17475. }
  17476. var shouldIndentNextCharacter = options.indentStart !== false;
  17477. var replacer = function (match) {
  17478. if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
  17479. shouldIndentNextCharacter = true;
  17480. return match;
  17481. };
  17482. this.intro = this.intro.replace(pattern, replacer);
  17483. var charIndex = 0;
  17484. var chunk = this.firstChunk;
  17485. while (chunk) {
  17486. var end = chunk.end;
  17487. if (chunk.edited) {
  17488. if (!isExcluded[charIndex]) {
  17489. chunk.content = chunk.content.replace(pattern, replacer);
  17490. if (chunk.content.length) {
  17491. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  17492. }
  17493. }
  17494. } else {
  17495. charIndex = chunk.start;
  17496. while (charIndex < end) {
  17497. if (!isExcluded[charIndex]) {
  17498. var char = this$1.original[charIndex];
  17499. if (char === '\n') {
  17500. shouldIndentNextCharacter = true;
  17501. } else if (char !== '\r' && shouldIndentNextCharacter) {
  17502. shouldIndentNextCharacter = false;
  17503. if (charIndex === chunk.start) {
  17504. chunk.prependRight(indentStr);
  17505. } else {
  17506. this$1._splitChunk(chunk, charIndex);
  17507. chunk = chunk.next;
  17508. chunk.prependRight(indentStr);
  17509. }
  17510. }
  17511. }
  17512. charIndex += 1;
  17513. }
  17514. }
  17515. charIndex = chunk.end;
  17516. chunk = chunk.next;
  17517. }
  17518. this.outro = this.outro.replace(pattern, replacer);
  17519. return this;
  17520. };
  17521. MagicString.prototype.insert = function insert () {
  17522. throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
  17523. };
  17524. MagicString.prototype.insertLeft = function insertLeft (index, content) {
  17525. if (!warned.insertLeft) {
  17526. console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
  17527. warned.insertLeft = true;
  17528. }
  17529. return this.appendLeft(index, content);
  17530. };
  17531. MagicString.prototype.insertRight = function insertRight (index, content) {
  17532. if (!warned.insertRight) {
  17533. console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
  17534. warned.insertRight = true;
  17535. }
  17536. return this.prependRight(index, content);
  17537. };
  17538. MagicString.prototype.move = function move (start, end, index) {
  17539. if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); }
  17540. this._split(start);
  17541. this._split(end);
  17542. this._split(index);
  17543. var first = this.byStart[start];
  17544. var last = this.byEnd[end];
  17545. var oldLeft = first.previous;
  17546. var oldRight = last.next;
  17547. var newRight = this.byStart[index];
  17548. if (!newRight && last === this.lastChunk) { return this; }
  17549. var newLeft = newRight ? newRight.previous : this.lastChunk;
  17550. if (oldLeft) { oldLeft.next = oldRight; }
  17551. if (oldRight) { oldRight.previous = oldLeft; }
  17552. if (newLeft) { newLeft.next = first; }
  17553. if (newRight) { newRight.previous = last; }
  17554. if (!first.previous) { this.firstChunk = last.next; }
  17555. if (!last.next) {
  17556. this.lastChunk = first.previous;
  17557. this.lastChunk.next = null;
  17558. }
  17559. first.previous = newLeft;
  17560. last.next = newRight || null;
  17561. if (!newLeft) { this.firstChunk = first; }
  17562. if (!newRight) { this.lastChunk = last; }
  17563. return this;
  17564. };
  17565. MagicString.prototype.overwrite = function overwrite (start, end, content, options) {
  17566. var this$1 = this;
  17567. if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); }
  17568. while (start < 0) { start += this$1.original.length; }
  17569. while (end < 0) { end += this$1.original.length; }
  17570. if (end > this.original.length) { throw new Error('end is out of bounds'); }
  17571. if (start === end)
  17572. { throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
  17573. this._split(start);
  17574. this._split(end);
  17575. if (options === true) {
  17576. if (!warned.storeName) {
  17577. console.warn('The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'); // eslint-disable-line no-console
  17578. warned.storeName = true;
  17579. }
  17580. options = { storeName: true };
  17581. }
  17582. var storeName = options !== undefined ? options.storeName : false;
  17583. var contentOnly = options !== undefined ? options.contentOnly : false;
  17584. if (storeName) {
  17585. var original = this.original.slice(start, end);
  17586. this.storedNames[original] = true;
  17587. }
  17588. var first = this.byStart[start];
  17589. var last = this.byEnd[end];
  17590. if (first) {
  17591. if (end > first.end && first.next !== this.byStart[first.end]) {
  17592. throw new Error('Cannot overwrite across a split point');
  17593. }
  17594. first.edit(content, storeName, contentOnly);
  17595. if (first !== last) {
  17596. var chunk = first.next;
  17597. while (chunk !== last) {
  17598. chunk.edit('', false);
  17599. chunk = chunk.next;
  17600. }
  17601. chunk.edit('', false);
  17602. }
  17603. } else {
  17604. // must be inserting at the end
  17605. var newChunk = new Chunk(start, end, '').edit(content, storeName);
  17606. // TODO last chunk in the array may not be the last chunk, if it's moved...
  17607. last.next = newChunk;
  17608. newChunk.previous = last;
  17609. }
  17610. return this;
  17611. };
  17612. MagicString.prototype.prepend = function prepend (content) {
  17613. if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
  17614. this.intro = content + this.intro;
  17615. return this;
  17616. };
  17617. MagicString.prototype.prependLeft = function prependLeft (index, content) {
  17618. if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
  17619. this._split(index);
  17620. var chunk = this.byEnd[index];
  17621. if (chunk) {
  17622. chunk.prependLeft(content);
  17623. } else {
  17624. this.intro = content + this.intro;
  17625. }
  17626. return this;
  17627. };
  17628. MagicString.prototype.prependRight = function prependRight (index, content) {
  17629. if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
  17630. this._split(index);
  17631. var chunk = this.byStart[index];
  17632. if (chunk) {
  17633. chunk.prependRight(content);
  17634. } else {
  17635. this.outro = content + this.outro;
  17636. }
  17637. return this;
  17638. };
  17639. MagicString.prototype.remove = function remove (start, end) {
  17640. var this$1 = this;
  17641. while (start < 0) { start += this$1.original.length; }
  17642. while (end < 0) { end += this$1.original.length; }
  17643. if (start === end) { return this; }
  17644. if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
  17645. if (start > end) { throw new Error('end must be greater than start'); }
  17646. this._split(start);
  17647. this._split(end);
  17648. var chunk = this.byStart[start];
  17649. while (chunk) {
  17650. chunk.intro = '';
  17651. chunk.outro = '';
  17652. chunk.edit('');
  17653. chunk = end > chunk.end ? this$1.byStart[chunk.end] : null;
  17654. }
  17655. return this;
  17656. };
  17657. MagicString.prototype.lastChar = function lastChar () {
  17658. if (this.outro.length)
  17659. { return this.outro[this.outro.length - 1]; }
  17660. var chunk = this.lastChunk;
  17661. do {
  17662. if (chunk.outro.length)
  17663. { return chunk.outro[chunk.outro.length - 1]; }
  17664. if (chunk.content.length)
  17665. { return chunk.content[chunk.content.length - 1]; }
  17666. if (chunk.intro.length)
  17667. { return chunk.intro[chunk.intro.length - 1]; }
  17668. } while (chunk = chunk.previous);
  17669. if (this.intro.length)
  17670. { return this.intro[this.intro.length - 1]; }
  17671. return '';
  17672. };
  17673. MagicString.prototype.lastLine = function lastLine () {
  17674. var lineIndex = this.outro.lastIndexOf(n);
  17675. if (lineIndex !== -1)
  17676. { return this.outro.substr(lineIndex + 1); }
  17677. var lineStr = this.outro;
  17678. var chunk = this.lastChunk;
  17679. do {
  17680. if (chunk.outro.length > 0) {
  17681. lineIndex = chunk.outro.lastIndexOf(n);
  17682. if (lineIndex !== -1)
  17683. { return chunk.outro.substr(lineIndex + 1) + lineStr; }
  17684. lineStr = chunk.outro + lineStr;
  17685. }
  17686. if (chunk.content.length > 0) {
  17687. lineIndex = chunk.content.lastIndexOf(n);
  17688. if (lineIndex !== -1)
  17689. { return chunk.content.substr(lineIndex + 1) + lineStr; }
  17690. lineStr = chunk.content + lineStr;
  17691. }
  17692. if (chunk.intro.length > 0) {
  17693. lineIndex = chunk.intro.lastIndexOf(n);
  17694. if (lineIndex !== -1)
  17695. { return chunk.intro.substr(lineIndex + 1) + lineStr; }
  17696. lineStr = chunk.intro + lineStr;
  17697. }
  17698. } while (chunk = chunk.previous);
  17699. lineIndex = this.intro.lastIndexOf(n);
  17700. if (lineIndex !== -1)
  17701. { return this.intro.substr(lineIndex + 1) + lineStr; }
  17702. return this.intro + lineStr;
  17703. };
  17704. MagicString.prototype.slice = function slice (start, end) {
  17705. var this$1 = this;
  17706. if ( start === void 0 ) start = 0;
  17707. if ( end === void 0 ) end = this.original.length;
  17708. while (start < 0) { start += this$1.original.length; }
  17709. while (end < 0) { end += this$1.original.length; }
  17710. var result = '';
  17711. // find start chunk
  17712. var chunk = this.firstChunk;
  17713. while (chunk && (chunk.start > start || chunk.end <= start)) {
  17714. // found end chunk before start
  17715. if (chunk.start < end && chunk.end >= end) {
  17716. return result;
  17717. }
  17718. chunk = chunk.next;
  17719. }
  17720. if (chunk && chunk.edited && chunk.start !== start)
  17721. { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
  17722. var startChunk = chunk;
  17723. while (chunk) {
  17724. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  17725. result += chunk.intro;
  17726. }
  17727. var containsEnd = chunk.start < end && chunk.end >= end;
  17728. if (containsEnd && chunk.edited && chunk.end !== end)
  17729. { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
  17730. var sliceStart = startChunk === chunk ? start - chunk.start : 0;
  17731. var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  17732. result += chunk.content.slice(sliceStart, sliceEnd);
  17733. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  17734. result += chunk.outro;
  17735. }
  17736. if (containsEnd) {
  17737. break;
  17738. }
  17739. chunk = chunk.next;
  17740. }
  17741. return result;
  17742. };
  17743. // TODO deprecate this? not really very useful
  17744. MagicString.prototype.snip = function snip (start, end) {
  17745. var clone = this.clone();
  17746. clone.remove(0, start);
  17747. clone.remove(end, clone.original.length);
  17748. return clone;
  17749. };
  17750. MagicString.prototype._split = function _split (index) {
  17751. var this$1 = this;
  17752. if (this.byStart[index] || this.byEnd[index]) { return; }
  17753. var chunk = this.lastSearchedChunk;
  17754. var searchForward = index > chunk.end;
  17755. while (chunk) {
  17756. if (chunk.contains(index)) { return this$1._splitChunk(chunk, index); }
  17757. chunk = searchForward ? this$1.byStart[chunk.end] : this$1.byEnd[chunk.start];
  17758. }
  17759. };
  17760. MagicString.prototype._splitChunk = function _splitChunk (chunk, index) {
  17761. if (chunk.edited && chunk.content.length) {
  17762. // zero-length edited chunks are a special case (overlapping replacements)
  17763. var loc = getLocator$1(this.original)(index);
  17764. throw new Error(
  17765. ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")")
  17766. );
  17767. }
  17768. var newChunk = chunk.split(index);
  17769. this.byEnd[index] = chunk;
  17770. this.byStart[index] = newChunk;
  17771. this.byEnd[newChunk.end] = newChunk;
  17772. if (chunk === this.lastChunk) { this.lastChunk = newChunk; }
  17773. this.lastSearchedChunk = chunk;
  17774. return true;
  17775. };
  17776. MagicString.prototype.toString = function toString () {
  17777. var str = this.intro;
  17778. var chunk = this.firstChunk;
  17779. while (chunk) {
  17780. str += chunk.toString();
  17781. chunk = chunk.next;
  17782. }
  17783. return str + this.outro;
  17784. };
  17785. MagicString.prototype.isEmpty = function isEmpty () {
  17786. var chunk = this.firstChunk;
  17787. do {
  17788. if (chunk.intro.length && chunk.intro.trim() ||
  17789. chunk.content.length && chunk.content.trim() ||
  17790. chunk.outro.length && chunk.outro.trim())
  17791. { return false; }
  17792. } while (chunk = chunk.next);
  17793. return true;
  17794. };
  17795. MagicString.prototype.length = function length () {
  17796. var chunk = this.firstChunk;
  17797. var length = 0;
  17798. do {
  17799. length += chunk.intro.length + chunk.content.length + chunk.outro.length;
  17800. } while (chunk = chunk.next);
  17801. return length;
  17802. };
  17803. MagicString.prototype.trimLines = function trimLines () {
  17804. return this.trim('[\\r\\n]');
  17805. };
  17806. MagicString.prototype.trim = function trim (charType) {
  17807. return this.trimStart(charType).trimEnd(charType);
  17808. };
  17809. MagicString.prototype.trimEndAborted = function trimEndAborted (charType) {
  17810. var this$1 = this;
  17811. var rx = new RegExp((charType || '\\s') + '+$');
  17812. this.outro = this.outro.replace(rx, '');
  17813. if (this.outro.length) { return true; }
  17814. var chunk = this.lastChunk;
  17815. do {
  17816. var end = chunk.end;
  17817. var aborted = chunk.trimEnd(rx);
  17818. // if chunk was trimmed, we have a new lastChunk
  17819. if (chunk.end !== end) {
  17820. if (this$1.lastChunk === chunk) {
  17821. this$1.lastChunk = chunk.next;
  17822. }
  17823. this$1.byEnd[chunk.end] = chunk;
  17824. this$1.byStart[chunk.next.start] = chunk.next;
  17825. this$1.byEnd[chunk.next.end] = chunk.next;
  17826. }
  17827. if (aborted) { return true; }
  17828. chunk = chunk.previous;
  17829. } while (chunk);
  17830. return false;
  17831. };
  17832. MagicString.prototype.trimEnd = function trimEnd (charType) {
  17833. this.trimEndAborted(charType);
  17834. return this;
  17835. };
  17836. MagicString.prototype.trimStartAborted = function trimStartAborted (charType) {
  17837. var this$1 = this;
  17838. var rx = new RegExp('^' + (charType || '\\s') + '+');
  17839. this.intro = this.intro.replace(rx, '');
  17840. if (this.intro.length) { return true; }
  17841. var chunk = this.firstChunk;
  17842. do {
  17843. var end = chunk.end;
  17844. var aborted = chunk.trimStart(rx);
  17845. if (chunk.end !== end) {
  17846. // special case...
  17847. if (chunk === this$1.lastChunk) { this$1.lastChunk = chunk.next; }
  17848. this$1.byEnd[chunk.end] = chunk;
  17849. this$1.byStart[chunk.next.start] = chunk.next;
  17850. this$1.byEnd[chunk.next.end] = chunk.next;
  17851. }
  17852. if (aborted) { return true; }
  17853. chunk = chunk.next;
  17854. } while (chunk);
  17855. return false;
  17856. };
  17857. MagicString.prototype.trimStart = function trimStart (charType) {
  17858. this.trimStartAborted(charType);
  17859. return this;
  17860. };
  17861. var hasOwnProp = Object.prototype.hasOwnProperty;
  17862. var Bundle = function Bundle(options) {
  17863. if ( options === void 0 ) options = {};
  17864. this.intro = options.intro || '';
  17865. this.separator = options.separator !== undefined ? options.separator : '\n';
  17866. this.sources = [];
  17867. this.uniqueSources = [];
  17868. this.uniqueSourceIndexByFilename = {};
  17869. };
  17870. Bundle.prototype.addSource = function addSource (source) {
  17871. if (source instanceof MagicString) {
  17872. return this.addSource({
  17873. content: source,
  17874. filename: source.filename,
  17875. separator: this.separator
  17876. });
  17877. }
  17878. if (!isObject(source) || !source.content) {
  17879. throw new Error('bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`');
  17880. }
  17881. ['filename', 'indentExclusionRanges', 'separator'].forEach(function (option) {
  17882. if (!hasOwnProp.call(source, option)) { source[option] = source.content[option]; }
  17883. });
  17884. if (source.separator === undefined) {
  17885. // TODO there's a bunch of this sort of thing, needs cleaning up
  17886. source.separator = this.separator;
  17887. }
  17888. if (source.filename) {
  17889. if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
  17890. this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
  17891. this.uniqueSources.push({ filename: source.filename, content: source.content.original });
  17892. } else {
  17893. var uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
  17894. if (source.content.original !== uniqueSource.content) {
  17895. throw new Error(("Illegal source: same filename (" + (source.filename) + "), different contents"));
  17896. }
  17897. }
  17898. }
  17899. this.sources.push(source);
  17900. return this;
  17901. };
  17902. Bundle.prototype.append = function append (str, options) {
  17903. this.addSource({
  17904. content: new MagicString(str),
  17905. separator: (options && options.separator) || ''
  17906. });
  17907. return this;
  17908. };
  17909. Bundle.prototype.clone = function clone () {
  17910. var bundle = new Bundle({
  17911. intro: this.intro,
  17912. separator: this.separator
  17913. });
  17914. this.sources.forEach(function (source) {
  17915. bundle.addSource({
  17916. filename: source.filename,
  17917. content: source.content.clone(),
  17918. separator: source.separator
  17919. });
  17920. });
  17921. return bundle;
  17922. };
  17923. Bundle.prototype.generateDecodedMap = function generateDecodedMap (options) {
  17924. var this$1 = this;
  17925. if ( options === void 0 ) options = {};
  17926. var names = [];
  17927. this.sources.forEach(function (source) {
  17928. Object.keys(source.content.storedNames).forEach(function (name) {
  17929. if (!~names.indexOf(name)) { names.push(name); }
  17930. });
  17931. });
  17932. var mappings = new Mappings(options.hires);
  17933. if (this.intro) {
  17934. mappings.advance(this.intro);
  17935. }
  17936. this.sources.forEach(function (source, i) {
  17937. if (i > 0) {
  17938. mappings.advance(this$1.separator);
  17939. }
  17940. var sourceIndex = source.filename ? this$1.uniqueSourceIndexByFilename[source.filename] : -1;
  17941. var magicString = source.content;
  17942. var locate = getLocator$1(magicString.original);
  17943. if (magicString.intro) {
  17944. mappings.advance(magicString.intro);
  17945. }
  17946. magicString.firstChunk.eachNext(function (chunk) {
  17947. var loc = locate(chunk.start);
  17948. if (chunk.intro.length) { mappings.advance(chunk.intro); }
  17949. if (source.filename) {
  17950. if (chunk.edited) {
  17951. mappings.addEdit(
  17952. sourceIndex,
  17953. chunk.content,
  17954. loc,
  17955. chunk.storeName ? names.indexOf(chunk.original) : -1
  17956. );
  17957. } else {
  17958. mappings.addUneditedChunk(
  17959. sourceIndex,
  17960. chunk,
  17961. magicString.original,
  17962. loc,
  17963. magicString.sourcemapLocations
  17964. );
  17965. }
  17966. } else {
  17967. mappings.advance(chunk.content);
  17968. }
  17969. if (chunk.outro.length) { mappings.advance(chunk.outro); }
  17970. });
  17971. if (magicString.outro) {
  17972. mappings.advance(magicString.outro);
  17973. }
  17974. });
  17975. return {
  17976. file: options.file ? options.file.split(/[/\\]/).pop() : null,
  17977. sources: this.uniqueSources.map(function (source) {
  17978. return options.file ? getRelativePath(options.file, source.filename) : source.filename;
  17979. }),
  17980. sourcesContent: this.uniqueSources.map(function (source) {
  17981. return options.includeContent ? source.content : null;
  17982. }),
  17983. names: names,
  17984. mappings: mappings.raw
  17985. };
  17986. };
  17987. Bundle.prototype.generateMap = function generateMap (options) {
  17988. return new SourceMap(this.generateDecodedMap(options));
  17989. };
  17990. Bundle.prototype.getIndentString = function getIndentString () {
  17991. var indentStringCounts = {};
  17992. this.sources.forEach(function (source) {
  17993. var indentStr = source.content.indentStr;
  17994. if (indentStr === null) { return; }
  17995. if (!indentStringCounts[indentStr]) { indentStringCounts[indentStr] = 0; }
  17996. indentStringCounts[indentStr] += 1;
  17997. });
  17998. return (
  17999. Object.keys(indentStringCounts).sort(function (a, b) {
  18000. return indentStringCounts[a] - indentStringCounts[b];
  18001. })[0] || '\t'
  18002. );
  18003. };
  18004. Bundle.prototype.indent = function indent (indentStr) {
  18005. var this$1 = this;
  18006. if (!arguments.length) {
  18007. indentStr = this.getIndentString();
  18008. }
  18009. if (indentStr === '') { return this; } // noop
  18010. var trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
  18011. this.sources.forEach(function (source, i) {
  18012. var separator = source.separator !== undefined ? source.separator : this$1.separator;
  18013. var indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));
  18014. source.content.indent(indentStr, {
  18015. exclude: source.indentExclusionRanges,
  18016. indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
  18017. });
  18018. trailingNewline = source.content.lastChar() === '\n';
  18019. });
  18020. if (this.intro) {
  18021. this.intro =
  18022. indentStr +
  18023. this.intro.replace(/^[^\n]/gm, function (match, index) {
  18024. return index > 0 ? indentStr + match : match;
  18025. });
  18026. }
  18027. return this;
  18028. };
  18029. Bundle.prototype.prepend = function prepend (str) {
  18030. this.intro = str + this.intro;
  18031. return this;
  18032. };
  18033. Bundle.prototype.toString = function toString () {
  18034. var this$1 = this;
  18035. var body = this.sources
  18036. .map(function (source, i) {
  18037. var separator = source.separator !== undefined ? source.separator : this$1.separator;
  18038. var str = (i > 0 ? separator : '') + source.content.toString();
  18039. return str;
  18040. })
  18041. .join('');
  18042. return this.intro + body;
  18043. };
  18044. Bundle.prototype.isEmpty = function isEmpty () {
  18045. if (this.intro.length && this.intro.trim())
  18046. { return false; }
  18047. if (this.sources.some(function (source) { return !source.content.isEmpty(); }))
  18048. { return false; }
  18049. return true;
  18050. };
  18051. Bundle.prototype.length = function length () {
  18052. return this.sources.reduce(function (length, source) { return length + source.content.length(); }, this.intro.length);
  18053. };
  18054. Bundle.prototype.trimLines = function trimLines () {
  18055. return this.trim('[\\r\\n]');
  18056. };
  18057. Bundle.prototype.trim = function trim (charType) {
  18058. return this.trimStart(charType).trimEnd(charType);
  18059. };
  18060. Bundle.prototype.trimStart = function trimStart (charType) {
  18061. var this$1 = this;
  18062. var rx = new RegExp('^' + (charType || '\\s') + '+');
  18063. this.intro = this.intro.replace(rx, '');
  18064. if (!this.intro) {
  18065. var source;
  18066. var i = 0;
  18067. do {
  18068. source = this$1.sources[i++];
  18069. if (!source) {
  18070. break;
  18071. }
  18072. } while (!source.content.trimStartAborted(charType));
  18073. }
  18074. return this;
  18075. };
  18076. Bundle.prototype.trimEnd = function trimEnd (charType) {
  18077. var this$1 = this;
  18078. var rx = new RegExp((charType || '\\s') + '+$');
  18079. var source;
  18080. var i = this.sources.length - 1;
  18081. do {
  18082. source = this$1.sources[i--];
  18083. if (!source) {
  18084. this$1.intro = this$1.intro.replace(rx, '');
  18085. break;
  18086. }
  18087. } while (!source.content.trimEndAborted(charType));
  18088. return this;
  18089. };
  18090. function isReference(node, parent) {
  18091. if (node.type === 'MemberExpression') {
  18092. return !node.computed && isReference(node.object, node);
  18093. }
  18094. if (node.type === 'Identifier') {
  18095. // the only time we could have an identifier node without a parent is
  18096. // if it's the entire body of a function without a block statement –
  18097. // i.e. an arrow function expression like `a => a`
  18098. if (!parent)
  18099. return true;
  18100. // TODO is this right?
  18101. if (parent.type === 'MemberExpression' || parent.type === 'MethodDefinition') {
  18102. return parent.computed || node === parent.object;
  18103. }
  18104. // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
  18105. if (parent.type === 'Property')
  18106. return parent.computed || node === parent.value;
  18107. // disregard the `bar` in `export { foo as bar }`
  18108. if (parent.type === 'ExportSpecifier' && node !== parent.local)
  18109. return false;
  18110. return true;
  18111. }
  18112. return false;
  18113. }
  18114. function getMethodName(node) {
  18115. if (node.type === 'Identifier')
  18116. return node.name;
  18117. if (node.type === 'Literal')
  18118. return String(node.value);
  18119. }
  18120. const keys = {
  18121. ObjectExpression: 'properties',
  18122. Program: 'body',
  18123. };
  18124. const offsets = {
  18125. ObjectExpression: [1, -1],
  18126. Program: [0, 0],
  18127. };
  18128. function removeNode(code, parent, node) {
  18129. const key = keys[parent.type];
  18130. const offset = offsets[parent.type];
  18131. if (!key || !offset)
  18132. throw new Error(`not implemented: ${parent.type}`);
  18133. const list = parent[key];
  18134. const i = list.indexOf(node);
  18135. if (i === -1)
  18136. throw new Error('node not in list');
  18137. let a;
  18138. let b;
  18139. if (list.length === 1) {
  18140. // remove everything, leave {}
  18141. a = parent.start + offset[0];
  18142. b = parent.end + offset[1];
  18143. }
  18144. else if (i === 0) {
  18145. // remove everything before second node, including comments
  18146. a = parent.start + offset[0];
  18147. while (/\s/.test(code.original[a]))
  18148. a += 1;
  18149. b = list[i].end;
  18150. while (/[\s,]/.test(code.original[b]))
  18151. b += 1;
  18152. }
  18153. else {
  18154. // remove the end of the previous node to the end of this one
  18155. a = list[i - 1].end;
  18156. b = node.end;
  18157. }
  18158. code.remove(a, b);
  18159. return;
  18160. }
  18161. function nodeToString(node) {
  18162. if (node.type === 'Literal' && typeof node.value === 'string') {
  18163. return node.value;
  18164. }
  18165. else if (node.type === 'TemplateLiteral'
  18166. && node.quasis.length === 1
  18167. && node.expressions.length === 0) {
  18168. return node.quasis[0].value.raw;
  18169. }
  18170. }
  18171. function list$1(items, conjunction = 'or') {
  18172. if (items.length === 1)
  18173. return items[0];
  18174. return `${items.slice(0, -1).join(', ')} ${conjunction} ${items[items.length - 1]}`;
  18175. }
  18176. const wrappers$1 = { es, amd, cjs, iife, umd, eval: expr };
  18177. function wrapModule(code, format, name, options, banner, sharedPath, helpers, imports, shorthandImports, source) {
  18178. if (format === 'es')
  18179. return es(code, name, options, banner, sharedPath, helpers, imports, shorthandImports, source);
  18180. const dependencies = imports.map((declaration, i) => {
  18181. const defaultImport = declaration.specifiers.find((x) => x.type === 'ImportDefaultSpecifier' ||
  18182. (x.type === 'ImportSpecifier' && x.imported.name === 'default'));
  18183. const namespaceImport = declaration.specifiers.find((x) => x.type === 'ImportNamespaceSpecifier');
  18184. const namedImports = declaration.specifiers.filter((x) => x.type === 'ImportSpecifier' && x.imported.name !== 'default');
  18185. const name = defaultImport || namespaceImport
  18186. ? (defaultImport || namespaceImport).local.name
  18187. : `__import${i}`;
  18188. const statements = [];
  18189. namedImports.forEach((specifier) => {
  18190. statements.push(`var ${specifier.local.name} = ${name}.${specifier.imported.name};`);
  18191. });
  18192. if (defaultImport) {
  18193. statements.push(`${name} = (${name} && ${name}.__esModule) ? ${name}["default"] : ${name};`);
  18194. }
  18195. return { name, statements, source: declaration.source.value };
  18196. })
  18197. .concat(shorthandImports.map(({ name, source }) => ({
  18198. name,
  18199. statements: [
  18200. `${name} = (${name} && ${name}.__esModule) ? ${name}["default"] : ${name};`,
  18201. ],
  18202. source,
  18203. })));
  18204. if (format === 'amd')
  18205. return amd(code, name, options, banner, dependencies);
  18206. if (format === 'cjs')
  18207. return cjs(code, name, options, banner, sharedPath, helpers, dependencies);
  18208. if (format === 'iife')
  18209. return iife(code, name, options, banner, dependencies);
  18210. if (format === 'umd')
  18211. return umd(code, name, options, banner, dependencies);
  18212. if (format === 'eval')
  18213. return expr(code, name, options, banner, dependencies);
  18214. throw new Error(`options.format is invalid (must be ${list$1(Object.keys(wrappers$1))})`);
  18215. }
  18216. function es(code, name, options, banner, sharedPath, helpers, imports, shorthandImports, source) {
  18217. const importHelpers = helpers.length > 0 && (`import { ${helpers.map(h => h.name === h.alias ? h.name : `${h.name} as ${h.alias}`).join(', ')} } from ${JSON.stringify(sharedPath)};`);
  18218. const importBlock = imports.length > 0 && (imports
  18219. .map((declaration) => source.slice(declaration.start, declaration.end))
  18220. .join('\n'));
  18221. const shorthandImportBlock = shorthandImports.length > 0 && (shorthandImports.map(({ name, source }) => `import ${name} from ${JSON.stringify(source)};`).join('\n'));
  18222. return deindent `
  18223. ${banner}
  18224. ${importHelpers}
  18225. ${importBlock}
  18226. ${shorthandImportBlock}
  18227. ${code}
  18228. export default ${name};`;
  18229. }
  18230. function amd(code, name, options, banner, dependencies) {
  18231. const sourceString = dependencies.length
  18232. ? `[${dependencies.map(d => `"${removeExtension(d.source)}"`).join(', ')}], `
  18233. : '';
  18234. const id = options.amd && options.amd.id;
  18235. return deindent `
  18236. define(${id ? `"${id}", ` : ''}${sourceString}function(${paramString(dependencies)}) { "use strict";
  18237. ${getCompatibilityStatements(dependencies)}
  18238. ${code}
  18239. return ${name};
  18240. });`;
  18241. }
  18242. function cjs(code, name, options, banner, sharedPath, helpers, dependencies) {
  18243. const helperDeclarations = helpers.map(h => `${h.alias === h.name ? h.name : `${h.name}: ${h.alias}`}`).join(', ');
  18244. const helperBlock = helpers.length > 0 && (`var { ${helperDeclarations} } = require(${JSON.stringify(sharedPath)});\n`);
  18245. const requireBlock = dependencies.length > 0 && (dependencies
  18246. .map(d => `var ${d.name} = require("${d.source}");`)
  18247. .join('\n\n'));
  18248. return deindent `
  18249. ${banner}
  18250. "use strict";
  18251. ${helperBlock}
  18252. ${requireBlock}
  18253. ${getCompatibilityStatements(dependencies)}
  18254. ${code}
  18255. module.exports = ${name};`;
  18256. }
  18257. function iife(code, name, options, banner, dependencies) {
  18258. if (!options.name) {
  18259. throw new Error(`Missing required 'name' option for IIFE export`);
  18260. }
  18261. const globals = getGlobals(dependencies, options);
  18262. return deindent `
  18263. ${banner}
  18264. var ${options.name} = (function(${paramString(dependencies)}) { "use strict";
  18265. ${getCompatibilityStatements(dependencies)}
  18266. ${code}
  18267. return ${name};
  18268. }(${globals.join(', ')}));`;
  18269. }
  18270. function umd(code, name, options, banner, dependencies) {
  18271. if (!options.name) {
  18272. throw new Error(`Missing required 'name' option for UMD export`);
  18273. }
  18274. const amdId = options.amd && options.amd.id ? `'${options.amd.id}', ` : '';
  18275. const amdDeps = dependencies.length
  18276. ? `[${dependencies.map(d => `"${removeExtension(d.source)}"`).join(', ')}], `
  18277. : '';
  18278. const cjsDeps = dependencies
  18279. .map(d => `require("${d.source}")`)
  18280. .join(', ');
  18281. const globals = getGlobals(dependencies, options);
  18282. return deindent `
  18283. ${banner}
  18284. (function(global, factory) {
  18285. typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory(${cjsDeps}) :
  18286. typeof define === "function" && define.amd ? define(${amdId}${amdDeps}factory) :
  18287. (global.${options.name} = factory(${globals.join(', ')}));
  18288. }(this, (function (${paramString(dependencies)}) { "use strict";
  18289. ${getCompatibilityStatements(dependencies)}
  18290. ${code}
  18291. return ${name};
  18292. })));`;
  18293. }
  18294. function expr(code, name, options, banner, dependencies) {
  18295. const globals = getGlobals(dependencies, options);
  18296. return deindent `
  18297. (function (${paramString(dependencies)}) { "use strict";
  18298. ${banner}
  18299. ${getCompatibilityStatements(dependencies)}
  18300. ${code}
  18301. return ${name};
  18302. }(${globals.join(', ')}))`;
  18303. }
  18304. function paramString(dependencies) {
  18305. return dependencies.map(dep => dep.name).join(', ');
  18306. }
  18307. function removeExtension(file) {
  18308. const index = file.lastIndexOf('.');
  18309. return ~index ? file.slice(0, index) : file;
  18310. }
  18311. function getCompatibilityStatements(dependencies) {
  18312. if (!dependencies.length)
  18313. return null;
  18314. const statements = [];
  18315. dependencies.forEach(dependency => {
  18316. statements.push(...dependency.statements);
  18317. });
  18318. return statements.join('\n');
  18319. }
  18320. function getGlobals(dependencies, options) {
  18321. const { globals, onwarn } = options;
  18322. const globalFn = getGlobalFn(globals);
  18323. return dependencies.map(d => {
  18324. let name = globalFn(d.source);
  18325. if (!name) {
  18326. if (d.name.startsWith('__import')) {
  18327. throw new Error(`Could not determine name for imported module '${d.source}' – use options.globals`);
  18328. }
  18329. else {
  18330. const warning = {
  18331. code: `options-missing-globals`,
  18332. message: `No name was supplied for imported module '${d.source}'. Guessing '${d.name}', but you should use options.globals`,
  18333. };
  18334. onwarn(warning);
  18335. }
  18336. name = d.name;
  18337. }
  18338. return name;
  18339. });
  18340. }
  18341. function getGlobalFn(globals) {
  18342. if (typeof globals === 'function')
  18343. return globals;
  18344. if (typeof globals === 'object') {
  18345. return id => globals[id];
  18346. }
  18347. return () => undefined;
  18348. }
  18349. function createScopes(expression) {
  18350. const map = new WeakMap();
  18351. const globals = new Set();
  18352. let scope = new Scope(null, false);
  18353. walk(expression, {
  18354. enter(node, parent) {
  18355. if (/Function/.test(node.type)) {
  18356. if (node.type === 'FunctionDeclaration') {
  18357. scope.declarations.add(node.id.name);
  18358. }
  18359. else {
  18360. scope = new Scope(scope, false);
  18361. map.set(node, scope);
  18362. if (node.id)
  18363. scope.declarations.add(node.id.name);
  18364. }
  18365. node.params.forEach((param) => {
  18366. extractNames(param).forEach(name => {
  18367. scope.declarations.add(name);
  18368. });
  18369. });
  18370. }
  18371. else if (/For(?:In|Of)Statement/.test(node.type)) {
  18372. scope = new Scope(scope, true);
  18373. map.set(node, scope);
  18374. }
  18375. else if (node.type === 'BlockStatement') {
  18376. scope = new Scope(scope, true);
  18377. map.set(node, scope);
  18378. }
  18379. else if (/(Function|Class|Variable)Declaration/.test(node.type)) {
  18380. scope.addDeclaration(node);
  18381. }
  18382. else if (isReference(node, parent)) {
  18383. if (!scope.has(node.name)) {
  18384. globals.add(node.name);
  18385. }
  18386. }
  18387. },
  18388. leave(node) {
  18389. if (map.has(node)) {
  18390. scope = scope.parent;
  18391. }
  18392. },
  18393. });
  18394. return { map, scope, globals };
  18395. }
  18396. // TODO remove this in favour of weakmap version
  18397. function annotateWithScopes(expression) {
  18398. const globals = new Set();
  18399. let scope = new Scope(null, false);
  18400. walk(expression, {
  18401. enter(node, parent) {
  18402. if (/Function/.test(node.type)) {
  18403. if (node.type === 'FunctionDeclaration') {
  18404. scope.declarations.add(node.id.name);
  18405. }
  18406. else {
  18407. node._scope = scope = new Scope(scope, false);
  18408. if (node.id)
  18409. scope.declarations.add(node.id.name);
  18410. }
  18411. node.params.forEach((param) => {
  18412. extractNames(param).forEach(name => {
  18413. scope.declarations.add(name);
  18414. });
  18415. });
  18416. }
  18417. else if (/For(?:In|Of)Statement/.test(node.type)) {
  18418. node._scope = scope = new Scope(scope, true);
  18419. }
  18420. else if (node.type === 'BlockStatement') {
  18421. node._scope = scope = new Scope(scope, true);
  18422. }
  18423. else if (/(Function|Class|Variable)Declaration/.test(node.type)) {
  18424. scope.addDeclaration(node);
  18425. }
  18426. else if (isReference(node, parent)) {
  18427. if (!scope.has(node.name)) {
  18428. globals.add(node.name);
  18429. }
  18430. }
  18431. },
  18432. leave(node) {
  18433. if (node._scope) {
  18434. scope = scope.parent;
  18435. }
  18436. },
  18437. });
  18438. return { scope, globals };
  18439. }
  18440. class Scope {
  18441. constructor(parent, block) {
  18442. this.parent = parent;
  18443. this.block = block;
  18444. this.declarations = new Set();
  18445. }
  18446. addDeclaration(node) {
  18447. if (node.kind === 'var' && !this.block && this.parent) {
  18448. this.parent.addDeclaration(node);
  18449. }
  18450. else if (node.type === 'VariableDeclaration') {
  18451. node.declarations.forEach((declarator) => {
  18452. extractNames(declarator.id).forEach(name => {
  18453. this.declarations.add(name);
  18454. });
  18455. });
  18456. }
  18457. else {
  18458. this.declarations.add(node.id.name);
  18459. }
  18460. }
  18461. has(name) {
  18462. return (this.declarations.has(name) || (this.parent && this.parent.has(name)));
  18463. }
  18464. }
  18465. function extractNames(param) {
  18466. const names = [];
  18467. extractors[param.type](names, param);
  18468. return names;
  18469. }
  18470. const extractors = {
  18471. Identifier(names, param) {
  18472. names.push(param.name);
  18473. },
  18474. ObjectPattern(names, param) {
  18475. param.properties.forEach((prop) => {
  18476. if (prop.type === 'RestElement') {
  18477. names.push(prop.argument.name);
  18478. }
  18479. else {
  18480. extractors[prop.value.type](names, prop.value);
  18481. }
  18482. });
  18483. },
  18484. ArrayPattern(names, param) {
  18485. param.elements.forEach((element) => {
  18486. if (element)
  18487. extractors[element.type](names, element);
  18488. });
  18489. },
  18490. RestElement(names, param) {
  18491. extractors[param.argument.type](names, param.argument);
  18492. },
  18493. AssignmentPattern(names, param) {
  18494. extractors[param.left.type](names, param.left);
  18495. },
  18496. };
  18497. const UNKNOWN = {};
  18498. function gatherPossibleValues(node, set) {
  18499. if (node.type === 'Literal') {
  18500. set.add(node.value);
  18501. }
  18502. else if (node.type === 'ConditionalExpression') {
  18503. gatherPossibleValues(node.consequent, set);
  18504. gatherPossibleValues(node.alternate, set);
  18505. }
  18506. else {
  18507. set.add(UNKNOWN);
  18508. }
  18509. }
  18510. class Selector$1 {
  18511. constructor(node, stylesheet) {
  18512. this.node = node;
  18513. this.stylesheet = stylesheet;
  18514. this.blocks = groupSelectors(node);
  18515. // take trailing :global(...) selectors out of consideration
  18516. let i = this.blocks.length;
  18517. while (i > 0) {
  18518. if (!this.blocks[i - 1].global)
  18519. break;
  18520. i -= 1;
  18521. }
  18522. this.localBlocks = this.blocks.slice(0, i);
  18523. this.used = this.blocks[0].global;
  18524. }
  18525. apply(node, stack) {
  18526. const toEncapsulate = [];
  18527. applySelector(this.stylesheet, this.localBlocks.slice(), node, stack.slice(), toEncapsulate);
  18528. if (toEncapsulate.length > 0) {
  18529. toEncapsulate.filter((_, i) => i === 0 || i === toEncapsulate.length - 1).forEach(({ node, block }) => {
  18530. this.stylesheet.nodesWithCssClass.add(node);
  18531. block.shouldEncapsulate = true;
  18532. });
  18533. this.used = true;
  18534. }
  18535. }
  18536. minify(code) {
  18537. let c = null;
  18538. this.blocks.forEach((block, i) => {
  18539. if (i > 0) {
  18540. if (block.start - c > 1) {
  18541. code.overwrite(c, block.start, block.combinator.name || ' ');
  18542. }
  18543. }
  18544. c = block.end;
  18545. });
  18546. }
  18547. transform(code, attr) {
  18548. function encapsulateBlock(block) {
  18549. let i = block.selectors.length;
  18550. while (i--) {
  18551. const selector = block.selectors[i];
  18552. if (selector.type === 'PseudoElementSelector' || selector.type === 'PseudoClassSelector')
  18553. continue;
  18554. if (selector.type === 'TypeSelector' && selector.name === '*') {
  18555. code.overwrite(selector.start, selector.end, attr);
  18556. }
  18557. else {
  18558. code.appendLeft(selector.end, attr);
  18559. }
  18560. break;
  18561. }
  18562. i = block.selectors.length;
  18563. while (i--) {
  18564. const selector = block.selectors[i];
  18565. if (selector.type === 'RefSelector') {
  18566. code.overwrite(selector.start, selector.end, `.svelte-ref-${selector.name}`, {
  18567. contentOnly: true,
  18568. storeName: false
  18569. });
  18570. }
  18571. }
  18572. }
  18573. this.blocks.forEach((block, i) => {
  18574. if (block.global) {
  18575. const selector = block.selectors[0];
  18576. const first = selector.children[0];
  18577. const last = selector.children[selector.children.length - 1];
  18578. code.remove(selector.start, first.start).remove(last.end, selector.end);
  18579. }
  18580. if (block.shouldEncapsulate)
  18581. encapsulateBlock(block);
  18582. });
  18583. }
  18584. validate(component) {
  18585. this.blocks.forEach((block) => {
  18586. let i = block.selectors.length;
  18587. while (i-- > 1) {
  18588. const selector = block.selectors[i];
  18589. if (selector.type === 'PseudoClassSelector' && selector.name === 'global') {
  18590. component.error(selector, {
  18591. code: `css-invalid-global`,
  18592. message: `:global(...) must be the first element in a compound selector`
  18593. });
  18594. }
  18595. }
  18596. });
  18597. let start = 0;
  18598. let end = this.blocks.length;
  18599. for (; start < end; start += 1) {
  18600. if (!this.blocks[start].global)
  18601. break;
  18602. }
  18603. for (; end > start; end -= 1) {
  18604. if (!this.blocks[end - 1].global)
  18605. break;
  18606. }
  18607. for (let i = start; i < end; i += 1) {
  18608. if (this.blocks[i].global) {
  18609. component.error(this.blocks[i].selectors[0], {
  18610. code: `css-invalid-global`,
  18611. message: `:global(...) can be at the start or end of a selector sequence, but not in the middle`
  18612. });
  18613. }
  18614. }
  18615. }
  18616. }
  18617. function applySelector(stylesheet, blocks, node, stack, toEncapsulate) {
  18618. const block = blocks.pop();
  18619. if (!block)
  18620. return false;
  18621. if (!node) {
  18622. return blocks.every(block => block.global);
  18623. }
  18624. let i = block.selectors.length;
  18625. while (i--) {
  18626. const selector = block.selectors[i];
  18627. if (selector.type === 'PseudoClassSelector' && selector.name === 'global') {
  18628. // TODO shouldn't see this here... maybe we should enforce that :global(...)
  18629. // cannot be sandwiched between non-global selectors?
  18630. return false;
  18631. }
  18632. if (selector.type === 'PseudoClassSelector' || selector.type === 'PseudoElementSelector') {
  18633. continue;
  18634. }
  18635. if (selector.type === 'ClassSelector') {
  18636. if (!attributeMatches(node, 'class', selector.name, '~=', false) && !classMatches(node, selector.name))
  18637. return false;
  18638. }
  18639. else if (selector.type === 'IdSelector') {
  18640. if (!attributeMatches(node, 'id', selector.name, '=', false))
  18641. return false;
  18642. }
  18643. else if (selector.type === 'AttributeSelector') {
  18644. if (!attributeMatches(node, selector.name.name, selector.value && unquote(selector.value), selector.matcher, selector.flags))
  18645. return false;
  18646. }
  18647. else if (selector.type === 'TypeSelector') {
  18648. // remove toLowerCase() in v2, when uppercase elements will be forbidden
  18649. if (node.name.toLowerCase() !== selector.name.toLowerCase() && selector.name !== '*')
  18650. return false;
  18651. }
  18652. else if (selector.type === 'RefSelector') {
  18653. if (node.ref && node.ref.name === selector.name) {
  18654. stylesheet.nodesWithRefCssClass.set(selector.name, node);
  18655. toEncapsulate.push({ node, block });
  18656. return true;
  18657. }
  18658. return;
  18659. }
  18660. else {
  18661. // bail. TODO figure out what these could be
  18662. toEncapsulate.push({ node, block });
  18663. return true;
  18664. }
  18665. }
  18666. if (block.combinator) {
  18667. if (block.combinator.type === 'WhiteSpace') {
  18668. while (stack.length) {
  18669. if (applySelector(stylesheet, blocks.slice(), stack.pop(), stack, toEncapsulate)) {
  18670. toEncapsulate.push({ node, block });
  18671. return true;
  18672. }
  18673. }
  18674. if (blocks.every(block => block.global)) {
  18675. toEncapsulate.push({ node, block });
  18676. return true;
  18677. }
  18678. return false;
  18679. }
  18680. else if (block.combinator.name === '>') {
  18681. if (applySelector(stylesheet, blocks, stack.pop(), stack, toEncapsulate)) {
  18682. toEncapsulate.push({ node, block });
  18683. return true;
  18684. }
  18685. return false;
  18686. }
  18687. // TODO other combinators
  18688. toEncapsulate.push({ node, block });
  18689. return true;
  18690. }
  18691. toEncapsulate.push({ node, block });
  18692. return true;
  18693. }
  18694. const operators = {
  18695. '=': (value, flags) => new RegExp(`^${value}$`, flags),
  18696. '~=': (value, flags) => new RegExp(`\\b${value}\\b`, flags),
  18697. '|=': (value, flags) => new RegExp(`^${value}(-.+)?$`, flags),
  18698. '^=': (value, flags) => new RegExp(`^${value}`, flags),
  18699. '$=': (value, flags) => new RegExp(`${value}$`, flags),
  18700. '*=': (value, flags) => new RegExp(value, flags)
  18701. };
  18702. function attributeMatches(node, name, expectedValue, operator, caseInsensitive) {
  18703. const spread = node.attributes.find(attr => attr.type === 'Spread');
  18704. if (spread)
  18705. return true;
  18706. const attr = node.attributes.find((attr) => attr.name === name);
  18707. if (!attr)
  18708. return false;
  18709. if (attr.isTrue)
  18710. return operator === null;
  18711. if (attr.chunks.length > 1)
  18712. return true;
  18713. if (!expectedValue)
  18714. return true;
  18715. const pattern = operators[operator](expectedValue, caseInsensitive ? 'i' : '');
  18716. const value = attr.chunks[0];
  18717. if (!value)
  18718. return false;
  18719. if (value.type === 'Text')
  18720. return pattern.test(value.data);
  18721. const possibleValues = new Set();
  18722. gatherPossibleValues(value.node, possibleValues);
  18723. if (possibleValues.has(UNKNOWN))
  18724. return true;
  18725. for (const x of Array.from(possibleValues)) { // TypeScript for-of is slightly unlike JS
  18726. if (pattern.test(x))
  18727. return true;
  18728. }
  18729. return false;
  18730. }
  18731. function classMatches(node, name) {
  18732. return node.classes.some(function (classDir) {
  18733. return classDir.name === name;
  18734. });
  18735. }
  18736. function unquote(value) {
  18737. if (value.type === 'Identifier')
  18738. return value.name;
  18739. const str = value.value;
  18740. if (str[0] === str[str.length - 1] && str[0] === "'" || str[0] === '"') {
  18741. return str.slice(1, str.length - 1);
  18742. }
  18743. return str;
  18744. }
  18745. class Block$2 {
  18746. constructor(combinator) {
  18747. this.combinator = combinator;
  18748. this.global = false;
  18749. this.selectors = [];
  18750. this.start = null;
  18751. this.end = null;
  18752. this.shouldEncapsulate = false;
  18753. }
  18754. add(selector) {
  18755. if (this.selectors.length === 0) {
  18756. this.start = selector.start;
  18757. this.global = selector.type === 'PseudoClassSelector' && selector.name === 'global';
  18758. }
  18759. this.selectors.push(selector);
  18760. this.end = selector.end;
  18761. }
  18762. }
  18763. function groupSelectors(selector) {
  18764. let block = new Block$2(null);
  18765. const blocks = [block];
  18766. selector.children.forEach((child, i) => {
  18767. if (child.type === 'WhiteSpace' || child.type === 'Combinator') {
  18768. block = new Block$2(child);
  18769. blocks.push(block);
  18770. }
  18771. else {
  18772. block.add(child);
  18773. }
  18774. });
  18775. return blocks;
  18776. }
  18777. // https://github.com/darkskyapp/string-hash/blob/master/index.js
  18778. function hash$1(str) {
  18779. let hash = 5381;
  18780. let i = str.length;
  18781. while (i--)
  18782. hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
  18783. return (hash >>> 0).toString(36);
  18784. }
  18785. function removeCSSPrefix (name) {
  18786. return name.replace(/^-((webkit)|(moz)|(o)|(ms))-/, '');
  18787. }
  18788. const isKeyframesNode = (node) => removeCSSPrefix(node.name) === 'keyframes';
  18789. class Rule$1 {
  18790. constructor(node, stylesheet, parent) {
  18791. this.node = node;
  18792. this.parent = parent;
  18793. this.selectors = node.selector.children.map((node) => new Selector$1(node, stylesheet));
  18794. this.declarations = node.block.children.map((node) => new Declaration$1(node));
  18795. }
  18796. apply(node, stack) {
  18797. this.selectors.forEach(selector => selector.apply(node, stack)); // TODO move the logic in here?
  18798. }
  18799. isUsed(dev) {
  18800. if (this.parent && this.parent.node.type === 'Atrule' && isKeyframesNode(this.parent.node))
  18801. return true;
  18802. if (this.declarations.length === 0)
  18803. return dev;
  18804. return this.selectors.some(s => s.used);
  18805. }
  18806. minify(code, dev) {
  18807. let c = this.node.start;
  18808. let started = false;
  18809. this.selectors.forEach((selector, i) => {
  18810. if (selector.used) {
  18811. const separator = started ? ',' : '';
  18812. if ((selector.node.start - c) > separator.length) {
  18813. code.overwrite(c, selector.node.start, separator);
  18814. }
  18815. selector.minify(code);
  18816. c = selector.node.end;
  18817. started = true;
  18818. }
  18819. });
  18820. code.remove(c, this.node.block.start);
  18821. c = this.node.block.start + 1;
  18822. this.declarations.forEach((declaration, i) => {
  18823. const separator = i > 0 ? ';' : '';
  18824. if ((declaration.node.start - c) > separator.length) {
  18825. code.overwrite(c, declaration.node.start, separator);
  18826. }
  18827. declaration.minify(code);
  18828. c = declaration.node.end;
  18829. });
  18830. code.remove(c, this.node.block.end - 1);
  18831. }
  18832. transform(code, id, keyframes) {
  18833. if (this.parent && this.parent.node.type === 'Atrule' && isKeyframesNode(this.parent.node))
  18834. return true;
  18835. const attr = `.${id}`;
  18836. this.selectors.forEach(selector => selector.transform(code, attr));
  18837. this.declarations.forEach(declaration => declaration.transform(code, keyframes));
  18838. }
  18839. validate(component) {
  18840. this.selectors.forEach(selector => {
  18841. selector.validate(component);
  18842. });
  18843. }
  18844. warnOnUnusedSelector(handler) {
  18845. this.selectors.forEach(selector => {
  18846. if (!selector.used)
  18847. handler(selector);
  18848. });
  18849. }
  18850. }
  18851. class Declaration$1 {
  18852. constructor(node) {
  18853. this.node = node;
  18854. }
  18855. transform(code, keyframes) {
  18856. const property = this.node.property && removeCSSPrefix(this.node.property.toLowerCase());
  18857. if (property === 'animation' || property === 'animation-name') {
  18858. this.node.value.children.forEach((block) => {
  18859. if (block.type === 'Identifier') {
  18860. const name = block.name;
  18861. if (keyframes.has(name)) {
  18862. code.overwrite(block.start, block.end, keyframes.get(name));
  18863. }
  18864. }
  18865. });
  18866. }
  18867. }
  18868. minify(code) {
  18869. if (!this.node.property)
  18870. return; // @apply, and possibly other weird cases?
  18871. const c = this.node.start + this.node.property.length;
  18872. const first = this.node.value.children ?
  18873. this.node.value.children[0] :
  18874. this.node.value;
  18875. let start = first.start;
  18876. while (/\s/.test(code.original[start]))
  18877. start += 1;
  18878. if (start - c > 1) {
  18879. code.overwrite(c, start, ':');
  18880. }
  18881. }
  18882. }
  18883. class Atrule$1 {
  18884. constructor(node) {
  18885. this.node = node;
  18886. this.children = [];
  18887. }
  18888. apply(node, stack) {
  18889. if (this.node.name === 'media' || this.node.name === 'supports') {
  18890. this.children.forEach(child => {
  18891. child.apply(node, stack);
  18892. });
  18893. }
  18894. else if (isKeyframesNode(this.node)) {
  18895. this.children.forEach((rule) => {
  18896. rule.selectors.forEach(selector => {
  18897. selector.used = true;
  18898. });
  18899. });
  18900. }
  18901. }
  18902. isUsed(dev) {
  18903. return true; // TODO
  18904. }
  18905. minify(code, dev) {
  18906. if (this.node.name === 'media') {
  18907. const expressionChar = code.original[this.node.expression.start];
  18908. let c = this.node.start + (expressionChar === '(' ? 6 : 7);
  18909. if (this.node.expression.start > c)
  18910. code.remove(c, this.node.expression.start);
  18911. this.node.expression.children.forEach((query) => {
  18912. // TODO minify queries
  18913. c = query.end;
  18914. });
  18915. code.remove(c, this.node.block.start);
  18916. }
  18917. else if (isKeyframesNode(this.node)) {
  18918. let c = this.node.start + this.node.name.length + 1;
  18919. if (this.node.expression.start - c > 1)
  18920. code.overwrite(c, this.node.expression.start, ' ');
  18921. c = this.node.expression.end;
  18922. if (this.node.block.start - c > 0)
  18923. code.remove(c, this.node.block.start);
  18924. }
  18925. else if (this.node.name === 'supports') {
  18926. let c = this.node.start + 9;
  18927. if (this.node.expression.start - c > 1)
  18928. code.overwrite(c, this.node.expression.start, ' ');
  18929. this.node.expression.children.forEach((query) => {
  18930. // TODO minify queries
  18931. c = query.end;
  18932. });
  18933. code.remove(c, this.node.block.start);
  18934. }
  18935. // TODO other atrules
  18936. if (this.node.block) {
  18937. let c = this.node.block.start + 1;
  18938. this.children.forEach(child => {
  18939. if (child.isUsed(dev)) {
  18940. code.remove(c, child.node.start);
  18941. child.minify(code, dev);
  18942. c = child.node.end;
  18943. }
  18944. });
  18945. code.remove(c, this.node.block.end - 1);
  18946. }
  18947. }
  18948. transform(code, id, keyframes) {
  18949. if (isKeyframesNode(this.node)) {
  18950. this.node.expression.children.forEach(({ type, name, start, end }) => {
  18951. if (type === 'Identifier') {
  18952. if (name.startsWith('-global-')) {
  18953. code.remove(start, start + 8);
  18954. }
  18955. else {
  18956. code.overwrite(start, end, keyframes.get(name));
  18957. }
  18958. }
  18959. });
  18960. }
  18961. this.children.forEach(child => {
  18962. child.transform(code, id, keyframes);
  18963. });
  18964. }
  18965. validate(component) {
  18966. this.children.forEach(child => {
  18967. child.validate(component);
  18968. });
  18969. }
  18970. warnOnUnusedSelector(handler) {
  18971. if (this.node.name !== 'media')
  18972. return;
  18973. this.children.forEach(child => {
  18974. child.warnOnUnusedSelector(handler);
  18975. });
  18976. }
  18977. }
  18978. class Stylesheet {
  18979. constructor(source, ast, filename, dev) {
  18980. this.source = source;
  18981. this.ast = ast;
  18982. this.filename = filename;
  18983. this.dev = dev;
  18984. this.children = [];
  18985. this.keyframes = new Map();
  18986. this.nodesWithCssClass = new Set();
  18987. this.nodesWithRefCssClass = new Map();
  18988. if (ast.css && ast.css.children.length) {
  18989. this.id = `svelte-${hash$1(ast.css.content.styles)}`;
  18990. this.hasStyles = true;
  18991. const stack = [];
  18992. let currentAtrule = null;
  18993. walk(this.ast.css, {
  18994. enter: (node) => {
  18995. if (node.type === 'Atrule') {
  18996. const last = stack[stack.length - 1];
  18997. const atrule = new Atrule$1(node);
  18998. stack.push(atrule);
  18999. // this is an awkward special case — @apply (and
  19000. // possibly other future constructs)
  19001. if (last && !(last instanceof Atrule$1))
  19002. return;
  19003. if (currentAtrule) {
  19004. currentAtrule.children.push(atrule);
  19005. }
  19006. else {
  19007. this.children.push(atrule);
  19008. }
  19009. if (isKeyframesNode(node)) {
  19010. node.expression.children.forEach((expression) => {
  19011. if (expression.type === 'Identifier' && !expression.name.startsWith('-global-')) {
  19012. this.keyframes.set(expression.name, `${this.id}-${expression.name}`);
  19013. }
  19014. });
  19015. }
  19016. currentAtrule = atrule;
  19017. }
  19018. if (node.type === 'Rule') {
  19019. const rule = new Rule$1(node, this, currentAtrule);
  19020. stack.push(rule);
  19021. if (currentAtrule) {
  19022. currentAtrule.children.push(rule);
  19023. }
  19024. else {
  19025. this.children.push(rule);
  19026. }
  19027. }
  19028. },
  19029. leave: (node) => {
  19030. if (node.type === 'Rule' || node.type === 'Atrule')
  19031. stack.pop();
  19032. if (node.type === 'Atrule')
  19033. currentAtrule = stack[stack.length - 1];
  19034. }
  19035. });
  19036. }
  19037. else {
  19038. this.hasStyles = false;
  19039. }
  19040. }
  19041. apply(node) {
  19042. if (!this.hasStyles)
  19043. return;
  19044. const stack = [];
  19045. let parent = node;
  19046. while (parent = parent.parent) {
  19047. if (parent.type === 'Element')
  19048. stack.unshift(parent);
  19049. }
  19050. for (let i = 0; i < this.children.length; i += 1) {
  19051. const child = this.children[i];
  19052. child.apply(node, stack);
  19053. }
  19054. }
  19055. reify() {
  19056. this.nodesWithCssClass.forEach((node) => {
  19057. node.addCssClass();
  19058. });
  19059. this.nodesWithRefCssClass.forEach((node, name) => {
  19060. node.addCssClass(`svelte-ref-${name}`);
  19061. });
  19062. }
  19063. render(cssOutputFilename, shouldTransformSelectors) {
  19064. if (!this.hasStyles) {
  19065. return { code: null, map: null };
  19066. }
  19067. const code = new MagicString(this.source);
  19068. walk(this.ast.css, {
  19069. enter: (node) => {
  19070. code.addSourcemapLocation(node.start);
  19071. code.addSourcemapLocation(node.end);
  19072. }
  19073. });
  19074. if (shouldTransformSelectors) {
  19075. this.children.forEach((child) => {
  19076. child.transform(code, this.id, this.keyframes);
  19077. });
  19078. }
  19079. let c = 0;
  19080. this.children.forEach(child => {
  19081. if (child.isUsed(this.dev)) {
  19082. code.remove(c, child.node.start);
  19083. child.minify(code, this.dev);
  19084. c = child.node.end;
  19085. }
  19086. });
  19087. code.remove(c, this.source.length);
  19088. return {
  19089. code: code.toString(),
  19090. map: code.generateMap({
  19091. includeContent: true,
  19092. source: this.filename,
  19093. file: cssOutputFilename
  19094. })
  19095. };
  19096. }
  19097. validate(component) {
  19098. this.children.forEach(child => {
  19099. child.validate(component);
  19100. });
  19101. }
  19102. warnOnUnusedSelectors(onwarn) {
  19103. let locator;
  19104. const handler = (selector) => {
  19105. const pos = selector.node.start;
  19106. if (!locator)
  19107. locator = getLocator(this.source, { offsetLine: 1 });
  19108. const start = locator(pos);
  19109. const end = locator(selector.node.end);
  19110. const frame = getCodeFrame(this.source, start.line - 1, start.column);
  19111. const message = `Unused CSS selector`;
  19112. onwarn({
  19113. code: `css-unused-selector`,
  19114. message,
  19115. frame,
  19116. start,
  19117. end,
  19118. pos,
  19119. filename: this.filename,
  19120. toString: () => `${message} (${start.line}:${start.column})\n${frame}`,
  19121. });
  19122. };
  19123. this.children.forEach(child => {
  19124. child.warnOnUnusedSelector(handler);
  19125. });
  19126. }
  19127. }
  19128. const test = typeof process !== 'undefined' && process.env.TEST;
  19129. class Node$1 {
  19130. constructor(component, parent, scope, info) {
  19131. this.start = info.start;
  19132. this.end = info.end;
  19133. this.type = info.type;
  19134. // this makes properties non-enumerable, which makes logging
  19135. // bearable. might have a performance cost. TODO remove in prod?
  19136. Object.defineProperties(this, {
  19137. component: {
  19138. value: component
  19139. },
  19140. parent: {
  19141. value: parent
  19142. }
  19143. });
  19144. }
  19145. cannotUseInnerHTML() {
  19146. if (this.canUseInnerHTML !== false) {
  19147. this.canUseInnerHTML = false;
  19148. if (this.parent)
  19149. this.parent.cannotUseInnerHTML();
  19150. }
  19151. }
  19152. hasAncestor(type) {
  19153. return this.parent ?
  19154. this.parent.type === type || this.parent.hasAncestor(type) :
  19155. false;
  19156. }
  19157. findNearest(selector) {
  19158. if (selector.test(this.type))
  19159. return this;
  19160. if (this.parent)
  19161. return this.parent.findNearest(selector);
  19162. }
  19163. remount(name) {
  19164. return `${this.var}.m(${name}._slotted.default, null);`;
  19165. }
  19166. warnIfEmptyBlock() {
  19167. if (!this.component.options.dev)
  19168. return;
  19169. if (!/Block$/.test(this.type) || !this.children)
  19170. return;
  19171. if (this.children.length > 1)
  19172. return;
  19173. const child = this.children[0];
  19174. if (!child || (child.type === 'Text' && !/[^ \r\n\f\v\t]/.test(child.data))) {
  19175. this.component.warn(this, {
  19176. code: 'empty-block',
  19177. message: 'Empty block'
  19178. });
  19179. }
  19180. }
  19181. }
  19182. class PendingBlock extends Node$1 {
  19183. constructor(component, parent, scope, info) {
  19184. super(component, parent, scope, info);
  19185. this.children = mapChildren(component, parent, scope, info.children);
  19186. this.warnIfEmptyBlock();
  19187. }
  19188. }
  19189. class ThenBlock extends Node$1 {
  19190. constructor(component, parent, scope, info) {
  19191. super(component, parent, scope, info);
  19192. this.children = mapChildren(component, parent, scope, info.children);
  19193. this.warnIfEmptyBlock();
  19194. }
  19195. }
  19196. class CatchBlock extends Node$1 {
  19197. constructor(component, parent, scope, info) {
  19198. super(component, parent, scope, info);
  19199. this.children = mapChildren(component, parent, scope, info.children);
  19200. this.warnIfEmptyBlock();
  19201. }
  19202. }
  19203. const binaryOperators = {
  19204. '**': 15,
  19205. '*': 14,
  19206. '/': 14,
  19207. '%': 14,
  19208. '+': 13,
  19209. '-': 13,
  19210. '<<': 12,
  19211. '>>': 12,
  19212. '>>>': 12,
  19213. '<': 11,
  19214. '<=': 11,
  19215. '>': 11,
  19216. '>=': 11,
  19217. 'in': 11,
  19218. 'instanceof': 11,
  19219. '==': 10,
  19220. '!=': 10,
  19221. '===': 10,
  19222. '!==': 10,
  19223. '&': 9,
  19224. '^': 8,
  19225. '|': 7
  19226. };
  19227. const logicalOperators = {
  19228. '&&': 6,
  19229. '||': 5
  19230. };
  19231. const precedence = {
  19232. Literal: () => 21,
  19233. Identifier: () => 21,
  19234. ParenthesizedExpression: () => 20,
  19235. MemberExpression: () => 19,
  19236. NewExpression: () => 19,
  19237. CallExpression: () => 19,
  19238. UpdateExpression: () => 17,
  19239. UnaryExpression: () => 16,
  19240. BinaryExpression: (node) => binaryOperators[node.operator],
  19241. LogicalExpression: (node) => logicalOperators[node.operator],
  19242. ConditionalExpression: () => 4,
  19243. AssignmentExpression: () => 3,
  19244. YieldExpression: () => 2,
  19245. SpreadElement: () => 1,
  19246. SequenceExpression: () => 0
  19247. };
  19248. class Expression {
  19249. constructor(component, parent, scope, info) {
  19250. this.usesContext = false;
  19251. this.usesEvent = false;
  19252. // TODO revert to direct property access in prod?
  19253. Object.defineProperties(this, {
  19254. component: {
  19255. value: component
  19256. }
  19257. });
  19258. this.node = info;
  19259. this.thisReferences = [];
  19260. this.snippet = `[✂${info.start}-${info.end}✂]`;
  19261. const dependencies = new Set();
  19262. const { code, helpers } = component;
  19263. let { map, scope: currentScope } = createScopes(info);
  19264. const isEventHandler = parent.type === 'EventHandler';
  19265. const expression = this;
  19266. const isSynthetic = parent.isSynthetic;
  19267. walk(info, {
  19268. enter(node, parent, key) {
  19269. // don't manipulate shorthand props twice
  19270. if (key === 'value' && parent.shorthand)
  19271. return;
  19272. code.addSourcemapLocation(node.start);
  19273. code.addSourcemapLocation(node.end);
  19274. if (map.has(node)) {
  19275. currentScope = map.get(node);
  19276. return;
  19277. }
  19278. if (node.type === 'ThisExpression') {
  19279. expression.thisReferences.push(node);
  19280. }
  19281. if (isReference(node, parent)) {
  19282. const { name, nodes } = flattenReference(node);
  19283. if (name === 'event' && isEventHandler) {
  19284. expression.usesEvent = true;
  19285. return;
  19286. }
  19287. if (currentScope.has(name))
  19288. return;
  19289. if (component.helpers.has(name)) {
  19290. let object = node;
  19291. while (object.type === 'MemberExpression')
  19292. object = object.object;
  19293. component.used.helpers.add(name);
  19294. const alias = component.templateVars.get(`helpers-${name}`);
  19295. if (alias !== name)
  19296. code.overwrite(object.start, object.end, alias);
  19297. return;
  19298. }
  19299. expression.usesContext = true;
  19300. if (!isSynthetic) {
  19301. // <option> value attribute could be synthetic — avoid double editing
  19302. code.prependRight(node.start, key === 'key' && parent.shorthand
  19303. ? `${name}: ctx.`
  19304. : 'ctx.');
  19305. }
  19306. if (scope.names.has(name)) {
  19307. scope.dependenciesForName.get(name).forEach(dependency => {
  19308. dependencies.add(dependency);
  19309. });
  19310. }
  19311. else {
  19312. dependencies.add(name);
  19313. component.expectedProperties.add(name);
  19314. }
  19315. if (node.type === 'MemberExpression') {
  19316. nodes.forEach(node => {
  19317. code.addSourcemapLocation(node.start);
  19318. code.addSourcemapLocation(node.end);
  19319. });
  19320. }
  19321. this.skip();
  19322. }
  19323. },
  19324. leave(node, parent) {
  19325. if (map.has(node))
  19326. currentScope = currentScope.parent;
  19327. }
  19328. });
  19329. this.dependencies = dependencies;
  19330. }
  19331. getPrecedence() {
  19332. return this.node.type in precedence ? precedence[this.node.type](this.node) : 0;
  19333. }
  19334. overwriteThis(name) {
  19335. this.thisReferences.forEach(ref => {
  19336. this.component.code.overwrite(ref.start, ref.end, name, {
  19337. storeName: true
  19338. });
  19339. });
  19340. }
  19341. }
  19342. class AwaitBlock$1 extends Node$1 {
  19343. constructor(component, parent, scope, info) {
  19344. super(component, parent, scope, info);
  19345. this.expression = new Expression(component, this, scope, info.expression);
  19346. const deps = this.expression.dependencies;
  19347. this.value = info.value;
  19348. this.error = info.error;
  19349. this.pending = new PendingBlock(component, this, scope, info.pending);
  19350. this.then = new ThenBlock(component, this, scope.add(this.value, deps), info.then);
  19351. this.catch = new CatchBlock(component, this, scope.add(this.error, deps), info.catch);
  19352. }
  19353. }
  19354. class Comment$2 extends Node$1 {
  19355. constructor(component, parent, scope, info) {
  19356. super(component, parent, scope, info);
  19357. this.data = info.data;
  19358. }
  19359. }
  19360. const validCalleeObjects = new Set(['this', 'event', 'console']);
  19361. const validBuiltins = new Set(['set', 'fire', 'destroy']);
  19362. class EventHandler extends Node$1 {
  19363. constructor(component, parent, scope, info) {
  19364. super(component, parent, scope, info);
  19365. this.name = info.name;
  19366. this.modifiers = new Set(info.modifiers);
  19367. component.used.events.add(this.name);
  19368. this.dependencies = new Set();
  19369. if (info.expression) {
  19370. this.validateExpression(info.expression);
  19371. this.callee = flattenReference(info.expression.callee);
  19372. this.insertionPoint = info.expression.start;
  19373. this.usesComponent = !validCalleeObjects.has(this.callee.name);
  19374. this.usesContext = false;
  19375. this.usesEventObject = this.callee.name === 'event';
  19376. this.args = info.expression.arguments.map(param => {
  19377. const expression = new Expression(component, this, scope, param);
  19378. addToSet(this.dependencies, expression.dependencies);
  19379. if (expression.usesContext)
  19380. this.usesContext = true;
  19381. if (expression.usesEvent)
  19382. this.usesEventObject = true;
  19383. return expression;
  19384. });
  19385. this.snippet = `[✂${info.expression.start}-${info.expression.end}✂];`;
  19386. }
  19387. else {
  19388. this.callee = null;
  19389. this.insertionPoint = null;
  19390. this.args = null;
  19391. this.usesComponent = true;
  19392. this.usesContext = false;
  19393. this.usesEventObject = true;
  19394. this.snippet = null; // TODO handle shorthand events here?
  19395. }
  19396. this.isCustomEvent = component.events.has(this.name);
  19397. this.shouldHoist = !this.isCustomEvent && parent.hasAncestor('EachBlock');
  19398. }
  19399. render(component, block, context, hoisted) {
  19400. if (this.insertionPoint === null)
  19401. return; // TODO handle shorthand events here?
  19402. if (!validCalleeObjects.has(this.callee.name)) {
  19403. const component_name = hoisted ? `component` : block.alias(`component`);
  19404. // allow event.stopPropagation(), this.select() etc
  19405. // TODO verify that it's a valid callee (i.e. built-in or declared method)
  19406. if (this.callee.name[0] === '$' && !component.methods.has(this.callee.name)) {
  19407. component.code.overwrite(this.insertionPoint, this.insertionPoint + 1, `${component_name}.store.`);
  19408. }
  19409. else {
  19410. component.code.prependRight(this.insertionPoint, `${component_name}.`);
  19411. }
  19412. }
  19413. if (this.isCustomEvent) {
  19414. this.args.forEach(arg => {
  19415. arg.overwriteThis(context);
  19416. });
  19417. if (this.callee && this.callee.name === 'this') {
  19418. const node = this.callee.nodes[0];
  19419. component.code.overwrite(node.start, node.end, context, {
  19420. storeName: true,
  19421. contentOnly: true
  19422. });
  19423. }
  19424. }
  19425. }
  19426. validateExpression(expression) {
  19427. const { callee, type } = expression;
  19428. if (type !== 'CallExpression') {
  19429. this.component.error(expression, {
  19430. code: `invalid-event-handler`,
  19431. message: `Expected a call expression`
  19432. });
  19433. }
  19434. const { component } = this;
  19435. const { name } = flattenReference(callee);
  19436. if (validCalleeObjects.has(name) || name === 'options')
  19437. return;
  19438. if (name === 'refs') {
  19439. this.component.refCallees.push(callee);
  19440. return;
  19441. }
  19442. if ((callee.type === 'Identifier' && validBuiltins.has(name)) ||
  19443. this.component.methods.has(name)) {
  19444. return;
  19445. }
  19446. if (name[0] === '$') {
  19447. // assume it's a store method
  19448. return;
  19449. }
  19450. const validCallees = ['this.*', 'refs.*', 'event.*', 'options.*', 'console.*'].concat(Array.from(validBuiltins), Array.from(this.component.methods.keys()));
  19451. let message = `'${component.source.slice(callee.start, callee.end)}' is an invalid callee `;
  19452. if (name === 'store') {
  19453. message += `(did you mean '$${component.source.slice(callee.start + 6, callee.end)}(...)'?)`;
  19454. }
  19455. else {
  19456. message += `(should be one of ${list$1(validCallees)})`;
  19457. if (callee.type === 'Identifier' && component.helpers.has(callee.name)) {
  19458. message += `. '${callee.name}' exists on 'helpers', did you put it in the wrong place?`;
  19459. }
  19460. }
  19461. component.warn(expression, {
  19462. code: `invalid-callee`,
  19463. message
  19464. });
  19465. }
  19466. }
  19467. class Document extends Node$1 {
  19468. constructor(component, parent, scope, info) {
  19469. super(component, parent, scope, info);
  19470. this.handlers = [];
  19471. info.attributes.forEach(node => {
  19472. if (node.type === 'EventHandler') {
  19473. this.handlers.push(new EventHandler(component, this, scope, node));
  19474. }
  19475. });
  19476. }
  19477. }
  19478. class ElseBlock extends Node$1 {
  19479. constructor(component, parent, scope, info) {
  19480. super(component, parent, scope, info);
  19481. this.children = mapChildren(component, this, scope, info.children);
  19482. this.warnIfEmptyBlock();
  19483. }
  19484. }
  19485. function unpackDestructuring(contexts, node, tail) {
  19486. if (!node)
  19487. return;
  19488. if (node.type === 'Identifier') {
  19489. contexts.push({
  19490. key: node,
  19491. tail
  19492. });
  19493. }
  19494. else if (node.type === 'ArrayPattern') {
  19495. node.elements.forEach((element, i) => {
  19496. unpackDestructuring(contexts, element, `${tail}[${i}]`);
  19497. });
  19498. }
  19499. else if (node.type === 'ObjectPattern') {
  19500. node.properties.forEach((property) => {
  19501. unpackDestructuring(contexts, property.value, `${tail}.${property.key.name}`);
  19502. });
  19503. }
  19504. }
  19505. class EachBlock$1 extends Node$1 {
  19506. constructor(component, parent, scope, info) {
  19507. super(component, parent, scope, info);
  19508. this.expression = new Expression(component, this, scope, info.expression);
  19509. this.context = info.context.name || 'each'; // TODO this is used to facilitate binding; currently fails with destructuring
  19510. this.index = info.index;
  19511. this.scope = scope.child();
  19512. this.contexts = [];
  19513. unpackDestructuring(this.contexts, info.context, '');
  19514. this.contexts.forEach(context => {
  19515. if (component.helpers.has(context.key.name)) {
  19516. component.warn(context.key, {
  19517. code: `each-context-clash`,
  19518. message: `Context clashes with a helper. Rename one or the other to eliminate any ambiguity`
  19519. });
  19520. }
  19521. this.scope.add(context.key.name, this.expression.dependencies);
  19522. });
  19523. this.key = info.key
  19524. ? new Expression(component, this, this.scope, info.key)
  19525. : null;
  19526. if (this.index) {
  19527. // index can only change if this is a keyed each block
  19528. const dependencies = this.key ? this.expression.dependencies : [];
  19529. this.scope.add(this.index, dependencies);
  19530. }
  19531. this.hasAnimation = false;
  19532. this.children = mapChildren(component, this, this.scope, info.children);
  19533. if (this.hasAnimation) {
  19534. if (this.children.length !== 1) {
  19535. const child = this.children.find(child => !!child.animation);
  19536. component.error(child.animation, {
  19537. code: `invalid-animation`,
  19538. message: `An element that use the animate directive must be the sole child of a keyed each block`
  19539. });
  19540. }
  19541. }
  19542. this.warnIfEmptyBlock(); // TODO would be better if EachBlock, IfBlock etc extended an abstract Block class
  19543. this.else = info.else
  19544. ? new ElseBlock(component, this, this.scope, info.else)
  19545. : null;
  19546. }
  19547. }
  19548. class Attribute$1 extends Node$1 {
  19549. constructor(component, parent, scope, info) {
  19550. super(component, parent, scope, info);
  19551. if (info.type === 'Spread') {
  19552. this.name = null;
  19553. this.isSpread = true;
  19554. this.isTrue = false;
  19555. this.isSynthetic = false;
  19556. this.expression = new Expression(component, this, scope, info.expression);
  19557. this.dependencies = this.expression.dependencies;
  19558. this.chunks = null;
  19559. this.isDynamic = true; // TODO not necessarily
  19560. this.shouldCache = false; // TODO does this mean anything here?
  19561. }
  19562. else {
  19563. this.name = info.name;
  19564. this.isTrue = info.value === true;
  19565. this.isSynthetic = info.synthetic;
  19566. this.dependencies = new Set();
  19567. this.chunks = this.isTrue
  19568. ? []
  19569. : info.value.map(node => {
  19570. if (node.type === 'Text')
  19571. return node;
  19572. const expression = new Expression(component, this, scope, node.expression);
  19573. addToSet(this.dependencies, expression.dependencies);
  19574. return expression;
  19575. });
  19576. this.isDynamic = this.dependencies.size > 0;
  19577. this.shouldCache = this.isDynamic
  19578. ? this.chunks.length === 1
  19579. ? this.chunks[0].node.type !== 'Identifier' || scope.names.has(this.chunks[0].node.name)
  19580. : true
  19581. : false;
  19582. }
  19583. }
  19584. getValue() {
  19585. if (this.isTrue)
  19586. return true;
  19587. if (this.chunks.length === 0)
  19588. return `""`;
  19589. if (this.chunks.length === 1) {
  19590. return this.chunks[0].type === 'Text'
  19591. ? stringify(this.chunks[0].data)
  19592. : this.chunks[0].snippet;
  19593. }
  19594. return (this.chunks[0].type === 'Text' ? '' : `"" + `) +
  19595. this.chunks
  19596. .map(chunk => {
  19597. if (chunk.type === 'Text') {
  19598. return stringify(chunk.data);
  19599. }
  19600. else {
  19601. return chunk.getPrecedence() <= 13 ? `(${chunk.snippet})` : chunk.snippet;
  19602. }
  19603. })
  19604. .join(' + ');
  19605. }
  19606. getStaticValue() {
  19607. if (this.isSpread || this.isDynamic)
  19608. return null;
  19609. return this.isTrue
  19610. ? true
  19611. : this.chunks[0]
  19612. ? this.chunks[0].data
  19613. : '';
  19614. }
  19615. }
  19616. class Binding extends Node$1 {
  19617. constructor(component, parent, scope, info) {
  19618. super(component, parent, scope, info);
  19619. this.name = info.name;
  19620. this.value = new Expression(component, this, scope, info.value);
  19621. let obj;
  19622. let prop;
  19623. const { name } = getObject(this.value.node);
  19624. this.isContextual = scope.names.has(name);
  19625. if (this.value.node.type === 'MemberExpression') {
  19626. prop = `[✂${this.value.node.property.start}-${this.value.node.property.end}✂]`;
  19627. if (!this.value.node.computed)
  19628. prop = `'${prop}'`;
  19629. obj = `[✂${this.value.node.object.start}-${this.value.node.object.end}✂]`;
  19630. this.usesContext = true;
  19631. }
  19632. else {
  19633. obj = 'ctx';
  19634. prop = `'${name}'`;
  19635. this.usesContext = scope.names.has(name);
  19636. }
  19637. this.obj = obj;
  19638. this.prop = prop;
  19639. }
  19640. }
  19641. class Transition extends Node$1 {
  19642. constructor(component, parent, scope, info) {
  19643. super(component, parent, scope, info);
  19644. if (!component.transitions.has(info.name)) {
  19645. component.error(info, {
  19646. code: `missing-transition`,
  19647. message: `Missing transition '${info.name}'`
  19648. });
  19649. }
  19650. this.name = info.name;
  19651. this.directive = info.intro && info.outro ? 'transition' : info.intro ? 'in' : 'out';
  19652. if ((info.intro && parent.intro) || (info.outro && parent.outro)) {
  19653. const parentTransition = (parent.intro || parent.outro);
  19654. const message = this.directive === parentTransition.directive
  19655. ? `An element can only have one '${this.directive}' directive`
  19656. : `An element cannot have both ${describe(parentTransition)} directive and ${describe(this)} directive`;
  19657. component.error(info, {
  19658. code: `duplicate-transition`,
  19659. message
  19660. });
  19661. }
  19662. this.component.used.transitions.add(this.name);
  19663. this.expression = info.expression
  19664. ? new Expression(component, this, scope, info.expression)
  19665. : null;
  19666. }
  19667. }
  19668. function describe(transition) {
  19669. return transition.directive === 'transition'
  19670. ? `a 'transition'`
  19671. : `an '${transition.directive}'`;
  19672. }
  19673. class Animation extends Node$1 {
  19674. constructor(component, parent, scope, info) {
  19675. super(component, parent, scope, info);
  19676. this.name = info.name;
  19677. component.used.animations.add(this.name);
  19678. if (parent.animation) {
  19679. component.error(this, {
  19680. code: `duplicate-animation`,
  19681. message: `An element can only have one 'animate' directive`
  19682. });
  19683. }
  19684. if (!component.animations.has(this.name)) {
  19685. component.error(this, {
  19686. code: `missing-animation`,
  19687. message: `Missing animation '${this.name}'`
  19688. });
  19689. }
  19690. const block = parent.parent;
  19691. if (!block || block.type !== 'EachBlock' || !block.key) {
  19692. // TODO can we relax the 'immediate child' rule?
  19693. component.error(this, {
  19694. code: `invalid-animation`,
  19695. message: `An element that use the animate directive must be the immediate child of a keyed each block`
  19696. });
  19697. }
  19698. block.hasAnimation = true;
  19699. this.expression = info.expression
  19700. ? new Expression(component, this, scope, info.expression)
  19701. : null;
  19702. }
  19703. }
  19704. class Action extends Node$1 {
  19705. constructor(component, parent, scope, info) {
  19706. super(component, parent, scope, info);
  19707. this.name = info.name;
  19708. component.used.actions.add(this.name);
  19709. if (!component.actions.has(this.name)) {
  19710. component.error(this, {
  19711. code: `missing-action`,
  19712. message: `Missing action '${this.name}'`
  19713. });
  19714. }
  19715. this.expression = info.expression
  19716. ? new Expression(component, this, scope, info.expression)
  19717. : null;
  19718. }
  19719. }
  19720. class Class extends Node$1 {
  19721. constructor(component, parent, scope, info) {
  19722. super(component, parent, scope, info);
  19723. this.name = info.name;
  19724. this.expression = info.expression
  19725. ? new Expression(component, this, scope, info.expression)
  19726. : null;
  19727. }
  19728. }
  19729. class Text$2 extends Node$1 {
  19730. constructor(component, parent, scope, info) {
  19731. super(component, parent, scope, info);
  19732. this.data = info.data;
  19733. }
  19734. }
  19735. // adapted from https://github.com/Glench/fuzzyset.js/blob/master/lib/fuzzyset.js
  19736. // BSD Licensed
  19737. const GRAM_SIZE_LOWER = 2;
  19738. const GRAM_SIZE_UPPER = 3;
  19739. // return an edit distance from 0 to 1
  19740. function _distance(str1, str2) {
  19741. if (str1 === null && str2 === null)
  19742. throw 'Trying to compare two null values';
  19743. if (str1 === null || str2 === null)
  19744. return 0;
  19745. str1 = String(str1);
  19746. str2 = String(str2);
  19747. const distance = levenshtein(str1, str2);
  19748. if (str1.length > str2.length) {
  19749. return 1 - distance / str1.length;
  19750. }
  19751. else {
  19752. return 1 - distance / str2.length;
  19753. }
  19754. }
  19755. // helper functions
  19756. function levenshtein(str1, str2) {
  19757. const current = [];
  19758. let prev;
  19759. let value;
  19760. for (let i = 0; i <= str2.length; i++) {
  19761. for (let j = 0; j <= str1.length; j++) {
  19762. if (i && j) {
  19763. if (str1.charAt(j - 1) === str2.charAt(i - 1)) {
  19764. value = prev;
  19765. }
  19766. else {
  19767. value = Math.min(current[j], current[j - 1], prev) + 1;
  19768. }
  19769. }
  19770. else {
  19771. value = i + j;
  19772. }
  19773. prev = current[j];
  19774. current[j] = value;
  19775. }
  19776. }
  19777. return current.pop();
  19778. }
  19779. const _nonWordRe = /[^\w, ]+/;
  19780. function _iterateGrams(value, gramSize) {
  19781. gramSize = gramSize || 2;
  19782. const simplified = '-' + value.toLowerCase().replace(_nonWordRe, '') + '-';
  19783. const lenDiff = gramSize - simplified.length;
  19784. const results = [];
  19785. if (lenDiff > 0) {
  19786. for (let i = 0; i < lenDiff; ++i) {
  19787. value += '-';
  19788. }
  19789. }
  19790. for (let i = 0; i < simplified.length - gramSize + 1; ++i) {
  19791. results.push(simplified.slice(i, i + gramSize));
  19792. }
  19793. return results;
  19794. }
  19795. function _gramCounter(value, gramSize) {
  19796. // return an object where key=gram, value=number of occurrences
  19797. gramSize = gramSize || 2;
  19798. const result = {};
  19799. const grams = _iterateGrams(value, gramSize);
  19800. let i = 0;
  19801. for (i; i < grams.length; ++i) {
  19802. if (grams[i] in result) {
  19803. result[grams[i]] += 1;
  19804. }
  19805. else {
  19806. result[grams[i]] = 1;
  19807. }
  19808. }
  19809. return result;
  19810. }
  19811. function sortDescending(a, b) {
  19812. return b[0] - a[0];
  19813. }
  19814. class FuzzySet {
  19815. constructor(arr) {
  19816. // define all the object functions and attributes
  19817. this.exactSet = {};
  19818. this.matchDict = {};
  19819. this.items = {};
  19820. // initialization
  19821. for (let i = GRAM_SIZE_LOWER; i < GRAM_SIZE_UPPER + 1; ++i) {
  19822. this.items[i] = [];
  19823. }
  19824. // add all the items to the set
  19825. for (let i = 0; i < arr.length; ++i) {
  19826. this.add(arr[i]);
  19827. }
  19828. }
  19829. add(value) {
  19830. const normalizedValue = value.toLowerCase();
  19831. if (normalizedValue in this.exactSet) {
  19832. return false;
  19833. }
  19834. let i = GRAM_SIZE_LOWER;
  19835. for (i; i < GRAM_SIZE_UPPER + 1; ++i) {
  19836. this._add(value, i);
  19837. }
  19838. }
  19839. _add(value, gramSize) {
  19840. const normalizedValue = value.toLowerCase();
  19841. const items = this.items[gramSize] || [];
  19842. const index = items.length;
  19843. items.push(0);
  19844. const gramCounts = _gramCounter(normalizedValue, gramSize);
  19845. let sumOfSquareGramCounts = 0;
  19846. let gram;
  19847. let gramCount;
  19848. for (gram in gramCounts) {
  19849. gramCount = gramCounts[gram];
  19850. sumOfSquareGramCounts += Math.pow(gramCount, 2);
  19851. if (gram in this.matchDict) {
  19852. this.matchDict[gram].push([index, gramCount]);
  19853. }
  19854. else {
  19855. this.matchDict[gram] = [[index, gramCount]];
  19856. }
  19857. }
  19858. const vectorNormal = Math.sqrt(sumOfSquareGramCounts);
  19859. items[index] = [vectorNormal, normalizedValue];
  19860. this.items[gramSize] = items;
  19861. this.exactSet[normalizedValue] = value;
  19862. }
  19863. ;
  19864. get(value) {
  19865. const normalizedValue = value.toLowerCase();
  19866. const result = this.exactSet[normalizedValue];
  19867. if (result) {
  19868. return [[1, result]];
  19869. }
  19870. let results = [];
  19871. // start with high gram size and if there are no results, go to lower gram sizes
  19872. for (let gramSize = GRAM_SIZE_UPPER; gramSize >= GRAM_SIZE_LOWER; --gramSize) {
  19873. results = this.__get(value, gramSize);
  19874. if (results) {
  19875. return results;
  19876. }
  19877. }
  19878. return null;
  19879. }
  19880. __get(value, gramSize) {
  19881. const normalizedValue = value.toLowerCase();
  19882. const matches = {};
  19883. const gramCounts = _gramCounter(normalizedValue, gramSize);
  19884. const items = this.items[gramSize];
  19885. let sumOfSquareGramCounts = 0;
  19886. let gram;
  19887. let gramCount;
  19888. let i;
  19889. let index;
  19890. let otherGramCount;
  19891. for (gram in gramCounts) {
  19892. gramCount = gramCounts[gram];
  19893. sumOfSquareGramCounts += Math.pow(gramCount, 2);
  19894. if (gram in this.matchDict) {
  19895. for (i = 0; i < this.matchDict[gram].length; ++i) {
  19896. index = this.matchDict[gram][i][0];
  19897. otherGramCount = this.matchDict[gram][i][1];
  19898. if (index in matches) {
  19899. matches[index] += gramCount * otherGramCount;
  19900. }
  19901. else {
  19902. matches[index] = gramCount * otherGramCount;
  19903. }
  19904. }
  19905. }
  19906. }
  19907. const vectorNormal = Math.sqrt(sumOfSquareGramCounts);
  19908. let results = [];
  19909. let matchScore;
  19910. // build a results list of [score, str]
  19911. for (const matchIndex in matches) {
  19912. matchScore = matches[matchIndex];
  19913. results.push([
  19914. matchScore / (vectorNormal * items[matchIndex][0]),
  19915. items[matchIndex][1],
  19916. ]);
  19917. }
  19918. results.sort(sortDescending);
  19919. let newResults = [];
  19920. const endIndex = Math.min(50, results.length);
  19921. // truncate somewhat arbitrarily to 50
  19922. for (let i = 0; i < endIndex; ++i) {
  19923. newResults.push([
  19924. _distance(results[i][1], normalizedValue),
  19925. results[i][1],
  19926. ]);
  19927. }
  19928. results = newResults;
  19929. results.sort(sortDescending);
  19930. newResults = [];
  19931. for (let i = 0; i < results.length; ++i) {
  19932. if (results[i][0] == results[0][0]) {
  19933. newResults.push([results[i][0], this.exactSet[results[i][1]]]);
  19934. }
  19935. }
  19936. return newResults;
  19937. }
  19938. ;
  19939. }
  19940. function fuzzymatch(name, names) {
  19941. const set = new FuzzySet(names);
  19942. const matches = set.get(name);
  19943. return matches && matches[0] && matches[0][0] > 0.7 ? matches[0][1] : null;
  19944. }
  19945. class Ref extends Node$1 {
  19946. constructor(component, parent, scope, info) {
  19947. super(component, parent, scope, info);
  19948. if (parent.ref) {
  19949. component.error({
  19950. code: 'duplicate-refs',
  19951. message: `Duplicate refs`
  19952. });
  19953. }
  19954. if (!isValidIdentifier(info.name)) {
  19955. const suggestion = info.name.replace(/[^_$a-z0-9]/ig, '_').replace(/^\d/, '_$&');
  19956. component.error(info, {
  19957. code: `invalid-reference-name`,
  19958. message: `Reference name '${info.name}' is invalid — must be a valid identifier such as ${suggestion}`
  19959. });
  19960. }
  19961. else {
  19962. component.refs.add(info.name);
  19963. }
  19964. this.name = info.name;
  19965. }
  19966. }
  19967. const svg$1 = /^(?:altGlyph|altGlyphDef|altGlyphItem|animate|animateColor|animateMotion|animateTransform|circle|clipPath|color-profile|cursor|defs|desc|discard|ellipse|feBlend|feColorMatrix|feComponentTransfer|feComposite|feConvolveMatrix|feDiffuseLighting|feDisplacementMap|feDistantLight|feDropShadow|feFlood|feFuncA|feFuncB|feFuncG|feFuncR|feGaussianBlur|feImage|feMerge|feMergeNode|feMorphology|feOffset|fePointLight|feSpecularLighting|feSpotLight|feTile|feTurbulence|filter|font|font-face|font-face-format|font-face-name|font-face-src|font-face-uri|foreignObject|g|glyph|glyphRef|hatch|hatchpath|hkern|image|line|linearGradient|marker|mask|mesh|meshgradient|meshpatch|meshrow|metadata|missing-glyph|mpath|path|pattern|polygon|polyline|radialGradient|rect|set|solidcolor|stop|switch|symbol|text|textPath|tref|tspan|unknown|use|view|vkern)$/;
  19968. const ariaAttributes = 'activedescendant atomic autocomplete busy checked controls current describedby details disabled dropeffect errormessage expanded flowto grabbed haspopup hidden invalid keyshortcuts label labelledby level live modal multiline multiselectable orientation owns placeholder posinset pressed readonly relevant required roledescription selected setsize sort valuemax valuemin valuenow valuetext'.split(' ');
  19969. const ariaAttributeSet = new Set(ariaAttributes);
  19970. const ariaRoles = 'alert alertdialog application article banner button cell checkbox columnheader combobox command complementary composite contentinfo definition dialog directory document feed figure form grid gridcell group heading img input landmark link list listbox listitem log main marquee math menu menubar menuitem menuitemcheckbox menuitemradio navigation none note option presentation progressbar radio radiogroup range region roletype row rowgroup rowheader scrollbar search searchbox section sectionhead select separator slider spinbutton status structure switch tab table tablist tabpanel term textbox timer toolbar tooltip tree treegrid treeitem widget window'.split(' ');
  19971. const ariaRoleSet = new Set(ariaRoles);
  19972. const a11yRequiredAttributes = {
  19973. a: ['href'],
  19974. area: ['alt', 'aria-label', 'aria-labelledby'],
  19975. // html-has-lang
  19976. html: ['lang'],
  19977. // iframe-has-title
  19978. iframe: ['title'],
  19979. img: ['alt'],
  19980. object: ['title', 'aria-label', 'aria-labelledby']
  19981. };
  19982. const a11yDistractingElements = new Set([
  19983. 'blink',
  19984. 'marquee'
  19985. ]);
  19986. const a11yRequiredContent = new Set([
  19987. // anchor-has-content
  19988. 'a',
  19989. // heading-has-content
  19990. 'h1',
  19991. 'h2',
  19992. 'h3',
  19993. 'h4',
  19994. 'h5',
  19995. 'h6'
  19996. ]);
  19997. const invisibleElements = new Set(['meta', 'html', 'script', 'style']);
  19998. const validModifiers = new Set([
  19999. 'preventDefault',
  20000. 'stopPropagation',
  20001. 'capture',
  20002. 'once',
  20003. 'passive'
  20004. ]);
  20005. const passiveEvents = new Set([
  20006. 'wheel',
  20007. 'touchstart',
  20008. 'touchmove',
  20009. 'touchend',
  20010. 'touchcancel'
  20011. ]);
  20012. class Element$1 extends Node$1 {
  20013. constructor(component, parent, scope, info) {
  20014. super(component, parent, scope, info);
  20015. this.name = info.name;
  20016. this.scope = scope;
  20017. const parentElement = parent.findNearest(/^Element/);
  20018. this.namespace = this.name === 'svg' ?
  20019. svg :
  20020. parentElement ? parentElement.namespace : this.component.namespace;
  20021. if (!this.namespace && svg$1.test(this.name)) {
  20022. this.component.warn(this, {
  20023. code: `missing-namespace`,
  20024. message: `<${this.name}> is an SVG element – did you forget to add { namespace: 'svg' } ?`
  20025. });
  20026. }
  20027. this.attributes = [];
  20028. this.actions = [];
  20029. this.bindings = [];
  20030. this.classes = [];
  20031. this.handlers = [];
  20032. this.intro = null;
  20033. this.outro = null;
  20034. this.animation = null;
  20035. if (this.name === 'textarea') {
  20036. if (info.children.length > 0) {
  20037. const valueAttribute = info.attributes.find(node => node.name === 'value');
  20038. if (valueAttribute) {
  20039. component.error(valueAttribute, {
  20040. code: `textarea-duplicate-value`,
  20041. message: `A <textarea> can have either a value attribute or (equivalently) child content, but not both`
  20042. });
  20043. }
  20044. // this is an egregious hack, but it's the easiest way to get <textarea>
  20045. // children treated the same way as a value attribute
  20046. info.attributes.push({
  20047. type: 'Attribute',
  20048. name: 'value',
  20049. value: info.children
  20050. });
  20051. info.children = [];
  20052. }
  20053. }
  20054. if (this.name === 'option') {
  20055. // Special case — treat these the same way:
  20056. // <option>{foo}</option>
  20057. // <option value={foo}>{foo}</option>
  20058. const valueAttribute = info.attributes.find((attribute) => attribute.name === 'value');
  20059. if (!valueAttribute) {
  20060. info.attributes.push({
  20061. type: 'Attribute',
  20062. name: 'value',
  20063. value: info.children,
  20064. synthetic: true
  20065. });
  20066. }
  20067. }
  20068. info.attributes.forEach(node => {
  20069. switch (node.type) {
  20070. case 'Action':
  20071. this.actions.push(new Action(component, this, scope, node));
  20072. break;
  20073. case 'Attribute':
  20074. case 'Spread':
  20075. // special case
  20076. if (node.name === 'xmlns')
  20077. this.namespace = node.value[0].data;
  20078. this.attributes.push(new Attribute$1(component, this, scope, node));
  20079. break;
  20080. case 'Binding':
  20081. this.bindings.push(new Binding(component, this, scope, node));
  20082. break;
  20083. case 'Class':
  20084. this.classes.push(new Class(component, this, scope, node));
  20085. break;
  20086. case 'EventHandler':
  20087. this.handlers.push(new EventHandler(component, this, scope, node));
  20088. break;
  20089. case 'Transition':
  20090. const transition = new Transition(component, this, scope, node);
  20091. if (node.intro)
  20092. this.intro = transition;
  20093. if (node.outro)
  20094. this.outro = transition;
  20095. break;
  20096. case 'Animation':
  20097. this.animation = new Animation(component, this, scope, node);
  20098. break;
  20099. case 'Ref':
  20100. this.ref = new Ref(component, this, scope, node);
  20101. break;
  20102. default:
  20103. throw new Error(`Not implemented: ${node.type}`);
  20104. }
  20105. });
  20106. this.children = mapChildren(component, this, scope, info.children);
  20107. this.validate();
  20108. component.stylesheet.apply(this);
  20109. }
  20110. validate() {
  20111. if (a11yDistractingElements.has(this.name)) {
  20112. // no-distracting-elements
  20113. this.component.warn(this, {
  20114. code: `a11y-distracting-elements`,
  20115. message: `A11y: Avoid <${this.name}> elements`
  20116. });
  20117. }
  20118. if (this.name === 'figcaption') {
  20119. if (this.parent.name !== 'figure') {
  20120. this.component.warn(this, {
  20121. code: `a11y-structure`,
  20122. message: `A11y: <figcaption> must be an immediate child of <figure>`
  20123. });
  20124. }
  20125. }
  20126. if (this.name === 'figure') {
  20127. const children = this.children.filter(node => {
  20128. if (node.type === 'Comment')
  20129. return false;
  20130. if (node.type === 'Text')
  20131. return /\S/.test(node.data);
  20132. return true;
  20133. });
  20134. const index = children.findIndex(child => child.name === 'figcaption');
  20135. if (index !== -1 && (index !== 0 && index !== children.length - 1)) {
  20136. this.component.warn(children[index], {
  20137. code: `a11y-structure`,
  20138. message: `A11y: <figcaption> must be first or last child of <figure>`
  20139. });
  20140. }
  20141. }
  20142. this.validateAttributes();
  20143. this.validateBindings();
  20144. this.validateContent();
  20145. this.validateEventHandlers();
  20146. }
  20147. validateAttributes() {
  20148. const { component } = this;
  20149. const attributeMap = new Map();
  20150. this.attributes.forEach(attribute => {
  20151. if (attribute.isSpread)
  20152. return;
  20153. const name = attribute.name.toLowerCase();
  20154. // aria-props
  20155. if (name.startsWith('aria-')) {
  20156. if (invisibleElements.has(this.name)) {
  20157. // aria-unsupported-elements
  20158. component.warn(attribute, {
  20159. code: `a11y-aria-attributes`,
  20160. message: `A11y: <${this.name}> should not have aria-* attributes`
  20161. });
  20162. }
  20163. const type = name.slice(5);
  20164. if (!ariaAttributeSet.has(type)) {
  20165. const match = fuzzymatch(type, ariaAttributes);
  20166. let message = `A11y: Unknown aria attribute 'aria-${type}'`;
  20167. if (match)
  20168. message += ` (did you mean '${match}'?)`;
  20169. component.warn(attribute, {
  20170. code: `a11y-unknown-aria-attribute`,
  20171. message
  20172. });
  20173. }
  20174. if (name === 'aria-hidden' && /^h[1-6]$/.test(this.name)) {
  20175. component.warn(attribute, {
  20176. code: `a11y-hidden`,
  20177. message: `A11y: <${this.name}> element should not be hidden`
  20178. });
  20179. }
  20180. }
  20181. // aria-role
  20182. if (name === 'role') {
  20183. if (invisibleElements.has(this.name)) {
  20184. // aria-unsupported-elements
  20185. component.warn(attribute, {
  20186. code: `a11y-misplaced-role`,
  20187. message: `A11y: <${this.name}> should not have role attribute`
  20188. });
  20189. }
  20190. const value = attribute.getStaticValue();
  20191. if (value && !ariaRoleSet.has(value)) {
  20192. const match = fuzzymatch(value, ariaRoles);
  20193. let message = `A11y: Unknown role '${value}'`;
  20194. if (match)
  20195. message += ` (did you mean '${match}'?)`;
  20196. component.warn(attribute, {
  20197. code: `a11y-unknown-role`,
  20198. message
  20199. });
  20200. }
  20201. }
  20202. // no-access-key
  20203. if (name === 'accesskey') {
  20204. component.warn(attribute, {
  20205. code: `a11y-accesskey`,
  20206. message: `A11y: Avoid using accesskey`
  20207. });
  20208. }
  20209. // no-autofocus
  20210. if (name === 'autofocus') {
  20211. component.warn(attribute, {
  20212. code: `a11y-autofocus`,
  20213. message: `A11y: Avoid using autofocus`
  20214. });
  20215. }
  20216. // scope
  20217. if (name === 'scope' && this.name !== 'th') {
  20218. component.warn(attribute, {
  20219. code: `a11y-misplaced-scope`,
  20220. message: `A11y: The scope attribute should only be used with <th> elements`
  20221. });
  20222. }
  20223. // tabindex-no-positive
  20224. if (name === 'tabindex') {
  20225. const value = attribute.getStaticValue();
  20226. if (!isNaN(value) && +value > 0) {
  20227. component.warn(attribute, {
  20228. code: `a11y-positive-tabindex`,
  20229. message: `A11y: avoid tabindex values above zero`
  20230. });
  20231. }
  20232. }
  20233. if (name === 'slot') {
  20234. if (attribute.isDynamic) {
  20235. component.error(attribute, {
  20236. code: `invalid-slot-attribute`,
  20237. message: `slot attribute cannot have a dynamic value`
  20238. });
  20239. }
  20240. let ancestor = this.parent;
  20241. do {
  20242. if (ancestor.type === 'InlineComponent')
  20243. break;
  20244. if (ancestor.type === 'Element' && /-/.test(ancestor.name))
  20245. break;
  20246. if (ancestor.type === 'IfBlock' || ancestor.type === 'EachBlock') {
  20247. const type = ancestor.type === 'IfBlock' ? 'if' : 'each';
  20248. const message = `Cannot place slotted elements inside an ${type}-block`;
  20249. component.error(attribute, {
  20250. code: `invalid-slotted-content`,
  20251. message
  20252. });
  20253. }
  20254. } while (ancestor = ancestor.parent);
  20255. if (!ancestor) {
  20256. component.error(attribute, {
  20257. code: `invalid-slotted-content`,
  20258. message: `Element with a slot='...' attribute must be a descendant of a component or custom element`
  20259. });
  20260. }
  20261. }
  20262. attributeMap.set(attribute.name, attribute);
  20263. });
  20264. // handle special cases
  20265. if (this.name === 'a') {
  20266. const attribute = attributeMap.get('href') || attributeMap.get('xlink:href');
  20267. if (attribute) {
  20268. const value = attribute.getStaticValue();
  20269. if (value === '' || value === '#') {
  20270. component.warn(attribute, {
  20271. code: `a11y-invalid-attribute`,
  20272. message: `A11y: '${value}' is not a valid ${attribute.name} attribute`
  20273. });
  20274. }
  20275. }
  20276. else {
  20277. component.warn(this, {
  20278. code: `a11y-missing-attribute`,
  20279. message: `A11y: <a> element should have an href attribute`
  20280. });
  20281. }
  20282. }
  20283. else {
  20284. const requiredAttributes = a11yRequiredAttributes[this.name];
  20285. if (requiredAttributes) {
  20286. const hasAttribute = requiredAttributes.some(name => attributeMap.has(name));
  20287. if (!hasAttribute) {
  20288. shouldHaveAttribute(this, requiredAttributes);
  20289. }
  20290. }
  20291. if (this.name === 'input') {
  20292. const type = attributeMap.get('type');
  20293. if (type && type.getStaticValue() === 'image') {
  20294. shouldHaveAttribute(this, ['alt', 'aria-label', 'aria-labelledby'], 'input type="image"');
  20295. }
  20296. }
  20297. }
  20298. }
  20299. validateBindings() {
  20300. const { component } = this;
  20301. const checkTypeAttribute = () => {
  20302. const attribute = this.attributes.find((attribute) => attribute.name === 'type');
  20303. if (!attribute)
  20304. return null;
  20305. if (attribute.isDynamic) {
  20306. component.error(attribute, {
  20307. code: `invalid-type`,
  20308. message: `'type' attribute cannot be dynamic if input uses two-way binding`
  20309. });
  20310. }
  20311. const value = attribute.getStaticValue();
  20312. if (value === true) {
  20313. component.error(attribute, {
  20314. code: `missing-type`,
  20315. message: `'type' attribute must be specified`
  20316. });
  20317. }
  20318. return value;
  20319. };
  20320. this.bindings.forEach(binding => {
  20321. const { name } = binding;
  20322. if (name === 'value') {
  20323. if (this.name !== 'input' &&
  20324. this.name !== 'textarea' &&
  20325. this.name !== 'select') {
  20326. component.error(binding, {
  20327. code: `invalid-binding`,
  20328. message: `'value' is not a valid binding on <${this.name}> elements`
  20329. });
  20330. }
  20331. if (this.name === 'select') {
  20332. const attribute = this.attributes.find((attribute) => attribute.name === 'multiple');
  20333. if (attribute && attribute.isDynamic) {
  20334. component.error(attribute, {
  20335. code: `dynamic-multiple-attribute`,
  20336. message: `'multiple' attribute cannot be dynamic if select uses two-way binding`
  20337. });
  20338. }
  20339. }
  20340. else {
  20341. checkTypeAttribute();
  20342. }
  20343. }
  20344. else if (name === 'checked' || name === 'indeterminate') {
  20345. if (this.name !== 'input') {
  20346. component.error(binding, {
  20347. code: `invalid-binding`,
  20348. message: `'${name}' is not a valid binding on <${this.name}> elements`
  20349. });
  20350. }
  20351. if (checkTypeAttribute() !== 'checkbox') {
  20352. component.error(binding, {
  20353. code: `invalid-binding`,
  20354. message: `'${name}' binding can only be used with <input type="checkbox">`
  20355. });
  20356. }
  20357. }
  20358. else if (name === 'group') {
  20359. if (this.name !== 'input') {
  20360. component.error(binding, {
  20361. code: `invalid-binding`,
  20362. message: `'group' is not a valid binding on <${this.name}> elements`
  20363. });
  20364. }
  20365. const type = checkTypeAttribute();
  20366. if (type !== 'checkbox' && type !== 'radio') {
  20367. component.error(binding, {
  20368. code: `invalid-binding`,
  20369. message: `'checked' binding can only be used with <input type="checkbox"> or <input type="radio">`
  20370. });
  20371. }
  20372. }
  20373. else if (name == 'files') {
  20374. if (this.name !== 'input') {
  20375. component.error(binding, {
  20376. code: `invalid-binding`,
  20377. message: `'files' binding acn only be used with <input type="file">`
  20378. });
  20379. }
  20380. const type = checkTypeAttribute();
  20381. if (type !== 'file') {
  20382. component.error(binding, {
  20383. code: `invalid-binding`,
  20384. message: `'files' binding can only be used with <input type="file">`
  20385. });
  20386. }
  20387. }
  20388. else if (name === 'currentTime' ||
  20389. name === 'duration' ||
  20390. name === 'paused' ||
  20391. name === 'buffered' ||
  20392. name === 'seekable' ||
  20393. name === 'played' ||
  20394. name === 'volume') {
  20395. if (this.name !== 'audio' && this.name !== 'video') {
  20396. component.error(binding, {
  20397. code: `invalid-binding`,
  20398. message: `'${name}' binding can only be used with <audio> or <video>`
  20399. });
  20400. }
  20401. }
  20402. else if (dimensions.test(name)) {
  20403. if (this.name === 'svg' && (name === 'offsetWidth' || name === 'offsetHeight')) {
  20404. component.error(binding, {
  20405. code: 'invalid-binding',
  20406. message: `'${binding.name}' is not a valid binding on <svg>. Use '${name.replace('offset', 'client')}' instead`
  20407. });
  20408. }
  20409. else if (svg$1.test(this.name)) {
  20410. component.error(binding, {
  20411. code: 'invalid-binding',
  20412. message: `'${binding.name}' is not a valid binding on SVG elements`
  20413. });
  20414. }
  20415. else if (isVoidElementName(this.name)) {
  20416. component.error(binding, {
  20417. code: 'invalid-binding',
  20418. message: `'${binding.name}' is not a valid binding on void elements like <${this.name}>. Use a wrapper element instead`
  20419. });
  20420. }
  20421. }
  20422. else {
  20423. component.error(binding, {
  20424. code: `invalid-binding`,
  20425. message: `'${binding.name}' is not a valid binding`
  20426. });
  20427. }
  20428. });
  20429. }
  20430. validateContent() {
  20431. if (!a11yRequiredContent.has(this.name))
  20432. return;
  20433. if (this.children.length === 0) {
  20434. this.component.warn(this, {
  20435. code: `a11y-missing-content`,
  20436. message: `A11y: <${this.name}> element should have child content`
  20437. });
  20438. }
  20439. }
  20440. validateEventHandlers() {
  20441. const { component } = this;
  20442. this.handlers.forEach(handler => {
  20443. if (handler.modifiers.has('passive') && handler.modifiers.has('preventDefault')) {
  20444. component.error(handler, {
  20445. code: 'invalid-event-modifier',
  20446. message: `The 'passive' and 'preventDefault' modifiers cannot be used together`
  20447. });
  20448. }
  20449. handler.modifiers.forEach(modifier => {
  20450. if (!validModifiers.has(modifier)) {
  20451. component.error(handler, {
  20452. code: 'invalid-event-modifier',
  20453. message: `Valid event modifiers are ${list$1([...validModifiers])}`
  20454. });
  20455. }
  20456. if (modifier === 'passive') {
  20457. if (passiveEvents.has(handler.name)) {
  20458. if (!handler.usesEventObject) {
  20459. component.warn(handler, {
  20460. code: 'redundant-event-modifier',
  20461. message: `Touch event handlers that don't use the 'event' object are passive by default`
  20462. });
  20463. }
  20464. }
  20465. else {
  20466. component.warn(handler, {
  20467. code: 'redundant-event-modifier',
  20468. message: `The passive modifier only works with wheel and touch events`
  20469. });
  20470. }
  20471. }
  20472. if (component.options.legacy && (modifier === 'once' || modifier === 'passive')) {
  20473. // TODO this could be supported, but it would need a few changes to
  20474. // how event listeners work
  20475. component.error(handler, {
  20476. code: 'invalid-event-modifier',
  20477. message: `The '${modifier}' modifier cannot be used in legacy mode`
  20478. });
  20479. }
  20480. });
  20481. if (passiveEvents.has(handler.name) && !handler.usesEventObject && !handler.modifiers.has('preventDefault')) {
  20482. // touch/wheel events should be passive by default
  20483. handler.modifiers.add('passive');
  20484. }
  20485. });
  20486. }
  20487. getStaticAttributeValue(name) {
  20488. const attribute = this.attributes.find((attr) => attr.type === 'Attribute' && attr.name.toLowerCase() === name);
  20489. if (!attribute)
  20490. return null;
  20491. if (attribute.isTrue)
  20492. return true;
  20493. if (attribute.chunks.length === 0)
  20494. return '';
  20495. if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
  20496. return attribute.chunks[0].data;
  20497. }
  20498. return null;
  20499. }
  20500. isMediaNode() {
  20501. return this.name === 'audio' || this.name === 'video';
  20502. }
  20503. remount(name) {
  20504. const slot = this.attributes.find(attribute => attribute.name === 'slot');
  20505. if (slot) {
  20506. const prop = quotePropIfNecessary(slot.chunks[0].data);
  20507. return `@append(${name}._slotted${prop}, ${this.var});`;
  20508. }
  20509. return `@append(${name}._slotted.default, ${this.var});`;
  20510. }
  20511. addCssClass(className = this.component.stylesheet.id) {
  20512. const classAttribute = this.attributes.find(a => a.name === 'class');
  20513. if (classAttribute && !classAttribute.isTrue) {
  20514. if (classAttribute.chunks.length === 1 && classAttribute.chunks[0].type === 'Text') {
  20515. classAttribute.chunks[0].data += ` ${className}`;
  20516. }
  20517. else {
  20518. classAttribute.chunks.push(new Text$2(this.component, this, this.scope, {
  20519. type: 'Text',
  20520. data: ` ${className}`
  20521. }));
  20522. }
  20523. }
  20524. else {
  20525. this.attributes.push(new Attribute$1(this.component, this, this.scope, {
  20526. type: 'Attribute',
  20527. name: 'class',
  20528. value: [{ type: 'Text', data: className }]
  20529. }));
  20530. }
  20531. }
  20532. }
  20533. function shouldHaveAttribute(node, attributes, name = node.name) {
  20534. const article = /^[aeiou]/.test(attributes[0]) ? 'an' : 'a';
  20535. const sequence = attributes.length > 1 ?
  20536. attributes.slice(0, -1).join(', ') + ` or ${attributes[attributes.length - 1]}` :
  20537. attributes[0];
  20538. node.component.warn(node, {
  20539. code: `a11y-missing-attribute`,
  20540. message: `A11y: <${name}> element should have ${article} ${sequence} attribute`
  20541. });
  20542. }
  20543. class Head$1 extends Node$1 {
  20544. constructor(component, parent, scope, info) {
  20545. super(component, parent, scope, info);
  20546. if (info.attributes.length) {
  20547. component.error(info.attributes[0], {
  20548. code: `invalid-attribute`,
  20549. message: `<svelte:head> should not have any attributes or directives`
  20550. });
  20551. }
  20552. this.children = mapChildren(component, parent, scope, info.children.filter(child => {
  20553. return (child.type !== 'Text' || /\S/.test(child.data));
  20554. }));
  20555. }
  20556. }
  20557. class IfBlock$1 extends Node$1 {
  20558. constructor(component, parent, scope, info) {
  20559. super(component, parent, scope, info);
  20560. this.expression = new Expression(component, this, scope, info.expression);
  20561. this.children = mapChildren(component, this, scope, info.children);
  20562. this.else = info.else
  20563. ? new ElseBlock(component, this, scope, info.else)
  20564. : null;
  20565. this.warnIfEmptyBlock();
  20566. }
  20567. }
  20568. class InlineComponent$1 extends Node$1 {
  20569. constructor(component, parent, scope, info) {
  20570. super(component, parent, scope, info);
  20571. component.hasComponents = true;
  20572. this.name = info.name;
  20573. if (this.name !== 'svelte:self' && this.name !== 'svelte:component') {
  20574. if (!component.components.has(this.name)) {
  20575. component.error(this, {
  20576. code: `missing-component`,
  20577. message: `${this.name} component is not defined`
  20578. });
  20579. }
  20580. component.used.components.add(this.name);
  20581. }
  20582. this.expression = this.name === 'svelte:component'
  20583. ? new Expression(component, this, scope, info.expression)
  20584. : null;
  20585. this.attributes = [];
  20586. this.bindings = [];
  20587. this.handlers = [];
  20588. info.attributes.forEach(node => {
  20589. switch (node.type) {
  20590. case 'Action':
  20591. component.error(node, {
  20592. code: `invalid-action`,
  20593. message: `Actions can only be applied to DOM elements, not components`
  20594. });
  20595. case 'Attribute':
  20596. case 'Spread':
  20597. this.attributes.push(new Attribute$1(component, this, scope, node));
  20598. break;
  20599. case 'Binding':
  20600. this.bindings.push(new Binding(component, this, scope, node));
  20601. break;
  20602. case 'Class':
  20603. component.error(node, {
  20604. code: `invalid-class`,
  20605. message: `Classes can only be applied to DOM elements, not components`
  20606. });
  20607. case 'EventHandler':
  20608. this.handlers.push(new EventHandler(component, this, scope, node));
  20609. break;
  20610. case 'Ref':
  20611. this.ref = new Ref(component, this, scope, node);
  20612. break;
  20613. case 'Transition':
  20614. component.error(node, {
  20615. code: `invalid-transition`,
  20616. message: `Transitions can only be applied to DOM elements, not components`
  20617. });
  20618. default:
  20619. throw new Error(`Not implemented: ${node.type}`);
  20620. }
  20621. });
  20622. this.children = mapChildren(component, this, scope, info.children);
  20623. }
  20624. }
  20625. class Tag$2 extends Node$1 {
  20626. constructor(component, parent, scope, info) {
  20627. super(component, parent, scope, info);
  20628. this.expression = new Expression(component, this, scope, info.expression);
  20629. this.shouldCache = (info.expression.type !== 'Identifier' ||
  20630. (this.expression.dependencies.size && scope.names.has(info.expression.name)));
  20631. }
  20632. }
  20633. class MustacheTag extends Tag$2 {
  20634. }
  20635. class RawMustacheTag extends Tag$2 {
  20636. }
  20637. class DebugTag$1 extends Node$1 {
  20638. constructor(component, parent, scope, info) {
  20639. super(component, parent, scope, info);
  20640. this.expressions = info.identifiers.map(node => {
  20641. return new Expression(component, parent, scope, node);
  20642. });
  20643. }
  20644. }
  20645. class Slot$1 extends Element$1 {
  20646. constructor(component, parent, scope, info) {
  20647. super(component, parent, scope, info);
  20648. info.attributes.forEach(attr => {
  20649. if (attr.type !== 'Attribute') {
  20650. component.error(attr, {
  20651. code: `invalid-slot-directive`,
  20652. message: `<slot> cannot have directives`
  20653. });
  20654. }
  20655. if (attr.name !== 'name') {
  20656. component.error(attr, {
  20657. code: `invalid-slot-attribute`,
  20658. message: `"name" is the only attribute permitted on <slot> elements`
  20659. });
  20660. }
  20661. if (attr.value.length !== 1 || attr.value[0].type !== 'Text') {
  20662. component.error(attr, {
  20663. code: `dynamic-slot-name`,
  20664. message: `<slot> name cannot be dynamic`
  20665. });
  20666. }
  20667. const slotName = attr.value[0].data;
  20668. if (slotName === 'default') {
  20669. component.error(attr, {
  20670. code: `invalid-slot-name`,
  20671. message: `default is a reserved word — it cannot be used as a slot name`
  20672. });
  20673. }
  20674. // TODO should duplicate slots be disallowed? Feels like it's more likely to be a
  20675. // bug than anything. Perhaps it should be a warning
  20676. // if (validator.slots.has(slotName)) {
  20677. // validator.error(`duplicate '${slotName}' <slot> element`, nameAttribute.start);
  20678. // }
  20679. // validator.slots.add(slotName);
  20680. });
  20681. // if (node.attributes.length === 0) && validator.slots.has('default')) {
  20682. // validator.error(node, {
  20683. // code: `duplicate-slot`,
  20684. // message: `duplicate default <slot> element`
  20685. // });
  20686. // }
  20687. }
  20688. getStaticAttributeValue(name) {
  20689. const attribute = this.attributes.find(attr => attr.name.toLowerCase() === name);
  20690. if (!attribute)
  20691. return null;
  20692. if (attribute.isTrue)
  20693. return true;
  20694. if (attribute.chunks.length === 0)
  20695. return '';
  20696. if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
  20697. return attribute.chunks[0].data;
  20698. }
  20699. return null;
  20700. }
  20701. }
  20702. class Title$1 extends Node$1 {
  20703. constructor(component, parent, scope, info) {
  20704. super(component, parent, scope, info);
  20705. this.children = mapChildren(component, parent, scope, info.children);
  20706. if (info.attributes.length > 0) {
  20707. component.error(info.attributes[0], {
  20708. code: `illegal-attribute`,
  20709. message: `<title> cannot have attributes`
  20710. });
  20711. }
  20712. info.children.forEach(child => {
  20713. if (child.type !== 'Text' && child.type !== 'MustacheTag') {
  20714. component.error(child, {
  20715. code: 'illegal-structure',
  20716. message: `<title> can only contain text and {tags}`
  20717. });
  20718. }
  20719. });
  20720. this.shouldCache = info.children.length === 1
  20721. ? (info.children[0].type !== 'Identifier' ||
  20722. scope.names.has(info.children[0].name))
  20723. : true;
  20724. }
  20725. }
  20726. const validBindings = [
  20727. 'innerWidth',
  20728. 'innerHeight',
  20729. 'outerWidth',
  20730. 'outerHeight',
  20731. 'scrollX',
  20732. 'scrollY',
  20733. 'online'
  20734. ];
  20735. class Window extends Node$1 {
  20736. constructor(component, parent, scope, info) {
  20737. super(component, parent, scope, info);
  20738. this.handlers = [];
  20739. this.bindings = [];
  20740. info.attributes.forEach(node => {
  20741. if (node.type === 'EventHandler') {
  20742. this.handlers.push(new EventHandler(component, this, scope, node));
  20743. }
  20744. else if (node.type === 'Binding') {
  20745. if (node.value.type !== 'Identifier') {
  20746. const { parts } = flattenReference(node.value);
  20747. component.error(node.value, {
  20748. code: `invalid-binding`,
  20749. message: `Bindings on <svelte:window> must be to top-level properties, e.g. '${parts[parts.length - 1]}' rather than '${parts.join('.')}'`
  20750. });
  20751. }
  20752. if (!~validBindings.indexOf(node.name)) {
  20753. const match = node.name === 'width'
  20754. ? 'innerWidth'
  20755. : node.name === 'height'
  20756. ? 'innerHeight'
  20757. : fuzzymatch(node.name, validBindings);
  20758. const message = `'${node.name}' is not a valid binding on <svelte:window>`;
  20759. if (match) {
  20760. component.error(node, {
  20761. code: `invalid-binding`,
  20762. message: `${message} (did you mean '${match}'?)`
  20763. });
  20764. }
  20765. else {
  20766. component.error(node, {
  20767. code: `invalid-binding`,
  20768. message: `${message} — valid bindings are ${list$1(validBindings)}`
  20769. });
  20770. }
  20771. }
  20772. this.bindings.push(new Binding(component, this, scope, node));
  20773. }
  20774. });
  20775. }
  20776. }
  20777. function getConstructor(type) {
  20778. switch (type) {
  20779. case 'AwaitBlock': return AwaitBlock$1;
  20780. case 'Comment': return Comment$2;
  20781. case 'Document': return Document;
  20782. case 'EachBlock': return EachBlock$1;
  20783. case 'Element': return Element$1;
  20784. case 'Head': return Head$1;
  20785. case 'IfBlock': return IfBlock$1;
  20786. case 'InlineComponent': return InlineComponent$1;
  20787. case 'MustacheTag': return MustacheTag;
  20788. case 'RawMustacheTag': return RawMustacheTag;
  20789. case 'DebugTag': return DebugTag$1;
  20790. case 'Slot': return Slot$1;
  20791. case 'Text': return Text$2;
  20792. case 'Title': return Title$1;
  20793. case 'Window': return Window;
  20794. default: throw new Error(`Not implemented: ${type}`);
  20795. }
  20796. }
  20797. function mapChildren(component, parent, scope, children) {
  20798. let last = null;
  20799. return children.map(child => {
  20800. const constructor = getConstructor(child.type);
  20801. const node = new constructor(component, parent, scope, child);
  20802. if (last)
  20803. last.next = node;
  20804. node.prev = last;
  20805. last = node;
  20806. return node;
  20807. });
  20808. }
  20809. class TemplateScope {
  20810. constructor(parent) {
  20811. this.names = new Set(parent ? parent.names : []);
  20812. this.dependenciesForName = new Map(parent ? parent.dependenciesForName : []);
  20813. }
  20814. add(name, dependencies) {
  20815. this.names.add(name);
  20816. this.dependenciesForName.set(name, dependencies);
  20817. return this;
  20818. }
  20819. child() {
  20820. return new TemplateScope(this);
  20821. }
  20822. }
  20823. class Fragment extends Node$1 {
  20824. constructor(component, info) {
  20825. const scope = new TemplateScope();
  20826. super(component, null, scope, info);
  20827. this.scope = scope;
  20828. this.children = mapChildren(component, this, scope, info.children);
  20829. }
  20830. }
  20831. // this file is auto-generated, do not edit it
  20832. const shared = {
  20833. "wrapAnimation": "function wrapAnimation(node, from, fn, params) {\n\tif (!from) return;\n\n\tconst to = node.getBoundingClientRect();\n\tif (from.left === to.left && from.right === to.right && from.top === to.top && from.bottom === to.bottom) return;\n\n\tconst info = fn(node, { from, to }, params);\n\n\tconst duration = 'duration' in info ? info.duration : 300;\n\tconst delay = 'delay' in info ? info.delay : 0;\n\tconst ease = info.easing || linear;\n\tconst start = window.performance.now() + delay;\n\tconst end = start + duration;\n\n\tconst program = {\n\t\ta: 0,\n\t\tt: 0,\n\t\tb: 1,\n\t\tdelta: 1,\n\t\tduration,\n\t\tstart,\n\t\tend\n\t};\n\n\tconst cssText = node.style.cssText;\n\n\tconst animation = {\n\t\tpending: delay ? program : null,\n\t\tprogram: delay ? null : program,\n\t\trunning: true,\n\n\t\tstart() {\n\t\t\tif (info.css) {\n\t\t\t\tif (delay) node.style.cssText = cssText;\n\n\t\t\t\tconst rule = generateRule(program, ease, info.css);\n\t\t\t\tprogram.name = `__svelte_${hash(rule)}`;\n\n\t\t\t\ttransitionManager.addRule(rule, program.name);\n\n\t\t\t\tnode.style.animation = (node.style.animation || '')\n\t\t\t\t\t.split(', ')\n\t\t\t\t\t.filter(anim => anim && (program.delta < 0 || !/__svelte/.test(anim)))\n\t\t\t\t\t.concat(`${program.name} ${program.duration}ms linear 1 forwards`)\n\t\t\t\t\t.join(', ');\n\t\t\t}\n\n\t\t\tanimation.program = program;\n\t\t\tanimation.pending = null;\n\t\t},\n\n\t\tupdate: now => {\n\t\t\tconst p = now - program.start;\n\t\t\tconst t = program.a + program.delta * ease(p / program.duration);\n\t\t\tif (info.tick) info.tick(t, 1 - t);\n\t\t},\n\n\t\tdone() {\n\t\t\tif (info.tick) info.tick(1, 0);\n\t\t\tanimation.stop();\n\t\t},\n\n\t\tstop() {\n\t\t\tif (info.css) transitionManager.deleteRule(node, program.name);\n\t\t\tanimation.running = false;\n\t\t}\n\t};\n\n\ttransitionManager.add(animation);\n\n\tif (info.tick) info.tick(0, 1);\n\n\tif (delay) {\n\t\tif (info.css) node.style.cssText += info.css(0, 1);\n\t} else {\n\t\tanimation.start();\n\t}\n\n\treturn animation;\n}",
  20834. "fixPosition": "function fixPosition(node) {\n\tconst style = getComputedStyle(node);\n\n\tif (style.position !== 'absolute' && style.position !== 'fixed') {\n\t\tconst { width, height } = style;\n\t\tconst a = node.getBoundingClientRect();\n\t\tnode.style.position = 'absolute';\n\t\tnode.style.width = width;\n\t\tnode.style.height = height;\n\t\tconst b = node.getBoundingClientRect();\n\n\t\tif (a.left !== b.left || a.top !== b.top) {\n\t\t\tconst style = getComputedStyle(node);\n\t\t\tconst transform = style.transform === 'none' ? '' : style.transform;\n\n\t\t\tnode.style.transform = `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`;\n\t\t}\n\t}\n}",
  20835. "handlePromise": "function handlePromise(promise, info) {\n\tvar token = info.token = {};\n\n\tfunction update(type, index, key, value) {\n\t\tif (info.token !== token) return;\n\n\t\tinfo.resolved = key && { [key]: value };\n\n\t\tconst child_ctx = assign(assign({}, info.ctx), info.resolved);\n\t\tconst block = type && (info.current = type)(info.component, child_ctx);\n\n\t\tif (info.block) {\n\t\t\tif (info.blocks) {\n\t\t\t\tinfo.blocks.forEach((block, i) => {\n\t\t\t\t\tif (i !== index && block) {\n\t\t\t\t\t\tgroupOutros();\n\t\t\t\t\t\tblock.o(() => {\n\t\t\t\t\t\t\tblock.d(1);\n\t\t\t\t\t\t\tinfo.blocks[i] = null;\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tinfo.block.d(1);\n\t\t\t}\n\n\t\t\tblock.c();\n\t\t\tblock[block.i ? 'i' : 'm'](info.mount(), info.anchor);\n\n\t\t\tinfo.component.root.set({}); // flush any handlers that were created\n\t\t}\n\n\t\tinfo.block = block;\n\t\tif (info.blocks) info.blocks[index] = block;\n\t}\n\n\tif (isPromise(promise)) {\n\t\tpromise.then(value => {\n\t\t\tupdate(info.then, 1, info.value, value);\n\t\t}, error => {\n\t\t\tupdate(info.catch, 2, info.error, error);\n\t\t});\n\n\t\t// if we previously had a then/catch block, destroy it\n\t\tif (info.current !== info.pending) {\n\t\t\tupdate(info.pending, 0);\n\t\t\treturn true;\n\t\t}\n\t} else {\n\t\tif (info.current !== info.then) {\n\t\t\tupdate(info.then, 1, info.value, promise);\n\t\t\treturn true;\n\t\t}\n\n\t\tinfo.resolved = { [info.value]: promise };\n\t}\n}",
  20836. "append": "function append(target, node) {\n\ttarget.appendChild(node);\n}",
  20837. "insert": "function insert(target, node, anchor) {\n\ttarget.insertBefore(node, anchor);\n}",
  20838. "detachNode": "function detachNode(node) {\n\tnode.parentNode.removeChild(node);\n}",
  20839. "detachBetween": "function detachBetween(before, after) {\n\twhile (before.nextSibling && before.nextSibling !== after) {\n\t\tbefore.parentNode.removeChild(before.nextSibling);\n\t}\n}",
  20840. "detachBefore": "function detachBefore(after) {\n\twhile (after.previousSibling) {\n\t\tafter.parentNode.removeChild(after.previousSibling);\n\t}\n}",
  20841. "detachAfter": "function detachAfter(before) {\n\twhile (before.nextSibling) {\n\t\tbefore.parentNode.removeChild(before.nextSibling);\n\t}\n}",
  20842. "reinsertBetween": "function reinsertBetween(before, after, target) {\n\twhile (before.nextSibling && before.nextSibling !== after) {\n\t\ttarget.appendChild(before.parentNode.removeChild(before.nextSibling));\n\t}\n}",
  20843. "reinsertChildren": "function reinsertChildren(parent, target) {\n\twhile (parent.firstChild) target.appendChild(parent.firstChild);\n}",
  20844. "reinsertAfter": "function reinsertAfter(before, target) {\n\twhile (before.nextSibling) target.appendChild(before.nextSibling);\n}",
  20845. "reinsertBefore": "function reinsertBefore(after, target) {\n\tvar parent = after.parentNode;\n\twhile (parent.firstChild !== after) target.appendChild(parent.firstChild);\n}",
  20846. "destroyEach": "function destroyEach(iterations, detach) {\n\tfor (var i = 0; i < iterations.length; i += 1) {\n\t\tif (iterations[i]) iterations[i].d(detach);\n\t}\n}",
  20847. "createFragment": "function createFragment() {\n\treturn document.createDocumentFragment();\n}",
  20848. "createElement": "function createElement(name) {\n\treturn document.createElement(name);\n}",
  20849. "createSvgElement": "function createSvgElement(name) {\n\treturn document.createElementNS('http://www.w3.org/2000/svg', name);\n}",
  20850. "createText": "function createText(data) {\n\treturn document.createTextNode(data);\n}",
  20851. "createComment": "function createComment() {\n\treturn document.createComment('');\n}",
  20852. "addListener": "function addListener(node, event, handler, options) {\n\tnode.addEventListener(event, handler, options);\n}",
  20853. "removeListener": "function removeListener(node, event, handler, options) {\n\tnode.removeEventListener(event, handler, options);\n}",
  20854. "setAttribute": "function setAttribute(node, attribute, value) {\n\tif (value == null) node.removeAttribute(attribute);\n\telse node.setAttribute(attribute, value);\n}",
  20855. "setAttributes": "function setAttributes(node, attributes) {\n\tfor (var key in attributes) {\n\t\tif (key === 'style') {\n\t\t\tnode.style.cssText = attributes[key];\n\t\t} else if (key in node) {\n\t\t\tnode[key] = attributes[key];\n\t\t} else {\n\t\t\tsetAttribute(node, key, attributes[key]);\n\t\t}\n\t}\n}",
  20856. "setCustomElementData": "function setCustomElementData(node, prop, value) {\n\tif (prop in node) {\n\t\tnode[prop] = value;\n\t} else if (value) {\n\t\tsetAttribute(node, prop, value);\n\t} else {\n\t\tnode.removeAttribute(prop);\n\t}\n}",
  20857. "setXlinkAttribute": "function setXlinkAttribute(node, attribute, value) {\n\tnode.setAttributeNS('http://www.w3.org/1999/xlink', attribute, value);\n}",
  20858. "getBindingGroupValue": "function getBindingGroupValue(group) {\n\tvar value = [];\n\tfor (var i = 0; i < group.length; i += 1) {\n\t\tif (group[i].checked) value.push(group[i].__value);\n\t}\n\treturn value;\n}",
  20859. "toNumber": "function toNumber(value) {\n\treturn value === '' ? undefined : +value;\n}",
  20860. "timeRangesToArray": "function timeRangesToArray(ranges) {\n\tvar array = [];\n\tfor (var i = 0; i < ranges.length; i += 1) {\n\t\tarray.push({ start: ranges.start(i), end: ranges.end(i) });\n\t}\n\treturn array;\n}",
  20861. "children": "function children (element) {\n\treturn Array.from(element.childNodes);\n}",
  20862. "claimElement": "function claimElement (nodes, name, attributes, svg) {\n\tfor (var i = 0; i < nodes.length; i += 1) {\n\t\tvar node = nodes[i];\n\t\tif (node.nodeName === name) {\n\t\t\tfor (var j = 0; j < node.attributes.length; j += 1) {\n\t\t\t\tvar attribute = node.attributes[j];\n\t\t\t\tif (!attributes[attribute.name]) node.removeAttribute(attribute.name);\n\t\t\t}\n\t\t\treturn nodes.splice(i, 1)[0]; // TODO strip unwanted attributes\n\t\t}\n\t}\n\n\treturn svg ? createSvgElement(name) : createElement(name);\n}",
  20863. "claimText": "function claimText (nodes, data) {\n\tfor (var i = 0; i < nodes.length; i += 1) {\n\t\tvar node = nodes[i];\n\t\tif (node.nodeType === 3) {\n\t\t\tnode.data = data;\n\t\t\treturn nodes.splice(i, 1)[0];\n\t\t}\n\t}\n\n\treturn createText(data);\n}",
  20864. "setData": "function setData(text, data) {\n\ttext.data = '' + data;\n}",
  20865. "setInputType": "function setInputType(input, type) {\n\ttry {\n\t\tinput.type = type;\n\t} catch (e) {}\n}",
  20866. "setStyle": "function setStyle(node, key, value) {\n\tnode.style.setProperty(key, value);\n}",
  20867. "selectOption": "function selectOption(select, value) {\n\tfor (var i = 0; i < select.options.length; i += 1) {\n\t\tvar option = select.options[i];\n\n\t\tif (option.__value === value) {\n\t\t\toption.selected = true;\n\t\t\treturn;\n\t\t}\n\t}\n}",
  20868. "selectOptions": "function selectOptions(select, value) {\n\tfor (var i = 0; i < select.options.length; i += 1) {\n\t\tvar option = select.options[i];\n\t\toption.selected = ~value.indexOf(option.__value);\n\t}\n}",
  20869. "selectValue": "function selectValue(select) {\n\tvar selectedOption = select.querySelector(':checked') || select.options[0];\n\treturn selectedOption && selectedOption.__value;\n}",
  20870. "selectMultipleValue": "function selectMultipleValue(select) {\n\treturn [].map.call(select.querySelectorAll(':checked'), function(option) {\n\t\treturn option.__value;\n\t});\n}",
  20871. "addResizeListener": "function addResizeListener(element, fn) {\n\tif (getComputedStyle(element).position === 'static') {\n\t\telement.style.position = 'relative';\n\t}\n\n\tconst object = document.createElement('object');\n\tobject.setAttribute('style', 'display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;');\n\tobject.type = 'text/html';\n\n\tlet win;\n\n\tobject.onload = () => {\n\t\twin = object.contentDocument.defaultView;\n\t\twin.addEventListener('resize', fn);\n\t};\n\n\tif (/Trident/.test(navigator.userAgent)) {\n\t\telement.appendChild(object);\n\t\tobject.data = 'about:blank';\n\t} else {\n\t\tobject.data = 'about:blank';\n\t\telement.appendChild(object);\n\t}\n\n\treturn {\n\t\tcancel: () => {\n\t\t\twin && win.removeEventListener && win.removeEventListener('resize', fn);\n\t\t\telement.removeChild(object);\n\t\t}\n\t};\n}",
  20872. "toggleClass": "function toggleClass(element, name, toggle) {\n\telement.classList.toggle(name, !!toggle);\n}",
  20873. "blankObject": "function blankObject() {\n\treturn Object.create(null);\n}",
  20874. "destroy": "function destroy(detach) {\n\tthis.destroy = noop;\n\tthis.fire('destroy');\n\tthis.set = noop;\n\n\tthis._fragment.d(detach !== false);\n\tthis._fragment = null;\n\tthis._state = {};\n}",
  20875. "destroyDev": "function destroyDev(detach) {\n\tdestroy.call(this, detach);\n\tthis.destroy = function() {\n\t\tconsole.warn('Component was already destroyed');\n\t};\n}",
  20876. "_differs": "function _differs(a, b) {\n\treturn a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');\n}",
  20877. "_differsImmutable": "function _differsImmutable(a, b) {\n\treturn a != a ? b == b : a !== b;\n}",
  20878. "fire": "function fire(eventName, data) {\n\tvar handlers =\n\t\teventName in this._handlers && this._handlers[eventName].slice();\n\tif (!handlers) return;\n\n\tfor (var i = 0; i < handlers.length; i += 1) {\n\t\tvar handler = handlers[i];\n\n\t\tif (!handler.__calling) {\n\t\t\ttry {\n\t\t\t\thandler.__calling = true;\n\t\t\t\thandler.call(this, data);\n\t\t\t} finally {\n\t\t\t\thandler.__calling = false;\n\t\t\t}\n\t\t}\n\t}\n}",
  20879. "flush": "function flush(component) {\n\tcomponent._lock = true;\n\tcallAll(component._beforecreate);\n\tcallAll(component._oncreate);\n\tcallAll(component._aftercreate);\n\tcomponent._lock = false;\n}",
  20880. "get": "function get() {\n\treturn this._state;\n}",
  20881. "init": "function init(component, options) {\n\tcomponent._handlers = blankObject();\n\tcomponent._slots = blankObject();\n\tcomponent._bind = options._bind;\n\tcomponent._staged = {};\n\n\tcomponent.options = options;\n\tcomponent.root = options.root || component;\n\tcomponent.store = options.store || component.root.store;\n\n\tif (!options.root) {\n\t\tcomponent._beforecreate = [];\n\t\tcomponent._oncreate = [];\n\t\tcomponent._aftercreate = [];\n\t}\n}",
  20882. "on": "function on(eventName, handler) {\n\tvar handlers = this._handlers[eventName] || (this._handlers[eventName] = []);\n\thandlers.push(handler);\n\n\treturn {\n\t\tcancel: function() {\n\t\t\tvar index = handlers.indexOf(handler);\n\t\t\tif (~index) handlers.splice(index, 1);\n\t\t}\n\t};\n}",
  20883. "set": "function set(newState) {\n\tthis._set(assign({}, newState));\n\tif (this.root._lock) return;\n\tflush(this.root);\n}",
  20884. "_set": "function _set(newState) {\n\tvar oldState = this._state,\n\t\tchanged = {},\n\t\tdirty = false;\n\n\tnewState = assign(this._staged, newState);\n\tthis._staged = {};\n\n\tfor (var key in newState) {\n\t\tif (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;\n\t}\n\tif (!dirty) return;\n\n\tthis._state = assign(assign({}, oldState), newState);\n\tthis._recompute(changed, this._state);\n\tif (this._bind) this._bind(changed, this._state);\n\n\tif (this._fragment) {\n\t\tthis.fire(\"state\", { changed: changed, current: this._state, previous: oldState });\n\t\tthis._fragment.p(changed, this._state);\n\t\tthis.fire(\"update\", { changed: changed, current: this._state, previous: oldState });\n\t}\n}",
  20885. "_stage": "function _stage(newState) {\n\tassign(this._staged, newState);\n}",
  20886. "setDev": "function setDev(newState) {\n\tif (typeof newState !== 'object') {\n\t\tthrow new Error(\n\t\t\tthis._debugName + '.set was called without an object of data key-values to update.'\n\t\t);\n\t}\n\n\tthis._checkReadOnly(newState);\n\tset.call(this, newState);\n}",
  20887. "callAll": "function callAll(fns) {\n\twhile (fns && fns.length) fns.shift()();\n}",
  20888. "_mount": "function _mount(target, anchor) {\n\tthis._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);\n}",
  20889. "PENDING": "{}",
  20890. "SUCCESS": "{}",
  20891. "FAILURE": "{}",
  20892. "removeFromStore": "function removeFromStore() {\n\tthis.store._remove(this);\n}",
  20893. "proto": "{\n\tdestroy,\n\tget,\n\tfire,\n\ton,\n\tset,\n\t_recompute: noop,\n\t_set,\n\t_stage,\n\t_mount,\n\t_differs\n}",
  20894. "protoDev": "{\n\tdestroy: destroyDev,\n\tget,\n\tfire,\n\ton,\n\tset: setDev,\n\t_recompute: noop,\n\t_set,\n\t_stage,\n\t_mount,\n\t_differs\n}",
  20895. "destroyBlock": "function destroyBlock(block, lookup) {\n\tblock.d(1);\n\tlookup[block.key] = null;\n}",
  20896. "outroAndDestroyBlock": "function outroAndDestroyBlock(block, lookup) {\n\tblock.o(function() {\n\t\tdestroyBlock(block, lookup);\n\t});\n}",
  20897. "fixAndOutroAndDestroyBlock": "function fixAndOutroAndDestroyBlock(block, lookup) {\n\tblock.f();\n\toutroAndDestroyBlock(block, lookup);\n}",
  20898. "updateKeyedEach": "function updateKeyedEach(old_blocks, component, changed, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, intro_method, next, get_context) {\n\tvar o = old_blocks.length;\n\tvar n = list.length;\n\n\tvar i = o;\n\tvar old_indexes = {};\n\twhile (i--) old_indexes[old_blocks[i].key] = i;\n\n\tvar new_blocks = [];\n\tvar new_lookup = {};\n\tvar deltas = {};\n\n\tvar i = n;\n\twhile (i--) {\n\t\tvar child_ctx = get_context(ctx, list, i);\n\t\tvar key = get_key(child_ctx);\n\t\tvar block = lookup[key];\n\n\t\tif (!block) {\n\t\t\tblock = create_each_block(component, key, child_ctx);\n\t\t\tblock.c();\n\t\t} else if (dynamic) {\n\t\t\tblock.p(changed, child_ctx);\n\t\t}\n\n\t\tnew_blocks[i] = new_lookup[key] = block;\n\n\t\tif (key in old_indexes) deltas[key] = Math.abs(i - old_indexes[key]);\n\t}\n\n\tvar will_move = {};\n\tvar did_move = {};\n\n\tfunction insert(block) {\n\t\tblock[intro_method](node, next);\n\t\tlookup[block.key] = block;\n\t\tnext = block.first;\n\t\tn--;\n\t}\n\n\twhile (o && n) {\n\t\tvar new_block = new_blocks[n - 1];\n\t\tvar old_block = old_blocks[o - 1];\n\t\tvar new_key = new_block.key;\n\t\tvar old_key = old_block.key;\n\n\t\tif (new_block === old_block) {\n\t\t\t// do nothing\n\t\t\tnext = new_block.first;\n\t\t\to--;\n\t\t\tn--;\n\t\t}\n\n\t\telse if (!new_lookup[old_key]) {\n\t\t\t// remove old block\n\t\t\tdestroy(old_block, lookup);\n\t\t\to--;\n\t\t}\n\n\t\telse if (!lookup[new_key] || will_move[new_key]) {\n\t\t\tinsert(new_block);\n\t\t}\n\n\t\telse if (did_move[old_key]) {\n\t\t\to--;\n\n\t\t} else if (deltas[new_key] > deltas[old_key]) {\n\t\t\tdid_move[new_key] = true;\n\t\t\tinsert(new_block);\n\n\t\t} else {\n\t\t\twill_move[old_key] = true;\n\t\t\to--;\n\t\t}\n\t}\n\n\twhile (o--) {\n\t\tvar old_block = old_blocks[o];\n\t\tif (!new_lookup[old_block.key]) destroy(old_block, lookup);\n\t}\n\n\twhile (n) insert(new_blocks[n - 1]);\n\n\treturn new_blocks;\n}",
  20899. "measure": "function measure(blocks) {\n\tconst rects = {};\n\tlet i = blocks.length;\n\twhile (i--) rects[blocks[i].key] = blocks[i].node.getBoundingClientRect();\n\treturn rects;\n}",
  20900. "animate": "function animate(blocks, rects, fn, params) {\n\tlet i = blocks.length;\n\twhile (i--) {\n\t\tconst block = blocks[i];\n\t\tconst from = rects[block.key];\n\n\t\tif (!from) continue;\n\t\tconst to = block.node.getBoundingClientRect();\n\n\t\tif (from.left === to.left && from.right === to.right && from.top === to.top && from.bottom === to.bottom) continue;\n\n\n\t}\n}",
  20901. "getSpreadUpdate": "function getSpreadUpdate(levels, updates) {\n\tvar update = {};\n\n\tvar to_null_out = {};\n\tvar accounted_for = {};\n\n\tvar i = levels.length;\n\twhile (i--) {\n\t\tvar o = levels[i];\n\t\tvar n = updates[i];\n\n\t\tif (n) {\n\t\t\tfor (var key in o) {\n\t\t\t\tif (!(key in n)) to_null_out[key] = 1;\n\t\t\t}\n\n\t\t\tfor (var key in n) {\n\t\t\t\tif (!accounted_for[key]) {\n\t\t\t\t\tupdate[key] = n[key];\n\t\t\t\t\taccounted_for[key] = 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlevels[i] = n;\n\t\t} else {\n\t\t\tfor (var key in o) {\n\t\t\t\taccounted_for[key] = 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (var key in to_null_out) {\n\t\tif (!(key in update)) update[key] = undefined;\n\t}\n\n\treturn update;\n}",
  20902. "invalidAttributeNameCharacter": "/[\\s'\">\\/=\\u{FDD0}-\\u{FDEF}\\u{FFFE}\\u{FFFF}\\u{1FFFE}\\u{1FFFF}\\u{2FFFE}\\u{2FFFF}\\u{3FFFE}\\u{3FFFF}\\u{4FFFE}\\u{4FFFF}\\u{5FFFE}\\u{5FFFF}\\u{6FFFE}\\u{6FFFF}\\u{7FFFE}\\u{7FFFF}\\u{8FFFE}\\u{8FFFF}\\u{9FFFE}\\u{9FFFF}\\u{AFFFE}\\u{AFFFF}\\u{BFFFE}\\u{BFFFF}\\u{CFFFE}\\u{CFFFF}\\u{DFFFE}\\u{DFFFF}\\u{EFFFE}\\u{EFFFF}\\u{FFFFE}\\u{FFFFF}\\u{10FFFE}\\u{10FFFF}]/u",
  20903. "spread": "function spread(args) {\n\tconst attributes = Object.assign({}, ...args);\n\tlet str = '';\n\n\tObject.keys(attributes).forEach(name => {\n\t\tif (invalidAttributeNameCharacter.test(name)) return;\n\n\t\tconst value = attributes[name];\n\t\tif (value === undefined) return;\n\t\tif (value === true) str += \" \" + name;\n\n\t\tconst escaped = String(value)\n\t\t\t.replace(/\"/g, '&#34;')\n\t\t\t.replace(/'/g, '&#39;');\n\n\t\tstr += \" \" + name + \"=\" + JSON.stringify(escaped);\n\t});\n\n\treturn str;\n}",
  20904. "escaped": "{\n\t'\"': '&quot;',\n\t\"'\": '&#39;',\n\t'&': '&amp;',\n\t'<': '&lt;',\n\t'>': '&gt;'\n}",
  20905. "escape": "function escape(html) {\n\treturn String(html).replace(/[\"'&<>]/g, match => escaped[match]);\n}",
  20906. "each": "function each(items, assign, fn) {\n\tlet str = '';\n\tfor (let i = 0; i < items.length; i += 1) {\n\t\tstr += fn(assign(items[i], i));\n\t}\n\treturn str;\n}",
  20907. "missingComponent": "{\n\t_render: () => ''\n}",
  20908. "validateSsrComponent": "function validateSsrComponent(component, name) {\n\tif (!component || !component._render) {\n\t\tif (name === 'svelte:component') name += ' this={...}';\n\t\tthrow new Error(`<${name}> is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules`);\n\t}\n\n\treturn component;\n}",
  20909. "debug": "function debug(file, line, column, values) {\n\tconsole.log(`{@debug} ${file ? file + ' ' : ''}(${line}:${column})`);\n\tconsole.log(values);\n\treturn '';\n}",
  20910. "linear": "function linear(t) {\n\treturn t;\n}",
  20911. "generateRule": "function generateRule({ a, b, delta, duration }, ease, fn) {\n\tconst step = 16.666 / duration;\n\tlet keyframes = '{\\n';\n\n\tfor (let p = 0; p <= 1; p += step) {\n\t\tconst t = a + delta * ease(p);\n\t\tkeyframes += p * 100 + `%{${fn(t, 1 - t)}}\\n`;\n\t}\n\n\treturn keyframes + `100% {${fn(b, 1 - b)}}\\n}`;\n}",
  20912. "hash": "function hash(str) {\n\tlet hash = 5381;\n\tlet i = str.length;\n\n\twhile (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i);\n\treturn hash >>> 0;\n}",
  20913. "wrapTransition": "function wrapTransition(component, node, fn, params, intro) {\n\tlet obj = fn.call(component, node, params);\n\tlet duration;\n\tlet ease;\n\tlet cssText;\n\n\tlet initialised = false;\n\n\treturn {\n\t\tt: intro ? 0 : 1,\n\t\trunning: false,\n\t\tprogram: null,\n\t\tpending: null,\n\n\t\trun(b, callback) {\n\t\t\tif (typeof obj === 'function') {\n\t\t\t\ttransitionManager.wait().then(() => {\n\t\t\t\t\tobj = obj();\n\t\t\t\t\tthis._run(b, callback);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis._run(b, callback);\n\t\t\t}\n\t\t},\n\n\t\t_run(b, callback) {\n\t\t\tduration = obj.duration || 300;\n\t\t\tease = obj.easing || linear;\n\n\t\t\tconst program = {\n\t\t\t\tstart: window.performance.now() + (obj.delay || 0),\n\t\t\t\tb,\n\t\t\t\tcallback: callback || noop\n\t\t\t};\n\n\t\t\tif (intro && !initialised) {\n\t\t\t\tif (obj.css && obj.delay) {\n\t\t\t\t\tcssText = node.style.cssText;\n\t\t\t\t\tnode.style.cssText += obj.css(0, 1);\n\t\t\t\t}\n\n\t\t\t\tif (obj.tick) obj.tick(0, 1);\n\t\t\t\tinitialised = true;\n\t\t\t}\n\n\t\t\tif (!b) {\n\t\t\t\tprogram.group = outros.current;\n\t\t\t\toutros.current.remaining += 1;\n\t\t\t}\n\n\t\t\tif (obj.delay) {\n\t\t\t\tthis.pending = program;\n\t\t\t} else {\n\t\t\t\tthis.start(program);\n\t\t\t}\n\n\t\t\tif (!this.running) {\n\t\t\t\tthis.running = true;\n\t\t\t\ttransitionManager.add(this);\n\t\t\t}\n\t\t},\n\n\t\tstart(program) {\n\t\t\tcomponent.fire(`${program.b ? 'intro' : 'outro'}.start`, { node });\n\n\t\t\tprogram.a = this.t;\n\t\t\tprogram.delta = program.b - program.a;\n\t\t\tprogram.duration = duration * Math.abs(program.b - program.a);\n\t\t\tprogram.end = program.start + program.duration;\n\n\t\t\tif (obj.css) {\n\t\t\t\tif (obj.delay) node.style.cssText = cssText;\n\n\t\t\t\tconst rule = generateRule(program, ease, obj.css);\n\t\t\t\ttransitionManager.addRule(rule, program.name = '__svelte_' + hash(rule));\n\n\t\t\t\tnode.style.animation = (node.style.animation || '')\n\t\t\t\t\t.split(', ')\n\t\t\t\t\t.filter(anim => anim && (program.delta < 0 || !/__svelte/.test(anim)))\n\t\t\t\t\t.concat(`${program.name} ${program.duration}ms linear 1 forwards`)\n\t\t\t\t\t.join(', ');\n\t\t\t}\n\n\t\t\tthis.program = program;\n\t\t\tthis.pending = null;\n\t\t},\n\n\t\tupdate(now) {\n\t\t\tconst program = this.program;\n\t\t\tif (!program) return;\n\n\t\t\tconst p = now - program.start;\n\t\t\tthis.t = program.a + program.delta * ease(p / program.duration);\n\t\t\tif (obj.tick) obj.tick(this.t, 1 - this.t);\n\t\t},\n\n\t\tdone() {\n\t\t\tconst program = this.program;\n\t\t\tthis.t = program.b;\n\n\t\t\tif (obj.tick) obj.tick(this.t, 1 - this.t);\n\n\t\t\tcomponent.fire(`${program.b ? 'intro' : 'outro'}.end`, { node });\n\n\t\t\tif (!program.b && !program.invalidated) {\n\t\t\t\tprogram.group.callbacks.push(() => {\n\t\t\t\t\tprogram.callback();\n\t\t\t\t\tif (obj.css) transitionManager.deleteRule(node, program.name);\n\t\t\t\t});\n\n\t\t\t\tif (--program.group.remaining === 0) {\n\t\t\t\t\tprogram.group.callbacks.forEach(run);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (obj.css) transitionManager.deleteRule(node, program.name);\n\t\t\t}\n\n\t\t\tthis.running = !!this.pending;\n\t\t},\n\n\t\tabort(reset) {\n\t\t\tif (this.program) {\n\t\t\t\tif (reset && obj.tick) obj.tick(1, 0);\n\t\t\t\tif (obj.css) transitionManager.deleteRule(node, this.program.name);\n\t\t\t\tthis.program = this.pending = null;\n\t\t\t\tthis.running = false;\n\t\t\t}\n\t\t},\n\n\t\tinvalidate() {\n\t\t\tif (this.program) {\n\t\t\t\tthis.program.invalidated = true;\n\t\t\t}\n\t\t}\n\t};\n}",
  20914. "outros": "{}",
  20915. "groupOutros": "function groupOutros() {\n\toutros.current = {\n\t\tremaining: 0,\n\t\tcallbacks: []\n\t};\n}",
  20916. "transitionManager": "{\n\trunning: false,\n\ttransitions: [],\n\tbound: null,\n\tstylesheet: null,\n\tactiveRules: {},\n\tpromise: null,\n\n\tadd(transition) {\n\t\tthis.transitions.push(transition);\n\n\t\tif (!this.running) {\n\t\t\tthis.running = true;\n\t\t\trequestAnimationFrame(this.bound || (this.bound = this.next.bind(this)));\n\t\t}\n\t},\n\n\taddRule(rule, name) {\n\t\tif (!this.stylesheet) {\n\t\t\tconst style = createElement('style');\n\t\t\tdocument.head.appendChild(style);\n\t\t\ttransitionManager.stylesheet = style.sheet;\n\t\t}\n\n\t\tif (!this.activeRules[name]) {\n\t\t\tthis.activeRules[name] = true;\n\t\t\tthis.stylesheet.insertRule(`@keyframes ${name} ${rule}`, this.stylesheet.cssRules.length);\n\t\t}\n\t},\n\n\tnext() {\n\t\tthis.running = false;\n\n\t\tconst now = window.performance.now();\n\t\tlet i = this.transitions.length;\n\n\t\twhile (i--) {\n\t\t\tconst transition = this.transitions[i];\n\n\t\t\tif (transition.program && now >= transition.program.end) {\n\t\t\t\ttransition.done();\n\t\t\t}\n\n\t\t\tif (transition.pending && now >= transition.pending.start) {\n\t\t\t\ttransition.start(transition.pending);\n\t\t\t}\n\n\t\t\tif (transition.running) {\n\t\t\t\ttransition.update(now);\n\t\t\t\tthis.running = true;\n\t\t\t} else if (!transition.pending) {\n\t\t\t\tthis.transitions.splice(i, 1);\n\t\t\t}\n\t\t}\n\n\t\tif (this.running) {\n\t\t\trequestAnimationFrame(this.bound);\n\t\t} else if (this.stylesheet) {\n\t\t\tlet i = this.stylesheet.cssRules.length;\n\t\t\twhile (i--) this.stylesheet.deleteRule(i);\n\t\t\tthis.activeRules = {};\n\t\t}\n\t},\n\n\tdeleteRule(node, name) {\n\t\tnode.style.animation = node.style.animation\n\t\t\t.split(', ')\n\t\t\t.filter(anim => anim && anim.indexOf(name) === -1)\n\t\t\t.join(', ');\n\t},\n\n\twait() {\n\t\tif (!transitionManager.promise) {\n\t\t\ttransitionManager.promise = Promise.resolve();\n\t\t\ttransitionManager.promise.then(() => {\n\t\t\t\ttransitionManager.promise = null;\n\t\t\t});\n\t\t}\n\n\t\treturn transitionManager.promise;\n\t}\n}",
  20917. "noop": "function noop() {}",
  20918. "assign": "function assign(tar, src) {\n\tfor (var k in src) tar[k] = src[k];\n\treturn tar;\n}",
  20919. "assignTrue": "function assignTrue(tar, src) {\n\tfor (var k in src) tar[k] = 1;\n\treturn tar;\n}",
  20920. "isPromise": "function isPromise(value) {\n\treturn value && typeof value.then === 'function';\n}",
  20921. "callAfter": "function callAfter(fn, i) {\n\tif (i === 0) fn();\n\treturn () => {\n\t\tif (!--i) fn();\n\t};\n}",
  20922. "addLoc": "function addLoc(element, file, line, column, char) {\n\telement.__svelte_meta = {\n\t\tloc: { file, line, column, char }\n\t};\n}",
  20923. "exclude": "function exclude(src, prop) {\n\tconst tar = {};\n\tfor (const k in src) k === prop || (tar[k] = src[k]);\n\treturn tar;\n}",
  20924. "run": "function run(fn) {\n\tfn();\n}"
  20925. };
  20926. function checkForComputedKeys(component, properties) {
  20927. properties.forEach(prop => {
  20928. if (prop.key.computed) {
  20929. component.error(prop, {
  20930. code: `computed-key`,
  20931. message: `Cannot use computed keys`
  20932. });
  20933. }
  20934. });
  20935. }
  20936. function checkForDupes(component, properties) {
  20937. const seen = new Set();
  20938. properties.forEach(prop => {
  20939. const name = getMethodName(prop.key);
  20940. if (seen.has(name)) {
  20941. component.error(prop, {
  20942. code: `duplicate-property`,
  20943. message: `Duplicate property '${name}'`
  20944. });
  20945. }
  20946. seen.add(name);
  20947. });
  20948. }
  20949. const disallowed = new Set(['Literal', 'ObjectExpression', 'ArrayExpression']);
  20950. function data$1(component, prop) {
  20951. while (prop.type === 'ParenthesizedExpression')
  20952. prop = prop.expression;
  20953. if (disallowed.has(prop.value.type)) {
  20954. component.error(prop.value, {
  20955. code: `invalid-data-property`,
  20956. message: `'data' must be a function`
  20957. });
  20958. }
  20959. }
  20960. function actions(component, prop) {
  20961. if (prop.value.type !== 'ObjectExpression') {
  20962. component.error(prop, {
  20963. code: `invalid-actions`,
  20964. message: `The 'actions' property must be an object literal`
  20965. });
  20966. }
  20967. checkForDupes(component, prop.value.properties);
  20968. checkForComputedKeys(component, prop.value.properties);
  20969. }
  20970. function transitions(component, prop) {
  20971. if (prop.value.type !== 'ObjectExpression') {
  20972. component.error(prop, {
  20973. code: `invalid-transitions-property`,
  20974. message: `The 'transitions' property must be an object literal`
  20975. });
  20976. }
  20977. checkForDupes(component, prop.value.properties);
  20978. checkForComputedKeys(component, prop.value.properties);
  20979. prop.value.properties.forEach(() => {
  20980. // TODO probably some validation that can happen here...
  20981. // checking for use of `this` etc?
  20982. });
  20983. }
  20984. function walkThroughTopFunctionScope(body, callback) {
  20985. let lexicalDepth = 0;
  20986. walk(body, {
  20987. enter(node) {
  20988. if (/^Function/.test(node.type)) {
  20989. lexicalDepth += 1;
  20990. }
  20991. else if (lexicalDepth === 0) {
  20992. callback(node);
  20993. }
  20994. },
  20995. leave(node) {
  20996. if (/^Function/.test(node.type)) {
  20997. lexicalDepth -= 1;
  20998. }
  20999. },
  21000. });
  21001. }
  21002. function isThisGetCallExpression(node) {
  21003. return node.type === 'CallExpression' &&
  21004. node.callee.type === 'MemberExpression' &&
  21005. node.callee.object.type === 'ThisExpression' &&
  21006. node.callee.property.name === 'get';
  21007. }
  21008. const isFunctionExpression = new Set([
  21009. 'FunctionExpression',
  21010. 'ArrowFunctionExpression',
  21011. ]);
  21012. function computed(component, prop) {
  21013. if (prop.value.type !== 'ObjectExpression') {
  21014. component.error(prop, {
  21015. code: `invalid-computed-property`,
  21016. message: `The 'computed' property must be an object literal`
  21017. });
  21018. }
  21019. checkForDupes(component, prop.value.properties);
  21020. checkForComputedKeys(component, prop.value.properties);
  21021. prop.value.properties.forEach((computation) => {
  21022. const name = getMethodName(computation.key);
  21023. if (!isValidIdentifier(name)) {
  21024. const suggestion = name.replace(/[^_$a-z0-9]/ig, '_').replace(/^\d/, '_$&');
  21025. component.error(computation.key, {
  21026. code: `invalid-computed-name`,
  21027. message: `Computed property name '${name}' is invalid — must be a valid identifier such as ${suggestion}`
  21028. });
  21029. }
  21030. if (reservedNames.has(name)) {
  21031. component.error(computation.key, {
  21032. code: `invalid-computed-name`,
  21033. message: `Computed property name '${name}' is invalid — cannot be a JavaScript reserved word`
  21034. });
  21035. }
  21036. if (!isFunctionExpression.has(computation.value.type)) {
  21037. component.error(computation.value, {
  21038. code: `invalid-computed-value`,
  21039. message: `Computed properties can be function expressions or arrow function expressions`
  21040. });
  21041. }
  21042. const { body, params } = computation.value;
  21043. walkThroughTopFunctionScope(body, (node) => {
  21044. if (isThisGetCallExpression(node) && !node.callee.property.computed) {
  21045. component.error(node, {
  21046. code: `impure-computed`,
  21047. message: `Cannot use this.get(...) — values must be passed into the function as arguments`
  21048. });
  21049. }
  21050. if (node.type === 'ThisExpression') {
  21051. component.error(node, {
  21052. code: `impure-computed`,
  21053. message: `Computed properties should be pure functions — they do not have access to the component instance and cannot use 'this'. Did you mean to put this in 'methods'?`
  21054. });
  21055. }
  21056. });
  21057. if (params.length === 0) {
  21058. component.error(computation.value, {
  21059. code: `impure-computed`,
  21060. message: `A computed value must depend on at least one property`
  21061. });
  21062. }
  21063. if (params.length > 1) {
  21064. component.error(computation.value, {
  21065. code: `invalid-computed-arguments`,
  21066. message: `Computed properties must take a single argument`
  21067. });
  21068. }
  21069. });
  21070. }
  21071. function usesThisOrArguments(node) {
  21072. let result = false;
  21073. walk(node, {
  21074. enter(node, parent) {
  21075. if (result ||
  21076. node.type === 'FunctionExpression' ||
  21077. node.type === 'FunctionDeclaration') {
  21078. return this.skip();
  21079. }
  21080. if (node.type === 'ThisExpression') {
  21081. result = true;
  21082. }
  21083. if (node.type === 'Identifier' &&
  21084. isReference(node, parent) &&
  21085. node.name === 'arguments') {
  21086. result = true;
  21087. }
  21088. },
  21089. });
  21090. return result;
  21091. }
  21092. function oncreate(component, prop) {
  21093. if (prop.value.type === 'ArrowFunctionExpression') {
  21094. if (usesThisOrArguments(prop.value.body)) {
  21095. component.error(prop, {
  21096. code: `invalid-oncreate-property`,
  21097. message: `'oncreate' should be a function expression, not an arrow function expression`
  21098. });
  21099. }
  21100. }
  21101. }
  21102. function ondestroy(component, prop) {
  21103. if (prop.value.type === 'ArrowFunctionExpression') {
  21104. if (usesThisOrArguments(prop.value.body)) {
  21105. component.error(prop, {
  21106. code: `invalid-ondestroy-property`,
  21107. message: `'ondestroy' should be a function expression, not an arrow function expression`
  21108. });
  21109. }
  21110. }
  21111. }
  21112. function onstate(component, prop) {
  21113. if (prop.value.type === 'ArrowFunctionExpression') {
  21114. if (usesThisOrArguments(prop.value.body)) {
  21115. component.error(prop, {
  21116. code: `invalid-onstate-property`,
  21117. message: `'onstate' should be a function expression, not an arrow function expression`
  21118. });
  21119. }
  21120. }
  21121. }
  21122. function onupdate(component, prop) {
  21123. if (prop.value.type === 'ArrowFunctionExpression') {
  21124. if (usesThisOrArguments(prop.value.body)) {
  21125. component.error(prop, {
  21126. code: `invalid-onupdate-property`,
  21127. message: `'onupdate' should be a function expression, not an arrow function expression`
  21128. });
  21129. }
  21130. }
  21131. }
  21132. function onrender(component, prop) {
  21133. component.warn(prop, {
  21134. code: `deprecated-onrender`,
  21135. message: `'onrender' has been deprecated in favour of 'oncreate', and will cause an error in Svelte 2.x`
  21136. });
  21137. oncreate(component, prop);
  21138. }
  21139. function onteardown(component, prop) {
  21140. component.warn(prop, {
  21141. code: `deprecated-onteardown`,
  21142. message: `'onteardown' has been deprecated in favour of 'ondestroy', and will cause an error in Svelte 2.x`
  21143. });
  21144. ondestroy(component, prop);
  21145. }
  21146. function helpers(component, prop) {
  21147. if (prop.value.type !== 'ObjectExpression') {
  21148. component.error(prop, {
  21149. code: `invalid-helpers-property`,
  21150. message: `The 'helpers' property must be an object literal`
  21151. });
  21152. }
  21153. checkForDupes(component, prop.value.properties);
  21154. checkForComputedKeys(component, prop.value.properties);
  21155. prop.value.properties.forEach((prop) => {
  21156. if (!/FunctionExpression/.test(prop.value.type))
  21157. return;
  21158. let usesArguments = false;
  21159. walkThroughTopFunctionScope(prop.value.body, (node) => {
  21160. if (isThisGetCallExpression(node) && !node.callee.property.computed) {
  21161. component.error(node, {
  21162. code: `impure-helper`,
  21163. message: `Cannot use this.get(...) — values must be passed into the helper function as arguments`
  21164. });
  21165. }
  21166. if (node.type === 'ThisExpression') {
  21167. component.error(node, {
  21168. code: `impure-helper`,
  21169. message: `Helpers should be pure functions — they do not have access to the component instance and cannot use 'this'. Did you mean to put this in 'methods'?`
  21170. });
  21171. }
  21172. else if (node.type === 'Identifier' && node.name === 'arguments') {
  21173. usesArguments = true;
  21174. }
  21175. });
  21176. if (prop.value.params.length === 0 && !usesArguments) {
  21177. component.warn(prop, {
  21178. code: `impure-helper`,
  21179. message: `Helpers should be pure functions, with at least one argument`
  21180. });
  21181. }
  21182. });
  21183. }
  21184. function checkForAccessors(component, properties, label) {
  21185. properties.forEach(prop => {
  21186. if (prop.kind !== 'init') {
  21187. component.error(prop, {
  21188. code: `illegal-accessor`,
  21189. message: `${label} cannot use getters and setters`
  21190. });
  21191. }
  21192. });
  21193. }
  21194. const builtin = new Set(['set', 'get', 'on', 'fire', 'destroy']);
  21195. function methods(component, prop) {
  21196. if (prop.value.type !== 'ObjectExpression') {
  21197. component.error(prop, {
  21198. code: `invalid-methods-property`,
  21199. message: `The 'methods' property must be an object literal`
  21200. });
  21201. }
  21202. checkForAccessors(component, prop.value.properties, 'Methods');
  21203. checkForDupes(component, prop.value.properties);
  21204. checkForComputedKeys(component, prop.value.properties);
  21205. prop.value.properties.forEach((prop) => {
  21206. const name = getMethodName(prop.key);
  21207. if (builtin.has(name)) {
  21208. component.error(prop, {
  21209. code: `invalid-method-name`,
  21210. message: `Cannot overwrite built-in method '${name}'`
  21211. });
  21212. }
  21213. if (prop.value.type === 'ArrowFunctionExpression') {
  21214. if (usesThisOrArguments(prop.value.body)) {
  21215. component.error(prop, {
  21216. code: `invalid-method-value`,
  21217. message: `Method '${prop.key.name}' should be a function expression, not an arrow function expression`
  21218. });
  21219. }
  21220. }
  21221. });
  21222. }
  21223. function components(component, prop) {
  21224. if (prop.value.type !== 'ObjectExpression') {
  21225. component.error(prop, {
  21226. code: `invalid-components-property`,
  21227. message: `The 'components' property must be an object literal`
  21228. });
  21229. }
  21230. checkForDupes(component, prop.value.properties);
  21231. checkForComputedKeys(component, prop.value.properties);
  21232. prop.value.properties.forEach((node) => {
  21233. const name = getMethodName(node.key);
  21234. if (name === 'state') {
  21235. // TODO is this still true?
  21236. component.error(node, {
  21237. code: `invalid-name`,
  21238. message: `Component constructors cannot be called 'state' due to technical limitations`
  21239. });
  21240. }
  21241. if (!/^[A-Z]/.test(name)) {
  21242. component.error(node, {
  21243. code: `component-lowercase`,
  21244. message: `Component names must be capitalised`
  21245. });
  21246. }
  21247. });
  21248. }
  21249. function events$1(component, prop) {
  21250. if (prop.value.type !== 'ObjectExpression') {
  21251. component.error(prop, {
  21252. code: `invalid-events-property`,
  21253. message: `The 'events' property must be an object literal`
  21254. });
  21255. }
  21256. checkForDupes(component, prop.value.properties);
  21257. checkForComputedKeys(component, prop.value.properties);
  21258. }
  21259. const valid = new Set(validNamespaces);
  21260. function namespace(component, prop) {
  21261. const ns = nodeToString(prop.value);
  21262. if (typeof ns !== 'string') {
  21263. component.error(prop, {
  21264. code: `invalid-namespace-property`,
  21265. message: `The 'namespace' property must be a string literal representing a valid namespace`
  21266. });
  21267. }
  21268. if (!valid.has(ns)) {
  21269. const match = fuzzymatch(ns, validNamespaces);
  21270. if (match) {
  21271. component.error(prop, {
  21272. code: `invalid-namespace-property`,
  21273. message: `Invalid namespace '${ns}' (did you mean '${match}'?)`
  21274. });
  21275. }
  21276. else {
  21277. component.error(prop, {
  21278. code: `invalid-namespace-property`,
  21279. message: `Invalid namespace '${ns}'`
  21280. });
  21281. }
  21282. }
  21283. }
  21284. function preload(component, prop) {
  21285. // not sure there's anything we need to check here...
  21286. }
  21287. function props(component, prop) {
  21288. if (prop.value.type !== 'ArrayExpression') {
  21289. component.error(prop.value, {
  21290. code: `invalid-props-property`,
  21291. message: `'props' must be an array expression, if specified`
  21292. });
  21293. }
  21294. prop.value.elements.forEach((element) => {
  21295. if (typeof nodeToString(element) !== 'string') {
  21296. component.error(element, {
  21297. code: `invalid-props-property`,
  21298. message: `'props' must be an array of string literals`
  21299. });
  21300. }
  21301. });
  21302. }
  21303. function tag$1(component, prop) {
  21304. const tag = nodeToString(prop.value);
  21305. if (typeof tag !== 'string') {
  21306. component.error(prop.value, {
  21307. code: `invalid-tag-property`,
  21308. message: `'tag' must be a string literal`
  21309. });
  21310. }
  21311. if (!/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) {
  21312. component.error(prop.value, {
  21313. code: `invalid-tag-property`,
  21314. message: `tag name must be two or more words joined by the '-' character`
  21315. });
  21316. }
  21317. }
  21318. function transitions$1(component, prop) {
  21319. if (prop.value.type !== 'ObjectExpression') {
  21320. component.error(prop, {
  21321. code: `invalid-transitions-property`,
  21322. message: `The 'transitions' property must be an object literal`
  21323. });
  21324. }
  21325. checkForDupes(component, prop.value.properties);
  21326. checkForComputedKeys(component, prop.value.properties);
  21327. prop.value.properties.forEach(() => {
  21328. // TODO probably some validation that can happen here...
  21329. // checking for use of `this` etc?
  21330. });
  21331. }
  21332. const disallowed$1 = new Set(['Literal', 'ObjectExpression', 'ArrayExpression']);
  21333. function setup(component, prop) {
  21334. while (prop.type === 'ParenthesizedExpression')
  21335. prop = prop.expression;
  21336. if (disallowed$1.has(prop.value.type)) {
  21337. component.error(prop.value, {
  21338. code: `invalid-setup-property`,
  21339. message: `'setup' must be a function`
  21340. });
  21341. }
  21342. }
  21343. function store(component, prop) {
  21344. // not sure there's anything we need to check here...
  21345. }
  21346. function immutable(component, prop) {
  21347. if (prop.value.type !== 'Literal' || typeof prop.value.value !== 'boolean') {
  21348. component.error(prop.value, {
  21349. code: `invalid-immutable-property`,
  21350. message: `'immutable' must be a boolean literal`
  21351. });
  21352. }
  21353. }
  21354. var propValidators = {
  21355. data: data$1,
  21356. actions,
  21357. animations: transitions,
  21358. computed,
  21359. oncreate,
  21360. ondestroy,
  21361. onstate,
  21362. onupdate,
  21363. onrender,
  21364. onteardown,
  21365. helpers,
  21366. methods,
  21367. components,
  21368. events: events$1,
  21369. namespace,
  21370. preload,
  21371. props,
  21372. tag: tag$1,
  21373. transitions: transitions$1,
  21374. setup,
  21375. store,
  21376. immutable,
  21377. };
  21378. function getIndentationLevel(str, b) {
  21379. let a = b;
  21380. while (a > 0 && str[a - 1] !== '\n')
  21381. a -= 1;
  21382. return /^\s*/.exec(str.slice(a, b))[0];
  21383. }
  21384. function getIndentExclusionRanges(node) {
  21385. // TODO can we fold this into a different pass?
  21386. const ranges = [];
  21387. walk(node, {
  21388. enter(node) {
  21389. if (node.type === 'TemplateElement')
  21390. ranges.push(node);
  21391. }
  21392. });
  21393. return ranges;
  21394. }
  21395. function removeIndentation(code, start, end, indentationLevel, ranges) {
  21396. const str = code.original.slice(start, end);
  21397. const pattern = new RegExp(`^${indentationLevel}`, 'gm');
  21398. let match;
  21399. while (match = pattern.exec(str)) {
  21400. // TODO bail if we're inside an exclusion range
  21401. code.remove(start + match.index, start + match.index + indentationLevel.length);
  21402. }
  21403. }
  21404. // We need to tell estree-walker that it should always
  21405. // look for an `else` block, otherwise it might get
  21406. // the wrong idea about the shape of each/if blocks
  21407. childKeys.EachBlock = childKeys.IfBlock = ['children', 'else'];
  21408. childKeys.Attribute = ['value'];
  21409. class Component {
  21410. constructor(ast, source, name, options, stats) {
  21411. this.stats = stats;
  21412. this.ast = ast;
  21413. this.source = source;
  21414. this.options = options;
  21415. this.imports = [];
  21416. this.shorthandImports = [];
  21417. this.helpers = new Set();
  21418. this.components = new Set();
  21419. this.events = new Set();
  21420. this.methods = new Set();
  21421. this.animations = new Set();
  21422. this.transitions = new Set();
  21423. this.actions = new Set();
  21424. this.importedComponents = new Map();
  21425. this.used = {
  21426. components: new Set(),
  21427. helpers: new Set(),
  21428. events: new Set(),
  21429. animations: new Set(),
  21430. transitions: new Set(),
  21431. actions: new Set(),
  21432. };
  21433. this.declarations = [];
  21434. this.refs = new Set();
  21435. this.refCallees = [];
  21436. this.indirectDependencies = new Map();
  21437. this.file = options.filename && (typeof process !== 'undefined' ? options.filename.replace(process.cwd(), '').replace(/^[\/\\]/, '') : options.filename);
  21438. this.locate = getLocator(this.source);
  21439. // track which properties are needed, so we can provide useful info
  21440. // in dev mode
  21441. this.expectedProperties = new Set();
  21442. this.code = new MagicString(source);
  21443. // styles
  21444. this.stylesheet = new Stylesheet(source, ast, options.filename, options.dev);
  21445. this.stylesheet.validate(this);
  21446. // allow compiler to deconflict user's `import { get } from 'whatever'` and
  21447. // Svelte's builtin `import { get, ... } from 'svelte/shared.ts'`;
  21448. this.userVars = new Set();
  21449. this.templateVars = new Map();
  21450. this.aliases = new Map();
  21451. this.usedNames = new Set();
  21452. this.computations = [];
  21453. this.templateProperties = {};
  21454. this.properties = new Map();
  21455. this.walkJs();
  21456. this.name = this.alias(name);
  21457. if (options.customElement === true) {
  21458. this.customElement = {
  21459. tag: this.tag,
  21460. props: this.props
  21461. };
  21462. }
  21463. else {
  21464. this.customElement = options.customElement;
  21465. }
  21466. if (this.customElement && !this.customElement.tag) {
  21467. throw new Error(`No tag name specified`); // TODO better error
  21468. }
  21469. this.fragment = new Fragment(this, ast.html);
  21470. // this.walkTemplate();
  21471. if (!this.customElement)
  21472. this.stylesheet.reify();
  21473. this.stylesheet.warnOnUnusedSelectors(options.onwarn);
  21474. if (this.defaultExport) {
  21475. const categories = {
  21476. components: 'component',
  21477. helpers: 'helper',
  21478. events: 'event definition',
  21479. transitions: 'transition',
  21480. actions: 'actions',
  21481. };
  21482. Object.keys(categories).forEach(category => {
  21483. const definitions = this.defaultExport.declaration.properties.find(prop => prop.key.name === category);
  21484. if (definitions) {
  21485. definitions.value.properties.forEach(prop => {
  21486. const { name } = prop.key;
  21487. if (!this.used[category].has(name)) {
  21488. this.warn(prop, {
  21489. code: `unused-${category.slice(0, -1)}`,
  21490. message: `The '${name}' ${categories[category]} is unused`
  21491. });
  21492. }
  21493. });
  21494. }
  21495. });
  21496. }
  21497. this.refCallees.forEach(callee => {
  21498. const { parts } = flattenReference(callee);
  21499. const ref = parts[1];
  21500. if (this.refs.has(ref)) ;
  21501. else {
  21502. const match = fuzzymatch(ref, Array.from(this.refs.keys()));
  21503. let message = `'refs.${ref}' does not exist`;
  21504. if (match)
  21505. message += ` (did you mean 'refs.${match}'?)`;
  21506. this.error(callee, {
  21507. code: `missing-ref`,
  21508. message
  21509. });
  21510. }
  21511. });
  21512. }
  21513. addSourcemapLocations(node) {
  21514. walk(node, {
  21515. enter: (node) => {
  21516. this.code.addSourcemapLocation(node.start);
  21517. this.code.addSourcemapLocation(node.end);
  21518. },
  21519. });
  21520. }
  21521. alias(name) {
  21522. if (!this.aliases.has(name)) {
  21523. this.aliases.set(name, this.getUniqueName(name));
  21524. }
  21525. return this.aliases.get(name);
  21526. }
  21527. generate(result, options, { banner = '', name, format }) {
  21528. const pattern = /\[✂(\d+)-(\d+)$/;
  21529. const helpers = new Set();
  21530. // TODO use same regex for both
  21531. result = result.replace(options.generate === 'ssr' ? /(@+|#+|%+)(\w*(?:-\w*)?)/g : /(%+|@+)(\w*(?:-\w*)?)/g, (match, sigil, name) => {
  21532. if (sigil === '@') {
  21533. if (name in shared) {
  21534. if (options.dev && `${name}Dev` in shared)
  21535. name = `${name}Dev`;
  21536. helpers.add(name);
  21537. }
  21538. return this.alias(name);
  21539. }
  21540. if (sigil === '%') {
  21541. return this.templateVars.get(name);
  21542. }
  21543. return sigil.slice(1) + name;
  21544. });
  21545. let importedHelpers;
  21546. if (options.shared) {
  21547. if (format !== 'es' && format !== 'cjs') {
  21548. throw new Error(`Components with shared helpers must be compiled with \`format: 'es'\` or \`format: 'cjs'\``);
  21549. }
  21550. importedHelpers = Array.from(helpers).sort().map(name => {
  21551. const alias = this.alias(name);
  21552. return { name, alias };
  21553. });
  21554. }
  21555. else {
  21556. let inlineHelpers = '';
  21557. const component = this;
  21558. importedHelpers = [];
  21559. helpers.forEach(name => {
  21560. const str = shared[name];
  21561. const code = new MagicString(str);
  21562. const expression = parseExpressionAt(str, 0);
  21563. let { scope } = annotateWithScopes(expression);
  21564. walk(expression, {
  21565. enter(node, parent) {
  21566. if (node._scope)
  21567. scope = node._scope;
  21568. if (node.type === 'Identifier' &&
  21569. isReference(node, parent) &&
  21570. !scope.has(node.name)) {
  21571. if (node.name in shared) {
  21572. // this helper function depends on another one
  21573. const dependency = node.name;
  21574. helpers.add(dependency);
  21575. const alias = component.alias(dependency);
  21576. if (alias !== node.name) {
  21577. code.overwrite(node.start, node.end, alias);
  21578. }
  21579. }
  21580. }
  21581. },
  21582. leave(node) {
  21583. if (node._scope)
  21584. scope = scope.parent;
  21585. },
  21586. });
  21587. if (name === 'transitionManager' || name === 'outros') {
  21588. // special case
  21589. const global = name === 'outros'
  21590. ? `_svelteOutros`
  21591. : `_svelteTransitionManager`;
  21592. inlineHelpers += `\n\nvar ${this.alias(name)} = window.${global} || (window.${global} = ${code});\n\n`;
  21593. }
  21594. else if (name === 'escaped' || name === 'missingComponent' || name === 'invalidAttributeNameCharacter') {
  21595. // vars are an awkward special case... would be nice to avoid this
  21596. const alias = this.alias(name);
  21597. inlineHelpers += `\n\nconst ${alias} = ${code};`;
  21598. }
  21599. else {
  21600. const alias = this.alias(expression.id.name);
  21601. if (alias !== expression.id.name) {
  21602. code.overwrite(expression.id.start, expression.id.end, alias);
  21603. }
  21604. inlineHelpers += `\n\n${code}`;
  21605. }
  21606. });
  21607. result += inlineHelpers;
  21608. }
  21609. const sharedPath = options.shared === true
  21610. ? 'svelte/shared.js'
  21611. : options.shared || '';
  21612. const module = wrapModule(result, format, name, options, banner, sharedPath, importedHelpers, this.imports, this.shorthandImports, this.source);
  21613. const parts = module.split('✂]');
  21614. const finalChunk = parts.pop();
  21615. const compiled = new Bundle({ separator: '' });
  21616. function addString(str) {
  21617. compiled.addSource({
  21618. content: new MagicString(str),
  21619. });
  21620. }
  21621. const { filename } = options;
  21622. // special case — the source file doesn't actually get used anywhere. we need
  21623. // to add an empty file to populate map.sources and map.sourcesContent
  21624. if (!parts.length) {
  21625. compiled.addSource({
  21626. filename,
  21627. content: new MagicString(this.source).remove(0, this.source.length),
  21628. });
  21629. }
  21630. parts.forEach((str) => {
  21631. const chunk = str.replace(pattern, '');
  21632. if (chunk)
  21633. addString(chunk);
  21634. const match = pattern.exec(str);
  21635. const snippet = this.code.snip(+match[1], +match[2]);
  21636. compiled.addSource({
  21637. filename,
  21638. content: snippet,
  21639. });
  21640. });
  21641. addString(finalChunk);
  21642. const css = this.customElement ?
  21643. { code: null, map: null } :
  21644. this.stylesheet.render(options.cssOutputFilename, true);
  21645. const js = {
  21646. code: compiled.toString(),
  21647. map: compiled.generateMap({
  21648. includeContent: true,
  21649. file: options.outputFilename,
  21650. })
  21651. };
  21652. return {
  21653. ast: this.ast,
  21654. js,
  21655. css,
  21656. stats: this.stats.render(this)
  21657. };
  21658. }
  21659. getUniqueName(name) {
  21660. if (test)
  21661. name = `${name}$`;
  21662. let alias = name;
  21663. for (let i = 1; reservedNames.has(alias) ||
  21664. this.userVars.has(alias) ||
  21665. this.usedNames.has(alias); alias = `${name}_${i++}`)
  21666. ;
  21667. this.usedNames.add(alias);
  21668. return alias;
  21669. }
  21670. getUniqueNameMaker() {
  21671. const localUsedNames = new Set();
  21672. function add(name) {
  21673. localUsedNames.add(name);
  21674. }
  21675. reservedNames.forEach(add);
  21676. this.userVars.forEach(add);
  21677. return (name) => {
  21678. if (test)
  21679. name = `${name}$`;
  21680. let alias = name;
  21681. for (let i = 1; this.usedNames.has(alias) ||
  21682. localUsedNames.has(alias); alias = `${name}_${i++}`)
  21683. ;
  21684. localUsedNames.add(alias);
  21685. return alias;
  21686. };
  21687. }
  21688. error(pos, e) {
  21689. error$1(e.message, {
  21690. name: 'ValidationError',
  21691. code: e.code,
  21692. source: this.source,
  21693. start: pos.start,
  21694. end: pos.end,
  21695. filename: this.options.filename
  21696. });
  21697. }
  21698. warn(pos, warning) {
  21699. if (!this.locator) {
  21700. this.locator = getLocator(this.source, { offsetLine: 1 });
  21701. }
  21702. const start = this.locator(pos.start);
  21703. const end = this.locator(pos.end);
  21704. const frame = getCodeFrame(this.source, start.line - 1, start.column);
  21705. this.stats.warn({
  21706. code: warning.code,
  21707. message: warning.message,
  21708. frame,
  21709. start,
  21710. end,
  21711. pos: pos.start,
  21712. filename: this.options.filename,
  21713. toString: () => `${warning.message} (${start.line + 1}:${start.column})\n${frame}`,
  21714. });
  21715. }
  21716. processDefaultExport(node, indentExclusionRanges) {
  21717. const { templateProperties, source, code } = this;
  21718. if (node.declaration.type !== 'ObjectExpression') {
  21719. this.error(node.declaration, {
  21720. code: `invalid-default-export`,
  21721. message: `Default export must be an object literal`
  21722. });
  21723. }
  21724. checkForComputedKeys(this, node.declaration.properties);
  21725. checkForDupes(this, node.declaration.properties);
  21726. const props = this.properties;
  21727. node.declaration.properties.forEach((prop) => {
  21728. props.set(getMethodName(prop.key), prop);
  21729. });
  21730. const validPropList = Object.keys(propValidators);
  21731. // ensure all exported props are valid
  21732. node.declaration.properties.forEach((prop) => {
  21733. const name = getMethodName(prop.key);
  21734. const propValidator = propValidators[name];
  21735. if (propValidator) {
  21736. propValidator(this, prop);
  21737. }
  21738. else {
  21739. const match = fuzzymatch(name, validPropList);
  21740. if (match) {
  21741. this.error(prop, {
  21742. code: `unexpected-property`,
  21743. message: `Unexpected property '${name}' (did you mean '${match}'?)`
  21744. });
  21745. }
  21746. else if (/FunctionExpression/.test(prop.value.type)) {
  21747. this.error(prop, {
  21748. code: `unexpected-property`,
  21749. message: `Unexpected property '${name}' (did you mean to include it in 'methods'?)`
  21750. });
  21751. }
  21752. else {
  21753. this.error(prop, {
  21754. code: `unexpected-property`,
  21755. message: `Unexpected property '${name}'`
  21756. });
  21757. }
  21758. }
  21759. });
  21760. if (props.has('namespace')) {
  21761. const ns = nodeToString(props.get('namespace').value);
  21762. this.namespace = namespaces[ns] || ns;
  21763. }
  21764. node.declaration.properties.forEach((prop) => {
  21765. templateProperties[getMethodName(prop.key)] = prop;
  21766. });
  21767. ['helpers', 'events', 'components', 'transitions', 'actions', 'animations'].forEach(key => {
  21768. if (templateProperties[key]) {
  21769. templateProperties[key].value.properties.forEach((prop) => {
  21770. this[key].add(getMethodName(prop.key));
  21771. });
  21772. }
  21773. });
  21774. const addArrowFunctionExpression = (type, name, node) => {
  21775. const { body, params, async } = node;
  21776. const fnKeyword = async ? 'async function' : 'function';
  21777. const paramString = params.length ?
  21778. `[✂${params[0].start}-${params[params.length - 1].end}✂]` :
  21779. ``;
  21780. const block = body.type === 'BlockStatement'
  21781. ? deindent `
  21782. ${fnKeyword} ${name}(${paramString}) [✂${body.start}-${body.end}✂]
  21783. `
  21784. : deindent `
  21785. ${fnKeyword} ${name}(${paramString}) {
  21786. return [✂${body.start}-${body.end}✂];
  21787. }
  21788. `;
  21789. this.declarations.push({ type, name, block, node });
  21790. };
  21791. const addFunctionExpression = (type, name, node) => {
  21792. const { async } = node;
  21793. const fnKeyword = async ? 'async function' : 'function';
  21794. let c = node.start;
  21795. while (this.source[c] !== '(')
  21796. c += 1;
  21797. const block = deindent `
  21798. ${fnKeyword} ${name}[✂${c}-${node.end}✂];
  21799. `;
  21800. this.declarations.push({ type, name, block, node });
  21801. };
  21802. const addValue = (type, name, node) => {
  21803. const block = deindent `
  21804. var ${name} = [✂${node.start}-${node.end}✂];
  21805. `;
  21806. this.declarations.push({ type, name, block, node });
  21807. };
  21808. const addDeclaration = (type, key, node, allowShorthandImport, disambiguator, conflicts) => {
  21809. const qualified = disambiguator ? `${disambiguator}-${key}` : key;
  21810. if (node.type === 'Identifier' && node.name === key) {
  21811. this.templateVars.set(qualified, key);
  21812. return;
  21813. }
  21814. let deconflicted = key;
  21815. if (conflicts)
  21816. while (deconflicted in conflicts)
  21817. deconflicted += '_';
  21818. let name = this.getUniqueName(deconflicted);
  21819. this.templateVars.set(qualified, name);
  21820. if (allowShorthandImport && node.type === 'Literal' && typeof node.value === 'string') {
  21821. this.shorthandImports.push({ name, source: node.value });
  21822. return;
  21823. }
  21824. // deindent
  21825. const indentationLevel = getIndentationLevel(source, node.start);
  21826. if (indentationLevel) {
  21827. removeIndentation(code, node.start, node.end, indentationLevel, indentExclusionRanges);
  21828. }
  21829. if (node.type === 'ArrowFunctionExpression') {
  21830. addArrowFunctionExpression(type, name, node);
  21831. }
  21832. else if (node.type === 'FunctionExpression') {
  21833. addFunctionExpression(type, name, node);
  21834. }
  21835. else {
  21836. addValue(type, name, node);
  21837. }
  21838. };
  21839. if (templateProperties.components) {
  21840. templateProperties.components.value.properties.forEach((property) => {
  21841. addDeclaration('components', getMethodName(property.key), property.value, true, 'components');
  21842. });
  21843. }
  21844. if (templateProperties.computed) {
  21845. const dependencies = new Map();
  21846. const fullStateComputations = [];
  21847. templateProperties.computed.value.properties.forEach((prop) => {
  21848. const key = getMethodName(prop.key);
  21849. const value = prop.value;
  21850. addDeclaration('computed', key, value, false, 'computed', {
  21851. state: true,
  21852. changed: true
  21853. });
  21854. const param = value.params[0];
  21855. const hasRestParam = (param.properties &&
  21856. param.properties.some(prop => prop.type === 'RestElement'));
  21857. if (param.type !== 'ObjectPattern' || hasRestParam) {
  21858. fullStateComputations.push({ key, deps: null, hasRestParam });
  21859. }
  21860. else {
  21861. const deps = param.properties.map(prop => prop.key.name);
  21862. deps.forEach(dep => {
  21863. this.expectedProperties.add(dep);
  21864. });
  21865. dependencies.set(key, deps);
  21866. }
  21867. });
  21868. const visited = new Set();
  21869. const visit = (key) => {
  21870. if (!dependencies.has(key))
  21871. return; // not a computation
  21872. if (visited.has(key))
  21873. return;
  21874. visited.add(key);
  21875. const deps = dependencies.get(key);
  21876. deps.forEach(visit);
  21877. this.computations.push({ key, deps, hasRestParam: false });
  21878. const prop = templateProperties.computed.value.properties.find((prop) => getMethodName(prop.key) === key);
  21879. };
  21880. templateProperties.computed.value.properties.forEach((prop) => visit(getMethodName(prop.key)));
  21881. if (fullStateComputations.length > 0) {
  21882. this.computations.push(...fullStateComputations);
  21883. }
  21884. }
  21885. if (templateProperties.data) {
  21886. addDeclaration('data', 'data', templateProperties.data.value);
  21887. }
  21888. if (templateProperties.events) {
  21889. templateProperties.events.value.properties.forEach((property) => {
  21890. addDeclaration('events', getMethodName(property.key), property.value, false, 'events');
  21891. });
  21892. }
  21893. if (templateProperties.helpers) {
  21894. templateProperties.helpers.value.properties.forEach((property) => {
  21895. addDeclaration('helpers', getMethodName(property.key), property.value, false, 'helpers');
  21896. });
  21897. }
  21898. if (templateProperties.methods) {
  21899. addDeclaration('methods', 'methods', templateProperties.methods.value);
  21900. templateProperties.methods.value.properties.forEach(property => {
  21901. this.methods.add(getMethodName(property.key));
  21902. });
  21903. }
  21904. if (templateProperties.namespace) {
  21905. const ns = nodeToString(templateProperties.namespace.value);
  21906. this.namespace = namespaces[ns] || ns;
  21907. }
  21908. if (templateProperties.oncreate) {
  21909. addDeclaration('oncreate', 'oncreate', templateProperties.oncreate.value);
  21910. }
  21911. if (templateProperties.ondestroy) {
  21912. addDeclaration('ondestroy', 'ondestroy', templateProperties.ondestroy.value);
  21913. }
  21914. if (templateProperties.onstate) {
  21915. addDeclaration('onstate', 'onstate', templateProperties.onstate.value);
  21916. }
  21917. if (templateProperties.onupdate) {
  21918. addDeclaration('onupdate', 'onupdate', templateProperties.onupdate.value);
  21919. }
  21920. if (templateProperties.preload) {
  21921. addDeclaration('preload', 'preload', templateProperties.preload.value);
  21922. }
  21923. if (templateProperties.props) {
  21924. this.props = templateProperties.props.value.elements.map((element) => nodeToString(element));
  21925. }
  21926. if (templateProperties.setup) {
  21927. addDeclaration('setup', 'setup', templateProperties.setup.value);
  21928. }
  21929. if (templateProperties.store) {
  21930. addDeclaration('store', 'store', templateProperties.store.value);
  21931. }
  21932. if (templateProperties.tag) {
  21933. this.tag = nodeToString(templateProperties.tag.value);
  21934. }
  21935. if (templateProperties.transitions) {
  21936. templateProperties.transitions.value.properties.forEach((property) => {
  21937. addDeclaration('transitions', getMethodName(property.key), property.value, false, 'transitions');
  21938. });
  21939. }
  21940. if (templateProperties.animations) {
  21941. templateProperties.animations.value.properties.forEach((property) => {
  21942. addDeclaration('animations', getMethodName(property.key), property.value, false, 'animations');
  21943. });
  21944. }
  21945. if (templateProperties.actions) {
  21946. templateProperties.actions.value.properties.forEach((property) => {
  21947. addDeclaration('actions', getMethodName(property.key), property.value, false, 'actions');
  21948. });
  21949. }
  21950. this.defaultExport = node;
  21951. }
  21952. walkJs() {
  21953. const { js } = this.ast;
  21954. if (!js)
  21955. return;
  21956. this.addSourcemapLocations(js.content);
  21957. const { code, source, imports } = this;
  21958. const indentationLevel = getIndentationLevel(source, js.content.body[0].start);
  21959. const indentExclusionRanges = getIndentExclusionRanges(js.content);
  21960. const { scope, globals } = annotateWithScopes(js.content);
  21961. scope.declarations.forEach(name => {
  21962. this.userVars.add(name);
  21963. });
  21964. globals.forEach(name => {
  21965. this.userVars.add(name);
  21966. });
  21967. const body = js.content.body.slice(); // slice, because we're going to be mutating the original
  21968. body.forEach(node => {
  21969. // check there are no named exports
  21970. if (node.type === 'ExportNamedDeclaration') {
  21971. this.error(node, {
  21972. code: `named-export`,
  21973. message: `A component can only have a default export`
  21974. });
  21975. }
  21976. if (node.type === 'ExportDefaultDeclaration') {
  21977. this.processDefaultExport(node, indentExclusionRanges);
  21978. }
  21979. // imports need to be hoisted out of the IIFE
  21980. else if (node.type === 'ImportDeclaration') {
  21981. removeNode(code, js.content, node);
  21982. imports.push(node);
  21983. node.specifiers.forEach((specifier) => {
  21984. this.userVars.add(specifier.local.name);
  21985. });
  21986. }
  21987. });
  21988. if (indentationLevel) {
  21989. if (this.defaultExport) {
  21990. removeIndentation(code, js.content.start, this.defaultExport.start, indentationLevel, indentExclusionRanges);
  21991. removeIndentation(code, this.defaultExport.end, js.content.end, indentationLevel, indentExclusionRanges);
  21992. }
  21993. else {
  21994. removeIndentation(code, js.content.start, js.content.end, indentationLevel, indentExclusionRanges);
  21995. }
  21996. }
  21997. let a = js.content.start;
  21998. while (/\s/.test(source[a]))
  21999. a += 1;
  22000. let b = js.content.end;
  22001. while (/\s/.test(source[b - 1]))
  22002. b -= 1;
  22003. this.javascript = this.defaultExport
  22004. ? [
  22005. a !== this.defaultExport.start ? `[✂${a}-${this.defaultExport.start}✂]` : '',
  22006. b !== this.defaultExport.end ? `[✂${this.defaultExport.end}-${b}✂]` : ''
  22007. ]
  22008. : [
  22009. a !== b ? `[✂${a}-${b}✂]` : '',
  22010. ''
  22011. ];
  22012. }
  22013. }
  22014. const seen = new Set();
  22015. function deprecate(message, code = message) {
  22016. if (seen.has(code))
  22017. return;
  22018. seen.add(code);
  22019. console.warn(`[svelte] DEPRECATION: ${message}`);
  22020. }
  22021. function normalize_options(options) {
  22022. let normalized = assign({ generate: 'dom', dev: false }, options);
  22023. const { onwarn } = normalized;
  22024. normalized.onwarn = onwarn
  22025. ? (warning) => onwarn(warning, default_onwarn)
  22026. : default_onwarn;
  22027. return normalized;
  22028. }
  22029. function default_onwarn({ start, message }) {
  22030. if (start) {
  22031. console.warn(`(${start.line}:${start.column}) – ${message}`);
  22032. }
  22033. else {
  22034. console.warn(message);
  22035. }
  22036. }
  22037. function validate_options(options, stats) {
  22038. const { name, filename } = options;
  22039. if (name && !/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name)) {
  22040. const error = new Error(`options.name must be a valid identifier (got '${name}')`);
  22041. throw error;
  22042. }
  22043. if (name && /^[a-z]/.test(name)) {
  22044. const message = `options.name should be capitalised`;
  22045. stats.warn({
  22046. code: `options-lowercase-name`,
  22047. message,
  22048. filename,
  22049. toString: () => message,
  22050. });
  22051. }
  22052. }
  22053. function compile(source, options = {}) {
  22054. const onerror = options.onerror || (err => {
  22055. throw err;
  22056. });
  22057. if (options.onerror) {
  22058. // TODO remove in v3
  22059. deprecate(`Instead of using options.onerror, wrap svelte.compile in a try-catch block`);
  22060. delete options.onerror;
  22061. }
  22062. options = normalize_options(options);
  22063. const stats = new Stats({
  22064. onwarn: options.onwarn
  22065. });
  22066. let ast;
  22067. try {
  22068. validate_options(options, stats);
  22069. stats.start('parse');
  22070. ast = parse$1(source, options);
  22071. stats.stop('parse');
  22072. stats.start('create component');
  22073. const component = new Component(ast, source, options.name || 'SvelteComponent', options, stats);
  22074. stats.stop('create component');
  22075. if (options.generate === false) {
  22076. return { ast, stats: stats.render(component), js: null, css: null };
  22077. }
  22078. if (options.generate === 'ssr') {
  22079. return ssr(component, options);
  22080. }
  22081. return dom(component, options);
  22082. }
  22083. catch (err) {
  22084. onerror(err);
  22085. }
  22086. }
  22087. /*! *****************************************************************************
  22088. Copyright (c) Microsoft Corporation. All rights reserved.
  22089. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  22090. this file except in compliance with the License. You may obtain a copy of the
  22091. License at http://www.apache.org/licenses/LICENSE-2.0
  22092. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22093. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  22094. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  22095. MERCHANTABLITY OR NON-INFRINGEMENT.
  22096. See the Apache Version 2.0 License for specific language governing permissions
  22097. and limitations under the License.
  22098. ***************************************************************************** */
  22099. function __awaiter$1(thisArg, _arguments, P, generator) {
  22100. return new (P || (P = Promise))(function (resolve, reject) {
  22101. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  22102. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  22103. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  22104. step((generator = generator.apply(thisArg, _arguments || [])).next());
  22105. });
  22106. }
  22107. function parseAttributeValue(value) {
  22108. return /^['"]/.test(value) ?
  22109. value.slice(1, -1) :
  22110. value;
  22111. }
  22112. function parseAttributes(str) {
  22113. const attrs = {};
  22114. str.split(/\s+/).filter(Boolean).forEach(attr => {
  22115. const [name, value] = attr.split('=');
  22116. attrs[name] = value ? parseAttributeValue(value) : true;
  22117. });
  22118. return attrs;
  22119. }
  22120. function replaceTagContents(source, type, preprocessor, options) {
  22121. return __awaiter$1(this, void 0, void 0, function* () {
  22122. const exp = new RegExp(`<${type}([\\S\\s]*?)>([\\S\\s]*?)<\\/${type}>`, 'ig');
  22123. const match = exp.exec(source);
  22124. if (match) {
  22125. const attributes = parseAttributes(match[1]);
  22126. const content = match[2];
  22127. const processed = yield preprocessor({
  22128. content,
  22129. attributes,
  22130. filename: options.filename
  22131. });
  22132. if (processed && processed.code) {
  22133. return (source.slice(0, match.index) +
  22134. `<${type}>${processed.code}</${type}>` +
  22135. source.slice(match.index + match[0].length));
  22136. }
  22137. }
  22138. return source;
  22139. });
  22140. }
  22141. function preprocess(source, options) {
  22142. return __awaiter$1(this, void 0, void 0, function* () {
  22143. const { markup, style, script } = options;
  22144. if (!!markup) {
  22145. const processed = yield markup({
  22146. content: source,
  22147. filename: options.filename
  22148. });
  22149. source = processed.code;
  22150. }
  22151. if (!!style) {
  22152. source = yield replaceTagContents(source, 'style', style, options);
  22153. }
  22154. if (!!script) {
  22155. source = yield replaceTagContents(source, 'script', script, options);
  22156. }
  22157. return {
  22158. // TODO return separated output, in future version where svelte.compile supports it:
  22159. // style: { code: styleCode, map: styleMap },
  22160. // script { code: scriptCode, map: scriptMap },
  22161. // markup { code: markupCode, map: markupMap },
  22162. toString() {
  22163. return source;
  22164. }
  22165. };
  22166. });
  22167. }
  22168. function create$1(source, options = {}) {
  22169. const onerror = options.onerror || (err => {
  22170. throw err;
  22171. });
  22172. if (options.onerror) {
  22173. // TODO remove in v3
  22174. deprecate(`Instead of using options.onerror, wrap svelte.create in a try-catch block`);
  22175. delete options.onerror;
  22176. }
  22177. options.format = 'eval';
  22178. try {
  22179. const compiled = compile(source, options);
  22180. if (!compiled || !compiled.js.code) {
  22181. return;
  22182. }
  22183. return (new Function(`return ${compiled.js.code}`))();
  22184. }
  22185. catch (err) {
  22186. onerror(err);
  22187. }
  22188. }
  22189. const VERSION = '2.15.3';
  22190. exports.create = create$1;
  22191. exports.VERSION = VERSION;
  22192. exports.compile = compile;
  22193. exports.parse = parse$1;
  22194. exports.preprocess = preprocess;
  22195. Object.defineProperty(exports, '__esModule', { value: true });
  22196. })));
  22197. //# sourceMappingURL=svelte.js.map