svelte.js 876 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588
  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. /*! *****************************************************************************
  7. Copyright (c) Microsoft Corporation. All rights reserved.
  8. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  9. this file except in compliance with the License. You may obtain a copy of the
  10. License at http://www.apache.org/licenses/LICENSE-2.0
  11. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  13. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  14. MERCHANTABLITY OR NON-INFRINGEMENT.
  15. See the Apache Version 2.0 License for specific language governing permissions
  16. and limitations under the License.
  17. ***************************************************************************** */
  18. function __awaiter(thisArg, _arguments, P, generator) {
  19. return new (P || (P = Promise))(function (resolve, reject) {
  20. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  21. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  22. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  23. step((generator = generator.apply(thisArg, _arguments || [])).next());
  24. });
  25. }
  26. // Reserved word lists for various dialects of the language
  27. var reservedWords = {
  28. 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",
  29. 5: "class enum extends super const export import",
  30. 6: "enum",
  31. strict: "implements interface let package private protected public static yield",
  32. strictBind: "eval arguments"
  33. };
  34. // And the keywords
  35. 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";
  36. var keywords = {
  37. 5: ecma5AndLessKeywords,
  38. 6: ecma5AndLessKeywords + " const class extends export import super"
  39. };
  40. var keywordRelationalOperator = /^in(stanceof)?$/;
  41. // ## Character categories
  42. // Big ugly regular expressions that match characters in the
  43. // whitespace, identifier, and identifier-start categories. These
  44. // are only applied when a character is found to actually have a
  45. // code point above 128.
  46. // Generated by `bin/generate-identifier-regex.js`.
  47. 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\u0561-\u0587\u05d0-\u05ea\u05f0-\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-\u1877\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\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-\u312e\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fea\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ae\ua7b0-\ua7b7\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\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";
  48. 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\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d4-\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\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-\u0c03\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\ua900-\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";
  49. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  50. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  51. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  52. // These are a run-length and offset encoded representation of the
  53. // >0xffff code points that are a valid part of identifiers. The
  54. // offset starts at 0x10000, and each pair of numbers represents an
  55. // offset to the next range, and then a size of the range. They were
  56. // generated by bin/generate-identifier-regex.js
  57. // eslint-disable-next-line comma-spacing
  58. 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,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,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,25,391,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,55,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,698,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,65,1,31,6124,20,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];
  59. // eslint-disable-next-line comma-spacing
  60. var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,7,0,161,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,87,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,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,19719,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];
  61. // This has a complexity linear to the value of the code. The
  62. // assumption is that looking up astral identifier characters is
  63. // rare.
  64. function isInAstralSet(code, set) {
  65. var pos = 0x10000;
  66. for (var i = 0; i < set.length; i += 2) {
  67. pos += set[i];
  68. if (pos > code) { return false }
  69. pos += set[i + 1];
  70. if (pos >= code) { return true }
  71. }
  72. }
  73. // Test whether a given character code starts an identifier.
  74. function isIdentifierStart(code, astral) {
  75. if (code < 65) { return code === 36 }
  76. if (code < 91) { return true }
  77. if (code < 97) { return code === 95 }
  78. if (code < 123) { return true }
  79. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  80. if (astral === false) { return false }
  81. return isInAstralSet(code, astralIdentifierStartCodes)
  82. }
  83. // Test whether a given character is part of an identifier.
  84. function isIdentifierChar(code, astral) {
  85. if (code < 48) { return code === 36 }
  86. if (code < 58) { return true }
  87. if (code < 65) { return false }
  88. if (code < 91) { return true }
  89. if (code < 97) { return code === 95 }
  90. if (code < 123) { return true }
  91. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  92. if (astral === false) { return false }
  93. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  94. }
  95. // ## Token types
  96. // The assignment of fine-grained, information-carrying type objects
  97. // allows the tokenizer to store the information it has about a
  98. // token in a way that is very cheap for the parser to look up.
  99. // All token type variables start with an underscore, to make them
  100. // easy to recognize.
  101. // The `beforeExpr` property is used to disambiguate between regular
  102. // expressions and divisions. It is set on all token types that can
  103. // be followed by an expression (thus, a slash after them would be a
  104. // regular expression).
  105. //
  106. // The `startsExpr` property is used to check if the token ends a
  107. // `yield` expression. It is set on all token types that either can
  108. // directly start an expression (like a quotation mark) or can
  109. // continue an expression (like the body of a string).
  110. //
  111. // `isLoop` marks a keyword as starting a loop, which is important
  112. // to know when parsing a label, in order to allow or disallow
  113. // continue jumps to that label.
  114. var TokenType = function TokenType(label, conf) {
  115. if ( conf === void 0 ) conf = {};
  116. this.label = label;
  117. this.keyword = conf.keyword;
  118. this.beforeExpr = !!conf.beforeExpr;
  119. this.startsExpr = !!conf.startsExpr;
  120. this.isLoop = !!conf.isLoop;
  121. this.isAssign = !!conf.isAssign;
  122. this.prefix = !!conf.prefix;
  123. this.postfix = !!conf.postfix;
  124. this.binop = conf.binop || null;
  125. this.updateContext = null;
  126. };
  127. function binop(name, prec) {
  128. return new TokenType(name, {beforeExpr: true, binop: prec})
  129. }
  130. var beforeExpr = {beforeExpr: true};
  131. var startsExpr = {startsExpr: true};
  132. // Map keyword names to token types.
  133. var keywords$1 = {};
  134. // Succinct definitions of keyword token types
  135. function kw(name, options) {
  136. if ( options === void 0 ) options = {};
  137. options.keyword = name;
  138. return keywords$1[name] = new TokenType(name, options)
  139. }
  140. var types = {
  141. num: new TokenType("num", startsExpr),
  142. regexp: new TokenType("regexp", startsExpr),
  143. string: new TokenType("string", startsExpr),
  144. name: new TokenType("name", startsExpr),
  145. eof: new TokenType("eof"),
  146. // Punctuation token types.
  147. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  148. bracketR: new TokenType("]"),
  149. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  150. braceR: new TokenType("}"),
  151. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  152. parenR: new TokenType(")"),
  153. comma: new TokenType(",", beforeExpr),
  154. semi: new TokenType(";", beforeExpr),
  155. colon: new TokenType(":", beforeExpr),
  156. dot: new TokenType("."),
  157. question: new TokenType("?", beforeExpr),
  158. arrow: new TokenType("=>", beforeExpr),
  159. template: new TokenType("template"),
  160. invalidTemplate: new TokenType("invalidTemplate"),
  161. ellipsis: new TokenType("...", beforeExpr),
  162. backQuote: new TokenType("`", startsExpr),
  163. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  164. // Operators. These carry several kinds of properties to help the
  165. // parser use them properly (the presence of these properties is
  166. // what categorizes them as operators).
  167. //
  168. // `binop`, when present, specifies that this operator is a binary
  169. // operator, and will refer to its precedence.
  170. //
  171. // `prefix` and `postfix` mark the operator as a prefix or postfix
  172. // unary operator.
  173. //
  174. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  175. // binary operators with a very low precedence, that should result
  176. // in AssignmentExpression nodes.
  177. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  178. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  179. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  180. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  181. logicalOR: binop("||", 1),
  182. logicalAND: binop("&&", 2),
  183. bitwiseOR: binop("|", 3),
  184. bitwiseXOR: binop("^", 4),
  185. bitwiseAND: binop("&", 5),
  186. equality: binop("==/!=/===/!==", 6),
  187. relational: binop("</>/<=/>=", 7),
  188. bitShift: binop("<</>>/>>>", 8),
  189. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  190. modulo: binop("%", 10),
  191. star: binop("*", 10),
  192. slash: binop("/", 10),
  193. starstar: new TokenType("**", {beforeExpr: true}),
  194. // Keyword token types.
  195. _break: kw("break"),
  196. _case: kw("case", beforeExpr),
  197. _catch: kw("catch"),
  198. _continue: kw("continue"),
  199. _debugger: kw("debugger"),
  200. _default: kw("default", beforeExpr),
  201. _do: kw("do", {isLoop: true, beforeExpr: true}),
  202. _else: kw("else", beforeExpr),
  203. _finally: kw("finally"),
  204. _for: kw("for", {isLoop: true}),
  205. _function: kw("function", startsExpr),
  206. _if: kw("if"),
  207. _return: kw("return", beforeExpr),
  208. _switch: kw("switch"),
  209. _throw: kw("throw", beforeExpr),
  210. _try: kw("try"),
  211. _var: kw("var"),
  212. _const: kw("const"),
  213. _while: kw("while", {isLoop: true}),
  214. _with: kw("with"),
  215. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  216. _this: kw("this", startsExpr),
  217. _super: kw("super", startsExpr),
  218. _class: kw("class", startsExpr),
  219. _extends: kw("extends", beforeExpr),
  220. _export: kw("export"),
  221. _import: kw("import"),
  222. _null: kw("null", startsExpr),
  223. _true: kw("true", startsExpr),
  224. _false: kw("false", startsExpr),
  225. _in: kw("in", {beforeExpr: true, binop: 7}),
  226. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  227. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  228. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  229. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  230. };
  231. // Matches a whole line break (where CRLF is considered a single
  232. // line break). Used to count lines.
  233. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  234. var lineBreakG = new RegExp(lineBreak.source, "g");
  235. function isNewLine(code) {
  236. return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
  237. }
  238. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  239. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  240. var ref = Object.prototype;
  241. var hasOwnProperty = ref.hasOwnProperty;
  242. var toString = ref.toString;
  243. // Checks if an object has a property.
  244. function has(obj, propName) {
  245. return hasOwnProperty.call(obj, propName)
  246. }
  247. var isArray = Array.isArray || (function (obj) { return (
  248. toString.call(obj) === "[object Array]"
  249. ); });
  250. // These are used when `options.locations` is on, for the
  251. // `startLoc` and `endLoc` properties.
  252. var Position = function Position(line, col) {
  253. this.line = line;
  254. this.column = col;
  255. };
  256. Position.prototype.offset = function offset (n) {
  257. return new Position(this.line, this.column + n)
  258. };
  259. var SourceLocation = function SourceLocation(p, start, end) {
  260. this.start = start;
  261. this.end = end;
  262. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  263. };
  264. // The `getLineInfo` function is mostly useful when the
  265. // `locations` option is off (for performance reasons) and you
  266. // want to find the line/column position for a given character
  267. // offset. `input` should be the code string that the offset refers
  268. // into.
  269. function getLineInfo(input, offset) {
  270. for (var line = 1, cur = 0;;) {
  271. lineBreakG.lastIndex = cur;
  272. var match = lineBreakG.exec(input);
  273. if (match && match.index < offset) {
  274. ++line;
  275. cur = match.index + match[0].length;
  276. } else {
  277. return new Position(line, offset - cur)
  278. }
  279. }
  280. }
  281. // A second optional argument can be given to further configure
  282. // the parser process. These options are recognized:
  283. var defaultOptions = {
  284. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  285. // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
  286. // for strict mode, the set of reserved words, and support for
  287. // new syntax features. The default is 7.
  288. ecmaVersion: 7,
  289. // `sourceType` indicates the mode the code should be parsed in.
  290. // Can be either `"script"` or `"module"`. This influences global
  291. // strict mode and parsing of `import` and `export` declarations.
  292. sourceType: "script",
  293. // `onInsertedSemicolon` can be a callback that will be called
  294. // when a semicolon is automatically inserted. It will be passed
  295. // th position of the comma as an offset, and if `locations` is
  296. // enabled, it is given the location as a `{line, column}` object
  297. // as second argument.
  298. onInsertedSemicolon: null,
  299. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  300. // trailing commas.
  301. onTrailingComma: null,
  302. // By default, reserved words are only enforced if ecmaVersion >= 5.
  303. // Set `allowReserved` to a boolean value to explicitly turn this on
  304. // an off. When this option has the value "never", reserved words
  305. // and keywords can also not be used as property names.
  306. allowReserved: null,
  307. // When enabled, a return at the top level is not considered an
  308. // error.
  309. allowReturnOutsideFunction: false,
  310. // When enabled, import/export statements are not constrained to
  311. // appearing at the top of the program.
  312. allowImportExportEverywhere: false,
  313. // When enabled, hashbang directive in the beginning of file
  314. // is allowed and treated as a line comment.
  315. allowHashBang: false,
  316. // When `locations` is on, `loc` properties holding objects with
  317. // `start` and `end` properties in `{line, column}` form (with
  318. // line being 1-based and column 0-based) will be attached to the
  319. // nodes.
  320. locations: false,
  321. // A function can be passed as `onToken` option, which will
  322. // cause Acorn to call that function with object in the same
  323. // format as tokens returned from `tokenizer().getToken()`. Note
  324. // that you are not allowed to call the parser from the
  325. // callback—that will corrupt its internal state.
  326. onToken: null,
  327. // A function can be passed as `onComment` option, which will
  328. // cause Acorn to call that function with `(block, text, start,
  329. // end)` parameters whenever a comment is skipped. `block` is a
  330. // boolean indicating whether this is a block (`/* */`) comment,
  331. // `text` is the content of the comment, and `start` and `end` are
  332. // character offsets that denote the start and end of the comment.
  333. // When the `locations` option is on, two more parameters are
  334. // passed, the full `{line, column}` locations of the start and
  335. // end of the comments. Note that you are not allowed to call the
  336. // parser from the callback—that will corrupt its internal state.
  337. onComment: null,
  338. // Nodes have their start and end characters offsets recorded in
  339. // `start` and `end` properties (directly on the node, rather than
  340. // the `loc` object, which holds line/column data. To also add a
  341. // [semi-standardized][range] `range` property holding a `[start,
  342. // end]` array with the same numbers, set the `ranges` option to
  343. // `true`.
  344. //
  345. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  346. ranges: false,
  347. // It is possible to parse multiple files into a single AST by
  348. // passing the tree produced by parsing the first file as
  349. // `program` option in subsequent parses. This will add the
  350. // toplevel forms of the parsed file to the `Program` (top) node
  351. // of an existing parse tree.
  352. program: null,
  353. // When `locations` is on, you can pass this to record the source
  354. // file in every node's `loc` object.
  355. sourceFile: null,
  356. // This value, if given, is stored in every node, whether
  357. // `locations` is on or off.
  358. directSourceFile: null,
  359. // When enabled, parenthesized expressions are represented by
  360. // (non-standard) ParenthesizedExpression nodes
  361. preserveParens: false,
  362. plugins: {}
  363. };
  364. // Interpret and default an options object
  365. function getOptions(opts) {
  366. var options = {};
  367. for (var opt in defaultOptions)
  368. { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  369. if (options.ecmaVersion >= 2015)
  370. { options.ecmaVersion -= 2009; }
  371. if (options.allowReserved == null)
  372. { options.allowReserved = options.ecmaVersion < 5; }
  373. if (isArray(options.onToken)) {
  374. var tokens = options.onToken;
  375. options.onToken = function (token) { return tokens.push(token); };
  376. }
  377. if (isArray(options.onComment))
  378. { options.onComment = pushComment(options, options.onComment); }
  379. return options
  380. }
  381. function pushComment(options, array) {
  382. return function(block, text, start, end, startLoc, endLoc) {
  383. var comment = {
  384. type: block ? "Block" : "Line",
  385. value: text,
  386. start: start,
  387. end: end
  388. };
  389. if (options.locations)
  390. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  391. if (options.ranges)
  392. { comment.range = [start, end]; }
  393. array.push(comment);
  394. }
  395. }
  396. // Registered plugins
  397. var plugins = {};
  398. function keywordRegexp(words) {
  399. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  400. }
  401. var Parser = function Parser(options, input, startPos) {
  402. this.options = options = getOptions(options);
  403. this.sourceFile = options.sourceFile;
  404. this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
  405. var reserved = "";
  406. if (!options.allowReserved) {
  407. for (var v = options.ecmaVersion;; v--)
  408. { if (reserved = reservedWords[v]) { break } }
  409. if (options.sourceType == "module") { reserved += " await"; }
  410. }
  411. this.reservedWords = keywordRegexp(reserved);
  412. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  413. this.reservedWordsStrict = keywordRegexp(reservedStrict);
  414. this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
  415. this.input = String(input);
  416. // Used to signal to callers of `readWord1` whether the word
  417. // contained any escape sequences. This is needed because words with
  418. // escape sequences must not be interpreted as keywords.
  419. this.containsEsc = false;
  420. // Load plugins
  421. this.loadPlugins(options.plugins);
  422. // Set up token state
  423. // The current position of the tokenizer in the input.
  424. if (startPos) {
  425. this.pos = startPos;
  426. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  427. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  428. } else {
  429. this.pos = this.lineStart = 0;
  430. this.curLine = 1;
  431. }
  432. // Properties of the current token:
  433. // Its type
  434. this.type = types.eof;
  435. // For tokens that include more information than their type, the value
  436. this.value = null;
  437. // Its start and end offset
  438. this.start = this.end = this.pos;
  439. // And, if locations are used, the {line, column} object
  440. // corresponding to those offsets
  441. this.startLoc = this.endLoc = this.curPosition();
  442. // Position information for the previous token
  443. this.lastTokEndLoc = this.lastTokStartLoc = null;
  444. this.lastTokStart = this.lastTokEnd = this.pos;
  445. // The context stack is used to superficially track syntactic
  446. // context to predict whether a regular expression is allowed in a
  447. // given position.
  448. this.context = this.initialContext();
  449. this.exprAllowed = true;
  450. // Figure out if it's a module code.
  451. this.inModule = options.sourceType === "module";
  452. this.strict = this.inModule || this.strictDirective(this.pos);
  453. // Used to signify the start of a potential arrow function
  454. this.potentialArrowAt = -1;
  455. // Flags to track whether we are in a function, a generator, an async function.
  456. this.inFunction = this.inGenerator = this.inAsync = false;
  457. // Positions to delayed-check that yield/await does not exist in default parameters.
  458. this.yieldPos = this.awaitPos = 0;
  459. // Labels in scope.
  460. this.labels = [];
  461. // If enabled, skip leading hashbang line.
  462. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  463. { this.skipLineComment(2); }
  464. // Scope tracking for duplicate variable names (see scope.js)
  465. this.scopeStack = [];
  466. this.enterFunctionScope();
  467. // For RegExp validation
  468. this.regexpState = null;
  469. };
  470. // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  471. Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
  472. Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
  473. Parser.prototype.extend = function extend (name, f) {
  474. this[name] = f(this[name]);
  475. };
  476. Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
  477. var this$1 = this;
  478. for (var name in pluginConfigs) {
  479. var plugin = plugins[name];
  480. if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
  481. plugin(this$1, pluginConfigs[name]);
  482. }
  483. };
  484. Parser.prototype.parse = function parse () {
  485. var node = this.options.program || this.startNode();
  486. this.nextToken();
  487. return this.parseTopLevel(node)
  488. };
  489. var pp = Parser.prototype;
  490. // ## Parser utilities
  491. var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
  492. pp.strictDirective = function(start) {
  493. var this$1 = this;
  494. for (;;) {
  495. skipWhiteSpace.lastIndex = start;
  496. start += skipWhiteSpace.exec(this$1.input)[0].length;
  497. var match = literal.exec(this$1.input.slice(start));
  498. if (!match) { return false }
  499. if ((match[1] || match[2]) == "use strict") { return true }
  500. start += match[0].length;
  501. }
  502. };
  503. // Predicate that tests whether the next token is of the given
  504. // type, and if yes, consumes it as a side effect.
  505. pp.eat = function(type) {
  506. if (this.type === type) {
  507. this.next();
  508. return true
  509. } else {
  510. return false
  511. }
  512. };
  513. // Tests whether parsed token is a contextual keyword.
  514. pp.isContextual = function(name) {
  515. return this.type === types.name && this.value === name && !this.containsEsc
  516. };
  517. // Consumes contextual keyword if possible.
  518. pp.eatContextual = function(name) {
  519. if (!this.isContextual(name)) { return false }
  520. this.next();
  521. return true
  522. };
  523. // Asserts that following token is given contextual keyword.
  524. pp.expectContextual = function(name) {
  525. if (!this.eatContextual(name)) { this.unexpected(); }
  526. };
  527. // Test whether a semicolon can be inserted at the current position.
  528. pp.canInsertSemicolon = function() {
  529. return this.type === types.eof ||
  530. this.type === types.braceR ||
  531. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  532. };
  533. pp.insertSemicolon = function() {
  534. if (this.canInsertSemicolon()) {
  535. if (this.options.onInsertedSemicolon)
  536. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  537. return true
  538. }
  539. };
  540. // Consume a semicolon, or, failing that, see if we are allowed to
  541. // pretend that there is a semicolon at this position.
  542. pp.semicolon = function() {
  543. if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
  544. };
  545. pp.afterTrailingComma = function(tokType, notNext) {
  546. if (this.type == tokType) {
  547. if (this.options.onTrailingComma)
  548. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  549. if (!notNext)
  550. { this.next(); }
  551. return true
  552. }
  553. };
  554. // Expect a token of a given type. If found, consume it, otherwise,
  555. // raise an unexpected token error.
  556. pp.expect = function(type) {
  557. this.eat(type) || this.unexpected();
  558. };
  559. // Raise an unexpected token error.
  560. pp.unexpected = function(pos) {
  561. this.raise(pos != null ? pos : this.start, "Unexpected token");
  562. };
  563. function DestructuringErrors() {
  564. this.shorthandAssign =
  565. this.trailingComma =
  566. this.parenthesizedAssign =
  567. this.parenthesizedBind =
  568. this.doubleProto =
  569. -1;
  570. }
  571. pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  572. if (!refDestructuringErrors) { return }
  573. if (refDestructuringErrors.trailingComma > -1)
  574. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  575. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  576. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  577. };
  578. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  579. if (!refDestructuringErrors) { return false }
  580. var shorthandAssign = refDestructuringErrors.shorthandAssign;
  581. var doubleProto = refDestructuringErrors.doubleProto;
  582. if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
  583. if (shorthandAssign >= 0)
  584. { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
  585. if (doubleProto >= 0)
  586. { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
  587. };
  588. pp.checkYieldAwaitInDefaultParams = function() {
  589. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  590. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  591. if (this.awaitPos)
  592. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  593. };
  594. pp.isSimpleAssignTarget = function(expr) {
  595. if (expr.type === "ParenthesizedExpression")
  596. { return this.isSimpleAssignTarget(expr.expression) }
  597. return expr.type === "Identifier" || expr.type === "MemberExpression"
  598. };
  599. var pp$1 = Parser.prototype;
  600. // ### Statement parsing
  601. // Parse a program. Initializes the parser, reads any number of
  602. // statements, and wraps them in a Program node. Optionally takes a
  603. // `program` argument. If present, the statements will be appended
  604. // to its body instead of creating a new node.
  605. pp$1.parseTopLevel = function(node) {
  606. var this$1 = this;
  607. var exports = {};
  608. if (!node.body) { node.body = []; }
  609. while (this.type !== types.eof) {
  610. var stmt = this$1.parseStatement(true, true, exports);
  611. node.body.push(stmt);
  612. }
  613. this.adaptDirectivePrologue(node.body);
  614. this.next();
  615. if (this.options.ecmaVersion >= 6) {
  616. node.sourceType = this.options.sourceType;
  617. }
  618. return this.finishNode(node, "Program")
  619. };
  620. var loopLabel = {kind: "loop"};
  621. var switchLabel = {kind: "switch"};
  622. pp$1.isLet = function() {
  623. if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
  624. skipWhiteSpace.lastIndex = this.pos;
  625. var skip = skipWhiteSpace.exec(this.input);
  626. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  627. if (nextCh === 91 || nextCh == 123) { return true } // '{' and '['
  628. if (isIdentifierStart(nextCh, true)) {
  629. var pos = next + 1;
  630. while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
  631. var ident = this.input.slice(next, pos);
  632. if (!keywordRelationalOperator.test(ident)) { return true }
  633. }
  634. return false
  635. };
  636. // check 'async [no LineTerminator here] function'
  637. // - 'async /*foo*/ function' is OK.
  638. // - 'async /*\n*/ function' is invalid.
  639. pp$1.isAsyncFunction = function() {
  640. if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
  641. { return false }
  642. skipWhiteSpace.lastIndex = this.pos;
  643. var skip = skipWhiteSpace.exec(this.input);
  644. var next = this.pos + skip[0].length;
  645. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  646. this.input.slice(next, next + 8) === "function" &&
  647. (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
  648. };
  649. // Parse a single statement.
  650. //
  651. // If expecting a statement and finding a slash operator, parse a
  652. // regular expression literal. This is to handle cases like
  653. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  654. // does not help.
  655. pp$1.parseStatement = function(declaration, topLevel, exports) {
  656. var starttype = this.type, node = this.startNode(), kind;
  657. if (this.isLet()) {
  658. starttype = types._var;
  659. kind = "let";
  660. }
  661. // Most types of statements are recognized by the keyword they
  662. // start with. Many are trivial to parse, some require a bit of
  663. // complexity.
  664. switch (starttype) {
  665. case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  666. case types._debugger: return this.parseDebuggerStatement(node)
  667. case types._do: return this.parseDoStatement(node)
  668. case types._for: return this.parseForStatement(node)
  669. case types._function:
  670. if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
  671. return this.parseFunctionStatement(node, false)
  672. case types._class:
  673. if (!declaration) { this.unexpected(); }
  674. return this.parseClass(node, true)
  675. case types._if: return this.parseIfStatement(node)
  676. case types._return: return this.parseReturnStatement(node)
  677. case types._switch: return this.parseSwitchStatement(node)
  678. case types._throw: return this.parseThrowStatement(node)
  679. case types._try: return this.parseTryStatement(node)
  680. case types._const: case types._var:
  681. kind = kind || this.value;
  682. if (!declaration && kind != "var") { this.unexpected(); }
  683. return this.parseVarStatement(node, kind)
  684. case types._while: return this.parseWhileStatement(node)
  685. case types._with: return this.parseWithStatement(node)
  686. case types.braceL: return this.parseBlock()
  687. case types.semi: return this.parseEmptyStatement(node)
  688. case types._export:
  689. case types._import:
  690. if (!this.options.allowImportExportEverywhere) {
  691. if (!topLevel)
  692. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  693. if (!this.inModule)
  694. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  695. }
  696. return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
  697. // If the statement does not start with a statement keyword or a
  698. // brace, it's an ExpressionStatement or LabeledStatement. We
  699. // simply start parsing an expression, and afterwards, if the
  700. // next token is a colon and the expression was a simple
  701. // Identifier node, we switch to interpreting it as a label.
  702. default:
  703. if (this.isAsyncFunction()) {
  704. if (!declaration) { this.unexpected(); }
  705. this.next();
  706. return this.parseFunctionStatement(node, true)
  707. }
  708. var maybeName = this.value, expr = this.parseExpression();
  709. if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
  710. { return this.parseLabeledStatement(node, maybeName, expr) }
  711. else { return this.parseExpressionStatement(node, expr) }
  712. }
  713. };
  714. pp$1.parseBreakContinueStatement = function(node, keyword) {
  715. var this$1 = this;
  716. var isBreak = keyword == "break";
  717. this.next();
  718. if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
  719. else if (this.type !== types.name) { this.unexpected(); }
  720. else {
  721. node.label = this.parseIdent();
  722. this.semicolon();
  723. }
  724. // Verify that there is an actual destination to break or
  725. // continue to.
  726. var i = 0;
  727. for (; i < this.labels.length; ++i) {
  728. var lab = this$1.labels[i];
  729. if (node.label == null || lab.name === node.label.name) {
  730. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  731. if (node.label && isBreak) { break }
  732. }
  733. }
  734. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  735. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  736. };
  737. pp$1.parseDebuggerStatement = function(node) {
  738. this.next();
  739. this.semicolon();
  740. return this.finishNode(node, "DebuggerStatement")
  741. };
  742. pp$1.parseDoStatement = function(node) {
  743. this.next();
  744. this.labels.push(loopLabel);
  745. node.body = this.parseStatement(false);
  746. this.labels.pop();
  747. this.expect(types._while);
  748. node.test = this.parseParenExpression();
  749. if (this.options.ecmaVersion >= 6)
  750. { this.eat(types.semi); }
  751. else
  752. { this.semicolon(); }
  753. return this.finishNode(node, "DoWhileStatement")
  754. };
  755. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  756. // loop is non-trivial. Basically, we have to parse the init `var`
  757. // statement or expression, disallowing the `in` operator (see
  758. // the second parameter to `parseExpression`), and then check
  759. // whether the next token is `in` or `of`. When there is no init
  760. // part (semicolon immediately after the opening parenthesis), it
  761. // is a regular `for` loop.
  762. pp$1.parseForStatement = function(node) {
  763. this.next();
  764. var awaitAt = (this.options.ecmaVersion >= 9 && this.inAsync && this.eatContextual("await")) ? this.lastTokStart : -1;
  765. this.labels.push(loopLabel);
  766. this.enterLexicalScope();
  767. this.expect(types.parenL);
  768. if (this.type === types.semi) {
  769. if (awaitAt > -1) { this.unexpected(awaitAt); }
  770. return this.parseFor(node, null)
  771. }
  772. var isLet = this.isLet();
  773. if (this.type === types._var || this.type === types._const || isLet) {
  774. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  775. this.next();
  776. this.parseVar(init$1, true, kind);
  777. this.finishNode(init$1, "VariableDeclaration");
  778. if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
  779. !(kind !== "var" && init$1.declarations[0].init)) {
  780. if (this.options.ecmaVersion >= 9) {
  781. if (this.type === types._in) {
  782. if (awaitAt > -1) { this.unexpected(awaitAt); }
  783. } else { node.await = awaitAt > -1; }
  784. }
  785. return this.parseForIn(node, init$1)
  786. }
  787. if (awaitAt > -1) { this.unexpected(awaitAt); }
  788. return this.parseFor(node, init$1)
  789. }
  790. var refDestructuringErrors = new DestructuringErrors;
  791. var init = this.parseExpression(true, refDestructuringErrors);
  792. if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  793. if (this.options.ecmaVersion >= 9) {
  794. if (this.type === types._in) {
  795. if (awaitAt > -1) { this.unexpected(awaitAt); }
  796. } else { node.await = awaitAt > -1; }
  797. }
  798. this.toAssignable(init, false, refDestructuringErrors);
  799. this.checkLVal(init);
  800. return this.parseForIn(node, init)
  801. } else {
  802. this.checkExpressionErrors(refDestructuringErrors, true);
  803. }
  804. if (awaitAt > -1) { this.unexpected(awaitAt); }
  805. return this.parseFor(node, init)
  806. };
  807. pp$1.parseFunctionStatement = function(node, isAsync) {
  808. this.next();
  809. return this.parseFunction(node, true, false, isAsync)
  810. };
  811. pp$1.parseIfStatement = function(node) {
  812. this.next();
  813. node.test = this.parseParenExpression();
  814. // allow function declarations in branches, but only in non-strict mode
  815. node.consequent = this.parseStatement(!this.strict && this.type == types._function);
  816. node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.type == types._function) : null;
  817. return this.finishNode(node, "IfStatement")
  818. };
  819. pp$1.parseReturnStatement = function(node) {
  820. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  821. { this.raise(this.start, "'return' outside of function"); }
  822. this.next();
  823. // In `return` (and `break`/`continue`), the keywords with
  824. // optional arguments, we eagerly look for a semicolon or the
  825. // possibility to insert one.
  826. if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
  827. else { node.argument = this.parseExpression(); this.semicolon(); }
  828. return this.finishNode(node, "ReturnStatement")
  829. };
  830. pp$1.parseSwitchStatement = function(node) {
  831. var this$1 = this;
  832. this.next();
  833. node.discriminant = this.parseParenExpression();
  834. node.cases = [];
  835. this.expect(types.braceL);
  836. this.labels.push(switchLabel);
  837. this.enterLexicalScope();
  838. // Statements under must be grouped (by label) in SwitchCase
  839. // nodes. `cur` is used to keep the node that we are currently
  840. // adding statements to.
  841. var cur;
  842. for (var sawDefault = false; this.type != types.braceR;) {
  843. if (this$1.type === types._case || this$1.type === types._default) {
  844. var isCase = this$1.type === types._case;
  845. if (cur) { this$1.finishNode(cur, "SwitchCase"); }
  846. node.cases.push(cur = this$1.startNode());
  847. cur.consequent = [];
  848. this$1.next();
  849. if (isCase) {
  850. cur.test = this$1.parseExpression();
  851. } else {
  852. if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
  853. sawDefault = true;
  854. cur.test = null;
  855. }
  856. this$1.expect(types.colon);
  857. } else {
  858. if (!cur) { this$1.unexpected(); }
  859. cur.consequent.push(this$1.parseStatement(true));
  860. }
  861. }
  862. this.exitLexicalScope();
  863. if (cur) { this.finishNode(cur, "SwitchCase"); }
  864. this.next(); // Closing brace
  865. this.labels.pop();
  866. return this.finishNode(node, "SwitchStatement")
  867. };
  868. pp$1.parseThrowStatement = function(node) {
  869. this.next();
  870. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  871. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  872. node.argument = this.parseExpression();
  873. this.semicolon();
  874. return this.finishNode(node, "ThrowStatement")
  875. };
  876. // Reused empty array added for node fields that are always empty.
  877. var empty = [];
  878. pp$1.parseTryStatement = function(node) {
  879. this.next();
  880. node.block = this.parseBlock();
  881. node.handler = null;
  882. if (this.type === types._catch) {
  883. var clause = this.startNode();
  884. this.next();
  885. this.expect(types.parenL);
  886. clause.param = this.parseBindingAtom();
  887. this.enterLexicalScope();
  888. this.checkLVal(clause.param, "let");
  889. this.expect(types.parenR);
  890. clause.body = this.parseBlock(false);
  891. this.exitLexicalScope();
  892. node.handler = this.finishNode(clause, "CatchClause");
  893. }
  894. node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
  895. if (!node.handler && !node.finalizer)
  896. { this.raise(node.start, "Missing catch or finally clause"); }
  897. return this.finishNode(node, "TryStatement")
  898. };
  899. pp$1.parseVarStatement = function(node, kind) {
  900. this.next();
  901. this.parseVar(node, false, kind);
  902. this.semicolon();
  903. return this.finishNode(node, "VariableDeclaration")
  904. };
  905. pp$1.parseWhileStatement = function(node) {
  906. this.next();
  907. node.test = this.parseParenExpression();
  908. this.labels.push(loopLabel);
  909. node.body = this.parseStatement(false);
  910. this.labels.pop();
  911. return this.finishNode(node, "WhileStatement")
  912. };
  913. pp$1.parseWithStatement = function(node) {
  914. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  915. this.next();
  916. node.object = this.parseParenExpression();
  917. node.body = this.parseStatement(false);
  918. return this.finishNode(node, "WithStatement")
  919. };
  920. pp$1.parseEmptyStatement = function(node) {
  921. this.next();
  922. return this.finishNode(node, "EmptyStatement")
  923. };
  924. pp$1.parseLabeledStatement = function(node, maybeName, expr) {
  925. var this$1 = this;
  926. for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
  927. {
  928. var label = list[i$1];
  929. if (label.name === maybeName)
  930. { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
  931. } }
  932. var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
  933. for (var i = this.labels.length - 1; i >= 0; i--) {
  934. var label$1 = this$1.labels[i];
  935. if (label$1.statementStart == node.start) {
  936. // Update information about previous labels on this node
  937. label$1.statementStart = this$1.start;
  938. label$1.kind = kind;
  939. } else { break }
  940. }
  941. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  942. node.body = this.parseStatement(true);
  943. if (node.body.type == "ClassDeclaration" ||
  944. node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
  945. node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
  946. { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
  947. this.labels.pop();
  948. node.label = expr;
  949. return this.finishNode(node, "LabeledStatement")
  950. };
  951. pp$1.parseExpressionStatement = function(node, expr) {
  952. node.expression = expr;
  953. this.semicolon();
  954. return this.finishNode(node, "ExpressionStatement")
  955. };
  956. // Parse a semicolon-enclosed block of statements, handling `"use
  957. // strict"` declarations when `allowStrict` is true (used for
  958. // function bodies).
  959. pp$1.parseBlock = function(createNewLexicalScope) {
  960. var this$1 = this;
  961. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  962. var node = this.startNode();
  963. node.body = [];
  964. this.expect(types.braceL);
  965. if (createNewLexicalScope) {
  966. this.enterLexicalScope();
  967. }
  968. while (!this.eat(types.braceR)) {
  969. var stmt = this$1.parseStatement(true);
  970. node.body.push(stmt);
  971. }
  972. if (createNewLexicalScope) {
  973. this.exitLexicalScope();
  974. }
  975. return this.finishNode(node, "BlockStatement")
  976. };
  977. // Parse a regular `for` loop. The disambiguation code in
  978. // `parseStatement` will already have parsed the init statement or
  979. // expression.
  980. pp$1.parseFor = function(node, init) {
  981. node.init = init;
  982. this.expect(types.semi);
  983. node.test = this.type === types.semi ? null : this.parseExpression();
  984. this.expect(types.semi);
  985. node.update = this.type === types.parenR ? null : this.parseExpression();
  986. this.expect(types.parenR);
  987. this.exitLexicalScope();
  988. node.body = this.parseStatement(false);
  989. this.labels.pop();
  990. return this.finishNode(node, "ForStatement")
  991. };
  992. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  993. // same from parser's perspective.
  994. pp$1.parseForIn = function(node, init) {
  995. var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
  996. this.next();
  997. if (type == "ForInStatement") {
  998. if (init.type === "AssignmentPattern" ||
  999. (init.type === "VariableDeclaration" && init.declarations[0].init != null &&
  1000. (this.strict || init.declarations[0].id.type !== "Identifier")))
  1001. { this.raise(init.start, "Invalid assignment in for-in loop head"); }
  1002. }
  1003. node.left = init;
  1004. node.right = type == "ForInStatement" ? this.parseExpression() : this.parseMaybeAssign();
  1005. this.expect(types.parenR);
  1006. this.exitLexicalScope();
  1007. node.body = this.parseStatement(false);
  1008. this.labels.pop();
  1009. return this.finishNode(node, type)
  1010. };
  1011. // Parse a list of variable declarations.
  1012. pp$1.parseVar = function(node, isFor, kind) {
  1013. var this$1 = this;
  1014. node.declarations = [];
  1015. node.kind = kind;
  1016. for (;;) {
  1017. var decl = this$1.startNode();
  1018. this$1.parseVarId(decl, kind);
  1019. if (this$1.eat(types.eq)) {
  1020. decl.init = this$1.parseMaybeAssign(isFor);
  1021. } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
  1022. this$1.unexpected();
  1023. } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
  1024. this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
  1025. } else {
  1026. decl.init = null;
  1027. }
  1028. node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
  1029. if (!this$1.eat(types.comma)) { break }
  1030. }
  1031. return node
  1032. };
  1033. pp$1.parseVarId = function(decl, kind) {
  1034. decl.id = this.parseBindingAtom(kind);
  1035. this.checkLVal(decl.id, kind, false);
  1036. };
  1037. // Parse a function declaration or literal (depending on the
  1038. // `isStatement` parameter).
  1039. pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
  1040. this.initFunction(node);
  1041. if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync)
  1042. { node.generator = this.eat(types.star); }
  1043. if (this.options.ecmaVersion >= 8)
  1044. { node.async = !!isAsync; }
  1045. if (isStatement) {
  1046. node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
  1047. if (node.id) {
  1048. this.checkLVal(node.id, "var");
  1049. }
  1050. }
  1051. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  1052. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  1053. this.inGenerator = node.generator;
  1054. this.inAsync = node.async;
  1055. this.yieldPos = 0;
  1056. this.awaitPos = 0;
  1057. this.inFunction = true;
  1058. this.enterFunctionScope();
  1059. if (!isStatement)
  1060. { node.id = this.type == types.name ? this.parseIdent() : null; }
  1061. this.parseFunctionParams(node);
  1062. this.parseFunctionBody(node, allowExpressionBody);
  1063. this.inGenerator = oldInGen;
  1064. this.inAsync = oldInAsync;
  1065. this.yieldPos = oldYieldPos;
  1066. this.awaitPos = oldAwaitPos;
  1067. this.inFunction = oldInFunc;
  1068. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
  1069. };
  1070. pp$1.parseFunctionParams = function(node) {
  1071. this.expect(types.parenL);
  1072. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  1073. this.checkYieldAwaitInDefaultParams();
  1074. };
  1075. // Parse a class declaration or literal (depending on the
  1076. // `isStatement` parameter).
  1077. pp$1.parseClass = function(node, isStatement) {
  1078. var this$1 = this;
  1079. this.next();
  1080. this.parseClassId(node, isStatement);
  1081. this.parseClassSuper(node);
  1082. var classBody = this.startNode();
  1083. var hadConstructor = false;
  1084. classBody.body = [];
  1085. this.expect(types.braceL);
  1086. while (!this.eat(types.braceR)) {
  1087. var member = this$1.parseClassMember(classBody);
  1088. if (member && member.type === "MethodDefinition" && member.kind === "constructor") {
  1089. if (hadConstructor) { this$1.raise(member.start, "Duplicate constructor in the same class"); }
  1090. hadConstructor = true;
  1091. }
  1092. }
  1093. node.body = this.finishNode(classBody, "ClassBody");
  1094. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1095. };
  1096. pp$1.parseClassMember = function(classBody) {
  1097. var this$1 = this;
  1098. if (this.eat(types.semi)) { return null }
  1099. var method = this.startNode();
  1100. var tryContextual = function (k, noLineBreak) {
  1101. if ( noLineBreak === void 0 ) noLineBreak = false;
  1102. var start = this$1.start, startLoc = this$1.startLoc;
  1103. if (!this$1.eatContextual(k)) { return false }
  1104. if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
  1105. if (method.key) { this$1.unexpected(); }
  1106. method.computed = false;
  1107. method.key = this$1.startNodeAt(start, startLoc);
  1108. method.key.name = k;
  1109. this$1.finishNode(method.key, "Identifier");
  1110. return false
  1111. };
  1112. method.kind = "method";
  1113. method.static = tryContextual("static");
  1114. var isGenerator = this.eat(types.star);
  1115. var isAsync = false;
  1116. if (!isGenerator) {
  1117. if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
  1118. isAsync = true;
  1119. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  1120. } else if (tryContextual("get")) {
  1121. method.kind = "get";
  1122. } else if (tryContextual("set")) {
  1123. method.kind = "set";
  1124. }
  1125. }
  1126. if (!method.key) { this.parsePropertyName(method); }
  1127. var key = method.key;
  1128. if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
  1129. key.type === "Literal" && key.value === "constructor")) {
  1130. if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
  1131. if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
  1132. if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
  1133. method.kind = "constructor";
  1134. } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
  1135. this.raise(key.start, "Classes may not have a static property named prototype");
  1136. }
  1137. this.parseClassMethod(classBody, method, isGenerator, isAsync);
  1138. if (method.kind === "get" && method.value.params.length !== 0)
  1139. { this.raiseRecoverable(method.value.start, "getter should have no params"); }
  1140. if (method.kind === "set" && method.value.params.length !== 1)
  1141. { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
  1142. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  1143. { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
  1144. return method
  1145. };
  1146. pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
  1147. method.value = this.parseMethod(isGenerator, isAsync);
  1148. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  1149. };
  1150. pp$1.parseClassId = function(node, isStatement) {
  1151. node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
  1152. };
  1153. pp$1.parseClassSuper = function(node) {
  1154. node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
  1155. };
  1156. // Parses module export declaration.
  1157. pp$1.parseExport = function(node, exports) {
  1158. var this$1 = this;
  1159. this.next();
  1160. // export * from '...'
  1161. if (this.eat(types.star)) {
  1162. this.expectContextual("from");
  1163. if (this.type !== types.string) { this.unexpected(); }
  1164. node.source = this.parseExprAtom();
  1165. this.semicolon();
  1166. return this.finishNode(node, "ExportAllDeclaration")
  1167. }
  1168. if (this.eat(types._default)) { // export default ...
  1169. this.checkExport(exports, "default", this.lastTokStart);
  1170. var isAsync;
  1171. if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
  1172. var fNode = this.startNode();
  1173. this.next();
  1174. if (isAsync) { this.next(); }
  1175. node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
  1176. } else if (this.type === types._class) {
  1177. var cNode = this.startNode();
  1178. node.declaration = this.parseClass(cNode, "nullableID");
  1179. } else {
  1180. node.declaration = this.parseMaybeAssign();
  1181. this.semicolon();
  1182. }
  1183. return this.finishNode(node, "ExportDefaultDeclaration")
  1184. }
  1185. // export var|const|let|function|class ...
  1186. if (this.shouldParseExportStatement()) {
  1187. node.declaration = this.parseStatement(true);
  1188. if (node.declaration.type === "VariableDeclaration")
  1189. { this.checkVariableExport(exports, node.declaration.declarations); }
  1190. else
  1191. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  1192. node.specifiers = [];
  1193. node.source = null;
  1194. } else { // export { x, y as z } [from '...']
  1195. node.declaration = null;
  1196. node.specifiers = this.parseExportSpecifiers(exports);
  1197. if (this.eatContextual("from")) {
  1198. if (this.type !== types.string) { this.unexpected(); }
  1199. node.source = this.parseExprAtom();
  1200. } else {
  1201. // check for keywords used as local names
  1202. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1203. var spec = list[i];
  1204. this$1.checkUnreserved(spec.local);
  1205. }
  1206. node.source = null;
  1207. }
  1208. this.semicolon();
  1209. }
  1210. return this.finishNode(node, "ExportNamedDeclaration")
  1211. };
  1212. pp$1.checkExport = function(exports, name, pos) {
  1213. if (!exports) { return }
  1214. if (has(exports, name))
  1215. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1216. exports[name] = true;
  1217. };
  1218. pp$1.checkPatternExport = function(exports, pat) {
  1219. var this$1 = this;
  1220. var type = pat.type;
  1221. if (type == "Identifier")
  1222. { this.checkExport(exports, pat.name, pat.start); }
  1223. else if (type == "ObjectPattern")
  1224. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1225. {
  1226. var prop = list[i];
  1227. this$1.checkPatternExport(exports, prop);
  1228. } }
  1229. else if (type == "ArrayPattern")
  1230. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1231. var elt = list$1[i$1];
  1232. if (elt) { this$1.checkPatternExport(exports, elt); }
  1233. } }
  1234. else if (type == "Property")
  1235. { this.checkPatternExport(exports, pat.value); }
  1236. else if (type == "AssignmentPattern")
  1237. { this.checkPatternExport(exports, pat.left); }
  1238. else if (type == "RestElement")
  1239. { this.checkPatternExport(exports, pat.argument); }
  1240. else if (type == "ParenthesizedExpression")
  1241. { this.checkPatternExport(exports, pat.expression); }
  1242. };
  1243. pp$1.checkVariableExport = function(exports, decls) {
  1244. var this$1 = this;
  1245. if (!exports) { return }
  1246. for (var i = 0, list = decls; i < list.length; i += 1)
  1247. {
  1248. var decl = list[i];
  1249. this$1.checkPatternExport(exports, decl.id);
  1250. }
  1251. };
  1252. pp$1.shouldParseExportStatement = function() {
  1253. return this.type.keyword === "var" ||
  1254. this.type.keyword === "const" ||
  1255. this.type.keyword === "class" ||
  1256. this.type.keyword === "function" ||
  1257. this.isLet() ||
  1258. this.isAsyncFunction()
  1259. };
  1260. // Parses a comma-separated list of module exports.
  1261. pp$1.parseExportSpecifiers = function(exports) {
  1262. var this$1 = this;
  1263. var nodes = [], first = true;
  1264. // export { x, y as z } [from '...']
  1265. this.expect(types.braceL);
  1266. while (!this.eat(types.braceR)) {
  1267. if (!first) {
  1268. this$1.expect(types.comma);
  1269. if (this$1.afterTrailingComma(types.braceR)) { break }
  1270. } else { first = false; }
  1271. var node = this$1.startNode();
  1272. node.local = this$1.parseIdent(true);
  1273. node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
  1274. this$1.checkExport(exports, node.exported.name, node.exported.start);
  1275. nodes.push(this$1.finishNode(node, "ExportSpecifier"));
  1276. }
  1277. return nodes
  1278. };
  1279. // Parses import declaration.
  1280. pp$1.parseImport = function(node) {
  1281. this.next();
  1282. // import '...'
  1283. if (this.type === types.string) {
  1284. node.specifiers = empty;
  1285. node.source = this.parseExprAtom();
  1286. } else {
  1287. node.specifiers = this.parseImportSpecifiers();
  1288. this.expectContextual("from");
  1289. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1290. }
  1291. this.semicolon();
  1292. return this.finishNode(node, "ImportDeclaration")
  1293. };
  1294. // Parses a comma-separated list of module imports.
  1295. pp$1.parseImportSpecifiers = function() {
  1296. var this$1 = this;
  1297. var nodes = [], first = true;
  1298. if (this.type === types.name) {
  1299. // import defaultObj, { x, y as z } from '...'
  1300. var node = this.startNode();
  1301. node.local = this.parseIdent();
  1302. this.checkLVal(node.local, "let");
  1303. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1304. if (!this.eat(types.comma)) { return nodes }
  1305. }
  1306. if (this.type === types.star) {
  1307. var node$1 = this.startNode();
  1308. this.next();
  1309. this.expectContextual("as");
  1310. node$1.local = this.parseIdent();
  1311. this.checkLVal(node$1.local, "let");
  1312. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1313. return nodes
  1314. }
  1315. this.expect(types.braceL);
  1316. while (!this.eat(types.braceR)) {
  1317. if (!first) {
  1318. this$1.expect(types.comma);
  1319. if (this$1.afterTrailingComma(types.braceR)) { break }
  1320. } else { first = false; }
  1321. var node$2 = this$1.startNode();
  1322. node$2.imported = this$1.parseIdent(true);
  1323. if (this$1.eatContextual("as")) {
  1324. node$2.local = this$1.parseIdent();
  1325. } else {
  1326. this$1.checkUnreserved(node$2.imported);
  1327. node$2.local = node$2.imported;
  1328. }
  1329. this$1.checkLVal(node$2.local, "let");
  1330. nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
  1331. }
  1332. return nodes
  1333. };
  1334. // Set `ExpressionStatement#directive` property for directive prologues.
  1335. pp$1.adaptDirectivePrologue = function(statements) {
  1336. for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
  1337. statements[i].directive = statements[i].expression.raw.slice(1, -1);
  1338. }
  1339. };
  1340. pp$1.isDirectiveCandidate = function(statement) {
  1341. return (
  1342. statement.type === "ExpressionStatement" &&
  1343. statement.expression.type === "Literal" &&
  1344. typeof statement.expression.value === "string" &&
  1345. // Reject parenthesized strings.
  1346. (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
  1347. )
  1348. };
  1349. var pp$2 = Parser.prototype;
  1350. // Convert existing expression atom to assignable pattern
  1351. // if possible.
  1352. pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
  1353. var this$1 = this;
  1354. if (this.options.ecmaVersion >= 6 && node) {
  1355. switch (node.type) {
  1356. case "Identifier":
  1357. if (this.inAsync && node.name === "await")
  1358. { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
  1359. break
  1360. case "ObjectPattern":
  1361. case "ArrayPattern":
  1362. case "RestElement":
  1363. break
  1364. case "ObjectExpression":
  1365. node.type = "ObjectPattern";
  1366. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1367. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1368. var prop = list[i];
  1369. this$1.toAssignable(prop, isBinding);
  1370. // Early error:
  1371. // AssignmentRestProperty[Yield, Await] :
  1372. // `...` DestructuringAssignmentTarget[Yield, Await]
  1373. //
  1374. // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
  1375. if (
  1376. prop.type === "RestElement" &&
  1377. (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
  1378. ) {
  1379. this$1.raise(prop.argument.start, "Unexpected token");
  1380. }
  1381. }
  1382. break
  1383. case "Property":
  1384. // AssignmentProperty has type == "Property"
  1385. if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
  1386. this.toAssignable(node.value, isBinding);
  1387. break
  1388. case "ArrayExpression":
  1389. node.type = "ArrayPattern";
  1390. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1391. this.toAssignableList(node.elements, isBinding);
  1392. break
  1393. case "SpreadElement":
  1394. node.type = "RestElement";
  1395. this.toAssignable(node.argument, isBinding);
  1396. if (node.argument.type === "AssignmentPattern")
  1397. { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
  1398. break
  1399. case "AssignmentExpression":
  1400. if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
  1401. node.type = "AssignmentPattern";
  1402. delete node.operator;
  1403. this.toAssignable(node.left, isBinding);
  1404. // falls through to AssignmentPattern
  1405. case "AssignmentPattern":
  1406. break
  1407. case "ParenthesizedExpression":
  1408. this.toAssignable(node.expression, isBinding);
  1409. break
  1410. case "MemberExpression":
  1411. if (!isBinding) { break }
  1412. default:
  1413. this.raise(node.start, "Assigning to rvalue");
  1414. }
  1415. } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1416. return node
  1417. };
  1418. // Convert list of expression atoms to binding list.
  1419. pp$2.toAssignableList = function(exprList, isBinding) {
  1420. var this$1 = this;
  1421. var end = exprList.length;
  1422. for (var i = 0; i < end; i++) {
  1423. var elt = exprList[i];
  1424. if (elt) { this$1.toAssignable(elt, isBinding); }
  1425. }
  1426. if (end) {
  1427. var last = exprList[end - 1];
  1428. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1429. { this.unexpected(last.argument.start); }
  1430. }
  1431. return exprList
  1432. };
  1433. // Parses spread element.
  1434. pp$2.parseSpread = function(refDestructuringErrors) {
  1435. var node = this.startNode();
  1436. this.next();
  1437. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1438. return this.finishNode(node, "SpreadElement")
  1439. };
  1440. pp$2.parseRestBinding = function() {
  1441. var node = this.startNode();
  1442. this.next();
  1443. // RestElement inside of a function parameter must be an identifier
  1444. if (this.options.ecmaVersion === 6 && this.type !== types.name)
  1445. { this.unexpected(); }
  1446. node.argument = this.parseBindingAtom();
  1447. return this.finishNode(node, "RestElement")
  1448. };
  1449. // Parses lvalue (assignable) atom.
  1450. pp$2.parseBindingAtom = function() {
  1451. if (this.options.ecmaVersion >= 6) {
  1452. switch (this.type) {
  1453. case types.bracketL:
  1454. var node = this.startNode();
  1455. this.next();
  1456. node.elements = this.parseBindingList(types.bracketR, true, true);
  1457. return this.finishNode(node, "ArrayPattern")
  1458. case types.braceL:
  1459. return this.parseObj(true)
  1460. }
  1461. }
  1462. return this.parseIdent()
  1463. };
  1464. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1465. var this$1 = this;
  1466. var elts = [], first = true;
  1467. while (!this.eat(close)) {
  1468. if (first) { first = false; }
  1469. else { this$1.expect(types.comma); }
  1470. if (allowEmpty && this$1.type === types.comma) {
  1471. elts.push(null);
  1472. } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
  1473. break
  1474. } else if (this$1.type === types.ellipsis) {
  1475. var rest = this$1.parseRestBinding();
  1476. this$1.parseBindingListItem(rest);
  1477. elts.push(rest);
  1478. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1479. this$1.expect(close);
  1480. break
  1481. } else {
  1482. var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
  1483. this$1.parseBindingListItem(elem);
  1484. elts.push(elem);
  1485. }
  1486. }
  1487. return elts
  1488. };
  1489. pp$2.parseBindingListItem = function(param) {
  1490. return param
  1491. };
  1492. // Parses assignment pattern around given atom if possible.
  1493. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  1494. left = left || this.parseBindingAtom();
  1495. if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
  1496. var node = this.startNodeAt(startPos, startLoc);
  1497. node.left = left;
  1498. node.right = this.parseMaybeAssign();
  1499. return this.finishNode(node, "AssignmentPattern")
  1500. };
  1501. // Verify that a node is an lval — something that can be assigned
  1502. // to.
  1503. // bindingType can be either:
  1504. // 'var' indicating that the lval creates a 'var' binding
  1505. // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
  1506. // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
  1507. pp$2.checkLVal = function(expr, bindingType, checkClashes) {
  1508. var this$1 = this;
  1509. switch (expr.type) {
  1510. case "Identifier":
  1511. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1512. { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1513. if (checkClashes) {
  1514. if (has(checkClashes, expr.name))
  1515. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1516. checkClashes[expr.name] = true;
  1517. }
  1518. if (bindingType && bindingType !== "none") {
  1519. if (
  1520. bindingType === "var" && !this.canDeclareVarName(expr.name) ||
  1521. bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
  1522. ) {
  1523. this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
  1524. }
  1525. if (bindingType === "var") {
  1526. this.declareVarName(expr.name);
  1527. } else {
  1528. this.declareLexicalName(expr.name);
  1529. }
  1530. }
  1531. break
  1532. case "MemberExpression":
  1533. if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
  1534. break
  1535. case "ObjectPattern":
  1536. for (var i = 0, list = expr.properties; i < list.length; i += 1)
  1537. {
  1538. var prop = list[i];
  1539. this$1.checkLVal(prop, bindingType, checkClashes);
  1540. }
  1541. break
  1542. case "Property":
  1543. // AssignmentProperty has type == "Property"
  1544. this.checkLVal(expr.value, bindingType, checkClashes);
  1545. break
  1546. case "ArrayPattern":
  1547. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1548. var elem = list$1[i$1];
  1549. if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
  1550. }
  1551. break
  1552. case "AssignmentPattern":
  1553. this.checkLVal(expr.left, bindingType, checkClashes);
  1554. break
  1555. case "RestElement":
  1556. this.checkLVal(expr.argument, bindingType, checkClashes);
  1557. break
  1558. case "ParenthesizedExpression":
  1559. this.checkLVal(expr.expression, bindingType, checkClashes);
  1560. break
  1561. default:
  1562. this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
  1563. }
  1564. };
  1565. // A recursive descent parser operates by defining functions for all
  1566. // syntactic elements, and recursively calling those, each function
  1567. // advancing the input stream and returning an AST node. Precedence
  1568. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  1569. // instead of `(!x)[1]` is handled by the fact that the parser
  1570. // function that parses unary prefix operators is called first, and
  1571. // in turn calls the function that parses `[]` subscripts — that
  1572. // way, it'll receive the node for `x[1]` already parsed, and wraps
  1573. // *that* in the unary operator node.
  1574. //
  1575. // Acorn uses an [operator precedence parser][opp] to handle binary
  1576. // operator precedence, because it is much more compact than using
  1577. // the technique outlined above, which uses different, nesting
  1578. // functions to specify precedence, for all of the ten binary
  1579. // precedence levels that JavaScript defines.
  1580. //
  1581. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  1582. var pp$3 = Parser.prototype;
  1583. // Check if property name clashes with already added.
  1584. // Object/class getters and setters are not allowed to clash —
  1585. // either with each other or with an init property — and in
  1586. // strict mode, init properties are also not allowed to be repeated.
  1587. pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
  1588. if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
  1589. { return }
  1590. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  1591. { return }
  1592. var key = prop.key;
  1593. var name;
  1594. switch (key.type) {
  1595. case "Identifier": name = key.name; break
  1596. case "Literal": name = String(key.value); break
  1597. default: return
  1598. }
  1599. var kind = prop.kind;
  1600. if (this.options.ecmaVersion >= 6) {
  1601. if (name === "__proto__" && kind === "init") {
  1602. if (propHash.proto) {
  1603. if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) { refDestructuringErrors.doubleProto = key.start; }
  1604. // Backwards-compat kludge. Can be removed in version 6.0
  1605. else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
  1606. }
  1607. propHash.proto = true;
  1608. }
  1609. return
  1610. }
  1611. name = "$" + name;
  1612. var other = propHash[name];
  1613. if (other) {
  1614. var redefinition;
  1615. if (kind === "init") {
  1616. redefinition = this.strict && other.init || other.get || other.set;
  1617. } else {
  1618. redefinition = other.init || other[kind];
  1619. }
  1620. if (redefinition)
  1621. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  1622. } else {
  1623. other = propHash[name] = {
  1624. init: false,
  1625. get: false,
  1626. set: false
  1627. };
  1628. }
  1629. other[kind] = true;
  1630. };
  1631. // ### Expression parsing
  1632. // These nest, from the most general expression type at the top to
  1633. // 'atomic', nondivisible expression types at the bottom. Most of
  1634. // the functions will simply let the function(s) below them parse,
  1635. // and, *if* the syntactic construct they handle is present, wrap
  1636. // the AST node that the inner parser gave them in another node.
  1637. // Parse a full expression. The optional arguments are used to
  1638. // forbid the `in` operator (in for loops initalization expressions)
  1639. // and provide reference for storing '=' operator inside shorthand
  1640. // property assignment in contexts where both object expression
  1641. // and object pattern might appear (so it's possible to raise
  1642. // delayed syntax error at correct position).
  1643. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  1644. var this$1 = this;
  1645. var startPos = this.start, startLoc = this.startLoc;
  1646. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  1647. if (this.type === types.comma) {
  1648. var node = this.startNodeAt(startPos, startLoc);
  1649. node.expressions = [expr];
  1650. while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
  1651. return this.finishNode(node, "SequenceExpression")
  1652. }
  1653. return expr
  1654. };
  1655. // Parse an assignment expression. This includes applications of
  1656. // operators like `+=`.
  1657. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  1658. if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
  1659. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
  1660. if (refDestructuringErrors) {
  1661. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  1662. oldTrailingComma = refDestructuringErrors.trailingComma;
  1663. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  1664. } else {
  1665. refDestructuringErrors = new DestructuringErrors;
  1666. ownDestructuringErrors = true;
  1667. }
  1668. var startPos = this.start, startLoc = this.startLoc;
  1669. if (this.type == types.parenL || this.type == types.name)
  1670. { this.potentialArrowAt = this.start; }
  1671. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  1672. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  1673. if (this.type.isAssign) {
  1674. var node = this.startNodeAt(startPos, startLoc);
  1675. node.operator = this.value;
  1676. node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
  1677. if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
  1678. refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
  1679. this.checkLVal(left);
  1680. this.next();
  1681. node.right = this.parseMaybeAssign(noIn);
  1682. return this.finishNode(node, "AssignmentExpression")
  1683. } else {
  1684. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  1685. }
  1686. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  1687. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  1688. return left
  1689. };
  1690. // Parse a ternary conditional (`?:`) operator.
  1691. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  1692. var startPos = this.start, startLoc = this.startLoc;
  1693. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  1694. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1695. if (this.eat(types.question)) {
  1696. var node = this.startNodeAt(startPos, startLoc);
  1697. node.test = expr;
  1698. node.consequent = this.parseMaybeAssign();
  1699. this.expect(types.colon);
  1700. node.alternate = this.parseMaybeAssign(noIn);
  1701. return this.finishNode(node, "ConditionalExpression")
  1702. }
  1703. return expr
  1704. };
  1705. // Start the precedence parser.
  1706. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  1707. var startPos = this.start, startLoc = this.startLoc;
  1708. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  1709. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1710. return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  1711. };
  1712. // Parse binary operators with the operator precedence parsing
  1713. // algorithm. `left` is the left-hand side of the operator.
  1714. // `minPrec` provides context that allows the function to stop and
  1715. // defer further parser to one of its callers when it encounters an
  1716. // operator that has a lower precedence than the set it is parsing.
  1717. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  1718. var prec = this.type.binop;
  1719. if (prec != null && (!noIn || this.type !== types._in)) {
  1720. if (prec > minPrec) {
  1721. var logical = this.type === types.logicalOR || this.type === types.logicalAND;
  1722. var op = this.value;
  1723. this.next();
  1724. var startPos = this.start, startLoc = this.startLoc;
  1725. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  1726. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  1727. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  1728. }
  1729. }
  1730. return left
  1731. };
  1732. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  1733. var node = this.startNodeAt(startPos, startLoc);
  1734. node.left = left;
  1735. node.operator = op;
  1736. node.right = right;
  1737. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  1738. };
  1739. // Parse unary operators, both prefix and postfix.
  1740. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  1741. var this$1 = this;
  1742. var startPos = this.start, startLoc = this.startLoc, expr;
  1743. if (this.inAsync && this.isContextual("await")) {
  1744. expr = this.parseAwait();
  1745. sawUnary = true;
  1746. } else if (this.type.prefix) {
  1747. var node = this.startNode(), update = this.type === types.incDec;
  1748. node.operator = this.value;
  1749. node.prefix = true;
  1750. this.next();
  1751. node.argument = this.parseMaybeUnary(null, true);
  1752. this.checkExpressionErrors(refDestructuringErrors, true);
  1753. if (update) { this.checkLVal(node.argument); }
  1754. else if (this.strict && node.operator === "delete" &&
  1755. node.argument.type === "Identifier")
  1756. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  1757. else { sawUnary = true; }
  1758. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  1759. } else {
  1760. expr = this.parseExprSubscripts(refDestructuringErrors);
  1761. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1762. while (this.type.postfix && !this.canInsertSemicolon()) {
  1763. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1764. node$1.operator = this$1.value;
  1765. node$1.prefix = false;
  1766. node$1.argument = expr;
  1767. this$1.checkLVal(expr);
  1768. this$1.next();
  1769. expr = this$1.finishNode(node$1, "UpdateExpression");
  1770. }
  1771. }
  1772. if (!sawUnary && this.eat(types.starstar))
  1773. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
  1774. else
  1775. { return expr }
  1776. };
  1777. // Parse call, dot, and `[]`-subscript expressions.
  1778. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  1779. var startPos = this.start, startLoc = this.startLoc;
  1780. var expr = this.parseExprAtom(refDestructuringErrors);
  1781. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  1782. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
  1783. var result = this.parseSubscripts(expr, startPos, startLoc);
  1784. if (refDestructuringErrors && result.type === "MemberExpression") {
  1785. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  1786. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  1787. }
  1788. return result
  1789. };
  1790. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  1791. var this$1 = this;
  1792. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  1793. this.lastTokEnd == base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async";
  1794. for (var computed = (void 0);;) {
  1795. if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
  1796. var node = this$1.startNodeAt(startPos, startLoc);
  1797. node.object = base;
  1798. node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
  1799. node.computed = !!computed;
  1800. if (computed) { this$1.expect(types.bracketR); }
  1801. base = this$1.finishNode(node, "MemberExpression");
  1802. } else if (!noCalls && this$1.eat(types.parenL)) {
  1803. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
  1804. this$1.yieldPos = 0;
  1805. this$1.awaitPos = 0;
  1806. var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
  1807. if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
  1808. this$1.checkPatternErrors(refDestructuringErrors, false);
  1809. this$1.checkYieldAwaitInDefaultParams();
  1810. this$1.yieldPos = oldYieldPos;
  1811. this$1.awaitPos = oldAwaitPos;
  1812. return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
  1813. }
  1814. this$1.checkExpressionErrors(refDestructuringErrors, true);
  1815. this$1.yieldPos = oldYieldPos || this$1.yieldPos;
  1816. this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
  1817. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1818. node$1.callee = base;
  1819. node$1.arguments = exprList;
  1820. base = this$1.finishNode(node$1, "CallExpression");
  1821. } else if (this$1.type === types.backQuote) {
  1822. var node$2 = this$1.startNodeAt(startPos, startLoc);
  1823. node$2.tag = base;
  1824. node$2.quasi = this$1.parseTemplate({isTagged: true});
  1825. base = this$1.finishNode(node$2, "TaggedTemplateExpression");
  1826. } else {
  1827. return base
  1828. }
  1829. }
  1830. };
  1831. // Parse an atomic expression — either a single token that is an
  1832. // expression, an expression started by a keyword like `function` or
  1833. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  1834. // or `{}`.
  1835. pp$3.parseExprAtom = function(refDestructuringErrors) {
  1836. var node, canBeArrow = this.potentialArrowAt == this.start;
  1837. switch (this.type) {
  1838. case types._super:
  1839. if (!this.inFunction)
  1840. { this.raise(this.start, "'super' outside of function or class"); }
  1841. node = this.startNode();
  1842. this.next();
  1843. // The `super` keyword can appear at below:
  1844. // SuperProperty:
  1845. // super [ Expression ]
  1846. // super . IdentifierName
  1847. // SuperCall:
  1848. // super Arguments
  1849. if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
  1850. { this.unexpected(); }
  1851. return this.finishNode(node, "Super")
  1852. case types._this:
  1853. node = this.startNode();
  1854. this.next();
  1855. return this.finishNode(node, "ThisExpression")
  1856. case types.name:
  1857. var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
  1858. var id = this.parseIdent(this.type !== types.name);
  1859. if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
  1860. { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
  1861. if (canBeArrow && !this.canInsertSemicolon()) {
  1862. if (this.eat(types.arrow))
  1863. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
  1864. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
  1865. id = this.parseIdent();
  1866. if (this.canInsertSemicolon() || !this.eat(types.arrow))
  1867. { this.unexpected(); }
  1868. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
  1869. }
  1870. }
  1871. return id
  1872. case types.regexp:
  1873. var value = this.value;
  1874. node = this.parseLiteral(value.value);
  1875. node.regex = {pattern: value.pattern, flags: value.flags};
  1876. return node
  1877. case types.num: case types.string:
  1878. return this.parseLiteral(this.value)
  1879. case types._null: case types._true: case types._false:
  1880. node = this.startNode();
  1881. node.value = this.type === types._null ? null : this.type === types._true;
  1882. node.raw = this.type.keyword;
  1883. this.next();
  1884. return this.finishNode(node, "Literal")
  1885. case types.parenL:
  1886. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
  1887. if (refDestructuringErrors) {
  1888. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  1889. { refDestructuringErrors.parenthesizedAssign = start; }
  1890. if (refDestructuringErrors.parenthesizedBind < 0)
  1891. { refDestructuringErrors.parenthesizedBind = start; }
  1892. }
  1893. return expr
  1894. case types.bracketL:
  1895. node = this.startNode();
  1896. this.next();
  1897. node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
  1898. return this.finishNode(node, "ArrayExpression")
  1899. case types.braceL:
  1900. return this.parseObj(false, refDestructuringErrors)
  1901. case types._function:
  1902. node = this.startNode();
  1903. this.next();
  1904. return this.parseFunction(node, false)
  1905. case types._class:
  1906. return this.parseClass(this.startNode(), false)
  1907. case types._new:
  1908. return this.parseNew()
  1909. case types.backQuote:
  1910. return this.parseTemplate()
  1911. default:
  1912. this.unexpected();
  1913. }
  1914. };
  1915. pp$3.parseLiteral = function(value) {
  1916. var node = this.startNode();
  1917. node.value = value;
  1918. node.raw = this.input.slice(this.start, this.end);
  1919. this.next();
  1920. return this.finishNode(node, "Literal")
  1921. };
  1922. pp$3.parseParenExpression = function() {
  1923. this.expect(types.parenL);
  1924. var val = this.parseExpression();
  1925. this.expect(types.parenR);
  1926. return val
  1927. };
  1928. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  1929. var this$1 = this;
  1930. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  1931. if (this.options.ecmaVersion >= 6) {
  1932. this.next();
  1933. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  1934. var exprList = [], first = true, lastIsComma = false;
  1935. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
  1936. this.yieldPos = 0;
  1937. this.awaitPos = 0;
  1938. while (this.type !== types.parenR) {
  1939. first ? first = false : this$1.expect(types.comma);
  1940. if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
  1941. lastIsComma = true;
  1942. break
  1943. } else if (this$1.type === types.ellipsis) {
  1944. spreadStart = this$1.start;
  1945. exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
  1946. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1947. break
  1948. } else {
  1949. exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
  1950. }
  1951. }
  1952. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  1953. this.expect(types.parenR);
  1954. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  1955. this.checkPatternErrors(refDestructuringErrors, false);
  1956. this.checkYieldAwaitInDefaultParams();
  1957. this.yieldPos = oldYieldPos;
  1958. this.awaitPos = oldAwaitPos;
  1959. return this.parseParenArrowList(startPos, startLoc, exprList)
  1960. }
  1961. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  1962. if (spreadStart) { this.unexpected(spreadStart); }
  1963. this.checkExpressionErrors(refDestructuringErrors, true);
  1964. this.yieldPos = oldYieldPos || this.yieldPos;
  1965. this.awaitPos = oldAwaitPos || this.awaitPos;
  1966. if (exprList.length > 1) {
  1967. val = this.startNodeAt(innerStartPos, innerStartLoc);
  1968. val.expressions = exprList;
  1969. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  1970. } else {
  1971. val = exprList[0];
  1972. }
  1973. } else {
  1974. val = this.parseParenExpression();
  1975. }
  1976. if (this.options.preserveParens) {
  1977. var par = this.startNodeAt(startPos, startLoc);
  1978. par.expression = val;
  1979. return this.finishNode(par, "ParenthesizedExpression")
  1980. } else {
  1981. return val
  1982. }
  1983. };
  1984. pp$3.parseParenItem = function(item) {
  1985. return item
  1986. };
  1987. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  1988. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  1989. };
  1990. // New's precedence is slightly tricky. It must allow its argument to
  1991. // be a `[]` or dot subscript expression, but not a call — at least,
  1992. // not without wrapping it in parentheses. Thus, it uses the noCalls
  1993. // argument to parseSubscripts to prevent it from consuming the
  1994. // argument list.
  1995. var empty$1 = [];
  1996. pp$3.parseNew = function() {
  1997. var node = this.startNode();
  1998. var meta = this.parseIdent(true);
  1999. if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
  2000. node.meta = meta;
  2001. var containsEsc = this.containsEsc;
  2002. node.property = this.parseIdent(true);
  2003. if (node.property.name !== "target" || containsEsc)
  2004. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
  2005. if (!this.inFunction)
  2006. { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
  2007. return this.finishNode(node, "MetaProperty")
  2008. }
  2009. var startPos = this.start, startLoc = this.startLoc;
  2010. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  2011. if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
  2012. else { node.arguments = empty$1; }
  2013. return this.finishNode(node, "NewExpression")
  2014. };
  2015. // Parse template expression.
  2016. pp$3.parseTemplateElement = function(ref) {
  2017. var isTagged = ref.isTagged;
  2018. var elem = this.startNode();
  2019. if (this.type === types.invalidTemplate) {
  2020. if (!isTagged) {
  2021. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  2022. }
  2023. elem.value = {
  2024. raw: this.value,
  2025. cooked: null
  2026. };
  2027. } else {
  2028. elem.value = {
  2029. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  2030. cooked: this.value
  2031. };
  2032. }
  2033. this.next();
  2034. elem.tail = this.type === types.backQuote;
  2035. return this.finishNode(elem, "TemplateElement")
  2036. };
  2037. pp$3.parseTemplate = function(ref) {
  2038. var this$1 = this;
  2039. if ( ref === void 0 ) ref = {};
  2040. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  2041. var node = this.startNode();
  2042. this.next();
  2043. node.expressions = [];
  2044. var curElt = this.parseTemplateElement({isTagged: isTagged});
  2045. node.quasis = [curElt];
  2046. while (!curElt.tail) {
  2047. this$1.expect(types.dollarBraceL);
  2048. node.expressions.push(this$1.parseExpression());
  2049. this$1.expect(types.braceR);
  2050. node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
  2051. }
  2052. this.next();
  2053. return this.finishNode(node, "TemplateLiteral")
  2054. };
  2055. pp$3.isAsyncProp = function(prop) {
  2056. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  2057. (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)) &&
  2058. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2059. };
  2060. // Parse an object literal or binding pattern.
  2061. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  2062. var this$1 = this;
  2063. var node = this.startNode(), first = true, propHash = {};
  2064. node.properties = [];
  2065. this.next();
  2066. while (!this.eat(types.braceR)) {
  2067. if (!first) {
  2068. this$1.expect(types.comma);
  2069. if (this$1.afterTrailingComma(types.braceR)) { break }
  2070. } else { first = false; }
  2071. var prop = this$1.parseProperty(isPattern, refDestructuringErrors);
  2072. if (!isPattern) { this$1.checkPropClash(prop, propHash, refDestructuringErrors); }
  2073. node.properties.push(prop);
  2074. }
  2075. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  2076. };
  2077. pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
  2078. var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
  2079. if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
  2080. if (isPattern) {
  2081. prop.argument = this.parseIdent(false);
  2082. if (this.type === types.comma) {
  2083. this.raise(this.start, "Comma is not permitted after the rest element");
  2084. }
  2085. return this.finishNode(prop, "RestElement")
  2086. }
  2087. // To disallow parenthesized identifier via `this.toAssignable()`.
  2088. if (this.type === types.parenL && refDestructuringErrors) {
  2089. if (refDestructuringErrors.parenthesizedAssign < 0) {
  2090. refDestructuringErrors.parenthesizedAssign = this.start;
  2091. }
  2092. if (refDestructuringErrors.parenthesizedBind < 0) {
  2093. refDestructuringErrors.parenthesizedBind = this.start;
  2094. }
  2095. }
  2096. // Parse argument.
  2097. prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2098. // To disallow trailing comma via `this.toAssignable()`.
  2099. if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
  2100. refDestructuringErrors.trailingComma = this.start;
  2101. }
  2102. // Finish
  2103. return this.finishNode(prop, "SpreadElement")
  2104. }
  2105. if (this.options.ecmaVersion >= 6) {
  2106. prop.method = false;
  2107. prop.shorthand = false;
  2108. if (isPattern || refDestructuringErrors) {
  2109. startPos = this.start;
  2110. startLoc = this.startLoc;
  2111. }
  2112. if (!isPattern)
  2113. { isGenerator = this.eat(types.star); }
  2114. }
  2115. var containsEsc = this.containsEsc;
  2116. this.parsePropertyName(prop);
  2117. if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
  2118. isAsync = true;
  2119. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  2120. this.parsePropertyName(prop, refDestructuringErrors);
  2121. } else {
  2122. isAsync = false;
  2123. }
  2124. this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
  2125. return this.finishNode(prop, "Property")
  2126. };
  2127. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
  2128. if ((isGenerator || isAsync) && this.type === types.colon)
  2129. { this.unexpected(); }
  2130. if (this.eat(types.colon)) {
  2131. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  2132. prop.kind = "init";
  2133. } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
  2134. if (isPattern) { this.unexpected(); }
  2135. prop.kind = "init";
  2136. prop.method = true;
  2137. prop.value = this.parseMethod(isGenerator, isAsync);
  2138. } else if (!isPattern && !containsEsc &&
  2139. this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2140. (prop.key.name === "get" || prop.key.name === "set") &&
  2141. (this.type != types.comma && this.type != types.braceR)) {
  2142. if (isGenerator || isAsync) { this.unexpected(); }
  2143. prop.kind = prop.key.name;
  2144. this.parsePropertyName(prop);
  2145. prop.value = this.parseMethod(false);
  2146. var paramCount = prop.kind === "get" ? 0 : 1;
  2147. if (prop.value.params.length !== paramCount) {
  2148. var start = prop.value.start;
  2149. if (prop.kind === "get")
  2150. { this.raiseRecoverable(start, "getter should have no params"); }
  2151. else
  2152. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2153. } else {
  2154. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2155. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2156. }
  2157. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2158. this.checkUnreserved(prop.key);
  2159. prop.kind = "init";
  2160. if (isPattern) {
  2161. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2162. } else if (this.type === types.eq && refDestructuringErrors) {
  2163. if (refDestructuringErrors.shorthandAssign < 0)
  2164. { refDestructuringErrors.shorthandAssign = this.start; }
  2165. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2166. } else {
  2167. prop.value = prop.key;
  2168. }
  2169. prop.shorthand = true;
  2170. } else { this.unexpected(); }
  2171. };
  2172. pp$3.parsePropertyName = function(prop) {
  2173. if (this.options.ecmaVersion >= 6) {
  2174. if (this.eat(types.bracketL)) {
  2175. prop.computed = true;
  2176. prop.key = this.parseMaybeAssign();
  2177. this.expect(types.bracketR);
  2178. return prop.key
  2179. } else {
  2180. prop.computed = false;
  2181. }
  2182. }
  2183. return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
  2184. };
  2185. // Initialize empty function node.
  2186. pp$3.initFunction = function(node) {
  2187. node.id = null;
  2188. if (this.options.ecmaVersion >= 6) {
  2189. node.generator = false;
  2190. node.expression = false;
  2191. }
  2192. if (this.options.ecmaVersion >= 8)
  2193. { node.async = false; }
  2194. };
  2195. // Parse object or class method.
  2196. pp$3.parseMethod = function(isGenerator, isAsync) {
  2197. var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2198. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2199. this.initFunction(node);
  2200. if (this.options.ecmaVersion >= 6)
  2201. { node.generator = isGenerator; }
  2202. if (this.options.ecmaVersion >= 8)
  2203. { node.async = !!isAsync; }
  2204. this.inGenerator = node.generator;
  2205. this.inAsync = node.async;
  2206. this.yieldPos = 0;
  2207. this.awaitPos = 0;
  2208. this.inFunction = true;
  2209. this.enterFunctionScope();
  2210. this.expect(types.parenL);
  2211. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  2212. this.checkYieldAwaitInDefaultParams();
  2213. this.parseFunctionBody(node, false);
  2214. this.inGenerator = oldInGen;
  2215. this.inAsync = oldInAsync;
  2216. this.yieldPos = oldYieldPos;
  2217. this.awaitPos = oldAwaitPos;
  2218. this.inFunction = oldInFunc;
  2219. return this.finishNode(node, "FunctionExpression")
  2220. };
  2221. // Parse arrow function expression with given parameters.
  2222. pp$3.parseArrowExpression = function(node, params, isAsync) {
  2223. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2224. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2225. this.enterFunctionScope();
  2226. this.initFunction(node);
  2227. if (this.options.ecmaVersion >= 8)
  2228. { node.async = !!isAsync; }
  2229. this.inGenerator = false;
  2230. this.inAsync = node.async;
  2231. this.yieldPos = 0;
  2232. this.awaitPos = 0;
  2233. this.inFunction = true;
  2234. node.params = this.toAssignableList(params, true);
  2235. this.parseFunctionBody(node, true);
  2236. this.inGenerator = oldInGen;
  2237. this.inAsync = oldInAsync;
  2238. this.yieldPos = oldYieldPos;
  2239. this.awaitPos = oldAwaitPos;
  2240. this.inFunction = oldInFunc;
  2241. return this.finishNode(node, "ArrowFunctionExpression")
  2242. };
  2243. // Parse function body and check parameters.
  2244. pp$3.parseFunctionBody = function(node, isArrowFunction) {
  2245. var isExpression = isArrowFunction && this.type !== types.braceL;
  2246. var oldStrict = this.strict, useStrict = false;
  2247. if (isExpression) {
  2248. node.body = this.parseMaybeAssign();
  2249. node.expression = true;
  2250. this.checkParams(node, false);
  2251. } else {
  2252. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2253. if (!oldStrict || nonSimple) {
  2254. useStrict = this.strictDirective(this.end);
  2255. // If this is a strict mode function, verify that argument names
  2256. // are not repeated, and it does not try to bind the words `eval`
  2257. // or `arguments`.
  2258. if (useStrict && nonSimple)
  2259. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2260. }
  2261. // Start a new scope with regard to labels and the `inFunction`
  2262. // flag (restore them to their old value afterwards).
  2263. var oldLabels = this.labels;
  2264. this.labels = [];
  2265. if (useStrict) { this.strict = true; }
  2266. // Add the params to varDeclaredNames to ensure that an error is thrown
  2267. // if a let/const declaration in the function clashes with one of the params.
  2268. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
  2269. node.body = this.parseBlock(false);
  2270. node.expression = false;
  2271. this.adaptDirectivePrologue(node.body.body);
  2272. this.labels = oldLabels;
  2273. }
  2274. this.exitFunctionScope();
  2275. if (this.strict && node.id) {
  2276. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2277. this.checkLVal(node.id, "none");
  2278. }
  2279. this.strict = oldStrict;
  2280. };
  2281. pp$3.isSimpleParamList = function(params) {
  2282. for (var i = 0, list = params; i < list.length; i += 1)
  2283. {
  2284. var param = list[i];
  2285. if (param.type !== "Identifier") { return false
  2286. } }
  2287. return true
  2288. };
  2289. // Checks function params for various disallowed patterns such as using "eval"
  2290. // or "arguments" and duplicate parameters.
  2291. pp$3.checkParams = function(node, allowDuplicates) {
  2292. var this$1 = this;
  2293. var nameHash = {};
  2294. for (var i = 0, list = node.params; i < list.length; i += 1)
  2295. {
  2296. var param = list[i];
  2297. this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
  2298. }
  2299. };
  2300. // Parses a comma-separated list of expressions, and returns them as
  2301. // an array. `close` is the token type that ends the list, and
  2302. // `allowEmpty` can be turned on to allow subsequent commas with
  2303. // nothing in between them to be parsed as `null` (which is needed
  2304. // for array literals).
  2305. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2306. var this$1 = this;
  2307. var elts = [], first = true;
  2308. while (!this.eat(close)) {
  2309. if (!first) {
  2310. this$1.expect(types.comma);
  2311. if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
  2312. } else { first = false; }
  2313. var elt = (void 0);
  2314. if (allowEmpty && this$1.type === types.comma)
  2315. { elt = null; }
  2316. else if (this$1.type === types.ellipsis) {
  2317. elt = this$1.parseSpread(refDestructuringErrors);
  2318. if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
  2319. { refDestructuringErrors.trailingComma = this$1.start; }
  2320. } else {
  2321. elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
  2322. }
  2323. elts.push(elt);
  2324. }
  2325. return elts
  2326. };
  2327. pp$3.checkUnreserved = function(ref) {
  2328. var start = ref.start;
  2329. var end = ref.end;
  2330. var name = ref.name;
  2331. if (this.inGenerator && name === "yield")
  2332. { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
  2333. if (this.inAsync && name === "await")
  2334. { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
  2335. if (this.isKeyword(name))
  2336. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2337. if (this.options.ecmaVersion < 6 &&
  2338. this.input.slice(start, end).indexOf("\\") != -1) { return }
  2339. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2340. if (re.test(name)) {
  2341. if (!this.inAsync && name === "await")
  2342. { this.raiseRecoverable(start, "Can not use keyword 'await' outside an async function"); }
  2343. this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
  2344. }
  2345. };
  2346. // Parse the next token as an identifier. If `liberal` is true (used
  2347. // when parsing properties), it will also convert keywords into
  2348. // identifiers.
  2349. pp$3.parseIdent = function(liberal, isBinding) {
  2350. var node = this.startNode();
  2351. if (liberal && this.options.allowReserved == "never") { liberal = false; }
  2352. if (this.type === types.name) {
  2353. node.name = this.value;
  2354. } else if (this.type.keyword) {
  2355. node.name = this.type.keyword;
  2356. // To fix https://github.com/acornjs/acorn/issues/575
  2357. // `class` and `function` keywords push new context into this.context.
  2358. // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
  2359. // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
  2360. if ((node.name === "class" || node.name === "function") &&
  2361. (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
  2362. this.context.pop();
  2363. }
  2364. } else {
  2365. this.unexpected();
  2366. }
  2367. this.next();
  2368. this.finishNode(node, "Identifier");
  2369. if (!liberal) { this.checkUnreserved(node); }
  2370. return node
  2371. };
  2372. // Parses yield expression inside generator.
  2373. pp$3.parseYield = function() {
  2374. if (!this.yieldPos) { this.yieldPos = this.start; }
  2375. var node = this.startNode();
  2376. this.next();
  2377. if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
  2378. node.delegate = false;
  2379. node.argument = null;
  2380. } else {
  2381. node.delegate = this.eat(types.star);
  2382. node.argument = this.parseMaybeAssign();
  2383. }
  2384. return this.finishNode(node, "YieldExpression")
  2385. };
  2386. pp$3.parseAwait = function() {
  2387. if (!this.awaitPos) { this.awaitPos = this.start; }
  2388. var node = this.startNode();
  2389. this.next();
  2390. node.argument = this.parseMaybeUnary(null, true);
  2391. return this.finishNode(node, "AwaitExpression")
  2392. };
  2393. var pp$4 = Parser.prototype;
  2394. // This function is used to raise exceptions on parse errors. It
  2395. // takes an offset integer (into the current `input`) to indicate
  2396. // the location of the error, attaches the position to the end
  2397. // of the error message, and then raises a `SyntaxError` with that
  2398. // message.
  2399. pp$4.raise = function(pos, message) {
  2400. var loc = getLineInfo(this.input, pos);
  2401. message += " (" + loc.line + ":" + loc.column + ")";
  2402. var err = new SyntaxError(message);
  2403. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  2404. throw err
  2405. };
  2406. pp$4.raiseRecoverable = pp$4.raise;
  2407. pp$4.curPosition = function() {
  2408. if (this.options.locations) {
  2409. return new Position(this.curLine, this.pos - this.lineStart)
  2410. }
  2411. };
  2412. var pp$5 = Parser.prototype;
  2413. // Object.assign polyfill
  2414. var assign = Object.assign || function(target) {
  2415. var sources = [], len = arguments.length - 1;
  2416. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  2417. for (var i = 0, list = sources; i < list.length; i += 1) {
  2418. var source = list[i];
  2419. for (var key in source) {
  2420. if (has(source, key)) {
  2421. target[key] = source[key];
  2422. }
  2423. }
  2424. }
  2425. return target
  2426. };
  2427. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  2428. pp$5.enterFunctionScope = function() {
  2429. // var: a hash of var-declared names in the current lexical scope
  2430. // lexical: a hash of lexically-declared names in the current lexical scope
  2431. // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
  2432. // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
  2433. this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
  2434. };
  2435. pp$5.exitFunctionScope = function() {
  2436. this.scopeStack.pop();
  2437. };
  2438. pp$5.enterLexicalScope = function() {
  2439. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2440. var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
  2441. this.scopeStack.push(childScope);
  2442. assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
  2443. };
  2444. pp$5.exitLexicalScope = function() {
  2445. var childScope = this.scopeStack.pop();
  2446. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2447. assign(parentScope.childVar, childScope.var, childScope.childVar);
  2448. };
  2449. /**
  2450. * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
  2451. * in the current lexical scope or any of the parent lexical scopes in this function.
  2452. */
  2453. pp$5.canDeclareVarName = function(name) {
  2454. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2455. return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
  2456. };
  2457. /**
  2458. * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
  2459. * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
  2460. * any child lexical scopes in this function.
  2461. */
  2462. pp$5.canDeclareLexicalName = function(name) {
  2463. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2464. return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
  2465. };
  2466. pp$5.declareVarName = function(name) {
  2467. this.scopeStack[this.scopeStack.length - 1].var[name] = true;
  2468. };
  2469. pp$5.declareLexicalName = function(name) {
  2470. this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
  2471. };
  2472. var Node = function Node(parser, pos, loc) {
  2473. this.type = "";
  2474. this.start = pos;
  2475. this.end = 0;
  2476. if (parser.options.locations)
  2477. { this.loc = new SourceLocation(parser, loc); }
  2478. if (parser.options.directSourceFile)
  2479. { this.sourceFile = parser.options.directSourceFile; }
  2480. if (parser.options.ranges)
  2481. { this.range = [pos, 0]; }
  2482. };
  2483. // Start an AST node, attaching a start offset.
  2484. var pp$6 = Parser.prototype;
  2485. pp$6.startNode = function() {
  2486. return new Node(this, this.start, this.startLoc)
  2487. };
  2488. pp$6.startNodeAt = function(pos, loc) {
  2489. return new Node(this, pos, loc)
  2490. };
  2491. // Finish an AST node, adding `type` and `end` properties.
  2492. function finishNodeAt(node, type, pos, loc) {
  2493. node.type = type;
  2494. node.end = pos;
  2495. if (this.options.locations)
  2496. { node.loc.end = loc; }
  2497. if (this.options.ranges)
  2498. { node.range[1] = pos; }
  2499. return node
  2500. }
  2501. pp$6.finishNode = function(node, type) {
  2502. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  2503. };
  2504. // Finish node at given position
  2505. pp$6.finishNodeAt = function(node, type, pos, loc) {
  2506. return finishNodeAt.call(this, node, type, pos, loc)
  2507. };
  2508. // The algorithm used to determine whether a regexp can appear at a
  2509. // given point in the program is loosely based on sweet.js' approach.
  2510. // See https://github.com/mozilla/sweet.js/wiki/design
  2511. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  2512. this.token = token;
  2513. this.isExpr = !!isExpr;
  2514. this.preserveSpace = !!preserveSpace;
  2515. this.override = override;
  2516. this.generator = !!generator;
  2517. };
  2518. var types$1 = {
  2519. b_stat: new TokContext("{", false),
  2520. b_expr: new TokContext("{", true),
  2521. b_tmpl: new TokContext("${", false),
  2522. p_stat: new TokContext("(", false),
  2523. p_expr: new TokContext("(", true),
  2524. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  2525. f_stat: new TokContext("function", false),
  2526. f_expr: new TokContext("function", true),
  2527. f_expr_gen: new TokContext("function", true, false, null, true),
  2528. f_gen: new TokContext("function", false, false, null, true)
  2529. };
  2530. var pp$7 = Parser.prototype;
  2531. pp$7.initialContext = function() {
  2532. return [types$1.b_stat]
  2533. };
  2534. pp$7.braceIsBlock = function(prevType) {
  2535. var parent = this.curContext();
  2536. if (parent === types$1.f_expr || parent === types$1.f_stat)
  2537. { return true }
  2538. if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
  2539. { return !parent.isExpr }
  2540. // The check for `tt.name && exprAllowed` detects whether we are
  2541. // after a `yield` or `of` construct. See the `updateContext` for
  2542. // `tt.name`.
  2543. if (prevType === types._return || prevType == types.name && this.exprAllowed)
  2544. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2545. if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
  2546. { return true }
  2547. if (prevType == types.braceL)
  2548. { return parent === types$1.b_stat }
  2549. if (prevType == types._var || prevType == types.name)
  2550. { return false }
  2551. return !this.exprAllowed
  2552. };
  2553. pp$7.inGeneratorContext = function() {
  2554. var this$1 = this;
  2555. for (var i = this.context.length - 1; i >= 1; i--) {
  2556. var context = this$1.context[i];
  2557. if (context.token === "function")
  2558. { return context.generator }
  2559. }
  2560. return false
  2561. };
  2562. pp$7.updateContext = function(prevType) {
  2563. var update, type = this.type;
  2564. if (type.keyword && prevType == types.dot)
  2565. { this.exprAllowed = false; }
  2566. else if (update = type.updateContext)
  2567. { update.call(this, prevType); }
  2568. else
  2569. { this.exprAllowed = type.beforeExpr; }
  2570. };
  2571. // Token-specific context update code
  2572. types.parenR.updateContext = types.braceR.updateContext = function() {
  2573. if (this.context.length == 1) {
  2574. this.exprAllowed = true;
  2575. return
  2576. }
  2577. var out = this.context.pop();
  2578. if (out === types$1.b_stat && this.curContext().token === "function") {
  2579. out = this.context.pop();
  2580. }
  2581. this.exprAllowed = !out.isExpr;
  2582. };
  2583. types.braceL.updateContext = function(prevType) {
  2584. this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
  2585. this.exprAllowed = true;
  2586. };
  2587. types.dollarBraceL.updateContext = function() {
  2588. this.context.push(types$1.b_tmpl);
  2589. this.exprAllowed = true;
  2590. };
  2591. types.parenL.updateContext = function(prevType) {
  2592. var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
  2593. this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
  2594. this.exprAllowed = true;
  2595. };
  2596. types.incDec.updateContext = function() {
  2597. // tokExprAllowed stays unchanged
  2598. };
  2599. types._function.updateContext = types._class.updateContext = function(prevType) {
  2600. if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
  2601. !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
  2602. { this.context.push(types$1.f_expr); }
  2603. else
  2604. { this.context.push(types$1.f_stat); }
  2605. this.exprAllowed = false;
  2606. };
  2607. types.backQuote.updateContext = function() {
  2608. if (this.curContext() === types$1.q_tmpl)
  2609. { this.context.pop(); }
  2610. else
  2611. { this.context.push(types$1.q_tmpl); }
  2612. this.exprAllowed = false;
  2613. };
  2614. types.star.updateContext = function(prevType) {
  2615. if (prevType == types._function) {
  2616. var index = this.context.length - 1;
  2617. if (this.context[index] === types$1.f_expr)
  2618. { this.context[index] = types$1.f_expr_gen; }
  2619. else
  2620. { this.context[index] = types$1.f_gen; }
  2621. }
  2622. this.exprAllowed = true;
  2623. };
  2624. types.name.updateContext = function(prevType) {
  2625. var allowed = false;
  2626. if (this.options.ecmaVersion >= 6) {
  2627. if (this.value == "of" && !this.exprAllowed ||
  2628. this.value == "yield" && this.inGeneratorContext())
  2629. { allowed = true; }
  2630. }
  2631. this.exprAllowed = allowed;
  2632. };
  2633. var data = {
  2634. "$LONE": [
  2635. "ASCII",
  2636. "ASCII_Hex_Digit",
  2637. "AHex",
  2638. "Alphabetic",
  2639. "Alpha",
  2640. "Any",
  2641. "Assigned",
  2642. "Bidi_Control",
  2643. "Bidi_C",
  2644. "Bidi_Mirrored",
  2645. "Bidi_M",
  2646. "Case_Ignorable",
  2647. "CI",
  2648. "Cased",
  2649. "Changes_When_Casefolded",
  2650. "CWCF",
  2651. "Changes_When_Casemapped",
  2652. "CWCM",
  2653. "Changes_When_Lowercased",
  2654. "CWL",
  2655. "Changes_When_NFKC_Casefolded",
  2656. "CWKCF",
  2657. "Changes_When_Titlecased",
  2658. "CWT",
  2659. "Changes_When_Uppercased",
  2660. "CWU",
  2661. "Dash",
  2662. "Default_Ignorable_Code_Point",
  2663. "DI",
  2664. "Deprecated",
  2665. "Dep",
  2666. "Diacritic",
  2667. "Dia",
  2668. "Emoji",
  2669. "Emoji_Component",
  2670. "Emoji_Modifier",
  2671. "Emoji_Modifier_Base",
  2672. "Emoji_Presentation",
  2673. "Extender",
  2674. "Ext",
  2675. "Grapheme_Base",
  2676. "Gr_Base",
  2677. "Grapheme_Extend",
  2678. "Gr_Ext",
  2679. "Hex_Digit",
  2680. "Hex",
  2681. "IDS_Binary_Operator",
  2682. "IDSB",
  2683. "IDS_Trinary_Operator",
  2684. "IDST",
  2685. "ID_Continue",
  2686. "IDC",
  2687. "ID_Start",
  2688. "IDS",
  2689. "Ideographic",
  2690. "Ideo",
  2691. "Join_Control",
  2692. "Join_C",
  2693. "Logical_Order_Exception",
  2694. "LOE",
  2695. "Lowercase",
  2696. "Lower",
  2697. "Math",
  2698. "Noncharacter_Code_Point",
  2699. "NChar",
  2700. "Pattern_Syntax",
  2701. "Pat_Syn",
  2702. "Pattern_White_Space",
  2703. "Pat_WS",
  2704. "Quotation_Mark",
  2705. "QMark",
  2706. "Radical",
  2707. "Regional_Indicator",
  2708. "RI",
  2709. "Sentence_Terminal",
  2710. "STerm",
  2711. "Soft_Dotted",
  2712. "SD",
  2713. "Terminal_Punctuation",
  2714. "Term",
  2715. "Unified_Ideograph",
  2716. "UIdeo",
  2717. "Uppercase",
  2718. "Upper",
  2719. "Variation_Selector",
  2720. "VS",
  2721. "White_Space",
  2722. "space",
  2723. "XID_Continue",
  2724. "XIDC",
  2725. "XID_Start",
  2726. "XIDS"
  2727. ],
  2728. "General_Category": [
  2729. "Cased_Letter",
  2730. "LC",
  2731. "Close_Punctuation",
  2732. "Pe",
  2733. "Connector_Punctuation",
  2734. "Pc",
  2735. "Control",
  2736. "Cc",
  2737. "cntrl",
  2738. "Currency_Symbol",
  2739. "Sc",
  2740. "Dash_Punctuation",
  2741. "Pd",
  2742. "Decimal_Number",
  2743. "Nd",
  2744. "digit",
  2745. "Enclosing_Mark",
  2746. "Me",
  2747. "Final_Punctuation",
  2748. "Pf",
  2749. "Format",
  2750. "Cf",
  2751. "Initial_Punctuation",
  2752. "Pi",
  2753. "Letter",
  2754. "L",
  2755. "Letter_Number",
  2756. "Nl",
  2757. "Line_Separator",
  2758. "Zl",
  2759. "Lowercase_Letter",
  2760. "Ll",
  2761. "Mark",
  2762. "M",
  2763. "Combining_Mark",
  2764. "Math_Symbol",
  2765. "Sm",
  2766. "Modifier_Letter",
  2767. "Lm",
  2768. "Modifier_Symbol",
  2769. "Sk",
  2770. "Nonspacing_Mark",
  2771. "Mn",
  2772. "Number",
  2773. "N",
  2774. "Open_Punctuation",
  2775. "Ps",
  2776. "Other",
  2777. "C",
  2778. "Other_Letter",
  2779. "Lo",
  2780. "Other_Number",
  2781. "No",
  2782. "Other_Punctuation",
  2783. "Po",
  2784. "Other_Symbol",
  2785. "So",
  2786. "Paragraph_Separator",
  2787. "Zp",
  2788. "Private_Use",
  2789. "Co",
  2790. "Punctuation",
  2791. "P",
  2792. "punct",
  2793. "Separator",
  2794. "Z",
  2795. "Space_Separator",
  2796. "Zs",
  2797. "Spacing_Mark",
  2798. "Mc",
  2799. "Surrogate",
  2800. "Cs",
  2801. "Symbol",
  2802. "S",
  2803. "Titlecase_Letter",
  2804. "Lt",
  2805. "Unassigned",
  2806. "Cn",
  2807. "Uppercase_Letter",
  2808. "Lu"
  2809. ],
  2810. "Script": [
  2811. "Adlam",
  2812. "Adlm",
  2813. "Ahom",
  2814. "Anatolian_Hieroglyphs",
  2815. "Hluw",
  2816. "Arabic",
  2817. "Arab",
  2818. "Armenian",
  2819. "Armn",
  2820. "Avestan",
  2821. "Avst",
  2822. "Balinese",
  2823. "Bali",
  2824. "Bamum",
  2825. "Bamu",
  2826. "Bassa_Vah",
  2827. "Bass",
  2828. "Batak",
  2829. "Batk",
  2830. "Bengali",
  2831. "Beng",
  2832. "Bhaiksuki",
  2833. "Bhks",
  2834. "Bopomofo",
  2835. "Bopo",
  2836. "Brahmi",
  2837. "Brah",
  2838. "Braille",
  2839. "Brai",
  2840. "Buginese",
  2841. "Bugi",
  2842. "Buhid",
  2843. "Buhd",
  2844. "Canadian_Aboriginal",
  2845. "Cans",
  2846. "Carian",
  2847. "Cari",
  2848. "Caucasian_Albanian",
  2849. "Aghb",
  2850. "Chakma",
  2851. "Cakm",
  2852. "Cham",
  2853. "Cherokee",
  2854. "Cher",
  2855. "Common",
  2856. "Zyyy",
  2857. "Coptic",
  2858. "Copt",
  2859. "Qaac",
  2860. "Cuneiform",
  2861. "Xsux",
  2862. "Cypriot",
  2863. "Cprt",
  2864. "Cyrillic",
  2865. "Cyrl",
  2866. "Deseret",
  2867. "Dsrt",
  2868. "Devanagari",
  2869. "Deva",
  2870. "Duployan",
  2871. "Dupl",
  2872. "Egyptian_Hieroglyphs",
  2873. "Egyp",
  2874. "Elbasan",
  2875. "Elba",
  2876. "Ethiopic",
  2877. "Ethi",
  2878. "Georgian",
  2879. "Geor",
  2880. "Glagolitic",
  2881. "Glag",
  2882. "Gothic",
  2883. "Goth",
  2884. "Grantha",
  2885. "Gran",
  2886. "Greek",
  2887. "Grek",
  2888. "Gujarati",
  2889. "Gujr",
  2890. "Gurmukhi",
  2891. "Guru",
  2892. "Han",
  2893. "Hani",
  2894. "Hangul",
  2895. "Hang",
  2896. "Hanunoo",
  2897. "Hano",
  2898. "Hatran",
  2899. "Hatr",
  2900. "Hebrew",
  2901. "Hebr",
  2902. "Hiragana",
  2903. "Hira",
  2904. "Imperial_Aramaic",
  2905. "Armi",
  2906. "Inherited",
  2907. "Zinh",
  2908. "Qaai",
  2909. "Inscriptional_Pahlavi",
  2910. "Phli",
  2911. "Inscriptional_Parthian",
  2912. "Prti",
  2913. "Javanese",
  2914. "Java",
  2915. "Kaithi",
  2916. "Kthi",
  2917. "Kannada",
  2918. "Knda",
  2919. "Katakana",
  2920. "Kana",
  2921. "Kayah_Li",
  2922. "Kali",
  2923. "Kharoshthi",
  2924. "Khar",
  2925. "Khmer",
  2926. "Khmr",
  2927. "Khojki",
  2928. "Khoj",
  2929. "Khudawadi",
  2930. "Sind",
  2931. "Lao",
  2932. "Laoo",
  2933. "Latin",
  2934. "Latn",
  2935. "Lepcha",
  2936. "Lepc",
  2937. "Limbu",
  2938. "Limb",
  2939. "Linear_A",
  2940. "Lina",
  2941. "Linear_B",
  2942. "Linb",
  2943. "Lisu",
  2944. "Lycian",
  2945. "Lyci",
  2946. "Lydian",
  2947. "Lydi",
  2948. "Mahajani",
  2949. "Mahj",
  2950. "Malayalam",
  2951. "Mlym",
  2952. "Mandaic",
  2953. "Mand",
  2954. "Manichaean",
  2955. "Mani",
  2956. "Marchen",
  2957. "Marc",
  2958. "Masaram_Gondi",
  2959. "Gonm",
  2960. "Meetei_Mayek",
  2961. "Mtei",
  2962. "Mende_Kikakui",
  2963. "Mend",
  2964. "Meroitic_Cursive",
  2965. "Merc",
  2966. "Meroitic_Hieroglyphs",
  2967. "Mero",
  2968. "Miao",
  2969. "Plrd",
  2970. "Modi",
  2971. "Mongolian",
  2972. "Mong",
  2973. "Mro",
  2974. "Mroo",
  2975. "Multani",
  2976. "Mult",
  2977. "Myanmar",
  2978. "Mymr",
  2979. "Nabataean",
  2980. "Nbat",
  2981. "New_Tai_Lue",
  2982. "Talu",
  2983. "Newa",
  2984. "Nko",
  2985. "Nkoo",
  2986. "Nushu",
  2987. "Nshu",
  2988. "Ogham",
  2989. "Ogam",
  2990. "Ol_Chiki",
  2991. "Olck",
  2992. "Old_Hungarian",
  2993. "Hung",
  2994. "Old_Italic",
  2995. "Ital",
  2996. "Old_North_Arabian",
  2997. "Narb",
  2998. "Old_Permic",
  2999. "Perm",
  3000. "Old_Persian",
  3001. "Xpeo",
  3002. "Old_South_Arabian",
  3003. "Sarb",
  3004. "Old_Turkic",
  3005. "Orkh",
  3006. "Oriya",
  3007. "Orya",
  3008. "Osage",
  3009. "Osge",
  3010. "Osmanya",
  3011. "Osma",
  3012. "Pahawh_Hmong",
  3013. "Hmng",
  3014. "Palmyrene",
  3015. "Palm",
  3016. "Pau_Cin_Hau",
  3017. "Pauc",
  3018. "Phags_Pa",
  3019. "Phag",
  3020. "Phoenician",
  3021. "Phnx",
  3022. "Psalter_Pahlavi",
  3023. "Phlp",
  3024. "Rejang",
  3025. "Rjng",
  3026. "Runic",
  3027. "Runr",
  3028. "Samaritan",
  3029. "Samr",
  3030. "Saurashtra",
  3031. "Saur",
  3032. "Sharada",
  3033. "Shrd",
  3034. "Shavian",
  3035. "Shaw",
  3036. "Siddham",
  3037. "Sidd",
  3038. "SignWriting",
  3039. "Sgnw",
  3040. "Sinhala",
  3041. "Sinh",
  3042. "Sora_Sompeng",
  3043. "Sora",
  3044. "Soyombo",
  3045. "Soyo",
  3046. "Sundanese",
  3047. "Sund",
  3048. "Syloti_Nagri",
  3049. "Sylo",
  3050. "Syriac",
  3051. "Syrc",
  3052. "Tagalog",
  3053. "Tglg",
  3054. "Tagbanwa",
  3055. "Tagb",
  3056. "Tai_Le",
  3057. "Tale",
  3058. "Tai_Tham",
  3059. "Lana",
  3060. "Tai_Viet",
  3061. "Tavt",
  3062. "Takri",
  3063. "Takr",
  3064. "Tamil",
  3065. "Taml",
  3066. "Tangut",
  3067. "Tang",
  3068. "Telugu",
  3069. "Telu",
  3070. "Thaana",
  3071. "Thaa",
  3072. "Thai",
  3073. "Tibetan",
  3074. "Tibt",
  3075. "Tifinagh",
  3076. "Tfng",
  3077. "Tirhuta",
  3078. "Tirh",
  3079. "Ugaritic",
  3080. "Ugar",
  3081. "Vai",
  3082. "Vaii",
  3083. "Warang_Citi",
  3084. "Wara",
  3085. "Yi",
  3086. "Yiii",
  3087. "Zanabazar_Square",
  3088. "Zanb"
  3089. ]
  3090. };
  3091. Array.prototype.push.apply(data.$LONE, data.General_Category);
  3092. data.gc = data.General_Category;
  3093. data.sc = data.Script_Extensions = data.scx = data.Script;
  3094. var pp$9 = Parser.prototype;
  3095. var RegExpValidationState = function RegExpValidationState(parser) {
  3096. this.parser = parser;
  3097. this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
  3098. this.source = "";
  3099. this.flags = "";
  3100. this.start = 0;
  3101. this.switchU = false;
  3102. this.switchN = false;
  3103. this.pos = 0;
  3104. this.lastIntValue = 0;
  3105. this.lastStringValue = "";
  3106. this.lastAssertionIsQuantifiable = false;
  3107. this.numCapturingParens = 0;
  3108. this.maxBackReference = 0;
  3109. this.groupNames = [];
  3110. this.backReferenceNames = [];
  3111. };
  3112. RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
  3113. var unicode = flags.indexOf("u") !== -1;
  3114. this.start = start | 0;
  3115. this.source = pattern + "";
  3116. this.flags = flags;
  3117. this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
  3118. this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
  3119. };
  3120. RegExpValidationState.prototype.raise = function raise (message) {
  3121. this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
  3122. };
  3123. // If u flag is given, this returns the code point at the index (it combines a surrogate pair).
  3124. // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
  3125. RegExpValidationState.prototype.at = function at (i) {
  3126. var s = this.source;
  3127. var l = s.length;
  3128. if (i >= l) {
  3129. return -1
  3130. }
  3131. var c = s.charCodeAt(i);
  3132. if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3133. return c
  3134. }
  3135. return (c << 10) + s.charCodeAt(i + 1) - 0x35FDC00
  3136. };
  3137. RegExpValidationState.prototype.nextIndex = function nextIndex (i) {
  3138. var s = this.source;
  3139. var l = s.length;
  3140. if (i >= l) {
  3141. return l
  3142. }
  3143. var c = s.charCodeAt(i);
  3144. if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3145. return i + 1
  3146. }
  3147. return i + 2
  3148. };
  3149. RegExpValidationState.prototype.current = function current () {
  3150. return this.at(this.pos)
  3151. };
  3152. RegExpValidationState.prototype.lookahead = function lookahead () {
  3153. return this.at(this.nextIndex(this.pos))
  3154. };
  3155. RegExpValidationState.prototype.advance = function advance () {
  3156. this.pos = this.nextIndex(this.pos);
  3157. };
  3158. RegExpValidationState.prototype.eat = function eat (ch) {
  3159. if (this.current() === ch) {
  3160. this.advance();
  3161. return true
  3162. }
  3163. return false
  3164. };
  3165. function codePointToString$1(ch) {
  3166. if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
  3167. ch -= 0x10000;
  3168. return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
  3169. }
  3170. /**
  3171. * Validate the flags part of a given RegExpLiteral.
  3172. *
  3173. * @param {RegExpValidationState} state The state to validate RegExp.
  3174. * @returns {void}
  3175. */
  3176. pp$9.validateRegExpFlags = function(state) {
  3177. var this$1 = this;
  3178. var validFlags = state.validFlags;
  3179. var flags = state.flags;
  3180. for (var i = 0; i < flags.length; i++) {
  3181. var flag = flags.charAt(i);
  3182. if (validFlags.indexOf(flag) == -1) {
  3183. this$1.raise(state.start, "Invalid regular expression flag");
  3184. }
  3185. if (flags.indexOf(flag, i + 1) > -1) {
  3186. this$1.raise(state.start, "Duplicate regular expression flag");
  3187. }
  3188. }
  3189. };
  3190. /**
  3191. * Validate the pattern part of a given RegExpLiteral.
  3192. *
  3193. * @param {RegExpValidationState} state The state to validate RegExp.
  3194. * @returns {void}
  3195. */
  3196. pp$9.validateRegExpPattern = function(state) {
  3197. this.regexp_pattern(state);
  3198. // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
  3199. // parsing contains a |GroupName|, reparse with the goal symbol
  3200. // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
  3201. // exception if _P_ did not conform to the grammar, if any elements of _P_
  3202. // were not matched by the parse, or if any Early Error conditions exist.
  3203. if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
  3204. state.switchN = true;
  3205. this.regexp_pattern(state);
  3206. }
  3207. };
  3208. // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
  3209. pp$9.regexp_pattern = function(state) {
  3210. state.pos = 0;
  3211. state.lastIntValue = 0;
  3212. state.lastStringValue = "";
  3213. state.lastAssertionIsQuantifiable = false;
  3214. state.numCapturingParens = 0;
  3215. state.maxBackReference = 0;
  3216. state.groupNames.length = 0;
  3217. state.backReferenceNames.length = 0;
  3218. this.regexp_disjunction(state);
  3219. if (state.pos !== state.source.length) {
  3220. // Make the same messages as V8.
  3221. if (state.eat(0x29 /* ) */)) {
  3222. state.raise("Unmatched ')'");
  3223. }
  3224. if (state.eat(0x5D /* [ */) || state.eat(0x7D /* } */)) {
  3225. state.raise("Lone quantifier brackets");
  3226. }
  3227. }
  3228. if (state.maxBackReference > state.numCapturingParens) {
  3229. state.raise("Invalid escape");
  3230. }
  3231. for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
  3232. var name = list[i];
  3233. if (state.groupNames.indexOf(name) === -1) {
  3234. state.raise("Invalid named capture referenced");
  3235. }
  3236. }
  3237. };
  3238. // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
  3239. pp$9.regexp_disjunction = function(state) {
  3240. var this$1 = this;
  3241. this.regexp_alternative(state);
  3242. while (state.eat(0x7C /* | */)) {
  3243. this$1.regexp_alternative(state);
  3244. }
  3245. // Make the same message as V8.
  3246. if (this.regexp_eatQuantifier(state, true)) {
  3247. state.raise("Nothing to repeat");
  3248. }
  3249. if (state.eat(0x7B /* { */)) {
  3250. state.raise("Lone quantifier brackets");
  3251. }
  3252. };
  3253. // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
  3254. pp$9.regexp_alternative = function(state) {
  3255. while (state.pos < state.source.length && this.regexp_eatTerm(state))
  3256. { }
  3257. };
  3258. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
  3259. pp$9.regexp_eatTerm = function(state) {
  3260. if (this.regexp_eatAssertion(state)) {
  3261. // Handle `QuantifiableAssertion Quantifier` alternative.
  3262. // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
  3263. // is a QuantifiableAssertion.
  3264. if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
  3265. // Make the same message as V8.
  3266. if (state.switchU) {
  3267. state.raise("Invalid quantifier");
  3268. }
  3269. }
  3270. return true
  3271. }
  3272. if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
  3273. this.regexp_eatQuantifier(state);
  3274. return true
  3275. }
  3276. return false
  3277. };
  3278. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
  3279. pp$9.regexp_eatAssertion = function(state) {
  3280. var start = state.pos;
  3281. state.lastAssertionIsQuantifiable = false;
  3282. // ^, $
  3283. if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
  3284. return true
  3285. }
  3286. // \b \B
  3287. if (state.eat(0x5C /* \ */)) {
  3288. if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
  3289. return true
  3290. }
  3291. state.pos = start;
  3292. }
  3293. // Lookahead / Lookbehind
  3294. if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
  3295. var lookbehind = false;
  3296. if (this.options.ecmaVersion >= 9) {
  3297. lookbehind = state.eat(0x3C /* < */);
  3298. }
  3299. if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
  3300. this.regexp_disjunction(state);
  3301. if (!state.eat(0x29 /* ) */)) {
  3302. state.raise("Unterminated group");
  3303. }
  3304. state.lastAssertionIsQuantifiable = !lookbehind;
  3305. return true
  3306. }
  3307. }
  3308. state.pos = start;
  3309. return false
  3310. };
  3311. // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
  3312. pp$9.regexp_eatQuantifier = function(state, noError) {
  3313. if ( noError === void 0 ) noError = false;
  3314. if (this.regexp_eatQuantifierPrefix(state, noError)) {
  3315. state.eat(0x3F /* ? */);
  3316. return true
  3317. }
  3318. return false
  3319. };
  3320. // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
  3321. pp$9.regexp_eatQuantifierPrefix = function(state, noError) {
  3322. return (
  3323. state.eat(0x2A /* * */) ||
  3324. state.eat(0x2B /* + */) ||
  3325. state.eat(0x3F /* ? */) ||
  3326. this.regexp_eatBracedQuantifier(state, noError)
  3327. )
  3328. };
  3329. pp$9.regexp_eatBracedQuantifier = function(state, noError) {
  3330. var start = state.pos;
  3331. if (state.eat(0x7B /* { */)) {
  3332. var min = 0, max = -1;
  3333. if (this.regexp_eatDecimalDigits(state)) {
  3334. min = state.lastIntValue;
  3335. if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
  3336. max = state.lastIntValue;
  3337. }
  3338. if (state.eat(0x7D /* } */)) {
  3339. // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
  3340. if (max !== -1 && max < min && !noError) {
  3341. state.raise("numbers out of order in {} quantifier");
  3342. }
  3343. return true
  3344. }
  3345. }
  3346. if (state.switchU && !noError) {
  3347. state.raise("Incomplete quantifier");
  3348. }
  3349. state.pos = start;
  3350. }
  3351. return false
  3352. };
  3353. // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
  3354. pp$9.regexp_eatAtom = function(state) {
  3355. return (
  3356. this.regexp_eatPatternCharacters(state) ||
  3357. state.eat(0x2E /* . */) ||
  3358. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3359. this.regexp_eatCharacterClass(state) ||
  3360. this.regexp_eatUncapturingGroup(state) ||
  3361. this.regexp_eatCapturingGroup(state)
  3362. )
  3363. };
  3364. pp$9.regexp_eatReverseSolidusAtomEscape = function(state) {
  3365. var start = state.pos;
  3366. if (state.eat(0x5C /* \ */)) {
  3367. if (this.regexp_eatAtomEscape(state)) {
  3368. return true
  3369. }
  3370. state.pos = start;
  3371. }
  3372. return false
  3373. };
  3374. pp$9.regexp_eatUncapturingGroup = function(state) {
  3375. var start = state.pos;
  3376. if (state.eat(0x28 /* ( */)) {
  3377. if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
  3378. this.regexp_disjunction(state);
  3379. if (state.eat(0x29 /* ) */)) {
  3380. return true
  3381. }
  3382. state.raise("Unterminated group");
  3383. }
  3384. state.pos = start;
  3385. }
  3386. return false
  3387. };
  3388. pp$9.regexp_eatCapturingGroup = function(state) {
  3389. if (state.eat(0x28 /* ( */)) {
  3390. if (this.options.ecmaVersion >= 9) {
  3391. this.regexp_groupSpecifier(state);
  3392. } else if (state.current() === 0x3F /* ? */) {
  3393. state.raise("Invalid group");
  3394. }
  3395. this.regexp_disjunction(state);
  3396. if (state.eat(0x29 /* ) */)) {
  3397. state.numCapturingParens += 1;
  3398. return true
  3399. }
  3400. state.raise("Unterminated group");
  3401. }
  3402. return false
  3403. };
  3404. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
  3405. pp$9.regexp_eatExtendedAtom = function(state) {
  3406. return (
  3407. state.eat(0x2E /* . */) ||
  3408. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3409. this.regexp_eatCharacterClass(state) ||
  3410. this.regexp_eatUncapturingGroup(state) ||
  3411. this.regexp_eatCapturingGroup(state) ||
  3412. this.regexp_eatInvalidBracedQuantifier(state) ||
  3413. this.regexp_eatExtendedPatternCharacter(state)
  3414. )
  3415. };
  3416. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
  3417. pp$9.regexp_eatInvalidBracedQuantifier = function(state) {
  3418. if (this.regexp_eatBracedQuantifier(state, true)) {
  3419. state.raise("Nothing to repeat");
  3420. }
  3421. return false
  3422. };
  3423. // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
  3424. pp$9.regexp_eatSyntaxCharacter = function(state) {
  3425. var ch = state.current();
  3426. if (isSyntaxCharacter(ch)) {
  3427. state.lastIntValue = ch;
  3428. state.advance();
  3429. return true
  3430. }
  3431. return false
  3432. };
  3433. function isSyntaxCharacter(ch) {
  3434. return (
  3435. ch === 0x24 /* $ */ ||
  3436. ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
  3437. ch === 0x2E /* . */ ||
  3438. ch === 0x3F /* ? */ ||
  3439. ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
  3440. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  3441. )
  3442. }
  3443. // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
  3444. // But eat eager.
  3445. pp$9.regexp_eatPatternCharacters = function(state) {
  3446. var start = state.pos;
  3447. var ch = 0;
  3448. while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
  3449. state.advance();
  3450. }
  3451. return state.pos !== start
  3452. };
  3453. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
  3454. pp$9.regexp_eatExtendedPatternCharacter = function(state) {
  3455. var ch = state.current();
  3456. if (
  3457. ch !== -1 &&
  3458. ch !== 0x24 /* $ */ &&
  3459. !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
  3460. ch !== 0x2E /* . */ &&
  3461. ch !== 0x3F /* ? */ &&
  3462. ch !== 0x5B /* [ */ &&
  3463. ch !== 0x5E /* ^ */ &&
  3464. ch !== 0x7C /* | */
  3465. ) {
  3466. state.advance();
  3467. return true
  3468. }
  3469. return false
  3470. };
  3471. // GroupSpecifier[U] ::
  3472. // [empty]
  3473. // `?` GroupName[?U]
  3474. pp$9.regexp_groupSpecifier = function(state) {
  3475. if (state.eat(0x3F /* ? */)) {
  3476. if (this.regexp_eatGroupName(state)) {
  3477. if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
  3478. state.raise("Duplicate capture group name");
  3479. }
  3480. state.groupNames.push(state.lastStringValue);
  3481. return
  3482. }
  3483. state.raise("Invalid group");
  3484. }
  3485. };
  3486. // GroupName[U] ::
  3487. // `<` RegExpIdentifierName[?U] `>`
  3488. // Note: this updates `state.lastStringValue` property with the eaten name.
  3489. pp$9.regexp_eatGroupName = function(state) {
  3490. state.lastStringValue = "";
  3491. if (state.eat(0x3C /* < */)) {
  3492. if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
  3493. return true
  3494. }
  3495. state.raise("Invalid capture group name");
  3496. }
  3497. return false
  3498. };
  3499. // RegExpIdentifierName[U] ::
  3500. // RegExpIdentifierStart[?U]
  3501. // RegExpIdentifierName[?U] RegExpIdentifierPart[?U]
  3502. // Note: this updates `state.lastStringValue` property with the eaten name.
  3503. pp$9.regexp_eatRegExpIdentifierName = function(state) {
  3504. state.lastStringValue = "";
  3505. if (this.regexp_eatRegExpIdentifierStart(state)) {
  3506. state.lastStringValue += codePointToString$1(state.lastIntValue);
  3507. while (this.regexp_eatRegExpIdentifierPart(state)) {
  3508. state.lastStringValue += codePointToString$1(state.lastIntValue);
  3509. }
  3510. return true
  3511. }
  3512. return false
  3513. };
  3514. // RegExpIdentifierStart[U] ::
  3515. // UnicodeIDStart
  3516. // `$`
  3517. // `_`
  3518. // `\` RegExpUnicodeEscapeSequence[?U]
  3519. pp$9.regexp_eatRegExpIdentifierStart = function(state) {
  3520. var start = state.pos;
  3521. var ch = state.current();
  3522. state.advance();
  3523. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
  3524. ch = state.lastIntValue;
  3525. }
  3526. if (isRegExpIdentifierStart(ch)) {
  3527. state.lastIntValue = ch;
  3528. return true
  3529. }
  3530. state.pos = start;
  3531. return false
  3532. };
  3533. function isRegExpIdentifierStart(ch) {
  3534. return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
  3535. }
  3536. // RegExpIdentifierPart[U] ::
  3537. // UnicodeIDContinue
  3538. // `$`
  3539. // `_`
  3540. // `\` RegExpUnicodeEscapeSequence[?U]
  3541. // <ZWNJ>
  3542. // <ZWJ>
  3543. pp$9.regexp_eatRegExpIdentifierPart = function(state) {
  3544. var start = state.pos;
  3545. var ch = state.current();
  3546. state.advance();
  3547. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
  3548. ch = state.lastIntValue;
  3549. }
  3550. if (isRegExpIdentifierPart(ch)) {
  3551. state.lastIntValue = ch;
  3552. return true
  3553. }
  3554. state.pos = start;
  3555. return false
  3556. };
  3557. function isRegExpIdentifierPart(ch) {
  3558. return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
  3559. }
  3560. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
  3561. pp$9.regexp_eatAtomEscape = function(state) {
  3562. if (
  3563. this.regexp_eatBackReference(state) ||
  3564. this.regexp_eatCharacterClassEscape(state) ||
  3565. this.regexp_eatCharacterEscape(state) ||
  3566. (state.switchN && this.regexp_eatKGroupName(state))
  3567. ) {
  3568. return true
  3569. }
  3570. if (state.switchU) {
  3571. // Make the same message as V8.
  3572. if (state.current() === 0x63 /* c */) {
  3573. state.raise("Invalid unicode escape");
  3574. }
  3575. state.raise("Invalid escape");
  3576. }
  3577. return false
  3578. };
  3579. pp$9.regexp_eatBackReference = function(state) {
  3580. var start = state.pos;
  3581. if (this.regexp_eatDecimalEscape(state)) {
  3582. var n = state.lastIntValue;
  3583. if (state.switchU) {
  3584. // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
  3585. if (n > state.maxBackReference) {
  3586. state.maxBackReference = n;
  3587. }
  3588. return true
  3589. }
  3590. if (n <= state.numCapturingParens) {
  3591. return true
  3592. }
  3593. state.pos = start;
  3594. }
  3595. return false
  3596. };
  3597. pp$9.regexp_eatKGroupName = function(state) {
  3598. if (state.eat(0x6B /* k */)) {
  3599. if (this.regexp_eatGroupName(state)) {
  3600. state.backReferenceNames.push(state.lastStringValue);
  3601. return true
  3602. }
  3603. state.raise("Invalid named reference");
  3604. }
  3605. return false
  3606. };
  3607. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
  3608. pp$9.regexp_eatCharacterEscape = function(state) {
  3609. return (
  3610. this.regexp_eatControlEscape(state) ||
  3611. this.regexp_eatCControlLetter(state) ||
  3612. this.regexp_eatZero(state) ||
  3613. this.regexp_eatHexEscapeSequence(state) ||
  3614. this.regexp_eatRegExpUnicodeEscapeSequence(state) ||
  3615. (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
  3616. this.regexp_eatIdentityEscape(state)
  3617. )
  3618. };
  3619. pp$9.regexp_eatCControlLetter = function(state) {
  3620. var start = state.pos;
  3621. if (state.eat(0x63 /* c */)) {
  3622. if (this.regexp_eatControlLetter(state)) {
  3623. return true
  3624. }
  3625. state.pos = start;
  3626. }
  3627. return false
  3628. };
  3629. pp$9.regexp_eatZero = function(state) {
  3630. if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
  3631. state.lastIntValue = 0;
  3632. state.advance();
  3633. return true
  3634. }
  3635. return false
  3636. };
  3637. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
  3638. pp$9.regexp_eatControlEscape = function(state) {
  3639. var ch = state.current();
  3640. if (ch === 0x74 /* t */) {
  3641. state.lastIntValue = 0x09; /* \t */
  3642. state.advance();
  3643. return true
  3644. }
  3645. if (ch === 0x6E /* n */) {
  3646. state.lastIntValue = 0x0A; /* \n */
  3647. state.advance();
  3648. return true
  3649. }
  3650. if (ch === 0x76 /* v */) {
  3651. state.lastIntValue = 0x0B; /* \v */
  3652. state.advance();
  3653. return true
  3654. }
  3655. if (ch === 0x66 /* f */) {
  3656. state.lastIntValue = 0x0C; /* \f */
  3657. state.advance();
  3658. return true
  3659. }
  3660. if (ch === 0x72 /* r */) {
  3661. state.lastIntValue = 0x0D; /* \r */
  3662. state.advance();
  3663. return true
  3664. }
  3665. return false
  3666. };
  3667. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
  3668. pp$9.regexp_eatControlLetter = function(state) {
  3669. var ch = state.current();
  3670. if (isControlLetter(ch)) {
  3671. state.lastIntValue = ch % 0x20;
  3672. state.advance();
  3673. return true
  3674. }
  3675. return false
  3676. };
  3677. function isControlLetter(ch) {
  3678. return (
  3679. (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
  3680. (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
  3681. )
  3682. }
  3683. // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
  3684. pp$9.regexp_eatRegExpUnicodeEscapeSequence = function(state) {
  3685. var start = state.pos;
  3686. if (state.eat(0x75 /* u */)) {
  3687. if (this.regexp_eatFixedHexDigits(state, 4)) {
  3688. var lead = state.lastIntValue;
  3689. if (state.switchU && lead >= 0xD800 && lead <= 0xDBFF) {
  3690. var leadSurrogateEnd = state.pos;
  3691. if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
  3692. var trail = state.lastIntValue;
  3693. if (trail >= 0xDC00 && trail <= 0xDFFF) {
  3694. state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  3695. return true
  3696. }
  3697. }
  3698. state.pos = leadSurrogateEnd;
  3699. state.lastIntValue = lead;
  3700. }
  3701. return true
  3702. }
  3703. if (
  3704. state.switchU &&
  3705. state.eat(0x7B /* { */) &&
  3706. this.regexp_eatHexDigits(state) &&
  3707. state.eat(0x7D /* } */) &&
  3708. isValidUnicode(state.lastIntValue)
  3709. ) {
  3710. return true
  3711. }
  3712. if (state.switchU) {
  3713. state.raise("Invalid unicode escape");
  3714. }
  3715. state.pos = start;
  3716. }
  3717. return false
  3718. };
  3719. function isValidUnicode(ch) {
  3720. return ch >= 0 && ch <= 0x10FFFF
  3721. }
  3722. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
  3723. pp$9.regexp_eatIdentityEscape = function(state) {
  3724. if (state.switchU) {
  3725. if (this.regexp_eatSyntaxCharacter(state)) {
  3726. return true
  3727. }
  3728. if (state.eat(0x2F /* / */)) {
  3729. state.lastIntValue = 0x2F; /* / */
  3730. return true
  3731. }
  3732. return false
  3733. }
  3734. var ch = state.current();
  3735. if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
  3736. state.lastIntValue = ch;
  3737. state.advance();
  3738. return true
  3739. }
  3740. return false
  3741. };
  3742. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
  3743. pp$9.regexp_eatDecimalEscape = function(state) {
  3744. state.lastIntValue = 0;
  3745. var ch = state.current();
  3746. if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
  3747. do {
  3748. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3749. state.advance();
  3750. } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
  3751. return true
  3752. }
  3753. return false
  3754. };
  3755. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
  3756. pp$9.regexp_eatCharacterClassEscape = function(state) {
  3757. var ch = state.current();
  3758. if (isCharacterClassEscape(ch)) {
  3759. state.lastIntValue = -1;
  3760. state.advance();
  3761. return true
  3762. }
  3763. if (
  3764. state.switchU &&
  3765. this.options.ecmaVersion >= 9 &&
  3766. (ch === 0x50 /* P */ || ch === 0x70 /* p */)
  3767. ) {
  3768. state.lastIntValue = -1;
  3769. state.advance();
  3770. if (
  3771. state.eat(0x7B /* { */) &&
  3772. this.regexp_eatUnicodePropertyValueExpression(state) &&
  3773. state.eat(0x7D /* } */)
  3774. ) {
  3775. return true
  3776. }
  3777. state.raise("Invalid property name");
  3778. }
  3779. return false
  3780. };
  3781. function isCharacterClassEscape(ch) {
  3782. return (
  3783. ch === 0x64 /* d */ ||
  3784. ch === 0x44 /* D */ ||
  3785. ch === 0x73 /* s */ ||
  3786. ch === 0x53 /* S */ ||
  3787. ch === 0x77 /* w */ ||
  3788. ch === 0x57 /* W */
  3789. )
  3790. }
  3791. // UnicodePropertyValueExpression ::
  3792. // UnicodePropertyName `=` UnicodePropertyValue
  3793. // LoneUnicodePropertyNameOrValue
  3794. pp$9.regexp_eatUnicodePropertyValueExpression = function(state) {
  3795. var start = state.pos;
  3796. // UnicodePropertyName `=` UnicodePropertyValue
  3797. if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
  3798. var name = state.lastStringValue;
  3799. if (this.regexp_eatUnicodePropertyValue(state)) {
  3800. var value = state.lastStringValue;
  3801. this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
  3802. return true
  3803. }
  3804. }
  3805. state.pos = start;
  3806. // LoneUnicodePropertyNameOrValue
  3807. if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
  3808. var nameOrValue = state.lastStringValue;
  3809. this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
  3810. return true
  3811. }
  3812. return false
  3813. };
  3814. pp$9.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
  3815. if (!data.hasOwnProperty(name) || data[name].indexOf(value) === -1) {
  3816. state.raise("Invalid property name");
  3817. }
  3818. };
  3819. pp$9.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
  3820. if (data.$LONE.indexOf(nameOrValue) === -1) {
  3821. state.raise("Invalid property name");
  3822. }
  3823. };
  3824. // UnicodePropertyName ::
  3825. // UnicodePropertyNameCharacters
  3826. pp$9.regexp_eatUnicodePropertyName = function(state) {
  3827. var ch = 0;
  3828. state.lastStringValue = "";
  3829. while (isUnicodePropertyNameCharacter(ch = state.current())) {
  3830. state.lastStringValue += codePointToString$1(ch);
  3831. state.advance();
  3832. }
  3833. return state.lastStringValue !== ""
  3834. };
  3835. function isUnicodePropertyNameCharacter(ch) {
  3836. return isControlLetter(ch) || ch === 0x5F /* _ */
  3837. }
  3838. // UnicodePropertyValue ::
  3839. // UnicodePropertyValueCharacters
  3840. pp$9.regexp_eatUnicodePropertyValue = function(state) {
  3841. var ch = 0;
  3842. state.lastStringValue = "";
  3843. while (isUnicodePropertyValueCharacter(ch = state.current())) {
  3844. state.lastStringValue += codePointToString$1(ch);
  3845. state.advance();
  3846. }
  3847. return state.lastStringValue !== ""
  3848. };
  3849. function isUnicodePropertyValueCharacter(ch) {
  3850. return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
  3851. }
  3852. // LoneUnicodePropertyNameOrValue ::
  3853. // UnicodePropertyValueCharacters
  3854. pp$9.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
  3855. return this.regexp_eatUnicodePropertyValue(state)
  3856. };
  3857. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
  3858. pp$9.regexp_eatCharacterClass = function(state) {
  3859. if (state.eat(0x5B /* [ */)) {
  3860. state.eat(0x5E /* ^ */);
  3861. this.regexp_classRanges(state);
  3862. if (state.eat(0x5D /* [ */)) {
  3863. return true
  3864. }
  3865. // Unreachable since it threw "unterminated regular expression" error before.
  3866. state.raise("Unterminated character class");
  3867. }
  3868. return false
  3869. };
  3870. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
  3871. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
  3872. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
  3873. pp$9.regexp_classRanges = function(state) {
  3874. var this$1 = this;
  3875. while (this.regexp_eatClassAtom(state)) {
  3876. var left = state.lastIntValue;
  3877. if (state.eat(0x2D /* - */) && this$1.regexp_eatClassAtom(state)) {
  3878. var right = state.lastIntValue;
  3879. if (state.switchU && (left === -1 || right === -1)) {
  3880. state.raise("Invalid character class");
  3881. }
  3882. if (left !== -1 && right !== -1 && left > right) {
  3883. state.raise("Range out of order in character class");
  3884. }
  3885. }
  3886. }
  3887. };
  3888. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
  3889. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
  3890. pp$9.regexp_eatClassAtom = function(state) {
  3891. var start = state.pos;
  3892. if (state.eat(0x5C /* \ */)) {
  3893. if (this.regexp_eatClassEscape(state)) {
  3894. return true
  3895. }
  3896. if (state.switchU) {
  3897. // Make the same message as V8.
  3898. var ch$1 = state.current();
  3899. if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
  3900. state.raise("Invalid class escape");
  3901. }
  3902. state.raise("Invalid escape");
  3903. }
  3904. state.pos = start;
  3905. }
  3906. var ch = state.current();
  3907. if (ch !== 0x5D /* [ */) {
  3908. state.lastIntValue = ch;
  3909. state.advance();
  3910. return true
  3911. }
  3912. return false
  3913. };
  3914. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
  3915. pp$9.regexp_eatClassEscape = function(state) {
  3916. var start = state.pos;
  3917. if (state.eat(0x62 /* b */)) {
  3918. state.lastIntValue = 0x08; /* <BS> */
  3919. return true
  3920. }
  3921. if (state.switchU && state.eat(0x2D /* - */)) {
  3922. state.lastIntValue = 0x2D; /* - */
  3923. return true
  3924. }
  3925. if (!state.switchU && state.eat(0x63 /* c */)) {
  3926. if (this.regexp_eatClassControlLetter(state)) {
  3927. return true
  3928. }
  3929. state.pos = start;
  3930. }
  3931. return (
  3932. this.regexp_eatCharacterClassEscape(state) ||
  3933. this.regexp_eatCharacterEscape(state)
  3934. )
  3935. };
  3936. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
  3937. pp$9.regexp_eatClassControlLetter = function(state) {
  3938. var ch = state.current();
  3939. if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
  3940. state.lastIntValue = ch % 0x20;
  3941. state.advance();
  3942. return true
  3943. }
  3944. return false
  3945. };
  3946. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  3947. pp$9.regexp_eatHexEscapeSequence = function(state) {
  3948. var start = state.pos;
  3949. if (state.eat(0x78 /* x */)) {
  3950. if (this.regexp_eatFixedHexDigits(state, 2)) {
  3951. return true
  3952. }
  3953. if (state.switchU) {
  3954. state.raise("Invalid escape");
  3955. }
  3956. state.pos = start;
  3957. }
  3958. return false
  3959. };
  3960. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
  3961. pp$9.regexp_eatDecimalDigits = function(state) {
  3962. var start = state.pos;
  3963. var ch = 0;
  3964. state.lastIntValue = 0;
  3965. while (isDecimalDigit(ch = state.current())) {
  3966. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3967. state.advance();
  3968. }
  3969. return state.pos !== start
  3970. };
  3971. function isDecimalDigit(ch) {
  3972. return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
  3973. }
  3974. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
  3975. pp$9.regexp_eatHexDigits = function(state) {
  3976. var start = state.pos;
  3977. var ch = 0;
  3978. state.lastIntValue = 0;
  3979. while (isHexDigit(ch = state.current())) {
  3980. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  3981. state.advance();
  3982. }
  3983. return state.pos !== start
  3984. };
  3985. function isHexDigit(ch) {
  3986. return (
  3987. (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
  3988. (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
  3989. (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
  3990. )
  3991. }
  3992. function hexToInt(ch) {
  3993. if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
  3994. return 10 + (ch - 0x41 /* A */)
  3995. }
  3996. if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
  3997. return 10 + (ch - 0x61 /* a */)
  3998. }
  3999. return ch - 0x30 /* 0 */
  4000. }
  4001. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
  4002. // Allows only 0-377(octal) i.e. 0-255(decimal).
  4003. pp$9.regexp_eatLegacyOctalEscapeSequence = function(state) {
  4004. if (this.regexp_eatOctalDigit(state)) {
  4005. var n1 = state.lastIntValue;
  4006. if (this.regexp_eatOctalDigit(state)) {
  4007. var n2 = state.lastIntValue;
  4008. if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
  4009. state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
  4010. } else {
  4011. state.lastIntValue = n1 * 8 + n2;
  4012. }
  4013. } else {
  4014. state.lastIntValue = n1;
  4015. }
  4016. return true
  4017. }
  4018. return false
  4019. };
  4020. // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
  4021. pp$9.regexp_eatOctalDigit = function(state) {
  4022. var ch = state.current();
  4023. if (isOctalDigit(ch)) {
  4024. state.lastIntValue = ch - 0x30; /* 0 */
  4025. state.advance();
  4026. return true
  4027. }
  4028. state.lastIntValue = 0;
  4029. return false
  4030. };
  4031. function isOctalDigit(ch) {
  4032. return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
  4033. }
  4034. // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
  4035. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
  4036. // And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4037. pp$9.regexp_eatFixedHexDigits = function(state, length) {
  4038. var start = state.pos;
  4039. state.lastIntValue = 0;
  4040. for (var i = 0; i < length; ++i) {
  4041. var ch = state.current();
  4042. if (!isHexDigit(ch)) {
  4043. state.pos = start;
  4044. return false
  4045. }
  4046. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4047. state.advance();
  4048. }
  4049. return true
  4050. };
  4051. // Object type used to represent tokens. Note that normally, tokens
  4052. // simply exist as properties on the parser object. This is only
  4053. // used for the onToken callback and the external tokenizer.
  4054. var Token = function Token(p) {
  4055. this.type = p.type;
  4056. this.value = p.value;
  4057. this.start = p.start;
  4058. this.end = p.end;
  4059. if (p.options.locations)
  4060. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  4061. if (p.options.ranges)
  4062. { this.range = [p.start, p.end]; }
  4063. };
  4064. // ## Tokenizer
  4065. var pp$8 = Parser.prototype;
  4066. // Move to the next token
  4067. pp$8.next = function() {
  4068. if (this.options.onToken)
  4069. { this.options.onToken(new Token(this)); }
  4070. this.lastTokEnd = this.end;
  4071. this.lastTokStart = this.start;
  4072. this.lastTokEndLoc = this.endLoc;
  4073. this.lastTokStartLoc = this.startLoc;
  4074. this.nextToken();
  4075. };
  4076. pp$8.getToken = function() {
  4077. this.next();
  4078. return new Token(this)
  4079. };
  4080. // If we're in an ES6 environment, make parsers iterable
  4081. if (typeof Symbol !== "undefined")
  4082. { pp$8[Symbol.iterator] = function() {
  4083. var this$1 = this;
  4084. return {
  4085. next: function () {
  4086. var token = this$1.getToken();
  4087. return {
  4088. done: token.type === types.eof,
  4089. value: token
  4090. }
  4091. }
  4092. }
  4093. }; }
  4094. // Toggle strict mode. Re-reads the next number or string to please
  4095. // pedantic tests (`"use strict"; 010;` should fail).
  4096. pp$8.curContext = function() {
  4097. return this.context[this.context.length - 1]
  4098. };
  4099. // Read a single token, updating the parser object's token-related
  4100. // properties.
  4101. pp$8.nextToken = function() {
  4102. var curContext = this.curContext();
  4103. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  4104. this.start = this.pos;
  4105. if (this.options.locations) { this.startLoc = this.curPosition(); }
  4106. if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
  4107. if (curContext.override) { return curContext.override(this) }
  4108. else { this.readToken(this.fullCharCodeAtPos()); }
  4109. };
  4110. pp$8.readToken = function(code) {
  4111. // Identifier or keyword. '\uXXXX' sequences are allowed in
  4112. // identifiers, so '\' also dispatches to that.
  4113. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  4114. { return this.readWord() }
  4115. return this.getTokenFromCode(code)
  4116. };
  4117. pp$8.fullCharCodeAtPos = function() {
  4118. var code = this.input.charCodeAt(this.pos);
  4119. if (code <= 0xd7ff || code >= 0xe000) { return code }
  4120. var next = this.input.charCodeAt(this.pos + 1);
  4121. return (code << 10) + next - 0x35fdc00
  4122. };
  4123. pp$8.skipBlockComment = function() {
  4124. var this$1 = this;
  4125. var startLoc = this.options.onComment && this.curPosition();
  4126. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  4127. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  4128. this.pos = end + 2;
  4129. if (this.options.locations) {
  4130. lineBreakG.lastIndex = start;
  4131. var match;
  4132. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  4133. ++this$1.curLine;
  4134. this$1.lineStart = match.index + match[0].length;
  4135. }
  4136. }
  4137. if (this.options.onComment)
  4138. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  4139. startLoc, this.curPosition()); }
  4140. };
  4141. pp$8.skipLineComment = function(startSkip) {
  4142. var this$1 = this;
  4143. var start = this.pos;
  4144. var startLoc = this.options.onComment && this.curPosition();
  4145. var ch = this.input.charCodeAt(this.pos += startSkip);
  4146. while (this.pos < this.input.length && !isNewLine(ch)) {
  4147. ch = this$1.input.charCodeAt(++this$1.pos);
  4148. }
  4149. if (this.options.onComment)
  4150. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  4151. startLoc, this.curPosition()); }
  4152. };
  4153. // Called at the start of the parse and after every token. Skips
  4154. // whitespace and comments, and.
  4155. pp$8.skipSpace = function() {
  4156. var this$1 = this;
  4157. loop: while (this.pos < this.input.length) {
  4158. var ch = this$1.input.charCodeAt(this$1.pos);
  4159. switch (ch) {
  4160. case 32: case 160: // ' '
  4161. ++this$1.pos;
  4162. break
  4163. case 13:
  4164. if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
  4165. ++this$1.pos;
  4166. }
  4167. case 10: case 8232: case 8233:
  4168. ++this$1.pos;
  4169. if (this$1.options.locations) {
  4170. ++this$1.curLine;
  4171. this$1.lineStart = this$1.pos;
  4172. }
  4173. break
  4174. case 47: // '/'
  4175. switch (this$1.input.charCodeAt(this$1.pos + 1)) {
  4176. case 42: // '*'
  4177. this$1.skipBlockComment();
  4178. break
  4179. case 47:
  4180. this$1.skipLineComment(2);
  4181. break
  4182. default:
  4183. break loop
  4184. }
  4185. break
  4186. default:
  4187. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  4188. ++this$1.pos;
  4189. } else {
  4190. break loop
  4191. }
  4192. }
  4193. }
  4194. };
  4195. // Called at the end of every token. Sets `end`, `val`, and
  4196. // maintains `context` and `exprAllowed`, and skips the space after
  4197. // the token, so that the next one's `start` will point at the
  4198. // right position.
  4199. pp$8.finishToken = function(type, val) {
  4200. this.end = this.pos;
  4201. if (this.options.locations) { this.endLoc = this.curPosition(); }
  4202. var prevType = this.type;
  4203. this.type = type;
  4204. this.value = val;
  4205. this.updateContext(prevType);
  4206. };
  4207. // ### Token reading
  4208. // This is the function that is called to fetch the next token. It
  4209. // is somewhat obscure, because it works in character codes rather
  4210. // than characters, and because operator parsing has been inlined
  4211. // into it.
  4212. //
  4213. // All in the name of speed.
  4214. //
  4215. pp$8.readToken_dot = function() {
  4216. var next = this.input.charCodeAt(this.pos + 1);
  4217. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  4218. var next2 = this.input.charCodeAt(this.pos + 2);
  4219. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  4220. this.pos += 3;
  4221. return this.finishToken(types.ellipsis)
  4222. } else {
  4223. ++this.pos;
  4224. return this.finishToken(types.dot)
  4225. }
  4226. };
  4227. pp$8.readToken_slash = function() { // '/'
  4228. var next = this.input.charCodeAt(this.pos + 1);
  4229. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  4230. if (next === 61) { return this.finishOp(types.assign, 2) }
  4231. return this.finishOp(types.slash, 1)
  4232. };
  4233. pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
  4234. var next = this.input.charCodeAt(this.pos + 1);
  4235. var size = 1;
  4236. var tokentype = code === 42 ? types.star : types.modulo;
  4237. // exponentiation operator ** and **=
  4238. if (this.options.ecmaVersion >= 7 && code == 42 && next === 42) {
  4239. ++size;
  4240. tokentype = types.starstar;
  4241. next = this.input.charCodeAt(this.pos + 2);
  4242. }
  4243. if (next === 61) { return this.finishOp(types.assign, size + 1) }
  4244. return this.finishOp(tokentype, size)
  4245. };
  4246. pp$8.readToken_pipe_amp = function(code) { // '|&'
  4247. var next = this.input.charCodeAt(this.pos + 1);
  4248. if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
  4249. if (next === 61) { return this.finishOp(types.assign, 2) }
  4250. return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
  4251. };
  4252. pp$8.readToken_caret = function() { // '^'
  4253. var next = this.input.charCodeAt(this.pos + 1);
  4254. if (next === 61) { return this.finishOp(types.assign, 2) }
  4255. return this.finishOp(types.bitwiseXOR, 1)
  4256. };
  4257. pp$8.readToken_plus_min = function(code) { // '+-'
  4258. var next = this.input.charCodeAt(this.pos + 1);
  4259. if (next === code) {
  4260. if (next == 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 62 &&
  4261. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  4262. // A `-->` line comment
  4263. this.skipLineComment(3);
  4264. this.skipSpace();
  4265. return this.nextToken()
  4266. }
  4267. return this.finishOp(types.incDec, 2)
  4268. }
  4269. if (next === 61) { return this.finishOp(types.assign, 2) }
  4270. return this.finishOp(types.plusMin, 1)
  4271. };
  4272. pp$8.readToken_lt_gt = function(code) { // '<>'
  4273. var next = this.input.charCodeAt(this.pos + 1);
  4274. var size = 1;
  4275. if (next === code) {
  4276. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  4277. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
  4278. return this.finishOp(types.bitShift, size)
  4279. }
  4280. if (next == 33 && code == 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 45 &&
  4281. this.input.charCodeAt(this.pos + 3) == 45) {
  4282. // `<!--`, an XML-style comment that should be interpreted as a line comment
  4283. this.skipLineComment(4);
  4284. this.skipSpace();
  4285. return this.nextToken()
  4286. }
  4287. if (next === 61) { size = 2; }
  4288. return this.finishOp(types.relational, size)
  4289. };
  4290. pp$8.readToken_eq_excl = function(code) { // '=!'
  4291. var next = this.input.charCodeAt(this.pos + 1);
  4292. if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  4293. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  4294. this.pos += 2;
  4295. return this.finishToken(types.arrow)
  4296. }
  4297. return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
  4298. };
  4299. pp$8.getTokenFromCode = function(code) {
  4300. switch (code) {
  4301. // The interpretation of a dot depends on whether it is followed
  4302. // by a digit or another two dots.
  4303. case 46: // '.'
  4304. return this.readToken_dot()
  4305. // Punctuation tokens.
  4306. case 40: ++this.pos; return this.finishToken(types.parenL)
  4307. case 41: ++this.pos; return this.finishToken(types.parenR)
  4308. case 59: ++this.pos; return this.finishToken(types.semi)
  4309. case 44: ++this.pos; return this.finishToken(types.comma)
  4310. case 91: ++this.pos; return this.finishToken(types.bracketL)
  4311. case 93: ++this.pos; return this.finishToken(types.bracketR)
  4312. case 123: ++this.pos; return this.finishToken(types.braceL)
  4313. case 125: ++this.pos; return this.finishToken(types.braceR)
  4314. case 58: ++this.pos; return this.finishToken(types.colon)
  4315. case 63: ++this.pos; return this.finishToken(types.question)
  4316. case 96: // '`'
  4317. if (this.options.ecmaVersion < 6) { break }
  4318. ++this.pos;
  4319. return this.finishToken(types.backQuote)
  4320. case 48: // '0'
  4321. var next = this.input.charCodeAt(this.pos + 1);
  4322. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  4323. if (this.options.ecmaVersion >= 6) {
  4324. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  4325. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  4326. }
  4327. // Anything else beginning with a digit is an integer, octal
  4328. // number, or float.
  4329. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  4330. return this.readNumber(false)
  4331. // Quotes produce strings.
  4332. case 34: case 39: // '"', "'"
  4333. return this.readString(code)
  4334. // Operators are parsed inline in tiny state machines. '=' (61) is
  4335. // often referred to. `finishOp` simply skips the amount of
  4336. // characters it is given as second argument, and returns a token
  4337. // of the type given by its first argument.
  4338. case 47: // '/'
  4339. return this.readToken_slash()
  4340. case 37: case 42: // '%*'
  4341. return this.readToken_mult_modulo_exp(code)
  4342. case 124: case 38: // '|&'
  4343. return this.readToken_pipe_amp(code)
  4344. case 94: // '^'
  4345. return this.readToken_caret()
  4346. case 43: case 45: // '+-'
  4347. return this.readToken_plus_min(code)
  4348. case 60: case 62: // '<>'
  4349. return this.readToken_lt_gt(code)
  4350. case 61: case 33: // '=!'
  4351. return this.readToken_eq_excl(code)
  4352. case 126: // '~'
  4353. return this.finishOp(types.prefix, 1)
  4354. }
  4355. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  4356. };
  4357. pp$8.finishOp = function(type, size) {
  4358. var str = this.input.slice(this.pos, this.pos + size);
  4359. this.pos += size;
  4360. return this.finishToken(type, str)
  4361. };
  4362. pp$8.readRegexp = function() {
  4363. var this$1 = this;
  4364. var escaped, inClass, start = this.pos;
  4365. for (;;) {
  4366. if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
  4367. var ch = this$1.input.charAt(this$1.pos);
  4368. if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
  4369. if (!escaped) {
  4370. if (ch === "[") { inClass = true; }
  4371. else if (ch === "]" && inClass) { inClass = false; }
  4372. else if (ch === "/" && !inClass) { break }
  4373. escaped = ch === "\\";
  4374. } else { escaped = false; }
  4375. ++this$1.pos;
  4376. }
  4377. var pattern = this.input.slice(start, this.pos);
  4378. ++this.pos;
  4379. var flagsStart = this.pos;
  4380. var flags = this.readWord1();
  4381. if (this.containsEsc) { this.unexpected(flagsStart); }
  4382. // Validate pattern
  4383. var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
  4384. state.reset(start, pattern, flags);
  4385. this.validateRegExpFlags(state);
  4386. this.validateRegExpPattern(state);
  4387. // Create Literal#value property value.
  4388. var value = null;
  4389. try {
  4390. value = new RegExp(pattern, flags);
  4391. } catch (e) {
  4392. // ESTree requires null if it failed to instantiate RegExp object.
  4393. // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
  4394. }
  4395. return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
  4396. };
  4397. // Read an integer in the given radix. Return null if zero digits
  4398. // were read, the integer value otherwise. When `len` is given, this
  4399. // will return `null` unless the integer has exactly `len` digits.
  4400. pp$8.readInt = function(radix, len) {
  4401. var this$1 = this;
  4402. var start = this.pos, total = 0;
  4403. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  4404. var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
  4405. if (code >= 97) { val = code - 97 + 10; } // a
  4406. else if (code >= 65) { val = code - 65 + 10; } // A
  4407. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  4408. else { val = Infinity; }
  4409. if (val >= radix) { break }
  4410. ++this$1.pos;
  4411. total = total * radix + val;
  4412. }
  4413. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  4414. return total
  4415. };
  4416. pp$8.readRadixNumber = function(radix) {
  4417. this.pos += 2; // 0x
  4418. var val = this.readInt(radix);
  4419. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  4420. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4421. return this.finishToken(types.num, val)
  4422. };
  4423. // Read an integer, octal integer, or floating-point number.
  4424. pp$8.readNumber = function(startsWithDot) {
  4425. var start = this.pos;
  4426. if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4427. var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  4428. if (octal && this.strict) { this.raise(start, "Invalid number"); }
  4429. if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
  4430. var next = this.input.charCodeAt(this.pos);
  4431. if (next === 46 && !octal) { // '.'
  4432. ++this.pos;
  4433. this.readInt(10);
  4434. next = this.input.charCodeAt(this.pos);
  4435. }
  4436. if ((next === 69 || next === 101) && !octal) { // 'eE'
  4437. next = this.input.charCodeAt(++this.pos);
  4438. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  4439. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4440. }
  4441. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4442. var str = this.input.slice(start, this.pos);
  4443. var val = octal ? parseInt(str, 8) : parseFloat(str);
  4444. return this.finishToken(types.num, val)
  4445. };
  4446. // Read a string value, interpreting backslash-escapes.
  4447. pp$8.readCodePoint = function() {
  4448. var ch = this.input.charCodeAt(this.pos), code;
  4449. if (ch === 123) { // '{'
  4450. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  4451. var codePos = ++this.pos;
  4452. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  4453. ++this.pos;
  4454. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  4455. } else {
  4456. code = this.readHexChar(4);
  4457. }
  4458. return code
  4459. };
  4460. function codePointToString(code) {
  4461. // UTF-16 Decoding
  4462. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  4463. code -= 0x10000;
  4464. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  4465. }
  4466. pp$8.readString = function(quote) {
  4467. var this$1 = this;
  4468. var out = "", chunkStart = ++this.pos;
  4469. for (;;) {
  4470. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
  4471. var ch = this$1.input.charCodeAt(this$1.pos);
  4472. if (ch === quote) { break }
  4473. if (ch === 92) { // '\'
  4474. out += this$1.input.slice(chunkStart, this$1.pos);
  4475. out += this$1.readEscapedChar(false);
  4476. chunkStart = this$1.pos;
  4477. } else {
  4478. if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
  4479. ++this$1.pos;
  4480. }
  4481. }
  4482. out += this.input.slice(chunkStart, this.pos++);
  4483. return this.finishToken(types.string, out)
  4484. };
  4485. // Reads template string tokens.
  4486. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  4487. pp$8.tryReadTemplateToken = function() {
  4488. this.inTemplateElement = true;
  4489. try {
  4490. this.readTmplToken();
  4491. } catch (err) {
  4492. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  4493. this.readInvalidTemplateToken();
  4494. } else {
  4495. throw err
  4496. }
  4497. }
  4498. this.inTemplateElement = false;
  4499. };
  4500. pp$8.invalidStringToken = function(position, message) {
  4501. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  4502. throw INVALID_TEMPLATE_ESCAPE_ERROR
  4503. } else {
  4504. this.raise(position, message);
  4505. }
  4506. };
  4507. pp$8.readTmplToken = function() {
  4508. var this$1 = this;
  4509. var out = "", chunkStart = this.pos;
  4510. for (;;) {
  4511. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
  4512. var ch = this$1.input.charCodeAt(this$1.pos);
  4513. if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
  4514. if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
  4515. if (ch === 36) {
  4516. this$1.pos += 2;
  4517. return this$1.finishToken(types.dollarBraceL)
  4518. } else {
  4519. ++this$1.pos;
  4520. return this$1.finishToken(types.backQuote)
  4521. }
  4522. }
  4523. out += this$1.input.slice(chunkStart, this$1.pos);
  4524. return this$1.finishToken(types.template, out)
  4525. }
  4526. if (ch === 92) { // '\'
  4527. out += this$1.input.slice(chunkStart, this$1.pos);
  4528. out += this$1.readEscapedChar(true);
  4529. chunkStart = this$1.pos;
  4530. } else if (isNewLine(ch)) {
  4531. out += this$1.input.slice(chunkStart, this$1.pos);
  4532. ++this$1.pos;
  4533. switch (ch) {
  4534. case 13:
  4535. if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
  4536. case 10:
  4537. out += "\n";
  4538. break
  4539. default:
  4540. out += String.fromCharCode(ch);
  4541. break
  4542. }
  4543. if (this$1.options.locations) {
  4544. ++this$1.curLine;
  4545. this$1.lineStart = this$1.pos;
  4546. }
  4547. chunkStart = this$1.pos;
  4548. } else {
  4549. ++this$1.pos;
  4550. }
  4551. }
  4552. };
  4553. // Reads a template token to search for the end, without validating any escape sequences
  4554. pp$8.readInvalidTemplateToken = function() {
  4555. var this$1 = this;
  4556. for (; this.pos < this.input.length; this.pos++) {
  4557. switch (this$1.input[this$1.pos]) {
  4558. case "\\":
  4559. ++this$1.pos;
  4560. break
  4561. case "$":
  4562. if (this$1.input[this$1.pos + 1] !== "{") {
  4563. break
  4564. }
  4565. // falls through
  4566. case "`":
  4567. return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
  4568. // no default
  4569. }
  4570. }
  4571. this.raise(this.start, "Unterminated template");
  4572. };
  4573. // Used to read escaped characters
  4574. pp$8.readEscapedChar = function(inTemplate) {
  4575. var ch = this.input.charCodeAt(++this.pos);
  4576. ++this.pos;
  4577. switch (ch) {
  4578. case 110: return "\n" // 'n' -> '\n'
  4579. case 114: return "\r" // 'r' -> '\r'
  4580. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  4581. case 117: return codePointToString(this.readCodePoint()) // 'u'
  4582. case 116: return "\t" // 't' -> '\t'
  4583. case 98: return "\b" // 'b' -> '\b'
  4584. case 118: return "\u000b" // 'v' -> '\u000b'
  4585. case 102: return "\f" // 'f' -> '\f'
  4586. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  4587. case 10: // ' \n'
  4588. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  4589. return ""
  4590. default:
  4591. if (ch >= 48 && ch <= 55) {
  4592. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  4593. var octal = parseInt(octalStr, 8);
  4594. if (octal > 255) {
  4595. octalStr = octalStr.slice(0, -1);
  4596. octal = parseInt(octalStr, 8);
  4597. }
  4598. this.pos += octalStr.length - 1;
  4599. ch = this.input.charCodeAt(this.pos);
  4600. if ((octalStr !== "0" || ch == 56 || ch == 57) && (this.strict || inTemplate)) {
  4601. this.invalidStringToken(
  4602. this.pos - 1 - octalStr.length,
  4603. inTemplate
  4604. ? "Octal literal in template string"
  4605. : "Octal literal in strict mode"
  4606. );
  4607. }
  4608. return String.fromCharCode(octal)
  4609. }
  4610. return String.fromCharCode(ch)
  4611. }
  4612. };
  4613. // Used to read character escape sequences ('\x', '\u', '\U').
  4614. pp$8.readHexChar = function(len) {
  4615. var codePos = this.pos;
  4616. var n = this.readInt(16, len);
  4617. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  4618. return n
  4619. };
  4620. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  4621. // to whether the word contained a '\u' escape.
  4622. //
  4623. // Incrementally adds only escaped chars, adding other chunks as-is
  4624. // as a micro-optimization.
  4625. pp$8.readWord1 = function() {
  4626. var this$1 = this;
  4627. this.containsEsc = false;
  4628. var word = "", first = true, chunkStart = this.pos;
  4629. var astral = this.options.ecmaVersion >= 6;
  4630. while (this.pos < this.input.length) {
  4631. var ch = this$1.fullCharCodeAtPos();
  4632. if (isIdentifierChar(ch, astral)) {
  4633. this$1.pos += ch <= 0xffff ? 1 : 2;
  4634. } else if (ch === 92) { // "\"
  4635. this$1.containsEsc = true;
  4636. word += this$1.input.slice(chunkStart, this$1.pos);
  4637. var escStart = this$1.pos;
  4638. if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
  4639. { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  4640. ++this$1.pos;
  4641. var esc = this$1.readCodePoint();
  4642. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  4643. { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
  4644. word += codePointToString(esc);
  4645. chunkStart = this$1.pos;
  4646. } else {
  4647. break
  4648. }
  4649. first = false;
  4650. }
  4651. return word + this.input.slice(chunkStart, this.pos)
  4652. };
  4653. // Read an identifier or keyword token. Will check for reserved
  4654. // words when necessary.
  4655. pp$8.readWord = function() {
  4656. var word = this.readWord1();
  4657. var type = types.name;
  4658. if (this.keywords.test(word)) {
  4659. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
  4660. type = keywords$1[word];
  4661. }
  4662. return this.finishToken(type, word)
  4663. };
  4664. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  4665. //
  4666. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  4667. // various contributors and released under an MIT license.
  4668. //
  4669. // Git repositories for Acorn are available at
  4670. //
  4671. // http://marijnhaverbeke.nl/git/acorn
  4672. // https://github.com/acornjs/acorn.git
  4673. //
  4674. // Please use the [github bug tracker][ghbt] to report issues.
  4675. //
  4676. // [ghbt]: https://github.com/acornjs/acorn/issues
  4677. //
  4678. // This file defines the main parser interface. The library also comes
  4679. // with a [error-tolerant parser][dammit] and an
  4680. // [abstract syntax tree walker][walk], defined in other files.
  4681. //
  4682. // [dammit]: acorn_loose.js
  4683. // [walk]: util/walk.js
  4684. var version = "5.5.3";
  4685. // The main exported interface (under `self.acorn` when in the
  4686. // browser) is a `parse` function that takes a code string and
  4687. // returns an abstract syntax tree as specified by [Mozilla parser
  4688. // API][api].
  4689. //
  4690. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  4691. function parse(input, options) {
  4692. return new Parser(options, input).parse()
  4693. }
  4694. // This function tries to parse a single expression at a given
  4695. // offset in a string. Useful for parsing mixed-language formats
  4696. // that embed JavaScript expressions.
  4697. function parseExpressionAt(input, pos, options) {
  4698. var p = new Parser(options, input, pos);
  4699. p.nextToken();
  4700. return p.parseExpression()
  4701. }
  4702. // Acorn is organized as a tokenizer and a recursive-descent parser.
  4703. // The `tokenizer` export provides an interface to the tokenizer.
  4704. function tokenizer(input, options) {
  4705. return new Parser(options, input)
  4706. }
  4707. // This is a terrible kludge to support the existing, pre-ES6
  4708. // interface where the loose parser module retroactively adds exports
  4709. // to this module.
  4710. var parse_dammit;
  4711. var LooseParser;
  4712. var pluginsLoose; // eslint-disable-line camelcase
  4713. function addLooseExports(parse, Parser$$1, plugins$$1) {
  4714. parse_dammit = parse; // eslint-disable-line camelcase
  4715. LooseParser = Parser$$1;
  4716. pluginsLoose = plugins$$1;
  4717. }
  4718. var acorn = /*#__PURE__*/Object.freeze({
  4719. version: version,
  4720. parse: parse,
  4721. parseExpressionAt: parseExpressionAt,
  4722. tokenizer: tokenizer,
  4723. get parse_dammit () { return parse_dammit; },
  4724. get LooseParser () { return LooseParser; },
  4725. get pluginsLoose () { return pluginsLoose; },
  4726. addLooseExports: addLooseExports,
  4727. Parser: Parser,
  4728. plugins: plugins,
  4729. defaultOptions: defaultOptions,
  4730. Position: Position,
  4731. SourceLocation: SourceLocation,
  4732. getLineInfo: getLineInfo,
  4733. Node: Node,
  4734. TokenType: TokenType,
  4735. tokTypes: types,
  4736. keywordTypes: keywords$1,
  4737. TokContext: TokContext,
  4738. tokContexts: types$1,
  4739. isIdentifierChar: isIdentifierChar,
  4740. isIdentifierStart: isIdentifierStart,
  4741. Token: Token,
  4742. isNewLine: isNewLine,
  4743. lineBreak: lineBreak,
  4744. lineBreakG: lineBreakG,
  4745. nonASCIIwhitespace: nonASCIIwhitespace
  4746. });
  4747. const literals = new Map([['true', true], ['false', false], ['null', null]]);
  4748. function readExpression(parser) {
  4749. const start = parser.index;
  4750. const name = parser.readUntil(/\s*}/);
  4751. if (name && /^[a-z]+$/.test(name)) {
  4752. const end = start + name.length;
  4753. if (literals.has(name)) {
  4754. return {
  4755. type: 'Literal',
  4756. start,
  4757. end,
  4758. value: literals.get(name),
  4759. raw: name,
  4760. };
  4761. }
  4762. return {
  4763. type: 'Identifier',
  4764. start,
  4765. end: start + name.length,
  4766. name,
  4767. };
  4768. }
  4769. parser.index = start;
  4770. try {
  4771. const node = parseExpressionAt(parser.template, parser.index, {
  4772. ecmaVersion: 9,
  4773. preserveParens: true,
  4774. });
  4775. parser.index = node.end;
  4776. return node;
  4777. }
  4778. catch (err) {
  4779. parser.acornError(err);
  4780. }
  4781. }
  4782. /* eslint-disable no-underscore-dangle */
  4783. const DynamicImportKey = 'Import';
  4784. function injectDynamicImport(acorn) {
  4785. const tt = acorn.tokTypes;
  4786. // NOTE: This allows `yield import()` to parse correctly.
  4787. tt._import.startsExpr = true;
  4788. function parseDynamicImport() {
  4789. const node = this.startNode();
  4790. this.next();
  4791. if (this.type !== tt.parenL) {
  4792. this.unexpected();
  4793. }
  4794. return this.finishNode(node, DynamicImportKey);
  4795. }
  4796. function peekNext() {
  4797. return this.input[this.pos];
  4798. }
  4799. // eslint-disable-next-line no-param-reassign
  4800. acorn.plugins.dynamicImport = function dynamicImportPlugin(instance) {
  4801. instance.extend('parseStatement', nextMethod => (
  4802. function parseStatement(...args) {
  4803. const node = this.startNode();
  4804. if (this.type === tt._import) {
  4805. const nextToken = peekNext.call(this);
  4806. if (nextToken === tt.parenL.label) {
  4807. const expr = this.parseExpression();
  4808. return this.parseExpressionStatement(node, expr);
  4809. }
  4810. }
  4811. return nextMethod.apply(this, args);
  4812. }
  4813. ));
  4814. instance.extend('parseExprAtom', nextMethod => (
  4815. function parseExprAtom(refDestructuringErrors) {
  4816. if (this.type === tt._import) {
  4817. return parseDynamicImport.call(this);
  4818. }
  4819. return nextMethod.call(this, refDestructuringErrors);
  4820. }
  4821. ));
  4822. };
  4823. return acorn;
  4824. }
  4825. function repeat(str, i) {
  4826. let result = '';
  4827. while (i--)
  4828. result += str;
  4829. return result;
  4830. }
  4831. const scriptClosingTag = '</script>';
  4832. injectDynamicImport(acorn);
  4833. function readScript(parser, start, attributes) {
  4834. const scriptStart = parser.index;
  4835. const scriptEnd = parser.template.indexOf(scriptClosingTag, scriptStart);
  4836. if (scriptEnd === -1)
  4837. parser.error({
  4838. code: `unclosed-script`,
  4839. message: `<script> must have a closing tag`
  4840. });
  4841. const source = repeat(' ', scriptStart) + parser.template.slice(scriptStart, scriptEnd);
  4842. parser.index = scriptEnd + scriptClosingTag.length;
  4843. let ast;
  4844. try {
  4845. ast = parse(source, {
  4846. ecmaVersion: 9,
  4847. sourceType: 'module',
  4848. plugins: {
  4849. dynamicImport: true
  4850. }
  4851. });
  4852. }
  4853. catch (err) {
  4854. parser.acornError(err);
  4855. }
  4856. if (!ast.body.length)
  4857. return null;
  4858. ast.start = scriptStart;
  4859. return {
  4860. start,
  4861. end: parser.index,
  4862. attributes,
  4863. content: ast,
  4864. };
  4865. }
  4866. var MAX_LINE_LENGTH = 100;
  4867. var OFFSET_CORRECTION = 60;
  4868. var TAB_REPLACEMENT = ' ';
  4869. function sourceFragment(error, extraLines) {
  4870. function processLines(start, end) {
  4871. return lines.slice(start, end).map(function(line, idx) {
  4872. var num = String(start + idx + 1);
  4873. while (num.length < maxNumLength) {
  4874. num = ' ' + num;
  4875. }
  4876. return num + ' |' + line;
  4877. }).join('\n');
  4878. }
  4879. var lines = error.source.split(/\n|\r\n?|\f/);
  4880. var line = error.line;
  4881. var column = error.column;
  4882. var startLine = Math.max(1, line - extraLines) - 1;
  4883. var endLine = Math.min(line + extraLines, lines.length + 1);
  4884. var maxNumLength = Math.max(4, String(endLine).length) + 1;
  4885. var cutLeft = 0;
  4886. // correct column according to replaced tab before column
  4887. column += (TAB_REPLACEMENT.length - 1) * (lines[line - 1].substr(0, column - 1).match(/\t/g) || []).length;
  4888. if (column > MAX_LINE_LENGTH) {
  4889. cutLeft = column - OFFSET_CORRECTION + 3;
  4890. column = OFFSET_CORRECTION - 2;
  4891. }
  4892. for (var i = startLine; i <= endLine; i++) {
  4893. if (i >= 0 && i < lines.length) {
  4894. lines[i] = lines[i].replace(/\t/g, TAB_REPLACEMENT);
  4895. lines[i] =
  4896. (cutLeft > 0 && lines[i].length > cutLeft ? '\u2026' : '') +
  4897. lines[i].substr(cutLeft, MAX_LINE_LENGTH - 2) +
  4898. (lines[i].length > cutLeft + MAX_LINE_LENGTH - 1 ? '\u2026' : '');
  4899. }
  4900. }
  4901. return [
  4902. processLines(startLine, line),
  4903. new Array(column + maxNumLength + 2).join('-') + '^',
  4904. processLines(line, endLine)
  4905. ].join('\n');
  4906. }
  4907. var CssSyntaxError = function(message, source, offset, line, column) {
  4908. // some VMs prevent setting line/column otherwise (iOS Safari 10 even throw an exception)
  4909. var error = Object.create(SyntaxError.prototype);
  4910. error.name = 'CssSyntaxError';
  4911. error.message = message;
  4912. error.stack = (new Error().stack || '').replace(/^.+\n/, error.name + ': ' + error.message + '\n');
  4913. error.source = source;
  4914. error.offset = offset;
  4915. error.line = line;
  4916. error.column = column;
  4917. error.sourceFragment = function(extraLines) {
  4918. return sourceFragment(error, isNaN(extraLines) ? 0 : extraLines);
  4919. };
  4920. Object.defineProperty(error, 'formattedMessage', {
  4921. get: function() {
  4922. return (
  4923. 'Parse error: ' + error.message + '\n' +
  4924. sourceFragment(error, 2)
  4925. );
  4926. }
  4927. });
  4928. // for backward capability
  4929. error.parseError = {
  4930. offset: offset,
  4931. line: line,
  4932. column: column
  4933. };
  4934. return error;
  4935. };
  4936. var error = CssSyntaxError;
  4937. var error$1 = /*#__PURE__*/Object.freeze({
  4938. default: error,
  4939. __moduleExports: error
  4940. });
  4941. // token types (note: value shouldn't intersect with used char codes)
  4942. var WHITESPACE = 1;
  4943. var IDENTIFIER = 2;
  4944. var NUMBER = 3;
  4945. var STRING = 4;
  4946. var COMMENT = 5;
  4947. var PUNCTUATOR = 6;
  4948. var CDO = 7;
  4949. var CDC = 8;
  4950. var ATRULE = 14;
  4951. var FUNCTION = 15;
  4952. var URL = 16;
  4953. var RAW = 17;
  4954. var TAB = 9;
  4955. var N = 10;
  4956. var F = 12;
  4957. var R = 13;
  4958. var SPACE = 32;
  4959. var TYPE = {
  4960. WhiteSpace: WHITESPACE,
  4961. Identifier: IDENTIFIER,
  4962. Number: NUMBER,
  4963. String: STRING,
  4964. Comment: COMMENT,
  4965. Punctuator: PUNCTUATOR,
  4966. CDO: CDO,
  4967. CDC: CDC,
  4968. Atrule: ATRULE,
  4969. Function: FUNCTION,
  4970. Url: URL,
  4971. Raw: RAW,
  4972. ExclamationMark: 33, // !
  4973. QuotationMark: 34, // "
  4974. NumberSign: 35, // #
  4975. DollarSign: 36, // $
  4976. PercentSign: 37, // %
  4977. Ampersand: 38, // &
  4978. Apostrophe: 39, // '
  4979. LeftParenthesis: 40, // (
  4980. RightParenthesis: 41, // )
  4981. Asterisk: 42, // *
  4982. PlusSign: 43, // +
  4983. Comma: 44, // ,
  4984. HyphenMinus: 45, // -
  4985. FullStop: 46, // .
  4986. Solidus: 47, // /
  4987. Colon: 58, // :
  4988. Semicolon: 59, // ;
  4989. LessThanSign: 60, // <
  4990. EqualsSign: 61, // =
  4991. GreaterThanSign: 62, // >
  4992. QuestionMark: 63, // ?
  4993. CommercialAt: 64, // @
  4994. LeftSquareBracket: 91, // [
  4995. Backslash: 92, // \
  4996. RightSquareBracket: 93, // ]
  4997. CircumflexAccent: 94, // ^
  4998. LowLine: 95, // _
  4999. GraveAccent: 96, // `
  5000. LeftCurlyBracket: 123, // {
  5001. VerticalLine: 124, // |
  5002. RightCurlyBracket: 125, // }
  5003. Tilde: 126 // ~
  5004. };
  5005. var NAME = Object.keys(TYPE).reduce(function(result, key) {
  5006. result[TYPE[key]] = key;
  5007. return result;
  5008. }, {});
  5009. // https://drafts.csswg.org/css-syntax/#tokenizer-definitions
  5010. // > non-ASCII code point
  5011. // > A code point with a value equal to or greater than U+0080 <control>
  5012. // > name-start code point
  5013. // > A letter, a non-ASCII code point, or U+005F LOW LINE (_).
  5014. // > name code point
  5015. // > A name-start code point, a digit, or U+002D HYPHEN-MINUS (-)
  5016. // That means only ASCII code points has a special meaning and we a maps for 0..127 codes only
  5017. var SafeUint32Array = typeof Uint32Array !== 'undefined' ? Uint32Array : Array; // fallback on Array when TypedArray is not supported
  5018. var SYMBOL_TYPE = new SafeUint32Array(0x80);
  5019. var PUNCTUATION = new SafeUint32Array(0x80);
  5020. var STOP_URL_RAW = new SafeUint32Array(0x80);
  5021. for (var i = 0; i < SYMBOL_TYPE.length; i++) {
  5022. SYMBOL_TYPE[i] = IDENTIFIER;
  5023. }
  5024. // fill categories
  5025. [
  5026. TYPE.ExclamationMark, // !
  5027. TYPE.QuotationMark, // "
  5028. TYPE.NumberSign, // #
  5029. TYPE.DollarSign, // $
  5030. TYPE.PercentSign, // %
  5031. TYPE.Ampersand, // &
  5032. TYPE.Apostrophe, // '
  5033. TYPE.LeftParenthesis, // (
  5034. TYPE.RightParenthesis, // )
  5035. TYPE.Asterisk, // *
  5036. TYPE.PlusSign, // +
  5037. TYPE.Comma, // ,
  5038. TYPE.HyphenMinus, // -
  5039. TYPE.FullStop, // .
  5040. TYPE.Solidus, // /
  5041. TYPE.Colon, // :
  5042. TYPE.Semicolon, // ;
  5043. TYPE.LessThanSign, // <
  5044. TYPE.EqualsSign, // =
  5045. TYPE.GreaterThanSign, // >
  5046. TYPE.QuestionMark, // ?
  5047. TYPE.CommercialAt, // @
  5048. TYPE.LeftSquareBracket, // [
  5049. // TYPE.Backslash, // \
  5050. TYPE.RightSquareBracket, // ]
  5051. TYPE.CircumflexAccent, // ^
  5052. // TYPE.LowLine, // _
  5053. TYPE.GraveAccent, // `
  5054. TYPE.LeftCurlyBracket, // {
  5055. TYPE.VerticalLine, // |
  5056. TYPE.RightCurlyBracket, // }
  5057. TYPE.Tilde // ~
  5058. ].forEach(function(key) {
  5059. SYMBOL_TYPE[Number(key)] = PUNCTUATOR;
  5060. PUNCTUATION[Number(key)] = PUNCTUATOR;
  5061. });
  5062. for (var i = 48; i <= 57; i++) {
  5063. SYMBOL_TYPE[i] = NUMBER;
  5064. }
  5065. SYMBOL_TYPE[SPACE] = WHITESPACE;
  5066. SYMBOL_TYPE[TAB] = WHITESPACE;
  5067. SYMBOL_TYPE[N] = WHITESPACE;
  5068. SYMBOL_TYPE[R] = WHITESPACE;
  5069. SYMBOL_TYPE[F] = WHITESPACE;
  5070. SYMBOL_TYPE[TYPE.Apostrophe] = STRING;
  5071. SYMBOL_TYPE[TYPE.QuotationMark] = STRING;
  5072. STOP_URL_RAW[SPACE] = 1;
  5073. STOP_URL_RAW[TAB] = 1;
  5074. STOP_URL_RAW[N] = 1;
  5075. STOP_URL_RAW[R] = 1;
  5076. STOP_URL_RAW[F] = 1;
  5077. STOP_URL_RAW[TYPE.Apostrophe] = 1;
  5078. STOP_URL_RAW[TYPE.QuotationMark] = 1;
  5079. STOP_URL_RAW[TYPE.LeftParenthesis] = 1;
  5080. STOP_URL_RAW[TYPE.RightParenthesis] = 1;
  5081. // whitespace is punctuation ...
  5082. PUNCTUATION[SPACE] = PUNCTUATOR;
  5083. PUNCTUATION[TAB] = PUNCTUATOR;
  5084. PUNCTUATION[N] = PUNCTUATOR;
  5085. PUNCTUATION[R] = PUNCTUATOR;
  5086. PUNCTUATION[F] = PUNCTUATOR;
  5087. // ... hyper minus is not
  5088. PUNCTUATION[TYPE.HyphenMinus] = 0;
  5089. var _const = {
  5090. TYPE: TYPE,
  5091. NAME: NAME,
  5092. SYMBOL_TYPE: SYMBOL_TYPE,
  5093. PUNCTUATION: PUNCTUATION,
  5094. STOP_URL_RAW: STOP_URL_RAW
  5095. };
  5096. var _const_1 = _const.TYPE;
  5097. var _const_2 = _const.NAME;
  5098. var _const_3 = _const.SYMBOL_TYPE;
  5099. var _const_4 = _const.PUNCTUATION;
  5100. var _const_5 = _const.STOP_URL_RAW;
  5101. var _const$1 = /*#__PURE__*/Object.freeze({
  5102. default: _const,
  5103. __moduleExports: _const,
  5104. TYPE: _const_1,
  5105. NAME: _const_2,
  5106. SYMBOL_TYPE: _const_3,
  5107. PUNCTUATION: _const_4,
  5108. STOP_URL_RAW: _const_5
  5109. });
  5110. var constants = ( _const$1 && _const ) || _const$1;
  5111. var PUNCTUATION$1 = constants.PUNCTUATION;
  5112. var STOP_URL_RAW$1 = constants.STOP_URL_RAW;
  5113. var TYPE$1 = constants.TYPE;
  5114. var FULLSTOP = TYPE$1.FullStop;
  5115. var PLUSSIGN = TYPE$1.PlusSign;
  5116. var HYPHENMINUS = TYPE$1.HyphenMinus;
  5117. var PUNCTUATOR$1 = TYPE$1.Punctuator;
  5118. var TAB$1 = 9;
  5119. var N$1 = 10;
  5120. var F$1 = 12;
  5121. var R$1 = 13;
  5122. var SPACE$1 = 32;
  5123. var BACK_SLASH = 92;
  5124. var E = 101; // 'e'.charCodeAt(0)
  5125. function firstCharOffset(source) {
  5126. // detect BOM (https://en.wikipedia.org/wiki/Byte_order_mark)
  5127. if (source.charCodeAt(0) === 0xFEFF || // UTF-16BE
  5128. source.charCodeAt(0) === 0xFFFE) { // UTF-16LE
  5129. return 1;
  5130. }
  5131. return 0;
  5132. }
  5133. function isHex(code) {
  5134. return (code >= 48 && code <= 57) || // 0 .. 9
  5135. (code >= 65 && code <= 70) || // A .. F
  5136. (code >= 97 && code <= 102); // a .. f
  5137. }
  5138. function isNumber(code) {
  5139. return code >= 48 && code <= 57;
  5140. }
  5141. function isNewline(source, offset, code) {
  5142. if (code === N$1 || code === F$1 || code === R$1) {
  5143. if (code === R$1 && offset + 1 < source.length && source.charCodeAt(offset + 1) === N$1) {
  5144. return 2;
  5145. }
  5146. return 1;
  5147. }
  5148. return 0;
  5149. }
  5150. function cmpChar(testStr, offset, referenceCode) {
  5151. var code = testStr.charCodeAt(offset);
  5152. // code.toLowerCase()
  5153. if (code >= 65 && code <= 90) {
  5154. code = code | 32;
  5155. }
  5156. return code === referenceCode;
  5157. }
  5158. function cmpStr(testStr, start, end, referenceStr) {
  5159. if (end - start !== referenceStr.length) {
  5160. return false;
  5161. }
  5162. if (start < 0 || end > testStr.length) {
  5163. return false;
  5164. }
  5165. for (var i = start; i < end; i++) {
  5166. var testCode = testStr.charCodeAt(i);
  5167. var refCode = referenceStr.charCodeAt(i - start);
  5168. // testStr[i].toLowerCase()
  5169. if (testCode >= 65 && testCode <= 90) {
  5170. testCode = testCode | 32;
  5171. }
  5172. if (testCode !== refCode) {
  5173. return false;
  5174. }
  5175. }
  5176. return true;
  5177. }
  5178. function endsWith(testStr, referenceStr) {
  5179. return cmpStr(testStr, testStr.length - referenceStr.length, testStr.length, referenceStr);
  5180. }
  5181. function findLastNonSpaceLocation(scanner) {
  5182. for (var i = scanner.source.length - 1; i >= 0; i--) {
  5183. var code = scanner.source.charCodeAt(i);
  5184. if (code !== SPACE$1 && code !== TAB$1 && code !== R$1 && code !== N$1 && code !== F$1) {
  5185. break;
  5186. }
  5187. }
  5188. return scanner.getLocation(i + 1);
  5189. }
  5190. function findWhiteSpaceEnd(source, offset) {
  5191. for (; offset < source.length; offset++) {
  5192. var code = source.charCodeAt(offset);
  5193. if (code !== SPACE$1 && code !== TAB$1 && code !== R$1 && code !== N$1 && code !== F$1) {
  5194. break;
  5195. }
  5196. }
  5197. return offset;
  5198. }
  5199. function findCommentEnd(source, offset) {
  5200. var commentEnd = source.indexOf('*/', offset);
  5201. if (commentEnd === -1) {
  5202. return source.length;
  5203. }
  5204. return commentEnd + 2;
  5205. }
  5206. function findStringEnd(source, offset, quote) {
  5207. for (; offset < source.length; offset++) {
  5208. var code = source.charCodeAt(offset);
  5209. // TODO: bad string
  5210. if (code === BACK_SLASH) {
  5211. offset++;
  5212. } else if (code === quote) {
  5213. offset++;
  5214. break;
  5215. }
  5216. }
  5217. return offset;
  5218. }
  5219. function findDecimalNumberEnd(source, offset) {
  5220. for (; offset < source.length; offset++) {
  5221. var code = source.charCodeAt(offset);
  5222. if (code < 48 || code > 57) { // not a 0 .. 9
  5223. break;
  5224. }
  5225. }
  5226. return offset;
  5227. }
  5228. function findNumberEnd(source, offset, allowFraction) {
  5229. var code;
  5230. offset = findDecimalNumberEnd(source, offset);
  5231. // fraction: .\d+
  5232. if (allowFraction && offset + 1 < source.length && source.charCodeAt(offset) === FULLSTOP) {
  5233. code = source.charCodeAt(offset + 1);
  5234. if (isNumber(code)) {
  5235. offset = findDecimalNumberEnd(source, offset + 1);
  5236. }
  5237. }
  5238. // exponent: e[+-]\d+
  5239. if (offset + 1 < source.length) {
  5240. if ((source.charCodeAt(offset) | 32) === E) { // case insensitive check for `e`
  5241. code = source.charCodeAt(offset + 1);
  5242. if (code === PLUSSIGN || code === HYPHENMINUS) {
  5243. if (offset + 2 < source.length) {
  5244. code = source.charCodeAt(offset + 2);
  5245. }
  5246. }
  5247. if (isNumber(code)) {
  5248. offset = findDecimalNumberEnd(source, offset + 2);
  5249. }
  5250. }
  5251. }
  5252. return offset;
  5253. }
  5254. // skip escaped unicode sequence that can ends with space
  5255. // [0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
  5256. function findEscaseEnd(source, offset) {
  5257. for (var i = 0; i < 7 && offset + i < source.length; i++) {
  5258. var code = source.charCodeAt(offset + i);
  5259. if (i !== 6 && isHex(code)) {
  5260. continue;
  5261. }
  5262. if (i > 0) {
  5263. offset += i - 1 + isNewline(source, offset + i, code);
  5264. if (code === SPACE$1 || code === TAB$1) {
  5265. offset++;
  5266. }
  5267. }
  5268. break;
  5269. }
  5270. return offset;
  5271. }
  5272. function findIdentifierEnd(source, offset) {
  5273. for (; offset < source.length; offset++) {
  5274. var code = source.charCodeAt(offset);
  5275. if (code === BACK_SLASH) {
  5276. offset = findEscaseEnd(source, offset + 1);
  5277. } else if (code < 0x80 && PUNCTUATION$1[code] === PUNCTUATOR$1) {
  5278. break;
  5279. }
  5280. }
  5281. return offset;
  5282. }
  5283. function findUrlRawEnd(source, offset) {
  5284. for (; offset < source.length; offset++) {
  5285. var code = source.charCodeAt(offset);
  5286. if (code === BACK_SLASH) {
  5287. offset = findEscaseEnd(source, offset + 1);
  5288. } else if (code < 0x80 && STOP_URL_RAW$1[code] === 1) {
  5289. break;
  5290. }
  5291. }
  5292. return offset;
  5293. }
  5294. var utils = {
  5295. firstCharOffset: firstCharOffset,
  5296. isHex: isHex,
  5297. isNumber: isNumber,
  5298. isNewline: isNewline,
  5299. cmpChar: cmpChar,
  5300. cmpStr: cmpStr,
  5301. endsWith: endsWith,
  5302. findLastNonSpaceLocation: findLastNonSpaceLocation,
  5303. findWhiteSpaceEnd: findWhiteSpaceEnd,
  5304. findCommentEnd: findCommentEnd,
  5305. findStringEnd: findStringEnd,
  5306. findDecimalNumberEnd: findDecimalNumberEnd,
  5307. findNumberEnd: findNumberEnd,
  5308. findEscaseEnd: findEscaseEnd,
  5309. findIdentifierEnd: findIdentifierEnd,
  5310. findUrlRawEnd: findUrlRawEnd
  5311. };
  5312. var utils_1 = utils.firstCharOffset;
  5313. var utils_2 = utils.isHex;
  5314. var utils_3 = utils.isNumber;
  5315. var utils_4 = utils.isNewline;
  5316. var utils_5 = utils.cmpChar;
  5317. var utils_6 = utils.cmpStr;
  5318. var utils_7 = utils.endsWith;
  5319. var utils_8 = utils.findLastNonSpaceLocation;
  5320. var utils_9 = utils.findWhiteSpaceEnd;
  5321. var utils_10 = utils.findCommentEnd;
  5322. var utils_11 = utils.findStringEnd;
  5323. var utils_12 = utils.findDecimalNumberEnd;
  5324. var utils_13 = utils.findNumberEnd;
  5325. var utils_14 = utils.findEscaseEnd;
  5326. var utils_15 = utils.findIdentifierEnd;
  5327. var utils_16 = utils.findUrlRawEnd;
  5328. var utils$1 = /*#__PURE__*/Object.freeze({
  5329. default: utils,
  5330. __moduleExports: utils,
  5331. firstCharOffset: utils_1,
  5332. isHex: utils_2,
  5333. isNumber: utils_3,
  5334. isNewline: utils_4,
  5335. cmpChar: utils_5,
  5336. cmpStr: utils_6,
  5337. endsWith: utils_7,
  5338. findLastNonSpaceLocation: utils_8,
  5339. findWhiteSpaceEnd: utils_9,
  5340. findCommentEnd: utils_10,
  5341. findStringEnd: utils_11,
  5342. findDecimalNumberEnd: utils_12,
  5343. findNumberEnd: utils_13,
  5344. findEscaseEnd: utils_14,
  5345. findIdentifierEnd: utils_15,
  5346. findUrlRawEnd: utils_16
  5347. });
  5348. var CssSyntaxError$1 = ( error$1 && error ) || error$1;
  5349. var utils$2 = ( utils$1 && utils ) || utils$1;
  5350. var TYPE$2 = constants.TYPE;
  5351. var NAME$1 = constants.NAME;
  5352. var SYMBOL_TYPE$1 = constants.SYMBOL_TYPE;
  5353. var firstCharOffset$1 = utils$2.firstCharOffset;
  5354. var cmpStr$1 = utils$2.cmpStr;
  5355. var isNumber$1 = utils$2.isNumber;
  5356. var findLastNonSpaceLocation$1 = utils$2.findLastNonSpaceLocation;
  5357. var findWhiteSpaceEnd$1 = utils$2.findWhiteSpaceEnd;
  5358. var findCommentEnd$1 = utils$2.findCommentEnd;
  5359. var findStringEnd$1 = utils$2.findStringEnd;
  5360. var findNumberEnd$1 = utils$2.findNumberEnd;
  5361. var findIdentifierEnd$1 = utils$2.findIdentifierEnd;
  5362. var findUrlRawEnd$1 = utils$2.findUrlRawEnd;
  5363. var NULL = 0;
  5364. var WHITESPACE$1 = TYPE$2.WhiteSpace;
  5365. var IDENTIFIER$1 = TYPE$2.Identifier;
  5366. var NUMBER$1 = TYPE$2.Number;
  5367. var STRING$1 = TYPE$2.String;
  5368. var COMMENT$1 = TYPE$2.Comment;
  5369. var PUNCTUATOR$2 = TYPE$2.Punctuator;
  5370. var CDO$1 = TYPE$2.CDO;
  5371. var CDC$1 = TYPE$2.CDC;
  5372. var ATRULE$1 = TYPE$2.Atrule;
  5373. var FUNCTION$1 = TYPE$2.Function;
  5374. var URL$1 = TYPE$2.Url;
  5375. var RAW$1 = TYPE$2.Raw;
  5376. var N$2 = 10;
  5377. var F$2 = 12;
  5378. var R$2 = 13;
  5379. var STAR = TYPE$2.Asterisk;
  5380. var SLASH = TYPE$2.Solidus;
  5381. var FULLSTOP$1 = TYPE$2.FullStop;
  5382. var PLUSSIGN$1 = TYPE$2.PlusSign;
  5383. var HYPHENMINUS$1 = TYPE$2.HyphenMinus;
  5384. var GREATERTHANSIGN = TYPE$2.GreaterThanSign;
  5385. var LESSTHANSIGN = TYPE$2.LessThanSign;
  5386. var EXCLAMATIONMARK = TYPE$2.ExclamationMark;
  5387. var COMMERCIALAT = TYPE$2.CommercialAt;
  5388. var QUOTATIONMARK = TYPE$2.QuotationMark;
  5389. var APOSTROPHE = TYPE$2.Apostrophe;
  5390. var LEFTPARENTHESIS = TYPE$2.LeftParenthesis;
  5391. var RIGHTPARENTHESIS = TYPE$2.RightParenthesis;
  5392. var LEFTCURLYBRACKET = TYPE$2.LeftCurlyBracket;
  5393. var RIGHTCURLYBRACKET = TYPE$2.RightCurlyBracket;
  5394. var LEFTSQUAREBRACKET = TYPE$2.LeftSquareBracket;
  5395. var RIGHTSQUAREBRACKET = TYPE$2.RightSquareBracket;
  5396. var MIN_BUFFER_SIZE = 16 * 1024;
  5397. var OFFSET_MASK = 0x00FFFFFF;
  5398. var TYPE_SHIFT = 24;
  5399. var SafeUint32Array$1 = typeof Uint32Array !== 'undefined' ? Uint32Array : Array; // fallback on Array when TypedArray is not supported
  5400. function computeLinesAndColumns(tokenizer, source) {
  5401. var sourceLength = source.length;
  5402. var start = firstCharOffset$1(source);
  5403. var lines = tokenizer.lines;
  5404. var line = tokenizer.startLine;
  5405. var columns = tokenizer.columns;
  5406. var column = tokenizer.startColumn;
  5407. if (lines === null || lines.length < sourceLength + 1) {
  5408. lines = new SafeUint32Array$1(Math.max(sourceLength + 1024, MIN_BUFFER_SIZE));
  5409. columns = new SafeUint32Array$1(lines.length);
  5410. }
  5411. for (var i = start; i < sourceLength; i++) {
  5412. var code = source.charCodeAt(i);
  5413. lines[i] = line;
  5414. columns[i] = column++;
  5415. if (code === N$2 || code === R$2 || code === F$2) {
  5416. if (code === R$2 && i + 1 < sourceLength && source.charCodeAt(i + 1) === N$2) {
  5417. i++;
  5418. lines[i] = line;
  5419. columns[i] = column;
  5420. }
  5421. line++;
  5422. column = 1;
  5423. }
  5424. }
  5425. lines[i] = line;
  5426. columns[i] = column;
  5427. tokenizer.linesAnsColumnsComputed = true;
  5428. tokenizer.lines = lines;
  5429. tokenizer.columns = columns;
  5430. }
  5431. function tokenLayout(tokenizer, source, startPos) {
  5432. var sourceLength = source.length;
  5433. var offsetAndType = tokenizer.offsetAndType;
  5434. var balance = tokenizer.balance;
  5435. var tokenCount = 0;
  5436. var prevType = 0;
  5437. var offset = startPos;
  5438. var anchor = 0;
  5439. var balanceCloseCode = 0;
  5440. var balanceStart = 0;
  5441. var balancePrev = 0;
  5442. if (offsetAndType === null || offsetAndType.length < sourceLength + 1) {
  5443. offsetAndType = new SafeUint32Array$1(sourceLength + 1024);
  5444. balance = new SafeUint32Array$1(sourceLength + 1024);
  5445. }
  5446. while (offset < sourceLength) {
  5447. var code = source.charCodeAt(offset);
  5448. var type = code < 0x80 ? SYMBOL_TYPE$1[code] : IDENTIFIER$1;
  5449. balance[tokenCount] = sourceLength;
  5450. switch (type) {
  5451. case WHITESPACE$1:
  5452. offset = findWhiteSpaceEnd$1(source, offset + 1);
  5453. break;
  5454. case PUNCTUATOR$2:
  5455. switch (code) {
  5456. case balanceCloseCode:
  5457. balancePrev = balanceStart & OFFSET_MASK;
  5458. balanceStart = balance[balancePrev];
  5459. balanceCloseCode = balanceStart >> TYPE_SHIFT;
  5460. balance[tokenCount] = balancePrev;
  5461. balance[balancePrev++] = tokenCount;
  5462. for (; balancePrev < tokenCount; balancePrev++) {
  5463. if (balance[balancePrev] === sourceLength) {
  5464. balance[balancePrev] = tokenCount;
  5465. }
  5466. }
  5467. break;
  5468. case LEFTSQUAREBRACKET:
  5469. balance[tokenCount] = balanceStart;
  5470. balanceCloseCode = RIGHTSQUAREBRACKET;
  5471. balanceStart = (balanceCloseCode << TYPE_SHIFT) | tokenCount;
  5472. break;
  5473. case LEFTCURLYBRACKET:
  5474. balance[tokenCount] = balanceStart;
  5475. balanceCloseCode = RIGHTCURLYBRACKET;
  5476. balanceStart = (balanceCloseCode << TYPE_SHIFT) | tokenCount;
  5477. break;
  5478. case LEFTPARENTHESIS:
  5479. balance[tokenCount] = balanceStart;
  5480. balanceCloseCode = RIGHTPARENTHESIS;
  5481. balanceStart = (balanceCloseCode << TYPE_SHIFT) | tokenCount;
  5482. break;
  5483. }
  5484. // /*
  5485. if (code === STAR && prevType === SLASH) {
  5486. type = COMMENT$1;
  5487. offset = findCommentEnd$1(source, offset + 1);
  5488. tokenCount--; // rewrite prev token
  5489. break;
  5490. }
  5491. // edge case for -.123 and +.123
  5492. if (code === FULLSTOP$1 && (prevType === PLUSSIGN$1 || prevType === HYPHENMINUS$1)) {
  5493. if (offset + 1 < sourceLength && isNumber$1(source.charCodeAt(offset + 1))) {
  5494. type = NUMBER$1;
  5495. offset = findNumberEnd$1(source, offset + 2, false);
  5496. tokenCount--; // rewrite prev token
  5497. break;
  5498. }
  5499. }
  5500. // <!--
  5501. if (code === EXCLAMATIONMARK && prevType === LESSTHANSIGN) {
  5502. if (offset + 2 < sourceLength &&
  5503. source.charCodeAt(offset + 1) === HYPHENMINUS$1 &&
  5504. source.charCodeAt(offset + 2) === HYPHENMINUS$1) {
  5505. type = CDO$1;
  5506. offset = offset + 3;
  5507. tokenCount--; // rewrite prev token
  5508. break;
  5509. }
  5510. }
  5511. // -->
  5512. if (code === HYPHENMINUS$1 && prevType === HYPHENMINUS$1) {
  5513. if (offset + 1 < sourceLength && source.charCodeAt(offset + 1) === GREATERTHANSIGN) {
  5514. type = CDC$1;
  5515. offset = offset + 2;
  5516. tokenCount--; // rewrite prev token
  5517. break;
  5518. }
  5519. }
  5520. // ident(
  5521. if (code === LEFTPARENTHESIS && prevType === IDENTIFIER$1) {
  5522. offset = offset + 1;
  5523. tokenCount--; // rewrite prev token
  5524. balance[tokenCount] = balance[tokenCount + 1];
  5525. balanceStart--;
  5526. // 4 char length identifier and equal to `url(` (case insensitive)
  5527. if (offset - anchor === 4 && cmpStr$1(source, anchor, offset, 'url(')) {
  5528. // special case for url() because it can contain any symbols sequence with few exceptions
  5529. anchor = findWhiteSpaceEnd$1(source, offset);
  5530. code = source.charCodeAt(anchor);
  5531. if (code !== LEFTPARENTHESIS &&
  5532. code !== RIGHTPARENTHESIS &&
  5533. code !== QUOTATIONMARK &&
  5534. code !== APOSTROPHE) {
  5535. // url(
  5536. offsetAndType[tokenCount++] = (URL$1 << TYPE_SHIFT) | offset;
  5537. balance[tokenCount] = sourceLength;
  5538. // ws*
  5539. if (anchor !== offset) {
  5540. offsetAndType[tokenCount++] = (WHITESPACE$1 << TYPE_SHIFT) | anchor;
  5541. balance[tokenCount] = sourceLength;
  5542. }
  5543. // raw
  5544. type = RAW$1;
  5545. offset = findUrlRawEnd$1(source, anchor);
  5546. } else {
  5547. type = URL$1;
  5548. }
  5549. } else {
  5550. type = FUNCTION$1;
  5551. }
  5552. break;
  5553. }
  5554. type = code;
  5555. offset = offset + 1;
  5556. break;
  5557. case NUMBER$1:
  5558. offset = findNumberEnd$1(source, offset + 1, prevType !== FULLSTOP$1);
  5559. // merge number with a preceding dot, dash or plus
  5560. if (prevType === FULLSTOP$1 ||
  5561. prevType === HYPHENMINUS$1 ||
  5562. prevType === PLUSSIGN$1) {
  5563. tokenCount--; // rewrite prev token
  5564. }
  5565. break;
  5566. case STRING$1:
  5567. offset = findStringEnd$1(source, offset + 1, code);
  5568. break;
  5569. default:
  5570. anchor = offset;
  5571. offset = findIdentifierEnd$1(source, offset);
  5572. // merge identifier with a preceding dash
  5573. if (prevType === HYPHENMINUS$1) {
  5574. // rewrite prev token
  5575. tokenCount--;
  5576. // restore prev prev token type
  5577. // for case @-prefix-ident
  5578. prevType = tokenCount === 0 ? 0 : offsetAndType[tokenCount - 1] >> TYPE_SHIFT;
  5579. }
  5580. if (prevType === COMMERCIALAT) {
  5581. // rewrite prev token and change type to <at-keyword-token>
  5582. tokenCount--;
  5583. type = ATRULE$1;
  5584. }
  5585. }
  5586. offsetAndType[tokenCount++] = (type << TYPE_SHIFT) | offset;
  5587. prevType = type;
  5588. }
  5589. // finalize arrays
  5590. offsetAndType[tokenCount] = offset;
  5591. balance[tokenCount] = sourceLength;
  5592. while (balanceStart !== 0) {
  5593. balancePrev = balanceStart & OFFSET_MASK;
  5594. balanceStart = balance[balancePrev];
  5595. balance[balancePrev] = sourceLength;
  5596. }
  5597. tokenizer.offsetAndType = offsetAndType;
  5598. tokenizer.tokenCount = tokenCount;
  5599. tokenizer.balance = balance;
  5600. }
  5601. //
  5602. // tokenizer
  5603. //
  5604. var Tokenizer = function(source, startOffset, startLine, startColumn) {
  5605. this.offsetAndType = null;
  5606. this.balance = null;
  5607. this.lines = null;
  5608. this.columns = null;
  5609. this.setSource(source, startOffset, startLine, startColumn);
  5610. };
  5611. Tokenizer.prototype = {
  5612. setSource: function(source, startOffset, startLine, startColumn) {
  5613. var safeSource = String(source || '');
  5614. var start = firstCharOffset$1(safeSource);
  5615. this.source = safeSource;
  5616. this.firstCharOffset = start;
  5617. this.startOffset = typeof startOffset === 'undefined' ? 0 : startOffset;
  5618. this.startLine = typeof startLine === 'undefined' ? 1 : startLine;
  5619. this.startColumn = typeof startColumn === 'undefined' ? 1 : startColumn;
  5620. this.linesAnsColumnsComputed = false;
  5621. this.eof = false;
  5622. this.currentToken = -1;
  5623. this.tokenType = 0;
  5624. this.tokenStart = start;
  5625. this.tokenEnd = start;
  5626. tokenLayout(this, safeSource, start);
  5627. this.next();
  5628. },
  5629. lookupType: function(offset) {
  5630. offset += this.currentToken;
  5631. if (offset < this.tokenCount) {
  5632. return this.offsetAndType[offset] >> TYPE_SHIFT;
  5633. }
  5634. return NULL;
  5635. },
  5636. lookupNonWSType: function(offset) {
  5637. offset += this.currentToken;
  5638. for (var type; offset < this.tokenCount; offset++) {
  5639. type = this.offsetAndType[offset] >> TYPE_SHIFT;
  5640. if (type !== WHITESPACE$1) {
  5641. return type;
  5642. }
  5643. }
  5644. return NULL;
  5645. },
  5646. lookupValue: function(offset, referenceStr) {
  5647. offset += this.currentToken;
  5648. if (offset < this.tokenCount) {
  5649. return cmpStr$1(
  5650. this.source,
  5651. this.offsetAndType[offset - 1] & OFFSET_MASK,
  5652. this.offsetAndType[offset] & OFFSET_MASK,
  5653. referenceStr
  5654. );
  5655. }
  5656. return false;
  5657. },
  5658. getTokenStart: function(tokenNum) {
  5659. if (tokenNum === this.currentToken) {
  5660. return this.tokenStart;
  5661. }
  5662. if (tokenNum > 0) {
  5663. return tokenNum < this.tokenCount
  5664. ? this.offsetAndType[tokenNum - 1] & OFFSET_MASK
  5665. : this.offsetAndType[this.tokenCount] & OFFSET_MASK;
  5666. }
  5667. return this.firstCharOffset;
  5668. },
  5669. getOffsetExcludeWS: function() {
  5670. if (this.currentToken > 0) {
  5671. if ((this.offsetAndType[this.currentToken - 1] >> TYPE_SHIFT) === WHITESPACE$1) {
  5672. return this.currentToken > 1
  5673. ? this.offsetAndType[this.currentToken - 2] & OFFSET_MASK
  5674. : this.firstCharOffset;
  5675. }
  5676. }
  5677. return this.tokenStart;
  5678. },
  5679. getRawLength: function(startToken, endTokenType1, endTokenType2, includeTokenType2) {
  5680. var cursor = startToken;
  5681. var balanceEnd;
  5682. loop:
  5683. for (; cursor < this.tokenCount; cursor++) {
  5684. balanceEnd = this.balance[cursor];
  5685. // belance end points to offset before start
  5686. if (balanceEnd < startToken) {
  5687. break loop;
  5688. }
  5689. // check token is stop type
  5690. switch (this.offsetAndType[cursor] >> TYPE_SHIFT) {
  5691. case endTokenType1:
  5692. break loop;
  5693. case endTokenType2:
  5694. if (includeTokenType2) {
  5695. cursor++;
  5696. }
  5697. break loop;
  5698. default:
  5699. // fast forward to the end of balanced block
  5700. if (this.balance[balanceEnd] === cursor) {
  5701. cursor = balanceEnd;
  5702. }
  5703. }
  5704. }
  5705. return cursor - this.currentToken;
  5706. },
  5707. getTokenValue: function() {
  5708. return this.source.substring(this.tokenStart, this.tokenEnd);
  5709. },
  5710. substrToCursor: function(start) {
  5711. return this.source.substring(start, this.tokenStart);
  5712. },
  5713. skipWS: function() {
  5714. for (var i = this.currentToken, skipTokenCount = 0; i < this.tokenCount; i++, skipTokenCount++) {
  5715. if ((this.offsetAndType[i] >> TYPE_SHIFT) !== WHITESPACE$1) {
  5716. break;
  5717. }
  5718. }
  5719. if (skipTokenCount > 0) {
  5720. this.skip(skipTokenCount);
  5721. }
  5722. },
  5723. skipSC: function() {
  5724. while (this.tokenType === WHITESPACE$1 || this.tokenType === COMMENT$1) {
  5725. this.next();
  5726. }
  5727. },
  5728. skip: function(tokenCount) {
  5729. var next = this.currentToken + tokenCount;
  5730. if (next < this.tokenCount) {
  5731. this.currentToken = next;
  5732. this.tokenStart = this.offsetAndType[next - 1] & OFFSET_MASK;
  5733. next = this.offsetAndType[next];
  5734. this.tokenType = next >> TYPE_SHIFT;
  5735. this.tokenEnd = next & OFFSET_MASK;
  5736. } else {
  5737. this.currentToken = this.tokenCount;
  5738. this.next();
  5739. }
  5740. },
  5741. next: function() {
  5742. var next = this.currentToken + 1;
  5743. if (next < this.tokenCount) {
  5744. this.currentToken = next;
  5745. this.tokenStart = this.tokenEnd;
  5746. next = this.offsetAndType[next];
  5747. this.tokenType = next >> TYPE_SHIFT;
  5748. this.tokenEnd = next & OFFSET_MASK;
  5749. } else {
  5750. this.currentToken = this.tokenCount;
  5751. this.eof = true;
  5752. this.tokenType = NULL;
  5753. this.tokenStart = this.tokenEnd = this.source.length;
  5754. }
  5755. },
  5756. eat: function(tokenType) {
  5757. if (this.tokenType !== tokenType) {
  5758. var offset = this.tokenStart;
  5759. var message = NAME$1[tokenType] + ' is expected';
  5760. // tweak message and offset
  5761. if (tokenType === IDENTIFIER$1) {
  5762. // when identifier is expected but there is a function or url
  5763. if (this.tokenType === FUNCTION$1 || this.tokenType === URL$1) {
  5764. offset = this.tokenEnd - 1;
  5765. message += ' but function found';
  5766. }
  5767. } else {
  5768. // when test type is part of another token show error for current position + 1
  5769. // e.g. eat(HYPHENMINUS) will fail on "-foo", but pointing on "-" is odd
  5770. if (this.source.charCodeAt(this.tokenStart) === tokenType) {
  5771. offset = offset + 1;
  5772. }
  5773. }
  5774. this.error(message, offset);
  5775. }
  5776. this.next();
  5777. },
  5778. eatNonWS: function(tokenType) {
  5779. this.skipWS();
  5780. this.eat(tokenType);
  5781. },
  5782. consume: function(tokenType) {
  5783. var value = this.getTokenValue();
  5784. this.eat(tokenType);
  5785. return value;
  5786. },
  5787. consumeFunctionName: function() {
  5788. var name = this.source.substring(this.tokenStart, this.tokenEnd - 1);
  5789. this.eat(FUNCTION$1);
  5790. return name;
  5791. },
  5792. consumeNonWS: function(tokenType) {
  5793. this.skipWS();
  5794. return this.consume(tokenType);
  5795. },
  5796. expectIdentifier: function(name) {
  5797. if (this.tokenType !== IDENTIFIER$1 || cmpStr$1(this.source, this.tokenStart, this.tokenEnd, name) === false) {
  5798. this.error('Identifier `' + name + '` is expected');
  5799. }
  5800. this.next();
  5801. },
  5802. getLocation: function(offset, filename) {
  5803. if (!this.linesAnsColumnsComputed) {
  5804. computeLinesAndColumns(this, this.source);
  5805. }
  5806. return {
  5807. source: filename,
  5808. offset: this.startOffset + offset,
  5809. line: this.lines[offset],
  5810. column: this.columns[offset]
  5811. };
  5812. },
  5813. getLocationRange: function(start, end, filename) {
  5814. if (!this.linesAnsColumnsComputed) {
  5815. computeLinesAndColumns(this, this.source);
  5816. }
  5817. return {
  5818. source: filename,
  5819. start: {
  5820. offset: this.startOffset + start,
  5821. line: this.lines[start],
  5822. column: this.columns[start]
  5823. },
  5824. end: {
  5825. offset: this.startOffset + end,
  5826. line: this.lines[end],
  5827. column: this.columns[end]
  5828. }
  5829. };
  5830. },
  5831. error: function(message, offset) {
  5832. var location = typeof offset !== 'undefined' && offset < this.source.length
  5833. ? this.getLocation(offset)
  5834. : this.eof
  5835. ? findLastNonSpaceLocation$1(this)
  5836. : this.getLocation(this.tokenStart);
  5837. throw new CssSyntaxError$1(
  5838. message || 'Unexpected input',
  5839. this.source,
  5840. location.offset,
  5841. location.line,
  5842. location.column
  5843. );
  5844. },
  5845. dump: function() {
  5846. var offset = 0;
  5847. return Array.prototype.slice.call(this.offsetAndType, 0, this.tokenCount).map(function(item, idx) {
  5848. var start = offset;
  5849. var end = item & OFFSET_MASK;
  5850. offset = end;
  5851. return {
  5852. idx: idx,
  5853. type: NAME$1[item >> TYPE_SHIFT],
  5854. chunk: this.source.substring(start, end),
  5855. balance: this.balance[idx]
  5856. };
  5857. }, this);
  5858. }
  5859. };
  5860. // extend with error class
  5861. Tokenizer.CssSyntaxError = CssSyntaxError$1;
  5862. // extend tokenizer with constants
  5863. Object.keys(constants).forEach(function(key) {
  5864. Tokenizer[key] = constants[key];
  5865. });
  5866. // extend tokenizer with static methods from utils
  5867. Object.keys(utils$2).forEach(function(key) {
  5868. Tokenizer[key] = utils$2[key];
  5869. });
  5870. // warm up tokenizer to elimitate code branches that never execute
  5871. // fix soft deoptimizations (insufficient type feedback)
  5872. new Tokenizer('\n\r\r\n\f<!---->//""\'\'/*\r\n\f*/1a;.\\31\t\+2{url(a);func();+1.2e3 -.4e-5 .6e+7}').getLocation();
  5873. var Tokenizer_1 = Tokenizer;
  5874. var Tokenizer$1 = /*#__PURE__*/Object.freeze({
  5875. default: Tokenizer_1,
  5876. __moduleExports: Tokenizer_1
  5877. });
  5878. var require$$0 = ( Tokenizer$1 && Tokenizer_1 ) || Tokenizer$1;
  5879. var tokenizer$1 = require$$0;
  5880. var tokenizer$2 = /*#__PURE__*/Object.freeze({
  5881. default: tokenizer$1,
  5882. __moduleExports: tokenizer$1
  5883. });
  5884. //
  5885. // item item item item
  5886. // /------\ /------\ /------\ /------\
  5887. // | data | | data | | data | | data |
  5888. // null <--+-prev |<---+-prev |<---+-prev |<---+-prev |
  5889. // | next-+--->| next-+--->| next-+--->| next-+--> null
  5890. // \------/ \------/ \------/ \------/
  5891. // ^ ^
  5892. // | list |
  5893. // | /------\ |
  5894. // \--------------+-head | |
  5895. // | tail-+--------------/
  5896. // \------/
  5897. //
  5898. function createItem(data) {
  5899. return {
  5900. prev: null,
  5901. next: null,
  5902. data: data
  5903. };
  5904. }
  5905. var cursors = null;
  5906. var List = function() {
  5907. this.cursor = null;
  5908. this.head = null;
  5909. this.tail = null;
  5910. };
  5911. List.createItem = createItem;
  5912. List.prototype.createItem = createItem;
  5913. List.prototype.getSize = function() {
  5914. var size = 0;
  5915. var cursor = this.head;
  5916. while (cursor) {
  5917. size++;
  5918. cursor = cursor.next;
  5919. }
  5920. return size;
  5921. };
  5922. List.prototype.fromArray = function(array) {
  5923. var cursor = null;
  5924. this.head = null;
  5925. for (var i = 0; i < array.length; i++) {
  5926. var item = createItem(array[i]);
  5927. if (cursor !== null) {
  5928. cursor.next = item;
  5929. } else {
  5930. this.head = item;
  5931. }
  5932. item.prev = cursor;
  5933. cursor = item;
  5934. }
  5935. this.tail = cursor;
  5936. return this;
  5937. };
  5938. List.prototype.toArray = function() {
  5939. var cursor = this.head;
  5940. var result = [];
  5941. while (cursor) {
  5942. result.push(cursor.data);
  5943. cursor = cursor.next;
  5944. }
  5945. return result;
  5946. };
  5947. List.prototype.toJSON = List.prototype.toArray;
  5948. List.prototype.isEmpty = function() {
  5949. return this.head === null;
  5950. };
  5951. List.prototype.first = function() {
  5952. return this.head && this.head.data;
  5953. };
  5954. List.prototype.last = function() {
  5955. return this.tail && this.tail.data;
  5956. };
  5957. function allocateCursor(node, prev, next) {
  5958. var cursor;
  5959. if (cursors !== null) {
  5960. cursor = cursors;
  5961. cursors = cursors.cursor;
  5962. cursor.prev = prev;
  5963. cursor.next = next;
  5964. cursor.cursor = node.cursor;
  5965. } else {
  5966. cursor = {
  5967. prev: prev,
  5968. next: next,
  5969. cursor: node.cursor
  5970. };
  5971. }
  5972. node.cursor = cursor;
  5973. return cursor;
  5974. }
  5975. function releaseCursor(node) {
  5976. var cursor = node.cursor;
  5977. node.cursor = cursor.cursor;
  5978. cursor.prev = null;
  5979. cursor.next = null;
  5980. cursor.cursor = cursors;
  5981. cursors = cursor;
  5982. }
  5983. List.prototype.each = function(fn, context) {
  5984. var item;
  5985. if (context === undefined) {
  5986. context = this;
  5987. }
  5988. // push cursor
  5989. var cursor = allocateCursor(this, null, this.head);
  5990. while (cursor.next !== null) {
  5991. item = cursor.next;
  5992. cursor.next = item.next;
  5993. fn.call(context, item.data, item, this);
  5994. }
  5995. // pop cursor
  5996. releaseCursor(this);
  5997. };
  5998. List.prototype.eachRight = function(fn, context) {
  5999. var item;
  6000. if (context === undefined) {
  6001. context = this;
  6002. }
  6003. // push cursor
  6004. var cursor = allocateCursor(this, this.tail, null);
  6005. while (cursor.prev !== null) {
  6006. item = cursor.prev;
  6007. cursor.prev = item.prev;
  6008. fn.call(context, item.data, item, this);
  6009. }
  6010. // pop cursor
  6011. releaseCursor(this);
  6012. };
  6013. List.prototype.nextUntil = function(start, fn, context) {
  6014. if (start === null) {
  6015. return;
  6016. }
  6017. var item;
  6018. if (context === undefined) {
  6019. context = this;
  6020. }
  6021. // push cursor
  6022. var cursor = allocateCursor(this, null, start);
  6023. while (cursor.next !== null) {
  6024. item = cursor.next;
  6025. cursor.next = item.next;
  6026. if (fn.call(context, item.data, item, this)) {
  6027. break;
  6028. }
  6029. }
  6030. // pop cursor
  6031. releaseCursor(this);
  6032. };
  6033. List.prototype.prevUntil = function(start, fn, context) {
  6034. if (start === null) {
  6035. return;
  6036. }
  6037. var item;
  6038. if (context === undefined) {
  6039. context = this;
  6040. }
  6041. // push cursor
  6042. var cursor = allocateCursor(this, start, null);
  6043. while (cursor.prev !== null) {
  6044. item = cursor.prev;
  6045. cursor.prev = item.prev;
  6046. if (fn.call(context, item.data, item, this)) {
  6047. break;
  6048. }
  6049. }
  6050. // pop cursor
  6051. releaseCursor(this);
  6052. };
  6053. List.prototype.some = function(fn, context) {
  6054. var cursor = this.head;
  6055. if (context === undefined) {
  6056. context = this;
  6057. }
  6058. while (cursor !== null) {
  6059. if (fn.call(context, cursor.data, cursor, this)) {
  6060. return true;
  6061. }
  6062. cursor = cursor.next;
  6063. }
  6064. return false;
  6065. };
  6066. List.prototype.map = function(fn, context) {
  6067. var result = [];
  6068. var cursor = this.head;
  6069. if (context === undefined) {
  6070. context = this;
  6071. }
  6072. while (cursor !== null) {
  6073. result.push(fn.call(context, cursor.data, cursor, this));
  6074. cursor = cursor.next;
  6075. }
  6076. return result;
  6077. };
  6078. List.prototype.clear = function() {
  6079. this.head = null;
  6080. this.tail = null;
  6081. };
  6082. List.prototype.copy = function() {
  6083. var result = new List();
  6084. var cursor = this.head;
  6085. while (cursor !== null) {
  6086. result.insert(createItem(cursor.data));
  6087. cursor = cursor.next;
  6088. }
  6089. return result;
  6090. };
  6091. List.prototype.updateCursors = function(prevOld, prevNew, nextOld, nextNew) {
  6092. var cursor = this.cursor;
  6093. while (cursor !== null) {
  6094. if (cursor.prev === prevOld) {
  6095. cursor.prev = prevNew;
  6096. }
  6097. if (cursor.next === nextOld) {
  6098. cursor.next = nextNew;
  6099. }
  6100. cursor = cursor.cursor;
  6101. }
  6102. };
  6103. List.prototype.prepend = function(item) {
  6104. // head
  6105. // ^
  6106. // item
  6107. this.updateCursors(null, item, this.head, item);
  6108. // insert to the beginning of the list
  6109. if (this.head !== null) {
  6110. // new item <- first item
  6111. this.head.prev = item;
  6112. // new item -> first item
  6113. item.next = this.head;
  6114. } else {
  6115. // if list has no head, then it also has no tail
  6116. // in this case tail points to the new item
  6117. this.tail = item;
  6118. }
  6119. // head always points to new item
  6120. this.head = item;
  6121. return this;
  6122. };
  6123. List.prototype.prependData = function(data) {
  6124. return this.prepend(createItem(data));
  6125. };
  6126. List.prototype.append = function(item) {
  6127. // tail
  6128. // ^
  6129. // item
  6130. this.updateCursors(this.tail, item, null, item);
  6131. // insert to the ending of the list
  6132. if (this.tail !== null) {
  6133. // last item -> new item
  6134. this.tail.next = item;
  6135. // last item <- new item
  6136. item.prev = this.tail;
  6137. } else {
  6138. // if list has no tail, then it also has no head
  6139. // in this case head points to new item
  6140. this.head = item;
  6141. }
  6142. // tail always points to new item
  6143. this.tail = item;
  6144. return this;
  6145. };
  6146. List.prototype.appendData = function(data) {
  6147. return this.append(createItem(data));
  6148. };
  6149. List.prototype.insert = function(item, before) {
  6150. if (before !== undefined && before !== null) {
  6151. // prev before
  6152. // ^
  6153. // item
  6154. this.updateCursors(before.prev, item, before, item);
  6155. if (before.prev === null) {
  6156. // insert to the beginning of list
  6157. if (this.head !== before) {
  6158. throw new Error('before doesn\'t belong to list');
  6159. }
  6160. // since head points to before therefore list doesn't empty
  6161. // no need to check tail
  6162. this.head = item;
  6163. before.prev = item;
  6164. item.next = before;
  6165. this.updateCursors(null, item);
  6166. } else {
  6167. // insert between two items
  6168. before.prev.next = item;
  6169. item.prev = before.prev;
  6170. before.prev = item;
  6171. item.next = before;
  6172. }
  6173. } else {
  6174. this.append(item);
  6175. }
  6176. };
  6177. List.prototype.insertData = function(data, before) {
  6178. this.insert(createItem(data), before);
  6179. };
  6180. List.prototype.remove = function(item) {
  6181. // item
  6182. // ^
  6183. // prev next
  6184. this.updateCursors(item, item.prev, item, item.next);
  6185. if (item.prev !== null) {
  6186. item.prev.next = item.next;
  6187. } else {
  6188. if (this.head !== item) {
  6189. throw new Error('item doesn\'t belong to list');
  6190. }
  6191. this.head = item.next;
  6192. }
  6193. if (item.next !== null) {
  6194. item.next.prev = item.prev;
  6195. } else {
  6196. if (this.tail !== item) {
  6197. throw new Error('item doesn\'t belong to list');
  6198. }
  6199. this.tail = item.prev;
  6200. }
  6201. item.prev = null;
  6202. item.next = null;
  6203. return item;
  6204. };
  6205. List.prototype.appendList = function(list) {
  6206. // ignore empty lists
  6207. if (list.head === null) {
  6208. return;
  6209. }
  6210. this.updateCursors(this.tail, list.tail, null, list.head);
  6211. // insert to end of the list
  6212. if (this.tail !== null) {
  6213. // if destination list has a tail, then it also has a head,
  6214. // but head doesn't change
  6215. // dest tail -> source head
  6216. this.tail.next = list.head;
  6217. // dest tail <- source head
  6218. list.head.prev = this.tail;
  6219. } else {
  6220. // if list has no a tail, then it also has no a head
  6221. // in this case points head to new item
  6222. this.head = list.head;
  6223. }
  6224. // tail always start point to new item
  6225. this.tail = list.tail;
  6226. list.head = null;
  6227. list.tail = null;
  6228. };
  6229. List.prototype.insertList = function(list, before) {
  6230. if (before !== undefined && before !== null) {
  6231. // ignore empty lists
  6232. if (list.head === null) {
  6233. return;
  6234. }
  6235. this.updateCursors(before.prev, list.tail, before, list.head);
  6236. // insert in the middle of dist list
  6237. if (before.prev !== null) {
  6238. // before.prev <-> list.head
  6239. before.prev.next = list.head;
  6240. list.head.prev = before.prev;
  6241. } else {
  6242. this.head = list.head;
  6243. }
  6244. before.prev = list.tail;
  6245. list.tail.next = before;
  6246. list.head = null;
  6247. list.tail = null;
  6248. } else {
  6249. this.appendList(list);
  6250. }
  6251. };
  6252. List.prototype.replace = function(oldItem, newItemOrList) {
  6253. if ('head' in newItemOrList) {
  6254. this.insertList(newItemOrList, oldItem);
  6255. } else {
  6256. this.insert(newItemOrList, oldItem);
  6257. }
  6258. this.remove(oldItem);
  6259. };
  6260. var list = List;
  6261. var list$1 = /*#__PURE__*/Object.freeze({
  6262. default: list,
  6263. __moduleExports: list
  6264. });
  6265. var List$1 = ( list$1 && list ) || list$1;
  6266. var require$$0$1 = ( tokenizer$2 && tokenizer$1 ) || tokenizer$2;
  6267. var TYPE$3 = require$$0$1.TYPE;
  6268. var WHITESPACE$2 = TYPE$3.WhiteSpace;
  6269. var COMMENT$2 = TYPE$3.Comment;
  6270. var sequence = function readSequence(recognizer) {
  6271. var children = new List$1();
  6272. var child = null;
  6273. var context = {
  6274. recognizer: recognizer,
  6275. space: null,
  6276. ignoreWS: false,
  6277. ignoreWSAfter: false
  6278. };
  6279. this.scanner.skipSC();
  6280. while (!this.scanner.eof) {
  6281. switch (this.scanner.tokenType) {
  6282. case COMMENT$2:
  6283. this.scanner.next();
  6284. continue;
  6285. case WHITESPACE$2:
  6286. if (context.ignoreWS) {
  6287. this.scanner.next();
  6288. } else {
  6289. context.space = this.WhiteSpace();
  6290. }
  6291. continue;
  6292. }
  6293. child = recognizer.getNode.call(this, context);
  6294. if (child === undefined) {
  6295. break;
  6296. }
  6297. if (context.space !== null) {
  6298. children.appendData(context.space);
  6299. context.space = null;
  6300. }
  6301. children.appendData(child);
  6302. if (context.ignoreWSAfter) {
  6303. context.ignoreWSAfter = false;
  6304. context.ignoreWS = true;
  6305. } else {
  6306. context.ignoreWS = false;
  6307. }
  6308. }
  6309. return children;
  6310. };
  6311. var sequence$1 = /*#__PURE__*/Object.freeze({
  6312. default: sequence,
  6313. __moduleExports: sequence
  6314. });
  6315. var sequence$2 = ( sequence$1 && sequence ) || sequence$1;
  6316. var noop = function() {};
  6317. function createParseContext(name) {
  6318. return function() {
  6319. return this[name]();
  6320. };
  6321. }
  6322. function processConfig(config) {
  6323. var parserConfig = {
  6324. context: {},
  6325. scope: {},
  6326. atrule: {},
  6327. pseudo: {}
  6328. };
  6329. if (config.parseContext) {
  6330. for (var name in config.parseContext) {
  6331. switch (typeof config.parseContext[name]) {
  6332. case 'function':
  6333. parserConfig.context[name] = config.parseContext[name];
  6334. break;
  6335. case 'string':
  6336. parserConfig.context[name] = createParseContext(config.parseContext[name]);
  6337. break;
  6338. }
  6339. }
  6340. }
  6341. if (config.scope) {
  6342. for (var name in config.scope) {
  6343. parserConfig.scope[name] = config.scope[name];
  6344. }
  6345. }
  6346. if (config.atrule) {
  6347. for (var name in config.atrule) {
  6348. var atrule = config.atrule[name];
  6349. if (atrule.parse) {
  6350. parserConfig.atrule[name] = atrule.parse;
  6351. }
  6352. }
  6353. }
  6354. if (config.pseudo) {
  6355. for (var name in config.pseudo) {
  6356. var pseudo = config.pseudo[name];
  6357. if (pseudo.parse) {
  6358. parserConfig.pseudo[name] = pseudo.parse;
  6359. }
  6360. }
  6361. }
  6362. if (config.node) {
  6363. for (var name in config.node) {
  6364. parserConfig[name] = config.node[name].parse;
  6365. }
  6366. }
  6367. return parserConfig;
  6368. }
  6369. var create = function createParser(config) {
  6370. var parser = {
  6371. scanner: new require$$0$1(),
  6372. filename: '<unknown>',
  6373. needPositions: false,
  6374. tolerant: false,
  6375. onParseError: noop,
  6376. parseAtruleExpression: true,
  6377. parseSelector: true,
  6378. parseValue: true,
  6379. parseCustomProperty: false,
  6380. readSequence: sequence$2,
  6381. tolerantParse: function(consumer, fallback) {
  6382. if (this.tolerant) {
  6383. var start = this.scanner.currentToken;
  6384. try {
  6385. return consumer.call(this);
  6386. } catch (e) {
  6387. this.onParseError(e);
  6388. return fallback.call(this, start);
  6389. }
  6390. } else {
  6391. return consumer.call(this);
  6392. }
  6393. },
  6394. getLocation: function(start, end) {
  6395. if (this.needPositions) {
  6396. return this.scanner.getLocationRange(
  6397. start,
  6398. end,
  6399. this.filename
  6400. );
  6401. }
  6402. return null;
  6403. },
  6404. getLocationFromList: function(list) {
  6405. if (this.needPositions) {
  6406. return this.scanner.getLocationRange(
  6407. list.head !== null ? list.first().loc.start.offset - this.scanner.startOffset : this.scanner.tokenStart,
  6408. list.head !== null ? list.last().loc.end.offset - this.scanner.startOffset : this.scanner.tokenStart,
  6409. this.filename
  6410. );
  6411. }
  6412. return null;
  6413. }
  6414. };
  6415. config = processConfig(config || {});
  6416. for (var key in config) {
  6417. parser[key] = config[key];
  6418. }
  6419. return function(source, options) {
  6420. options = options || {};
  6421. var context = options.context || 'default';
  6422. var ast;
  6423. parser.scanner.setSource(source, options.offset, options.line, options.column);
  6424. parser.filename = options.filename || '<unknown>';
  6425. parser.needPositions = Boolean(options.positions);
  6426. parser.tolerant = Boolean(options.tolerant);
  6427. parser.onParseError = typeof options.onParseError === 'function' ? options.onParseError : noop;
  6428. parser.parseAtruleExpression = 'parseAtruleExpression' in options ? Boolean(options.parseAtruleExpression) : true;
  6429. parser.parseSelector = 'parseSelector' in options ? Boolean(options.parseSelector) : true;
  6430. parser.parseValue = 'parseValue' in options ? Boolean(options.parseValue) : true;
  6431. parser.parseCustomProperty = 'parseCustomProperty' in options ? Boolean(options.parseCustomProperty) : false;
  6432. if (!parser.context.hasOwnProperty(context)) {
  6433. throw new Error('Unknown context `' + context + '`');
  6434. }
  6435. ast = parser.context[context].call(parser, options);
  6436. if (!parser.scanner.eof) {
  6437. parser.scanner.error();
  6438. }
  6439. // console.log(JSON.stringify(ast, null, 4));
  6440. return ast;
  6441. };
  6442. };
  6443. var create$1 = /*#__PURE__*/Object.freeze({
  6444. default: create,
  6445. __moduleExports: create
  6446. });
  6447. var cmpChar$1 = require$$0$1.cmpChar;
  6448. var TYPE$4 = require$$0$1.TYPE;
  6449. var IDENTIFIER$2 = TYPE$4.Identifier;
  6450. var STRING$2 = TYPE$4.String;
  6451. var NUMBER$2 = TYPE$4.Number;
  6452. var FUNCTION$2 = TYPE$4.Function;
  6453. var URL$2 = TYPE$4.Url;
  6454. var NUMBERSIGN = TYPE$4.NumberSign;
  6455. var LEFTPARENTHESIS$1 = TYPE$4.LeftParenthesis;
  6456. var LEFTSQUAREBRACKET$1 = TYPE$4.LeftSquareBracket;
  6457. var PLUSSIGN$2 = TYPE$4.PlusSign;
  6458. var HYPHENMINUS$2 = TYPE$4.HyphenMinus;
  6459. var COMMA = TYPE$4.Comma;
  6460. var SOLIDUS = TYPE$4.Solidus;
  6461. var ASTERISK = TYPE$4.Asterisk;
  6462. var PERCENTSIGN = TYPE$4.PercentSign;
  6463. var BACKSLASH = TYPE$4.Backslash;
  6464. var U = 117; // 'u'.charCodeAt(0)
  6465. var _default = function defaultRecognizer(context) {
  6466. switch (this.scanner.tokenType) {
  6467. case NUMBERSIGN:
  6468. return this.HexColor();
  6469. case COMMA:
  6470. context.space = null;
  6471. context.ignoreWSAfter = true;
  6472. return this.Operator();
  6473. case SOLIDUS:
  6474. case ASTERISK:
  6475. case PLUSSIGN$2:
  6476. case HYPHENMINUS$2:
  6477. return this.Operator();
  6478. case LEFTPARENTHESIS$1:
  6479. return this.Parentheses(this.readSequence, context.recognizer);
  6480. case LEFTSQUAREBRACKET$1:
  6481. return this.Brackets(this.readSequence, context.recognizer);
  6482. case STRING$2:
  6483. return this.String();
  6484. case NUMBER$2:
  6485. switch (this.scanner.lookupType(1)) {
  6486. case PERCENTSIGN:
  6487. return this.Percentage();
  6488. case IDENTIFIER$2:
  6489. // edge case: number with folowing \0 and \9 hack shouldn't to be a Dimension
  6490. if (cmpChar$1(this.scanner.source, this.scanner.tokenEnd, BACKSLASH)) {
  6491. return this.Number();
  6492. } else {
  6493. return this.Dimension();
  6494. }
  6495. default:
  6496. return this.Number();
  6497. }
  6498. case FUNCTION$2:
  6499. return this.Function(this.readSequence, context.recognizer);
  6500. case URL$2:
  6501. return this.Url();
  6502. case IDENTIFIER$2:
  6503. // check for unicode range, it should start with u+ or U+
  6504. if (cmpChar$1(this.scanner.source, this.scanner.tokenStart, U) &&
  6505. cmpChar$1(this.scanner.source, this.scanner.tokenStart + 1, PLUSSIGN$2)) {
  6506. return this.UnicodeRange();
  6507. } else {
  6508. return this.Identifier();
  6509. }
  6510. }
  6511. };
  6512. var _default$1 = /*#__PURE__*/Object.freeze({
  6513. default: _default,
  6514. __moduleExports: _default
  6515. });
  6516. var require$$0$2 = ( _default$1 && _default ) || _default$1;
  6517. var atruleExpression = {
  6518. getNode: require$$0$2
  6519. };
  6520. var atruleExpression_1 = atruleExpression.getNode;
  6521. var atruleExpression$1 = /*#__PURE__*/Object.freeze({
  6522. default: atruleExpression,
  6523. __moduleExports: atruleExpression,
  6524. getNode: atruleExpression_1
  6525. });
  6526. var TYPE$5 = require$$0$1.TYPE;
  6527. var IDENTIFIER$3 = TYPE$5.Identifier;
  6528. var NUMBER$3 = TYPE$5.Number;
  6529. var NUMBERSIGN$1 = TYPE$5.NumberSign;
  6530. var LEFTSQUAREBRACKET$2 = TYPE$5.LeftSquareBracket;
  6531. var PLUSSIGN$3 = TYPE$5.PlusSign;
  6532. var SOLIDUS$1 = TYPE$5.Solidus;
  6533. var ASTERISK$1 = TYPE$5.Asterisk;
  6534. var FULLSTOP$2 = TYPE$5.FullStop;
  6535. var COLON = TYPE$5.Colon;
  6536. var GREATERTHANSIGN$1 = TYPE$5.GreaterThanSign;
  6537. var VERTICALLINE = TYPE$5.VerticalLine;
  6538. var TILDE = TYPE$5.Tilde;
  6539. function getNode(context) {
  6540. switch (this.scanner.tokenType) {
  6541. case PLUSSIGN$3:
  6542. case GREATERTHANSIGN$1:
  6543. case TILDE:
  6544. context.space = null;
  6545. context.ignoreWSAfter = true;
  6546. return this.Combinator();
  6547. case SOLIDUS$1: // /deep/
  6548. return this.Combinator();
  6549. case FULLSTOP$2:
  6550. return this.ClassSelector();
  6551. case LEFTSQUAREBRACKET$2:
  6552. return this.AttributeSelector();
  6553. case NUMBERSIGN$1:
  6554. return this.IdSelector();
  6555. case COLON:
  6556. if (this.scanner.lookupType(1) === COLON) {
  6557. return this.PseudoElementSelector();
  6558. } else {
  6559. return this.PseudoClassSelector();
  6560. }
  6561. case IDENTIFIER$3:
  6562. case ASTERISK$1:
  6563. case VERTICALLINE:
  6564. return this.TypeSelector();
  6565. case NUMBER$3:
  6566. return this.Percentage();
  6567. }
  6568. }
  6569. var selector = {
  6570. getNode: getNode
  6571. };
  6572. var selector_1 = selector.getNode;
  6573. var selector$1 = /*#__PURE__*/Object.freeze({
  6574. default: selector,
  6575. __moduleExports: selector,
  6576. getNode: selector_1
  6577. });
  6578. // https://drafts.csswg.org/css-images-4/#element-notation
  6579. // https://developer.mozilla.org/en-US/docs/Web/CSS/element
  6580. var element = function() {
  6581. this.scanner.skipSC();
  6582. var id = this.IdSelector();
  6583. this.scanner.skipSC();
  6584. return new List$1().appendData(
  6585. id
  6586. );
  6587. };
  6588. var element$1 = /*#__PURE__*/Object.freeze({
  6589. default: element,
  6590. __moduleExports: element
  6591. });
  6592. // legacy IE function
  6593. // expression '(' raw ')'
  6594. var expression = function() {
  6595. return new List$1().appendData(
  6596. this.Raw(this.scanner.currentToken, 0, 0, false, false)
  6597. );
  6598. };
  6599. var expression$1 = /*#__PURE__*/Object.freeze({
  6600. default: expression,
  6601. __moduleExports: expression
  6602. });
  6603. var TYPE$6 = require$$0$1.TYPE;
  6604. var IDENTIFIER$4 = TYPE$6.Identifier;
  6605. var COMMA$1 = TYPE$6.Comma;
  6606. var SEMICOLON = TYPE$6.Semicolon;
  6607. var HYPHENMINUS$3 = TYPE$6.HyphenMinus;
  6608. var EXCLAMATIONMARK$1 = TYPE$6.ExclamationMark;
  6609. // var '(' ident (',' <value>? )? ')'
  6610. var _var = function() {
  6611. var children = new List$1();
  6612. this.scanner.skipSC();
  6613. var identStart = this.scanner.tokenStart;
  6614. this.scanner.eat(HYPHENMINUS$3);
  6615. if (this.scanner.source.charCodeAt(this.scanner.tokenStart) !== HYPHENMINUS$3) {
  6616. this.scanner.error('HyphenMinus is expected');
  6617. }
  6618. this.scanner.eat(IDENTIFIER$4);
  6619. children.appendData({
  6620. type: 'Identifier',
  6621. loc: this.getLocation(identStart, this.scanner.tokenStart),
  6622. name: this.scanner.substrToCursor(identStart)
  6623. });
  6624. this.scanner.skipSC();
  6625. if (this.scanner.tokenType === COMMA$1) {
  6626. children.appendData(this.Operator());
  6627. children.appendData(this.parseCustomProperty
  6628. ? this.Value(null)
  6629. : this.Raw(this.scanner.currentToken, EXCLAMATIONMARK$1, SEMICOLON, false, false)
  6630. );
  6631. }
  6632. return children;
  6633. };
  6634. var _var$1 = /*#__PURE__*/Object.freeze({
  6635. default: _var,
  6636. __moduleExports: _var
  6637. });
  6638. var require$$1 = ( element$1 && element ) || element$1;
  6639. var require$$2 = ( expression$1 && expression ) || expression$1;
  6640. var require$$3 = ( _var$1 && _var ) || _var$1;
  6641. var value = {
  6642. getNode: require$$0$2,
  6643. '-moz-element': require$$1,
  6644. 'element': require$$1,
  6645. 'expression': require$$2,
  6646. 'var': require$$3
  6647. };
  6648. var value_1 = value.getNode;
  6649. var value$1 = /*#__PURE__*/Object.freeze({
  6650. default: value,
  6651. __moduleExports: value,
  6652. getNode: value_1
  6653. });
  6654. var require$$0$3 = ( atruleExpression$1 && atruleExpression ) || atruleExpression$1;
  6655. var require$$1$1 = ( selector$1 && selector ) || selector$1;
  6656. var require$$2$1 = ( value$1 && value ) || value$1;
  6657. var scope = {
  6658. AtruleExpression: require$$0$3,
  6659. Selector: require$$1$1,
  6660. Value: require$$2$1
  6661. };
  6662. var scope_1 = scope.AtruleExpression;
  6663. var scope_2 = scope.Selector;
  6664. var scope_3 = scope.Value;
  6665. var scope$1 = /*#__PURE__*/Object.freeze({
  6666. default: scope,
  6667. __moduleExports: scope,
  6668. AtruleExpression: scope_1,
  6669. Selector: scope_2,
  6670. Value: scope_3
  6671. });
  6672. var fontFace = {
  6673. parse: {
  6674. expression: null,
  6675. block: function() {
  6676. return this.Block(this.Declaration);
  6677. }
  6678. }
  6679. };
  6680. var fontFace_1 = fontFace.parse;
  6681. var fontFace$1 = /*#__PURE__*/Object.freeze({
  6682. default: fontFace,
  6683. __moduleExports: fontFace,
  6684. parse: fontFace_1
  6685. });
  6686. var TYPE$7 = require$$0$1.TYPE;
  6687. var STRING$3 = TYPE$7.String;
  6688. var IDENTIFIER$5 = TYPE$7.Identifier;
  6689. var URL$3 = TYPE$7.Url;
  6690. var LEFTPARENTHESIS$2 = TYPE$7.LeftParenthesis;
  6691. var _import = {
  6692. parse: {
  6693. expression: function() {
  6694. var children = new List$1();
  6695. this.scanner.skipSC();
  6696. switch (this.scanner.tokenType) {
  6697. case STRING$3:
  6698. children.appendData(this.String());
  6699. break;
  6700. case URL$3:
  6701. children.appendData(this.Url());
  6702. break;
  6703. default:
  6704. this.scanner.error('String or url() is expected');
  6705. }
  6706. if (this.scanner.lookupNonWSType(0) === IDENTIFIER$5 ||
  6707. this.scanner.lookupNonWSType(0) === LEFTPARENTHESIS$2) {
  6708. children.appendData(this.WhiteSpace());
  6709. children.appendData(this.MediaQueryList());
  6710. }
  6711. return children;
  6712. },
  6713. block: null
  6714. }
  6715. };
  6716. var _import_1 = _import.parse;
  6717. var _import$1 = /*#__PURE__*/Object.freeze({
  6718. default: _import,
  6719. __moduleExports: _import,
  6720. parse: _import_1
  6721. });
  6722. var media = {
  6723. parse: {
  6724. expression: function() {
  6725. return new List$1().appendData(
  6726. this.MediaQueryList()
  6727. );
  6728. },
  6729. block: function() {
  6730. return this.Block(this.Rule);
  6731. }
  6732. }
  6733. };
  6734. var media_1 = media.parse;
  6735. var media$1 = /*#__PURE__*/Object.freeze({
  6736. default: media,
  6737. __moduleExports: media,
  6738. parse: media_1
  6739. });
  6740. var TYPE$8 = require$$0$1.TYPE;
  6741. var LEFTCURLYBRACKET$1 = TYPE$8.LeftCurlyBracket;
  6742. var page = {
  6743. parse: {
  6744. expression: function() {
  6745. if (this.scanner.lookupNonWSType(0) === LEFTCURLYBRACKET$1) {
  6746. return null;
  6747. }
  6748. return new List$1().appendData(
  6749. this.SelectorList()
  6750. );
  6751. },
  6752. block: function() {
  6753. return this.Block(this.Declaration);
  6754. }
  6755. }
  6756. };
  6757. var page_1 = page.parse;
  6758. var page$1 = /*#__PURE__*/Object.freeze({
  6759. default: page,
  6760. __moduleExports: page,
  6761. parse: page_1
  6762. });
  6763. var TYPE$9 = require$$0$1.TYPE;
  6764. var WHITESPACE$3 = TYPE$9.WhiteSpace;
  6765. var COMMENT$3 = TYPE$9.Comment;
  6766. var IDENTIFIER$6 = TYPE$9.Identifier;
  6767. var FUNCTION$3 = TYPE$9.Function;
  6768. var LEFTPARENTHESIS$3 = TYPE$9.LeftParenthesis;
  6769. var HYPHENMINUS$4 = TYPE$9.HyphenMinus;
  6770. var COLON$1 = TYPE$9.Colon;
  6771. function consumeRaw() {
  6772. return new List$1().appendData(
  6773. this.Raw(this.scanner.currentToken, 0, 0, false, false)
  6774. );
  6775. }
  6776. function parentheses() {
  6777. var index = 0;
  6778. this.scanner.skipSC();
  6779. // TODO: make it simplier
  6780. if (this.scanner.tokenType === IDENTIFIER$6) {
  6781. index = 1;
  6782. } else if (this.scanner.tokenType === HYPHENMINUS$4 &&
  6783. this.scanner.lookupType(1) === IDENTIFIER$6) {
  6784. index = 2;
  6785. }
  6786. if (index !== 0 && this.scanner.lookupNonWSType(index) === COLON$1) {
  6787. return new List$1().appendData(
  6788. this.Declaration()
  6789. );
  6790. }
  6791. return readSequence.call(this);
  6792. }
  6793. function readSequence() {
  6794. var children = new List$1();
  6795. var space = null;
  6796. var child;
  6797. this.scanner.skipSC();
  6798. scan:
  6799. while (!this.scanner.eof) {
  6800. switch (this.scanner.tokenType) {
  6801. case WHITESPACE$3:
  6802. space = this.WhiteSpace();
  6803. continue;
  6804. case COMMENT$3:
  6805. this.scanner.next();
  6806. continue;
  6807. case FUNCTION$3:
  6808. child = this.Function(consumeRaw, this.scope.AtruleExpression);
  6809. break;
  6810. case IDENTIFIER$6:
  6811. child = this.Identifier();
  6812. break;
  6813. case LEFTPARENTHESIS$3:
  6814. child = this.Parentheses(parentheses, this.scope.AtruleExpression);
  6815. break;
  6816. default:
  6817. break scan;
  6818. }
  6819. if (space !== null) {
  6820. children.appendData(space);
  6821. space = null;
  6822. }
  6823. children.appendData(child);
  6824. }
  6825. return children;
  6826. }
  6827. var supports = {
  6828. parse: {
  6829. expression: function() {
  6830. var children = readSequence.call(this);
  6831. if (children.isEmpty()) {
  6832. this.scanner.error('Condition is expected');
  6833. }
  6834. return children;
  6835. },
  6836. block: function() {
  6837. return this.Block(this.Rule);
  6838. }
  6839. }
  6840. };
  6841. var supports_1 = supports.parse;
  6842. var supports$1 = /*#__PURE__*/Object.freeze({
  6843. default: supports,
  6844. __moduleExports: supports,
  6845. parse: supports_1
  6846. });
  6847. var require$$0$4 = ( fontFace$1 && fontFace ) || fontFace$1;
  6848. var require$$1$2 = ( _import$1 && _import ) || _import$1;
  6849. var require$$2$2 = ( media$1 && media ) || media$1;
  6850. var require$$3$1 = ( page$1 && page ) || page$1;
  6851. var require$$4 = ( supports$1 && supports ) || supports$1;
  6852. var atrule = {
  6853. 'font-face': require$$0$4,
  6854. 'import': require$$1$2,
  6855. 'media': require$$2$2,
  6856. 'page': require$$3$1,
  6857. 'supports': require$$4
  6858. };
  6859. var atrule$1 = /*#__PURE__*/Object.freeze({
  6860. default: atrule,
  6861. __moduleExports: atrule
  6862. });
  6863. var dir = {
  6864. parse: function() {
  6865. return new List$1().appendData(
  6866. this.Identifier()
  6867. );
  6868. }
  6869. };
  6870. var dir_1 = dir.parse;
  6871. var dir$1 = /*#__PURE__*/Object.freeze({
  6872. default: dir,
  6873. __moduleExports: dir,
  6874. parse: dir_1
  6875. });
  6876. var has$1 = {
  6877. parse: function() {
  6878. return new List$1().appendData(
  6879. this.SelectorList()
  6880. );
  6881. }
  6882. };
  6883. var has_1 = has$1.parse;
  6884. var has$2 = /*#__PURE__*/Object.freeze({
  6885. default: has$1,
  6886. __moduleExports: has$1,
  6887. parse: has_1
  6888. });
  6889. var lang = {
  6890. parse: function() {
  6891. return new List$1().appendData(
  6892. this.Identifier()
  6893. );
  6894. }
  6895. };
  6896. var lang_1 = lang.parse;
  6897. var lang$1 = /*#__PURE__*/Object.freeze({
  6898. default: lang,
  6899. __moduleExports: lang,
  6900. parse: lang_1
  6901. });
  6902. var selectorList = {
  6903. parse: function selectorList() {
  6904. return new List$1().appendData(
  6905. this.SelectorList()
  6906. );
  6907. }
  6908. };
  6909. var selectorList_1 = selectorList.parse;
  6910. var selectorList$1 = /*#__PURE__*/Object.freeze({
  6911. default: selectorList,
  6912. __moduleExports: selectorList,
  6913. parse: selectorList_1
  6914. });
  6915. var require$$0$5 = ( selectorList$1 && selectorList ) || selectorList$1;
  6916. var matches = require$$0$5;
  6917. var matches$1 = /*#__PURE__*/Object.freeze({
  6918. default: matches,
  6919. __moduleExports: matches
  6920. });
  6921. var not = require$$0$5;
  6922. var not$1 = /*#__PURE__*/Object.freeze({
  6923. default: not,
  6924. __moduleExports: not
  6925. });
  6926. var ALLOW_OF_CLAUSE = true;
  6927. var nthWithOfClause = {
  6928. parse: function() {
  6929. return new List$1().appendData(
  6930. this.Nth(ALLOW_OF_CLAUSE)
  6931. );
  6932. }
  6933. };
  6934. var nthWithOfClause_1 = nthWithOfClause.parse;
  6935. var nthWithOfClause$1 = /*#__PURE__*/Object.freeze({
  6936. default: nthWithOfClause,
  6937. __moduleExports: nthWithOfClause,
  6938. parse: nthWithOfClause_1
  6939. });
  6940. var require$$0$6 = ( nthWithOfClause$1 && nthWithOfClause ) || nthWithOfClause$1;
  6941. var nthChild = require$$0$6;
  6942. var nthChild$1 = /*#__PURE__*/Object.freeze({
  6943. default: nthChild,
  6944. __moduleExports: nthChild
  6945. });
  6946. var nthLastChild = require$$0$6;
  6947. var nthLastChild$1 = /*#__PURE__*/Object.freeze({
  6948. default: nthLastChild,
  6949. __moduleExports: nthLastChild
  6950. });
  6951. var DISALLOW_OF_CLAUSE = false;
  6952. var nth = {
  6953. parse: function nth() {
  6954. return new List$1().appendData(
  6955. this.Nth(DISALLOW_OF_CLAUSE)
  6956. );
  6957. }
  6958. };
  6959. var nth_1 = nth.parse;
  6960. var nth$1 = /*#__PURE__*/Object.freeze({
  6961. default: nth,
  6962. __moduleExports: nth,
  6963. parse: nth_1
  6964. });
  6965. var require$$0$7 = ( nth$1 && nth ) || nth$1;
  6966. var nthLastOfType = require$$0$7;
  6967. var nthLastOfType$1 = /*#__PURE__*/Object.freeze({
  6968. default: nthLastOfType,
  6969. __moduleExports: nthLastOfType
  6970. });
  6971. var nthOfType = require$$0$7;
  6972. var nthOfType$1 = /*#__PURE__*/Object.freeze({
  6973. default: nthOfType,
  6974. __moduleExports: nthOfType
  6975. });
  6976. var slotted = {
  6977. parse: function compoundSelector() {
  6978. return new List$1().appendData(
  6979. this.Selector()
  6980. );
  6981. }
  6982. };
  6983. var slotted_1 = slotted.parse;
  6984. var slotted$1 = /*#__PURE__*/Object.freeze({
  6985. default: slotted,
  6986. __moduleExports: slotted,
  6987. parse: slotted_1
  6988. });
  6989. var require$$0$8 = ( dir$1 && dir ) || dir$1;
  6990. var require$$1$3 = ( has$2 && has$1 ) || has$2;
  6991. var require$$2$3 = ( lang$1 && lang ) || lang$1;
  6992. var require$$3$2 = ( matches$1 && matches ) || matches$1;
  6993. var require$$4$1 = ( not$1 && not ) || not$1;
  6994. var require$$5 = ( nthChild$1 && nthChild ) || nthChild$1;
  6995. var require$$6 = ( nthLastChild$1 && nthLastChild ) || nthLastChild$1;
  6996. var require$$7 = ( nthLastOfType$1 && nthLastOfType ) || nthLastOfType$1;
  6997. var require$$8 = ( nthOfType$1 && nthOfType ) || nthOfType$1;
  6998. var require$$9 = ( slotted$1 && slotted ) || slotted$1;
  6999. var pseudo = {
  7000. 'dir': require$$0$8,
  7001. 'has': require$$1$3,
  7002. 'lang': require$$2$3,
  7003. 'matches': require$$3$2,
  7004. 'not': require$$4$1,
  7005. 'nth-child': require$$5,
  7006. 'nth-last-child': require$$6,
  7007. 'nth-last-of-type': require$$7,
  7008. 'nth-of-type': require$$8,
  7009. 'slotted': require$$9
  7010. };
  7011. var pseudo$1 = /*#__PURE__*/Object.freeze({
  7012. default: pseudo,
  7013. __moduleExports: pseudo
  7014. });
  7015. var cmpChar$2 = require$$0$1.cmpChar;
  7016. var isNumber$2 = require$$0$1.isNumber;
  7017. var TYPE$10 = require$$0$1.TYPE;
  7018. var IDENTIFIER$7 = TYPE$10.Identifier;
  7019. var NUMBER$4 = TYPE$10.Number;
  7020. var PLUSSIGN$4 = TYPE$10.PlusSign;
  7021. var HYPHENMINUS$5 = TYPE$10.HyphenMinus;
  7022. var N$3 = 110; // 'n'.charCodeAt(0)
  7023. var DISALLOW_SIGN = true;
  7024. var ALLOW_SIGN = false;
  7025. function checkTokenIsInteger(scanner, disallowSign) {
  7026. var pos = scanner.tokenStart;
  7027. if (scanner.source.charCodeAt(pos) === PLUSSIGN$4 ||
  7028. scanner.source.charCodeAt(pos) === HYPHENMINUS$5) {
  7029. if (disallowSign) {
  7030. scanner.error();
  7031. }
  7032. pos++;
  7033. }
  7034. for (; pos < scanner.tokenEnd; pos++) {
  7035. if (!isNumber$2(scanner.source.charCodeAt(pos))) {
  7036. scanner.error('Unexpected input', pos);
  7037. }
  7038. }
  7039. }
  7040. // An+B microsyntax https://www.w3.org/TR/css-syntax-3/#anb
  7041. var AnPlusB = {
  7042. name: 'AnPlusB',
  7043. structure: {
  7044. a: [String, null],
  7045. b: [String, null]
  7046. },
  7047. parse: function() {
  7048. var start = this.scanner.tokenStart;
  7049. var end = start;
  7050. var prefix = '';
  7051. var a = null;
  7052. var b = null;
  7053. if (this.scanner.tokenType === NUMBER$4 ||
  7054. this.scanner.tokenType === PLUSSIGN$4) {
  7055. checkTokenIsInteger(this.scanner, ALLOW_SIGN);
  7056. prefix = this.scanner.getTokenValue();
  7057. this.scanner.next();
  7058. end = this.scanner.tokenStart;
  7059. }
  7060. if (this.scanner.tokenType === IDENTIFIER$7) {
  7061. var bStart = this.scanner.tokenStart;
  7062. if (cmpChar$2(this.scanner.source, bStart, HYPHENMINUS$5)) {
  7063. if (prefix === '') {
  7064. prefix = '-';
  7065. bStart++;
  7066. } else {
  7067. this.scanner.error('Unexpected hyphen minus');
  7068. }
  7069. }
  7070. if (!cmpChar$2(this.scanner.source, bStart, N$3)) {
  7071. this.scanner.error();
  7072. }
  7073. a = prefix === '' ? '1' :
  7074. prefix === '+' ? '+1' :
  7075. prefix === '-' ? '-1' :
  7076. prefix;
  7077. var len = this.scanner.tokenEnd - bStart;
  7078. if (len > 1) {
  7079. // ..n-..
  7080. if (this.scanner.source.charCodeAt(bStart + 1) !== HYPHENMINUS$5) {
  7081. this.scanner.error('Unexpected input', bStart + 1);
  7082. }
  7083. if (len > 2) {
  7084. // ..n-{number}..
  7085. this.scanner.tokenStart = bStart + 2;
  7086. } else {
  7087. // ..n- {number}
  7088. this.scanner.next();
  7089. this.scanner.skipSC();
  7090. }
  7091. checkTokenIsInteger(this.scanner, DISALLOW_SIGN);
  7092. b = '-' + this.scanner.getTokenValue();
  7093. this.scanner.next();
  7094. end = this.scanner.tokenStart;
  7095. } else {
  7096. prefix = '';
  7097. this.scanner.next();
  7098. end = this.scanner.tokenStart;
  7099. this.scanner.skipSC();
  7100. if (this.scanner.tokenType === HYPHENMINUS$5 ||
  7101. this.scanner.tokenType === PLUSSIGN$4) {
  7102. prefix = this.scanner.getTokenValue();
  7103. this.scanner.next();
  7104. this.scanner.skipSC();
  7105. }
  7106. if (this.scanner.tokenType === NUMBER$4) {
  7107. checkTokenIsInteger(this.scanner, prefix !== '');
  7108. if (!isNumber$2(this.scanner.source.charCodeAt(this.scanner.tokenStart))) {
  7109. prefix = this.scanner.source.charAt(this.scanner.tokenStart);
  7110. this.scanner.tokenStart++;
  7111. }
  7112. if (prefix === '') {
  7113. // should be an operator before number
  7114. this.scanner.error();
  7115. } else if (prefix === '+') {
  7116. // plus is using by default
  7117. prefix = '';
  7118. }
  7119. b = prefix + this.scanner.getTokenValue();
  7120. this.scanner.next();
  7121. end = this.scanner.tokenStart;
  7122. } else {
  7123. if (prefix) {
  7124. this.scanner.eat(NUMBER$4);
  7125. }
  7126. }
  7127. }
  7128. } else {
  7129. if (prefix === '' || prefix === '+') { // no number
  7130. this.scanner.error(
  7131. 'Number or identifier is expected',
  7132. this.scanner.tokenStart + (
  7133. this.scanner.tokenType === PLUSSIGN$4 ||
  7134. this.scanner.tokenType === HYPHENMINUS$5
  7135. )
  7136. );
  7137. }
  7138. b = prefix;
  7139. }
  7140. return {
  7141. type: 'AnPlusB',
  7142. loc: this.getLocation(start, end),
  7143. a: a,
  7144. b: b
  7145. };
  7146. },
  7147. generate: function(processChunk, node) {
  7148. var a = node.a !== null && node.a !== undefined;
  7149. var b = node.b !== null && node.b !== undefined;
  7150. if (a) {
  7151. processChunk(
  7152. node.a === '+1' ? '+n' :
  7153. node.a === '1' ? 'n' :
  7154. node.a === '-1' ? '-n' :
  7155. node.a + 'n'
  7156. );
  7157. if (b) {
  7158. b = String(node.b);
  7159. if (b.charAt(0) === '-' || b.charAt(0) === '+') {
  7160. processChunk(b.charAt(0));
  7161. processChunk(b.substr(1));
  7162. } else {
  7163. processChunk('+');
  7164. processChunk(b);
  7165. }
  7166. }
  7167. } else {
  7168. processChunk(String(node.b));
  7169. }
  7170. }
  7171. };
  7172. var AnPlusB_1 = AnPlusB.name;
  7173. var AnPlusB_2 = AnPlusB.structure;
  7174. var AnPlusB_3 = AnPlusB.parse;
  7175. var AnPlusB_4 = AnPlusB.generate;
  7176. var AnPlusB$1 = /*#__PURE__*/Object.freeze({
  7177. default: AnPlusB,
  7178. __moduleExports: AnPlusB,
  7179. name: AnPlusB_1,
  7180. structure: AnPlusB_2,
  7181. parse: AnPlusB_3,
  7182. generate: AnPlusB_4
  7183. });
  7184. var TYPE$11 = require$$0$1.TYPE;
  7185. var ATRULE$2 = TYPE$11.Atrule;
  7186. var SEMICOLON$1 = TYPE$11.Semicolon;
  7187. var LEFTCURLYBRACKET$2 = TYPE$11.LeftCurlyBracket;
  7188. var RIGHTCURLYBRACKET$1 = TYPE$11.RightCurlyBracket;
  7189. function isBlockAtrule() {
  7190. for (var offset = 1, type; type = this.scanner.lookupType(offset); offset++) {
  7191. if (type === RIGHTCURLYBRACKET$1) {
  7192. return true;
  7193. }
  7194. if (type === LEFTCURLYBRACKET$2 ||
  7195. type === ATRULE$2) {
  7196. return false;
  7197. }
  7198. }
  7199. this.scanner.skip(offset);
  7200. this.scanner.eat(RIGHTCURLYBRACKET$1);
  7201. }
  7202. var Atrule = {
  7203. name: 'Atrule',
  7204. structure: {
  7205. name: String,
  7206. expression: ['AtruleExpression', null],
  7207. block: ['Block', null]
  7208. },
  7209. parse: function() {
  7210. var start = this.scanner.tokenStart;
  7211. var name;
  7212. var nameLowerCase;
  7213. var expression = null;
  7214. var block = null;
  7215. this.scanner.eat(ATRULE$2);
  7216. name = this.scanner.substrToCursor(start + 1);
  7217. nameLowerCase = name.toLowerCase();
  7218. this.scanner.skipSC();
  7219. expression = this.AtruleExpression(name);
  7220. // turn empty AtruleExpression into null
  7221. if (expression.children.head === null) {
  7222. expression = null;
  7223. }
  7224. this.scanner.skipSC();
  7225. if (this.atrule.hasOwnProperty(nameLowerCase)) {
  7226. if (typeof this.atrule[nameLowerCase].block === 'function') {
  7227. if (this.scanner.tokenType !== LEFTCURLYBRACKET$2) {
  7228. // FIXME: make tolerant
  7229. this.scanner.error('Curly bracket is expected');
  7230. }
  7231. block = this.atrule[nameLowerCase].block.call(this);
  7232. } else {
  7233. if (!this.tolerant || !this.scanner.eof) {
  7234. this.scanner.eat(SEMICOLON$1);
  7235. }
  7236. }
  7237. } else {
  7238. switch (this.scanner.tokenType) {
  7239. case SEMICOLON$1:
  7240. this.scanner.next();
  7241. break;
  7242. case LEFTCURLYBRACKET$2:
  7243. // TODO: should consume block content as Raw?
  7244. block = this.Block(isBlockAtrule.call(this) ? this.Declaration : this.Rule);
  7245. break;
  7246. default:
  7247. if (!this.tolerant) {
  7248. this.scanner.error('Semicolon or block is expected');
  7249. }
  7250. }
  7251. }
  7252. return {
  7253. type: 'Atrule',
  7254. loc: this.getLocation(start, this.scanner.tokenStart),
  7255. name: name,
  7256. expression: expression,
  7257. block: block
  7258. };
  7259. },
  7260. generate: function(processChunk, node) {
  7261. processChunk('@');
  7262. processChunk(node.name);
  7263. if (node.expression !== null) {
  7264. processChunk(' ');
  7265. this.generate(processChunk, node.expression);
  7266. }
  7267. if (node.block) {
  7268. this.generate(processChunk, node.block);
  7269. } else {
  7270. processChunk(';');
  7271. }
  7272. },
  7273. walkContext: 'atrule'
  7274. };
  7275. var Atrule_1 = Atrule.name;
  7276. var Atrule_2 = Atrule.structure;
  7277. var Atrule_3 = Atrule.parse;
  7278. var Atrule_4 = Atrule.generate;
  7279. var Atrule_5 = Atrule.walkContext;
  7280. var Atrule$1 = /*#__PURE__*/Object.freeze({
  7281. default: Atrule,
  7282. __moduleExports: Atrule,
  7283. name: Atrule_1,
  7284. structure: Atrule_2,
  7285. parse: Atrule_3,
  7286. generate: Atrule_4,
  7287. walkContext: Atrule_5
  7288. });
  7289. var TYPE$12 = require$$0$1.TYPE;
  7290. var SEMICOLON$2 = TYPE$12.Semicolon;
  7291. var LEFTCURLYBRACKET$3 = TYPE$12.LeftCurlyBracket;
  7292. function consumeRaw$1(startToken) {
  7293. return new List$1().appendData(
  7294. this.Raw(startToken, SEMICOLON$2, LEFTCURLYBRACKET$3, false, true)
  7295. );
  7296. }
  7297. function consumeDefaultSequence() {
  7298. return this.readSequence(this.scope.AtruleExpression);
  7299. }
  7300. var AtruleExpression = {
  7301. name: 'AtruleExpression',
  7302. structure: {
  7303. children: [[]]
  7304. },
  7305. parse: function(name) {
  7306. var children = null;
  7307. var startToken = this.scanner.currentToken;
  7308. if (name !== null) {
  7309. name = name.toLowerCase();
  7310. }
  7311. if (this.parseAtruleExpression) {
  7312. // custom consumer
  7313. if (this.atrule.hasOwnProperty(name)) {
  7314. if (typeof this.atrule[name].expression === 'function') {
  7315. children = this.tolerantParse(this.atrule[name].expression, consumeRaw$1);
  7316. }
  7317. } else {
  7318. // default consumer
  7319. this.scanner.skipSC();
  7320. children = this.tolerantParse(consumeDefaultSequence, consumeRaw$1);
  7321. }
  7322. if (this.tolerant) {
  7323. if (this.scanner.eof || (this.scanner.tokenType !== SEMICOLON$2 && this.scanner.tokenType !== LEFTCURLYBRACKET$3)) {
  7324. children = consumeRaw$1.call(this, startToken);
  7325. }
  7326. }
  7327. } else {
  7328. children = consumeRaw$1.call(this, startToken);
  7329. }
  7330. if (children === null) {
  7331. children = new List$1();
  7332. }
  7333. return {
  7334. type: 'AtruleExpression',
  7335. loc: this.getLocationFromList(children),
  7336. children: children
  7337. };
  7338. },
  7339. generate: function(processChunk, node) {
  7340. this.each(processChunk, node);
  7341. },
  7342. walkContext: 'atruleExpression'
  7343. };
  7344. var AtruleExpression_1 = AtruleExpression.name;
  7345. var AtruleExpression_2 = AtruleExpression.structure;
  7346. var AtruleExpression_3 = AtruleExpression.parse;
  7347. var AtruleExpression_4 = AtruleExpression.generate;
  7348. var AtruleExpression_5 = AtruleExpression.walkContext;
  7349. var AtruleExpression$1 = /*#__PURE__*/Object.freeze({
  7350. default: AtruleExpression,
  7351. __moduleExports: AtruleExpression,
  7352. name: AtruleExpression_1,
  7353. structure: AtruleExpression_2,
  7354. parse: AtruleExpression_3,
  7355. generate: AtruleExpression_4,
  7356. walkContext: AtruleExpression_5
  7357. });
  7358. var TYPE$13 = require$$0$1.TYPE;
  7359. var IDENTIFIER$8 = TYPE$13.Identifier;
  7360. var STRING$4 = TYPE$13.String;
  7361. var DOLLARSIGN = TYPE$13.DollarSign;
  7362. var ASTERISK$2 = TYPE$13.Asterisk;
  7363. var COLON$2 = TYPE$13.Colon;
  7364. var EQUALSSIGN = TYPE$13.EqualsSign;
  7365. var LEFTSQUAREBRACKET$3 = TYPE$13.LeftSquareBracket;
  7366. var RIGHTSQUAREBRACKET$1 = TYPE$13.RightSquareBracket;
  7367. var CIRCUMFLEXACCENT = TYPE$13.CircumflexAccent;
  7368. var VERTICALLINE$1 = TYPE$13.VerticalLine;
  7369. var TILDE$1 = TYPE$13.Tilde;
  7370. function getAttributeName() {
  7371. if (this.scanner.eof) {
  7372. this.scanner.error('Unexpected end of input');
  7373. }
  7374. var start = this.scanner.tokenStart;
  7375. var expectIdentifier = false;
  7376. var checkColon = true;
  7377. if (this.scanner.tokenType === ASTERISK$2) {
  7378. expectIdentifier = true;
  7379. checkColon = false;
  7380. this.scanner.next();
  7381. } else if (this.scanner.tokenType !== VERTICALLINE$1) {
  7382. this.scanner.eat(IDENTIFIER$8);
  7383. }
  7384. if (this.scanner.tokenType === VERTICALLINE$1) {
  7385. if (this.scanner.lookupType(1) !== EQUALSSIGN) {
  7386. this.scanner.next();
  7387. this.scanner.eat(IDENTIFIER$8);
  7388. } else if (expectIdentifier) {
  7389. this.scanner.error('Identifier is expected', this.scanner.tokenEnd);
  7390. }
  7391. } else if (expectIdentifier) {
  7392. this.scanner.error('Vertical line is expected');
  7393. }
  7394. if (checkColon && this.scanner.tokenType === COLON$2) {
  7395. this.scanner.next();
  7396. this.scanner.eat(IDENTIFIER$8);
  7397. }
  7398. return {
  7399. type: 'Identifier',
  7400. loc: this.getLocation(start, this.scanner.tokenStart),
  7401. name: this.scanner.substrToCursor(start)
  7402. };
  7403. }
  7404. function getOperator() {
  7405. var start = this.scanner.tokenStart;
  7406. var tokenType = this.scanner.tokenType;
  7407. if (tokenType !== EQUALSSIGN && // =
  7408. tokenType !== TILDE$1 && // ~=
  7409. tokenType !== CIRCUMFLEXACCENT && // ^=
  7410. tokenType !== DOLLARSIGN && // $=
  7411. tokenType !== ASTERISK$2 && // *=
  7412. tokenType !== VERTICALLINE$1 // |=
  7413. ) {
  7414. this.scanner.error('Attribute selector (=, ~=, ^=, $=, *=, |=) is expected');
  7415. }
  7416. if (tokenType === EQUALSSIGN) {
  7417. this.scanner.next();
  7418. } else {
  7419. this.scanner.next();
  7420. this.scanner.eat(EQUALSSIGN);
  7421. }
  7422. return this.scanner.substrToCursor(start);
  7423. }
  7424. // '[' S* attrib_name ']'
  7425. // '[' S* attrib_name S* attrib_matcher S* [ IDENT | STRING ] S* attrib_flags? S* ']'
  7426. var AttributeSelector = {
  7427. name: 'AttributeSelector',
  7428. structure: {
  7429. name: 'Identifier',
  7430. matcher: [String, null],
  7431. value: ['String', 'Identifier', null],
  7432. flags: [String, null]
  7433. },
  7434. parse: function() {
  7435. var start = this.scanner.tokenStart;
  7436. var name;
  7437. var matcher = null;
  7438. var value = null;
  7439. var flags = null;
  7440. this.scanner.eat(LEFTSQUAREBRACKET$3);
  7441. this.scanner.skipSC();
  7442. name = getAttributeName.call(this);
  7443. this.scanner.skipSC();
  7444. if (this.scanner.tokenType !== RIGHTSQUAREBRACKET$1) {
  7445. // avoid case `[name i]`
  7446. if (this.scanner.tokenType !== IDENTIFIER$8) {
  7447. matcher = getOperator.call(this);
  7448. this.scanner.skipSC();
  7449. value = this.scanner.tokenType === STRING$4
  7450. ? this.String()
  7451. : this.Identifier();
  7452. this.scanner.skipSC();
  7453. }
  7454. // attribute flags
  7455. if (this.scanner.tokenType === IDENTIFIER$8) {
  7456. flags = this.scanner.getTokenValue();
  7457. this.scanner.next();
  7458. this.scanner.skipSC();
  7459. }
  7460. }
  7461. this.scanner.eat(RIGHTSQUAREBRACKET$1);
  7462. return {
  7463. type: 'AttributeSelector',
  7464. loc: this.getLocation(start, this.scanner.tokenStart),
  7465. name: name,
  7466. matcher: matcher,
  7467. value: value,
  7468. flags: flags
  7469. };
  7470. },
  7471. generate: function(processChunk, node) {
  7472. var flagsPrefix = ' ';
  7473. processChunk('[');
  7474. this.generate(processChunk, node.name);
  7475. if (node.matcher !== null) {
  7476. processChunk(node.matcher);
  7477. if (node.value !== null) {
  7478. this.generate(processChunk, node.value);
  7479. // space between string and flags is not required
  7480. if (node.value.type === 'String') {
  7481. flagsPrefix = '';
  7482. }
  7483. }
  7484. }
  7485. if (node.flags !== null) {
  7486. processChunk(flagsPrefix);
  7487. processChunk(node.flags);
  7488. }
  7489. processChunk(']');
  7490. }
  7491. };
  7492. var AttributeSelector_1 = AttributeSelector.name;
  7493. var AttributeSelector_2 = AttributeSelector.structure;
  7494. var AttributeSelector_3 = AttributeSelector.parse;
  7495. var AttributeSelector_4 = AttributeSelector.generate;
  7496. var AttributeSelector$1 = /*#__PURE__*/Object.freeze({
  7497. default: AttributeSelector,
  7498. __moduleExports: AttributeSelector,
  7499. name: AttributeSelector_1,
  7500. structure: AttributeSelector_2,
  7501. parse: AttributeSelector_3,
  7502. generate: AttributeSelector_4
  7503. });
  7504. var TYPE$14 = require$$0$1.TYPE;
  7505. var WHITESPACE$4 = TYPE$14.WhiteSpace;
  7506. var COMMENT$4 = TYPE$14.Comment;
  7507. var SEMICOLON$3 = TYPE$14.Semicolon;
  7508. var ATRULE$3 = TYPE$14.Atrule;
  7509. var LEFTCURLYBRACKET$4 = TYPE$14.LeftCurlyBracket;
  7510. var RIGHTCURLYBRACKET$2 = TYPE$14.RightCurlyBracket;
  7511. function consumeRaw$2(startToken) {
  7512. return this.Raw(startToken, 0, SEMICOLON$3, true, true);
  7513. }
  7514. var Block = {
  7515. name: 'Block',
  7516. structure: {
  7517. children: [['Atrule', 'Rule', 'Declaration']]
  7518. },
  7519. parse: function(defaultConsumer) {
  7520. if (!defaultConsumer) {
  7521. defaultConsumer = this.Declaration;
  7522. }
  7523. var start = this.scanner.tokenStart;
  7524. var children = new List$1();
  7525. this.scanner.eat(LEFTCURLYBRACKET$4);
  7526. scan:
  7527. while (!this.scanner.eof) {
  7528. switch (this.scanner.tokenType) {
  7529. case RIGHTCURLYBRACKET$2:
  7530. break scan;
  7531. case WHITESPACE$4:
  7532. case COMMENT$4:
  7533. case SEMICOLON$3:
  7534. this.scanner.next();
  7535. break;
  7536. case ATRULE$3:
  7537. children.appendData(this.tolerantParse(this.Atrule, consumeRaw$2));
  7538. break;
  7539. default:
  7540. children.appendData(this.tolerantParse(defaultConsumer, consumeRaw$2));
  7541. }
  7542. }
  7543. if (!this.tolerant || !this.scanner.eof) {
  7544. this.scanner.eat(RIGHTCURLYBRACKET$2);
  7545. }
  7546. return {
  7547. type: 'Block',
  7548. loc: this.getLocation(start, this.scanner.tokenStart),
  7549. children: children
  7550. };
  7551. },
  7552. generate: function(processChunk, node) {
  7553. processChunk('{');
  7554. this.each(processChunk, node);
  7555. processChunk('}');
  7556. },
  7557. walkContext: 'block'
  7558. };
  7559. var Block_1 = Block.name;
  7560. var Block_2 = Block.structure;
  7561. var Block_3 = Block.parse;
  7562. var Block_4 = Block.generate;
  7563. var Block_5 = Block.walkContext;
  7564. var Block$1 = /*#__PURE__*/Object.freeze({
  7565. default: Block,
  7566. __moduleExports: Block,
  7567. name: Block_1,
  7568. structure: Block_2,
  7569. parse: Block_3,
  7570. generate: Block_4,
  7571. walkContext: Block_5
  7572. });
  7573. var TYPE$15 = require$$0$1.TYPE;
  7574. var LEFTSQUAREBRACKET$4 = TYPE$15.LeftSquareBracket;
  7575. var RIGHTSQUAREBRACKET$2 = TYPE$15.RightSquareBracket;
  7576. // currently only Grid Layout uses square brackets, but left it universal
  7577. // https://drafts.csswg.org/css-grid/#track-sizing
  7578. // [ ident* ]
  7579. var Brackets = {
  7580. name: 'Brackets',
  7581. structure: {
  7582. children: [[]]
  7583. },
  7584. parse: function(readSequence, recognizer) {
  7585. var start = this.scanner.tokenStart;
  7586. var children = null;
  7587. this.scanner.eat(LEFTSQUAREBRACKET$4);
  7588. children = readSequence.call(this, recognizer);
  7589. this.scanner.eat(RIGHTSQUAREBRACKET$2);
  7590. return {
  7591. type: 'Brackets',
  7592. loc: this.getLocation(start, this.scanner.tokenStart),
  7593. children: children
  7594. };
  7595. },
  7596. generate: function(processChunk, node) {
  7597. processChunk('[');
  7598. this.each(processChunk, node);
  7599. processChunk(']');
  7600. }
  7601. };
  7602. var Brackets_1 = Brackets.name;
  7603. var Brackets_2 = Brackets.structure;
  7604. var Brackets_3 = Brackets.parse;
  7605. var Brackets_4 = Brackets.generate;
  7606. var Brackets$1 = /*#__PURE__*/Object.freeze({
  7607. default: Brackets,
  7608. __moduleExports: Brackets,
  7609. name: Brackets_1,
  7610. structure: Brackets_2,
  7611. parse: Brackets_3,
  7612. generate: Brackets_4
  7613. });
  7614. var CDC$2 = require$$0$1.TYPE.CDC;
  7615. var CDC_1 = {
  7616. name: 'CDC',
  7617. structure: [],
  7618. parse: function() {
  7619. var start = this.scanner.tokenStart;
  7620. this.scanner.eat(CDC$2); // -->
  7621. return {
  7622. type: 'CDC',
  7623. loc: this.getLocation(start, this.scanner.tokenStart)
  7624. };
  7625. },
  7626. generate: function(processChunk) {
  7627. processChunk('-->');
  7628. }
  7629. };
  7630. var CDC_2 = CDC_1.name;
  7631. var CDC_3 = CDC_1.structure;
  7632. var CDC_4 = CDC_1.parse;
  7633. var CDC_5 = CDC_1.generate;
  7634. var CDC$3 = /*#__PURE__*/Object.freeze({
  7635. default: CDC_1,
  7636. __moduleExports: CDC_1,
  7637. name: CDC_2,
  7638. structure: CDC_3,
  7639. parse: CDC_4,
  7640. generate: CDC_5
  7641. });
  7642. var CDO$2 = require$$0$1.TYPE.CDO;
  7643. var CDO_1 = {
  7644. name: 'CDO',
  7645. structure: [],
  7646. parse: function() {
  7647. var start = this.scanner.tokenStart;
  7648. this.scanner.eat(CDO$2); // <!--
  7649. return {
  7650. type: 'CDO',
  7651. loc: this.getLocation(start, this.scanner.tokenStart)
  7652. };
  7653. },
  7654. generate: function(processChunk) {
  7655. processChunk('<!--');
  7656. }
  7657. };
  7658. var CDO_2 = CDO_1.name;
  7659. var CDO_3 = CDO_1.structure;
  7660. var CDO_4 = CDO_1.parse;
  7661. var CDO_5 = CDO_1.generate;
  7662. var CDO$3 = /*#__PURE__*/Object.freeze({
  7663. default: CDO_1,
  7664. __moduleExports: CDO_1,
  7665. name: CDO_2,
  7666. structure: CDO_3,
  7667. parse: CDO_4,
  7668. generate: CDO_5
  7669. });
  7670. var TYPE$16 = require$$0$1.TYPE;
  7671. var IDENTIFIER$9 = TYPE$16.Identifier;
  7672. var FULLSTOP$3 = TYPE$16.FullStop;
  7673. // '.' ident
  7674. var ClassSelector = {
  7675. name: 'ClassSelector',
  7676. structure: {
  7677. name: String
  7678. },
  7679. parse: function() {
  7680. this.scanner.eat(FULLSTOP$3);
  7681. return {
  7682. type: 'ClassSelector',
  7683. loc: this.getLocation(this.scanner.tokenStart - 1, this.scanner.tokenEnd),
  7684. name: this.scanner.consume(IDENTIFIER$9)
  7685. };
  7686. },
  7687. generate: function(processChunk, node) {
  7688. processChunk('.');
  7689. processChunk(node.name);
  7690. }
  7691. };
  7692. var ClassSelector_1 = ClassSelector.name;
  7693. var ClassSelector_2 = ClassSelector.structure;
  7694. var ClassSelector_3 = ClassSelector.parse;
  7695. var ClassSelector_4 = ClassSelector.generate;
  7696. var ClassSelector$1 = /*#__PURE__*/Object.freeze({
  7697. default: ClassSelector,
  7698. __moduleExports: ClassSelector,
  7699. name: ClassSelector_1,
  7700. structure: ClassSelector_2,
  7701. parse: ClassSelector_3,
  7702. generate: ClassSelector_4
  7703. });
  7704. var TYPE$17 = require$$0$1.TYPE;
  7705. var PLUSSIGN$5 = TYPE$17.PlusSign;
  7706. var SOLIDUS$2 = TYPE$17.Solidus;
  7707. var GREATERTHANSIGN$2 = TYPE$17.GreaterThanSign;
  7708. var TILDE$2 = TYPE$17.Tilde;
  7709. // + | > | ~ | /deep/
  7710. var Combinator = {
  7711. name: 'Combinator',
  7712. structure: {
  7713. name: String
  7714. },
  7715. parse: function() {
  7716. var start = this.scanner.tokenStart;
  7717. switch (this.scanner.tokenType) {
  7718. case GREATERTHANSIGN$2:
  7719. case PLUSSIGN$5:
  7720. case TILDE$2:
  7721. this.scanner.next();
  7722. break;
  7723. case SOLIDUS$2:
  7724. this.scanner.next();
  7725. this.scanner.expectIdentifier('deep');
  7726. this.scanner.eat(SOLIDUS$2);
  7727. break;
  7728. default:
  7729. this.scanner.error('Combinator is expected');
  7730. }
  7731. return {
  7732. type: 'Combinator',
  7733. loc: this.getLocation(start, this.scanner.tokenStart),
  7734. name: this.scanner.substrToCursor(start)
  7735. };
  7736. },
  7737. generate: function(processChunk, node) {
  7738. processChunk(node.name);
  7739. }
  7740. };
  7741. var Combinator_1 = Combinator.name;
  7742. var Combinator_2 = Combinator.structure;
  7743. var Combinator_3 = Combinator.parse;
  7744. var Combinator_4 = Combinator.generate;
  7745. var Combinator$1 = /*#__PURE__*/Object.freeze({
  7746. default: Combinator,
  7747. __moduleExports: Combinator,
  7748. name: Combinator_1,
  7749. structure: Combinator_2,
  7750. parse: Combinator_3,
  7751. generate: Combinator_4
  7752. });
  7753. var TYPE$18 = require$$0$1.TYPE;
  7754. var ASTERISK$3 = TYPE$18.Asterisk;
  7755. var SOLIDUS$3 = TYPE$18.Solidus;
  7756. // '/*' .* '*/'
  7757. var Comment = {
  7758. name: 'Comment',
  7759. structure: {
  7760. value: String
  7761. },
  7762. parse: function() {
  7763. var start = this.scanner.tokenStart;
  7764. var end = this.scanner.tokenEnd;
  7765. if ((end - start + 2) >= 2 &&
  7766. this.scanner.source.charCodeAt(end - 2) === ASTERISK$3 &&
  7767. this.scanner.source.charCodeAt(end - 1) === SOLIDUS$3) {
  7768. end -= 2;
  7769. }
  7770. this.scanner.next();
  7771. return {
  7772. type: 'Comment',
  7773. loc: this.getLocation(start, this.scanner.tokenStart),
  7774. value: this.scanner.source.substring(start + 2, end)
  7775. };
  7776. },
  7777. generate: function(processChunk, node) {
  7778. processChunk('/*');
  7779. processChunk(node.value);
  7780. processChunk('*/');
  7781. }
  7782. };
  7783. var Comment_1 = Comment.name;
  7784. var Comment_2 = Comment.structure;
  7785. var Comment_3 = Comment.parse;
  7786. var Comment_4 = Comment.generate;
  7787. var Comment$1 = /*#__PURE__*/Object.freeze({
  7788. default: Comment,
  7789. __moduleExports: Comment,
  7790. name: Comment_1,
  7791. structure: Comment_2,
  7792. parse: Comment_3,
  7793. generate: Comment_4
  7794. });
  7795. var TYPE$19 = require$$0$1.TYPE;
  7796. var IDENTIFIER$10 = TYPE$19.Identifier;
  7797. var COLON$3 = TYPE$19.Colon;
  7798. var EXCLAMATIONMARK$2 = TYPE$19.ExclamationMark;
  7799. var SOLIDUS$4 = TYPE$19.Solidus;
  7800. var ASTERISK$4 = TYPE$19.Asterisk;
  7801. var DOLLARSIGN$1 = TYPE$19.DollarSign;
  7802. var HYPHENMINUS$6 = TYPE$19.HyphenMinus;
  7803. var SEMICOLON$4 = TYPE$19.Semicolon;
  7804. var RIGHTCURLYBRACKET$3 = TYPE$19.RightCurlyBracket;
  7805. var RIGHTPARENTHESIS$1 = TYPE$19.RightParenthesis;
  7806. var PLUSSIGN$6 = TYPE$19.PlusSign;
  7807. var NUMBERSIGN$2 = TYPE$19.NumberSign;
  7808. var Declaration = {
  7809. name: 'Declaration',
  7810. structure: {
  7811. important: [Boolean, String],
  7812. property: String,
  7813. value: ['Value', 'Raw']
  7814. },
  7815. parse: function() {
  7816. var start = this.scanner.tokenStart;
  7817. var property = readProperty.call(this);
  7818. var important = false;
  7819. var value;
  7820. this.scanner.skipSC();
  7821. this.scanner.eat(COLON$3);
  7822. if (isCustomProperty(property) ? this.parseCustomProperty : this.parseValue) {
  7823. value = this.Value(property);
  7824. } else {
  7825. value = this.Raw(this.scanner.currentToken, EXCLAMATIONMARK$2, SEMICOLON$4, false, false);
  7826. }
  7827. if (this.scanner.tokenType === EXCLAMATIONMARK$2) {
  7828. important = getImportant(this.scanner);
  7829. this.scanner.skipSC();
  7830. }
  7831. // TODO: include or not to include semicolon to range?
  7832. // if (this.scanner.tokenType === SEMICOLON) {
  7833. // this.scanner.next();
  7834. // }
  7835. if (!this.scanner.eof &&
  7836. this.scanner.tokenType !== SEMICOLON$4 &&
  7837. this.scanner.tokenType !== RIGHTPARENTHESIS$1 &&
  7838. this.scanner.tokenType !== RIGHTCURLYBRACKET$3) {
  7839. this.scanner.error();
  7840. }
  7841. return {
  7842. type: 'Declaration',
  7843. loc: this.getLocation(start, this.scanner.tokenStart),
  7844. important: important,
  7845. property: property,
  7846. value: value
  7847. };
  7848. },
  7849. generate: function(processChunk, node, item) {
  7850. processChunk(node.property);
  7851. processChunk(':');
  7852. this.generate(processChunk, node.value);
  7853. if (node.important) {
  7854. processChunk(node.important === true ? '!important' : '!' + node.important);
  7855. }
  7856. if (item && item.next) {
  7857. processChunk(';');
  7858. }
  7859. },
  7860. walkContext: 'declaration'
  7861. };
  7862. function isCustomProperty(name) {
  7863. return name.length >= 2 &&
  7864. name.charCodeAt(0) === HYPHENMINUS$6 &&
  7865. name.charCodeAt(1) === HYPHENMINUS$6;
  7866. }
  7867. function readProperty() {
  7868. var start = this.scanner.tokenStart;
  7869. var prefix = 0;
  7870. // hacks
  7871. switch (this.scanner.tokenType) {
  7872. case ASTERISK$4:
  7873. case DOLLARSIGN$1:
  7874. case PLUSSIGN$6:
  7875. case NUMBERSIGN$2:
  7876. prefix = 1;
  7877. break;
  7878. // TODO: not sure we should support this hack
  7879. case SOLIDUS$4:
  7880. prefix = this.scanner.lookupType(1) === SOLIDUS$4 ? 2 : 1;
  7881. break;
  7882. }
  7883. if (this.scanner.lookupType(prefix) === HYPHENMINUS$6) {
  7884. prefix++;
  7885. }
  7886. if (prefix) {
  7887. this.scanner.skip(prefix);
  7888. }
  7889. this.scanner.eat(IDENTIFIER$10);
  7890. return this.scanner.substrToCursor(start);
  7891. }
  7892. // ! ws* important
  7893. function getImportant(scanner) {
  7894. scanner.eat(EXCLAMATIONMARK$2);
  7895. scanner.skipSC();
  7896. var important = scanner.consume(IDENTIFIER$10);
  7897. // store original value in case it differ from `important`
  7898. // for better original source restoring and hacks like `!ie` support
  7899. return important === 'important' ? true : important;
  7900. }
  7901. var Declaration_1 = Declaration.name;
  7902. var Declaration_2 = Declaration.structure;
  7903. var Declaration_3 = Declaration.parse;
  7904. var Declaration_4 = Declaration.generate;
  7905. var Declaration_5 = Declaration.walkContext;
  7906. var Declaration$1 = /*#__PURE__*/Object.freeze({
  7907. default: Declaration,
  7908. __moduleExports: Declaration,
  7909. name: Declaration_1,
  7910. structure: Declaration_2,
  7911. parse: Declaration_3,
  7912. generate: Declaration_4,
  7913. walkContext: Declaration_5
  7914. });
  7915. var TYPE$20 = require$$0$1.TYPE;
  7916. var WHITESPACE$5 = TYPE$20.WhiteSpace;
  7917. var COMMENT$5 = TYPE$20.Comment;
  7918. var SEMICOLON$5 = TYPE$20.Semicolon;
  7919. function consumeRaw$3(startToken) {
  7920. return this.Raw(startToken, 0, SEMICOLON$5, true, true);
  7921. }
  7922. var DeclarationList = {
  7923. name: 'DeclarationList',
  7924. structure: {
  7925. children: [['Declaration']]
  7926. },
  7927. parse: function() {
  7928. var children = new List$1();
  7929. scan:
  7930. while (!this.scanner.eof) {
  7931. switch (this.scanner.tokenType) {
  7932. case WHITESPACE$5:
  7933. case COMMENT$5:
  7934. case SEMICOLON$5:
  7935. this.scanner.next();
  7936. break;
  7937. default:
  7938. children.appendData(this.tolerantParse(this.Declaration, consumeRaw$3));
  7939. }
  7940. }
  7941. return {
  7942. type: 'DeclarationList',
  7943. loc: this.getLocationFromList(children),
  7944. children: children
  7945. };
  7946. },
  7947. generate: function(processChunk, node) {
  7948. this.each(processChunk, node);
  7949. }
  7950. };
  7951. var DeclarationList_1 = DeclarationList.name;
  7952. var DeclarationList_2 = DeclarationList.structure;
  7953. var DeclarationList_3 = DeclarationList.parse;
  7954. var DeclarationList_4 = DeclarationList.generate;
  7955. var DeclarationList$1 = /*#__PURE__*/Object.freeze({
  7956. default: DeclarationList,
  7957. __moduleExports: DeclarationList,
  7958. name: DeclarationList_1,
  7959. structure: DeclarationList_2,
  7960. parse: DeclarationList_3,
  7961. generate: DeclarationList_4
  7962. });
  7963. var NUMBER$5 = require$$0$1.TYPE.Number;
  7964. // special reader for units to avoid adjoined IE hacks (i.e. '1px\9')
  7965. function readUnit(scanner) {
  7966. var unit = scanner.getTokenValue();
  7967. var backSlashPos = unit.indexOf('\\');
  7968. if (backSlashPos > 0) {
  7969. // patch token offset
  7970. scanner.tokenStart += backSlashPos;
  7971. // return part before backslash
  7972. return unit.substring(0, backSlashPos);
  7973. }
  7974. // no backslash in unit name
  7975. scanner.next();
  7976. return unit;
  7977. }
  7978. // number ident
  7979. var Dimension = {
  7980. name: 'Dimension',
  7981. structure: {
  7982. value: String,
  7983. unit: String
  7984. },
  7985. parse: function() {
  7986. var start = this.scanner.tokenStart;
  7987. var value = this.scanner.consume(NUMBER$5);
  7988. var unit = readUnit(this.scanner);
  7989. return {
  7990. type: 'Dimension',
  7991. loc: this.getLocation(start, this.scanner.tokenStart),
  7992. value: value,
  7993. unit: unit
  7994. };
  7995. },
  7996. generate: function(processChunk, node) {
  7997. processChunk(node.value);
  7998. processChunk(node.unit);
  7999. }
  8000. };
  8001. var Dimension_1 = Dimension.name;
  8002. var Dimension_2 = Dimension.structure;
  8003. var Dimension_3 = Dimension.parse;
  8004. var Dimension_4 = Dimension.generate;
  8005. var Dimension$1 = /*#__PURE__*/Object.freeze({
  8006. default: Dimension,
  8007. __moduleExports: Dimension,
  8008. name: Dimension_1,
  8009. structure: Dimension_2,
  8010. parse: Dimension_3,
  8011. generate: Dimension_4
  8012. });
  8013. var TYPE$21 = require$$0$1.TYPE;
  8014. var RIGHTPARENTHESIS$2 = TYPE$21.RightParenthesis;
  8015. // <function-token> <sequence> ')'
  8016. var _Function = {
  8017. name: 'Function',
  8018. structure: {
  8019. name: String,
  8020. children: [[]]
  8021. },
  8022. parse: function(readSequence, recognizer) {
  8023. var start = this.scanner.tokenStart;
  8024. var name = this.scanner.consumeFunctionName();
  8025. var nameLowerCase = name.toLowerCase();
  8026. var children;
  8027. children = recognizer.hasOwnProperty(nameLowerCase)
  8028. ? recognizer[nameLowerCase].call(this, recognizer)
  8029. : readSequence.call(this, recognizer);
  8030. this.scanner.eat(RIGHTPARENTHESIS$2);
  8031. return {
  8032. type: 'Function',
  8033. loc: this.getLocation(start, this.scanner.tokenStart),
  8034. name: name,
  8035. children: children
  8036. };
  8037. },
  8038. generate: function(processChunk, node) {
  8039. processChunk(node.name);
  8040. processChunk('(');
  8041. this.each(processChunk, node);
  8042. processChunk(')');
  8043. },
  8044. walkContext: 'function'
  8045. };
  8046. var _Function_1 = _Function.name;
  8047. var _Function_2 = _Function.structure;
  8048. var _Function_3 = _Function.parse;
  8049. var _Function_4 = _Function.generate;
  8050. var _Function_5 = _Function.walkContext;
  8051. var _Function$1 = /*#__PURE__*/Object.freeze({
  8052. default: _Function,
  8053. __moduleExports: _Function,
  8054. name: _Function_1,
  8055. structure: _Function_2,
  8056. parse: _Function_3,
  8057. generate: _Function_4,
  8058. walkContext: _Function_5
  8059. });
  8060. var isHex$1 = require$$0$1.isHex;
  8061. var TYPE$22 = require$$0$1.TYPE;
  8062. var IDENTIFIER$11 = TYPE$22.Identifier;
  8063. var NUMBER$6 = TYPE$22.Number;
  8064. var NUMBERSIGN$3 = TYPE$22.NumberSign;
  8065. function consumeHexSequence(scanner, required) {
  8066. if (!isHex$1(scanner.source.charCodeAt(scanner.tokenStart))) {
  8067. if (required) {
  8068. scanner.error('Unexpected input', scanner.tokenStart);
  8069. } else {
  8070. return;
  8071. }
  8072. }
  8073. for (var pos = scanner.tokenStart + 1; pos < scanner.tokenEnd; pos++) {
  8074. var code = scanner.source.charCodeAt(pos);
  8075. // break on non-hex char
  8076. if (!isHex$1(code)) {
  8077. // break token, exclude symbol
  8078. scanner.tokenStart = pos;
  8079. return;
  8080. }
  8081. }
  8082. // token is full hex sequence, go to next token
  8083. scanner.next();
  8084. }
  8085. // # ident
  8086. var HexColor = {
  8087. name: 'HexColor',
  8088. structure: {
  8089. value: String
  8090. },
  8091. parse: function() {
  8092. var start = this.scanner.tokenStart;
  8093. this.scanner.eat(NUMBERSIGN$3);
  8094. scan:
  8095. switch (this.scanner.tokenType) {
  8096. case NUMBER$6:
  8097. consumeHexSequence(this.scanner, true);
  8098. // if token is identifier then number consists of hex only,
  8099. // try to add identifier to result
  8100. if (this.scanner.tokenType === IDENTIFIER$11) {
  8101. consumeHexSequence(this.scanner, false);
  8102. }
  8103. break;
  8104. case IDENTIFIER$11:
  8105. consumeHexSequence(this.scanner, true);
  8106. break;
  8107. default:
  8108. this.scanner.error('Number or identifier is expected');
  8109. }
  8110. return {
  8111. type: 'HexColor',
  8112. loc: this.getLocation(start, this.scanner.tokenStart),
  8113. value: this.scanner.substrToCursor(start + 1) // skip #
  8114. };
  8115. },
  8116. generate: function(processChunk, node) {
  8117. processChunk('#');
  8118. processChunk(node.value);
  8119. }
  8120. };
  8121. var HexColor_1 = HexColor.name;
  8122. var HexColor_2 = HexColor.structure;
  8123. var HexColor_3 = HexColor.parse;
  8124. var HexColor_4 = HexColor.generate;
  8125. var HexColor$1 = /*#__PURE__*/Object.freeze({
  8126. default: HexColor,
  8127. __moduleExports: HexColor,
  8128. name: HexColor_1,
  8129. structure: HexColor_2,
  8130. parse: HexColor_3,
  8131. generate: HexColor_4
  8132. });
  8133. var TYPE$23 = require$$0$1.TYPE;
  8134. var IDENTIFIER$12 = TYPE$23.Identifier;
  8135. var Identifier = {
  8136. name: 'Identifier',
  8137. structure: {
  8138. name: String
  8139. },
  8140. parse: function() {
  8141. return {
  8142. type: 'Identifier',
  8143. loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  8144. name: this.scanner.consume(IDENTIFIER$12)
  8145. };
  8146. },
  8147. generate: function(processChunk, node) {
  8148. processChunk(node.name);
  8149. }
  8150. };
  8151. var Identifier_1 = Identifier.name;
  8152. var Identifier_2 = Identifier.structure;
  8153. var Identifier_3 = Identifier.parse;
  8154. var Identifier_4 = Identifier.generate;
  8155. var Identifier$1 = /*#__PURE__*/Object.freeze({
  8156. default: Identifier,
  8157. __moduleExports: Identifier,
  8158. name: Identifier_1,
  8159. structure: Identifier_2,
  8160. parse: Identifier_3,
  8161. generate: Identifier_4
  8162. });
  8163. var TYPE$24 = require$$0$1.TYPE;
  8164. var IDENTIFIER$13 = TYPE$24.Identifier;
  8165. var NUMBERSIGN$4 = TYPE$24.NumberSign;
  8166. // '#' ident
  8167. var IdSelector = {
  8168. name: 'IdSelector',
  8169. structure: {
  8170. name: String
  8171. },
  8172. parse: function() {
  8173. this.scanner.eat(NUMBERSIGN$4);
  8174. return {
  8175. type: 'IdSelector',
  8176. loc: this.getLocation(this.scanner.tokenStart - 1, this.scanner.tokenEnd),
  8177. name: this.scanner.consume(IDENTIFIER$13)
  8178. };
  8179. },
  8180. generate: function(processChunk, node) {
  8181. processChunk('#');
  8182. processChunk(node.name);
  8183. }
  8184. };
  8185. var IdSelector_1 = IdSelector.name;
  8186. var IdSelector_2 = IdSelector.structure;
  8187. var IdSelector_3 = IdSelector.parse;
  8188. var IdSelector_4 = IdSelector.generate;
  8189. var IdSelector$1 = /*#__PURE__*/Object.freeze({
  8190. default: IdSelector,
  8191. __moduleExports: IdSelector,
  8192. name: IdSelector_1,
  8193. structure: IdSelector_2,
  8194. parse: IdSelector_3,
  8195. generate: IdSelector_4
  8196. });
  8197. var TYPE$25 = require$$0$1.TYPE;
  8198. var IDENTIFIER$14 = TYPE$25.Identifier;
  8199. var NUMBER$7 = TYPE$25.Number;
  8200. var LEFTPARENTHESIS$4 = TYPE$25.LeftParenthesis;
  8201. var RIGHTPARENTHESIS$3 = TYPE$25.RightParenthesis;
  8202. var COLON$4 = TYPE$25.Colon;
  8203. var SOLIDUS$5 = TYPE$25.Solidus;
  8204. var MediaFeature = {
  8205. name: 'MediaFeature',
  8206. structure: {
  8207. name: String,
  8208. value: ['Identifier', 'Number', 'Dimension', 'Ratio', null]
  8209. },
  8210. parse: function() {
  8211. var start = this.scanner.tokenStart;
  8212. var name;
  8213. var value = null;
  8214. this.scanner.eat(LEFTPARENTHESIS$4);
  8215. this.scanner.skipSC();
  8216. name = this.scanner.consume(IDENTIFIER$14);
  8217. this.scanner.skipSC();
  8218. if (this.scanner.tokenType !== RIGHTPARENTHESIS$3) {
  8219. this.scanner.eat(COLON$4);
  8220. this.scanner.skipSC();
  8221. switch (this.scanner.tokenType) {
  8222. case NUMBER$7:
  8223. if (this.scanner.lookupType(1) === IDENTIFIER$14) {
  8224. value = this.Dimension();
  8225. } else if (this.scanner.lookupNonWSType(1) === SOLIDUS$5) {
  8226. value = this.Ratio();
  8227. } else {
  8228. value = this.Number();
  8229. }
  8230. break;
  8231. case IDENTIFIER$14:
  8232. value = this.Identifier();
  8233. break;
  8234. default:
  8235. this.scanner.error('Number, dimension, ratio or identifier is expected');
  8236. }
  8237. this.scanner.skipSC();
  8238. }
  8239. this.scanner.eat(RIGHTPARENTHESIS$3);
  8240. return {
  8241. type: 'MediaFeature',
  8242. loc: this.getLocation(start, this.scanner.tokenStart),
  8243. name: name,
  8244. value: value
  8245. };
  8246. },
  8247. generate: function(processChunk, node) {
  8248. processChunk('(');
  8249. processChunk(node.name);
  8250. if (node.value !== null) {
  8251. processChunk(':');
  8252. this.generate(processChunk, node.value);
  8253. }
  8254. processChunk(')');
  8255. }
  8256. };
  8257. var MediaFeature_1 = MediaFeature.name;
  8258. var MediaFeature_2 = MediaFeature.structure;
  8259. var MediaFeature_3 = MediaFeature.parse;
  8260. var MediaFeature_4 = MediaFeature.generate;
  8261. var MediaFeature$1 = /*#__PURE__*/Object.freeze({
  8262. default: MediaFeature,
  8263. __moduleExports: MediaFeature,
  8264. name: MediaFeature_1,
  8265. structure: MediaFeature_2,
  8266. parse: MediaFeature_3,
  8267. generate: MediaFeature_4
  8268. });
  8269. var TYPE$26 = require$$0$1.TYPE;
  8270. var WHITESPACE$6 = TYPE$26.WhiteSpace;
  8271. var COMMENT$6 = TYPE$26.Comment;
  8272. var IDENTIFIER$15 = TYPE$26.Identifier;
  8273. var LEFTPARENTHESIS$5 = TYPE$26.LeftParenthesis;
  8274. var MediaQuery = {
  8275. name: 'MediaQuery',
  8276. structure: {
  8277. children: [['Identifier', 'MediaFeature', 'WhiteSpace']]
  8278. },
  8279. parse: function() {
  8280. this.scanner.skipSC();
  8281. var children = new List$1();
  8282. var child = null;
  8283. var space = null;
  8284. scan:
  8285. while (!this.scanner.eof) {
  8286. switch (this.scanner.tokenType) {
  8287. case COMMENT$6:
  8288. this.scanner.next();
  8289. continue;
  8290. case WHITESPACE$6:
  8291. space = this.WhiteSpace();
  8292. continue;
  8293. case IDENTIFIER$15:
  8294. child = this.Identifier();
  8295. break;
  8296. case LEFTPARENTHESIS$5:
  8297. child = this.MediaFeature();
  8298. break;
  8299. default:
  8300. break scan;
  8301. }
  8302. if (space !== null) {
  8303. children.appendData(space);
  8304. space = null;
  8305. }
  8306. children.appendData(child);
  8307. }
  8308. if (child === null) {
  8309. this.scanner.error('Identifier or parenthesis is expected');
  8310. }
  8311. return {
  8312. type: 'MediaQuery',
  8313. loc: this.getLocationFromList(children),
  8314. children: children
  8315. };
  8316. },
  8317. generate: function(processChunk, node) {
  8318. this.each(processChunk, node);
  8319. }
  8320. };
  8321. var MediaQuery_1 = MediaQuery.name;
  8322. var MediaQuery_2 = MediaQuery.structure;
  8323. var MediaQuery_3 = MediaQuery.parse;
  8324. var MediaQuery_4 = MediaQuery.generate;
  8325. var MediaQuery$1 = /*#__PURE__*/Object.freeze({
  8326. default: MediaQuery,
  8327. __moduleExports: MediaQuery,
  8328. name: MediaQuery_1,
  8329. structure: MediaQuery_2,
  8330. parse: MediaQuery_3,
  8331. generate: MediaQuery_4
  8332. });
  8333. var COMMA$2 = require$$0$1.TYPE.Comma;
  8334. var MediaQueryList = {
  8335. name: 'MediaQueryList',
  8336. structure: {
  8337. children: [['MediaQuery']]
  8338. },
  8339. parse: function(relative) {
  8340. var children = new List$1();
  8341. this.scanner.skipSC();
  8342. while (!this.scanner.eof) {
  8343. children.appendData(this.MediaQuery(relative));
  8344. if (this.scanner.tokenType !== COMMA$2) {
  8345. break;
  8346. }
  8347. this.scanner.next();
  8348. }
  8349. return {
  8350. type: 'MediaQueryList',
  8351. loc: this.getLocationFromList(children),
  8352. children: children
  8353. };
  8354. },
  8355. generate: function(processChunk, node) {
  8356. this.eachComma(processChunk, node);
  8357. }
  8358. };
  8359. var MediaQueryList_1 = MediaQueryList.name;
  8360. var MediaQueryList_2 = MediaQueryList.structure;
  8361. var MediaQueryList_3 = MediaQueryList.parse;
  8362. var MediaQueryList_4 = MediaQueryList.generate;
  8363. var MediaQueryList$1 = /*#__PURE__*/Object.freeze({
  8364. default: MediaQueryList,
  8365. __moduleExports: MediaQueryList,
  8366. name: MediaQueryList_1,
  8367. structure: MediaQueryList_2,
  8368. parse: MediaQueryList_3,
  8369. generate: MediaQueryList_4
  8370. });
  8371. // https://drafts.csswg.org/css-syntax-3/#the-anb-type
  8372. var Nth = {
  8373. name: 'Nth',
  8374. structure: {
  8375. nth: ['AnPlusB', 'Identifier'],
  8376. selector: ['SelectorList', null]
  8377. },
  8378. parse: function(allowOfClause) {
  8379. this.scanner.skipSC();
  8380. var start = this.scanner.tokenStart;
  8381. var end = start;
  8382. var selector = null;
  8383. var query;
  8384. if (this.scanner.lookupValue(0, 'odd') || this.scanner.lookupValue(0, 'even')) {
  8385. query = this.Identifier();
  8386. } else {
  8387. query = this.AnPlusB();
  8388. }
  8389. this.scanner.skipSC();
  8390. if (allowOfClause && this.scanner.lookupValue(0, 'of')) {
  8391. this.scanner.next();
  8392. selector = this.SelectorList();
  8393. if (this.needPositions) {
  8394. end = selector.children.last().loc.end.offset;
  8395. }
  8396. } else {
  8397. if (this.needPositions) {
  8398. end = query.loc.end.offset;
  8399. }
  8400. }
  8401. return {
  8402. type: 'Nth',
  8403. loc: this.getLocation(start, end),
  8404. nth: query,
  8405. selector: selector
  8406. };
  8407. },
  8408. generate: function(processChunk, node) {
  8409. this.generate(processChunk, node.nth);
  8410. if (node.selector !== null) {
  8411. processChunk(' of ');
  8412. this.generate(processChunk, node.selector);
  8413. }
  8414. }
  8415. };
  8416. var Nth_1 = Nth.name;
  8417. var Nth_2 = Nth.structure;
  8418. var Nth_3 = Nth.parse;
  8419. var Nth_4 = Nth.generate;
  8420. var Nth$1 = /*#__PURE__*/Object.freeze({
  8421. default: Nth,
  8422. __moduleExports: Nth,
  8423. name: Nth_1,
  8424. structure: Nth_2,
  8425. parse: Nth_3,
  8426. generate: Nth_4
  8427. });
  8428. var NUMBER$8 = require$$0$1.TYPE.Number;
  8429. var _Number = {
  8430. name: 'Number',
  8431. structure: {
  8432. value: String
  8433. },
  8434. parse: function() {
  8435. return {
  8436. type: 'Number',
  8437. loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  8438. value: this.scanner.consume(NUMBER$8)
  8439. };
  8440. },
  8441. generate: function(processChunk, node) {
  8442. processChunk(node.value);
  8443. }
  8444. };
  8445. var _Number_1 = _Number.name;
  8446. var _Number_2 = _Number.structure;
  8447. var _Number_3 = _Number.parse;
  8448. var _Number_4 = _Number.generate;
  8449. var _Number$1 = /*#__PURE__*/Object.freeze({
  8450. default: _Number,
  8451. __moduleExports: _Number,
  8452. name: _Number_1,
  8453. structure: _Number_2,
  8454. parse: _Number_3,
  8455. generate: _Number_4
  8456. });
  8457. // '/' | '*' | ',' | ':' | '+' | '-'
  8458. var Operator = {
  8459. name: 'Operator',
  8460. structure: {
  8461. value: String
  8462. },
  8463. parse: function() {
  8464. var start = this.scanner.tokenStart;
  8465. this.scanner.next();
  8466. return {
  8467. type: 'Operator',
  8468. loc: this.getLocation(start, this.scanner.tokenStart),
  8469. value: this.scanner.substrToCursor(start)
  8470. };
  8471. },
  8472. generate: function(processChunk, node) {
  8473. processChunk(node.value);
  8474. }
  8475. };
  8476. var Operator_1 = Operator.name;
  8477. var Operator_2 = Operator.structure;
  8478. var Operator_3 = Operator.parse;
  8479. var Operator_4 = Operator.generate;
  8480. var Operator$1 = /*#__PURE__*/Object.freeze({
  8481. default: Operator,
  8482. __moduleExports: Operator,
  8483. name: Operator_1,
  8484. structure: Operator_2,
  8485. parse: Operator_3,
  8486. generate: Operator_4
  8487. });
  8488. var TYPE$27 = require$$0$1.TYPE;
  8489. var LEFTPARENTHESIS$6 = TYPE$27.LeftParenthesis;
  8490. var RIGHTPARENTHESIS$4 = TYPE$27.RightParenthesis;
  8491. var Parentheses = {
  8492. name: 'Parentheses',
  8493. structure: {
  8494. children: [[]]
  8495. },
  8496. parse: function(readSequence, recognizer) {
  8497. var start = this.scanner.tokenStart;
  8498. var children = null;
  8499. this.scanner.eat(LEFTPARENTHESIS$6);
  8500. children = readSequence.call(this, recognizer);
  8501. this.scanner.eat(RIGHTPARENTHESIS$4);
  8502. return {
  8503. type: 'Parentheses',
  8504. loc: this.getLocation(start, this.scanner.tokenStart),
  8505. children: children
  8506. };
  8507. },
  8508. generate: function(processChunk, node) {
  8509. processChunk('(');
  8510. this.each(processChunk, node);
  8511. processChunk(')');
  8512. }
  8513. };
  8514. var Parentheses_1 = Parentheses.name;
  8515. var Parentheses_2 = Parentheses.structure;
  8516. var Parentheses_3 = Parentheses.parse;
  8517. var Parentheses_4 = Parentheses.generate;
  8518. var Parentheses$1 = /*#__PURE__*/Object.freeze({
  8519. default: Parentheses,
  8520. __moduleExports: Parentheses,
  8521. name: Parentheses_1,
  8522. structure: Parentheses_2,
  8523. parse: Parentheses_3,
  8524. generate: Parentheses_4
  8525. });
  8526. var TYPE$28 = require$$0$1.TYPE;
  8527. var NUMBER$9 = TYPE$28.Number;
  8528. var PERCENTSIGN$1 = TYPE$28.PercentSign;
  8529. var Percentage = {
  8530. name: 'Percentage',
  8531. structure: {
  8532. value: String
  8533. },
  8534. parse: function() {
  8535. var start = this.scanner.tokenStart;
  8536. var number = this.scanner.consume(NUMBER$9);
  8537. this.scanner.eat(PERCENTSIGN$1);
  8538. return {
  8539. type: 'Percentage',
  8540. loc: this.getLocation(start, this.scanner.tokenStart),
  8541. value: number
  8542. };
  8543. },
  8544. generate: function(processChunk, node) {
  8545. processChunk(node.value);
  8546. processChunk('%');
  8547. }
  8548. };
  8549. var Percentage_1 = Percentage.name;
  8550. var Percentage_2 = Percentage.structure;
  8551. var Percentage_3 = Percentage.parse;
  8552. var Percentage_4 = Percentage.generate;
  8553. var Percentage$1 = /*#__PURE__*/Object.freeze({
  8554. default: Percentage,
  8555. __moduleExports: Percentage,
  8556. name: Percentage_1,
  8557. structure: Percentage_2,
  8558. parse: Percentage_3,
  8559. generate: Percentage_4
  8560. });
  8561. var TYPE$29 = require$$0$1.TYPE;
  8562. var IDENTIFIER$16 = TYPE$29.Identifier;
  8563. var FUNCTION$4 = TYPE$29.Function;
  8564. var COLON$5 = TYPE$29.Colon;
  8565. var RIGHTPARENTHESIS$5 = TYPE$29.RightParenthesis;
  8566. // : ident [ '(' .. ')' ]?
  8567. var PseudoClassSelector = {
  8568. name: 'PseudoClassSelector',
  8569. structure: {
  8570. name: String,
  8571. children: [['Raw'], null]
  8572. },
  8573. parse: function() {
  8574. var start = this.scanner.tokenStart;
  8575. var children = null;
  8576. var name;
  8577. var nameLowerCase;
  8578. this.scanner.eat(COLON$5);
  8579. if (this.scanner.tokenType === FUNCTION$4) {
  8580. name = this.scanner.consumeFunctionName();
  8581. nameLowerCase = name.toLowerCase();
  8582. if (this.pseudo.hasOwnProperty(nameLowerCase)) {
  8583. this.scanner.skipSC();
  8584. children = this.pseudo[nameLowerCase].call(this);
  8585. this.scanner.skipSC();
  8586. } else {
  8587. children = new List$1().appendData(
  8588. this.Raw(this.scanner.currentToken, 0, 0, false, false)
  8589. );
  8590. }
  8591. this.scanner.eat(RIGHTPARENTHESIS$5);
  8592. } else {
  8593. name = this.scanner.consume(IDENTIFIER$16);
  8594. }
  8595. return {
  8596. type: 'PseudoClassSelector',
  8597. loc: this.getLocation(start, this.scanner.tokenStart),
  8598. name: name,
  8599. children: children
  8600. };
  8601. },
  8602. generate: function(processChunk, node) {
  8603. processChunk(':');
  8604. processChunk(node.name);
  8605. if (node.children !== null) {
  8606. processChunk('(');
  8607. this.each(processChunk, node);
  8608. processChunk(')');
  8609. }
  8610. },
  8611. walkContext: 'function'
  8612. };
  8613. var PseudoClassSelector_1 = PseudoClassSelector.name;
  8614. var PseudoClassSelector_2 = PseudoClassSelector.structure;
  8615. var PseudoClassSelector_3 = PseudoClassSelector.parse;
  8616. var PseudoClassSelector_4 = PseudoClassSelector.generate;
  8617. var PseudoClassSelector_5 = PseudoClassSelector.walkContext;
  8618. var PseudoClassSelector$1 = /*#__PURE__*/Object.freeze({
  8619. default: PseudoClassSelector,
  8620. __moduleExports: PseudoClassSelector,
  8621. name: PseudoClassSelector_1,
  8622. structure: PseudoClassSelector_2,
  8623. parse: PseudoClassSelector_3,
  8624. generate: PseudoClassSelector_4,
  8625. walkContext: PseudoClassSelector_5
  8626. });
  8627. var TYPE$30 = require$$0$1.TYPE;
  8628. var IDENTIFIER$17 = TYPE$30.Identifier;
  8629. var FUNCTION$5 = TYPE$30.Function;
  8630. var COLON$6 = TYPE$30.Colon;
  8631. var RIGHTPARENTHESIS$6 = TYPE$30.RightParenthesis;
  8632. // :: ident [ '(' .. ')' ]?
  8633. var PseudoElementSelector = {
  8634. name: 'PseudoElementSelector',
  8635. structure: {
  8636. name: String,
  8637. children: [['Raw'], null]
  8638. },
  8639. parse: function() {
  8640. var start = this.scanner.tokenStart;
  8641. var children = null;
  8642. var name;
  8643. var nameLowerCase;
  8644. this.scanner.eat(COLON$6);
  8645. this.scanner.eat(COLON$6);
  8646. if (this.scanner.tokenType === FUNCTION$5) {
  8647. name = this.scanner.consumeFunctionName();
  8648. nameLowerCase = name.toLowerCase();
  8649. if (this.pseudo.hasOwnProperty(nameLowerCase)) {
  8650. this.scanner.skipSC();
  8651. children = this.pseudo[nameLowerCase].call(this);
  8652. this.scanner.skipSC();
  8653. } else {
  8654. children = new List$1().appendData(
  8655. this.Raw(this.scanner.currentToken, 0, 0, false, false)
  8656. );
  8657. }
  8658. this.scanner.eat(RIGHTPARENTHESIS$6);
  8659. } else {
  8660. name = this.scanner.consume(IDENTIFIER$17);
  8661. }
  8662. return {
  8663. type: 'PseudoElementSelector',
  8664. loc: this.getLocation(start, this.scanner.tokenStart),
  8665. name: name,
  8666. children: children
  8667. };
  8668. },
  8669. generate: function(processChunk, node) {
  8670. processChunk('::');
  8671. processChunk(node.name);
  8672. if (node.children !== null) {
  8673. processChunk('(');
  8674. this.each(processChunk, node);
  8675. processChunk(')');
  8676. }
  8677. },
  8678. walkContext: 'function'
  8679. };
  8680. var PseudoElementSelector_1 = PseudoElementSelector.name;
  8681. var PseudoElementSelector_2 = PseudoElementSelector.structure;
  8682. var PseudoElementSelector_3 = PseudoElementSelector.parse;
  8683. var PseudoElementSelector_4 = PseudoElementSelector.generate;
  8684. var PseudoElementSelector_5 = PseudoElementSelector.walkContext;
  8685. var PseudoElementSelector$1 = /*#__PURE__*/Object.freeze({
  8686. default: PseudoElementSelector,
  8687. __moduleExports: PseudoElementSelector,
  8688. name: PseudoElementSelector_1,
  8689. structure: PseudoElementSelector_2,
  8690. parse: PseudoElementSelector_3,
  8691. generate: PseudoElementSelector_4,
  8692. walkContext: PseudoElementSelector_5
  8693. });
  8694. var isNumber$3 = require$$0$1.isNumber;
  8695. var TYPE$31 = require$$0$1.TYPE;
  8696. var NUMBER$10 = TYPE$31.Number;
  8697. var SOLIDUS$6 = TYPE$31.Solidus;
  8698. var FULLSTOP$4 = TYPE$31.FullStop;
  8699. // Terms of <ratio> should to be a positive number (not zero or negative)
  8700. // (see https://drafts.csswg.org/mediaqueries-3/#values)
  8701. // However, -o-min-device-pixel-ratio takes fractional values as a ratio's term
  8702. // and this is using by various sites. Therefore we relax checking on parse
  8703. // to test a term is unsigned number without exponent part.
  8704. // Additional checks may to be applied on lexer validation.
  8705. function consumeNumber(scanner) {
  8706. var value = scanner.consumeNonWS(NUMBER$10);
  8707. for (var i = 0; i < value.length; i++) {
  8708. var code = value.charCodeAt(i);
  8709. if (!isNumber$3(code) && code !== FULLSTOP$4) {
  8710. scanner.error('Unsigned number is expected', scanner.tokenStart - value.length + i);
  8711. }
  8712. }
  8713. if (Number(value) === 0) {
  8714. scanner.error('Zero number is not allowed', scanner.tokenStart - value.length);
  8715. }
  8716. return value;
  8717. }
  8718. // <positive-integer> S* '/' S* <positive-integer>
  8719. var Ratio = {
  8720. name: 'Ratio',
  8721. structure: {
  8722. left: String,
  8723. right: String
  8724. },
  8725. parse: function() {
  8726. var start = this.scanner.tokenStart;
  8727. var left = consumeNumber(this.scanner);
  8728. var right;
  8729. this.scanner.eatNonWS(SOLIDUS$6);
  8730. right = consumeNumber(this.scanner);
  8731. return {
  8732. type: 'Ratio',
  8733. loc: this.getLocation(start, this.scanner.tokenStart),
  8734. left: left,
  8735. right: right
  8736. };
  8737. },
  8738. generate: function(processChunk, node) {
  8739. processChunk(node.left);
  8740. processChunk('/');
  8741. processChunk(node.right);
  8742. }
  8743. };
  8744. var Ratio_1 = Ratio.name;
  8745. var Ratio_2 = Ratio.structure;
  8746. var Ratio_3 = Ratio.parse;
  8747. var Ratio_4 = Ratio.generate;
  8748. var Ratio$1 = /*#__PURE__*/Object.freeze({
  8749. default: Ratio,
  8750. __moduleExports: Ratio,
  8751. name: Ratio_1,
  8752. structure: Ratio_2,
  8753. parse: Ratio_3,
  8754. generate: Ratio_4
  8755. });
  8756. var Raw = {
  8757. name: 'Raw',
  8758. structure: {
  8759. value: String
  8760. },
  8761. parse: function(startToken, endTokenType1, endTokenType2, includeTokenType2, excludeWhiteSpace) {
  8762. var startOffset = this.scanner.getTokenStart(startToken);
  8763. var endOffset;
  8764. this.scanner.skip(
  8765. this.scanner.getRawLength(
  8766. startToken,
  8767. endTokenType1,
  8768. endTokenType2,
  8769. includeTokenType2
  8770. )
  8771. );
  8772. if (excludeWhiteSpace && this.scanner.tokenStart > startOffset) {
  8773. endOffset = this.scanner.getOffsetExcludeWS();
  8774. } else {
  8775. endOffset = this.scanner.tokenStart;
  8776. }
  8777. return {
  8778. type: 'Raw',
  8779. loc: this.getLocation(startOffset, endOffset),
  8780. value: this.scanner.source.substring(startOffset, endOffset)
  8781. };
  8782. },
  8783. generate: function(processChunk, node) {
  8784. processChunk(node.value);
  8785. }
  8786. };
  8787. var Raw_1 = Raw.name;
  8788. var Raw_2 = Raw.structure;
  8789. var Raw_3 = Raw.parse;
  8790. var Raw_4 = Raw.generate;
  8791. var Raw$1 = /*#__PURE__*/Object.freeze({
  8792. default: Raw,
  8793. __moduleExports: Raw,
  8794. name: Raw_1,
  8795. structure: Raw_2,
  8796. parse: Raw_3,
  8797. generate: Raw_4
  8798. });
  8799. var TYPE$32 = require$$0$1.TYPE;
  8800. var LEFTCURLYBRACKET$5 = TYPE$32.LeftCurlyBracket;
  8801. function consumeRaw$4(startToken) {
  8802. return this.Raw(startToken, LEFTCURLYBRACKET$5, 0, false, true);
  8803. }
  8804. var Rule = {
  8805. name: 'Rule',
  8806. structure: {
  8807. selector: ['SelectorList', 'Raw'],
  8808. block: ['Block']
  8809. },
  8810. parse: function() {
  8811. var startToken = this.scanner.currentToken;
  8812. var startOffset = this.scanner.tokenStart;
  8813. var selector = this.parseSelector
  8814. ? this.tolerantParse(this.SelectorList, consumeRaw$4)
  8815. : consumeRaw$4.call(this, startToken);
  8816. var block = this.Block(this.Declaration);
  8817. return {
  8818. type: 'Rule',
  8819. loc: this.getLocation(startOffset, this.scanner.tokenStart),
  8820. selector: selector,
  8821. block: block
  8822. };
  8823. },
  8824. generate: function(processChunk, node) {
  8825. this.generate(processChunk, node.selector);
  8826. this.generate(processChunk, node.block);
  8827. },
  8828. walkContext: 'rule'
  8829. };
  8830. var Rule_1 = Rule.name;
  8831. var Rule_2 = Rule.structure;
  8832. var Rule_3 = Rule.parse;
  8833. var Rule_4 = Rule.generate;
  8834. var Rule_5 = Rule.walkContext;
  8835. var Rule$1 = /*#__PURE__*/Object.freeze({
  8836. default: Rule,
  8837. __moduleExports: Rule,
  8838. name: Rule_1,
  8839. structure: Rule_2,
  8840. parse: Rule_3,
  8841. generate: Rule_4,
  8842. walkContext: Rule_5
  8843. });
  8844. var Selector = {
  8845. name: 'Selector',
  8846. structure: {
  8847. children: [[
  8848. 'TypeSelector',
  8849. 'IdSelector',
  8850. 'ClassSelector',
  8851. 'AttributeSelector',
  8852. 'PseudoClassSelector',
  8853. 'PseudoElementSelector',
  8854. 'Combinator',
  8855. 'WhiteSpace'
  8856. ]]
  8857. },
  8858. parse: function() {
  8859. var children = this.readSequence(this.scope.Selector);
  8860. // nothing were consumed
  8861. if (children.isEmpty()) {
  8862. this.scanner.error('Selector is expected');
  8863. }
  8864. return {
  8865. type: 'Selector',
  8866. loc: this.getLocationFromList(children),
  8867. children: children
  8868. };
  8869. },
  8870. generate: function(processChunk, node) {
  8871. this.each(processChunk, node);
  8872. }
  8873. };
  8874. var Selector_1 = Selector.name;
  8875. var Selector_2 = Selector.structure;
  8876. var Selector_3 = Selector.parse;
  8877. var Selector_4 = Selector.generate;
  8878. var Selector$1 = /*#__PURE__*/Object.freeze({
  8879. default: Selector,
  8880. __moduleExports: Selector,
  8881. name: Selector_1,
  8882. structure: Selector_2,
  8883. parse: Selector_3,
  8884. generate: Selector_4
  8885. });
  8886. var TYPE$33 = require$$0$1.TYPE;
  8887. var COMMA$3 = TYPE$33.Comma;
  8888. var LEFTCURLYBRACKET$6 = TYPE$33.LeftCurlyBracket;
  8889. var SelectorList = {
  8890. name: 'SelectorList',
  8891. structure: {
  8892. children: [['Selector', 'Raw']]
  8893. },
  8894. parse: function() {
  8895. var children = new List$1();
  8896. while (!this.scanner.eof) {
  8897. children.appendData(this.parseSelector
  8898. ? this.Selector()
  8899. : this.Raw(this.scanner.currentToken, COMMA$3, LEFTCURLYBRACKET$6, false, false)
  8900. );
  8901. if (this.scanner.tokenType === COMMA$3) {
  8902. this.scanner.next();
  8903. continue;
  8904. }
  8905. break;
  8906. }
  8907. return {
  8908. type: 'SelectorList',
  8909. loc: this.getLocationFromList(children),
  8910. children: children
  8911. };
  8912. },
  8913. generate: function(processChunk, node) {
  8914. this.eachComma(processChunk, node);
  8915. },
  8916. walkContext: 'selector'
  8917. };
  8918. var SelectorList_1 = SelectorList.name;
  8919. var SelectorList_2 = SelectorList.structure;
  8920. var SelectorList_3 = SelectorList.parse;
  8921. var SelectorList_4 = SelectorList.generate;
  8922. var SelectorList_5 = SelectorList.walkContext;
  8923. var SelectorList$1 = /*#__PURE__*/Object.freeze({
  8924. default: SelectorList,
  8925. __moduleExports: SelectorList,
  8926. name: SelectorList_1,
  8927. structure: SelectorList_2,
  8928. parse: SelectorList_3,
  8929. generate: SelectorList_4,
  8930. walkContext: SelectorList_5
  8931. });
  8932. var STRING$5 = require$$0$1.TYPE.String;
  8933. var _String = {
  8934. name: 'String',
  8935. structure: {
  8936. value: String
  8937. },
  8938. parse: function() {
  8939. return {
  8940. type: 'String',
  8941. loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  8942. value: this.scanner.consume(STRING$5)
  8943. };
  8944. },
  8945. generate: function(processChunk, node) {
  8946. processChunk(node.value);
  8947. }
  8948. };
  8949. var _String_1 = _String.name;
  8950. var _String_2 = _String.structure;
  8951. var _String_3 = _String.parse;
  8952. var _String_4 = _String.generate;
  8953. var _String$1 = /*#__PURE__*/Object.freeze({
  8954. default: _String,
  8955. __moduleExports: _String,
  8956. name: _String_1,
  8957. structure: _String_2,
  8958. parse: _String_3,
  8959. generate: _String_4
  8960. });
  8961. var TYPE$34 = require$$0$1.TYPE;
  8962. var WHITESPACE$7 = TYPE$34.WhiteSpace;
  8963. var COMMENT$7 = TYPE$34.Comment;
  8964. var EXCLAMATIONMARK$3 = TYPE$34.ExclamationMark;
  8965. var ATRULE$4 = TYPE$34.Atrule;
  8966. var CDO$4 = TYPE$34.CDO;
  8967. var CDC$4 = TYPE$34.CDC;
  8968. function consumeRaw$5(startToken) {
  8969. return this.Raw(startToken, 0, 0, false, false);
  8970. }
  8971. var StyleSheet = {
  8972. name: 'StyleSheet',
  8973. structure: {
  8974. children: [['Comment', 'Atrule', 'Rule', 'Raw']]
  8975. },
  8976. parse: function() {
  8977. var start = this.scanner.tokenStart;
  8978. var children = new List$1();
  8979. var child;
  8980. scan:
  8981. while (!this.scanner.eof) {
  8982. switch (this.scanner.tokenType) {
  8983. case WHITESPACE$7:
  8984. this.scanner.next();
  8985. continue;
  8986. case COMMENT$7:
  8987. // ignore comments except exclamation comments (i.e. /*! .. */) on top level
  8988. if (this.scanner.source.charCodeAt(this.scanner.tokenStart + 2) !== EXCLAMATIONMARK$3) {
  8989. this.scanner.next();
  8990. continue;
  8991. }
  8992. child = this.Comment();
  8993. break;
  8994. case CDO$4: // <!--
  8995. child = this.CDO();
  8996. break;
  8997. case CDC$4: // -->
  8998. child = this.CDC();
  8999. break;
  9000. // CSS Syntax Module Level 3
  9001. // §2.2 Error handling
  9002. // At the "top level" of a stylesheet, an <at-keyword-token> starts an at-rule.
  9003. case ATRULE$4:
  9004. child = this.Atrule();
  9005. break;
  9006. // Anything else starts a qualified rule ...
  9007. default:
  9008. child = this.tolerantParse(this.Rule, consumeRaw$5);
  9009. }
  9010. children.appendData(child);
  9011. }
  9012. return {
  9013. type: 'StyleSheet',
  9014. loc: this.getLocation(start, this.scanner.tokenStart),
  9015. children: children
  9016. };
  9017. },
  9018. generate: function(processChunk, node) {
  9019. this.each(processChunk, node);
  9020. },
  9021. walkContext: 'stylesheet'
  9022. };
  9023. var StyleSheet_1 = StyleSheet.name;
  9024. var StyleSheet_2 = StyleSheet.structure;
  9025. var StyleSheet_3 = StyleSheet.parse;
  9026. var StyleSheet_4 = StyleSheet.generate;
  9027. var StyleSheet_5 = StyleSheet.walkContext;
  9028. var StyleSheet$1 = /*#__PURE__*/Object.freeze({
  9029. default: StyleSheet,
  9030. __moduleExports: StyleSheet,
  9031. name: StyleSheet_1,
  9032. structure: StyleSheet_2,
  9033. parse: StyleSheet_3,
  9034. generate: StyleSheet_4,
  9035. walkContext: StyleSheet_5
  9036. });
  9037. var TYPE$35 = require$$0$1.TYPE;
  9038. var IDENTIFIER$18 = TYPE$35.Identifier;
  9039. var ASTERISK$5 = TYPE$35.Asterisk;
  9040. var VERTICALLINE$2 = TYPE$35.VerticalLine;
  9041. function eatIdentifierOrAsterisk() {
  9042. if (this.scanner.tokenType !== IDENTIFIER$18 &&
  9043. this.scanner.tokenType !== ASTERISK$5) {
  9044. this.scanner.error('Identifier or asterisk is expected');
  9045. }
  9046. this.scanner.next();
  9047. }
  9048. // ident
  9049. // ident|ident
  9050. // ident|*
  9051. // *
  9052. // *|ident
  9053. // *|*
  9054. // |ident
  9055. // |*
  9056. var TypeSelector = {
  9057. name: 'TypeSelector',
  9058. structure: {
  9059. name: String
  9060. },
  9061. parse: function() {
  9062. var start = this.scanner.tokenStart;
  9063. if (this.scanner.tokenType === VERTICALLINE$2) {
  9064. this.scanner.next();
  9065. eatIdentifierOrAsterisk.call(this);
  9066. } else {
  9067. eatIdentifierOrAsterisk.call(this);
  9068. if (this.scanner.tokenType === VERTICALLINE$2) {
  9069. this.scanner.next();
  9070. eatIdentifierOrAsterisk.call(this);
  9071. }
  9072. }
  9073. return {
  9074. type: 'TypeSelector',
  9075. loc: this.getLocation(start, this.scanner.tokenStart),
  9076. name: this.scanner.substrToCursor(start)
  9077. };
  9078. },
  9079. generate: function(processChunk, node) {
  9080. processChunk(node.name);
  9081. }
  9082. };
  9083. var TypeSelector_1 = TypeSelector.name;
  9084. var TypeSelector_2 = TypeSelector.structure;
  9085. var TypeSelector_3 = TypeSelector.parse;
  9086. var TypeSelector_4 = TypeSelector.generate;
  9087. var TypeSelector$1 = /*#__PURE__*/Object.freeze({
  9088. default: TypeSelector,
  9089. __moduleExports: TypeSelector,
  9090. name: TypeSelector_1,
  9091. structure: TypeSelector_2,
  9092. parse: TypeSelector_3,
  9093. generate: TypeSelector_4
  9094. });
  9095. var isHex$2 = require$$0$1.isHex;
  9096. var TYPE$36 = require$$0$1.TYPE;
  9097. var IDENTIFIER$19 = TYPE$36.Identifier;
  9098. var NUMBER$11 = TYPE$36.Number;
  9099. var PLUSSIGN$7 = TYPE$36.PlusSign;
  9100. var HYPHENMINUS$7 = TYPE$36.HyphenMinus;
  9101. var FULLSTOP$5 = TYPE$36.FullStop;
  9102. var QUESTIONMARK = TYPE$36.QuestionMark;
  9103. function scanUnicodeNumber(scanner) {
  9104. for (var pos = scanner.tokenStart + 1; pos < scanner.tokenEnd; pos++) {
  9105. var code = scanner.source.charCodeAt(pos);
  9106. // break on fullstop or hyperminus/plussign after exponent
  9107. if (code === FULLSTOP$5 || code === PLUSSIGN$7) {
  9108. // break token, exclude symbol
  9109. scanner.tokenStart = pos;
  9110. return false;
  9111. }
  9112. }
  9113. return true;
  9114. }
  9115. // https://drafts.csswg.org/css-syntax-3/#urange
  9116. function scanUnicodeRange(scanner) {
  9117. var hexStart = scanner.tokenStart + 1; // skip +
  9118. var hexLength = 0;
  9119. scan: {
  9120. if (scanner.tokenType === NUMBER$11) {
  9121. if (scanner.source.charCodeAt(scanner.tokenStart) !== FULLSTOP$5 && scanUnicodeNumber(scanner)) {
  9122. scanner.next();
  9123. } else if (scanner.source.charCodeAt(scanner.tokenStart) !== HYPHENMINUS$7) {
  9124. break scan;
  9125. }
  9126. } else {
  9127. scanner.next(); // PLUSSIGN
  9128. }
  9129. if (scanner.tokenType === HYPHENMINUS$7) {
  9130. scanner.next();
  9131. }
  9132. if (scanner.tokenType === NUMBER$11) {
  9133. scanner.next();
  9134. }
  9135. if (scanner.tokenType === IDENTIFIER$19) {
  9136. scanner.next();
  9137. }
  9138. if (scanner.tokenStart === hexStart) {
  9139. scanner.error('Unexpected input', hexStart);
  9140. }
  9141. }
  9142. // validate for U+x{1,6} or U+x{1,6}-x{1,6}
  9143. // where x is [0-9a-fA-F]
  9144. for (var i = hexStart, wasHyphenMinus = false; i < scanner.tokenStart; i++) {
  9145. var code = scanner.source.charCodeAt(i);
  9146. if (isHex$2(code) === false && (code !== HYPHENMINUS$7 || wasHyphenMinus)) {
  9147. scanner.error('Unexpected input', i);
  9148. }
  9149. if (code === HYPHENMINUS$7) {
  9150. // hex sequence shouldn't be an empty
  9151. if (hexLength === 0) {
  9152. scanner.error('Unexpected input', i);
  9153. }
  9154. wasHyphenMinus = true;
  9155. hexLength = 0;
  9156. } else {
  9157. hexLength++;
  9158. // too long hex sequence
  9159. if (hexLength > 6) {
  9160. scanner.error('Too long hex sequence', i);
  9161. }
  9162. }
  9163. }
  9164. // check we have a non-zero sequence
  9165. if (hexLength === 0) {
  9166. scanner.error('Unexpected input', i - 1);
  9167. }
  9168. // U+abc???
  9169. if (!wasHyphenMinus) {
  9170. // consume as many U+003F QUESTION MARK (?) code points as possible
  9171. for (; hexLength < 6 && !scanner.eof; scanner.next()) {
  9172. if (scanner.tokenType !== QUESTIONMARK) {
  9173. break;
  9174. }
  9175. hexLength++;
  9176. }
  9177. }
  9178. }
  9179. var UnicodeRange = {
  9180. name: 'UnicodeRange',
  9181. structure: {
  9182. value: String
  9183. },
  9184. parse: function() {
  9185. var start = this.scanner.tokenStart;
  9186. this.scanner.next(); // U or u
  9187. scanUnicodeRange(this.scanner);
  9188. return {
  9189. type: 'UnicodeRange',
  9190. loc: this.getLocation(start, this.scanner.tokenStart),
  9191. value: this.scanner.substrToCursor(start)
  9192. };
  9193. },
  9194. generate: function(processChunk, node) {
  9195. processChunk(node.value);
  9196. }
  9197. };
  9198. var UnicodeRange_1 = UnicodeRange.name;
  9199. var UnicodeRange_2 = UnicodeRange.structure;
  9200. var UnicodeRange_3 = UnicodeRange.parse;
  9201. var UnicodeRange_4 = UnicodeRange.generate;
  9202. var UnicodeRange$1 = /*#__PURE__*/Object.freeze({
  9203. default: UnicodeRange,
  9204. __moduleExports: UnicodeRange,
  9205. name: UnicodeRange_1,
  9206. structure: UnicodeRange_2,
  9207. parse: UnicodeRange_3,
  9208. generate: UnicodeRange_4
  9209. });
  9210. var TYPE$37 = require$$0$1.TYPE;
  9211. var STRING$6 = TYPE$37.String;
  9212. var URL$4 = TYPE$37.Url;
  9213. var RAW$2 = TYPE$37.Raw;
  9214. var RIGHTPARENTHESIS$7 = TYPE$37.RightParenthesis;
  9215. // url '(' S* (string | raw) S* ')'
  9216. var Url = {
  9217. name: 'Url',
  9218. structure: {
  9219. value: ['String', 'Raw']
  9220. },
  9221. parse: function() {
  9222. var start = this.scanner.tokenStart;
  9223. var value;
  9224. this.scanner.eat(URL$4);
  9225. this.scanner.skipSC();
  9226. switch (this.scanner.tokenType) {
  9227. case STRING$6:
  9228. value = this.String();
  9229. break;
  9230. case RAW$2:
  9231. value = this.Raw(this.scanner.currentToken, 0, RAW$2, true, false);
  9232. break;
  9233. default:
  9234. this.scanner.error('String or Raw is expected');
  9235. }
  9236. this.scanner.skipSC();
  9237. this.scanner.eat(RIGHTPARENTHESIS$7);
  9238. return {
  9239. type: 'Url',
  9240. loc: this.getLocation(start, this.scanner.tokenStart),
  9241. value: value
  9242. };
  9243. },
  9244. generate: function(processChunk, node) {
  9245. processChunk('url');
  9246. processChunk('(');
  9247. this.generate(processChunk, node.value);
  9248. processChunk(')');
  9249. }
  9250. };
  9251. var Url_1 = Url.name;
  9252. var Url_2 = Url.structure;
  9253. var Url_3 = Url.parse;
  9254. var Url_4 = Url.generate;
  9255. var Url$1 = /*#__PURE__*/Object.freeze({
  9256. default: Url,
  9257. __moduleExports: Url,
  9258. name: Url_1,
  9259. structure: Url_2,
  9260. parse: Url_3,
  9261. generate: Url_4
  9262. });
  9263. var endsWith$1 = require$$0$1.endsWith;
  9264. var TYPE$38 = require$$0$1.TYPE;
  9265. var WHITESPACE$8 = TYPE$38.WhiteSpace;
  9266. var COMMENT$8 = TYPE$38.Comment;
  9267. var FUNCTION$6 = TYPE$38.Function;
  9268. var COLON$7 = TYPE$38.Colon;
  9269. var SEMICOLON$6 = TYPE$38.Semicolon;
  9270. var EXCLAMATIONMARK$4 = TYPE$38.ExclamationMark;
  9271. // 'progid:' ws* 'DXImageTransform.Microsoft.' ident ws* '(' .* ')'
  9272. function checkProgid(scanner) {
  9273. var offset = 0;
  9274. for (var type; type = scanner.lookupType(offset); offset++) {
  9275. if (type !== WHITESPACE$8 && type !== COMMENT$8) {
  9276. break;
  9277. }
  9278. }
  9279. if (scanner.lookupValue(offset, 'alpha(') ||
  9280. scanner.lookupValue(offset, 'chroma(') ||
  9281. scanner.lookupValue(offset, 'dropshadow(')) {
  9282. if (scanner.lookupType(offset) !== FUNCTION$6) {
  9283. return false;
  9284. }
  9285. } else {
  9286. if (scanner.lookupValue(offset, 'progid') === false ||
  9287. scanner.lookupType(offset + 1) !== COLON$7) {
  9288. return false;
  9289. }
  9290. }
  9291. return true;
  9292. }
  9293. var Value = {
  9294. name: 'Value',
  9295. structure: {
  9296. children: [[]]
  9297. },
  9298. parse: function(property) {
  9299. // special parser for filter property since it can contains non-standart syntax for old IE
  9300. if (property !== null && endsWith$1(property, 'filter') && checkProgid(this.scanner)) {
  9301. this.scanner.skipSC();
  9302. return this.Raw(this.scanner.currentToken, EXCLAMATIONMARK$4, SEMICOLON$6, false, false);
  9303. }
  9304. var start = this.scanner.tokenStart;
  9305. var children = this.readSequence(this.scope.Value);
  9306. return {
  9307. type: 'Value',
  9308. loc: this.getLocation(start, this.scanner.tokenStart),
  9309. children: children
  9310. };
  9311. },
  9312. generate: function(processChunk, node) {
  9313. this.each(processChunk, node);
  9314. }
  9315. };
  9316. var Value_1 = Value.name;
  9317. var Value_2 = Value.structure;
  9318. var Value_3 = Value.parse;
  9319. var Value_4 = Value.generate;
  9320. var Value$1 = /*#__PURE__*/Object.freeze({
  9321. default: Value,
  9322. __moduleExports: Value,
  9323. name: Value_1,
  9324. structure: Value_2,
  9325. parse: Value_3,
  9326. generate: Value_4
  9327. });
  9328. var WHITESPACE$9 = require$$0$1.TYPE.WhiteSpace;
  9329. var SPACE$2 = Object.freeze({
  9330. type: 'WhiteSpace',
  9331. loc: null,
  9332. value: ' '
  9333. });
  9334. var WhiteSpace = {
  9335. name: 'WhiteSpace',
  9336. structure: {
  9337. value: String
  9338. },
  9339. parse: function() {
  9340. this.scanner.eat(WHITESPACE$9);
  9341. return SPACE$2;
  9342. // return {
  9343. // type: 'WhiteSpace',
  9344. // loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  9345. // value: this.scanner.consume(WHITESPACE)
  9346. // };
  9347. },
  9348. generate: function(processChunk, node) {
  9349. processChunk(node.value);
  9350. }
  9351. };
  9352. var WhiteSpace_1 = WhiteSpace.name;
  9353. var WhiteSpace_2 = WhiteSpace.structure;
  9354. var WhiteSpace_3 = WhiteSpace.parse;
  9355. var WhiteSpace_4 = WhiteSpace.generate;
  9356. var WhiteSpace$1 = /*#__PURE__*/Object.freeze({
  9357. default: WhiteSpace,
  9358. __moduleExports: WhiteSpace,
  9359. name: WhiteSpace_1,
  9360. structure: WhiteSpace_2,
  9361. parse: WhiteSpace_3,
  9362. generate: WhiteSpace_4
  9363. });
  9364. var require$$0$9 = ( AnPlusB$1 && AnPlusB ) || AnPlusB$1;
  9365. var require$$1$4 = ( Atrule$1 && Atrule ) || Atrule$1;
  9366. var require$$2$4 = ( AtruleExpression$1 && AtruleExpression ) || AtruleExpression$1;
  9367. var require$$3$3 = ( AttributeSelector$1 && AttributeSelector ) || AttributeSelector$1;
  9368. var require$$4$2 = ( Block$1 && Block ) || Block$1;
  9369. var require$$5$1 = ( Brackets$1 && Brackets ) || Brackets$1;
  9370. var require$$6$1 = ( CDC$3 && CDC_1 ) || CDC$3;
  9371. var require$$7$1 = ( CDO$3 && CDO_1 ) || CDO$3;
  9372. var require$$8$1 = ( ClassSelector$1 && ClassSelector ) || ClassSelector$1;
  9373. var require$$9$1 = ( Combinator$1 && Combinator ) || Combinator$1;
  9374. var require$$10 = ( Comment$1 && Comment ) || Comment$1;
  9375. var require$$11 = ( Declaration$1 && Declaration ) || Declaration$1;
  9376. var require$$12 = ( DeclarationList$1 && DeclarationList ) || DeclarationList$1;
  9377. var require$$13 = ( Dimension$1 && Dimension ) || Dimension$1;
  9378. var require$$14 = ( _Function$1 && _Function ) || _Function$1;
  9379. var require$$15 = ( HexColor$1 && HexColor ) || HexColor$1;
  9380. var require$$16 = ( Identifier$1 && Identifier ) || Identifier$1;
  9381. var require$$17 = ( IdSelector$1 && IdSelector ) || IdSelector$1;
  9382. var require$$18 = ( MediaFeature$1 && MediaFeature ) || MediaFeature$1;
  9383. var require$$19 = ( MediaQuery$1 && MediaQuery ) || MediaQuery$1;
  9384. var require$$20 = ( MediaQueryList$1 && MediaQueryList ) || MediaQueryList$1;
  9385. var require$$21 = ( Nth$1 && Nth ) || Nth$1;
  9386. var require$$22 = ( _Number$1 && _Number ) || _Number$1;
  9387. var require$$23 = ( Operator$1 && Operator ) || Operator$1;
  9388. var require$$24 = ( Parentheses$1 && Parentheses ) || Parentheses$1;
  9389. var require$$25 = ( Percentage$1 && Percentage ) || Percentage$1;
  9390. var require$$26 = ( PseudoClassSelector$1 && PseudoClassSelector ) || PseudoClassSelector$1;
  9391. var require$$27 = ( PseudoElementSelector$1 && PseudoElementSelector ) || PseudoElementSelector$1;
  9392. var require$$28 = ( Ratio$1 && Ratio ) || Ratio$1;
  9393. var require$$29 = ( Raw$1 && Raw ) || Raw$1;
  9394. var require$$30 = ( Rule$1 && Rule ) || Rule$1;
  9395. var require$$31 = ( Selector$1 && Selector ) || Selector$1;
  9396. var require$$32 = ( SelectorList$1 && SelectorList ) || SelectorList$1;
  9397. var require$$33 = ( _String$1 && _String ) || _String$1;
  9398. var require$$34 = ( StyleSheet$1 && StyleSheet ) || StyleSheet$1;
  9399. var require$$35 = ( TypeSelector$1 && TypeSelector ) || TypeSelector$1;
  9400. var require$$36 = ( UnicodeRange$1 && UnicodeRange ) || UnicodeRange$1;
  9401. var require$$37 = ( Url$1 && Url ) || Url$1;
  9402. var require$$38 = ( Value$1 && Value ) || Value$1;
  9403. var require$$39 = ( WhiteSpace$1 && WhiteSpace ) || WhiteSpace$1;
  9404. var node = {
  9405. AnPlusB: require$$0$9,
  9406. Atrule: require$$1$4,
  9407. AtruleExpression: require$$2$4,
  9408. AttributeSelector: require$$3$3,
  9409. Block: require$$4$2,
  9410. Brackets: require$$5$1,
  9411. CDC: require$$6$1,
  9412. CDO: require$$7$1,
  9413. ClassSelector: require$$8$1,
  9414. Combinator: require$$9$1,
  9415. Comment: require$$10,
  9416. Declaration: require$$11,
  9417. DeclarationList: require$$12,
  9418. Dimension: require$$13,
  9419. Function: require$$14,
  9420. HexColor: require$$15,
  9421. Identifier: require$$16,
  9422. IdSelector: require$$17,
  9423. MediaFeature: require$$18,
  9424. MediaQuery: require$$19,
  9425. MediaQueryList: require$$20,
  9426. Nth: require$$21,
  9427. Number: require$$22,
  9428. Operator: require$$23,
  9429. Parentheses: require$$24,
  9430. Percentage: require$$25,
  9431. PseudoClassSelector: require$$26,
  9432. PseudoElementSelector: require$$27,
  9433. Ratio: require$$28,
  9434. Raw: require$$29,
  9435. Rule: require$$30,
  9436. Selector: require$$31,
  9437. SelectorList: require$$32,
  9438. String: require$$33,
  9439. StyleSheet: require$$34,
  9440. TypeSelector: require$$35,
  9441. UnicodeRange: require$$36,
  9442. Url: require$$37,
  9443. Value: require$$38,
  9444. WhiteSpace: require$$39
  9445. };
  9446. var node_1 = node.AnPlusB;
  9447. var node_2 = node.Atrule;
  9448. var node_3 = node.AtruleExpression;
  9449. var node_4 = node.AttributeSelector;
  9450. var node_5 = node.Block;
  9451. var node_6 = node.Brackets;
  9452. var node_7 = node.CDC;
  9453. var node_8 = node.CDO;
  9454. var node_9 = node.ClassSelector;
  9455. var node_10 = node.Combinator;
  9456. var node_11 = node.Comment;
  9457. var node_12 = node.Declaration;
  9458. var node_13 = node.DeclarationList;
  9459. var node_14 = node.Dimension;
  9460. var node_15 = node.HexColor;
  9461. var node_16 = node.Identifier;
  9462. var node_17 = node.IdSelector;
  9463. var node_18 = node.MediaFeature;
  9464. var node_19 = node.MediaQuery;
  9465. var node_20 = node.MediaQueryList;
  9466. var node_21 = node.Nth;
  9467. var node_22 = node.Operator;
  9468. var node_23 = node.Parentheses;
  9469. var node_24 = node.Percentage;
  9470. var node_25 = node.PseudoClassSelector;
  9471. var node_26 = node.PseudoElementSelector;
  9472. var node_27 = node.Ratio;
  9473. var node_28 = node.Raw;
  9474. var node_29 = node.Rule;
  9475. var node_30 = node.Selector;
  9476. var node_31 = node.SelectorList;
  9477. var node_32 = node.StyleSheet;
  9478. var node_33 = node.TypeSelector;
  9479. var node_34 = node.UnicodeRange;
  9480. var node_35 = node.Url;
  9481. var node_36 = node.Value;
  9482. var node_37 = node.WhiteSpace;
  9483. var node$1 = /*#__PURE__*/Object.freeze({
  9484. default: node,
  9485. __moduleExports: node,
  9486. AnPlusB: node_1,
  9487. Atrule: node_2,
  9488. AtruleExpression: node_3,
  9489. AttributeSelector: node_4,
  9490. Block: node_5,
  9491. Brackets: node_6,
  9492. CDC: node_7,
  9493. CDO: node_8,
  9494. ClassSelector: node_9,
  9495. Combinator: node_10,
  9496. Comment: node_11,
  9497. Declaration: node_12,
  9498. DeclarationList: node_13,
  9499. Dimension: node_14,
  9500. HexColor: node_15,
  9501. Identifier: node_16,
  9502. IdSelector: node_17,
  9503. MediaFeature: node_18,
  9504. MediaQuery: node_19,
  9505. MediaQueryList: node_20,
  9506. Nth: node_21,
  9507. Operator: node_22,
  9508. Parentheses: node_23,
  9509. Percentage: node_24,
  9510. PseudoClassSelector: node_25,
  9511. PseudoElementSelector: node_26,
  9512. Ratio: node_27,
  9513. Raw: node_28,
  9514. Rule: node_29,
  9515. Selector: node_30,
  9516. SelectorList: node_31,
  9517. StyleSheet: node_32,
  9518. TypeSelector: node_33,
  9519. UnicodeRange: node_34,
  9520. Url: node_35,
  9521. Value: node_36,
  9522. WhiteSpace: node_37
  9523. });
  9524. var require$$0$10 = ( scope$1 && scope ) || scope$1;
  9525. var require$$1$5 = ( atrule$1 && atrule ) || atrule$1;
  9526. var require$$2$5 = ( pseudo$1 && pseudo ) || pseudo$1;
  9527. var require$$3$4 = ( node$1 && node ) || node$1;
  9528. var parser = {
  9529. parseContext: {
  9530. default: 'StyleSheet',
  9531. stylesheet: 'StyleSheet',
  9532. atrule: 'Atrule',
  9533. atruleExpression: function(options) {
  9534. return this.AtruleExpression(options.atrule ? String(options.atrule) : null);
  9535. },
  9536. mediaQueryList: 'MediaQueryList',
  9537. mediaQuery: 'MediaQuery',
  9538. rule: 'Rule',
  9539. selectorList: 'SelectorList',
  9540. selector: 'Selector',
  9541. block: function() {
  9542. return this.Block(this.Declaration);
  9543. },
  9544. declarationList: 'DeclarationList',
  9545. declaration: 'Declaration',
  9546. value: function(options) {
  9547. return this.Value(options.property ? String(options.property) : null);
  9548. }
  9549. },
  9550. scope: require$$0$10,
  9551. atrule: require$$1$5,
  9552. pseudo: require$$2$5,
  9553. node: require$$3$4
  9554. };
  9555. var parser_1 = parser.parseContext;
  9556. var parser_2 = parser.scope;
  9557. var parser_3 = parser.atrule;
  9558. var parser_4 = parser.pseudo;
  9559. var parser_5 = parser.node;
  9560. var parser$1 = /*#__PURE__*/Object.freeze({
  9561. default: parser,
  9562. __moduleExports: parser,
  9563. parseContext: parser_1,
  9564. scope: parser_2,
  9565. atrule: parser_3,
  9566. pseudo: parser_4,
  9567. node: parser_5
  9568. });
  9569. var createParser = ( create$1 && create ) || create$1;
  9570. var config = ( parser$1 && parser ) || parser$1;
  9571. var parser$2 = createParser(config);
  9572. function walk ( ast, ref) {
  9573. var enter = ref.enter;
  9574. var leave = ref.leave;
  9575. visit( ast, null, enter, leave );
  9576. }
  9577. var shouldSkip = false;
  9578. var context = { skip: function () { return shouldSkip = true; } };
  9579. var childKeys = {};
  9580. var toString$1 = Object.prototype.toString;
  9581. function isArray$1 ( thing ) {
  9582. return toString$1.call( thing ) === '[object Array]';
  9583. }
  9584. function visit ( node, parent, enter, leave, prop, index ) {
  9585. if ( !node ) { return; }
  9586. if ( enter ) {
  9587. var _shouldSkip = shouldSkip;
  9588. shouldSkip = false;
  9589. enter.call( context, node, parent, prop, index );
  9590. var skipped = shouldSkip;
  9591. shouldSkip = _shouldSkip;
  9592. if ( skipped ) { return; }
  9593. }
  9594. var keys = childKeys[ node.type ] || (
  9595. childKeys[ node.type ] = Object.keys( node ).filter( function (key) { return typeof node[ key ] === 'object'; } )
  9596. );
  9597. for ( var i = 0; i < keys.length; i += 1 ) {
  9598. var key = keys[i];
  9599. var value = node[ key ];
  9600. if ( isArray$1( value ) ) {
  9601. for ( var j = 0; j < value.length; j += 1 ) {
  9602. visit( value[j], node, enter, leave, key, j );
  9603. }
  9604. }
  9605. else if ( value && value.type ) {
  9606. visit( value, node, enter, leave, key, null );
  9607. }
  9608. }
  9609. if ( leave ) {
  9610. leave( node, parent, prop, index );
  9611. }
  9612. }
  9613. function readStyle(parser, start, attributes) {
  9614. const contentStart = parser.index;
  9615. const styles = parser.readUntil(/<\/style>/);
  9616. const contentEnd = parser.index;
  9617. let ast;
  9618. try {
  9619. ast = parser$2(styles, {
  9620. positions: true,
  9621. offset: contentStart,
  9622. });
  9623. }
  9624. catch (err) {
  9625. if (err.name === 'CssSyntaxError') {
  9626. parser.error({
  9627. code: `css-syntax-error`,
  9628. message: err.message
  9629. }, err.offset);
  9630. }
  9631. else {
  9632. throw err;
  9633. }
  9634. }
  9635. ast = JSON.parse(JSON.stringify(ast));
  9636. // tidy up AST
  9637. walk(ast, {
  9638. enter: (node) => {
  9639. // replace `ref:a` nodes
  9640. if (node.type === 'Selector') {
  9641. for (let i = 0; i < node.children.length; i += 1) {
  9642. const a = node.children[i];
  9643. const b = node.children[i + 1];
  9644. if (isRefSelector(a, b)) {
  9645. node.children.splice(i, 2, {
  9646. type: 'RefSelector',
  9647. start: a.loc.start.offset,
  9648. end: b.loc.end.offset,
  9649. name: b.name
  9650. });
  9651. }
  9652. }
  9653. }
  9654. if (node.loc) {
  9655. node.start = node.loc.start.offset;
  9656. node.end = node.loc.end.offset;
  9657. delete node.loc;
  9658. }
  9659. }
  9660. });
  9661. parser.eat('</style>', true);
  9662. const end = parser.index;
  9663. return {
  9664. start,
  9665. end,
  9666. attributes,
  9667. children: ast.children,
  9668. content: {
  9669. start: contentStart,
  9670. end: contentEnd,
  9671. styles,
  9672. },
  9673. };
  9674. }
  9675. function isRefSelector(a, b) {
  9676. if (!b)
  9677. return false;
  9678. return (a.type === 'TypeSelector' &&
  9679. a.name === 'ref' &&
  9680. b.type === 'PseudoClassSelector');
  9681. }
  9682. const DIRECTIVES = {
  9683. Ref: {
  9684. names: ['ref'],
  9685. attribute(start, end, type, name) {
  9686. return { start, end, type, name };
  9687. },
  9688. allowedExpressionTypes: [],
  9689. error: 'ref directives cannot have a value'
  9690. },
  9691. EventHandler: {
  9692. names: ['on'],
  9693. attribute(start, end, type, name, expression) {
  9694. return { start, end, type, name, expression };
  9695. },
  9696. allowedExpressionTypes: ['CallExpression'],
  9697. error: 'Expected a method call'
  9698. },
  9699. Binding: {
  9700. names: ['bind'],
  9701. attribute(start, end, type, name, expression) {
  9702. return {
  9703. start, end, type, name,
  9704. value: expression || {
  9705. type: 'Identifier',
  9706. start: start + 5,
  9707. end,
  9708. name,
  9709. }
  9710. };
  9711. },
  9712. allowedExpressionTypes: ['Identifier', 'MemberExpression'],
  9713. error: 'Can only bind to an identifier (e.g. `foo`) or a member expression (e.g. `foo.bar` or `foo[baz]`)'
  9714. },
  9715. Transition: {
  9716. names: ['in', 'out', 'transition'],
  9717. attribute(start, end, type, name, expression, directiveName) {
  9718. return {
  9719. start, end, type, name, expression,
  9720. intro: directiveName === 'in' || directiveName === 'transition',
  9721. outro: directiveName === 'out' || directiveName === 'transition',
  9722. };
  9723. },
  9724. allowedExpressionTypes: ['ObjectExpression'],
  9725. error: 'Transition argument must be an object literal, e.g. `{ duration: 400 }`'
  9726. },
  9727. Animation: {
  9728. names: ['animate'],
  9729. attribute(start, end, type, name, expression) {
  9730. return { start, end, type, name, expression };
  9731. },
  9732. allowedExpressionTypes: ['ObjectExpression'],
  9733. error: 'Animation argument must be an object literal, e.g. `{ duration: 400 }`'
  9734. },
  9735. Action: {
  9736. names: ['use'],
  9737. attribute(start, end, type, name, expression) {
  9738. return { start, end, type, name, expression };
  9739. },
  9740. allowedExpressionTypes: ['Identifier', 'MemberExpression', 'ObjectExpression', 'Literal', 'CallExpression'],
  9741. error: 'Data passed to actions must be an identifier (e.g. `foo`), a member expression ' +
  9742. '(e.g. `foo.bar` or `foo[baz]`), a method call (e.g. `foo()`), or a literal (e.g. `true` or `\'a string\'`'
  9743. },
  9744. };
  9745. const lookupByName = {};
  9746. Object.keys(DIRECTIVES).forEach(name => {
  9747. const directive = DIRECTIVES[name];
  9748. directive.names.forEach(type => lookupByName[type] = name);
  9749. });
  9750. function readExpression$1(parser, start, quoteMark) {
  9751. let str = '';
  9752. let escaped = false;
  9753. for (let i = start; i < parser.template.length; i += 1) {
  9754. const char = parser.template[i];
  9755. if (quoteMark) {
  9756. if (char === quoteMark) {
  9757. if (escaped) {
  9758. str += quoteMark;
  9759. }
  9760. else {
  9761. break;
  9762. }
  9763. }
  9764. else if (escaped) {
  9765. str += '\\' + char;
  9766. escaped = false;
  9767. }
  9768. else if (char === '\\') {
  9769. escaped = true;
  9770. }
  9771. else {
  9772. str += char;
  9773. }
  9774. }
  9775. else if (/[\s\/>]/.test(char)) {
  9776. break;
  9777. }
  9778. else {
  9779. str += char;
  9780. }
  9781. }
  9782. const expression = parseExpressionAt(repeat(' ', start) + str, start, {
  9783. ecmaVersion: 9,
  9784. });
  9785. parser.index = expression.end;
  9786. parser.allowWhitespace();
  9787. if (quoteMark)
  9788. parser.eat(quoteMark, true);
  9789. return expression;
  9790. }
  9791. function readDirective(parser, start, attrName) {
  9792. const [directiveName, name] = attrName.split(':');
  9793. if (name === undefined)
  9794. return; // No colon in the name
  9795. if (directiveName === '') {
  9796. // not a directive — :foo is short for foo={{foo}}
  9797. return {
  9798. start: start,
  9799. end: start + name.length + 1,
  9800. type: 'Attribute',
  9801. name,
  9802. value: getShorthandValue(start + 1, name)
  9803. };
  9804. }
  9805. const type = lookupByName[directiveName];
  9806. if (!type)
  9807. return; // not a registered directive
  9808. const directive = DIRECTIVES[type];
  9809. let expression = null;
  9810. if (parser.eat('=')) {
  9811. const quoteMark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null;
  9812. const expressionStart = parser.index;
  9813. try {
  9814. expression = readExpression$1(parser, expressionStart, quoteMark);
  9815. if (directive.allowedExpressionTypes.indexOf(expression.type) === -1) {
  9816. parser.error({
  9817. code: `invalid-directive-value`,
  9818. message: directive.error
  9819. }, expressionStart);
  9820. }
  9821. }
  9822. catch (err) {
  9823. if (parser.template[expressionStart] === '{') {
  9824. // assume the mistake was wrapping the directive arguments.
  9825. // this could yield false positives! but hopefully not too many
  9826. let message = 'directive values should not be wrapped';
  9827. const expressionEnd = parser.template.indexOf('}', expressionStart);
  9828. if (expressionEnd !== -1) {
  9829. const value = parser.template.slice(expressionStart + 1, expressionEnd);
  9830. message += ` — use '${value}', not '{${value}}'`;
  9831. }
  9832. parser.error({
  9833. code: `invalid-directive-value`,
  9834. message
  9835. }, expressionStart);
  9836. }
  9837. throw err;
  9838. }
  9839. }
  9840. return directive.attribute(start, parser.index, type, name, expression, directiveName);
  9841. }
  9842. function getShorthandValue(start, name) {
  9843. const end = start + name.length;
  9844. return [
  9845. {
  9846. type: 'AttributeShorthand',
  9847. start,
  9848. end,
  9849. expression: {
  9850. type: 'Identifier',
  9851. start,
  9852. end,
  9853. name,
  9854. },
  9855. },
  9856. ];
  9857. }
  9858. // https://dev.w3.org/html5/html-author/charref
  9859. var htmlEntities = {
  9860. CounterClockwiseContourIntegral: 8755,
  9861. ClockwiseContourIntegral: 8754,
  9862. DoubleLongLeftRightArrow: 10234,
  9863. DiacriticalDoubleAcute: 733,
  9864. NotSquareSupersetEqual: 8931,
  9865. CloseCurlyDoubleQuote: 8221,
  9866. DoubleContourIntegral: 8751,
  9867. FilledVerySmallSquare: 9642,
  9868. NegativeVeryThinSpace: 8203,
  9869. NotPrecedesSlantEqual: 8928,
  9870. NotRightTriangleEqual: 8941,
  9871. NotSucceedsSlantEqual: 8929,
  9872. CapitalDifferentialD: 8517,
  9873. DoubleLeftRightArrow: 8660,
  9874. DoubleLongRightArrow: 10233,
  9875. EmptyVerySmallSquare: 9643,
  9876. NestedGreaterGreater: 8811,
  9877. NotDoubleVerticalBar: 8742,
  9878. NotLeftTriangleEqual: 8940,
  9879. NotSquareSubsetEqual: 8930,
  9880. OpenCurlyDoubleQuote: 8220,
  9881. ReverseUpEquilibrium: 10607,
  9882. DoubleLongLeftArrow: 10232,
  9883. DownLeftRightVector: 10576,
  9884. LeftArrowRightArrow: 8646,
  9885. NegativeMediumSpace: 8203,
  9886. RightArrowLeftArrow: 8644,
  9887. SquareSupersetEqual: 8850,
  9888. leftrightsquigarrow: 8621,
  9889. DownRightTeeVector: 10591,
  9890. DownRightVectorBar: 10583,
  9891. LongLeftRightArrow: 10231,
  9892. Longleftrightarrow: 10234,
  9893. NegativeThickSpace: 8203,
  9894. PrecedesSlantEqual: 8828,
  9895. ReverseEquilibrium: 8651,
  9896. RightDoubleBracket: 10215,
  9897. RightDownTeeVector: 10589,
  9898. RightDownVectorBar: 10581,
  9899. RightTriangleEqual: 8885,
  9900. SquareIntersection: 8851,
  9901. SucceedsSlantEqual: 8829,
  9902. blacktriangleright: 9656,
  9903. longleftrightarrow: 10231,
  9904. DoubleUpDownArrow: 8661,
  9905. DoubleVerticalBar: 8741,
  9906. DownLeftTeeVector: 10590,
  9907. DownLeftVectorBar: 10582,
  9908. FilledSmallSquare: 9724,
  9909. GreaterSlantEqual: 10878,
  9910. LeftDoubleBracket: 10214,
  9911. LeftDownTeeVector: 10593,
  9912. LeftDownVectorBar: 10585,
  9913. LeftTriangleEqual: 8884,
  9914. NegativeThinSpace: 8203,
  9915. NotReverseElement: 8716,
  9916. NotTildeFullEqual: 8775,
  9917. RightAngleBracket: 10217,
  9918. RightUpDownVector: 10575,
  9919. SquareSubsetEqual: 8849,
  9920. VerticalSeparator: 10072,
  9921. blacktriangledown: 9662,
  9922. blacktriangleleft: 9666,
  9923. leftrightharpoons: 8651,
  9924. rightleftharpoons: 8652,
  9925. twoheadrightarrow: 8608,
  9926. DiacriticalAcute: 180,
  9927. DiacriticalGrave: 96,
  9928. DiacriticalTilde: 732,
  9929. DoubleRightArrow: 8658,
  9930. DownArrowUpArrow: 8693,
  9931. EmptySmallSquare: 9723,
  9932. GreaterEqualLess: 8923,
  9933. GreaterFullEqual: 8807,
  9934. LeftAngleBracket: 10216,
  9935. LeftUpDownVector: 10577,
  9936. LessEqualGreater: 8922,
  9937. NonBreakingSpace: 160,
  9938. NotRightTriangle: 8939,
  9939. NotSupersetEqual: 8841,
  9940. RightTriangleBar: 10704,
  9941. RightUpTeeVector: 10588,
  9942. RightUpVectorBar: 10580,
  9943. UnderParenthesis: 9181,
  9944. UpArrowDownArrow: 8645,
  9945. circlearrowright: 8635,
  9946. downharpoonright: 8642,
  9947. ntrianglerighteq: 8941,
  9948. rightharpoondown: 8641,
  9949. rightrightarrows: 8649,
  9950. twoheadleftarrow: 8606,
  9951. vartriangleright: 8883,
  9952. CloseCurlyQuote: 8217,
  9953. ContourIntegral: 8750,
  9954. DoubleDownArrow: 8659,
  9955. DoubleLeftArrow: 8656,
  9956. DownRightVector: 8641,
  9957. LeftRightVector: 10574,
  9958. LeftTriangleBar: 10703,
  9959. LeftUpTeeVector: 10592,
  9960. LeftUpVectorBar: 10584,
  9961. LowerRightArrow: 8600,
  9962. NotGreaterEqual: 8817,
  9963. NotGreaterTilde: 8821,
  9964. NotLeftTriangle: 8938,
  9965. OverParenthesis: 9180,
  9966. RightDownVector: 8642,
  9967. ShortRightArrow: 8594,
  9968. UpperRightArrow: 8599,
  9969. bigtriangledown: 9661,
  9970. circlearrowleft: 8634,
  9971. curvearrowright: 8631,
  9972. downharpoonleft: 8643,
  9973. leftharpoondown: 8637,
  9974. leftrightarrows: 8646,
  9975. nLeftrightarrow: 8654,
  9976. nleftrightarrow: 8622,
  9977. ntrianglelefteq: 8940,
  9978. rightleftarrows: 8644,
  9979. rightsquigarrow: 8605,
  9980. rightthreetimes: 8908,
  9981. straightepsilon: 1013,
  9982. trianglerighteq: 8885,
  9983. vartriangleleft: 8882,
  9984. DiacriticalDot: 729,
  9985. DoubleRightTee: 8872,
  9986. DownLeftVector: 8637,
  9987. GreaterGreater: 10914,
  9988. HorizontalLine: 9472,
  9989. InvisibleComma: 8291,
  9990. InvisibleTimes: 8290,
  9991. LeftDownVector: 8643,
  9992. LeftRightArrow: 8596,
  9993. Leftrightarrow: 8660,
  9994. LessSlantEqual: 10877,
  9995. LongRightArrow: 10230,
  9996. Longrightarrow: 10233,
  9997. LowerLeftArrow: 8601,
  9998. NestedLessLess: 8810,
  9999. NotGreaterLess: 8825,
  10000. NotLessGreater: 8824,
  10001. NotSubsetEqual: 8840,
  10002. NotVerticalBar: 8740,
  10003. OpenCurlyQuote: 8216,
  10004. ReverseElement: 8715,
  10005. RightTeeVector: 10587,
  10006. RightVectorBar: 10579,
  10007. ShortDownArrow: 8595,
  10008. ShortLeftArrow: 8592,
  10009. SquareSuperset: 8848,
  10010. TildeFullEqual: 8773,
  10011. UpperLeftArrow: 8598,
  10012. ZeroWidthSpace: 8203,
  10013. curvearrowleft: 8630,
  10014. doublebarwedge: 8966,
  10015. downdownarrows: 8650,
  10016. hookrightarrow: 8618,
  10017. leftleftarrows: 8647,
  10018. leftrightarrow: 8596,
  10019. leftthreetimes: 8907,
  10020. longrightarrow: 10230,
  10021. looparrowright: 8620,
  10022. nshortparallel: 8742,
  10023. ntriangleright: 8939,
  10024. rightarrowtail: 8611,
  10025. rightharpoonup: 8640,
  10026. trianglelefteq: 8884,
  10027. upharpoonright: 8638,
  10028. ApplyFunction: 8289,
  10029. DifferentialD: 8518,
  10030. DoubleLeftTee: 10980,
  10031. DoubleUpArrow: 8657,
  10032. LeftTeeVector: 10586,
  10033. LeftVectorBar: 10578,
  10034. LessFullEqual: 8806,
  10035. LongLeftArrow: 10229,
  10036. Longleftarrow: 10232,
  10037. NotTildeEqual: 8772,
  10038. NotTildeTilde: 8777,
  10039. Poincareplane: 8460,
  10040. PrecedesEqual: 10927,
  10041. PrecedesTilde: 8830,
  10042. RightArrowBar: 8677,
  10043. RightTeeArrow: 8614,
  10044. RightTriangle: 8883,
  10045. RightUpVector: 8638,
  10046. SucceedsEqual: 10928,
  10047. SucceedsTilde: 8831,
  10048. SupersetEqual: 8839,
  10049. UpEquilibrium: 10606,
  10050. VerticalTilde: 8768,
  10051. VeryThinSpace: 8202,
  10052. bigtriangleup: 9651,
  10053. blacktriangle: 9652,
  10054. divideontimes: 8903,
  10055. fallingdotseq: 8786,
  10056. hookleftarrow: 8617,
  10057. leftarrowtail: 8610,
  10058. leftharpoonup: 8636,
  10059. longleftarrow: 10229,
  10060. looparrowleft: 8619,
  10061. measuredangle: 8737,
  10062. ntriangleleft: 8938,
  10063. shortparallel: 8741,
  10064. smallsetminus: 8726,
  10065. triangleright: 9657,
  10066. upharpoonleft: 8639,
  10067. DownArrowBar: 10515,
  10068. DownTeeArrow: 8615,
  10069. ExponentialE: 8519,
  10070. GreaterEqual: 8805,
  10071. GreaterTilde: 8819,
  10072. HilbertSpace: 8459,
  10073. HumpDownHump: 8782,
  10074. Intersection: 8898,
  10075. LeftArrowBar: 8676,
  10076. LeftTeeArrow: 8612,
  10077. LeftTriangle: 8882,
  10078. LeftUpVector: 8639,
  10079. NotCongruent: 8802,
  10080. NotLessEqual: 8816,
  10081. NotLessTilde: 8820,
  10082. Proportional: 8733,
  10083. RightCeiling: 8969,
  10084. RoundImplies: 10608,
  10085. ShortUpArrow: 8593,
  10086. SquareSubset: 8847,
  10087. UnderBracket: 9141,
  10088. VerticalLine: 124,
  10089. blacklozenge: 10731,
  10090. exponentiale: 8519,
  10091. risingdotseq: 8787,
  10092. triangledown: 9663,
  10093. triangleleft: 9667,
  10094. CircleMinus: 8854,
  10095. CircleTimes: 8855,
  10096. Equilibrium: 8652,
  10097. GreaterLess: 8823,
  10098. LeftCeiling: 8968,
  10099. LessGreater: 8822,
  10100. MediumSpace: 8287,
  10101. NotPrecedes: 8832,
  10102. NotSucceeds: 8833,
  10103. OverBracket: 9140,
  10104. RightVector: 8640,
  10105. Rrightarrow: 8667,
  10106. RuleDelayed: 10740,
  10107. SmallCircle: 8728,
  10108. SquareUnion: 8852,
  10109. SubsetEqual: 8838,
  10110. UpDownArrow: 8597,
  10111. Updownarrow: 8661,
  10112. VerticalBar: 8739,
  10113. backepsilon: 1014,
  10114. blacksquare: 9642,
  10115. circledcirc: 8858,
  10116. circleddash: 8861,
  10117. curlyeqprec: 8926,
  10118. curlyeqsucc: 8927,
  10119. diamondsuit: 9830,
  10120. eqslantless: 10901,
  10121. expectation: 8496,
  10122. nRightarrow: 8655,
  10123. nrightarrow: 8603,
  10124. preccurlyeq: 8828,
  10125. precnapprox: 10937,
  10126. quaternions: 8461,
  10127. straightphi: 981,
  10128. succcurlyeq: 8829,
  10129. succnapprox: 10938,
  10130. thickapprox: 8776,
  10131. updownarrow: 8597,
  10132. Bernoullis: 8492,
  10133. CirclePlus: 8853,
  10134. EqualTilde: 8770,
  10135. Fouriertrf: 8497,
  10136. ImaginaryI: 8520,
  10137. Laplacetrf: 8466,
  10138. LeftVector: 8636,
  10139. Lleftarrow: 8666,
  10140. NotElement: 8713,
  10141. NotGreater: 8815,
  10142. Proportion: 8759,
  10143. RightArrow: 8594,
  10144. RightFloor: 8971,
  10145. Rightarrow: 8658,
  10146. TildeEqual: 8771,
  10147. TildeTilde: 8776,
  10148. UnderBrace: 9183,
  10149. UpArrowBar: 10514,
  10150. UpTeeArrow: 8613,
  10151. circledast: 8859,
  10152. complement: 8705,
  10153. curlywedge: 8911,
  10154. eqslantgtr: 10902,
  10155. gtreqqless: 10892,
  10156. lessapprox: 10885,
  10157. lesseqqgtr: 10891,
  10158. lmoustache: 9136,
  10159. longmapsto: 10236,
  10160. mapstodown: 8615,
  10161. mapstoleft: 8612,
  10162. nLeftarrow: 8653,
  10163. nleftarrow: 8602,
  10164. precapprox: 10935,
  10165. rightarrow: 8594,
  10166. rmoustache: 9137,
  10167. sqsubseteq: 8849,
  10168. sqsupseteq: 8850,
  10169. subsetneqq: 10955,
  10170. succapprox: 10936,
  10171. supsetneqq: 10956,
  10172. upuparrows: 8648,
  10173. varepsilon: 949,
  10174. varnothing: 8709,
  10175. Backslash: 8726,
  10176. CenterDot: 183,
  10177. CircleDot: 8857,
  10178. Congruent: 8801,
  10179. Coproduct: 8720,
  10180. DoubleDot: 168,
  10181. DownArrow: 8595,
  10182. DownBreve: 785,
  10183. Downarrow: 8659,
  10184. HumpEqual: 8783,
  10185. LeftArrow: 8592,
  10186. LeftFloor: 8970,
  10187. Leftarrow: 8656,
  10188. LessTilde: 8818,
  10189. Mellintrf: 8499,
  10190. MinusPlus: 8723,
  10191. NotCupCap: 8813,
  10192. NotExists: 8708,
  10193. OverBrace: 9182,
  10194. PlusMinus: 177,
  10195. Therefore: 8756,
  10196. ThinSpace: 8201,
  10197. TripleDot: 8411,
  10198. UnionPlus: 8846,
  10199. backprime: 8245,
  10200. backsimeq: 8909,
  10201. bigotimes: 10754,
  10202. centerdot: 183,
  10203. checkmark: 10003,
  10204. complexes: 8450,
  10205. dotsquare: 8865,
  10206. downarrow: 8595,
  10207. gtrapprox: 10886,
  10208. gtreqless: 8923,
  10209. heartsuit: 9829,
  10210. leftarrow: 8592,
  10211. lesseqgtr: 8922,
  10212. nparallel: 8742,
  10213. nshortmid: 8740,
  10214. nsubseteq: 8840,
  10215. nsupseteq: 8841,
  10216. pitchfork: 8916,
  10217. rationals: 8474,
  10218. spadesuit: 9824,
  10219. subseteqq: 10949,
  10220. subsetneq: 8842,
  10221. supseteqq: 10950,
  10222. supsetneq: 8843,
  10223. therefore: 8756,
  10224. triangleq: 8796,
  10225. varpropto: 8733,
  10226. DDotrahd: 10513,
  10227. DotEqual: 8784,
  10228. Integral: 8747,
  10229. LessLess: 10913,
  10230. NotEqual: 8800,
  10231. NotTilde: 8769,
  10232. PartialD: 8706,
  10233. Precedes: 8826,
  10234. RightTee: 8866,
  10235. Succeeds: 8827,
  10236. SuchThat: 8715,
  10237. Superset: 8835,
  10238. Uarrocir: 10569,
  10239. UnderBar: 818,
  10240. andslope: 10840,
  10241. angmsdaa: 10664,
  10242. angmsdab: 10665,
  10243. angmsdac: 10666,
  10244. angmsdad: 10667,
  10245. angmsdae: 10668,
  10246. angmsdaf: 10669,
  10247. angmsdag: 10670,
  10248. angmsdah: 10671,
  10249. angrtvbd: 10653,
  10250. approxeq: 8778,
  10251. awconint: 8755,
  10252. backcong: 8780,
  10253. barwedge: 8965,
  10254. bbrktbrk: 9142,
  10255. bigoplus: 10753,
  10256. bigsqcup: 10758,
  10257. biguplus: 10756,
  10258. bigwedge: 8896,
  10259. boxminus: 8863,
  10260. boxtimes: 8864,
  10261. capbrcup: 10825,
  10262. circledR: 174,
  10263. circledS: 9416,
  10264. cirfnint: 10768,
  10265. clubsuit: 9827,
  10266. cupbrcap: 10824,
  10267. curlyvee: 8910,
  10268. cwconint: 8754,
  10269. doteqdot: 8785,
  10270. dotminus: 8760,
  10271. drbkarow: 10512,
  10272. dzigrarr: 10239,
  10273. elinters: 9191,
  10274. emptyset: 8709,
  10275. eqvparsl: 10725,
  10276. fpartint: 10765,
  10277. geqslant: 10878,
  10278. gesdotol: 10884,
  10279. gnapprox: 10890,
  10280. hksearow: 10533,
  10281. hkswarow: 10534,
  10282. imagline: 8464,
  10283. imagpart: 8465,
  10284. infintie: 10717,
  10285. integers: 8484,
  10286. intercal: 8890,
  10287. intlarhk: 10775,
  10288. laemptyv: 10676,
  10289. ldrushar: 10571,
  10290. leqslant: 10877,
  10291. lesdotor: 10883,
  10292. llcorner: 8990,
  10293. lnapprox: 10889,
  10294. lrcorner: 8991,
  10295. lurdshar: 10570,
  10296. mapstoup: 8613,
  10297. multimap: 8888,
  10298. naturals: 8469,
  10299. otimesas: 10806,
  10300. parallel: 8741,
  10301. plusacir: 10787,
  10302. pointint: 10773,
  10303. precneqq: 10933,
  10304. precnsim: 8936,
  10305. profalar: 9006,
  10306. profline: 8978,
  10307. profsurf: 8979,
  10308. raemptyv: 10675,
  10309. realpart: 8476,
  10310. rppolint: 10770,
  10311. rtriltri: 10702,
  10312. scpolint: 10771,
  10313. setminus: 8726,
  10314. shortmid: 8739,
  10315. smeparsl: 10724,
  10316. sqsubset: 8847,
  10317. sqsupset: 8848,
  10318. subseteq: 8838,
  10319. succneqq: 10934,
  10320. succnsim: 8937,
  10321. supseteq: 8839,
  10322. thetasym: 977,
  10323. thicksim: 8764,
  10324. timesbar: 10801,
  10325. triangle: 9653,
  10326. triminus: 10810,
  10327. trpezium: 9186,
  10328. ulcorner: 8988,
  10329. urcorner: 8989,
  10330. varkappa: 1008,
  10331. varsigma: 962,
  10332. vartheta: 977,
  10333. Because: 8757,
  10334. Cayleys: 8493,
  10335. Cconint: 8752,
  10336. Cedilla: 184,
  10337. Diamond: 8900,
  10338. DownTee: 8868,
  10339. Element: 8712,
  10340. Epsilon: 917,
  10341. Implies: 8658,
  10342. LeftTee: 8867,
  10343. NewLine: 10,
  10344. NoBreak: 8288,
  10345. NotLess: 8814,
  10346. Omicron: 927,
  10347. OverBar: 175,
  10348. Product: 8719,
  10349. UpArrow: 8593,
  10350. Uparrow: 8657,
  10351. Upsilon: 933,
  10352. alefsym: 8501,
  10353. angrtvb: 8894,
  10354. angzarr: 9084,
  10355. asympeq: 8781,
  10356. backsim: 8765,
  10357. because: 8757,
  10358. bemptyv: 10672,
  10359. between: 8812,
  10360. bigcirc: 9711,
  10361. bigodot: 10752,
  10362. bigstar: 9733,
  10363. boxplus: 8862,
  10364. ccupssm: 10832,
  10365. cemptyv: 10674,
  10366. cirscir: 10690,
  10367. coloneq: 8788,
  10368. congdot: 10861,
  10369. cudarrl: 10552,
  10370. cudarrr: 10549,
  10371. cularrp: 10557,
  10372. curarrm: 10556,
  10373. dbkarow: 10511,
  10374. ddagger: 8225,
  10375. ddotseq: 10871,
  10376. demptyv: 10673,
  10377. diamond: 8900,
  10378. digamma: 989,
  10379. dotplus: 8724,
  10380. dwangle: 10662,
  10381. epsilon: 949,
  10382. eqcolon: 8789,
  10383. equivDD: 10872,
  10384. gesdoto: 10882,
  10385. gtquest: 10876,
  10386. gtrless: 8823,
  10387. harrcir: 10568,
  10388. intprod: 10812,
  10389. isindot: 8949,
  10390. larrbfs: 10527,
  10391. larrsim: 10611,
  10392. lbrksld: 10639,
  10393. lbrkslu: 10637,
  10394. ldrdhar: 10599,
  10395. lesdoto: 10881,
  10396. lessdot: 8918,
  10397. lessgtr: 8822,
  10398. lesssim: 8818,
  10399. lotimes: 10804,
  10400. lozenge: 9674,
  10401. ltquest: 10875,
  10402. luruhar: 10598,
  10403. maltese: 10016,
  10404. minusdu: 10794,
  10405. napprox: 8777,
  10406. natural: 9838,
  10407. nearrow: 8599,
  10408. nexists: 8708,
  10409. notinva: 8713,
  10410. notinvb: 8951,
  10411. notinvc: 8950,
  10412. notniva: 8716,
  10413. notnivb: 8958,
  10414. notnivc: 8957,
  10415. npolint: 10772,
  10416. nsqsube: 8930,
  10417. nsqsupe: 8931,
  10418. nvinfin: 10718,
  10419. nwarrow: 8598,
  10420. olcross: 10683,
  10421. omicron: 959,
  10422. orderof: 8500,
  10423. orslope: 10839,
  10424. pertenk: 8241,
  10425. planckh: 8462,
  10426. pluscir: 10786,
  10427. plussim: 10790,
  10428. plustwo: 10791,
  10429. precsim: 8830,
  10430. quatint: 10774,
  10431. questeq: 8799,
  10432. rarrbfs: 10528,
  10433. rarrsim: 10612,
  10434. rbrksld: 10638,
  10435. rbrkslu: 10640,
  10436. rdldhar: 10601,
  10437. realine: 8475,
  10438. rotimes: 10805,
  10439. ruluhar: 10600,
  10440. searrow: 8600,
  10441. simplus: 10788,
  10442. simrarr: 10610,
  10443. subedot: 10947,
  10444. submult: 10945,
  10445. subplus: 10943,
  10446. subrarr: 10617,
  10447. succsim: 8831,
  10448. supdsub: 10968,
  10449. supedot: 10948,
  10450. suphsub: 10967,
  10451. suplarr: 10619,
  10452. supmult: 10946,
  10453. supplus: 10944,
  10454. swarrow: 8601,
  10455. topfork: 10970,
  10456. triplus: 10809,
  10457. tritime: 10811,
  10458. uparrow: 8593,
  10459. upsilon: 965,
  10460. uwangle: 10663,
  10461. vzigzag: 10650,
  10462. zigrarr: 8669,
  10463. Aacute: 193,
  10464. Abreve: 258,
  10465. Agrave: 192,
  10466. Assign: 8788,
  10467. Atilde: 195,
  10468. Barwed: 8966,
  10469. Bumpeq: 8782,
  10470. Cacute: 262,
  10471. Ccaron: 268,
  10472. Ccedil: 199,
  10473. Colone: 10868,
  10474. Conint: 8751,
  10475. CupCap: 8781,
  10476. Dagger: 8225,
  10477. Dcaron: 270,
  10478. DotDot: 8412,
  10479. Dstrok: 272,
  10480. Eacute: 201,
  10481. Ecaron: 282,
  10482. Egrave: 200,
  10483. Exists: 8707,
  10484. ForAll: 8704,
  10485. Gammad: 988,
  10486. Gbreve: 286,
  10487. Gcedil: 290,
  10488. HARDcy: 1066,
  10489. Hstrok: 294,
  10490. Iacute: 205,
  10491. Igrave: 204,
  10492. Itilde: 296,
  10493. Jsercy: 1032,
  10494. Kcedil: 310,
  10495. Lacute: 313,
  10496. Lambda: 923,
  10497. Lcaron: 317,
  10498. Lcedil: 315,
  10499. Lmidot: 319,
  10500. Lstrok: 321,
  10501. Nacute: 323,
  10502. Ncaron: 327,
  10503. Ncedil: 325,
  10504. Ntilde: 209,
  10505. Oacute: 211,
  10506. Odblac: 336,
  10507. Ograve: 210,
  10508. Oslash: 216,
  10509. Otilde: 213,
  10510. Otimes: 10807,
  10511. Racute: 340,
  10512. Rarrtl: 10518,
  10513. Rcaron: 344,
  10514. Rcedil: 342,
  10515. SHCHcy: 1065,
  10516. SOFTcy: 1068,
  10517. Sacute: 346,
  10518. Scaron: 352,
  10519. Scedil: 350,
  10520. Square: 9633,
  10521. Subset: 8912,
  10522. Supset: 8913,
  10523. Tcaron: 356,
  10524. Tcedil: 354,
  10525. Tstrok: 358,
  10526. Uacute: 218,
  10527. Ubreve: 364,
  10528. Udblac: 368,
  10529. Ugrave: 217,
  10530. Utilde: 360,
  10531. Vdashl: 10982,
  10532. Verbar: 8214,
  10533. Vvdash: 8874,
  10534. Yacute: 221,
  10535. Zacute: 377,
  10536. Zcaron: 381,
  10537. aacute: 225,
  10538. abreve: 259,
  10539. agrave: 224,
  10540. andand: 10837,
  10541. angmsd: 8737,
  10542. angsph: 8738,
  10543. apacir: 10863,
  10544. approx: 8776,
  10545. atilde: 227,
  10546. barvee: 8893,
  10547. barwed: 8965,
  10548. becaus: 8757,
  10549. bernou: 8492,
  10550. bigcap: 8898,
  10551. bigcup: 8899,
  10552. bigvee: 8897,
  10553. bkarow: 10509,
  10554. bottom: 8869,
  10555. bowtie: 8904,
  10556. boxbox: 10697,
  10557. bprime: 8245,
  10558. brvbar: 166,
  10559. bullet: 8226,
  10560. bumpeq: 8783,
  10561. cacute: 263,
  10562. capand: 10820,
  10563. capcap: 10827,
  10564. capcup: 10823,
  10565. capdot: 10816,
  10566. ccaron: 269,
  10567. ccedil: 231,
  10568. circeq: 8791,
  10569. cirmid: 10991,
  10570. colone: 8788,
  10571. commat: 64,
  10572. compfn: 8728,
  10573. conint: 8750,
  10574. coprod: 8720,
  10575. copysr: 8471,
  10576. cularr: 8630,
  10577. cupcap: 10822,
  10578. cupcup: 10826,
  10579. cupdot: 8845,
  10580. curarr: 8631,
  10581. curren: 164,
  10582. cylcty: 9005,
  10583. dagger: 8224,
  10584. daleth: 8504,
  10585. dcaron: 271,
  10586. dfisht: 10623,
  10587. divide: 247,
  10588. divonx: 8903,
  10589. dlcorn: 8990,
  10590. dlcrop: 8973,
  10591. dollar: 36,
  10592. drcorn: 8991,
  10593. drcrop: 8972,
  10594. dstrok: 273,
  10595. eacute: 233,
  10596. easter: 10862,
  10597. ecaron: 283,
  10598. ecolon: 8789,
  10599. egrave: 232,
  10600. egsdot: 10904,
  10601. elsdot: 10903,
  10602. emptyv: 8709,
  10603. emsp13: 8196,
  10604. emsp14: 8197,
  10605. eparsl: 10723,
  10606. eqcirc: 8790,
  10607. equals: 61,
  10608. equest: 8799,
  10609. female: 9792,
  10610. ffilig: 64259,
  10611. ffllig: 64260,
  10612. forall: 8704,
  10613. frac12: 189,
  10614. frac13: 8531,
  10615. frac14: 188,
  10616. frac15: 8533,
  10617. frac16: 8537,
  10618. frac18: 8539,
  10619. frac23: 8532,
  10620. frac25: 8534,
  10621. frac34: 190,
  10622. frac35: 8535,
  10623. frac38: 8540,
  10624. frac45: 8536,
  10625. frac56: 8538,
  10626. frac58: 8541,
  10627. frac78: 8542,
  10628. gacute: 501,
  10629. gammad: 989,
  10630. gbreve: 287,
  10631. gesdot: 10880,
  10632. gesles: 10900,
  10633. gtlPar: 10645,
  10634. gtrarr: 10616,
  10635. gtrdot: 8919,
  10636. gtrsim: 8819,
  10637. hairsp: 8202,
  10638. hamilt: 8459,
  10639. hardcy: 1098,
  10640. hearts: 9829,
  10641. hellip: 8230,
  10642. hercon: 8889,
  10643. homtht: 8763,
  10644. horbar: 8213,
  10645. hslash: 8463,
  10646. hstrok: 295,
  10647. hybull: 8259,
  10648. hyphen: 8208,
  10649. iacute: 237,
  10650. igrave: 236,
  10651. iiiint: 10764,
  10652. iinfin: 10716,
  10653. incare: 8453,
  10654. inodot: 305,
  10655. intcal: 8890,
  10656. iquest: 191,
  10657. isinsv: 8947,
  10658. itilde: 297,
  10659. jsercy: 1112,
  10660. kappav: 1008,
  10661. kcedil: 311,
  10662. kgreen: 312,
  10663. lAtail: 10523,
  10664. lacute: 314,
  10665. lagran: 8466,
  10666. lambda: 955,
  10667. langle: 10216,
  10668. larrfs: 10525,
  10669. larrhk: 8617,
  10670. larrlp: 8619,
  10671. larrpl: 10553,
  10672. larrtl: 8610,
  10673. latail: 10521,
  10674. lbrace: 123,
  10675. lbrack: 91,
  10676. lcaron: 318,
  10677. lcedil: 316,
  10678. ldquor: 8222,
  10679. lesdot: 10879,
  10680. lesges: 10899,
  10681. lfisht: 10620,
  10682. lfloor: 8970,
  10683. lharul: 10602,
  10684. llhard: 10603,
  10685. lmidot: 320,
  10686. lmoust: 9136,
  10687. loplus: 10797,
  10688. lowast: 8727,
  10689. lowbar: 95,
  10690. lparlt: 10643,
  10691. lrhard: 10605,
  10692. lsaquo: 8249,
  10693. lsquor: 8218,
  10694. lstrok: 322,
  10695. lthree: 8907,
  10696. ltimes: 8905,
  10697. ltlarr: 10614,
  10698. ltrPar: 10646,
  10699. mapsto: 8614,
  10700. marker: 9646,
  10701. mcomma: 10793,
  10702. midast: 42,
  10703. midcir: 10992,
  10704. middot: 183,
  10705. minusb: 8863,
  10706. minusd: 8760,
  10707. mnplus: 8723,
  10708. models: 8871,
  10709. mstpos: 8766,
  10710. nVDash: 8879,
  10711. nVdash: 8878,
  10712. nacute: 324,
  10713. ncaron: 328,
  10714. ncedil: 326,
  10715. nearhk: 10532,
  10716. nequiv: 8802,
  10717. nesear: 10536,
  10718. nexist: 8708,
  10719. nltrie: 8940,
  10720. nprcue: 8928,
  10721. nrtrie: 8941,
  10722. nsccue: 8929,
  10723. nsimeq: 8772,
  10724. ntilde: 241,
  10725. numero: 8470,
  10726. nvDash: 8877,
  10727. nvHarr: 10500,
  10728. nvdash: 8876,
  10729. nvlArr: 10498,
  10730. nvrArr: 10499,
  10731. nwarhk: 10531,
  10732. nwnear: 10535,
  10733. oacute: 243,
  10734. odblac: 337,
  10735. odsold: 10684,
  10736. ograve: 242,
  10737. ominus: 8854,
  10738. origof: 8886,
  10739. oslash: 248,
  10740. otilde: 245,
  10741. otimes: 8855,
  10742. parsim: 10995,
  10743. percnt: 37,
  10744. period: 46,
  10745. permil: 8240,
  10746. phmmat: 8499,
  10747. planck: 8463,
  10748. plankv: 8463,
  10749. plusdo: 8724,
  10750. plusdu: 10789,
  10751. plusmn: 177,
  10752. preceq: 10927,
  10753. primes: 8473,
  10754. prnsim: 8936,
  10755. propto: 8733,
  10756. prurel: 8880,
  10757. puncsp: 8200,
  10758. qprime: 8279,
  10759. rAtail: 10524,
  10760. racute: 341,
  10761. rangle: 10217,
  10762. rarrap: 10613,
  10763. rarrfs: 10526,
  10764. rarrhk: 8618,
  10765. rarrlp: 8620,
  10766. rarrpl: 10565,
  10767. rarrtl: 8611,
  10768. ratail: 10522,
  10769. rbrace: 125,
  10770. rbrack: 93,
  10771. rcaron: 345,
  10772. rcedil: 343,
  10773. rdquor: 8221,
  10774. rfisht: 10621,
  10775. rfloor: 8971,
  10776. rharul: 10604,
  10777. rmoust: 9137,
  10778. roplus: 10798,
  10779. rpargt: 10644,
  10780. rsaquo: 8250,
  10781. rsquor: 8217,
  10782. rthree: 8908,
  10783. rtimes: 8906,
  10784. sacute: 347,
  10785. scaron: 353,
  10786. scedil: 351,
  10787. scnsim: 8937,
  10788. searhk: 10533,
  10789. seswar: 10537,
  10790. sfrown: 8994,
  10791. shchcy: 1097,
  10792. sigmaf: 962,
  10793. sigmav: 962,
  10794. simdot: 10858,
  10795. smashp: 10803,
  10796. softcy: 1100,
  10797. solbar: 9023,
  10798. spades: 9824,
  10799. sqsube: 8849,
  10800. sqsupe: 8850,
  10801. square: 9633,
  10802. squarf: 9642,
  10803. ssetmn: 8726,
  10804. ssmile: 8995,
  10805. sstarf: 8902,
  10806. subdot: 10941,
  10807. subset: 8834,
  10808. subsim: 10951,
  10809. subsub: 10965,
  10810. subsup: 10963,
  10811. succeq: 10928,
  10812. supdot: 10942,
  10813. supset: 8835,
  10814. supsim: 10952,
  10815. supsub: 10964,
  10816. supsup: 10966,
  10817. swarhk: 10534,
  10818. swnwar: 10538,
  10819. target: 8982,
  10820. tcaron: 357,
  10821. tcedil: 355,
  10822. telrec: 8981,
  10823. there4: 8756,
  10824. thetav: 977,
  10825. thinsp: 8201,
  10826. thksim: 8764,
  10827. timesb: 8864,
  10828. timesd: 10800,
  10829. topbot: 9014,
  10830. topcir: 10993,
  10831. tprime: 8244,
  10832. tridot: 9708,
  10833. tstrok: 359,
  10834. uacute: 250,
  10835. ubreve: 365,
  10836. udblac: 369,
  10837. ufisht: 10622,
  10838. ugrave: 249,
  10839. ulcorn: 8988,
  10840. ulcrop: 8975,
  10841. urcorn: 8989,
  10842. urcrop: 8974,
  10843. utilde: 361,
  10844. vangrt: 10652,
  10845. varphi: 966,
  10846. varrho: 1009,
  10847. veebar: 8891,
  10848. vellip: 8942,
  10849. verbar: 124,
  10850. wedbar: 10847,
  10851. wedgeq: 8793,
  10852. weierp: 8472,
  10853. wreath: 8768,
  10854. xoplus: 10753,
  10855. xotime: 10754,
  10856. xsqcup: 10758,
  10857. xuplus: 10756,
  10858. xwedge: 8896,
  10859. yacute: 253,
  10860. zacute: 378,
  10861. zcaron: 382,
  10862. zeetrf: 8488,
  10863. AElig: 198,
  10864. Acirc: 194,
  10865. Alpha: 913,
  10866. Amacr: 256,
  10867. Aogon: 260,
  10868. Aring: 197,
  10869. Breve: 728,
  10870. Ccirc: 264,
  10871. Colon: 8759,
  10872. Cross: 10799,
  10873. Dashv: 10980,
  10874. Delta: 916,
  10875. Ecirc: 202,
  10876. Emacr: 274,
  10877. Eogon: 280,
  10878. Equal: 10869,
  10879. Gamma: 915,
  10880. Gcirc: 284,
  10881. Hacek: 711,
  10882. Hcirc: 292,
  10883. IJlig: 306,
  10884. Icirc: 206,
  10885. Imacr: 298,
  10886. Iogon: 302,
  10887. Iukcy: 1030,
  10888. Jcirc: 308,
  10889. Jukcy: 1028,
  10890. Kappa: 922,
  10891. OElig: 338,
  10892. Ocirc: 212,
  10893. Omacr: 332,
  10894. Omega: 937,
  10895. Prime: 8243,
  10896. RBarr: 10512,
  10897. Scirc: 348,
  10898. Sigma: 931,
  10899. THORN: 222,
  10900. TRADE: 8482,
  10901. TSHcy: 1035,
  10902. Theta: 920,
  10903. Tilde: 8764,
  10904. Ubrcy: 1038,
  10905. Ucirc: 219,
  10906. Umacr: 362,
  10907. Union: 8899,
  10908. Uogon: 370,
  10909. UpTee: 8869,
  10910. Uring: 366,
  10911. VDash: 8875,
  10912. Vdash: 8873,
  10913. Wcirc: 372,
  10914. Wedge: 8896,
  10915. Ycirc: 374,
  10916. acirc: 226,
  10917. acute: 180,
  10918. aelig: 230,
  10919. aleph: 8501,
  10920. alpha: 945,
  10921. amacr: 257,
  10922. amalg: 10815,
  10923. angle: 8736,
  10924. angrt: 8735,
  10925. angst: 8491,
  10926. aogon: 261,
  10927. aring: 229,
  10928. asymp: 8776,
  10929. awint: 10769,
  10930. bcong: 8780,
  10931. bdquo: 8222,
  10932. bepsi: 1014,
  10933. blank: 9251,
  10934. blk12: 9618,
  10935. blk14: 9617,
  10936. blk34: 9619,
  10937. block: 9608,
  10938. boxDL: 9559,
  10939. boxDR: 9556,
  10940. boxDl: 9558,
  10941. boxDr: 9555,
  10942. boxHD: 9574,
  10943. boxHU: 9577,
  10944. boxHd: 9572,
  10945. boxHu: 9575,
  10946. boxUL: 9565,
  10947. boxUR: 9562,
  10948. boxUl: 9564,
  10949. boxUr: 9561,
  10950. boxVH: 9580,
  10951. boxVL: 9571,
  10952. boxVR: 9568,
  10953. boxVh: 9579,
  10954. boxVl: 9570,
  10955. boxVr: 9567,
  10956. boxdL: 9557,
  10957. boxdR: 9554,
  10958. boxdl: 9488,
  10959. boxdr: 9484,
  10960. boxhD: 9573,
  10961. boxhU: 9576,
  10962. boxhd: 9516,
  10963. boxhu: 9524,
  10964. boxuL: 9563,
  10965. boxuR: 9560,
  10966. boxul: 9496,
  10967. boxur: 9492,
  10968. boxvH: 9578,
  10969. boxvL: 9569,
  10970. boxvR: 9566,
  10971. boxvh: 9532,
  10972. boxvl: 9508,
  10973. boxvr: 9500,
  10974. breve: 728,
  10975. bsemi: 8271,
  10976. bsime: 8909,
  10977. bsolb: 10693,
  10978. bumpE: 10926,
  10979. bumpe: 8783,
  10980. caret: 8257,
  10981. caron: 711,
  10982. ccaps: 10829,
  10983. ccirc: 265,
  10984. ccups: 10828,
  10985. cedil: 184,
  10986. check: 10003,
  10987. clubs: 9827,
  10988. colon: 58,
  10989. comma: 44,
  10990. crarr: 8629,
  10991. cross: 10007,
  10992. csube: 10961,
  10993. csupe: 10962,
  10994. ctdot: 8943,
  10995. cuepr: 8926,
  10996. cuesc: 8927,
  10997. cupor: 10821,
  10998. cuvee: 8910,
  10999. cuwed: 8911,
  11000. cwint: 8753,
  11001. dashv: 8867,
  11002. dblac: 733,
  11003. ddarr: 8650,
  11004. delta: 948,
  11005. dharl: 8643,
  11006. dharr: 8642,
  11007. diams: 9830,
  11008. disin: 8946,
  11009. doteq: 8784,
  11010. dtdot: 8945,
  11011. dtrif: 9662,
  11012. duarr: 8693,
  11013. duhar: 10607,
  11014. eDDot: 10871,
  11015. ecirc: 234,
  11016. efDot: 8786,
  11017. emacr: 275,
  11018. empty: 8709,
  11019. eogon: 281,
  11020. eplus: 10865,
  11021. epsiv: 949,
  11022. eqsim: 8770,
  11023. equiv: 8801,
  11024. erDot: 8787,
  11025. erarr: 10609,
  11026. esdot: 8784,
  11027. exist: 8707,
  11028. fflig: 64256,
  11029. filig: 64257,
  11030. fllig: 64258,
  11031. fltns: 9649,
  11032. forkv: 10969,
  11033. frasl: 8260,
  11034. frown: 8994,
  11035. gamma: 947,
  11036. gcirc: 285,
  11037. gescc: 10921,
  11038. gimel: 8503,
  11039. gneqq: 8809,
  11040. gnsim: 8935,
  11041. grave: 96,
  11042. gsime: 10894,
  11043. gsiml: 10896,
  11044. gtcir: 10874,
  11045. gtdot: 8919,
  11046. harrw: 8621,
  11047. hcirc: 293,
  11048. hoarr: 8703,
  11049. icirc: 238,
  11050. iexcl: 161,
  11051. iiint: 8749,
  11052. iiota: 8489,
  11053. ijlig: 307,
  11054. imacr: 299,
  11055. image: 8465,
  11056. imath: 305,
  11057. imped: 437,
  11058. infin: 8734,
  11059. iogon: 303,
  11060. iprod: 10812,
  11061. isinE: 8953,
  11062. isins: 8948,
  11063. isinv: 8712,
  11064. iukcy: 1110,
  11065. jcirc: 309,
  11066. jmath: 567,
  11067. jukcy: 1108,
  11068. kappa: 954,
  11069. lAarr: 8666,
  11070. lBarr: 10510,
  11071. langd: 10641,
  11072. laquo: 171,
  11073. larrb: 8676,
  11074. lbarr: 10508,
  11075. lbbrk: 10098,
  11076. lbrke: 10635,
  11077. lceil: 8968,
  11078. ldquo: 8220,
  11079. lescc: 10920,
  11080. lhard: 8637,
  11081. lharu: 8636,
  11082. lhblk: 9604,
  11083. llarr: 8647,
  11084. lltri: 9722,
  11085. lneqq: 8808,
  11086. lnsim: 8934,
  11087. loang: 10220,
  11088. loarr: 8701,
  11089. lobrk: 10214,
  11090. lopar: 10629,
  11091. lrarr: 8646,
  11092. lrhar: 8651,
  11093. lrtri: 8895,
  11094. lsime: 10893,
  11095. lsimg: 10895,
  11096. lsquo: 8216,
  11097. ltcir: 10873,
  11098. ltdot: 8918,
  11099. ltrie: 8884,
  11100. ltrif: 9666,
  11101. mDDot: 8762,
  11102. mdash: 8212,
  11103. micro: 181,
  11104. minus: 8722,
  11105. mumap: 8888,
  11106. nabla: 8711,
  11107. napos: 329,
  11108. natur: 9838,
  11109. ncong: 8775,
  11110. ndash: 8211,
  11111. neArr: 8663,
  11112. nearr: 8599,
  11113. ngsim: 8821,
  11114. nhArr: 8654,
  11115. nharr: 8622,
  11116. nhpar: 10994,
  11117. nlArr: 8653,
  11118. nlarr: 8602,
  11119. nless: 8814,
  11120. nlsim: 8820,
  11121. nltri: 8938,
  11122. notin: 8713,
  11123. notni: 8716,
  11124. nprec: 8832,
  11125. nrArr: 8655,
  11126. nrarr: 8603,
  11127. nrtri: 8939,
  11128. nsime: 8772,
  11129. nsmid: 8740,
  11130. nspar: 8742,
  11131. nsube: 8840,
  11132. nsucc: 8833,
  11133. nsupe: 8841,
  11134. numsp: 8199,
  11135. nwArr: 8662,
  11136. nwarr: 8598,
  11137. ocirc: 244,
  11138. odash: 8861,
  11139. oelig: 339,
  11140. ofcir: 10687,
  11141. ohbar: 10677,
  11142. olarr: 8634,
  11143. olcir: 10686,
  11144. oline: 8254,
  11145. omacr: 333,
  11146. omega: 969,
  11147. operp: 10681,
  11148. oplus: 8853,
  11149. orarr: 8635,
  11150. order: 8500,
  11151. ovbar: 9021,
  11152. parsl: 11005,
  11153. phone: 9742,
  11154. plusb: 8862,
  11155. pluse: 10866,
  11156. pound: 163,
  11157. prcue: 8828,
  11158. prime: 8242,
  11159. prnap: 10937,
  11160. prsim: 8830,
  11161. quest: 63,
  11162. rAarr: 8667,
  11163. rBarr: 10511,
  11164. radic: 8730,
  11165. rangd: 10642,
  11166. range: 10661,
  11167. raquo: 187,
  11168. rarrb: 8677,
  11169. rarrc: 10547,
  11170. rarrw: 8605,
  11171. ratio: 8758,
  11172. rbarr: 10509,
  11173. rbbrk: 10099,
  11174. rbrke: 10636,
  11175. rceil: 8969,
  11176. rdquo: 8221,
  11177. reals: 8477,
  11178. rhard: 8641,
  11179. rharu: 8640,
  11180. rlarr: 8644,
  11181. rlhar: 8652,
  11182. rnmid: 10990,
  11183. roang: 10221,
  11184. roarr: 8702,
  11185. robrk: 10215,
  11186. ropar: 10630,
  11187. rrarr: 8649,
  11188. rsquo: 8217,
  11189. rtrie: 8885,
  11190. rtrif: 9656,
  11191. sbquo: 8218,
  11192. sccue: 8829,
  11193. scirc: 349,
  11194. scnap: 10938,
  11195. scsim: 8831,
  11196. sdotb: 8865,
  11197. sdote: 10854,
  11198. seArr: 8664,
  11199. searr: 8600,
  11200. setmn: 8726,
  11201. sharp: 9839,
  11202. sigma: 963,
  11203. simeq: 8771,
  11204. simgE: 10912,
  11205. simlE: 10911,
  11206. simne: 8774,
  11207. slarr: 8592,
  11208. smile: 8995,
  11209. sqcap: 8851,
  11210. sqcup: 8852,
  11211. sqsub: 8847,
  11212. sqsup: 8848,
  11213. srarr: 8594,
  11214. starf: 9733,
  11215. strns: 175,
  11216. subnE: 10955,
  11217. subne: 8842,
  11218. supnE: 10956,
  11219. supne: 8843,
  11220. swArr: 8665,
  11221. swarr: 8601,
  11222. szlig: 223,
  11223. theta: 952,
  11224. thkap: 8776,
  11225. thorn: 254,
  11226. tilde: 732,
  11227. times: 215,
  11228. trade: 8482,
  11229. trisb: 10701,
  11230. tshcy: 1115,
  11231. twixt: 8812,
  11232. ubrcy: 1118,
  11233. ucirc: 251,
  11234. udarr: 8645,
  11235. udhar: 10606,
  11236. uharl: 8639,
  11237. uharr: 8638,
  11238. uhblk: 9600,
  11239. ultri: 9720,
  11240. umacr: 363,
  11241. uogon: 371,
  11242. uplus: 8846,
  11243. upsih: 978,
  11244. uring: 367,
  11245. urtri: 9721,
  11246. utdot: 8944,
  11247. utrif: 9652,
  11248. uuarr: 8648,
  11249. vBarv: 10985,
  11250. vDash: 8872,
  11251. varpi: 982,
  11252. vdash: 8866,
  11253. veeeq: 8794,
  11254. vltri: 8882,
  11255. vprop: 8733,
  11256. vrtri: 8883,
  11257. wcirc: 373,
  11258. wedge: 8743,
  11259. xcirc: 9711,
  11260. xdtri: 9661,
  11261. xhArr: 10234,
  11262. xharr: 10231,
  11263. xlArr: 10232,
  11264. xlarr: 10229,
  11265. xodot: 10752,
  11266. xrArr: 10233,
  11267. xrarr: 10230,
  11268. xutri: 9651,
  11269. ycirc: 375,
  11270. Aopf: 120120,
  11271. Ascr: 119964,
  11272. Auml: 196,
  11273. Barv: 10983,
  11274. Beta: 914,
  11275. Bopf: 120121,
  11276. Bscr: 8492,
  11277. CHcy: 1063,
  11278. COPY: 169,
  11279. Cdot: 266,
  11280. Copf: 8450,
  11281. Cscr: 119966,
  11282. DJcy: 1026,
  11283. DScy: 1029,
  11284. DZcy: 1039,
  11285. Darr: 8609,
  11286. Dopf: 120123,
  11287. Dscr: 119967,
  11288. Edot: 278,
  11289. Eopf: 120124,
  11290. Escr: 8496,
  11291. Esim: 10867,
  11292. Euml: 203,
  11293. Fopf: 120125,
  11294. Fscr: 8497,
  11295. GJcy: 1027,
  11296. Gdot: 288,
  11297. Gopf: 120126,
  11298. Gscr: 119970,
  11299. Hopf: 8461,
  11300. Hscr: 8459,
  11301. IEcy: 1045,
  11302. IOcy: 1025,
  11303. Idot: 304,
  11304. Iopf: 120128,
  11305. Iota: 921,
  11306. Iscr: 8464,
  11307. Iuml: 207,
  11308. Jopf: 120129,
  11309. Jscr: 119973,
  11310. KHcy: 1061,
  11311. KJcy: 1036,
  11312. Kopf: 120130,
  11313. Kscr: 119974,
  11314. LJcy: 1033,
  11315. Lang: 10218,
  11316. Larr: 8606,
  11317. Lopf: 120131,
  11318. Lscr: 8466,
  11319. Mopf: 120132,
  11320. Mscr: 8499,
  11321. NJcy: 1034,
  11322. Nopf: 8469,
  11323. Nscr: 119977,
  11324. Oopf: 120134,
  11325. Oscr: 119978,
  11326. Ouml: 214,
  11327. Popf: 8473,
  11328. Pscr: 119979,
  11329. QUOT: 34,
  11330. Qopf: 8474,
  11331. Qscr: 119980,
  11332. Rang: 10219,
  11333. Rarr: 8608,
  11334. Ropf: 8477,
  11335. Rscr: 8475,
  11336. SHcy: 1064,
  11337. Sopf: 120138,
  11338. Sqrt: 8730,
  11339. Sscr: 119982,
  11340. Star: 8902,
  11341. TScy: 1062,
  11342. Topf: 120139,
  11343. Tscr: 119983,
  11344. Uarr: 8607,
  11345. Uopf: 120140,
  11346. Upsi: 978,
  11347. Uscr: 119984,
  11348. Uuml: 220,
  11349. Vbar: 10987,
  11350. Vert: 8214,
  11351. Vopf: 120141,
  11352. Vscr: 119985,
  11353. Wopf: 120142,
  11354. Wscr: 119986,
  11355. Xopf: 120143,
  11356. Xscr: 119987,
  11357. YAcy: 1071,
  11358. YIcy: 1031,
  11359. YUcy: 1070,
  11360. Yopf: 120144,
  11361. Yscr: 119988,
  11362. Yuml: 376,
  11363. ZHcy: 1046,
  11364. Zdot: 379,
  11365. Zeta: 918,
  11366. Zopf: 8484,
  11367. Zscr: 119989,
  11368. andd: 10844,
  11369. andv: 10842,
  11370. ange: 10660,
  11371. aopf: 120146,
  11372. apid: 8779,
  11373. apos: 39,
  11374. ascr: 119990,
  11375. auml: 228,
  11376. bNot: 10989,
  11377. bbrk: 9141,
  11378. beta: 946,
  11379. beth: 8502,
  11380. bnot: 8976,
  11381. bopf: 120147,
  11382. boxH: 9552,
  11383. boxV: 9553,
  11384. boxh: 9472,
  11385. boxv: 9474,
  11386. bscr: 119991,
  11387. bsim: 8765,
  11388. bsol: 92,
  11389. bull: 8226,
  11390. bump: 8782,
  11391. cdot: 267,
  11392. cent: 162,
  11393. chcy: 1095,
  11394. cirE: 10691,
  11395. circ: 710,
  11396. cire: 8791,
  11397. comp: 8705,
  11398. cong: 8773,
  11399. copf: 120148,
  11400. copy: 169,
  11401. cscr: 119992,
  11402. csub: 10959,
  11403. csup: 10960,
  11404. dArr: 8659,
  11405. dHar: 10597,
  11406. darr: 8595,
  11407. dash: 8208,
  11408. diam: 8900,
  11409. djcy: 1106,
  11410. dopf: 120149,
  11411. dscr: 119993,
  11412. dscy: 1109,
  11413. dsol: 10742,
  11414. dtri: 9663,
  11415. dzcy: 1119,
  11416. eDot: 8785,
  11417. ecir: 8790,
  11418. edot: 279,
  11419. emsp: 8195,
  11420. ensp: 8194,
  11421. eopf: 120150,
  11422. epar: 8917,
  11423. epsi: 1013,
  11424. escr: 8495,
  11425. esim: 8770,
  11426. euml: 235,
  11427. euro: 8364,
  11428. excl: 33,
  11429. flat: 9837,
  11430. fnof: 402,
  11431. fopf: 120151,
  11432. fork: 8916,
  11433. fscr: 119995,
  11434. gdot: 289,
  11435. geqq: 8807,
  11436. gjcy: 1107,
  11437. gnap: 10890,
  11438. gneq: 10888,
  11439. gopf: 120152,
  11440. gscr: 8458,
  11441. gsim: 8819,
  11442. gtcc: 10919,
  11443. hArr: 8660,
  11444. half: 189,
  11445. harr: 8596,
  11446. hbar: 8463,
  11447. hopf: 120153,
  11448. hscr: 119997,
  11449. iecy: 1077,
  11450. imof: 8887,
  11451. iocy: 1105,
  11452. iopf: 120154,
  11453. iota: 953,
  11454. iscr: 119998,
  11455. isin: 8712,
  11456. iuml: 239,
  11457. jopf: 120155,
  11458. jscr: 119999,
  11459. khcy: 1093,
  11460. kjcy: 1116,
  11461. kopf: 120156,
  11462. kscr: 120000,
  11463. lArr: 8656,
  11464. lHar: 10594,
  11465. lang: 10216,
  11466. larr: 8592,
  11467. late: 10925,
  11468. lcub: 123,
  11469. ldca: 10550,
  11470. ldsh: 8626,
  11471. leqq: 8806,
  11472. ljcy: 1113,
  11473. lnap: 10889,
  11474. lneq: 10887,
  11475. lopf: 120157,
  11476. lozf: 10731,
  11477. lpar: 40,
  11478. lscr: 120001,
  11479. lsim: 8818,
  11480. lsqb: 91,
  11481. ltcc: 10918,
  11482. ltri: 9667,
  11483. macr: 175,
  11484. male: 9794,
  11485. malt: 10016,
  11486. mlcp: 10971,
  11487. mldr: 8230,
  11488. mopf: 120158,
  11489. mscr: 120002,
  11490. nbsp: 160,
  11491. ncap: 10819,
  11492. ncup: 10818,
  11493. ngeq: 8817,
  11494. ngtr: 8815,
  11495. nisd: 8954,
  11496. njcy: 1114,
  11497. nldr: 8229,
  11498. nleq: 8816,
  11499. nmid: 8740,
  11500. nopf: 120159,
  11501. npar: 8742,
  11502. nscr: 120003,
  11503. nsim: 8769,
  11504. nsub: 8836,
  11505. nsup: 8837,
  11506. ntgl: 8825,
  11507. ntlg: 8824,
  11508. oast: 8859,
  11509. ocir: 8858,
  11510. odiv: 10808,
  11511. odot: 8857,
  11512. ogon: 731,
  11513. oint: 8750,
  11514. omid: 10678,
  11515. oopf: 120160,
  11516. opar: 10679,
  11517. ordf: 170,
  11518. ordm: 186,
  11519. oror: 10838,
  11520. oscr: 8500,
  11521. osol: 8856,
  11522. ouml: 246,
  11523. para: 182,
  11524. part: 8706,
  11525. perp: 8869,
  11526. phiv: 966,
  11527. plus: 43,
  11528. popf: 120161,
  11529. prap: 10935,
  11530. prec: 8826,
  11531. prnE: 10933,
  11532. prod: 8719,
  11533. prop: 8733,
  11534. pscr: 120005,
  11535. qint: 10764,
  11536. qopf: 120162,
  11537. qscr: 120006,
  11538. quot: 34,
  11539. rArr: 8658,
  11540. rHar: 10596,
  11541. race: 10714,
  11542. rang: 10217,
  11543. rarr: 8594,
  11544. rcub: 125,
  11545. rdca: 10551,
  11546. rdsh: 8627,
  11547. real: 8476,
  11548. rect: 9645,
  11549. rhov: 1009,
  11550. ring: 730,
  11551. ropf: 120163,
  11552. rpar: 41,
  11553. rscr: 120007,
  11554. rsqb: 93,
  11555. rtri: 9657,
  11556. scap: 10936,
  11557. scnE: 10934,
  11558. sdot: 8901,
  11559. sect: 167,
  11560. semi: 59,
  11561. sext: 10038,
  11562. shcy: 1096,
  11563. sime: 8771,
  11564. simg: 10910,
  11565. siml: 10909,
  11566. smid: 8739,
  11567. smte: 10924,
  11568. solb: 10692,
  11569. sopf: 120164,
  11570. spar: 8741,
  11571. squf: 9642,
  11572. sscr: 120008,
  11573. star: 9734,
  11574. subE: 10949,
  11575. sube: 8838,
  11576. succ: 8827,
  11577. sung: 9834,
  11578. sup1: 185,
  11579. sup2: 178,
  11580. sup3: 179,
  11581. supE: 10950,
  11582. supe: 8839,
  11583. tbrk: 9140,
  11584. tdot: 8411,
  11585. tint: 8749,
  11586. toea: 10536,
  11587. topf: 120165,
  11588. tosa: 10537,
  11589. trie: 8796,
  11590. tscr: 120009,
  11591. tscy: 1094,
  11592. uArr: 8657,
  11593. uHar: 10595,
  11594. uarr: 8593,
  11595. uopf: 120166,
  11596. upsi: 965,
  11597. uscr: 120010,
  11598. utri: 9653,
  11599. uuml: 252,
  11600. vArr: 8661,
  11601. vBar: 10984,
  11602. varr: 8597,
  11603. vert: 124,
  11604. vopf: 120167,
  11605. vscr: 120011,
  11606. wopf: 120168,
  11607. wscr: 120012,
  11608. xcap: 8898,
  11609. xcup: 8899,
  11610. xmap: 10236,
  11611. xnis: 8955,
  11612. xopf: 120169,
  11613. xscr: 120013,
  11614. xvee: 8897,
  11615. yacy: 1103,
  11616. yicy: 1111,
  11617. yopf: 120170,
  11618. yscr: 120014,
  11619. yucy: 1102,
  11620. yuml: 255,
  11621. zdot: 380,
  11622. zeta: 950,
  11623. zhcy: 1078,
  11624. zopf: 120171,
  11625. zscr: 120015,
  11626. zwnj: 8204,
  11627. AMP: 38,
  11628. Acy: 1040,
  11629. Afr: 120068,
  11630. And: 10835,
  11631. Bcy: 1041,
  11632. Bfr: 120069,
  11633. Cap: 8914,
  11634. Cfr: 8493,
  11635. Chi: 935,
  11636. Cup: 8915,
  11637. Dcy: 1044,
  11638. Del: 8711,
  11639. Dfr: 120071,
  11640. Dot: 168,
  11641. ENG: 330,
  11642. ETH: 208,
  11643. Ecy: 1069,
  11644. Efr: 120072,
  11645. Eta: 919,
  11646. Fcy: 1060,
  11647. Ffr: 120073,
  11648. Gcy: 1043,
  11649. Gfr: 120074,
  11650. Hat: 94,
  11651. Hfr: 8460,
  11652. Icy: 1048,
  11653. Ifr: 8465,
  11654. Int: 8748,
  11655. Jcy: 1049,
  11656. Jfr: 120077,
  11657. Kcy: 1050,
  11658. Kfr: 120078,
  11659. Lcy: 1051,
  11660. Lfr: 120079,
  11661. Lsh: 8624,
  11662. Map: 10501,
  11663. Mcy: 1052,
  11664. Mfr: 120080,
  11665. Ncy: 1053,
  11666. Nfr: 120081,
  11667. Not: 10988,
  11668. Ocy: 1054,
  11669. Ofr: 120082,
  11670. Pcy: 1055,
  11671. Pfr: 120083,
  11672. Phi: 934,
  11673. Psi: 936,
  11674. Qfr: 120084,
  11675. REG: 174,
  11676. Rcy: 1056,
  11677. Rfr: 8476,
  11678. Rho: 929,
  11679. Rsh: 8625,
  11680. Scy: 1057,
  11681. Sfr: 120086,
  11682. Sub: 8912,
  11683. Sum: 8721,
  11684. Sup: 8913,
  11685. Tab: 9,
  11686. Tau: 932,
  11687. Tcy: 1058,
  11688. Tfr: 120087,
  11689. Ucy: 1059,
  11690. Ufr: 120088,
  11691. Vcy: 1042,
  11692. Vee: 8897,
  11693. Vfr: 120089,
  11694. Wfr: 120090,
  11695. Xfr: 120091,
  11696. Ycy: 1067,
  11697. Yfr: 120092,
  11698. Zcy: 1047,
  11699. Zfr: 8488,
  11700. acd: 8767,
  11701. acy: 1072,
  11702. afr: 120094,
  11703. amp: 38,
  11704. and: 8743,
  11705. ang: 8736,
  11706. apE: 10864,
  11707. ape: 8778,
  11708. ast: 42,
  11709. bcy: 1073,
  11710. bfr: 120095,
  11711. bot: 8869,
  11712. cap: 8745,
  11713. cfr: 120096,
  11714. chi: 967,
  11715. cir: 9675,
  11716. cup: 8746,
  11717. dcy: 1076,
  11718. deg: 176,
  11719. dfr: 120097,
  11720. die: 168,
  11721. div: 247,
  11722. dot: 729,
  11723. ecy: 1101,
  11724. efr: 120098,
  11725. egs: 10902,
  11726. ell: 8467,
  11727. els: 10901,
  11728. eng: 331,
  11729. eta: 951,
  11730. eth: 240,
  11731. fcy: 1092,
  11732. ffr: 120099,
  11733. gEl: 10892,
  11734. gap: 10886,
  11735. gcy: 1075,
  11736. gel: 8923,
  11737. geq: 8805,
  11738. ges: 10878,
  11739. gfr: 120100,
  11740. ggg: 8921,
  11741. glE: 10898,
  11742. gla: 10917,
  11743. glj: 10916,
  11744. gnE: 8809,
  11745. gne: 10888,
  11746. hfr: 120101,
  11747. icy: 1080,
  11748. iff: 8660,
  11749. ifr: 120102,
  11750. int: 8747,
  11751. jcy: 1081,
  11752. jfr: 120103,
  11753. kcy: 1082,
  11754. kfr: 120104,
  11755. lEg: 10891,
  11756. lap: 10885,
  11757. lat: 10923,
  11758. lcy: 1083,
  11759. leg: 8922,
  11760. leq: 8804,
  11761. les: 10877,
  11762. lfr: 120105,
  11763. lgE: 10897,
  11764. lnE: 8808,
  11765. lne: 10887,
  11766. loz: 9674,
  11767. lrm: 8206,
  11768. lsh: 8624,
  11769. map: 8614,
  11770. mcy: 1084,
  11771. mfr: 120106,
  11772. mho: 8487,
  11773. mid: 8739,
  11774. nap: 8777,
  11775. ncy: 1085,
  11776. nfr: 120107,
  11777. nge: 8817,
  11778. ngt: 8815,
  11779. nis: 8956,
  11780. niv: 8715,
  11781. nle: 8816,
  11782. nlt: 8814,
  11783. not: 172,
  11784. npr: 8832,
  11785. nsc: 8833,
  11786. num: 35,
  11787. ocy: 1086,
  11788. ofr: 120108,
  11789. ogt: 10689,
  11790. ohm: 8486,
  11791. olt: 10688,
  11792. ord: 10845,
  11793. orv: 10843,
  11794. par: 8741,
  11795. pcy: 1087,
  11796. pfr: 120109,
  11797. phi: 966,
  11798. piv: 982,
  11799. prE: 10931,
  11800. pre: 10927,
  11801. psi: 968,
  11802. qfr: 120110,
  11803. rcy: 1088,
  11804. reg: 174,
  11805. rfr: 120111,
  11806. rho: 961,
  11807. rlm: 8207,
  11808. rsh: 8625,
  11809. scE: 10932,
  11810. sce: 10928,
  11811. scy: 1089,
  11812. sfr: 120112,
  11813. shy: 173,
  11814. sim: 8764,
  11815. smt: 10922,
  11816. sol: 47,
  11817. squ: 9633,
  11818. sub: 8834,
  11819. sum: 8721,
  11820. sup: 8835,
  11821. tau: 964,
  11822. tcy: 1090,
  11823. tfr: 120113,
  11824. top: 8868,
  11825. ucy: 1091,
  11826. ufr: 120114,
  11827. uml: 168,
  11828. vcy: 1074,
  11829. vee: 8744,
  11830. vfr: 120115,
  11831. wfr: 120116,
  11832. xfr: 120117,
  11833. ycy: 1099,
  11834. yen: 165,
  11835. yfr: 120118,
  11836. zcy: 1079,
  11837. zfr: 120119,
  11838. zwj: 8205,
  11839. DD: 8517,
  11840. GT: 62,
  11841. Gg: 8921,
  11842. Gt: 8811,
  11843. Im: 8465,
  11844. LT: 60,
  11845. Ll: 8920,
  11846. Lt: 8810,
  11847. Mu: 924,
  11848. Nu: 925,
  11849. Or: 10836,
  11850. Pi: 928,
  11851. Pr: 10939,
  11852. Re: 8476,
  11853. Sc: 10940,
  11854. Xi: 926,
  11855. ac: 8766,
  11856. af: 8289,
  11857. ap: 8776,
  11858. dd: 8518,
  11859. ee: 8519,
  11860. eg: 10906,
  11861. el: 10905,
  11862. gE: 8807,
  11863. ge: 8805,
  11864. gg: 8811,
  11865. gl: 8823,
  11866. gt: 62,
  11867. ic: 8291,
  11868. ii: 8520,
  11869. in: 8712,
  11870. it: 8290,
  11871. lE: 8806,
  11872. le: 8804,
  11873. lg: 8822,
  11874. ll: 8810,
  11875. lt: 60,
  11876. mp: 8723,
  11877. mu: 956,
  11878. ne: 8800,
  11879. ni: 8715,
  11880. nu: 957,
  11881. oS: 9416,
  11882. or: 8744,
  11883. pi: 960,
  11884. pm: 177,
  11885. pr: 8826,
  11886. rx: 8478,
  11887. sc: 8827,
  11888. wp: 8472,
  11889. wr: 8768,
  11890. xi: 958,
  11891. };
  11892. const windows1252 = [
  11893. 8364,
  11894. 129,
  11895. 8218,
  11896. 402,
  11897. 8222,
  11898. 8230,
  11899. 8224,
  11900. 8225,
  11901. 710,
  11902. 8240,
  11903. 352,
  11904. 8249,
  11905. 338,
  11906. 141,
  11907. 381,
  11908. 143,
  11909. 144,
  11910. 8216,
  11911. 8217,
  11912. 8220,
  11913. 8221,
  11914. 8226,
  11915. 8211,
  11916. 8212,
  11917. 732,
  11918. 8482,
  11919. 353,
  11920. 8250,
  11921. 339,
  11922. 157,
  11923. 382,
  11924. 376,
  11925. ];
  11926. const entityPattern = new RegExp(`&(#?(?:x[\\w\\d]+|\\d+|${Object.keys(htmlEntities).join('|')}));?`, 'g');
  11927. function decodeCharacterReferences(html) {
  11928. return html.replace(entityPattern, (match, entity) => {
  11929. let code;
  11930. // Handle named entities
  11931. if (entity[0] !== '#') {
  11932. code = htmlEntities[entity];
  11933. }
  11934. else if (entity[1] === 'x') {
  11935. code = parseInt(entity.substring(2), 16);
  11936. }
  11937. else {
  11938. code = parseInt(entity.substring(1), 10);
  11939. }
  11940. if (!code) {
  11941. return match;
  11942. }
  11943. return String.fromCodePoint(validateCode(code));
  11944. });
  11945. }
  11946. const NUL = 0;
  11947. // some code points are verboten. If we were inserting HTML, the browser would replace the illegal
  11948. // code points with alternatives in some cases - since we're bypassing that mechanism, we need
  11949. // to replace them ourselves
  11950. //
  11951. // Source: http://en.wikipedia.org/wiki/Character_encodings_in_HTML#Illegal_characters
  11952. function validateCode(code) {
  11953. // line feed becomes generic whitespace
  11954. if (code === 10) {
  11955. return 32;
  11956. }
  11957. // ASCII range. (Why someone would use HTML entities for ASCII characters I don't know, but...)
  11958. if (code < 128) {
  11959. return code;
  11960. }
  11961. // code points 128-159 are dealt with leniently by browsers, but they're incorrect. We need
  11962. // to correct the mistake or we'll end up with missing € signs and so on
  11963. if (code <= 159) {
  11964. return windows1252[code - 128];
  11965. }
  11966. // basic multilingual plane
  11967. if (code < 55296) {
  11968. return code;
  11969. }
  11970. // UTF-16 surrogate halves
  11971. if (code <= 57343) {
  11972. return NUL;
  11973. }
  11974. // rest of the basic multilingual plane
  11975. if (code <= 65535) {
  11976. return code;
  11977. }
  11978. // supplementary multilingual plane 0x10000 - 0x1ffff
  11979. if (code >= 65536 && code <= 131071) {
  11980. return code;
  11981. }
  11982. // supplementary ideographic plane 0x20000 - 0x2ffff
  11983. if (code >= 131072 && code <= 196607) {
  11984. return code;
  11985. }
  11986. return NUL;
  11987. }
  11988. const voidElementNames = /^(?:area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/;
  11989. function isVoidElementName(name) {
  11990. return voidElementNames.test(name) || name.toLowerCase() === '!doctype';
  11991. }
  11992. const validTagName = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/;
  11993. const metaTags = new Map([
  11994. ['svelte:window', 'Window'],
  11995. ['svelte:head', 'Head']
  11996. ]);
  11997. const specials = new Map([
  11998. [
  11999. 'script',
  12000. {
  12001. read: readScript,
  12002. property: 'js',
  12003. },
  12004. ],
  12005. [
  12006. 'style',
  12007. {
  12008. read: readStyle,
  12009. property: 'css',
  12010. },
  12011. ],
  12012. ]);
  12013. const SELF = 'svelte:self';
  12014. const COMPONENT = 'svelte:component';
  12015. // based on http://developers.whatwg.org/syntax.html#syntax-tag-omission
  12016. const disallowedContents = new Map([
  12017. ['li', new Set(['li'])],
  12018. ['dt', new Set(['dt', 'dd'])],
  12019. ['dd', new Set(['dt', 'dd'])],
  12020. [
  12021. 'p',
  12022. 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(' ')),
  12023. ],
  12024. ['rt', new Set(['rt', 'rp'])],
  12025. ['rp', new Set(['rt', 'rp'])],
  12026. ['optgroup', new Set(['optgroup'])],
  12027. ['option', new Set(['option', 'optgroup'])],
  12028. ['thead', new Set(['tbody', 'tfoot'])],
  12029. ['tbody', new Set(['tbody', 'tfoot'])],
  12030. ['tfoot', new Set(['tbody'])],
  12031. ['tr', new Set(['tr', 'tbody'])],
  12032. ['td', new Set(['td', 'th', 'tr'])],
  12033. ['th', new Set(['td', 'th', 'tr'])],
  12034. ]);
  12035. function parentIsHead(stack) {
  12036. let i = stack.length;
  12037. while (i--) {
  12038. const { type } = stack[i];
  12039. if (type === 'Head')
  12040. return true;
  12041. if (type === 'Element' || type === 'Component')
  12042. return false;
  12043. }
  12044. return false;
  12045. }
  12046. function tag(parser) {
  12047. const start = parser.index++;
  12048. let parent = parser.current();
  12049. if (parser.eat('!--')) {
  12050. const data = parser.readUntil(/-->/);
  12051. parser.eat('-->', true, 'comment was left open, expected -->');
  12052. parser.current().children.push({
  12053. start,
  12054. end: parser.index,
  12055. type: 'Comment',
  12056. data,
  12057. });
  12058. return;
  12059. }
  12060. const isClosingTag = parser.eat('/');
  12061. const name = readTagName(parser);
  12062. if (metaTags.has(name)) {
  12063. const slug = metaTags.get(name).toLowerCase();
  12064. if (isClosingTag) {
  12065. if (name === 'svelte:window' && parser.current().children.length) {
  12066. parser.error({
  12067. code: `invalid-window-content`,
  12068. message: `<${name}> cannot have children`
  12069. }, parser.current().children[0].start);
  12070. }
  12071. }
  12072. else {
  12073. if (name in parser.metaTags) {
  12074. parser.error({
  12075. code: `duplicate-${slug}`,
  12076. message: `A component can only have one <${name}> tag`
  12077. }, start);
  12078. }
  12079. if (parser.stack.length > 1) {
  12080. parser.error({
  12081. code: `invalid-${slug}-placement`,
  12082. message: `<${name}> tags cannot be inside elements or blocks`
  12083. }, start);
  12084. }
  12085. parser.metaTags[name] = true;
  12086. }
  12087. }
  12088. const type = metaTags.has(name)
  12089. ? metaTags.get(name)
  12090. : (/[A-Z]/.test(name[0]) || name === 'svelte:self' || name === 'svelte:component') ? 'Component'
  12091. : name === 'title' && parentIsHead(parser.stack) ? 'Title'
  12092. : name === 'slot' && !parser.customElement ? 'Slot' : 'Element';
  12093. const element = {
  12094. start,
  12095. end: null,
  12096. type,
  12097. name,
  12098. attributes: [],
  12099. children: [],
  12100. };
  12101. parser.allowWhitespace();
  12102. if (isClosingTag) {
  12103. if (isVoidElementName(name)) {
  12104. parser.error({
  12105. code: `invalid-void-content`,
  12106. message: `<${name}> is a void element and cannot have children, or a closing tag`
  12107. }, start);
  12108. }
  12109. parser.eat('>', true);
  12110. // close any elements that don't have their own closing tags, e.g. <div><p></div>
  12111. while (parent.name !== name) {
  12112. if (parent.type !== 'Element')
  12113. parser.error({
  12114. code: `invalid-closing-tag`,
  12115. message: `</${name}> attempted to close an element that was not open`
  12116. }, start);
  12117. parent.end = start;
  12118. parser.stack.pop();
  12119. parent = parser.current();
  12120. }
  12121. parent.end = parser.index;
  12122. parser.stack.pop();
  12123. return;
  12124. }
  12125. else if (disallowedContents.has(parent.name)) {
  12126. // can this be a child of the parent element, or does it implicitly
  12127. // close it, like `<li>one<li>two`?
  12128. if (disallowedContents.get(parent.name).has(name)) {
  12129. parent.end = start;
  12130. parser.stack.pop();
  12131. }
  12132. }
  12133. if (name === 'slot') {
  12134. let i = parser.stack.length;
  12135. while (i--) {
  12136. const item = parser.stack[i];
  12137. if (item.type === 'EachBlock') {
  12138. parser.error({
  12139. code: `invalid-slot-placement`,
  12140. message: `<slot> cannot be a child of an each-block`
  12141. }, start);
  12142. }
  12143. }
  12144. }
  12145. const uniqueNames = new Set();
  12146. let attribute;
  12147. while ((attribute = readAttribute(parser, uniqueNames))) {
  12148. if (attribute.type === 'Binding' && !parser.allowBindings) {
  12149. parser.error({
  12150. code: `binding-disabled`,
  12151. message: `Two-way binding is disabled`
  12152. }, attribute.start);
  12153. }
  12154. element.attributes.push(attribute);
  12155. parser.allowWhitespace();
  12156. }
  12157. if (name === 'svelte:component') {
  12158. // TODO post v2, treat this just as any other attribute
  12159. const index = element.attributes.findIndex(attr => attr.name === 'this');
  12160. if (!~index) {
  12161. parser.error({
  12162. code: `missing-component-definition`,
  12163. message: `<svelte:component> must have a 'this' attribute`
  12164. }, start);
  12165. }
  12166. const definition = element.attributes.splice(index, 1)[0];
  12167. if (definition.value === true || definition.value.length !== 1 || definition.value[0].type === 'Text') {
  12168. parser.error({
  12169. code: `invalid-component-definition`,
  12170. message: `invalid component definition`
  12171. }, definition.start);
  12172. }
  12173. element.expression = definition.value[0].expression;
  12174. }
  12175. // special cases – top-level <script> and <style>
  12176. if (specials.has(name) && parser.stack.length === 1) {
  12177. const special = specials.get(name);
  12178. if (parser[special.property]) {
  12179. parser.index = start;
  12180. parser.error({
  12181. code: `duplicate-${name}`,
  12182. message: `You can only have one top-level <${name}> tag per component`
  12183. });
  12184. }
  12185. parser.eat('>', true);
  12186. parser[special.property] = special.read(parser, start, element.attributes);
  12187. return;
  12188. }
  12189. parser.current().children.push(element);
  12190. const selfClosing = parser.eat('/') || isVoidElementName(name);
  12191. parser.eat('>', true);
  12192. if (selfClosing) {
  12193. // don't push self-closing elements onto the stack
  12194. element.end = parser.index;
  12195. }
  12196. else if (name === 'textarea') {
  12197. // special case
  12198. element.children = readSequence$1(parser, () => parser.template.slice(parser.index, parser.index + 11) === '</textarea>');
  12199. parser.read(/<\/textarea>/);
  12200. element.end = parser.index;
  12201. }
  12202. else if (name === 'script') {
  12203. // special case
  12204. const start = parser.index;
  12205. const data = parser.readUntil(/<\/script>/);
  12206. const end = parser.index;
  12207. element.children.push({ start, end, type: 'Text', data });
  12208. parser.eat('</script>', true);
  12209. element.end = parser.index;
  12210. }
  12211. else if (name === 'style') {
  12212. // special case
  12213. const start = parser.index;
  12214. const data = parser.readUntil(/<\/style>/);
  12215. const end = parser.index;
  12216. element.children.push({ start, end, type: 'Text', data });
  12217. parser.eat('</style>', true);
  12218. }
  12219. else {
  12220. parser.stack.push(element);
  12221. }
  12222. }
  12223. function readTagName(parser) {
  12224. const start = parser.index;
  12225. if (parser.eat(SELF)) {
  12226. // check we're inside a block, otherwise this
  12227. // will cause infinite recursion
  12228. let i = parser.stack.length;
  12229. let legal = false;
  12230. while (i--) {
  12231. const fragment = parser.stack[i];
  12232. if (fragment.type === 'IfBlock' || fragment.type === 'EachBlock') {
  12233. legal = true;
  12234. break;
  12235. }
  12236. }
  12237. if (!legal) {
  12238. parser.error({
  12239. code: `invalid-self-placement`,
  12240. message: `<${SELF}> components can only exist inside if-blocks or each-blocks`
  12241. }, start);
  12242. }
  12243. return SELF;
  12244. }
  12245. if (parser.eat(COMPONENT))
  12246. return COMPONENT;
  12247. const name = parser.readUntil(/(\s|\/|>)/);
  12248. if (metaTags.has(name))
  12249. return name;
  12250. if (!validTagName.test(name)) {
  12251. parser.error({
  12252. code: `invalid-tag-name`,
  12253. message: `Expected valid tag name`
  12254. }, start);
  12255. }
  12256. return name;
  12257. }
  12258. function readAttribute(parser, uniqueNames) {
  12259. const start = parser.index;
  12260. if (parser.eat('{')) {
  12261. parser.allowWhitespace();
  12262. if (parser.eat('...')) {
  12263. const expression = readExpression(parser);
  12264. parser.allowWhitespace();
  12265. parser.eat('}', true);
  12266. return {
  12267. start,
  12268. end: parser.index,
  12269. type: 'Spread',
  12270. expression
  12271. };
  12272. }
  12273. else {
  12274. const valueStart = parser.index;
  12275. const name = parser.readIdentifier();
  12276. parser.allowWhitespace();
  12277. parser.eat('}', true);
  12278. return {
  12279. start,
  12280. end: parser.index,
  12281. type: 'Attribute',
  12282. name,
  12283. value: [{
  12284. start: valueStart,
  12285. end: valueStart + name.length,
  12286. type: 'AttributeShorthand',
  12287. expression: {
  12288. start: valueStart,
  12289. end: valueStart + name.length,
  12290. type: 'Identifier',
  12291. name
  12292. }
  12293. }]
  12294. };
  12295. }
  12296. }
  12297. let name = parser.readUntil(/(\s|=|\/|>)/);
  12298. if (!name)
  12299. return null;
  12300. if (uniqueNames.has(name)) {
  12301. parser.error({
  12302. code: `duplicate-attribute`,
  12303. message: 'Attributes need to be unique'
  12304. }, start);
  12305. }
  12306. uniqueNames.add(name);
  12307. parser.allowWhitespace();
  12308. const directive = readDirective(parser, start, name);
  12309. if (directive)
  12310. return directive;
  12311. let value = parser.eat('=') ? readAttributeValue(parser) : true;
  12312. return {
  12313. start,
  12314. end: parser.index,
  12315. type: 'Attribute',
  12316. name,
  12317. value,
  12318. };
  12319. }
  12320. function readAttributeValue(parser) {
  12321. const quoteMark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null;
  12322. const regex = quoteMark === `'`
  12323. ? /'/
  12324. : quoteMark === `"` ? /"/ : /[\s"'=<>\/`]/;
  12325. const value = readSequence$1(parser, () => regex.test(parser.template[parser.index]));
  12326. if (quoteMark)
  12327. parser.index += 1;
  12328. return value;
  12329. }
  12330. function readSequence$1(parser, done) {
  12331. let currentChunk = {
  12332. start: parser.index,
  12333. end: null,
  12334. type: 'Text',
  12335. data: '',
  12336. };
  12337. const chunks = [];
  12338. while (parser.index < parser.template.length) {
  12339. const index = parser.index;
  12340. if (done()) {
  12341. currentChunk.end = parser.index;
  12342. if (currentChunk.data)
  12343. chunks.push(currentChunk);
  12344. chunks.forEach(chunk => {
  12345. if (chunk.type === 'Text')
  12346. chunk.data = decodeCharacterReferences(chunk.data);
  12347. });
  12348. return chunks;
  12349. }
  12350. else if (parser.eat('{')) {
  12351. if (currentChunk.data) {
  12352. currentChunk.end = index;
  12353. chunks.push(currentChunk);
  12354. }
  12355. parser.allowWhitespace();
  12356. const expression = readExpression(parser);
  12357. parser.allowWhitespace();
  12358. parser.eat('}', true);
  12359. chunks.push({
  12360. start: index,
  12361. end: parser.index,
  12362. type: 'MustacheTag',
  12363. expression,
  12364. });
  12365. currentChunk = {
  12366. start: parser.index,
  12367. end: null,
  12368. type: 'Text',
  12369. data: '',
  12370. };
  12371. }
  12372. else {
  12373. currentChunk.data += parser.template[parser.index++];
  12374. }
  12375. }
  12376. parser.error({
  12377. code: `unexpected-eof`,
  12378. message: `Unexpected end of input`
  12379. });
  12380. }
  12381. function errorOnAssignmentPattern(parser) {
  12382. if (parser.eat('=')) {
  12383. parser.error({
  12384. code: 'invalid-assignment-pattern',
  12385. message: 'Assignment patterns are not supported'
  12386. }, parser.index - 1);
  12387. }
  12388. }
  12389. function readContext(parser) {
  12390. const context = {
  12391. start: parser.index,
  12392. end: null,
  12393. type: null
  12394. };
  12395. if (parser.eat('[')) {
  12396. context.type = 'ArrayPattern';
  12397. context.elements = [];
  12398. do {
  12399. parser.allowWhitespace();
  12400. if (parser.template[parser.index] === ',') {
  12401. context.elements.push(null);
  12402. }
  12403. else {
  12404. context.elements.push(readContext(parser));
  12405. parser.allowWhitespace();
  12406. }
  12407. } while (parser.eat(','));
  12408. errorOnAssignmentPattern(parser);
  12409. parser.eat(']', true);
  12410. }
  12411. else if (parser.eat('{')) {
  12412. context.type = 'ObjectPattern';
  12413. context.properties = [];
  12414. do {
  12415. parser.allowWhitespace();
  12416. const start = parser.index;
  12417. const name = parser.readIdentifier();
  12418. const key = {
  12419. start,
  12420. end: parser.index,
  12421. type: 'Identifier',
  12422. name
  12423. };
  12424. parser.allowWhitespace();
  12425. const value = parser.eat(':')
  12426. ? (parser.allowWhitespace(), readContext(parser))
  12427. : key;
  12428. const property = {
  12429. start,
  12430. end: value.end,
  12431. type: 'Property',
  12432. key,
  12433. value
  12434. };
  12435. context.properties.push(property);
  12436. parser.allowWhitespace();
  12437. } while (parser.eat(','));
  12438. errorOnAssignmentPattern(parser);
  12439. parser.eat('}', true);
  12440. }
  12441. else {
  12442. const name = parser.readIdentifier();
  12443. if (name) {
  12444. context.type = 'Identifier';
  12445. context.end = parser.index;
  12446. context.name = name;
  12447. }
  12448. else {
  12449. parser.error({
  12450. code: 'invalid-context',
  12451. message: 'Expected a name, array pattern or object pattern'
  12452. });
  12453. }
  12454. errorOnAssignmentPattern(parser);
  12455. }
  12456. return context;
  12457. }
  12458. const whitespace = /[ \t\r\n]/;
  12459. const dimensions = /^(?:offset|client)(?:Width|Height)$/;
  12460. function trimStart(str) {
  12461. let i = 0;
  12462. while (whitespace.test(str[i]))
  12463. i += 1;
  12464. return str.slice(i);
  12465. }
  12466. function trimEnd(str) {
  12467. let i = str.length;
  12468. while (whitespace.test(str[i - 1]))
  12469. i -= 1;
  12470. return str.slice(0, i);
  12471. }
  12472. function trimWhitespace(block, trimBefore, trimAfter) {
  12473. if (!block.children || block.children.length === 0)
  12474. return; // AwaitBlock
  12475. const firstChild = block.children[0];
  12476. const lastChild = block.children[block.children.length - 1];
  12477. if (firstChild.type === 'Text' && trimBefore) {
  12478. firstChild.data = trimStart(firstChild.data);
  12479. if (!firstChild.data)
  12480. block.children.shift();
  12481. }
  12482. if (lastChild.type === 'Text' && trimAfter) {
  12483. lastChild.data = trimEnd(lastChild.data);
  12484. if (!lastChild.data)
  12485. block.children.pop();
  12486. }
  12487. if (block.else) {
  12488. trimWhitespace(block.else, trimBefore, trimAfter);
  12489. }
  12490. if (firstChild.elseif) {
  12491. trimWhitespace(firstChild, trimBefore, trimAfter);
  12492. }
  12493. }
  12494. function mustache(parser) {
  12495. const start = parser.index;
  12496. parser.index += 1;
  12497. parser.allowWhitespace();
  12498. // {{/if}} or {{/each}}
  12499. if (parser.eat('/')) {
  12500. let block = parser.current();
  12501. let expected;
  12502. if (block.type === 'ElseBlock' || block.type === 'PendingBlock' || block.type === 'ThenBlock' || block.type === 'CatchBlock') {
  12503. block.end = start;
  12504. parser.stack.pop();
  12505. block = parser.current();
  12506. expected = 'await';
  12507. }
  12508. if (block.type === 'IfBlock') {
  12509. expected = 'if';
  12510. }
  12511. else if (block.type === 'EachBlock') {
  12512. expected = 'each';
  12513. }
  12514. else if (block.type === 'AwaitBlock') {
  12515. expected = 'await';
  12516. }
  12517. else {
  12518. parser.error({
  12519. code: `unexpected-block-close`,
  12520. message: `Unexpected block closing tag`
  12521. });
  12522. }
  12523. parser.eat(expected, true);
  12524. parser.allowWhitespace();
  12525. parser.eat('}', true);
  12526. while (block.elseif) {
  12527. block.end = parser.index;
  12528. parser.stack.pop();
  12529. block = parser.current();
  12530. if (block.else) {
  12531. block.else.end = start;
  12532. }
  12533. }
  12534. // strip leading/trailing whitespace as necessary
  12535. const charBefore = parser.template[block.start - 1];
  12536. const charAfter = parser.template[parser.index];
  12537. const trimBefore = !charBefore || whitespace.test(charBefore);
  12538. const trimAfter = !charAfter || whitespace.test(charAfter);
  12539. trimWhitespace(block, trimBefore, trimAfter);
  12540. block.end = parser.index;
  12541. parser.stack.pop();
  12542. }
  12543. else if (parser.eat(':elseif')) {
  12544. const block = parser.current();
  12545. if (block.type !== 'IfBlock')
  12546. parser.error({
  12547. code: `invalid-elseif-placement`,
  12548. message: 'Cannot have an {{elseif ...}} block outside an {{#if ...}} block'
  12549. });
  12550. parser.requireWhitespace();
  12551. const expression = readExpression(parser);
  12552. parser.allowWhitespace();
  12553. parser.eat('}', true);
  12554. block.else = {
  12555. start: parser.index,
  12556. end: null,
  12557. type: 'ElseBlock',
  12558. children: [
  12559. {
  12560. start: parser.index,
  12561. end: null,
  12562. type: 'IfBlock',
  12563. elseif: true,
  12564. expression,
  12565. children: [],
  12566. },
  12567. ],
  12568. };
  12569. parser.stack.push(block.else.children[0]);
  12570. }
  12571. else if (parser.eat(':else')) {
  12572. const block = parser.current();
  12573. if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
  12574. parser.error({
  12575. code: `invalid-else-placement`,
  12576. message: 'Cannot have an {{else}} block outside an {{#if ...}} or {{#each ...}} block'
  12577. });
  12578. }
  12579. parser.allowWhitespace();
  12580. parser.eat('}', true);
  12581. block.else = {
  12582. start: parser.index,
  12583. end: null,
  12584. type: 'ElseBlock',
  12585. children: [],
  12586. };
  12587. parser.stack.push(block.else);
  12588. }
  12589. else if (parser.eat(':then')) {
  12590. // TODO DRY out this and the next section
  12591. const pendingBlock = parser.current();
  12592. if (pendingBlock.type === 'PendingBlock') {
  12593. pendingBlock.end = start;
  12594. parser.stack.pop();
  12595. const awaitBlock = parser.current();
  12596. parser.requireWhitespace();
  12597. awaitBlock.value = parser.readIdentifier();
  12598. parser.allowWhitespace();
  12599. parser.eat('}', true);
  12600. const thenBlock = {
  12601. start,
  12602. end: null,
  12603. type: 'ThenBlock',
  12604. children: []
  12605. };
  12606. awaitBlock.then = thenBlock;
  12607. parser.stack.push(thenBlock);
  12608. }
  12609. }
  12610. else if (parser.eat(':catch')) {
  12611. const thenBlock = parser.current();
  12612. if (thenBlock.type === 'ThenBlock') {
  12613. thenBlock.end = start;
  12614. parser.stack.pop();
  12615. const awaitBlock = parser.current();
  12616. parser.requireWhitespace();
  12617. awaitBlock.error = parser.readIdentifier();
  12618. parser.allowWhitespace();
  12619. parser.eat('}', true);
  12620. const catchBlock = {
  12621. start,
  12622. end: null,
  12623. type: 'CatchBlock',
  12624. children: []
  12625. };
  12626. awaitBlock.catch = catchBlock;
  12627. parser.stack.push(catchBlock);
  12628. }
  12629. }
  12630. else if (parser.eat('#')) {
  12631. // {{#if foo}} or {{#each foo}}
  12632. let type;
  12633. if (parser.eat('if')) {
  12634. type = 'IfBlock';
  12635. }
  12636. else if (parser.eat('each')) {
  12637. type = 'EachBlock';
  12638. }
  12639. else if (parser.eat('await')) {
  12640. type = 'AwaitBlock';
  12641. }
  12642. else {
  12643. parser.error({
  12644. code: `expected-block-type`,
  12645. message: `Expected if, each or await`
  12646. });
  12647. }
  12648. parser.requireWhitespace();
  12649. const expression = readExpression(parser);
  12650. const block = type === 'AwaitBlock' ?
  12651. {
  12652. start,
  12653. end: null,
  12654. type,
  12655. expression,
  12656. value: null,
  12657. error: null,
  12658. pending: {
  12659. start: null,
  12660. end: null,
  12661. type: 'PendingBlock',
  12662. children: []
  12663. },
  12664. then: {
  12665. start: null,
  12666. end: null,
  12667. type: 'ThenBlock',
  12668. children: []
  12669. },
  12670. catch: {
  12671. start: null,
  12672. end: null,
  12673. type: 'CatchBlock',
  12674. children: []
  12675. },
  12676. } :
  12677. {
  12678. start,
  12679. end: null,
  12680. type,
  12681. expression,
  12682. children: [],
  12683. };
  12684. parser.allowWhitespace();
  12685. // {{#each}} blocks must declare a context – {{#each list as item}}
  12686. if (type === 'EachBlock') {
  12687. parser.eat('as', true);
  12688. parser.requireWhitespace();
  12689. block.context = readContext(parser);
  12690. parser.allowWhitespace();
  12691. if (parser.eat(',')) {
  12692. parser.allowWhitespace();
  12693. block.index = parser.readIdentifier();
  12694. if (!block.index)
  12695. parser.error({
  12696. code: `expected-name`,
  12697. message: `Expected name`
  12698. });
  12699. parser.allowWhitespace();
  12700. }
  12701. if (parser.eat('(')) {
  12702. parser.allowWhitespace();
  12703. block.key = readExpression(parser);
  12704. parser.allowWhitespace();
  12705. parser.eat(')', true);
  12706. parser.allowWhitespace();
  12707. }
  12708. else if (parser.eat('@')) {
  12709. block.key = parser.readIdentifier();
  12710. if (!block.key)
  12711. parser.error({
  12712. code: `expected-name`,
  12713. message: `Expected name`
  12714. });
  12715. parser.allowWhitespace();
  12716. }
  12717. }
  12718. let awaitBlockShorthand = type === 'AwaitBlock' && parser.eat('then');
  12719. if (awaitBlockShorthand) {
  12720. parser.requireWhitespace();
  12721. block.value = parser.readIdentifier();
  12722. parser.allowWhitespace();
  12723. }
  12724. parser.eat('}', true);
  12725. parser.current().children.push(block);
  12726. parser.stack.push(block);
  12727. if (type === 'AwaitBlock') {
  12728. const childBlock = awaitBlockShorthand ? block.then : block.pending;
  12729. childBlock.start = parser.index;
  12730. parser.stack.push(childBlock);
  12731. }
  12732. }
  12733. else if (parser.eat('@html')) {
  12734. // {{{raw}}} mustache
  12735. const expression = readExpression(parser);
  12736. parser.allowWhitespace();
  12737. parser.eat('}', true);
  12738. parser.current().children.push({
  12739. start,
  12740. end: parser.index,
  12741. type: 'RawMustacheTag',
  12742. expression,
  12743. });
  12744. }
  12745. else {
  12746. const expression = readExpression(parser);
  12747. parser.allowWhitespace();
  12748. parser.eat('}', true);
  12749. parser.current().children.push({
  12750. start,
  12751. end: parser.index,
  12752. type: 'MustacheTag',
  12753. expression,
  12754. });
  12755. }
  12756. }
  12757. function text(parser) {
  12758. const start = parser.index;
  12759. let data = '';
  12760. while (parser.index < parser.template.length &&
  12761. !parser.match('<') &&
  12762. !parser.match('{')) {
  12763. data += parser.template[parser.index++];
  12764. }
  12765. parser.current().children.push({
  12766. start,
  12767. end: parser.index,
  12768. type: 'Text',
  12769. data: decodeCharacterReferences(data),
  12770. });
  12771. }
  12772. function fragment(parser) {
  12773. if (parser.match('<')) {
  12774. return tag;
  12775. }
  12776. if (parser.match('{')) {
  12777. return mustache;
  12778. }
  12779. return text;
  12780. }
  12781. const reservedNames = new Set([
  12782. 'arguments',
  12783. 'await',
  12784. 'break',
  12785. 'case',
  12786. 'catch',
  12787. 'class',
  12788. 'const',
  12789. 'continue',
  12790. 'debugger',
  12791. 'default',
  12792. 'delete',
  12793. 'do',
  12794. 'else',
  12795. 'enum',
  12796. 'eval',
  12797. 'export',
  12798. 'extends',
  12799. 'false',
  12800. 'finally',
  12801. 'for',
  12802. 'function',
  12803. 'if',
  12804. 'implements',
  12805. 'import',
  12806. 'in',
  12807. 'instanceof',
  12808. 'interface',
  12809. 'let',
  12810. 'new',
  12811. 'null',
  12812. 'package',
  12813. 'private',
  12814. 'protected',
  12815. 'public',
  12816. 'return',
  12817. 'static',
  12818. 'super',
  12819. 'switch',
  12820. 'this',
  12821. 'throw',
  12822. 'true',
  12823. 'try',
  12824. 'typeof',
  12825. 'var',
  12826. 'void',
  12827. 'while',
  12828. 'with',
  12829. 'yield',
  12830. ]);
  12831. // Adapted from https://github.com/acornjs/acorn/blob/6584815dca7440e00de841d1dad152302fdd7ca5/src/tokenize.js
  12832. // Reproduced under MIT License https://github.com/acornjs/acorn/blob/master/LICENSE
  12833. function fullCharCodeAt(str, i) {
  12834. let code = str.charCodeAt(i);
  12835. if (code <= 0xd7ff || code >= 0xe000)
  12836. return code;
  12837. let next = str.charCodeAt(i + 1);
  12838. return (code << 10) + next - 0x35fdc00;
  12839. }
  12840. function getLocator(source, options) {
  12841. if (options === void 0) { options = {}; }
  12842. var offsetLine = options.offsetLine || 0;
  12843. var offsetColumn = options.offsetColumn || 0;
  12844. var originalLines = source.split('\n');
  12845. var start = 0;
  12846. var lineRanges = originalLines.map(function (line, i) {
  12847. var end = start + line.length + 1;
  12848. var range = { start: start, end: end, line: i };
  12849. start = end;
  12850. return range;
  12851. });
  12852. var i = 0;
  12853. function rangeContains(range, index) {
  12854. return range.start <= index && index < range.end;
  12855. }
  12856. function getLocation(range, index) {
  12857. return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };
  12858. }
  12859. function locate(search, startIndex) {
  12860. if (typeof search === 'string') {
  12861. search = source.indexOf(search, startIndex || 0);
  12862. }
  12863. var range = lineRanges[i];
  12864. var d = search >= range.end ? 1 : -1;
  12865. while (range) {
  12866. if (rangeContains(range, search))
  12867. return getLocation(range, search);
  12868. i += d;
  12869. range = lineRanges[i];
  12870. }
  12871. }
  12872. return locate;
  12873. }
  12874. function locate(source, search, options) {
  12875. if (typeof options === 'number') {
  12876. throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument');
  12877. }
  12878. return getLocator(source, options)(search, options && options.startIndex);
  12879. }
  12880. function tabsToSpaces(str) {
  12881. return str.replace(/^\t+/, match => match.split('\t').join(' '));
  12882. }
  12883. function getCodeFrame(source, line, column) {
  12884. const lines = source.split('\n');
  12885. const frameStart = Math.max(0, line - 2);
  12886. const frameEnd = Math.min(line + 3, lines.length);
  12887. const digits = String(frameEnd + 1).length;
  12888. return lines
  12889. .slice(frameStart, frameEnd)
  12890. .map((str, i) => {
  12891. const isErrorLine = frameStart + i === line;
  12892. let lineNum = String(i + frameStart + 1);
  12893. while (lineNum.length < digits)
  12894. lineNum = ` ${lineNum}`;
  12895. if (isErrorLine) {
  12896. const indicator = repeat(' ', digits + 2 + tabsToSpaces(str.slice(0, column)).length) + '^';
  12897. return `${lineNum}: ${tabsToSpaces(str)}\n${indicator}`;
  12898. }
  12899. return `${lineNum}: ${tabsToSpaces(str)}`;
  12900. })
  12901. .join('\n');
  12902. }
  12903. class CompileError extends Error {
  12904. toString() {
  12905. return `${this.message} (${this.start.line}:${this.start.column})\n${this.frame}`;
  12906. }
  12907. }
  12908. function error$2(message, props) {
  12909. const error = new CompileError(message);
  12910. error.name = props.name;
  12911. const start = locate(props.source, props.start, { offsetLine: 1 });
  12912. const end = locate(props.source, props.end || props.start, { offsetLine: 1 });
  12913. error.code = props.code;
  12914. error.start = start;
  12915. error.end = end;
  12916. error.pos = props.start;
  12917. error.filename = props.filename;
  12918. error.frame = getCodeFrame(props.source, start.line - 1, start.column);
  12919. throw error;
  12920. }
  12921. class Parser$1 {
  12922. constructor(template, options) {
  12923. if (typeof template !== 'string') {
  12924. throw new TypeError('Template must be a string');
  12925. }
  12926. this.template = template.replace(/\s+$/, '');
  12927. this.filename = options.filename;
  12928. this.customElement = options.customElement;
  12929. this.allowBindings = options.bind !== false;
  12930. this.index = 0;
  12931. this.stack = [];
  12932. this.metaTags = {};
  12933. this.html = {
  12934. start: null,
  12935. end: null,
  12936. type: 'Fragment',
  12937. children: [],
  12938. };
  12939. this.css = null;
  12940. this.js = null;
  12941. this.stack.push(this.html);
  12942. let state = fragment;
  12943. while (this.index < this.template.length) {
  12944. state = state(this) || fragment;
  12945. }
  12946. if (this.stack.length > 1) {
  12947. const current = this.current();
  12948. const type = current.type === 'Element' ? `<${current.name}>` : 'Block';
  12949. const slug = current.type === 'Element' ? 'element' : 'block';
  12950. this.error({
  12951. code: `unclosed-${slug}`,
  12952. message: `${type} was left open`
  12953. }, current.start);
  12954. }
  12955. if (state !== fragment) {
  12956. this.error({
  12957. code: `unexpected-eof`,
  12958. message: 'Unexpected end of input'
  12959. });
  12960. }
  12961. if (this.html.children.length) {
  12962. let start = this.html.children[0] && this.html.children[0].start;
  12963. while (/\s/.test(template[start]))
  12964. start += 1;
  12965. let end = this.html.children[this.html.children.length - 1] && this.html.children[this.html.children.length - 1].end;
  12966. while (/\s/.test(template[end - 1]))
  12967. end -= 1;
  12968. this.html.start = start;
  12969. this.html.end = end;
  12970. }
  12971. else {
  12972. this.html.start = this.html.end = null;
  12973. }
  12974. }
  12975. current() {
  12976. return this.stack[this.stack.length - 1];
  12977. }
  12978. acornError(err) {
  12979. this.error({
  12980. code: `parse-error`,
  12981. message: err.message.replace(/ \(\d+:\d+\)$/, '')
  12982. }, err.pos);
  12983. }
  12984. error({ code, message }, index = this.index) {
  12985. error$2(message, {
  12986. name: 'ParseError',
  12987. code,
  12988. source: this.template,
  12989. start: index,
  12990. filename: this.filename
  12991. });
  12992. }
  12993. eat(str, required, message) {
  12994. if (this.match(str)) {
  12995. this.index += str.length;
  12996. return true;
  12997. }
  12998. if (required) {
  12999. this.error({
  13000. code: `unexpected-${this.index === this.template.length ? 'eof' : 'token'}`,
  13001. message: message || `Expected ${str}`
  13002. });
  13003. }
  13004. return false;
  13005. }
  13006. match(str) {
  13007. return this.template.slice(this.index, this.index + str.length) === str;
  13008. }
  13009. allowWhitespace() {
  13010. while (this.index < this.template.length &&
  13011. whitespace.test(this.template[this.index])) {
  13012. this.index++;
  13013. }
  13014. }
  13015. read(pattern) {
  13016. const match = pattern.exec(this.template.slice(this.index));
  13017. if (!match || match.index !== 0)
  13018. return null;
  13019. this.index += match[0].length;
  13020. return match[0];
  13021. }
  13022. readIdentifier() {
  13023. const start = this.index;
  13024. let i = this.index;
  13025. const code = fullCharCodeAt(this.template, i);
  13026. if (!isIdentifierStart(code, true))
  13027. return null;
  13028. i += code <= 0xffff ? 1 : 2;
  13029. while (i < this.template.length) {
  13030. const code = fullCharCodeAt(this.template, i);
  13031. if (!isIdentifierChar(code, true))
  13032. break;
  13033. i += code <= 0xffff ? 1 : 2;
  13034. }
  13035. const identifier = this.template.slice(this.index, this.index = i);
  13036. if (reservedNames.has(identifier)) {
  13037. this.error({
  13038. code: `unexpected-reserved-word`,
  13039. message: `'${identifier}' is a reserved word in JavaScript and cannot be used here`
  13040. }, start);
  13041. }
  13042. return identifier;
  13043. }
  13044. readUntil(pattern) {
  13045. if (this.index >= this.template.length)
  13046. this.error({
  13047. code: `unexpected-eof`,
  13048. message: 'Unexpected end of input'
  13049. });
  13050. const start = this.index;
  13051. const match = pattern.exec(this.template.slice(start));
  13052. if (match) {
  13053. this.index = start + match.index;
  13054. return this.template.slice(start, this.index);
  13055. }
  13056. this.index = this.template.length;
  13057. return this.template.slice(start);
  13058. }
  13059. remaining() {
  13060. return this.template.slice(this.index);
  13061. }
  13062. requireWhitespace() {
  13063. if (!whitespace.test(this.template[this.index])) {
  13064. this.error({
  13065. code: `missing-whitespace`,
  13066. message: `Expected whitespace`
  13067. });
  13068. }
  13069. this.allowWhitespace();
  13070. }
  13071. }
  13072. function parse$1(template, options = {}) {
  13073. const parser = new Parser$1(template, options);
  13074. return {
  13075. html: parser.html,
  13076. css: parser.css,
  13077. js: parser.js,
  13078. };
  13079. }
  13080. const disallowed = new Set(['Literal', 'ObjectExpression', 'ArrayExpression']);
  13081. function data$1(validator, prop) {
  13082. while (prop.type === 'ParenthesizedExpression')
  13083. prop = prop.expression;
  13084. if (disallowed.has(prop.value.type)) {
  13085. validator.error(prop.value, {
  13086. code: `invalid-data-property`,
  13087. message: `'data' must be a function`
  13088. });
  13089. }
  13090. }
  13091. function getMethodName(node) {
  13092. if (node.type === 'Identifier')
  13093. return node.name;
  13094. if (node.type === 'Literal')
  13095. return String(node.value);
  13096. }
  13097. function checkForDupes(validator, properties) {
  13098. const seen = new Set();
  13099. properties.forEach(prop => {
  13100. const name = getMethodName(prop.key);
  13101. if (seen.has(name)) {
  13102. validator.error(prop, {
  13103. code: `duplicate-property`,
  13104. message: `Duplicate property '${name}'`
  13105. });
  13106. }
  13107. seen.add(name);
  13108. });
  13109. }
  13110. function checkForComputedKeys(validator, properties) {
  13111. properties.forEach(prop => {
  13112. if (prop.key.computed) {
  13113. validator.error(prop, {
  13114. code: `computed-key`,
  13115. message: `Cannot use computed keys`
  13116. });
  13117. }
  13118. });
  13119. }
  13120. function actions(validator, prop) {
  13121. if (prop.value.type !== 'ObjectExpression') {
  13122. validator.error(prop, {
  13123. code: `invalid-actions`,
  13124. message: `The 'actions' property must be an object literal`
  13125. });
  13126. }
  13127. checkForDupes(validator, prop.value.properties);
  13128. checkForComputedKeys(validator, prop.value.properties);
  13129. }
  13130. function transitions(validator, prop) {
  13131. if (prop.value.type !== 'ObjectExpression') {
  13132. validator.error(prop, {
  13133. code: `invalid-transitions-property`,
  13134. message: `The 'transitions' property must be an object literal`
  13135. });
  13136. }
  13137. checkForDupes(validator, prop.value.properties);
  13138. checkForComputedKeys(validator, prop.value.properties);
  13139. prop.value.properties.forEach(() => {
  13140. // TODO probably some validation that can happen here...
  13141. // checking for use of `this` etc?
  13142. });
  13143. }
  13144. function isValidIdentifier(str) {
  13145. let i = 0;
  13146. while (i < str.length) {
  13147. const code = fullCharCodeAt(str, i);
  13148. if (!(i === 0 ? isIdentifierStart : isIdentifierChar)(code, true))
  13149. return false;
  13150. i += code <= 0xffff ? 1 : 2;
  13151. }
  13152. return true;
  13153. }
  13154. function walkThroughTopFunctionScope(body, callback) {
  13155. let lexicalDepth = 0;
  13156. walk(body, {
  13157. enter(node) {
  13158. if (/^Function/.test(node.type)) {
  13159. lexicalDepth += 1;
  13160. }
  13161. else if (lexicalDepth === 0) {
  13162. callback(node);
  13163. }
  13164. },
  13165. leave(node) {
  13166. if (/^Function/.test(node.type)) {
  13167. lexicalDepth -= 1;
  13168. }
  13169. },
  13170. });
  13171. }
  13172. function isThisGetCallExpression(node) {
  13173. return node.type === 'CallExpression' &&
  13174. node.callee.type === 'MemberExpression' &&
  13175. node.callee.object.type === 'ThisExpression' &&
  13176. node.callee.property.name === 'get';
  13177. }
  13178. const isFunctionExpression = new Set([
  13179. 'FunctionExpression',
  13180. 'ArrowFunctionExpression',
  13181. ]);
  13182. function computed(validator, prop) {
  13183. if (prop.value.type !== 'ObjectExpression') {
  13184. validator.error(prop, {
  13185. code: `invalid-computed-property`,
  13186. message: `The 'computed' property must be an object literal`
  13187. });
  13188. }
  13189. checkForDupes(validator, prop.value.properties);
  13190. checkForComputedKeys(validator, prop.value.properties);
  13191. prop.value.properties.forEach((computation) => {
  13192. const name = getMethodName(computation.key);
  13193. if (!isValidIdentifier(name)) {
  13194. const suggestion = name.replace(/[^_$a-z0-9]/ig, '_').replace(/^\d/, '_$&');
  13195. validator.error(computation.key, {
  13196. code: `invalid-computed-name`,
  13197. message: `Computed property name '${name}' is invalid — must be a valid identifier such as ${suggestion}`
  13198. });
  13199. }
  13200. if (reservedNames.has(name)) {
  13201. validator.error(computation.key, {
  13202. code: `invalid-computed-name`,
  13203. message: `Computed property name '${name}' is invalid — cannot be a JavaScript reserved word`
  13204. });
  13205. }
  13206. if (!isFunctionExpression.has(computation.value.type)) {
  13207. validator.error(computation.value, {
  13208. code: `invalid-computed-value`,
  13209. message: `Computed properties can be function expressions or arrow function expressions`
  13210. });
  13211. }
  13212. const { body, params } = computation.value;
  13213. walkThroughTopFunctionScope(body, (node) => {
  13214. if (isThisGetCallExpression(node) && !node.callee.property.computed) {
  13215. validator.error(node, {
  13216. code: `impure-computed`,
  13217. message: `Cannot use this.get(...) — values must be passed into the function as arguments`
  13218. });
  13219. }
  13220. if (node.type === 'ThisExpression') {
  13221. validator.error(node, {
  13222. code: `impure-computed`,
  13223. 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'?`
  13224. });
  13225. }
  13226. });
  13227. if (params.length === 0) {
  13228. validator.error(computation.value, {
  13229. code: `impure-computed`,
  13230. message: `A computed value must depend on at least one property`
  13231. });
  13232. }
  13233. if (params.length > 1) {
  13234. validator.error(computation.value, {
  13235. code: `invalid-computed-arguments`,
  13236. message: `Computed properties must take a single argument`
  13237. });
  13238. }
  13239. });
  13240. }
  13241. function isReference(node, parent) {
  13242. if (node.type === 'MemberExpression') {
  13243. return !node.computed && isReference(node.object, node);
  13244. }
  13245. if (node.type === 'Identifier') {
  13246. // the only time we could have an identifier node without a parent is
  13247. // if it's the entire body of a function without a block statement –
  13248. // i.e. an arrow function expression like `a => a`
  13249. if (!parent)
  13250. return true;
  13251. // TODO is this right?
  13252. if (parent.type === 'MemberExpression' || parent.type === 'MethodDefinition') {
  13253. return parent.computed || node === parent.object;
  13254. }
  13255. // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
  13256. if (parent.type === 'Property')
  13257. return parent.computed || node === parent.value;
  13258. // disregard the `bar` in `export { foo as bar }`
  13259. if (parent.type === 'ExportSpecifier' && node !== parent.local)
  13260. return false;
  13261. return true;
  13262. }
  13263. return false;
  13264. }
  13265. function usesThisOrArguments(node) {
  13266. let result = false;
  13267. walk(node, {
  13268. enter(node, parent) {
  13269. if (result ||
  13270. node.type === 'FunctionExpression' ||
  13271. node.type === 'FunctionDeclaration') {
  13272. return this.skip();
  13273. }
  13274. if (node.type === 'ThisExpression') {
  13275. result = true;
  13276. }
  13277. if (node.type === 'Identifier' &&
  13278. isReference(node, parent) &&
  13279. node.name === 'arguments') {
  13280. result = true;
  13281. }
  13282. },
  13283. });
  13284. return result;
  13285. }
  13286. function oncreate(validator, prop) {
  13287. if (prop.value.type === 'ArrowFunctionExpression') {
  13288. if (usesThisOrArguments(prop.value.body)) {
  13289. validator.error(prop, {
  13290. code: `invalid-oncreate-property`,
  13291. message: `'oncreate' should be a function expression, not an arrow function expression`
  13292. });
  13293. }
  13294. }
  13295. }
  13296. function ondestroy(validator, prop) {
  13297. if (prop.value.type === 'ArrowFunctionExpression') {
  13298. if (usesThisOrArguments(prop.value.body)) {
  13299. validator.error(prop, {
  13300. code: `invalid-ondestroy-property`,
  13301. message: `'ondestroy' should be a function expression, not an arrow function expression`
  13302. });
  13303. }
  13304. }
  13305. }
  13306. function onstate(validator, prop) {
  13307. if (prop.value.type === 'ArrowFunctionExpression') {
  13308. if (usesThisOrArguments(prop.value.body)) {
  13309. validator.error(prop, {
  13310. code: `invalid-onstate-property`,
  13311. message: `'onstate' should be a function expression, not an arrow function expression`
  13312. });
  13313. }
  13314. }
  13315. }
  13316. function onupdate(validator, prop) {
  13317. if (prop.value.type === 'ArrowFunctionExpression') {
  13318. if (usesThisOrArguments(prop.value.body)) {
  13319. validator.error(prop, {
  13320. code: `invalid-onupdate-property`,
  13321. message: `'onupdate' should be a function expression, not an arrow function expression`
  13322. });
  13323. }
  13324. }
  13325. }
  13326. function onrender(validator, prop) {
  13327. validator.warn(prop, {
  13328. code: `deprecated-onrender`,
  13329. message: `'onrender' has been deprecated in favour of 'oncreate', and will cause an error in Svelte 2.x`
  13330. });
  13331. oncreate(validator, prop);
  13332. }
  13333. function onteardown(validator, prop) {
  13334. validator.warn(prop, {
  13335. code: `deprecated-onteardown`,
  13336. message: `'onteardown' has been deprecated in favour of 'ondestroy', and will cause an error in Svelte 2.x`
  13337. });
  13338. ondestroy(validator, prop);
  13339. }
  13340. function helpers(validator, prop) {
  13341. if (prop.value.type !== 'ObjectExpression') {
  13342. validator.error(prop, {
  13343. code: `invalid-helpers-property`,
  13344. message: `The 'helpers' property must be an object literal`
  13345. });
  13346. }
  13347. checkForDupes(validator, prop.value.properties);
  13348. checkForComputedKeys(validator, prop.value.properties);
  13349. prop.value.properties.forEach((prop) => {
  13350. if (!/FunctionExpression/.test(prop.value.type))
  13351. return;
  13352. let usesArguments = false;
  13353. walkThroughTopFunctionScope(prop.value.body, (node) => {
  13354. if (isThisGetCallExpression(node) && !node.callee.property.computed) {
  13355. validator.error(node, {
  13356. code: `impure-helper`,
  13357. message: `Cannot use this.get(...) — values must be passed into the helper function as arguments`
  13358. });
  13359. }
  13360. if (node.type === 'ThisExpression') {
  13361. validator.error(node, {
  13362. code: `impure-helper`,
  13363. 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'?`
  13364. });
  13365. }
  13366. else if (node.type === 'Identifier' && node.name === 'arguments') {
  13367. usesArguments = true;
  13368. }
  13369. });
  13370. if (prop.value.params.length === 0 && !usesArguments) {
  13371. validator.warn(prop, {
  13372. code: `impure-helper`,
  13373. message: `Helpers should be pure functions, with at least one argument`
  13374. });
  13375. }
  13376. });
  13377. }
  13378. function checkForAccessors(validator, properties, label) {
  13379. properties.forEach(prop => {
  13380. if (prop.kind !== 'init') {
  13381. validator.error(prop, {
  13382. code: `illegal-accessor`,
  13383. message: `${label} cannot use getters and setters`
  13384. });
  13385. }
  13386. });
  13387. }
  13388. const builtin = new Set(['set', 'get', 'on', 'fire', 'destroy']);
  13389. function methods(validator, prop) {
  13390. if (prop.value.type !== 'ObjectExpression') {
  13391. validator.error(prop, {
  13392. code: `invalid-methods-property`,
  13393. message: `The 'methods' property must be an object literal`
  13394. });
  13395. }
  13396. checkForAccessors(validator, prop.value.properties, 'Methods');
  13397. checkForDupes(validator, prop.value.properties);
  13398. checkForComputedKeys(validator, prop.value.properties);
  13399. prop.value.properties.forEach((prop) => {
  13400. const name = getMethodName(prop.key);
  13401. if (builtin.has(name)) {
  13402. validator.error(prop, {
  13403. code: `invalid-method-name`,
  13404. message: `Cannot overwrite built-in method '${name}'`
  13405. });
  13406. }
  13407. if (prop.value.type === 'ArrowFunctionExpression') {
  13408. if (usesThisOrArguments(prop.value.body)) {
  13409. validator.error(prop, {
  13410. code: `invalid-method-value`,
  13411. message: `Method '${prop.key.name}' should be a function expression, not an arrow function expression`
  13412. });
  13413. }
  13414. }
  13415. });
  13416. }
  13417. function components(validator, prop) {
  13418. if (prop.value.type !== 'ObjectExpression') {
  13419. validator.error(prop, {
  13420. code: `invalid-components-property`,
  13421. message: `The 'components' property must be an object literal`
  13422. });
  13423. }
  13424. checkForDupes(validator, prop.value.properties);
  13425. checkForComputedKeys(validator, prop.value.properties);
  13426. prop.value.properties.forEach((component) => {
  13427. const name = getMethodName(component.key);
  13428. if (name === 'state') {
  13429. // TODO is this still true?
  13430. validator.error(component, {
  13431. code: `invalid-name`,
  13432. message: `Component constructors cannot be called 'state' due to technical limitations`
  13433. });
  13434. }
  13435. if (!/^[A-Z]/.test(name)) {
  13436. validator.error(component, {
  13437. code: `component-lowercase`,
  13438. message: `Component names must be capitalised`
  13439. });
  13440. }
  13441. });
  13442. }
  13443. function events(validator, prop) {
  13444. if (prop.value.type !== 'ObjectExpression') {
  13445. validator.error(prop, {
  13446. code: `invalid-events-property`,
  13447. message: `The 'events' property must be an object literal`
  13448. });
  13449. }
  13450. checkForDupes(validator, prop.value.properties);
  13451. checkForComputedKeys(validator, prop.value.properties);
  13452. }
  13453. const html = 'http://www.w3.org/1999/xhtml';
  13454. const mathml = 'http://www.w3.org/1998/Math/MathML';
  13455. const svg = 'http://www.w3.org/2000/svg';
  13456. const xlink = 'http://www.w3.org/1999/xlink';
  13457. const xml = 'http://www.w3.org/XML/1998/namespace';
  13458. const xmlns = 'http://www.w3.org/2000/xmlns';
  13459. const validNamespaces = [
  13460. 'html',
  13461. 'mathml',
  13462. 'svg',
  13463. 'xlink',
  13464. 'xml',
  13465. 'xmlns',
  13466. html,
  13467. mathml,
  13468. svg,
  13469. xlink,
  13470. xml,
  13471. xmlns,
  13472. ];
  13473. const namespaces = { html, mathml, svg, xlink, xml, xmlns };
  13474. function nodeToString(node) {
  13475. if (node.type === 'Literal' && typeof node.value === 'string') {
  13476. return node.value;
  13477. }
  13478. else if (node.type === 'TemplateLiteral'
  13479. && node.quasis.length === 1
  13480. && node.expressions.length === 0) {
  13481. return node.quasis[0].value.raw;
  13482. }
  13483. }
  13484. // adapted from https://github.com/Glench/fuzzyset.js/blob/master/lib/fuzzyset.js
  13485. // BSD Licensed
  13486. const GRAM_SIZE_LOWER = 2;
  13487. const GRAM_SIZE_UPPER = 3;
  13488. // return an edit distance from 0 to 1
  13489. function _distance(str1, str2) {
  13490. if (str1 === null && str2 === null)
  13491. throw 'Trying to compare two null values';
  13492. if (str1 === null || str2 === null)
  13493. return 0;
  13494. str1 = String(str1);
  13495. str2 = String(str2);
  13496. const distance = levenshtein(str1, str2);
  13497. if (str1.length > str2.length) {
  13498. return 1 - distance / str1.length;
  13499. }
  13500. else {
  13501. return 1 - distance / str2.length;
  13502. }
  13503. }
  13504. // helper functions
  13505. function levenshtein(str1, str2) {
  13506. const current = [];
  13507. let prev;
  13508. let value;
  13509. for (let i = 0; i <= str2.length; i++) {
  13510. for (let j = 0; j <= str1.length; j++) {
  13511. if (i && j) {
  13512. if (str1.charAt(j - 1) === str2.charAt(i - 1)) {
  13513. value = prev;
  13514. }
  13515. else {
  13516. value = Math.min(current[j], current[j - 1], prev) + 1;
  13517. }
  13518. }
  13519. else {
  13520. value = i + j;
  13521. }
  13522. prev = current[j];
  13523. current[j] = value;
  13524. }
  13525. }
  13526. return current.pop();
  13527. }
  13528. const _nonWordRe = /[^\w, ]+/;
  13529. function _iterateGrams(value, gramSize) {
  13530. gramSize = gramSize || 2;
  13531. const simplified = '-' + value.toLowerCase().replace(_nonWordRe, '') + '-';
  13532. const lenDiff = gramSize - simplified.length;
  13533. const results = [];
  13534. if (lenDiff > 0) {
  13535. for (let i = 0; i < lenDiff; ++i) {
  13536. value += '-';
  13537. }
  13538. }
  13539. for (let i = 0; i < simplified.length - gramSize + 1; ++i) {
  13540. results.push(simplified.slice(i, i + gramSize));
  13541. }
  13542. return results;
  13543. }
  13544. function _gramCounter(value, gramSize) {
  13545. // return an object where key=gram, value=number of occurrences
  13546. gramSize = gramSize || 2;
  13547. const result = {};
  13548. const grams = _iterateGrams(value, gramSize);
  13549. let i = 0;
  13550. for (i; i < grams.length; ++i) {
  13551. if (grams[i] in result) {
  13552. result[grams[i]] += 1;
  13553. }
  13554. else {
  13555. result[grams[i]] = 1;
  13556. }
  13557. }
  13558. return result;
  13559. }
  13560. function sortDescending(a, b) {
  13561. return b[0] - a[0];
  13562. }
  13563. class FuzzySet {
  13564. constructor(arr) {
  13565. // define all the object functions and attributes
  13566. this.exactSet = {};
  13567. this.matchDict = {};
  13568. this.items = {};
  13569. // initialization
  13570. for (let i = GRAM_SIZE_LOWER; i < GRAM_SIZE_UPPER + 1; ++i) {
  13571. this.items[i] = [];
  13572. }
  13573. // add all the items to the set
  13574. for (let i = 0; i < arr.length; ++i) {
  13575. this.add(arr[i]);
  13576. }
  13577. }
  13578. add(value) {
  13579. const normalizedValue = value.toLowerCase();
  13580. if (normalizedValue in this.exactSet) {
  13581. return false;
  13582. }
  13583. let i = GRAM_SIZE_LOWER;
  13584. for (i; i < GRAM_SIZE_UPPER + 1; ++i) {
  13585. this._add(value, i);
  13586. }
  13587. }
  13588. _add(value, gramSize) {
  13589. const normalizedValue = value.toLowerCase();
  13590. const items = this.items[gramSize] || [];
  13591. const index = items.length;
  13592. items.push(0);
  13593. const gramCounts = _gramCounter(normalizedValue, gramSize);
  13594. let sumOfSquareGramCounts = 0;
  13595. let gram;
  13596. let gramCount;
  13597. for (gram in gramCounts) {
  13598. gramCount = gramCounts[gram];
  13599. sumOfSquareGramCounts += Math.pow(gramCount, 2);
  13600. if (gram in this.matchDict) {
  13601. this.matchDict[gram].push([index, gramCount]);
  13602. }
  13603. else {
  13604. this.matchDict[gram] = [[index, gramCount]];
  13605. }
  13606. }
  13607. const vectorNormal = Math.sqrt(sumOfSquareGramCounts);
  13608. items[index] = [vectorNormal, normalizedValue];
  13609. this.items[gramSize] = items;
  13610. this.exactSet[normalizedValue] = value;
  13611. }
  13612. ;
  13613. get(value) {
  13614. const normalizedValue = value.toLowerCase();
  13615. const result = this.exactSet[normalizedValue];
  13616. if (result) {
  13617. return [[1, result]];
  13618. }
  13619. let results = [];
  13620. // start with high gram size and if there are no results, go to lower gram sizes
  13621. for (let gramSize = GRAM_SIZE_UPPER; gramSize >= GRAM_SIZE_LOWER; --gramSize) {
  13622. results = this.__get(value, gramSize);
  13623. if (results) {
  13624. return results;
  13625. }
  13626. }
  13627. return null;
  13628. }
  13629. __get(value, gramSize) {
  13630. const normalizedValue = value.toLowerCase();
  13631. const matches = {};
  13632. const gramCounts = _gramCounter(normalizedValue, gramSize);
  13633. const items = this.items[gramSize];
  13634. let sumOfSquareGramCounts = 0;
  13635. let gram;
  13636. let gramCount;
  13637. let i;
  13638. let index;
  13639. let otherGramCount;
  13640. for (gram in gramCounts) {
  13641. gramCount = gramCounts[gram];
  13642. sumOfSquareGramCounts += Math.pow(gramCount, 2);
  13643. if (gram in this.matchDict) {
  13644. for (i = 0; i < this.matchDict[gram].length; ++i) {
  13645. index = this.matchDict[gram][i][0];
  13646. otherGramCount = this.matchDict[gram][i][1];
  13647. if (index in matches) {
  13648. matches[index] += gramCount * otherGramCount;
  13649. }
  13650. else {
  13651. matches[index] = gramCount * otherGramCount;
  13652. }
  13653. }
  13654. }
  13655. }
  13656. const vectorNormal = Math.sqrt(sumOfSquareGramCounts);
  13657. let results = [];
  13658. let matchScore;
  13659. // build a results list of [score, str]
  13660. for (const matchIndex in matches) {
  13661. matchScore = matches[matchIndex];
  13662. results.push([
  13663. matchScore / (vectorNormal * items[matchIndex][0]),
  13664. items[matchIndex][1],
  13665. ]);
  13666. }
  13667. results.sort(sortDescending);
  13668. let newResults = [];
  13669. const endIndex = Math.min(50, results.length);
  13670. // truncate somewhat arbitrarily to 50
  13671. for (let i = 0; i < endIndex; ++i) {
  13672. newResults.push([
  13673. _distance(results[i][1], normalizedValue),
  13674. results[i][1],
  13675. ]);
  13676. }
  13677. results = newResults;
  13678. results.sort(sortDescending);
  13679. newResults = [];
  13680. for (let i = 0; i < results.length; ++i) {
  13681. if (results[i][0] == results[0][0]) {
  13682. newResults.push([results[i][0], this.exactSet[results[i][1]]]);
  13683. }
  13684. }
  13685. return newResults;
  13686. }
  13687. ;
  13688. }
  13689. function fuzzymatch(name, names) {
  13690. const set = new FuzzySet(names);
  13691. const matches = set.get(name);
  13692. return matches && matches[0] && matches[0][0] > 0.7 ? matches[0][1] : null;
  13693. }
  13694. const valid = new Set(validNamespaces);
  13695. function namespace(validator, prop) {
  13696. const ns = nodeToString(prop.value);
  13697. if (typeof ns !== 'string') {
  13698. validator.error(prop, {
  13699. code: `invalid-namespace-property`,
  13700. message: `The 'namespace' property must be a string literal representing a valid namespace`
  13701. });
  13702. }
  13703. if (!valid.has(ns)) {
  13704. const match = fuzzymatch(ns, validNamespaces);
  13705. if (match) {
  13706. validator.error(prop, {
  13707. code: `invalid-namespace-property`,
  13708. message: `Invalid namespace '${ns}' (did you mean '${match}'?)`
  13709. });
  13710. }
  13711. else {
  13712. validator.error(prop, {
  13713. code: `invalid-namespace-property`,
  13714. message: `Invalid namespace '${ns}'`
  13715. });
  13716. }
  13717. }
  13718. }
  13719. function preload(validator, prop) {
  13720. // not sure there's anything we need to check here...
  13721. }
  13722. function props(validator, prop) {
  13723. if (prop.value.type !== 'ArrayExpression') {
  13724. validator.error(prop.value, {
  13725. code: `invalid-props-property`,
  13726. message: `'props' must be an array expression, if specified`
  13727. });
  13728. }
  13729. prop.value.elements.forEach((element) => {
  13730. if (typeof nodeToString(element) !== 'string') {
  13731. validator.error(element, {
  13732. code: `invalid-props-property`,
  13733. message: `'props' must be an array of string literals`
  13734. });
  13735. }
  13736. });
  13737. }
  13738. function tag$1(validator, prop) {
  13739. const tag = nodeToString(prop.value);
  13740. if (typeof tag !== 'string') {
  13741. validator.error(prop.value, {
  13742. code: `invalid-tag-property`,
  13743. message: `'tag' must be a string literal`
  13744. });
  13745. }
  13746. if (!/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) {
  13747. validator.error(prop.value, {
  13748. code: `invalid-tag-property`,
  13749. message: `tag name must be two or more words joined by the '-' character`
  13750. });
  13751. }
  13752. }
  13753. function transitions$1(validator, prop) {
  13754. if (prop.value.type !== 'ObjectExpression') {
  13755. validator.error(prop, {
  13756. code: `invalid-transitions-property`,
  13757. message: `The 'transitions' property must be an object literal`
  13758. });
  13759. }
  13760. checkForDupes(validator, prop.value.properties);
  13761. checkForComputedKeys(validator, prop.value.properties);
  13762. prop.value.properties.forEach(() => {
  13763. // TODO probably some validation that can happen here...
  13764. // checking for use of `this` etc?
  13765. });
  13766. }
  13767. const disallowed$1 = new Set(['Literal', 'ObjectExpression', 'ArrayExpression']);
  13768. function setup(validator, prop) {
  13769. while (prop.type === 'ParenthesizedExpression')
  13770. prop = prop.expression;
  13771. if (disallowed$1.has(prop.value.type)) {
  13772. validator.error(prop.value, {
  13773. code: `invalid-setup-property`,
  13774. message: `'setup' must be a function`
  13775. });
  13776. }
  13777. }
  13778. function store(validator, prop) {
  13779. // not sure there's anything we need to check here...
  13780. }
  13781. function immutable(validator, prop) {
  13782. if (prop.value.type !== 'Literal' || typeof prop.value.value !== 'boolean') {
  13783. validator.error(prop.value, {
  13784. code: `invalid-immutable-property`,
  13785. message: `'immutable' must be a boolean literal`
  13786. });
  13787. }
  13788. }
  13789. var propValidators = {
  13790. data: data$1,
  13791. actions,
  13792. animations: transitions,
  13793. computed,
  13794. oncreate,
  13795. ondestroy,
  13796. onstate,
  13797. onupdate,
  13798. onrender,
  13799. onteardown,
  13800. helpers,
  13801. methods,
  13802. components,
  13803. events,
  13804. namespace,
  13805. preload,
  13806. props,
  13807. tag: tag$1,
  13808. transitions: transitions$1,
  13809. setup,
  13810. store,
  13811. immutable,
  13812. };
  13813. const validPropList = Object.keys(propValidators);
  13814. function validateJs(validator, js) {
  13815. js.content.body.forEach((node) => {
  13816. // check there are no named exports
  13817. if (node.type === 'ExportNamedDeclaration') {
  13818. validator.error(node, {
  13819. code: `named-export`,
  13820. message: `A component can only have a default export`
  13821. });
  13822. }
  13823. if (node.type === 'ExportDefaultDeclaration') {
  13824. if (node.declaration.type !== 'ObjectExpression') {
  13825. validator.error(node.declaration, {
  13826. code: `invalid-default-export`,
  13827. message: `Default export must be an object literal`
  13828. });
  13829. }
  13830. checkForComputedKeys(validator, node.declaration.properties);
  13831. checkForDupes(validator, node.declaration.properties);
  13832. const props = validator.properties;
  13833. node.declaration.properties.forEach((prop) => {
  13834. props.set(getMethodName(prop.key), prop);
  13835. });
  13836. // Remove these checks in version 2
  13837. if (props.has('oncreate') && props.has('onrender')) {
  13838. validator.error(props.get('onrender'), {
  13839. code: `duplicate-oncreate`,
  13840. message: 'Cannot have both oncreate and onrender'
  13841. });
  13842. }
  13843. if (props.has('ondestroy') && props.has('onteardown')) {
  13844. validator.error(props.get('onteardown'), {
  13845. code: `duplicate-ondestroy`,
  13846. message: 'Cannot have both ondestroy and onteardown'
  13847. });
  13848. }
  13849. // ensure all exported props are valid
  13850. node.declaration.properties.forEach((prop) => {
  13851. const name = getMethodName(prop.key);
  13852. const propValidator = propValidators[name];
  13853. if (propValidator) {
  13854. propValidator(validator, prop);
  13855. }
  13856. else {
  13857. const match = fuzzymatch(name, validPropList);
  13858. if (match) {
  13859. validator.error(prop, {
  13860. code: `unexpected-property`,
  13861. message: `Unexpected property '${name}' (did you mean '${match}'?)`
  13862. });
  13863. }
  13864. else if (/FunctionExpression/.test(prop.value.type)) {
  13865. validator.error(prop, {
  13866. code: `unexpected-property`,
  13867. message: `Unexpected property '${name}' (did you mean to include it in 'methods'?)`
  13868. });
  13869. }
  13870. else {
  13871. validator.error(prop, {
  13872. code: `unexpected-property`,
  13873. message: `Unexpected property '${name}'`
  13874. });
  13875. }
  13876. }
  13877. });
  13878. if (props.has('namespace')) {
  13879. const ns = nodeToString(props.get('namespace').value);
  13880. validator.namespace = namespaces[ns] || ns;
  13881. }
  13882. validator.defaultExport = node;
  13883. }
  13884. });
  13885. ['components', 'methods', 'helpers', 'transitions', 'animations', 'actions'].forEach(key => {
  13886. if (validator.properties.has(key)) {
  13887. validator.properties.get(key).value.properties.forEach((prop) => {
  13888. validator[key].set(getMethodName(prop.key), prop.value);
  13889. });
  13890. }
  13891. });
  13892. }
  13893. function flattenReference(node) {
  13894. if (node.type === 'Expression')
  13895. throw new Error('bad');
  13896. const nodes = [];
  13897. const parts = [];
  13898. const propEnd = node.end;
  13899. while (node.type === 'MemberExpression') {
  13900. if (node.computed)
  13901. return null;
  13902. nodes.unshift(node.property);
  13903. parts.unshift(node.property.name);
  13904. node = node.object;
  13905. }
  13906. const propStart = node.end;
  13907. const name = node.type === 'Identifier'
  13908. ? node.name
  13909. : node.type === 'ThisExpression' ? 'this' : null;
  13910. if (!name)
  13911. return null;
  13912. parts.unshift(name);
  13913. nodes.unshift(node);
  13914. return { name, nodes, parts, keypath: `${name}[✂${propStart}-${propEnd}✂]` };
  13915. }
  13916. function list$2(items, conjunction = 'or') {
  13917. if (items.length === 1)
  13918. return items[0];
  13919. return `${items.slice(0, -1).join(', ')} ${conjunction} ${items[items.length - 1]}`;
  13920. }
  13921. const validCalleeObjects = new Set(['this', 'event', 'console']);
  13922. const validBuiltins = new Set(['set', 'fire', 'destroy']);
  13923. function validateEventHandlerCallee(validator, attribute, refCallees) {
  13924. if (!attribute.expression)
  13925. return;
  13926. const { callee, type } = attribute.expression;
  13927. if (type !== 'CallExpression') {
  13928. validator.error(attribute.expression, {
  13929. code: `invalid-event-handler`,
  13930. message: `Expected a call expression`
  13931. });
  13932. }
  13933. const { name } = flattenReference(callee);
  13934. if (validCalleeObjects.has(name) || name === 'options')
  13935. return;
  13936. if (name === 'refs') {
  13937. refCallees.push(callee);
  13938. return;
  13939. }
  13940. if ((callee.type === 'Identifier' && validBuiltins.has(callee.name)) ||
  13941. validator.methods.has(callee.name)) {
  13942. return;
  13943. }
  13944. if (name[0] === '$') {
  13945. // assume it's a store method
  13946. return;
  13947. }
  13948. const validCallees = ['this.*', 'event.*', 'options.*', 'console.*'].concat(Array.from(validBuiltins), Array.from(validator.methods.keys()));
  13949. let message = `'${validator.source.slice(callee.start, callee.end)}' is an invalid callee `;
  13950. if (name === 'store') {
  13951. message += `(did you mean '$${validator.source.slice(callee.start + 6, callee.end)}(...)'?)`;
  13952. }
  13953. else {
  13954. message += `(should be one of ${list$2(validCallees)})`;
  13955. if (callee.type === 'Identifier' && validator.helpers.has(callee.name)) {
  13956. message += `. '${callee.name}' exists on 'helpers', did you put it in the wrong place?`;
  13957. }
  13958. }
  13959. validator.warn(attribute.expression, {
  13960. code: `invalid-callee`,
  13961. message
  13962. });
  13963. }
  13964. function validateComponent(validator, node, refs, refCallees, stack, elementStack) {
  13965. if (node.name !== 'svelte:self' && node.name !== 'svelte:component' && !validator.components.has(node.name)) {
  13966. validator.error(node, {
  13967. code: `missing-component`,
  13968. message: `${node.name} component is not defined`
  13969. });
  13970. }
  13971. validator.used.components.add(node.name);
  13972. node.attributes.forEach((attribute) => {
  13973. if (attribute.type === 'Ref') {
  13974. if (!refs.has(attribute.name))
  13975. refs.set(attribute.name, []);
  13976. refs.get(attribute.name).push(node);
  13977. }
  13978. if (attribute.type === 'EventHandler') {
  13979. validator.used.events.add(attribute.name);
  13980. validateEventHandlerCallee(validator, attribute, refCallees);
  13981. }
  13982. else if (attribute.type === 'Transition') {
  13983. validator.error(attribute, {
  13984. code: `invalid-transition`,
  13985. message: `Transitions can only be applied to DOM elements, not components`
  13986. });
  13987. }
  13988. else if (attribute.type === 'Action') {
  13989. validator.error(attribute, {
  13990. code: `invalid-action`,
  13991. message: `Actions can only be applied to DOM elements, not components`
  13992. });
  13993. }
  13994. });
  13995. }
  13996. 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)$/;
  13997. function validateElement(validator, node, refs, refCallees, stack, elementStack) {
  13998. if (elementStack.length === 0 && validator.namespace !== svg && svg$1.test(node.name)) {
  13999. validator.warn(node, {
  14000. code: `missing-namespace`,
  14001. message: `<${node.name}> is an SVG element – did you forget to add { namespace: 'svg' } ?`
  14002. });
  14003. }
  14004. if (node.name === 'slot') {
  14005. const nameAttribute = node.attributes.find((attribute) => attribute.name === 'name');
  14006. if (nameAttribute) {
  14007. if (nameAttribute.value.length !== 1 || nameAttribute.value[0].type !== 'Text') {
  14008. validator.error(nameAttribute, {
  14009. code: `dynamic-slot-name`,
  14010. message: `<slot> name cannot be dynamic`
  14011. });
  14012. }
  14013. const slotName = nameAttribute.value[0].data;
  14014. if (slotName === 'default') {
  14015. validator.error(nameAttribute, {
  14016. code: `invalid-slot-name`,
  14017. message: `default is a reserved word — it cannot be used as a slot name`
  14018. });
  14019. }
  14020. // TODO should duplicate slots be disallowed? Feels like it's more likely to be a
  14021. // bug than anything. Perhaps it should be a warning
  14022. // if (validator.slots.has(slotName)) {
  14023. // validator.error(`duplicate '${slotName}' <slot> element`, nameAttribute.start);
  14024. // }
  14025. // validator.slots.add(slotName);
  14026. }
  14027. else {
  14028. // if (validator.slots.has('default')) {
  14029. // validator.error(`duplicate default <slot> element`, node.start);
  14030. // }
  14031. // validator.slots.add('default');
  14032. }
  14033. }
  14034. if (node.name === 'title') {
  14035. if (node.attributes.length > 0) {
  14036. validator.error(node.attributes[0], {
  14037. code: `illegal-attribute`,
  14038. message: `<title> cannot have attributes`
  14039. });
  14040. }
  14041. node.children.forEach(child => {
  14042. if (child.type !== 'Text' && child.type !== 'MustacheTag') {
  14043. validator.error(child, {
  14044. code: 'illegal-structure',
  14045. message: `<title> can only contain text and {{tags}}`
  14046. });
  14047. }
  14048. });
  14049. }
  14050. let hasIntro;
  14051. let hasOutro;
  14052. let hasTransition;
  14053. let hasAnimation;
  14054. node.attributes.forEach((attribute) => {
  14055. if (attribute.type === 'Ref') {
  14056. if (!refs.has(attribute.name))
  14057. refs.set(attribute.name, []);
  14058. refs.get(attribute.name).push(node);
  14059. }
  14060. if (attribute.type === 'Binding') {
  14061. const { name } = attribute;
  14062. if (name === 'value') {
  14063. if (node.name !== 'input' &&
  14064. node.name !== 'textarea' &&
  14065. node.name !== 'select') {
  14066. validator.error(attribute, {
  14067. code: `invalid-binding`,
  14068. message: `'value' is not a valid binding on <${node.name}> elements`
  14069. });
  14070. }
  14071. if (node.name === 'select') {
  14072. const attribute = node.attributes.find((attribute) => attribute.name === 'multiple');
  14073. if (attribute && isDynamic(attribute)) {
  14074. validator.error(attribute, {
  14075. code: `dynamic-multiple-attribute`,
  14076. message: `'multiple' attribute cannot be dynamic if select uses two-way binding`
  14077. });
  14078. }
  14079. }
  14080. else {
  14081. checkTypeAttribute(validator, node);
  14082. }
  14083. }
  14084. else if (name === 'checked' || name === 'indeterminate') {
  14085. if (node.name !== 'input') {
  14086. validator.error(attribute, {
  14087. code: `invalid-binding`,
  14088. message: `'${name}' is not a valid binding on <${node.name}> elements`
  14089. });
  14090. }
  14091. if (checkTypeAttribute(validator, node) !== 'checkbox') {
  14092. validator.error(attribute, {
  14093. code: `invalid-binding`,
  14094. message: `'${name}' binding can only be used with <input type="checkbox">`
  14095. });
  14096. }
  14097. }
  14098. else if (name === 'group') {
  14099. if (node.name !== 'input') {
  14100. validator.error(attribute, {
  14101. code: `invalid-binding`,
  14102. message: `'group' is not a valid binding on <${node.name}> elements`
  14103. });
  14104. }
  14105. const type = checkTypeAttribute(validator, node);
  14106. if (type !== 'checkbox' && type !== 'radio') {
  14107. validator.error(attribute, {
  14108. code: `invalid-binding`,
  14109. message: `'checked' binding can only be used with <input type="checkbox"> or <input type="radio">`
  14110. });
  14111. }
  14112. }
  14113. else if (name === 'currentTime' ||
  14114. name === 'duration' ||
  14115. name === 'paused' ||
  14116. name === 'buffered' ||
  14117. name === 'seekable' ||
  14118. name === 'played' ||
  14119. name === 'volume') {
  14120. if (node.name !== 'audio' && node.name !== 'video') {
  14121. validator.error(attribute, {
  14122. code: `invalid-binding`,
  14123. message: `'${name}' binding can only be used with <audio> or <video>`
  14124. });
  14125. }
  14126. }
  14127. else if (dimensions.test(name)) {
  14128. if (node.name === 'svg' && (name === 'offsetWidth' || name === 'offsetHeight')) {
  14129. validator.error(attribute, {
  14130. code: 'invalid-binding',
  14131. message: `'${attribute.name}' is not a valid binding on <svg>. Use '${name.replace('offset', 'client')}' instead`
  14132. });
  14133. }
  14134. else if (svg$1.test(node.name)) {
  14135. validator.error(attribute, {
  14136. code: 'invalid-binding',
  14137. message: `'${attribute.name}' is not a valid binding on SVG elements`
  14138. });
  14139. }
  14140. else if (isVoidElementName(node.name)) {
  14141. validator.error(attribute, {
  14142. code: 'invalid-binding',
  14143. message: `'${attribute.name}' is not a valid binding on void elements like <${node.name}>. Use a wrapper element instead`
  14144. });
  14145. }
  14146. }
  14147. else {
  14148. validator.error(attribute, {
  14149. code: `invalid-binding`,
  14150. message: `'${attribute.name}' is not a valid binding`
  14151. });
  14152. }
  14153. }
  14154. else if (attribute.type === 'EventHandler') {
  14155. validator.used.events.add(attribute.name);
  14156. validateEventHandlerCallee(validator, attribute, refCallees);
  14157. }
  14158. else if (attribute.type === 'Transition') {
  14159. validator.used.transitions.add(attribute.name);
  14160. const bidi = attribute.intro && attribute.outro;
  14161. if (hasTransition) {
  14162. if (bidi) {
  14163. validator.error(attribute, {
  14164. code: `duplicate-transition`,
  14165. message: `An element can only have one 'transition' directive`
  14166. });
  14167. }
  14168. validator.error(attribute, {
  14169. code: `duplicate-transition`,
  14170. message: `An element cannot have both a 'transition' directive and an '${attribute.intro ? 'in' : 'out'}' directive`
  14171. });
  14172. }
  14173. if ((hasIntro && attribute.intro) || (hasOutro && attribute.outro)) {
  14174. if (bidi) {
  14175. validator.error(attribute, {
  14176. code: `duplicate-transition`,
  14177. message: `An element cannot have both an '${hasIntro ? 'in' : 'out'}' directive and a 'transition' directive`
  14178. });
  14179. }
  14180. validator.error(attribute, {
  14181. code: `duplicate-transition`,
  14182. message: `An element can only have one '${hasIntro ? 'in' : 'out'}' directive`
  14183. });
  14184. }
  14185. if (attribute.intro)
  14186. hasIntro = true;
  14187. if (attribute.outro)
  14188. hasOutro = true;
  14189. if (bidi)
  14190. hasTransition = true;
  14191. if (!validator.transitions.has(attribute.name)) {
  14192. validator.error(attribute, {
  14193. code: `missing-transition`,
  14194. message: `Missing transition '${attribute.name}'`
  14195. });
  14196. }
  14197. }
  14198. else if (attribute.type === 'Animation') {
  14199. validator.used.animations.add(attribute.name);
  14200. if (hasAnimation) {
  14201. validator.error(attribute, {
  14202. code: `duplicate-animation`,
  14203. message: `An element can only have one 'animate' directive`
  14204. });
  14205. }
  14206. if (!validator.animations.has(attribute.name)) {
  14207. validator.error(attribute, {
  14208. code: `missing-animation`,
  14209. message: `Missing animation '${attribute.name}'`
  14210. });
  14211. }
  14212. const parent = stack[stack.length - 1];
  14213. if (!parent || parent.type !== 'EachBlock' || !parent.key) {
  14214. // TODO can we relax the 'immediate child' rule?
  14215. validator.error(attribute, {
  14216. code: `invalid-animation`,
  14217. message: `An element that use the animate directive must be the immediate child of a keyed each block`
  14218. });
  14219. }
  14220. if (parent.children.length > 1) {
  14221. validator.error(attribute, {
  14222. code: `invalid-animation`,
  14223. message: `An element that use the animate directive must be the sole child of a keyed each block`
  14224. });
  14225. }
  14226. hasAnimation = true;
  14227. }
  14228. else if (attribute.type === 'Attribute') {
  14229. if (attribute.name === 'value' && node.name === 'textarea') {
  14230. if (node.children.length) {
  14231. validator.error(attribute, {
  14232. code: `textarea-duplicate-value`,
  14233. message: `A <textarea> can have either a value attribute or (equivalently) child content, but not both`
  14234. });
  14235. }
  14236. }
  14237. if (attribute.name === 'slot') {
  14238. checkSlotAttribute(validator, node, attribute, stack);
  14239. }
  14240. }
  14241. else if (attribute.type === 'Action') {
  14242. validator.used.actions.add(attribute.name);
  14243. if (!validator.actions.has(attribute.name)) {
  14244. validator.error(attribute, {
  14245. code: `missing-action`,
  14246. message: `Missing action '${attribute.name}'`
  14247. });
  14248. }
  14249. }
  14250. });
  14251. }
  14252. function checkTypeAttribute(validator, node) {
  14253. const attribute = node.attributes.find((attribute) => attribute.name === 'type');
  14254. if (!attribute)
  14255. return null;
  14256. if (attribute.value === true) {
  14257. validator.error(attribute, {
  14258. code: `missing-type`,
  14259. message: `'type' attribute must be specified`
  14260. });
  14261. }
  14262. if (isDynamic(attribute)) {
  14263. validator.error(attribute, {
  14264. code: `invalid-type`,
  14265. message: `'type' attribute cannot be dynamic if input uses two-way binding`
  14266. });
  14267. }
  14268. return attribute.value[0].data;
  14269. }
  14270. function checkSlotAttribute(validator, node, attribute, stack) {
  14271. if (isDynamic(attribute)) {
  14272. validator.error(attribute, {
  14273. code: `invalid-slot-attribute`,
  14274. message: `slot attribute cannot have a dynamic value`
  14275. });
  14276. }
  14277. let i = stack.length;
  14278. while (i--) {
  14279. const parent = stack[i];
  14280. if (parent.type === 'Component') {
  14281. // if we're inside a component or a custom element, gravy
  14282. if (parent.name === 'svelte:self' || parent.name === 'svelte:component' || validator.components.has(parent.name))
  14283. return;
  14284. }
  14285. else if (parent.type === 'Element') {
  14286. if (/-/.test(parent.name))
  14287. return;
  14288. }
  14289. if (parent.type === 'IfBlock' || parent.type === 'EachBlock') {
  14290. const message = `Cannot place slotted elements inside an ${parent.type === 'IfBlock' ? 'if' : 'each'}-block`;
  14291. validator.error(attribute, {
  14292. code: `invalid-slotted-content`,
  14293. message
  14294. });
  14295. }
  14296. }
  14297. validator.error(attribute, {
  14298. code: `invalid-slotted-content`,
  14299. message: `Element with a slot='...' attribute must be a descendant of a component or custom element`
  14300. });
  14301. }
  14302. function isDynamic(attribute) {
  14303. if (attribute.value === true)
  14304. return false;
  14305. return attribute.value.length > 1 || attribute.value[0].type !== 'Text';
  14306. }
  14307. const validBindings = [
  14308. 'innerWidth',
  14309. 'innerHeight',
  14310. 'outerWidth',
  14311. 'outerHeight',
  14312. 'scrollX',
  14313. 'scrollY',
  14314. 'online'
  14315. ];
  14316. function validateWindow(validator, node, refs, refCallees) {
  14317. node.attributes.forEach((attribute) => {
  14318. if (attribute.type === 'Binding') {
  14319. if (attribute.value.type !== 'Identifier') {
  14320. const { parts } = flattenReference(attribute.value);
  14321. validator.error(attribute.value, {
  14322. code: `invalid-binding`,
  14323. message: `Bindings on <svelte:window> must be to top-level properties, e.g. '${parts[parts.length - 1]}' rather than '${parts.join('.')}'`
  14324. });
  14325. }
  14326. if (!~validBindings.indexOf(attribute.name)) {
  14327. const match = attribute.name === 'width'
  14328. ? 'innerWidth'
  14329. : attribute.name === 'height'
  14330. ? 'innerHeight'
  14331. : fuzzymatch(attribute.name, validBindings);
  14332. const message = `'${attribute.name}' is not a valid binding on <svelte:window>`;
  14333. if (match) {
  14334. validator.error(attribute, {
  14335. code: `invalid-binding`,
  14336. message: `${message} (did you mean '${match}'?)`
  14337. });
  14338. }
  14339. else {
  14340. validator.error(attribute, {
  14341. code: `invalid-binding`,
  14342. message: `${message} — valid bindings are ${list$2(validBindings)}`
  14343. });
  14344. }
  14345. }
  14346. }
  14347. else if (attribute.type === 'EventHandler') {
  14348. validator.used.events.add(attribute.name);
  14349. validateEventHandlerCallee(validator, attribute, refCallees);
  14350. }
  14351. });
  14352. }
  14353. function validateHead(validator, node, refs, refCallees) {
  14354. if (node.attributes.length) {
  14355. validator.error(node.attributes[0], {
  14356. code: `invalid-attribute`,
  14357. message: `<svelte:head> should not have any attributes or directives`
  14358. });
  14359. }
  14360. // TODO ensure only valid elements are included here
  14361. node.children.forEach(node => {
  14362. if (node.type !== 'Element' && node.type !== 'Title')
  14363. return; // TODO handle {{#if}} and friends?
  14364. validateElement(validator, node, refs, refCallees, [], []);
  14365. });
  14366. }
  14367. function validateSlot(validator, node) {
  14368. node.attributes.forEach(attr => {
  14369. if (attr.type !== 'Attribute') {
  14370. validator.error(attr, {
  14371. code: `invalid-slot-directive`,
  14372. message: `<slot> cannot have directives`
  14373. });
  14374. }
  14375. if (attr.name !== 'name') {
  14376. validator.error(attr, {
  14377. code: `invalid-slot-attribute`,
  14378. message: `"name" is the only attribute permitted on <slot> elements`
  14379. });
  14380. }
  14381. if (attr.value.length !== 1 || attr.value[0].type !== 'Text') {
  14382. validator.error(attr, {
  14383. code: `dynamic-slot-name`,
  14384. message: `<slot> name cannot be dynamic`
  14385. });
  14386. }
  14387. const slotName = attr.value[0].data;
  14388. if (slotName === 'default') {
  14389. validator.error(attr, {
  14390. code: `invalid-slot-name`,
  14391. message: `default is a reserved word — it cannot be used as a slot name`
  14392. });
  14393. }
  14394. // TODO should duplicate slots be disallowed? Feels like it's more likely to be a
  14395. // bug than anything. Perhaps it should be a warning
  14396. // if (validator.slots.has(slotName)) {
  14397. // validator.error(`duplicate '${slotName}' <slot> element`, nameAttribute.start);
  14398. // }
  14399. // validator.slots.add(slotName);
  14400. });
  14401. // if (node.attributes.length === 0) && validator.slots.has('default')) {
  14402. // validator.error(node, {
  14403. // code: `duplicate-slot`,
  14404. // message: `duplicate default <slot> element`
  14405. // });
  14406. // }
  14407. }
  14408. function getStaticAttributeValue(node, name) {
  14409. const attribute = node.attributes.find((attr) => attr.type === 'Attribute' && attr.name.toLowerCase() === name);
  14410. if (!attribute)
  14411. return null;
  14412. if (attribute.value === true)
  14413. return true;
  14414. if (attribute.value.length === 0)
  14415. return '';
  14416. if (attribute.value.length === 1 && attribute.value[0].type === 'Text') {
  14417. return attribute.value[0].data;
  14418. }
  14419. return null;
  14420. }
  14421. 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(' ');
  14422. const ariaAttributeSet = new Set(ariaAttributes);
  14423. 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(' ');
  14424. const ariaRoleSet = new Set(ariaRoles);
  14425. const invisibleElements = new Set(['meta', 'html', 'script', 'style']);
  14426. function a11y(validator, node, elementStack) {
  14427. if (node.type === 'Text') {
  14428. // accessible-emoji
  14429. return;
  14430. }
  14431. if (node.type !== 'Element')
  14432. return;
  14433. const attributeMap = new Map();
  14434. node.attributes.forEach((attribute) => {
  14435. if (attribute.type === 'Spread')
  14436. return;
  14437. const name = attribute.name.toLowerCase();
  14438. // aria-props
  14439. if (name.startsWith('aria-')) {
  14440. if (invisibleElements.has(node.name)) {
  14441. // aria-unsupported-elements
  14442. validator.warn(attribute, {
  14443. code: `a11y-aria-attributes`,
  14444. message: `A11y: <${node.name}> should not have aria-* attributes`
  14445. });
  14446. }
  14447. const type = name.slice(5);
  14448. if (!ariaAttributeSet.has(type)) {
  14449. const match = fuzzymatch(type, ariaAttributes);
  14450. let message = `A11y: Unknown aria attribute 'aria-${type}'`;
  14451. if (match)
  14452. message += ` (did you mean '${match}'?)`;
  14453. validator.warn(attribute, {
  14454. code: `a11y-unknown-aria-attribute`,
  14455. message
  14456. });
  14457. }
  14458. }
  14459. // aria-role
  14460. if (name === 'role') {
  14461. if (invisibleElements.has(node.name)) {
  14462. // aria-unsupported-elements
  14463. validator.warn(attribute, {
  14464. code: `a11y-misplaced-role`,
  14465. message: `A11y: <${node.name}> should not have role attribute`
  14466. });
  14467. }
  14468. const value = getStaticAttributeValue(node, 'role');
  14469. if (value && !ariaRoleSet.has(value)) {
  14470. const match = fuzzymatch(value, ariaRoles);
  14471. let message = `A11y: Unknown role '${value}'`;
  14472. if (match)
  14473. message += ` (did you mean '${match}'?)`;
  14474. validator.warn(attribute, {
  14475. code: `a11y-unknown-role`,
  14476. message
  14477. });
  14478. }
  14479. }
  14480. // no-access-key
  14481. if (name === 'accesskey') {
  14482. validator.warn(attribute, {
  14483. code: `a11y-accesskey`,
  14484. message: `A11y: Avoid using accesskey`
  14485. });
  14486. }
  14487. // no-autofocus
  14488. if (name === 'autofocus') {
  14489. validator.warn(attribute, {
  14490. code: `a11y-autofocus`,
  14491. message: `A11y: Avoid using autofocus`
  14492. });
  14493. }
  14494. // scope
  14495. if (name === 'scope' && node.name !== 'th') {
  14496. validator.warn(attribute, {
  14497. code: `a11y-misplaced-scope`,
  14498. message: `A11y: The scope attribute should only be used with <th> elements`
  14499. });
  14500. }
  14501. // tabindex-no-positive
  14502. if (name === 'tabindex') {
  14503. const value = getStaticAttributeValue(node, 'tabindex');
  14504. if (!isNaN(value) && +value > 0) {
  14505. validator.warn(attribute, {
  14506. code: `a11y-positive-tabindex`,
  14507. message: `A11y: avoid tabindex values above zero`
  14508. });
  14509. }
  14510. }
  14511. attributeMap.set(attribute.name, attribute);
  14512. });
  14513. function shouldHaveAttribute(attributes, name = node.name) {
  14514. if (attributes.length === 0 || !attributes.some((name) => attributeMap.has(name))) {
  14515. const article = /^[aeiou]/.test(attributes[0]) ? 'an' : 'a';
  14516. const sequence = attributes.length > 1 ?
  14517. attributes.slice(0, -1).join(', ') + ` or ${attributes[attributes.length - 1]}` :
  14518. attributes[0];
  14519. validator.warn(node, {
  14520. code: `a11y-missing-attribute`,
  14521. message: `A11y: <${name}> element should have ${article} ${sequence} attribute`
  14522. });
  14523. }
  14524. }
  14525. function shouldHaveContent() {
  14526. if (node.children.length === 0) {
  14527. validator.warn(node, {
  14528. code: `a11y-missing-content`,
  14529. message: `A11y: <${node.name}> element should have child content`
  14530. });
  14531. }
  14532. }
  14533. function shouldHaveValidHref(attribute) {
  14534. const href = attributeMap.get(attribute);
  14535. const value = getStaticAttributeValue(node, attribute);
  14536. if (value === '' || value === '#') {
  14537. validator.warn(href, {
  14538. code: `a11y-invalid-attribute`,
  14539. message: `A11y: '${value}' is not a valid ${attribute} attribute`
  14540. });
  14541. }
  14542. }
  14543. if (node.name === 'a') {
  14544. if (attributeMap.has('href')) {
  14545. // anchor-is-valid
  14546. shouldHaveValidHref('href');
  14547. }
  14548. else if (attributeMap.has('xlink:href')) {
  14549. // anchor-in-svg-is-valid
  14550. shouldHaveValidHref('xlink:href');
  14551. }
  14552. else {
  14553. validator.warn(node, {
  14554. code: `a11y-missing-attribute`,
  14555. message: `A11y: <a> element should have an href attribute`
  14556. });
  14557. }
  14558. // anchor-has-content
  14559. shouldHaveContent();
  14560. }
  14561. if (node.name === 'img')
  14562. shouldHaveAttribute(['alt']);
  14563. if (node.name === 'area')
  14564. shouldHaveAttribute(['alt', 'aria-label', 'aria-labelledby']);
  14565. if (node.name === 'object')
  14566. shouldHaveAttribute(['title', 'aria-label', 'aria-labelledby']);
  14567. if (node.name === 'input' && getStaticAttributeValue(node, 'type') === 'image') {
  14568. shouldHaveAttribute(['alt', 'aria-label', 'aria-labelledby'], 'input type="image"');
  14569. }
  14570. // heading-has-content
  14571. if (/^h[1-6]$/.test(node.name)) {
  14572. shouldHaveContent();
  14573. if (attributeMap.has('aria-hidden')) {
  14574. validator.warn(attributeMap.get('aria-hidden'), {
  14575. code: `a11y-hidden`,
  14576. message: `A11y: <${node.name}> element should not be hidden`
  14577. });
  14578. }
  14579. }
  14580. // iframe-has-title
  14581. if (node.name === 'iframe') {
  14582. shouldHaveAttribute(['title']);
  14583. }
  14584. // html-has-lang
  14585. if (node.name === 'html') {
  14586. shouldHaveAttribute(['lang']);
  14587. }
  14588. // no-distracting-elements
  14589. if (node.name === 'marquee' || node.name === 'blink') {
  14590. validator.warn(node, {
  14591. code: `a11y-distracting-elements`,
  14592. message: `A11y: Avoid <${node.name}> elements`
  14593. });
  14594. }
  14595. if (node.name === 'figcaption') {
  14596. const parent = elementStack[elementStack.length - 1];
  14597. if (parent) {
  14598. if (parent.name !== 'figure') {
  14599. validator.warn(node, {
  14600. code: `a11y-structure`,
  14601. message: `A11y: <figcaption> must be an immediate child of <figure>`
  14602. });
  14603. }
  14604. else {
  14605. const children = parent.children.filter(node => {
  14606. if (node.type === 'Comment')
  14607. return false;
  14608. if (node.type === 'Text')
  14609. return /\S/.test(node.data);
  14610. return true;
  14611. });
  14612. const index = children.indexOf(node);
  14613. if (index !== 0 && index !== children.length - 1) {
  14614. validator.warn(node, {
  14615. code: `a11y-structure`,
  14616. message: `A11y: <figcaption> must be first or last child of <figure>`
  14617. });
  14618. }
  14619. }
  14620. }
  14621. }
  14622. }
  14623. function unpackDestructuring(contexts, node, tail) {
  14624. if (!node)
  14625. return;
  14626. if (node.type === 'Identifier') {
  14627. contexts.push({
  14628. key: node,
  14629. tail
  14630. });
  14631. }
  14632. else if (node.type === 'ArrayPattern') {
  14633. node.elements.forEach((element, i) => {
  14634. unpackDestructuring(contexts, element, `${tail}[${i}]`);
  14635. });
  14636. }
  14637. else if (node.type === 'ObjectPattern') {
  14638. node.properties.forEach((property) => {
  14639. unpackDestructuring(contexts, property.value, `${tail}.${property.key.name}`);
  14640. });
  14641. }
  14642. }
  14643. function isEmptyBlock(node) {
  14644. if (!/Block$/.test(node.type) || !node.children)
  14645. return false;
  14646. if (node.children.length > 1)
  14647. return false;
  14648. const child = node.children[0];
  14649. return !child || (child.type === 'Text' && !/\S/.test(child.data));
  14650. }
  14651. function validateHtml(validator, html) {
  14652. const refs = new Map();
  14653. const refCallees = [];
  14654. const stack = [];
  14655. const elementStack = [];
  14656. function visit(node) {
  14657. if (node.type === 'Window') {
  14658. validateWindow(validator, node, refs, refCallees);
  14659. }
  14660. else if (node.type === 'Head') {
  14661. validateHead(validator, node, refs, refCallees);
  14662. }
  14663. else if (node.type === 'Slot') {
  14664. validateSlot(validator, node);
  14665. }
  14666. else if (node.type === 'Component' || node.name === 'svelte:self' || node.name === 'svelte:component') {
  14667. validateComponent(validator, node, refs, refCallees, stack, elementStack);
  14668. }
  14669. else if (node.type === 'Element') {
  14670. validateElement(validator, node, refs, refCallees, stack, elementStack);
  14671. a11y(validator, node, elementStack);
  14672. }
  14673. else if (node.type === 'EachBlock') {
  14674. const contexts = [];
  14675. unpackDestructuring(contexts, node.context, '');
  14676. contexts.forEach(prop => {
  14677. if (validator.helpers.has(prop.key.name)) {
  14678. validator.warn(prop.key, {
  14679. code: `each-context-clash`,
  14680. message: `Context clashes with a helper. Rename one or the other to eliminate any ambiguity`
  14681. });
  14682. }
  14683. });
  14684. }
  14685. if (validator.options.dev && isEmptyBlock(node)) {
  14686. validator.warn(node, {
  14687. code: `empty-block`,
  14688. message: 'Empty block'
  14689. });
  14690. }
  14691. if (node.children) {
  14692. if (node.type === 'Element')
  14693. elementStack.push(node);
  14694. stack.push(node);
  14695. node.children.forEach(visit);
  14696. stack.pop();
  14697. if (node.type === 'Element')
  14698. elementStack.pop();
  14699. }
  14700. if (node.else) {
  14701. visit(node.else);
  14702. }
  14703. if (node.type === 'AwaitBlock') {
  14704. visit(node.pending);
  14705. visit(node.then);
  14706. visit(node.catch);
  14707. }
  14708. }
  14709. html.children.forEach(visit);
  14710. refCallees.forEach(callee => {
  14711. const { parts } = flattenReference(callee);
  14712. const ref = parts[1];
  14713. if (refs.has(ref)) {
  14714. // TODO check method is valid, e.g. `audio.stop()` should be `audio.pause()`
  14715. }
  14716. else {
  14717. const match = fuzzymatch(ref, Array.from(refs.keys()));
  14718. let message = `'refs.${ref}' does not exist`;
  14719. if (match)
  14720. message += ` (did you mean 'refs.${match}'?)`;
  14721. validator.error(callee, {
  14722. code: `missing-ref`,
  14723. message
  14724. });
  14725. }
  14726. });
  14727. }
  14728. class Validator {
  14729. constructor(ast, source, stats, options) {
  14730. this.source = source;
  14731. this.stats = stats;
  14732. this.filename = options.filename;
  14733. this.options = options;
  14734. this.namespace = null;
  14735. this.defaultExport = null;
  14736. this.properties = new Map();
  14737. this.components = new Map();
  14738. this.methods = new Map();
  14739. this.helpers = new Map();
  14740. this.animations = new Map();
  14741. this.transitions = new Map();
  14742. this.actions = new Map();
  14743. this.slots = new Set();
  14744. this.used = {
  14745. components: new Set(),
  14746. helpers: new Set(),
  14747. events: new Set(),
  14748. animations: new Set(),
  14749. transitions: new Set(),
  14750. actions: new Set(),
  14751. };
  14752. }
  14753. error(pos, { code, message }) {
  14754. error$2(message, {
  14755. name: 'ValidationError',
  14756. code,
  14757. source: this.source,
  14758. start: pos.start,
  14759. end: pos.end,
  14760. filename: this.filename
  14761. });
  14762. }
  14763. warn(pos, { code, message }) {
  14764. if (!this.locator)
  14765. this.locator = getLocator(this.source, { offsetLine: 1 });
  14766. const start = this.locator(pos.start);
  14767. const end = this.locator(pos.end);
  14768. const frame = getCodeFrame(this.source, start.line - 1, start.column);
  14769. this.stats.warn({
  14770. code,
  14771. message,
  14772. frame,
  14773. start,
  14774. end,
  14775. pos: pos.start,
  14776. filename: this.filename,
  14777. toString: () => `${message} (${start.line + 1}:${start.column})\n${frame}`,
  14778. });
  14779. }
  14780. }
  14781. function validate(ast, source, stylesheet, stats, options) {
  14782. const { onerror, name, filename, dev, parser } = options;
  14783. try {
  14784. if (name && !/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name)) {
  14785. const error = new Error(`options.name must be a valid identifier (got '${name}')`);
  14786. throw error;
  14787. }
  14788. if (name && /^[a-z]/.test(name)) {
  14789. const message = `options.name should be capitalised`;
  14790. stats.warn({
  14791. code: `options-lowercase-name`,
  14792. message,
  14793. filename,
  14794. toString: () => message,
  14795. });
  14796. }
  14797. const validator = new Validator(ast, source, stats, {
  14798. name,
  14799. filename,
  14800. dev,
  14801. parser
  14802. });
  14803. if (ast.js) {
  14804. validateJs(validator, ast.js);
  14805. }
  14806. if (ast.css) {
  14807. stylesheet.validate(validator);
  14808. }
  14809. if (ast.html) {
  14810. validateHtml(validator, ast.html);
  14811. }
  14812. // need to do a second pass of the JS, now that we've analysed the markup
  14813. if (ast.js && validator.defaultExport) {
  14814. const categories = {
  14815. components: 'component',
  14816. // TODO helpers require a bit more work — need to analyse all expressions
  14817. // helpers: 'helper',
  14818. events: 'event definition',
  14819. transitions: 'transition',
  14820. actions: 'actions',
  14821. };
  14822. Object.keys(categories).forEach(category => {
  14823. const definitions = validator.defaultExport.declaration.properties.find(prop => prop.key.name === category);
  14824. if (definitions) {
  14825. definitions.value.properties.forEach(prop => {
  14826. const { name } = prop.key;
  14827. if (!validator.used[category].has(name)) {
  14828. validator.warn(prop, {
  14829. code: `unused-${category.slice(0, -1)}`,
  14830. message: `The '${name}' ${categories[category]} is unused`
  14831. });
  14832. }
  14833. });
  14834. }
  14835. });
  14836. }
  14837. }
  14838. catch (err) {
  14839. if (onerror) {
  14840. onerror(err);
  14841. }
  14842. else {
  14843. throw err;
  14844. }
  14845. }
  14846. }
  14847. const start = /\n(\t+)/;
  14848. function deindent(strings, ...values) {
  14849. const indentation = start.exec(strings[0])[1];
  14850. const pattern = new RegExp(`^${indentation}`, 'gm');
  14851. let result = strings[0].replace(start, '').replace(pattern, '');
  14852. let trailingIndentation = getTrailingIndentation(result);
  14853. for (let i = 1; i < strings.length; i += 1) {
  14854. let expression = values[i - 1];
  14855. const string = strings[i].replace(pattern, '');
  14856. if (Array.isArray(expression)) {
  14857. expression = expression.length ? expression.join('\n') : null;
  14858. }
  14859. if (expression || expression === '') {
  14860. const value = String(expression).replace(/\n/g, `\n${trailingIndentation}`);
  14861. result += value + string;
  14862. }
  14863. else {
  14864. let c = result.length;
  14865. while (/\s/.test(result[c - 1]))
  14866. c -= 1;
  14867. result = result.slice(0, c) + string;
  14868. }
  14869. trailingIndentation = getTrailingIndentation(result);
  14870. }
  14871. return result.trim().replace(/\t+$/gm, '');
  14872. }
  14873. function getTrailingIndentation(str) {
  14874. let i = str.length;
  14875. while (str[i - 1] === ' ' || str[i - 1] === '\t')
  14876. i -= 1;
  14877. return str.slice(i, str.length);
  14878. }
  14879. function stringify(data, options = {}) {
  14880. return JSON.stringify(escape(data, options));
  14881. }
  14882. function escape(data, { onlyEscapeAtSymbol = false } = {}) {
  14883. return data.replace(onlyEscapeAtSymbol ? /(%+|@+)/g : /(%+|@+|#+)/g, (match) => {
  14884. return match + match[0];
  14885. });
  14886. }
  14887. const escaped = {
  14888. '&': '&amp;',
  14889. '<': '&lt;',
  14890. '>': '&gt;',
  14891. };
  14892. function escapeHTML(html) {
  14893. return String(html).replace(/[&<>]/g, match => escaped[match]);
  14894. }
  14895. function escapeTemplate(str) {
  14896. return str.replace(/(\${|`|\\)/g, '\\$1');
  14897. }
  14898. var ChunkType;
  14899. (function (ChunkType) {
  14900. ChunkType[ChunkType["Line"] = 0] = "Line";
  14901. ChunkType[ChunkType["Block"] = 1] = "Block";
  14902. })(ChunkType || (ChunkType = {}));
  14903. class CodeBuilder {
  14904. constructor(str = '') {
  14905. this.result = str;
  14906. const initial = str
  14907. ? /\n/.test(str) ? ChunkType.Block : ChunkType.Line
  14908. : null;
  14909. this.first = initial;
  14910. this.last = initial;
  14911. this.lastCondition = null;
  14912. this.conditionStack = [];
  14913. this.indent = '';
  14914. }
  14915. addConditional(condition, body) {
  14916. this.reifyConditions();
  14917. body = body.replace(/^/gm, `${this.indent}\t`);
  14918. if (condition === this.lastCondition) {
  14919. this.result += `\n${body}`;
  14920. }
  14921. else {
  14922. if (this.lastCondition) {
  14923. this.result += `\n${this.indent}}`;
  14924. }
  14925. this.result += `${this.last === ChunkType.Block ? '\n\n' : '\n'}${this.indent}if (${condition}) {\n${body}`;
  14926. this.lastCondition = condition;
  14927. }
  14928. this.last = ChunkType.Block;
  14929. }
  14930. addLine(line) {
  14931. this.reifyConditions();
  14932. if (this.lastCondition) {
  14933. this.result += `\n${this.indent}}`;
  14934. this.lastCondition = null;
  14935. }
  14936. if (this.last === ChunkType.Block) {
  14937. this.result += `\n\n${this.indent}${line}`;
  14938. }
  14939. else if (this.last === ChunkType.Line) {
  14940. this.result += `\n${this.indent}${line}`;
  14941. }
  14942. else {
  14943. this.result += line;
  14944. }
  14945. this.last = ChunkType.Line;
  14946. if (!this.first)
  14947. this.first = ChunkType.Line;
  14948. }
  14949. addLineAtStart(line) {
  14950. this.reifyConditions();
  14951. if (this.first === ChunkType.Block) {
  14952. this.result = `${line}\n\n${this.indent}${this.result}`;
  14953. }
  14954. else if (this.first === ChunkType.Line) {
  14955. this.result = `${line}\n${this.indent}${this.result}`;
  14956. }
  14957. else {
  14958. this.result += line;
  14959. }
  14960. this.first = ChunkType.Line;
  14961. if (!this.last)
  14962. this.last = ChunkType.Line;
  14963. }
  14964. addBlock(block) {
  14965. this.reifyConditions();
  14966. if (this.indent)
  14967. block = block.replace(/^/gm, `${this.indent}`);
  14968. if (this.lastCondition) {
  14969. this.result += `\n${this.indent}}`;
  14970. this.lastCondition = null;
  14971. }
  14972. if (this.result) {
  14973. this.result += `\n\n${this.indent}${block}`;
  14974. }
  14975. else {
  14976. this.result += block;
  14977. }
  14978. this.last = ChunkType.Block;
  14979. if (!this.first)
  14980. this.first = ChunkType.Block;
  14981. }
  14982. addBlockAtStart(block) {
  14983. this.reifyConditions();
  14984. if (this.result) {
  14985. this.result = `${block}\n\n${this.indent}${this.result}`;
  14986. }
  14987. else {
  14988. this.result += block;
  14989. }
  14990. this.first = ChunkType.Block;
  14991. if (!this.last)
  14992. this.last = ChunkType.Block;
  14993. }
  14994. isEmpty() {
  14995. return this.result === '';
  14996. }
  14997. pushCondition(condition) {
  14998. this.conditionStack.push({ condition, used: false });
  14999. }
  15000. popCondition() {
  15001. const { used } = this.conditionStack.pop();
  15002. this.indent = repeat('\t', this.conditionStack.length);
  15003. if (used)
  15004. this.addLine('}');
  15005. }
  15006. reifyConditions() {
  15007. for (let i = 0; i < this.conditionStack.length; i += 1) {
  15008. const condition = this.conditionStack[i];
  15009. if (!condition.used) {
  15010. const line = `if (${condition.condition}) {`;
  15011. if (this.last === ChunkType.Block) {
  15012. this.result += `\n\n${this.indent}${line}`;
  15013. }
  15014. else if (this.last === ChunkType.Line) {
  15015. this.result += `\n${this.indent}${line}`;
  15016. }
  15017. else {
  15018. this.result += line;
  15019. }
  15020. this.last = ChunkType.Line;
  15021. if (!this.first)
  15022. this.first = ChunkType.Line;
  15023. this.indent = repeat('\t', this.conditionStack.length);
  15024. condition.used = true;
  15025. }
  15026. }
  15027. }
  15028. toString() {
  15029. return this.result.trim() + (this.lastCondition ? `\n}` : ``);
  15030. }
  15031. }
  15032. var globalWhitelist = new Set([
  15033. 'Array',
  15034. 'Boolean',
  15035. 'console',
  15036. 'Date',
  15037. 'decodeURI',
  15038. 'decodeURIComponent',
  15039. 'encodeURI',
  15040. 'encodeURIComponent',
  15041. 'Infinity',
  15042. 'Intl',
  15043. 'isFinite',
  15044. 'isNaN',
  15045. 'JSON',
  15046. 'Map',
  15047. 'Math',
  15048. 'NaN',
  15049. 'Number',
  15050. 'Object',
  15051. 'parseFloat',
  15052. 'parseInt',
  15053. 'Promise',
  15054. 'RegExp',
  15055. 'Set',
  15056. 'String',
  15057. 'undefined',
  15058. ]);
  15059. var charToInteger = {};
  15060. var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  15061. for (var i$1 = 0; i$1 < chars.length; i$1++) {
  15062. charToInteger[chars.charCodeAt(i$1)] = i$1;
  15063. }
  15064. function encode(decoded) {
  15065. var sourceFileIndex = 0; // second field
  15066. var sourceCodeLine = 0; // third field
  15067. var sourceCodeColumn = 0; // fourth field
  15068. var nameIndex = 0; // fifth field
  15069. var mappings = '';
  15070. for (var i = 0; i < decoded.length; i++) {
  15071. var line = decoded[i];
  15072. if (i > 0)
  15073. mappings += ';';
  15074. if (line.length === 0)
  15075. continue;
  15076. var generatedCodeColumn = 0; // first field
  15077. var lineMappings = [];
  15078. for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
  15079. var segment = line_1[_i];
  15080. var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
  15081. generatedCodeColumn = segment[0];
  15082. if (segment.length > 1) {
  15083. segmentMappings +=
  15084. encodeInteger(segment[1] - sourceFileIndex) +
  15085. encodeInteger(segment[2] - sourceCodeLine) +
  15086. encodeInteger(segment[3] - sourceCodeColumn);
  15087. sourceFileIndex = segment[1];
  15088. sourceCodeLine = segment[2];
  15089. sourceCodeColumn = segment[3];
  15090. }
  15091. if (segment.length === 5) {
  15092. segmentMappings += encodeInteger(segment[4] - nameIndex);
  15093. nameIndex = segment[4];
  15094. }
  15095. lineMappings.push(segmentMappings);
  15096. }
  15097. mappings += lineMappings.join(',');
  15098. }
  15099. return mappings;
  15100. }
  15101. function encodeInteger(num) {
  15102. var result = '';
  15103. num = num < 0 ? (-num << 1) | 1 : num << 1;
  15104. do {
  15105. var clamped = num & 31;
  15106. num >>= 5;
  15107. if (num > 0) {
  15108. clamped |= 32;
  15109. }
  15110. result += chars[clamped];
  15111. } while (num > 0);
  15112. return result;
  15113. }
  15114. var Chunk = function Chunk(start, end, content) {
  15115. this.start = start;
  15116. this.end = end;
  15117. this.original = content;
  15118. this.intro = '';
  15119. this.outro = '';
  15120. this.content = content;
  15121. this.storeName = false;
  15122. this.edited = false;
  15123. // we make these non-enumerable, for sanity while debugging
  15124. Object.defineProperties(this, {
  15125. previous: { writable: true, value: null },
  15126. next: { writable: true, value: null }
  15127. });
  15128. };
  15129. Chunk.prototype.appendLeft = function appendLeft (content) {
  15130. this.outro += content;
  15131. };
  15132. Chunk.prototype.appendRight = function appendRight (content) {
  15133. this.intro = this.intro + content;
  15134. };
  15135. Chunk.prototype.clone = function clone () {
  15136. var chunk = new Chunk(this.start, this.end, this.original);
  15137. chunk.intro = this.intro;
  15138. chunk.outro = this.outro;
  15139. chunk.content = this.content;
  15140. chunk.storeName = this.storeName;
  15141. chunk.edited = this.edited;
  15142. return chunk;
  15143. };
  15144. Chunk.prototype.contains = function contains (index) {
  15145. return this.start < index && index < this.end;
  15146. };
  15147. Chunk.prototype.eachNext = function eachNext (fn) {
  15148. var chunk = this;
  15149. while (chunk) {
  15150. fn(chunk);
  15151. chunk = chunk.next;
  15152. }
  15153. };
  15154. Chunk.prototype.eachPrevious = function eachPrevious (fn) {
  15155. var chunk = this;
  15156. while (chunk) {
  15157. fn(chunk);
  15158. chunk = chunk.previous;
  15159. }
  15160. };
  15161. Chunk.prototype.edit = function edit (content, storeName, contentOnly) {
  15162. this.content = content;
  15163. if (!contentOnly) {
  15164. this.intro = '';
  15165. this.outro = '';
  15166. }
  15167. this.storeName = storeName;
  15168. this.edited = true;
  15169. return this;
  15170. };
  15171. Chunk.prototype.prependLeft = function prependLeft (content) {
  15172. this.outro = content + this.outro;
  15173. };
  15174. Chunk.prototype.prependRight = function prependRight (content) {
  15175. this.intro = content + this.intro;
  15176. };
  15177. Chunk.prototype.split = function split (index) {
  15178. var sliceIndex = index - this.start;
  15179. var originalBefore = this.original.slice(0, sliceIndex);
  15180. var originalAfter = this.original.slice(sliceIndex);
  15181. this.original = originalBefore;
  15182. var newChunk = new Chunk(index, this.end, originalAfter);
  15183. newChunk.outro = this.outro;
  15184. this.outro = '';
  15185. this.end = index;
  15186. if (this.edited) {
  15187. // TODO is this block necessary?...
  15188. newChunk.edit('', false);
  15189. this.content = '';
  15190. } else {
  15191. this.content = originalBefore;
  15192. }
  15193. newChunk.next = this.next;
  15194. if (newChunk.next) { newChunk.next.previous = newChunk; }
  15195. newChunk.previous = this;
  15196. this.next = newChunk;
  15197. return newChunk;
  15198. };
  15199. Chunk.prototype.toString = function toString () {
  15200. return this.intro + this.content + this.outro;
  15201. };
  15202. Chunk.prototype.trimEnd = function trimEnd (rx) {
  15203. this.outro = this.outro.replace(rx, '');
  15204. if (this.outro.length) { return true; }
  15205. var trimmed = this.content.replace(rx, '');
  15206. if (trimmed.length) {
  15207. if (trimmed !== this.content) {
  15208. this.split(this.start + trimmed.length).edit('', false);
  15209. }
  15210. return true;
  15211. } else {
  15212. this.edit('', false);
  15213. this.intro = this.intro.replace(rx, '');
  15214. if (this.intro.length) { return true; }
  15215. }
  15216. };
  15217. Chunk.prototype.trimStart = function trimStart (rx) {
  15218. this.intro = this.intro.replace(rx, '');
  15219. if (this.intro.length) { return true; }
  15220. var trimmed = this.content.replace(rx, '');
  15221. if (trimmed.length) {
  15222. if (trimmed !== this.content) {
  15223. this.split(this.end - trimmed.length);
  15224. this.edit('', false);
  15225. }
  15226. return true;
  15227. } else {
  15228. this.edit('', false);
  15229. this.outro = this.outro.replace(rx, '');
  15230. if (this.outro.length) { return true; }
  15231. }
  15232. };
  15233. var btoa = function () {
  15234. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  15235. };
  15236. if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
  15237. btoa = window.btoa;
  15238. } else if (typeof Buffer === 'function') {
  15239. btoa = function (str) { return new Buffer(str).toString('base64'); };
  15240. }
  15241. var SourceMap = function SourceMap(properties) {
  15242. this.version = 3;
  15243. this.file = properties.file;
  15244. this.sources = properties.sources;
  15245. this.sourcesContent = properties.sourcesContent;
  15246. this.names = properties.names;
  15247. this.mappings = encode(properties.mappings);
  15248. };
  15249. SourceMap.prototype.toString = function toString () {
  15250. return JSON.stringify(this);
  15251. };
  15252. SourceMap.prototype.toUrl = function toUrl () {
  15253. return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
  15254. };
  15255. function guessIndent(code) {
  15256. var lines = code.split('\n');
  15257. var tabbed = lines.filter(function (line) { return /^\t+/.test(line); });
  15258. var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); });
  15259. if (tabbed.length === 0 && spaced.length === 0) {
  15260. return null;
  15261. }
  15262. // More lines tabbed than spaced? Assume tabs, and
  15263. // default to tabs in the case of a tie (or nothing
  15264. // to go on)
  15265. if (tabbed.length >= spaced.length) {
  15266. return '\t';
  15267. }
  15268. // Otherwise, we need to guess the multiple
  15269. var min = spaced.reduce(function (previous, current) {
  15270. var numSpaces = /^ +/.exec(current)[0].length;
  15271. return Math.min(numSpaces, previous);
  15272. }, Infinity);
  15273. return new Array(min + 1).join(' ');
  15274. }
  15275. function getRelativePath(from, to) {
  15276. var fromParts = from.split(/[/\\]/);
  15277. var toParts = to.split(/[/\\]/);
  15278. fromParts.pop(); // get dirname
  15279. while (fromParts[0] === toParts[0]) {
  15280. fromParts.shift();
  15281. toParts.shift();
  15282. }
  15283. if (fromParts.length) {
  15284. var i = fromParts.length;
  15285. while (i--) { fromParts[i] = '..'; }
  15286. }
  15287. return fromParts.concat(toParts).join('/');
  15288. }
  15289. var toString$2 = Object.prototype.toString;
  15290. function isObject(thing) {
  15291. return toString$2.call(thing) === '[object Object]';
  15292. }
  15293. function getLocator$1(source) {
  15294. var originalLines = source.split('\n');
  15295. var lineOffsets = [];
  15296. for (var i = 0, pos = 0; i < originalLines.length; i++) {
  15297. lineOffsets.push(pos);
  15298. pos += originalLines[i].length + 1;
  15299. }
  15300. return function locate(index) {
  15301. var i = 0;
  15302. var j = lineOffsets.length;
  15303. while (i < j) {
  15304. var m = (i + j) >> 1;
  15305. if (index < lineOffsets[m]) {
  15306. j = m;
  15307. } else {
  15308. i = m + 1;
  15309. }
  15310. }
  15311. var line = i - 1;
  15312. var column = index - lineOffsets[line];
  15313. return { line: line, column: column };
  15314. };
  15315. }
  15316. var Mappings = function Mappings(hires) {
  15317. this.hires = hires;
  15318. this.generatedCodeLine = 0;
  15319. this.generatedCodeColumn = 0;
  15320. this.raw = [];
  15321. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  15322. this.pending = null;
  15323. };
  15324. Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) {
  15325. if (content.length) {
  15326. var segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  15327. if (nameIndex >= 0) {
  15328. segment.push(nameIndex);
  15329. }
  15330. this.rawSegments.push(segment);
  15331. } else if (this.pending) {
  15332. this.rawSegments.push(this.pending);
  15333. }
  15334. this.advance(content);
  15335. this.pending = null;
  15336. };
  15337. Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) {
  15338. var this$1 = this;
  15339. var originalCharIndex = chunk.start;
  15340. var first = true;
  15341. while (originalCharIndex < chunk.end) {
  15342. if (this$1.hires || first || sourcemapLocations[originalCharIndex]) {
  15343. this$1.rawSegments.push([this$1.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
  15344. }
  15345. if (original[originalCharIndex] === '\n') {
  15346. loc.line += 1;
  15347. loc.column = 0;
  15348. this$1.generatedCodeLine += 1;
  15349. this$1.raw[this$1.generatedCodeLine] = this$1.rawSegments = [];
  15350. this$1.generatedCodeColumn = 0;
  15351. } else {
  15352. loc.column += 1;
  15353. this$1.generatedCodeColumn += 1;
  15354. }
  15355. originalCharIndex += 1;
  15356. first = false;
  15357. }
  15358. this.pending = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  15359. };
  15360. Mappings.prototype.advance = function advance (str) {
  15361. var this$1 = this;
  15362. if (!str) { return; }
  15363. var lines = str.split('\n');
  15364. if (lines.length > 1) {
  15365. for (var i = 0; i < lines.length - 1; i++) {
  15366. this$1.generatedCodeLine++;
  15367. this$1.raw[this$1.generatedCodeLine] = this$1.rawSegments = [];
  15368. }
  15369. this.generatedCodeColumn = 0;
  15370. }
  15371. this.generatedCodeColumn += lines[lines.length - 1].length;
  15372. };
  15373. var warned = {
  15374. insertLeft: false,
  15375. insertRight: false,
  15376. storeName: false
  15377. };
  15378. var MagicString = function MagicString(string, options) {
  15379. if ( options === void 0 ) options = {};
  15380. var chunk = new Chunk(0, string.length, string);
  15381. Object.defineProperties(this, {
  15382. original: { writable: true, value: string },
  15383. outro: { writable: true, value: '' },
  15384. intro: { writable: true, value: '' },
  15385. firstChunk: { writable: true, value: chunk },
  15386. lastChunk: { writable: true, value: chunk },
  15387. lastSearchedChunk: { writable: true, value: chunk },
  15388. byStart: { writable: true, value: {} },
  15389. byEnd: { writable: true, value: {} },
  15390. filename: { writable: true, value: options.filename },
  15391. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  15392. sourcemapLocations: { writable: true, value: {} },
  15393. storedNames: { writable: true, value: {} },
  15394. indentStr: { writable: true, value: guessIndent(string) }
  15395. });
  15396. this.byStart[0] = chunk;
  15397. this.byEnd[string.length] = chunk;
  15398. };
  15399. MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
  15400. this.sourcemapLocations[char] = true;
  15401. };
  15402. MagicString.prototype.append = function append (content) {
  15403. if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
  15404. this.outro += content;
  15405. return this;
  15406. };
  15407. MagicString.prototype.appendLeft = function appendLeft (index, content) {
  15408. if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
  15409. this._split(index);
  15410. var chunk = this.byEnd[index];
  15411. if (chunk) {
  15412. chunk.appendLeft(content);
  15413. } else {
  15414. this.intro += content;
  15415. }
  15416. return this;
  15417. };
  15418. MagicString.prototype.appendRight = function appendRight (index, content) {
  15419. if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
  15420. this._split(index);
  15421. var chunk = this.byStart[index];
  15422. if (chunk) {
  15423. chunk.appendRight(content);
  15424. } else {
  15425. this.outro += content;
  15426. }
  15427. return this;
  15428. };
  15429. MagicString.prototype.clone = function clone () {
  15430. var cloned = new MagicString(this.original, { filename: this.filename });
  15431. var originalChunk = this.firstChunk;
  15432. var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  15433. while (originalChunk) {
  15434. cloned.byStart[clonedChunk.start] = clonedChunk;
  15435. cloned.byEnd[clonedChunk.end] = clonedChunk;
  15436. var nextOriginalChunk = originalChunk.next;
  15437. var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  15438. if (nextClonedChunk) {
  15439. clonedChunk.next = nextClonedChunk;
  15440. nextClonedChunk.previous = clonedChunk;
  15441. clonedChunk = nextClonedChunk;
  15442. }
  15443. originalChunk = nextOriginalChunk;
  15444. }
  15445. cloned.lastChunk = clonedChunk;
  15446. if (this.indentExclusionRanges) {
  15447. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  15448. }
  15449. Object.keys(this.sourcemapLocations).forEach(function (loc) {
  15450. cloned.sourcemapLocations[loc] = true;
  15451. });
  15452. return cloned;
  15453. };
  15454. MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
  15455. var this$1 = this;
  15456. options = options || {};
  15457. var sourceIndex = 0;
  15458. var names = Object.keys(this.storedNames);
  15459. var mappings = new Mappings(options.hires);
  15460. var locate = getLocator$1(this.original);
  15461. if (this.intro) {
  15462. mappings.advance(this.intro);
  15463. }
  15464. this.firstChunk.eachNext(function (chunk) {
  15465. var loc = locate(chunk.start);
  15466. if (chunk.intro.length) { mappings.advance(chunk.intro); }
  15467. if (chunk.edited) {
  15468. mappings.addEdit(
  15469. sourceIndex,
  15470. chunk.content,
  15471. loc,
  15472. chunk.storeName ? names.indexOf(chunk.original) : -1
  15473. );
  15474. } else {
  15475. mappings.addUneditedChunk(sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations);
  15476. }
  15477. if (chunk.outro.length) { mappings.advance(chunk.outro); }
  15478. });
  15479. return {
  15480. file: options.file ? options.file.split(/[/\\]/).pop() : null,
  15481. sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
  15482. sourcesContent: options.includeContent ? [this.original] : [null],
  15483. names: names,
  15484. mappings: mappings.raw
  15485. };
  15486. };
  15487. MagicString.prototype.generateMap = function generateMap (options) {
  15488. return new SourceMap(this.generateDecodedMap(options));
  15489. };
  15490. MagicString.prototype.getIndentString = function getIndentString () {
  15491. return this.indentStr === null ? '\t' : this.indentStr;
  15492. };
  15493. MagicString.prototype.indent = function indent (indentStr, options) {
  15494. var this$1 = this;
  15495. var pattern = /^[^\r\n]/gm;
  15496. if (isObject(indentStr)) {
  15497. options = indentStr;
  15498. indentStr = undefined;
  15499. }
  15500. indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
  15501. if (indentStr === '') { return this; } // noop
  15502. options = options || {};
  15503. // Process exclusion ranges
  15504. var isExcluded = {};
  15505. if (options.exclude) {
  15506. var exclusions =
  15507. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  15508. exclusions.forEach(function (exclusion) {
  15509. for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
  15510. isExcluded[i] = true;
  15511. }
  15512. });
  15513. }
  15514. var shouldIndentNextCharacter = options.indentStart !== false;
  15515. var replacer = function (match) {
  15516. if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
  15517. shouldIndentNextCharacter = true;
  15518. return match;
  15519. };
  15520. this.intro = this.intro.replace(pattern, replacer);
  15521. var charIndex = 0;
  15522. var chunk = this.firstChunk;
  15523. while (chunk) {
  15524. var end = chunk.end;
  15525. if (chunk.edited) {
  15526. if (!isExcluded[charIndex]) {
  15527. chunk.content = chunk.content.replace(pattern, replacer);
  15528. if (chunk.content.length) {
  15529. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  15530. }
  15531. }
  15532. } else {
  15533. charIndex = chunk.start;
  15534. while (charIndex < end) {
  15535. if (!isExcluded[charIndex]) {
  15536. var char = this$1.original[charIndex];
  15537. if (char === '\n') {
  15538. shouldIndentNextCharacter = true;
  15539. } else if (char !== '\r' && shouldIndentNextCharacter) {
  15540. shouldIndentNextCharacter = false;
  15541. if (charIndex === chunk.start) {
  15542. chunk.prependRight(indentStr);
  15543. } else {
  15544. this$1._splitChunk(chunk, charIndex);
  15545. chunk = chunk.next;
  15546. chunk.prependRight(indentStr);
  15547. }
  15548. }
  15549. }
  15550. charIndex += 1;
  15551. }
  15552. }
  15553. charIndex = chunk.end;
  15554. chunk = chunk.next;
  15555. }
  15556. this.outro = this.outro.replace(pattern, replacer);
  15557. return this;
  15558. };
  15559. MagicString.prototype.insert = function insert () {
  15560. throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
  15561. };
  15562. MagicString.prototype.insertLeft = function insertLeft (index, content) {
  15563. if (!warned.insertLeft) {
  15564. console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
  15565. warned.insertLeft = true;
  15566. }
  15567. return this.appendLeft(index, content);
  15568. };
  15569. MagicString.prototype.insertRight = function insertRight (index, content) {
  15570. if (!warned.insertRight) {
  15571. console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
  15572. warned.insertRight = true;
  15573. }
  15574. return this.prependRight(index, content);
  15575. };
  15576. MagicString.prototype.move = function move (start, end, index) {
  15577. if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); }
  15578. this._split(start);
  15579. this._split(end);
  15580. this._split(index);
  15581. var first = this.byStart[start];
  15582. var last = this.byEnd[end];
  15583. var oldLeft = first.previous;
  15584. var oldRight = last.next;
  15585. var newRight = this.byStart[index];
  15586. if (!newRight && last === this.lastChunk) { return this; }
  15587. var newLeft = newRight ? newRight.previous : this.lastChunk;
  15588. if (oldLeft) { oldLeft.next = oldRight; }
  15589. if (oldRight) { oldRight.previous = oldLeft; }
  15590. if (newLeft) { newLeft.next = first; }
  15591. if (newRight) { newRight.previous = last; }
  15592. if (!first.previous) { this.firstChunk = last.next; }
  15593. if (!last.next) {
  15594. this.lastChunk = first.previous;
  15595. this.lastChunk.next = null;
  15596. }
  15597. first.previous = newLeft;
  15598. last.next = newRight || null;
  15599. if (!newLeft) { this.firstChunk = first; }
  15600. if (!newRight) { this.lastChunk = last; }
  15601. return this;
  15602. };
  15603. MagicString.prototype.overwrite = function overwrite (start, end, content, options) {
  15604. var this$1 = this;
  15605. if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); }
  15606. while (start < 0) { start += this$1.original.length; }
  15607. while (end < 0) { end += this$1.original.length; }
  15608. if (end > this.original.length) { throw new Error('end is out of bounds'); }
  15609. if (start === end)
  15610. { throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
  15611. this._split(start);
  15612. this._split(end);
  15613. if (options === true) {
  15614. if (!warned.storeName) {
  15615. 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
  15616. warned.storeName = true;
  15617. }
  15618. options = { storeName: true };
  15619. }
  15620. var storeName = options !== undefined ? options.storeName : false;
  15621. var contentOnly = options !== undefined ? options.contentOnly : false;
  15622. if (storeName) {
  15623. var original = this.original.slice(start, end);
  15624. this.storedNames[original] = true;
  15625. }
  15626. var first = this.byStart[start];
  15627. var last = this.byEnd[end];
  15628. if (first) {
  15629. if (end > first.end && first.next !== this.byStart[first.end]) {
  15630. throw new Error('Cannot overwrite across a split point');
  15631. }
  15632. first.edit(content, storeName, contentOnly);
  15633. if (first !== last) {
  15634. var chunk = first.next;
  15635. while (chunk !== last) {
  15636. chunk.edit('', false);
  15637. chunk = chunk.next;
  15638. }
  15639. chunk.edit('', false);
  15640. }
  15641. } else {
  15642. // must be inserting at the end
  15643. var newChunk = new Chunk(start, end, '').edit(content, storeName);
  15644. // TODO last chunk in the array may not be the last chunk, if it's moved...
  15645. last.next = newChunk;
  15646. newChunk.previous = last;
  15647. }
  15648. return this;
  15649. };
  15650. MagicString.prototype.prepend = function prepend (content) {
  15651. if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
  15652. this.intro = content + this.intro;
  15653. return this;
  15654. };
  15655. MagicString.prototype.prependLeft = function prependLeft (index, content) {
  15656. if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
  15657. this._split(index);
  15658. var chunk = this.byEnd[index];
  15659. if (chunk) {
  15660. chunk.prependLeft(content);
  15661. } else {
  15662. this.intro = content + this.intro;
  15663. }
  15664. return this;
  15665. };
  15666. MagicString.prototype.prependRight = function prependRight (index, content) {
  15667. if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
  15668. this._split(index);
  15669. var chunk = this.byStart[index];
  15670. if (chunk) {
  15671. chunk.prependRight(content);
  15672. } else {
  15673. this.outro = content + this.outro;
  15674. }
  15675. return this;
  15676. };
  15677. MagicString.prototype.remove = function remove (start, end) {
  15678. var this$1 = this;
  15679. while (start < 0) { start += this$1.original.length; }
  15680. while (end < 0) { end += this$1.original.length; }
  15681. if (start === end) { return this; }
  15682. if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
  15683. if (start > end) { throw new Error('end must be greater than start'); }
  15684. this._split(start);
  15685. this._split(end);
  15686. var chunk = this.byStart[start];
  15687. while (chunk) {
  15688. chunk.intro = '';
  15689. chunk.outro = '';
  15690. chunk.edit('');
  15691. chunk = end > chunk.end ? this$1.byStart[chunk.end] : null;
  15692. }
  15693. return this;
  15694. };
  15695. MagicString.prototype.lastChar = function lastChar () {
  15696. var chunk = this.lastChunk;
  15697. do {
  15698. if (chunk.outro.length)
  15699. { return chunk.outro[chunk.outro.length - 1]; }
  15700. if (chunk.content.length)
  15701. { return chunk.content[chunk.content.length - 1]; }
  15702. if (chunk.intro.length)
  15703. { return chunk.intro[chunk.intro.length - 1]; }
  15704. } while (chunk = chunk.previous);
  15705. return '';
  15706. };
  15707. MagicString.prototype.slice = function slice (start, end) {
  15708. var this$1 = this;
  15709. if ( start === void 0 ) start = 0;
  15710. if ( end === void 0 ) end = this.original.length;
  15711. while (start < 0) { start += this$1.original.length; }
  15712. while (end < 0) { end += this$1.original.length; }
  15713. var result = '';
  15714. // find start chunk
  15715. var chunk = this.firstChunk;
  15716. while (chunk && (chunk.start > start || chunk.end <= start)) {
  15717. // found end chunk before start
  15718. if (chunk.start < end && chunk.end >= end) {
  15719. return result;
  15720. }
  15721. chunk = chunk.next;
  15722. }
  15723. if (chunk && chunk.edited && chunk.start !== start)
  15724. { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
  15725. var startChunk = chunk;
  15726. while (chunk) {
  15727. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  15728. result += chunk.intro;
  15729. }
  15730. var containsEnd = chunk.start < end && chunk.end >= end;
  15731. if (containsEnd && chunk.edited && chunk.end !== end)
  15732. { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
  15733. var sliceStart = startChunk === chunk ? start - chunk.start : 0;
  15734. var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  15735. result += chunk.content.slice(sliceStart, sliceEnd);
  15736. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  15737. result += chunk.outro;
  15738. }
  15739. if (containsEnd) {
  15740. break;
  15741. }
  15742. chunk = chunk.next;
  15743. }
  15744. return result;
  15745. };
  15746. // TODO deprecate this? not really very useful
  15747. MagicString.prototype.snip = function snip (start, end) {
  15748. var clone = this.clone();
  15749. clone.remove(0, start);
  15750. clone.remove(end, clone.original.length);
  15751. return clone;
  15752. };
  15753. MagicString.prototype._split = function _split (index) {
  15754. var this$1 = this;
  15755. if (this.byStart[index] || this.byEnd[index]) { return; }
  15756. var chunk = this.lastSearchedChunk;
  15757. var searchForward = index > chunk.end;
  15758. while (chunk) {
  15759. if (chunk.contains(index)) { return this$1._splitChunk(chunk, index); }
  15760. chunk = searchForward ? this$1.byStart[chunk.end] : this$1.byEnd[chunk.start];
  15761. }
  15762. };
  15763. MagicString.prototype._splitChunk = function _splitChunk (chunk, index) {
  15764. if (chunk.edited && chunk.content.length) {
  15765. // zero-length edited chunks are a special case (overlapping replacements)
  15766. var loc = getLocator$1(this.original)(index);
  15767. throw new Error(
  15768. ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")")
  15769. );
  15770. }
  15771. var newChunk = chunk.split(index);
  15772. this.byEnd[index] = chunk;
  15773. this.byStart[index] = newChunk;
  15774. this.byEnd[newChunk.end] = newChunk;
  15775. if (chunk === this.lastChunk) { this.lastChunk = newChunk; }
  15776. this.lastSearchedChunk = chunk;
  15777. return true;
  15778. };
  15779. MagicString.prototype.toString = function toString () {
  15780. var str = this.intro;
  15781. var chunk = this.firstChunk;
  15782. while (chunk) {
  15783. str += chunk.toString();
  15784. chunk = chunk.next;
  15785. }
  15786. return str + this.outro;
  15787. };
  15788. MagicString.prototype.isEmpty = function isEmpty () {
  15789. var chunk = this.firstChunk;
  15790. do {
  15791. if (chunk.intro.length && chunk.intro.trim() ||
  15792. chunk.content.length && chunk.content.trim() ||
  15793. chunk.outro.length && chunk.outro.trim())
  15794. { return false; }
  15795. } while (chunk = chunk.next);
  15796. return true;
  15797. };
  15798. MagicString.prototype.trimLines = function trimLines () {
  15799. return this.trim('[\\r\\n]');
  15800. };
  15801. MagicString.prototype.trim = function trim (charType) {
  15802. return this.trimStart(charType).trimEnd(charType);
  15803. };
  15804. MagicString.prototype.trimEndAborted = function trimEndAborted (charType) {
  15805. var this$1 = this;
  15806. var rx = new RegExp((charType || '\\s') + '+$');
  15807. this.outro = this.outro.replace(rx, '');
  15808. if (this.outro.length) { return true; }
  15809. var chunk = this.lastChunk;
  15810. do {
  15811. var end = chunk.end;
  15812. var aborted = chunk.trimEnd(rx);
  15813. // if chunk was trimmed, we have a new lastChunk
  15814. if (chunk.end !== end) {
  15815. if (this$1.lastChunk === chunk) {
  15816. this$1.lastChunk = chunk.next;
  15817. }
  15818. this$1.byEnd[chunk.end] = chunk;
  15819. this$1.byStart[chunk.next.start] = chunk.next;
  15820. this$1.byEnd[chunk.next.end] = chunk.next;
  15821. }
  15822. if (aborted) { return true; }
  15823. chunk = chunk.previous;
  15824. } while (chunk);
  15825. return false;
  15826. };
  15827. MagicString.prototype.trimEnd = function trimEnd (charType) {
  15828. this.trimEndAborted(charType);
  15829. return this;
  15830. };
  15831. MagicString.prototype.trimStartAborted = function trimStartAborted (charType) {
  15832. var this$1 = this;
  15833. var rx = new RegExp('^' + (charType || '\\s') + '+');
  15834. this.intro = this.intro.replace(rx, '');
  15835. if (this.intro.length) { return true; }
  15836. var chunk = this.firstChunk;
  15837. do {
  15838. var end = chunk.end;
  15839. var aborted = chunk.trimStart(rx);
  15840. if (chunk.end !== end) {
  15841. // special case...
  15842. if (chunk === this$1.lastChunk) { this$1.lastChunk = chunk.next; }
  15843. this$1.byEnd[chunk.end] = chunk;
  15844. this$1.byStart[chunk.next.start] = chunk.next;
  15845. this$1.byEnd[chunk.next.end] = chunk.next;
  15846. }
  15847. if (aborted) { return true; }
  15848. chunk = chunk.next;
  15849. } while (chunk);
  15850. return false;
  15851. };
  15852. MagicString.prototype.trimStart = function trimStart (charType) {
  15853. this.trimStartAborted(charType);
  15854. return this;
  15855. };
  15856. var hasOwnProp = Object.prototype.hasOwnProperty;
  15857. var Bundle = function Bundle(options) {
  15858. if ( options === void 0 ) options = {};
  15859. this.intro = options.intro || '';
  15860. this.separator = options.separator !== undefined ? options.separator : '\n';
  15861. this.sources = [];
  15862. this.uniqueSources = [];
  15863. this.uniqueSourceIndexByFilename = {};
  15864. };
  15865. Bundle.prototype.addSource = function addSource (source) {
  15866. if (source instanceof MagicString) {
  15867. return this.addSource({
  15868. content: source,
  15869. filename: source.filename,
  15870. separator: this.separator
  15871. });
  15872. }
  15873. if (!isObject(source) || !source.content) {
  15874. throw new Error('bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`');
  15875. }
  15876. ['filename', 'indentExclusionRanges', 'separator'].forEach(function (option) {
  15877. if (!hasOwnProp.call(source, option)) { source[option] = source.content[option]; }
  15878. });
  15879. if (source.separator === undefined) {
  15880. // TODO there's a bunch of this sort of thing, needs cleaning up
  15881. source.separator = this.separator;
  15882. }
  15883. if (source.filename) {
  15884. if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
  15885. this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
  15886. this.uniqueSources.push({ filename: source.filename, content: source.content.original });
  15887. } else {
  15888. var uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
  15889. if (source.content.original !== uniqueSource.content) {
  15890. throw new Error(("Illegal source: same filename (" + (source.filename) + "), different contents"));
  15891. }
  15892. }
  15893. }
  15894. this.sources.push(source);
  15895. return this;
  15896. };
  15897. Bundle.prototype.append = function append (str, options) {
  15898. this.addSource({
  15899. content: new MagicString(str),
  15900. separator: (options && options.separator) || ''
  15901. });
  15902. return this;
  15903. };
  15904. Bundle.prototype.clone = function clone () {
  15905. var bundle = new Bundle({
  15906. intro: this.intro,
  15907. separator: this.separator
  15908. });
  15909. this.sources.forEach(function (source) {
  15910. bundle.addSource({
  15911. filename: source.filename,
  15912. content: source.content.clone(),
  15913. separator: source.separator
  15914. });
  15915. });
  15916. return bundle;
  15917. };
  15918. Bundle.prototype.generateDecodedMap = function generateDecodedMap (options) {
  15919. var this$1 = this;
  15920. if ( options === void 0 ) options = {};
  15921. var names = [];
  15922. this.sources.forEach(function (source) {
  15923. Object.keys(source.content.storedNames).forEach(function (name) {
  15924. if (!~names.indexOf(name)) { names.push(name); }
  15925. });
  15926. });
  15927. var mappings = new Mappings(options.hires);
  15928. if (this.intro) {
  15929. mappings.advance(this.intro);
  15930. }
  15931. this.sources.forEach(function (source, i) {
  15932. if (i > 0) {
  15933. mappings.advance(this$1.separator);
  15934. }
  15935. var sourceIndex = source.filename ? this$1.uniqueSourceIndexByFilename[source.filename] : -1;
  15936. var magicString = source.content;
  15937. var locate = getLocator$1(magicString.original);
  15938. if (magicString.intro) {
  15939. mappings.advance(magicString.intro);
  15940. }
  15941. magicString.firstChunk.eachNext(function (chunk) {
  15942. var loc = locate(chunk.start);
  15943. if (chunk.intro.length) { mappings.advance(chunk.intro); }
  15944. if (source.filename) {
  15945. if (chunk.edited) {
  15946. mappings.addEdit(
  15947. sourceIndex,
  15948. chunk.content,
  15949. loc,
  15950. chunk.storeName ? names.indexOf(chunk.original) : -1
  15951. );
  15952. } else {
  15953. mappings.addUneditedChunk(
  15954. sourceIndex,
  15955. chunk,
  15956. magicString.original,
  15957. loc,
  15958. magicString.sourcemapLocations
  15959. );
  15960. }
  15961. } else {
  15962. mappings.advance(chunk.content);
  15963. }
  15964. if (chunk.outro.length) { mappings.advance(chunk.outro); }
  15965. });
  15966. if (magicString.outro) {
  15967. mappings.advance(magicString.outro);
  15968. }
  15969. });
  15970. return {
  15971. file: options.file ? options.file.split(/[/\\]/).pop() : null,
  15972. sources: this.uniqueSources.map(function (source) {
  15973. return options.file ? getRelativePath(options.file, source.filename) : source.filename;
  15974. }),
  15975. sourcesContent: this.uniqueSources.map(function (source) {
  15976. return options.includeContent ? source.content : null;
  15977. }),
  15978. names: names,
  15979. mappings: mappings.raw
  15980. };
  15981. };
  15982. Bundle.prototype.generateMap = function generateMap (options) {
  15983. return new SourceMap(this.generateDecodedMap(options));
  15984. };
  15985. Bundle.prototype.getIndentString = function getIndentString () {
  15986. var indentStringCounts = {};
  15987. this.sources.forEach(function (source) {
  15988. var indentStr = source.content.indentStr;
  15989. if (indentStr === null) { return; }
  15990. if (!indentStringCounts[indentStr]) { indentStringCounts[indentStr] = 0; }
  15991. indentStringCounts[indentStr] += 1;
  15992. });
  15993. return (
  15994. Object.keys(indentStringCounts).sort(function (a, b) {
  15995. return indentStringCounts[a] - indentStringCounts[b];
  15996. })[0] || '\t'
  15997. );
  15998. };
  15999. Bundle.prototype.indent = function indent (indentStr) {
  16000. var this$1 = this;
  16001. if (!arguments.length) {
  16002. indentStr = this.getIndentString();
  16003. }
  16004. if (indentStr === '') { return this; } // noop
  16005. var trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
  16006. this.sources.forEach(function (source, i) {
  16007. var separator = source.separator !== undefined ? source.separator : this$1.separator;
  16008. var indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));
  16009. source.content.indent(indentStr, {
  16010. exclude: source.indentExclusionRanges,
  16011. indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
  16012. });
  16013. trailingNewline = source.content.lastChar() === '\n';
  16014. });
  16015. if (this.intro) {
  16016. this.intro =
  16017. indentStr +
  16018. this.intro.replace(/^[^\n]/gm, function (match, index) {
  16019. return index > 0 ? indentStr + match : match;
  16020. });
  16021. }
  16022. return this;
  16023. };
  16024. Bundle.prototype.prepend = function prepend (str) {
  16025. this.intro = str + this.intro;
  16026. return this;
  16027. };
  16028. Bundle.prototype.toString = function toString () {
  16029. var this$1 = this;
  16030. var body = this.sources
  16031. .map(function (source, i) {
  16032. var separator = source.separator !== undefined ? source.separator : this$1.separator;
  16033. var str = (i > 0 ? separator : '') + source.content.toString();
  16034. return str;
  16035. })
  16036. .join('');
  16037. return this.intro + body;
  16038. };
  16039. Bundle.prototype.isEmpty = function isEmpty () {
  16040. if (this.intro.length && this.intro.trim())
  16041. { return false; }
  16042. if (this.sources.some(function (source) { return !source.content.isEmpty(); }))
  16043. { return false; }
  16044. return true;
  16045. };
  16046. Bundle.prototype.trimLines = function trimLines () {
  16047. return this.trim('[\\r\\n]');
  16048. };
  16049. Bundle.prototype.trim = function trim (charType) {
  16050. return this.trimStart(charType).trimEnd(charType);
  16051. };
  16052. Bundle.prototype.trimStart = function trimStart (charType) {
  16053. var this$1 = this;
  16054. var rx = new RegExp('^' + (charType || '\\s') + '+');
  16055. this.intro = this.intro.replace(rx, '');
  16056. if (!this.intro) {
  16057. var source;
  16058. var i = 0;
  16059. do {
  16060. source = this$1.sources[i++];
  16061. if (!source) {
  16062. break;
  16063. }
  16064. } while (!source.content.trimStartAborted(charType));
  16065. }
  16066. return this;
  16067. };
  16068. Bundle.prototype.trimEnd = function trimEnd (charType) {
  16069. var this$1 = this;
  16070. var rx = new RegExp((charType || '\\s') + '+$');
  16071. var source;
  16072. var i = this.sources.length - 1;
  16073. do {
  16074. source = this$1.sources[i--];
  16075. if (!source) {
  16076. this$1.intro = this$1.intro.replace(rx, '');
  16077. break;
  16078. }
  16079. } while (!source.content.trimEndAborted(charType));
  16080. return this;
  16081. };
  16082. const keys = {
  16083. ObjectExpression: 'properties',
  16084. Program: 'body',
  16085. };
  16086. const offsets = {
  16087. ObjectExpression: [1, -1],
  16088. Program: [0, 0],
  16089. };
  16090. function removeNode(code, parent, node) {
  16091. const key = keys[parent.type];
  16092. const offset = offsets[parent.type];
  16093. if (!key || !offset)
  16094. throw new Error(`not implemented: ${parent.type}`);
  16095. const list = parent[key];
  16096. const i = list.indexOf(node);
  16097. if (i === -1)
  16098. throw new Error('node not in list');
  16099. let a;
  16100. let b;
  16101. if (list.length === 1) {
  16102. // remove everything, leave {}
  16103. a = parent.start + offset[0];
  16104. b = parent.end + offset[1];
  16105. }
  16106. else if (i === 0) {
  16107. // remove everything before second node, including comments
  16108. a = parent.start + offset[0];
  16109. while (/\s/.test(code.original[a]))
  16110. a += 1;
  16111. b = list[i].end;
  16112. while (/[\s,]/.test(code.original[b]))
  16113. b += 1;
  16114. }
  16115. else {
  16116. // remove the end of the previous node to the end of this one
  16117. a = list[i - 1].end;
  16118. b = node.end;
  16119. }
  16120. code.remove(a, b);
  16121. list.splice(i, 1);
  16122. return;
  16123. }
  16124. const wrappers = { es, amd, cjs, iife, umd, eval: expr };
  16125. function wrapModule(code, format, name, options, banner, sharedPath, helpers, imports, shorthandImports, source) {
  16126. if (format === 'es')
  16127. return es(code, name, options, banner, sharedPath, helpers, imports, shorthandImports, source);
  16128. const dependencies = imports.map((declaration, i) => {
  16129. const defaultImport = declaration.specifiers.find((x) => x.type === 'ImportDefaultSpecifier' ||
  16130. (x.type === 'ImportSpecifier' && x.imported.name === 'default'));
  16131. const namespaceImport = declaration.specifiers.find((x) => x.type === 'ImportNamespaceSpecifier');
  16132. const namedImports = declaration.specifiers.filter((x) => x.type === 'ImportSpecifier' && x.imported.name !== 'default');
  16133. const name = defaultImport || namespaceImport
  16134. ? (defaultImport || namespaceImport).local.name
  16135. : `__import${i}`;
  16136. const statements = [];
  16137. namedImports.forEach((specifier) => {
  16138. statements.push(`var ${specifier.local.name} = ${name}.${specifier.imported.name};`);
  16139. });
  16140. if (defaultImport) {
  16141. statements.push(`${name} = (${name} && ${name}.__esModule) ? ${name}["default"] : ${name};`);
  16142. }
  16143. return { name, statements, source: declaration.source.value };
  16144. })
  16145. .concat(shorthandImports.map(({ name, source }) => ({
  16146. name,
  16147. statements: [
  16148. `${name} = (${name} && ${name}.__esModule) ? ${name}["default"] : ${name};`,
  16149. ],
  16150. source,
  16151. })));
  16152. if (format === 'amd')
  16153. return amd(code, name, options, banner, dependencies);
  16154. if (format === 'cjs')
  16155. return cjs(code, name, options, banner, sharedPath, helpers, dependencies);
  16156. if (format === 'iife')
  16157. return iife(code, name, options, banner, dependencies);
  16158. if (format === 'umd')
  16159. return umd(code, name, options, banner, dependencies);
  16160. if (format === 'eval')
  16161. return expr(code, name, options, banner, dependencies);
  16162. throw new Error(`options.format is invalid (must be ${list$2(Object.keys(wrappers))})`);
  16163. }
  16164. function es(code, name, options, banner, sharedPath, helpers, imports, shorthandImports, source) {
  16165. 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)};`);
  16166. const importBlock = imports.length > 0 && (imports
  16167. .map((declaration) => source.slice(declaration.start, declaration.end))
  16168. .join('\n'));
  16169. const shorthandImportBlock = shorthandImports.length > 0 && (shorthandImports.map(({ name, source }) => `import ${name} from ${JSON.stringify(source)};`).join('\n'));
  16170. return deindent `
  16171. ${banner}
  16172. ${importHelpers}
  16173. ${importBlock}
  16174. ${shorthandImportBlock}
  16175. ${code}
  16176. export default ${name};`;
  16177. }
  16178. function amd(code, name, options, banner, dependencies) {
  16179. const sourceString = dependencies.length
  16180. ? `[${dependencies.map(d => `"${removeExtension(d.source)}"`).join(', ')}], `
  16181. : '';
  16182. const id = options.amd && options.amd.id;
  16183. return deindent `
  16184. define(${id ? `"${id}", ` : ''}${sourceString}function(${paramString(dependencies)}) { "use strict";
  16185. ${getCompatibilityStatements(dependencies)}
  16186. ${code}
  16187. return ${name};
  16188. });`;
  16189. }
  16190. function cjs(code, name, options, banner, sharedPath, helpers, dependencies) {
  16191. const helperDeclarations = helpers.map(h => `${h.alias === h.name ? h.name : `${h.name}: ${h.alias}`}`).join(', ');
  16192. const helperBlock = helpers.length > 0 && (`var { ${helperDeclarations} } = require(${JSON.stringify(sharedPath)});\n`);
  16193. const requireBlock = dependencies.length > 0 && (dependencies
  16194. .map(d => `var ${d.name} = require("${d.source}");`)
  16195. .join('\n\n'));
  16196. return deindent `
  16197. ${banner}
  16198. "use strict";
  16199. ${helperBlock}
  16200. ${requireBlock}
  16201. ${getCompatibilityStatements(dependencies)}
  16202. ${code}
  16203. module.exports = ${name};`;
  16204. }
  16205. function iife(code, name, options, banner, dependencies) {
  16206. if (!options.name) {
  16207. throw new Error(`Missing required 'name' option for IIFE export`);
  16208. }
  16209. const globals = getGlobals(dependencies, options);
  16210. return deindent `
  16211. ${banner}
  16212. var ${options.name} = (function(${paramString(dependencies)}) { "use strict";
  16213. ${getCompatibilityStatements(dependencies)}
  16214. ${code}
  16215. return ${name};
  16216. }(${globals.join(', ')}));`;
  16217. }
  16218. function umd(code, name, options, banner, dependencies) {
  16219. if (!options.name) {
  16220. throw new Error(`Missing required 'name' option for UMD export`);
  16221. }
  16222. const amdId = options.amd && options.amd.id ? `'${options.amd.id}', ` : '';
  16223. const amdDeps = dependencies.length
  16224. ? `[${dependencies.map(d => `"${removeExtension(d.source)}"`).join(', ')}], `
  16225. : '';
  16226. const cjsDeps = dependencies
  16227. .map(d => `require("${d.source}")`)
  16228. .join(', ');
  16229. const globals = getGlobals(dependencies, options);
  16230. return deindent `
  16231. ${banner}
  16232. (function(global, factory) {
  16233. typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory(${cjsDeps}) :
  16234. typeof define === "function" && define.amd ? define(${amdId}${amdDeps}factory) :
  16235. (global.${options.name} = factory(${globals.join(', ')}));
  16236. }(this, (function (${paramString(dependencies)}) { "use strict";
  16237. ${getCompatibilityStatements(dependencies)}
  16238. ${code}
  16239. return ${name};
  16240. })));`;
  16241. }
  16242. function expr(code, name, options, banner, dependencies) {
  16243. const globals = getGlobals(dependencies, options);
  16244. return deindent `
  16245. (function (${paramString(dependencies)}) { "use strict";
  16246. ${banner}
  16247. ${getCompatibilityStatements(dependencies)}
  16248. ${code}
  16249. return ${name};
  16250. }(${globals.join(', ')}))`;
  16251. }
  16252. function paramString(dependencies) {
  16253. return dependencies.map(dep => dep.name).join(', ');
  16254. }
  16255. function removeExtension(file) {
  16256. const index = file.lastIndexOf('.');
  16257. return ~index ? file.slice(0, index) : file;
  16258. }
  16259. function getCompatibilityStatements(dependencies) {
  16260. if (!dependencies.length)
  16261. return null;
  16262. const statements = [];
  16263. dependencies.forEach(dependency => {
  16264. statements.push(...dependency.statements);
  16265. });
  16266. return statements.join('\n');
  16267. }
  16268. function getGlobals(dependencies, options) {
  16269. const { globals, onerror, onwarn } = options;
  16270. const globalFn = getGlobalFn(globals);
  16271. return dependencies.map(d => {
  16272. let name = globalFn(d.source);
  16273. if (!name) {
  16274. if (d.name.startsWith('__import')) {
  16275. const error = new Error(`Could not determine name for imported module '${d.source}' – use options.globals`);
  16276. onerror(error);
  16277. }
  16278. else {
  16279. const warning = {
  16280. code: `options-missing-globals`,
  16281. message: `No name was supplied for imported module '${d.source}'. Guessing '${d.name}', but you should use options.globals`,
  16282. };
  16283. onwarn(warning);
  16284. }
  16285. name = d.name;
  16286. }
  16287. return name;
  16288. });
  16289. }
  16290. function getGlobalFn(globals) {
  16291. if (typeof globals === 'function')
  16292. return globals;
  16293. if (typeof globals === 'object') {
  16294. return id => globals[id];
  16295. }
  16296. return () => undefined;
  16297. }
  16298. function createScopes(expression) {
  16299. const map = new WeakMap();
  16300. const globals = new Set();
  16301. let scope = new Scope(null, false);
  16302. walk(expression, {
  16303. enter(node, parent) {
  16304. if (/Function/.test(node.type)) {
  16305. if (node.type === 'FunctionDeclaration') {
  16306. scope.declarations.add(node.id.name);
  16307. }
  16308. else {
  16309. scope = new Scope(scope, false);
  16310. map.set(node, scope);
  16311. if (node.id)
  16312. scope.declarations.add(node.id.name);
  16313. }
  16314. node.params.forEach((param) => {
  16315. extractNames(param).forEach(name => {
  16316. scope.declarations.add(name);
  16317. });
  16318. });
  16319. }
  16320. else if (/For(?:In|Of)Statement/.test(node.type)) {
  16321. scope = new Scope(scope, true);
  16322. map.set(node, scope);
  16323. }
  16324. else if (node.type === 'BlockStatement') {
  16325. scope = new Scope(scope, true);
  16326. map.set(node, scope);
  16327. }
  16328. else if (/(Function|Class|Variable)Declaration/.test(node.type)) {
  16329. scope.addDeclaration(node);
  16330. }
  16331. else if (isReference(node, parent)) {
  16332. if (!scope.has(node.name)) {
  16333. globals.add(node.name);
  16334. }
  16335. }
  16336. },
  16337. leave(node) {
  16338. if (map.has(node)) {
  16339. scope = scope.parent;
  16340. }
  16341. },
  16342. });
  16343. return { map, scope, globals };
  16344. }
  16345. // TODO remove this in favour of weakmap version
  16346. function annotateWithScopes(expression) {
  16347. const globals = new Set();
  16348. let scope = new Scope(null, false);
  16349. walk(expression, {
  16350. enter(node, parent) {
  16351. if (/Function/.test(node.type)) {
  16352. if (node.type === 'FunctionDeclaration') {
  16353. scope.declarations.add(node.id.name);
  16354. }
  16355. else {
  16356. node._scope = scope = new Scope(scope, false);
  16357. if (node.id)
  16358. scope.declarations.add(node.id.name);
  16359. }
  16360. node.params.forEach((param) => {
  16361. extractNames(param).forEach(name => {
  16362. scope.declarations.add(name);
  16363. });
  16364. });
  16365. }
  16366. else if (/For(?:In|Of)Statement/.test(node.type)) {
  16367. node._scope = scope = new Scope(scope, true);
  16368. }
  16369. else if (node.type === 'BlockStatement') {
  16370. node._scope = scope = new Scope(scope, true);
  16371. }
  16372. else if (/(Function|Class|Variable)Declaration/.test(node.type)) {
  16373. scope.addDeclaration(node);
  16374. }
  16375. else if (isReference(node, parent)) {
  16376. if (!scope.has(node.name)) {
  16377. globals.add(node.name);
  16378. }
  16379. }
  16380. },
  16381. leave(node) {
  16382. if (node._scope) {
  16383. scope = scope.parent;
  16384. }
  16385. },
  16386. });
  16387. return { scope, globals };
  16388. }
  16389. class Scope {
  16390. constructor(parent, block) {
  16391. this.parent = parent;
  16392. this.block = block;
  16393. this.declarations = new Set();
  16394. }
  16395. addDeclaration(node) {
  16396. if (node.kind === 'var' && !this.block && this.parent) {
  16397. this.parent.addDeclaration(node);
  16398. }
  16399. else if (node.type === 'VariableDeclaration') {
  16400. node.declarations.forEach((declarator) => {
  16401. extractNames(declarator.id).forEach(name => {
  16402. this.declarations.add(name);
  16403. });
  16404. });
  16405. }
  16406. else {
  16407. this.declarations.add(node.id.name);
  16408. }
  16409. }
  16410. has(name) {
  16411. return (this.declarations.has(name) || (this.parent && this.parent.has(name)));
  16412. }
  16413. }
  16414. function extractNames(param) {
  16415. const names = [];
  16416. extractors[param.type](names, param);
  16417. return names;
  16418. }
  16419. const extractors = {
  16420. Identifier(names, param) {
  16421. names.push(param.name);
  16422. },
  16423. ObjectPattern(names, param) {
  16424. param.properties.forEach((prop) => {
  16425. extractors[prop.value.type](names, prop.value);
  16426. });
  16427. },
  16428. ArrayPattern(names, param) {
  16429. param.elements.forEach((element) => {
  16430. if (element)
  16431. extractors[element.type](names, element);
  16432. });
  16433. },
  16434. RestElement(names, param) {
  16435. extractors[param.argument.type](names, param.argument);
  16436. },
  16437. AssignmentPattern(names, param) {
  16438. extractors[param.left.type](names, param.left);
  16439. },
  16440. };
  16441. const test = typeof process !== 'undefined' && process.env.TEST;
  16442. class Node$1 {
  16443. constructor(compiler, parent, scope, info) {
  16444. this.start = info.start;
  16445. this.end = info.end;
  16446. this.type = info.type;
  16447. // this makes properties non-enumerable, which makes logging
  16448. // bearable. might have a performance cost. TODO remove in prod?
  16449. Object.defineProperties(this, {
  16450. compiler: {
  16451. value: compiler
  16452. },
  16453. parent: {
  16454. value: parent
  16455. }
  16456. });
  16457. }
  16458. cannotUseInnerHTML() {
  16459. if (this.canUseInnerHTML !== false) {
  16460. this.canUseInnerHTML = false;
  16461. if (this.parent)
  16462. this.parent.cannotUseInnerHTML();
  16463. }
  16464. }
  16465. init(block, stripWhitespace, nextSibling) {
  16466. // implemented by subclasses
  16467. }
  16468. initChildren(block, stripWhitespace, nextSibling) {
  16469. // glue text nodes together
  16470. const cleaned = [];
  16471. let lastChild;
  16472. let windowComponent;
  16473. this.children.forEach((child) => {
  16474. if (child.type === 'Comment')
  16475. return;
  16476. // special case — this is an easy way to remove whitespace surrounding
  16477. // <svelte:window/>. lil hacky but it works
  16478. if (child.type === 'Window') {
  16479. windowComponent = child;
  16480. return;
  16481. }
  16482. if (child.type === 'Text' && lastChild && lastChild.type === 'Text') {
  16483. lastChild.data += child.data;
  16484. lastChild.end = child.end;
  16485. }
  16486. else {
  16487. if (child.type === 'Text' && stripWhitespace && cleaned.length === 0) {
  16488. child.data = trimStart(child.data);
  16489. if (child.data)
  16490. cleaned.push(child);
  16491. }
  16492. else {
  16493. cleaned.push(child);
  16494. }
  16495. }
  16496. lastChild = child;
  16497. });
  16498. lastChild = null;
  16499. cleaned.forEach((child, i) => {
  16500. child.canUseInnerHTML = !this.compiler.options.hydratable;
  16501. child.init(block, stripWhitespace, cleaned[i + 1] || nextSibling);
  16502. if (child.shouldSkip)
  16503. return;
  16504. if (lastChild)
  16505. lastChild.next = child;
  16506. child.prev = lastChild;
  16507. lastChild = child;
  16508. });
  16509. // We want to remove trailing whitespace inside an element/component/block,
  16510. // *unless* there is no whitespace between this node and its next sibling
  16511. if (stripWhitespace && lastChild && lastChild.type === 'Text') {
  16512. const shouldTrim = (nextSibling ? (nextSibling.type === 'Text' && /^\s/.test(nextSibling.data)) : !this.hasAncestor('EachBlock'));
  16513. if (shouldTrim) {
  16514. lastChild.data = trimEnd(lastChild.data);
  16515. if (!lastChild.data) {
  16516. cleaned.pop();
  16517. lastChild = cleaned[cleaned.length - 1];
  16518. lastChild.next = null;
  16519. }
  16520. }
  16521. }
  16522. this.children = cleaned;
  16523. if (windowComponent)
  16524. cleaned.unshift(windowComponent);
  16525. }
  16526. build(block, parentNode, parentNodes) {
  16527. // implemented by subclasses
  16528. }
  16529. isDomNode() {
  16530. return this.type === 'Element' || this.type === 'Text' || this.type === 'MustacheTag';
  16531. }
  16532. hasAncestor(type) {
  16533. return this.parent ?
  16534. this.parent.type === type || this.parent.hasAncestor(type) :
  16535. false;
  16536. }
  16537. findNearest(selector) {
  16538. if (selector.test(this.type))
  16539. return this;
  16540. if (this.parent)
  16541. return this.parent.findNearest(selector);
  16542. }
  16543. getOrCreateAnchor(block, parentNode, parentNodes) {
  16544. // TODO use this in EachBlock and IfBlock — tricky because
  16545. // children need to be created first
  16546. const needsAnchor = this.next ? !this.next.isDomNode() : !parentNode || !this.parent.isDomNode();
  16547. const anchor = needsAnchor
  16548. ? block.getUniqueName(`${this.var}_anchor`)
  16549. : (this.next && this.next.var) || 'null';
  16550. if (needsAnchor) {
  16551. block.addElement(anchor, `@createComment()`, parentNodes && `@createComment()`, parentNode);
  16552. }
  16553. return anchor;
  16554. }
  16555. getUpdateMountNode(anchor) {
  16556. return this.parent.isDomNode() ? this.parent.var : `${anchor}.parentNode`;
  16557. }
  16558. remount(name) {
  16559. return `${this.var}.m(${name}._slotted.default, null);`;
  16560. }
  16561. }
  16562. class PendingBlock extends Node$1 {
  16563. constructor(compiler, parent, scope, info) {
  16564. super(compiler, parent, scope, info);
  16565. this.children = mapChildren(compiler, parent, scope, info.children);
  16566. }
  16567. }
  16568. class ThenBlock extends Node$1 {
  16569. constructor(compiler, parent, scope, info) {
  16570. super(compiler, parent, scope, info);
  16571. this.children = mapChildren(compiler, parent, scope, info.children);
  16572. }
  16573. }
  16574. class CatchBlock extends Node$1 {
  16575. constructor(compiler, parent, scope, info) {
  16576. super(compiler, parent, scope, info);
  16577. this.children = mapChildren(compiler, parent, scope, info.children);
  16578. }
  16579. }
  16580. function createDebuggingComment(node, compiler) {
  16581. const { locate, source } = compiler;
  16582. let c = node.start;
  16583. if (node.type === 'ElseBlock') {
  16584. while (source[c - 1] !== '{')
  16585. c -= 1;
  16586. while (source[c - 1] === '{')
  16587. c -= 1;
  16588. }
  16589. let d = node.expression ? node.expression.node.end : c;
  16590. while (source[d] !== '}')
  16591. d += 1;
  16592. while (source[d] === '}')
  16593. d += 1;
  16594. const start = locate(c);
  16595. const loc = `(${start.line + 1}:${start.column})`;
  16596. return `${loc} ${source.slice(c, d)}`.replace(/\s/g, ' ');
  16597. }
  16598. const binaryOperators = {
  16599. '**': 15,
  16600. '*': 14,
  16601. '/': 14,
  16602. '%': 14,
  16603. '+': 13,
  16604. '-': 13,
  16605. '<<': 12,
  16606. '>>': 12,
  16607. '>>>': 12,
  16608. '<': 11,
  16609. '<=': 11,
  16610. '>': 11,
  16611. '>=': 11,
  16612. 'in': 11,
  16613. 'instanceof': 11,
  16614. '==': 10,
  16615. '!=': 10,
  16616. '===': 10,
  16617. '!==': 10,
  16618. '&': 9,
  16619. '^': 8,
  16620. '|': 7
  16621. };
  16622. const logicalOperators = {
  16623. '&&': 6,
  16624. '||': 5
  16625. };
  16626. const precedence = {
  16627. Literal: () => 21,
  16628. Identifier: () => 21,
  16629. ParenthesizedExpression: () => 20,
  16630. MemberExpression: () => 19,
  16631. NewExpression: () => 19,
  16632. CallExpression: () => 19,
  16633. UpdateExpression: () => 17,
  16634. UnaryExpression: () => 16,
  16635. BinaryExpression: (node) => binaryOperators[node.operator],
  16636. LogicalExpression: (node) => logicalOperators[node.operator],
  16637. ConditionalExpression: () => 4,
  16638. AssignmentExpression: () => 3,
  16639. YieldExpression: () => 2,
  16640. SpreadElement: () => 1,
  16641. SequenceExpression: () => 0
  16642. };
  16643. class Expression {
  16644. constructor(compiler, parent, scope, info) {
  16645. // TODO revert to direct property access in prod?
  16646. Object.defineProperties(this, {
  16647. compiler: {
  16648. value: compiler
  16649. }
  16650. });
  16651. this.node = info;
  16652. this.thisReferences = [];
  16653. this.snippet = `[✂${info.start}-${info.end}✂]`;
  16654. this.usesContext = false;
  16655. const dependencies = new Set();
  16656. const { code, helpers } = compiler;
  16657. let { map, scope: currentScope } = createScopes(info);
  16658. const isEventHandler = parent.type === 'EventHandler';
  16659. const expression = this;
  16660. const isSynthetic = parent.isSynthetic;
  16661. walk(info, {
  16662. enter(node, parent, key) {
  16663. // don't manipulate shorthand props twice
  16664. if (key === 'value' && parent.shorthand)
  16665. return;
  16666. code.addSourcemapLocation(node.start);
  16667. code.addSourcemapLocation(node.end);
  16668. if (map.has(node)) {
  16669. currentScope = map.get(node);
  16670. return;
  16671. }
  16672. if (node.type === 'ThisExpression') {
  16673. expression.thisReferences.push(node);
  16674. }
  16675. if (isReference(node, parent)) {
  16676. const { name, nodes } = flattenReference(node);
  16677. if (currentScope.has(name) || (name === 'event' && isEventHandler))
  16678. return;
  16679. if (compiler.helpers.has(name)) {
  16680. let object = node;
  16681. while (object.type === 'MemberExpression')
  16682. object = object.object;
  16683. const alias = compiler.templateVars.get(`helpers-${name}`);
  16684. if (alias !== name)
  16685. code.overwrite(object.start, object.end, alias);
  16686. return;
  16687. }
  16688. expression.usesContext = true;
  16689. if (!isSynthetic) {
  16690. // <option> value attribute could be synthetic — avoid double editing
  16691. code.prependRight(node.start, key === 'key' && parent.shorthand
  16692. ? `${name}: ctx.`
  16693. : 'ctx.');
  16694. }
  16695. if (scope.names.has(name)) {
  16696. scope.dependenciesForName.get(name).forEach(dependency => {
  16697. dependencies.add(dependency);
  16698. });
  16699. }
  16700. else {
  16701. dependencies.add(name);
  16702. compiler.expectedProperties.add(name);
  16703. }
  16704. if (node.type === 'MemberExpression') {
  16705. nodes.forEach(node => {
  16706. code.addSourcemapLocation(node.start);
  16707. code.addSourcemapLocation(node.end);
  16708. });
  16709. }
  16710. this.skip();
  16711. }
  16712. },
  16713. leave(node, parent) {
  16714. if (map.has(node))
  16715. currentScope = currentScope.parent;
  16716. }
  16717. });
  16718. this.dependencies = dependencies;
  16719. }
  16720. getPrecedence() {
  16721. return this.node.type in precedence ? precedence[this.node.type](this.node) : 0;
  16722. }
  16723. overwriteThis(name) {
  16724. this.thisReferences.forEach(ref => {
  16725. this.compiler.code.overwrite(ref.start, ref.end, name, {
  16726. storeName: true
  16727. });
  16728. });
  16729. }
  16730. }
  16731. class AwaitBlock extends Node$1 {
  16732. constructor(compiler, parent, scope, info) {
  16733. super(compiler, parent, scope, info);
  16734. this.expression = new Expression(compiler, this, scope, info.expression);
  16735. const deps = this.expression.dependencies;
  16736. this.value = info.value;
  16737. this.error = info.error;
  16738. this.pending = new PendingBlock(compiler, this, scope, info.pending);
  16739. this.then = new ThenBlock(compiler, this, scope.add(this.value, deps), info.then);
  16740. this.catch = new CatchBlock(compiler, this, scope.add(this.error, deps), info.catch);
  16741. }
  16742. init(block, stripWhitespace, nextSibling) {
  16743. this.cannotUseInnerHTML();
  16744. this.var = block.getUniqueName('await_block');
  16745. block.addDependencies(this.expression.dependencies);
  16746. let isDynamic = false;
  16747. let hasIntros = false;
  16748. let hasOutros = false;
  16749. ['pending', 'then', 'catch'].forEach(status => {
  16750. const child = this[status];
  16751. child.block = block.child({
  16752. comment: createDebuggingComment(child, this.compiler),
  16753. name: this.compiler.getUniqueName(`create_${status}_block`)
  16754. });
  16755. child.initChildren(child.block, stripWhitespace, nextSibling);
  16756. this.compiler.target.blocks.push(child.block);
  16757. if (child.block.dependencies.size > 0) {
  16758. isDynamic = true;
  16759. block.addDependencies(child.block.dependencies);
  16760. }
  16761. if (child.block.hasIntros)
  16762. hasIntros = true;
  16763. if (child.block.hasOutros)
  16764. hasOutros = true;
  16765. });
  16766. this.pending.block.hasUpdateMethod = isDynamic;
  16767. this.then.block.hasUpdateMethod = isDynamic;
  16768. this.catch.block.hasUpdateMethod = isDynamic;
  16769. this.pending.block.hasIntroMethod = hasIntros;
  16770. this.then.block.hasIntroMethod = hasIntros;
  16771. this.catch.block.hasIntroMethod = hasIntros;
  16772. this.pending.block.hasOutroMethod = hasOutros;
  16773. this.then.block.hasOutroMethod = hasOutros;
  16774. this.catch.block.hasOutroMethod = hasOutros;
  16775. if (hasOutros && this.compiler.options.nestedTransitions)
  16776. block.addOutro();
  16777. }
  16778. build(block, parentNode, parentNodes) {
  16779. const name = this.var;
  16780. const anchor = this.getOrCreateAnchor(block, parentNode, parentNodes);
  16781. const updateMountNode = this.getUpdateMountNode(anchor);
  16782. const { snippet } = this.expression;
  16783. const info = block.getUniqueName(`info`);
  16784. const promise = block.getUniqueName(`promise`);
  16785. block.addVariable(promise);
  16786. block.maintainContext = true;
  16787. const infoProps = [
  16788. block.alias('component') === 'component' ? 'component' : `component: #component`,
  16789. 'ctx',
  16790. 'current: null',
  16791. this.pending.block.name && `pending: ${this.pending.block.name}`,
  16792. this.then.block.name && `then: ${this.then.block.name}`,
  16793. this.catch.block.name && `catch: ${this.catch.block.name}`,
  16794. this.then.block.name && `value: '${this.value}'`,
  16795. this.catch.block.name && `error: '${this.error}'`,
  16796. this.pending.block.hasOutroMethod && `blocks: Array(3)`
  16797. ].filter(Boolean);
  16798. block.builders.init.addBlock(deindent `
  16799. let ${info} = {
  16800. ${infoProps.join(',\n')}
  16801. };
  16802. `);
  16803. block.builders.init.addBlock(deindent `
  16804. @handlePromise(${promise} = ${snippet}, ${info});
  16805. `);
  16806. block.builders.create.addBlock(deindent `
  16807. ${info}.block.c();
  16808. `);
  16809. if (parentNodes) {
  16810. block.builders.claim.addBlock(deindent `
  16811. ${info}.block.l(${parentNodes});
  16812. `);
  16813. }
  16814. const initialMountNode = parentNode || '#target';
  16815. const anchorNode = parentNode ? 'null' : 'anchor';
  16816. const hasTransitions = this.pending.block.hasIntroMethod || this.pending.block.hasOutroMethod;
  16817. block.builders.mount.addBlock(deindent `
  16818. ${info}.block.${hasTransitions ? 'i' : 'm'}(${initialMountNode}, ${info}.anchor = ${anchorNode});
  16819. ${info}.mount = () => ${updateMountNode};
  16820. `);
  16821. const conditions = [];
  16822. if (this.expression.dependencies.size > 0) {
  16823. conditions.push(`(${[...this.expression.dependencies].map(dep => `'${dep}' in changed`).join(' || ')})`);
  16824. }
  16825. conditions.push(`${promise} !== (${promise} = ${snippet})`, `@handlePromise(${promise}, ${info})`);
  16826. block.builders.update.addLine(`${info}.ctx = ctx;`);
  16827. if (this.pending.block.hasUpdateMethod) {
  16828. block.builders.update.addBlock(deindent `
  16829. if (${conditions.join(' && ')}) {
  16830. // nothing
  16831. } else {
  16832. ${info}.block.p(changed, @assign(@assign({}, ctx), ${info}.resolved));
  16833. }
  16834. `);
  16835. }
  16836. else {
  16837. block.builders.update.addBlock(deindent `
  16838. ${conditions.join(' && ')}
  16839. `);
  16840. }
  16841. if (this.pending.block.hasOutroMethod && this.compiler.options.nestedTransitions) {
  16842. block.builders.outro.addBlock(deindent `
  16843. #outrocallback = @callAfter(#outrocallback, 3);
  16844. for (let #i = 0; #i < 3; #i += 1) {
  16845. const block = ${info}.blocks[#i];
  16846. if (block) block.o(#outrocallback);
  16847. else #outrocallback();
  16848. }
  16849. `);
  16850. }
  16851. block.builders.destroy.addBlock(deindent `
  16852. ${info}.block.d(${parentNode ? '' : 'detach'});
  16853. ${info} = null;
  16854. `);
  16855. [this.pending, this.then, this.catch].forEach(status => {
  16856. status.children.forEach(child => {
  16857. child.build(status.block, null, 'nodes');
  16858. });
  16859. });
  16860. }
  16861. ssr() {
  16862. const target = this.compiler.target;
  16863. const { snippet } = this.expression;
  16864. target.append('${(function(__value) { if(@isPromise(__value)) return `');
  16865. this.pending.children.forEach((child) => {
  16866. child.ssr();
  16867. });
  16868. target.append('`; return function(ctx) { return `');
  16869. this.then.children.forEach((child) => {
  16870. child.ssr();
  16871. });
  16872. target.append(`\`;}(Object.assign({}, ctx, { ${this.value}: __value }));}(${snippet})) }`);
  16873. }
  16874. }
  16875. class Comment$2 extends Node$1 {
  16876. constructor(compiler, parent, scope, info) {
  16877. super(compiler, parent, scope, info);
  16878. this.data = info.data;
  16879. }
  16880. ssr() {
  16881. // Allow option to preserve comments, otherwise ignore
  16882. if (this.compiler.options.preserveComments) {
  16883. this.compiler.target.append(`<!--${this.data}-->`);
  16884. }
  16885. }
  16886. }
  16887. function stringifyProps(props) {
  16888. if (!props.length)
  16889. return '{}';
  16890. const joined = props.join(', ');
  16891. if (joined.length > 40) {
  16892. // make larger data objects readable
  16893. return `{\n\t${props.join(',\n\t')}\n}`;
  16894. }
  16895. return `{ ${joined} }`;
  16896. }
  16897. function getTailSnippet(node) {
  16898. const end = node.end;
  16899. while (node.type === 'MemberExpression')
  16900. node = node.object;
  16901. const start = node.end;
  16902. return `[✂${start}-${end}✂]`;
  16903. }
  16904. function getObject(node) {
  16905. while (node.type === 'MemberExpression')
  16906. node = node.object;
  16907. return node;
  16908. }
  16909. function quoteNameIfNecessary(name) {
  16910. if (!isValidIdentifier(name))
  16911. return `"${name}"`;
  16912. return name;
  16913. }
  16914. function quotePropIfNecessary(name) {
  16915. if (!isValidIdentifier(name))
  16916. return `["${name}"]`;
  16917. return `.${name}`;
  16918. }
  16919. 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(' ');
  16920. const svgAttributeLookup = new Map();
  16921. svgAttributes.forEach(name => {
  16922. svgAttributeLookup.set(name.toLowerCase(), name);
  16923. });
  16924. function fixAttributeCasing(name) {
  16925. name = name.toLowerCase();
  16926. return svgAttributeLookup.get(name) || name;
  16927. }
  16928. function addToSet(a, b) {
  16929. b.forEach(item => {
  16930. a.add(item);
  16931. });
  16932. }
  16933. class Attribute extends Node$1 {
  16934. constructor(compiler, parent, scope, info) {
  16935. super(compiler, parent, scope, info);
  16936. if (info.type === 'Spread') {
  16937. this.name = null;
  16938. this.isSpread = true;
  16939. this.isTrue = false;
  16940. this.isSynthetic = false;
  16941. this.expression = new Expression(compiler, this, scope, info.expression);
  16942. this.dependencies = this.expression.dependencies;
  16943. this.chunks = null;
  16944. this.isDynamic = true; // TODO not necessarily
  16945. this.shouldCache = false; // TODO does this mean anything here?
  16946. }
  16947. else {
  16948. this.name = info.name;
  16949. this.isTrue = info.value === true;
  16950. this.isSynthetic = info.synthetic;
  16951. this.dependencies = new Set();
  16952. this.chunks = this.isTrue
  16953. ? []
  16954. : info.value.map(node => {
  16955. if (node.type === 'Text')
  16956. return node;
  16957. const expression = new Expression(compiler, this, scope, node.expression);
  16958. addToSet(this.dependencies, expression.dependencies);
  16959. return expression;
  16960. });
  16961. this.isDynamic = this.dependencies.size > 0;
  16962. this.shouldCache = this.isDynamic
  16963. ? this.chunks.length === 1
  16964. ? this.chunks[0].node.type !== 'Identifier' || scope.names.has(this.chunks[0].node.name)
  16965. : true
  16966. : false;
  16967. }
  16968. }
  16969. getValue() {
  16970. if (this.isTrue)
  16971. return true;
  16972. if (this.chunks.length === 0)
  16973. return `""`;
  16974. if (this.chunks.length === 1) {
  16975. return this.chunks[0].type === 'Text'
  16976. ? stringify(this.chunks[0].data)
  16977. : this.chunks[0].snippet;
  16978. }
  16979. return (this.chunks[0].type === 'Text' ? '' : `"" + `) +
  16980. this.chunks
  16981. .map(chunk => {
  16982. if (chunk.type === 'Text') {
  16983. return stringify(chunk.data);
  16984. }
  16985. else {
  16986. return chunk.getPrecedence() <= 13 ? `(${chunk.snippet})` : chunk.snippet;
  16987. }
  16988. })
  16989. .join(' + ');
  16990. }
  16991. render(block) {
  16992. const node = this.parent;
  16993. const name = fixAttributeCasing(this.name);
  16994. if (name === 'style') {
  16995. const styleProps = optimizeStyle(this.chunks);
  16996. if (styleProps) {
  16997. this.renderStyle(block, styleProps);
  16998. return;
  16999. }
  17000. }
  17001. let metadata = node.namespace ? null : attributeLookup[name];
  17002. if (metadata && metadata.appliesTo && !~metadata.appliesTo.indexOf(node.name))
  17003. metadata = null;
  17004. const isIndirectlyBoundValue = name === 'value' &&
  17005. (node.name === 'option' || // TODO check it's actually bound
  17006. (node.name === 'input' &&
  17007. node.bindings.find((binding) => /checked|group/.test(binding.name))));
  17008. const propertyName = isIndirectlyBoundValue
  17009. ? '__value'
  17010. : metadata && metadata.propertyName;
  17011. // xlink is a special case... we could maybe extend this to generic
  17012. // namespaced attributes but I'm not sure that's applicable in
  17013. // HTML5?
  17014. const method = name.slice(0, 6) === 'xlink:'
  17015. ? '@setXlinkAttribute'
  17016. : '@setAttribute';
  17017. const isLegacyInputType = this.compiler.options.legacy && name === 'type' && this.parent.name === 'input';
  17018. const isDataSet = /^data-/.test(name) && !this.compiler.options.legacy && !node.namespace;
  17019. const camelCaseName = isDataSet ? name.replace('data-', '').replace(/(-\w)/g, function (m) {
  17020. return m[1].toUpperCase();
  17021. }) : name;
  17022. if (this.isDynamic) {
  17023. let value;
  17024. // TODO some of this code is repeated in Tag.ts — would be good to
  17025. // DRY it out if that's possible without introducing crazy indirection
  17026. if (this.chunks.length === 1) {
  17027. // single {tag} — may be a non-string
  17028. value = this.chunks[0].snippet;
  17029. }
  17030. else {
  17031. // '{foo} {bar}' — treat as string concatenation
  17032. value =
  17033. (this.chunks[0].type === 'Text' ? '' : `"" + `) +
  17034. this.chunks
  17035. .map((chunk) => {
  17036. if (chunk.type === 'Text') {
  17037. return stringify(chunk.data);
  17038. }
  17039. else {
  17040. return chunk.getPrecedence() <= 13
  17041. ? `(${chunk.snippet})`
  17042. : chunk.snippet;
  17043. }
  17044. })
  17045. .join(' + ');
  17046. }
  17047. const isSelectValueAttribute = name === 'value' && node.name === 'select';
  17048. const shouldCache = this.shouldCache || isSelectValueAttribute;
  17049. const last = shouldCache && block.getUniqueName(`${node.var}_${name.replace(/[^a-zA-Z_$]/g, '_')}_value`);
  17050. if (shouldCache)
  17051. block.addVariable(last);
  17052. let updater;
  17053. const init = shouldCache ? `${last} = ${value}` : value;
  17054. if (isLegacyInputType) {
  17055. block.builders.hydrate.addLine(`@setInputType(${node.var}, ${init});`);
  17056. updater = `@setInputType(${node.var}, ${shouldCache ? last : value});`;
  17057. }
  17058. else if (isSelectValueAttribute) {
  17059. // annoying special case
  17060. const isMultipleSelect = node.getStaticAttributeValue('multiple');
  17061. const i = block.getUniqueName('i');
  17062. const option = block.getUniqueName('option');
  17063. const ifStatement = isMultipleSelect
  17064. ? deindent `
  17065. ${option}.selected = ~${last}.indexOf(${option}.__value);`
  17066. : deindent `
  17067. if (${option}.__value === ${last}) {
  17068. ${option}.selected = true;
  17069. break;
  17070. }`;
  17071. updater = deindent `
  17072. for (var ${i} = 0; ${i} < ${node.var}.options.length; ${i} += 1) {
  17073. var ${option} = ${node.var}.options[${i}];
  17074. ${ifStatement}
  17075. }
  17076. `;
  17077. block.builders.hydrate.addBlock(deindent `
  17078. ${last} = ${value};
  17079. ${updater}
  17080. `);
  17081. }
  17082. else if (propertyName) {
  17083. block.builders.hydrate.addLine(`${node.var}.${propertyName} = ${init};`);
  17084. updater = `${node.var}.${propertyName} = ${shouldCache ? last : value};`;
  17085. }
  17086. else if (isDataSet) {
  17087. block.builders.hydrate.addLine(`${node.var}.dataset.${camelCaseName} = ${init};`);
  17088. updater = `${node.var}.dataset.${camelCaseName} = ${shouldCache ? last : value};`;
  17089. }
  17090. else {
  17091. block.builders.hydrate.addLine(`${method}(${node.var}, "${name}", ${init});`);
  17092. updater = `${method}(${node.var}, "${name}", ${shouldCache ? last : value});`;
  17093. }
  17094. if (this.dependencies.size || isSelectValueAttribute) {
  17095. const dependencies = Array.from(this.dependencies);
  17096. const changedCheck = ((block.hasOutros ? `#outroing || ` : '') +
  17097. dependencies.map(dependency => `changed.${dependency}`).join(' || '));
  17098. const updateCachedValue = `${last} !== (${last} = ${value})`;
  17099. const condition = shouldCache ?
  17100. (dependencies.length ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue) :
  17101. changedCheck;
  17102. block.builders.update.addConditional(condition, updater);
  17103. }
  17104. }
  17105. else {
  17106. const value = this.getValue();
  17107. const statement = (isLegacyInputType
  17108. ? `@setInputType(${node.var}, ${value});`
  17109. : propertyName
  17110. ? `${node.var}.${propertyName} = ${value};`
  17111. : isDataSet
  17112. ? `${node.var}.dataset.${camelCaseName} = ${value};`
  17113. : `${method}(${node.var}, "${name}", ${value});`);
  17114. block.builders.hydrate.addLine(statement);
  17115. // special case – autofocus. has to be handled in a bit of a weird way
  17116. if (this.isTrue && name === 'autofocus') {
  17117. block.autofocus = node.var;
  17118. }
  17119. }
  17120. if (isIndirectlyBoundValue) {
  17121. const updateValue = `${node.var}.value = ${node.var}.__value;`;
  17122. block.builders.hydrate.addLine(updateValue);
  17123. if (this.isDynamic)
  17124. block.builders.update.addLine(updateValue);
  17125. }
  17126. }
  17127. renderStyle(block, styleProps) {
  17128. styleProps.forEach((prop) => {
  17129. let value;
  17130. if (isDynamic$1(prop.value)) {
  17131. const propDependencies = new Set();
  17132. value =
  17133. ((prop.value.length === 1 || prop.value[0].type === 'Text') ? '' : `"" + `) +
  17134. prop.value
  17135. .map((chunk) => {
  17136. if (chunk.type === 'Text') {
  17137. return stringify(chunk.data);
  17138. }
  17139. else {
  17140. const { dependencies, snippet } = chunk;
  17141. dependencies.forEach(d => {
  17142. propDependencies.add(d);
  17143. });
  17144. return chunk.getPrecedence() <= 13 ? `(${snippet})` : snippet;
  17145. }
  17146. })
  17147. .join(' + ');
  17148. if (propDependencies.size) {
  17149. const dependencies = Array.from(propDependencies);
  17150. const condition = ((block.hasOutros ? `#outroing || ` : '') +
  17151. dependencies.map(dependency => `changed.${dependency}`).join(' || '));
  17152. block.builders.update.addConditional(condition, `@setStyle(${this.parent.var}, "${prop.key}", ${value});`);
  17153. }
  17154. }
  17155. else {
  17156. value = stringify(prop.value[0].data);
  17157. }
  17158. block.builders.hydrate.addLine(`@setStyle(${this.parent.var}, "${prop.key}", ${value});`);
  17159. });
  17160. }
  17161. stringifyForSsr() {
  17162. return this.chunks
  17163. .map((chunk) => {
  17164. if (chunk.type === 'Text') {
  17165. return escapeTemplate(escape(chunk.data).replace(/"/g, '&quot;'));
  17166. }
  17167. return '${@escape(' + chunk.snippet + ')}';
  17168. })
  17169. .join('');
  17170. }
  17171. }
  17172. // source: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
  17173. const attributeLookup = {
  17174. accept: { appliesTo: ['form', 'input'] },
  17175. 'accept-charset': { propertyName: 'acceptCharset', appliesTo: ['form'] },
  17176. accesskey: { propertyName: 'accessKey' },
  17177. action: { appliesTo: ['form'] },
  17178. align: {
  17179. appliesTo: [
  17180. 'applet',
  17181. 'caption',
  17182. 'col',
  17183. 'colgroup',
  17184. 'hr',
  17185. 'iframe',
  17186. 'img',
  17187. 'table',
  17188. 'tbody',
  17189. 'td',
  17190. 'tfoot',
  17191. 'th',
  17192. 'thead',
  17193. 'tr',
  17194. ],
  17195. },
  17196. allowfullscreen: { propertyName: 'allowFullscreen', appliesTo: ['iframe'] },
  17197. alt: { appliesTo: ['applet', 'area', 'img', 'input'] },
  17198. async: { appliesTo: ['script'] },
  17199. autocomplete: { appliesTo: ['form', 'input'] },
  17200. autofocus: { appliesTo: ['button', 'input', 'keygen', 'select', 'textarea'] },
  17201. autoplay: { appliesTo: ['audio', 'video'] },
  17202. autosave: { appliesTo: ['input'] },
  17203. bgcolor: {
  17204. propertyName: 'bgColor',
  17205. appliesTo: [
  17206. 'body',
  17207. 'col',
  17208. 'colgroup',
  17209. 'marquee',
  17210. 'table',
  17211. 'tbody',
  17212. 'tfoot',
  17213. 'td',
  17214. 'th',
  17215. 'tr',
  17216. ],
  17217. },
  17218. border: { appliesTo: ['img', 'object', 'table'] },
  17219. buffered: { appliesTo: ['audio', 'video'] },
  17220. challenge: { appliesTo: ['keygen'] },
  17221. charset: { appliesTo: ['meta', 'script'] },
  17222. checked: { appliesTo: ['command', 'input'] },
  17223. cite: { appliesTo: ['blockquote', 'del', 'ins', 'q'] },
  17224. class: { propertyName: 'className' },
  17225. code: { appliesTo: ['applet'] },
  17226. codebase: { propertyName: 'codeBase', appliesTo: ['applet'] },
  17227. color: { appliesTo: ['basefont', 'font', 'hr'] },
  17228. cols: { appliesTo: ['textarea'] },
  17229. colspan: { propertyName: 'colSpan', appliesTo: ['td', 'th'] },
  17230. content: { appliesTo: ['meta'] },
  17231. contenteditable: { propertyName: 'contentEditable' },
  17232. contextmenu: {},
  17233. controls: { appliesTo: ['audio', 'video'] },
  17234. coords: { appliesTo: ['area'] },
  17235. data: { appliesTo: ['object'] },
  17236. datetime: { propertyName: 'dateTime', appliesTo: ['del', 'ins', 'time'] },
  17237. default: { appliesTo: ['track'] },
  17238. defer: { appliesTo: ['script'] },
  17239. dir: {},
  17240. dirname: { propertyName: 'dirName', appliesTo: ['input', 'textarea'] },
  17241. disabled: {
  17242. appliesTo: [
  17243. 'button',
  17244. 'command',
  17245. 'fieldset',
  17246. 'input',
  17247. 'keygen',
  17248. 'optgroup',
  17249. 'option',
  17250. 'select',
  17251. 'textarea',
  17252. ],
  17253. },
  17254. download: { appliesTo: ['a', 'area'] },
  17255. draggable: {},
  17256. dropzone: {},
  17257. enctype: { appliesTo: ['form'] },
  17258. for: { propertyName: 'htmlFor', appliesTo: ['label', 'output'] },
  17259. form: {
  17260. appliesTo: [
  17261. 'button',
  17262. 'fieldset',
  17263. 'input',
  17264. 'keygen',
  17265. 'label',
  17266. 'meter',
  17267. 'object',
  17268. 'output',
  17269. 'progress',
  17270. 'select',
  17271. 'textarea',
  17272. ],
  17273. },
  17274. formaction: { appliesTo: ['input', 'button'] },
  17275. headers: { appliesTo: ['td', 'th'] },
  17276. height: {
  17277. appliesTo: ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video'],
  17278. },
  17279. hidden: {},
  17280. high: { appliesTo: ['meter'] },
  17281. href: { appliesTo: ['a', 'area', 'base', 'link'] },
  17282. hreflang: { appliesTo: ['a', 'area', 'link'] },
  17283. 'http-equiv': { propertyName: 'httpEquiv', appliesTo: ['meta'] },
  17284. icon: { appliesTo: ['command'] },
  17285. id: {},
  17286. indeterminate: { appliesTo: ['input'] },
  17287. ismap: { propertyName: 'isMap', appliesTo: ['img'] },
  17288. itemprop: {},
  17289. keytype: { appliesTo: ['keygen'] },
  17290. kind: { appliesTo: ['track'] },
  17291. label: { appliesTo: ['track'] },
  17292. lang: {},
  17293. language: { appliesTo: ['script'] },
  17294. loop: { appliesTo: ['audio', 'bgsound', 'marquee', 'video'] },
  17295. low: { appliesTo: ['meter'] },
  17296. manifest: { appliesTo: ['html'] },
  17297. max: { appliesTo: ['input', 'meter', 'progress'] },
  17298. maxlength: { propertyName: 'maxLength', appliesTo: ['input', 'textarea'] },
  17299. media: { appliesTo: ['a', 'area', 'link', 'source', 'style'] },
  17300. method: { appliesTo: ['form'] },
  17301. min: { appliesTo: ['input', 'meter'] },
  17302. multiple: { appliesTo: ['input', 'select'] },
  17303. muted: { appliesTo: ['audio', 'video'] },
  17304. name: {
  17305. appliesTo: [
  17306. 'button',
  17307. 'form',
  17308. 'fieldset',
  17309. 'iframe',
  17310. 'input',
  17311. 'keygen',
  17312. 'object',
  17313. 'output',
  17314. 'select',
  17315. 'textarea',
  17316. 'map',
  17317. 'meta',
  17318. 'param',
  17319. ],
  17320. },
  17321. novalidate: { propertyName: 'noValidate', appliesTo: ['form'] },
  17322. open: { appliesTo: ['details'] },
  17323. optimum: { appliesTo: ['meter'] },
  17324. pattern: { appliesTo: ['input'] },
  17325. ping: { appliesTo: ['a', 'area'] },
  17326. placeholder: { appliesTo: ['input', 'textarea'] },
  17327. poster: { appliesTo: ['video'] },
  17328. preload: { appliesTo: ['audio', 'video'] },
  17329. radiogroup: { appliesTo: ['command'] },
  17330. readonly: { propertyName: 'readOnly', appliesTo: ['input', 'textarea'] },
  17331. rel: { appliesTo: ['a', 'area', 'link'] },
  17332. required: { appliesTo: ['input', 'select', 'textarea'] },
  17333. reversed: { appliesTo: ['ol'] },
  17334. rows: { appliesTo: ['textarea'] },
  17335. rowspan: { propertyName: 'rowSpan', appliesTo: ['td', 'th'] },
  17336. sandbox: { appliesTo: ['iframe'] },
  17337. scope: { appliesTo: ['th'] },
  17338. scoped: { appliesTo: ['style'] },
  17339. seamless: { appliesTo: ['iframe'] },
  17340. selected: { appliesTo: ['option'] },
  17341. shape: { appliesTo: ['a', 'area'] },
  17342. size: { appliesTo: ['input', 'select'] },
  17343. sizes: { appliesTo: ['link', 'img', 'source'] },
  17344. span: { appliesTo: ['col', 'colgroup'] },
  17345. spellcheck: {},
  17346. src: {
  17347. appliesTo: [
  17348. 'audio',
  17349. 'embed',
  17350. 'iframe',
  17351. 'img',
  17352. 'input',
  17353. 'script',
  17354. 'source',
  17355. 'track',
  17356. 'video',
  17357. ],
  17358. },
  17359. srcdoc: { appliesTo: ['iframe'] },
  17360. srclang: { appliesTo: ['track'] },
  17361. srcset: { appliesTo: ['img'] },
  17362. start: { appliesTo: ['ol'] },
  17363. step: { appliesTo: ['input'] },
  17364. style: { propertyName: 'style.cssText' },
  17365. summary: { appliesTo: ['table'] },
  17366. tabindex: { propertyName: 'tabIndex' },
  17367. target: { appliesTo: ['a', 'area', 'base', 'form'] },
  17368. title: {},
  17369. type: {
  17370. appliesTo: [
  17371. 'button',
  17372. 'command',
  17373. 'embed',
  17374. 'object',
  17375. 'script',
  17376. 'source',
  17377. 'style',
  17378. 'menu',
  17379. ],
  17380. },
  17381. usemap: { propertyName: 'useMap', appliesTo: ['img', 'input', 'object'] },
  17382. value: {
  17383. appliesTo: [
  17384. 'button',
  17385. 'option',
  17386. 'input',
  17387. 'li',
  17388. 'meter',
  17389. 'progress',
  17390. 'param',
  17391. 'select',
  17392. 'textarea',
  17393. ],
  17394. },
  17395. volume: { appliesTo: ['audio', 'video'] },
  17396. width: {
  17397. appliesTo: ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video'],
  17398. },
  17399. wrap: { appliesTo: ['textarea'] },
  17400. };
  17401. Object.keys(attributeLookup).forEach(name => {
  17402. const metadata = attributeLookup[name];
  17403. if (!metadata.propertyName)
  17404. metadata.propertyName = name;
  17405. });
  17406. function optimizeStyle(value) {
  17407. const props = [];
  17408. let chunks = value.slice();
  17409. while (chunks.length) {
  17410. const chunk = chunks[0];
  17411. if (chunk.type !== 'Text')
  17412. return null;
  17413. const keyMatch = /^\s*([\w-]+):\s*/.exec(chunk.data);
  17414. if (!keyMatch)
  17415. return null;
  17416. const key = keyMatch[1];
  17417. const offset = keyMatch.index + keyMatch[0].length;
  17418. const remainingData = chunk.data.slice(offset);
  17419. if (remainingData) {
  17420. chunks[0] = {
  17421. start: chunk.start + offset,
  17422. end: chunk.end,
  17423. type: 'Text',
  17424. data: remainingData
  17425. };
  17426. }
  17427. else {
  17428. chunks.shift();
  17429. }
  17430. const result = getStyleValue(chunks);
  17431. if (!result)
  17432. return null;
  17433. props.push({ key, value: result.value });
  17434. chunks = result.chunks;
  17435. }
  17436. return props;
  17437. }
  17438. function getStyleValue(chunks) {
  17439. const value = [];
  17440. let inUrl = false;
  17441. let quoteMark = null;
  17442. let escaped = false;
  17443. while (chunks.length) {
  17444. const chunk = chunks.shift();
  17445. if (chunk.type === 'Text') {
  17446. let c = 0;
  17447. while (c < chunk.data.length) {
  17448. const char = chunk.data[c];
  17449. if (escaped) {
  17450. escaped = false;
  17451. }
  17452. else if (char === '\\') {
  17453. escaped = true;
  17454. }
  17455. else if (char === quoteMark) {
  17456. }
  17457. else if (char === '"' || char === "'") {
  17458. quoteMark = char;
  17459. }
  17460. else if (char === ')' && inUrl) {
  17461. inUrl = false;
  17462. }
  17463. else if (char === 'u' && chunk.data.slice(c, c + 4) === 'url(') {
  17464. inUrl = true;
  17465. }
  17466. else if (char === ';' && !inUrl && !quoteMark) {
  17467. break;
  17468. }
  17469. c += 1;
  17470. }
  17471. if (c > 0) {
  17472. value.push({
  17473. type: 'Text',
  17474. start: chunk.start,
  17475. end: chunk.start + c,
  17476. data: chunk.data.slice(0, c)
  17477. });
  17478. }
  17479. while (/[;\s]/.test(chunk.data[c]))
  17480. c += 1;
  17481. const remainingData = chunk.data.slice(c);
  17482. if (remainingData) {
  17483. chunks.unshift({
  17484. start: chunk.start + c,
  17485. end: chunk.end,
  17486. type: 'Text',
  17487. data: remainingData
  17488. });
  17489. break;
  17490. }
  17491. }
  17492. else {
  17493. value.push(chunk);
  17494. }
  17495. }
  17496. return {
  17497. chunks,
  17498. value
  17499. };
  17500. }
  17501. function isDynamic$1(value) {
  17502. return value.length > 1 || value[0].type !== 'Text';
  17503. }
  17504. const readOnlyMediaAttributes = new Set([
  17505. 'duration',
  17506. 'buffered',
  17507. 'seekable',
  17508. 'played'
  17509. ]);
  17510. // TODO a lot of this element-specific stuff should live in Element —
  17511. // Binding should ideally be agnostic between Element and Component
  17512. class Binding extends Node$1 {
  17513. constructor(compiler, parent, scope, info) {
  17514. super(compiler, parent, scope, info);
  17515. this.name = info.name;
  17516. this.value = new Expression(compiler, this, scope, info.value);
  17517. let obj;
  17518. let prop;
  17519. const { name } = getObject(this.value.node);
  17520. this.isContextual = scope.names.has(name);
  17521. if (this.value.node.type === 'MemberExpression') {
  17522. prop = `[✂${this.value.node.property.start}-${this.value.node.property.end}✂]`;
  17523. if (!this.value.node.computed)
  17524. prop = `'${prop}'`;
  17525. obj = `[✂${this.value.node.object.start}-${this.value.node.object.end}✂]`;
  17526. this.usesContext = true;
  17527. }
  17528. else {
  17529. obj = 'ctx';
  17530. prop = `'${name}'`;
  17531. this.usesContext = scope.names.has(name);
  17532. }
  17533. this.obj = obj;
  17534. this.prop = prop;
  17535. }
  17536. munge(block) {
  17537. const node = this.parent;
  17538. const needsLock = node.name !== 'input' || !/radio|checkbox|range|color/.test(node.getStaticAttributeValue('type'));
  17539. const isReadOnly = ((node.isMediaNode() && readOnlyMediaAttributes.has(this.name)) ||
  17540. dimensions.test(this.name));
  17541. let updateCondition;
  17542. const { name } = getObject(this.value.node);
  17543. const { snippet } = this.value;
  17544. // special case: if you have e.g. `<input type=checkbox bind:checked=selected.done>`
  17545. // and `selected` is an object chosen with a <select>, then when `checked` changes,
  17546. // we need to tell the component to update all the values `selected` might be
  17547. // pointing to
  17548. // TODO should this happen in preprocess?
  17549. const dependencies = new Set(this.value.dependencies);
  17550. this.value.dependencies.forEach((prop) => {
  17551. const indirectDependencies = this.compiler.indirectDependencies.get(prop);
  17552. if (indirectDependencies) {
  17553. indirectDependencies.forEach(indirectDependency => {
  17554. dependencies.add(indirectDependency);
  17555. });
  17556. }
  17557. });
  17558. // view to model
  17559. const valueFromDom = getValueFromDom(this.compiler, node, this);
  17560. const handler = getEventHandler(this, this.compiler, block, name, snippet, dependencies, valueFromDom);
  17561. // model to view
  17562. let updateDom = getDomUpdater(node, this, snippet);
  17563. let initialUpdate = updateDom;
  17564. // special cases
  17565. if (this.name === 'group') {
  17566. const bindingGroup = getBindingGroup(this.compiler, this.value.node);
  17567. block.builders.hydrate.addLine(`#component._bindingGroups[${bindingGroup}].push(${node.var});`);
  17568. block.builders.destroy.addLine(`#component._bindingGroups[${bindingGroup}].splice(#component._bindingGroups[${bindingGroup}].indexOf(${node.var}), 1);`);
  17569. }
  17570. if (this.name === 'currentTime' || this.name === 'volume') {
  17571. updateCondition = `!isNaN(${snippet})`;
  17572. if (this.name === 'currentTime')
  17573. initialUpdate = null;
  17574. }
  17575. if (this.name === 'paused') {
  17576. // this is necessary to prevent audio restarting by itself
  17577. const last = block.getUniqueName(`${node.var}_is_paused`);
  17578. block.addVariable(last, 'true');
  17579. updateCondition = `${last} !== (${last} = ${snippet})`;
  17580. updateDom = `${node.var}[${last} ? "pause" : "play"]();`;
  17581. initialUpdate = null;
  17582. }
  17583. // bind:offsetWidth and bind:offsetHeight
  17584. if (dimensions.test(this.name)) {
  17585. initialUpdate = null;
  17586. updateDom = null;
  17587. }
  17588. return {
  17589. name: this.name,
  17590. object: name,
  17591. handler,
  17592. updateDom,
  17593. initialUpdate,
  17594. needsLock: !isReadOnly && needsLock,
  17595. updateCondition,
  17596. isReadOnlyMediaAttribute: this.isReadOnlyMediaAttribute()
  17597. };
  17598. }
  17599. isReadOnlyMediaAttribute() {
  17600. return readOnlyMediaAttributes.has(this.name);
  17601. }
  17602. }
  17603. function getDomUpdater(node, binding, snippet) {
  17604. if (binding.isReadOnlyMediaAttribute()) {
  17605. return null;
  17606. }
  17607. if (node.name === 'select') {
  17608. return node.getStaticAttributeValue('multiple') === true ?
  17609. `@selectOptions(${node.var}, ${snippet})` :
  17610. `@selectOption(${node.var}, ${snippet})`;
  17611. }
  17612. if (binding.name === 'group') {
  17613. const type = node.getStaticAttributeValue('type');
  17614. const condition = type === 'checkbox'
  17615. ? `~${snippet}.indexOf(${node.var}.__value)`
  17616. : `${node.var}.__value === ${snippet}`;
  17617. return `${node.var}.checked = ${condition};`;
  17618. }
  17619. return `${node.var}.${binding.name} = ${snippet};`;
  17620. }
  17621. function getBindingGroup(compiler, value) {
  17622. const { parts } = flattenReference(value); // TODO handle cases involving computed member expressions
  17623. const keypath = parts.join('.');
  17624. // TODO handle contextual bindings — `keypath` should include unique ID of
  17625. // each block that provides context
  17626. let index = compiler.bindingGroups.indexOf(keypath);
  17627. if (index === -1) {
  17628. index = compiler.bindingGroups.length;
  17629. compiler.bindingGroups.push(keypath);
  17630. }
  17631. return index;
  17632. }
  17633. function getEventHandler(binding, compiler, block, name, snippet, dependencies, value, isContextual) {
  17634. const storeDependencies = [...dependencies].filter(prop => prop[0] === '$').map(prop => prop.slice(1));
  17635. dependencies = [...dependencies].filter(prop => prop[0] !== '$');
  17636. if (binding.isContextual) {
  17637. const tail = binding.value.node.type === 'MemberExpression'
  17638. ? getTailSnippet(binding.value.node)
  17639. : '';
  17640. const head = block.bindings.get(name);
  17641. return {
  17642. usesContext: true,
  17643. usesState: true,
  17644. usesStore: storeDependencies.length > 0,
  17645. mutation: `${head}${tail} = ${value};`,
  17646. props: dependencies.map(prop => `${prop}: ctx.${prop}`),
  17647. storeProps: storeDependencies.map(prop => `${prop}: $.${prop}`)
  17648. };
  17649. }
  17650. if (binding.value.node.type === 'MemberExpression') {
  17651. // This is a little confusing, and should probably be tidied up
  17652. // at some point. It addresses a tricky bug (#893), wherein
  17653. // Svelte tries to `set()` a computed property, which throws an
  17654. // error in dev mode. a) it's possible that we should be
  17655. // replacing computations with *their* dependencies, and b)
  17656. // we should probably populate `compiler.target.readonly` sooner so
  17657. // that we don't have to do the `.some()` here
  17658. dependencies = dependencies.filter(prop => !compiler.computations.some(computation => computation.key === prop));
  17659. return {
  17660. usesContext: false,
  17661. usesState: true,
  17662. usesStore: storeDependencies.length > 0,
  17663. mutation: `${snippet} = ${value}`,
  17664. props: dependencies.map((prop) => `${prop}: ctx.${prop}`),
  17665. storeProps: storeDependencies.map(prop => `${prop}: $.${prop}`)
  17666. };
  17667. }
  17668. let props;
  17669. let storeProps;
  17670. if (name[0] === '$') {
  17671. props = [];
  17672. storeProps = [`${name.slice(1)}: ${value}`];
  17673. }
  17674. else {
  17675. props = [`${name}: ${value}`];
  17676. storeProps = [];
  17677. }
  17678. return {
  17679. usesContext: false,
  17680. usesState: false,
  17681. usesStore: false,
  17682. mutation: null,
  17683. props,
  17684. storeProps
  17685. };
  17686. }
  17687. function getValueFromDom(compiler, node, binding) {
  17688. // <select bind:value='selected>
  17689. if (node.name === 'select') {
  17690. return node.getStaticAttributeValue('multiple') === true ?
  17691. `@selectMultipleValue(${node.var})` :
  17692. `@selectValue(${node.var})`;
  17693. }
  17694. const type = node.getStaticAttributeValue('type');
  17695. // <input type='checkbox' bind:group='foo'>
  17696. if (binding.name === 'group') {
  17697. const bindingGroup = getBindingGroup(compiler, binding.value.node);
  17698. if (type === 'checkbox') {
  17699. return `@getBindingGroupValue(#component._bindingGroups[${bindingGroup}])`;
  17700. }
  17701. return `${node.var}.__value`;
  17702. }
  17703. // <input type='range|number' bind:value>
  17704. if (type === 'range' || type === 'number') {
  17705. return `@toNumber(${node.var}.${binding.name})`;
  17706. }
  17707. if ((binding.name === 'buffered' || binding.name === 'seekable' || binding.name === 'played')) {
  17708. return `@timeRangesToArray(${node.var}.${binding.name})`;
  17709. }
  17710. // everything else
  17711. return `${node.var}.${binding.name}`;
  17712. }
  17713. class EventHandler extends Node$1 {
  17714. constructor(compiler, parent, scope, info) {
  17715. super(compiler, parent, scope, info);
  17716. this.name = info.name;
  17717. this.dependencies = new Set();
  17718. if (info.expression) {
  17719. this.callee = flattenReference(info.expression.callee);
  17720. this.insertionPoint = info.expression.start;
  17721. this.usesComponent = !validCalleeObjects.has(this.callee.name);
  17722. this.usesContext = false;
  17723. this.args = info.expression.arguments.map(param => {
  17724. const expression = new Expression(compiler, this, scope, param);
  17725. addToSet(this.dependencies, expression.dependencies);
  17726. if (expression.usesContext)
  17727. this.usesContext = true;
  17728. return expression;
  17729. });
  17730. this.snippet = `[✂${info.expression.start}-${info.expression.end}✂];`;
  17731. }
  17732. else {
  17733. this.callee = null;
  17734. this.insertionPoint = null;
  17735. this.args = null;
  17736. this.usesComponent = true;
  17737. this.usesContext = false;
  17738. this.snippet = null; // TODO handle shorthand events here?
  17739. }
  17740. this.isCustomEvent = compiler.events.has(this.name);
  17741. this.shouldHoist = !this.isCustomEvent && parent.hasAncestor('EachBlock');
  17742. }
  17743. render(compiler, block, hoisted) {
  17744. if (this.insertionPoint === null)
  17745. return; // TODO handle shorthand events here?
  17746. if (!validCalleeObjects.has(this.callee.name)) {
  17747. const component = hoisted ? `component` : block.alias(`component`);
  17748. // allow event.stopPropagation(), this.select() etc
  17749. // TODO verify that it's a valid callee (i.e. built-in or declared method)
  17750. if (this.callee.name[0] === '$' && !compiler.methods.has(this.callee.name)) {
  17751. compiler.code.overwrite(this.insertionPoint, this.insertionPoint + 1, `${component}.store.`);
  17752. }
  17753. else {
  17754. compiler.code.prependRight(this.insertionPoint, `${component}.`);
  17755. }
  17756. }
  17757. if (this.isCustomEvent) {
  17758. this.args.forEach(arg => {
  17759. arg.overwriteThis(this.parent.var);
  17760. });
  17761. if (this.callee && this.callee.name === 'this') {
  17762. const node = this.callee.nodes[0];
  17763. compiler.code.overwrite(node.start, node.end, this.parent.var, {
  17764. storeName: true,
  17765. contentOnly: true
  17766. });
  17767. }
  17768. }
  17769. }
  17770. }
  17771. class Component extends Node$1 {
  17772. constructor(compiler, parent, scope, info) {
  17773. super(compiler, parent, scope, info);
  17774. compiler.hasComponents = true;
  17775. this.name = info.name;
  17776. this.expression = this.name === 'svelte:component'
  17777. ? new Expression(compiler, this, scope, info.expression)
  17778. : null;
  17779. this.attributes = [];
  17780. this.bindings = [];
  17781. this.handlers = [];
  17782. info.attributes.forEach(node => {
  17783. switch (node.type) {
  17784. case 'Attribute':
  17785. case 'Spread':
  17786. this.attributes.push(new Attribute(compiler, this, scope, node));
  17787. break;
  17788. case 'Binding':
  17789. this.bindings.push(new Binding(compiler, this, scope, node));
  17790. break;
  17791. case 'EventHandler':
  17792. this.handlers.push(new EventHandler(compiler, this, scope, node));
  17793. break;
  17794. case 'Ref':
  17795. // TODO catch this in validation
  17796. if (this.ref)
  17797. throw new Error(`Duplicate refs`);
  17798. compiler.usesRefs = true;
  17799. this.ref = node.name;
  17800. break;
  17801. default:
  17802. throw new Error(`Not implemented: ${node.type}`);
  17803. }
  17804. });
  17805. this.children = mapChildren(compiler, this, scope, info.children);
  17806. }
  17807. init(block, stripWhitespace, nextSibling) {
  17808. this.cannotUseInnerHTML();
  17809. this.attributes.forEach(attr => {
  17810. block.addDependencies(attr.dependencies);
  17811. });
  17812. this.bindings.forEach(binding => {
  17813. block.addDependencies(binding.value.dependencies);
  17814. });
  17815. this.handlers.forEach(handler => {
  17816. block.addDependencies(handler.dependencies);
  17817. });
  17818. this.var = block.getUniqueName((this.name === 'svelte:self' ? this.compiler.name :
  17819. this.name === 'svelte:component' ? 'switch_instance' :
  17820. this.name).toLowerCase());
  17821. if (this.children.length) {
  17822. this._slots = new Set(['default']);
  17823. this.children.forEach(child => {
  17824. child.init(block, stripWhitespace, nextSibling);
  17825. });
  17826. }
  17827. if (this.compiler.options.nestedTransitions) {
  17828. block.addOutro();
  17829. }
  17830. }
  17831. build(block, parentNode, parentNodes) {
  17832. const { compiler } = this;
  17833. const name = this.var;
  17834. const componentInitProperties = [`root: #component.root`];
  17835. if (this.children.length > 0) {
  17836. const slots = Array.from(this._slots).map(name => `${quoteNameIfNecessary(name)}: @createFragment()`);
  17837. componentInitProperties.push(`slots: { ${slots.join(', ')} }`);
  17838. this.children.forEach((child) => {
  17839. child.build(block, `${this.var}._slotted.default`, 'nodes');
  17840. });
  17841. }
  17842. const statements = [];
  17843. const name_initial_data = block.getUniqueName(`${name}_initial_data`);
  17844. const name_changes = block.getUniqueName(`${name}_changes`);
  17845. let name_updating;
  17846. let beforecreate = null;
  17847. const updates = [];
  17848. const usesSpread = !!this.attributes.find(a => a.isSpread);
  17849. const attributeObject = usesSpread
  17850. ? '{}'
  17851. : stringifyProps(this.attributes.map(attr => `${attr.name}: ${attr.getValue()}`));
  17852. if (this.attributes.length || this.bindings.length) {
  17853. componentInitProperties.push(`data: ${name_initial_data}`);
  17854. }
  17855. if (!usesSpread && (this.attributes.filter(a => a.isDynamic).length || this.bindings.length)) {
  17856. updates.push(`var ${name_changes} = {};`);
  17857. }
  17858. if (this.attributes.length) {
  17859. if (usesSpread) {
  17860. const levels = block.getUniqueName(`${this.var}_spread_levels`);
  17861. const initialProps = [];
  17862. const changes = [];
  17863. const allDependencies = new Set();
  17864. this.attributes.forEach(attr => {
  17865. addToSet(allDependencies, attr.dependencies);
  17866. });
  17867. this.attributes.forEach(attr => {
  17868. const { name, dependencies } = attr;
  17869. const condition = dependencies.size > 0 && (dependencies.size !== allDependencies.size)
  17870. ? [...dependencies].map(d => `changed.${d}`).join(' || ')
  17871. : null;
  17872. if (attr.isSpread) {
  17873. const value = attr.expression.snippet;
  17874. initialProps.push(value);
  17875. changes.push(condition ? `${condition} && ${value}` : value);
  17876. }
  17877. else {
  17878. const obj = `{ ${quoteNameIfNecessary(name)}: ${attr.getValue()} }`;
  17879. initialProps.push(obj);
  17880. changes.push(condition ? `${condition} && ${obj}` : obj);
  17881. }
  17882. });
  17883. block.builders.init.addBlock(deindent `
  17884. var ${levels} = [
  17885. ${initialProps.join(',\n')}
  17886. ];
  17887. `);
  17888. statements.push(deindent `
  17889. for (var #i = 0; #i < ${levels}.length; #i += 1) {
  17890. ${name_initial_data} = @assign(${name_initial_data}, ${levels}[#i]);
  17891. }
  17892. `);
  17893. const conditions = [...allDependencies].map(dep => `changed.${dep}`).join(' || ');
  17894. updates.push(deindent `
  17895. var ${name_changes} = ${allDependencies.size === 1 ? `${conditions}` : `(${conditions})`} ? @getSpreadUpdate(${levels}, [
  17896. ${changes.join(',\n')}
  17897. ]) : {};
  17898. `);
  17899. }
  17900. else {
  17901. this.attributes
  17902. .filter((attribute) => attribute.isDynamic)
  17903. .forEach((attribute) => {
  17904. if (attribute.dependencies.size > 0) {
  17905. updates.push(deindent `
  17906. if (${[...attribute.dependencies]
  17907. .map(dependency => `changed.${dependency}`)
  17908. .join(' || ')}) ${name_changes}.${attribute.name} = ${attribute.getValue()};
  17909. `);
  17910. }
  17911. });
  17912. }
  17913. }
  17914. if (this.bindings.length) {
  17915. compiler.target.hasComplexBindings = true;
  17916. name_updating = block.alias(`${name}_updating`);
  17917. block.addVariable(name_updating, '{}');
  17918. let hasLocalBindings = false;
  17919. let hasStoreBindings = false;
  17920. const builder = new CodeBuilder();
  17921. this.bindings.forEach((binding) => {
  17922. let { name: key } = getObject(binding.value.node);
  17923. let setFromChild;
  17924. if (binding.isContextual) {
  17925. const computed = isComputed$1(binding.value.node);
  17926. const tail = binding.value.node.type === 'MemberExpression' ? getTailSnippet(binding.value.node) : '';
  17927. const head = block.bindings.get(key);
  17928. const lhs = binding.value.node.type === 'MemberExpression'
  17929. ? binding.value.snippet
  17930. : `${head}${tail} = childState.${binding.name}`;
  17931. setFromChild = deindent `
  17932. ${lhs} = childState.${binding.name};
  17933. ${[...binding.value.dependencies]
  17934. .map((name) => {
  17935. const isStoreProp = name[0] === '$';
  17936. const prop = isStoreProp ? name.slice(1) : name;
  17937. const newState = isStoreProp ? 'newStoreState' : 'newState';
  17938. if (isStoreProp)
  17939. hasStoreBindings = true;
  17940. else
  17941. hasLocalBindings = true;
  17942. return `${newState}.${prop} = ctx.${name};`;
  17943. })}
  17944. `;
  17945. }
  17946. else {
  17947. const isStoreProp = key[0] === '$';
  17948. const prop = isStoreProp ? key.slice(1) : key;
  17949. const newState = isStoreProp ? 'newStoreState' : 'newState';
  17950. if (isStoreProp)
  17951. hasStoreBindings = true;
  17952. else
  17953. hasLocalBindings = true;
  17954. if (binding.value.node.type === 'MemberExpression') {
  17955. setFromChild = deindent `
  17956. ${binding.value.snippet} = childState.${binding.name};
  17957. ${newState}.${prop} = ctx.${key};
  17958. `;
  17959. }
  17960. else {
  17961. setFromChild = `${newState}.${prop} = childState.${binding.name};`;
  17962. }
  17963. }
  17964. statements.push(deindent `
  17965. if (${binding.value.snippet} !== void 0) {
  17966. ${name_initial_data}.${binding.name} = ${binding.value.snippet};
  17967. ${name_updating}.${binding.name} = true;
  17968. }`);
  17969. builder.addConditional(`!${name_updating}.${binding.name} && changed.${binding.name}`, setFromChild);
  17970. updates.push(deindent `
  17971. if (!${name_updating}.${binding.name} && ${[...binding.value.dependencies].map((dependency) => `changed.${dependency}`).join(' || ')}) {
  17972. ${name_changes}.${binding.name} = ${binding.value.snippet};
  17973. ${name_updating}.${binding.name} = ${binding.value.snippet} !== void 0;
  17974. }
  17975. `);
  17976. });
  17977. block.maintainContext = true; // TODO put this somewhere more logical
  17978. const initialisers = [
  17979. hasLocalBindings && 'newState = {}',
  17980. hasStoreBindings && 'newStoreState = {}',
  17981. ].filter(Boolean).join(', ');
  17982. // TODO use component.on('state', ...) instead of _bind
  17983. componentInitProperties.push(deindent `
  17984. _bind(changed, childState) {
  17985. var ${initialisers};
  17986. ${builder}
  17987. ${hasStoreBindings && `#component.store.set(newStoreState);`}
  17988. ${hasLocalBindings && `#component._set(newState);`}
  17989. ${name_updating} = {};
  17990. }
  17991. `);
  17992. beforecreate = deindent `
  17993. #component.root._beforecreate.push(() => {
  17994. ${name}._bind({ ${this.bindings.map(b => `${b.name}: 1`).join(', ')} }, ${name}.get());
  17995. });
  17996. `;
  17997. }
  17998. this.handlers.forEach(handler => {
  17999. handler.var = block.getUniqueName(`${this.var}_${handler.name}`); // TODO this is hacky
  18000. handler.render(compiler, block, false); // TODO hoist when possible
  18001. if (handler.usesContext)
  18002. block.maintainContext = true; // TODO is there a better place to put this?
  18003. });
  18004. if (this.name === 'svelte:component') {
  18005. const switch_value = block.getUniqueName('switch_value');
  18006. const switch_props = block.getUniqueName('switch_props');
  18007. const { dependencies, snippet } = this.expression;
  18008. const anchor = this.getOrCreateAnchor(block, parentNode, parentNodes);
  18009. block.builders.init.addBlock(deindent `
  18010. var ${switch_value} = ${snippet};
  18011. function ${switch_props}(ctx) {
  18012. ${(this.attributes.length || this.bindings.length) && deindent `
  18013. var ${name_initial_data} = ${attributeObject};`}
  18014. ${statements}
  18015. return {
  18016. ${componentInitProperties.join(',\n')}
  18017. };
  18018. }
  18019. if (${switch_value}) {
  18020. var ${name} = new ${switch_value}(${switch_props}(ctx));
  18021. ${beforecreate}
  18022. }
  18023. ${this.handlers.map(handler => deindent `
  18024. function ${handler.var}(event) {
  18025. ${handler.snippet || `#component.fire("${handler.name}", event);`}
  18026. }
  18027. if (${name}) ${name}.on("${handler.name}", ${handler.var});
  18028. `)}
  18029. `);
  18030. block.builders.create.addLine(`if (${name}) ${name}._fragment.c();`);
  18031. if (parentNodes) {
  18032. block.builders.claim.addLine(`if (${name}) ${name}._fragment.l(${parentNodes});`);
  18033. }
  18034. block.builders.mount.addBlock(deindent `
  18035. if (${name}) {
  18036. ${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});
  18037. ${this.ref && `#component.refs.${this.ref} = ${name};`}
  18038. }
  18039. `);
  18040. const updateMountNode = this.getUpdateMountNode(anchor);
  18041. if (updates.length) {
  18042. block.builders.update.addBlock(deindent `
  18043. ${updates}
  18044. `);
  18045. }
  18046. block.builders.update.addBlock(deindent `
  18047. if (${switch_value} !== (${switch_value} = ${snippet})) {
  18048. if (${name}) ${name}.destroy();
  18049. if (${switch_value}) {
  18050. ${name} = new ${switch_value}(${switch_props}(ctx));
  18051. ${this.bindings.length > 0 && deindent `
  18052. #component.root._beforecreate.push(() => {
  18053. const changed = {};
  18054. ${this.bindings.map(binding => deindent `
  18055. if (${binding.value.snippet} === void 0) changed.${binding.name} = 1;`)}
  18056. ${name}._bind(changed, ${name}.get());
  18057. });`}
  18058. ${name}._fragment.c();
  18059. ${this.children.map(child => child.remount(name))}
  18060. ${name}._mount(${updateMountNode}, ${anchor});
  18061. ${this.handlers.map(handler => deindent `
  18062. ${name}.on("${handler.name}", ${handler.var});
  18063. `)}
  18064. ${this.ref && `#component.refs.${this.ref} = ${name};`}
  18065. }
  18066. ${this.ref && deindent `
  18067. else if (#component.refs.${this.ref} === ${name}) {
  18068. #component.refs.${this.ref} = null;
  18069. }`}
  18070. }
  18071. `);
  18072. if (updates.length) {
  18073. block.builders.update.addBlock(deindent `
  18074. else if (${switch_value}) {
  18075. ${name}._set(${name_changes});
  18076. ${this.bindings.length && `${name_updating} = {};`}
  18077. }
  18078. `);
  18079. }
  18080. block.builders.destroy.addLine(`if (${name}) ${name}.destroy(${parentNode ? '' : 'detach'});`);
  18081. }
  18082. else {
  18083. const expression = this.name === 'svelte:self'
  18084. ? compiler.name
  18085. : `%components-${this.name}`;
  18086. block.builders.init.addBlock(deindent `
  18087. ${(this.attributes.length || this.bindings.length) && deindent `
  18088. var ${name_initial_data} = ${attributeObject};`}
  18089. ${statements}
  18090. var ${name} = new ${expression}({
  18091. ${componentInitProperties.join(',\n')}
  18092. });
  18093. ${beforecreate}
  18094. ${this.handlers.map(handler => deindent `
  18095. ${name}.on("${handler.name}", function(event) {
  18096. ${handler.snippet || `#component.fire("${handler.name}", event);`}
  18097. });
  18098. `)}
  18099. ${this.ref && `#component.refs.${this.ref} = ${name};`}
  18100. `);
  18101. block.builders.create.addLine(`${name}._fragment.c();`);
  18102. if (parentNodes) {
  18103. block.builders.claim.addLine(`${name}._fragment.l(${parentNodes});`);
  18104. }
  18105. block.builders.mount.addLine(`${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});`);
  18106. if (updates.length) {
  18107. block.builders.update.addBlock(deindent `
  18108. ${updates}
  18109. ${name}._set(${name_changes});
  18110. ${this.bindings.length && `${name_updating} = {};`}
  18111. `);
  18112. }
  18113. block.builders.destroy.addLine(deindent `
  18114. ${name}.destroy(${parentNode ? '' : 'detach'});
  18115. ${this.ref && `if (#component.refs.${this.ref} === ${name}) #component.refs.${this.ref} = null;`}
  18116. `);
  18117. }
  18118. if (this.compiler.options.nestedTransitions) {
  18119. block.builders.outro.addLine(`${name}._fragment.o(#outrocallback);`);
  18120. }
  18121. }
  18122. remount(name) {
  18123. return `${this.var}._mount(${name}._slotted.default, null);`;
  18124. }
  18125. ssr() {
  18126. function stringifyAttribute(chunk) {
  18127. if (chunk.type === 'Text') {
  18128. return escapeTemplate(escape(chunk.data));
  18129. }
  18130. return '${@escape( ' + chunk.snippet + ')}';
  18131. }
  18132. const bindingProps = this.bindings.map(binding => {
  18133. const { name } = getObject(binding.value.node);
  18134. const tail = binding.value.node.type === 'MemberExpression'
  18135. ? getTailSnippet(binding.value.node)
  18136. : '';
  18137. return `${binding.name}: ctx.${name}${tail}`;
  18138. });
  18139. function getAttributeValue(attribute) {
  18140. if (attribute.isTrue)
  18141. return `true`;
  18142. if (attribute.chunks.length === 0)
  18143. return `''`;
  18144. if (attribute.chunks.length === 1) {
  18145. const chunk = attribute.chunks[0];
  18146. if (chunk.type === 'Text') {
  18147. return stringify(chunk.data);
  18148. }
  18149. return chunk.snippet;
  18150. }
  18151. return '`' + attribute.chunks.map(stringifyAttribute).join('') + '`';
  18152. }
  18153. const usesSpread = this.attributes.find(attr => attr.isSpread);
  18154. const props = usesSpread
  18155. ? `Object.assign(${this.attributes
  18156. .map(attribute => {
  18157. if (attribute.isSpread) {
  18158. return attribute.expression.snippet;
  18159. }
  18160. else {
  18161. return `{ ${attribute.name}: ${getAttributeValue(attribute)} }`;
  18162. }
  18163. })
  18164. .concat(bindingProps.map(p => `{ ${p} }`))
  18165. .join(', ')})`
  18166. : `{ ${this.attributes
  18167. .map(attribute => `${attribute.name}: ${getAttributeValue(attribute)}`)
  18168. .concat(bindingProps)
  18169. .join(', ')} }`;
  18170. const isDynamicComponent = this.name === 'svelte:component';
  18171. const expression = (this.name === 'svelte:self' ? this.compiler.name :
  18172. (isDynamicComponent ? `((${this.expression.snippet}) || @missingComponent)` :
  18173. `%components-${this.name}`));
  18174. this.bindings.forEach(binding => {
  18175. const conditions = [];
  18176. let node = this;
  18177. while (node = node.parent) {
  18178. if (node.type === 'IfBlock') {
  18179. // TODO handle contextual bindings...
  18180. conditions.push(`(${node.expression.snippet})`);
  18181. }
  18182. }
  18183. conditions.push(`!('${binding.name}' in ctx)`);
  18184. const { name } = getObject(binding.value.node);
  18185. this.compiler.target.bindings.push(deindent `
  18186. if (${conditions.reverse().join('&&')}) {
  18187. tmp = ${expression}.data();
  18188. if ('${name}' in tmp) {
  18189. ctx.${binding.name} = tmp.${name};
  18190. settled = false;
  18191. }
  18192. }
  18193. `);
  18194. });
  18195. let open = `\${${expression}._render(__result, ${props}`;
  18196. const options = [];
  18197. options.push(`store: options.store`);
  18198. if (this.children.length) {
  18199. const appendTarget = {
  18200. slots: { default: '' },
  18201. slotStack: ['default']
  18202. };
  18203. this.compiler.target.appendTargets.push(appendTarget);
  18204. this.children.forEach((child) => {
  18205. child.ssr();
  18206. });
  18207. const slotted = Object.keys(appendTarget.slots)
  18208. .map(name => `${quoteNameIfNecessary(name)}: () => \`${appendTarget.slots[name]}\``)
  18209. .join(', ');
  18210. options.push(`slotted: { ${slotted} }`);
  18211. this.compiler.target.appendTargets.pop();
  18212. }
  18213. if (options.length) {
  18214. open += `, { ${options.join(', ')} }`;
  18215. }
  18216. this.compiler.target.append(open);
  18217. this.compiler.target.append(')}');
  18218. }
  18219. }
  18220. function isComputed$1(node) {
  18221. while (node.type === 'MemberExpression') {
  18222. if (node.computed)
  18223. return true;
  18224. node = node.object;
  18225. }
  18226. return false;
  18227. }
  18228. class ElseBlock extends Node$1 {
  18229. constructor(compiler, parent, scope, info) {
  18230. super(compiler, parent, scope, info);
  18231. this.children = mapChildren(compiler, this, scope, info.children);
  18232. }
  18233. }
  18234. class EachBlock extends Node$1 {
  18235. constructor(compiler, parent, scope, info) {
  18236. super(compiler, parent, scope, info);
  18237. this.expression = new Expression(compiler, this, scope, info.expression);
  18238. this.context = info.context.name || 'each'; // TODO this is used to facilitate binding; currently fails with destructuring
  18239. this.index = info.index;
  18240. this.scope = scope.child();
  18241. this.contexts = [];
  18242. unpackDestructuring(this.contexts, info.context, '');
  18243. this.contexts.forEach(context => {
  18244. this.scope.add(context.key.name, this.expression.dependencies);
  18245. });
  18246. this.key = info.key
  18247. ? new Expression(compiler, this, this.scope, info.key)
  18248. : null;
  18249. if (this.index) {
  18250. // index can only change if this is a keyed each block
  18251. const dependencies = this.key ? this.expression.dependencies : [];
  18252. this.scope.add(this.index, dependencies);
  18253. }
  18254. this.children = mapChildren(compiler, this, this.scope, info.children);
  18255. this.else = info.else
  18256. ? new ElseBlock(compiler, this, this.scope, info.else)
  18257. : null;
  18258. }
  18259. init(block, stripWhitespace, nextSibling) {
  18260. this.cannotUseInnerHTML();
  18261. this.var = block.getUniqueName(`each`);
  18262. this.iterations = block.getUniqueName(`${this.var}_blocks`);
  18263. this.get_each_context = this.compiler.getUniqueName(`get_${this.var}_context`);
  18264. const { dependencies } = this.expression;
  18265. block.addDependencies(dependencies);
  18266. this.block = block.child({
  18267. comment: createDebuggingComment(this, this.compiler),
  18268. name: this.compiler.getUniqueName('create_each_block'),
  18269. key: this.key,
  18270. bindings: new Map(block.bindings)
  18271. });
  18272. this.each_block_value = this.compiler.getUniqueName('each_value');
  18273. const indexName = this.index || this.compiler.getUniqueName(`${this.context}_index`);
  18274. this.contexts.forEach(prop => {
  18275. this.block.bindings.set(prop.key.name, `ctx.${this.each_block_value}[ctx.${indexName}]${prop.tail}`);
  18276. });
  18277. if (this.index) {
  18278. this.block.getUniqueName(this.index); // this prevents name collisions (#1254)
  18279. }
  18280. this.contextProps = this.contexts.map(prop => `child_ctx.${prop.key.name} = list[i]${prop.tail};`);
  18281. // TODO only add these if necessary
  18282. this.contextProps.push(`child_ctx.${this.each_block_value} = list;`, `child_ctx.${indexName} = i;`);
  18283. this.compiler.target.blocks.push(this.block);
  18284. this.initChildren(this.block, stripWhitespace, nextSibling);
  18285. block.addDependencies(this.block.dependencies);
  18286. this.block.hasUpdateMethod = this.block.dependencies.size > 0;
  18287. if (this.else) {
  18288. this.else.block = block.child({
  18289. comment: createDebuggingComment(this.else, this.compiler),
  18290. name: this.compiler.getUniqueName(`${this.block.name}_else`),
  18291. });
  18292. this.compiler.target.blocks.push(this.else.block);
  18293. this.else.initChildren(this.else.block, stripWhitespace, nextSibling);
  18294. this.else.block.hasUpdateMethod = this.else.block.dependencies.size > 0;
  18295. }
  18296. if (this.block.hasOutros || (this.else && this.else.block.hasOutros)) {
  18297. block.addOutro();
  18298. }
  18299. }
  18300. build(block, parentNode, parentNodes) {
  18301. if (this.children.length === 0)
  18302. return;
  18303. const { compiler } = this;
  18304. const each = this.var;
  18305. const create_each_block = this.block.name;
  18306. const iterations = this.iterations;
  18307. const needsAnchor = this.next ? !this.next.isDomNode() : !parentNode || !this.parent.isDomNode();
  18308. const anchor = needsAnchor
  18309. ? block.getUniqueName(`${each}_anchor`)
  18310. : (this.next && this.next.var) || 'null';
  18311. // hack the sourcemap, so that if data is missing the bug
  18312. // is easy to find
  18313. let c = this.start + 2;
  18314. while (compiler.source[c] !== 'e')
  18315. c += 1;
  18316. compiler.code.overwrite(c, c + 4, 'length');
  18317. const length = `[✂${c}-${c + 4}✂]`;
  18318. const mountOrIntro = (this.block.hasIntroMethod || this.block.hasOutroMethod) ? 'i' : 'm';
  18319. const vars = {
  18320. each,
  18321. create_each_block,
  18322. length,
  18323. iterations,
  18324. anchor,
  18325. mountOrIntro,
  18326. };
  18327. const { snippet } = this.expression;
  18328. block.builders.init.addLine(`var ${this.each_block_value} = ${snippet};`);
  18329. this.compiler.target.blocks.push(deindent `
  18330. function ${this.get_each_context}(ctx, list, i) {
  18331. const child_ctx = Object.create(ctx);
  18332. ${this.contextProps}
  18333. return child_ctx;
  18334. }
  18335. `);
  18336. if (this.key) {
  18337. this.buildKeyed(block, parentNode, parentNodes, snippet, vars);
  18338. }
  18339. else {
  18340. this.buildUnkeyed(block, parentNode, parentNodes, snippet, vars);
  18341. }
  18342. if (needsAnchor) {
  18343. block.addElement(anchor, `@createComment()`, parentNodes && `@createComment()`, parentNode);
  18344. }
  18345. if (this.else) {
  18346. const each_block_else = compiler.getUniqueName(`${each}_else`);
  18347. block.builders.init.addLine(`var ${each_block_else} = null;`);
  18348. // TODO neaten this up... will end up with an empty line in the block
  18349. block.builders.init.addBlock(deindent `
  18350. if (!${this.each_block_value}.${length}) {
  18351. ${each_block_else} = ${this.else.block.name}(#component, ctx);
  18352. ${each_block_else}.c();
  18353. }
  18354. `);
  18355. block.builders.mount.addBlock(deindent `
  18356. if (${each_block_else}) {
  18357. ${each_block_else}.${mountOrIntro}(${parentNode || '#target'}, null);
  18358. }
  18359. `);
  18360. const initialMountNode = parentNode || `${anchor}.parentNode`;
  18361. if (this.else.block.hasUpdateMethod) {
  18362. block.builders.update.addBlock(deindent `
  18363. if (!${this.each_block_value}.${length} && ${each_block_else}) {
  18364. ${each_block_else}.p(changed, ctx);
  18365. } else if (!${this.each_block_value}.${length}) {
  18366. ${each_block_else} = ${this.else.block.name}(#component, ctx);
  18367. ${each_block_else}.c();
  18368. ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor});
  18369. } else if (${each_block_else}) {
  18370. ${each_block_else}.d(1);
  18371. ${each_block_else} = null;
  18372. }
  18373. `);
  18374. }
  18375. else {
  18376. block.builders.update.addBlock(deindent `
  18377. if (${this.each_block_value}.${length}) {
  18378. if (${each_block_else}) {
  18379. ${each_block_else}.d(1);
  18380. ${each_block_else} = null;
  18381. }
  18382. } else if (!${each_block_else}) {
  18383. ${each_block_else} = ${this.else.block.name}(#component, ctx);
  18384. ${each_block_else}.c();
  18385. ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor});
  18386. }
  18387. `);
  18388. }
  18389. block.builders.destroy.addBlock(deindent `
  18390. if (${each_block_else}) ${each_block_else}.d(${parentNode ? '' : 'detach'});
  18391. `);
  18392. }
  18393. this.children.forEach((child) => {
  18394. child.build(this.block, null, 'nodes');
  18395. });
  18396. if (this.else) {
  18397. this.else.children.forEach((child) => {
  18398. child.build(this.else.block, null, 'nodes');
  18399. });
  18400. }
  18401. }
  18402. buildKeyed(block, parentNode, parentNodes, snippet, { each, create_each_block, length, anchor, mountOrIntro, }) {
  18403. const get_key = block.getUniqueName('get_key');
  18404. const blocks = block.getUniqueName(`${each}_blocks`);
  18405. const lookup = block.getUniqueName(`${each}_lookup`);
  18406. block.addVariable(blocks, '[]');
  18407. block.addVariable(lookup, `@blankObject()`);
  18408. if (this.children[0].isDomNode()) {
  18409. this.block.first = this.children[0].var;
  18410. }
  18411. else {
  18412. this.block.first = this.block.getUniqueName('first');
  18413. this.block.addElement(this.block.first, `@createComment()`, parentNodes && `@createComment()`, null);
  18414. }
  18415. block.builders.init.addBlock(deindent `
  18416. const ${get_key} = ctx => ${this.key.snippet};
  18417. for (var #i = 0; #i < ${this.each_block_value}.${length}; #i += 1) {
  18418. let child_ctx = ${this.get_each_context}(ctx, ${this.each_block_value}, #i);
  18419. let key = ${get_key}(child_ctx);
  18420. ${blocks}[#i] = ${lookup}[key] = ${create_each_block}(#component, key, child_ctx);
  18421. }
  18422. `);
  18423. const initialMountNode = parentNode || '#target';
  18424. const updateMountNode = this.getUpdateMountNode(anchor);
  18425. const anchorNode = parentNode ? 'null' : 'anchor';
  18426. block.builders.create.addBlock(deindent `
  18427. for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].c();
  18428. `);
  18429. if (parentNodes) {
  18430. block.builders.claim.addBlock(deindent `
  18431. for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].l(${parentNodes});
  18432. `);
  18433. }
  18434. block.builders.mount.addBlock(deindent `
  18435. for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode});
  18436. `);
  18437. const dynamic = this.block.hasUpdateMethod;
  18438. const rects = block.getUniqueName('rects');
  18439. const destroy = this.block.hasAnimation
  18440. ? `@fixAndOutroAndDestroyBlock`
  18441. : this.block.hasOutros
  18442. ? `@outroAndDestroyBlock`
  18443. : `@destroyBlock`;
  18444. block.builders.update.addBlock(deindent `
  18445. const ${this.each_block_value} = ${snippet};
  18446. ${this.block.hasOutros && `@transitionManager.groupOutros();`}
  18447. ${this.block.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].r();`}
  18448. ${blocks} = @updateKeyedEach(${blocks}, #component, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, "${mountOrIntro}", ${anchor}, ${this.get_each_context});
  18449. ${this.block.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].a();`}
  18450. `);
  18451. if (this.compiler.options.nestedTransitions) {
  18452. block.builders.outro.addBlock(deindent `
  18453. #outrocallback = @callAfter(#outrocallback, ${blocks}.length);
  18454. for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].o(#outrocallback);
  18455. `);
  18456. }
  18457. block.builders.destroy.addBlock(deindent `
  18458. for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].d(${parentNode ? '' : 'detach'});
  18459. `);
  18460. }
  18461. buildUnkeyed(block, parentNode, parentNodes, snippet, { create_each_block, length, iterations, anchor, mountOrIntro, }) {
  18462. block.builders.init.addBlock(deindent `
  18463. var ${iterations} = [];
  18464. for (var #i = 0; #i < ${this.each_block_value}.${length}; #i += 1) {
  18465. ${iterations}[#i] = ${create_each_block}(#component, ${this.get_each_context}(ctx, ${this.each_block_value}, #i));
  18466. }
  18467. `);
  18468. const initialMountNode = parentNode || '#target';
  18469. const updateMountNode = this.getUpdateMountNode(anchor);
  18470. const anchorNode = parentNode ? 'null' : 'anchor';
  18471. block.builders.create.addBlock(deindent `
  18472. for (var #i = 0; #i < ${iterations}.length; #i += 1) {
  18473. ${iterations}[#i].c();
  18474. }
  18475. `);
  18476. if (parentNodes) {
  18477. block.builders.claim.addBlock(deindent `
  18478. for (var #i = 0; #i < ${iterations}.length; #i += 1) {
  18479. ${iterations}[#i].l(${parentNodes});
  18480. }
  18481. `);
  18482. }
  18483. block.builders.mount.addBlock(deindent `
  18484. for (var #i = 0; #i < ${iterations}.length; #i += 1) {
  18485. ${iterations}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode});
  18486. }
  18487. `);
  18488. const allDependencies = new Set(this.block.dependencies);
  18489. const { dependencies } = this.expression;
  18490. dependencies.forEach((dependency) => {
  18491. allDependencies.add(dependency);
  18492. });
  18493. const outro = this.block.hasOutros && block.getUniqueName('outro');
  18494. if (outro) {
  18495. block.builders.init.addBlock(deindent `
  18496. function ${outro}(i, detach, fn) {
  18497. if (${iterations}[i]) {
  18498. ${iterations}[i].o(() => {
  18499. ${iterations}[i].d(detach);
  18500. if (detach) ${iterations}[i] = null;
  18501. if (fn) fn();
  18502. });
  18503. }
  18504. }
  18505. `);
  18506. }
  18507. // TODO do this for keyed blocks as well
  18508. const condition = Array.from(allDependencies)
  18509. .map(dependency => `changed.${dependency}`)
  18510. .join(' || ');
  18511. if (condition !== '') {
  18512. const forLoopBody = this.block.hasUpdateMethod
  18513. ? (this.block.hasIntros || this.block.hasOutros)
  18514. ? deindent `
  18515. if (${iterations}[#i]) {
  18516. ${iterations}[#i].p(changed, child_ctx);
  18517. } else {
  18518. ${iterations}[#i] = ${create_each_block}(#component, child_ctx);
  18519. ${iterations}[#i].c();
  18520. }
  18521. ${iterations}[#i].i(${updateMountNode}, ${anchor});
  18522. `
  18523. : deindent `
  18524. if (${iterations}[#i]) {
  18525. ${iterations}[#i].p(changed, child_ctx);
  18526. } else {
  18527. ${iterations}[#i] = ${create_each_block}(#component, child_ctx);
  18528. ${iterations}[#i].c();
  18529. ${iterations}[#i].m(${updateMountNode}, ${anchor});
  18530. }
  18531. `
  18532. : deindent `
  18533. ${iterations}[#i] = ${create_each_block}(#component, child_ctx);
  18534. ${iterations}[#i].c();
  18535. ${iterations}[#i].${mountOrIntro}(${updateMountNode}, ${anchor});
  18536. `;
  18537. const start = this.block.hasUpdateMethod ? '0' : `${iterations}.length`;
  18538. let destroy;
  18539. if (this.block.hasOutros) {
  18540. destroy = deindent `
  18541. @transitionManager.groupOutros();
  18542. for (; #i < ${iterations}.length; #i += 1) ${outro}(#i, 1);
  18543. `;
  18544. }
  18545. else {
  18546. destroy = deindent `
  18547. for (; #i < ${iterations}.length; #i += 1) {
  18548. ${iterations}[#i].d(1);
  18549. }
  18550. ${iterations}.length = ${this.each_block_value}.${length};
  18551. `;
  18552. }
  18553. block.builders.update.addBlock(deindent `
  18554. if (${condition}) {
  18555. ${this.each_block_value} = ${snippet};
  18556. for (var #i = ${start}; #i < ${this.each_block_value}.${length}; #i += 1) {
  18557. const child_ctx = ${this.get_each_context}(ctx, ${this.each_block_value}, #i);
  18558. ${forLoopBody}
  18559. }
  18560. ${destroy}
  18561. }
  18562. `);
  18563. }
  18564. if (outro && this.compiler.options.nestedTransitions) {
  18565. block.builders.outro.addBlock(deindent `
  18566. #outrocallback = @callAfter(#outrocallback, #i);
  18567. for (let #i = 0; #i < ${iterations}.length; #i += 1) ${outro}(#i, 0, #outrocallback);`);
  18568. }
  18569. block.builders.destroy.addBlock(`@destroyEach(${iterations}, detach);`);
  18570. }
  18571. remount(name) {
  18572. // TODO consider keyed blocks
  18573. return `for (var #i = 0; #i < ${this.iterations}.length; #i += 1) ${this.iterations}[#i].m(${name}._slotted.default, null);`;
  18574. }
  18575. ssr() {
  18576. const { compiler } = this;
  18577. const { snippet } = this.expression;
  18578. const props = this.contexts.map(prop => `${prop.key.name}: item${prop.tail}`);
  18579. const getContext = this.index
  18580. ? `(item, i) => Object.assign({}, ctx, { ${props.join(', ')}, ${this.index}: i })`
  18581. : `item => Object.assign({}, ctx, { ${props.join(', ')} })`;
  18582. const open = `\${ ${this.else ? `${snippet}.length ? ` : ''}@each(${snippet}, ${getContext}, ctx => \``;
  18583. compiler.target.append(open);
  18584. this.children.forEach((child) => {
  18585. child.ssr();
  18586. });
  18587. const close = `\`)`;
  18588. compiler.target.append(close);
  18589. if (this.else) {
  18590. compiler.target.append(` : \``);
  18591. this.else.children.forEach((child) => {
  18592. child.ssr();
  18593. });
  18594. compiler.target.append(`\``);
  18595. }
  18596. compiler.target.append('}');
  18597. }
  18598. }
  18599. class Transition extends Node$1 {
  18600. constructor(compiler, parent, scope, info) {
  18601. super(compiler, parent, scope, info);
  18602. this.name = info.name;
  18603. this.expression = info.expression
  18604. ? new Expression(compiler, this, scope, info.expression)
  18605. : null;
  18606. }
  18607. }
  18608. class Animation extends Node$1 {
  18609. constructor(compiler, parent, scope, info) {
  18610. super(compiler, parent, scope, info);
  18611. this.name = info.name;
  18612. this.expression = info.expression
  18613. ? new Expression(compiler, this, scope, info.expression)
  18614. : null;
  18615. }
  18616. build(block, parentNode, parentNodes) {
  18617. }
  18618. }
  18619. class Action extends Node$1 {
  18620. constructor(compiler, parent, scope, info) {
  18621. super(compiler, parent, scope, info);
  18622. this.name = info.name;
  18623. this.expression = info.expression
  18624. ? new Expression(compiler, this, scope, info.expression)
  18625. : null;
  18626. }
  18627. }
  18628. // Whitespace inside one of these elements will not result in
  18629. // a whitespace node being created in any circumstances. (This
  18630. // list is almost certainly very incomplete)
  18631. const elementsWithoutText = new Set([
  18632. 'audio',
  18633. 'datalist',
  18634. 'dl',
  18635. 'ol',
  18636. 'optgroup',
  18637. 'select',
  18638. 'ul',
  18639. 'video',
  18640. ]);
  18641. function shouldSkip$1(node) {
  18642. if (/\S/.test(node.data))
  18643. return false;
  18644. const parentElement = node.findNearest(/(?:Element|Component|Head)/);
  18645. if (!parentElement)
  18646. return false;
  18647. if (parentElement.type === 'Head')
  18648. return true;
  18649. if (parentElement.type === 'Component')
  18650. return parentElement.children.length === 1 && node === parentElement.children[0];
  18651. return parentElement.namespace || elementsWithoutText.has(parentElement.name);
  18652. }
  18653. class Text extends Node$1 {
  18654. constructor(compiler, parent, scope, info) {
  18655. super(compiler, parent, scope, info);
  18656. this.data = info.data;
  18657. }
  18658. init(block) {
  18659. const parentElement = this.findNearest(/(?:Element|Component)/);
  18660. if (shouldSkip$1(this)) {
  18661. this.shouldSkip = true;
  18662. return;
  18663. }
  18664. this.var = block.getUniqueName(`text`);
  18665. }
  18666. build(block, parentNode, parentNodes) {
  18667. if (this.shouldSkip)
  18668. return;
  18669. block.addElement(this.var, `@createText(${stringify(this.data)})`, parentNodes && `@claimText(${parentNodes}, ${stringify(this.data)})`, parentNode);
  18670. }
  18671. remount(name) {
  18672. return `@appendNode(${this.var}, ${name}._slotted.default);`;
  18673. }
  18674. ssr() {
  18675. let text = this.data;
  18676. if (!this.parent ||
  18677. this.parent.type !== 'Element' ||
  18678. (this.parent.name !== 'script' && this.parent.name !== 'style')) {
  18679. // unless this Text node is inside a <script> or <style> element, escape &,<,>
  18680. text = escapeHTML(text);
  18681. }
  18682. this.compiler.target.append(escape(escapeTemplate(text)));
  18683. }
  18684. }
  18685. // source: https://gist.github.com/ArjanSchouten/0b8574a6ad7f5065a5e7
  18686. const booleanAttributes = new Set('async autocomplete autofocus autoplay border challenge checked compact contenteditable controls default defer disabled formnovalidate frameborder hidden indeterminate ismap loop multiple muted nohref noresize noshade novalidate nowrap open readonly required reversed scoped scrolling seamless selected sortable spellcheck translate'.split(' '));
  18687. class Element extends Node$1 {
  18688. constructor(compiler, parent, scope, info) {
  18689. super(compiler, parent, scope, info);
  18690. this.name = info.name;
  18691. this.scope = scope;
  18692. const parentElement = parent.findNearest(/^Element/);
  18693. this.namespace = this.name === 'svg' ?
  18694. svg :
  18695. parentElement ? parentElement.namespace : this.compiler.namespace;
  18696. this.attributes = [];
  18697. this.actions = [];
  18698. this.bindings = [];
  18699. this.handlers = [];
  18700. this.intro = null;
  18701. this.outro = null;
  18702. this.animation = null;
  18703. if (this.name === 'textarea') {
  18704. // this is an egregious hack, but it's the easiest way to get <textarea>
  18705. // children treated the same way as a value attribute
  18706. if (info.children.length > 0) {
  18707. info.attributes.push({
  18708. type: 'Attribute',
  18709. name: 'value',
  18710. value: info.children
  18711. });
  18712. info.children = [];
  18713. }
  18714. }
  18715. if (this.name === 'option') {
  18716. // Special case — treat these the same way:
  18717. // <option>{foo}</option>
  18718. // <option value={foo}>{foo}</option>
  18719. const valueAttribute = info.attributes.find((attribute) => attribute.name === 'value');
  18720. if (!valueAttribute) {
  18721. info.attributes.push({
  18722. type: 'Attribute',
  18723. name: 'value',
  18724. value: info.children,
  18725. synthetic: true
  18726. });
  18727. }
  18728. }
  18729. info.attributes.forEach(node => {
  18730. switch (node.type) {
  18731. case 'Action':
  18732. this.actions.push(new Action(compiler, this, scope, node));
  18733. break;
  18734. case 'Attribute':
  18735. case 'Spread':
  18736. // special case
  18737. if (node.name === 'xmlns')
  18738. this.namespace = node.value[0].data;
  18739. this.attributes.push(new Attribute(compiler, this, scope, node));
  18740. break;
  18741. case 'Binding':
  18742. this.bindings.push(new Binding(compiler, this, scope, node));
  18743. break;
  18744. case 'EventHandler':
  18745. this.handlers.push(new EventHandler(compiler, this, scope, node));
  18746. break;
  18747. case 'Transition':
  18748. const transition = new Transition(compiler, this, scope, node);
  18749. if (node.intro)
  18750. this.intro = transition;
  18751. if (node.outro)
  18752. this.outro = transition;
  18753. break;
  18754. case 'Animation':
  18755. this.animation = new Animation(compiler, this, scope, node);
  18756. break;
  18757. case 'Ref':
  18758. // TODO catch this in validation
  18759. if (this.ref)
  18760. throw new Error(`Duplicate refs`);
  18761. compiler.usesRefs = true;
  18762. this.ref = node.name;
  18763. break;
  18764. default:
  18765. throw new Error(`Not implemented: ${node.type}`);
  18766. }
  18767. });
  18768. this.children = mapChildren(compiler, this, scope, info.children);
  18769. compiler.stylesheet.apply(this);
  18770. }
  18771. init(block, stripWhitespace, nextSibling) {
  18772. if (this.name === 'slot' || this.name === 'option') {
  18773. this.cannotUseInnerHTML();
  18774. }
  18775. this.var = block.getUniqueName(this.name.replace(/[^a-zA-Z0-9_$]/g, '_'));
  18776. this.attributes.forEach(attr => {
  18777. if (attr.dependencies.size) {
  18778. this.parent.cannotUseInnerHTML();
  18779. block.addDependencies(attr.dependencies);
  18780. // special case — <option value={foo}> — see below
  18781. if (this.name === 'option' && attr.name === 'value') {
  18782. let select = this.parent;
  18783. while (select && (select.type !== 'Element' || select.name !== 'select'))
  18784. select = select.parent;
  18785. if (select && select.selectBindingDependencies) {
  18786. select.selectBindingDependencies.forEach(prop => {
  18787. attr.dependencies.forEach((dependency) => {
  18788. this.compiler.indirectDependencies.get(prop).add(dependency);
  18789. });
  18790. });
  18791. }
  18792. }
  18793. }
  18794. });
  18795. this.actions.forEach(action => {
  18796. this.parent.cannotUseInnerHTML();
  18797. if (action.expression) {
  18798. block.addDependencies(action.expression.dependencies);
  18799. }
  18800. });
  18801. this.bindings.forEach(binding => {
  18802. this.parent.cannotUseInnerHTML();
  18803. block.addDependencies(binding.value.dependencies);
  18804. });
  18805. this.handlers.forEach(handler => {
  18806. this.parent.cannotUseInnerHTML();
  18807. block.addDependencies(handler.dependencies);
  18808. });
  18809. if (this.intro || this.outro || this.animation || this.ref) {
  18810. this.parent.cannotUseInnerHTML();
  18811. }
  18812. if (this.intro)
  18813. block.addIntro();
  18814. if (this.outro)
  18815. block.addOutro();
  18816. if (this.animation)
  18817. block.addAnimation();
  18818. const valueAttribute = this.attributes.find((attribute) => attribute.name === 'value');
  18819. // special case — in a case like this...
  18820. //
  18821. // <select bind:value='foo'>
  18822. // <option value='{bar}'>bar</option>
  18823. // <option value='{baz}'>baz</option>
  18824. // </option>
  18825. //
  18826. // ...we need to know that `foo` depends on `bar` and `baz`,
  18827. // so that if `foo.qux` changes, we know that we need to
  18828. // mark `bar` and `baz` as dirty too
  18829. if (this.name === 'select') {
  18830. const binding = this.bindings.find(node => node.name === 'value');
  18831. if (binding) {
  18832. // TODO does this also apply to e.g. `<input type='checkbox' bind:group='foo'>`?
  18833. const dependencies = binding.value.dependencies;
  18834. this.selectBindingDependencies = dependencies;
  18835. dependencies.forEach((prop) => {
  18836. this.compiler.indirectDependencies.set(prop, new Set());
  18837. });
  18838. }
  18839. else {
  18840. this.selectBindingDependencies = null;
  18841. }
  18842. }
  18843. const slot = this.getStaticAttributeValue('slot');
  18844. if (slot && this.hasAncestor('Component')) {
  18845. this.cannotUseInnerHTML();
  18846. this.slotted = true;
  18847. // TODO validate slots — no nesting, no dynamic names...
  18848. const component = this.findNearest(/^Component/);
  18849. component._slots.add(slot);
  18850. }
  18851. if (this.children.length) {
  18852. if (this.name === 'pre' || this.name === 'textarea')
  18853. stripWhitespace = false;
  18854. this.initChildren(block, stripWhitespace, nextSibling);
  18855. }
  18856. }
  18857. build(block, parentNode, parentNodes) {
  18858. const { compiler } = this;
  18859. if (this.name === 'slot') {
  18860. const slotName = this.getStaticAttributeValue('name') || 'default';
  18861. this.compiler.slots.add(slotName);
  18862. }
  18863. if (this.name === 'noscript')
  18864. return;
  18865. const childState = {
  18866. parentNode: this.var,
  18867. parentNodes: parentNodes && block.getUniqueName(`${this.var}_nodes`) // if we're in unclaimable territory, i.e. <head>, parentNodes is null
  18868. };
  18869. const name = this.var;
  18870. const slot = this.attributes.find((attribute) => attribute.name === 'slot');
  18871. const prop = slot && quotePropIfNecessary(slot.chunks[0].data);
  18872. const initialMountNode = this.slotted ?
  18873. `${this.findNearest(/^Component/).var}._slotted${prop}` : // TODO this looks bonkers
  18874. parentNode;
  18875. block.addVariable(name);
  18876. const renderStatement = getRenderStatement(this.namespace, this.name);
  18877. block.builders.create.addLine(`${name} = ${renderStatement};`);
  18878. if (this.compiler.options.hydratable) {
  18879. if (parentNodes) {
  18880. block.builders.claim.addBlock(deindent `
  18881. ${name} = ${getClaimStatement(compiler, this.namespace, parentNodes, this)};
  18882. var ${childState.parentNodes} = @children(${name});
  18883. `);
  18884. }
  18885. else {
  18886. block.builders.claim.addLine(`${name} = ${renderStatement};`);
  18887. }
  18888. }
  18889. if (initialMountNode) {
  18890. block.builders.mount.addLine(`@appendNode(${name}, ${initialMountNode});`);
  18891. if (initialMountNode === 'document.head') {
  18892. block.builders.destroy.addLine(`@detachNode(${name});`);
  18893. }
  18894. }
  18895. else {
  18896. block.builders.mount.addLine(`@insertNode(${name}, #target, anchor);`);
  18897. // TODO we eventually need to consider what happens to elements
  18898. // that belong to the same outgroup as an outroing element...
  18899. block.builders.destroy.addConditional('detach', `@detachNode(${name});`);
  18900. }
  18901. // TODO move this into a class as well?
  18902. if (this._cssRefAttribute) {
  18903. block.builders.hydrate.addLine(`@setAttribute(${name}, "svelte-ref-${this._cssRefAttribute}", "");`);
  18904. }
  18905. // insert static children with textContent or innerHTML
  18906. if (!this.namespace && this.canUseInnerHTML && this.children.length > 0) {
  18907. if (this.children.length === 1 && this.children[0].type === 'Text') {
  18908. block.builders.create.addLine(`${name}.textContent = ${stringify(this.children[0].data)};`);
  18909. }
  18910. else {
  18911. block.builders.create.addLine(`${name}.innerHTML = ${stringify(this.children.map(toHTML).join(''))};`);
  18912. }
  18913. }
  18914. else {
  18915. this.children.forEach((child) => {
  18916. child.build(block, childState.parentNode, childState.parentNodes);
  18917. });
  18918. }
  18919. let hasHoistedEventHandlerOrBinding = (
  18920. //(this.hasAncestor('EachBlock') && this.bindings.length > 0) ||
  18921. this.handlers.some(handler => handler.shouldHoist));
  18922. const eventHandlerOrBindingUsesComponent = (this.bindings.length > 0 ||
  18923. this.handlers.some(handler => handler.usesComponent));
  18924. const eventHandlerOrBindingUsesContext = (this.bindings.some(binding => binding.usesContext) ||
  18925. this.handlers.some(handler => handler.usesContext));
  18926. if (hasHoistedEventHandlerOrBinding) {
  18927. const initialProps = [];
  18928. if (eventHandlerOrBindingUsesComponent) {
  18929. const component = block.alias('component');
  18930. initialProps.push(component === 'component' ? 'component' : `component: ${component}`);
  18931. }
  18932. if (eventHandlerOrBindingUsesContext) {
  18933. initialProps.push(`ctx`);
  18934. block.builders.update.addLine(`${name}._svelte.ctx = ctx;`);
  18935. }
  18936. if (initialProps.length) {
  18937. block.builders.hydrate.addBlock(deindent `
  18938. ${name}._svelte = { ${initialProps.join(', ')} };
  18939. `);
  18940. }
  18941. }
  18942. else {
  18943. if (eventHandlerOrBindingUsesContext) {
  18944. block.maintainContext = true;
  18945. }
  18946. }
  18947. this.addBindings(block);
  18948. this.addEventHandlers(block);
  18949. if (this.ref)
  18950. this.addRef(block);
  18951. this.addAttributes(block);
  18952. this.addTransitions(block);
  18953. this.addAnimation(block);
  18954. this.addActions(block);
  18955. if (this.initialUpdate) {
  18956. block.builders.mount.addBlock(this.initialUpdate);
  18957. }
  18958. if (childState.parentNodes) {
  18959. block.builders.claim.addLine(`${childState.parentNodes}.forEach(@detachNode);`);
  18960. }
  18961. function toHTML(node) {
  18962. if (node.type === 'Text') {
  18963. return node.parent &&
  18964. node.parent.type === 'Element' &&
  18965. (node.parent.name === 'script' || node.parent.name === 'style')
  18966. ? node.data
  18967. : escapeHTML(node.data);
  18968. }
  18969. if (node.name === 'noscript')
  18970. return '';
  18971. let open = `<${node.name}`;
  18972. if (node._cssRefAttribute) {
  18973. open += ` svelte-ref-${node._cssRefAttribute}`;
  18974. }
  18975. node.attributes.forEach((attr) => {
  18976. open += ` ${fixAttributeCasing(attr.name)}${stringifyAttributeValue(attr.chunks)}`;
  18977. });
  18978. if (isVoidElementName(node.name))
  18979. return open + '>';
  18980. return `${open}>${node.children.map(toHTML).join('')}</${node.name}>`;
  18981. }
  18982. }
  18983. addBindings(block) {
  18984. if (this.bindings.length === 0)
  18985. return;
  18986. if (this.name === 'select' || this.isMediaNode())
  18987. this.compiler.target.hasComplexBindings = true;
  18988. const needsLock = this.name !== 'input' || !/radio|checkbox|range|color/.test(this.getStaticAttributeValue('type'));
  18989. // TODO munge in constructor
  18990. const mungedBindings = this.bindings.map(binding => binding.munge(block));
  18991. const lock = mungedBindings.some(binding => binding.needsLock) ?
  18992. block.getUniqueName(`${this.var}_updating`) :
  18993. null;
  18994. if (lock)
  18995. block.addVariable(lock, 'false');
  18996. const groups = events$1
  18997. .map(event => {
  18998. return {
  18999. events: event.eventNames,
  19000. bindings: mungedBindings.filter(binding => event.filter(this, binding.name))
  19001. };
  19002. })
  19003. .filter(group => group.bindings.length);
  19004. groups.forEach(group => {
  19005. const handler = block.getUniqueName(`${this.var}_${group.events.join('_')}_handler`);
  19006. const needsLock = group.bindings.some(binding => binding.needsLock);
  19007. group.bindings.forEach(binding => {
  19008. if (!binding.updateDom)
  19009. return;
  19010. const updateConditions = needsLock ? [`!${lock}`] : [];
  19011. if (binding.updateCondition)
  19012. updateConditions.push(binding.updateCondition);
  19013. block.builders.update.addLine(updateConditions.length ? `if (${updateConditions.join(' && ')}) ${binding.updateDom}` : binding.updateDom);
  19014. });
  19015. const usesContext = group.bindings.some(binding => binding.handler.usesContext);
  19016. const usesState = group.bindings.some(binding => binding.handler.usesState);
  19017. const usesStore = group.bindings.some(binding => binding.handler.usesStore);
  19018. const mutations = group.bindings.map(binding => binding.handler.mutation).filter(Boolean).join('\n');
  19019. const props = new Set();
  19020. const storeProps = new Set();
  19021. group.bindings.forEach(binding => {
  19022. binding.handler.props.forEach(prop => {
  19023. props.add(prop);
  19024. });
  19025. binding.handler.storeProps.forEach(prop => {
  19026. storeProps.add(prop);
  19027. });
  19028. }); // TODO use stringifyProps here, once indenting is fixed
  19029. // media bindings — awkward special case. The native timeupdate events
  19030. // fire too infrequently, so we need to take matters into our
  19031. // own hands
  19032. let animation_frame;
  19033. if (group.events[0] === 'timeupdate') {
  19034. animation_frame = block.getUniqueName(`${this.var}_animationframe`);
  19035. block.addVariable(animation_frame);
  19036. }
  19037. block.builders.init.addBlock(deindent `
  19038. function ${handler}() {
  19039. ${animation_frame && deindent `
  19040. cancelAnimationFrame(${animation_frame});
  19041. if (!${this.var}.paused) ${animation_frame} = requestAnimationFrame(${handler});`}
  19042. ${usesStore && `var $ = #component.store.get();`}
  19043. ${needsLock && `${lock} = true;`}
  19044. ${mutations.length > 0 && mutations}
  19045. ${props.size > 0 && `#component.set({ ${Array.from(props).join(', ')} });`}
  19046. ${storeProps.size > 0 && `#component.store.set({ ${Array.from(storeProps).join(', ')} });`}
  19047. ${needsLock && `${lock} = false;`}
  19048. }
  19049. `);
  19050. group.events.forEach(name => {
  19051. if (name === 'resize') {
  19052. // special case
  19053. const resize_listener = block.getUniqueName(`${this.var}_resize_listener`);
  19054. block.addVariable(resize_listener);
  19055. block.builders.mount.addLine(`${resize_listener} = @addResizeListener(${this.var}, ${handler});`);
  19056. block.builders.destroy.addLine(`${resize_listener}.cancel();`);
  19057. }
  19058. else {
  19059. block.builders.hydrate.addLine(`@addListener(${this.var}, "${name}", ${handler});`);
  19060. block.builders.destroy.addLine(`@removeListener(${this.var}, "${name}", ${handler});`);
  19061. }
  19062. });
  19063. const allInitialStateIsDefined = group.bindings
  19064. .map(binding => `'${binding.object}' in ctx`)
  19065. .join(' && ');
  19066. if (this.name === 'select' || group.bindings.find(binding => binding.name === 'indeterminate' || binding.isReadOnlyMediaAttribute)) {
  19067. this.compiler.target.hasComplexBindings = true;
  19068. block.builders.hydrate.addLine(`if (!(${allInitialStateIsDefined})) #component.root._beforecreate.push(${handler});`);
  19069. }
  19070. if (group.events[0] === 'resize') {
  19071. this.compiler.target.hasComplexBindings = true;
  19072. block.builders.hydrate.addLine(`#component.root._beforecreate.push(${handler});`);
  19073. }
  19074. });
  19075. this.initialUpdate = mungedBindings.map(binding => binding.initialUpdate).filter(Boolean).join('\n');
  19076. }
  19077. addAttributes(block) {
  19078. if (this.attributes.find(attr => attr.type === 'Spread')) {
  19079. this.addSpreadAttributes(block);
  19080. return;
  19081. }
  19082. this.attributes.forEach((attribute) => {
  19083. attribute.render(block);
  19084. });
  19085. }
  19086. addSpreadAttributes(block) {
  19087. const levels = block.getUniqueName(`${this.var}_levels`);
  19088. const data = block.getUniqueName(`${this.var}_data`);
  19089. const initialProps = [];
  19090. const updates = [];
  19091. this.attributes
  19092. .filter(attr => attr.type === 'Attribute' || attr.type === 'Spread')
  19093. .forEach(attr => {
  19094. const condition = attr.dependencies.size > 0
  19095. ? [...attr.dependencies].map(d => `changed.${d}`).join(' || ')
  19096. : null;
  19097. if (attr.isSpread) {
  19098. const { snippet, dependencies } = attr.expression;
  19099. initialProps.push(snippet);
  19100. updates.push(condition ? `${condition} && ${snippet}` : snippet);
  19101. }
  19102. else {
  19103. const snippet = `{ ${quoteNameIfNecessary(attr.name)}: ${attr.getValue()} }`;
  19104. initialProps.push(snippet);
  19105. updates.push(condition ? `${condition} && ${snippet}` : snippet);
  19106. }
  19107. });
  19108. block.builders.init.addBlock(deindent `
  19109. var ${levels} = [
  19110. ${initialProps.join(',\n')}
  19111. ];
  19112. var ${data} = {};
  19113. for (var #i = 0; #i < ${levels}.length; #i += 1) {
  19114. ${data} = @assign(${data}, ${levels}[#i]);
  19115. }
  19116. `);
  19117. block.builders.hydrate.addLine(`@setAttributes(${this.var}, ${data});`);
  19118. block.builders.update.addBlock(deindent `
  19119. @setAttributes(${this.var}, @getSpreadUpdate(${levels}, [
  19120. ${updates.join(',\n')}
  19121. ]));
  19122. `);
  19123. }
  19124. addEventHandlers(block) {
  19125. const { compiler } = this;
  19126. this.handlers.forEach(handler => {
  19127. const isCustomEvent = compiler.events.has(handler.name);
  19128. if (handler.callee) {
  19129. handler.render(this.compiler, block, handler.shouldHoist);
  19130. }
  19131. const target = handler.shouldHoist ? 'this' : this.var;
  19132. // get a name for the event handler that is globally unique
  19133. // if hoisted, locally unique otherwise
  19134. const handlerName = (handler.shouldHoist ? compiler : block).getUniqueName(`${handler.name.replace(/[^a-zA-Z0-9_$]/g, '_')}_handler`);
  19135. const component = block.alias('component'); // can't use #component, might be hoisted
  19136. // create the handler body
  19137. const handlerBody = deindent `
  19138. ${handler.shouldHoist && (handler.usesComponent || handler.usesContext
  19139. ? `const { ${[handler.usesComponent && 'component', handler.usesContext && 'ctx'].filter(Boolean).join(', ')} } = ${target}._svelte;`
  19140. : null)}
  19141. ${handler.snippet ?
  19142. handler.snippet :
  19143. `${component}.fire("${handler.name}", event);`}
  19144. `;
  19145. if (isCustomEvent) {
  19146. block.addVariable(handlerName);
  19147. block.builders.hydrate.addBlock(deindent `
  19148. ${handlerName} = %events-${handler.name}.call(${component}, ${this.var}, function(event) {
  19149. ${handlerBody}
  19150. });
  19151. `);
  19152. block.builders.destroy.addLine(deindent `
  19153. ${handlerName}.destroy();
  19154. `);
  19155. }
  19156. else {
  19157. const handlerFunction = deindent `
  19158. function ${handlerName}(event) {
  19159. ${handlerBody}
  19160. }
  19161. `;
  19162. if (handler.shouldHoist) {
  19163. compiler.target.blocks.push(handlerFunction);
  19164. }
  19165. else {
  19166. block.builders.init.addBlock(handlerFunction);
  19167. }
  19168. block.builders.hydrate.addLine(`@addListener(${this.var}, "${handler.name}", ${handlerName});`);
  19169. block.builders.destroy.addLine(`@removeListener(${this.var}, "${handler.name}", ${handlerName});`);
  19170. }
  19171. });
  19172. }
  19173. addRef(block) {
  19174. const ref = `#component.refs.${this.ref}`;
  19175. block.builders.mount.addLine(`${ref} = ${this.var};`);
  19176. block.builders.destroy.addLine(`if (${ref} === ${this.var}) ${ref} = null;`);
  19177. }
  19178. addTransitions(block) {
  19179. const { intro, outro } = this;
  19180. if (!intro && !outro)
  19181. return;
  19182. if (intro === outro) {
  19183. const name = block.getUniqueName(`${this.var}_transition`);
  19184. const snippet = intro.expression
  19185. ? intro.expression.snippet
  19186. : '{}';
  19187. block.addVariable(name);
  19188. const fn = `%transitions-${intro.name}`;
  19189. block.builders.intro.addConditional(`#component.root._intro`, deindent `
  19190. if (${name}) ${name}.invalidate();
  19191. #component.root._aftercreate.push(() => {
  19192. if (!${name}) ${name} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true);
  19193. ${name}.run(1);
  19194. });
  19195. `);
  19196. block.builders.outro.addBlock(deindent `
  19197. if (!${name}) ${name} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, false);
  19198. ${name}.run(0, () => {
  19199. #outrocallback();
  19200. ${name} = null;
  19201. });
  19202. `);
  19203. }
  19204. else {
  19205. const introName = intro && block.getUniqueName(`${this.var}_intro`);
  19206. const outroName = outro && block.getUniqueName(`${this.var}_outro`);
  19207. if (intro) {
  19208. block.addVariable(introName);
  19209. const snippet = intro.expression
  19210. ? intro.expression.snippet
  19211. : '{}';
  19212. const fn = `%transitions-${intro.name}`; // TODO add built-in transitions?
  19213. if (outro) {
  19214. block.builders.intro.addBlock(deindent `
  19215. if (${introName}) ${introName}.abort();
  19216. if (${outroName}) ${outroName}.abort();
  19217. `);
  19218. }
  19219. block.builders.intro.addConditional(`#component.root._intro`, deindent `
  19220. #component.root._aftercreate.push(() => {
  19221. ${introName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true);
  19222. ${introName}.run(1);
  19223. });
  19224. `);
  19225. }
  19226. if (outro) {
  19227. block.addVariable(outroName);
  19228. const snippet = outro.expression
  19229. ? outro.expression.snippet
  19230. : '{}';
  19231. const fn = `%transitions-${outro.name}`;
  19232. block.builders.intro.addBlock(deindent `
  19233. if (${outroName}) ${outroName}.abort();
  19234. `);
  19235. // TODO hide elements that have outro'd (unless they belong to a still-outroing
  19236. // group) prior to their removal from the DOM
  19237. block.builders.outro.addBlock(deindent `
  19238. ${outroName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, false);
  19239. ${outroName}.run(0, #outrocallback);
  19240. `);
  19241. }
  19242. }
  19243. }
  19244. addAnimation(block) {
  19245. if (!this.animation)
  19246. return;
  19247. const rect = block.getUniqueName('rect');
  19248. const animation = block.getUniqueName('animation');
  19249. block.addVariable(rect);
  19250. block.addVariable(animation);
  19251. block.builders.measure.addBlock(deindent `
  19252. ${rect} = ${this.var}.getBoundingClientRect();
  19253. `);
  19254. block.builders.fix.addBlock(deindent `
  19255. @fixPosition(${this.var});
  19256. if (${animation}) ${animation}.stop();
  19257. `);
  19258. const params = this.animation.expression ? this.animation.expression.snippet : '{}';
  19259. block.builders.animate.addBlock(deindent `
  19260. if (${animation}) ${animation}.stop();
  19261. ${animation} = @wrapAnimation(${this.var}, ${rect}, %animations-${this.animation.name}, ${params});
  19262. `);
  19263. }
  19264. addActions(block) {
  19265. this.actions.forEach(action => {
  19266. const { expression } = action;
  19267. let snippet, dependencies;
  19268. if (expression) {
  19269. snippet = action.expression.snippet;
  19270. dependencies = action.expression.dependencies;
  19271. }
  19272. const name = block.getUniqueName(`${action.name.replace(/[^a-zA-Z0-9_$]/g, '_')}_action`);
  19273. block.addVariable(name);
  19274. const fn = `%actions-${action.name}`;
  19275. block.builders.hydrate.addLine(`${name} = ${fn}.call(#component, ${this.var}${snippet ? `, ${snippet}` : ''}) || {};`);
  19276. if (dependencies && dependencies.size > 0) {
  19277. let conditional = `typeof ${name}.update === 'function' && `;
  19278. const deps = [...dependencies].map(dependency => `changed.${dependency}`).join(' || ');
  19279. conditional += dependencies.size > 1 ? `(${deps})` : deps;
  19280. block.builders.update.addConditional(conditional, `${name}.update.call(#component, ${snippet});`);
  19281. }
  19282. block.builders.destroy.addLine(`if (typeof ${name}.destroy === 'function') ${name}.destroy.call(#component);`);
  19283. });
  19284. }
  19285. getStaticAttributeValue(name) {
  19286. const attribute = this.attributes.find((attr) => attr.type === 'Attribute' && attr.name.toLowerCase() === name);
  19287. if (!attribute)
  19288. return null;
  19289. if (attribute.isTrue)
  19290. return true;
  19291. if (attribute.chunks.length === 0)
  19292. return '';
  19293. if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
  19294. return attribute.chunks[0].data;
  19295. }
  19296. return null;
  19297. }
  19298. isMediaNode() {
  19299. return this.name === 'audio' || this.name === 'video';
  19300. }
  19301. remount(name) {
  19302. const slot = this.attributes.find(attribute => attribute.name === 'slot');
  19303. if (slot) {
  19304. const prop = quotePropIfNecessary(slot.chunks[0].data);
  19305. return `@appendNode(${this.var}, ${name}._slotted${prop});`;
  19306. }
  19307. return `@appendNode(${this.var}, ${name}._slotted.default);`;
  19308. }
  19309. addCssClass() {
  19310. const classAttribute = this.attributes.find(a => a.name === 'class');
  19311. if (classAttribute && !classAttribute.isTrue) {
  19312. if (classAttribute.chunks.length === 1 && classAttribute.chunks[0].type === 'Text') {
  19313. classAttribute.chunks[0].data += ` ${this.compiler.stylesheet.id}`;
  19314. }
  19315. else {
  19316. classAttribute.chunks.push(new Text(this.compiler, this, this.scope, {
  19317. type: 'Text',
  19318. data: ` ${this.compiler.stylesheet.id}`
  19319. })
  19320. // new Text({ type: 'Text', data: ` ${this.compiler.stylesheet.id}` })
  19321. );
  19322. }
  19323. }
  19324. else {
  19325. this.attributes.push(new Attribute(this.compiler, this, this.scope, {
  19326. type: 'Attribute',
  19327. name: 'class',
  19328. value: [{ type: 'Text', data: `${this.compiler.stylesheet.id}` }]
  19329. }));
  19330. }
  19331. }
  19332. ssr() {
  19333. const { compiler } = this;
  19334. let openingTag = `<${this.name}`;
  19335. let textareaContents; // awkward special case
  19336. const slot = this.getStaticAttributeValue('slot');
  19337. if (slot && this.hasAncestor('Component')) {
  19338. const slot = this.attributes.find((attribute) => attribute.name === 'slot');
  19339. const slotName = slot.chunks[0].data;
  19340. const appendTarget = compiler.target.appendTargets[compiler.target.appendTargets.length - 1];
  19341. appendTarget.slotStack.push(slotName);
  19342. appendTarget.slots[slotName] = '';
  19343. }
  19344. if (this.attributes.find(attr => attr.isSpread)) {
  19345. // TODO dry this out
  19346. const args = [];
  19347. this.attributes.forEach(attribute => {
  19348. if (attribute.isSpread) {
  19349. args.push(attribute.expression.snippet);
  19350. }
  19351. else {
  19352. if (attribute.name === 'value' && this.name === 'textarea') {
  19353. textareaContents = attribute.stringifyForSsr();
  19354. }
  19355. else if (attribute.isTrue) {
  19356. args.push(`{ ${quoteNameIfNecessary(attribute.name)}: true }`);
  19357. }
  19358. else if (booleanAttributes.has(attribute.name) &&
  19359. attribute.chunks.length === 1 &&
  19360. attribute.chunks[0].type !== 'Text') {
  19361. // a boolean attribute with one non-Text chunk
  19362. args.push(`{ ${quoteNameIfNecessary(attribute.name)}: ${attribute.chunks[0].snippet} }`);
  19363. }
  19364. else {
  19365. args.push(`{ ${quoteNameIfNecessary(attribute.name)}: \`${attribute.stringifyForSsr()}\` }`);
  19366. }
  19367. }
  19368. });
  19369. openingTag += "${@spread([" + args.join(', ') + "])}";
  19370. }
  19371. else {
  19372. this.attributes.forEach((attribute) => {
  19373. if (attribute.type !== 'Attribute')
  19374. return;
  19375. if (attribute.name === 'value' && this.name === 'textarea') {
  19376. textareaContents = attribute.stringifyForSsr();
  19377. }
  19378. else if (attribute.isTrue) {
  19379. openingTag += ` ${attribute.name}`;
  19380. }
  19381. else if (booleanAttributes.has(attribute.name) &&
  19382. attribute.chunks.length === 1 &&
  19383. attribute.chunks[0].type !== 'Text') {
  19384. // a boolean attribute with one non-Text chunk
  19385. openingTag += '${' + attribute.chunks[0].snippet + ' ? " ' + attribute.name + '" : "" }';
  19386. }
  19387. else {
  19388. openingTag += ` ${attribute.name}="${attribute.stringifyForSsr()}"`;
  19389. }
  19390. });
  19391. }
  19392. if (this._cssRefAttribute) {
  19393. openingTag += ` svelte-ref-${this._cssRefAttribute}`;
  19394. }
  19395. openingTag += '>';
  19396. compiler.target.append(openingTag);
  19397. if (this.name === 'textarea' && textareaContents !== undefined) {
  19398. compiler.target.append(textareaContents);
  19399. }
  19400. else {
  19401. this.children.forEach((child) => {
  19402. child.ssr();
  19403. });
  19404. }
  19405. if (!isVoidElementName(this.name)) {
  19406. compiler.target.append(`</${this.name}>`);
  19407. }
  19408. }
  19409. }
  19410. function getRenderStatement(namespace, name) {
  19411. if (namespace === 'http://www.w3.org/2000/svg') {
  19412. return `@createSvgElement("${name}")`;
  19413. }
  19414. if (namespace) {
  19415. return `document.createElementNS("${namespace}", "${name}")`;
  19416. }
  19417. return `@createElement("${name}")`;
  19418. }
  19419. function getClaimStatement(compiler, namespace, nodes, node) {
  19420. const attributes = node.attributes
  19421. .filter((attr) => attr.type === 'Attribute')
  19422. .map((attr) => `${quoteNameIfNecessary(attr.name)}: true`)
  19423. .join(', ');
  19424. const name = namespace ? node.name : node.name.toUpperCase();
  19425. return `@claimElement(${nodes}, "${name}", ${attributes
  19426. ? `{ ${attributes} }`
  19427. : `{}`}, ${namespace === svg ? true : false})`;
  19428. }
  19429. function stringifyAttributeValue(value) {
  19430. if (value === true)
  19431. return '';
  19432. if (value.length === 0)
  19433. return `=""`;
  19434. const data = value[0].data;
  19435. return `=${JSON.stringify(data)}`;
  19436. }
  19437. const events$1 = [
  19438. {
  19439. eventNames: ['input'],
  19440. filter: (node, name) => node.name === 'textarea' ||
  19441. node.name === 'input' && !/radio|checkbox|range/.test(node.getStaticAttributeValue('type'))
  19442. },
  19443. {
  19444. eventNames: ['change'],
  19445. filter: (node, name) => node.name === 'select' ||
  19446. node.name === 'input' && /radio|checkbox/.test(node.getStaticAttributeValue('type'))
  19447. },
  19448. {
  19449. eventNames: ['change', 'input'],
  19450. filter: (node, name) => node.name === 'input' && node.getStaticAttributeValue('type') === 'range'
  19451. },
  19452. {
  19453. eventNames: ['resize'],
  19454. filter: (node, name) => dimensions.test(name)
  19455. },
  19456. // media events
  19457. {
  19458. eventNames: ['timeupdate'],
  19459. filter: (node, name) => node.isMediaNode() &&
  19460. (name === 'currentTime' || name === 'played')
  19461. },
  19462. {
  19463. eventNames: ['durationchange'],
  19464. filter: (node, name) => node.isMediaNode() &&
  19465. name === 'duration'
  19466. },
  19467. {
  19468. eventNames: ['play', 'pause'],
  19469. filter: (node, name) => node.isMediaNode() &&
  19470. name === 'paused'
  19471. },
  19472. {
  19473. eventNames: ['progress'],
  19474. filter: (node, name) => node.isMediaNode() &&
  19475. name === 'buffered'
  19476. },
  19477. {
  19478. eventNames: ['loadedmetadata'],
  19479. filter: (node, name) => node.isMediaNode() &&
  19480. (name === 'buffered' || name === 'seekable')
  19481. },
  19482. {
  19483. eventNames: ['volumechange'],
  19484. filter: (node, name) => node.isMediaNode() &&
  19485. name === 'volume'
  19486. }
  19487. ];
  19488. class Head extends Node$1 {
  19489. constructor(compiler, parent, scope, info) {
  19490. super(compiler, parent, scope, info);
  19491. this.children = mapChildren(compiler, parent, scope, info.children.filter(child => {
  19492. return (child.type !== 'Text' || /\S/.test(child.data));
  19493. }));
  19494. }
  19495. init(block, stripWhitespace, nextSibling) {
  19496. this.initChildren(block, true, null);
  19497. }
  19498. build(block, parentNode, parentNodes) {
  19499. this.var = 'document.head';
  19500. this.children.forEach((child) => {
  19501. child.build(block, 'document.head', null);
  19502. });
  19503. }
  19504. ssr() {
  19505. this.compiler.target.append('${(__result.head += `');
  19506. this.children.forEach((child) => {
  19507. child.ssr();
  19508. });
  19509. this.compiler.target.append('`, "")}');
  19510. }
  19511. }
  19512. function isElseIf(node) {
  19513. return (node && node.children.length === 1 && node.children[0].type === 'IfBlock');
  19514. }
  19515. function isElseBranch(branch) {
  19516. return branch.block && !branch.condition;
  19517. }
  19518. class IfBlock extends Node$1 {
  19519. constructor(compiler, parent, scope, info) {
  19520. super(compiler, parent, scope, info);
  19521. this.expression = new Expression(compiler, this, scope, info.expression);
  19522. this.children = mapChildren(compiler, this, scope, info.children);
  19523. this.else = info.else
  19524. ? new ElseBlock(compiler, this, scope, info.else)
  19525. : null;
  19526. }
  19527. init(block, stripWhitespace, nextSibling) {
  19528. const { compiler } = this;
  19529. this.cannotUseInnerHTML();
  19530. const blocks = [];
  19531. let dynamic = false;
  19532. let hasIntros = false;
  19533. let hasOutros = false;
  19534. function attachBlocks(node) {
  19535. node.var = block.getUniqueName(`if_block`);
  19536. block.addDependencies(node.expression.dependencies);
  19537. node.block = block.child({
  19538. comment: createDebuggingComment(node, compiler),
  19539. name: compiler.getUniqueName(`create_if_block`),
  19540. });
  19541. blocks.push(node.block);
  19542. node.initChildren(node.block, stripWhitespace, nextSibling);
  19543. if (node.block.dependencies.size > 0) {
  19544. dynamic = true;
  19545. block.addDependencies(node.block.dependencies);
  19546. }
  19547. if (node.block.hasIntros)
  19548. hasIntros = true;
  19549. if (node.block.hasOutros)
  19550. hasOutros = true;
  19551. if (isElseIf(node.else)) {
  19552. attachBlocks(node.else.children[0]);
  19553. }
  19554. else if (node.else) {
  19555. node.else.block = block.child({
  19556. comment: createDebuggingComment(node.else, compiler),
  19557. name: compiler.getUniqueName(`create_if_block`),
  19558. });
  19559. blocks.push(node.else.block);
  19560. node.else.initChildren(node.else.block, stripWhitespace, nextSibling);
  19561. if (node.else.block.dependencies.size > 0) {
  19562. dynamic = true;
  19563. block.addDependencies(node.else.block.dependencies);
  19564. }
  19565. }
  19566. }
  19567. attachBlocks(this);
  19568. if (compiler.options.nestedTransitions) {
  19569. if (hasIntros)
  19570. block.addIntro();
  19571. if (hasOutros)
  19572. block.addOutro();
  19573. }
  19574. blocks.forEach(block => {
  19575. block.hasUpdateMethod = dynamic;
  19576. block.hasIntroMethod = hasIntros;
  19577. block.hasOutroMethod = hasOutros;
  19578. });
  19579. compiler.target.blocks.push(...blocks);
  19580. }
  19581. build(block, parentNode, parentNodes) {
  19582. const name = this.var;
  19583. const needsAnchor = this.next ? !this.next.isDomNode() : !parentNode || !this.parent.isDomNode();
  19584. const anchor = needsAnchor
  19585. ? block.getUniqueName(`${name}_anchor`)
  19586. : (this.next && this.next.var) || 'null';
  19587. const branches = this.getBranches(block, parentNode, parentNodes, this);
  19588. const hasElse = isElseBranch(branches[branches.length - 1]);
  19589. const if_name = hasElse ? '' : `if (${name}) `;
  19590. const dynamic = branches[0].hasUpdateMethod; // can use [0] as proxy for all, since they necessarily have the same value
  19591. const hasOutros = branches[0].hasOutroMethod;
  19592. const vars = { name, anchor, if_name, hasElse };
  19593. if (this.else) {
  19594. if (hasOutros) {
  19595. this.buildCompoundWithOutros(block, parentNode, parentNodes, branches, dynamic, vars);
  19596. if (this.compiler.options.nestedTransitions) {
  19597. block.builders.outro.addLine(`${name}.o(#outrocallback);`);
  19598. }
  19599. }
  19600. else {
  19601. this.buildCompound(block, parentNode, parentNodes, branches, dynamic, vars);
  19602. }
  19603. }
  19604. else {
  19605. this.buildSimple(block, parentNode, parentNodes, branches[0], dynamic, vars);
  19606. if (hasOutros && this.compiler.options.nestedTransitions) {
  19607. block.builders.outro.addLine(`if (${name}) ${name}.o(#outrocallback);`);
  19608. }
  19609. }
  19610. block.builders.create.addLine(`${if_name}${name}.c();`);
  19611. if (parentNodes) {
  19612. block.builders.claim.addLine(`${if_name}${name}.l(${parentNodes});`);
  19613. }
  19614. if (needsAnchor) {
  19615. block.addElement(anchor, `@createComment()`, parentNodes && `@createComment()`, parentNode);
  19616. }
  19617. }
  19618. buildCompound(block, parentNode, parentNodes, branches, dynamic, { name, anchor, hasElse, if_name }) {
  19619. const select_block_type = this.compiler.getUniqueName(`select_block_type`);
  19620. const current_block_type = block.getUniqueName(`current_block_type`);
  19621. const current_block_type_and = hasElse ? '' : `${current_block_type} && `;
  19622. block.builders.init.addBlock(deindent `
  19623. function ${select_block_type}(ctx) {
  19624. ${branches
  19625. .map(({ condition, block }) => `${condition ? `if (${condition}) ` : ''}return ${block};`)
  19626. .join('\n')}
  19627. }
  19628. `);
  19629. block.builders.init.addBlock(deindent `
  19630. var ${current_block_type} = ${select_block_type}(ctx);
  19631. var ${name} = ${current_block_type_and}${current_block_type}(#component, ctx);
  19632. `);
  19633. const mountOrIntro = branches[0].hasIntroMethod ? 'i' : 'm';
  19634. const initialMountNode = parentNode || '#target';
  19635. const anchorNode = parentNode ? 'null' : 'anchor';
  19636. block.builders.mount.addLine(`${if_name}${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode});`);
  19637. const updateMountNode = this.getUpdateMountNode(anchor);
  19638. const changeBlock = deindent `
  19639. ${hasElse
  19640. ? deindent `
  19641. ${name}.d(1);
  19642. `
  19643. : deindent `
  19644. if (${name}) {
  19645. ${name}.d(1);
  19646. }`}
  19647. ${name} = ${current_block_type_and}${current_block_type}(#component, ctx);
  19648. ${if_name}${name}.c();
  19649. ${if_name}${name}.${mountOrIntro}(${updateMountNode}, ${anchor});
  19650. `;
  19651. if (dynamic) {
  19652. block.builders.update.addBlock(deindent `
  19653. if (${current_block_type} === (${current_block_type} = ${select_block_type}(ctx)) && ${name}) {
  19654. ${name}.p(changed, ctx);
  19655. } else {
  19656. ${changeBlock}
  19657. }
  19658. `);
  19659. }
  19660. else {
  19661. block.builders.update.addBlock(deindent `
  19662. if (${current_block_type} !== (${current_block_type} = ${select_block_type}(ctx))) {
  19663. ${changeBlock}
  19664. }
  19665. `);
  19666. }
  19667. block.builders.destroy.addLine(`${if_name}${name}.d(${parentNode ? '' : 'detach'});`);
  19668. }
  19669. // if any of the siblings have outros, we need to keep references to the blocks
  19670. // (TODO does this only apply to bidi transitions?)
  19671. buildCompoundWithOutros(block, parentNode, parentNodes, branches, dynamic, { name, anchor, hasElse }) {
  19672. const select_block_type = block.getUniqueName(`select_block_type`);
  19673. const current_block_type_index = block.getUniqueName(`current_block_type_index`);
  19674. const previous_block_index = block.getUniqueName(`previous_block_index`);
  19675. const if_block_creators = block.getUniqueName(`if_block_creators`);
  19676. const if_blocks = block.getUniqueName(`if_blocks`);
  19677. const if_current_block_type_index = hasElse
  19678. ? ''
  19679. : `if (~${current_block_type_index}) `;
  19680. block.addVariable(current_block_type_index);
  19681. block.addVariable(name);
  19682. block.builders.init.addBlock(deindent `
  19683. var ${if_block_creators} = [
  19684. ${branches.map(branch => branch.block).join(',\n')}
  19685. ];
  19686. var ${if_blocks} = [];
  19687. function ${select_block_type}(ctx) {
  19688. ${branches
  19689. .map(({ condition, block }, i) => `${condition ? `if (${condition}) ` : ''}return ${block ? i : -1};`)
  19690. .join('\n')}
  19691. }
  19692. `);
  19693. if (hasElse) {
  19694. block.builders.init.addBlock(deindent `
  19695. ${current_block_type_index} = ${select_block_type}(ctx);
  19696. ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx);
  19697. `);
  19698. }
  19699. else {
  19700. block.builders.init.addBlock(deindent `
  19701. if (~(${current_block_type_index} = ${select_block_type}(ctx))) {
  19702. ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx);
  19703. }
  19704. `);
  19705. }
  19706. const mountOrIntro = branches[0].hasIntroMethod ? 'i' : 'm';
  19707. const initialMountNode = parentNode || '#target';
  19708. const anchorNode = parentNode ? 'null' : 'anchor';
  19709. block.builders.mount.addLine(`${if_current_block_type_index}${if_blocks}[${current_block_type_index}].${mountOrIntro}(${initialMountNode}, ${anchorNode});`);
  19710. const updateMountNode = this.getUpdateMountNode(anchor);
  19711. const destroyOldBlock = deindent `
  19712. @transitionManager.groupOutros();
  19713. ${name}.o(function() {
  19714. ${if_blocks}[${previous_block_index}].d(1);
  19715. ${if_blocks}[${previous_block_index}] = null;
  19716. });
  19717. `;
  19718. const createNewBlock = deindent `
  19719. ${name} = ${if_blocks}[${current_block_type_index}];
  19720. if (!${name}) {
  19721. ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx);
  19722. ${name}.c();
  19723. }
  19724. ${name}.${mountOrIntro}(${updateMountNode}, ${anchor});
  19725. `;
  19726. const changeBlock = hasElse
  19727. ? deindent `
  19728. ${destroyOldBlock}
  19729. ${createNewBlock}
  19730. `
  19731. : deindent `
  19732. if (${name}) {
  19733. ${destroyOldBlock}
  19734. }
  19735. if (~${current_block_type_index}) {
  19736. ${createNewBlock}
  19737. } else {
  19738. ${name} = null;
  19739. }
  19740. `;
  19741. if (dynamic) {
  19742. block.builders.update.addBlock(deindent `
  19743. var ${previous_block_index} = ${current_block_type_index};
  19744. ${current_block_type_index} = ${select_block_type}(ctx);
  19745. if (${current_block_type_index} === ${previous_block_index}) {
  19746. ${if_current_block_type_index}${if_blocks}[${current_block_type_index}].p(changed, ctx);
  19747. } else {
  19748. ${changeBlock}
  19749. }
  19750. `);
  19751. }
  19752. else {
  19753. block.builders.update.addBlock(deindent `
  19754. var ${previous_block_index} = ${current_block_type_index};
  19755. ${current_block_type_index} = ${select_block_type}(ctx);
  19756. if (${current_block_type_index} !== ${previous_block_index}) {
  19757. ${changeBlock}
  19758. }
  19759. `);
  19760. }
  19761. block.builders.destroy.addLine(deindent `
  19762. ${if_current_block_type_index}${if_blocks}[${current_block_type_index}].d(${parentNode ? '' : 'detach'});
  19763. `);
  19764. }
  19765. buildSimple(block, parentNode, parentNodes, branch, dynamic, { name, anchor, if_name }) {
  19766. block.builders.init.addBlock(deindent `
  19767. var ${name} = (${branch.condition}) && ${branch.block}(#component, ctx);
  19768. `);
  19769. const mountOrIntro = branch.hasIntroMethod ? 'i' : 'm';
  19770. const initialMountNode = parentNode || '#target';
  19771. const anchorNode = parentNode ? 'null' : 'anchor';
  19772. block.builders.mount.addLine(`if (${name}) ${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode});`);
  19773. const updateMountNode = this.getUpdateMountNode(anchor);
  19774. const enter = dynamic
  19775. ? (branch.hasIntroMethod || branch.hasOutroMethod)
  19776. ? deindent `
  19777. if (${name}) {
  19778. ${name}.p(changed, ctx);
  19779. } else {
  19780. ${name} = ${branch.block}(#component, ctx);
  19781. if (${name}) ${name}.c();
  19782. }
  19783. ${name}.i(${updateMountNode}, ${anchor});
  19784. `
  19785. : deindent `
  19786. if (${name}) {
  19787. ${name}.p(changed, ctx);
  19788. } else {
  19789. ${name} = ${branch.block}(#component, ctx);
  19790. ${name}.c();
  19791. ${name}.m(${updateMountNode}, ${anchor});
  19792. }
  19793. `
  19794. : (branch.hasIntroMethod || branch.hasOutroMethod)
  19795. ? deindent `
  19796. if (!${name}) {
  19797. ${name} = ${branch.block}(#component, ctx);
  19798. ${name}.c();
  19799. }
  19800. ${name}.i(${updateMountNode}, ${anchor});
  19801. `
  19802. : deindent `
  19803. if (!${name}) {
  19804. ${name} = ${branch.block}(#component, ctx);
  19805. ${name}.c();
  19806. ${name}.m(${updateMountNode}, ${anchor});
  19807. }
  19808. `;
  19809. // no `p()` here — we don't want to update outroing nodes,
  19810. // as that will typically result in glitching
  19811. const exit = branch.hasOutroMethod
  19812. ? deindent `
  19813. @transitionManager.groupOutros();
  19814. ${name}.o(function() {
  19815. ${name}.d(1);
  19816. ${name} = null;
  19817. });
  19818. `
  19819. : deindent `
  19820. ${name}.d(1);
  19821. ${name} = null;
  19822. `;
  19823. block.builders.update.addBlock(deindent `
  19824. if (${branch.condition}) {
  19825. ${enter}
  19826. } else if (${name}) {
  19827. ${exit}
  19828. }
  19829. `);
  19830. block.builders.destroy.addLine(`${if_name}${name}.d(${parentNode ? '' : 'detach'});`);
  19831. }
  19832. getBranches(block, parentNode, parentNodes, node) {
  19833. const branches = [
  19834. {
  19835. condition: node.expression.snippet,
  19836. block: node.block.name,
  19837. hasUpdateMethod: node.block.hasUpdateMethod,
  19838. hasIntroMethod: node.block.hasIntroMethod,
  19839. hasOutroMethod: node.block.hasOutroMethod,
  19840. },
  19841. ];
  19842. this.visitChildren(block, node);
  19843. if (isElseIf(node.else)) {
  19844. branches.push(...this.getBranches(block, parentNode, parentNodes, node.else.children[0]));
  19845. }
  19846. else {
  19847. branches.push({
  19848. condition: null,
  19849. block: node.else ? node.else.block.name : null,
  19850. hasUpdateMethod: node.else ? node.else.block.hasUpdateMethod : false,
  19851. hasIntroMethod: node.else ? node.else.block.hasIntroMethod : false,
  19852. hasOutroMethod: node.else ? node.else.block.hasOutroMethod : false,
  19853. });
  19854. if (node.else) {
  19855. this.visitChildren(block, node.else);
  19856. }
  19857. }
  19858. return branches;
  19859. }
  19860. ssr() {
  19861. const { compiler } = this;
  19862. const { snippet } = this.expression;
  19863. compiler.target.append('${ ' + snippet + ' ? `');
  19864. this.children.forEach((child) => {
  19865. child.ssr();
  19866. });
  19867. compiler.target.append('` : `');
  19868. if (this.else) {
  19869. this.else.children.forEach((child) => {
  19870. child.ssr();
  19871. });
  19872. }
  19873. compiler.target.append('` }');
  19874. }
  19875. visitChildren(block, node) {
  19876. node.children.forEach((child) => {
  19877. child.build(node.block, null, 'nodes');
  19878. });
  19879. }
  19880. }
  19881. class Tag extends Node$1 {
  19882. constructor(compiler, parent, scope, info) {
  19883. super(compiler, parent, scope, info);
  19884. this.expression = new Expression(compiler, this, scope, info.expression);
  19885. this.shouldCache = (info.expression.type !== 'Identifier' ||
  19886. (this.expression.dependencies.size && scope.names.has(info.expression.name)));
  19887. }
  19888. init(block) {
  19889. this.cannotUseInnerHTML();
  19890. this.var = block.getUniqueName(this.type === 'MustacheTag' ? 'text' : 'raw');
  19891. block.addDependencies(this.expression.dependencies);
  19892. }
  19893. renameThisMethod(block, update) {
  19894. const { snippet, dependencies } = this.expression;
  19895. const value = this.shouldCache && block.getUniqueName(`${this.var}_value`);
  19896. const content = this.shouldCache ? value : snippet;
  19897. if (this.shouldCache)
  19898. block.addVariable(value, snippet);
  19899. if (dependencies.size) {
  19900. const changedCheck = ((block.hasOutros ? `#outroing || ` : '') +
  19901. [...dependencies].map((dependency) => `changed.${dependency}`).join(' || '));
  19902. const updateCachedValue = `${value} !== (${value} = ${snippet})`;
  19903. const condition = this.shouldCache ?
  19904. (dependencies.size ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue) :
  19905. changedCheck;
  19906. block.builders.update.addConditional(condition, update(content));
  19907. }
  19908. return { init: content };
  19909. }
  19910. }
  19911. class MustacheTag extends Tag {
  19912. build(block, parentNode, parentNodes) {
  19913. const { init } = this.renameThisMethod(block, value => `${this.var}.data = ${value};`);
  19914. block.addElement(this.var, `@createText(${init})`, parentNodes && `@claimText(${parentNodes}, ${init})`, parentNode);
  19915. }
  19916. remount(name) {
  19917. return `@appendNode(${this.var}, ${name}._slotted.default);`;
  19918. }
  19919. ssr() {
  19920. this.compiler.target.append(this.parent &&
  19921. this.parent.type === 'Element' &&
  19922. this.parent.name === 'style'
  19923. ? '${' + this.expression.snippet + '}'
  19924. : '${@escape(' + this.expression.snippet + ')}');
  19925. }
  19926. }
  19927. class RawMustacheTag extends Tag {
  19928. build(block, parentNode, parentNodes) {
  19929. const name = this.var;
  19930. const needsAnchorBefore = this.prev ? this.prev.type !== 'Element' : !parentNode;
  19931. const needsAnchorAfter = this.next ? this.next.type !== 'Element' : !parentNode;
  19932. const anchorBefore = needsAnchorBefore
  19933. ? block.getUniqueName(`${name}_before`)
  19934. : (this.prev && this.prev.var) || 'null';
  19935. const anchorAfter = needsAnchorAfter
  19936. ? block.getUniqueName(`${name}_after`)
  19937. : (this.next && this.next.var) || 'null';
  19938. let detach;
  19939. let insert;
  19940. let useInnerHTML = false;
  19941. if (anchorBefore === 'null' && anchorAfter === 'null') {
  19942. useInnerHTML = true;
  19943. detach = `${parentNode}.innerHTML = '';`;
  19944. insert = content => `${parentNode}.innerHTML = ${content};`;
  19945. }
  19946. else if (anchorBefore === 'null') {
  19947. detach = `@detachBefore(${anchorAfter});`;
  19948. insert = content => `${anchorAfter}.insertAdjacentHTML("beforebegin", ${content});`;
  19949. }
  19950. else if (anchorAfter === 'null') {
  19951. detach = `@detachAfter(${anchorBefore});`;
  19952. insert = content => `${anchorBefore}.insertAdjacentHTML("afterend", ${content});`;
  19953. }
  19954. else {
  19955. detach = `@detachBetween(${anchorBefore}, ${anchorAfter});`;
  19956. insert = content => `${anchorBefore}.insertAdjacentHTML("afterend", ${content});`;
  19957. }
  19958. const { init } = this.renameThisMethod(block, content => deindent `
  19959. ${!useInnerHTML && detach}
  19960. ${insert(content)}
  19961. `);
  19962. // we would have used comments here, but the `insertAdjacentHTML` api only
  19963. // exists for `Element`s.
  19964. if (needsAnchorBefore) {
  19965. block.addElement(anchorBefore, `@createElement('noscript')`, parentNodes && `@createElement('noscript')`, parentNode, true);
  19966. }
  19967. function addAnchorAfter() {
  19968. block.addElement(anchorAfter, `@createElement('noscript')`, parentNodes && `@createElement('noscript')`, parentNode);
  19969. }
  19970. if (needsAnchorAfter && anchorBefore === 'null') {
  19971. // anchorAfter needs to be in the DOM before we
  19972. // insert the HTML...
  19973. addAnchorAfter();
  19974. }
  19975. block.builders.mount.addLine(insert(init));
  19976. if (!parentNode) {
  19977. block.builders.destroy.addConditional('detach', needsAnchorBefore
  19978. ? `${detach}\n@detachNode(${anchorBefore});`
  19979. : detach);
  19980. }
  19981. if (needsAnchorAfter && anchorBefore !== 'null') {
  19982. // ...otherwise it should go afterwards
  19983. addAnchorAfter();
  19984. }
  19985. }
  19986. remount(name) {
  19987. return `@appendNode(${this.var}, ${name}._slotted.default);`;
  19988. }
  19989. ssr() {
  19990. this.compiler.target.append('${' + this.expression.snippet + '}');
  19991. }
  19992. }
  19993. function sanitize(name) {
  19994. return name.replace(/[^a-zA-Z]+/g, '_').replace(/^_/, '').replace(/_$/, '');
  19995. }
  19996. class Slot extends Element {
  19997. init(block, stripWhitespace, nextSibling) {
  19998. this.cannotUseInnerHTML();
  19999. this.var = block.getUniqueName('slot');
  20000. if (this.children.length) {
  20001. this.initChildren(block, stripWhitespace, nextSibling);
  20002. }
  20003. }
  20004. build(block, parentNode, parentNodes) {
  20005. const { compiler } = this;
  20006. const slotName = this.getStaticAttributeValue('name') || 'default';
  20007. compiler.slots.add(slotName);
  20008. const content_name = block.getUniqueName(`slot_content_${sanitize(slotName)}`);
  20009. const prop = quotePropIfNecessary(slotName);
  20010. block.addVariable(content_name, `#component._slotted${prop}`);
  20011. const needsAnchorBefore = this.prev ? this.prev.type !== 'Element' : !parentNode;
  20012. const needsAnchorAfter = this.next ? this.next.type !== 'Element' : !parentNode;
  20013. const anchorBefore = needsAnchorBefore
  20014. ? block.getUniqueName(`${content_name}_before`)
  20015. : (this.prev && this.prev.var) || 'null';
  20016. const anchorAfter = needsAnchorAfter
  20017. ? block.getUniqueName(`${content_name}_after`)
  20018. : (this.next && this.next.var) || 'null';
  20019. if (needsAnchorBefore)
  20020. block.addVariable(anchorBefore);
  20021. if (needsAnchorAfter)
  20022. block.addVariable(anchorAfter);
  20023. let mountBefore = block.builders.mount.toString();
  20024. let destroyBefore = block.builders.destroy.toString();
  20025. block.builders.create.pushCondition(`!${content_name}`);
  20026. block.builders.hydrate.pushCondition(`!${content_name}`);
  20027. block.builders.mount.pushCondition(`!${content_name}`);
  20028. block.builders.update.pushCondition(`!${content_name}`);
  20029. block.builders.destroy.pushCondition(`!${content_name}`);
  20030. this.children.forEach((child) => {
  20031. child.build(block, parentNode, parentNodes);
  20032. });
  20033. block.builders.create.popCondition();
  20034. block.builders.hydrate.popCondition();
  20035. block.builders.mount.popCondition();
  20036. block.builders.update.popCondition();
  20037. block.builders.destroy.popCondition();
  20038. const mountLeadin = block.builders.mount.toString() !== mountBefore
  20039. ? `else`
  20040. : `if (${content_name})`;
  20041. if (parentNode) {
  20042. block.builders.mount.addBlock(deindent `
  20043. ${mountLeadin} {
  20044. ${needsAnchorBefore && `@appendNode(${anchorBefore} || (${anchorBefore} = @createComment()), ${parentNode});`}
  20045. @appendNode(${content_name}, ${parentNode});
  20046. ${needsAnchorAfter && `@appendNode(${anchorAfter} || (${anchorAfter} = @createComment()), ${parentNode});`}
  20047. }
  20048. `);
  20049. }
  20050. else {
  20051. block.builders.mount.addBlock(deindent `
  20052. ${mountLeadin} {
  20053. ${needsAnchorBefore && `@insertNode(${anchorBefore} || (${anchorBefore} = @createComment()), #target, anchor);`}
  20054. @insertNode(${content_name}, #target, anchor);
  20055. ${needsAnchorAfter && `@insertNode(${anchorAfter} || (${anchorAfter} = @createComment()), #target, anchor);`}
  20056. }
  20057. `);
  20058. }
  20059. // if the slot is unmounted, move nodes back into the document fragment,
  20060. // so that it can be reinserted later
  20061. // TODO so that this can work with public API, component._slotted should
  20062. // be all fragments, derived from options.slots. Not === options.slots
  20063. const unmountLeadin = block.builders.destroy.toString() !== destroyBefore
  20064. ? `else`
  20065. : `if (${content_name})`;
  20066. if (anchorBefore === 'null' && anchorAfter === 'null') {
  20067. block.builders.destroy.addBlock(deindent `
  20068. ${unmountLeadin} {
  20069. @reinsertChildren(${parentNode}, ${content_name});
  20070. }
  20071. `);
  20072. }
  20073. else if (anchorBefore === 'null') {
  20074. block.builders.destroy.addBlock(deindent `
  20075. ${unmountLeadin} {
  20076. @reinsertBefore(${anchorAfter}, ${content_name});
  20077. }
  20078. `);
  20079. }
  20080. else if (anchorAfter === 'null') {
  20081. block.builders.destroy.addBlock(deindent `
  20082. ${unmountLeadin} {
  20083. @reinsertAfter(${anchorBefore}, ${content_name});
  20084. }
  20085. `);
  20086. }
  20087. else {
  20088. block.builders.destroy.addBlock(deindent `
  20089. ${unmountLeadin} {
  20090. @reinsertBetween(${anchorBefore}, ${anchorAfter}, ${content_name});
  20091. @detachNode(${anchorBefore});
  20092. @detachNode(${anchorAfter});
  20093. }
  20094. `);
  20095. }
  20096. }
  20097. getStaticAttributeValue(name) {
  20098. const attribute = this.attributes.find(attr => attr.name.toLowerCase() === name);
  20099. if (!attribute)
  20100. return null;
  20101. if (attribute.isTrue)
  20102. return true;
  20103. if (attribute.chunks.length === 0)
  20104. return '';
  20105. if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
  20106. return attribute.chunks[0].data;
  20107. }
  20108. return null;
  20109. }
  20110. ssr() {
  20111. const name = this.attributes.find(attribute => attribute.name === 'name');
  20112. const slotName = name && name.chunks[0].data || 'default';
  20113. const prop = quotePropIfNecessary(slotName);
  20114. this.compiler.target.append(`\${options && options.slotted && options.slotted${prop} ? options.slotted${prop}() : \``);
  20115. this.children.forEach((child) => {
  20116. child.ssr();
  20117. });
  20118. this.compiler.target.append(`\`}`);
  20119. }
  20120. }
  20121. class Title extends Node$1 {
  20122. constructor(compiler, parent, scope, info) {
  20123. super(compiler, parent, scope, info);
  20124. this.children = mapChildren(compiler, parent, scope, info.children);
  20125. this.shouldCache = info.children.length === 1
  20126. ? (info.children[0].type !== 'Identifier' ||
  20127. scope.names.has(info.children[0].name))
  20128. : true;
  20129. }
  20130. build(block, parentNode, parentNodes) {
  20131. const isDynamic = !!this.children.find(node => node.type !== 'Text');
  20132. if (isDynamic) {
  20133. let value;
  20134. const allDependencies = new Set();
  20135. // TODO some of this code is repeated in Tag.ts — would be good to
  20136. // DRY it out if that's possible without introducing crazy indirection
  20137. if (this.children.length === 1) {
  20138. // single {{tag}} — may be a non-string
  20139. const { expression } = this.children[0];
  20140. const { dependencies, snippet } = this.children[0].expression;
  20141. value = snippet;
  20142. dependencies.forEach(d => {
  20143. allDependencies.add(d);
  20144. });
  20145. }
  20146. else {
  20147. // '{foo} {bar}' — treat as string concatenation
  20148. value =
  20149. (this.children[0].type === 'Text' ? '' : `"" + `) +
  20150. this.children
  20151. .map((chunk) => {
  20152. if (chunk.type === 'Text') {
  20153. return stringify(chunk.data);
  20154. }
  20155. else {
  20156. const { dependencies, snippet } = chunk.expression;
  20157. dependencies.forEach(d => {
  20158. allDependencies.add(d);
  20159. });
  20160. return chunk.expression.getPrecedence() <= 13 ? `(${snippet})` : snippet;
  20161. }
  20162. })
  20163. .join(' + ');
  20164. }
  20165. const last = this.shouldCache && block.getUniqueName(`title_value`);
  20166. if (this.shouldCache)
  20167. block.addVariable(last);
  20168. let updater;
  20169. const init = this.shouldCache ? `${last} = ${value}` : value;
  20170. block.builders.init.addLine(`document.title = ${init};`);
  20171. updater = `document.title = ${this.shouldCache ? last : value};`;
  20172. if (allDependencies.size) {
  20173. const dependencies = Array.from(allDependencies);
  20174. const changedCheck = ((block.hasOutros ? `#outroing || ` : '') +
  20175. dependencies.map(dependency => `changed.${dependency}`).join(' || '));
  20176. const updateCachedValue = `${last} !== (${last} = ${value})`;
  20177. const condition = this.shouldCache ?
  20178. (dependencies.length ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue) :
  20179. changedCheck;
  20180. block.builders.update.addConditional(condition, updater);
  20181. }
  20182. }
  20183. else {
  20184. const value = stringify(this.children[0].data);
  20185. block.builders.hydrate.addLine(`document.title = ${value};`);
  20186. }
  20187. }
  20188. ssr() {
  20189. this.compiler.target.append(`<title>`);
  20190. this.children.forEach((child) => {
  20191. child.ssr();
  20192. });
  20193. this.compiler.target.append(`</title>`);
  20194. }
  20195. }
  20196. const associatedEvents = {
  20197. innerWidth: 'resize',
  20198. innerHeight: 'resize',
  20199. outerWidth: 'resize',
  20200. outerHeight: 'resize',
  20201. scrollX: 'scroll',
  20202. scrollY: 'scroll',
  20203. };
  20204. const properties = {
  20205. scrollX: 'pageXOffset',
  20206. scrollY: 'pageYOffset'
  20207. };
  20208. const readonly = new Set([
  20209. 'innerWidth',
  20210. 'innerHeight',
  20211. 'outerWidth',
  20212. 'outerHeight',
  20213. 'online',
  20214. ]);
  20215. class Window extends Node$1 {
  20216. constructor(compiler, parent, scope, info) {
  20217. super(compiler, parent, scope, info);
  20218. this.handlers = [];
  20219. this.bindings = [];
  20220. info.attributes.forEach(node => {
  20221. if (node.type === 'EventHandler') {
  20222. this.handlers.push(new EventHandler(compiler, this, scope, node));
  20223. }
  20224. else if (node.type === 'Binding') {
  20225. this.bindings.push(new Binding(compiler, this, scope, node));
  20226. }
  20227. });
  20228. }
  20229. build(block, parentNode, parentNodes) {
  20230. const { compiler } = this;
  20231. const events = {};
  20232. const bindings = {};
  20233. this.handlers.forEach(handler => {
  20234. // TODO verify that it's a valid callee (i.e. built-in or declared method)
  20235. compiler.addSourcemapLocations(handler.expression);
  20236. const isCustomEvent = compiler.events.has(handler.name);
  20237. let usesState = handler.dependencies.size > 0;
  20238. handler.render(compiler, block, false); // TODO hoist?
  20239. const handlerName = block.getUniqueName(`onwindow${handler.name}`);
  20240. const handlerBody = deindent `
  20241. ${usesState && `var ctx = #component.get();`}
  20242. ${handler.snippet};
  20243. `;
  20244. if (isCustomEvent) {
  20245. // TODO dry this out
  20246. block.addVariable(handlerName);
  20247. block.builders.hydrate.addBlock(deindent `
  20248. ${handlerName} = %events-${handler.name}.call(#component, window, function(event) {
  20249. ${handlerBody}
  20250. });
  20251. `);
  20252. block.builders.destroy.addLine(deindent `
  20253. ${handlerName}.destroy();
  20254. `);
  20255. }
  20256. else {
  20257. block.builders.init.addBlock(deindent `
  20258. function ${handlerName}(event) {
  20259. ${handlerBody}
  20260. }
  20261. window.addEventListener("${handler.name}", ${handlerName});
  20262. `);
  20263. block.builders.destroy.addBlock(deindent `
  20264. window.removeEventListener("${handler.name}", ${handlerName});
  20265. `);
  20266. }
  20267. });
  20268. this.bindings.forEach(binding => {
  20269. // in dev mode, throw if read-only values are written to
  20270. if (readonly.has(binding.name)) {
  20271. compiler.target.readonly.add(binding.value.node.name);
  20272. }
  20273. bindings[binding.name] = binding.value.node.name;
  20274. // bind:online is a special case, we need to listen for two separate events
  20275. if (binding.name === 'online')
  20276. return;
  20277. const associatedEvent = associatedEvents[binding.name];
  20278. const property = properties[binding.name] || binding.name;
  20279. if (!events[associatedEvent])
  20280. events[associatedEvent] = [];
  20281. events[associatedEvent].push(`${binding.value.node.name}: this.${property}`);
  20282. // add initial value
  20283. compiler.target.metaBindings.push(`this._state.${binding.value.node.name} = window.${property};`);
  20284. });
  20285. const lock = block.getUniqueName(`window_updating`);
  20286. const clear = block.getUniqueName(`clear_window_updating`);
  20287. const timeout = block.getUniqueName(`window_updating_timeout`);
  20288. Object.keys(events).forEach(event => {
  20289. const handlerName = block.getUniqueName(`onwindow${event}`);
  20290. const props = events[event].join(',\n');
  20291. if (event === 'scroll') {
  20292. // TODO other bidirectional bindings...
  20293. block.addVariable(lock, 'false');
  20294. block.addVariable(clear, `function() { ${lock} = false; }`);
  20295. block.addVariable(timeout);
  20296. }
  20297. const handlerBody = deindent `
  20298. ${event === 'scroll' && deindent `
  20299. if (${lock}) return;
  20300. ${lock} = true;
  20301. `}
  20302. ${compiler.options.dev && `component._updatingReadonlyProperty = true;`}
  20303. #component.set({
  20304. ${props}
  20305. });
  20306. ${compiler.options.dev && `component._updatingReadonlyProperty = false;`}
  20307. ${event === 'scroll' && `${lock} = false;`}
  20308. `;
  20309. block.builders.init.addBlock(deindent `
  20310. function ${handlerName}(event) {
  20311. ${handlerBody}
  20312. }
  20313. window.addEventListener("${event}", ${handlerName});
  20314. `);
  20315. block.builders.destroy.addBlock(deindent `
  20316. window.removeEventListener("${event}", ${handlerName});
  20317. `);
  20318. });
  20319. // special case... might need to abstract this out if we add more special cases
  20320. if (bindings.scrollX || bindings.scrollY) {
  20321. block.builders.init.addBlock(deindent `
  20322. #component.on("state", ({ changed, current }) => {
  20323. if (${[bindings.scrollX, bindings.scrollY].map(binding => binding && `changed["${binding}"]`).filter(Boolean).join(' || ')}) {
  20324. ${lock} = true;
  20325. clearTimeout(${timeout});
  20326. window.scrollTo(${bindings.scrollX ? `current["${bindings.scrollX}"]` : `window.pageXOffset`}, ${bindings.scrollY ? `current["${bindings.scrollY}"]` : `window.pageYOffset`});
  20327. ${timeout} = setTimeout(${clear}, 100);
  20328. }
  20329. });
  20330. `);
  20331. }
  20332. // another special case. (I'm starting to think these are all special cases.)
  20333. if (bindings.online) {
  20334. const handlerName = block.getUniqueName(`onlinestatuschanged`);
  20335. block.builders.init.addBlock(deindent `
  20336. function ${handlerName}(event) {
  20337. #component.set({ ${bindings.online}: navigator.onLine });
  20338. }
  20339. window.addEventListener("online", ${handlerName});
  20340. window.addEventListener("offline", ${handlerName});
  20341. `);
  20342. // add initial value
  20343. compiler.target.metaBindings.push(`this._state.${bindings.online} = navigator.onLine;`);
  20344. block.builders.destroy.addBlock(deindent `
  20345. window.removeEventListener("online", ${handlerName});
  20346. window.removeEventListener("offline", ${handlerName});
  20347. `);
  20348. }
  20349. }
  20350. ssr() {
  20351. // noop
  20352. }
  20353. }
  20354. function getConstructor(type) {
  20355. switch (type) {
  20356. case 'AwaitBlock': return AwaitBlock;
  20357. case 'Comment': return Comment$2;
  20358. case 'Component': return Component;
  20359. case 'EachBlock': return EachBlock;
  20360. case 'Element': return Element;
  20361. case 'Head': return Head;
  20362. case 'IfBlock': return IfBlock;
  20363. case 'MustacheTag': return MustacheTag;
  20364. case 'RawMustacheTag': return RawMustacheTag;
  20365. case 'Slot': return Slot;
  20366. case 'Text': return Text;
  20367. case 'Title': return Title;
  20368. case 'Window': return Window;
  20369. default: throw new Error(`Not implemented: ${type}`);
  20370. }
  20371. }
  20372. function mapChildren(compiler, parent, scope, children) {
  20373. let last = null;
  20374. return children.map(child => {
  20375. const constructor = getConstructor(child.type);
  20376. const node = new constructor(compiler, parent, scope, child);
  20377. if (last)
  20378. last.next = node;
  20379. node.prev = last;
  20380. last = node;
  20381. return node;
  20382. });
  20383. }
  20384. class Block$2 {
  20385. constructor(options) {
  20386. this.parent = options.parent;
  20387. this.compiler = options.compiler;
  20388. this.name = options.name;
  20389. this.comment = options.comment;
  20390. // for keyed each blocks
  20391. this.key = options.key;
  20392. this.first = null;
  20393. this.dependencies = new Set();
  20394. this.bindings = options.bindings;
  20395. this.builders = {
  20396. init: new CodeBuilder(),
  20397. create: new CodeBuilder(),
  20398. claim: new CodeBuilder(),
  20399. hydrate: new CodeBuilder(),
  20400. mount: new CodeBuilder(),
  20401. measure: new CodeBuilder(),
  20402. fix: new CodeBuilder(),
  20403. animate: new CodeBuilder(),
  20404. intro: new CodeBuilder(),
  20405. update: new CodeBuilder(),
  20406. outro: new CodeBuilder(),
  20407. destroy: new CodeBuilder(),
  20408. };
  20409. this.hasAnimation = false;
  20410. this.hasIntroMethod = false; // a block could have an intro method but not intro transitions, e.g. if a sibling block has intros
  20411. this.hasOutroMethod = false;
  20412. this.outros = 0;
  20413. this.getUniqueName = this.compiler.getUniqueNameMaker();
  20414. this.variables = new Map();
  20415. this.aliases = new Map()
  20416. .set('component', this.getUniqueName('component'))
  20417. .set('ctx', this.getUniqueName('ctx'));
  20418. if (this.key)
  20419. this.aliases.set('key', this.getUniqueName('key'));
  20420. this.hasUpdateMethod = false; // determined later
  20421. }
  20422. addDependencies(dependencies) {
  20423. dependencies.forEach(dependency => {
  20424. this.dependencies.add(dependency);
  20425. });
  20426. }
  20427. addElement(name, renderStatement, claimStatement, parentNode, noDetach) {
  20428. this.addVariable(name);
  20429. this.builders.create.addLine(`${name} = ${renderStatement};`);
  20430. this.builders.claim.addLine(`${name} = ${claimStatement || renderStatement};`);
  20431. if (parentNode) {
  20432. this.builders.mount.addLine(`@appendNode(${name}, ${parentNode});`);
  20433. if (parentNode === 'document.head')
  20434. this.builders.destroy.addLine(`@detachNode(${name});`);
  20435. }
  20436. else {
  20437. this.builders.mount.addLine(`@insertNode(${name}, #target, anchor);`);
  20438. if (!noDetach)
  20439. this.builders.destroy.addConditional('detach', `@detachNode(${name});`);
  20440. }
  20441. }
  20442. addIntro() {
  20443. this.hasIntros = this.hasIntroMethod = this.compiler.target.hasIntroTransitions = true;
  20444. }
  20445. addOutro() {
  20446. this.hasOutros = this.hasOutroMethod = this.compiler.target.hasOutroTransitions = true;
  20447. this.outros += 1;
  20448. }
  20449. addAnimation() {
  20450. this.hasAnimation = true;
  20451. }
  20452. addVariable(name, init) {
  20453. if (this.variables.has(name) && this.variables.get(name) !== init) {
  20454. throw new Error(`Variable '${name}' already initialised with a different value`);
  20455. }
  20456. this.variables.set(name, init);
  20457. }
  20458. alias(name) {
  20459. if (!this.aliases.has(name)) {
  20460. this.aliases.set(name, this.getUniqueName(name));
  20461. }
  20462. return this.aliases.get(name);
  20463. }
  20464. child(options) {
  20465. return new Block$2(Object.assign({}, this, { key: null }, options, { parent: this }));
  20466. }
  20467. toString() {
  20468. const { dev } = this.compiler.options;
  20469. let introing;
  20470. const hasIntros = !this.builders.intro.isEmpty();
  20471. if (hasIntros) {
  20472. introing = this.getUniqueName('introing');
  20473. this.addVariable(introing);
  20474. }
  20475. let outroing;
  20476. const hasOutros = !this.builders.outro.isEmpty();
  20477. if (hasOutros) {
  20478. outroing = this.alias('outroing');
  20479. this.addVariable(outroing);
  20480. }
  20481. if (this.autofocus) {
  20482. this.builders.mount.addLine(`${this.autofocus}.focus();`);
  20483. }
  20484. const properties = new CodeBuilder();
  20485. let localKey;
  20486. if (this.key) {
  20487. localKey = this.getUniqueName('key');
  20488. properties.addBlock(`key: ${localKey},`);
  20489. }
  20490. if (this.first) {
  20491. properties.addBlock(`first: null,`);
  20492. this.builders.hydrate.addLine(`this.first = ${this.first};`);
  20493. }
  20494. if (this.builders.create.isEmpty() && this.builders.hydrate.isEmpty()) {
  20495. properties.addBlock(`c: @noop,`);
  20496. }
  20497. else {
  20498. const hydrate = !this.builders.hydrate.isEmpty() && (this.compiler.options.hydratable
  20499. ? `this.h()`
  20500. : this.builders.hydrate);
  20501. properties.addBlock(deindent `
  20502. ${dev ? 'c: function create' : 'c'}() {
  20503. ${this.builders.create}
  20504. ${hydrate}
  20505. },
  20506. `);
  20507. }
  20508. if (this.compiler.options.hydratable) {
  20509. if (this.builders.claim.isEmpty() && this.builders.hydrate.isEmpty()) {
  20510. properties.addBlock(`l: @noop,`);
  20511. }
  20512. else {
  20513. properties.addBlock(deindent `
  20514. ${dev ? 'l: function claim' : 'l'}(nodes) {
  20515. ${this.builders.claim}
  20516. ${!this.builders.hydrate.isEmpty() && `this.h();`}
  20517. },
  20518. `);
  20519. }
  20520. }
  20521. if (this.compiler.options.hydratable && !this.builders.hydrate.isEmpty()) {
  20522. properties.addBlock(deindent `
  20523. ${dev ? 'h: function hydrate' : 'h'}() {
  20524. ${this.builders.hydrate}
  20525. },
  20526. `);
  20527. }
  20528. if (this.builders.mount.isEmpty()) {
  20529. properties.addBlock(`m: @noop,`);
  20530. }
  20531. else {
  20532. properties.addBlock(deindent `
  20533. ${dev ? 'm: function mount' : 'm'}(#target, anchor) {
  20534. ${this.builders.mount}
  20535. },
  20536. `);
  20537. }
  20538. if (this.hasUpdateMethod || this.maintainContext) {
  20539. if (this.builders.update.isEmpty() && !this.maintainContext) {
  20540. properties.addBlock(`p: @noop,`);
  20541. }
  20542. else {
  20543. properties.addBlock(deindent `
  20544. ${dev ? 'p: function update' : 'p'}(changed, ${this.maintainContext ? '_ctx' : 'ctx'}) {
  20545. ${this.maintainContext && `ctx = _ctx;`}
  20546. ${this.builders.update}
  20547. },
  20548. `);
  20549. }
  20550. }
  20551. if (this.hasAnimation) {
  20552. properties.addBlock(deindent `
  20553. ${dev ? `r: function measure` : `r`}() {
  20554. ${this.builders.measure}
  20555. },
  20556. ${dev ? `f: function fix` : `f`}() {
  20557. ${this.builders.fix}
  20558. },
  20559. ${dev ? `a: function animate` : `a`}() {
  20560. ${this.builders.animate}
  20561. },
  20562. `);
  20563. }
  20564. if (this.hasIntroMethod || this.hasOutroMethod) {
  20565. if (hasIntros) {
  20566. properties.addBlock(deindent `
  20567. ${dev ? 'i: function intro' : 'i'}(#target, anchor) {
  20568. if (${introing}) return;
  20569. ${introing} = true;
  20570. ${hasOutros && `${outroing} = false;`}
  20571. ${this.builders.intro}
  20572. this.m(#target, anchor);
  20573. },
  20574. `);
  20575. }
  20576. else {
  20577. if (this.builders.mount.isEmpty()) {
  20578. properties.addBlock(`i: @noop,`);
  20579. }
  20580. else {
  20581. properties.addBlock(deindent `
  20582. ${dev ? 'i: function intro' : 'i'}(#target, anchor) {
  20583. this.m(#target, anchor);
  20584. },
  20585. `);
  20586. }
  20587. }
  20588. if (hasOutros) {
  20589. properties.addBlock(deindent `
  20590. ${dev ? 'o: function outro' : 'o'}(#outrocallback) {
  20591. if (${outroing}) return;
  20592. ${outroing} = true;
  20593. ${hasIntros && `${introing} = false;`}
  20594. ${this.outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${this.outros});`}
  20595. ${this.builders.outro}
  20596. },
  20597. `);
  20598. }
  20599. else {
  20600. properties.addBlock(deindent `
  20601. o: @run,
  20602. `);
  20603. }
  20604. }
  20605. if (this.builders.destroy.isEmpty()) {
  20606. properties.addBlock(`d: @noop`);
  20607. }
  20608. else {
  20609. properties.addBlock(deindent `
  20610. ${dev ? 'd: function destroy' : 'd'}(detach) {
  20611. ${this.builders.destroy}
  20612. }
  20613. `);
  20614. }
  20615. return deindent `
  20616. ${this.comment && `// ${escape(this.comment)}`}
  20617. function ${this.name}(#component${this.key ? `, ${localKey}` : ''}, ctx) {
  20618. ${this.variables.size > 0 &&
  20619. `var ${Array.from(this.variables.keys())
  20620. .map(key => {
  20621. const init = this.variables.get(key);
  20622. return init !== undefined ? `${key} = ${init}` : key;
  20623. })
  20624. .join(', ')};`}
  20625. ${!this.builders.init.isEmpty() && this.builders.init}
  20626. return {
  20627. ${properties}
  20628. };
  20629. }
  20630. `.replace(/(#+)(\w*)/g, (match, sigil, name) => {
  20631. return sigil === '#' ? this.alias(name) : sigil.slice(1) + name;
  20632. });
  20633. }
  20634. }
  20635. class TemplateScope {
  20636. constructor(parent) {
  20637. this.names = new Set(parent ? parent.names : []);
  20638. this.dependenciesForName = new Map(parent ? parent.dependenciesForName : []);
  20639. }
  20640. add(name, dependencies) {
  20641. this.names.add(name);
  20642. this.dependenciesForName.set(name, dependencies);
  20643. return this;
  20644. }
  20645. child() {
  20646. return new TemplateScope(this);
  20647. }
  20648. }
  20649. class Fragment extends Node$1 {
  20650. constructor(compiler, info) {
  20651. const scope = new TemplateScope();
  20652. super(compiler, null, scope, info);
  20653. this.scope = scope;
  20654. this.children = mapChildren(compiler, this, scope, info.children);
  20655. }
  20656. init() {
  20657. this.block = new Block$2({
  20658. compiler: this.compiler,
  20659. name: '@create_main_fragment',
  20660. key: null,
  20661. bindings: new Map(),
  20662. dependencies: new Set(),
  20663. });
  20664. this.compiler.target.blocks.push(this.block);
  20665. this.initChildren(this.block, true, null);
  20666. this.block.hasUpdateMethod = true;
  20667. }
  20668. build() {
  20669. this.init();
  20670. this.children.forEach(child => {
  20671. child.build(this.block, null, 'nodes');
  20672. });
  20673. }
  20674. }
  20675. // this file is auto-generated, do not edit it
  20676. const shared = {
  20677. "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}",
  20678. "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}",
  20679. "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\ttransitionManager.groupOutros();\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}",
  20680. "appendNode": "function appendNode(node, target) {\n\ttarget.appendChild(node);\n}",
  20681. "insertNode": "function insertNode(node, target, anchor) {\n\ttarget.insertBefore(node, anchor);\n}",
  20682. "detachNode": "function detachNode(node) {\n\tnode.parentNode.removeChild(node);\n}",
  20683. "detachBetween": "function detachBetween(before, after) {\n\twhile (before.nextSibling && before.nextSibling !== after) {\n\t\tbefore.parentNode.removeChild(before.nextSibling);\n\t}\n}",
  20684. "detachBefore": "function detachBefore(after) {\n\twhile (after.previousSibling) {\n\t\tafter.parentNode.removeChild(after.previousSibling);\n\t}\n}",
  20685. "detachAfter": "function detachAfter(before) {\n\twhile (before.nextSibling) {\n\t\tbefore.parentNode.removeChild(before.nextSibling);\n\t}\n}",
  20686. "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}",
  20687. "reinsertChildren": "function reinsertChildren(parent, target) {\n\twhile (parent.firstChild) target.appendChild(parent.firstChild);\n}",
  20688. "reinsertAfter": "function reinsertAfter(before, target) {\n\twhile (before.nextSibling) target.appendChild(before.nextSibling);\n}",
  20689. "reinsertBefore": "function reinsertBefore(after, target) {\n\tvar parent = after.parentNode;\n\twhile (parent.firstChild !== after) target.appendChild(parent.firstChild);\n}",
  20690. "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}",
  20691. "createFragment": "function createFragment() {\n\treturn document.createDocumentFragment();\n}",
  20692. "createElement": "function createElement(name) {\n\treturn document.createElement(name);\n}",
  20693. "createSvgElement": "function createSvgElement(name) {\n\treturn document.createElementNS('http://www.w3.org/2000/svg', name);\n}",
  20694. "createText": "function createText(data) {\n\treturn document.createTextNode(data);\n}",
  20695. "createComment": "function createComment() {\n\treturn document.createComment('');\n}",
  20696. "addListener": "function addListener(node, event, handler) {\n\tnode.addEventListener(event, handler, false);\n}",
  20697. "removeListener": "function removeListener(node, event, handler) {\n\tnode.removeEventListener(event, handler, false);\n}",
  20698. "setAttribute": "function setAttribute(node, attribute, value) {\n\tnode.setAttribute(attribute, value);\n}",
  20699. "setAttributes": "function setAttributes(node, attributes) {\n\tfor (var key in attributes) {\n\t\tif (key in node) {\n\t\t\tnode[key] = attributes[key];\n\t\t} else {\n\t\t\tif (attributes[key] === undefined) removeAttribute(node, key);\n\t\t\telse setAttribute(node, key, attributes[key]);\n\t\t}\n\t}\n}",
  20700. "removeAttribute": "function removeAttribute(node, attribute) {\n\tnode.removeAttribute(attribute);\n}",
  20701. "setXlinkAttribute": "function setXlinkAttribute(node, attribute, value) {\n\tnode.setAttributeNS('http://www.w3.org/1999/xlink', attribute, value);\n}",
  20702. "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}",
  20703. "toNumber": "function toNumber(value) {\n\treturn value === '' ? undefined : +value;\n}",
  20704. "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}",
  20705. "children": "function children (element) {\n\treturn Array.from(element.childNodes);\n}",
  20706. "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}",
  20707. "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}",
  20708. "setInputType": "function setInputType(input, type) {\n\ttry {\n\t\tinput.type = type;\n\t} catch (e) {}\n}",
  20709. "setStyle": "function setStyle(node, key, value) {\n\tnode.style.setProperty(key, value);\n}",
  20710. "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}",
  20711. "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}",
  20712. "selectValue": "function selectValue(select) {\n\tvar selectedOption = select.querySelector(':checked') || select.options[0];\n\treturn selectedOption && selectedOption.__value;\n}",
  20713. "selectMultipleValue": "function selectMultipleValue(select) {\n\treturn [].map.call(select.querySelectorAll(':checked'), function(option) {\n\t\treturn option.__value;\n\t});\n}",
  20714. "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.removeEventListener('resize', fn);\n\t\t\telement.removeChild(object);\n\t\t}\n\t};\n}",
  20715. "blankObject": "function blankObject() {\n\treturn Object.create(null);\n}",
  20716. "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}",
  20717. "destroyDev": "function destroyDev(detach) {\n\tdestroy.call(this, detach);\n\tthis.destroy = function() {\n\t\tconsole.warn('Component was already destroyed');\n\t};\n}",
  20718. "_differs": "function _differs(a, b) {\n\treturn a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');\n}",
  20719. "_differsImmutable": "function _differsImmutable(a, b) {\n\treturn a != a ? b == b : a !== b;\n}",
  20720. "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\thandler.__calling = true;\n\t\t\thandler.call(this, data);\n\t\t\thandler.__calling = false;\n\t\t}\n\t}\n}",
  20721. "get": "function get() {\n\treturn this._state;\n}",
  20722. "init": "function init(component, options) {\n\tcomponent._handlers = blankObject();\n\tcomponent._bind = options._bind;\n\n\tcomponent.options = options;\n\tcomponent.root = options.root || component;\n\tcomponent.store = component.root.store || options.store;\n}",
  20723. "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}",
  20724. "run": "function run(fn) {\n\tfn();\n}",
  20725. "set": "function set(newState) {\n\tthis._set(assign({}, newState));\n\tif (this.root._lock) return;\n\tthis.root._lock = true;\n\tcallAll(this.root._beforecreate);\n\tcallAll(this.root._oncreate);\n\tcallAll(this.root._aftercreate);\n\tthis.root._lock = false;\n}",
  20726. "_set": "function _set(newState) {\n\tvar oldState = this._state,\n\t\tchanged = {},\n\t\tdirty = false;\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}",
  20727. "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}",
  20728. "callAll": "function callAll(fns) {\n\twhile (fns && fns.length) fns.shift()();\n}",
  20729. "_mount": "function _mount(target, anchor) {\n\tthis._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);\n}",
  20730. "PENDING": "{}",
  20731. "SUCCESS": "{}",
  20732. "FAILURE": "{}",
  20733. "removeFromStore": "function removeFromStore() {\n\tthis.store._remove(this);\n}",
  20734. "proto": "{\n\tdestroy,\n\tget,\n\tfire,\n\ton,\n\tset,\n\t_recompute: noop,\n\t_set,\n\t_mount,\n\t_differs\n}",
  20735. "protoDev": "{\n\tdestroy: destroyDev,\n\tget,\n\tfire,\n\ton,\n\tset: setDev,\n\t_recompute: noop,\n\t_set,\n\t_mount,\n\t_differs\n}",
  20736. "destroyBlock": "function destroyBlock(block, lookup) {\n\tblock.d(1);\n\tlookup[block.key] = null;\n}",
  20737. "outroAndDestroyBlock": "function outroAndDestroyBlock(block, lookup) {\n\tblock.o(function() {\n\t\tdestroyBlock(block, lookup);\n\t});\n}",
  20738. "fixAndOutroAndDestroyBlock": "function fixAndOutroAndDestroyBlock(block, lookup) {\n\tblock.f();\n\toutroAndDestroyBlock(block, lookup);\n}",
  20739. "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}",
  20740. "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}",
  20741. "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}",
  20742. "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}",
  20743. "spread": "function spread(args) {\n\tconst attributes = Object.assign({}, ...args);\n\tlet str = '';\n\n\tObject.keys(attributes).forEach(name => {\n\t\tconst value = attributes[name];\n\t\tif (value === undefined) return;\n\t\tif (value === true) str += \" \" + name;\n\t\tstr += \" \" + name + \"=\" + JSON.stringify(value);\n\t});\n\n\treturn str;\n}",
  20744. "escaped": "{\n\t'\"': '&quot;',\n\t\"'\": '&#39;',\n\t'&': '&amp;',\n\t'<': '&lt;',\n\t'>': '&gt;'\n}",
  20745. "escape": "function escape(html) {\n\treturn String(html).replace(/[\"'&<>]/g, match => escaped[match]);\n}",
  20746. "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}",
  20747. "missingComponent": "{\n\t_render: () => ''\n}",
  20748. "linear": "function linear(t) {\n\treturn t;\n}",
  20749. "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}",
  20750. "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}",
  20751. "wrapTransition": "function wrapTransition(component, node, fn, params, intro) {\n\tlet obj = fn(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 = transitionManager.outros;\n\t\t\t\ttransitionManager.outros.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(fn => {\n\t\t\t\t\t\tfn();\n\t\t\t\t\t});\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() {\n\t\t\tif (this.program) {\n\t\t\t\tif (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}",
  20752. "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\tgroupOutros() {\n\t\tthis.outros = {\n\t\t\tremaining: 0,\n\t\t\tcallbacks: []\n\t\t};\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}",
  20753. "noop": "function noop() {}",
  20754. "assign": "function assign(tar, src) {\n\tfor (var k in src) tar[k] = src[k];\n\treturn tar;\n}",
  20755. "assignTrue": "function assignTrue(tar, src) {\n\tfor (var k in src) tar[k] = 1;\n\treturn tar;\n}",
  20756. "isPromise": "function isPromise(value) {\n\treturn value && typeof value.then === 'function';\n}",
  20757. "callAfter": "function callAfter(fn, i) {\n\treturn () => {\n\t\tif (!--i) fn();\n\t};\n}"
  20758. };
  20759. function detectIndentation(str) {
  20760. const pattern = /^[\t\s]{1,4}/gm;
  20761. let match;
  20762. while (match = pattern.exec(str)) {
  20763. if (match[0][0] === '\t')
  20764. return '\t';
  20765. if (match[0].length === 2)
  20766. return ' ';
  20767. }
  20768. return ' ';
  20769. }
  20770. function getIndentationLevel(str, b) {
  20771. let a = b;
  20772. while (a > 0 && str[a - 1] !== '\n')
  20773. a -= 1;
  20774. return /^\s*/.exec(str.slice(a, b))[0];
  20775. }
  20776. function getIndentExclusionRanges(node) {
  20777. const ranges = [];
  20778. walk(node, {
  20779. enter(node) {
  20780. if (node.type === 'TemplateElement')
  20781. ranges.push(node);
  20782. }
  20783. });
  20784. return ranges;
  20785. }
  20786. function removeIndentation(code, start, end, indentationLevel, ranges) {
  20787. const str = code.original.slice(start, end);
  20788. const pattern = new RegExp(`^${indentationLevel}`, 'gm');
  20789. let match;
  20790. while (match = pattern.exec(str)) {
  20791. // TODO bail if we're inside an exclusion range
  20792. code.remove(start + match.index, start + match.index + indentationLevel.length);
  20793. }
  20794. }
  20795. // We need to tell estree-walker that it should always
  20796. // look for an `else` block, otherwise it might get
  20797. // the wrong idea about the shape of each/if blocks
  20798. childKeys.EachBlock = childKeys.IfBlock = ['children', 'else'];
  20799. childKeys.Attribute = ['value'];
  20800. class Compiler {
  20801. constructor(ast, source, name, stylesheet, options, stats, dom, target) {
  20802. stats.start('compile');
  20803. this.stats = stats;
  20804. this.ast = ast;
  20805. this.source = source;
  20806. this.options = options;
  20807. this.target = target;
  20808. this.imports = [];
  20809. this.shorthandImports = [];
  20810. this.helpers = new Set();
  20811. this.components = new Set();
  20812. this.events = new Set();
  20813. this.methods = new Set();
  20814. this.animations = new Set();
  20815. this.transitions = new Set();
  20816. this.actions = new Set();
  20817. this.importedComponents = new Map();
  20818. this.slots = new Set();
  20819. this.bindingGroups = [];
  20820. this.indirectDependencies = new Map();
  20821. this.locate = getLocator(this.source);
  20822. // track which properties are needed, so we can provide useful info
  20823. // in dev mode
  20824. this.expectedProperties = new Set();
  20825. this.code = new MagicString(source);
  20826. this.usesRefs = false;
  20827. // styles
  20828. this.stylesheet = stylesheet;
  20829. // allow compiler to deconflict user's `import { get } from 'whatever'` and
  20830. // Svelte's builtin `import { get, ... } from 'svelte/shared.ts'`;
  20831. this.userVars = new Set();
  20832. this.templateVars = new Map();
  20833. this.aliases = new Map();
  20834. this.usedNames = new Set();
  20835. this.computations = [];
  20836. this.templateProperties = {};
  20837. this.walkJs(dom);
  20838. this.name = this.alias(name);
  20839. if (options.customElement === true) {
  20840. this.customElement = {
  20841. tag: this.tag,
  20842. props: this.props
  20843. };
  20844. }
  20845. else {
  20846. this.customElement = options.customElement;
  20847. }
  20848. if (this.customElement && !this.customElement.tag) {
  20849. throw new Error(`No tag name specified`); // TODO better error
  20850. }
  20851. this.fragment = new Fragment(this, ast.html);
  20852. // this.walkTemplate();
  20853. if (!this.customElement)
  20854. this.stylesheet.reify();
  20855. stylesheet.warnOnUnusedSelectors(options.onwarn);
  20856. }
  20857. addSourcemapLocations(node) {
  20858. walk(node, {
  20859. enter: (node) => {
  20860. this.code.addSourcemapLocation(node.start);
  20861. this.code.addSourcemapLocation(node.end);
  20862. },
  20863. });
  20864. }
  20865. alias(name) {
  20866. if (!this.aliases.has(name)) {
  20867. this.aliases.set(name, this.getUniqueName(name));
  20868. }
  20869. return this.aliases.get(name);
  20870. }
  20871. generate(result, options, { banner = '', name, format }) {
  20872. const pattern = /\[✂(\d+)-(\d+)$/;
  20873. const helpers = new Set();
  20874. // TODO use same regex for both
  20875. result = result.replace(options.generate === 'ssr' ? /(@+|#+|%+)(\w*(?:-\w*)?)/g : /(%+|@+)(\w*(?:-\w*)?)/g, (match, sigil, name) => {
  20876. if (sigil === '@') {
  20877. if (name in shared) {
  20878. if (options.dev && `${name}Dev` in shared)
  20879. name = `${name}Dev`;
  20880. helpers.add(name);
  20881. }
  20882. return this.alias(name);
  20883. }
  20884. if (sigil === '%') {
  20885. return this.templateVars.get(name);
  20886. }
  20887. return sigil.slice(1) + name;
  20888. });
  20889. let importedHelpers;
  20890. if (options.shared) {
  20891. if (format !== 'es' && format !== 'cjs') {
  20892. throw new Error(`Components with shared helpers must be compiled with \`format: 'es'\` or \`format: 'cjs'\``);
  20893. }
  20894. importedHelpers = Array.from(helpers).sort().map(name => {
  20895. const alias = this.alias(name);
  20896. return { name, alias };
  20897. });
  20898. }
  20899. else {
  20900. let inlineHelpers = '';
  20901. const compiler = this;
  20902. importedHelpers = [];
  20903. helpers.forEach(name => {
  20904. const str = shared[name];
  20905. const code = new MagicString(str);
  20906. const expression = parseExpressionAt(str, 0);
  20907. let { scope } = annotateWithScopes(expression);
  20908. walk(expression, {
  20909. enter(node, parent) {
  20910. if (node._scope)
  20911. scope = node._scope;
  20912. if (node.type === 'Identifier' &&
  20913. isReference(node, parent) &&
  20914. !scope.has(node.name)) {
  20915. if (node.name in shared) {
  20916. // this helper function depends on another one
  20917. const dependency = node.name;
  20918. helpers.add(dependency);
  20919. const alias = compiler.alias(dependency);
  20920. if (alias !== node.name) {
  20921. code.overwrite(node.start, node.end, alias);
  20922. }
  20923. }
  20924. }
  20925. },
  20926. leave(node) {
  20927. if (node._scope)
  20928. scope = scope.parent;
  20929. },
  20930. });
  20931. if (name === 'transitionManager') {
  20932. // special case
  20933. const global = `_svelteTransitionManager`;
  20934. inlineHelpers += `\n\nvar ${this.alias('transitionManager')} = window.${global} || (window.${global} = ${code});\n\n`;
  20935. }
  20936. else if (name === 'escaped' || name === 'missingComponent') {
  20937. // vars are an awkward special case... would be nice to avoid this
  20938. const alias = this.alias(name);
  20939. inlineHelpers += `\n\nconst ${alias} = ${code};`;
  20940. }
  20941. else {
  20942. const alias = this.alias(expression.id.name);
  20943. if (alias !== expression.id.name) {
  20944. code.overwrite(expression.id.start, expression.id.end, alias);
  20945. }
  20946. inlineHelpers += `\n\n${code}`;
  20947. }
  20948. });
  20949. result += inlineHelpers;
  20950. }
  20951. const sharedPath = options.shared === true
  20952. ? 'svelte/shared.js'
  20953. : options.shared || '';
  20954. const module = wrapModule(result, format, name, options, banner, sharedPath, importedHelpers, this.imports, this.shorthandImports, this.source);
  20955. const parts = module.split('✂]');
  20956. const finalChunk = parts.pop();
  20957. const compiled = new Bundle({ separator: '' });
  20958. function addString(str) {
  20959. compiled.addSource({
  20960. content: new MagicString(str),
  20961. });
  20962. }
  20963. const { filename } = options;
  20964. // special case — the source file doesn't actually get used anywhere. we need
  20965. // to add an empty file to populate map.sources and map.sourcesContent
  20966. if (!parts.length) {
  20967. compiled.addSource({
  20968. filename,
  20969. content: new MagicString(this.source).remove(0, this.source.length),
  20970. });
  20971. }
  20972. parts.forEach((str) => {
  20973. const chunk = str.replace(pattern, '');
  20974. if (chunk)
  20975. addString(chunk);
  20976. const match = pattern.exec(str);
  20977. const snippet = this.code.snip(+match[1], +match[2]);
  20978. compiled.addSource({
  20979. filename,
  20980. content: snippet,
  20981. });
  20982. });
  20983. addString(finalChunk);
  20984. const css = this.customElement ?
  20985. { code: null, map: null } :
  20986. this.stylesheet.render(options.cssOutputFilename, true);
  20987. const js = {
  20988. code: compiled.toString(),
  20989. map: compiled.generateMap({
  20990. includeContent: true,
  20991. file: options.outputFilename,
  20992. })
  20993. };
  20994. this.stats.stop('compile');
  20995. return {
  20996. ast: this.ast,
  20997. js,
  20998. css,
  20999. stats: this.stats.render(this)
  21000. };
  21001. }
  21002. getUniqueName(name) {
  21003. if (test)
  21004. name = `${name}$`;
  21005. let alias = name;
  21006. for (let i = 1; reservedNames.has(alias) ||
  21007. this.userVars.has(alias) ||
  21008. this.usedNames.has(alias); alias = `${name}_${i++}`)
  21009. ;
  21010. this.usedNames.add(alias);
  21011. return alias;
  21012. }
  21013. getUniqueNameMaker() {
  21014. const localUsedNames = new Set();
  21015. function add(name) {
  21016. localUsedNames.add(name);
  21017. }
  21018. reservedNames.forEach(add);
  21019. this.userVars.forEach(add);
  21020. return (name) => {
  21021. if (test)
  21022. name = `${name}$`;
  21023. let alias = name;
  21024. for (let i = 1; this.usedNames.has(alias) ||
  21025. localUsedNames.has(alias); alias = `${name}_${i++}`)
  21026. ;
  21027. localUsedNames.add(alias);
  21028. return alias;
  21029. };
  21030. }
  21031. walkJs(dom) {
  21032. const { code, source, computations, methods, templateProperties, imports } = this;
  21033. const { js } = this.ast;
  21034. const componentDefinition = new CodeBuilder();
  21035. if (js) {
  21036. this.addSourcemapLocations(js.content);
  21037. const indentation = detectIndentation(source.slice(js.start, js.end));
  21038. const indentationLevel = getIndentationLevel(source, js.content.body[0].start);
  21039. const indentExclusionRanges = getIndentExclusionRanges(js.content);
  21040. const { scope, globals } = annotateWithScopes(js.content);
  21041. scope.declarations.forEach(name => {
  21042. this.userVars.add(name);
  21043. });
  21044. globals.forEach(name => {
  21045. this.userVars.add(name);
  21046. });
  21047. const body = js.content.body.slice(); // slice, because we're going to be mutating the original
  21048. // imports need to be hoisted out of the IIFE
  21049. for (let i = 0; i < body.length; i += 1) {
  21050. const node = body[i];
  21051. if (node.type === 'ImportDeclaration') {
  21052. removeNode(code, js.content, node);
  21053. imports.push(node);
  21054. node.specifiers.forEach((specifier) => {
  21055. this.userVars.add(specifier.local.name);
  21056. });
  21057. }
  21058. }
  21059. const defaultExport = this.defaultExport = body.find((node) => node.type === 'ExportDefaultDeclaration');
  21060. if (defaultExport) {
  21061. defaultExport.declaration.properties.forEach((prop) => {
  21062. templateProperties[getMethodName(prop.key)] = prop;
  21063. });
  21064. ['helpers', 'events', 'components', 'transitions', 'actions', 'animations'].forEach(key => {
  21065. if (templateProperties[key]) {
  21066. templateProperties[key].value.properties.forEach((prop) => {
  21067. this[key].add(getMethodName(prop.key));
  21068. });
  21069. }
  21070. });
  21071. const addArrowFunctionExpression = (name, node) => {
  21072. const { body, params, async } = node;
  21073. const fnKeyword = async ? 'async function' : 'function';
  21074. const paramString = params.length ?
  21075. `[✂${params[0].start}-${params[params.length - 1].end}✂]` :
  21076. ``;
  21077. if (body.type === 'BlockStatement') {
  21078. componentDefinition.addBlock(deindent `
  21079. ${fnKeyword} ${name}(${paramString}) [✂${body.start}-${body.end}✂]
  21080. `);
  21081. }
  21082. else {
  21083. componentDefinition.addBlock(deindent `
  21084. ${fnKeyword} ${name}(${paramString}) {
  21085. return [✂${body.start}-${body.end}✂];
  21086. }
  21087. `);
  21088. }
  21089. };
  21090. const addFunctionExpression = (name, node) => {
  21091. const { async } = node;
  21092. const fnKeyword = async ? 'async function' : 'function';
  21093. let c = node.start;
  21094. while (this.source[c] !== '(')
  21095. c += 1;
  21096. componentDefinition.addBlock(deindent `
  21097. ${fnKeyword} ${name}[✂${c}-${node.end}✂];
  21098. `);
  21099. };
  21100. const addValue = (name, node) => {
  21101. componentDefinition.addBlock(deindent `
  21102. var ${name} = [✂${node.start}-${node.end}✂];
  21103. `);
  21104. };
  21105. const addDeclaration = (key, node, allowShorthandImport, disambiguator, conflicts) => {
  21106. const qualified = disambiguator ? `${disambiguator}-${key}` : key;
  21107. if (node.type === 'Identifier' && node.name === key) {
  21108. this.templateVars.set(qualified, key);
  21109. return;
  21110. }
  21111. let deconflicted = key;
  21112. if (conflicts)
  21113. while (deconflicted in conflicts)
  21114. deconflicted += '_';
  21115. let name = this.getUniqueName(deconflicted);
  21116. this.templateVars.set(qualified, name);
  21117. if (allowShorthandImport && node.type === 'Literal' && typeof node.value === 'string') {
  21118. this.shorthandImports.push({ name, source: node.value });
  21119. return;
  21120. }
  21121. // deindent
  21122. const indentationLevel = getIndentationLevel(source, node.start);
  21123. if (indentationLevel) {
  21124. removeIndentation(code, node.start, node.end, indentationLevel, indentExclusionRanges);
  21125. }
  21126. if (node.type === 'ArrowFunctionExpression') {
  21127. addArrowFunctionExpression(name, node);
  21128. }
  21129. else if (node.type === 'FunctionExpression') {
  21130. addFunctionExpression(name, node);
  21131. }
  21132. else {
  21133. addValue(name, node);
  21134. }
  21135. };
  21136. if (templateProperties.components) {
  21137. templateProperties.components.value.properties.forEach((property) => {
  21138. addDeclaration(getMethodName(property.key), property.value, true, 'components');
  21139. });
  21140. }
  21141. if (templateProperties.computed) {
  21142. const dependencies = new Map();
  21143. const fullStateComputations = [];
  21144. templateProperties.computed.value.properties.forEach((prop) => {
  21145. const key = getMethodName(prop.key);
  21146. const value = prop.value;
  21147. addDeclaration(key, value, false, 'computed', {
  21148. state: true,
  21149. changed: true
  21150. });
  21151. const param = value.params[0];
  21152. if (param.type === 'ObjectPattern') {
  21153. const deps = param.properties.map(prop => prop.key.name);
  21154. deps.forEach(dep => {
  21155. this.expectedProperties.add(dep);
  21156. });
  21157. dependencies.set(key, deps);
  21158. }
  21159. else {
  21160. fullStateComputations.push({ key, deps: null });
  21161. }
  21162. });
  21163. const visited = new Set();
  21164. const visit = (key) => {
  21165. if (!dependencies.has(key))
  21166. return; // not a computation
  21167. if (visited.has(key))
  21168. return;
  21169. visited.add(key);
  21170. const deps = dependencies.get(key);
  21171. deps.forEach(visit);
  21172. computations.push({ key, deps });
  21173. const prop = templateProperties.computed.value.properties.find((prop) => getMethodName(prop.key) === key);
  21174. };
  21175. templateProperties.computed.value.properties.forEach((prop) => visit(getMethodName(prop.key)));
  21176. if (fullStateComputations.length > 0) {
  21177. computations.push(...fullStateComputations);
  21178. }
  21179. }
  21180. if (templateProperties.data) {
  21181. addDeclaration('data', templateProperties.data.value);
  21182. }
  21183. if (templateProperties.events && dom) {
  21184. templateProperties.events.value.properties.forEach((property) => {
  21185. addDeclaration(getMethodName(property.key), property.value, false, 'events');
  21186. });
  21187. }
  21188. if (templateProperties.helpers) {
  21189. templateProperties.helpers.value.properties.forEach((property) => {
  21190. addDeclaration(getMethodName(property.key), property.value, false, 'helpers');
  21191. });
  21192. }
  21193. if (templateProperties.methods && dom) {
  21194. addDeclaration('methods', templateProperties.methods.value);
  21195. templateProperties.methods.value.properties.forEach(prop => {
  21196. this.methods.add(prop.key.name);
  21197. });
  21198. }
  21199. if (templateProperties.namespace) {
  21200. const ns = nodeToString(templateProperties.namespace.value);
  21201. this.namespace = namespaces[ns] || ns;
  21202. }
  21203. if (templateProperties.oncreate && dom) {
  21204. addDeclaration('oncreate', templateProperties.oncreate.value);
  21205. }
  21206. if (templateProperties.ondestroy && dom) {
  21207. addDeclaration('ondestroy', templateProperties.ondestroy.value);
  21208. }
  21209. if (templateProperties.onstate && dom) {
  21210. addDeclaration('onstate', templateProperties.onstate.value);
  21211. }
  21212. if (templateProperties.onupdate && dom) {
  21213. addDeclaration('onupdate', templateProperties.onupdate.value);
  21214. }
  21215. if (templateProperties.preload) {
  21216. addDeclaration('preload', templateProperties.preload.value);
  21217. }
  21218. if (templateProperties.props) {
  21219. this.props = templateProperties.props.value.elements.map((element) => nodeToString(element));
  21220. }
  21221. if (templateProperties.setup) {
  21222. addDeclaration('setup', templateProperties.setup.value);
  21223. }
  21224. if (templateProperties.store) {
  21225. addDeclaration('store', templateProperties.store.value);
  21226. }
  21227. if (templateProperties.tag) {
  21228. this.tag = nodeToString(templateProperties.tag.value);
  21229. }
  21230. if (templateProperties.transitions) {
  21231. templateProperties.transitions.value.properties.forEach((property) => {
  21232. addDeclaration(getMethodName(property.key), property.value, false, 'transitions');
  21233. });
  21234. }
  21235. if (templateProperties.animations) {
  21236. templateProperties.animations.value.properties.forEach((property) => {
  21237. addDeclaration(getMethodName(property.key), property.value, false, 'animations');
  21238. });
  21239. }
  21240. if (templateProperties.actions) {
  21241. templateProperties.actions.value.properties.forEach((property) => {
  21242. addDeclaration(getMethodName(property.key), property.value, false, 'actions');
  21243. });
  21244. }
  21245. }
  21246. if (indentationLevel) {
  21247. if (defaultExport) {
  21248. removeIndentation(code, js.content.start, defaultExport.start, indentationLevel, indentExclusionRanges);
  21249. removeIndentation(code, defaultExport.end, js.content.end, indentationLevel, indentExclusionRanges);
  21250. }
  21251. else {
  21252. removeIndentation(code, js.content.start, js.content.end, indentationLevel, indentExclusionRanges);
  21253. }
  21254. }
  21255. let a = js.content.start;
  21256. while (/\s/.test(source[a]))
  21257. a += 1;
  21258. let b = js.content.end;
  21259. while (/\s/.test(source[b - 1]))
  21260. b -= 1;
  21261. if (defaultExport) {
  21262. this.javascript = '';
  21263. if (a !== defaultExport.start)
  21264. this.javascript += `[✂${a}-${defaultExport.start}✂]`;
  21265. if (!componentDefinition.isEmpty())
  21266. this.javascript += componentDefinition;
  21267. if (defaultExport.end !== b)
  21268. this.javascript += `[✂${defaultExport.end}-${b}✂]`;
  21269. }
  21270. else {
  21271. this.javascript = a === b ? null : `[✂${a}-${b}✂]`;
  21272. }
  21273. }
  21274. }
  21275. }
  21276. class DomTarget {
  21277. constructor() {
  21278. this.blocks = [];
  21279. this.readonly = new Set();
  21280. // initial values for e.g. window.innerWidth, if there's a <svelte:window> meta tag
  21281. this.metaBindings = [];
  21282. }
  21283. }
  21284. function dom(ast, source, stylesheet, options, stats) {
  21285. const format = options.format || 'es';
  21286. const target = new DomTarget();
  21287. const compiler = new Compiler(ast, source, options.name || 'SvelteComponent', stylesheet, options, stats, true, target);
  21288. const { computations, name, templateProperties, namespace, } = compiler;
  21289. compiler.fragment.build();
  21290. const { block } = compiler.fragment;
  21291. if (compiler.options.nestedTransitions) {
  21292. block.hasOutroMethod = true;
  21293. }
  21294. // prevent fragment being created twice (#1063)
  21295. if (options.customElement)
  21296. block.builders.create.addLine(`this.c = @noop;`);
  21297. const builder = new CodeBuilder();
  21298. const computationBuilder = new CodeBuilder();
  21299. const computationDeps = new Set();
  21300. if (computations.length) {
  21301. computations.forEach(({ key, deps }) => {
  21302. if (target.readonly.has(key)) {
  21303. // <svelte:window> bindings
  21304. throw new Error(`Cannot have a computed value '${key}' that clashes with a read-only property`);
  21305. }
  21306. target.readonly.add(key);
  21307. if (deps) {
  21308. deps.forEach(dep => {
  21309. computationDeps.add(dep);
  21310. });
  21311. const condition = `${deps.map(dep => `changed.${dep}`).join(' || ')}`;
  21312. const statement = `if (this._differs(state.${key}, (state.${key} = %computed-${key}(state)))) changed.${key} = true;`;
  21313. computationBuilder.addConditional(condition, statement);
  21314. }
  21315. else {
  21316. // computed property depends on entire state object —
  21317. // these must go at the end
  21318. computationBuilder.addLine(`if (this._differs(state.${key}, (state.${key} = %computed-${key}(state)))) changed.${key} = true;`);
  21319. }
  21320. });
  21321. }
  21322. if (compiler.javascript) {
  21323. builder.addBlock(compiler.javascript);
  21324. }
  21325. const css = compiler.stylesheet.render(options.filename, !compiler.customElement);
  21326. const styles = compiler.stylesheet.hasStyles && stringify(options.dev ?
  21327. `${css.code}\n/*# sourceMappingURL=${css.map.toUrl()} */` :
  21328. css.code, { onlyEscapeAtSymbol: true });
  21329. if (styles && compiler.options.css !== false && !compiler.customElement) {
  21330. builder.addBlock(deindent `
  21331. function @add_css() {
  21332. var style = @createElement("style");
  21333. style.id = '${compiler.stylesheet.id}-style';
  21334. style.textContent = ${styles};
  21335. @appendNode(style, document.head);
  21336. }
  21337. `);
  21338. }
  21339. target.blocks.forEach(block => {
  21340. builder.addBlock(block.toString());
  21341. });
  21342. const sharedPath = options.shared === true
  21343. ? 'svelte/shared.js'
  21344. : options.shared || '';
  21345. const proto = sharedPath
  21346. ? `@proto`
  21347. : deindent `
  21348. {
  21349. ${['destroy', 'get', 'fire', 'on', 'set', '_set', '_mount', '_differs']
  21350. .map(n => `${n}: @${n}`)
  21351. .join(',\n')}
  21352. }`;
  21353. const debugName = `<${compiler.customElement ? compiler.tag : name}>`;
  21354. // generate initial state object
  21355. const expectedProperties = Array.from(compiler.expectedProperties);
  21356. const globals = expectedProperties.filter(prop => globalWhitelist.has(prop));
  21357. const storeProps = expectedProperties.filter(prop => prop[0] === '$');
  21358. const initialState = [];
  21359. if (globals.length > 0) {
  21360. initialState.push(`{ ${globals.map(prop => `${prop} : ${prop}`).join(', ')} }`);
  21361. }
  21362. if (storeProps.length > 0) {
  21363. initialState.push(`this.store._init([${storeProps.map(prop => `"${prop.slice(1)}"`)}])`);
  21364. }
  21365. if (templateProperties.data) {
  21366. initialState.push(`%data()`);
  21367. }
  21368. else if (globals.length === 0 && storeProps.length === 0) {
  21369. initialState.push('{}');
  21370. }
  21371. initialState.push(`options.data`);
  21372. const hasInitHooks = !!(templateProperties.oncreate || templateProperties.onstate || templateProperties.onupdate);
  21373. const constructorBody = deindent `
  21374. ${options.dev && `this._debugName = '${debugName}';`}
  21375. ${options.dev && !compiler.customElement &&
  21376. `if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");`}
  21377. @init(this, options);
  21378. ${templateProperties.store && `this.store = %store();`}
  21379. ${compiler.usesRefs && `this.refs = {};`}
  21380. this._state = ${initialState.reduce((state, piece) => `@assign(${state}, ${piece})`)};
  21381. ${storeProps.length > 0 && `this.store._add(this, [${storeProps.map(prop => `"${prop.slice(1)}"`)}]);`}
  21382. ${target.metaBindings}
  21383. ${computations.length && `this._recompute({ ${Array.from(computationDeps).map(dep => `${dep}: 1`).join(', ')} }, this._state);`}
  21384. ${options.dev &&
  21385. Array.from(compiler.expectedProperties).map(prop => {
  21386. if (globalWhitelist.has(prop))
  21387. return;
  21388. if (computations.find(c => c.key === prop))
  21389. return;
  21390. const message = compiler.components.has(prop) ?
  21391. `${debugName} expected to find '${prop}' in \`data\`, but found it in \`components\` instead` :
  21392. `${debugName} was created without expected data property '${prop}'`;
  21393. const conditions = [`!('${prop}' in this._state)`];
  21394. if (compiler.customElement)
  21395. conditions.push(`!('${prop}' in this.attributes)`);
  21396. return `if (${conditions.join(' && ')}) console.warn("${message}");`;
  21397. })}
  21398. ${compiler.bindingGroups.length &&
  21399. `this._bindingGroups = [${Array(compiler.bindingGroups.length).fill('[]').join(', ')}];`}
  21400. this._intro = ${compiler.options.skipIntroByDefault ? '!!options.intro' : 'true'};
  21401. ${templateProperties.onstate && `this._handlers.state = [%onstate];`}
  21402. ${templateProperties.onupdate && `this._handlers.update = [%onupdate];`}
  21403. ${(templateProperties.ondestroy || storeProps.length) && (`this._handlers.destroy = [${[templateProperties.ondestroy && `%ondestroy`, storeProps.length && `@removeFromStore`].filter(Boolean).join(', ')}];`)}
  21404. ${compiler.slots.size && `this._slotted = options.slots || {};`}
  21405. ${compiler.customElement ?
  21406. deindent `
  21407. this.attachShadow({ mode: 'open' });
  21408. ${css.code && `this.shadowRoot.innerHTML = \`<style>${escape(css.code, { onlyEscapeAtSymbol: true }).replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
  21409. ` :
  21410. (compiler.stylesheet.hasStyles && options.css !== false &&
  21411. `if (!document.getElementById("${compiler.stylesheet.id}-style")) @add_css();`)}
  21412. ${(hasInitHooks || compiler.hasComponents || target.hasComplexBindings || target.hasIntroTransitions) && deindent `
  21413. if (!options.root) {
  21414. this._oncreate = [];
  21415. ${(compiler.hasComponents || target.hasComplexBindings) && `this._beforecreate = [];`}
  21416. ${(compiler.hasComponents || target.hasIntroTransitions) && `this._aftercreate = [];`}
  21417. }
  21418. `}
  21419. ${compiler.slots.size && `this.slots = {};`}
  21420. this._fragment = @create_main_fragment(this, this._state);
  21421. ${hasInitHooks && deindent `
  21422. this.root._oncreate.push(() => {
  21423. ${templateProperties.onstate && `%onstate.call(this, { changed: @assignTrue({}, this._state), current: this._state });`}
  21424. ${templateProperties.oncreate && `%oncreate.call(this);`}
  21425. this.fire("update", { changed: @assignTrue({}, this._state), current: this._state });
  21426. });
  21427. `}
  21428. ${compiler.customElement ? deindent `
  21429. this._fragment.c();
  21430. this._fragment.${block.hasIntroMethod ? 'i' : 'm'}(this.shadowRoot, null);
  21431. if (options.target) this._mount(options.target, options.anchor);
  21432. ` : deindent `
  21433. if (options.target) {
  21434. ${compiler.options.hydratable
  21435. ? deindent `
  21436. var nodes = @children(options.target);
  21437. options.hydrate ? this._fragment.l(nodes) : this._fragment.c();
  21438. nodes.forEach(@detachNode);
  21439. ` :
  21440. deindent `
  21441. ${options.dev && `if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the \`hydratable: true\` option");`}
  21442. this._fragment.c();
  21443. `}
  21444. this._mount(options.target, options.anchor);
  21445. ${(compiler.hasComponents || target.hasComplexBindings || hasInitHooks || target.hasIntroTransitions) && deindent `
  21446. ${compiler.hasComponents && `this._lock = true;`}
  21447. ${(compiler.hasComponents || target.hasComplexBindings) && `@callAll(this._beforecreate);`}
  21448. ${(compiler.hasComponents || hasInitHooks) && `@callAll(this._oncreate);`}
  21449. ${(compiler.hasComponents || target.hasIntroTransitions) && `@callAll(this._aftercreate);`}
  21450. ${compiler.hasComponents && `this._lock = false;`}
  21451. `}
  21452. }
  21453. `}
  21454. ${compiler.options.skipIntroByDefault && `this._intro = true;`}
  21455. `;
  21456. if (compiler.customElement) {
  21457. const props = compiler.props || Array.from(compiler.expectedProperties);
  21458. builder.addBlock(deindent `
  21459. class ${name} extends HTMLElement {
  21460. constructor(options = {}) {
  21461. super();
  21462. ${constructorBody}
  21463. }
  21464. static get observedAttributes() {
  21465. return ${JSON.stringify(props)};
  21466. }
  21467. ${props.map(prop => deindent `
  21468. get ${prop}() {
  21469. return this.get().${prop};
  21470. }
  21471. set ${prop}(value) {
  21472. this.set({ ${prop}: value });
  21473. }
  21474. `).join('\n\n')}
  21475. ${compiler.slots.size && deindent `
  21476. connectedCallback() {
  21477. Object.keys(this._slotted).forEach(key => {
  21478. this.appendChild(this._slotted[key]);
  21479. });
  21480. }`}
  21481. attributeChangedCallback(attr, oldValue, newValue) {
  21482. this.set({ [attr]: newValue });
  21483. }
  21484. ${(compiler.hasComponents || target.hasComplexBindings || templateProperties.oncreate || target.hasIntroTransitions) && deindent `
  21485. connectedCallback() {
  21486. ${compiler.hasComponents && `this._lock = true;`}
  21487. ${(compiler.hasComponents || target.hasComplexBindings) && `@callAll(this._beforecreate);`}
  21488. ${(compiler.hasComponents || templateProperties.oncreate) && `@callAll(this._oncreate);`}
  21489. ${(compiler.hasComponents || target.hasIntroTransitions) && `@callAll(this._aftercreate);`}
  21490. ${compiler.hasComponents && `this._lock = false;`}
  21491. }
  21492. `}
  21493. }
  21494. @assign(${name}.prototype, ${proto});
  21495. ${templateProperties.methods && `@assign(${name}.prototype, %methods);`}
  21496. @assign(${name}.prototype, {
  21497. _mount(target, anchor) {
  21498. target.insertBefore(this, anchor);
  21499. }
  21500. });
  21501. customElements.define("${compiler.tag}", ${name});
  21502. `);
  21503. }
  21504. else {
  21505. builder.addBlock(deindent `
  21506. function ${name}(options) {
  21507. ${constructorBody}
  21508. }
  21509. @assign(${name}.prototype, ${proto});
  21510. ${templateProperties.methods && `@assign(${name}.prototype, %methods);`}
  21511. `);
  21512. }
  21513. const immutable = templateProperties.immutable ? templateProperties.immutable.value.value : options.immutable;
  21514. builder.addBlock(deindent `
  21515. ${options.dev && deindent `
  21516. ${name}.prototype._checkReadOnly = function _checkReadOnly(newState) {
  21517. ${Array.from(target.readonly).map(prop => `if ('${prop}' in newState && !this._updatingReadonlyProperty) throw new Error("${debugName}: Cannot set read-only property '${prop}'");`)}
  21518. };
  21519. `}
  21520. ${computations.length ? deindent `
  21521. ${name}.prototype._recompute = function _recompute(changed, state) {
  21522. ${computationBuilder}
  21523. }
  21524. ` : (!sharedPath && `${name}.prototype._recompute = @noop;`)}
  21525. ${templateProperties.setup && `%setup(${name});`}
  21526. ${templateProperties.preload && `${name}.preload = %preload;`}
  21527. ${immutable && `${name}.prototype._differs = @_differsImmutable;`}
  21528. `);
  21529. let result = builder.toString();
  21530. const filename = options.filename && (typeof process !== 'undefined' ? options.filename.replace(process.cwd(), '').replace(/^[\/\\]/, '') : options.filename);
  21531. return compiler.generate(result, options, {
  21532. banner: `/* ${filename ? `${filename} ` : ``}generated by Svelte v${"2.6.5"} */`,
  21533. sharedPath,
  21534. name,
  21535. format,
  21536. });
  21537. }
  21538. class SsrTarget {
  21539. constructor() {
  21540. this.bindings = [];
  21541. this.renderCode = '';
  21542. this.appendTargets = [];
  21543. }
  21544. append(code) {
  21545. if (this.appendTargets.length) {
  21546. const appendTarget = this.appendTargets[this.appendTargets.length - 1];
  21547. const slotName = appendTarget.slotStack[appendTarget.slotStack.length - 1];
  21548. appendTarget.slots[slotName] += code;
  21549. }
  21550. else {
  21551. this.renderCode += code;
  21552. }
  21553. }
  21554. }
  21555. function ssr(ast, source, stylesheet, options, stats) {
  21556. const format = options.format || 'cjs';
  21557. const target = new SsrTarget();
  21558. const compiler = new Compiler(ast, source, options.name || 'SvelteComponent', stylesheet, options, stats, false, target);
  21559. const { computations, name, templateProperties } = compiler;
  21560. // create main render() function
  21561. trim(compiler.fragment.children).forEach((node) => {
  21562. node.ssr();
  21563. });
  21564. const css = compiler.customElement ?
  21565. { code: null, map: null } :
  21566. compiler.stylesheet.render(options.filename, true);
  21567. // generate initial state object
  21568. const expectedProperties = Array.from(compiler.expectedProperties);
  21569. const globals = expectedProperties.filter(prop => globalWhitelist.has(prop));
  21570. const storeProps = expectedProperties.filter(prop => prop[0] === '$');
  21571. const initialState = [];
  21572. if (globals.length > 0) {
  21573. initialState.push(`{ ${globals.map(prop => `${prop} : ${prop}`).join(', ')} }`);
  21574. }
  21575. if (storeProps.length > 0) {
  21576. const initialize = `_init([${storeProps.map(prop => `"${prop.slice(1)}"`)}])`;
  21577. initialState.push(`options.store.${initialize}`);
  21578. }
  21579. if (templateProperties.data) {
  21580. initialState.push(`%data()`);
  21581. }
  21582. else if (globals.length === 0 && storeProps.length === 0) {
  21583. initialState.push('{}');
  21584. }
  21585. initialState.push('ctx');
  21586. // TODO concatenate CSS maps
  21587. const result = deindent `
  21588. ${compiler.javascript}
  21589. var ${name} = {};
  21590. ${options.filename && `${name}.filename = ${stringify(options.filename)}`};
  21591. ${name}.data = function() {
  21592. return ${templateProperties.data ? `%data()` : `{}`};
  21593. };
  21594. ${name}.render = function(state, options = {}) {
  21595. var components = new Set();
  21596. function addComponent(component) {
  21597. components.add(component);
  21598. }
  21599. var result = { head: '', addComponent };
  21600. var html = ${name}._render(result, state, options);
  21601. var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\\n');
  21602. return {
  21603. html,
  21604. head: result.head,
  21605. css: { code: cssCode, map: null },
  21606. toString() {
  21607. return html;
  21608. }
  21609. };
  21610. }
  21611. ${name}._render = function(__result, ctx, options) {
  21612. ${templateProperties.store && `options.store = %store();`}
  21613. __result.addComponent(${name});
  21614. ctx = Object.assign(${initialState.join(', ')});
  21615. ${computations.map(({ key }) => `ctx.${key} = %computed-${key}(ctx);`)}
  21616. ${target.bindings.length &&
  21617. deindent `
  21618. var settled = false;
  21619. var tmp;
  21620. while (!settled) {
  21621. settled = true;
  21622. ${target.bindings.join('\n\n')}
  21623. }
  21624. `}
  21625. return \`${target.renderCode}\`;
  21626. };
  21627. ${name}.css = {
  21628. code: ${css.code ? stringify(css.code) : `''`},
  21629. map: ${css.map ? stringify(css.map.toString()) : 'null'}
  21630. };
  21631. var warned = false;
  21632. ${templateProperties.preload && `${name}.preload = %preload;`}
  21633. `;
  21634. return compiler.generate(result, options, { name, format });
  21635. }
  21636. function trim(nodes) {
  21637. let start = 0;
  21638. for (; start < nodes.length; start += 1) {
  21639. const node = nodes[start];
  21640. if (node.type !== 'Text')
  21641. break;
  21642. node.data = node.data.replace(/^\s+/, '');
  21643. if (node.data)
  21644. break;
  21645. }
  21646. let end = nodes.length;
  21647. for (; end > start; end -= 1) {
  21648. const node = nodes[end - 1];
  21649. if (node.type !== 'Text')
  21650. break;
  21651. node.data = node.data.replace(/\s+$/, '');
  21652. if (node.data)
  21653. break;
  21654. }
  21655. return nodes.slice(start, end);
  21656. }
  21657. const now = (typeof process !== 'undefined' && process.hrtime)
  21658. ? () => {
  21659. const t = process.hrtime();
  21660. return t[0] * 1e3 + t[1] / 1e6;
  21661. }
  21662. : () => self.performance.now();
  21663. function collapseTimings(timings) {
  21664. const result = {};
  21665. timings.forEach(timing => {
  21666. result[timing.label] = Object.assign({
  21667. total: timing.end - timing.start
  21668. }, timing.children && collapseTimings(timing.children));
  21669. });
  21670. return result;
  21671. }
  21672. class Stats {
  21673. constructor({ onwarn }) {
  21674. this.startTime = now();
  21675. this.stack = [];
  21676. this.currentChildren = this.timings = [];
  21677. this.onwarn = onwarn;
  21678. this.warnings = [];
  21679. }
  21680. start(label) {
  21681. const timing = {
  21682. label,
  21683. start: now(),
  21684. end: null,
  21685. children: []
  21686. };
  21687. this.currentChildren.push(timing);
  21688. this.stack.push(timing);
  21689. this.currentTiming = timing;
  21690. this.currentChildren = timing.children;
  21691. }
  21692. stop(label) {
  21693. if (label !== this.currentTiming.label) {
  21694. throw new Error(`Mismatched timing labels`);
  21695. }
  21696. this.currentTiming.end = now();
  21697. this.stack.pop();
  21698. this.currentTiming = this.stack[this.stack.length - 1];
  21699. this.currentChildren = this.currentTiming ? this.currentTiming.children : this.timings;
  21700. }
  21701. render(compiler) {
  21702. const timings = Object.assign({
  21703. total: now() - this.startTime
  21704. }, collapseTimings(this.timings));
  21705. // TODO would be good to have this info even
  21706. // if options.generate is false
  21707. const imports = compiler && compiler.imports.map(node => {
  21708. return {
  21709. source: node.source.value,
  21710. specifiers: node.specifiers.map(specifier => {
  21711. return {
  21712. name: (specifier.type === 'ImportDefaultSpecifier' ? 'default' :
  21713. specifier.type === 'ImportNamespaceSpecifier' ? '*' :
  21714. specifier.imported.name),
  21715. as: specifier.local.name
  21716. };
  21717. })
  21718. };
  21719. });
  21720. const hooks = compiler && {
  21721. oncreate: !!compiler.templateProperties.oncreate,
  21722. ondestroy: !!compiler.templateProperties.ondestroy,
  21723. onstate: !!compiler.templateProperties.onstate,
  21724. onupdate: !!compiler.templateProperties.onupdate
  21725. };
  21726. return {
  21727. timings,
  21728. warnings: this.warnings,
  21729. imports,
  21730. hooks
  21731. };
  21732. }
  21733. warn(warning) {
  21734. this.warnings.push(warning);
  21735. this.onwarn(warning);
  21736. }
  21737. }
  21738. function assign$1(tar, src) {
  21739. for (var k in src) tar[k] = src[k];
  21740. return tar;
  21741. }
  21742. const UNKNOWN = {};
  21743. function gatherPossibleValues(node, set) {
  21744. if (node.type === 'Literal') {
  21745. set.add(node.value);
  21746. }
  21747. else if (node.type === 'ConditionalExpression') {
  21748. gatherPossibleValues(node.consequent, set);
  21749. gatherPossibleValues(node.alternate, set);
  21750. }
  21751. else {
  21752. set.add(UNKNOWN);
  21753. }
  21754. }
  21755. class Selector$2 {
  21756. constructor(node, stylesheet) {
  21757. this.node = node;
  21758. this.stylesheet = stylesheet;
  21759. this.blocks = groupSelectors(node);
  21760. // take trailing :global(...) selectors out of consideration
  21761. let i = this.blocks.length;
  21762. while (i > 0) {
  21763. if (!this.blocks[i - 1].global)
  21764. break;
  21765. i -= 1;
  21766. }
  21767. this.localBlocks = this.blocks.slice(0, i);
  21768. this.used = this.blocks[0].global;
  21769. }
  21770. apply(node, stack) {
  21771. const toEncapsulate = [];
  21772. applySelector(this.localBlocks.slice(), node, stack.slice(), toEncapsulate);
  21773. if (toEncapsulate.length > 0) {
  21774. toEncapsulate.filter((_, i) => i === 0 || i === toEncapsulate.length - 1).forEach(({ node, block }) => {
  21775. this.stylesheet.nodesWithCssClass.add(node);
  21776. block.shouldEncapsulate = true;
  21777. });
  21778. this.used = true;
  21779. }
  21780. }
  21781. minify(code) {
  21782. let c = null;
  21783. this.blocks.forEach((block, i) => {
  21784. if (i > 0) {
  21785. if (block.start - c > 1) {
  21786. code.overwrite(c, block.start, block.combinator.name || ' ');
  21787. }
  21788. }
  21789. c = block.end;
  21790. });
  21791. }
  21792. transform(code, attr) {
  21793. function encapsulateBlock(block) {
  21794. let i = block.selectors.length;
  21795. while (i--) {
  21796. const selector = block.selectors[i];
  21797. if (selector.type === 'PseudoElementSelector' || selector.type === 'PseudoClassSelector')
  21798. continue;
  21799. if (selector.type === 'TypeSelector' && selector.name === '*') {
  21800. code.overwrite(selector.start, selector.end, attr);
  21801. }
  21802. else {
  21803. code.appendLeft(selector.end, attr);
  21804. }
  21805. break;
  21806. }
  21807. i = block.selectors.length;
  21808. while (i--) {
  21809. const selector = block.selectors[i];
  21810. if (selector.type === 'RefSelector') {
  21811. code.overwrite(selector.start, selector.end, `[svelte-ref-${selector.name}]`, {
  21812. contentOnly: true,
  21813. storeName: false
  21814. });
  21815. }
  21816. }
  21817. }
  21818. this.blocks.forEach((block, i) => {
  21819. if (block.global) {
  21820. const selector = block.selectors[0];
  21821. const first = selector.children[0];
  21822. const last = selector.children[selector.children.length - 1];
  21823. code.remove(selector.start, first.start).remove(last.end, selector.end);
  21824. }
  21825. if (block.shouldEncapsulate)
  21826. encapsulateBlock(block);
  21827. });
  21828. }
  21829. validate(validator) {
  21830. this.blocks.forEach((block) => {
  21831. let i = block.selectors.length;
  21832. while (i-- > 1) {
  21833. const selector = block.selectors[i];
  21834. if (selector.type === 'PseudoClassSelector' && selector.name === 'global') {
  21835. validator.error(selector, {
  21836. code: `css-invalid-global`,
  21837. message: `:global(...) must be the first element in a compound selector`
  21838. });
  21839. }
  21840. }
  21841. });
  21842. let start = 0;
  21843. let end = this.blocks.length;
  21844. for (; start < end; start += 1) {
  21845. if (!this.blocks[start].global)
  21846. break;
  21847. }
  21848. for (; end > start; end -= 1) {
  21849. if (!this.blocks[end - 1].global)
  21850. break;
  21851. }
  21852. for (let i = start; i < end; i += 1) {
  21853. if (this.blocks[i].global) {
  21854. validator.error(this.blocks[i].selectors[0], {
  21855. code: `css-invalid-global`,
  21856. message: `:global(...) can be at the start or end of a selector sequence, but not in the middle`
  21857. });
  21858. }
  21859. }
  21860. }
  21861. }
  21862. function applySelector(blocks, node, stack, toEncapsulate) {
  21863. const block = blocks.pop();
  21864. if (!block)
  21865. return false;
  21866. if (!node) {
  21867. return blocks.every(block => block.global);
  21868. }
  21869. let i = block.selectors.length;
  21870. let j = stack.length;
  21871. while (i--) {
  21872. const selector = block.selectors[i];
  21873. if (selector.type === 'PseudoClassSelector' && selector.name === 'global') {
  21874. // TODO shouldn't see this here... maybe we should enforce that :global(...)
  21875. // cannot be sandwiched between non-global selectors?
  21876. return false;
  21877. }
  21878. if (selector.type === 'PseudoClassSelector' || selector.type === 'PseudoElementSelector') {
  21879. continue;
  21880. }
  21881. if (selector.type === 'ClassSelector') {
  21882. if (!attributeMatches(node, 'class', selector.name, '~=', false))
  21883. return false;
  21884. }
  21885. else if (selector.type === 'IdSelector') {
  21886. if (!attributeMatches(node, 'id', selector.name, '=', false))
  21887. return false;
  21888. }
  21889. else if (selector.type === 'AttributeSelector') {
  21890. if (!attributeMatches(node, selector.name.name, selector.value && unquote(selector.value), selector.matcher, selector.flags))
  21891. return false;
  21892. }
  21893. else if (selector.type === 'TypeSelector') {
  21894. // remove toLowerCase() in v2, when uppercase elements will be forbidden
  21895. if (node.name.toLowerCase() !== selector.name.toLowerCase() && selector.name !== '*')
  21896. return false;
  21897. }
  21898. else if (selector.type === 'RefSelector') {
  21899. if (node.ref === selector.name) {
  21900. node._cssRefAttribute = selector.name;
  21901. toEncapsulate.push({ node, block });
  21902. return true;
  21903. }
  21904. return;
  21905. }
  21906. else {
  21907. // bail. TODO figure out what these could be
  21908. toEncapsulate.push({ node, block });
  21909. return true;
  21910. }
  21911. }
  21912. if (block.combinator) {
  21913. if (block.combinator.type === 'WhiteSpace') {
  21914. while (stack.length) {
  21915. if (applySelector(blocks.slice(), stack.pop(), stack, toEncapsulate)) {
  21916. toEncapsulate.push({ node, block });
  21917. return true;
  21918. }
  21919. }
  21920. return false;
  21921. }
  21922. else if (block.combinator.name === '>') {
  21923. if (applySelector(blocks, stack.pop(), stack, toEncapsulate)) {
  21924. toEncapsulate.push({ node, block });
  21925. return true;
  21926. }
  21927. return false;
  21928. }
  21929. // TODO other combinators
  21930. toEncapsulate.push({ node, block });
  21931. return true;
  21932. }
  21933. toEncapsulate.push({ node, block });
  21934. return true;
  21935. }
  21936. const operators = {
  21937. '=': (value, flags) => new RegExp(`^${value}$`, flags),
  21938. '~=': (value, flags) => new RegExp(`\\b${value}\\b`, flags),
  21939. '|=': (value, flags) => new RegExp(`^${value}(-.+)?$`, flags),
  21940. '^=': (value, flags) => new RegExp(`^${value}`, flags),
  21941. '$=': (value, flags) => new RegExp(`${value}$`, flags),
  21942. '*=': (value, flags) => new RegExp(value, flags)
  21943. };
  21944. function attributeMatches(node, name, expectedValue, operator, caseInsensitive) {
  21945. const spread = node.attributes.find(attr => attr.type === 'Spread');
  21946. if (spread)
  21947. return true;
  21948. const attr = node.attributes.find((attr) => attr.name === name);
  21949. if (!attr)
  21950. return false;
  21951. if (attr.isTrue)
  21952. return operator === null;
  21953. if (attr.chunks.length > 1)
  21954. return true;
  21955. if (!expectedValue)
  21956. return true;
  21957. const pattern = operators[operator](expectedValue, caseInsensitive ? 'i' : '');
  21958. const value = attr.chunks[0];
  21959. if (!value)
  21960. return false;
  21961. if (value.type === 'Text')
  21962. return pattern.test(value.data);
  21963. const possibleValues = new Set();
  21964. gatherPossibleValues(value.node, possibleValues);
  21965. if (possibleValues.has(UNKNOWN))
  21966. return true;
  21967. for (const x of Array.from(possibleValues)) { // TypeScript for-of is slightly unlike JS
  21968. if (pattern.test(x))
  21969. return true;
  21970. }
  21971. return false;
  21972. }
  21973. function unquote(value) {
  21974. if (value.type === 'Identifier')
  21975. return value.name;
  21976. const str = value.value;
  21977. if (str[0] === str[str.length - 1] && str[0] === "'" || str[0] === '"') {
  21978. return str.slice(1, str.length - 1);
  21979. }
  21980. return str;
  21981. }
  21982. class Block$3 {
  21983. constructor(combinator) {
  21984. this.combinator = combinator;
  21985. this.global = false;
  21986. this.selectors = [];
  21987. this.start = null;
  21988. this.end = null;
  21989. this.shouldEncapsulate = false;
  21990. }
  21991. add(selector) {
  21992. if (this.selectors.length === 0) {
  21993. this.start = selector.start;
  21994. this.global = selector.type === 'PseudoClassSelector' && selector.name === 'global';
  21995. }
  21996. this.selectors.push(selector);
  21997. this.end = selector.end;
  21998. }
  21999. }
  22000. function groupSelectors(selector) {
  22001. let block = new Block$3(null);
  22002. const blocks = [block];
  22003. selector.children.forEach((child, i) => {
  22004. if (child.type === 'WhiteSpace' || child.type === 'Combinator') {
  22005. block = new Block$3(child);
  22006. blocks.push(block);
  22007. }
  22008. else {
  22009. block.add(child);
  22010. }
  22011. });
  22012. return blocks;
  22013. }
  22014. // https://github.com/darkskyapp/string-hash/blob/master/index.js
  22015. function hash$1(str) {
  22016. let hash = 5381;
  22017. let i = str.length;
  22018. while (i--)
  22019. hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
  22020. return (hash >>> 0).toString(36);
  22021. }
  22022. class Rule$2 {
  22023. constructor(node, stylesheet, parent) {
  22024. this.node = node;
  22025. this.parent = parent;
  22026. this.selectors = node.selector.children.map((node) => new Selector$2(node, stylesheet));
  22027. this.declarations = node.block.children.map((node) => new Declaration$2(node));
  22028. }
  22029. apply(node, stack) {
  22030. this.selectors.forEach(selector => selector.apply(node, stack)); // TODO move the logic in here?
  22031. }
  22032. isUsed(dev) {
  22033. if (this.parent && this.parent.node.type === 'Atrule' && this.parent.node.name === 'keyframes')
  22034. return true;
  22035. if (this.declarations.length === 0)
  22036. return dev;
  22037. return this.selectors.some(s => s.used);
  22038. }
  22039. minify(code, dev) {
  22040. let c = this.node.start;
  22041. let started = false;
  22042. this.selectors.forEach((selector, i) => {
  22043. if (selector.used) {
  22044. const separator = started ? ',' : '';
  22045. if ((selector.node.start - c) > separator.length) {
  22046. code.overwrite(c, selector.node.start, separator);
  22047. }
  22048. selector.minify(code);
  22049. c = selector.node.end;
  22050. started = true;
  22051. }
  22052. });
  22053. code.remove(c, this.node.block.start);
  22054. c = this.node.block.start + 1;
  22055. this.declarations.forEach((declaration, i) => {
  22056. const separator = i > 0 ? ';' : '';
  22057. if ((declaration.node.start - c) > separator.length) {
  22058. code.overwrite(c, declaration.node.start, separator);
  22059. }
  22060. declaration.minify(code);
  22061. c = declaration.node.end;
  22062. });
  22063. code.remove(c, this.node.block.end - 1);
  22064. }
  22065. transform(code, id, keyframes) {
  22066. if (this.parent && this.parent.node.type === 'Atrule' && this.parent.node.name === 'keyframes')
  22067. return true;
  22068. const attr = `.${id}`;
  22069. this.selectors.forEach(selector => selector.transform(code, attr));
  22070. this.declarations.forEach(declaration => declaration.transform(code, keyframes));
  22071. }
  22072. validate(validator) {
  22073. this.selectors.forEach(selector => {
  22074. selector.validate(validator);
  22075. });
  22076. }
  22077. warnOnUnusedSelector(handler) {
  22078. this.selectors.forEach(selector => {
  22079. if (!selector.used)
  22080. handler(selector);
  22081. });
  22082. }
  22083. }
  22084. class Declaration$2 {
  22085. constructor(node) {
  22086. this.node = node;
  22087. }
  22088. transform(code, keyframes) {
  22089. const property = this.node.property && this.node.property.toLowerCase();
  22090. if (property === 'animation' || property === 'animation-name') {
  22091. this.node.value.children.forEach((block) => {
  22092. if (block.type === 'Identifier') {
  22093. const name = block.name;
  22094. if (keyframes.has(name)) {
  22095. code.overwrite(block.start, block.end, keyframes.get(name));
  22096. }
  22097. }
  22098. });
  22099. }
  22100. }
  22101. minify(code) {
  22102. if (!this.node.property)
  22103. return; // @apply, and possibly other weird cases?
  22104. const c = this.node.start + this.node.property.length;
  22105. const first = this.node.value.children ?
  22106. this.node.value.children[0] :
  22107. this.node.value;
  22108. let start = first.start;
  22109. while (/\s/.test(code.original[start]))
  22110. start += 1;
  22111. if (start - c > 1) {
  22112. code.overwrite(c, start, ':');
  22113. }
  22114. }
  22115. }
  22116. class Atrule$2 {
  22117. constructor(node) {
  22118. this.node = node;
  22119. this.children = [];
  22120. }
  22121. apply(node, stack) {
  22122. if (this.node.name === 'media' || this.node.name === 'supports') {
  22123. this.children.forEach(child => {
  22124. child.apply(node, stack);
  22125. });
  22126. }
  22127. else if (this.node.name === 'keyframes') {
  22128. this.children.forEach((rule) => {
  22129. rule.selectors.forEach(selector => {
  22130. selector.used = true;
  22131. });
  22132. });
  22133. }
  22134. }
  22135. isUsed(dev) {
  22136. return true; // TODO
  22137. }
  22138. minify(code, dev) {
  22139. if (this.node.name === 'media') {
  22140. const expressionChar = code.original[this.node.expression.start];
  22141. let c = this.node.start + (expressionChar === '(' ? 6 : 7);
  22142. if (this.node.expression.start > c)
  22143. code.remove(c, this.node.expression.start);
  22144. this.node.expression.children.forEach((query) => {
  22145. // TODO minify queries
  22146. c = query.end;
  22147. });
  22148. code.remove(c, this.node.block.start);
  22149. }
  22150. else if (this.node.name === 'keyframes') {
  22151. let c = this.node.start + 10;
  22152. if (this.node.expression.start - c > 1)
  22153. code.overwrite(c, this.node.expression.start, ' ');
  22154. c = this.node.expression.end;
  22155. if (this.node.block.start - c > 0)
  22156. code.remove(c, this.node.block.start);
  22157. }
  22158. else if (this.node.name === 'supports') {
  22159. let c = this.node.start + 9;
  22160. if (this.node.expression.start - c > 1)
  22161. code.overwrite(c, this.node.expression.start, ' ');
  22162. this.node.expression.children.forEach((query) => {
  22163. // TODO minify queries
  22164. c = query.end;
  22165. });
  22166. code.remove(c, this.node.block.start);
  22167. }
  22168. // TODO other atrules
  22169. if (this.node.block) {
  22170. let c = this.node.block.start + 1;
  22171. this.children.forEach(child => {
  22172. if (child.isUsed(dev)) {
  22173. code.remove(c, child.node.start);
  22174. child.minify(code, dev);
  22175. c = child.node.end;
  22176. }
  22177. });
  22178. code.remove(c, this.node.block.end - 1);
  22179. }
  22180. }
  22181. transform(code, id, keyframes) {
  22182. if (this.node.name === 'keyframes') {
  22183. this.node.expression.children.forEach(({ type, name, start, end }) => {
  22184. if (type === 'Identifier') {
  22185. if (name.startsWith('-global-')) {
  22186. code.remove(start, start + 8);
  22187. }
  22188. else {
  22189. code.overwrite(start, end, keyframes.get(name));
  22190. }
  22191. }
  22192. });
  22193. }
  22194. this.children.forEach(child => {
  22195. child.transform(code, id, keyframes);
  22196. });
  22197. }
  22198. validate(validator) {
  22199. this.children.forEach(child => {
  22200. child.validate(validator);
  22201. });
  22202. }
  22203. warnOnUnusedSelector(handler) {
  22204. if (this.node.name !== 'media')
  22205. return;
  22206. this.children.forEach(child => {
  22207. child.warnOnUnusedSelector(handler);
  22208. });
  22209. }
  22210. }
  22211. class Stylesheet {
  22212. constructor(source, ast, filename, dev) {
  22213. this.source = source;
  22214. this.ast = ast;
  22215. this.filename = filename;
  22216. this.dev = dev;
  22217. this.children = [];
  22218. this.keyframes = new Map();
  22219. this.nodesWithCssClass = new Set();
  22220. if (ast.css && ast.css.children.length) {
  22221. this.id = `svelte-${hash$1(ast.css.content.styles)}`;
  22222. this.hasStyles = true;
  22223. const stack = [];
  22224. let currentAtrule = null;
  22225. walk(this.ast.css, {
  22226. enter: (node) => {
  22227. if (node.type === 'Atrule') {
  22228. const last = stack[stack.length - 1];
  22229. const atrule = new Atrule$2(node);
  22230. stack.push(atrule);
  22231. // this is an awkward special case — @apply (and
  22232. // possibly other future constructs)
  22233. if (last && !(last instanceof Atrule$2))
  22234. return;
  22235. if (currentAtrule) {
  22236. currentAtrule.children.push(atrule);
  22237. }
  22238. else {
  22239. this.children.push(atrule);
  22240. }
  22241. if (node.name === 'keyframes') {
  22242. node.expression.children.forEach((expression) => {
  22243. if (expression.type === 'Identifier' && !expression.name.startsWith('-global-')) {
  22244. this.keyframes.set(expression.name, `${this.id}-${expression.name}`);
  22245. }
  22246. });
  22247. }
  22248. currentAtrule = atrule;
  22249. }
  22250. if (node.type === 'Rule') {
  22251. const rule = new Rule$2(node, this, currentAtrule);
  22252. stack.push(rule);
  22253. if (currentAtrule) {
  22254. currentAtrule.children.push(rule);
  22255. }
  22256. else {
  22257. this.children.push(rule);
  22258. }
  22259. }
  22260. },
  22261. leave: (node) => {
  22262. if (node.type === 'Rule' || node.type === 'Atrule')
  22263. stack.pop();
  22264. if (node.type === 'Atrule')
  22265. currentAtrule = stack[stack.length - 1];
  22266. }
  22267. });
  22268. }
  22269. else {
  22270. this.hasStyles = false;
  22271. }
  22272. }
  22273. apply(node) {
  22274. if (!this.hasStyles)
  22275. return;
  22276. const stack = [];
  22277. let parent = node;
  22278. while (parent = parent.parent) {
  22279. if (parent.type === 'Element')
  22280. stack.unshift(parent);
  22281. }
  22282. for (let i = 0; i < this.children.length; i += 1) {
  22283. const child = this.children[i];
  22284. child.apply(node, stack);
  22285. }
  22286. }
  22287. reify() {
  22288. this.nodesWithCssClass.forEach((node) => {
  22289. node.addCssClass();
  22290. });
  22291. }
  22292. render(cssOutputFilename, shouldTransformSelectors) {
  22293. if (!this.hasStyles) {
  22294. return { code: null, map: null };
  22295. }
  22296. const code = new MagicString(this.source);
  22297. walk(this.ast.css, {
  22298. enter: (node) => {
  22299. code.addSourcemapLocation(node.start);
  22300. code.addSourcemapLocation(node.end);
  22301. }
  22302. });
  22303. if (shouldTransformSelectors) {
  22304. this.children.forEach((child) => {
  22305. child.transform(code, this.id, this.keyframes);
  22306. });
  22307. }
  22308. let c = 0;
  22309. this.children.forEach(child => {
  22310. if (child.isUsed(this.dev)) {
  22311. code.remove(c, child.node.start);
  22312. child.minify(code, this.dev);
  22313. c = child.node.end;
  22314. }
  22315. });
  22316. code.remove(c, this.source.length);
  22317. return {
  22318. code: code.toString(),
  22319. map: code.generateMap({
  22320. includeContent: true,
  22321. source: this.filename,
  22322. file: cssOutputFilename
  22323. })
  22324. };
  22325. }
  22326. validate(validator) {
  22327. this.children.forEach(child => {
  22328. child.validate(validator);
  22329. });
  22330. }
  22331. warnOnUnusedSelectors(onwarn) {
  22332. let locator;
  22333. const handler = (selector) => {
  22334. const pos = selector.node.start;
  22335. if (!locator)
  22336. locator = getLocator(this.source, { offsetLine: 1 });
  22337. const start = locator(pos);
  22338. const end = locator(selector.node.end);
  22339. const frame = getCodeFrame(this.source, start.line - 1, start.column);
  22340. const message = `Unused CSS selector`;
  22341. onwarn({
  22342. code: `css-unused-selector`,
  22343. message,
  22344. frame,
  22345. start,
  22346. end,
  22347. pos,
  22348. filename: this.filename,
  22349. toString: () => `${message} (${start.line}:${start.column})\n${frame}`,
  22350. });
  22351. };
  22352. this.children.forEach(child => {
  22353. child.warnOnUnusedSelector(handler);
  22354. });
  22355. }
  22356. }
  22357. const version$1 = '2.6.5';
  22358. function normalizeOptions(options) {
  22359. let normalizedOptions = assign$1({ generate: 'dom' }, options);
  22360. const { onwarn, onerror } = normalizedOptions;
  22361. normalizedOptions.onwarn = onwarn
  22362. ? (warning) => onwarn(warning, defaultOnwarn)
  22363. : defaultOnwarn;
  22364. normalizedOptions.onerror = onerror
  22365. ? (error) => onerror(error, defaultOnerror)
  22366. : defaultOnerror;
  22367. return normalizedOptions;
  22368. }
  22369. function defaultOnwarn(warning) {
  22370. if (warning.start) {
  22371. console.warn(`(${warning.start.line}:${warning.start.column}) – ${warning.message}`); // eslint-disable-line no-console
  22372. }
  22373. else {
  22374. console.warn(warning.message); // eslint-disable-line no-console
  22375. }
  22376. }
  22377. function defaultOnerror(error) {
  22378. throw error;
  22379. }
  22380. function parseAttributeValue(value) {
  22381. return /^['"]/.test(value) ?
  22382. value.slice(1, -1) :
  22383. value;
  22384. }
  22385. function parseAttributes(str) {
  22386. const attrs = {};
  22387. str.split(/\s+/).filter(Boolean).forEach(attr => {
  22388. const [name, value] = attr.split('=');
  22389. attrs[name] = value ? parseAttributeValue(value) : true;
  22390. });
  22391. return attrs;
  22392. }
  22393. function replaceTagContents(source, type, preprocessor, options) {
  22394. return __awaiter(this, void 0, void 0, function* () {
  22395. const exp = new RegExp(`<${type}([\\S\\s]*?)>([\\S\\s]*?)<\\/${type}>`, 'ig');
  22396. const match = exp.exec(source);
  22397. if (match) {
  22398. const attributes = parseAttributes(match[1]);
  22399. const content = match[2];
  22400. const processed = yield preprocessor({
  22401. content,
  22402. attributes,
  22403. filename: options.filename
  22404. });
  22405. if (processed && processed.code) {
  22406. return (source.slice(0, match.index) +
  22407. `<${type}>${processed.code}</${type}>` +
  22408. source.slice(match.index + match[0].length));
  22409. }
  22410. }
  22411. return source;
  22412. });
  22413. }
  22414. function preprocess(source, options) {
  22415. return __awaiter(this, void 0, void 0, function* () {
  22416. const { markup, style, script } = options;
  22417. if (!!markup) {
  22418. const processed = yield markup({
  22419. content: source,
  22420. filename: options.filename
  22421. });
  22422. source = processed.code;
  22423. }
  22424. if (!!style) {
  22425. source = yield replaceTagContents(source, 'style', style, options);
  22426. }
  22427. if (!!script) {
  22428. source = yield replaceTagContents(source, 'script', script, options);
  22429. }
  22430. return {
  22431. // TODO return separated output, in future version where svelte.compile supports it:
  22432. // style: { code: styleCode, map: styleMap },
  22433. // script { code: scriptCode, map: scriptMap },
  22434. // markup { code: markupCode, map: markupMap },
  22435. toString() {
  22436. return source;
  22437. }
  22438. };
  22439. });
  22440. }
  22441. function compile(source, _options) {
  22442. const options = normalizeOptions(_options);
  22443. let ast;
  22444. const stats = new Stats({
  22445. onwarn: options.onwarn
  22446. });
  22447. try {
  22448. stats.start('parse');
  22449. ast = parse$1(source, options);
  22450. stats.stop('parse');
  22451. }
  22452. catch (err) {
  22453. options.onerror(err);
  22454. return;
  22455. }
  22456. stats.start('stylesheet');
  22457. const stylesheet = new Stylesheet(source, ast, options.filename, options.dev);
  22458. stats.stop('stylesheet');
  22459. stats.start('validate');
  22460. validate(ast, source, stylesheet, stats, options);
  22461. stats.stop('validate');
  22462. if (options.generate === false) {
  22463. return { ast, stats: stats.render(null), js: null, css: null };
  22464. }
  22465. const compiler = options.generate === 'ssr' ? ssr : dom;
  22466. return compiler(ast, source, stylesheet, options, stats);
  22467. }
  22468. function create$2(source, _options = {}) {
  22469. _options.format = 'eval';
  22470. const compiled = compile(source, _options);
  22471. if (!compiled || !compiled.js.code) {
  22472. return;
  22473. }
  22474. try {
  22475. return (new Function(`return ${compiled.js.code}`))();
  22476. }
  22477. catch (err) {
  22478. if (_options.onerror) {
  22479. _options.onerror(err);
  22480. return;
  22481. }
  22482. else {
  22483. throw err;
  22484. }
  22485. }
  22486. }
  22487. exports.preprocess = preprocess;
  22488. exports.parse = parse$1;
  22489. exports.create = create$2;
  22490. exports.compile = compile;
  22491. exports.VERSION = version$1;
  22492. Object.defineProperty(exports, '__esModule', { value: true });
  22493. })));
  22494. //# sourceMappingURL=svelte.js.map