compiler-sfc.esm-browser.js 1.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309
  1. function makeMap(str, expectsLowerCase) {
  2. const map = /* @__PURE__ */ Object.create(null);
  3. const list = str.split(",");
  4. for (let i = 0; i < list.length; i++) {
  5. map[list[i]] = true;
  6. }
  7. return expectsLowerCase ? (val) => !!map[val.toLowerCase()] : (val) => !!map[val];
  8. }
  9. const EMPTY_OBJ = Object.freeze({}) ;
  10. const NOOP = () => {
  11. };
  12. const NO = () => false;
  13. const onRE = /^on[^a-z]/;
  14. const isOn = (key) => onRE.test(key);
  15. const extend = Object.assign;
  16. const hasOwnProperty$3 = Object.prototype.hasOwnProperty;
  17. const hasOwn = (val, key) => hasOwnProperty$3.call(val, key);
  18. const isArray$3 = Array.isArray;
  19. const isMap = (val) => toTypeString(val) === "[object Map]";
  20. const isSet = (val) => toTypeString(val) === "[object Set]";
  21. const isFunction$1 = (val) => typeof val === "function";
  22. const isString$2 = (val) => typeof val === "string";
  23. const isSymbol$1 = (val) => typeof val === "symbol";
  24. const isObject$2 = (val) => val !== null && typeof val === "object";
  25. const objectToString$1 = Object.prototype.toString;
  26. const toTypeString = (value) => objectToString$1.call(value);
  27. const isPlainObject = (val) => toTypeString(val) === "[object Object]";
  28. const isReservedProp = /* @__PURE__ */ makeMap(
  29. // the leading comma is intentional so empty string "" is also included
  30. ",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"
  31. );
  32. const isBuiltInDirective = /* @__PURE__ */ makeMap(
  33. "bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"
  34. );
  35. const cacheStringFunction = (fn) => {
  36. const cache = /* @__PURE__ */ Object.create(null);
  37. return (str) => {
  38. const hit = cache[str];
  39. return hit || (cache[str] = fn(str));
  40. };
  41. };
  42. const camelizeRE = /-(\w)/g;
  43. const camelize = cacheStringFunction((str) => {
  44. return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
  45. });
  46. const hyphenateRE = /\B([A-Z])/g;
  47. const hyphenate = cacheStringFunction(
  48. (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
  49. );
  50. const capitalize$1 = cacheStringFunction(
  51. (str) => str.charAt(0).toUpperCase() + str.slice(1)
  52. );
  53. const toHandlerKey = cacheStringFunction(
  54. (str) => str ? `on${capitalize$1(str)}` : ``
  55. );
  56. const identRE = /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/;
  57. function genPropsAccessExp(name) {
  58. return identRE.test(name) ? `__props.${name}` : `__props[${JSON.stringify(name)}]`;
  59. }
  60. const PatchFlagNames = {
  61. [1]: `TEXT`,
  62. [2]: `CLASS`,
  63. [4]: `STYLE`,
  64. [8]: `PROPS`,
  65. [16]: `FULL_PROPS`,
  66. [32]: `HYDRATE_EVENTS`,
  67. [64]: `STABLE_FRAGMENT`,
  68. [128]: `KEYED_FRAGMENT`,
  69. [256]: `UNKEYED_FRAGMENT`,
  70. [512]: `NEED_PATCH`,
  71. [1024]: `DYNAMIC_SLOTS`,
  72. [2048]: `DEV_ROOT_FRAGMENT`,
  73. [-1]: `HOISTED`,
  74. [-2]: `BAIL`
  75. };
  76. const slotFlagsText = {
  77. [1]: "STABLE",
  78. [2]: "DYNAMIC",
  79. [3]: "FORWARDED"
  80. };
  81. const GLOBALS_WHITE_LISTED = "Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console";
  82. const isGloballyWhitelisted = /* @__PURE__ */ makeMap(GLOBALS_WHITE_LISTED);
  83. const range = 2;
  84. function generateCodeFrame(source, start = 0, end = source.length) {
  85. let lines = source.split(/(\r?\n)/);
  86. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  87. lines = lines.filter((_, idx) => idx % 2 === 0);
  88. let count = 0;
  89. const res = [];
  90. for (let i = 0; i < lines.length; i++) {
  91. count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
  92. if (count >= start) {
  93. for (let j = i - range; j <= i + range || end > count; j++) {
  94. if (j < 0 || j >= lines.length)
  95. continue;
  96. const line = j + 1;
  97. res.push(
  98. `${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
  99. );
  100. const lineLength = lines[j].length;
  101. const newLineSeqLength = newlineSequences[j] && newlineSequences[j].length || 0;
  102. if (j === i) {
  103. const pad = start - (count - (lineLength + newLineSeqLength));
  104. const length = Math.max(
  105. 1,
  106. end > count ? lineLength - pad : end - start
  107. );
  108. res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
  109. } else if (j > i) {
  110. if (end > count) {
  111. const length = Math.max(Math.min(end - count, lineLength), 1);
  112. res.push(` | ` + "^".repeat(length));
  113. }
  114. count += lineLength + newLineSeqLength;
  115. }
  116. }
  117. break;
  118. }
  119. }
  120. return res.join("\n");
  121. }
  122. function normalizeStyle(value) {
  123. if (isArray$3(value)) {
  124. const res = {};
  125. for (let i = 0; i < value.length; i++) {
  126. const item = value[i];
  127. const normalized = isString$2(item) ? parseStringStyle(item) : normalizeStyle(item);
  128. if (normalized) {
  129. for (const key in normalized) {
  130. res[key] = normalized[key];
  131. }
  132. }
  133. }
  134. return res;
  135. } else if (isString$2(value)) {
  136. return value;
  137. } else if (isObject$2(value)) {
  138. return value;
  139. }
  140. }
  141. const listDelimiterRE = /;(?![^(]*\))/g;
  142. const propertyDelimiterRE = /:([^]+)/;
  143. const styleCommentRE = /\/\*[^]*?\*\//g;
  144. function parseStringStyle(cssText) {
  145. const ret = {};
  146. cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
  147. if (item) {
  148. const tmp = item.split(propertyDelimiterRE);
  149. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  150. }
  151. });
  152. return ret;
  153. }
  154. function stringifyStyle(styles) {
  155. let ret = "";
  156. if (!styles || isString$2(styles)) {
  157. return ret;
  158. }
  159. for (const key in styles) {
  160. const value = styles[key];
  161. const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
  162. if (isString$2(value) || typeof value === "number") {
  163. ret += `${normalizedKey}:${value};`;
  164. }
  165. }
  166. return ret;
  167. }
  168. function normalizeClass(value) {
  169. let res = "";
  170. if (isString$2(value)) {
  171. res = value;
  172. } else if (isArray$3(value)) {
  173. for (let i = 0; i < value.length; i++) {
  174. const normalized = normalizeClass(value[i]);
  175. if (normalized) {
  176. res += normalized + " ";
  177. }
  178. }
  179. } else if (isObject$2(value)) {
  180. for (const name in value) {
  181. if (value[name]) {
  182. res += name + " ";
  183. }
  184. }
  185. }
  186. return res.trim();
  187. }
  188. const HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot";
  189. const SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,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,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
  190. const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
  191. const isHTMLTag = /* @__PURE__ */ makeMap(HTML_TAGS);
  192. const isSVGTag = /* @__PURE__ */ makeMap(SVG_TAGS);
  193. const isVoidTag = /* @__PURE__ */ makeMap(VOID_TAGS);
  194. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  195. const isBooleanAttr = /* @__PURE__ */ makeMap(
  196. specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`
  197. );
  198. const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/;
  199. const attrValidationCache = {};
  200. function isSSRSafeAttrName(name) {
  201. if (attrValidationCache.hasOwnProperty(name)) {
  202. return attrValidationCache[name];
  203. }
  204. const isUnsafe = unsafeAttrCharRE.test(name);
  205. if (isUnsafe) {
  206. console.error(`unsafe attribute name: ${name}`);
  207. }
  208. return attrValidationCache[name] = !isUnsafe;
  209. }
  210. const propsToAttrMap = {
  211. acceptCharset: "accept-charset",
  212. className: "class",
  213. htmlFor: "for",
  214. httpEquiv: "http-equiv"
  215. };
  216. const isKnownHtmlAttr = /* @__PURE__ */ makeMap(
  217. `accept,accept-charset,accesskey,action,align,allow,alt,async,autocapitalize,autocomplete,autofocus,autoplay,background,bgcolor,border,buffered,capture,challenge,charset,checked,cite,class,code,codebase,color,cols,colspan,content,contenteditable,contextmenu,controls,coords,crossorigin,csp,data,datetime,decoding,default,defer,dir,dirname,disabled,download,draggable,dropzone,enctype,enterkeyhint,for,form,formaction,formenctype,formmethod,formnovalidate,formtarget,headers,height,hidden,high,href,hreflang,http-equiv,icon,id,importance,inert,integrity,ismap,itemprop,keytype,kind,label,lang,language,loading,list,loop,low,manifest,max,maxlength,minlength,media,min,multiple,muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,preload,radiogroup,readonly,referrerpolicy,rel,required,reversed,rows,rowspan,sandbox,scope,scoped,selected,shape,size,sizes,slot,span,spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,target,title,translate,type,usemap,value,width,wrap`
  218. );
  219. const isKnownSvgAttr = /* @__PURE__ */ makeMap(
  220. `xmlns,accent-height,accumulate,additive,alignment-baseline,alphabetic,amplitude,arabic-form,ascent,attributeName,attributeType,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,crossorigin,cursor,cx,cy,d,decelerate,descent,diffuseConstant,direction,display,divisor,dominant-baseline,dur,dx,dy,edgeMode,elevation,enable-background,end,exponent,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,hreflang,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,opacity,operator,order,orient,orientation,origin,overflow,overline-position,overline-thickness,panose-1,paint-order,path,pathLength,patternContentUnits,patternTransform,patternUnits,ping,pointer-events,points,pointsAtX,pointsAtY,pointsAtZ,preserveAlpha,preserveAspectRatio,primitiveUnits,r,radius,referrerPolicy,refX,refY,rel,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,transform-origin,type,u1,u2,underline-position,underline-thickness,unicode,unicode-bidi,unicode-range,units-per-em,v-alphabetic,v-hanging,v-ideographic,v-mathematical,values,vector-effect,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`
  221. );
  222. const escapeRE = /["'&<>]/;
  223. function escapeHtml(string) {
  224. const str = "" + string;
  225. const match = escapeRE.exec(str);
  226. if (!match) {
  227. return str;
  228. }
  229. let html = "";
  230. let escaped;
  231. let index;
  232. let lastIndex = 0;
  233. for (index = match.index; index < str.length; index++) {
  234. switch (str.charCodeAt(index)) {
  235. case 34:
  236. escaped = "&quot;";
  237. break;
  238. case 38:
  239. escaped = "&amp;";
  240. break;
  241. case 39:
  242. escaped = "&#39;";
  243. break;
  244. case 60:
  245. escaped = "&lt;";
  246. break;
  247. case 62:
  248. escaped = "&gt;";
  249. break;
  250. default:
  251. continue;
  252. }
  253. if (lastIndex !== index) {
  254. html += str.slice(lastIndex, index);
  255. }
  256. lastIndex = index + 1;
  257. html += escaped;
  258. }
  259. return lastIndex !== index ? html + str.slice(lastIndex, index) : html;
  260. }
  261. const toDisplayString = (val) => {
  262. return isString$2(val) ? val : val == null ? "" : isArray$3(val) || isObject$2(val) && (val.toString === objectToString$1 || !isFunction$1(val.toString)) ? JSON.stringify(val, replacer, 2) : String(val);
  263. };
  264. const replacer = (_key, val) => {
  265. if (val && val.__v_isRef) {
  266. return replacer(_key, val.value);
  267. } else if (isMap(val)) {
  268. return {
  269. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val2]) => {
  270. entries[`${key} =>`] = val2;
  271. return entries;
  272. }, {})
  273. };
  274. } else if (isSet(val)) {
  275. return {
  276. [`Set(${val.size})`]: [...val.values()]
  277. };
  278. } else if (isObject$2(val) && !isArray$3(val) && !isPlainObject(val)) {
  279. return String(val);
  280. }
  281. return val;
  282. };
  283. function defaultOnError(error) {
  284. throw error;
  285. }
  286. function defaultOnWarn(msg) {
  287. console.warn(`[Vue warn] ${msg.message}`);
  288. }
  289. function createCompilerError(code, loc, messages, additionalMessage) {
  290. const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
  291. const error = new SyntaxError(String(msg));
  292. error.code = code;
  293. error.loc = loc;
  294. return error;
  295. }
  296. const errorMessages = {
  297. // parse errors
  298. [0]: "Illegal comment.",
  299. [1]: "CDATA section is allowed only in XML context.",
  300. [2]: "Duplicate attribute.",
  301. [3]: "End tag cannot have attributes.",
  302. [4]: "Illegal '/' in tags.",
  303. [5]: "Unexpected EOF in tag.",
  304. [6]: "Unexpected EOF in CDATA section.",
  305. [7]: "Unexpected EOF in comment.",
  306. [8]: "Unexpected EOF in script.",
  307. [9]: "Unexpected EOF in tag.",
  308. [10]: "Incorrectly closed comment.",
  309. [11]: "Incorrectly opened comment.",
  310. [12]: "Illegal tag name. Use '&lt;' to print '<'.",
  311. [13]: "Attribute value was expected.",
  312. [14]: "End tag name was expected.",
  313. [15]: "Whitespace was expected.",
  314. [16]: "Unexpected '<!--' in comment.",
  315. [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
  316. [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
  317. [19]: "Attribute name cannot start with '='.",
  318. [21]: "'<?' is allowed only in XML context.",
  319. [20]: `Unexpected null character.`,
  320. [22]: "Illegal '/' in tags.",
  321. // Vue-specific parse errors
  322. [23]: "Invalid end tag.",
  323. [24]: "Element is missing end tag.",
  324. [25]: "Interpolation end sign was not found.",
  325. [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
  326. [26]: "Legal directive name was expected.",
  327. // transform errors
  328. [28]: `v-if/v-else-if is missing expression.`,
  329. [29]: `v-if/else branches must use unique keys.`,
  330. [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  331. [31]: `v-for is missing expression.`,
  332. [32]: `v-for has invalid expression.`,
  333. [33]: `<template v-for> key should be placed on the <template> tag.`,
  334. [34]: `v-bind is missing expression.`,
  335. [35]: `v-on is missing expression.`,
  336. [36]: `Unexpected custom directive on <slot> outlet.`,
  337. [37]: `Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.`,
  338. [38]: `Duplicate slot names found. `,
  339. [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
  340. [40]: `v-slot can only be used on components or <template> tags.`,
  341. [41]: `v-model is missing expression.`,
  342. [42]: `v-model value must be a valid JavaScript member expression.`,
  343. [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  344. [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
  345. Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  346. [45]: `Error parsing JavaScript expression: `,
  347. [46]: `<KeepAlive> expects exactly one child component.`,
  348. // generic errors
  349. [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  350. [48]: `ES module mode is not supported in this build of compiler.`,
  351. [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  352. [50]: `"scopeId" option is only supported in module mode.`,
  353. // deprecations
  354. [51]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`,
  355. [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
  356. // just to fulfill types
  357. [53]: ``
  358. };
  359. const FRAGMENT = Symbol(`Fragment` );
  360. const TELEPORT = Symbol(`Teleport` );
  361. const SUSPENSE = Symbol(`Suspense` );
  362. const KEEP_ALIVE = Symbol(`KeepAlive` );
  363. const BASE_TRANSITION = Symbol(`BaseTransition` );
  364. const OPEN_BLOCK = Symbol(`openBlock` );
  365. const CREATE_BLOCK = Symbol(`createBlock` );
  366. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  367. const CREATE_VNODE = Symbol(`createVNode` );
  368. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  369. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  370. const CREATE_TEXT = Symbol(`createTextVNode` );
  371. const CREATE_STATIC = Symbol(`createStaticVNode` );
  372. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  373. const RESOLVE_DYNAMIC_COMPONENT = Symbol(
  374. `resolveDynamicComponent`
  375. );
  376. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  377. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  378. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  379. const RENDER_LIST = Symbol(`renderList` );
  380. const RENDER_SLOT = Symbol(`renderSlot` );
  381. const CREATE_SLOTS = Symbol(`createSlots` );
  382. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  383. const MERGE_PROPS = Symbol(`mergeProps` );
  384. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  385. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  386. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  387. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  388. const TO_HANDLERS = Symbol(`toHandlers` );
  389. const CAMELIZE = Symbol(`camelize` );
  390. const CAPITALIZE = Symbol(`capitalize` );
  391. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  392. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  393. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  394. const POP_SCOPE_ID = Symbol(`popScopeId` );
  395. const WITH_CTX = Symbol(`withCtx` );
  396. const UNREF = Symbol(`unref` );
  397. const IS_REF = Symbol(`isRef` );
  398. const WITH_MEMO = Symbol(`withMemo` );
  399. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  400. const helperNameMap = {
  401. [FRAGMENT]: `Fragment`,
  402. [TELEPORT]: `Teleport`,
  403. [SUSPENSE]: `Suspense`,
  404. [KEEP_ALIVE]: `KeepAlive`,
  405. [BASE_TRANSITION]: `BaseTransition`,
  406. [OPEN_BLOCK]: `openBlock`,
  407. [CREATE_BLOCK]: `createBlock`,
  408. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  409. [CREATE_VNODE]: `createVNode`,
  410. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  411. [CREATE_COMMENT]: `createCommentVNode`,
  412. [CREATE_TEXT]: `createTextVNode`,
  413. [CREATE_STATIC]: `createStaticVNode`,
  414. [RESOLVE_COMPONENT]: `resolveComponent`,
  415. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  416. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  417. [RESOLVE_FILTER]: `resolveFilter`,
  418. [WITH_DIRECTIVES]: `withDirectives`,
  419. [RENDER_LIST]: `renderList`,
  420. [RENDER_SLOT]: `renderSlot`,
  421. [CREATE_SLOTS]: `createSlots`,
  422. [TO_DISPLAY_STRING]: `toDisplayString`,
  423. [MERGE_PROPS]: `mergeProps`,
  424. [NORMALIZE_CLASS]: `normalizeClass`,
  425. [NORMALIZE_STYLE]: `normalizeStyle`,
  426. [NORMALIZE_PROPS]: `normalizeProps`,
  427. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  428. [TO_HANDLERS]: `toHandlers`,
  429. [CAMELIZE]: `camelize`,
  430. [CAPITALIZE]: `capitalize`,
  431. [TO_HANDLER_KEY]: `toHandlerKey`,
  432. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  433. [PUSH_SCOPE_ID]: `pushScopeId`,
  434. [POP_SCOPE_ID]: `popScopeId`,
  435. [WITH_CTX]: `withCtx`,
  436. [UNREF]: `unref`,
  437. [IS_REF]: `isRef`,
  438. [WITH_MEMO]: `withMemo`,
  439. [IS_MEMO_SAME]: `isMemoSame`
  440. };
  441. function registerRuntimeHelpers(helpers) {
  442. Object.getOwnPropertySymbols(helpers).forEach((s) => {
  443. helperNameMap[s] = helpers[s];
  444. });
  445. }
  446. const locStub = {
  447. source: "",
  448. start: { line: 1, column: 1, offset: 0 },
  449. end: { line: 1, column: 1, offset: 0 }
  450. };
  451. function createRoot(children, loc = locStub) {
  452. return {
  453. type: 0,
  454. children,
  455. helpers: /* @__PURE__ */ new Set(),
  456. components: [],
  457. directives: [],
  458. hoists: [],
  459. imports: [],
  460. cached: 0,
  461. temps: 0,
  462. codegenNode: void 0,
  463. loc
  464. };
  465. }
  466. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  467. if (context) {
  468. if (isBlock) {
  469. context.helper(OPEN_BLOCK);
  470. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  471. } else {
  472. context.helper(getVNodeHelper(context.inSSR, isComponent));
  473. }
  474. if (directives) {
  475. context.helper(WITH_DIRECTIVES);
  476. }
  477. }
  478. return {
  479. type: 13,
  480. tag,
  481. props,
  482. children,
  483. patchFlag,
  484. dynamicProps,
  485. directives,
  486. isBlock,
  487. disableTracking,
  488. isComponent,
  489. loc
  490. };
  491. }
  492. function createArrayExpression(elements, loc = locStub) {
  493. return {
  494. type: 17,
  495. loc,
  496. elements
  497. };
  498. }
  499. function createObjectExpression(properties, loc = locStub) {
  500. return {
  501. type: 15,
  502. loc,
  503. properties
  504. };
  505. }
  506. function createObjectProperty(key, value) {
  507. return {
  508. type: 16,
  509. loc: locStub,
  510. key: isString$2(key) ? createSimpleExpression(key, true) : key,
  511. value
  512. };
  513. }
  514. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
  515. return {
  516. type: 4,
  517. loc,
  518. content,
  519. isStatic,
  520. constType: isStatic ? 3 : constType
  521. };
  522. }
  523. function createInterpolation(content, loc) {
  524. return {
  525. type: 5,
  526. loc,
  527. content: isString$2(content) ? createSimpleExpression(content, false, loc) : content
  528. };
  529. }
  530. function createCompoundExpression(children, loc = locStub) {
  531. return {
  532. type: 8,
  533. loc,
  534. children
  535. };
  536. }
  537. function createCallExpression(callee, args = [], loc = locStub) {
  538. return {
  539. type: 14,
  540. loc,
  541. callee,
  542. arguments: args
  543. };
  544. }
  545. function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
  546. return {
  547. type: 18,
  548. params,
  549. returns,
  550. newline,
  551. isSlot,
  552. loc
  553. };
  554. }
  555. function createConditionalExpression(test, consequent, alternate, newline = true) {
  556. return {
  557. type: 19,
  558. test,
  559. consequent,
  560. alternate,
  561. newline,
  562. loc: locStub
  563. };
  564. }
  565. function createCacheExpression(index, value, isVNode = false) {
  566. return {
  567. type: 20,
  568. index,
  569. value,
  570. isVNode,
  571. loc: locStub
  572. };
  573. }
  574. function createBlockStatement(body) {
  575. return {
  576. type: 21,
  577. body,
  578. loc: locStub
  579. };
  580. }
  581. function createTemplateLiteral(elements) {
  582. return {
  583. type: 22,
  584. elements,
  585. loc: locStub
  586. };
  587. }
  588. function createIfStatement(test, consequent, alternate) {
  589. return {
  590. type: 23,
  591. test,
  592. consequent,
  593. alternate,
  594. loc: locStub
  595. };
  596. }
  597. function createAssignmentExpression(left, right) {
  598. return {
  599. type: 24,
  600. left,
  601. right,
  602. loc: locStub
  603. };
  604. }
  605. function createSequenceExpression(expressions) {
  606. return {
  607. type: 25,
  608. expressions,
  609. loc: locStub
  610. };
  611. }
  612. function createReturnStatement(returns) {
  613. return {
  614. type: 26,
  615. returns,
  616. loc: locStub
  617. };
  618. }
  619. function getVNodeHelper(ssr, isComponent) {
  620. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  621. }
  622. function getVNodeBlockHelper(ssr, isComponent) {
  623. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  624. }
  625. function convertToBlock(node, { helper, removeHelper, inSSR }) {
  626. if (!node.isBlock) {
  627. node.isBlock = true;
  628. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  629. helper(OPEN_BLOCK);
  630. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  631. }
  632. }
  633. function getDefaultExportFromCjs (x) {
  634. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  635. }
  636. function getAugmentedNamespace(n) {
  637. if (n.__esModule) return n;
  638. var f = n.default;
  639. if (typeof f == "function") {
  640. var a = function a () {
  641. if (this instanceof a) {
  642. var args = [null];
  643. args.push.apply(args, arguments);
  644. var Ctor = Function.bind.apply(f, args);
  645. return new Ctor();
  646. }
  647. return f.apply(this, arguments);
  648. };
  649. a.prototype = f.prototype;
  650. } else a = {};
  651. Object.defineProperty(a, '__esModule', {value: true});
  652. Object.keys(n).forEach(function (k) {
  653. var d = Object.getOwnPropertyDescriptor(n, k);
  654. Object.defineProperty(a, k, d.get ? d : {
  655. enumerable: true,
  656. get: function () {
  657. return n[k];
  658. }
  659. });
  660. });
  661. return a;
  662. }
  663. var lib = {};
  664. Object.defineProperty(lib, '__esModule', {
  665. value: true
  666. });
  667. const defaultOptions = {
  668. sourceType: "script",
  669. sourceFilename: undefined,
  670. startColumn: 0,
  671. startLine: 1,
  672. allowAwaitOutsideFunction: false,
  673. allowReturnOutsideFunction: false,
  674. allowNewTargetOutsideFunction: false,
  675. allowImportExportEverywhere: false,
  676. allowSuperOutsideMethod: false,
  677. allowUndeclaredExports: false,
  678. plugins: [],
  679. strictMode: null,
  680. ranges: false,
  681. tokens: false,
  682. createParenthesizedExpressions: false,
  683. errorRecovery: false,
  684. attachComment: true,
  685. annexB: true
  686. };
  687. function getOptions(opts) {
  688. if (opts && opts.annexB != null && opts.annexB !== false) {
  689. throw new Error("The `annexB` option can only be set to `false`.");
  690. }
  691. const options = {};
  692. for (const key of Object.keys(defaultOptions)) {
  693. options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key];
  694. }
  695. return options;
  696. }
  697. class TokContext {
  698. constructor(token, preserveSpace) {
  699. this.token = void 0;
  700. this.preserveSpace = void 0;
  701. this.token = token;
  702. this.preserveSpace = !!preserveSpace;
  703. }
  704. }
  705. const types$1 = {
  706. brace: new TokContext("{"),
  707. j_oTag: new TokContext("<tag"),
  708. j_cTag: new TokContext("</tag"),
  709. j_expr: new TokContext("<tag>...</tag>", true)
  710. };
  711. {
  712. types$1.template = new TokContext("`", true);
  713. }
  714. const beforeExpr = true;
  715. const startsExpr = true;
  716. const isLoop = true;
  717. const isAssign = true;
  718. const prefix = true;
  719. const postfix = true;
  720. class ExportedTokenType {
  721. constructor(label, conf = {}) {
  722. this.label = void 0;
  723. this.keyword = void 0;
  724. this.beforeExpr = void 0;
  725. this.startsExpr = void 0;
  726. this.rightAssociative = void 0;
  727. this.isLoop = void 0;
  728. this.isAssign = void 0;
  729. this.prefix = void 0;
  730. this.postfix = void 0;
  731. this.binop = void 0;
  732. this.label = label;
  733. this.keyword = conf.keyword;
  734. this.beforeExpr = !!conf.beforeExpr;
  735. this.startsExpr = !!conf.startsExpr;
  736. this.rightAssociative = !!conf.rightAssociative;
  737. this.isLoop = !!conf.isLoop;
  738. this.isAssign = !!conf.isAssign;
  739. this.prefix = !!conf.prefix;
  740. this.postfix = !!conf.postfix;
  741. this.binop = conf.binop != null ? conf.binop : null;
  742. {
  743. this.updateContext = null;
  744. }
  745. }
  746. }
  747. const keywords$1 = new Map();
  748. function createKeyword(name, options = {}) {
  749. options.keyword = name;
  750. const token = createToken(name, options);
  751. keywords$1.set(name, token);
  752. return token;
  753. }
  754. function createBinop(name, binop) {
  755. return createToken(name, {
  756. beforeExpr,
  757. binop
  758. });
  759. }
  760. let tokenTypeCounter = -1;
  761. const tokenTypes$1 = [];
  762. const tokenLabels = [];
  763. const tokenBinops = [];
  764. const tokenBeforeExprs = [];
  765. const tokenStartsExprs = [];
  766. const tokenPrefixes = [];
  767. function createToken(name, options = {}) {
  768. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  769. ++tokenTypeCounter;
  770. tokenLabels.push(name);
  771. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  772. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  773. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  774. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  775. tokenTypes$1.push(new ExportedTokenType(name, options));
  776. return tokenTypeCounter;
  777. }
  778. function createKeywordLike(name, options = {}) {
  779. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  780. ++tokenTypeCounter;
  781. keywords$1.set(name, tokenTypeCounter);
  782. tokenLabels.push(name);
  783. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  784. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  785. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  786. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  787. tokenTypes$1.push(new ExportedTokenType("name", options));
  788. return tokenTypeCounter;
  789. }
  790. const tt = {
  791. bracketL: createToken("[", {
  792. beforeExpr,
  793. startsExpr
  794. }),
  795. bracketHashL: createToken("#[", {
  796. beforeExpr,
  797. startsExpr
  798. }),
  799. bracketBarL: createToken("[|", {
  800. beforeExpr,
  801. startsExpr
  802. }),
  803. bracketR: createToken("]"),
  804. bracketBarR: createToken("|]"),
  805. braceL: createToken("{", {
  806. beforeExpr,
  807. startsExpr
  808. }),
  809. braceBarL: createToken("{|", {
  810. beforeExpr,
  811. startsExpr
  812. }),
  813. braceHashL: createToken("#{", {
  814. beforeExpr,
  815. startsExpr
  816. }),
  817. braceR: createToken("}"),
  818. braceBarR: createToken("|}"),
  819. parenL: createToken("(", {
  820. beforeExpr,
  821. startsExpr
  822. }),
  823. parenR: createToken(")"),
  824. comma: createToken(",", {
  825. beforeExpr
  826. }),
  827. semi: createToken(";", {
  828. beforeExpr
  829. }),
  830. colon: createToken(":", {
  831. beforeExpr
  832. }),
  833. doubleColon: createToken("::", {
  834. beforeExpr
  835. }),
  836. dot: createToken("."),
  837. question: createToken("?", {
  838. beforeExpr
  839. }),
  840. questionDot: createToken("?."),
  841. arrow: createToken("=>", {
  842. beforeExpr
  843. }),
  844. template: createToken("template"),
  845. ellipsis: createToken("...", {
  846. beforeExpr
  847. }),
  848. backQuote: createToken("`", {
  849. startsExpr
  850. }),
  851. dollarBraceL: createToken("${", {
  852. beforeExpr,
  853. startsExpr
  854. }),
  855. templateTail: createToken("...`", {
  856. startsExpr
  857. }),
  858. templateNonTail: createToken("...${", {
  859. beforeExpr,
  860. startsExpr
  861. }),
  862. at: createToken("@"),
  863. hash: createToken("#", {
  864. startsExpr
  865. }),
  866. interpreterDirective: createToken("#!..."),
  867. eq: createToken("=", {
  868. beforeExpr,
  869. isAssign
  870. }),
  871. assign: createToken("_=", {
  872. beforeExpr,
  873. isAssign
  874. }),
  875. slashAssign: createToken("_=", {
  876. beforeExpr,
  877. isAssign
  878. }),
  879. xorAssign: createToken("_=", {
  880. beforeExpr,
  881. isAssign
  882. }),
  883. moduloAssign: createToken("_=", {
  884. beforeExpr,
  885. isAssign
  886. }),
  887. incDec: createToken("++/--", {
  888. prefix,
  889. postfix,
  890. startsExpr
  891. }),
  892. bang: createToken("!", {
  893. beforeExpr,
  894. prefix,
  895. startsExpr
  896. }),
  897. tilde: createToken("~", {
  898. beforeExpr,
  899. prefix,
  900. startsExpr
  901. }),
  902. doubleCaret: createToken("^^", {
  903. startsExpr
  904. }),
  905. doubleAt: createToken("@@", {
  906. startsExpr
  907. }),
  908. pipeline: createBinop("|>", 0),
  909. nullishCoalescing: createBinop("??", 1),
  910. logicalOR: createBinop("||", 1),
  911. logicalAND: createBinop("&&", 2),
  912. bitwiseOR: createBinop("|", 3),
  913. bitwiseXOR: createBinop("^", 4),
  914. bitwiseAND: createBinop("&", 5),
  915. equality: createBinop("==/!=/===/!==", 6),
  916. lt: createBinop("</>/<=/>=", 7),
  917. gt: createBinop("</>/<=/>=", 7),
  918. relational: createBinop("</>/<=/>=", 7),
  919. bitShift: createBinop("<</>>/>>>", 8),
  920. bitShiftL: createBinop("<</>>/>>>", 8),
  921. bitShiftR: createBinop("<</>>/>>>", 8),
  922. plusMin: createToken("+/-", {
  923. beforeExpr,
  924. binop: 9,
  925. prefix,
  926. startsExpr
  927. }),
  928. modulo: createToken("%", {
  929. binop: 10,
  930. startsExpr
  931. }),
  932. star: createToken("*", {
  933. binop: 10
  934. }),
  935. slash: createBinop("/", 10),
  936. exponent: createToken("**", {
  937. beforeExpr,
  938. binop: 11,
  939. rightAssociative: true
  940. }),
  941. _in: createKeyword("in", {
  942. beforeExpr,
  943. binop: 7
  944. }),
  945. _instanceof: createKeyword("instanceof", {
  946. beforeExpr,
  947. binop: 7
  948. }),
  949. _break: createKeyword("break"),
  950. _case: createKeyword("case", {
  951. beforeExpr
  952. }),
  953. _catch: createKeyword("catch"),
  954. _continue: createKeyword("continue"),
  955. _debugger: createKeyword("debugger"),
  956. _default: createKeyword("default", {
  957. beforeExpr
  958. }),
  959. _else: createKeyword("else", {
  960. beforeExpr
  961. }),
  962. _finally: createKeyword("finally"),
  963. _function: createKeyword("function", {
  964. startsExpr
  965. }),
  966. _if: createKeyword("if"),
  967. _return: createKeyword("return", {
  968. beforeExpr
  969. }),
  970. _switch: createKeyword("switch"),
  971. _throw: createKeyword("throw", {
  972. beforeExpr,
  973. prefix,
  974. startsExpr
  975. }),
  976. _try: createKeyword("try"),
  977. _var: createKeyword("var"),
  978. _const: createKeyword("const"),
  979. _with: createKeyword("with"),
  980. _new: createKeyword("new", {
  981. beforeExpr,
  982. startsExpr
  983. }),
  984. _this: createKeyword("this", {
  985. startsExpr
  986. }),
  987. _super: createKeyword("super", {
  988. startsExpr
  989. }),
  990. _class: createKeyword("class", {
  991. startsExpr
  992. }),
  993. _extends: createKeyword("extends", {
  994. beforeExpr
  995. }),
  996. _export: createKeyword("export"),
  997. _import: createKeyword("import", {
  998. startsExpr
  999. }),
  1000. _null: createKeyword("null", {
  1001. startsExpr
  1002. }),
  1003. _true: createKeyword("true", {
  1004. startsExpr
  1005. }),
  1006. _false: createKeyword("false", {
  1007. startsExpr
  1008. }),
  1009. _typeof: createKeyword("typeof", {
  1010. beforeExpr,
  1011. prefix,
  1012. startsExpr
  1013. }),
  1014. _void: createKeyword("void", {
  1015. beforeExpr,
  1016. prefix,
  1017. startsExpr
  1018. }),
  1019. _delete: createKeyword("delete", {
  1020. beforeExpr,
  1021. prefix,
  1022. startsExpr
  1023. }),
  1024. _do: createKeyword("do", {
  1025. isLoop,
  1026. beforeExpr
  1027. }),
  1028. _for: createKeyword("for", {
  1029. isLoop
  1030. }),
  1031. _while: createKeyword("while", {
  1032. isLoop
  1033. }),
  1034. _as: createKeywordLike("as", {
  1035. startsExpr
  1036. }),
  1037. _assert: createKeywordLike("assert", {
  1038. startsExpr
  1039. }),
  1040. _async: createKeywordLike("async", {
  1041. startsExpr
  1042. }),
  1043. _await: createKeywordLike("await", {
  1044. startsExpr
  1045. }),
  1046. _from: createKeywordLike("from", {
  1047. startsExpr
  1048. }),
  1049. _get: createKeywordLike("get", {
  1050. startsExpr
  1051. }),
  1052. _let: createKeywordLike("let", {
  1053. startsExpr
  1054. }),
  1055. _meta: createKeywordLike("meta", {
  1056. startsExpr
  1057. }),
  1058. _of: createKeywordLike("of", {
  1059. startsExpr
  1060. }),
  1061. _sent: createKeywordLike("sent", {
  1062. startsExpr
  1063. }),
  1064. _set: createKeywordLike("set", {
  1065. startsExpr
  1066. }),
  1067. _static: createKeywordLike("static", {
  1068. startsExpr
  1069. }),
  1070. _using: createKeywordLike("using", {
  1071. startsExpr
  1072. }),
  1073. _yield: createKeywordLike("yield", {
  1074. startsExpr
  1075. }),
  1076. _asserts: createKeywordLike("asserts", {
  1077. startsExpr
  1078. }),
  1079. _checks: createKeywordLike("checks", {
  1080. startsExpr
  1081. }),
  1082. _exports: createKeywordLike("exports", {
  1083. startsExpr
  1084. }),
  1085. _global: createKeywordLike("global", {
  1086. startsExpr
  1087. }),
  1088. _implements: createKeywordLike("implements", {
  1089. startsExpr
  1090. }),
  1091. _intrinsic: createKeywordLike("intrinsic", {
  1092. startsExpr
  1093. }),
  1094. _infer: createKeywordLike("infer", {
  1095. startsExpr
  1096. }),
  1097. _is: createKeywordLike("is", {
  1098. startsExpr
  1099. }),
  1100. _mixins: createKeywordLike("mixins", {
  1101. startsExpr
  1102. }),
  1103. _proto: createKeywordLike("proto", {
  1104. startsExpr
  1105. }),
  1106. _require: createKeywordLike("require", {
  1107. startsExpr
  1108. }),
  1109. _satisfies: createKeywordLike("satisfies", {
  1110. startsExpr
  1111. }),
  1112. _keyof: createKeywordLike("keyof", {
  1113. startsExpr
  1114. }),
  1115. _readonly: createKeywordLike("readonly", {
  1116. startsExpr
  1117. }),
  1118. _unique: createKeywordLike("unique", {
  1119. startsExpr
  1120. }),
  1121. _abstract: createKeywordLike("abstract", {
  1122. startsExpr
  1123. }),
  1124. _declare: createKeywordLike("declare", {
  1125. startsExpr
  1126. }),
  1127. _enum: createKeywordLike("enum", {
  1128. startsExpr
  1129. }),
  1130. _module: createKeywordLike("module", {
  1131. startsExpr
  1132. }),
  1133. _namespace: createKeywordLike("namespace", {
  1134. startsExpr
  1135. }),
  1136. _interface: createKeywordLike("interface", {
  1137. startsExpr
  1138. }),
  1139. _type: createKeywordLike("type", {
  1140. startsExpr
  1141. }),
  1142. _opaque: createKeywordLike("opaque", {
  1143. startsExpr
  1144. }),
  1145. name: createToken("name", {
  1146. startsExpr
  1147. }),
  1148. string: createToken("string", {
  1149. startsExpr
  1150. }),
  1151. num: createToken("num", {
  1152. startsExpr
  1153. }),
  1154. bigint: createToken("bigint", {
  1155. startsExpr
  1156. }),
  1157. decimal: createToken("decimal", {
  1158. startsExpr
  1159. }),
  1160. regexp: createToken("regexp", {
  1161. startsExpr
  1162. }),
  1163. privateName: createToken("#name", {
  1164. startsExpr
  1165. }),
  1166. eof: createToken("eof"),
  1167. jsxName: createToken("jsxName"),
  1168. jsxText: createToken("jsxText", {
  1169. beforeExpr: true
  1170. }),
  1171. jsxTagStart: createToken("jsxTagStart", {
  1172. startsExpr: true
  1173. }),
  1174. jsxTagEnd: createToken("jsxTagEnd"),
  1175. placeholder: createToken("%%", {
  1176. startsExpr: true
  1177. })
  1178. };
  1179. function tokenIsIdentifier(token) {
  1180. return token >= 93 && token <= 130;
  1181. }
  1182. function tokenKeywordOrIdentifierIsKeyword(token) {
  1183. return token <= 92;
  1184. }
  1185. function tokenIsKeywordOrIdentifier(token) {
  1186. return token >= 58 && token <= 130;
  1187. }
  1188. function tokenIsLiteralPropertyName(token) {
  1189. return token >= 58 && token <= 134;
  1190. }
  1191. function tokenComesBeforeExpression(token) {
  1192. return tokenBeforeExprs[token];
  1193. }
  1194. function tokenCanStartExpression(token) {
  1195. return tokenStartsExprs[token];
  1196. }
  1197. function tokenIsAssignment(token) {
  1198. return token >= 29 && token <= 33;
  1199. }
  1200. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1201. return token >= 127 && token <= 129;
  1202. }
  1203. function tokenIsLoop(token) {
  1204. return token >= 90 && token <= 92;
  1205. }
  1206. function tokenIsKeyword(token) {
  1207. return token >= 58 && token <= 92;
  1208. }
  1209. function tokenIsOperator(token) {
  1210. return token >= 39 && token <= 59;
  1211. }
  1212. function tokenIsPostfix(token) {
  1213. return token === 34;
  1214. }
  1215. function tokenIsPrefix(token) {
  1216. return tokenPrefixes[token];
  1217. }
  1218. function tokenIsTSTypeOperator(token) {
  1219. return token >= 119 && token <= 121;
  1220. }
  1221. function tokenIsTSDeclarationStart(token) {
  1222. return token >= 122 && token <= 128;
  1223. }
  1224. function tokenLabelName(token) {
  1225. return tokenLabels[token];
  1226. }
  1227. function tokenOperatorPrecedence(token) {
  1228. return tokenBinops[token];
  1229. }
  1230. function tokenIsRightAssociative(token) {
  1231. return token === 57;
  1232. }
  1233. function tokenIsTemplate(token) {
  1234. return token >= 24 && token <= 25;
  1235. }
  1236. function getExportedToken(token) {
  1237. return tokenTypes$1[token];
  1238. }
  1239. {
  1240. tokenTypes$1[8].updateContext = context => {
  1241. context.pop();
  1242. };
  1243. tokenTypes$1[5].updateContext = tokenTypes$1[7].updateContext = tokenTypes$1[23].updateContext = context => {
  1244. context.push(types$1.brace);
  1245. };
  1246. tokenTypes$1[22].updateContext = context => {
  1247. if (context[context.length - 1] === types$1.template) {
  1248. context.pop();
  1249. } else {
  1250. context.push(types$1.template);
  1251. }
  1252. };
  1253. tokenTypes$1[140].updateContext = context => {
  1254. context.push(types$1.j_expr, types$1.j_oTag);
  1255. };
  1256. }
  1257. function _objectWithoutPropertiesLoose(source, excluded) {
  1258. if (source == null) return {};
  1259. var target = {};
  1260. var sourceKeys = Object.keys(source);
  1261. var key, i;
  1262. for (i = 0; i < sourceKeys.length; i++) {
  1263. key = sourceKeys[i];
  1264. if (excluded.indexOf(key) >= 0) continue;
  1265. target[key] = source[key];
  1266. }
  1267. return target;
  1268. }
  1269. class Position {
  1270. constructor(line, col, index) {
  1271. this.line = void 0;
  1272. this.column = void 0;
  1273. this.index = void 0;
  1274. this.line = line;
  1275. this.column = col;
  1276. this.index = index;
  1277. }
  1278. }
  1279. class SourceLocation {
  1280. constructor(start, end) {
  1281. this.start = void 0;
  1282. this.end = void 0;
  1283. this.filename = void 0;
  1284. this.identifierName = void 0;
  1285. this.start = start;
  1286. this.end = end;
  1287. }
  1288. }
  1289. function createPositionWithColumnOffset(position, columnOffset) {
  1290. const {
  1291. line,
  1292. column,
  1293. index
  1294. } = position;
  1295. return new Position(line, column + columnOffset, index + columnOffset);
  1296. }
  1297. var ParseErrorCode = {
  1298. SyntaxError: "BABEL_PARSER_SYNTAX_ERROR",
  1299. SourceTypeModuleError: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"
  1300. };
  1301. const reflect = (keys, last = keys.length - 1) => ({
  1302. get() {
  1303. return keys.reduce((object, key) => object[key], this);
  1304. },
  1305. set(value) {
  1306. keys.reduce((item, key, i) => i === last ? item[key] = value : item[key], this);
  1307. }
  1308. });
  1309. const instantiate = (constructor, properties, descriptors) => Object.keys(descriptors).map(key => [key, descriptors[key]]).filter(([, descriptor]) => !!descriptor).map(([key, descriptor]) => [key, typeof descriptor === "function" ? {
  1310. value: descriptor,
  1311. enumerable: false
  1312. } : typeof descriptor.reflect === "string" ? Object.assign({}, descriptor, reflect(descriptor.reflect.split("."))) : descriptor]).reduce((instance, [key, descriptor]) => Object.defineProperty(instance, key, Object.assign({
  1313. configurable: true
  1314. }, descriptor)), Object.assign(new constructor(), properties));
  1315. var ModuleErrors = {
  1316. ImportMetaOutsideModule: {
  1317. message: `import.meta may appear only with 'sourceType: "module"'`,
  1318. code: ParseErrorCode.SourceTypeModuleError
  1319. },
  1320. ImportOutsideModule: {
  1321. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  1322. code: ParseErrorCode.SourceTypeModuleError
  1323. }
  1324. };
  1325. const NodeDescriptions = {
  1326. ArrayPattern: "array destructuring pattern",
  1327. AssignmentExpression: "assignment expression",
  1328. AssignmentPattern: "assignment expression",
  1329. ArrowFunctionExpression: "arrow function expression",
  1330. ConditionalExpression: "conditional expression",
  1331. CatchClause: "catch clause",
  1332. ForOfStatement: "for-of statement",
  1333. ForInStatement: "for-in statement",
  1334. ForStatement: "for-loop",
  1335. FormalParameters: "function parameter list",
  1336. Identifier: "identifier",
  1337. ImportSpecifier: "import specifier",
  1338. ImportDefaultSpecifier: "import default specifier",
  1339. ImportNamespaceSpecifier: "import namespace specifier",
  1340. ObjectPattern: "object destructuring pattern",
  1341. ParenthesizedExpression: "parenthesized expression",
  1342. RestElement: "rest element",
  1343. UpdateExpression: {
  1344. true: "prefix operation",
  1345. false: "postfix operation"
  1346. },
  1347. VariableDeclarator: "variable declaration",
  1348. YieldExpression: "yield expression"
  1349. };
  1350. const toNodeDescription = ({
  1351. type,
  1352. prefix
  1353. }) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type];
  1354. var StandardErrors = {
  1355. AccessorIsGenerator: ({
  1356. kind
  1357. }) => `A ${kind}ter cannot be a generator.`,
  1358. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  1359. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  1360. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  1361. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  1362. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  1363. AwaitInUsingBinding: "'await' is not allowed to be used as a name in 'using' declarations.",
  1364. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  1365. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  1366. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  1367. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  1368. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  1369. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  1370. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  1371. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  1372. ConstructorIsAsync: "Constructor can't be an async function.",
  1373. ConstructorIsGenerator: "Constructor can't be a generator.",
  1374. DeclarationMissingInitializer: ({
  1375. kind
  1376. }) => `Missing initializer in ${kind} declaration.`,
  1377. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  1378. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  1379. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  1380. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  1381. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  1382. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  1383. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  1384. DeletePrivateField: "Deleting a private field is not allowed.",
  1385. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  1386. DuplicateConstructor: "Duplicate constructor in the same class.",
  1387. DuplicateDefaultExport: "Only one default export allowed per module.",
  1388. DuplicateExport: ({
  1389. exportName
  1390. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  1391. DuplicateProto: "Redefinition of __proto__ property.",
  1392. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  1393. ElementAfterRest: "Rest element must be last element.",
  1394. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  1395. ExportBindingIsString: ({
  1396. localName,
  1397. exportName
  1398. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  1399. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  1400. ForInOfLoopInitializer: ({
  1401. type
  1402. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  1403. ForInUsing: "For-in loop may not start with 'using' declaration.",
  1404. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  1405. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  1406. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  1407. IllegalBreakContinue: ({
  1408. type
  1409. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  1410. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  1411. IllegalReturn: "'return' outside of function.",
  1412. ImportBindingIsString: ({
  1413. importName
  1414. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  1415. ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
  1416. ImportCallArity: ({
  1417. maxArgumentCount
  1418. }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`,
  1419. ImportCallNotNewExpression: "Cannot use new with import(...).",
  1420. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  1421. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  1422. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  1423. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  1424. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  1425. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  1426. InvalidCodePoint: "Code point out of bounds.",
  1427. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  1428. InvalidDecimal: "Invalid decimal.",
  1429. InvalidDigit: ({
  1430. radix
  1431. }) => `Expected number in radix ${radix}.`,
  1432. InvalidEscapeSequence: "Bad character escape sequence.",
  1433. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  1434. InvalidEscapedReservedWord: ({
  1435. reservedWord
  1436. }) => `Escape sequence in keyword ${reservedWord}.`,
  1437. InvalidIdentifier: ({
  1438. identifierName
  1439. }) => `Invalid identifier ${identifierName}.`,
  1440. InvalidLhs: ({
  1441. ancestor
  1442. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  1443. InvalidLhsBinding: ({
  1444. ancestor
  1445. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  1446. InvalidNumber: "Invalid number.",
  1447. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  1448. InvalidOrUnexpectedToken: ({
  1449. unexpected
  1450. }) => `Unexpected character '${unexpected}'.`,
  1451. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  1452. InvalidPrivateFieldResolution: ({
  1453. identifierName
  1454. }) => `Private name #${identifierName} is not defined.`,
  1455. InvalidPropertyBindingPattern: "Binding member expression.",
  1456. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  1457. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  1458. LabelRedeclaration: ({
  1459. labelName
  1460. }) => `Label '${labelName}' is already declared.`,
  1461. LetInLexicalBinding: "'let' is not allowed to be used as a name in 'let' or 'const' declarations.",
  1462. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  1463. MalformedRegExpFlags: "Invalid regular expression flag.",
  1464. MissingClassName: "A class name is required.",
  1465. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  1466. MissingSemicolon: "Missing semicolon.",
  1467. MissingPlugin: ({
  1468. missingPlugin
  1469. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  1470. MissingOneOfPlugins: ({
  1471. missingPlugin
  1472. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  1473. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  1474. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  1475. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  1476. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  1477. ModuleAttributesWithDuplicateKeys: ({
  1478. key
  1479. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  1480. ModuleExportNameHasLoneSurrogate: ({
  1481. surrogateCharCode
  1482. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  1483. ModuleExportUndefined: ({
  1484. localName
  1485. }) => `Export '${localName}' is not defined.`,
  1486. MultipleDefaultsInSwitch: "Multiple default clauses.",
  1487. NewlineAfterThrow: "Illegal newline after throw.",
  1488. NoCatchOrFinally: "Missing catch or finally clause.",
  1489. NumberIdentifier: "Identifier directly after number.",
  1490. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  1491. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  1492. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  1493. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  1494. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  1495. ParamDupe: "Argument name clash.",
  1496. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  1497. PatternHasMethod: "Object pattern can't contain methods.",
  1498. PrivateInExpectedIn: ({
  1499. identifierName
  1500. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  1501. PrivateNameRedeclaration: ({
  1502. identifierName
  1503. }) => `Duplicate private name #${identifierName}.`,
  1504. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  1505. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  1506. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  1507. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  1508. RestTrailingComma: "Unexpected trailing comma after rest element.",
  1509. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  1510. SloppyFunctionAnnexB: "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement.",
  1511. StaticPrototype: "Classes may not have static property named prototype.",
  1512. SuperNotAllowed: "`super()` is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class?",
  1513. SuperPrivateField: "Private fields can't be accessed on super.",
  1514. TrailingDecorator: "Decorators must be attached to a class element.",
  1515. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  1516. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  1517. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  1518. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  1519. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  1520. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  1521. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  1522. UnexpectedKeyword: ({
  1523. keyword
  1524. }) => `Unexpected keyword '${keyword}'.`,
  1525. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  1526. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  1527. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  1528. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  1529. UnexpectedPrivateField: "Unexpected private name.",
  1530. UnexpectedReservedWord: ({
  1531. reservedWord
  1532. }) => `Unexpected reserved word '${reservedWord}'.`,
  1533. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  1534. UnexpectedToken: ({
  1535. expected,
  1536. unexpected
  1537. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  1538. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  1539. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  1540. UnsupportedBind: "Binding should be performed on object property.",
  1541. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  1542. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  1543. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  1544. UnsupportedMetaProperty: ({
  1545. target,
  1546. onlyValidPropertyName
  1547. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  1548. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  1549. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  1550. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  1551. UnterminatedComment: "Unterminated comment.",
  1552. UnterminatedRegExp: "Unterminated regular expression.",
  1553. UnterminatedString: "Unterminated string constant.",
  1554. UnterminatedTemplate: "Unterminated template.",
  1555. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  1556. VarRedeclaration: ({
  1557. identifierName
  1558. }) => `Identifier '${identifierName}' has already been declared.`,
  1559. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  1560. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  1561. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  1562. };
  1563. var StrictModeErrors = {
  1564. StrictDelete: "Deleting local variable in strict mode.",
  1565. StrictEvalArguments: ({
  1566. referenceName
  1567. }) => `Assigning to '${referenceName}' in strict mode.`,
  1568. StrictEvalArgumentsBinding: ({
  1569. bindingName
  1570. }) => `Binding '${bindingName}' in strict mode.`,
  1571. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  1572. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  1573. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  1574. StrictWith: "'with' in strict mode."
  1575. };
  1576. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  1577. var PipelineOperatorErrors = {
  1578. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  1579. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  1580. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  1581. PipeTopicUnconfiguredToken: ({
  1582. token
  1583. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  1584. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  1585. PipeUnparenthesizedBody: ({
  1586. type
  1587. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  1588. type
  1589. })}; please wrap it in parentheses.`,
  1590. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  1591. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  1592. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  1593. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  1594. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  1595. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  1596. };
  1597. const _excluded$1 = ["toMessage"],
  1598. _excluded2$1 = ["message"];
  1599. function toParseErrorConstructor(_ref) {
  1600. let {
  1601. toMessage
  1602. } = _ref,
  1603. properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  1604. return function constructor({
  1605. loc,
  1606. details
  1607. }) {
  1608. return instantiate(SyntaxError, Object.assign({}, properties, {
  1609. loc
  1610. }), {
  1611. clone(overrides = {}) {
  1612. const loc = overrides.loc || {};
  1613. return constructor({
  1614. loc: new Position("line" in loc ? loc.line : this.loc.line, "column" in loc ? loc.column : this.loc.column, "index" in loc ? loc.index : this.loc.index),
  1615. details: Object.assign({}, this.details, overrides.details)
  1616. });
  1617. },
  1618. details: {
  1619. value: details,
  1620. enumerable: false
  1621. },
  1622. message: {
  1623. get() {
  1624. return `${toMessage(this.details)} (${this.loc.line}:${this.loc.column})`;
  1625. },
  1626. set(value) {
  1627. Object.defineProperty(this, "message", {
  1628. value
  1629. });
  1630. }
  1631. },
  1632. pos: {
  1633. reflect: "loc.index",
  1634. enumerable: true
  1635. },
  1636. missingPlugin: "missingPlugin" in details && {
  1637. reflect: "details.missingPlugin",
  1638. enumerable: true
  1639. }
  1640. });
  1641. };
  1642. }
  1643. function ParseErrorEnum(argument, syntaxPlugin) {
  1644. if (Array.isArray(argument)) {
  1645. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  1646. }
  1647. const ParseErrorConstructors = {};
  1648. for (const reasonCode of Object.keys(argument)) {
  1649. const template = argument[reasonCode];
  1650. const _ref2 = typeof template === "string" ? {
  1651. message: () => template
  1652. } : typeof template === "function" ? {
  1653. message: template
  1654. } : template,
  1655. {
  1656. message
  1657. } = _ref2,
  1658. rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
  1659. const toMessage = typeof message === "string" ? () => message : message;
  1660. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  1661. code: ParseErrorCode.SyntaxError,
  1662. reasonCode,
  1663. toMessage
  1664. }, syntaxPlugin ? {
  1665. syntaxPlugin
  1666. } : {}, rest));
  1667. }
  1668. return ParseErrorConstructors;
  1669. }
  1670. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  1671. const {
  1672. defineProperty
  1673. } = Object;
  1674. const toUnenumerable = (object, key) => defineProperty(object, key, {
  1675. enumerable: false,
  1676. value: object[key]
  1677. });
  1678. function toESTreeLocation(node) {
  1679. node.loc.start && toUnenumerable(node.loc.start, "index");
  1680. node.loc.end && toUnenumerable(node.loc.end, "index");
  1681. return node;
  1682. }
  1683. var estree = superClass => class ESTreeParserMixin extends superClass {
  1684. parse() {
  1685. const file = toESTreeLocation(super.parse());
  1686. if (this.options.tokens) {
  1687. file.tokens = file.tokens.map(toESTreeLocation);
  1688. }
  1689. return file;
  1690. }
  1691. parseRegExpLiteral({
  1692. pattern,
  1693. flags
  1694. }) {
  1695. let regex = null;
  1696. try {
  1697. regex = new RegExp(pattern, flags);
  1698. } catch (e) {}
  1699. const node = this.estreeParseLiteral(regex);
  1700. node.regex = {
  1701. pattern,
  1702. flags
  1703. };
  1704. return node;
  1705. }
  1706. parseBigIntLiteral(value) {
  1707. let bigInt;
  1708. try {
  1709. bigInt = BigInt(value);
  1710. } catch (_unused) {
  1711. bigInt = null;
  1712. }
  1713. const node = this.estreeParseLiteral(bigInt);
  1714. node.bigint = String(node.value || value);
  1715. return node;
  1716. }
  1717. parseDecimalLiteral(value) {
  1718. const decimal = null;
  1719. const node = this.estreeParseLiteral(decimal);
  1720. node.decimal = String(node.value || value);
  1721. return node;
  1722. }
  1723. estreeParseLiteral(value) {
  1724. return this.parseLiteral(value, "Literal");
  1725. }
  1726. parseStringLiteral(value) {
  1727. return this.estreeParseLiteral(value);
  1728. }
  1729. parseNumericLiteral(value) {
  1730. return this.estreeParseLiteral(value);
  1731. }
  1732. parseNullLiteral() {
  1733. return this.estreeParseLiteral(null);
  1734. }
  1735. parseBooleanLiteral(value) {
  1736. return this.estreeParseLiteral(value);
  1737. }
  1738. directiveToStmt(directive) {
  1739. const expression = directive.value;
  1740. delete directive.value;
  1741. expression.type = "Literal";
  1742. expression.raw = expression.extra.raw;
  1743. expression.value = expression.extra.expressionValue;
  1744. const stmt = directive;
  1745. stmt.type = "ExpressionStatement";
  1746. stmt.expression = expression;
  1747. stmt.directive = expression.extra.rawValue;
  1748. delete expression.extra;
  1749. return stmt;
  1750. }
  1751. initFunction(node, isAsync) {
  1752. super.initFunction(node, isAsync);
  1753. node.expression = false;
  1754. }
  1755. checkDeclaration(node) {
  1756. if (node != null && this.isObjectProperty(node)) {
  1757. this.checkDeclaration(node.value);
  1758. } else {
  1759. super.checkDeclaration(node);
  1760. }
  1761. }
  1762. getObjectOrClassMethodParams(method) {
  1763. return method.value.params;
  1764. }
  1765. isValidDirective(stmt) {
  1766. var _stmt$expression$extr;
  1767. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  1768. }
  1769. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  1770. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  1771. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  1772. node.body = directiveStatements.concat(node.body);
  1773. delete node.directives;
  1774. }
  1775. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  1776. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  1777. if (method.typeParameters) {
  1778. method.value.typeParameters = method.typeParameters;
  1779. delete method.typeParameters;
  1780. }
  1781. classBody.body.push(method);
  1782. }
  1783. parsePrivateName() {
  1784. const node = super.parsePrivateName();
  1785. {
  1786. if (!this.getPluginOption("estree", "classFeatures")) {
  1787. return node;
  1788. }
  1789. }
  1790. return this.convertPrivateNameToPrivateIdentifier(node);
  1791. }
  1792. convertPrivateNameToPrivateIdentifier(node) {
  1793. const name = super.getPrivateNameSV(node);
  1794. node = node;
  1795. delete node.id;
  1796. node.name = name;
  1797. node.type = "PrivateIdentifier";
  1798. return node;
  1799. }
  1800. isPrivateName(node) {
  1801. {
  1802. if (!this.getPluginOption("estree", "classFeatures")) {
  1803. return super.isPrivateName(node);
  1804. }
  1805. }
  1806. return node.type === "PrivateIdentifier";
  1807. }
  1808. getPrivateNameSV(node) {
  1809. {
  1810. if (!this.getPluginOption("estree", "classFeatures")) {
  1811. return super.getPrivateNameSV(node);
  1812. }
  1813. }
  1814. return node.name;
  1815. }
  1816. parseLiteral(value, type) {
  1817. const node = super.parseLiteral(value, type);
  1818. node.raw = node.extra.raw;
  1819. delete node.extra;
  1820. return node;
  1821. }
  1822. parseFunctionBody(node, allowExpression, isMethod = false) {
  1823. super.parseFunctionBody(node, allowExpression, isMethod);
  1824. node.expression = node.body.type !== "BlockStatement";
  1825. }
  1826. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  1827. let funcNode = this.startNode();
  1828. funcNode.kind = node.kind;
  1829. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  1830. funcNode.type = "FunctionExpression";
  1831. delete funcNode.kind;
  1832. node.value = funcNode;
  1833. if (type === "ClassPrivateMethod") {
  1834. node.computed = false;
  1835. }
  1836. return this.finishNode(node, "MethodDefinition");
  1837. }
  1838. parseClassProperty(...args) {
  1839. const propertyNode = super.parseClassProperty(...args);
  1840. {
  1841. if (!this.getPluginOption("estree", "classFeatures")) {
  1842. return propertyNode;
  1843. }
  1844. }
  1845. propertyNode.type = "PropertyDefinition";
  1846. return propertyNode;
  1847. }
  1848. parseClassPrivateProperty(...args) {
  1849. const propertyNode = super.parseClassPrivateProperty(...args);
  1850. {
  1851. if (!this.getPluginOption("estree", "classFeatures")) {
  1852. return propertyNode;
  1853. }
  1854. }
  1855. propertyNode.type = "PropertyDefinition";
  1856. propertyNode.computed = false;
  1857. return propertyNode;
  1858. }
  1859. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  1860. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  1861. if (node) {
  1862. node.type = "Property";
  1863. if (node.kind === "method") {
  1864. node.kind = "init";
  1865. }
  1866. node.shorthand = false;
  1867. }
  1868. return node;
  1869. }
  1870. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  1871. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  1872. if (node) {
  1873. node.kind = "init";
  1874. node.type = "Property";
  1875. }
  1876. return node;
  1877. }
  1878. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  1879. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  1880. }
  1881. isAssignable(node, isBinding) {
  1882. if (node != null && this.isObjectProperty(node)) {
  1883. return this.isAssignable(node.value, isBinding);
  1884. }
  1885. return super.isAssignable(node, isBinding);
  1886. }
  1887. toAssignable(node, isLHS = false) {
  1888. if (node != null && this.isObjectProperty(node)) {
  1889. const {
  1890. key,
  1891. value
  1892. } = node;
  1893. if (this.isPrivateName(key)) {
  1894. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  1895. }
  1896. this.toAssignable(value, isLHS);
  1897. } else {
  1898. super.toAssignable(node, isLHS);
  1899. }
  1900. }
  1901. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  1902. if (prop.kind === "get" || prop.kind === "set") {
  1903. this.raise(Errors.PatternHasAccessor, {
  1904. at: prop.key
  1905. });
  1906. } else if (prop.method) {
  1907. this.raise(Errors.PatternHasMethod, {
  1908. at: prop.key
  1909. });
  1910. } else {
  1911. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  1912. }
  1913. }
  1914. finishCallExpression(unfinished, optional) {
  1915. const node = super.finishCallExpression(unfinished, optional);
  1916. if (node.callee.type === "Import") {
  1917. node.type = "ImportExpression";
  1918. node.source = node.arguments[0];
  1919. if (this.hasPlugin("importAssertions")) {
  1920. var _node$arguments$;
  1921. node.attributes = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
  1922. }
  1923. delete node.arguments;
  1924. delete node.callee;
  1925. }
  1926. return node;
  1927. }
  1928. toReferencedArguments(node) {
  1929. if (node.type === "ImportExpression") {
  1930. return;
  1931. }
  1932. super.toReferencedArguments(node);
  1933. }
  1934. parseExport(unfinished, decorators) {
  1935. const exportStartLoc = this.state.lastTokStartLoc;
  1936. const node = super.parseExport(unfinished, decorators);
  1937. switch (node.type) {
  1938. case "ExportAllDeclaration":
  1939. node.exported = null;
  1940. break;
  1941. case "ExportNamedDeclaration":
  1942. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  1943. node.type = "ExportAllDeclaration";
  1944. node.exported = node.specifiers[0].exported;
  1945. delete node.specifiers;
  1946. }
  1947. case "ExportDefaultDeclaration":
  1948. {
  1949. var _declaration$decorato;
  1950. const {
  1951. declaration
  1952. } = node;
  1953. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  1954. this.resetStartLocation(node, exportStartLoc);
  1955. }
  1956. }
  1957. break;
  1958. }
  1959. return node;
  1960. }
  1961. parseSubscript(base, startLoc, noCalls, state) {
  1962. const node = super.parseSubscript(base, startLoc, noCalls, state);
  1963. if (state.optionalChainMember) {
  1964. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  1965. node.type = node.type.substring(8);
  1966. }
  1967. if (state.stop) {
  1968. const chain = this.startNodeAtNode(node);
  1969. chain.expression = node;
  1970. return this.finishNode(chain, "ChainExpression");
  1971. }
  1972. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  1973. node.optional = false;
  1974. }
  1975. return node;
  1976. }
  1977. hasPropertyAsPrivateName(node) {
  1978. if (node.type === "ChainExpression") {
  1979. node = node.expression;
  1980. }
  1981. return super.hasPropertyAsPrivateName(node);
  1982. }
  1983. isObjectProperty(node) {
  1984. return node.type === "Property" && node.kind === "init" && !node.method;
  1985. }
  1986. isObjectMethod(node) {
  1987. return node.method || node.kind === "get" || node.kind === "set";
  1988. }
  1989. finishNodeAt(node, type, endLoc) {
  1990. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  1991. }
  1992. resetStartLocation(node, startLoc) {
  1993. super.resetStartLocation(node, startLoc);
  1994. toESTreeLocation(node);
  1995. }
  1996. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  1997. super.resetEndLocation(node, endLoc);
  1998. toESTreeLocation(node);
  1999. }
  2000. };
  2001. let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\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\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\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\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\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-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\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-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ca\ua7d0\ua7d1\ua7d3\ua7d5-\ua7d9\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\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";
  2002. let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0898-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\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\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\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-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\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\u1cf4\u1cf7-\u1cf9\u1dc0-\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\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
  2003. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  2004. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  2005. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  2006. const 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, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 68, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 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, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 4026, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 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, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 757, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 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, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938, 6, 4191];
  2007. const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 81, 2, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 9, 5351, 0, 7, 14, 13835, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 45, 3, 22, 543, 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, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 983, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  2008. function isInAstralSet(code, set) {
  2009. let pos = 0x10000;
  2010. for (let i = 0, length = set.length; i < length; i += 2) {
  2011. pos += set[i];
  2012. if (pos > code) return false;
  2013. pos += set[i + 1];
  2014. if (pos >= code) return true;
  2015. }
  2016. return false;
  2017. }
  2018. function isIdentifierStart(code) {
  2019. if (code < 65) return code === 36;
  2020. if (code <= 90) return true;
  2021. if (code < 97) return code === 95;
  2022. if (code <= 122) return true;
  2023. if (code <= 0xffff) {
  2024. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  2025. }
  2026. return isInAstralSet(code, astralIdentifierStartCodes);
  2027. }
  2028. function isIdentifierChar(code) {
  2029. if (code < 48) return code === 36;
  2030. if (code < 58) return true;
  2031. if (code < 65) return false;
  2032. if (code <= 90) return true;
  2033. if (code < 97) return code === 95;
  2034. if (code <= 122) return true;
  2035. if (code <= 0xffff) {
  2036. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  2037. }
  2038. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  2039. }
  2040. const reservedWords = {
  2041. keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"],
  2042. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  2043. strictBind: ["eval", "arguments"]
  2044. };
  2045. const keywords = new Set(reservedWords.keyword);
  2046. const reservedWordsStrictSet = new Set(reservedWords.strict);
  2047. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  2048. function isReservedWord(word, inModule) {
  2049. return inModule && word === "await" || word === "enum";
  2050. }
  2051. function isStrictReservedWord(word, inModule) {
  2052. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  2053. }
  2054. function isStrictBindOnlyReservedWord(word) {
  2055. return reservedWordsStrictBindSet.has(word);
  2056. }
  2057. function isStrictBindReservedWord(word, inModule) {
  2058. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  2059. }
  2060. function isKeyword(word) {
  2061. return keywords.has(word);
  2062. }
  2063. function isIteratorStart(current, next, next2) {
  2064. return current === 64 && next === 64 && isIdentifierStart(next2);
  2065. }
  2066. const reservedWordLikeSet = new Set(["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete", "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield", "eval", "arguments", "enum", "await"]);
  2067. function canBeReservedWord(word) {
  2068. return reservedWordLikeSet.has(word);
  2069. }
  2070. const SCOPE_OTHER = 0b000000000,
  2071. SCOPE_PROGRAM = 0b000000001,
  2072. SCOPE_FUNCTION = 0b000000010,
  2073. SCOPE_ARROW = 0b000000100,
  2074. SCOPE_SIMPLE_CATCH = 0b000001000,
  2075. SCOPE_SUPER = 0b000010000,
  2076. SCOPE_DIRECT_SUPER = 0b000100000,
  2077. SCOPE_CLASS = 0b001000000,
  2078. SCOPE_STATIC_BLOCK = 0b010000000,
  2079. SCOPE_TS_MODULE = 0b100000000,
  2080. SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_STATIC_BLOCK | SCOPE_TS_MODULE;
  2081. const BIND_KIND_VALUE = 0b0000000000001,
  2082. BIND_KIND_TYPE = 0b0000000000010,
  2083. BIND_SCOPE_VAR = 0b0000000000100,
  2084. BIND_SCOPE_LEXICAL = 0b0000000001000,
  2085. BIND_SCOPE_FUNCTION = 0b0000000010000,
  2086. BIND_FLAGS_NONE = 0b00000001000000,
  2087. BIND_FLAGS_CLASS = 0b00000010000000,
  2088. BIND_FLAGS_TS_ENUM = 0b00000100000000,
  2089. BIND_FLAGS_TS_CONST_ENUM = 0b00001000000000,
  2090. BIND_FLAGS_TS_EXPORT_ONLY = 0b00010000000000,
  2091. BIND_FLAGS_FLOW_DECLARE_FN = 0b00100000000000,
  2092. BIND_FLAGS_TS_IMPORT = 0b01000000000000,
  2093. BIND_FLAGS_NO_LET_IN_LEXICAL = 0b10000000000000;
  2094. const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_CLASS | BIND_FLAGS_NO_LET_IN_LEXICAL,
  2095. BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | BIND_FLAGS_NO_LET_IN_LEXICAL,
  2096. BIND_CATCH_PARAM = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0,
  2097. BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0,
  2098. BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0,
  2099. BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS,
  2100. BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0,
  2101. BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM | BIND_FLAGS_NO_LET_IN_LEXICAL,
  2102. BIND_TS_AMBIENT = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  2103. BIND_NONE = 0 | 0 | 0 | BIND_FLAGS_NONE,
  2104. BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE,
  2105. BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM,
  2106. BIND_TS_NAMESPACE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  2107. BIND_TS_TYPE_IMPORT = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_TS_IMPORT,
  2108. BIND_FLOW_DECLARE_FN = BIND_FLAGS_FLOW_DECLARE_FN;
  2109. const CLASS_ELEMENT_FLAG_STATIC = 0b100,
  2110. CLASS_ELEMENT_KIND_GETTER = 0b010,
  2111. CLASS_ELEMENT_KIND_SETTER = 0b001,
  2112. CLASS_ELEMENT_KIND_ACCESSOR = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_KIND_SETTER;
  2113. const CLASS_ELEMENT_STATIC_GETTER = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_FLAG_STATIC,
  2114. CLASS_ELEMENT_STATIC_SETTER = CLASS_ELEMENT_KIND_SETTER | CLASS_ELEMENT_FLAG_STATIC,
  2115. CLASS_ELEMENT_INSTANCE_GETTER = CLASS_ELEMENT_KIND_GETTER,
  2116. CLASS_ELEMENT_INSTANCE_SETTER = CLASS_ELEMENT_KIND_SETTER,
  2117. CLASS_ELEMENT_OTHER = 0;
  2118. class Scope {
  2119. constructor(flags) {
  2120. this.var = new Set();
  2121. this.lexical = new Set();
  2122. this.functions = new Set();
  2123. this.flags = flags;
  2124. }
  2125. }
  2126. class ScopeHandler {
  2127. constructor(parser, inModule) {
  2128. this.parser = void 0;
  2129. this.scopeStack = [];
  2130. this.inModule = void 0;
  2131. this.undefinedExports = new Map();
  2132. this.parser = parser;
  2133. this.inModule = inModule;
  2134. }
  2135. get inTopLevel() {
  2136. return (this.currentScope().flags & SCOPE_PROGRAM) > 0;
  2137. }
  2138. get inFunction() {
  2139. return (this.currentVarScopeFlags() & SCOPE_FUNCTION) > 0;
  2140. }
  2141. get allowSuper() {
  2142. return (this.currentThisScopeFlags() & SCOPE_SUPER) > 0;
  2143. }
  2144. get allowDirectSuper() {
  2145. return (this.currentThisScopeFlags() & SCOPE_DIRECT_SUPER) > 0;
  2146. }
  2147. get inClass() {
  2148. return (this.currentThisScopeFlags() & SCOPE_CLASS) > 0;
  2149. }
  2150. get inClassAndNotInNonArrowFunction() {
  2151. const flags = this.currentThisScopeFlags();
  2152. return (flags & SCOPE_CLASS) > 0 && (flags & SCOPE_FUNCTION) === 0;
  2153. }
  2154. get inStaticBlock() {
  2155. for (let i = this.scopeStack.length - 1;; i--) {
  2156. const {
  2157. flags
  2158. } = this.scopeStack[i];
  2159. if (flags & SCOPE_STATIC_BLOCK) {
  2160. return true;
  2161. }
  2162. if (flags & (SCOPE_VAR | SCOPE_CLASS)) {
  2163. return false;
  2164. }
  2165. }
  2166. }
  2167. get inNonArrowFunction() {
  2168. return (this.currentThisScopeFlags() & SCOPE_FUNCTION) > 0;
  2169. }
  2170. get treatFunctionsAsVar() {
  2171. return this.treatFunctionsAsVarInScope(this.currentScope());
  2172. }
  2173. createScope(flags) {
  2174. return new Scope(flags);
  2175. }
  2176. enter(flags) {
  2177. this.scopeStack.push(this.createScope(flags));
  2178. }
  2179. exit() {
  2180. const scope = this.scopeStack.pop();
  2181. return scope.flags;
  2182. }
  2183. treatFunctionsAsVarInScope(scope) {
  2184. return !!(scope.flags & (SCOPE_FUNCTION | SCOPE_STATIC_BLOCK) || !this.parser.inModule && scope.flags & SCOPE_PROGRAM);
  2185. }
  2186. declareName(name, bindingType, loc) {
  2187. let scope = this.currentScope();
  2188. if (bindingType & BIND_SCOPE_LEXICAL || bindingType & BIND_SCOPE_FUNCTION) {
  2189. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  2190. if (bindingType & BIND_SCOPE_FUNCTION) {
  2191. scope.functions.add(name);
  2192. } else {
  2193. scope.lexical.add(name);
  2194. }
  2195. if (bindingType & BIND_SCOPE_LEXICAL) {
  2196. this.maybeExportDefined(scope, name);
  2197. }
  2198. } else if (bindingType & BIND_SCOPE_VAR) {
  2199. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  2200. scope = this.scopeStack[i];
  2201. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  2202. scope.var.add(name);
  2203. this.maybeExportDefined(scope, name);
  2204. if (scope.flags & SCOPE_VAR) break;
  2205. }
  2206. }
  2207. if (this.parser.inModule && scope.flags & SCOPE_PROGRAM) {
  2208. this.undefinedExports.delete(name);
  2209. }
  2210. }
  2211. maybeExportDefined(scope, name) {
  2212. if (this.parser.inModule && scope.flags & SCOPE_PROGRAM) {
  2213. this.undefinedExports.delete(name);
  2214. }
  2215. }
  2216. checkRedeclarationInScope(scope, name, bindingType, loc) {
  2217. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  2218. this.parser.raise(Errors.VarRedeclaration, {
  2219. at: loc,
  2220. identifierName: name
  2221. });
  2222. }
  2223. }
  2224. isRedeclaredInScope(scope, name, bindingType) {
  2225. if (!(bindingType & BIND_KIND_VALUE)) return false;
  2226. if (bindingType & BIND_SCOPE_LEXICAL) {
  2227. return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
  2228. }
  2229. if (bindingType & BIND_SCOPE_FUNCTION) {
  2230. return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
  2231. }
  2232. return scope.lexical.has(name) && !(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
  2233. }
  2234. checkLocalExport(id) {
  2235. const {
  2236. name
  2237. } = id;
  2238. const topLevelScope = this.scopeStack[0];
  2239. if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) {
  2240. this.undefinedExports.set(name, id.loc.start);
  2241. }
  2242. }
  2243. currentScope() {
  2244. return this.scopeStack[this.scopeStack.length - 1];
  2245. }
  2246. currentVarScopeFlags() {
  2247. for (let i = this.scopeStack.length - 1;; i--) {
  2248. const {
  2249. flags
  2250. } = this.scopeStack[i];
  2251. if (flags & SCOPE_VAR) {
  2252. return flags;
  2253. }
  2254. }
  2255. }
  2256. currentThisScopeFlags() {
  2257. for (let i = this.scopeStack.length - 1;; i--) {
  2258. const {
  2259. flags
  2260. } = this.scopeStack[i];
  2261. if (flags & (SCOPE_VAR | SCOPE_CLASS) && !(flags & SCOPE_ARROW)) {
  2262. return flags;
  2263. }
  2264. }
  2265. }
  2266. }
  2267. class FlowScope extends Scope {
  2268. constructor(...args) {
  2269. super(...args);
  2270. this.declareFunctions = new Set();
  2271. }
  2272. }
  2273. class FlowScopeHandler extends ScopeHandler {
  2274. createScope(flags) {
  2275. return new FlowScope(flags);
  2276. }
  2277. declareName(name, bindingType, loc) {
  2278. const scope = this.currentScope();
  2279. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  2280. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  2281. this.maybeExportDefined(scope, name);
  2282. scope.declareFunctions.add(name);
  2283. return;
  2284. }
  2285. super.declareName(name, bindingType, loc);
  2286. }
  2287. isRedeclaredInScope(scope, name, bindingType) {
  2288. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  2289. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  2290. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  2291. }
  2292. return false;
  2293. }
  2294. checkLocalExport(id) {
  2295. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  2296. super.checkLocalExport(id);
  2297. }
  2298. }
  2299. }
  2300. class BaseParser {
  2301. constructor() {
  2302. this.sawUnambiguousESM = false;
  2303. this.ambiguousScriptDifferentAst = false;
  2304. }
  2305. hasPlugin(pluginConfig) {
  2306. if (typeof pluginConfig === "string") {
  2307. return this.plugins.has(pluginConfig);
  2308. } else {
  2309. const [pluginName, pluginOptions] = pluginConfig;
  2310. if (!this.hasPlugin(pluginName)) {
  2311. return false;
  2312. }
  2313. const actualOptions = this.plugins.get(pluginName);
  2314. for (const key of Object.keys(pluginOptions)) {
  2315. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  2316. return false;
  2317. }
  2318. }
  2319. return true;
  2320. }
  2321. }
  2322. getPluginOption(plugin, name) {
  2323. var _this$plugins$get;
  2324. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  2325. }
  2326. }
  2327. function setTrailingComments(node, comments) {
  2328. if (node.trailingComments === undefined) {
  2329. node.trailingComments = comments;
  2330. } else {
  2331. node.trailingComments.unshift(...comments);
  2332. }
  2333. }
  2334. function setLeadingComments(node, comments) {
  2335. if (node.leadingComments === undefined) {
  2336. node.leadingComments = comments;
  2337. } else {
  2338. node.leadingComments.unshift(...comments);
  2339. }
  2340. }
  2341. function setInnerComments(node, comments) {
  2342. if (node.innerComments === undefined) {
  2343. node.innerComments = comments;
  2344. } else {
  2345. node.innerComments.unshift(...comments);
  2346. }
  2347. }
  2348. function adjustInnerComments(node, elements, commentWS) {
  2349. let lastElement = null;
  2350. let i = elements.length;
  2351. while (lastElement === null && i > 0) {
  2352. lastElement = elements[--i];
  2353. }
  2354. if (lastElement === null || lastElement.start > commentWS.start) {
  2355. setInnerComments(node, commentWS.comments);
  2356. } else {
  2357. setTrailingComments(lastElement, commentWS.comments);
  2358. }
  2359. }
  2360. class CommentsParser extends BaseParser {
  2361. addComment(comment) {
  2362. if (this.filename) comment.loc.filename = this.filename;
  2363. this.state.comments.push(comment);
  2364. }
  2365. processComment(node) {
  2366. const {
  2367. commentStack
  2368. } = this.state;
  2369. const commentStackLength = commentStack.length;
  2370. if (commentStackLength === 0) return;
  2371. let i = commentStackLength - 1;
  2372. const lastCommentWS = commentStack[i];
  2373. if (lastCommentWS.start === node.end) {
  2374. lastCommentWS.leadingNode = node;
  2375. i--;
  2376. }
  2377. const {
  2378. start: nodeStart
  2379. } = node;
  2380. for (; i >= 0; i--) {
  2381. const commentWS = commentStack[i];
  2382. const commentEnd = commentWS.end;
  2383. if (commentEnd > nodeStart) {
  2384. commentWS.containingNode = node;
  2385. this.finalizeComment(commentWS);
  2386. commentStack.splice(i, 1);
  2387. } else {
  2388. if (commentEnd === nodeStart) {
  2389. commentWS.trailingNode = node;
  2390. }
  2391. break;
  2392. }
  2393. }
  2394. }
  2395. finalizeComment(commentWS) {
  2396. const {
  2397. comments
  2398. } = commentWS;
  2399. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  2400. if (commentWS.leadingNode !== null) {
  2401. setTrailingComments(commentWS.leadingNode, comments);
  2402. }
  2403. if (commentWS.trailingNode !== null) {
  2404. setLeadingComments(commentWS.trailingNode, comments);
  2405. }
  2406. } else {
  2407. const {
  2408. containingNode: node,
  2409. start: commentStart
  2410. } = commentWS;
  2411. if (this.input.charCodeAt(commentStart - 1) === 44) {
  2412. switch (node.type) {
  2413. case "ObjectExpression":
  2414. case "ObjectPattern":
  2415. case "RecordExpression":
  2416. adjustInnerComments(node, node.properties, commentWS);
  2417. break;
  2418. case "CallExpression":
  2419. case "OptionalCallExpression":
  2420. adjustInnerComments(node, node.arguments, commentWS);
  2421. break;
  2422. case "FunctionDeclaration":
  2423. case "FunctionExpression":
  2424. case "ArrowFunctionExpression":
  2425. case "ObjectMethod":
  2426. case "ClassMethod":
  2427. case "ClassPrivateMethod":
  2428. adjustInnerComments(node, node.params, commentWS);
  2429. break;
  2430. case "ArrayExpression":
  2431. case "ArrayPattern":
  2432. case "TupleExpression":
  2433. adjustInnerComments(node, node.elements, commentWS);
  2434. break;
  2435. case "ExportNamedDeclaration":
  2436. case "ImportDeclaration":
  2437. adjustInnerComments(node, node.specifiers, commentWS);
  2438. break;
  2439. default:
  2440. {
  2441. setInnerComments(node, comments);
  2442. }
  2443. }
  2444. } else {
  2445. setInnerComments(node, comments);
  2446. }
  2447. }
  2448. }
  2449. finalizeRemainingComments() {
  2450. const {
  2451. commentStack
  2452. } = this.state;
  2453. for (let i = commentStack.length - 1; i >= 0; i--) {
  2454. this.finalizeComment(commentStack[i]);
  2455. }
  2456. this.state.commentStack = [];
  2457. }
  2458. resetPreviousNodeTrailingComments(node) {
  2459. const {
  2460. commentStack
  2461. } = this.state;
  2462. const {
  2463. length
  2464. } = commentStack;
  2465. if (length === 0) return;
  2466. const commentWS = commentStack[length - 1];
  2467. if (commentWS.leadingNode === node) {
  2468. commentWS.leadingNode = null;
  2469. }
  2470. }
  2471. takeSurroundingComments(node, start, end) {
  2472. const {
  2473. commentStack
  2474. } = this.state;
  2475. const commentStackLength = commentStack.length;
  2476. if (commentStackLength === 0) return;
  2477. let i = commentStackLength - 1;
  2478. for (; i >= 0; i--) {
  2479. const commentWS = commentStack[i];
  2480. const commentEnd = commentWS.end;
  2481. const commentStart = commentWS.start;
  2482. if (commentStart === end) {
  2483. commentWS.leadingNode = node;
  2484. } else if (commentEnd === start) {
  2485. commentWS.trailingNode = node;
  2486. } else if (commentEnd < start) {
  2487. break;
  2488. }
  2489. }
  2490. }
  2491. }
  2492. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  2493. const lineBreakG = new RegExp(lineBreak.source, "g");
  2494. function isNewLine(code) {
  2495. switch (code) {
  2496. case 10:
  2497. case 13:
  2498. case 8232:
  2499. case 8233:
  2500. return true;
  2501. default:
  2502. return false;
  2503. }
  2504. }
  2505. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  2506. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/y;
  2507. const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  2508. function isWhitespace(code) {
  2509. switch (code) {
  2510. case 0x0009:
  2511. case 0x000b:
  2512. case 0x000c:
  2513. case 32:
  2514. case 160:
  2515. case 5760:
  2516. case 0x2000:
  2517. case 0x2001:
  2518. case 0x2002:
  2519. case 0x2003:
  2520. case 0x2004:
  2521. case 0x2005:
  2522. case 0x2006:
  2523. case 0x2007:
  2524. case 0x2008:
  2525. case 0x2009:
  2526. case 0x200a:
  2527. case 0x202f:
  2528. case 0x205f:
  2529. case 0x3000:
  2530. case 0xfeff:
  2531. return true;
  2532. default:
  2533. return false;
  2534. }
  2535. }
  2536. class State {
  2537. constructor() {
  2538. this.strict = void 0;
  2539. this.curLine = void 0;
  2540. this.lineStart = void 0;
  2541. this.startLoc = void 0;
  2542. this.endLoc = void 0;
  2543. this.errors = [];
  2544. this.potentialArrowAt = -1;
  2545. this.noArrowAt = [];
  2546. this.noArrowParamsConversionAt = [];
  2547. this.maybeInArrowParameters = false;
  2548. this.inType = false;
  2549. this.noAnonFunctionType = false;
  2550. this.hasFlowComment = false;
  2551. this.isAmbientContext = false;
  2552. this.inAbstractClass = false;
  2553. this.inDisallowConditionalTypesContext = false;
  2554. this.topicContext = {
  2555. maxNumOfResolvableTopics: 0,
  2556. maxTopicIndex: null
  2557. };
  2558. this.soloAwait = false;
  2559. this.inFSharpPipelineDirectBody = false;
  2560. this.labels = [];
  2561. this.comments = [];
  2562. this.commentStack = [];
  2563. this.pos = 0;
  2564. this.type = 137;
  2565. this.value = null;
  2566. this.start = 0;
  2567. this.end = 0;
  2568. this.lastTokEndLoc = null;
  2569. this.lastTokStartLoc = null;
  2570. this.lastTokStart = 0;
  2571. this.context = [types$1.brace];
  2572. this.canStartJSXElement = true;
  2573. this.containsEsc = false;
  2574. this.firstInvalidTemplateEscapePos = null;
  2575. this.strictErrors = new Map();
  2576. this.tokensLength = 0;
  2577. }
  2578. init({
  2579. strictMode,
  2580. sourceType,
  2581. startLine,
  2582. startColumn
  2583. }) {
  2584. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  2585. this.curLine = startLine;
  2586. this.lineStart = -startColumn;
  2587. this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
  2588. }
  2589. curPosition() {
  2590. return new Position(this.curLine, this.pos - this.lineStart, this.pos);
  2591. }
  2592. clone(skipArrays) {
  2593. const state = new State();
  2594. const keys = Object.keys(this);
  2595. for (let i = 0, length = keys.length; i < length; i++) {
  2596. const key = keys[i];
  2597. let val = this[key];
  2598. if (!skipArrays && Array.isArray(val)) {
  2599. val = val.slice();
  2600. }
  2601. state[key] = val;
  2602. }
  2603. return state;
  2604. }
  2605. }
  2606. var _isDigit = function isDigit(code) {
  2607. return code >= 48 && code <= 57;
  2608. };
  2609. const forbiddenNumericSeparatorSiblings = {
  2610. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  2611. hex: new Set([46, 88, 95, 120])
  2612. };
  2613. const isAllowedNumericSeparatorSibling = {
  2614. bin: ch => ch === 48 || ch === 49,
  2615. oct: ch => ch >= 48 && ch <= 55,
  2616. dec: ch => ch >= 48 && ch <= 57,
  2617. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  2618. };
  2619. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  2620. const initialPos = pos;
  2621. const initialLineStart = lineStart;
  2622. const initialCurLine = curLine;
  2623. let out = "";
  2624. let firstInvalidLoc = null;
  2625. let chunkStart = pos;
  2626. const {
  2627. length
  2628. } = input;
  2629. for (;;) {
  2630. if (pos >= length) {
  2631. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2632. out += input.slice(chunkStart, pos);
  2633. break;
  2634. }
  2635. const ch = input.charCodeAt(pos);
  2636. if (isStringEnd(type, ch, input, pos)) {
  2637. out += input.slice(chunkStart, pos);
  2638. break;
  2639. }
  2640. if (ch === 92) {
  2641. out += input.slice(chunkStart, pos);
  2642. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  2643. if (res.ch === null && !firstInvalidLoc) {
  2644. firstInvalidLoc = {
  2645. pos,
  2646. lineStart,
  2647. curLine
  2648. };
  2649. } else {
  2650. out += res.ch;
  2651. }
  2652. ({
  2653. pos,
  2654. lineStart,
  2655. curLine
  2656. } = res);
  2657. chunkStart = pos;
  2658. } else if (ch === 8232 || ch === 8233) {
  2659. ++pos;
  2660. ++curLine;
  2661. lineStart = pos;
  2662. } else if (ch === 10 || ch === 13) {
  2663. if (type === "template") {
  2664. out += input.slice(chunkStart, pos) + "\n";
  2665. ++pos;
  2666. if (ch === 13 && input.charCodeAt(pos) === 10) {
  2667. ++pos;
  2668. }
  2669. ++curLine;
  2670. chunkStart = lineStart = pos;
  2671. } else {
  2672. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2673. }
  2674. } else {
  2675. ++pos;
  2676. }
  2677. }
  2678. return {
  2679. pos,
  2680. str: out,
  2681. firstInvalidLoc,
  2682. lineStart,
  2683. curLine,
  2684. containsInvalid: !!firstInvalidLoc
  2685. };
  2686. }
  2687. function isStringEnd(type, ch, input, pos) {
  2688. if (type === "template") {
  2689. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  2690. }
  2691. return ch === (type === "double" ? 34 : 39);
  2692. }
  2693. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  2694. const throwOnInvalid = !inTemplate;
  2695. pos++;
  2696. const res = ch => ({
  2697. pos,
  2698. ch,
  2699. lineStart,
  2700. curLine
  2701. });
  2702. const ch = input.charCodeAt(pos++);
  2703. switch (ch) {
  2704. case 110:
  2705. return res("\n");
  2706. case 114:
  2707. return res("\r");
  2708. case 120:
  2709. {
  2710. let code;
  2711. ({
  2712. code,
  2713. pos
  2714. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2715. return res(code === null ? null : String.fromCharCode(code));
  2716. }
  2717. case 117:
  2718. {
  2719. let code;
  2720. ({
  2721. code,
  2722. pos
  2723. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2724. return res(code === null ? null : String.fromCodePoint(code));
  2725. }
  2726. case 116:
  2727. return res("\t");
  2728. case 98:
  2729. return res("\b");
  2730. case 118:
  2731. return res("\u000b");
  2732. case 102:
  2733. return res("\f");
  2734. case 13:
  2735. if (input.charCodeAt(pos) === 10) {
  2736. ++pos;
  2737. }
  2738. case 10:
  2739. lineStart = pos;
  2740. ++curLine;
  2741. case 8232:
  2742. case 8233:
  2743. return res("");
  2744. case 56:
  2745. case 57:
  2746. if (inTemplate) {
  2747. return res(null);
  2748. } else {
  2749. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2750. }
  2751. default:
  2752. if (ch >= 48 && ch <= 55) {
  2753. const startPos = pos - 1;
  2754. const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
  2755. let octalStr = match[0];
  2756. let octal = parseInt(octalStr, 8);
  2757. if (octal > 255) {
  2758. octalStr = octalStr.slice(0, -1);
  2759. octal = parseInt(octalStr, 8);
  2760. }
  2761. pos += octalStr.length - 1;
  2762. const next = input.charCodeAt(pos);
  2763. if (octalStr !== "0" || next === 56 || next === 57) {
  2764. if (inTemplate) {
  2765. return res(null);
  2766. } else {
  2767. errors.strictNumericEscape(startPos, lineStart, curLine);
  2768. }
  2769. }
  2770. return res(String.fromCharCode(octal));
  2771. }
  2772. return res(String.fromCharCode(ch));
  2773. }
  2774. }
  2775. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2776. const initialPos = pos;
  2777. let n;
  2778. ({
  2779. n,
  2780. pos
  2781. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2782. if (n === null) {
  2783. if (throwOnInvalid) {
  2784. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2785. } else {
  2786. pos = initialPos - 1;
  2787. }
  2788. }
  2789. return {
  2790. code: n,
  2791. pos
  2792. };
  2793. }
  2794. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2795. const start = pos;
  2796. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2797. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2798. let invalid = false;
  2799. let total = 0;
  2800. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2801. const code = input.charCodeAt(pos);
  2802. let val;
  2803. if (code === 95 && allowNumSeparator !== "bail") {
  2804. const prev = input.charCodeAt(pos - 1);
  2805. const next = input.charCodeAt(pos + 1);
  2806. if (!allowNumSeparator) {
  2807. if (bailOnError) return {
  2808. n: null,
  2809. pos
  2810. };
  2811. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2812. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2813. if (bailOnError) return {
  2814. n: null,
  2815. pos
  2816. };
  2817. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2818. }
  2819. ++pos;
  2820. continue;
  2821. }
  2822. if (code >= 97) {
  2823. val = code - 97 + 10;
  2824. } else if (code >= 65) {
  2825. val = code - 65 + 10;
  2826. } else if (_isDigit(code)) {
  2827. val = code - 48;
  2828. } else {
  2829. val = Infinity;
  2830. }
  2831. if (val >= radix) {
  2832. if (val <= 9 && bailOnError) {
  2833. return {
  2834. n: null,
  2835. pos
  2836. };
  2837. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2838. val = 0;
  2839. } else if (forceLen) {
  2840. val = 0;
  2841. invalid = true;
  2842. } else {
  2843. break;
  2844. }
  2845. }
  2846. ++pos;
  2847. total = total * radix + val;
  2848. }
  2849. if (pos === start || len != null && pos - start !== len || invalid) {
  2850. return {
  2851. n: null,
  2852. pos
  2853. };
  2854. }
  2855. return {
  2856. n: total,
  2857. pos
  2858. };
  2859. }
  2860. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2861. const ch = input.charCodeAt(pos);
  2862. let code;
  2863. if (ch === 123) {
  2864. ++pos;
  2865. ({
  2866. code,
  2867. pos
  2868. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2869. ++pos;
  2870. if (code !== null && code > 0x10ffff) {
  2871. if (throwOnInvalid) {
  2872. errors.invalidCodePoint(pos, lineStart, curLine);
  2873. } else {
  2874. return {
  2875. code: null,
  2876. pos
  2877. };
  2878. }
  2879. }
  2880. } else {
  2881. ({
  2882. code,
  2883. pos
  2884. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2885. }
  2886. return {
  2887. code,
  2888. pos
  2889. };
  2890. }
  2891. const _excluded = ["at"],
  2892. _excluded2 = ["at"];
  2893. function buildPosition(pos, lineStart, curLine) {
  2894. return new Position(curLine, pos - lineStart, pos);
  2895. }
  2896. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2897. class Token {
  2898. constructor(state) {
  2899. this.type = state.type;
  2900. this.value = state.value;
  2901. this.start = state.start;
  2902. this.end = state.end;
  2903. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2904. }
  2905. }
  2906. class Tokenizer extends CommentsParser {
  2907. constructor(options, input) {
  2908. super();
  2909. this.isLookahead = void 0;
  2910. this.tokens = [];
  2911. this.errorHandlers_readInt = {
  2912. invalidDigit: (pos, lineStart, curLine, radix) => {
  2913. if (!this.options.errorRecovery) return false;
  2914. this.raise(Errors.InvalidDigit, {
  2915. at: buildPosition(pos, lineStart, curLine),
  2916. radix
  2917. });
  2918. return true;
  2919. },
  2920. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2921. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2922. };
  2923. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2924. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2925. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2926. });
  2927. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2928. strictNumericEscape: (pos, lineStart, curLine) => {
  2929. this.recordStrictModeErrors(Errors.StrictNumericEscape, {
  2930. at: buildPosition(pos, lineStart, curLine)
  2931. });
  2932. },
  2933. unterminated: (pos, lineStart, curLine) => {
  2934. throw this.raise(Errors.UnterminatedString, {
  2935. at: buildPosition(pos - 1, lineStart, curLine)
  2936. });
  2937. }
  2938. });
  2939. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2940. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2941. unterminated: (pos, lineStart, curLine) => {
  2942. throw this.raise(Errors.UnterminatedTemplate, {
  2943. at: buildPosition(pos, lineStart, curLine)
  2944. });
  2945. }
  2946. });
  2947. this.state = new State();
  2948. this.state.init(options);
  2949. this.input = input;
  2950. this.length = input.length;
  2951. this.isLookahead = false;
  2952. }
  2953. pushToken(token) {
  2954. this.tokens.length = this.state.tokensLength;
  2955. this.tokens.push(token);
  2956. ++this.state.tokensLength;
  2957. }
  2958. next() {
  2959. this.checkKeywordEscapes();
  2960. if (this.options.tokens) {
  2961. this.pushToken(new Token(this.state));
  2962. }
  2963. this.state.lastTokStart = this.state.start;
  2964. this.state.lastTokEndLoc = this.state.endLoc;
  2965. this.state.lastTokStartLoc = this.state.startLoc;
  2966. this.nextToken();
  2967. }
  2968. eat(type) {
  2969. if (this.match(type)) {
  2970. this.next();
  2971. return true;
  2972. } else {
  2973. return false;
  2974. }
  2975. }
  2976. match(type) {
  2977. return this.state.type === type;
  2978. }
  2979. createLookaheadState(state) {
  2980. return {
  2981. pos: state.pos,
  2982. value: null,
  2983. type: state.type,
  2984. start: state.start,
  2985. end: state.end,
  2986. context: [this.curContext()],
  2987. inType: state.inType,
  2988. startLoc: state.startLoc,
  2989. lastTokEndLoc: state.lastTokEndLoc,
  2990. curLine: state.curLine,
  2991. lineStart: state.lineStart,
  2992. curPosition: state.curPosition
  2993. };
  2994. }
  2995. lookahead() {
  2996. const old = this.state;
  2997. this.state = this.createLookaheadState(old);
  2998. this.isLookahead = true;
  2999. this.nextToken();
  3000. this.isLookahead = false;
  3001. const curr = this.state;
  3002. this.state = old;
  3003. return curr;
  3004. }
  3005. nextTokenStart() {
  3006. return this.nextTokenStartSince(this.state.pos);
  3007. }
  3008. nextTokenStartSince(pos) {
  3009. skipWhiteSpace.lastIndex = pos;
  3010. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  3011. }
  3012. lookaheadCharCode() {
  3013. return this.input.charCodeAt(this.nextTokenStart());
  3014. }
  3015. codePointAtPos(pos) {
  3016. let cp = this.input.charCodeAt(pos);
  3017. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  3018. const trail = this.input.charCodeAt(pos);
  3019. if ((trail & 0xfc00) === 0xdc00) {
  3020. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  3021. }
  3022. }
  3023. return cp;
  3024. }
  3025. setStrict(strict) {
  3026. this.state.strict = strict;
  3027. if (strict) {
  3028. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, {
  3029. at
  3030. }));
  3031. this.state.strictErrors.clear();
  3032. }
  3033. }
  3034. curContext() {
  3035. return this.state.context[this.state.context.length - 1];
  3036. }
  3037. nextToken() {
  3038. this.skipSpace();
  3039. this.state.start = this.state.pos;
  3040. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  3041. if (this.state.pos >= this.length) {
  3042. this.finishToken(137);
  3043. return;
  3044. }
  3045. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  3046. }
  3047. skipBlockComment(commentEnd) {
  3048. let startLoc;
  3049. if (!this.isLookahead) startLoc = this.state.curPosition();
  3050. const start = this.state.pos;
  3051. const end = this.input.indexOf(commentEnd, start + 2);
  3052. if (end === -1) {
  3053. throw this.raise(Errors.UnterminatedComment, {
  3054. at: this.state.curPosition()
  3055. });
  3056. }
  3057. this.state.pos = end + commentEnd.length;
  3058. lineBreakG.lastIndex = start + 2;
  3059. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  3060. ++this.state.curLine;
  3061. this.state.lineStart = lineBreakG.lastIndex;
  3062. }
  3063. if (this.isLookahead) return;
  3064. const comment = {
  3065. type: "CommentBlock",
  3066. value: this.input.slice(start + 2, end),
  3067. start,
  3068. end: end + commentEnd.length,
  3069. loc: new SourceLocation(startLoc, this.state.curPosition())
  3070. };
  3071. if (this.options.tokens) this.pushToken(comment);
  3072. return comment;
  3073. }
  3074. skipLineComment(startSkip) {
  3075. const start = this.state.pos;
  3076. let startLoc;
  3077. if (!this.isLookahead) startLoc = this.state.curPosition();
  3078. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  3079. if (this.state.pos < this.length) {
  3080. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  3081. ch = this.input.charCodeAt(this.state.pos);
  3082. }
  3083. }
  3084. if (this.isLookahead) return;
  3085. const end = this.state.pos;
  3086. const value = this.input.slice(start + startSkip, end);
  3087. const comment = {
  3088. type: "CommentLine",
  3089. value,
  3090. start,
  3091. end,
  3092. loc: new SourceLocation(startLoc, this.state.curPosition())
  3093. };
  3094. if (this.options.tokens) this.pushToken(comment);
  3095. return comment;
  3096. }
  3097. skipSpace() {
  3098. const spaceStart = this.state.pos;
  3099. const comments = [];
  3100. loop: while (this.state.pos < this.length) {
  3101. const ch = this.input.charCodeAt(this.state.pos);
  3102. switch (ch) {
  3103. case 32:
  3104. case 160:
  3105. case 9:
  3106. ++this.state.pos;
  3107. break;
  3108. case 13:
  3109. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  3110. ++this.state.pos;
  3111. }
  3112. case 10:
  3113. case 8232:
  3114. case 8233:
  3115. ++this.state.pos;
  3116. ++this.state.curLine;
  3117. this.state.lineStart = this.state.pos;
  3118. break;
  3119. case 47:
  3120. switch (this.input.charCodeAt(this.state.pos + 1)) {
  3121. case 42:
  3122. {
  3123. const comment = this.skipBlockComment("*/");
  3124. if (comment !== undefined) {
  3125. this.addComment(comment);
  3126. if (this.options.attachComment) comments.push(comment);
  3127. }
  3128. break;
  3129. }
  3130. case 47:
  3131. {
  3132. const comment = this.skipLineComment(2);
  3133. if (comment !== undefined) {
  3134. this.addComment(comment);
  3135. if (this.options.attachComment) comments.push(comment);
  3136. }
  3137. break;
  3138. }
  3139. default:
  3140. break loop;
  3141. }
  3142. break;
  3143. default:
  3144. if (isWhitespace(ch)) {
  3145. ++this.state.pos;
  3146. } else if (ch === 45 && !this.inModule && this.options.annexB) {
  3147. const pos = this.state.pos;
  3148. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  3149. const comment = this.skipLineComment(3);
  3150. if (comment !== undefined) {
  3151. this.addComment(comment);
  3152. if (this.options.attachComment) comments.push(comment);
  3153. }
  3154. } else {
  3155. break loop;
  3156. }
  3157. } else if (ch === 60 && !this.inModule && this.options.annexB) {
  3158. const pos = this.state.pos;
  3159. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  3160. const comment = this.skipLineComment(4);
  3161. if (comment !== undefined) {
  3162. this.addComment(comment);
  3163. if (this.options.attachComment) comments.push(comment);
  3164. }
  3165. } else {
  3166. break loop;
  3167. }
  3168. } else {
  3169. break loop;
  3170. }
  3171. }
  3172. }
  3173. if (comments.length > 0) {
  3174. const end = this.state.pos;
  3175. const commentWhitespace = {
  3176. start: spaceStart,
  3177. end,
  3178. comments,
  3179. leadingNode: null,
  3180. trailingNode: null,
  3181. containingNode: null
  3182. };
  3183. this.state.commentStack.push(commentWhitespace);
  3184. }
  3185. }
  3186. finishToken(type, val) {
  3187. this.state.end = this.state.pos;
  3188. this.state.endLoc = this.state.curPosition();
  3189. const prevType = this.state.type;
  3190. this.state.type = type;
  3191. this.state.value = val;
  3192. if (!this.isLookahead) {
  3193. this.updateContext(prevType);
  3194. }
  3195. }
  3196. replaceToken(type) {
  3197. this.state.type = type;
  3198. this.updateContext();
  3199. }
  3200. readToken_numberSign() {
  3201. if (this.state.pos === 0 && this.readToken_interpreter()) {
  3202. return;
  3203. }
  3204. const nextPos = this.state.pos + 1;
  3205. const next = this.codePointAtPos(nextPos);
  3206. if (next >= 48 && next <= 57) {
  3207. throw this.raise(Errors.UnexpectedDigitAfterHash, {
  3208. at: this.state.curPosition()
  3209. });
  3210. }
  3211. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  3212. this.expectPlugin("recordAndTuple");
  3213. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  3214. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, {
  3215. at: this.state.curPosition()
  3216. });
  3217. }
  3218. this.state.pos += 2;
  3219. if (next === 123) {
  3220. this.finishToken(7);
  3221. } else {
  3222. this.finishToken(1);
  3223. }
  3224. } else if (isIdentifierStart(next)) {
  3225. ++this.state.pos;
  3226. this.finishToken(136, this.readWord1(next));
  3227. } else if (next === 92) {
  3228. ++this.state.pos;
  3229. this.finishToken(136, this.readWord1());
  3230. } else {
  3231. this.finishOp(27, 1);
  3232. }
  3233. }
  3234. readToken_dot() {
  3235. const next = this.input.charCodeAt(this.state.pos + 1);
  3236. if (next >= 48 && next <= 57) {
  3237. this.readNumber(true);
  3238. return;
  3239. }
  3240. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  3241. this.state.pos += 3;
  3242. this.finishToken(21);
  3243. } else {
  3244. ++this.state.pos;
  3245. this.finishToken(16);
  3246. }
  3247. }
  3248. readToken_slash() {
  3249. const next = this.input.charCodeAt(this.state.pos + 1);
  3250. if (next === 61) {
  3251. this.finishOp(31, 2);
  3252. } else {
  3253. this.finishOp(56, 1);
  3254. }
  3255. }
  3256. readToken_interpreter() {
  3257. if (this.state.pos !== 0 || this.length < 2) return false;
  3258. let ch = this.input.charCodeAt(this.state.pos + 1);
  3259. if (ch !== 33) return false;
  3260. const start = this.state.pos;
  3261. this.state.pos += 1;
  3262. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  3263. ch = this.input.charCodeAt(this.state.pos);
  3264. }
  3265. const value = this.input.slice(start + 2, this.state.pos);
  3266. this.finishToken(28, value);
  3267. return true;
  3268. }
  3269. readToken_mult_modulo(code) {
  3270. let type = code === 42 ? 55 : 54;
  3271. let width = 1;
  3272. let next = this.input.charCodeAt(this.state.pos + 1);
  3273. if (code === 42 && next === 42) {
  3274. width++;
  3275. next = this.input.charCodeAt(this.state.pos + 2);
  3276. type = 57;
  3277. }
  3278. if (next === 61 && !this.state.inType) {
  3279. width++;
  3280. type = code === 37 ? 33 : 30;
  3281. }
  3282. this.finishOp(type, width);
  3283. }
  3284. readToken_pipe_amp(code) {
  3285. const next = this.input.charCodeAt(this.state.pos + 1);
  3286. if (next === code) {
  3287. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  3288. this.finishOp(30, 3);
  3289. } else {
  3290. this.finishOp(code === 124 ? 41 : 42, 2);
  3291. }
  3292. return;
  3293. }
  3294. if (code === 124) {
  3295. if (next === 62) {
  3296. this.finishOp(39, 2);
  3297. return;
  3298. }
  3299. if (this.hasPlugin("recordAndTuple") && next === 125) {
  3300. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  3301. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, {
  3302. at: this.state.curPosition()
  3303. });
  3304. }
  3305. this.state.pos += 2;
  3306. this.finishToken(9);
  3307. return;
  3308. }
  3309. if (this.hasPlugin("recordAndTuple") && next === 93) {
  3310. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  3311. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, {
  3312. at: this.state.curPosition()
  3313. });
  3314. }
  3315. this.state.pos += 2;
  3316. this.finishToken(4);
  3317. return;
  3318. }
  3319. }
  3320. if (next === 61) {
  3321. this.finishOp(30, 2);
  3322. return;
  3323. }
  3324. this.finishOp(code === 124 ? 43 : 45, 1);
  3325. }
  3326. readToken_caret() {
  3327. const next = this.input.charCodeAt(this.state.pos + 1);
  3328. if (next === 61 && !this.state.inType) {
  3329. this.finishOp(32, 2);
  3330. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  3331. proposal: "hack",
  3332. topicToken: "^^"
  3333. }])) {
  3334. this.finishOp(37, 2);
  3335. const lookaheadCh = this.input.codePointAt(this.state.pos);
  3336. if (lookaheadCh === 94) {
  3337. this.unexpected();
  3338. }
  3339. } else {
  3340. this.finishOp(44, 1);
  3341. }
  3342. }
  3343. readToken_atSign() {
  3344. const next = this.input.charCodeAt(this.state.pos + 1);
  3345. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  3346. proposal: "hack",
  3347. topicToken: "@@"
  3348. }])) {
  3349. this.finishOp(38, 2);
  3350. } else {
  3351. this.finishOp(26, 1);
  3352. }
  3353. }
  3354. readToken_plus_min(code) {
  3355. const next = this.input.charCodeAt(this.state.pos + 1);
  3356. if (next === code) {
  3357. this.finishOp(34, 2);
  3358. return;
  3359. }
  3360. if (next === 61) {
  3361. this.finishOp(30, 2);
  3362. } else {
  3363. this.finishOp(53, 1);
  3364. }
  3365. }
  3366. readToken_lt() {
  3367. const {
  3368. pos
  3369. } = this.state;
  3370. const next = this.input.charCodeAt(pos + 1);
  3371. if (next === 60) {
  3372. if (this.input.charCodeAt(pos + 2) === 61) {
  3373. this.finishOp(30, 3);
  3374. return;
  3375. }
  3376. this.finishOp(51, 2);
  3377. return;
  3378. }
  3379. if (next === 61) {
  3380. this.finishOp(49, 2);
  3381. return;
  3382. }
  3383. this.finishOp(47, 1);
  3384. }
  3385. readToken_gt() {
  3386. const {
  3387. pos
  3388. } = this.state;
  3389. const next = this.input.charCodeAt(pos + 1);
  3390. if (next === 62) {
  3391. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  3392. if (this.input.charCodeAt(pos + size) === 61) {
  3393. this.finishOp(30, size + 1);
  3394. return;
  3395. }
  3396. this.finishOp(52, size);
  3397. return;
  3398. }
  3399. if (next === 61) {
  3400. this.finishOp(49, 2);
  3401. return;
  3402. }
  3403. this.finishOp(48, 1);
  3404. }
  3405. readToken_eq_excl(code) {
  3406. const next = this.input.charCodeAt(this.state.pos + 1);
  3407. if (next === 61) {
  3408. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  3409. return;
  3410. }
  3411. if (code === 61 && next === 62) {
  3412. this.state.pos += 2;
  3413. this.finishToken(19);
  3414. return;
  3415. }
  3416. this.finishOp(code === 61 ? 29 : 35, 1);
  3417. }
  3418. readToken_question() {
  3419. const next = this.input.charCodeAt(this.state.pos + 1);
  3420. const next2 = this.input.charCodeAt(this.state.pos + 2);
  3421. if (next === 63) {
  3422. if (next2 === 61) {
  3423. this.finishOp(30, 3);
  3424. } else {
  3425. this.finishOp(40, 2);
  3426. }
  3427. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  3428. this.state.pos += 2;
  3429. this.finishToken(18);
  3430. } else {
  3431. ++this.state.pos;
  3432. this.finishToken(17);
  3433. }
  3434. }
  3435. getTokenFromCode(code) {
  3436. switch (code) {
  3437. case 46:
  3438. this.readToken_dot();
  3439. return;
  3440. case 40:
  3441. ++this.state.pos;
  3442. this.finishToken(10);
  3443. return;
  3444. case 41:
  3445. ++this.state.pos;
  3446. this.finishToken(11);
  3447. return;
  3448. case 59:
  3449. ++this.state.pos;
  3450. this.finishToken(13);
  3451. return;
  3452. case 44:
  3453. ++this.state.pos;
  3454. this.finishToken(12);
  3455. return;
  3456. case 91:
  3457. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  3458. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  3459. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, {
  3460. at: this.state.curPosition()
  3461. });
  3462. }
  3463. this.state.pos += 2;
  3464. this.finishToken(2);
  3465. } else {
  3466. ++this.state.pos;
  3467. this.finishToken(0);
  3468. }
  3469. return;
  3470. case 93:
  3471. ++this.state.pos;
  3472. this.finishToken(3);
  3473. return;
  3474. case 123:
  3475. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  3476. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  3477. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, {
  3478. at: this.state.curPosition()
  3479. });
  3480. }
  3481. this.state.pos += 2;
  3482. this.finishToken(6);
  3483. } else {
  3484. ++this.state.pos;
  3485. this.finishToken(5);
  3486. }
  3487. return;
  3488. case 125:
  3489. ++this.state.pos;
  3490. this.finishToken(8);
  3491. return;
  3492. case 58:
  3493. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  3494. this.finishOp(15, 2);
  3495. } else {
  3496. ++this.state.pos;
  3497. this.finishToken(14);
  3498. }
  3499. return;
  3500. case 63:
  3501. this.readToken_question();
  3502. return;
  3503. case 96:
  3504. this.readTemplateToken();
  3505. return;
  3506. case 48:
  3507. {
  3508. const next = this.input.charCodeAt(this.state.pos + 1);
  3509. if (next === 120 || next === 88) {
  3510. this.readRadixNumber(16);
  3511. return;
  3512. }
  3513. if (next === 111 || next === 79) {
  3514. this.readRadixNumber(8);
  3515. return;
  3516. }
  3517. if (next === 98 || next === 66) {
  3518. this.readRadixNumber(2);
  3519. return;
  3520. }
  3521. }
  3522. case 49:
  3523. case 50:
  3524. case 51:
  3525. case 52:
  3526. case 53:
  3527. case 54:
  3528. case 55:
  3529. case 56:
  3530. case 57:
  3531. this.readNumber(false);
  3532. return;
  3533. case 34:
  3534. case 39:
  3535. this.readString(code);
  3536. return;
  3537. case 47:
  3538. this.readToken_slash();
  3539. return;
  3540. case 37:
  3541. case 42:
  3542. this.readToken_mult_modulo(code);
  3543. return;
  3544. case 124:
  3545. case 38:
  3546. this.readToken_pipe_amp(code);
  3547. return;
  3548. case 94:
  3549. this.readToken_caret();
  3550. return;
  3551. case 43:
  3552. case 45:
  3553. this.readToken_plus_min(code);
  3554. return;
  3555. case 60:
  3556. this.readToken_lt();
  3557. return;
  3558. case 62:
  3559. this.readToken_gt();
  3560. return;
  3561. case 61:
  3562. case 33:
  3563. this.readToken_eq_excl(code);
  3564. return;
  3565. case 126:
  3566. this.finishOp(36, 1);
  3567. return;
  3568. case 64:
  3569. this.readToken_atSign();
  3570. return;
  3571. case 35:
  3572. this.readToken_numberSign();
  3573. return;
  3574. case 92:
  3575. this.readWord();
  3576. return;
  3577. default:
  3578. if (isIdentifierStart(code)) {
  3579. this.readWord(code);
  3580. return;
  3581. }
  3582. }
  3583. throw this.raise(Errors.InvalidOrUnexpectedToken, {
  3584. at: this.state.curPosition(),
  3585. unexpected: String.fromCodePoint(code)
  3586. });
  3587. }
  3588. finishOp(type, size) {
  3589. const str = this.input.slice(this.state.pos, this.state.pos + size);
  3590. this.state.pos += size;
  3591. this.finishToken(type, str);
  3592. }
  3593. readRegexp() {
  3594. const startLoc = this.state.startLoc;
  3595. const start = this.state.start + 1;
  3596. let escaped, inClass;
  3597. let {
  3598. pos
  3599. } = this.state;
  3600. for (;; ++pos) {
  3601. if (pos >= this.length) {
  3602. throw this.raise(Errors.UnterminatedRegExp, {
  3603. at: createPositionWithColumnOffset(startLoc, 1)
  3604. });
  3605. }
  3606. const ch = this.input.charCodeAt(pos);
  3607. if (isNewLine(ch)) {
  3608. throw this.raise(Errors.UnterminatedRegExp, {
  3609. at: createPositionWithColumnOffset(startLoc, 1)
  3610. });
  3611. }
  3612. if (escaped) {
  3613. escaped = false;
  3614. } else {
  3615. if (ch === 91) {
  3616. inClass = true;
  3617. } else if (ch === 93 && inClass) {
  3618. inClass = false;
  3619. } else if (ch === 47 && !inClass) {
  3620. break;
  3621. }
  3622. escaped = ch === 92;
  3623. }
  3624. }
  3625. const content = this.input.slice(start, pos);
  3626. ++pos;
  3627. let mods = "";
  3628. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  3629. while (pos < this.length) {
  3630. const cp = this.codePointAtPos(pos);
  3631. const char = String.fromCharCode(cp);
  3632. if (VALID_REGEX_FLAGS.has(cp)) {
  3633. if (cp === 118) {
  3634. this.expectPlugin("regexpUnicodeSets", nextPos());
  3635. if (mods.includes("u")) {
  3636. this.raise(Errors.IncompatibleRegExpUVFlags, {
  3637. at: nextPos()
  3638. });
  3639. }
  3640. } else if (cp === 117) {
  3641. if (mods.includes("v")) {
  3642. this.raise(Errors.IncompatibleRegExpUVFlags, {
  3643. at: nextPos()
  3644. });
  3645. }
  3646. }
  3647. if (mods.includes(char)) {
  3648. this.raise(Errors.DuplicateRegExpFlags, {
  3649. at: nextPos()
  3650. });
  3651. }
  3652. } else if (isIdentifierChar(cp) || cp === 92) {
  3653. this.raise(Errors.MalformedRegExpFlags, {
  3654. at: nextPos()
  3655. });
  3656. } else {
  3657. break;
  3658. }
  3659. ++pos;
  3660. mods += char;
  3661. }
  3662. this.state.pos = pos;
  3663. this.finishToken(135, {
  3664. pattern: content,
  3665. flags: mods
  3666. });
  3667. }
  3668. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  3669. const {
  3670. n,
  3671. pos
  3672. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  3673. this.state.pos = pos;
  3674. return n;
  3675. }
  3676. readRadixNumber(radix) {
  3677. const startLoc = this.state.curPosition();
  3678. let isBigInt = false;
  3679. this.state.pos += 2;
  3680. const val = this.readInt(radix);
  3681. if (val == null) {
  3682. this.raise(Errors.InvalidDigit, {
  3683. at: createPositionWithColumnOffset(startLoc, 2),
  3684. radix
  3685. });
  3686. }
  3687. const next = this.input.charCodeAt(this.state.pos);
  3688. if (next === 110) {
  3689. ++this.state.pos;
  3690. isBigInt = true;
  3691. } else if (next === 109) {
  3692. throw this.raise(Errors.InvalidDecimal, {
  3693. at: startLoc
  3694. });
  3695. }
  3696. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3697. throw this.raise(Errors.NumberIdentifier, {
  3698. at: this.state.curPosition()
  3699. });
  3700. }
  3701. if (isBigInt) {
  3702. const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
  3703. this.finishToken(133, str);
  3704. return;
  3705. }
  3706. this.finishToken(132, val);
  3707. }
  3708. readNumber(startsWithDot) {
  3709. const start = this.state.pos;
  3710. const startLoc = this.state.curPosition();
  3711. let isFloat = false;
  3712. let isBigInt = false;
  3713. let isDecimal = false;
  3714. let hasExponent = false;
  3715. let isOctal = false;
  3716. if (!startsWithDot && this.readInt(10) === null) {
  3717. this.raise(Errors.InvalidNumber, {
  3718. at: this.state.curPosition()
  3719. });
  3720. }
  3721. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3722. if (hasLeadingZero) {
  3723. const integer = this.input.slice(start, this.state.pos);
  3724. this.recordStrictModeErrors(Errors.StrictOctalLiteral, {
  3725. at: startLoc
  3726. });
  3727. if (!this.state.strict) {
  3728. const underscorePos = integer.indexOf("_");
  3729. if (underscorePos > 0) {
  3730. this.raise(Errors.ZeroDigitNumericSeparator, {
  3731. at: createPositionWithColumnOffset(startLoc, underscorePos)
  3732. });
  3733. }
  3734. }
  3735. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3736. }
  3737. let next = this.input.charCodeAt(this.state.pos);
  3738. if (next === 46 && !isOctal) {
  3739. ++this.state.pos;
  3740. this.readInt(10);
  3741. isFloat = true;
  3742. next = this.input.charCodeAt(this.state.pos);
  3743. }
  3744. if ((next === 69 || next === 101) && !isOctal) {
  3745. next = this.input.charCodeAt(++this.state.pos);
  3746. if (next === 43 || next === 45) {
  3747. ++this.state.pos;
  3748. }
  3749. if (this.readInt(10) === null) {
  3750. this.raise(Errors.InvalidOrMissingExponent, {
  3751. at: startLoc
  3752. });
  3753. }
  3754. isFloat = true;
  3755. hasExponent = true;
  3756. next = this.input.charCodeAt(this.state.pos);
  3757. }
  3758. if (next === 110) {
  3759. if (isFloat || hasLeadingZero) {
  3760. this.raise(Errors.InvalidBigIntLiteral, {
  3761. at: startLoc
  3762. });
  3763. }
  3764. ++this.state.pos;
  3765. isBigInt = true;
  3766. }
  3767. if (next === 109) {
  3768. this.expectPlugin("decimal", this.state.curPosition());
  3769. if (hasExponent || hasLeadingZero) {
  3770. this.raise(Errors.InvalidDecimal, {
  3771. at: startLoc
  3772. });
  3773. }
  3774. ++this.state.pos;
  3775. isDecimal = true;
  3776. }
  3777. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3778. throw this.raise(Errors.NumberIdentifier, {
  3779. at: this.state.curPosition()
  3780. });
  3781. }
  3782. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3783. if (isBigInt) {
  3784. this.finishToken(133, str);
  3785. return;
  3786. }
  3787. if (isDecimal) {
  3788. this.finishToken(134, str);
  3789. return;
  3790. }
  3791. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3792. this.finishToken(132, val);
  3793. }
  3794. readCodePoint(throwOnInvalid) {
  3795. const {
  3796. code,
  3797. pos
  3798. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3799. this.state.pos = pos;
  3800. return code;
  3801. }
  3802. readString(quote) {
  3803. const {
  3804. str,
  3805. pos,
  3806. curLine,
  3807. lineStart
  3808. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3809. this.state.pos = pos + 1;
  3810. this.state.lineStart = lineStart;
  3811. this.state.curLine = curLine;
  3812. this.finishToken(131, str);
  3813. }
  3814. readTemplateContinuation() {
  3815. if (!this.match(8)) {
  3816. this.unexpected(null, 8);
  3817. }
  3818. this.state.pos--;
  3819. this.readTemplateToken();
  3820. }
  3821. readTemplateToken() {
  3822. const opening = this.input[this.state.pos];
  3823. const {
  3824. str,
  3825. firstInvalidLoc,
  3826. pos,
  3827. curLine,
  3828. lineStart
  3829. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3830. this.state.pos = pos + 1;
  3831. this.state.lineStart = lineStart;
  3832. this.state.curLine = curLine;
  3833. if (firstInvalidLoc) {
  3834. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
  3835. }
  3836. if (this.input.codePointAt(pos) === 96) {
  3837. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3838. } else {
  3839. this.state.pos++;
  3840. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3841. }
  3842. }
  3843. recordStrictModeErrors(toParseError, {
  3844. at
  3845. }) {
  3846. const index = at.index;
  3847. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3848. this.raise(toParseError, {
  3849. at
  3850. });
  3851. } else {
  3852. this.state.strictErrors.set(index, [toParseError, at]);
  3853. }
  3854. }
  3855. readWord1(firstCode) {
  3856. this.state.containsEsc = false;
  3857. let word = "";
  3858. const start = this.state.pos;
  3859. let chunkStart = this.state.pos;
  3860. if (firstCode !== undefined) {
  3861. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3862. }
  3863. while (this.state.pos < this.length) {
  3864. const ch = this.codePointAtPos(this.state.pos);
  3865. if (isIdentifierChar(ch)) {
  3866. this.state.pos += ch <= 0xffff ? 1 : 2;
  3867. } else if (ch === 92) {
  3868. this.state.containsEsc = true;
  3869. word += this.input.slice(chunkStart, this.state.pos);
  3870. const escStart = this.state.curPosition();
  3871. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3872. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3873. this.raise(Errors.MissingUnicodeEscape, {
  3874. at: this.state.curPosition()
  3875. });
  3876. chunkStart = this.state.pos - 1;
  3877. continue;
  3878. }
  3879. ++this.state.pos;
  3880. const esc = this.readCodePoint(true);
  3881. if (esc !== null) {
  3882. if (!identifierCheck(esc)) {
  3883. this.raise(Errors.EscapedCharNotAnIdentifier, {
  3884. at: escStart
  3885. });
  3886. }
  3887. word += String.fromCodePoint(esc);
  3888. }
  3889. chunkStart = this.state.pos;
  3890. } else {
  3891. break;
  3892. }
  3893. }
  3894. return word + this.input.slice(chunkStart, this.state.pos);
  3895. }
  3896. readWord(firstCode) {
  3897. const word = this.readWord1(firstCode);
  3898. const type = keywords$1.get(word);
  3899. if (type !== undefined) {
  3900. this.finishToken(type, tokenLabelName(type));
  3901. } else {
  3902. this.finishToken(130, word);
  3903. }
  3904. }
  3905. checkKeywordEscapes() {
  3906. const {
  3907. type
  3908. } = this.state;
  3909. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3910. this.raise(Errors.InvalidEscapedReservedWord, {
  3911. at: this.state.startLoc,
  3912. reservedWord: tokenLabelName(type)
  3913. });
  3914. }
  3915. }
  3916. raise(toParseError, raiseProperties) {
  3917. const {
  3918. at
  3919. } = raiseProperties,
  3920. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded);
  3921. const loc = at instanceof Position ? at : at.loc.start;
  3922. const error = toParseError({
  3923. loc,
  3924. details
  3925. });
  3926. if (!this.options.errorRecovery) throw error;
  3927. if (!this.isLookahead) this.state.errors.push(error);
  3928. return error;
  3929. }
  3930. raiseOverwrite(toParseError, raiseProperties) {
  3931. const {
  3932. at
  3933. } = raiseProperties,
  3934. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2);
  3935. const loc = at instanceof Position ? at : at.loc.start;
  3936. const pos = loc.index;
  3937. const errors = this.state.errors;
  3938. for (let i = errors.length - 1; i >= 0; i--) {
  3939. const error = errors[i];
  3940. if (error.loc.index === pos) {
  3941. return errors[i] = toParseError({
  3942. loc,
  3943. details
  3944. });
  3945. }
  3946. if (error.loc.index < pos) break;
  3947. }
  3948. return this.raise(toParseError, raiseProperties);
  3949. }
  3950. updateContext(prevType) {}
  3951. unexpected(loc, type) {
  3952. throw this.raise(Errors.UnexpectedToken, {
  3953. expected: type ? tokenLabelName(type) : null,
  3954. at: loc != null ? loc : this.state.startLoc
  3955. });
  3956. }
  3957. expectPlugin(pluginName, loc) {
  3958. if (this.hasPlugin(pluginName)) {
  3959. return true;
  3960. }
  3961. throw this.raise(Errors.MissingPlugin, {
  3962. at: loc != null ? loc : this.state.startLoc,
  3963. missingPlugin: [pluginName]
  3964. });
  3965. }
  3966. expectOnePlugin(pluginNames) {
  3967. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3968. throw this.raise(Errors.MissingOneOfPlugins, {
  3969. at: this.state.startLoc,
  3970. missingPlugin: pluginNames
  3971. });
  3972. }
  3973. }
  3974. errorBuilder(error) {
  3975. return (pos, lineStart, curLine) => {
  3976. this.raise(error, {
  3977. at: buildPosition(pos, lineStart, curLine)
  3978. });
  3979. };
  3980. }
  3981. }
  3982. class ClassScope {
  3983. constructor() {
  3984. this.privateNames = new Set();
  3985. this.loneAccessors = new Map();
  3986. this.undefinedPrivateNames = new Map();
  3987. }
  3988. }
  3989. class ClassScopeHandler {
  3990. constructor(parser) {
  3991. this.parser = void 0;
  3992. this.stack = [];
  3993. this.undefinedPrivateNames = new Map();
  3994. this.parser = parser;
  3995. }
  3996. current() {
  3997. return this.stack[this.stack.length - 1];
  3998. }
  3999. enter() {
  4000. this.stack.push(new ClassScope());
  4001. }
  4002. exit() {
  4003. const oldClassScope = this.stack.pop();
  4004. const current = this.current();
  4005. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  4006. if (current) {
  4007. if (!current.undefinedPrivateNames.has(name)) {
  4008. current.undefinedPrivateNames.set(name, loc);
  4009. }
  4010. } else {
  4011. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  4012. at: loc,
  4013. identifierName: name
  4014. });
  4015. }
  4016. }
  4017. }
  4018. declarePrivateName(name, elementType, loc) {
  4019. const {
  4020. privateNames,
  4021. loneAccessors,
  4022. undefinedPrivateNames
  4023. } = this.current();
  4024. let redefined = privateNames.has(name);
  4025. if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) {
  4026. const accessor = redefined && loneAccessors.get(name);
  4027. if (accessor) {
  4028. const oldStatic = accessor & CLASS_ELEMENT_FLAG_STATIC;
  4029. const newStatic = elementType & CLASS_ELEMENT_FLAG_STATIC;
  4030. const oldKind = accessor & CLASS_ELEMENT_KIND_ACCESSOR;
  4031. const newKind = elementType & CLASS_ELEMENT_KIND_ACCESSOR;
  4032. redefined = oldKind === newKind || oldStatic !== newStatic;
  4033. if (!redefined) loneAccessors.delete(name);
  4034. } else if (!redefined) {
  4035. loneAccessors.set(name, elementType);
  4036. }
  4037. }
  4038. if (redefined) {
  4039. this.parser.raise(Errors.PrivateNameRedeclaration, {
  4040. at: loc,
  4041. identifierName: name
  4042. });
  4043. }
  4044. privateNames.add(name);
  4045. undefinedPrivateNames.delete(name);
  4046. }
  4047. usePrivateName(name, loc) {
  4048. let classScope;
  4049. for (classScope of this.stack) {
  4050. if (classScope.privateNames.has(name)) return;
  4051. }
  4052. if (classScope) {
  4053. classScope.undefinedPrivateNames.set(name, loc);
  4054. } else {
  4055. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  4056. at: loc,
  4057. identifierName: name
  4058. });
  4059. }
  4060. }
  4061. }
  4062. const kExpression = 0,
  4063. kMaybeArrowParameterDeclaration = 1,
  4064. kMaybeAsyncArrowParameterDeclaration = 2,
  4065. kParameterDeclaration = 3;
  4066. class ExpressionScope {
  4067. constructor(type = kExpression) {
  4068. this.type = void 0;
  4069. this.type = type;
  4070. }
  4071. canBeArrowParameterDeclaration() {
  4072. return this.type === kMaybeAsyncArrowParameterDeclaration || this.type === kMaybeArrowParameterDeclaration;
  4073. }
  4074. isCertainlyParameterDeclaration() {
  4075. return this.type === kParameterDeclaration;
  4076. }
  4077. }
  4078. class ArrowHeadParsingScope extends ExpressionScope {
  4079. constructor(type) {
  4080. super(type);
  4081. this.declarationErrors = new Map();
  4082. }
  4083. recordDeclarationError(ParsingErrorClass, {
  4084. at
  4085. }) {
  4086. const index = at.index;
  4087. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  4088. }
  4089. clearDeclarationError(index) {
  4090. this.declarationErrors.delete(index);
  4091. }
  4092. iterateErrors(iterator) {
  4093. this.declarationErrors.forEach(iterator);
  4094. }
  4095. }
  4096. class ExpressionScopeHandler {
  4097. constructor(parser) {
  4098. this.parser = void 0;
  4099. this.stack = [new ExpressionScope()];
  4100. this.parser = parser;
  4101. }
  4102. enter(scope) {
  4103. this.stack.push(scope);
  4104. }
  4105. exit() {
  4106. this.stack.pop();
  4107. }
  4108. recordParameterInitializerError(toParseError, {
  4109. at: node
  4110. }) {
  4111. const origin = {
  4112. at: node.loc.start
  4113. };
  4114. const {
  4115. stack
  4116. } = this;
  4117. let i = stack.length - 1;
  4118. let scope = stack[i];
  4119. while (!scope.isCertainlyParameterDeclaration()) {
  4120. if (scope.canBeArrowParameterDeclaration()) {
  4121. scope.recordDeclarationError(toParseError, origin);
  4122. } else {
  4123. return;
  4124. }
  4125. scope = stack[--i];
  4126. }
  4127. this.parser.raise(toParseError, origin);
  4128. }
  4129. recordArrowParameterBindingError(error, {
  4130. at: node
  4131. }) {
  4132. const {
  4133. stack
  4134. } = this;
  4135. const scope = stack[stack.length - 1];
  4136. const origin = {
  4137. at: node.loc.start
  4138. };
  4139. if (scope.isCertainlyParameterDeclaration()) {
  4140. this.parser.raise(error, origin);
  4141. } else if (scope.canBeArrowParameterDeclaration()) {
  4142. scope.recordDeclarationError(error, origin);
  4143. } else {
  4144. return;
  4145. }
  4146. }
  4147. recordAsyncArrowParametersError({
  4148. at
  4149. }) {
  4150. const {
  4151. stack
  4152. } = this;
  4153. let i = stack.length - 1;
  4154. let scope = stack[i];
  4155. while (scope.canBeArrowParameterDeclaration()) {
  4156. if (scope.type === kMaybeAsyncArrowParameterDeclaration) {
  4157. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, {
  4158. at
  4159. });
  4160. }
  4161. scope = stack[--i];
  4162. }
  4163. }
  4164. validateAsPattern() {
  4165. const {
  4166. stack
  4167. } = this;
  4168. const currentScope = stack[stack.length - 1];
  4169. if (!currentScope.canBeArrowParameterDeclaration()) return;
  4170. currentScope.iterateErrors(([toParseError, loc]) => {
  4171. this.parser.raise(toParseError, {
  4172. at: loc
  4173. });
  4174. let i = stack.length - 2;
  4175. let scope = stack[i];
  4176. while (scope.canBeArrowParameterDeclaration()) {
  4177. scope.clearDeclarationError(loc.index);
  4178. scope = stack[--i];
  4179. }
  4180. });
  4181. }
  4182. }
  4183. function newParameterDeclarationScope() {
  4184. return new ExpressionScope(kParameterDeclaration);
  4185. }
  4186. function newArrowHeadScope() {
  4187. return new ArrowHeadParsingScope(kMaybeArrowParameterDeclaration);
  4188. }
  4189. function newAsyncArrowScope() {
  4190. return new ArrowHeadParsingScope(kMaybeAsyncArrowParameterDeclaration);
  4191. }
  4192. function newExpressionScope() {
  4193. return new ExpressionScope();
  4194. }
  4195. const PARAM = 0b0000,
  4196. PARAM_YIELD = 0b0001,
  4197. PARAM_AWAIT = 0b0010,
  4198. PARAM_RETURN = 0b0100,
  4199. PARAM_IN = 0b1000;
  4200. class ProductionParameterHandler {
  4201. constructor() {
  4202. this.stacks = [];
  4203. }
  4204. enter(flags) {
  4205. this.stacks.push(flags);
  4206. }
  4207. exit() {
  4208. this.stacks.pop();
  4209. }
  4210. currentFlags() {
  4211. return this.stacks[this.stacks.length - 1];
  4212. }
  4213. get hasAwait() {
  4214. return (this.currentFlags() & PARAM_AWAIT) > 0;
  4215. }
  4216. get hasYield() {
  4217. return (this.currentFlags() & PARAM_YIELD) > 0;
  4218. }
  4219. get hasReturn() {
  4220. return (this.currentFlags() & PARAM_RETURN) > 0;
  4221. }
  4222. get hasIn() {
  4223. return (this.currentFlags() & PARAM_IN) > 0;
  4224. }
  4225. }
  4226. function functionFlags(isAsync, isGenerator) {
  4227. return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);
  4228. }
  4229. class UtilParser extends Tokenizer {
  4230. addExtra(node, key, value, enumerable = true) {
  4231. if (!node) return;
  4232. const extra = node.extra = node.extra || {};
  4233. if (enumerable) {
  4234. extra[key] = value;
  4235. } else {
  4236. Object.defineProperty(extra, key, {
  4237. enumerable,
  4238. value
  4239. });
  4240. }
  4241. }
  4242. isContextual(token) {
  4243. return this.state.type === token && !this.state.containsEsc;
  4244. }
  4245. isUnparsedContextual(nameStart, name) {
  4246. const nameEnd = nameStart + name.length;
  4247. if (this.input.slice(nameStart, nameEnd) === name) {
  4248. const nextCh = this.input.charCodeAt(nameEnd);
  4249. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  4250. }
  4251. return false;
  4252. }
  4253. isLookaheadContextual(name) {
  4254. const next = this.nextTokenStart();
  4255. return this.isUnparsedContextual(next, name);
  4256. }
  4257. eatContextual(token) {
  4258. if (this.isContextual(token)) {
  4259. this.next();
  4260. return true;
  4261. }
  4262. return false;
  4263. }
  4264. expectContextual(token, toParseError) {
  4265. if (!this.eatContextual(token)) {
  4266. if (toParseError != null) {
  4267. throw this.raise(toParseError, {
  4268. at: this.state.startLoc
  4269. });
  4270. }
  4271. this.unexpected(null, token);
  4272. }
  4273. }
  4274. canInsertSemicolon() {
  4275. return this.match(137) || this.match(8) || this.hasPrecedingLineBreak();
  4276. }
  4277. hasPrecedingLineBreak() {
  4278. return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
  4279. }
  4280. hasFollowingLineBreak() {
  4281. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  4282. return skipWhiteSpaceToLineBreak.test(this.input);
  4283. }
  4284. isLineTerminator() {
  4285. return this.eat(13) || this.canInsertSemicolon();
  4286. }
  4287. semicolon(allowAsi = true) {
  4288. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  4289. this.raise(Errors.MissingSemicolon, {
  4290. at: this.state.lastTokEndLoc
  4291. });
  4292. }
  4293. expect(type, loc) {
  4294. this.eat(type) || this.unexpected(loc, type);
  4295. }
  4296. tryParse(fn, oldState = this.state.clone()) {
  4297. const abortSignal = {
  4298. node: null
  4299. };
  4300. try {
  4301. const node = fn((node = null) => {
  4302. abortSignal.node = node;
  4303. throw abortSignal;
  4304. });
  4305. if (this.state.errors.length > oldState.errors.length) {
  4306. const failState = this.state;
  4307. this.state = oldState;
  4308. this.state.tokensLength = failState.tokensLength;
  4309. return {
  4310. node,
  4311. error: failState.errors[oldState.errors.length],
  4312. thrown: false,
  4313. aborted: false,
  4314. failState
  4315. };
  4316. }
  4317. return {
  4318. node,
  4319. error: null,
  4320. thrown: false,
  4321. aborted: false,
  4322. failState: null
  4323. };
  4324. } catch (error) {
  4325. const failState = this.state;
  4326. this.state = oldState;
  4327. if (error instanceof SyntaxError) {
  4328. return {
  4329. node: null,
  4330. error,
  4331. thrown: true,
  4332. aborted: false,
  4333. failState
  4334. };
  4335. }
  4336. if (error === abortSignal) {
  4337. return {
  4338. node: abortSignal.node,
  4339. error: null,
  4340. thrown: false,
  4341. aborted: true,
  4342. failState
  4343. };
  4344. }
  4345. throw error;
  4346. }
  4347. }
  4348. checkExpressionErrors(refExpressionErrors, andThrow) {
  4349. if (!refExpressionErrors) return false;
  4350. const {
  4351. shorthandAssignLoc,
  4352. doubleProtoLoc,
  4353. privateKeyLoc,
  4354. optionalParametersLoc
  4355. } = refExpressionErrors;
  4356. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  4357. if (!andThrow) {
  4358. return hasErrors;
  4359. }
  4360. if (shorthandAssignLoc != null) {
  4361. this.raise(Errors.InvalidCoverInitializedName, {
  4362. at: shorthandAssignLoc
  4363. });
  4364. }
  4365. if (doubleProtoLoc != null) {
  4366. this.raise(Errors.DuplicateProto, {
  4367. at: doubleProtoLoc
  4368. });
  4369. }
  4370. if (privateKeyLoc != null) {
  4371. this.raise(Errors.UnexpectedPrivateField, {
  4372. at: privateKeyLoc
  4373. });
  4374. }
  4375. if (optionalParametersLoc != null) {
  4376. this.unexpected(optionalParametersLoc);
  4377. }
  4378. }
  4379. isLiteralPropertyName() {
  4380. return tokenIsLiteralPropertyName(this.state.type);
  4381. }
  4382. isPrivateName(node) {
  4383. return node.type === "PrivateName";
  4384. }
  4385. getPrivateNameSV(node) {
  4386. return node.id.name;
  4387. }
  4388. hasPropertyAsPrivateName(node) {
  4389. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  4390. }
  4391. isObjectProperty(node) {
  4392. return node.type === "ObjectProperty";
  4393. }
  4394. isObjectMethod(node) {
  4395. return node.type === "ObjectMethod";
  4396. }
  4397. initializeScopes(inModule = this.options.sourceType === "module") {
  4398. const oldLabels = this.state.labels;
  4399. this.state.labels = [];
  4400. const oldExportedIdentifiers = this.exportedIdentifiers;
  4401. this.exportedIdentifiers = new Set();
  4402. const oldInModule = this.inModule;
  4403. this.inModule = inModule;
  4404. const oldScope = this.scope;
  4405. const ScopeHandler = this.getScopeHandler();
  4406. this.scope = new ScopeHandler(this, inModule);
  4407. const oldProdParam = this.prodParam;
  4408. this.prodParam = new ProductionParameterHandler();
  4409. const oldClassScope = this.classScope;
  4410. this.classScope = new ClassScopeHandler(this);
  4411. const oldExpressionScope = this.expressionScope;
  4412. this.expressionScope = new ExpressionScopeHandler(this);
  4413. return () => {
  4414. this.state.labels = oldLabels;
  4415. this.exportedIdentifiers = oldExportedIdentifiers;
  4416. this.inModule = oldInModule;
  4417. this.scope = oldScope;
  4418. this.prodParam = oldProdParam;
  4419. this.classScope = oldClassScope;
  4420. this.expressionScope = oldExpressionScope;
  4421. };
  4422. }
  4423. enterInitialScopes() {
  4424. let paramFlags = PARAM;
  4425. if (this.inModule) {
  4426. paramFlags |= PARAM_AWAIT;
  4427. }
  4428. this.scope.enter(SCOPE_PROGRAM);
  4429. this.prodParam.enter(paramFlags);
  4430. }
  4431. checkDestructuringPrivate(refExpressionErrors) {
  4432. const {
  4433. privateKeyLoc
  4434. } = refExpressionErrors;
  4435. if (privateKeyLoc !== null) {
  4436. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  4437. }
  4438. }
  4439. }
  4440. class ExpressionErrors {
  4441. constructor() {
  4442. this.shorthandAssignLoc = null;
  4443. this.doubleProtoLoc = null;
  4444. this.privateKeyLoc = null;
  4445. this.optionalParametersLoc = null;
  4446. }
  4447. }
  4448. let Node$5 = class Node {
  4449. constructor(parser, pos, loc) {
  4450. this.type = "";
  4451. this.start = pos;
  4452. this.end = 0;
  4453. this.loc = new SourceLocation(loc);
  4454. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  4455. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  4456. }
  4457. };
  4458. const NodePrototype = Node$5.prototype;
  4459. {
  4460. NodePrototype.__clone = function () {
  4461. const newNode = new Node$5(undefined, this.start, this.loc.start);
  4462. const keys = Object.keys(this);
  4463. for (let i = 0, length = keys.length; i < length; i++) {
  4464. const key = keys[i];
  4465. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  4466. newNode[key] = this[key];
  4467. }
  4468. }
  4469. return newNode;
  4470. };
  4471. }
  4472. function clonePlaceholder(node) {
  4473. return cloneIdentifier(node);
  4474. }
  4475. function cloneIdentifier(node) {
  4476. const {
  4477. type,
  4478. start,
  4479. end,
  4480. loc,
  4481. range,
  4482. extra,
  4483. name
  4484. } = node;
  4485. const cloned = Object.create(NodePrototype);
  4486. cloned.type = type;
  4487. cloned.start = start;
  4488. cloned.end = end;
  4489. cloned.loc = loc;
  4490. cloned.range = range;
  4491. cloned.extra = extra;
  4492. cloned.name = name;
  4493. if (type === "Placeholder") {
  4494. cloned.expectedNode = node.expectedNode;
  4495. }
  4496. return cloned;
  4497. }
  4498. function cloneStringLiteral(node) {
  4499. const {
  4500. type,
  4501. start,
  4502. end,
  4503. loc,
  4504. range,
  4505. extra
  4506. } = node;
  4507. if (type === "Placeholder") {
  4508. return clonePlaceholder(node);
  4509. }
  4510. const cloned = Object.create(NodePrototype);
  4511. cloned.type = type;
  4512. cloned.start = start;
  4513. cloned.end = end;
  4514. cloned.loc = loc;
  4515. cloned.range = range;
  4516. if (node.raw !== undefined) {
  4517. cloned.raw = node.raw;
  4518. } else {
  4519. cloned.extra = extra;
  4520. }
  4521. cloned.value = node.value;
  4522. return cloned;
  4523. }
  4524. class NodeUtils extends UtilParser {
  4525. startNode() {
  4526. return new Node$5(this, this.state.start, this.state.startLoc);
  4527. }
  4528. startNodeAt(loc) {
  4529. return new Node$5(this, loc.index, loc);
  4530. }
  4531. startNodeAtNode(type) {
  4532. return this.startNodeAt(type.loc.start);
  4533. }
  4534. finishNode(node, type) {
  4535. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  4536. }
  4537. finishNodeAt(node, type, endLoc) {
  4538. node.type = type;
  4539. node.end = endLoc.index;
  4540. node.loc.end = endLoc;
  4541. if (this.options.ranges) node.range[1] = endLoc.index;
  4542. if (this.options.attachComment) this.processComment(node);
  4543. return node;
  4544. }
  4545. resetStartLocation(node, startLoc) {
  4546. node.start = startLoc.index;
  4547. node.loc.start = startLoc;
  4548. if (this.options.ranges) node.range[0] = startLoc.index;
  4549. }
  4550. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  4551. node.end = endLoc.index;
  4552. node.loc.end = endLoc;
  4553. if (this.options.ranges) node.range[1] = endLoc.index;
  4554. }
  4555. resetStartLocationFromNode(node, locationNode) {
  4556. this.resetStartLocation(node, locationNode.loc.start);
  4557. }
  4558. }
  4559. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  4560. const FlowErrors = ParseErrorEnum`flow`({
  4561. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  4562. AmbiguousDeclareModuleKind: "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module.",
  4563. AssignReservedType: ({
  4564. reservedType
  4565. }) => `Cannot overwrite reserved type ${reservedType}.`,
  4566. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  4567. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  4568. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  4569. EnumBooleanMemberNotInitialized: ({
  4570. memberName,
  4571. enumName
  4572. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  4573. EnumDuplicateMemberName: ({
  4574. memberName,
  4575. enumName
  4576. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  4577. EnumInconsistentMemberValues: ({
  4578. enumName
  4579. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  4580. EnumInvalidExplicitType: ({
  4581. invalidEnumType,
  4582. enumName
  4583. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  4584. EnumInvalidExplicitTypeUnknownSupplied: ({
  4585. enumName
  4586. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  4587. EnumInvalidMemberInitializerPrimaryType: ({
  4588. enumName,
  4589. memberName,
  4590. explicitType
  4591. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  4592. EnumInvalidMemberInitializerSymbolType: ({
  4593. enumName,
  4594. memberName
  4595. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  4596. EnumInvalidMemberInitializerUnknownType: ({
  4597. enumName,
  4598. memberName
  4599. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  4600. EnumInvalidMemberName: ({
  4601. enumName,
  4602. memberName,
  4603. suggestion
  4604. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  4605. EnumNumberMemberNotInitialized: ({
  4606. enumName,
  4607. memberName
  4608. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  4609. EnumStringMemberInconsistentlyInitailized: ({
  4610. enumName
  4611. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  4612. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  4613. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  4614. ImportTypeShorthandOnlyInPureImport: "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements.",
  4615. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  4616. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  4617. InexactVariance: "Explicit inexact syntax cannot have variance.",
  4618. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  4619. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  4620. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  4621. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  4622. PatternIsOptional: Object.assign({
  4623. message: "A binding pattern parameter cannot be optional in an implementation signature."
  4624. }, {
  4625. reasonCode: "OptionalBindingPattern"
  4626. }),
  4627. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  4628. SpreadVariance: "Spread properties cannot have variance.",
  4629. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  4630. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  4631. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  4632. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  4633. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  4634. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  4635. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  4636. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  4637. UnexpectedReservedType: ({
  4638. reservedType
  4639. }) => `Unexpected reserved type ${reservedType}.`,
  4640. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  4641. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  4642. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  4643. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  4644. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  4645. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  4646. UnsupportedDeclareExportKind: ({
  4647. unsupportedExportKind,
  4648. suggestion
  4649. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  4650. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  4651. UnterminatedFlowComment: "Unterminated flow-comment."
  4652. });
  4653. function isEsModuleType(bodyElement) {
  4654. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  4655. }
  4656. function hasTypeImportKind(node) {
  4657. return node.importKind === "type" || node.importKind === "typeof";
  4658. }
  4659. function isMaybeDefaultImport(type) {
  4660. return tokenIsKeywordOrIdentifier(type) && type !== 97;
  4661. }
  4662. const exportSuggestions = {
  4663. const: "declare export var",
  4664. let: "declare export var",
  4665. type: "export type",
  4666. interface: "export interface"
  4667. };
  4668. function partition(list, test) {
  4669. const list1 = [];
  4670. const list2 = [];
  4671. for (let i = 0; i < list.length; i++) {
  4672. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  4673. }
  4674. return [list1, list2];
  4675. }
  4676. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  4677. var flow = superClass => class FlowParserMixin extends superClass {
  4678. constructor(...args) {
  4679. super(...args);
  4680. this.flowPragma = undefined;
  4681. }
  4682. getScopeHandler() {
  4683. return FlowScopeHandler;
  4684. }
  4685. shouldParseTypes() {
  4686. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  4687. }
  4688. shouldParseEnums() {
  4689. return !!this.getPluginOption("flow", "enums");
  4690. }
  4691. finishToken(type, val) {
  4692. if (type !== 131 && type !== 13 && type !== 28) {
  4693. if (this.flowPragma === undefined) {
  4694. this.flowPragma = null;
  4695. }
  4696. }
  4697. super.finishToken(type, val);
  4698. }
  4699. addComment(comment) {
  4700. if (this.flowPragma === undefined) {
  4701. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  4702. if (!matches) ;else if (matches[1] === "flow") {
  4703. this.flowPragma = "flow";
  4704. } else if (matches[1] === "noflow") {
  4705. this.flowPragma = "noflow";
  4706. } else {
  4707. throw new Error("Unexpected flow pragma");
  4708. }
  4709. }
  4710. super.addComment(comment);
  4711. }
  4712. flowParseTypeInitialiser(tok) {
  4713. const oldInType = this.state.inType;
  4714. this.state.inType = true;
  4715. this.expect(tok || 14);
  4716. const type = this.flowParseType();
  4717. this.state.inType = oldInType;
  4718. return type;
  4719. }
  4720. flowParsePredicate() {
  4721. const node = this.startNode();
  4722. const moduloLoc = this.state.startLoc;
  4723. this.next();
  4724. this.expectContextual(108);
  4725. if (this.state.lastTokStart > moduloLoc.index + 1) {
  4726. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, {
  4727. at: moduloLoc
  4728. });
  4729. }
  4730. if (this.eat(10)) {
  4731. node.value = super.parseExpression();
  4732. this.expect(11);
  4733. return this.finishNode(node, "DeclaredPredicate");
  4734. } else {
  4735. return this.finishNode(node, "InferredPredicate");
  4736. }
  4737. }
  4738. flowParseTypeAndPredicateInitialiser() {
  4739. const oldInType = this.state.inType;
  4740. this.state.inType = true;
  4741. this.expect(14);
  4742. let type = null;
  4743. let predicate = null;
  4744. if (this.match(54)) {
  4745. this.state.inType = oldInType;
  4746. predicate = this.flowParsePredicate();
  4747. } else {
  4748. type = this.flowParseType();
  4749. this.state.inType = oldInType;
  4750. if (this.match(54)) {
  4751. predicate = this.flowParsePredicate();
  4752. }
  4753. }
  4754. return [type, predicate];
  4755. }
  4756. flowParseDeclareClass(node) {
  4757. this.next();
  4758. this.flowParseInterfaceish(node, true);
  4759. return this.finishNode(node, "DeclareClass");
  4760. }
  4761. flowParseDeclareFunction(node) {
  4762. this.next();
  4763. const id = node.id = this.parseIdentifier();
  4764. const typeNode = this.startNode();
  4765. const typeContainer = this.startNode();
  4766. if (this.match(47)) {
  4767. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4768. } else {
  4769. typeNode.typeParameters = null;
  4770. }
  4771. this.expect(10);
  4772. const tmp = this.flowParseFunctionTypeParams();
  4773. typeNode.params = tmp.params;
  4774. typeNode.rest = tmp.rest;
  4775. typeNode.this = tmp._this;
  4776. this.expect(11);
  4777. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4778. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4779. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4780. this.resetEndLocation(id);
  4781. this.semicolon();
  4782. this.scope.declareName(node.id.name, BIND_FLOW_DECLARE_FN, node.id.loc.start);
  4783. return this.finishNode(node, "DeclareFunction");
  4784. }
  4785. flowParseDeclare(node, insideModule) {
  4786. if (this.match(80)) {
  4787. return this.flowParseDeclareClass(node);
  4788. } else if (this.match(68)) {
  4789. return this.flowParseDeclareFunction(node);
  4790. } else if (this.match(74)) {
  4791. return this.flowParseDeclareVariable(node);
  4792. } else if (this.eatContextual(125)) {
  4793. if (this.match(16)) {
  4794. return this.flowParseDeclareModuleExports(node);
  4795. } else {
  4796. if (insideModule) {
  4797. this.raise(FlowErrors.NestedDeclareModule, {
  4798. at: this.state.lastTokStartLoc
  4799. });
  4800. }
  4801. return this.flowParseDeclareModule(node);
  4802. }
  4803. } else if (this.isContextual(128)) {
  4804. return this.flowParseDeclareTypeAlias(node);
  4805. } else if (this.isContextual(129)) {
  4806. return this.flowParseDeclareOpaqueType(node);
  4807. } else if (this.isContextual(127)) {
  4808. return this.flowParseDeclareInterface(node);
  4809. } else if (this.match(82)) {
  4810. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4811. } else {
  4812. this.unexpected();
  4813. }
  4814. }
  4815. flowParseDeclareVariable(node) {
  4816. this.next();
  4817. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4818. this.scope.declareName(node.id.name, BIND_VAR, node.id.loc.start);
  4819. this.semicolon();
  4820. return this.finishNode(node, "DeclareVariable");
  4821. }
  4822. flowParseDeclareModule(node) {
  4823. this.scope.enter(SCOPE_OTHER);
  4824. if (this.match(131)) {
  4825. node.id = super.parseExprAtom();
  4826. } else {
  4827. node.id = this.parseIdentifier();
  4828. }
  4829. const bodyNode = node.body = this.startNode();
  4830. const body = bodyNode.body = [];
  4831. this.expect(5);
  4832. while (!this.match(8)) {
  4833. let bodyNode = this.startNode();
  4834. if (this.match(83)) {
  4835. this.next();
  4836. if (!this.isContextual(128) && !this.match(87)) {
  4837. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, {
  4838. at: this.state.lastTokStartLoc
  4839. });
  4840. }
  4841. super.parseImport(bodyNode);
  4842. } else {
  4843. this.expectContextual(123, FlowErrors.UnsupportedStatementInDeclareModule);
  4844. bodyNode = this.flowParseDeclare(bodyNode, true);
  4845. }
  4846. body.push(bodyNode);
  4847. }
  4848. this.scope.exit();
  4849. this.expect(8);
  4850. this.finishNode(bodyNode, "BlockStatement");
  4851. let kind = null;
  4852. let hasModuleExport = false;
  4853. body.forEach(bodyElement => {
  4854. if (isEsModuleType(bodyElement)) {
  4855. if (kind === "CommonJS") {
  4856. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4857. at: bodyElement
  4858. });
  4859. }
  4860. kind = "ES";
  4861. } else if (bodyElement.type === "DeclareModuleExports") {
  4862. if (hasModuleExport) {
  4863. this.raise(FlowErrors.DuplicateDeclareModuleExports, {
  4864. at: bodyElement
  4865. });
  4866. }
  4867. if (kind === "ES") {
  4868. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4869. at: bodyElement
  4870. });
  4871. }
  4872. kind = "CommonJS";
  4873. hasModuleExport = true;
  4874. }
  4875. });
  4876. node.kind = kind || "CommonJS";
  4877. return this.finishNode(node, "DeclareModule");
  4878. }
  4879. flowParseDeclareExportDeclaration(node, insideModule) {
  4880. this.expect(82);
  4881. if (this.eat(65)) {
  4882. if (this.match(68) || this.match(80)) {
  4883. node.declaration = this.flowParseDeclare(this.startNode());
  4884. } else {
  4885. node.declaration = this.flowParseType();
  4886. this.semicolon();
  4887. }
  4888. node.default = true;
  4889. return this.finishNode(node, "DeclareExportDeclaration");
  4890. } else {
  4891. if (this.match(75) || this.isLet() || (this.isContextual(128) || this.isContextual(127)) && !insideModule) {
  4892. const label = this.state.value;
  4893. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, {
  4894. at: this.state.startLoc,
  4895. unsupportedExportKind: label,
  4896. suggestion: exportSuggestions[label]
  4897. });
  4898. }
  4899. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(129)) {
  4900. node.declaration = this.flowParseDeclare(this.startNode());
  4901. node.default = false;
  4902. return this.finishNode(node, "DeclareExportDeclaration");
  4903. } else if (this.match(55) || this.match(5) || this.isContextual(127) || this.isContextual(128) || this.isContextual(129)) {
  4904. node = this.parseExport(node, null);
  4905. if (node.type === "ExportNamedDeclaration") {
  4906. node.type = "ExportDeclaration";
  4907. node.default = false;
  4908. delete node.exportKind;
  4909. }
  4910. node.type = "Declare" + node.type;
  4911. return node;
  4912. }
  4913. }
  4914. this.unexpected();
  4915. }
  4916. flowParseDeclareModuleExports(node) {
  4917. this.next();
  4918. this.expectContextual(109);
  4919. node.typeAnnotation = this.flowParseTypeAnnotation();
  4920. this.semicolon();
  4921. return this.finishNode(node, "DeclareModuleExports");
  4922. }
  4923. flowParseDeclareTypeAlias(node) {
  4924. this.next();
  4925. const finished = this.flowParseTypeAlias(node);
  4926. finished.type = "DeclareTypeAlias";
  4927. return finished;
  4928. }
  4929. flowParseDeclareOpaqueType(node) {
  4930. this.next();
  4931. const finished = this.flowParseOpaqueType(node, true);
  4932. finished.type = "DeclareOpaqueType";
  4933. return finished;
  4934. }
  4935. flowParseDeclareInterface(node) {
  4936. this.next();
  4937. this.flowParseInterfaceish(node, false);
  4938. return this.finishNode(node, "DeclareInterface");
  4939. }
  4940. flowParseInterfaceish(node, isClass) {
  4941. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4942. this.scope.declareName(node.id.name, isClass ? BIND_FUNCTION : BIND_LEXICAL, node.id.loc.start);
  4943. if (this.match(47)) {
  4944. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4945. } else {
  4946. node.typeParameters = null;
  4947. }
  4948. node.extends = [];
  4949. node.implements = [];
  4950. node.mixins = [];
  4951. if (this.eat(81)) {
  4952. do {
  4953. node.extends.push(this.flowParseInterfaceExtends());
  4954. } while (!isClass && this.eat(12));
  4955. }
  4956. if (isClass) {
  4957. if (this.eatContextual(115)) {
  4958. do {
  4959. node.mixins.push(this.flowParseInterfaceExtends());
  4960. } while (this.eat(12));
  4961. }
  4962. if (this.eatContextual(111)) {
  4963. do {
  4964. node.implements.push(this.flowParseInterfaceExtends());
  4965. } while (this.eat(12));
  4966. }
  4967. }
  4968. node.body = this.flowParseObjectType({
  4969. allowStatic: isClass,
  4970. allowExact: false,
  4971. allowSpread: false,
  4972. allowProto: isClass,
  4973. allowInexact: false
  4974. });
  4975. }
  4976. flowParseInterfaceExtends() {
  4977. const node = this.startNode();
  4978. node.id = this.flowParseQualifiedTypeIdentifier();
  4979. if (this.match(47)) {
  4980. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4981. } else {
  4982. node.typeParameters = null;
  4983. }
  4984. return this.finishNode(node, "InterfaceExtends");
  4985. }
  4986. flowParseInterface(node) {
  4987. this.flowParseInterfaceish(node, false);
  4988. return this.finishNode(node, "InterfaceDeclaration");
  4989. }
  4990. checkNotUnderscore(word) {
  4991. if (word === "_") {
  4992. this.raise(FlowErrors.UnexpectedReservedUnderscore, {
  4993. at: this.state.startLoc
  4994. });
  4995. }
  4996. }
  4997. checkReservedType(word, startLoc, declaration) {
  4998. if (!reservedTypes.has(word)) return;
  4999. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, {
  5000. at: startLoc,
  5001. reservedType: word
  5002. });
  5003. }
  5004. flowParseRestrictedIdentifier(liberal, declaration) {
  5005. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  5006. return this.parseIdentifier(liberal);
  5007. }
  5008. flowParseTypeAlias(node) {
  5009. node.id = this.flowParseRestrictedIdentifier(false, true);
  5010. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.loc.start);
  5011. if (this.match(47)) {
  5012. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5013. } else {
  5014. node.typeParameters = null;
  5015. }
  5016. node.right = this.flowParseTypeInitialiser(29);
  5017. this.semicolon();
  5018. return this.finishNode(node, "TypeAlias");
  5019. }
  5020. flowParseOpaqueType(node, declare) {
  5021. this.expectContextual(128);
  5022. node.id = this.flowParseRestrictedIdentifier(true, true);
  5023. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.loc.start);
  5024. if (this.match(47)) {
  5025. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5026. } else {
  5027. node.typeParameters = null;
  5028. }
  5029. node.supertype = null;
  5030. if (this.match(14)) {
  5031. node.supertype = this.flowParseTypeInitialiser(14);
  5032. }
  5033. node.impltype = null;
  5034. if (!declare) {
  5035. node.impltype = this.flowParseTypeInitialiser(29);
  5036. }
  5037. this.semicolon();
  5038. return this.finishNode(node, "OpaqueType");
  5039. }
  5040. flowParseTypeParameter(requireDefault = false) {
  5041. const nodeStartLoc = this.state.startLoc;
  5042. const node = this.startNode();
  5043. const variance = this.flowParseVariance();
  5044. const ident = this.flowParseTypeAnnotatableIdentifier();
  5045. node.name = ident.name;
  5046. node.variance = variance;
  5047. node.bound = ident.typeAnnotation;
  5048. if (this.match(29)) {
  5049. this.eat(29);
  5050. node.default = this.flowParseType();
  5051. } else {
  5052. if (requireDefault) {
  5053. this.raise(FlowErrors.MissingTypeParamDefault, {
  5054. at: nodeStartLoc
  5055. });
  5056. }
  5057. }
  5058. return this.finishNode(node, "TypeParameter");
  5059. }
  5060. flowParseTypeParameterDeclaration() {
  5061. const oldInType = this.state.inType;
  5062. const node = this.startNode();
  5063. node.params = [];
  5064. this.state.inType = true;
  5065. if (this.match(47) || this.match(140)) {
  5066. this.next();
  5067. } else {
  5068. this.unexpected();
  5069. }
  5070. let defaultRequired = false;
  5071. do {
  5072. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  5073. node.params.push(typeParameter);
  5074. if (typeParameter.default) {
  5075. defaultRequired = true;
  5076. }
  5077. if (!this.match(48)) {
  5078. this.expect(12);
  5079. }
  5080. } while (!this.match(48));
  5081. this.expect(48);
  5082. this.state.inType = oldInType;
  5083. return this.finishNode(node, "TypeParameterDeclaration");
  5084. }
  5085. flowParseTypeParameterInstantiation() {
  5086. const node = this.startNode();
  5087. const oldInType = this.state.inType;
  5088. node.params = [];
  5089. this.state.inType = true;
  5090. this.expect(47);
  5091. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5092. this.state.noAnonFunctionType = false;
  5093. while (!this.match(48)) {
  5094. node.params.push(this.flowParseType());
  5095. if (!this.match(48)) {
  5096. this.expect(12);
  5097. }
  5098. }
  5099. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5100. this.expect(48);
  5101. this.state.inType = oldInType;
  5102. return this.finishNode(node, "TypeParameterInstantiation");
  5103. }
  5104. flowParseTypeParameterInstantiationCallOrNew() {
  5105. const node = this.startNode();
  5106. const oldInType = this.state.inType;
  5107. node.params = [];
  5108. this.state.inType = true;
  5109. this.expect(47);
  5110. while (!this.match(48)) {
  5111. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  5112. if (!this.match(48)) {
  5113. this.expect(12);
  5114. }
  5115. }
  5116. this.expect(48);
  5117. this.state.inType = oldInType;
  5118. return this.finishNode(node, "TypeParameterInstantiation");
  5119. }
  5120. flowParseInterfaceType() {
  5121. const node = this.startNode();
  5122. this.expectContextual(127);
  5123. node.extends = [];
  5124. if (this.eat(81)) {
  5125. do {
  5126. node.extends.push(this.flowParseInterfaceExtends());
  5127. } while (this.eat(12));
  5128. }
  5129. node.body = this.flowParseObjectType({
  5130. allowStatic: false,
  5131. allowExact: false,
  5132. allowSpread: false,
  5133. allowProto: false,
  5134. allowInexact: false
  5135. });
  5136. return this.finishNode(node, "InterfaceTypeAnnotation");
  5137. }
  5138. flowParseObjectPropertyKey() {
  5139. return this.match(132) || this.match(131) ? super.parseExprAtom() : this.parseIdentifier(true);
  5140. }
  5141. flowParseObjectTypeIndexer(node, isStatic, variance) {
  5142. node.static = isStatic;
  5143. if (this.lookahead().type === 14) {
  5144. node.id = this.flowParseObjectPropertyKey();
  5145. node.key = this.flowParseTypeInitialiser();
  5146. } else {
  5147. node.id = null;
  5148. node.key = this.flowParseType();
  5149. }
  5150. this.expect(3);
  5151. node.value = this.flowParseTypeInitialiser();
  5152. node.variance = variance;
  5153. return this.finishNode(node, "ObjectTypeIndexer");
  5154. }
  5155. flowParseObjectTypeInternalSlot(node, isStatic) {
  5156. node.static = isStatic;
  5157. node.id = this.flowParseObjectPropertyKey();
  5158. this.expect(3);
  5159. this.expect(3);
  5160. if (this.match(47) || this.match(10)) {
  5161. node.method = true;
  5162. node.optional = false;
  5163. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  5164. } else {
  5165. node.method = false;
  5166. if (this.eat(17)) {
  5167. node.optional = true;
  5168. }
  5169. node.value = this.flowParseTypeInitialiser();
  5170. }
  5171. return this.finishNode(node, "ObjectTypeInternalSlot");
  5172. }
  5173. flowParseObjectTypeMethodish(node) {
  5174. node.params = [];
  5175. node.rest = null;
  5176. node.typeParameters = null;
  5177. node.this = null;
  5178. if (this.match(47)) {
  5179. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5180. }
  5181. this.expect(10);
  5182. if (this.match(78)) {
  5183. node.this = this.flowParseFunctionTypeParam(true);
  5184. node.this.name = null;
  5185. if (!this.match(11)) {
  5186. this.expect(12);
  5187. }
  5188. }
  5189. while (!this.match(11) && !this.match(21)) {
  5190. node.params.push(this.flowParseFunctionTypeParam(false));
  5191. if (!this.match(11)) {
  5192. this.expect(12);
  5193. }
  5194. }
  5195. if (this.eat(21)) {
  5196. node.rest = this.flowParseFunctionTypeParam(false);
  5197. }
  5198. this.expect(11);
  5199. node.returnType = this.flowParseTypeInitialiser();
  5200. return this.finishNode(node, "FunctionTypeAnnotation");
  5201. }
  5202. flowParseObjectTypeCallProperty(node, isStatic) {
  5203. const valueNode = this.startNode();
  5204. node.static = isStatic;
  5205. node.value = this.flowParseObjectTypeMethodish(valueNode);
  5206. return this.finishNode(node, "ObjectTypeCallProperty");
  5207. }
  5208. flowParseObjectType({
  5209. allowStatic,
  5210. allowExact,
  5211. allowSpread,
  5212. allowProto,
  5213. allowInexact
  5214. }) {
  5215. const oldInType = this.state.inType;
  5216. this.state.inType = true;
  5217. const nodeStart = this.startNode();
  5218. nodeStart.callProperties = [];
  5219. nodeStart.properties = [];
  5220. nodeStart.indexers = [];
  5221. nodeStart.internalSlots = [];
  5222. let endDelim;
  5223. let exact;
  5224. let inexact = false;
  5225. if (allowExact && this.match(6)) {
  5226. this.expect(6);
  5227. endDelim = 9;
  5228. exact = true;
  5229. } else {
  5230. this.expect(5);
  5231. endDelim = 8;
  5232. exact = false;
  5233. }
  5234. nodeStart.exact = exact;
  5235. while (!this.match(endDelim)) {
  5236. let isStatic = false;
  5237. let protoStartLoc = null;
  5238. let inexactStartLoc = null;
  5239. const node = this.startNode();
  5240. if (allowProto && this.isContextual(116)) {
  5241. const lookahead = this.lookahead();
  5242. if (lookahead.type !== 14 && lookahead.type !== 17) {
  5243. this.next();
  5244. protoStartLoc = this.state.startLoc;
  5245. allowStatic = false;
  5246. }
  5247. }
  5248. if (allowStatic && this.isContextual(104)) {
  5249. const lookahead = this.lookahead();
  5250. if (lookahead.type !== 14 && lookahead.type !== 17) {
  5251. this.next();
  5252. isStatic = true;
  5253. }
  5254. }
  5255. const variance = this.flowParseVariance();
  5256. if (this.eat(0)) {
  5257. if (protoStartLoc != null) {
  5258. this.unexpected(protoStartLoc);
  5259. }
  5260. if (this.eat(0)) {
  5261. if (variance) {
  5262. this.unexpected(variance.loc.start);
  5263. }
  5264. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  5265. } else {
  5266. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  5267. }
  5268. } else if (this.match(10) || this.match(47)) {
  5269. if (protoStartLoc != null) {
  5270. this.unexpected(protoStartLoc);
  5271. }
  5272. if (variance) {
  5273. this.unexpected(variance.loc.start);
  5274. }
  5275. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  5276. } else {
  5277. let kind = "init";
  5278. if (this.isContextual(98) || this.isContextual(103)) {
  5279. const lookahead = this.lookahead();
  5280. if (tokenIsLiteralPropertyName(lookahead.type)) {
  5281. kind = this.state.value;
  5282. this.next();
  5283. }
  5284. }
  5285. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  5286. if (propOrInexact === null) {
  5287. inexact = true;
  5288. inexactStartLoc = this.state.lastTokStartLoc;
  5289. } else {
  5290. nodeStart.properties.push(propOrInexact);
  5291. }
  5292. }
  5293. this.flowObjectTypeSemicolon();
  5294. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  5295. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, {
  5296. at: inexactStartLoc
  5297. });
  5298. }
  5299. }
  5300. this.expect(endDelim);
  5301. if (allowSpread) {
  5302. nodeStart.inexact = inexact;
  5303. }
  5304. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  5305. this.state.inType = oldInType;
  5306. return out;
  5307. }
  5308. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  5309. if (this.eat(21)) {
  5310. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  5311. if (isInexactToken) {
  5312. if (!allowSpread) {
  5313. this.raise(FlowErrors.InexactInsideNonObject, {
  5314. at: this.state.lastTokStartLoc
  5315. });
  5316. } else if (!allowInexact) {
  5317. this.raise(FlowErrors.InexactInsideExact, {
  5318. at: this.state.lastTokStartLoc
  5319. });
  5320. }
  5321. if (variance) {
  5322. this.raise(FlowErrors.InexactVariance, {
  5323. at: variance
  5324. });
  5325. }
  5326. return null;
  5327. }
  5328. if (!allowSpread) {
  5329. this.raise(FlowErrors.UnexpectedSpreadType, {
  5330. at: this.state.lastTokStartLoc
  5331. });
  5332. }
  5333. if (protoStartLoc != null) {
  5334. this.unexpected(protoStartLoc);
  5335. }
  5336. if (variance) {
  5337. this.raise(FlowErrors.SpreadVariance, {
  5338. at: variance
  5339. });
  5340. }
  5341. node.argument = this.flowParseType();
  5342. return this.finishNode(node, "ObjectTypeSpreadProperty");
  5343. } else {
  5344. node.key = this.flowParseObjectPropertyKey();
  5345. node.static = isStatic;
  5346. node.proto = protoStartLoc != null;
  5347. node.kind = kind;
  5348. let optional = false;
  5349. if (this.match(47) || this.match(10)) {
  5350. node.method = true;
  5351. if (protoStartLoc != null) {
  5352. this.unexpected(protoStartLoc);
  5353. }
  5354. if (variance) {
  5355. this.unexpected(variance.loc.start);
  5356. }
  5357. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  5358. if (kind === "get" || kind === "set") {
  5359. this.flowCheckGetterSetterParams(node);
  5360. }
  5361. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  5362. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5363. at: node.value.this
  5364. });
  5365. }
  5366. } else {
  5367. if (kind !== "init") this.unexpected();
  5368. node.method = false;
  5369. if (this.eat(17)) {
  5370. optional = true;
  5371. }
  5372. node.value = this.flowParseTypeInitialiser();
  5373. node.variance = variance;
  5374. }
  5375. node.optional = optional;
  5376. return this.finishNode(node, "ObjectTypeProperty");
  5377. }
  5378. }
  5379. flowCheckGetterSetterParams(property) {
  5380. const paramCount = property.kind === "get" ? 0 : 1;
  5381. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  5382. if (property.value.this) {
  5383. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, {
  5384. at: property.value.this
  5385. });
  5386. }
  5387. if (length !== paramCount) {
  5388. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  5389. at: property
  5390. });
  5391. }
  5392. if (property.kind === "set" && property.value.rest) {
  5393. this.raise(Errors.BadSetterRestParameter, {
  5394. at: property
  5395. });
  5396. }
  5397. }
  5398. flowObjectTypeSemicolon() {
  5399. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  5400. this.unexpected();
  5401. }
  5402. }
  5403. flowParseQualifiedTypeIdentifier(startLoc, id) {
  5404. var _startLoc;
  5405. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  5406. let node = id || this.flowParseRestrictedIdentifier(true);
  5407. while (this.eat(16)) {
  5408. const node2 = this.startNodeAt(startLoc);
  5409. node2.qualification = node;
  5410. node2.id = this.flowParseRestrictedIdentifier(true);
  5411. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  5412. }
  5413. return node;
  5414. }
  5415. flowParseGenericType(startLoc, id) {
  5416. const node = this.startNodeAt(startLoc);
  5417. node.typeParameters = null;
  5418. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  5419. if (this.match(47)) {
  5420. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5421. }
  5422. return this.finishNode(node, "GenericTypeAnnotation");
  5423. }
  5424. flowParseTypeofType() {
  5425. const node = this.startNode();
  5426. this.expect(87);
  5427. node.argument = this.flowParsePrimaryType();
  5428. return this.finishNode(node, "TypeofTypeAnnotation");
  5429. }
  5430. flowParseTupleType() {
  5431. const node = this.startNode();
  5432. node.types = [];
  5433. this.expect(0);
  5434. while (this.state.pos < this.length && !this.match(3)) {
  5435. node.types.push(this.flowParseType());
  5436. if (this.match(3)) break;
  5437. this.expect(12);
  5438. }
  5439. this.expect(3);
  5440. return this.finishNode(node, "TupleTypeAnnotation");
  5441. }
  5442. flowParseFunctionTypeParam(first) {
  5443. let name = null;
  5444. let optional = false;
  5445. let typeAnnotation = null;
  5446. const node = this.startNode();
  5447. const lh = this.lookahead();
  5448. const isThis = this.state.type === 78;
  5449. if (lh.type === 14 || lh.type === 17) {
  5450. if (isThis && !first) {
  5451. this.raise(FlowErrors.ThisParamMustBeFirst, {
  5452. at: node
  5453. });
  5454. }
  5455. name = this.parseIdentifier(isThis);
  5456. if (this.eat(17)) {
  5457. optional = true;
  5458. if (isThis) {
  5459. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  5460. at: node
  5461. });
  5462. }
  5463. }
  5464. typeAnnotation = this.flowParseTypeInitialiser();
  5465. } else {
  5466. typeAnnotation = this.flowParseType();
  5467. }
  5468. node.name = name;
  5469. node.optional = optional;
  5470. node.typeAnnotation = typeAnnotation;
  5471. return this.finishNode(node, "FunctionTypeParam");
  5472. }
  5473. reinterpretTypeAsFunctionTypeParam(type) {
  5474. const node = this.startNodeAt(type.loc.start);
  5475. node.name = null;
  5476. node.optional = false;
  5477. node.typeAnnotation = type;
  5478. return this.finishNode(node, "FunctionTypeParam");
  5479. }
  5480. flowParseFunctionTypeParams(params = []) {
  5481. let rest = null;
  5482. let _this = null;
  5483. if (this.match(78)) {
  5484. _this = this.flowParseFunctionTypeParam(true);
  5485. _this.name = null;
  5486. if (!this.match(11)) {
  5487. this.expect(12);
  5488. }
  5489. }
  5490. while (!this.match(11) && !this.match(21)) {
  5491. params.push(this.flowParseFunctionTypeParam(false));
  5492. if (!this.match(11)) {
  5493. this.expect(12);
  5494. }
  5495. }
  5496. if (this.eat(21)) {
  5497. rest = this.flowParseFunctionTypeParam(false);
  5498. }
  5499. return {
  5500. params,
  5501. rest,
  5502. _this
  5503. };
  5504. }
  5505. flowIdentToTypeAnnotation(startLoc, node, id) {
  5506. switch (id.name) {
  5507. case "any":
  5508. return this.finishNode(node, "AnyTypeAnnotation");
  5509. case "bool":
  5510. case "boolean":
  5511. return this.finishNode(node, "BooleanTypeAnnotation");
  5512. case "mixed":
  5513. return this.finishNode(node, "MixedTypeAnnotation");
  5514. case "empty":
  5515. return this.finishNode(node, "EmptyTypeAnnotation");
  5516. case "number":
  5517. return this.finishNode(node, "NumberTypeAnnotation");
  5518. case "string":
  5519. return this.finishNode(node, "StringTypeAnnotation");
  5520. case "symbol":
  5521. return this.finishNode(node, "SymbolTypeAnnotation");
  5522. default:
  5523. this.checkNotUnderscore(id.name);
  5524. return this.flowParseGenericType(startLoc, id);
  5525. }
  5526. }
  5527. flowParsePrimaryType() {
  5528. const startLoc = this.state.startLoc;
  5529. const node = this.startNode();
  5530. let tmp;
  5531. let type;
  5532. let isGroupedType = false;
  5533. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5534. switch (this.state.type) {
  5535. case 5:
  5536. return this.flowParseObjectType({
  5537. allowStatic: false,
  5538. allowExact: false,
  5539. allowSpread: true,
  5540. allowProto: false,
  5541. allowInexact: true
  5542. });
  5543. case 6:
  5544. return this.flowParseObjectType({
  5545. allowStatic: false,
  5546. allowExact: true,
  5547. allowSpread: true,
  5548. allowProto: false,
  5549. allowInexact: false
  5550. });
  5551. case 0:
  5552. this.state.noAnonFunctionType = false;
  5553. type = this.flowParseTupleType();
  5554. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5555. return type;
  5556. case 47:
  5557. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5558. this.expect(10);
  5559. tmp = this.flowParseFunctionTypeParams();
  5560. node.params = tmp.params;
  5561. node.rest = tmp.rest;
  5562. node.this = tmp._this;
  5563. this.expect(11);
  5564. this.expect(19);
  5565. node.returnType = this.flowParseType();
  5566. return this.finishNode(node, "FunctionTypeAnnotation");
  5567. case 10:
  5568. this.next();
  5569. if (!this.match(11) && !this.match(21)) {
  5570. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  5571. const token = this.lookahead().type;
  5572. isGroupedType = token !== 17 && token !== 14;
  5573. } else {
  5574. isGroupedType = true;
  5575. }
  5576. }
  5577. if (isGroupedType) {
  5578. this.state.noAnonFunctionType = false;
  5579. type = this.flowParseType();
  5580. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5581. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  5582. this.expect(11);
  5583. return type;
  5584. } else {
  5585. this.eat(12);
  5586. }
  5587. }
  5588. if (type) {
  5589. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  5590. } else {
  5591. tmp = this.flowParseFunctionTypeParams();
  5592. }
  5593. node.params = tmp.params;
  5594. node.rest = tmp.rest;
  5595. node.this = tmp._this;
  5596. this.expect(11);
  5597. this.expect(19);
  5598. node.returnType = this.flowParseType();
  5599. node.typeParameters = null;
  5600. return this.finishNode(node, "FunctionTypeAnnotation");
  5601. case 131:
  5602. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  5603. case 85:
  5604. case 86:
  5605. node.value = this.match(85);
  5606. this.next();
  5607. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  5608. case 53:
  5609. if (this.state.value === "-") {
  5610. this.next();
  5611. if (this.match(132)) {
  5612. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  5613. }
  5614. if (this.match(133)) {
  5615. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  5616. }
  5617. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, {
  5618. at: this.state.startLoc
  5619. });
  5620. }
  5621. this.unexpected();
  5622. return;
  5623. case 132:
  5624. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  5625. case 133:
  5626. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  5627. case 88:
  5628. this.next();
  5629. return this.finishNode(node, "VoidTypeAnnotation");
  5630. case 84:
  5631. this.next();
  5632. return this.finishNode(node, "NullLiteralTypeAnnotation");
  5633. case 78:
  5634. this.next();
  5635. return this.finishNode(node, "ThisTypeAnnotation");
  5636. case 55:
  5637. this.next();
  5638. return this.finishNode(node, "ExistsTypeAnnotation");
  5639. case 87:
  5640. return this.flowParseTypeofType();
  5641. default:
  5642. if (tokenIsKeyword(this.state.type)) {
  5643. const label = tokenLabelName(this.state.type);
  5644. this.next();
  5645. return super.createIdentifier(node, label);
  5646. } else if (tokenIsIdentifier(this.state.type)) {
  5647. if (this.isContextual(127)) {
  5648. return this.flowParseInterfaceType();
  5649. }
  5650. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  5651. }
  5652. }
  5653. this.unexpected();
  5654. }
  5655. flowParsePostfixType() {
  5656. const startLoc = this.state.startLoc;
  5657. let type = this.flowParsePrimaryType();
  5658. let seenOptionalIndexedAccess = false;
  5659. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  5660. const node = this.startNodeAt(startLoc);
  5661. const optional = this.eat(18);
  5662. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  5663. this.expect(0);
  5664. if (!optional && this.match(3)) {
  5665. node.elementType = type;
  5666. this.next();
  5667. type = this.finishNode(node, "ArrayTypeAnnotation");
  5668. } else {
  5669. node.objectType = type;
  5670. node.indexType = this.flowParseType();
  5671. this.expect(3);
  5672. if (seenOptionalIndexedAccess) {
  5673. node.optional = optional;
  5674. type = this.finishNode(node, "OptionalIndexedAccessType");
  5675. } else {
  5676. type = this.finishNode(node, "IndexedAccessType");
  5677. }
  5678. }
  5679. }
  5680. return type;
  5681. }
  5682. flowParsePrefixType() {
  5683. const node = this.startNode();
  5684. if (this.eat(17)) {
  5685. node.typeAnnotation = this.flowParsePrefixType();
  5686. return this.finishNode(node, "NullableTypeAnnotation");
  5687. } else {
  5688. return this.flowParsePostfixType();
  5689. }
  5690. }
  5691. flowParseAnonFunctionWithoutParens() {
  5692. const param = this.flowParsePrefixType();
  5693. if (!this.state.noAnonFunctionType && this.eat(19)) {
  5694. const node = this.startNodeAt(param.loc.start);
  5695. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  5696. node.rest = null;
  5697. node.this = null;
  5698. node.returnType = this.flowParseType();
  5699. node.typeParameters = null;
  5700. return this.finishNode(node, "FunctionTypeAnnotation");
  5701. }
  5702. return param;
  5703. }
  5704. flowParseIntersectionType() {
  5705. const node = this.startNode();
  5706. this.eat(45);
  5707. const type = this.flowParseAnonFunctionWithoutParens();
  5708. node.types = [type];
  5709. while (this.eat(45)) {
  5710. node.types.push(this.flowParseAnonFunctionWithoutParens());
  5711. }
  5712. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5713. }
  5714. flowParseUnionType() {
  5715. const node = this.startNode();
  5716. this.eat(43);
  5717. const type = this.flowParseIntersectionType();
  5718. node.types = [type];
  5719. while (this.eat(43)) {
  5720. node.types.push(this.flowParseIntersectionType());
  5721. }
  5722. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5723. }
  5724. flowParseType() {
  5725. const oldInType = this.state.inType;
  5726. this.state.inType = true;
  5727. const type = this.flowParseUnionType();
  5728. this.state.inType = oldInType;
  5729. return type;
  5730. }
  5731. flowParseTypeOrImplicitInstantiation() {
  5732. if (this.state.type === 130 && this.state.value === "_") {
  5733. const startLoc = this.state.startLoc;
  5734. const node = this.parseIdentifier();
  5735. return this.flowParseGenericType(startLoc, node);
  5736. } else {
  5737. return this.flowParseType();
  5738. }
  5739. }
  5740. flowParseTypeAnnotation() {
  5741. const node = this.startNode();
  5742. node.typeAnnotation = this.flowParseTypeInitialiser();
  5743. return this.finishNode(node, "TypeAnnotation");
  5744. }
  5745. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5746. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5747. if (this.match(14)) {
  5748. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5749. this.resetEndLocation(ident);
  5750. }
  5751. return ident;
  5752. }
  5753. typeCastToParameter(node) {
  5754. node.expression.typeAnnotation = node.typeAnnotation;
  5755. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5756. return node.expression;
  5757. }
  5758. flowParseVariance() {
  5759. let variance = null;
  5760. if (this.match(53)) {
  5761. variance = this.startNode();
  5762. if (this.state.value === "+") {
  5763. variance.kind = "plus";
  5764. } else {
  5765. variance.kind = "minus";
  5766. }
  5767. this.next();
  5768. return this.finishNode(variance, "Variance");
  5769. }
  5770. return variance;
  5771. }
  5772. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5773. if (allowExpressionBody) {
  5774. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5775. return;
  5776. }
  5777. super.parseFunctionBody(node, false, isMethod);
  5778. }
  5779. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5780. if (this.match(14)) {
  5781. const typeNode = this.startNode();
  5782. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5783. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5784. }
  5785. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5786. }
  5787. parseStatementLike(flags) {
  5788. if (this.state.strict && this.isContextual(127)) {
  5789. const lookahead = this.lookahead();
  5790. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5791. const node = this.startNode();
  5792. this.next();
  5793. return this.flowParseInterface(node);
  5794. }
  5795. } else if (this.shouldParseEnums() && this.isContextual(124)) {
  5796. const node = this.startNode();
  5797. this.next();
  5798. return this.flowParseEnumDeclaration(node);
  5799. }
  5800. const stmt = super.parseStatementLike(flags);
  5801. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5802. this.flowPragma = null;
  5803. }
  5804. return stmt;
  5805. }
  5806. parseExpressionStatement(node, expr, decorators) {
  5807. if (expr.type === "Identifier") {
  5808. if (expr.name === "declare") {
  5809. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5810. return this.flowParseDeclare(node);
  5811. }
  5812. } else if (tokenIsIdentifier(this.state.type)) {
  5813. if (expr.name === "interface") {
  5814. return this.flowParseInterface(node);
  5815. } else if (expr.name === "type") {
  5816. return this.flowParseTypeAlias(node);
  5817. } else if (expr.name === "opaque") {
  5818. return this.flowParseOpaqueType(node, false);
  5819. }
  5820. }
  5821. }
  5822. return super.parseExpressionStatement(node, expr, decorators);
  5823. }
  5824. shouldParseExportDeclaration() {
  5825. const {
  5826. type
  5827. } = this.state;
  5828. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
  5829. return !this.state.containsEsc;
  5830. }
  5831. return super.shouldParseExportDeclaration();
  5832. }
  5833. isExportDefaultSpecifier() {
  5834. const {
  5835. type
  5836. } = this.state;
  5837. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
  5838. return this.state.containsEsc;
  5839. }
  5840. return super.isExportDefaultSpecifier();
  5841. }
  5842. parseExportDefaultExpression() {
  5843. if (this.shouldParseEnums() && this.isContextual(124)) {
  5844. const node = this.startNode();
  5845. this.next();
  5846. return this.flowParseEnumDeclaration(node);
  5847. }
  5848. return super.parseExportDefaultExpression();
  5849. }
  5850. parseConditional(expr, startLoc, refExpressionErrors) {
  5851. if (!this.match(17)) return expr;
  5852. if (this.state.maybeInArrowParameters) {
  5853. const nextCh = this.lookaheadCharCode();
  5854. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5855. this.setOptionalParametersError(refExpressionErrors);
  5856. return expr;
  5857. }
  5858. }
  5859. this.expect(17);
  5860. const state = this.state.clone();
  5861. const originalNoArrowAt = this.state.noArrowAt;
  5862. const node = this.startNodeAt(startLoc);
  5863. let {
  5864. consequent,
  5865. failed
  5866. } = this.tryParseConditionalConsequent();
  5867. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5868. if (failed || invalid.length > 0) {
  5869. const noArrowAt = [...originalNoArrowAt];
  5870. if (invalid.length > 0) {
  5871. this.state = state;
  5872. this.state.noArrowAt = noArrowAt;
  5873. for (let i = 0; i < invalid.length; i++) {
  5874. noArrowAt.push(invalid[i].start);
  5875. }
  5876. ({
  5877. consequent,
  5878. failed
  5879. } = this.tryParseConditionalConsequent());
  5880. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5881. }
  5882. if (failed && valid.length > 1) {
  5883. this.raise(FlowErrors.AmbiguousConditionalArrow, {
  5884. at: state.startLoc
  5885. });
  5886. }
  5887. if (failed && valid.length === 1) {
  5888. this.state = state;
  5889. noArrowAt.push(valid[0].start);
  5890. this.state.noArrowAt = noArrowAt;
  5891. ({
  5892. consequent,
  5893. failed
  5894. } = this.tryParseConditionalConsequent());
  5895. }
  5896. }
  5897. this.getArrowLikeExpressions(consequent, true);
  5898. this.state.noArrowAt = originalNoArrowAt;
  5899. this.expect(14);
  5900. node.test = expr;
  5901. node.consequent = consequent;
  5902. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5903. return this.finishNode(node, "ConditionalExpression");
  5904. }
  5905. tryParseConditionalConsequent() {
  5906. this.state.noArrowParamsConversionAt.push(this.state.start);
  5907. const consequent = this.parseMaybeAssignAllowIn();
  5908. const failed = !this.match(14);
  5909. this.state.noArrowParamsConversionAt.pop();
  5910. return {
  5911. consequent,
  5912. failed
  5913. };
  5914. }
  5915. getArrowLikeExpressions(node, disallowInvalid) {
  5916. const stack = [node];
  5917. const arrows = [];
  5918. while (stack.length !== 0) {
  5919. const node = stack.pop();
  5920. if (node.type === "ArrowFunctionExpression") {
  5921. if (node.typeParameters || !node.returnType) {
  5922. this.finishArrowValidation(node);
  5923. } else {
  5924. arrows.push(node);
  5925. }
  5926. stack.push(node.body);
  5927. } else if (node.type === "ConditionalExpression") {
  5928. stack.push(node.consequent);
  5929. stack.push(node.alternate);
  5930. }
  5931. }
  5932. if (disallowInvalid) {
  5933. arrows.forEach(node => this.finishArrowValidation(node));
  5934. return [arrows, []];
  5935. }
  5936. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5937. }
  5938. finishArrowValidation(node) {
  5939. var _node$extra;
  5940. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5941. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  5942. super.checkParams(node, false, true);
  5943. this.scope.exit();
  5944. }
  5945. forwardNoArrowParamsConversionAt(node, parse) {
  5946. let result;
  5947. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5948. this.state.noArrowParamsConversionAt.push(this.state.start);
  5949. result = parse();
  5950. this.state.noArrowParamsConversionAt.pop();
  5951. } else {
  5952. result = parse();
  5953. }
  5954. return result;
  5955. }
  5956. parseParenItem(node, startLoc) {
  5957. node = super.parseParenItem(node, startLoc);
  5958. if (this.eat(17)) {
  5959. node.optional = true;
  5960. this.resetEndLocation(node);
  5961. }
  5962. if (this.match(14)) {
  5963. const typeCastNode = this.startNodeAt(startLoc);
  5964. typeCastNode.expression = node;
  5965. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5966. return this.finishNode(typeCastNode, "TypeCastExpression");
  5967. }
  5968. return node;
  5969. }
  5970. assertModuleNodeAllowed(node) {
  5971. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5972. return;
  5973. }
  5974. super.assertModuleNodeAllowed(node);
  5975. }
  5976. parseExport(node, decorators) {
  5977. const decl = super.parseExport(node, decorators);
  5978. if (decl.type === "ExportNamedDeclaration" || decl.type === "ExportAllDeclaration") {
  5979. decl.exportKind = decl.exportKind || "value";
  5980. }
  5981. return decl;
  5982. }
  5983. parseExportDeclaration(node) {
  5984. if (this.isContextual(128)) {
  5985. node.exportKind = "type";
  5986. const declarationNode = this.startNode();
  5987. this.next();
  5988. if (this.match(5)) {
  5989. node.specifiers = this.parseExportSpecifiers(true);
  5990. super.parseExportFrom(node);
  5991. return null;
  5992. } else {
  5993. return this.flowParseTypeAlias(declarationNode);
  5994. }
  5995. } else if (this.isContextual(129)) {
  5996. node.exportKind = "type";
  5997. const declarationNode = this.startNode();
  5998. this.next();
  5999. return this.flowParseOpaqueType(declarationNode, false);
  6000. } else if (this.isContextual(127)) {
  6001. node.exportKind = "type";
  6002. const declarationNode = this.startNode();
  6003. this.next();
  6004. return this.flowParseInterface(declarationNode);
  6005. } else if (this.shouldParseEnums() && this.isContextual(124)) {
  6006. node.exportKind = "value";
  6007. const declarationNode = this.startNode();
  6008. this.next();
  6009. return this.flowParseEnumDeclaration(declarationNode);
  6010. } else {
  6011. return super.parseExportDeclaration(node);
  6012. }
  6013. }
  6014. eatExportStar(node) {
  6015. if (super.eatExportStar(node)) return true;
  6016. if (this.isContextual(128) && this.lookahead().type === 55) {
  6017. node.exportKind = "type";
  6018. this.next();
  6019. this.next();
  6020. return true;
  6021. }
  6022. return false;
  6023. }
  6024. maybeParseExportNamespaceSpecifier(node) {
  6025. const {
  6026. startLoc
  6027. } = this.state;
  6028. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  6029. if (hasNamespace && node.exportKind === "type") {
  6030. this.unexpected(startLoc);
  6031. }
  6032. return hasNamespace;
  6033. }
  6034. parseClassId(node, isStatement, optionalId) {
  6035. super.parseClassId(node, isStatement, optionalId);
  6036. if (this.match(47)) {
  6037. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6038. }
  6039. }
  6040. parseClassMember(classBody, member, state) {
  6041. const {
  6042. startLoc
  6043. } = this.state;
  6044. if (this.isContextual(123)) {
  6045. if (super.parseClassMemberFromModifier(classBody, member)) {
  6046. return;
  6047. }
  6048. member.declare = true;
  6049. }
  6050. super.parseClassMember(classBody, member, state);
  6051. if (member.declare) {
  6052. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  6053. this.raise(FlowErrors.DeclareClassElement, {
  6054. at: startLoc
  6055. });
  6056. } else if (member.value) {
  6057. this.raise(FlowErrors.DeclareClassFieldInitializer, {
  6058. at: member.value
  6059. });
  6060. }
  6061. }
  6062. }
  6063. isIterator(word) {
  6064. return word === "iterator" || word === "asyncIterator";
  6065. }
  6066. readIterator() {
  6067. const word = super.readWord1();
  6068. const fullWord = "@@" + word;
  6069. if (!this.isIterator(word) || !this.state.inType) {
  6070. this.raise(Errors.InvalidIdentifier, {
  6071. at: this.state.curPosition(),
  6072. identifierName: fullWord
  6073. });
  6074. }
  6075. this.finishToken(130, fullWord);
  6076. }
  6077. getTokenFromCode(code) {
  6078. const next = this.input.charCodeAt(this.state.pos + 1);
  6079. if (code === 123 && next === 124) {
  6080. this.finishOp(6, 2);
  6081. } else if (this.state.inType && (code === 62 || code === 60)) {
  6082. this.finishOp(code === 62 ? 48 : 47, 1);
  6083. } else if (this.state.inType && code === 63) {
  6084. if (next === 46) {
  6085. this.finishOp(18, 2);
  6086. } else {
  6087. this.finishOp(17, 1);
  6088. }
  6089. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  6090. this.state.pos += 2;
  6091. this.readIterator();
  6092. } else {
  6093. super.getTokenFromCode(code);
  6094. }
  6095. }
  6096. isAssignable(node, isBinding) {
  6097. if (node.type === "TypeCastExpression") {
  6098. return this.isAssignable(node.expression, isBinding);
  6099. } else {
  6100. return super.isAssignable(node, isBinding);
  6101. }
  6102. }
  6103. toAssignable(node, isLHS = false) {
  6104. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  6105. node.left = this.typeCastToParameter(node.left);
  6106. }
  6107. super.toAssignable(node, isLHS);
  6108. }
  6109. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  6110. for (let i = 0; i < exprList.length; i++) {
  6111. const expr = exprList[i];
  6112. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  6113. exprList[i] = this.typeCastToParameter(expr);
  6114. }
  6115. }
  6116. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  6117. }
  6118. toReferencedList(exprList, isParenthesizedExpr) {
  6119. for (let i = 0; i < exprList.length; i++) {
  6120. var _expr$extra;
  6121. const expr = exprList[i];
  6122. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  6123. this.raise(FlowErrors.TypeCastInPattern, {
  6124. at: expr.typeAnnotation
  6125. });
  6126. }
  6127. }
  6128. return exprList;
  6129. }
  6130. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  6131. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  6132. if (canBePattern && !this.state.maybeInArrowParameters) {
  6133. this.toReferencedList(node.elements);
  6134. }
  6135. return node;
  6136. }
  6137. isValidLVal(type, isParenthesized, binding) {
  6138. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  6139. }
  6140. parseClassProperty(node) {
  6141. if (this.match(14)) {
  6142. node.typeAnnotation = this.flowParseTypeAnnotation();
  6143. }
  6144. return super.parseClassProperty(node);
  6145. }
  6146. parseClassPrivateProperty(node) {
  6147. if (this.match(14)) {
  6148. node.typeAnnotation = this.flowParseTypeAnnotation();
  6149. }
  6150. return super.parseClassPrivateProperty(node);
  6151. }
  6152. isClassMethod() {
  6153. return this.match(47) || super.isClassMethod();
  6154. }
  6155. isClassProperty() {
  6156. return this.match(14) || super.isClassProperty();
  6157. }
  6158. isNonstaticConstructor(method) {
  6159. return !this.match(14) && super.isNonstaticConstructor(method);
  6160. }
  6161. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  6162. if (method.variance) {
  6163. this.unexpected(method.variance.loc.start);
  6164. }
  6165. delete method.variance;
  6166. if (this.match(47)) {
  6167. method.typeParameters = this.flowParseTypeParameterDeclaration();
  6168. }
  6169. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  6170. if (method.params && isConstructor) {
  6171. const params = method.params;
  6172. if (params.length > 0 && this.isThisParam(params[0])) {
  6173. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  6174. at: method
  6175. });
  6176. }
  6177. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  6178. const params = method.value.params;
  6179. if (params.length > 0 && this.isThisParam(params[0])) {
  6180. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  6181. at: method
  6182. });
  6183. }
  6184. }
  6185. }
  6186. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  6187. if (method.variance) {
  6188. this.unexpected(method.variance.loc.start);
  6189. }
  6190. delete method.variance;
  6191. if (this.match(47)) {
  6192. method.typeParameters = this.flowParseTypeParameterDeclaration();
  6193. }
  6194. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  6195. }
  6196. parseClassSuper(node) {
  6197. super.parseClassSuper(node);
  6198. if (node.superClass && this.match(47)) {
  6199. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  6200. }
  6201. if (this.isContextual(111)) {
  6202. this.next();
  6203. const implemented = node.implements = [];
  6204. do {
  6205. const node = this.startNode();
  6206. node.id = this.flowParseRestrictedIdentifier(true);
  6207. if (this.match(47)) {
  6208. node.typeParameters = this.flowParseTypeParameterInstantiation();
  6209. } else {
  6210. node.typeParameters = null;
  6211. }
  6212. implemented.push(this.finishNode(node, "ClassImplements"));
  6213. } while (this.eat(12));
  6214. }
  6215. }
  6216. checkGetterSetterParams(method) {
  6217. super.checkGetterSetterParams(method);
  6218. const params = this.getObjectOrClassMethodParams(method);
  6219. if (params.length > 0) {
  6220. const param = params[0];
  6221. if (this.isThisParam(param) && method.kind === "get") {
  6222. this.raise(FlowErrors.GetterMayNotHaveThisParam, {
  6223. at: param
  6224. });
  6225. } else if (this.isThisParam(param)) {
  6226. this.raise(FlowErrors.SetterMayNotHaveThisParam, {
  6227. at: param
  6228. });
  6229. }
  6230. }
  6231. }
  6232. parsePropertyNamePrefixOperator(node) {
  6233. node.variance = this.flowParseVariance();
  6234. }
  6235. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  6236. if (prop.variance) {
  6237. this.unexpected(prop.variance.loc.start);
  6238. }
  6239. delete prop.variance;
  6240. let typeParameters;
  6241. if (this.match(47) && !isAccessor) {
  6242. typeParameters = this.flowParseTypeParameterDeclaration();
  6243. if (!this.match(10)) this.unexpected();
  6244. }
  6245. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  6246. if (typeParameters) {
  6247. (result.value || result).typeParameters = typeParameters;
  6248. }
  6249. return result;
  6250. }
  6251. parseAssignableListItemTypes(param) {
  6252. if (this.eat(17)) {
  6253. if (param.type !== "Identifier") {
  6254. this.raise(FlowErrors.PatternIsOptional, {
  6255. at: param
  6256. });
  6257. }
  6258. if (this.isThisParam(param)) {
  6259. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  6260. at: param
  6261. });
  6262. }
  6263. param.optional = true;
  6264. }
  6265. if (this.match(14)) {
  6266. param.typeAnnotation = this.flowParseTypeAnnotation();
  6267. } else if (this.isThisParam(param)) {
  6268. this.raise(FlowErrors.ThisParamAnnotationRequired, {
  6269. at: param
  6270. });
  6271. }
  6272. if (this.match(29) && this.isThisParam(param)) {
  6273. this.raise(FlowErrors.ThisParamNoDefault, {
  6274. at: param
  6275. });
  6276. }
  6277. this.resetEndLocation(param);
  6278. return param;
  6279. }
  6280. parseMaybeDefault(startLoc, left) {
  6281. const node = super.parseMaybeDefault(startLoc, left);
  6282. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  6283. this.raise(FlowErrors.TypeBeforeInitializer, {
  6284. at: node.typeAnnotation
  6285. });
  6286. }
  6287. return node;
  6288. }
  6289. shouldParseDefaultImport(node) {
  6290. if (!hasTypeImportKind(node)) {
  6291. return super.shouldParseDefaultImport(node);
  6292. }
  6293. return isMaybeDefaultImport(this.state.type);
  6294. }
  6295. checkImportReflection(node) {
  6296. super.checkImportReflection(node);
  6297. if (node.module && node.importKind !== "value") {
  6298. this.raise(FlowErrors.ImportReflectionHasImportType, {
  6299. at: node.specifiers[0].loc.start
  6300. });
  6301. }
  6302. }
  6303. parseImportSpecifierLocal(node, specifier, type) {
  6304. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  6305. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  6306. }
  6307. maybeParseDefaultImportSpecifier(node) {
  6308. node.importKind = "value";
  6309. let kind = null;
  6310. if (this.match(87)) {
  6311. kind = "typeof";
  6312. } else if (this.isContextual(128)) {
  6313. kind = "type";
  6314. }
  6315. if (kind) {
  6316. const lh = this.lookahead();
  6317. const {
  6318. type
  6319. } = lh;
  6320. if (kind === "type" && type === 55) {
  6321. this.unexpected(null, lh.type);
  6322. }
  6323. if (isMaybeDefaultImport(type) || type === 5 || type === 55) {
  6324. this.next();
  6325. node.importKind = kind;
  6326. }
  6327. }
  6328. return super.maybeParseDefaultImportSpecifier(node);
  6329. }
  6330. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  6331. const firstIdent = specifier.imported;
  6332. let specifierTypeKind = null;
  6333. if (firstIdent.type === "Identifier") {
  6334. if (firstIdent.name === "type") {
  6335. specifierTypeKind = "type";
  6336. } else if (firstIdent.name === "typeof") {
  6337. specifierTypeKind = "typeof";
  6338. }
  6339. }
  6340. let isBinding = false;
  6341. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  6342. const as_ident = this.parseIdentifier(true);
  6343. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  6344. specifier.imported = as_ident;
  6345. specifier.importKind = specifierTypeKind;
  6346. specifier.local = cloneIdentifier(as_ident);
  6347. } else {
  6348. specifier.imported = firstIdent;
  6349. specifier.importKind = null;
  6350. specifier.local = this.parseIdentifier();
  6351. }
  6352. } else {
  6353. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  6354. specifier.imported = this.parseIdentifier(true);
  6355. specifier.importKind = specifierTypeKind;
  6356. } else {
  6357. if (importedIsString) {
  6358. throw this.raise(Errors.ImportBindingIsString, {
  6359. at: specifier,
  6360. importName: firstIdent.value
  6361. });
  6362. }
  6363. specifier.imported = firstIdent;
  6364. specifier.importKind = null;
  6365. }
  6366. if (this.eatContextual(93)) {
  6367. specifier.local = this.parseIdentifier();
  6368. } else {
  6369. isBinding = true;
  6370. specifier.local = cloneIdentifier(specifier.imported);
  6371. }
  6372. }
  6373. const specifierIsTypeImport = hasTypeImportKind(specifier);
  6374. if (isInTypeOnlyImport && specifierIsTypeImport) {
  6375. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, {
  6376. at: specifier
  6377. });
  6378. }
  6379. if (isInTypeOnlyImport || specifierIsTypeImport) {
  6380. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  6381. }
  6382. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  6383. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  6384. }
  6385. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  6386. }
  6387. parseBindingAtom() {
  6388. switch (this.state.type) {
  6389. case 78:
  6390. return this.parseIdentifier(true);
  6391. default:
  6392. return super.parseBindingAtom();
  6393. }
  6394. }
  6395. parseFunctionParams(node, isConstructor) {
  6396. const kind = node.kind;
  6397. if (kind !== "get" && kind !== "set" && this.match(47)) {
  6398. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6399. }
  6400. super.parseFunctionParams(node, isConstructor);
  6401. }
  6402. parseVarId(decl, kind) {
  6403. super.parseVarId(decl, kind);
  6404. if (this.match(14)) {
  6405. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  6406. this.resetEndLocation(decl.id);
  6407. }
  6408. }
  6409. parseAsyncArrowFromCallExpression(node, call) {
  6410. if (this.match(14)) {
  6411. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  6412. this.state.noAnonFunctionType = true;
  6413. node.returnType = this.flowParseTypeAnnotation();
  6414. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6415. }
  6416. return super.parseAsyncArrowFromCallExpression(node, call);
  6417. }
  6418. shouldParseAsyncArrow() {
  6419. return this.match(14) || super.shouldParseAsyncArrow();
  6420. }
  6421. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  6422. var _jsx;
  6423. let state = null;
  6424. let jsx;
  6425. if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
  6426. state = this.state.clone();
  6427. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  6428. if (!jsx.error) return jsx.node;
  6429. const {
  6430. context
  6431. } = this.state;
  6432. const currentContext = context[context.length - 1];
  6433. if (currentContext === types$1.j_oTag || currentContext === types$1.j_expr) {
  6434. context.pop();
  6435. }
  6436. }
  6437. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  6438. var _jsx2, _jsx3;
  6439. state = state || this.state.clone();
  6440. let typeParameters;
  6441. const arrow = this.tryParse(abort => {
  6442. var _arrowExpression$extr;
  6443. typeParameters = this.flowParseTypeParameterDeclaration();
  6444. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  6445. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  6446. this.resetStartLocationFromNode(result, typeParameters);
  6447. return result;
  6448. });
  6449. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  6450. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  6451. if (expr.type !== "ArrowFunctionExpression") abort();
  6452. expr.typeParameters = typeParameters;
  6453. this.resetStartLocationFromNode(expr, typeParameters);
  6454. return arrowExpression;
  6455. }, state);
  6456. let arrowExpression = null;
  6457. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  6458. if (!arrow.error && !arrow.aborted) {
  6459. if (arrow.node.async) {
  6460. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, {
  6461. at: typeParameters
  6462. });
  6463. }
  6464. return arrow.node;
  6465. }
  6466. arrowExpression = arrow.node;
  6467. }
  6468. if ((_jsx2 = jsx) != null && _jsx2.node) {
  6469. this.state = jsx.failState;
  6470. return jsx.node;
  6471. }
  6472. if (arrowExpression) {
  6473. this.state = arrow.failState;
  6474. return arrowExpression;
  6475. }
  6476. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  6477. if (arrow.thrown) throw arrow.error;
  6478. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, {
  6479. at: typeParameters
  6480. });
  6481. }
  6482. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  6483. }
  6484. parseArrow(node) {
  6485. if (this.match(14)) {
  6486. const result = this.tryParse(() => {
  6487. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  6488. this.state.noAnonFunctionType = true;
  6489. const typeNode = this.startNode();
  6490. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  6491. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6492. if (this.canInsertSemicolon()) this.unexpected();
  6493. if (!this.match(19)) this.unexpected();
  6494. return typeNode;
  6495. });
  6496. if (result.thrown) return null;
  6497. if (result.error) this.state = result.failState;
  6498. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  6499. }
  6500. return super.parseArrow(node);
  6501. }
  6502. shouldParseArrow(params) {
  6503. return this.match(14) || super.shouldParseArrow(params);
  6504. }
  6505. setArrowFunctionParameters(node, params) {
  6506. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  6507. node.params = params;
  6508. } else {
  6509. super.setArrowFunctionParameters(node, params);
  6510. }
  6511. }
  6512. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  6513. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  6514. return;
  6515. }
  6516. for (let i = 0; i < node.params.length; i++) {
  6517. if (this.isThisParam(node.params[i]) && i > 0) {
  6518. this.raise(FlowErrors.ThisParamMustBeFirst, {
  6519. at: node.params[i]
  6520. });
  6521. }
  6522. }
  6523. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  6524. }
  6525. parseParenAndDistinguishExpression(canBeArrow) {
  6526. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  6527. }
  6528. parseSubscripts(base, startLoc, noCalls) {
  6529. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startLoc.index) !== -1) {
  6530. this.next();
  6531. const node = this.startNodeAt(startLoc);
  6532. node.callee = base;
  6533. node.arguments = super.parseCallExpressionArguments(11, false);
  6534. base = this.finishNode(node, "CallExpression");
  6535. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  6536. const state = this.state.clone();
  6537. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  6538. if (!arrow.error && !arrow.aborted) return arrow.node;
  6539. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  6540. if (result.node && !result.error) return result.node;
  6541. if (arrow.node) {
  6542. this.state = arrow.failState;
  6543. return arrow.node;
  6544. }
  6545. if (result.node) {
  6546. this.state = result.failState;
  6547. return result.node;
  6548. }
  6549. throw arrow.error || result.error;
  6550. }
  6551. return super.parseSubscripts(base, startLoc, noCalls);
  6552. }
  6553. parseSubscript(base, startLoc, noCalls, subscriptState) {
  6554. if (this.match(18) && this.isLookaheadToken_lt()) {
  6555. subscriptState.optionalChainMember = true;
  6556. if (noCalls) {
  6557. subscriptState.stop = true;
  6558. return base;
  6559. }
  6560. this.next();
  6561. const node = this.startNodeAt(startLoc);
  6562. node.callee = base;
  6563. node.typeArguments = this.flowParseTypeParameterInstantiation();
  6564. this.expect(10);
  6565. node.arguments = this.parseCallExpressionArguments(11, false);
  6566. node.optional = true;
  6567. return this.finishCallExpression(node, true);
  6568. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  6569. const node = this.startNodeAt(startLoc);
  6570. node.callee = base;
  6571. const result = this.tryParse(() => {
  6572. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  6573. this.expect(10);
  6574. node.arguments = super.parseCallExpressionArguments(11, false);
  6575. if (subscriptState.optionalChainMember) {
  6576. node.optional = false;
  6577. }
  6578. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  6579. });
  6580. if (result.node) {
  6581. if (result.error) this.state = result.failState;
  6582. return result.node;
  6583. }
  6584. }
  6585. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  6586. }
  6587. parseNewCallee(node) {
  6588. super.parseNewCallee(node);
  6589. let targs = null;
  6590. if (this.shouldParseTypes() && this.match(47)) {
  6591. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  6592. }
  6593. node.typeArguments = targs;
  6594. }
  6595. parseAsyncArrowWithTypeParameters(startLoc) {
  6596. const node = this.startNodeAt(startLoc);
  6597. this.parseFunctionParams(node, false);
  6598. if (!this.parseArrow(node)) return;
  6599. return super.parseArrowExpression(node, undefined, true);
  6600. }
  6601. readToken_mult_modulo(code) {
  6602. const next = this.input.charCodeAt(this.state.pos + 1);
  6603. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  6604. this.state.hasFlowComment = false;
  6605. this.state.pos += 2;
  6606. this.nextToken();
  6607. return;
  6608. }
  6609. super.readToken_mult_modulo(code);
  6610. }
  6611. readToken_pipe_amp(code) {
  6612. const next = this.input.charCodeAt(this.state.pos + 1);
  6613. if (code === 124 && next === 125) {
  6614. this.finishOp(9, 2);
  6615. return;
  6616. }
  6617. super.readToken_pipe_amp(code);
  6618. }
  6619. parseTopLevel(file, program) {
  6620. const fileNode = super.parseTopLevel(file, program);
  6621. if (this.state.hasFlowComment) {
  6622. this.raise(FlowErrors.UnterminatedFlowComment, {
  6623. at: this.state.curPosition()
  6624. });
  6625. }
  6626. return fileNode;
  6627. }
  6628. skipBlockComment() {
  6629. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  6630. if (this.state.hasFlowComment) {
  6631. throw this.raise(FlowErrors.NestedFlowComment, {
  6632. at: this.state.startLoc
  6633. });
  6634. }
  6635. this.hasFlowCommentCompletion();
  6636. const commentSkip = this.skipFlowComment();
  6637. if (commentSkip) {
  6638. this.state.pos += commentSkip;
  6639. this.state.hasFlowComment = true;
  6640. }
  6641. return;
  6642. }
  6643. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  6644. }
  6645. skipFlowComment() {
  6646. const {
  6647. pos
  6648. } = this.state;
  6649. let shiftToFirstNonWhiteSpace = 2;
  6650. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  6651. shiftToFirstNonWhiteSpace++;
  6652. }
  6653. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  6654. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  6655. if (ch2 === 58 && ch3 === 58) {
  6656. return shiftToFirstNonWhiteSpace + 2;
  6657. }
  6658. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  6659. return shiftToFirstNonWhiteSpace + 12;
  6660. }
  6661. if (ch2 === 58 && ch3 !== 58) {
  6662. return shiftToFirstNonWhiteSpace;
  6663. }
  6664. return false;
  6665. }
  6666. hasFlowCommentCompletion() {
  6667. const end = this.input.indexOf("*/", this.state.pos);
  6668. if (end === -1) {
  6669. throw this.raise(Errors.UnterminatedComment, {
  6670. at: this.state.curPosition()
  6671. });
  6672. }
  6673. }
  6674. flowEnumErrorBooleanMemberNotInitialized(loc, {
  6675. enumName,
  6676. memberName
  6677. }) {
  6678. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, {
  6679. at: loc,
  6680. memberName,
  6681. enumName
  6682. });
  6683. }
  6684. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  6685. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({
  6686. at: loc
  6687. }, enumContext));
  6688. }
  6689. flowEnumErrorNumberMemberNotInitialized(loc, {
  6690. enumName,
  6691. memberName
  6692. }) {
  6693. this.raise(FlowErrors.EnumNumberMemberNotInitialized, {
  6694. at: loc,
  6695. enumName,
  6696. memberName
  6697. });
  6698. }
  6699. flowEnumErrorStringMemberInconsistentlyInitailized(node, {
  6700. enumName
  6701. }) {
  6702. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitailized, {
  6703. at: node,
  6704. enumName
  6705. });
  6706. }
  6707. flowEnumMemberInit() {
  6708. const startLoc = this.state.startLoc;
  6709. const endOfInit = () => this.match(12) || this.match(8);
  6710. switch (this.state.type) {
  6711. case 132:
  6712. {
  6713. const literal = this.parseNumericLiteral(this.state.value);
  6714. if (endOfInit()) {
  6715. return {
  6716. type: "number",
  6717. loc: literal.loc.start,
  6718. value: literal
  6719. };
  6720. }
  6721. return {
  6722. type: "invalid",
  6723. loc: startLoc
  6724. };
  6725. }
  6726. case 131:
  6727. {
  6728. const literal = this.parseStringLiteral(this.state.value);
  6729. if (endOfInit()) {
  6730. return {
  6731. type: "string",
  6732. loc: literal.loc.start,
  6733. value: literal
  6734. };
  6735. }
  6736. return {
  6737. type: "invalid",
  6738. loc: startLoc
  6739. };
  6740. }
  6741. case 85:
  6742. case 86:
  6743. {
  6744. const literal = this.parseBooleanLiteral(this.match(85));
  6745. if (endOfInit()) {
  6746. return {
  6747. type: "boolean",
  6748. loc: literal.loc.start,
  6749. value: literal
  6750. };
  6751. }
  6752. return {
  6753. type: "invalid",
  6754. loc: startLoc
  6755. };
  6756. }
  6757. default:
  6758. return {
  6759. type: "invalid",
  6760. loc: startLoc
  6761. };
  6762. }
  6763. }
  6764. flowEnumMemberRaw() {
  6765. const loc = this.state.startLoc;
  6766. const id = this.parseIdentifier(true);
  6767. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6768. type: "none",
  6769. loc
  6770. };
  6771. return {
  6772. id,
  6773. init
  6774. };
  6775. }
  6776. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6777. const {
  6778. explicitType
  6779. } = context;
  6780. if (explicitType === null) {
  6781. return;
  6782. }
  6783. if (explicitType !== expectedType) {
  6784. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6785. }
  6786. }
  6787. flowEnumMembers({
  6788. enumName,
  6789. explicitType
  6790. }) {
  6791. const seenNames = new Set();
  6792. const members = {
  6793. booleanMembers: [],
  6794. numberMembers: [],
  6795. stringMembers: [],
  6796. defaultedMembers: []
  6797. };
  6798. let hasUnknownMembers = false;
  6799. while (!this.match(8)) {
  6800. if (this.eat(21)) {
  6801. hasUnknownMembers = true;
  6802. break;
  6803. }
  6804. const memberNode = this.startNode();
  6805. const {
  6806. id,
  6807. init
  6808. } = this.flowEnumMemberRaw();
  6809. const memberName = id.name;
  6810. if (memberName === "") {
  6811. continue;
  6812. }
  6813. if (/^[a-z]/.test(memberName)) {
  6814. this.raise(FlowErrors.EnumInvalidMemberName, {
  6815. at: id,
  6816. memberName,
  6817. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6818. enumName
  6819. });
  6820. }
  6821. if (seenNames.has(memberName)) {
  6822. this.raise(FlowErrors.EnumDuplicateMemberName, {
  6823. at: id,
  6824. memberName,
  6825. enumName
  6826. });
  6827. }
  6828. seenNames.add(memberName);
  6829. const context = {
  6830. enumName,
  6831. explicitType,
  6832. memberName
  6833. };
  6834. memberNode.id = id;
  6835. switch (init.type) {
  6836. case "boolean":
  6837. {
  6838. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6839. memberNode.init = init.value;
  6840. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6841. break;
  6842. }
  6843. case "number":
  6844. {
  6845. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6846. memberNode.init = init.value;
  6847. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6848. break;
  6849. }
  6850. case "string":
  6851. {
  6852. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6853. memberNode.init = init.value;
  6854. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6855. break;
  6856. }
  6857. case "invalid":
  6858. {
  6859. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6860. }
  6861. case "none":
  6862. {
  6863. switch (explicitType) {
  6864. case "boolean":
  6865. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6866. break;
  6867. case "number":
  6868. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6869. break;
  6870. default:
  6871. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6872. }
  6873. }
  6874. }
  6875. if (!this.match(8)) {
  6876. this.expect(12);
  6877. }
  6878. }
  6879. return {
  6880. members,
  6881. hasUnknownMembers
  6882. };
  6883. }
  6884. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6885. enumName
  6886. }) {
  6887. if (initializedMembers.length === 0) {
  6888. return defaultedMembers;
  6889. } else if (defaultedMembers.length === 0) {
  6890. return initializedMembers;
  6891. } else if (defaultedMembers.length > initializedMembers.length) {
  6892. for (const member of initializedMembers) {
  6893. this.flowEnumErrorStringMemberInconsistentlyInitailized(member, {
  6894. enumName
  6895. });
  6896. }
  6897. return defaultedMembers;
  6898. } else {
  6899. for (const member of defaultedMembers) {
  6900. this.flowEnumErrorStringMemberInconsistentlyInitailized(member, {
  6901. enumName
  6902. });
  6903. }
  6904. return initializedMembers;
  6905. }
  6906. }
  6907. flowEnumParseExplicitType({
  6908. enumName
  6909. }) {
  6910. if (!this.eatContextual(101)) return null;
  6911. if (!tokenIsIdentifier(this.state.type)) {
  6912. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, {
  6913. at: this.state.startLoc,
  6914. enumName
  6915. });
  6916. }
  6917. const {
  6918. value
  6919. } = this.state;
  6920. this.next();
  6921. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6922. this.raise(FlowErrors.EnumInvalidExplicitType, {
  6923. at: this.state.startLoc,
  6924. enumName,
  6925. invalidEnumType: value
  6926. });
  6927. }
  6928. return value;
  6929. }
  6930. flowEnumBody(node, id) {
  6931. const enumName = id.name;
  6932. const nameLoc = id.loc.start;
  6933. const explicitType = this.flowEnumParseExplicitType({
  6934. enumName
  6935. });
  6936. this.expect(5);
  6937. const {
  6938. members,
  6939. hasUnknownMembers
  6940. } = this.flowEnumMembers({
  6941. enumName,
  6942. explicitType
  6943. });
  6944. node.hasUnknownMembers = hasUnknownMembers;
  6945. switch (explicitType) {
  6946. case "boolean":
  6947. node.explicitType = true;
  6948. node.members = members.booleanMembers;
  6949. this.expect(8);
  6950. return this.finishNode(node, "EnumBooleanBody");
  6951. case "number":
  6952. node.explicitType = true;
  6953. node.members = members.numberMembers;
  6954. this.expect(8);
  6955. return this.finishNode(node, "EnumNumberBody");
  6956. case "string":
  6957. node.explicitType = true;
  6958. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6959. enumName
  6960. });
  6961. this.expect(8);
  6962. return this.finishNode(node, "EnumStringBody");
  6963. case "symbol":
  6964. node.members = members.defaultedMembers;
  6965. this.expect(8);
  6966. return this.finishNode(node, "EnumSymbolBody");
  6967. default:
  6968. {
  6969. const empty = () => {
  6970. node.members = [];
  6971. this.expect(8);
  6972. return this.finishNode(node, "EnumStringBody");
  6973. };
  6974. node.explicitType = false;
  6975. const boolsLen = members.booleanMembers.length;
  6976. const numsLen = members.numberMembers.length;
  6977. const strsLen = members.stringMembers.length;
  6978. const defaultedLen = members.defaultedMembers.length;
  6979. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6980. return empty();
  6981. } else if (!boolsLen && !numsLen) {
  6982. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6983. enumName
  6984. });
  6985. this.expect(8);
  6986. return this.finishNode(node, "EnumStringBody");
  6987. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6988. for (const member of members.defaultedMembers) {
  6989. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6990. enumName,
  6991. memberName: member.id.name
  6992. });
  6993. }
  6994. node.members = members.booleanMembers;
  6995. this.expect(8);
  6996. return this.finishNode(node, "EnumBooleanBody");
  6997. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6998. for (const member of members.defaultedMembers) {
  6999. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  7000. enumName,
  7001. memberName: member.id.name
  7002. });
  7003. }
  7004. node.members = members.numberMembers;
  7005. this.expect(8);
  7006. return this.finishNode(node, "EnumNumberBody");
  7007. } else {
  7008. this.raise(FlowErrors.EnumInconsistentMemberValues, {
  7009. at: nameLoc,
  7010. enumName
  7011. });
  7012. return empty();
  7013. }
  7014. }
  7015. }
  7016. }
  7017. flowParseEnumDeclaration(node) {
  7018. const id = this.parseIdentifier();
  7019. node.id = id;
  7020. node.body = this.flowEnumBody(this.startNode(), id);
  7021. return this.finishNode(node, "EnumDeclaration");
  7022. }
  7023. isLookaheadToken_lt() {
  7024. const next = this.nextTokenStart();
  7025. if (this.input.charCodeAt(next) === 60) {
  7026. const afterNext = this.input.charCodeAt(next + 1);
  7027. return afterNext !== 60 && afterNext !== 61;
  7028. }
  7029. return false;
  7030. }
  7031. maybeUnwrapTypeCastExpression(node) {
  7032. return node.type === "TypeCastExpression" ? node.expression : node;
  7033. }
  7034. };
  7035. const entities = {
  7036. __proto__: null,
  7037. quot: "\u0022",
  7038. amp: "&",
  7039. apos: "\u0027",
  7040. lt: "<",
  7041. gt: ">",
  7042. nbsp: "\u00A0",
  7043. iexcl: "\u00A1",
  7044. cent: "\u00A2",
  7045. pound: "\u00A3",
  7046. curren: "\u00A4",
  7047. yen: "\u00A5",
  7048. brvbar: "\u00A6",
  7049. sect: "\u00A7",
  7050. uml: "\u00A8",
  7051. copy: "\u00A9",
  7052. ordf: "\u00AA",
  7053. laquo: "\u00AB",
  7054. not: "\u00AC",
  7055. shy: "\u00AD",
  7056. reg: "\u00AE",
  7057. macr: "\u00AF",
  7058. deg: "\u00B0",
  7059. plusmn: "\u00B1",
  7060. sup2: "\u00B2",
  7061. sup3: "\u00B3",
  7062. acute: "\u00B4",
  7063. micro: "\u00B5",
  7064. para: "\u00B6",
  7065. middot: "\u00B7",
  7066. cedil: "\u00B8",
  7067. sup1: "\u00B9",
  7068. ordm: "\u00BA",
  7069. raquo: "\u00BB",
  7070. frac14: "\u00BC",
  7071. frac12: "\u00BD",
  7072. frac34: "\u00BE",
  7073. iquest: "\u00BF",
  7074. Agrave: "\u00C0",
  7075. Aacute: "\u00C1",
  7076. Acirc: "\u00C2",
  7077. Atilde: "\u00C3",
  7078. Auml: "\u00C4",
  7079. Aring: "\u00C5",
  7080. AElig: "\u00C6",
  7081. Ccedil: "\u00C7",
  7082. Egrave: "\u00C8",
  7083. Eacute: "\u00C9",
  7084. Ecirc: "\u00CA",
  7085. Euml: "\u00CB",
  7086. Igrave: "\u00CC",
  7087. Iacute: "\u00CD",
  7088. Icirc: "\u00CE",
  7089. Iuml: "\u00CF",
  7090. ETH: "\u00D0",
  7091. Ntilde: "\u00D1",
  7092. Ograve: "\u00D2",
  7093. Oacute: "\u00D3",
  7094. Ocirc: "\u00D4",
  7095. Otilde: "\u00D5",
  7096. Ouml: "\u00D6",
  7097. times: "\u00D7",
  7098. Oslash: "\u00D8",
  7099. Ugrave: "\u00D9",
  7100. Uacute: "\u00DA",
  7101. Ucirc: "\u00DB",
  7102. Uuml: "\u00DC",
  7103. Yacute: "\u00DD",
  7104. THORN: "\u00DE",
  7105. szlig: "\u00DF",
  7106. agrave: "\u00E0",
  7107. aacute: "\u00E1",
  7108. acirc: "\u00E2",
  7109. atilde: "\u00E3",
  7110. auml: "\u00E4",
  7111. aring: "\u00E5",
  7112. aelig: "\u00E6",
  7113. ccedil: "\u00E7",
  7114. egrave: "\u00E8",
  7115. eacute: "\u00E9",
  7116. ecirc: "\u00EA",
  7117. euml: "\u00EB",
  7118. igrave: "\u00EC",
  7119. iacute: "\u00ED",
  7120. icirc: "\u00EE",
  7121. iuml: "\u00EF",
  7122. eth: "\u00F0",
  7123. ntilde: "\u00F1",
  7124. ograve: "\u00F2",
  7125. oacute: "\u00F3",
  7126. ocirc: "\u00F4",
  7127. otilde: "\u00F5",
  7128. ouml: "\u00F6",
  7129. divide: "\u00F7",
  7130. oslash: "\u00F8",
  7131. ugrave: "\u00F9",
  7132. uacute: "\u00FA",
  7133. ucirc: "\u00FB",
  7134. uuml: "\u00FC",
  7135. yacute: "\u00FD",
  7136. thorn: "\u00FE",
  7137. yuml: "\u00FF",
  7138. OElig: "\u0152",
  7139. oelig: "\u0153",
  7140. Scaron: "\u0160",
  7141. scaron: "\u0161",
  7142. Yuml: "\u0178",
  7143. fnof: "\u0192",
  7144. circ: "\u02C6",
  7145. tilde: "\u02DC",
  7146. Alpha: "\u0391",
  7147. Beta: "\u0392",
  7148. Gamma: "\u0393",
  7149. Delta: "\u0394",
  7150. Epsilon: "\u0395",
  7151. Zeta: "\u0396",
  7152. Eta: "\u0397",
  7153. Theta: "\u0398",
  7154. Iota: "\u0399",
  7155. Kappa: "\u039A",
  7156. Lambda: "\u039B",
  7157. Mu: "\u039C",
  7158. Nu: "\u039D",
  7159. Xi: "\u039E",
  7160. Omicron: "\u039F",
  7161. Pi: "\u03A0",
  7162. Rho: "\u03A1",
  7163. Sigma: "\u03A3",
  7164. Tau: "\u03A4",
  7165. Upsilon: "\u03A5",
  7166. Phi: "\u03A6",
  7167. Chi: "\u03A7",
  7168. Psi: "\u03A8",
  7169. Omega: "\u03A9",
  7170. alpha: "\u03B1",
  7171. beta: "\u03B2",
  7172. gamma: "\u03B3",
  7173. delta: "\u03B4",
  7174. epsilon: "\u03B5",
  7175. zeta: "\u03B6",
  7176. eta: "\u03B7",
  7177. theta: "\u03B8",
  7178. iota: "\u03B9",
  7179. kappa: "\u03BA",
  7180. lambda: "\u03BB",
  7181. mu: "\u03BC",
  7182. nu: "\u03BD",
  7183. xi: "\u03BE",
  7184. omicron: "\u03BF",
  7185. pi: "\u03C0",
  7186. rho: "\u03C1",
  7187. sigmaf: "\u03C2",
  7188. sigma: "\u03C3",
  7189. tau: "\u03C4",
  7190. upsilon: "\u03C5",
  7191. phi: "\u03C6",
  7192. chi: "\u03C7",
  7193. psi: "\u03C8",
  7194. omega: "\u03C9",
  7195. thetasym: "\u03D1",
  7196. upsih: "\u03D2",
  7197. piv: "\u03D6",
  7198. ensp: "\u2002",
  7199. emsp: "\u2003",
  7200. thinsp: "\u2009",
  7201. zwnj: "\u200C",
  7202. zwj: "\u200D",
  7203. lrm: "\u200E",
  7204. rlm: "\u200F",
  7205. ndash: "\u2013",
  7206. mdash: "\u2014",
  7207. lsquo: "\u2018",
  7208. rsquo: "\u2019",
  7209. sbquo: "\u201A",
  7210. ldquo: "\u201C",
  7211. rdquo: "\u201D",
  7212. bdquo: "\u201E",
  7213. dagger: "\u2020",
  7214. Dagger: "\u2021",
  7215. bull: "\u2022",
  7216. hellip: "\u2026",
  7217. permil: "\u2030",
  7218. prime: "\u2032",
  7219. Prime: "\u2033",
  7220. lsaquo: "\u2039",
  7221. rsaquo: "\u203A",
  7222. oline: "\u203E",
  7223. frasl: "\u2044",
  7224. euro: "\u20AC",
  7225. image: "\u2111",
  7226. weierp: "\u2118",
  7227. real: "\u211C",
  7228. trade: "\u2122",
  7229. alefsym: "\u2135",
  7230. larr: "\u2190",
  7231. uarr: "\u2191",
  7232. rarr: "\u2192",
  7233. darr: "\u2193",
  7234. harr: "\u2194",
  7235. crarr: "\u21B5",
  7236. lArr: "\u21D0",
  7237. uArr: "\u21D1",
  7238. rArr: "\u21D2",
  7239. dArr: "\u21D3",
  7240. hArr: "\u21D4",
  7241. forall: "\u2200",
  7242. part: "\u2202",
  7243. exist: "\u2203",
  7244. empty: "\u2205",
  7245. nabla: "\u2207",
  7246. isin: "\u2208",
  7247. notin: "\u2209",
  7248. ni: "\u220B",
  7249. prod: "\u220F",
  7250. sum: "\u2211",
  7251. minus: "\u2212",
  7252. lowast: "\u2217",
  7253. radic: "\u221A",
  7254. prop: "\u221D",
  7255. infin: "\u221E",
  7256. ang: "\u2220",
  7257. and: "\u2227",
  7258. or: "\u2228",
  7259. cap: "\u2229",
  7260. cup: "\u222A",
  7261. int: "\u222B",
  7262. there4: "\u2234",
  7263. sim: "\u223C",
  7264. cong: "\u2245",
  7265. asymp: "\u2248",
  7266. ne: "\u2260",
  7267. equiv: "\u2261",
  7268. le: "\u2264",
  7269. ge: "\u2265",
  7270. sub: "\u2282",
  7271. sup: "\u2283",
  7272. nsub: "\u2284",
  7273. sube: "\u2286",
  7274. supe: "\u2287",
  7275. oplus: "\u2295",
  7276. otimes: "\u2297",
  7277. perp: "\u22A5",
  7278. sdot: "\u22C5",
  7279. lceil: "\u2308",
  7280. rceil: "\u2309",
  7281. lfloor: "\u230A",
  7282. rfloor: "\u230B",
  7283. lang: "\u2329",
  7284. rang: "\u232A",
  7285. loz: "\u25CA",
  7286. spades: "\u2660",
  7287. clubs: "\u2663",
  7288. hearts: "\u2665",
  7289. diams: "\u2666"
  7290. };
  7291. const JsxErrors = ParseErrorEnum`jsx`({
  7292. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  7293. MissingClosingTagElement: ({
  7294. openingTagName
  7295. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  7296. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  7297. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  7298. UnexpectedToken: ({
  7299. unexpected,
  7300. HTMLEntity
  7301. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  7302. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  7303. UnterminatedJsxContent: "Unterminated JSX contents.",
  7304. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  7305. });
  7306. function isFragment(object) {
  7307. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  7308. }
  7309. function getQualifiedJSXName(object) {
  7310. if (object.type === "JSXIdentifier") {
  7311. return object.name;
  7312. }
  7313. if (object.type === "JSXNamespacedName") {
  7314. return object.namespace.name + ":" + object.name.name;
  7315. }
  7316. if (object.type === "JSXMemberExpression") {
  7317. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  7318. }
  7319. throw new Error("Node had unexpected type: " + object.type);
  7320. }
  7321. var jsx = superClass => class JSXParserMixin extends superClass {
  7322. jsxReadToken() {
  7323. let out = "";
  7324. let chunkStart = this.state.pos;
  7325. for (;;) {
  7326. if (this.state.pos >= this.length) {
  7327. throw this.raise(JsxErrors.UnterminatedJsxContent, {
  7328. at: this.state.startLoc
  7329. });
  7330. }
  7331. const ch = this.input.charCodeAt(this.state.pos);
  7332. switch (ch) {
  7333. case 60:
  7334. case 123:
  7335. if (this.state.pos === this.state.start) {
  7336. if (ch === 60 && this.state.canStartJSXElement) {
  7337. ++this.state.pos;
  7338. this.finishToken(140);
  7339. } else {
  7340. super.getTokenFromCode(ch);
  7341. }
  7342. return;
  7343. }
  7344. out += this.input.slice(chunkStart, this.state.pos);
  7345. this.finishToken(139, out);
  7346. return;
  7347. case 38:
  7348. out += this.input.slice(chunkStart, this.state.pos);
  7349. out += this.jsxReadEntity();
  7350. chunkStart = this.state.pos;
  7351. break;
  7352. case 62:
  7353. case 125:
  7354. default:
  7355. if (isNewLine(ch)) {
  7356. out += this.input.slice(chunkStart, this.state.pos);
  7357. out += this.jsxReadNewLine(true);
  7358. chunkStart = this.state.pos;
  7359. } else {
  7360. ++this.state.pos;
  7361. }
  7362. }
  7363. }
  7364. }
  7365. jsxReadNewLine(normalizeCRLF) {
  7366. const ch = this.input.charCodeAt(this.state.pos);
  7367. let out;
  7368. ++this.state.pos;
  7369. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  7370. ++this.state.pos;
  7371. out = normalizeCRLF ? "\n" : "\r\n";
  7372. } else {
  7373. out = String.fromCharCode(ch);
  7374. }
  7375. ++this.state.curLine;
  7376. this.state.lineStart = this.state.pos;
  7377. return out;
  7378. }
  7379. jsxReadString(quote) {
  7380. let out = "";
  7381. let chunkStart = ++this.state.pos;
  7382. for (;;) {
  7383. if (this.state.pos >= this.length) {
  7384. throw this.raise(Errors.UnterminatedString, {
  7385. at: this.state.startLoc
  7386. });
  7387. }
  7388. const ch = this.input.charCodeAt(this.state.pos);
  7389. if (ch === quote) break;
  7390. if (ch === 38) {
  7391. out += this.input.slice(chunkStart, this.state.pos);
  7392. out += this.jsxReadEntity();
  7393. chunkStart = this.state.pos;
  7394. } else if (isNewLine(ch)) {
  7395. out += this.input.slice(chunkStart, this.state.pos);
  7396. out += this.jsxReadNewLine(false);
  7397. chunkStart = this.state.pos;
  7398. } else {
  7399. ++this.state.pos;
  7400. }
  7401. }
  7402. out += this.input.slice(chunkStart, this.state.pos++);
  7403. this.finishToken(131, out);
  7404. }
  7405. jsxReadEntity() {
  7406. const startPos = ++this.state.pos;
  7407. if (this.codePointAtPos(this.state.pos) === 35) {
  7408. ++this.state.pos;
  7409. let radix = 10;
  7410. if (this.codePointAtPos(this.state.pos) === 120) {
  7411. radix = 16;
  7412. ++this.state.pos;
  7413. }
  7414. const codePoint = this.readInt(radix, undefined, false, "bail");
  7415. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  7416. ++this.state.pos;
  7417. return String.fromCodePoint(codePoint);
  7418. }
  7419. } else {
  7420. let count = 0;
  7421. let semi = false;
  7422. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) {
  7423. ++this.state.pos;
  7424. }
  7425. if (semi) {
  7426. const desc = this.input.slice(startPos, this.state.pos);
  7427. const entity = entities[desc];
  7428. ++this.state.pos;
  7429. if (entity) {
  7430. return entity;
  7431. }
  7432. }
  7433. }
  7434. this.state.pos = startPos;
  7435. return "&";
  7436. }
  7437. jsxReadWord() {
  7438. let ch;
  7439. const start = this.state.pos;
  7440. do {
  7441. ch = this.input.charCodeAt(++this.state.pos);
  7442. } while (isIdentifierChar(ch) || ch === 45);
  7443. this.finishToken(138, this.input.slice(start, this.state.pos));
  7444. }
  7445. jsxParseIdentifier() {
  7446. const node = this.startNode();
  7447. if (this.match(138)) {
  7448. node.name = this.state.value;
  7449. } else if (tokenIsKeyword(this.state.type)) {
  7450. node.name = tokenLabelName(this.state.type);
  7451. } else {
  7452. this.unexpected();
  7453. }
  7454. this.next();
  7455. return this.finishNode(node, "JSXIdentifier");
  7456. }
  7457. jsxParseNamespacedName() {
  7458. const startLoc = this.state.startLoc;
  7459. const name = this.jsxParseIdentifier();
  7460. if (!this.eat(14)) return name;
  7461. const node = this.startNodeAt(startLoc);
  7462. node.namespace = name;
  7463. node.name = this.jsxParseIdentifier();
  7464. return this.finishNode(node, "JSXNamespacedName");
  7465. }
  7466. jsxParseElementName() {
  7467. const startLoc = this.state.startLoc;
  7468. let node = this.jsxParseNamespacedName();
  7469. if (node.type === "JSXNamespacedName") {
  7470. return node;
  7471. }
  7472. while (this.eat(16)) {
  7473. const newNode = this.startNodeAt(startLoc);
  7474. newNode.object = node;
  7475. newNode.property = this.jsxParseIdentifier();
  7476. node = this.finishNode(newNode, "JSXMemberExpression");
  7477. }
  7478. return node;
  7479. }
  7480. jsxParseAttributeValue() {
  7481. let node;
  7482. switch (this.state.type) {
  7483. case 5:
  7484. node = this.startNode();
  7485. this.setContext(types$1.brace);
  7486. this.next();
  7487. node = this.jsxParseExpressionContainer(node, types$1.j_oTag);
  7488. if (node.expression.type === "JSXEmptyExpression") {
  7489. this.raise(JsxErrors.AttributeIsEmpty, {
  7490. at: node
  7491. });
  7492. }
  7493. return node;
  7494. case 140:
  7495. case 131:
  7496. return this.parseExprAtom();
  7497. default:
  7498. throw this.raise(JsxErrors.UnsupportedJsxValue, {
  7499. at: this.state.startLoc
  7500. });
  7501. }
  7502. }
  7503. jsxParseEmptyExpression() {
  7504. const node = this.startNodeAt(this.state.lastTokEndLoc);
  7505. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  7506. }
  7507. jsxParseSpreadChild(node) {
  7508. this.next();
  7509. node.expression = this.parseExpression();
  7510. this.setContext(types$1.j_expr);
  7511. this.state.canStartJSXElement = true;
  7512. this.expect(8);
  7513. return this.finishNode(node, "JSXSpreadChild");
  7514. }
  7515. jsxParseExpressionContainer(node, previousContext) {
  7516. if (this.match(8)) {
  7517. node.expression = this.jsxParseEmptyExpression();
  7518. } else {
  7519. const expression = this.parseExpression();
  7520. node.expression = expression;
  7521. }
  7522. this.setContext(previousContext);
  7523. this.state.canStartJSXElement = true;
  7524. this.expect(8);
  7525. return this.finishNode(node, "JSXExpressionContainer");
  7526. }
  7527. jsxParseAttribute() {
  7528. const node = this.startNode();
  7529. if (this.match(5)) {
  7530. this.setContext(types$1.brace);
  7531. this.next();
  7532. this.expect(21);
  7533. node.argument = this.parseMaybeAssignAllowIn();
  7534. this.setContext(types$1.j_oTag);
  7535. this.state.canStartJSXElement = true;
  7536. this.expect(8);
  7537. return this.finishNode(node, "JSXSpreadAttribute");
  7538. }
  7539. node.name = this.jsxParseNamespacedName();
  7540. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  7541. return this.finishNode(node, "JSXAttribute");
  7542. }
  7543. jsxParseOpeningElementAt(startLoc) {
  7544. const node = this.startNodeAt(startLoc);
  7545. if (this.eat(141)) {
  7546. return this.finishNode(node, "JSXOpeningFragment");
  7547. }
  7548. node.name = this.jsxParseElementName();
  7549. return this.jsxParseOpeningElementAfterName(node);
  7550. }
  7551. jsxParseOpeningElementAfterName(node) {
  7552. const attributes = [];
  7553. while (!this.match(56) && !this.match(141)) {
  7554. attributes.push(this.jsxParseAttribute());
  7555. }
  7556. node.attributes = attributes;
  7557. node.selfClosing = this.eat(56);
  7558. this.expect(141);
  7559. return this.finishNode(node, "JSXOpeningElement");
  7560. }
  7561. jsxParseClosingElementAt(startLoc) {
  7562. const node = this.startNodeAt(startLoc);
  7563. if (this.eat(141)) {
  7564. return this.finishNode(node, "JSXClosingFragment");
  7565. }
  7566. node.name = this.jsxParseElementName();
  7567. this.expect(141);
  7568. return this.finishNode(node, "JSXClosingElement");
  7569. }
  7570. jsxParseElementAt(startLoc) {
  7571. const node = this.startNodeAt(startLoc);
  7572. const children = [];
  7573. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  7574. let closingElement = null;
  7575. if (!openingElement.selfClosing) {
  7576. contents: for (;;) {
  7577. switch (this.state.type) {
  7578. case 140:
  7579. startLoc = this.state.startLoc;
  7580. this.next();
  7581. if (this.eat(56)) {
  7582. closingElement = this.jsxParseClosingElementAt(startLoc);
  7583. break contents;
  7584. }
  7585. children.push(this.jsxParseElementAt(startLoc));
  7586. break;
  7587. case 139:
  7588. children.push(this.parseExprAtom());
  7589. break;
  7590. case 5:
  7591. {
  7592. const node = this.startNode();
  7593. this.setContext(types$1.brace);
  7594. this.next();
  7595. if (this.match(21)) {
  7596. children.push(this.jsxParseSpreadChild(node));
  7597. } else {
  7598. children.push(this.jsxParseExpressionContainer(node, types$1.j_expr));
  7599. }
  7600. break;
  7601. }
  7602. default:
  7603. this.unexpected();
  7604. }
  7605. }
  7606. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  7607. this.raise(JsxErrors.MissingClosingTagFragment, {
  7608. at: closingElement
  7609. });
  7610. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  7611. this.raise(JsxErrors.MissingClosingTagElement, {
  7612. at: closingElement,
  7613. openingTagName: getQualifiedJSXName(openingElement.name)
  7614. });
  7615. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  7616. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  7617. this.raise(JsxErrors.MissingClosingTagElement, {
  7618. at: closingElement,
  7619. openingTagName: getQualifiedJSXName(openingElement.name)
  7620. });
  7621. }
  7622. }
  7623. }
  7624. if (isFragment(openingElement)) {
  7625. node.openingFragment = openingElement;
  7626. node.closingFragment = closingElement;
  7627. } else {
  7628. node.openingElement = openingElement;
  7629. node.closingElement = closingElement;
  7630. }
  7631. node.children = children;
  7632. if (this.match(47)) {
  7633. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, {
  7634. at: this.state.startLoc
  7635. });
  7636. }
  7637. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  7638. }
  7639. jsxParseElement() {
  7640. const startLoc = this.state.startLoc;
  7641. this.next();
  7642. return this.jsxParseElementAt(startLoc);
  7643. }
  7644. setContext(newContext) {
  7645. const {
  7646. context
  7647. } = this.state;
  7648. context[context.length - 1] = newContext;
  7649. }
  7650. parseExprAtom(refExpressionErrors) {
  7651. if (this.match(139)) {
  7652. return this.parseLiteral(this.state.value, "JSXText");
  7653. } else if (this.match(140)) {
  7654. return this.jsxParseElement();
  7655. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  7656. this.replaceToken(140);
  7657. return this.jsxParseElement();
  7658. } else {
  7659. return super.parseExprAtom(refExpressionErrors);
  7660. }
  7661. }
  7662. skipSpace() {
  7663. const curContext = this.curContext();
  7664. if (!curContext.preserveSpace) super.skipSpace();
  7665. }
  7666. getTokenFromCode(code) {
  7667. const context = this.curContext();
  7668. if (context === types$1.j_expr) {
  7669. this.jsxReadToken();
  7670. return;
  7671. }
  7672. if (context === types$1.j_oTag || context === types$1.j_cTag) {
  7673. if (isIdentifierStart(code)) {
  7674. this.jsxReadWord();
  7675. return;
  7676. }
  7677. if (code === 62) {
  7678. ++this.state.pos;
  7679. this.finishToken(141);
  7680. return;
  7681. }
  7682. if ((code === 34 || code === 39) && context === types$1.j_oTag) {
  7683. this.jsxReadString(code);
  7684. return;
  7685. }
  7686. }
  7687. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  7688. ++this.state.pos;
  7689. this.finishToken(140);
  7690. return;
  7691. }
  7692. super.getTokenFromCode(code);
  7693. }
  7694. updateContext(prevType) {
  7695. const {
  7696. context,
  7697. type
  7698. } = this.state;
  7699. if (type === 56 && prevType === 140) {
  7700. context.splice(-2, 2, types$1.j_cTag);
  7701. this.state.canStartJSXElement = false;
  7702. } else if (type === 140) {
  7703. context.push(types$1.j_oTag);
  7704. } else if (type === 141) {
  7705. const out = context[context.length - 1];
  7706. if (out === types$1.j_oTag && prevType === 56 || out === types$1.j_cTag) {
  7707. context.pop();
  7708. this.state.canStartJSXElement = context[context.length - 1] === types$1.j_expr;
  7709. } else {
  7710. this.setContext(types$1.j_expr);
  7711. this.state.canStartJSXElement = true;
  7712. }
  7713. } else {
  7714. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  7715. }
  7716. }
  7717. };
  7718. class TypeScriptScope extends Scope {
  7719. constructor(...args) {
  7720. super(...args);
  7721. this.types = new Set();
  7722. this.enums = new Set();
  7723. this.constEnums = new Set();
  7724. this.classes = new Set();
  7725. this.exportOnlyBindings = new Set();
  7726. }
  7727. }
  7728. class TypeScriptScopeHandler extends ScopeHandler {
  7729. constructor(...args) {
  7730. super(...args);
  7731. this.importsStack = [];
  7732. }
  7733. createScope(flags) {
  7734. this.importsStack.push(new Set());
  7735. return new TypeScriptScope(flags);
  7736. }
  7737. enter(flags) {
  7738. if (flags == SCOPE_TS_MODULE) {
  7739. this.importsStack.push(new Set());
  7740. }
  7741. super.enter(flags);
  7742. }
  7743. exit() {
  7744. const flags = super.exit();
  7745. if (flags == SCOPE_TS_MODULE) {
  7746. this.importsStack.pop();
  7747. }
  7748. return flags;
  7749. }
  7750. hasImport(name, allowShadow) {
  7751. const len = this.importsStack.length;
  7752. if (this.importsStack[len - 1].has(name)) {
  7753. return true;
  7754. }
  7755. if (!allowShadow && len > 1) {
  7756. for (let i = 0; i < len - 1; i++) {
  7757. if (this.importsStack[i].has(name)) return true;
  7758. }
  7759. }
  7760. return false;
  7761. }
  7762. declareName(name, bindingType, loc) {
  7763. if (bindingType & BIND_FLAGS_TS_IMPORT) {
  7764. if (this.hasImport(name, true)) {
  7765. this.parser.raise(Errors.VarRedeclaration, {
  7766. at: loc,
  7767. identifierName: name
  7768. });
  7769. }
  7770. this.importsStack[this.importsStack.length - 1].add(name);
  7771. return;
  7772. }
  7773. const scope = this.currentScope();
  7774. if (bindingType & BIND_FLAGS_TS_EXPORT_ONLY) {
  7775. this.maybeExportDefined(scope, name);
  7776. scope.exportOnlyBindings.add(name);
  7777. return;
  7778. }
  7779. super.declareName(name, bindingType, loc);
  7780. if (bindingType & BIND_KIND_TYPE) {
  7781. if (!(bindingType & BIND_KIND_VALUE)) {
  7782. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7783. this.maybeExportDefined(scope, name);
  7784. }
  7785. scope.types.add(name);
  7786. }
  7787. if (bindingType & BIND_FLAGS_TS_ENUM) scope.enums.add(name);
  7788. if (bindingType & BIND_FLAGS_TS_CONST_ENUM) scope.constEnums.add(name);
  7789. if (bindingType & BIND_FLAGS_CLASS) scope.classes.add(name);
  7790. }
  7791. isRedeclaredInScope(scope, name, bindingType) {
  7792. if (scope.enums.has(name)) {
  7793. if (bindingType & BIND_FLAGS_TS_ENUM) {
  7794. const isConst = !!(bindingType & BIND_FLAGS_TS_CONST_ENUM);
  7795. const wasConst = scope.constEnums.has(name);
  7796. return isConst !== wasConst;
  7797. }
  7798. return true;
  7799. }
  7800. if (bindingType & BIND_FLAGS_CLASS && scope.classes.has(name)) {
  7801. if (scope.lexical.has(name)) {
  7802. return !!(bindingType & BIND_KIND_VALUE);
  7803. } else {
  7804. return false;
  7805. }
  7806. }
  7807. if (bindingType & BIND_KIND_TYPE && scope.types.has(name)) {
  7808. return true;
  7809. }
  7810. return super.isRedeclaredInScope(scope, name, bindingType);
  7811. }
  7812. checkLocalExport(id) {
  7813. const {
  7814. name
  7815. } = id;
  7816. if (this.hasImport(name)) return;
  7817. const len = this.scopeStack.length;
  7818. for (let i = len - 1; i >= 0; i--) {
  7819. const scope = this.scopeStack[i];
  7820. if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return;
  7821. }
  7822. super.checkLocalExport(id);
  7823. }
  7824. }
  7825. const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7826. const unwrapParenthesizedExpression = node => {
  7827. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7828. };
  7829. class LValParser extends NodeUtils {
  7830. toAssignable(node, isLHS = false) {
  7831. var _node$extra, _node$extra3;
  7832. let parenthesized = undefined;
  7833. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7834. parenthesized = unwrapParenthesizedExpression(node);
  7835. if (isLHS) {
  7836. if (parenthesized.type === "Identifier") {
  7837. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, {
  7838. at: node
  7839. });
  7840. } else if (parenthesized.type !== "MemberExpression") {
  7841. this.raise(Errors.InvalidParenthesizedAssignment, {
  7842. at: node
  7843. });
  7844. }
  7845. } else {
  7846. this.raise(Errors.InvalidParenthesizedAssignment, {
  7847. at: node
  7848. });
  7849. }
  7850. }
  7851. switch (node.type) {
  7852. case "Identifier":
  7853. case "ObjectPattern":
  7854. case "ArrayPattern":
  7855. case "AssignmentPattern":
  7856. case "RestElement":
  7857. break;
  7858. case "ObjectExpression":
  7859. node.type = "ObjectPattern";
  7860. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7861. var _node$extra2;
  7862. const prop = node.properties[i];
  7863. const isLast = i === last;
  7864. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7865. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7866. this.raise(Errors.RestTrailingComma, {
  7867. at: node.extra.trailingCommaLoc
  7868. });
  7869. }
  7870. }
  7871. break;
  7872. case "ObjectProperty":
  7873. {
  7874. const {
  7875. key,
  7876. value
  7877. } = node;
  7878. if (this.isPrivateName(key)) {
  7879. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7880. }
  7881. this.toAssignable(value, isLHS);
  7882. break;
  7883. }
  7884. case "SpreadElement":
  7885. {
  7886. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7887. }
  7888. case "ArrayExpression":
  7889. node.type = "ArrayPattern";
  7890. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7891. break;
  7892. case "AssignmentExpression":
  7893. if (node.operator !== "=") {
  7894. this.raise(Errors.MissingEqInAssignment, {
  7895. at: node.left.loc.end
  7896. });
  7897. }
  7898. node.type = "AssignmentPattern";
  7899. delete node.operator;
  7900. this.toAssignable(node.left, isLHS);
  7901. break;
  7902. case "ParenthesizedExpression":
  7903. this.toAssignable(parenthesized, isLHS);
  7904. break;
  7905. }
  7906. }
  7907. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7908. if (prop.type === "ObjectMethod") {
  7909. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
  7910. at: prop.key
  7911. });
  7912. } else if (prop.type === "SpreadElement") {
  7913. prop.type = "RestElement";
  7914. const arg = prop.argument;
  7915. this.checkToRestConversion(arg, false);
  7916. this.toAssignable(arg, isLHS);
  7917. if (!isLast) {
  7918. this.raise(Errors.RestTrailingComma, {
  7919. at: prop
  7920. });
  7921. }
  7922. } else {
  7923. this.toAssignable(prop, isLHS);
  7924. }
  7925. }
  7926. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7927. const end = exprList.length - 1;
  7928. for (let i = 0; i <= end; i++) {
  7929. const elt = exprList[i];
  7930. if (!elt) continue;
  7931. if (elt.type === "SpreadElement") {
  7932. elt.type = "RestElement";
  7933. const arg = elt.argument;
  7934. this.checkToRestConversion(arg, true);
  7935. this.toAssignable(arg, isLHS);
  7936. } else {
  7937. this.toAssignable(elt, isLHS);
  7938. }
  7939. if (elt.type === "RestElement") {
  7940. if (i < end) {
  7941. this.raise(Errors.RestTrailingComma, {
  7942. at: elt
  7943. });
  7944. } else if (trailingCommaLoc) {
  7945. this.raise(Errors.RestTrailingComma, {
  7946. at: trailingCommaLoc
  7947. });
  7948. }
  7949. }
  7950. }
  7951. }
  7952. isAssignable(node, isBinding) {
  7953. switch (node.type) {
  7954. case "Identifier":
  7955. case "ObjectPattern":
  7956. case "ArrayPattern":
  7957. case "AssignmentPattern":
  7958. case "RestElement":
  7959. return true;
  7960. case "ObjectExpression":
  7961. {
  7962. const last = node.properties.length - 1;
  7963. return node.properties.every((prop, i) => {
  7964. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7965. });
  7966. }
  7967. case "ObjectProperty":
  7968. return this.isAssignable(node.value);
  7969. case "SpreadElement":
  7970. return this.isAssignable(node.argument);
  7971. case "ArrayExpression":
  7972. return node.elements.every(element => element === null || this.isAssignable(element));
  7973. case "AssignmentExpression":
  7974. return node.operator === "=";
  7975. case "ParenthesizedExpression":
  7976. return this.isAssignable(node.expression);
  7977. case "MemberExpression":
  7978. case "OptionalMemberExpression":
  7979. return !isBinding;
  7980. default:
  7981. return false;
  7982. }
  7983. }
  7984. toReferencedList(exprList, isParenthesizedExpr) {
  7985. return exprList;
  7986. }
  7987. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7988. this.toReferencedList(exprList, isParenthesizedExpr);
  7989. for (const expr of exprList) {
  7990. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7991. this.toReferencedListDeep(expr.elements);
  7992. }
  7993. }
  7994. }
  7995. parseSpread(refExpressionErrors) {
  7996. const node = this.startNode();
  7997. this.next();
  7998. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7999. return this.finishNode(node, "SpreadElement");
  8000. }
  8001. parseRestBinding() {
  8002. const node = this.startNode();
  8003. this.next();
  8004. node.argument = this.parseBindingAtom();
  8005. return this.finishNode(node, "RestElement");
  8006. }
  8007. parseBindingAtom() {
  8008. switch (this.state.type) {
  8009. case 0:
  8010. {
  8011. const node = this.startNode();
  8012. this.next();
  8013. node.elements = this.parseBindingList(3, 93, 1);
  8014. return this.finishNode(node, "ArrayPattern");
  8015. }
  8016. case 5:
  8017. return this.parseObjectLike(8, true);
  8018. }
  8019. return this.parseIdentifier();
  8020. }
  8021. parseBindingList(close, closeCharCode, flags) {
  8022. const allowEmpty = flags & 1;
  8023. const elts = [];
  8024. let first = true;
  8025. while (!this.eat(close)) {
  8026. if (first) {
  8027. first = false;
  8028. } else {
  8029. this.expect(12);
  8030. }
  8031. if (allowEmpty && this.match(12)) {
  8032. elts.push(null);
  8033. } else if (this.eat(close)) {
  8034. break;
  8035. } else if (this.match(21)) {
  8036. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags));
  8037. if (!this.checkCommaAfterRest(closeCharCode)) {
  8038. this.expect(close);
  8039. break;
  8040. }
  8041. } else {
  8042. const decorators = [];
  8043. if (this.match(26) && this.hasPlugin("decorators")) {
  8044. this.raise(Errors.UnsupportedParameterDecorator, {
  8045. at: this.state.startLoc
  8046. });
  8047. }
  8048. while (this.match(26)) {
  8049. decorators.push(this.parseDecorator());
  8050. }
  8051. elts.push(this.parseAssignableListItem(flags, decorators));
  8052. }
  8053. }
  8054. return elts;
  8055. }
  8056. parseBindingRestProperty(prop) {
  8057. this.next();
  8058. prop.argument = this.parseIdentifier();
  8059. this.checkCommaAfterRest(125);
  8060. return this.finishNode(prop, "RestElement");
  8061. }
  8062. parseBindingProperty() {
  8063. const prop = this.startNode();
  8064. const {
  8065. type,
  8066. startLoc
  8067. } = this.state;
  8068. if (type === 21) {
  8069. return this.parseBindingRestProperty(prop);
  8070. } else if (type === 136) {
  8071. this.expectPlugin("destructuringPrivate", startLoc);
  8072. this.classScope.usePrivateName(this.state.value, startLoc);
  8073. prop.key = this.parsePrivateName();
  8074. } else {
  8075. this.parsePropertyName(prop);
  8076. }
  8077. prop.method = false;
  8078. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  8079. }
  8080. parseAssignableListItem(flags, decorators) {
  8081. const left = this.parseMaybeDefault();
  8082. this.parseAssignableListItemTypes(left, flags);
  8083. const elt = this.parseMaybeDefault(left.loc.start, left);
  8084. if (decorators.length) {
  8085. left.decorators = decorators;
  8086. }
  8087. return elt;
  8088. }
  8089. parseAssignableListItemTypes(param, flags) {
  8090. return param;
  8091. }
  8092. parseMaybeDefault(startLoc, left) {
  8093. var _startLoc, _left;
  8094. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  8095. left = (_left = left) != null ? _left : this.parseBindingAtom();
  8096. if (!this.eat(29)) return left;
  8097. const node = this.startNodeAt(startLoc);
  8098. node.left = left;
  8099. node.right = this.parseMaybeAssignAllowIn();
  8100. return this.finishNode(node, "AssignmentPattern");
  8101. }
  8102. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  8103. return getOwn$1({
  8104. AssignmentPattern: "left",
  8105. RestElement: "argument",
  8106. ObjectProperty: "value",
  8107. ParenthesizedExpression: "expression",
  8108. ArrayPattern: "elements",
  8109. ObjectPattern: "properties"
  8110. }, type);
  8111. }
  8112. checkLVal(expression, {
  8113. in: ancestor,
  8114. binding = BIND_NONE,
  8115. checkClashes = false,
  8116. strictModeChanged = false,
  8117. hasParenthesizedAncestor = false
  8118. }) {
  8119. var _expression$extra;
  8120. const type = expression.type;
  8121. if (this.isObjectMethod(expression)) return;
  8122. if (type === "MemberExpression") {
  8123. if (binding !== BIND_NONE) {
  8124. this.raise(Errors.InvalidPropertyBindingPattern, {
  8125. at: expression
  8126. });
  8127. }
  8128. return;
  8129. }
  8130. if (type === "Identifier") {
  8131. this.checkIdentifier(expression, binding, strictModeChanged);
  8132. const {
  8133. name
  8134. } = expression;
  8135. if (checkClashes) {
  8136. if (checkClashes.has(name)) {
  8137. this.raise(Errors.ParamDupe, {
  8138. at: expression
  8139. });
  8140. } else {
  8141. checkClashes.add(name);
  8142. }
  8143. }
  8144. return;
  8145. }
  8146. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  8147. if (validity === true) return;
  8148. if (validity === false) {
  8149. const ParseErrorClass = binding === BIND_NONE ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  8150. this.raise(ParseErrorClass, {
  8151. at: expression,
  8152. ancestor
  8153. });
  8154. return;
  8155. }
  8156. const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
  8157. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" || type === "ParenthesizedExpression" ? {
  8158. type
  8159. } : ancestor;
  8160. for (const child of [].concat(expression[key])) {
  8161. if (child) {
  8162. this.checkLVal(child, {
  8163. in: nextAncestor,
  8164. binding,
  8165. checkClashes,
  8166. strictModeChanged,
  8167. hasParenthesizedAncestor: isParenthesizedExpression
  8168. });
  8169. }
  8170. }
  8171. }
  8172. checkIdentifier(at, bindingType, strictModeChanged = false) {
  8173. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  8174. if (bindingType === BIND_NONE) {
  8175. this.raise(Errors.StrictEvalArguments, {
  8176. at,
  8177. referenceName: at.name
  8178. });
  8179. } else {
  8180. this.raise(Errors.StrictEvalArgumentsBinding, {
  8181. at,
  8182. bindingName: at.name
  8183. });
  8184. }
  8185. }
  8186. if (bindingType & BIND_FLAGS_NO_LET_IN_LEXICAL && at.name === "let") {
  8187. this.raise(Errors.LetInLexicalBinding, {
  8188. at
  8189. });
  8190. }
  8191. if (!(bindingType & BIND_NONE)) {
  8192. this.declareNameFromIdentifier(at, bindingType);
  8193. }
  8194. }
  8195. declareNameFromIdentifier(identifier, binding) {
  8196. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  8197. }
  8198. checkToRestConversion(node, allowPattern) {
  8199. switch (node.type) {
  8200. case "ParenthesizedExpression":
  8201. this.checkToRestConversion(node.expression, allowPattern);
  8202. break;
  8203. case "Identifier":
  8204. case "MemberExpression":
  8205. break;
  8206. case "ArrayExpression":
  8207. case "ObjectExpression":
  8208. if (allowPattern) break;
  8209. default:
  8210. this.raise(Errors.InvalidRestAssignmentPattern, {
  8211. at: node
  8212. });
  8213. }
  8214. }
  8215. checkCommaAfterRest(close) {
  8216. if (!this.match(12)) {
  8217. return false;
  8218. }
  8219. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
  8220. at: this.state.startLoc
  8221. });
  8222. return true;
  8223. }
  8224. }
  8225. const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  8226. function nonNull(x) {
  8227. if (x == null) {
  8228. throw new Error(`Unexpected ${x} value.`);
  8229. }
  8230. return x;
  8231. }
  8232. function assert$1(x) {
  8233. if (!x) {
  8234. throw new Error("Assert fail");
  8235. }
  8236. }
  8237. const TSErrors = ParseErrorEnum`typescript`({
  8238. AbstractMethodHasImplementation: ({
  8239. methodName
  8240. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  8241. AbstractPropertyHasInitializer: ({
  8242. propertyName
  8243. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  8244. AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  8245. AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  8246. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  8247. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  8248. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  8249. ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  8250. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  8251. DeclareAccessor: ({
  8252. kind
  8253. }) => `'declare' is not allowed in ${kind}ters.`,
  8254. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  8255. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  8256. DuplicateAccessibilityModifier: ({
  8257. modifier
  8258. }) => `Accessibility modifier already seen.`,
  8259. DuplicateModifier: ({
  8260. modifier
  8261. }) => `Duplicate modifier: '${modifier}'.`,
  8262. EmptyHeritageClauseType: ({
  8263. token
  8264. }) => `'${token}' list cannot be empty.`,
  8265. EmptyTypeArguments: "Type argument list cannot be empty.",
  8266. EmptyTypeParameters: "Type parameter list cannot be empty.",
  8267. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  8268. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  8269. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  8270. IncompatibleModifiers: ({
  8271. modifiers
  8272. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  8273. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  8274. IndexSignatureHasAccessibility: ({
  8275. modifier
  8276. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  8277. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  8278. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  8279. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  8280. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  8281. InvalidModifierOnTypeMember: ({
  8282. modifier
  8283. }) => `'${modifier}' modifier cannot appear on a type member.`,
  8284. InvalidModifierOnTypeParameter: ({
  8285. modifier
  8286. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  8287. InvalidModifierOnTypeParameterPositions: ({
  8288. modifier
  8289. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  8290. InvalidModifiersOrder: ({
  8291. orderedModifiers
  8292. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  8293. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  8294. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  8295. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  8296. MixedLabeledAndUnlabeledElements: "Tuple members must all have names or all not have names.",
  8297. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  8298. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  8299. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  8300. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  8301. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  8302. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  8303. PrivateElementHasAccessibility: ({
  8304. modifier
  8305. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  8306. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  8307. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  8308. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  8309. SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  8310. SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  8311. SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  8312. SingleTypeParameterWithoutTrailingComma: ({
  8313. typeParameterName
  8314. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  8315. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  8316. TupleOptionalAfterType: "A labeled tuple optional element must be declared using a question mark after the name and before the colon (`name?: type`), rather than after the type (`name: type?`).",
  8317. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  8318. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  8319. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  8320. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  8321. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  8322. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  8323. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  8324. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  8325. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  8326. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  8327. UnsupportedSignatureParameterKind: ({
  8328. type
  8329. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  8330. });
  8331. function keywordTypeFromName(value) {
  8332. switch (value) {
  8333. case "any":
  8334. return "TSAnyKeyword";
  8335. case "boolean":
  8336. return "TSBooleanKeyword";
  8337. case "bigint":
  8338. return "TSBigIntKeyword";
  8339. case "never":
  8340. return "TSNeverKeyword";
  8341. case "number":
  8342. return "TSNumberKeyword";
  8343. case "object":
  8344. return "TSObjectKeyword";
  8345. case "string":
  8346. return "TSStringKeyword";
  8347. case "symbol":
  8348. return "TSSymbolKeyword";
  8349. case "undefined":
  8350. return "TSUndefinedKeyword";
  8351. case "unknown":
  8352. return "TSUnknownKeyword";
  8353. default:
  8354. return undefined;
  8355. }
  8356. }
  8357. function tsIsAccessModifier(modifier) {
  8358. return modifier === "private" || modifier === "public" || modifier === "protected";
  8359. }
  8360. function tsIsVarianceAnnotations(modifier) {
  8361. return modifier === "in" || modifier === "out";
  8362. }
  8363. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  8364. constructor(...args) {
  8365. super(...args);
  8366. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  8367. allowedModifiers: ["in", "out"],
  8368. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  8369. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  8370. });
  8371. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  8372. allowedModifiers: ["const"],
  8373. disallowedModifiers: ["in", "out"],
  8374. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  8375. });
  8376. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  8377. allowedModifiers: ["in", "out", "const"],
  8378. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  8379. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  8380. });
  8381. }
  8382. getScopeHandler() {
  8383. return TypeScriptScopeHandler;
  8384. }
  8385. tsIsIdentifier() {
  8386. return tokenIsIdentifier(this.state.type);
  8387. }
  8388. tsTokenCanFollowModifier() {
  8389. return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(136) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  8390. }
  8391. tsNextTokenCanFollowModifier() {
  8392. this.next();
  8393. return this.tsTokenCanFollowModifier();
  8394. }
  8395. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  8396. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  8397. return undefined;
  8398. }
  8399. const modifier = this.state.value;
  8400. if (allowedModifiers.indexOf(modifier) !== -1) {
  8401. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  8402. return undefined;
  8403. }
  8404. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  8405. return modifier;
  8406. }
  8407. }
  8408. return undefined;
  8409. }
  8410. tsParseModifiers({
  8411. allowedModifiers,
  8412. disallowedModifiers,
  8413. stopOnStartOfClassStaticBlock,
  8414. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  8415. }, modified) {
  8416. const enforceOrder = (loc, modifier, before, after) => {
  8417. if (modifier === before && modified[after]) {
  8418. this.raise(TSErrors.InvalidModifiersOrder, {
  8419. at: loc,
  8420. orderedModifiers: [before, after]
  8421. });
  8422. }
  8423. };
  8424. const incompatible = (loc, modifier, mod1, mod2) => {
  8425. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  8426. this.raise(TSErrors.IncompatibleModifiers, {
  8427. at: loc,
  8428. modifiers: [mod1, mod2]
  8429. });
  8430. }
  8431. };
  8432. for (;;) {
  8433. const {
  8434. startLoc
  8435. } = this.state;
  8436. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  8437. if (!modifier) break;
  8438. if (tsIsAccessModifier(modifier)) {
  8439. if (modified.accessibility) {
  8440. this.raise(TSErrors.DuplicateAccessibilityModifier, {
  8441. at: startLoc,
  8442. modifier
  8443. });
  8444. } else {
  8445. enforceOrder(startLoc, modifier, modifier, "override");
  8446. enforceOrder(startLoc, modifier, modifier, "static");
  8447. enforceOrder(startLoc, modifier, modifier, "readonly");
  8448. modified.accessibility = modifier;
  8449. }
  8450. } else if (tsIsVarianceAnnotations(modifier)) {
  8451. if (modified[modifier]) {
  8452. this.raise(TSErrors.DuplicateModifier, {
  8453. at: startLoc,
  8454. modifier
  8455. });
  8456. }
  8457. modified[modifier] = true;
  8458. enforceOrder(startLoc, modifier, "in", "out");
  8459. } else {
  8460. if (Object.hasOwnProperty.call(modified, modifier)) {
  8461. this.raise(TSErrors.DuplicateModifier, {
  8462. at: startLoc,
  8463. modifier
  8464. });
  8465. } else {
  8466. enforceOrder(startLoc, modifier, "static", "readonly");
  8467. enforceOrder(startLoc, modifier, "static", "override");
  8468. enforceOrder(startLoc, modifier, "override", "readonly");
  8469. enforceOrder(startLoc, modifier, "abstract", "override");
  8470. incompatible(startLoc, modifier, "declare", "override");
  8471. incompatible(startLoc, modifier, "static", "abstract");
  8472. }
  8473. modified[modifier] = true;
  8474. }
  8475. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  8476. this.raise(errorTemplate, {
  8477. at: startLoc,
  8478. modifier
  8479. });
  8480. }
  8481. }
  8482. }
  8483. tsIsListTerminator(kind) {
  8484. switch (kind) {
  8485. case "EnumMembers":
  8486. case "TypeMembers":
  8487. return this.match(8);
  8488. case "HeritageClauseElement":
  8489. return this.match(5);
  8490. case "TupleElementTypes":
  8491. return this.match(3);
  8492. case "TypeParametersOrArguments":
  8493. return this.match(48);
  8494. }
  8495. }
  8496. tsParseList(kind, parseElement) {
  8497. const result = [];
  8498. while (!this.tsIsListTerminator(kind)) {
  8499. result.push(parseElement());
  8500. }
  8501. return result;
  8502. }
  8503. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  8504. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  8505. }
  8506. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  8507. const result = [];
  8508. let trailingCommaPos = -1;
  8509. for (;;) {
  8510. if (this.tsIsListTerminator(kind)) {
  8511. break;
  8512. }
  8513. trailingCommaPos = -1;
  8514. const element = parseElement();
  8515. if (element == null) {
  8516. return undefined;
  8517. }
  8518. result.push(element);
  8519. if (this.eat(12)) {
  8520. trailingCommaPos = this.state.lastTokStart;
  8521. continue;
  8522. }
  8523. if (this.tsIsListTerminator(kind)) {
  8524. break;
  8525. }
  8526. if (expectSuccess) {
  8527. this.expect(12);
  8528. }
  8529. return undefined;
  8530. }
  8531. if (refTrailingCommaPos) {
  8532. refTrailingCommaPos.value = trailingCommaPos;
  8533. }
  8534. return result;
  8535. }
  8536. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  8537. if (!skipFirstToken) {
  8538. if (bracket) {
  8539. this.expect(0);
  8540. } else {
  8541. this.expect(47);
  8542. }
  8543. }
  8544. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  8545. if (bracket) {
  8546. this.expect(3);
  8547. } else {
  8548. this.expect(48);
  8549. }
  8550. return result;
  8551. }
  8552. tsParseImportType() {
  8553. const node = this.startNode();
  8554. this.expect(83);
  8555. this.expect(10);
  8556. if (!this.match(131)) {
  8557. this.raise(TSErrors.UnsupportedImportTypeArgument, {
  8558. at: this.state.startLoc
  8559. });
  8560. }
  8561. node.argument = super.parseExprAtom();
  8562. this.expect(11);
  8563. if (this.eat(16)) {
  8564. node.qualifier = this.tsParseEntityName();
  8565. }
  8566. if (this.match(47)) {
  8567. node.typeParameters = this.tsParseTypeArguments();
  8568. }
  8569. return this.finishNode(node, "TSImportType");
  8570. }
  8571. tsParseEntityName(allowReservedWords = true) {
  8572. let entity = this.parseIdentifier(allowReservedWords);
  8573. while (this.eat(16)) {
  8574. const node = this.startNodeAtNode(entity);
  8575. node.left = entity;
  8576. node.right = this.parseIdentifier(allowReservedWords);
  8577. entity = this.finishNode(node, "TSQualifiedName");
  8578. }
  8579. return entity;
  8580. }
  8581. tsParseTypeReference() {
  8582. const node = this.startNode();
  8583. node.typeName = this.tsParseEntityName();
  8584. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8585. node.typeParameters = this.tsParseTypeArguments();
  8586. }
  8587. return this.finishNode(node, "TSTypeReference");
  8588. }
  8589. tsParseThisTypePredicate(lhs) {
  8590. this.next();
  8591. const node = this.startNodeAtNode(lhs);
  8592. node.parameterName = lhs;
  8593. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  8594. node.asserts = false;
  8595. return this.finishNode(node, "TSTypePredicate");
  8596. }
  8597. tsParseThisTypeNode() {
  8598. const node = this.startNode();
  8599. this.next();
  8600. return this.finishNode(node, "TSThisType");
  8601. }
  8602. tsParseTypeQuery() {
  8603. const node = this.startNode();
  8604. this.expect(87);
  8605. if (this.match(83)) {
  8606. node.exprName = this.tsParseImportType();
  8607. } else {
  8608. node.exprName = this.tsParseEntityName();
  8609. }
  8610. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8611. node.typeParameters = this.tsParseTypeArguments();
  8612. }
  8613. return this.finishNode(node, "TSTypeQuery");
  8614. }
  8615. tsParseTypeParameter(parseModifiers) {
  8616. const node = this.startNode();
  8617. parseModifiers(node);
  8618. node.name = this.tsParseTypeParameterName();
  8619. node.constraint = this.tsEatThenParseType(81);
  8620. node.default = this.tsEatThenParseType(29);
  8621. return this.finishNode(node, "TSTypeParameter");
  8622. }
  8623. tsTryParseTypeParameters(parseModifiers) {
  8624. if (this.match(47)) {
  8625. return this.tsParseTypeParameters(parseModifiers);
  8626. }
  8627. }
  8628. tsParseTypeParameters(parseModifiers) {
  8629. const node = this.startNode();
  8630. if (this.match(47) || this.match(140)) {
  8631. this.next();
  8632. } else {
  8633. this.unexpected();
  8634. }
  8635. const refTrailingCommaPos = {
  8636. value: -1
  8637. };
  8638. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  8639. if (node.params.length === 0) {
  8640. this.raise(TSErrors.EmptyTypeParameters, {
  8641. at: node
  8642. });
  8643. }
  8644. if (refTrailingCommaPos.value !== -1) {
  8645. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  8646. }
  8647. return this.finishNode(node, "TSTypeParameterDeclaration");
  8648. }
  8649. tsFillSignature(returnToken, signature) {
  8650. const returnTokenRequired = returnToken === 19;
  8651. const paramsKey = "parameters";
  8652. const returnTypeKey = "typeAnnotation";
  8653. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  8654. this.expect(10);
  8655. signature[paramsKey] = this.tsParseBindingListForSignature();
  8656. if (returnTokenRequired) {
  8657. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8658. } else if (this.match(returnToken)) {
  8659. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8660. }
  8661. }
  8662. tsParseBindingListForSignature() {
  8663. return super.parseBindingList(11, 41, 2).map(pattern => {
  8664. if (pattern.type !== "Identifier" && pattern.type !== "RestElement" && pattern.type !== "ObjectPattern" && pattern.type !== "ArrayPattern") {
  8665. this.raise(TSErrors.UnsupportedSignatureParameterKind, {
  8666. at: pattern,
  8667. type: pattern.type
  8668. });
  8669. }
  8670. return pattern;
  8671. });
  8672. }
  8673. tsParseTypeMemberSemicolon() {
  8674. if (!this.eat(12) && !this.isLineTerminator()) {
  8675. this.expect(13);
  8676. }
  8677. }
  8678. tsParseSignatureMember(kind, node) {
  8679. this.tsFillSignature(14, node);
  8680. this.tsParseTypeMemberSemicolon();
  8681. return this.finishNode(node, kind);
  8682. }
  8683. tsIsUnambiguouslyIndexSignature() {
  8684. this.next();
  8685. if (tokenIsIdentifier(this.state.type)) {
  8686. this.next();
  8687. return this.match(14);
  8688. }
  8689. return false;
  8690. }
  8691. tsTryParseIndexSignature(node) {
  8692. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8693. return undefined;
  8694. }
  8695. this.expect(0);
  8696. const id = this.parseIdentifier();
  8697. id.typeAnnotation = this.tsParseTypeAnnotation();
  8698. this.resetEndLocation(id);
  8699. this.expect(3);
  8700. node.parameters = [id];
  8701. const type = this.tsTryParseTypeAnnotation();
  8702. if (type) node.typeAnnotation = type;
  8703. this.tsParseTypeMemberSemicolon();
  8704. return this.finishNode(node, "TSIndexSignature");
  8705. }
  8706. tsParsePropertyOrMethodSignature(node, readonly) {
  8707. if (this.eat(17)) node.optional = true;
  8708. const nodeAny = node;
  8709. if (this.match(10) || this.match(47)) {
  8710. if (readonly) {
  8711. this.raise(TSErrors.ReadonlyForMethodSignature, {
  8712. at: node
  8713. });
  8714. }
  8715. const method = nodeAny;
  8716. if (method.kind && this.match(47)) {
  8717. this.raise(TSErrors.AccesorCannotHaveTypeParameters, {
  8718. at: this.state.curPosition()
  8719. });
  8720. }
  8721. this.tsFillSignature(14, method);
  8722. this.tsParseTypeMemberSemicolon();
  8723. const paramsKey = "parameters";
  8724. const returnTypeKey = "typeAnnotation";
  8725. if (method.kind === "get") {
  8726. if (method[paramsKey].length > 0) {
  8727. this.raise(Errors.BadGetterArity, {
  8728. at: this.state.curPosition()
  8729. });
  8730. if (this.isThisParam(method[paramsKey][0])) {
  8731. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8732. at: this.state.curPosition()
  8733. });
  8734. }
  8735. }
  8736. } else if (method.kind === "set") {
  8737. if (method[paramsKey].length !== 1) {
  8738. this.raise(Errors.BadSetterArity, {
  8739. at: this.state.curPosition()
  8740. });
  8741. } else {
  8742. const firstParameter = method[paramsKey][0];
  8743. if (this.isThisParam(firstParameter)) {
  8744. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8745. at: this.state.curPosition()
  8746. });
  8747. }
  8748. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8749. this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, {
  8750. at: this.state.curPosition()
  8751. });
  8752. }
  8753. if (firstParameter.type === "RestElement") {
  8754. this.raise(TSErrors.SetAccesorCannotHaveRestParameter, {
  8755. at: this.state.curPosition()
  8756. });
  8757. }
  8758. }
  8759. if (method[returnTypeKey]) {
  8760. this.raise(TSErrors.SetAccesorCannotHaveReturnType, {
  8761. at: method[returnTypeKey]
  8762. });
  8763. }
  8764. } else {
  8765. method.kind = "method";
  8766. }
  8767. return this.finishNode(method, "TSMethodSignature");
  8768. } else {
  8769. const property = nodeAny;
  8770. if (readonly) property.readonly = true;
  8771. const type = this.tsTryParseTypeAnnotation();
  8772. if (type) property.typeAnnotation = type;
  8773. this.tsParseTypeMemberSemicolon();
  8774. return this.finishNode(property, "TSPropertySignature");
  8775. }
  8776. }
  8777. tsParseTypeMember() {
  8778. const node = this.startNode();
  8779. if (this.match(10) || this.match(47)) {
  8780. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8781. }
  8782. if (this.match(77)) {
  8783. const id = this.startNode();
  8784. this.next();
  8785. if (this.match(10) || this.match(47)) {
  8786. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8787. } else {
  8788. node.key = this.createIdentifier(id, "new");
  8789. return this.tsParsePropertyOrMethodSignature(node, false);
  8790. }
  8791. }
  8792. this.tsParseModifiers({
  8793. allowedModifiers: ["readonly"],
  8794. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8795. }, node);
  8796. const idx = this.tsTryParseIndexSignature(node);
  8797. if (idx) {
  8798. return idx;
  8799. }
  8800. super.parsePropertyName(node);
  8801. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8802. node.kind = node.key.name;
  8803. super.parsePropertyName(node);
  8804. }
  8805. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8806. }
  8807. tsParseTypeLiteral() {
  8808. const node = this.startNode();
  8809. node.members = this.tsParseObjectTypeMembers();
  8810. return this.finishNode(node, "TSTypeLiteral");
  8811. }
  8812. tsParseObjectTypeMembers() {
  8813. this.expect(5);
  8814. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8815. this.expect(8);
  8816. return members;
  8817. }
  8818. tsIsStartOfMappedType() {
  8819. this.next();
  8820. if (this.eat(53)) {
  8821. return this.isContextual(120);
  8822. }
  8823. if (this.isContextual(120)) {
  8824. this.next();
  8825. }
  8826. if (!this.match(0)) {
  8827. return false;
  8828. }
  8829. this.next();
  8830. if (!this.tsIsIdentifier()) {
  8831. return false;
  8832. }
  8833. this.next();
  8834. return this.match(58);
  8835. }
  8836. tsParseMappedTypeParameter() {
  8837. const node = this.startNode();
  8838. node.name = this.tsParseTypeParameterName();
  8839. node.constraint = this.tsExpectThenParseType(58);
  8840. return this.finishNode(node, "TSTypeParameter");
  8841. }
  8842. tsParseMappedType() {
  8843. const node = this.startNode();
  8844. this.expect(5);
  8845. if (this.match(53)) {
  8846. node.readonly = this.state.value;
  8847. this.next();
  8848. this.expectContextual(120);
  8849. } else if (this.eatContextual(120)) {
  8850. node.readonly = true;
  8851. }
  8852. this.expect(0);
  8853. node.typeParameter = this.tsParseMappedTypeParameter();
  8854. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8855. this.expect(3);
  8856. if (this.match(53)) {
  8857. node.optional = this.state.value;
  8858. this.next();
  8859. this.expect(17);
  8860. } else if (this.eat(17)) {
  8861. node.optional = true;
  8862. }
  8863. node.typeAnnotation = this.tsTryParseType();
  8864. this.semicolon();
  8865. this.expect(8);
  8866. return this.finishNode(node, "TSMappedType");
  8867. }
  8868. tsParseTupleType() {
  8869. const node = this.startNode();
  8870. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8871. let seenOptionalElement = false;
  8872. let labeledElements = null;
  8873. node.elementTypes.forEach(elementNode => {
  8874. var _labeledElements;
  8875. const {
  8876. type
  8877. } = elementNode;
  8878. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8879. this.raise(TSErrors.OptionalTypeBeforeRequired, {
  8880. at: elementNode
  8881. });
  8882. }
  8883. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8884. let checkType = type;
  8885. if (type === "TSRestType") {
  8886. elementNode = elementNode.typeAnnotation;
  8887. checkType = elementNode.type;
  8888. }
  8889. const isLabeled = checkType === "TSNamedTupleMember";
  8890. (_labeledElements = labeledElements) != null ? _labeledElements : labeledElements = isLabeled;
  8891. if (labeledElements !== isLabeled) {
  8892. this.raise(TSErrors.MixedLabeledAndUnlabeledElements, {
  8893. at: elementNode
  8894. });
  8895. }
  8896. });
  8897. return this.finishNode(node, "TSTupleType");
  8898. }
  8899. tsParseTupleElementType() {
  8900. const {
  8901. startLoc
  8902. } = this.state;
  8903. const rest = this.eat(21);
  8904. let labeled;
  8905. let label;
  8906. let optional;
  8907. let type;
  8908. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8909. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8910. if (chAfterWord === 58) {
  8911. labeled = true;
  8912. optional = false;
  8913. label = this.parseIdentifier(true);
  8914. this.expect(14);
  8915. type = this.tsParseType();
  8916. } else if (chAfterWord === 63) {
  8917. optional = true;
  8918. const startLoc = this.state.startLoc;
  8919. const wordName = this.state.value;
  8920. const typeOrLabel = this.tsParseNonArrayType();
  8921. if (this.lookaheadCharCode() === 58) {
  8922. labeled = true;
  8923. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8924. this.expect(17);
  8925. this.expect(14);
  8926. type = this.tsParseType();
  8927. } else {
  8928. labeled = false;
  8929. type = typeOrLabel;
  8930. this.expect(17);
  8931. }
  8932. } else {
  8933. type = this.tsParseType();
  8934. optional = this.eat(17);
  8935. labeled = this.eat(14);
  8936. }
  8937. if (labeled) {
  8938. let labeledNode;
  8939. if (label) {
  8940. labeledNode = this.startNodeAtNode(label);
  8941. labeledNode.optional = optional;
  8942. labeledNode.label = label;
  8943. labeledNode.elementType = type;
  8944. if (this.eat(17)) {
  8945. labeledNode.optional = true;
  8946. this.raise(TSErrors.TupleOptionalAfterType, {
  8947. at: this.state.lastTokStartLoc
  8948. });
  8949. }
  8950. } else {
  8951. labeledNode = this.startNodeAtNode(type);
  8952. labeledNode.optional = optional;
  8953. this.raise(TSErrors.InvalidTupleMemberLabel, {
  8954. at: type
  8955. });
  8956. labeledNode.label = type;
  8957. labeledNode.elementType = this.tsParseType();
  8958. }
  8959. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8960. } else if (optional) {
  8961. const optionalTypeNode = this.startNodeAtNode(type);
  8962. optionalTypeNode.typeAnnotation = type;
  8963. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8964. }
  8965. if (rest) {
  8966. const restNode = this.startNodeAt(startLoc);
  8967. restNode.typeAnnotation = type;
  8968. type = this.finishNode(restNode, "TSRestType");
  8969. }
  8970. return type;
  8971. }
  8972. tsParseParenthesizedType() {
  8973. const node = this.startNode();
  8974. this.expect(10);
  8975. node.typeAnnotation = this.tsParseType();
  8976. this.expect(11);
  8977. return this.finishNode(node, "TSParenthesizedType");
  8978. }
  8979. tsParseFunctionOrConstructorType(type, abstract) {
  8980. const node = this.startNode();
  8981. if (type === "TSConstructorType") {
  8982. node.abstract = !!abstract;
  8983. if (abstract) this.next();
  8984. this.next();
  8985. }
  8986. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8987. return this.finishNode(node, type);
  8988. }
  8989. tsParseLiteralTypeNode() {
  8990. const node = this.startNode();
  8991. node.literal = (() => {
  8992. switch (this.state.type) {
  8993. case 132:
  8994. case 133:
  8995. case 131:
  8996. case 85:
  8997. case 86:
  8998. return super.parseExprAtom();
  8999. default:
  9000. this.unexpected();
  9001. }
  9002. })();
  9003. return this.finishNode(node, "TSLiteralType");
  9004. }
  9005. tsParseTemplateLiteralType() {
  9006. const node = this.startNode();
  9007. node.literal = super.parseTemplate(false);
  9008. return this.finishNode(node, "TSLiteralType");
  9009. }
  9010. parseTemplateSubstitution() {
  9011. if (this.state.inType) return this.tsParseType();
  9012. return super.parseTemplateSubstitution();
  9013. }
  9014. tsParseThisTypeOrThisTypePredicate() {
  9015. const thisKeyword = this.tsParseThisTypeNode();
  9016. if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
  9017. return this.tsParseThisTypePredicate(thisKeyword);
  9018. } else {
  9019. return thisKeyword;
  9020. }
  9021. }
  9022. tsParseNonArrayType() {
  9023. switch (this.state.type) {
  9024. case 131:
  9025. case 132:
  9026. case 133:
  9027. case 85:
  9028. case 86:
  9029. return this.tsParseLiteralTypeNode();
  9030. case 53:
  9031. if (this.state.value === "-") {
  9032. const node = this.startNode();
  9033. const nextToken = this.lookahead();
  9034. if (nextToken.type !== 132 && nextToken.type !== 133) {
  9035. this.unexpected();
  9036. }
  9037. node.literal = this.parseMaybeUnary();
  9038. return this.finishNode(node, "TSLiteralType");
  9039. }
  9040. break;
  9041. case 78:
  9042. return this.tsParseThisTypeOrThisTypePredicate();
  9043. case 87:
  9044. return this.tsParseTypeQuery();
  9045. case 83:
  9046. return this.tsParseImportType();
  9047. case 5:
  9048. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  9049. case 0:
  9050. return this.tsParseTupleType();
  9051. case 10:
  9052. return this.tsParseParenthesizedType();
  9053. case 25:
  9054. case 24:
  9055. return this.tsParseTemplateLiteralType();
  9056. default:
  9057. {
  9058. const {
  9059. type
  9060. } = this.state;
  9061. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  9062. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  9063. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  9064. const node = this.startNode();
  9065. this.next();
  9066. return this.finishNode(node, nodeType);
  9067. }
  9068. return this.tsParseTypeReference();
  9069. }
  9070. }
  9071. }
  9072. this.unexpected();
  9073. }
  9074. tsParseArrayTypeOrHigher() {
  9075. let type = this.tsParseNonArrayType();
  9076. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  9077. if (this.match(3)) {
  9078. const node = this.startNodeAtNode(type);
  9079. node.elementType = type;
  9080. this.expect(3);
  9081. type = this.finishNode(node, "TSArrayType");
  9082. } else {
  9083. const node = this.startNodeAtNode(type);
  9084. node.objectType = type;
  9085. node.indexType = this.tsParseType();
  9086. this.expect(3);
  9087. type = this.finishNode(node, "TSIndexedAccessType");
  9088. }
  9089. }
  9090. return type;
  9091. }
  9092. tsParseTypeOperator() {
  9093. const node = this.startNode();
  9094. const operator = this.state.value;
  9095. this.next();
  9096. node.operator = operator;
  9097. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  9098. if (operator === "readonly") {
  9099. this.tsCheckTypeAnnotationForReadOnly(node);
  9100. }
  9101. return this.finishNode(node, "TSTypeOperator");
  9102. }
  9103. tsCheckTypeAnnotationForReadOnly(node) {
  9104. switch (node.typeAnnotation.type) {
  9105. case "TSTupleType":
  9106. case "TSArrayType":
  9107. return;
  9108. default:
  9109. this.raise(TSErrors.UnexpectedReadonly, {
  9110. at: node
  9111. });
  9112. }
  9113. }
  9114. tsParseInferType() {
  9115. const node = this.startNode();
  9116. this.expectContextual(113);
  9117. const typeParameter = this.startNode();
  9118. typeParameter.name = this.tsParseTypeParameterName();
  9119. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  9120. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  9121. return this.finishNode(node, "TSInferType");
  9122. }
  9123. tsParseConstraintForInferType() {
  9124. if (this.eat(81)) {
  9125. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  9126. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  9127. return constraint;
  9128. }
  9129. }
  9130. }
  9131. tsParseTypeOperatorOrHigher() {
  9132. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  9133. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(113) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  9134. }
  9135. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  9136. const node = this.startNode();
  9137. const hasLeadingOperator = this.eat(operator);
  9138. const types = [];
  9139. do {
  9140. types.push(parseConstituentType());
  9141. } while (this.eat(operator));
  9142. if (types.length === 1 && !hasLeadingOperator) {
  9143. return types[0];
  9144. }
  9145. node.types = types;
  9146. return this.finishNode(node, kind);
  9147. }
  9148. tsParseIntersectionTypeOrHigher() {
  9149. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  9150. }
  9151. tsParseUnionTypeOrHigher() {
  9152. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  9153. }
  9154. tsIsStartOfFunctionType() {
  9155. if (this.match(47)) {
  9156. return true;
  9157. }
  9158. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  9159. }
  9160. tsSkipParameterStart() {
  9161. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  9162. this.next();
  9163. return true;
  9164. }
  9165. if (this.match(5)) {
  9166. const {
  9167. errors
  9168. } = this.state;
  9169. const previousErrorCount = errors.length;
  9170. try {
  9171. this.parseObjectLike(8, true);
  9172. return errors.length === previousErrorCount;
  9173. } catch (_unused) {
  9174. return false;
  9175. }
  9176. }
  9177. if (this.match(0)) {
  9178. this.next();
  9179. const {
  9180. errors
  9181. } = this.state;
  9182. const previousErrorCount = errors.length;
  9183. try {
  9184. super.parseBindingList(3, 93, 1);
  9185. return errors.length === previousErrorCount;
  9186. } catch (_unused2) {
  9187. return false;
  9188. }
  9189. }
  9190. return false;
  9191. }
  9192. tsIsUnambiguouslyStartOfFunctionType() {
  9193. this.next();
  9194. if (this.match(11) || this.match(21)) {
  9195. return true;
  9196. }
  9197. if (this.tsSkipParameterStart()) {
  9198. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  9199. return true;
  9200. }
  9201. if (this.match(11)) {
  9202. this.next();
  9203. if (this.match(19)) {
  9204. return true;
  9205. }
  9206. }
  9207. }
  9208. return false;
  9209. }
  9210. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  9211. return this.tsInType(() => {
  9212. const t = this.startNode();
  9213. this.expect(returnToken);
  9214. const node = this.startNode();
  9215. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  9216. if (asserts && this.match(78)) {
  9217. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  9218. if (thisTypePredicate.type === "TSThisType") {
  9219. node.parameterName = thisTypePredicate;
  9220. node.asserts = true;
  9221. node.typeAnnotation = null;
  9222. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  9223. } else {
  9224. this.resetStartLocationFromNode(thisTypePredicate, node);
  9225. thisTypePredicate.asserts = true;
  9226. }
  9227. t.typeAnnotation = thisTypePredicate;
  9228. return this.finishNode(t, "TSTypeAnnotation");
  9229. }
  9230. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  9231. if (!typePredicateVariable) {
  9232. if (!asserts) {
  9233. return this.tsParseTypeAnnotation(false, t);
  9234. }
  9235. node.parameterName = this.parseIdentifier();
  9236. node.asserts = asserts;
  9237. node.typeAnnotation = null;
  9238. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  9239. return this.finishNode(t, "TSTypeAnnotation");
  9240. }
  9241. const type = this.tsParseTypeAnnotation(false);
  9242. node.parameterName = typePredicateVariable;
  9243. node.typeAnnotation = type;
  9244. node.asserts = asserts;
  9245. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  9246. return this.finishNode(t, "TSTypeAnnotation");
  9247. });
  9248. }
  9249. tsTryParseTypeOrTypePredicateAnnotation() {
  9250. return this.match(14) ? this.tsParseTypeOrTypePredicateAnnotation(14) : undefined;
  9251. }
  9252. tsTryParseTypeAnnotation() {
  9253. return this.match(14) ? this.tsParseTypeAnnotation() : undefined;
  9254. }
  9255. tsTryParseType() {
  9256. return this.tsEatThenParseType(14);
  9257. }
  9258. tsParseTypePredicatePrefix() {
  9259. const id = this.parseIdentifier();
  9260. if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
  9261. this.next();
  9262. return id;
  9263. }
  9264. }
  9265. tsParseTypePredicateAsserts() {
  9266. if (this.state.type !== 107) {
  9267. return false;
  9268. }
  9269. const containsEsc = this.state.containsEsc;
  9270. this.next();
  9271. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  9272. return false;
  9273. }
  9274. if (containsEsc) {
  9275. this.raise(Errors.InvalidEscapedReservedWord, {
  9276. at: this.state.lastTokStartLoc,
  9277. reservedWord: "asserts"
  9278. });
  9279. }
  9280. return true;
  9281. }
  9282. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  9283. this.tsInType(() => {
  9284. if (eatColon) this.expect(14);
  9285. t.typeAnnotation = this.tsParseType();
  9286. });
  9287. return this.finishNode(t, "TSTypeAnnotation");
  9288. }
  9289. tsParseType() {
  9290. assert$1(this.state.inType);
  9291. const type = this.tsParseNonConditionalType();
  9292. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  9293. return type;
  9294. }
  9295. const node = this.startNodeAtNode(type);
  9296. node.checkType = type;
  9297. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  9298. this.expect(17);
  9299. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  9300. this.expect(14);
  9301. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  9302. return this.finishNode(node, "TSConditionalType");
  9303. }
  9304. isAbstractConstructorSignature() {
  9305. return this.isContextual(122) && this.lookahead().type === 77;
  9306. }
  9307. tsParseNonConditionalType() {
  9308. if (this.tsIsStartOfFunctionType()) {
  9309. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  9310. }
  9311. if (this.match(77)) {
  9312. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  9313. } else if (this.isAbstractConstructorSignature()) {
  9314. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  9315. }
  9316. return this.tsParseUnionTypeOrHigher();
  9317. }
  9318. tsParseTypeAssertion() {
  9319. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9320. this.raise(TSErrors.ReservedTypeAssertion, {
  9321. at: this.state.startLoc
  9322. });
  9323. }
  9324. const node = this.startNode();
  9325. node.typeAnnotation = this.tsInType(() => {
  9326. this.next();
  9327. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  9328. });
  9329. this.expect(48);
  9330. node.expression = this.parseMaybeUnary();
  9331. return this.finishNode(node, "TSTypeAssertion");
  9332. }
  9333. tsParseHeritageClause(token) {
  9334. const originalStartLoc = this.state.startLoc;
  9335. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  9336. const node = this.startNode();
  9337. node.expression = this.tsParseEntityName();
  9338. if (this.match(47)) {
  9339. node.typeParameters = this.tsParseTypeArguments();
  9340. }
  9341. return this.finishNode(node, "TSExpressionWithTypeArguments");
  9342. });
  9343. if (!delimitedList.length) {
  9344. this.raise(TSErrors.EmptyHeritageClauseType, {
  9345. at: originalStartLoc,
  9346. token
  9347. });
  9348. }
  9349. return delimitedList;
  9350. }
  9351. tsParseInterfaceDeclaration(node, properties = {}) {
  9352. if (this.hasFollowingLineBreak()) return null;
  9353. this.expectContextual(127);
  9354. if (properties.declare) node.declare = true;
  9355. if (tokenIsIdentifier(this.state.type)) {
  9356. node.id = this.parseIdentifier();
  9357. this.checkIdentifier(node.id, BIND_TS_INTERFACE);
  9358. } else {
  9359. node.id = null;
  9360. this.raise(TSErrors.MissingInterfaceName, {
  9361. at: this.state.startLoc
  9362. });
  9363. }
  9364. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9365. if (this.eat(81)) {
  9366. node.extends = this.tsParseHeritageClause("extends");
  9367. }
  9368. const body = this.startNode();
  9369. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  9370. node.body = this.finishNode(body, "TSInterfaceBody");
  9371. return this.finishNode(node, "TSInterfaceDeclaration");
  9372. }
  9373. tsParseTypeAliasDeclaration(node) {
  9374. node.id = this.parseIdentifier();
  9375. this.checkIdentifier(node.id, BIND_TS_TYPE);
  9376. node.typeAnnotation = this.tsInType(() => {
  9377. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  9378. this.expect(29);
  9379. if (this.isContextual(112) && this.lookahead().type !== 16) {
  9380. const node = this.startNode();
  9381. this.next();
  9382. return this.finishNode(node, "TSIntrinsicKeyword");
  9383. }
  9384. return this.tsParseType();
  9385. });
  9386. this.semicolon();
  9387. return this.finishNode(node, "TSTypeAliasDeclaration");
  9388. }
  9389. tsInNoContext(cb) {
  9390. const oldContext = this.state.context;
  9391. this.state.context = [oldContext[0]];
  9392. try {
  9393. return cb();
  9394. } finally {
  9395. this.state.context = oldContext;
  9396. }
  9397. }
  9398. tsInType(cb) {
  9399. const oldInType = this.state.inType;
  9400. this.state.inType = true;
  9401. try {
  9402. return cb();
  9403. } finally {
  9404. this.state.inType = oldInType;
  9405. }
  9406. }
  9407. tsInDisallowConditionalTypesContext(cb) {
  9408. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  9409. this.state.inDisallowConditionalTypesContext = true;
  9410. try {
  9411. return cb();
  9412. } finally {
  9413. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  9414. }
  9415. }
  9416. tsInAllowConditionalTypesContext(cb) {
  9417. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  9418. this.state.inDisallowConditionalTypesContext = false;
  9419. try {
  9420. return cb();
  9421. } finally {
  9422. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  9423. }
  9424. }
  9425. tsEatThenParseType(token) {
  9426. return !this.match(token) ? undefined : this.tsNextThenParseType();
  9427. }
  9428. tsExpectThenParseType(token) {
  9429. return this.tsDoThenParseType(() => this.expect(token));
  9430. }
  9431. tsNextThenParseType() {
  9432. return this.tsDoThenParseType(() => this.next());
  9433. }
  9434. tsDoThenParseType(cb) {
  9435. return this.tsInType(() => {
  9436. cb();
  9437. return this.tsParseType();
  9438. });
  9439. }
  9440. tsParseEnumMember() {
  9441. const node = this.startNode();
  9442. node.id = this.match(131) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  9443. if (this.eat(29)) {
  9444. node.initializer = super.parseMaybeAssignAllowIn();
  9445. }
  9446. return this.finishNode(node, "TSEnumMember");
  9447. }
  9448. tsParseEnumDeclaration(node, properties = {}) {
  9449. if (properties.const) node.const = true;
  9450. if (properties.declare) node.declare = true;
  9451. this.expectContextual(124);
  9452. node.id = this.parseIdentifier();
  9453. this.checkIdentifier(node.id, node.const ? BIND_TS_CONST_ENUM : BIND_TS_ENUM);
  9454. this.expect(5);
  9455. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  9456. this.expect(8);
  9457. return this.finishNode(node, "TSEnumDeclaration");
  9458. }
  9459. tsParseModuleBlock() {
  9460. const node = this.startNode();
  9461. this.scope.enter(SCOPE_OTHER);
  9462. this.expect(5);
  9463. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  9464. this.scope.exit();
  9465. return this.finishNode(node, "TSModuleBlock");
  9466. }
  9467. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  9468. node.id = this.parseIdentifier();
  9469. if (!nested) {
  9470. this.checkIdentifier(node.id, BIND_TS_NAMESPACE);
  9471. }
  9472. if (this.eat(16)) {
  9473. const inner = this.startNode();
  9474. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  9475. node.body = inner;
  9476. } else {
  9477. this.scope.enter(SCOPE_TS_MODULE);
  9478. this.prodParam.enter(PARAM);
  9479. node.body = this.tsParseModuleBlock();
  9480. this.prodParam.exit();
  9481. this.scope.exit();
  9482. }
  9483. return this.finishNode(node, "TSModuleDeclaration");
  9484. }
  9485. tsParseAmbientExternalModuleDeclaration(node) {
  9486. if (this.isContextual(110)) {
  9487. node.global = true;
  9488. node.id = this.parseIdentifier();
  9489. } else if (this.match(131)) {
  9490. node.id = super.parseStringLiteral(this.state.value);
  9491. } else {
  9492. this.unexpected();
  9493. }
  9494. if (this.match(5)) {
  9495. this.scope.enter(SCOPE_TS_MODULE);
  9496. this.prodParam.enter(PARAM);
  9497. node.body = this.tsParseModuleBlock();
  9498. this.prodParam.exit();
  9499. this.scope.exit();
  9500. } else {
  9501. this.semicolon();
  9502. }
  9503. return this.finishNode(node, "TSModuleDeclaration");
  9504. }
  9505. tsParseImportEqualsDeclaration(node, isExport) {
  9506. node.isExport = isExport || false;
  9507. node.id = this.parseIdentifier();
  9508. this.checkIdentifier(node.id, BIND_FLAGS_TS_IMPORT);
  9509. this.expect(29);
  9510. const moduleReference = this.tsParseModuleReference();
  9511. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  9512. this.raise(TSErrors.ImportAliasHasImportType, {
  9513. at: moduleReference
  9514. });
  9515. }
  9516. node.moduleReference = moduleReference;
  9517. this.semicolon();
  9518. return this.finishNode(node, "TSImportEqualsDeclaration");
  9519. }
  9520. tsIsExternalModuleReference() {
  9521. return this.isContextual(117) && this.lookaheadCharCode() === 40;
  9522. }
  9523. tsParseModuleReference() {
  9524. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  9525. }
  9526. tsParseExternalModuleReference() {
  9527. const node = this.startNode();
  9528. this.expectContextual(117);
  9529. this.expect(10);
  9530. if (!this.match(131)) {
  9531. this.unexpected();
  9532. }
  9533. node.expression = super.parseExprAtom();
  9534. this.expect(11);
  9535. return this.finishNode(node, "TSExternalModuleReference");
  9536. }
  9537. tsLookAhead(f) {
  9538. const state = this.state.clone();
  9539. const res = f();
  9540. this.state = state;
  9541. return res;
  9542. }
  9543. tsTryParseAndCatch(f) {
  9544. const result = this.tryParse(abort => f() || abort());
  9545. if (result.aborted || !result.node) return undefined;
  9546. if (result.error) this.state = result.failState;
  9547. return result.node;
  9548. }
  9549. tsTryParse(f) {
  9550. const state = this.state.clone();
  9551. const result = f();
  9552. if (result !== undefined && result !== false) {
  9553. return result;
  9554. } else {
  9555. this.state = state;
  9556. return undefined;
  9557. }
  9558. }
  9559. tsTryParseDeclare(nany) {
  9560. if (this.isLineTerminator()) {
  9561. return;
  9562. }
  9563. let starttype = this.state.type;
  9564. let kind;
  9565. if (this.isContextual(99)) {
  9566. starttype = 74;
  9567. kind = "let";
  9568. }
  9569. return this.tsInAmbientContext(() => {
  9570. if (starttype === 68) {
  9571. nany.declare = true;
  9572. return super.parseFunctionStatement(nany, false, false);
  9573. }
  9574. if (starttype === 80) {
  9575. nany.declare = true;
  9576. return this.parseClass(nany, true, false);
  9577. }
  9578. if (starttype === 124) {
  9579. return this.tsParseEnumDeclaration(nany, {
  9580. declare: true
  9581. });
  9582. }
  9583. if (starttype === 110) {
  9584. return this.tsParseAmbientExternalModuleDeclaration(nany);
  9585. }
  9586. if (starttype === 75 || starttype === 74) {
  9587. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  9588. nany.declare = true;
  9589. return this.parseVarStatement(nany, kind || this.state.value, true);
  9590. }
  9591. this.expect(75);
  9592. return this.tsParseEnumDeclaration(nany, {
  9593. const: true,
  9594. declare: true
  9595. });
  9596. }
  9597. if (starttype === 127) {
  9598. const result = this.tsParseInterfaceDeclaration(nany, {
  9599. declare: true
  9600. });
  9601. if (result) return result;
  9602. }
  9603. if (tokenIsIdentifier(starttype)) {
  9604. return this.tsParseDeclaration(nany, this.state.value, true, null);
  9605. }
  9606. });
  9607. }
  9608. tsTryParseExportDeclaration() {
  9609. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  9610. }
  9611. tsParseExpressionStatement(node, expr, decorators) {
  9612. switch (expr.name) {
  9613. case "declare":
  9614. {
  9615. const declaration = this.tsTryParseDeclare(node);
  9616. if (declaration) {
  9617. declaration.declare = true;
  9618. return declaration;
  9619. }
  9620. break;
  9621. }
  9622. case "global":
  9623. if (this.match(5)) {
  9624. this.scope.enter(SCOPE_TS_MODULE);
  9625. this.prodParam.enter(PARAM);
  9626. const mod = node;
  9627. mod.global = true;
  9628. mod.id = expr;
  9629. mod.body = this.tsParseModuleBlock();
  9630. this.scope.exit();
  9631. this.prodParam.exit();
  9632. return this.finishNode(mod, "TSModuleDeclaration");
  9633. }
  9634. break;
  9635. default:
  9636. return this.tsParseDeclaration(node, expr.name, false, decorators);
  9637. }
  9638. }
  9639. tsParseDeclaration(node, value, next, decorators) {
  9640. switch (value) {
  9641. case "abstract":
  9642. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  9643. return this.tsParseAbstractDeclaration(node, decorators);
  9644. }
  9645. break;
  9646. case "module":
  9647. if (this.tsCheckLineTerminator(next)) {
  9648. if (this.match(131)) {
  9649. return this.tsParseAmbientExternalModuleDeclaration(node);
  9650. } else if (tokenIsIdentifier(this.state.type)) {
  9651. return this.tsParseModuleOrNamespaceDeclaration(node);
  9652. }
  9653. }
  9654. break;
  9655. case "namespace":
  9656. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9657. return this.tsParseModuleOrNamespaceDeclaration(node);
  9658. }
  9659. break;
  9660. case "type":
  9661. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9662. return this.tsParseTypeAliasDeclaration(node);
  9663. }
  9664. break;
  9665. }
  9666. }
  9667. tsCheckLineTerminator(next) {
  9668. if (next) {
  9669. if (this.hasFollowingLineBreak()) return false;
  9670. this.next();
  9671. return true;
  9672. }
  9673. return !this.isLineTerminator();
  9674. }
  9675. tsTryParseGenericAsyncArrowFunction(startLoc) {
  9676. if (!this.match(47)) {
  9677. return undefined;
  9678. }
  9679. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  9680. this.state.maybeInArrowParameters = true;
  9681. const res = this.tsTryParseAndCatch(() => {
  9682. const node = this.startNodeAt(startLoc);
  9683. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9684. super.parseFunctionParams(node);
  9685. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  9686. this.expect(19);
  9687. return node;
  9688. });
  9689. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9690. if (!res) {
  9691. return undefined;
  9692. }
  9693. return super.parseArrowExpression(res, null, true);
  9694. }
  9695. tsParseTypeArgumentsInExpression() {
  9696. if (this.reScan_lt() !== 47) {
  9697. return undefined;
  9698. }
  9699. return this.tsParseTypeArguments();
  9700. }
  9701. tsParseTypeArguments() {
  9702. const node = this.startNode();
  9703. node.params = this.tsInType(() => this.tsInNoContext(() => {
  9704. this.expect(47);
  9705. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  9706. }));
  9707. if (node.params.length === 0) {
  9708. this.raise(TSErrors.EmptyTypeArguments, {
  9709. at: node
  9710. });
  9711. }
  9712. this.expect(48);
  9713. return this.finishNode(node, "TSTypeParameterInstantiation");
  9714. }
  9715. tsIsDeclarationStart() {
  9716. return tokenIsTSDeclarationStart(this.state.type);
  9717. }
  9718. isExportDefaultSpecifier() {
  9719. if (this.tsIsDeclarationStart()) return false;
  9720. return super.isExportDefaultSpecifier();
  9721. }
  9722. parseAssignableListItem(flags, decorators) {
  9723. const startLoc = this.state.startLoc;
  9724. const modified = {};
  9725. this.tsParseModifiers({
  9726. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9727. }, modified);
  9728. const accessibility = modified.accessibility;
  9729. const override = modified.override;
  9730. const readonly = modified.readonly;
  9731. if (!(flags & 4) && (accessibility || readonly || override)) {
  9732. this.raise(TSErrors.UnexpectedParameterModifier, {
  9733. at: startLoc
  9734. });
  9735. }
  9736. const left = this.parseMaybeDefault();
  9737. this.parseAssignableListItemTypes(left, flags);
  9738. const elt = this.parseMaybeDefault(left.loc.start, left);
  9739. if (accessibility || readonly || override) {
  9740. const pp = this.startNodeAt(startLoc);
  9741. if (decorators.length) {
  9742. pp.decorators = decorators;
  9743. }
  9744. if (accessibility) pp.accessibility = accessibility;
  9745. if (readonly) pp.readonly = readonly;
  9746. if (override) pp.override = override;
  9747. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9748. this.raise(TSErrors.UnsupportedParameterPropertyKind, {
  9749. at: pp
  9750. });
  9751. }
  9752. pp.parameter = elt;
  9753. return this.finishNode(pp, "TSParameterProperty");
  9754. }
  9755. if (decorators.length) {
  9756. left.decorators = decorators;
  9757. }
  9758. return elt;
  9759. }
  9760. isSimpleParameter(node) {
  9761. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9762. }
  9763. tsDisallowOptionalPattern(node) {
  9764. for (const param of node.params) {
  9765. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9766. this.raise(TSErrors.PatternIsOptional, {
  9767. at: param
  9768. });
  9769. }
  9770. }
  9771. }
  9772. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9773. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9774. this.tsDisallowOptionalPattern(node);
  9775. }
  9776. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9777. if (this.match(14)) {
  9778. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9779. }
  9780. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9781. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9782. return this.finishNode(node, bodilessType);
  9783. }
  9784. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9785. this.raise(TSErrors.DeclareFunctionHasImplementation, {
  9786. at: node
  9787. });
  9788. if (node.declare) {
  9789. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9790. }
  9791. }
  9792. this.tsDisallowOptionalPattern(node);
  9793. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9794. }
  9795. registerFunctionStatementId(node) {
  9796. if (!node.body && node.id) {
  9797. this.checkIdentifier(node.id, BIND_TS_AMBIENT);
  9798. } else {
  9799. super.registerFunctionStatementId(node);
  9800. }
  9801. }
  9802. tsCheckForInvalidTypeCasts(items) {
  9803. items.forEach(node => {
  9804. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9805. this.raise(TSErrors.UnexpectedTypeAnnotation, {
  9806. at: node.typeAnnotation
  9807. });
  9808. }
  9809. });
  9810. }
  9811. toReferencedList(exprList, isInParens) {
  9812. this.tsCheckForInvalidTypeCasts(exprList);
  9813. return exprList;
  9814. }
  9815. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9816. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9817. if (node.type === "ArrayExpression") {
  9818. this.tsCheckForInvalidTypeCasts(node.elements);
  9819. }
  9820. return node;
  9821. }
  9822. parseSubscript(base, startLoc, noCalls, state) {
  9823. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9824. this.state.canStartJSXElement = false;
  9825. this.next();
  9826. const nonNullExpression = this.startNodeAt(startLoc);
  9827. nonNullExpression.expression = base;
  9828. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9829. }
  9830. let isOptionalCall = false;
  9831. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9832. if (noCalls) {
  9833. state.stop = true;
  9834. return base;
  9835. }
  9836. state.optionalChainMember = isOptionalCall = true;
  9837. this.next();
  9838. }
  9839. if (this.match(47) || this.match(51)) {
  9840. let missingParenErrorLoc;
  9841. const result = this.tsTryParseAndCatch(() => {
  9842. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9843. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9844. if (asyncArrowFn) {
  9845. return asyncArrowFn;
  9846. }
  9847. }
  9848. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9849. if (!typeArguments) return;
  9850. if (isOptionalCall && !this.match(10)) {
  9851. missingParenErrorLoc = this.state.curPosition();
  9852. return;
  9853. }
  9854. if (tokenIsTemplate(this.state.type)) {
  9855. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9856. result.typeParameters = typeArguments;
  9857. return result;
  9858. }
  9859. if (!noCalls && this.eat(10)) {
  9860. const node = this.startNodeAt(startLoc);
  9861. node.callee = base;
  9862. node.arguments = this.parseCallExpressionArguments(11, false);
  9863. this.tsCheckForInvalidTypeCasts(node.arguments);
  9864. node.typeParameters = typeArguments;
  9865. if (state.optionalChainMember) {
  9866. node.optional = isOptionalCall;
  9867. }
  9868. return this.finishCallExpression(node, state.optionalChainMember);
  9869. }
  9870. const tokenType = this.state.type;
  9871. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9872. return;
  9873. }
  9874. const node = this.startNodeAt(startLoc);
  9875. node.expression = base;
  9876. node.typeParameters = typeArguments;
  9877. return this.finishNode(node, "TSInstantiationExpression");
  9878. });
  9879. if (missingParenErrorLoc) {
  9880. this.unexpected(missingParenErrorLoc, 10);
  9881. }
  9882. if (result) {
  9883. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  9884. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, {
  9885. at: this.state.startLoc
  9886. });
  9887. }
  9888. return result;
  9889. }
  9890. }
  9891. return super.parseSubscript(base, startLoc, noCalls, state);
  9892. }
  9893. parseNewCallee(node) {
  9894. var _callee$extra;
  9895. super.parseNewCallee(node);
  9896. const {
  9897. callee
  9898. } = node;
  9899. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9900. node.typeParameters = callee.typeParameters;
  9901. node.callee = callee.expression;
  9902. }
  9903. }
  9904. parseExprOp(left, leftStartLoc, minPrec) {
  9905. let isSatisfies;
  9906. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(118)))) {
  9907. const node = this.startNodeAt(leftStartLoc);
  9908. node.expression = left;
  9909. node.typeAnnotation = this.tsInType(() => {
  9910. this.next();
  9911. if (this.match(75)) {
  9912. if (isSatisfies) {
  9913. this.raise(Errors.UnexpectedKeyword, {
  9914. at: this.state.startLoc,
  9915. keyword: "const"
  9916. });
  9917. }
  9918. return this.tsParseTypeReference();
  9919. }
  9920. return this.tsParseType();
  9921. });
  9922. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9923. this.reScan_lt_gt();
  9924. return this.parseExprOp(node, leftStartLoc, minPrec);
  9925. }
  9926. return super.parseExprOp(left, leftStartLoc, minPrec);
  9927. }
  9928. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9929. if (!this.state.isAmbientContext) {
  9930. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9931. }
  9932. }
  9933. checkImportReflection(node) {
  9934. super.checkImportReflection(node);
  9935. if (node.module && node.importKind !== "value") {
  9936. this.raise(TSErrors.ImportReflectionHasImportType, {
  9937. at: node.specifiers[0].loc.start
  9938. });
  9939. }
  9940. }
  9941. checkDuplicateExports() {}
  9942. parseImport(node) {
  9943. node.importKind = "value";
  9944. if (tokenIsIdentifier(this.state.type) || this.match(55) || this.match(5)) {
  9945. let ahead = this.lookahead();
  9946. if (this.isContextual(128) && ahead.type !== 12 && ahead.type !== 97 && ahead.type !== 29) {
  9947. node.importKind = "type";
  9948. this.next();
  9949. ahead = this.lookahead();
  9950. }
  9951. if (tokenIsIdentifier(this.state.type) && ahead.type === 29) {
  9952. return this.tsParseImportEqualsDeclaration(node);
  9953. }
  9954. }
  9955. const importNode = super.parseImport(node);
  9956. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9957. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, {
  9958. at: importNode
  9959. });
  9960. }
  9961. return importNode;
  9962. }
  9963. parseExport(node, decorators) {
  9964. if (this.match(83)) {
  9965. this.next();
  9966. if (this.isContextual(128) && this.lookaheadCharCode() !== 61) {
  9967. node.importKind = "type";
  9968. this.next();
  9969. } else {
  9970. node.importKind = "value";
  9971. }
  9972. return this.tsParseImportEqualsDeclaration(node, true);
  9973. } else if (this.eat(29)) {
  9974. const assign = node;
  9975. assign.expression = super.parseExpression();
  9976. this.semicolon();
  9977. return this.finishNode(assign, "TSExportAssignment");
  9978. } else if (this.eatContextual(93)) {
  9979. const decl = node;
  9980. this.expectContextual(126);
  9981. decl.id = this.parseIdentifier();
  9982. this.semicolon();
  9983. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9984. } else {
  9985. node.exportKind = "value";
  9986. if (this.isContextual(128)) {
  9987. const ch = this.lookaheadCharCode();
  9988. if (ch === 123 || ch === 42) {
  9989. this.next();
  9990. node.exportKind = "type";
  9991. }
  9992. }
  9993. return super.parseExport(node, decorators);
  9994. }
  9995. }
  9996. isAbstractClass() {
  9997. return this.isContextual(122) && this.lookahead().type === 80;
  9998. }
  9999. parseExportDefaultExpression() {
  10000. if (this.isAbstractClass()) {
  10001. const cls = this.startNode();
  10002. this.next();
  10003. cls.abstract = true;
  10004. return this.parseClass(cls, true, true);
  10005. }
  10006. if (this.match(127)) {
  10007. const result = this.tsParseInterfaceDeclaration(this.startNode());
  10008. if (result) return result;
  10009. }
  10010. return super.parseExportDefaultExpression();
  10011. }
  10012. parseVarStatement(node, kind, allowMissingInitializer = false) {
  10013. const {
  10014. isAmbientContext
  10015. } = this.state;
  10016. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  10017. if (!isAmbientContext) return declaration;
  10018. for (const {
  10019. id,
  10020. init
  10021. } of declaration.declarations) {
  10022. if (!init) continue;
  10023. if (kind !== "const" || !!id.typeAnnotation) {
  10024. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, {
  10025. at: init
  10026. });
  10027. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  10028. this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, {
  10029. at: init
  10030. });
  10031. }
  10032. }
  10033. return declaration;
  10034. }
  10035. parseStatementContent(flags, decorators) {
  10036. if (this.match(75) && this.isLookaheadContextual("enum")) {
  10037. const node = this.startNode();
  10038. this.expect(75);
  10039. return this.tsParseEnumDeclaration(node, {
  10040. const: true
  10041. });
  10042. }
  10043. if (this.isContextual(124)) {
  10044. return this.tsParseEnumDeclaration(this.startNode());
  10045. }
  10046. if (this.isContextual(127)) {
  10047. const result = this.tsParseInterfaceDeclaration(this.startNode());
  10048. if (result) return result;
  10049. }
  10050. return super.parseStatementContent(flags, decorators);
  10051. }
  10052. parseAccessModifier() {
  10053. return this.tsParseModifier(["public", "protected", "private"]);
  10054. }
  10055. tsHasSomeModifiers(member, modifiers) {
  10056. return modifiers.some(modifier => {
  10057. if (tsIsAccessModifier(modifier)) {
  10058. return member.accessibility === modifier;
  10059. }
  10060. return !!member[modifier];
  10061. });
  10062. }
  10063. tsIsStartOfStaticBlocks() {
  10064. return this.isContextual(104) && this.lookaheadCharCode() === 123;
  10065. }
  10066. parseClassMember(classBody, member, state) {
  10067. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  10068. this.tsParseModifiers({
  10069. allowedModifiers: modifiers,
  10070. disallowedModifiers: ["in", "out"],
  10071. stopOnStartOfClassStaticBlock: true,
  10072. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  10073. }, member);
  10074. const callParseClassMemberWithIsStatic = () => {
  10075. if (this.tsIsStartOfStaticBlocks()) {
  10076. this.next();
  10077. this.next();
  10078. if (this.tsHasSomeModifiers(member, modifiers)) {
  10079. this.raise(TSErrors.StaticBlockCannotHaveModifier, {
  10080. at: this.state.curPosition()
  10081. });
  10082. }
  10083. super.parseClassStaticBlock(classBody, member);
  10084. } else {
  10085. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  10086. }
  10087. };
  10088. if (member.declare) {
  10089. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  10090. } else {
  10091. callParseClassMemberWithIsStatic();
  10092. }
  10093. }
  10094. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  10095. const idx = this.tsTryParseIndexSignature(member);
  10096. if (idx) {
  10097. classBody.body.push(idx);
  10098. if (member.abstract) {
  10099. this.raise(TSErrors.IndexSignatureHasAbstract, {
  10100. at: member
  10101. });
  10102. }
  10103. if (member.accessibility) {
  10104. this.raise(TSErrors.IndexSignatureHasAccessibility, {
  10105. at: member,
  10106. modifier: member.accessibility
  10107. });
  10108. }
  10109. if (member.declare) {
  10110. this.raise(TSErrors.IndexSignatureHasDeclare, {
  10111. at: member
  10112. });
  10113. }
  10114. if (member.override) {
  10115. this.raise(TSErrors.IndexSignatureHasOverride, {
  10116. at: member
  10117. });
  10118. }
  10119. return;
  10120. }
  10121. if (!this.state.inAbstractClass && member.abstract) {
  10122. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
  10123. at: member
  10124. });
  10125. }
  10126. if (member.override) {
  10127. if (!state.hadSuperClass) {
  10128. this.raise(TSErrors.OverrideNotInSubClass, {
  10129. at: member
  10130. });
  10131. }
  10132. }
  10133. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  10134. }
  10135. parsePostMemberNameModifiers(methodOrProp) {
  10136. const optional = this.eat(17);
  10137. if (optional) methodOrProp.optional = true;
  10138. if (methodOrProp.readonly && this.match(10)) {
  10139. this.raise(TSErrors.ClassMethodHasReadonly, {
  10140. at: methodOrProp
  10141. });
  10142. }
  10143. if (methodOrProp.declare && this.match(10)) {
  10144. this.raise(TSErrors.ClassMethodHasDeclare, {
  10145. at: methodOrProp
  10146. });
  10147. }
  10148. }
  10149. parseExpressionStatement(node, expr, decorators) {
  10150. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  10151. return decl || super.parseExpressionStatement(node, expr, decorators);
  10152. }
  10153. shouldParseExportDeclaration() {
  10154. if (this.tsIsDeclarationStart()) return true;
  10155. return super.shouldParseExportDeclaration();
  10156. }
  10157. parseConditional(expr, startLoc, refExpressionErrors) {
  10158. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  10159. return super.parseConditional(expr, startLoc, refExpressionErrors);
  10160. }
  10161. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  10162. if (!result.node) {
  10163. if (result.error) {
  10164. super.setOptionalParametersError(refExpressionErrors, result.error);
  10165. }
  10166. return expr;
  10167. }
  10168. if (result.error) this.state = result.failState;
  10169. return result.node;
  10170. }
  10171. parseParenItem(node, startLoc) {
  10172. node = super.parseParenItem(node, startLoc);
  10173. if (this.eat(17)) {
  10174. node.optional = true;
  10175. this.resetEndLocation(node);
  10176. }
  10177. if (this.match(14)) {
  10178. const typeCastNode = this.startNodeAt(startLoc);
  10179. typeCastNode.expression = node;
  10180. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  10181. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  10182. }
  10183. return node;
  10184. }
  10185. parseExportDeclaration(node) {
  10186. if (!this.state.isAmbientContext && this.isContextual(123)) {
  10187. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  10188. }
  10189. const startLoc = this.state.startLoc;
  10190. const isDeclare = this.eatContextual(123);
  10191. if (isDeclare && (this.isContextual(123) || !this.shouldParseExportDeclaration())) {
  10192. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
  10193. at: this.state.startLoc
  10194. });
  10195. }
  10196. const isIdentifier = tokenIsIdentifier(this.state.type);
  10197. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  10198. if (!declaration) return null;
  10199. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  10200. node.exportKind = "type";
  10201. }
  10202. if (isDeclare) {
  10203. this.resetStartLocation(declaration, startLoc);
  10204. declaration.declare = true;
  10205. }
  10206. return declaration;
  10207. }
  10208. parseClassId(node, isStatement, optionalId, bindingType) {
  10209. if ((!isStatement || optionalId) && this.isContextual(111)) {
  10210. return;
  10211. }
  10212. super.parseClassId(node, isStatement, optionalId, node.declare ? BIND_TS_AMBIENT : BIND_CLASS);
  10213. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  10214. if (typeParameters) node.typeParameters = typeParameters;
  10215. }
  10216. parseClassPropertyAnnotation(node) {
  10217. if (!node.optional) {
  10218. if (this.eat(35)) {
  10219. node.definite = true;
  10220. } else if (this.eat(17)) {
  10221. node.optional = true;
  10222. }
  10223. }
  10224. const type = this.tsTryParseTypeAnnotation();
  10225. if (type) node.typeAnnotation = type;
  10226. }
  10227. parseClassProperty(node) {
  10228. this.parseClassPropertyAnnotation(node);
  10229. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  10230. this.raise(TSErrors.DeclareClassFieldHasInitializer, {
  10231. at: this.state.startLoc
  10232. });
  10233. }
  10234. if (node.abstract && this.match(29)) {
  10235. const {
  10236. key
  10237. } = node;
  10238. this.raise(TSErrors.AbstractPropertyHasInitializer, {
  10239. at: this.state.startLoc,
  10240. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  10241. });
  10242. }
  10243. return super.parseClassProperty(node);
  10244. }
  10245. parseClassPrivateProperty(node) {
  10246. if (node.abstract) {
  10247. this.raise(TSErrors.PrivateElementHasAbstract, {
  10248. at: node
  10249. });
  10250. }
  10251. if (node.accessibility) {
  10252. this.raise(TSErrors.PrivateElementHasAccessibility, {
  10253. at: node,
  10254. modifier: node.accessibility
  10255. });
  10256. }
  10257. this.parseClassPropertyAnnotation(node);
  10258. return super.parseClassPrivateProperty(node);
  10259. }
  10260. parseClassAccessorProperty(node) {
  10261. this.parseClassPropertyAnnotation(node);
  10262. if (node.optional) {
  10263. this.raise(TSErrors.AccessorCannotBeOptional, {
  10264. at: node
  10265. });
  10266. }
  10267. return super.parseClassAccessorProperty(node);
  10268. }
  10269. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  10270. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  10271. if (typeParameters && isConstructor) {
  10272. this.raise(TSErrors.ConstructorHasTypeParameters, {
  10273. at: typeParameters
  10274. });
  10275. }
  10276. const {
  10277. declare = false,
  10278. kind
  10279. } = method;
  10280. if (declare && (kind === "get" || kind === "set")) {
  10281. this.raise(TSErrors.DeclareAccessor, {
  10282. at: method,
  10283. kind
  10284. });
  10285. }
  10286. if (typeParameters) method.typeParameters = typeParameters;
  10287. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  10288. }
  10289. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  10290. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  10291. if (typeParameters) method.typeParameters = typeParameters;
  10292. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  10293. }
  10294. declareClassPrivateMethodInScope(node, kind) {
  10295. if (node.type === "TSDeclareMethod") return;
  10296. if (node.type === "MethodDefinition" && !node.value.body) return;
  10297. super.declareClassPrivateMethodInScope(node, kind);
  10298. }
  10299. parseClassSuper(node) {
  10300. super.parseClassSuper(node);
  10301. if (node.superClass && (this.match(47) || this.match(51))) {
  10302. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  10303. }
  10304. if (this.eatContextual(111)) {
  10305. node.implements = this.tsParseHeritageClause("implements");
  10306. }
  10307. }
  10308. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  10309. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  10310. if (typeParameters) prop.typeParameters = typeParameters;
  10311. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  10312. }
  10313. parseFunctionParams(node, isConstructor) {
  10314. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  10315. if (typeParameters) node.typeParameters = typeParameters;
  10316. super.parseFunctionParams(node, isConstructor);
  10317. }
  10318. parseVarId(decl, kind) {
  10319. super.parseVarId(decl, kind);
  10320. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  10321. decl.definite = true;
  10322. }
  10323. const type = this.tsTryParseTypeAnnotation();
  10324. if (type) {
  10325. decl.id.typeAnnotation = type;
  10326. this.resetEndLocation(decl.id);
  10327. }
  10328. }
  10329. parseAsyncArrowFromCallExpression(node, call) {
  10330. if (this.match(14)) {
  10331. node.returnType = this.tsParseTypeAnnotation();
  10332. }
  10333. return super.parseAsyncArrowFromCallExpression(node, call);
  10334. }
  10335. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10336. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2, _jsx4, _typeCast3;
  10337. let state;
  10338. let jsx;
  10339. let typeCast;
  10340. if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
  10341. state = this.state.clone();
  10342. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  10343. if (!jsx.error) return jsx.node;
  10344. const {
  10345. context
  10346. } = this.state;
  10347. const currentContext = context[context.length - 1];
  10348. if (currentContext === types$1.j_oTag || currentContext === types$1.j_expr) {
  10349. context.pop();
  10350. }
  10351. }
  10352. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  10353. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  10354. }
  10355. if (!state || state === this.state) state = this.state.clone();
  10356. let typeParameters;
  10357. const arrow = this.tryParse(abort => {
  10358. var _expr$extra, _typeParameters;
  10359. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  10360. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  10361. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10362. abort();
  10363. }
  10364. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  10365. this.resetStartLocationFromNode(expr, typeParameters);
  10366. }
  10367. expr.typeParameters = typeParameters;
  10368. return expr;
  10369. }, state);
  10370. if (!arrow.error && !arrow.aborted) {
  10371. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  10372. return arrow.node;
  10373. }
  10374. if (!jsx) {
  10375. assert$1(!this.hasPlugin("jsx"));
  10376. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  10377. if (!typeCast.error) return typeCast.node;
  10378. }
  10379. if ((_jsx2 = jsx) != null && _jsx2.node) {
  10380. this.state = jsx.failState;
  10381. return jsx.node;
  10382. }
  10383. if (arrow.node) {
  10384. this.state = arrow.failState;
  10385. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  10386. return arrow.node;
  10387. }
  10388. if ((_typeCast = typeCast) != null && _typeCast.node) {
  10389. this.state = typeCast.failState;
  10390. return typeCast.node;
  10391. }
  10392. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  10393. if (arrow.thrown) throw arrow.error;
  10394. if ((_typeCast2 = typeCast) != null && _typeCast2.thrown) throw typeCast.error;
  10395. throw ((_jsx4 = jsx) == null ? void 0 : _jsx4.error) || arrow.error || ((_typeCast3 = typeCast) == null ? void 0 : _typeCast3.error);
  10396. }
  10397. reportReservedArrowTypeParam(node) {
  10398. var _node$extra;
  10399. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  10400. this.raise(TSErrors.ReservedArrowTypeParam, {
  10401. at: node
  10402. });
  10403. }
  10404. }
  10405. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10406. if (!this.hasPlugin("jsx") && this.match(47)) {
  10407. return this.tsParseTypeAssertion();
  10408. } else {
  10409. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  10410. }
  10411. }
  10412. parseArrow(node) {
  10413. if (this.match(14)) {
  10414. const result = this.tryParse(abort => {
  10415. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  10416. if (this.canInsertSemicolon() || !this.match(19)) abort();
  10417. return returnType;
  10418. });
  10419. if (result.aborted) return;
  10420. if (!result.thrown) {
  10421. if (result.error) this.state = result.failState;
  10422. node.returnType = result.node;
  10423. }
  10424. }
  10425. return super.parseArrow(node);
  10426. }
  10427. parseAssignableListItemTypes(param, flags) {
  10428. if (!(flags & 2)) return param;
  10429. if (this.eat(17)) {
  10430. param.optional = true;
  10431. }
  10432. const type = this.tsTryParseTypeAnnotation();
  10433. if (type) param.typeAnnotation = type;
  10434. this.resetEndLocation(param);
  10435. return param;
  10436. }
  10437. isAssignable(node, isBinding) {
  10438. switch (node.type) {
  10439. case "TSTypeCastExpression":
  10440. return this.isAssignable(node.expression, isBinding);
  10441. case "TSParameterProperty":
  10442. return true;
  10443. default:
  10444. return super.isAssignable(node, isBinding);
  10445. }
  10446. }
  10447. toAssignable(node, isLHS = false) {
  10448. switch (node.type) {
  10449. case "ParenthesizedExpression":
  10450. this.toAssignableParenthesizedExpression(node, isLHS);
  10451. break;
  10452. case "TSAsExpression":
  10453. case "TSSatisfiesExpression":
  10454. case "TSNonNullExpression":
  10455. case "TSTypeAssertion":
  10456. if (isLHS) {
  10457. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
  10458. at: node
  10459. });
  10460. } else {
  10461. this.raise(TSErrors.UnexpectedTypeCastInParameter, {
  10462. at: node
  10463. });
  10464. }
  10465. this.toAssignable(node.expression, isLHS);
  10466. break;
  10467. case "AssignmentExpression":
  10468. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  10469. node.left = this.typeCastToParameter(node.left);
  10470. }
  10471. default:
  10472. super.toAssignable(node, isLHS);
  10473. }
  10474. }
  10475. toAssignableParenthesizedExpression(node, isLHS) {
  10476. switch (node.expression.type) {
  10477. case "TSAsExpression":
  10478. case "TSSatisfiesExpression":
  10479. case "TSNonNullExpression":
  10480. case "TSTypeAssertion":
  10481. case "ParenthesizedExpression":
  10482. this.toAssignable(node.expression, isLHS);
  10483. break;
  10484. default:
  10485. super.toAssignable(node, isLHS);
  10486. }
  10487. }
  10488. checkToRestConversion(node, allowPattern) {
  10489. switch (node.type) {
  10490. case "TSAsExpression":
  10491. case "TSSatisfiesExpression":
  10492. case "TSTypeAssertion":
  10493. case "TSNonNullExpression":
  10494. this.checkToRestConversion(node.expression, false);
  10495. break;
  10496. default:
  10497. super.checkToRestConversion(node, allowPattern);
  10498. }
  10499. }
  10500. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  10501. return getOwn({
  10502. TSTypeCastExpression: true,
  10503. TSParameterProperty: "parameter",
  10504. TSNonNullExpression: "expression",
  10505. TSAsExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
  10506. TSSatisfiesExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
  10507. TSTypeAssertion: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true]
  10508. }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  10509. }
  10510. parseBindingAtom() {
  10511. switch (this.state.type) {
  10512. case 78:
  10513. return this.parseIdentifier(true);
  10514. default:
  10515. return super.parseBindingAtom();
  10516. }
  10517. }
  10518. parseMaybeDecoratorArguments(expr) {
  10519. if (this.match(47) || this.match(51)) {
  10520. const typeArguments = this.tsParseTypeArgumentsInExpression();
  10521. if (this.match(10)) {
  10522. const call = super.parseMaybeDecoratorArguments(expr);
  10523. call.typeParameters = typeArguments;
  10524. return call;
  10525. }
  10526. this.unexpected(null, 10);
  10527. }
  10528. return super.parseMaybeDecoratorArguments(expr);
  10529. }
  10530. checkCommaAfterRest(close) {
  10531. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  10532. this.next();
  10533. return false;
  10534. } else {
  10535. return super.checkCommaAfterRest(close);
  10536. }
  10537. }
  10538. isClassMethod() {
  10539. return this.match(47) || super.isClassMethod();
  10540. }
  10541. isClassProperty() {
  10542. return this.match(35) || this.match(14) || super.isClassProperty();
  10543. }
  10544. parseMaybeDefault(startLoc, left) {
  10545. const node = super.parseMaybeDefault(startLoc, left);
  10546. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  10547. this.raise(TSErrors.TypeAnnotationAfterAssign, {
  10548. at: node.typeAnnotation
  10549. });
  10550. }
  10551. return node;
  10552. }
  10553. getTokenFromCode(code) {
  10554. if (this.state.inType) {
  10555. if (code === 62) {
  10556. this.finishOp(48, 1);
  10557. return;
  10558. }
  10559. if (code === 60) {
  10560. this.finishOp(47, 1);
  10561. return;
  10562. }
  10563. }
  10564. super.getTokenFromCode(code);
  10565. }
  10566. reScan_lt_gt() {
  10567. const {
  10568. type
  10569. } = this.state;
  10570. if (type === 47) {
  10571. this.state.pos -= 1;
  10572. this.readToken_lt();
  10573. } else if (type === 48) {
  10574. this.state.pos -= 1;
  10575. this.readToken_gt();
  10576. }
  10577. }
  10578. reScan_lt() {
  10579. const {
  10580. type
  10581. } = this.state;
  10582. if (type === 51) {
  10583. this.state.pos -= 2;
  10584. this.finishOp(47, 1);
  10585. return 47;
  10586. }
  10587. return type;
  10588. }
  10589. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  10590. for (let i = 0; i < exprList.length; i++) {
  10591. const expr = exprList[i];
  10592. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  10593. exprList[i] = this.typeCastToParameter(expr);
  10594. }
  10595. }
  10596. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  10597. }
  10598. typeCastToParameter(node) {
  10599. node.expression.typeAnnotation = node.typeAnnotation;
  10600. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  10601. return node.expression;
  10602. }
  10603. shouldParseArrow(params) {
  10604. if (this.match(14)) {
  10605. return params.every(expr => this.isAssignable(expr, true));
  10606. }
  10607. return super.shouldParseArrow(params);
  10608. }
  10609. shouldParseAsyncArrow() {
  10610. return this.match(14) || super.shouldParseAsyncArrow();
  10611. }
  10612. canHaveLeadingDecorator() {
  10613. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  10614. }
  10615. jsxParseOpeningElementAfterName(node) {
  10616. if (this.match(47) || this.match(51)) {
  10617. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  10618. if (typeArguments) node.typeParameters = typeArguments;
  10619. }
  10620. return super.jsxParseOpeningElementAfterName(node);
  10621. }
  10622. getGetterSetterExpectedParamCount(method) {
  10623. const baseCount = super.getGetterSetterExpectedParamCount(method);
  10624. const params = this.getObjectOrClassMethodParams(method);
  10625. const firstParam = params[0];
  10626. const hasContextParam = firstParam && this.isThisParam(firstParam);
  10627. return hasContextParam ? baseCount + 1 : baseCount;
  10628. }
  10629. parseCatchClauseParam() {
  10630. const param = super.parseCatchClauseParam();
  10631. const type = this.tsTryParseTypeAnnotation();
  10632. if (type) {
  10633. param.typeAnnotation = type;
  10634. this.resetEndLocation(param);
  10635. }
  10636. return param;
  10637. }
  10638. tsInAmbientContext(cb) {
  10639. const oldIsAmbientContext = this.state.isAmbientContext;
  10640. this.state.isAmbientContext = true;
  10641. try {
  10642. return cb();
  10643. } finally {
  10644. this.state.isAmbientContext = oldIsAmbientContext;
  10645. }
  10646. }
  10647. parseClass(node, isStatement, optionalId) {
  10648. const oldInAbstractClass = this.state.inAbstractClass;
  10649. this.state.inAbstractClass = !!node.abstract;
  10650. try {
  10651. return super.parseClass(node, isStatement, optionalId);
  10652. } finally {
  10653. this.state.inAbstractClass = oldInAbstractClass;
  10654. }
  10655. }
  10656. tsParseAbstractDeclaration(node, decorators) {
  10657. if (this.match(80)) {
  10658. node.abstract = true;
  10659. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  10660. } else if (this.isContextual(127)) {
  10661. if (!this.hasFollowingLineBreak()) {
  10662. node.abstract = true;
  10663. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
  10664. at: node
  10665. });
  10666. return this.tsParseInterfaceDeclaration(node);
  10667. }
  10668. } else {
  10669. this.unexpected(null, 80);
  10670. }
  10671. }
  10672. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  10673. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  10674. if (method.abstract) {
  10675. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  10676. if (hasBody) {
  10677. const {
  10678. key
  10679. } = method;
  10680. this.raise(TSErrors.AbstractMethodHasImplementation, {
  10681. at: method,
  10682. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  10683. });
  10684. }
  10685. }
  10686. return method;
  10687. }
  10688. tsParseTypeParameterName() {
  10689. const typeName = this.parseIdentifier();
  10690. return typeName.name;
  10691. }
  10692. shouldParseAsAmbientContext() {
  10693. return !!this.getPluginOption("typescript", "dts");
  10694. }
  10695. parse() {
  10696. if (this.shouldParseAsAmbientContext()) {
  10697. this.state.isAmbientContext = true;
  10698. }
  10699. return super.parse();
  10700. }
  10701. getExpression() {
  10702. if (this.shouldParseAsAmbientContext()) {
  10703. this.state.isAmbientContext = true;
  10704. }
  10705. return super.getExpression();
  10706. }
  10707. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  10708. if (!isString && isMaybeTypeOnly) {
  10709. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  10710. return this.finishNode(node, "ExportSpecifier");
  10711. }
  10712. node.exportKind = "value";
  10713. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10714. }
  10715. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10716. if (!importedIsString && isMaybeTypeOnly) {
  10717. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10718. return this.finishNode(specifier, "ImportSpecifier");
  10719. }
  10720. specifier.importKind = "value";
  10721. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
  10722. }
  10723. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10724. const leftOfAsKey = isImport ? "imported" : "local";
  10725. const rightOfAsKey = isImport ? "local" : "exported";
  10726. let leftOfAs = node[leftOfAsKey];
  10727. let rightOfAs;
  10728. let hasTypeSpecifier = false;
  10729. let canParseAsKeyword = true;
  10730. const loc = leftOfAs.loc.start;
  10731. if (this.isContextual(93)) {
  10732. const firstAs = this.parseIdentifier();
  10733. if (this.isContextual(93)) {
  10734. const secondAs = this.parseIdentifier();
  10735. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10736. hasTypeSpecifier = true;
  10737. leftOfAs = firstAs;
  10738. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10739. canParseAsKeyword = false;
  10740. } else {
  10741. rightOfAs = secondAs;
  10742. canParseAsKeyword = false;
  10743. }
  10744. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10745. canParseAsKeyword = false;
  10746. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10747. } else {
  10748. hasTypeSpecifier = true;
  10749. leftOfAs = firstAs;
  10750. }
  10751. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10752. hasTypeSpecifier = true;
  10753. if (isImport) {
  10754. leftOfAs = this.parseIdentifier(true);
  10755. if (!this.isContextual(93)) {
  10756. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10757. }
  10758. } else {
  10759. leftOfAs = this.parseModuleExportName();
  10760. }
  10761. }
  10762. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10763. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
  10764. at: loc
  10765. });
  10766. }
  10767. node[leftOfAsKey] = leftOfAs;
  10768. node[rightOfAsKey] = rightOfAs;
  10769. const kindKey = isImport ? "importKind" : "exportKind";
  10770. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10771. if (canParseAsKeyword && this.eatContextual(93)) {
  10772. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10773. }
  10774. if (!node[rightOfAsKey]) {
  10775. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  10776. }
  10777. if (isImport) {
  10778. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
  10779. }
  10780. }
  10781. };
  10782. function isPossiblyLiteralEnum(expression) {
  10783. if (expression.type !== "MemberExpression") return false;
  10784. const {
  10785. computed,
  10786. property
  10787. } = expression;
  10788. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10789. return false;
  10790. }
  10791. return isUncomputedMemberExpressionChain(expression.object);
  10792. }
  10793. function isValidAmbientConstInitializer(expression, estree) {
  10794. var _expression$extra;
  10795. const {
  10796. type
  10797. } = expression;
  10798. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10799. return false;
  10800. }
  10801. if (estree) {
  10802. if (type === "Literal") {
  10803. const {
  10804. value
  10805. } = expression;
  10806. if (typeof value === "string" || typeof value === "boolean") {
  10807. return true;
  10808. }
  10809. }
  10810. } else {
  10811. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10812. return true;
  10813. }
  10814. }
  10815. if (isNumber$1(expression, estree) || isNegativeNumber(expression, estree)) {
  10816. return true;
  10817. }
  10818. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10819. return true;
  10820. }
  10821. if (isPossiblyLiteralEnum(expression)) {
  10822. return true;
  10823. }
  10824. return false;
  10825. }
  10826. function isNumber$1(expression, estree) {
  10827. if (estree) {
  10828. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10829. } else {
  10830. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10831. }
  10832. }
  10833. function isNegativeNumber(expression, estree) {
  10834. if (expression.type === "UnaryExpression") {
  10835. const {
  10836. operator,
  10837. argument
  10838. } = expression;
  10839. if (operator === "-" && isNumber$1(argument, estree)) {
  10840. return true;
  10841. }
  10842. }
  10843. return false;
  10844. }
  10845. function isUncomputedMemberExpressionChain(expression) {
  10846. if (expression.type === "Identifier") return true;
  10847. if (expression.type !== "MemberExpression") return false;
  10848. if (expression.computed) return false;
  10849. return isUncomputedMemberExpressionChain(expression.object);
  10850. }
  10851. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10852. ClassNameIsRequired: "A class name is required.",
  10853. UnexpectedSpace: "Unexpected space in placeholder."
  10854. });
  10855. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10856. parsePlaceholder(expectedNode) {
  10857. if (this.match(142)) {
  10858. const node = this.startNode();
  10859. this.next();
  10860. this.assertNoSpace();
  10861. node.name = super.parseIdentifier(true);
  10862. this.assertNoSpace();
  10863. this.expect(142);
  10864. return this.finishPlaceholder(node, expectedNode);
  10865. }
  10866. }
  10867. finishPlaceholder(node, expectedNode) {
  10868. const isFinished = !!(node.expectedNode && node.type === "Placeholder");
  10869. node.expectedNode = expectedNode;
  10870. return isFinished ? node : this.finishNode(node, "Placeholder");
  10871. }
  10872. getTokenFromCode(code) {
  10873. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10874. this.finishOp(142, 2);
  10875. } else {
  10876. super.getTokenFromCode(code);
  10877. }
  10878. }
  10879. parseExprAtom(refExpressionErrors) {
  10880. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10881. }
  10882. parseIdentifier(liberal) {
  10883. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10884. }
  10885. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10886. if (word !== undefined) {
  10887. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10888. }
  10889. }
  10890. parseBindingAtom() {
  10891. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10892. }
  10893. isValidLVal(type, isParenthesized, binding) {
  10894. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10895. }
  10896. toAssignable(node, isLHS) {
  10897. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10898. node.expectedNode = "Pattern";
  10899. } else {
  10900. super.toAssignable(node, isLHS);
  10901. }
  10902. }
  10903. chStartsBindingIdentifier(ch, pos) {
  10904. if (super.chStartsBindingIdentifier(ch, pos)) {
  10905. return true;
  10906. }
  10907. const nextToken = this.lookahead();
  10908. if (nextToken.type === 142) {
  10909. return true;
  10910. }
  10911. return false;
  10912. }
  10913. verifyBreakContinue(node, isBreak) {
  10914. if (node.label && node.label.type === "Placeholder") return;
  10915. super.verifyBreakContinue(node, isBreak);
  10916. }
  10917. parseExpressionStatement(node, expr) {
  10918. if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) {
  10919. return super.parseExpressionStatement(node, expr);
  10920. }
  10921. if (this.match(14)) {
  10922. const stmt = node;
  10923. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10924. this.next();
  10925. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10926. return this.finishNode(stmt, "LabeledStatement");
  10927. }
  10928. this.semicolon();
  10929. node.name = expr.name;
  10930. return this.finishPlaceholder(node, "Statement");
  10931. }
  10932. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10933. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10934. }
  10935. parseFunctionId(requireId) {
  10936. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10937. }
  10938. parseClass(node, isStatement, optionalId) {
  10939. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10940. this.next();
  10941. const oldStrict = this.state.strict;
  10942. const placeholder = this.parsePlaceholder("Identifier");
  10943. if (placeholder) {
  10944. if (this.match(81) || this.match(142) || this.match(5)) {
  10945. node.id = placeholder;
  10946. } else if (optionalId || !isStatement) {
  10947. node.id = null;
  10948. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10949. return this.finishNode(node, type);
  10950. } else {
  10951. throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
  10952. at: this.state.startLoc
  10953. });
  10954. }
  10955. } else {
  10956. this.parseClassId(node, isStatement, optionalId);
  10957. }
  10958. super.parseClassSuper(node);
  10959. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10960. return this.finishNode(node, type);
  10961. }
  10962. parseExport(node, decorators) {
  10963. const placeholder = this.parsePlaceholder("Identifier");
  10964. if (!placeholder) return super.parseExport(node, decorators);
  10965. if (!this.isContextual(97) && !this.match(12)) {
  10966. node.specifiers = [];
  10967. node.source = null;
  10968. node.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10969. return this.finishNode(node, "ExportNamedDeclaration");
  10970. }
  10971. this.expectPlugin("exportDefaultFrom");
  10972. const specifier = this.startNode();
  10973. specifier.exported = placeholder;
  10974. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10975. return super.parseExport(node, decorators);
  10976. }
  10977. isExportDefaultSpecifier() {
  10978. if (this.match(65)) {
  10979. const next = this.nextTokenStart();
  10980. if (this.isUnparsedContextual(next, "from")) {
  10981. if (this.input.startsWith(tokenLabelName(142), this.nextTokenStartSince(next + 4))) {
  10982. return true;
  10983. }
  10984. }
  10985. }
  10986. return super.isExportDefaultSpecifier();
  10987. }
  10988. maybeParseExportDefaultSpecifier(node) {
  10989. if (node.specifiers && node.specifiers.length > 0) {
  10990. return true;
  10991. }
  10992. return super.maybeParseExportDefaultSpecifier(node);
  10993. }
  10994. checkExport(node) {
  10995. const {
  10996. specifiers
  10997. } = node;
  10998. if (specifiers != null && specifiers.length) {
  10999. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  11000. }
  11001. super.checkExport(node);
  11002. node.specifiers = specifiers;
  11003. }
  11004. parseImport(node) {
  11005. const placeholder = this.parsePlaceholder("Identifier");
  11006. if (!placeholder) return super.parseImport(node);
  11007. node.specifiers = [];
  11008. if (!this.isContextual(97) && !this.match(12)) {
  11009. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  11010. this.semicolon();
  11011. return this.finishNode(node, "ImportDeclaration");
  11012. }
  11013. const specifier = this.startNodeAtNode(placeholder);
  11014. specifier.local = placeholder;
  11015. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  11016. if (this.eat(12)) {
  11017. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  11018. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  11019. }
  11020. this.expectContextual(97);
  11021. node.source = this.parseImportSource();
  11022. this.semicolon();
  11023. return this.finishNode(node, "ImportDeclaration");
  11024. }
  11025. parseImportSource() {
  11026. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  11027. }
  11028. assertNoSpace() {
  11029. if (this.state.start > this.state.lastTokEndLoc.index) {
  11030. this.raise(PlaceholderErrors.UnexpectedSpace, {
  11031. at: this.state.lastTokEndLoc
  11032. });
  11033. }
  11034. }
  11035. };
  11036. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  11037. parseV8Intrinsic() {
  11038. if (this.match(54)) {
  11039. const v8IntrinsicStartLoc = this.state.startLoc;
  11040. const node = this.startNode();
  11041. this.next();
  11042. if (tokenIsIdentifier(this.state.type)) {
  11043. const name = this.parseIdentifierName();
  11044. const identifier = this.createIdentifier(node, name);
  11045. identifier.type = "V8IntrinsicIdentifier";
  11046. if (this.match(10)) {
  11047. return identifier;
  11048. }
  11049. }
  11050. this.unexpected(v8IntrinsicStartLoc);
  11051. }
  11052. }
  11053. parseExprAtom(refExpressionErrors) {
  11054. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  11055. }
  11056. };
  11057. function hasPlugin(plugins, expectedConfig) {
  11058. const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
  11059. const expectedKeys = Object.keys(expectedOptions);
  11060. const expectedOptionsIsEmpty = expectedKeys.length === 0;
  11061. return plugins.some(p => {
  11062. if (typeof p === "string") {
  11063. return expectedOptionsIsEmpty && p === expectedName;
  11064. } else {
  11065. const [pluginName, pluginOptions] = p;
  11066. if (pluginName !== expectedName) {
  11067. return false;
  11068. }
  11069. for (const key of expectedKeys) {
  11070. if (pluginOptions[key] !== expectedOptions[key]) {
  11071. return false;
  11072. }
  11073. }
  11074. return true;
  11075. }
  11076. });
  11077. }
  11078. function getPluginOption(plugins, name, option) {
  11079. const plugin = plugins.find(plugin => {
  11080. if (Array.isArray(plugin)) {
  11081. return plugin[0] === name;
  11082. } else {
  11083. return plugin === name;
  11084. }
  11085. });
  11086. if (plugin && Array.isArray(plugin) && plugin.length > 1) {
  11087. return plugin[1][option];
  11088. }
  11089. return null;
  11090. }
  11091. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  11092. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  11093. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  11094. function validatePlugins(plugins) {
  11095. if (hasPlugin(plugins, "decorators")) {
  11096. if (hasPlugin(plugins, "decorators-legacy")) {
  11097. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  11098. }
  11099. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  11100. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  11101. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  11102. }
  11103. const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
  11104. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  11105. throw new Error("'allowCallParenthesized' must be a boolean.");
  11106. }
  11107. }
  11108. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  11109. throw new Error("Cannot combine flow and typescript plugins.");
  11110. }
  11111. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  11112. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  11113. }
  11114. if (hasPlugin(plugins, "pipelineOperator")) {
  11115. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  11116. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  11117. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  11118. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  11119. }
  11120. const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
  11121. syntaxType: "hash"
  11122. }]);
  11123. if (proposal === "hack") {
  11124. if (hasPlugin(plugins, "placeholders")) {
  11125. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  11126. }
  11127. if (hasPlugin(plugins, "v8intrinsic")) {
  11128. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  11129. }
  11130. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  11131. if (!TOPIC_TOKENS.includes(topicToken)) {
  11132. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  11133. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  11134. }
  11135. if (topicToken === "#" && tupleSyntaxIsHash) {
  11136. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  11137. }
  11138. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  11139. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  11140. }
  11141. }
  11142. if (hasPlugin(plugins, "moduleAttributes")) {
  11143. {
  11144. if (hasPlugin(plugins, "importAssertions")) {
  11145. throw new Error("Cannot combine importAssertions and moduleAttributes plugins.");
  11146. }
  11147. const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  11148. if (moduleAttributesVersionPluginOption !== "may-2020") {
  11149. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  11150. }
  11151. }
  11152. }
  11153. if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  11154. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  11155. }
  11156. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  11157. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  11158. error.missingPlugins = "doExpressions";
  11159. throw error;
  11160. }
  11161. }
  11162. const mixinPlugins = {
  11163. estree,
  11164. jsx,
  11165. flow,
  11166. typescript,
  11167. v8intrinsic,
  11168. placeholders
  11169. };
  11170. const mixinPluginNames = Object.keys(mixinPlugins);
  11171. class ExpressionParser extends LValParser {
  11172. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  11173. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  11174. return;
  11175. }
  11176. const key = prop.key;
  11177. const name = key.type === "Identifier" ? key.name : key.value;
  11178. if (name === "__proto__") {
  11179. if (isRecord) {
  11180. this.raise(Errors.RecordNoProto, {
  11181. at: key
  11182. });
  11183. return;
  11184. }
  11185. if (protoRef.used) {
  11186. if (refExpressionErrors) {
  11187. if (refExpressionErrors.doubleProtoLoc === null) {
  11188. refExpressionErrors.doubleProtoLoc = key.loc.start;
  11189. }
  11190. } else {
  11191. this.raise(Errors.DuplicateProto, {
  11192. at: key
  11193. });
  11194. }
  11195. }
  11196. protoRef.used = true;
  11197. }
  11198. }
  11199. shouldExitDescending(expr, potentialArrowAt) {
  11200. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  11201. }
  11202. getExpression() {
  11203. this.enterInitialScopes();
  11204. this.nextToken();
  11205. const expr = this.parseExpression();
  11206. if (!this.match(137)) {
  11207. this.unexpected();
  11208. }
  11209. this.finalizeRemainingComments();
  11210. expr.comments = this.state.comments;
  11211. expr.errors = this.state.errors;
  11212. if (this.options.tokens) {
  11213. expr.tokens = this.tokens;
  11214. }
  11215. return expr;
  11216. }
  11217. parseExpression(disallowIn, refExpressionErrors) {
  11218. if (disallowIn) {
  11219. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  11220. }
  11221. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  11222. }
  11223. parseExpressionBase(refExpressionErrors) {
  11224. const startLoc = this.state.startLoc;
  11225. const expr = this.parseMaybeAssign(refExpressionErrors);
  11226. if (this.match(12)) {
  11227. const node = this.startNodeAt(startLoc);
  11228. node.expressions = [expr];
  11229. while (this.eat(12)) {
  11230. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  11231. }
  11232. this.toReferencedList(node.expressions);
  11233. return this.finishNode(node, "SequenceExpression");
  11234. }
  11235. return expr;
  11236. }
  11237. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  11238. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  11239. }
  11240. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  11241. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  11242. }
  11243. setOptionalParametersError(refExpressionErrors, resultError) {
  11244. var _resultError$loc;
  11245. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  11246. }
  11247. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  11248. const startLoc = this.state.startLoc;
  11249. if (this.isContextual(106)) {
  11250. if (this.prodParam.hasYield) {
  11251. let left = this.parseYield();
  11252. if (afterLeftParse) {
  11253. left = afterLeftParse.call(this, left, startLoc);
  11254. }
  11255. return left;
  11256. }
  11257. }
  11258. let ownExpressionErrors;
  11259. if (refExpressionErrors) {
  11260. ownExpressionErrors = false;
  11261. } else {
  11262. refExpressionErrors = new ExpressionErrors();
  11263. ownExpressionErrors = true;
  11264. }
  11265. const {
  11266. type
  11267. } = this.state;
  11268. if (type === 10 || tokenIsIdentifier(type)) {
  11269. this.state.potentialArrowAt = this.state.start;
  11270. }
  11271. let left = this.parseMaybeConditional(refExpressionErrors);
  11272. if (afterLeftParse) {
  11273. left = afterLeftParse.call(this, left, startLoc);
  11274. }
  11275. if (tokenIsAssignment(this.state.type)) {
  11276. const node = this.startNodeAt(startLoc);
  11277. const operator = this.state.value;
  11278. node.operator = operator;
  11279. if (this.match(29)) {
  11280. this.toAssignable(left, true);
  11281. node.left = left;
  11282. const startIndex = startLoc.index;
  11283. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  11284. refExpressionErrors.doubleProtoLoc = null;
  11285. }
  11286. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  11287. refExpressionErrors.shorthandAssignLoc = null;
  11288. }
  11289. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  11290. this.checkDestructuringPrivate(refExpressionErrors);
  11291. refExpressionErrors.privateKeyLoc = null;
  11292. }
  11293. } else {
  11294. node.left = left;
  11295. }
  11296. this.next();
  11297. node.right = this.parseMaybeAssign();
  11298. this.checkLVal(left, {
  11299. in: this.finishNode(node, "AssignmentExpression")
  11300. });
  11301. return node;
  11302. } else if (ownExpressionErrors) {
  11303. this.checkExpressionErrors(refExpressionErrors, true);
  11304. }
  11305. return left;
  11306. }
  11307. parseMaybeConditional(refExpressionErrors) {
  11308. const startLoc = this.state.startLoc;
  11309. const potentialArrowAt = this.state.potentialArrowAt;
  11310. const expr = this.parseExprOps(refExpressionErrors);
  11311. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11312. return expr;
  11313. }
  11314. return this.parseConditional(expr, startLoc, refExpressionErrors);
  11315. }
  11316. parseConditional(expr, startLoc, refExpressionErrors) {
  11317. if (this.eat(17)) {
  11318. const node = this.startNodeAt(startLoc);
  11319. node.test = expr;
  11320. node.consequent = this.parseMaybeAssignAllowIn();
  11321. this.expect(14);
  11322. node.alternate = this.parseMaybeAssign();
  11323. return this.finishNode(node, "ConditionalExpression");
  11324. }
  11325. return expr;
  11326. }
  11327. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  11328. return this.match(136) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  11329. }
  11330. parseExprOps(refExpressionErrors) {
  11331. const startLoc = this.state.startLoc;
  11332. const potentialArrowAt = this.state.potentialArrowAt;
  11333. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  11334. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11335. return expr;
  11336. }
  11337. return this.parseExprOp(expr, startLoc, -1);
  11338. }
  11339. parseExprOp(left, leftStartLoc, minPrec) {
  11340. if (this.isPrivateName(left)) {
  11341. const value = this.getPrivateNameSV(left);
  11342. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  11343. this.raise(Errors.PrivateInExpectedIn, {
  11344. at: left,
  11345. identifierName: value
  11346. });
  11347. }
  11348. this.classScope.usePrivateName(value, left.loc.start);
  11349. }
  11350. const op = this.state.type;
  11351. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  11352. let prec = tokenOperatorPrecedence(op);
  11353. if (prec > minPrec) {
  11354. if (op === 39) {
  11355. this.expectPlugin("pipelineOperator");
  11356. if (this.state.inFSharpPipelineDirectBody) {
  11357. return left;
  11358. }
  11359. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  11360. }
  11361. const node = this.startNodeAt(leftStartLoc);
  11362. node.left = left;
  11363. node.operator = this.state.value;
  11364. const logical = op === 41 || op === 42;
  11365. const coalesce = op === 40;
  11366. if (coalesce) {
  11367. prec = tokenOperatorPrecedence(42);
  11368. }
  11369. this.next();
  11370. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  11371. proposal: "minimal"
  11372. }])) {
  11373. if (this.state.type === 96 && this.prodParam.hasAwait) {
  11374. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, {
  11375. at: this.state.startLoc
  11376. });
  11377. }
  11378. }
  11379. node.right = this.parseExprOpRightExpr(op, prec);
  11380. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  11381. const nextOp = this.state.type;
  11382. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  11383. throw this.raise(Errors.MixingCoalesceWithLogical, {
  11384. at: this.state.startLoc
  11385. });
  11386. }
  11387. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  11388. }
  11389. }
  11390. return left;
  11391. }
  11392. parseExprOpRightExpr(op, prec) {
  11393. const startLoc = this.state.startLoc;
  11394. switch (op) {
  11395. case 39:
  11396. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  11397. case "hack":
  11398. return this.withTopicBindingContext(() => {
  11399. return this.parseHackPipeBody();
  11400. });
  11401. case "smart":
  11402. return this.withTopicBindingContext(() => {
  11403. if (this.prodParam.hasYield && this.isContextual(106)) {
  11404. throw this.raise(Errors.PipeBodyIsTighter, {
  11405. at: this.state.startLoc
  11406. });
  11407. }
  11408. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  11409. });
  11410. case "fsharp":
  11411. return this.withSoloAwaitPermittingContext(() => {
  11412. return this.parseFSharpPipelineBody(prec);
  11413. });
  11414. }
  11415. default:
  11416. return this.parseExprOpBaseRightExpr(op, prec);
  11417. }
  11418. }
  11419. parseExprOpBaseRightExpr(op, prec) {
  11420. const startLoc = this.state.startLoc;
  11421. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  11422. }
  11423. parseHackPipeBody() {
  11424. var _body$extra;
  11425. const {
  11426. startLoc
  11427. } = this.state;
  11428. const body = this.parseMaybeAssign();
  11429. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  11430. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  11431. this.raise(Errors.PipeUnparenthesizedBody, {
  11432. at: startLoc,
  11433. type: body.type
  11434. });
  11435. }
  11436. if (!this.topicReferenceWasUsedInCurrentContext()) {
  11437. this.raise(Errors.PipeTopicUnused, {
  11438. at: startLoc
  11439. });
  11440. }
  11441. return body;
  11442. }
  11443. checkExponentialAfterUnary(node) {
  11444. if (this.match(57)) {
  11445. this.raise(Errors.UnexpectedTokenUnaryExponentiation, {
  11446. at: node.argument
  11447. });
  11448. }
  11449. }
  11450. parseMaybeUnary(refExpressionErrors, sawUnary) {
  11451. const startLoc = this.state.startLoc;
  11452. const isAwait = this.isContextual(96);
  11453. if (isAwait && this.isAwaitAllowed()) {
  11454. this.next();
  11455. const expr = this.parseAwait(startLoc);
  11456. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  11457. return expr;
  11458. }
  11459. const update = this.match(34);
  11460. const node = this.startNode();
  11461. if (tokenIsPrefix(this.state.type)) {
  11462. node.operator = this.state.value;
  11463. node.prefix = true;
  11464. if (this.match(72)) {
  11465. this.expectPlugin("throwExpressions");
  11466. }
  11467. const isDelete = this.match(89);
  11468. this.next();
  11469. node.argument = this.parseMaybeUnary(null, true);
  11470. this.checkExpressionErrors(refExpressionErrors, true);
  11471. if (this.state.strict && isDelete) {
  11472. const arg = node.argument;
  11473. if (arg.type === "Identifier") {
  11474. this.raise(Errors.StrictDelete, {
  11475. at: node
  11476. });
  11477. } else if (this.hasPropertyAsPrivateName(arg)) {
  11478. this.raise(Errors.DeletePrivateField, {
  11479. at: node
  11480. });
  11481. }
  11482. }
  11483. if (!update) {
  11484. if (!sawUnary) {
  11485. this.checkExponentialAfterUnary(node);
  11486. }
  11487. return this.finishNode(node, "UnaryExpression");
  11488. }
  11489. }
  11490. const expr = this.parseUpdate(node, update, refExpressionErrors);
  11491. if (isAwait) {
  11492. const {
  11493. type
  11494. } = this.state;
  11495. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  11496. if (startsExpr && !this.isAmbiguousAwait()) {
  11497. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, {
  11498. at: startLoc
  11499. });
  11500. return this.parseAwait(startLoc);
  11501. }
  11502. }
  11503. return expr;
  11504. }
  11505. parseUpdate(node, update, refExpressionErrors) {
  11506. if (update) {
  11507. const updateExpressionNode = node;
  11508. this.checkLVal(updateExpressionNode.argument, {
  11509. in: this.finishNode(updateExpressionNode, "UpdateExpression")
  11510. });
  11511. return node;
  11512. }
  11513. const startLoc = this.state.startLoc;
  11514. let expr = this.parseExprSubscripts(refExpressionErrors);
  11515. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  11516. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  11517. const node = this.startNodeAt(startLoc);
  11518. node.operator = this.state.value;
  11519. node.prefix = false;
  11520. node.argument = expr;
  11521. this.next();
  11522. this.checkLVal(expr, {
  11523. in: expr = this.finishNode(node, "UpdateExpression")
  11524. });
  11525. }
  11526. return expr;
  11527. }
  11528. parseExprSubscripts(refExpressionErrors) {
  11529. const startLoc = this.state.startLoc;
  11530. const potentialArrowAt = this.state.potentialArrowAt;
  11531. const expr = this.parseExprAtom(refExpressionErrors);
  11532. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11533. return expr;
  11534. }
  11535. return this.parseSubscripts(expr, startLoc);
  11536. }
  11537. parseSubscripts(base, startLoc, noCalls) {
  11538. const state = {
  11539. optionalChainMember: false,
  11540. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  11541. stop: false
  11542. };
  11543. do {
  11544. base = this.parseSubscript(base, startLoc, noCalls, state);
  11545. state.maybeAsyncArrow = false;
  11546. } while (!state.stop);
  11547. return base;
  11548. }
  11549. parseSubscript(base, startLoc, noCalls, state) {
  11550. const {
  11551. type
  11552. } = this.state;
  11553. if (!noCalls && type === 15) {
  11554. return this.parseBind(base, startLoc, noCalls, state);
  11555. } else if (tokenIsTemplate(type)) {
  11556. return this.parseTaggedTemplateExpression(base, startLoc, state);
  11557. }
  11558. let optional = false;
  11559. if (type === 18) {
  11560. if (noCalls) {
  11561. this.raise(Errors.OptionalChainingNoNew, {
  11562. at: this.state.startLoc
  11563. });
  11564. if (this.lookaheadCharCode() === 40) {
  11565. state.stop = true;
  11566. return base;
  11567. }
  11568. }
  11569. state.optionalChainMember = optional = true;
  11570. this.next();
  11571. }
  11572. if (!noCalls && this.match(10)) {
  11573. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  11574. } else {
  11575. const computed = this.eat(0);
  11576. if (computed || optional || this.eat(16)) {
  11577. return this.parseMember(base, startLoc, state, computed, optional);
  11578. } else {
  11579. state.stop = true;
  11580. return base;
  11581. }
  11582. }
  11583. }
  11584. parseMember(base, startLoc, state, computed, optional) {
  11585. const node = this.startNodeAt(startLoc);
  11586. node.object = base;
  11587. node.computed = computed;
  11588. if (computed) {
  11589. node.property = this.parseExpression();
  11590. this.expect(3);
  11591. } else if (this.match(136)) {
  11592. if (base.type === "Super") {
  11593. this.raise(Errors.SuperPrivateField, {
  11594. at: startLoc
  11595. });
  11596. }
  11597. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  11598. node.property = this.parsePrivateName();
  11599. } else {
  11600. node.property = this.parseIdentifier(true);
  11601. }
  11602. if (state.optionalChainMember) {
  11603. node.optional = optional;
  11604. return this.finishNode(node, "OptionalMemberExpression");
  11605. } else {
  11606. return this.finishNode(node, "MemberExpression");
  11607. }
  11608. }
  11609. parseBind(base, startLoc, noCalls, state) {
  11610. const node = this.startNodeAt(startLoc);
  11611. node.object = base;
  11612. this.next();
  11613. node.callee = this.parseNoCallExpr();
  11614. state.stop = true;
  11615. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  11616. }
  11617. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  11618. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11619. let refExpressionErrors = null;
  11620. this.state.maybeInArrowParameters = true;
  11621. this.next();
  11622. const node = this.startNodeAt(startLoc);
  11623. node.callee = base;
  11624. const {
  11625. maybeAsyncArrow,
  11626. optionalChainMember
  11627. } = state;
  11628. if (maybeAsyncArrow) {
  11629. this.expressionScope.enter(newAsyncArrowScope());
  11630. refExpressionErrors = new ExpressionErrors();
  11631. }
  11632. if (optionalChainMember) {
  11633. node.optional = optional;
  11634. }
  11635. if (optional) {
  11636. node.arguments = this.parseCallExpressionArguments(11);
  11637. } else {
  11638. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
  11639. }
  11640. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  11641. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  11642. state.stop = true;
  11643. this.checkDestructuringPrivate(refExpressionErrors);
  11644. this.expressionScope.validateAsPattern();
  11645. this.expressionScope.exit();
  11646. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  11647. } else {
  11648. if (maybeAsyncArrow) {
  11649. this.checkExpressionErrors(refExpressionErrors, true);
  11650. this.expressionScope.exit();
  11651. }
  11652. this.toReferencedArguments(finishedNode);
  11653. }
  11654. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11655. return finishedNode;
  11656. }
  11657. toReferencedArguments(node, isParenthesizedExpr) {
  11658. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  11659. }
  11660. parseTaggedTemplateExpression(base, startLoc, state) {
  11661. const node = this.startNodeAt(startLoc);
  11662. node.tag = base;
  11663. node.quasi = this.parseTemplate(true);
  11664. if (state.optionalChainMember) {
  11665. this.raise(Errors.OptionalChainingNoTemplate, {
  11666. at: startLoc
  11667. });
  11668. }
  11669. return this.finishNode(node, "TaggedTemplateExpression");
  11670. }
  11671. atPossibleAsyncArrow(base) {
  11672. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && base.start === this.state.potentialArrowAt;
  11673. }
  11674. finishCallExpression(node, optional) {
  11675. if (node.callee.type === "Import") {
  11676. if (node.arguments.length === 2) {
  11677. {
  11678. if (!this.hasPlugin("moduleAttributes")) {
  11679. this.expectPlugin("importAssertions");
  11680. }
  11681. }
  11682. }
  11683. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11684. this.raise(Errors.ImportCallArity, {
  11685. at: node,
  11686. maxArgumentCount: this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
  11687. });
  11688. } else {
  11689. for (const arg of node.arguments) {
  11690. if (arg.type === "SpreadElement") {
  11691. this.raise(Errors.ImportCallSpreadArgument, {
  11692. at: arg
  11693. });
  11694. }
  11695. }
  11696. }
  11697. }
  11698. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11699. }
  11700. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11701. const elts = [];
  11702. let first = true;
  11703. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11704. this.state.inFSharpPipelineDirectBody = false;
  11705. while (!this.eat(close)) {
  11706. if (first) {
  11707. first = false;
  11708. } else {
  11709. this.expect(12);
  11710. if (this.match(close)) {
  11711. if (dynamicImport && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  11712. this.raise(Errors.ImportCallArgumentTrailingComma, {
  11713. at: this.state.lastTokStartLoc
  11714. });
  11715. }
  11716. if (nodeForExtra) {
  11717. this.addTrailingCommaExtraToNode(nodeForExtra);
  11718. }
  11719. this.next();
  11720. break;
  11721. }
  11722. }
  11723. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  11724. }
  11725. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11726. return elts;
  11727. }
  11728. shouldParseAsyncArrow() {
  11729. return this.match(19) && !this.canInsertSemicolon();
  11730. }
  11731. parseAsyncArrowFromCallExpression(node, call) {
  11732. var _call$extra;
  11733. this.resetPreviousNodeTrailingComments(call);
  11734. this.expect(19);
  11735. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11736. if (call.innerComments) {
  11737. setInnerComments(node, call.innerComments);
  11738. }
  11739. if (call.callee.trailingComments) {
  11740. setInnerComments(node, call.callee.trailingComments);
  11741. }
  11742. return node;
  11743. }
  11744. parseNoCallExpr() {
  11745. const startLoc = this.state.startLoc;
  11746. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11747. }
  11748. parseExprAtom(refExpressionErrors) {
  11749. let node;
  11750. let decorators = null;
  11751. const {
  11752. type
  11753. } = this.state;
  11754. switch (type) {
  11755. case 79:
  11756. return this.parseSuper();
  11757. case 83:
  11758. node = this.startNode();
  11759. this.next();
  11760. if (this.match(16)) {
  11761. return this.parseImportMetaProperty(node);
  11762. }
  11763. if (!this.match(10)) {
  11764. this.raise(Errors.UnsupportedImport, {
  11765. at: this.state.lastTokStartLoc
  11766. });
  11767. }
  11768. return this.finishNode(node, "Import");
  11769. case 78:
  11770. node = this.startNode();
  11771. this.next();
  11772. return this.finishNode(node, "ThisExpression");
  11773. case 90:
  11774. {
  11775. return this.parseDo(this.startNode(), false);
  11776. }
  11777. case 56:
  11778. case 31:
  11779. {
  11780. this.readRegexp();
  11781. return this.parseRegExpLiteral(this.state.value);
  11782. }
  11783. case 132:
  11784. return this.parseNumericLiteral(this.state.value);
  11785. case 133:
  11786. return this.parseBigIntLiteral(this.state.value);
  11787. case 134:
  11788. return this.parseDecimalLiteral(this.state.value);
  11789. case 131:
  11790. return this.parseStringLiteral(this.state.value);
  11791. case 84:
  11792. return this.parseNullLiteral();
  11793. case 85:
  11794. return this.parseBooleanLiteral(true);
  11795. case 86:
  11796. return this.parseBooleanLiteral(false);
  11797. case 10:
  11798. {
  11799. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11800. return this.parseParenAndDistinguishExpression(canBeArrow);
  11801. }
  11802. case 2:
  11803. case 1:
  11804. {
  11805. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11806. }
  11807. case 0:
  11808. {
  11809. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11810. }
  11811. case 6:
  11812. case 7:
  11813. {
  11814. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11815. }
  11816. case 5:
  11817. {
  11818. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11819. }
  11820. case 68:
  11821. return this.parseFunctionOrFunctionSent();
  11822. case 26:
  11823. decorators = this.parseDecorators();
  11824. case 80:
  11825. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11826. case 77:
  11827. return this.parseNewOrNewTarget();
  11828. case 25:
  11829. case 24:
  11830. return this.parseTemplate(false);
  11831. case 15:
  11832. {
  11833. node = this.startNode();
  11834. this.next();
  11835. node.object = null;
  11836. const callee = node.callee = this.parseNoCallExpr();
  11837. if (callee.type === "MemberExpression") {
  11838. return this.finishNode(node, "BindExpression");
  11839. } else {
  11840. throw this.raise(Errors.UnsupportedBind, {
  11841. at: callee
  11842. });
  11843. }
  11844. }
  11845. case 136:
  11846. {
  11847. this.raise(Errors.PrivateInExpectedIn, {
  11848. at: this.state.startLoc,
  11849. identifierName: this.state.value
  11850. });
  11851. return this.parsePrivateName();
  11852. }
  11853. case 33:
  11854. {
  11855. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11856. }
  11857. case 32:
  11858. {
  11859. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11860. }
  11861. case 37:
  11862. case 38:
  11863. {
  11864. return this.parseTopicReference("hack");
  11865. }
  11866. case 44:
  11867. case 54:
  11868. case 27:
  11869. {
  11870. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11871. if (pipeProposal) {
  11872. return this.parseTopicReference(pipeProposal);
  11873. }
  11874. this.unexpected();
  11875. break;
  11876. }
  11877. case 47:
  11878. {
  11879. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11880. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11881. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11882. } else {
  11883. this.unexpected();
  11884. }
  11885. break;
  11886. }
  11887. default:
  11888. if (tokenIsIdentifier(type)) {
  11889. if (this.isContextual(125) && this.lookaheadCharCode() === 123 && !this.hasFollowingLineBreak()) {
  11890. return this.parseModuleExpression();
  11891. }
  11892. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11893. const containsEsc = this.state.containsEsc;
  11894. const id = this.parseIdentifier();
  11895. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11896. const {
  11897. type
  11898. } = this.state;
  11899. if (type === 68) {
  11900. this.resetPreviousNodeTrailingComments(id);
  11901. this.next();
  11902. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11903. } else if (tokenIsIdentifier(type)) {
  11904. if (this.lookaheadCharCode() === 61) {
  11905. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11906. } else {
  11907. return id;
  11908. }
  11909. } else if (type === 90) {
  11910. this.resetPreviousNodeTrailingComments(id);
  11911. return this.parseDo(this.startNodeAtNode(id), true);
  11912. }
  11913. }
  11914. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11915. this.next();
  11916. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11917. }
  11918. return id;
  11919. } else {
  11920. this.unexpected();
  11921. }
  11922. }
  11923. }
  11924. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11925. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11926. if (pipeProposal) {
  11927. this.state.type = topicTokenType;
  11928. this.state.value = topicTokenValue;
  11929. this.state.pos--;
  11930. this.state.end--;
  11931. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11932. return this.parseTopicReference(pipeProposal);
  11933. } else {
  11934. this.unexpected();
  11935. }
  11936. }
  11937. parseTopicReference(pipeProposal) {
  11938. const node = this.startNode();
  11939. const startLoc = this.state.startLoc;
  11940. const tokenType = this.state.type;
  11941. this.next();
  11942. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11943. }
  11944. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11945. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11946. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  11947. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11948. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, {
  11949. at: startLoc
  11950. });
  11951. }
  11952. this.registerTopicReference();
  11953. return this.finishNode(node, nodeType);
  11954. } else {
  11955. throw this.raise(Errors.PipeTopicUnconfiguredToken, {
  11956. at: startLoc,
  11957. token: tokenLabelName(tokenType)
  11958. });
  11959. }
  11960. }
  11961. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11962. switch (pipeProposal) {
  11963. case "hack":
  11964. {
  11965. return this.hasPlugin(["pipelineOperator", {
  11966. topicToken: tokenLabelName(tokenType)
  11967. }]);
  11968. }
  11969. case "smart":
  11970. return tokenType === 27;
  11971. default:
  11972. throw this.raise(Errors.PipeTopicRequiresHackPipes, {
  11973. at: startLoc
  11974. });
  11975. }
  11976. }
  11977. parseAsyncArrowUnaryFunction(node) {
  11978. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11979. const params = [this.parseIdentifier()];
  11980. this.prodParam.exit();
  11981. if (this.hasPrecedingLineBreak()) {
  11982. this.raise(Errors.LineTerminatorBeforeArrow, {
  11983. at: this.state.curPosition()
  11984. });
  11985. }
  11986. this.expect(19);
  11987. return this.parseArrowExpression(node, params, true);
  11988. }
  11989. parseDo(node, isAsync) {
  11990. this.expectPlugin("doExpressions");
  11991. if (isAsync) {
  11992. this.expectPlugin("asyncDoExpressions");
  11993. }
  11994. node.async = isAsync;
  11995. this.next();
  11996. const oldLabels = this.state.labels;
  11997. this.state.labels = [];
  11998. if (isAsync) {
  11999. this.prodParam.enter(PARAM_AWAIT);
  12000. node.body = this.parseBlock();
  12001. this.prodParam.exit();
  12002. } else {
  12003. node.body = this.parseBlock();
  12004. }
  12005. this.state.labels = oldLabels;
  12006. return this.finishNode(node, "DoExpression");
  12007. }
  12008. parseSuper() {
  12009. const node = this.startNode();
  12010. this.next();
  12011. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  12012. this.raise(Errors.SuperNotAllowed, {
  12013. at: node
  12014. });
  12015. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  12016. this.raise(Errors.UnexpectedSuper, {
  12017. at: node
  12018. });
  12019. }
  12020. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  12021. this.raise(Errors.UnsupportedSuper, {
  12022. at: node
  12023. });
  12024. }
  12025. return this.finishNode(node, "Super");
  12026. }
  12027. parsePrivateName() {
  12028. const node = this.startNode();
  12029. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  12030. const name = this.state.value;
  12031. this.next();
  12032. node.id = this.createIdentifier(id, name);
  12033. return this.finishNode(node, "PrivateName");
  12034. }
  12035. parseFunctionOrFunctionSent() {
  12036. const node = this.startNode();
  12037. this.next();
  12038. if (this.prodParam.hasYield && this.match(16)) {
  12039. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  12040. this.next();
  12041. if (this.match(102)) {
  12042. this.expectPlugin("functionSent");
  12043. } else if (!this.hasPlugin("functionSent")) {
  12044. this.unexpected();
  12045. }
  12046. return this.parseMetaProperty(node, meta, "sent");
  12047. }
  12048. return this.parseFunction(node);
  12049. }
  12050. parseMetaProperty(node, meta, propertyName) {
  12051. node.meta = meta;
  12052. const containsEsc = this.state.containsEsc;
  12053. node.property = this.parseIdentifier(true);
  12054. if (node.property.name !== propertyName || containsEsc) {
  12055. this.raise(Errors.UnsupportedMetaProperty, {
  12056. at: node.property,
  12057. target: meta.name,
  12058. onlyValidPropertyName: propertyName
  12059. });
  12060. }
  12061. return this.finishNode(node, "MetaProperty");
  12062. }
  12063. parseImportMetaProperty(node) {
  12064. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  12065. this.next();
  12066. if (this.isContextual(100)) {
  12067. if (!this.inModule) {
  12068. this.raise(Errors.ImportMetaOutsideModule, {
  12069. at: id
  12070. });
  12071. }
  12072. this.sawUnambiguousESM = true;
  12073. }
  12074. return this.parseMetaProperty(node, id, "meta");
  12075. }
  12076. parseLiteralAtNode(value, type, node) {
  12077. this.addExtra(node, "rawValue", value);
  12078. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  12079. node.value = value;
  12080. this.next();
  12081. return this.finishNode(node, type);
  12082. }
  12083. parseLiteral(value, type) {
  12084. const node = this.startNode();
  12085. return this.parseLiteralAtNode(value, type, node);
  12086. }
  12087. parseStringLiteral(value) {
  12088. return this.parseLiteral(value, "StringLiteral");
  12089. }
  12090. parseNumericLiteral(value) {
  12091. return this.parseLiteral(value, "NumericLiteral");
  12092. }
  12093. parseBigIntLiteral(value) {
  12094. return this.parseLiteral(value, "BigIntLiteral");
  12095. }
  12096. parseDecimalLiteral(value) {
  12097. return this.parseLiteral(value, "DecimalLiteral");
  12098. }
  12099. parseRegExpLiteral(value) {
  12100. const node = this.parseLiteral(value.value, "RegExpLiteral");
  12101. node.pattern = value.pattern;
  12102. node.flags = value.flags;
  12103. return node;
  12104. }
  12105. parseBooleanLiteral(value) {
  12106. const node = this.startNode();
  12107. node.value = value;
  12108. this.next();
  12109. return this.finishNode(node, "BooleanLiteral");
  12110. }
  12111. parseNullLiteral() {
  12112. const node = this.startNode();
  12113. this.next();
  12114. return this.finishNode(node, "NullLiteral");
  12115. }
  12116. parseParenAndDistinguishExpression(canBeArrow) {
  12117. const startLoc = this.state.startLoc;
  12118. let val;
  12119. this.next();
  12120. this.expressionScope.enter(newArrowHeadScope());
  12121. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12122. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12123. this.state.maybeInArrowParameters = true;
  12124. this.state.inFSharpPipelineDirectBody = false;
  12125. const innerStartLoc = this.state.startLoc;
  12126. const exprList = [];
  12127. const refExpressionErrors = new ExpressionErrors();
  12128. let first = true;
  12129. let spreadStartLoc;
  12130. let optionalCommaStartLoc;
  12131. while (!this.match(11)) {
  12132. if (first) {
  12133. first = false;
  12134. } else {
  12135. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  12136. if (this.match(11)) {
  12137. optionalCommaStartLoc = this.state.startLoc;
  12138. break;
  12139. }
  12140. }
  12141. if (this.match(21)) {
  12142. const spreadNodeStartLoc = this.state.startLoc;
  12143. spreadStartLoc = this.state.startLoc;
  12144. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  12145. if (!this.checkCommaAfterRest(41)) {
  12146. break;
  12147. }
  12148. } else {
  12149. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  12150. }
  12151. }
  12152. const innerEndLoc = this.state.lastTokEndLoc;
  12153. this.expect(11);
  12154. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12155. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12156. let arrowNode = this.startNodeAt(startLoc);
  12157. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  12158. this.checkDestructuringPrivate(refExpressionErrors);
  12159. this.expressionScope.validateAsPattern();
  12160. this.expressionScope.exit();
  12161. this.parseArrowExpression(arrowNode, exprList, false);
  12162. return arrowNode;
  12163. }
  12164. this.expressionScope.exit();
  12165. if (!exprList.length) {
  12166. this.unexpected(this.state.lastTokStartLoc);
  12167. }
  12168. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  12169. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  12170. this.checkExpressionErrors(refExpressionErrors, true);
  12171. this.toReferencedListDeep(exprList, true);
  12172. if (exprList.length > 1) {
  12173. val = this.startNodeAt(innerStartLoc);
  12174. val.expressions = exprList;
  12175. this.finishNode(val, "SequenceExpression");
  12176. this.resetEndLocation(val, innerEndLoc);
  12177. } else {
  12178. val = exprList[0];
  12179. }
  12180. return this.wrapParenthesis(startLoc, val);
  12181. }
  12182. wrapParenthesis(startLoc, expression) {
  12183. if (!this.options.createParenthesizedExpressions) {
  12184. this.addExtra(expression, "parenthesized", true);
  12185. this.addExtra(expression, "parenStart", startLoc.index);
  12186. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  12187. return expression;
  12188. }
  12189. const parenExpression = this.startNodeAt(startLoc);
  12190. parenExpression.expression = expression;
  12191. return this.finishNode(parenExpression, "ParenthesizedExpression");
  12192. }
  12193. shouldParseArrow(params) {
  12194. return !this.canInsertSemicolon();
  12195. }
  12196. parseArrow(node) {
  12197. if (this.eat(19)) {
  12198. return node;
  12199. }
  12200. }
  12201. parseParenItem(node, startLoc) {
  12202. return node;
  12203. }
  12204. parseNewOrNewTarget() {
  12205. const node = this.startNode();
  12206. this.next();
  12207. if (this.match(16)) {
  12208. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  12209. this.next();
  12210. const metaProp = this.parseMetaProperty(node, meta, "target");
  12211. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
  12212. this.raise(Errors.UnexpectedNewTarget, {
  12213. at: metaProp
  12214. });
  12215. }
  12216. return metaProp;
  12217. }
  12218. return this.parseNew(node);
  12219. }
  12220. parseNew(node) {
  12221. this.parseNewCallee(node);
  12222. if (this.eat(10)) {
  12223. const args = this.parseExprList(11);
  12224. this.toReferencedList(args);
  12225. node.arguments = args;
  12226. } else {
  12227. node.arguments = [];
  12228. }
  12229. return this.finishNode(node, "NewExpression");
  12230. }
  12231. parseNewCallee(node) {
  12232. node.callee = this.parseNoCallExpr();
  12233. if (node.callee.type === "Import") {
  12234. this.raise(Errors.ImportCallNotNewExpression, {
  12235. at: node.callee
  12236. });
  12237. }
  12238. }
  12239. parseTemplateElement(isTagged) {
  12240. const {
  12241. start,
  12242. startLoc,
  12243. end,
  12244. value
  12245. } = this.state;
  12246. const elemStart = start + 1;
  12247. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  12248. if (value === null) {
  12249. if (!isTagged) {
  12250. this.raise(Errors.InvalidEscapeSequenceTemplate, {
  12251. at: createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1)
  12252. });
  12253. }
  12254. }
  12255. const isTail = this.match(24);
  12256. const endOffset = isTail ? -1 : -2;
  12257. const elemEnd = end + endOffset;
  12258. elem.value = {
  12259. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  12260. cooked: value === null ? null : value.slice(1, endOffset)
  12261. };
  12262. elem.tail = isTail;
  12263. this.next();
  12264. const finishedNode = this.finishNode(elem, "TemplateElement");
  12265. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  12266. return finishedNode;
  12267. }
  12268. parseTemplate(isTagged) {
  12269. const node = this.startNode();
  12270. node.expressions = [];
  12271. let curElt = this.parseTemplateElement(isTagged);
  12272. node.quasis = [curElt];
  12273. while (!curElt.tail) {
  12274. node.expressions.push(this.parseTemplateSubstitution());
  12275. this.readTemplateContinuation();
  12276. node.quasis.push(curElt = this.parseTemplateElement(isTagged));
  12277. }
  12278. return this.finishNode(node, "TemplateLiteral");
  12279. }
  12280. parseTemplateSubstitution() {
  12281. return this.parseExpression();
  12282. }
  12283. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  12284. if (isRecord) {
  12285. this.expectPlugin("recordAndTuple");
  12286. }
  12287. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12288. this.state.inFSharpPipelineDirectBody = false;
  12289. const propHash = Object.create(null);
  12290. let first = true;
  12291. const node = this.startNode();
  12292. node.properties = [];
  12293. this.next();
  12294. while (!this.match(close)) {
  12295. if (first) {
  12296. first = false;
  12297. } else {
  12298. this.expect(12);
  12299. if (this.match(close)) {
  12300. this.addTrailingCommaExtraToNode(node);
  12301. break;
  12302. }
  12303. }
  12304. let prop;
  12305. if (isPattern) {
  12306. prop = this.parseBindingProperty();
  12307. } else {
  12308. prop = this.parsePropertyDefinition(refExpressionErrors);
  12309. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  12310. }
  12311. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  12312. this.raise(Errors.InvalidRecordProperty, {
  12313. at: prop
  12314. });
  12315. }
  12316. if (prop.shorthand) {
  12317. this.addExtra(prop, "shorthand", true);
  12318. }
  12319. node.properties.push(prop);
  12320. }
  12321. this.next();
  12322. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12323. let type = "ObjectExpression";
  12324. if (isPattern) {
  12325. type = "ObjectPattern";
  12326. } else if (isRecord) {
  12327. type = "RecordExpression";
  12328. }
  12329. return this.finishNode(node, type);
  12330. }
  12331. addTrailingCommaExtraToNode(node) {
  12332. this.addExtra(node, "trailingComma", this.state.lastTokStart);
  12333. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  12334. }
  12335. maybeAsyncOrAccessorProp(prop) {
  12336. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  12337. }
  12338. parsePropertyDefinition(refExpressionErrors) {
  12339. let decorators = [];
  12340. if (this.match(26)) {
  12341. if (this.hasPlugin("decorators")) {
  12342. this.raise(Errors.UnsupportedPropertyDecorator, {
  12343. at: this.state.startLoc
  12344. });
  12345. }
  12346. while (this.match(26)) {
  12347. decorators.push(this.parseDecorator());
  12348. }
  12349. }
  12350. const prop = this.startNode();
  12351. let isAsync = false;
  12352. let isAccessor = false;
  12353. let startLoc;
  12354. if (this.match(21)) {
  12355. if (decorators.length) this.unexpected();
  12356. return this.parseSpread();
  12357. }
  12358. if (decorators.length) {
  12359. prop.decorators = decorators;
  12360. decorators = [];
  12361. }
  12362. prop.method = false;
  12363. if (refExpressionErrors) {
  12364. startLoc = this.state.startLoc;
  12365. }
  12366. let isGenerator = this.eat(55);
  12367. this.parsePropertyNamePrefixOperator(prop);
  12368. const containsEsc = this.state.containsEsc;
  12369. const key = this.parsePropertyName(prop, refExpressionErrors);
  12370. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  12371. const keyName = key.name;
  12372. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  12373. isAsync = true;
  12374. this.resetPreviousNodeTrailingComments(key);
  12375. isGenerator = this.eat(55);
  12376. this.parsePropertyName(prop);
  12377. }
  12378. if (keyName === "get" || keyName === "set") {
  12379. isAccessor = true;
  12380. this.resetPreviousNodeTrailingComments(key);
  12381. prop.kind = keyName;
  12382. if (this.match(55)) {
  12383. isGenerator = true;
  12384. this.raise(Errors.AccessorIsGenerator, {
  12385. at: this.state.curPosition(),
  12386. kind: keyName
  12387. });
  12388. this.next();
  12389. }
  12390. this.parsePropertyName(prop);
  12391. }
  12392. }
  12393. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  12394. }
  12395. getGetterSetterExpectedParamCount(method) {
  12396. return method.kind === "get" ? 0 : 1;
  12397. }
  12398. getObjectOrClassMethodParams(method) {
  12399. return method.params;
  12400. }
  12401. checkGetterSetterParams(method) {
  12402. var _params;
  12403. const paramCount = this.getGetterSetterExpectedParamCount(method);
  12404. const params = this.getObjectOrClassMethodParams(method);
  12405. if (params.length !== paramCount) {
  12406. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  12407. at: method
  12408. });
  12409. }
  12410. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  12411. this.raise(Errors.BadSetterRestParameter, {
  12412. at: method
  12413. });
  12414. }
  12415. }
  12416. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  12417. if (isAccessor) {
  12418. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  12419. this.checkGetterSetterParams(finishedProp);
  12420. return finishedProp;
  12421. }
  12422. if (isAsync || isGenerator || this.match(10)) {
  12423. if (isPattern) this.unexpected();
  12424. prop.kind = "method";
  12425. prop.method = true;
  12426. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  12427. }
  12428. }
  12429. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  12430. prop.shorthand = false;
  12431. if (this.eat(14)) {
  12432. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  12433. return this.finishNode(prop, "ObjectProperty");
  12434. }
  12435. if (!prop.computed && prop.key.type === "Identifier") {
  12436. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  12437. if (isPattern) {
  12438. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  12439. } else if (this.match(29)) {
  12440. const shorthandAssignLoc = this.state.startLoc;
  12441. if (refExpressionErrors != null) {
  12442. if (refExpressionErrors.shorthandAssignLoc === null) {
  12443. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  12444. }
  12445. } else {
  12446. this.raise(Errors.InvalidCoverInitializedName, {
  12447. at: shorthandAssignLoc
  12448. });
  12449. }
  12450. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  12451. } else {
  12452. prop.value = cloneIdentifier(prop.key);
  12453. }
  12454. prop.shorthand = true;
  12455. return this.finishNode(prop, "ObjectProperty");
  12456. }
  12457. }
  12458. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  12459. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  12460. if (!node) this.unexpected();
  12461. return node;
  12462. }
  12463. parsePropertyName(prop, refExpressionErrors) {
  12464. if (this.eat(0)) {
  12465. prop.computed = true;
  12466. prop.key = this.parseMaybeAssignAllowIn();
  12467. this.expect(3);
  12468. } else {
  12469. const {
  12470. type,
  12471. value
  12472. } = this.state;
  12473. let key;
  12474. if (tokenIsKeywordOrIdentifier(type)) {
  12475. key = this.parseIdentifier(true);
  12476. } else {
  12477. switch (type) {
  12478. case 132:
  12479. key = this.parseNumericLiteral(value);
  12480. break;
  12481. case 131:
  12482. key = this.parseStringLiteral(value);
  12483. break;
  12484. case 133:
  12485. key = this.parseBigIntLiteral(value);
  12486. break;
  12487. case 134:
  12488. key = this.parseDecimalLiteral(value);
  12489. break;
  12490. case 136:
  12491. {
  12492. const privateKeyLoc = this.state.startLoc;
  12493. if (refExpressionErrors != null) {
  12494. if (refExpressionErrors.privateKeyLoc === null) {
  12495. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  12496. }
  12497. } else {
  12498. this.raise(Errors.UnexpectedPrivateField, {
  12499. at: privateKeyLoc
  12500. });
  12501. }
  12502. key = this.parsePrivateName();
  12503. break;
  12504. }
  12505. default:
  12506. this.unexpected();
  12507. }
  12508. }
  12509. prop.key = key;
  12510. if (type !== 136) {
  12511. prop.computed = false;
  12512. }
  12513. }
  12514. return prop.key;
  12515. }
  12516. initFunction(node, isAsync) {
  12517. node.id = null;
  12518. node.generator = false;
  12519. node.async = isAsync;
  12520. }
  12521. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  12522. this.initFunction(node, isAsync);
  12523. node.generator = isGenerator;
  12524. this.scope.enter(SCOPE_FUNCTION | SCOPE_SUPER | (inClassScope ? SCOPE_CLASS : 0) | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  12525. this.prodParam.enter(functionFlags(isAsync, node.generator));
  12526. this.parseFunctionParams(node, isConstructor);
  12527. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  12528. this.prodParam.exit();
  12529. this.scope.exit();
  12530. return finishedNode;
  12531. }
  12532. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  12533. if (isTuple) {
  12534. this.expectPlugin("recordAndTuple");
  12535. }
  12536. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12537. this.state.inFSharpPipelineDirectBody = false;
  12538. const node = this.startNode();
  12539. this.next();
  12540. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  12541. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12542. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  12543. }
  12544. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  12545. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  12546. let flags = functionFlags(isAsync, false);
  12547. if (!this.match(5) && this.prodParam.hasIn) {
  12548. flags |= PARAM_IN;
  12549. }
  12550. this.prodParam.enter(flags);
  12551. this.initFunction(node, isAsync);
  12552. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12553. if (params) {
  12554. this.state.maybeInArrowParameters = true;
  12555. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  12556. }
  12557. this.state.maybeInArrowParameters = false;
  12558. this.parseFunctionBody(node, true);
  12559. this.prodParam.exit();
  12560. this.scope.exit();
  12561. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12562. return this.finishNode(node, "ArrowFunctionExpression");
  12563. }
  12564. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  12565. this.toAssignableList(params, trailingCommaLoc, false);
  12566. node.params = params;
  12567. }
  12568. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  12569. this.parseFunctionBody(node, false, isMethod);
  12570. return this.finishNode(node, type);
  12571. }
  12572. parseFunctionBody(node, allowExpression, isMethod = false) {
  12573. const isExpression = allowExpression && !this.match(5);
  12574. this.expressionScope.enter(newExpressionScope());
  12575. if (isExpression) {
  12576. node.body = this.parseMaybeAssign();
  12577. this.checkParams(node, false, allowExpression, false);
  12578. } else {
  12579. const oldStrict = this.state.strict;
  12580. const oldLabels = this.state.labels;
  12581. this.state.labels = [];
  12582. this.prodParam.enter(this.prodParam.currentFlags() | PARAM_RETURN);
  12583. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  12584. const nonSimple = !this.isSimpleParamList(node.params);
  12585. if (hasStrictModeDirective && nonSimple) {
  12586. this.raise(Errors.IllegalLanguageModeDirective, {
  12587. at: (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node
  12588. });
  12589. }
  12590. const strictModeChanged = !oldStrict && this.state.strict;
  12591. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  12592. if (this.state.strict && node.id) {
  12593. this.checkIdentifier(node.id, BIND_OUTSIDE, strictModeChanged);
  12594. }
  12595. });
  12596. this.prodParam.exit();
  12597. this.state.labels = oldLabels;
  12598. }
  12599. this.expressionScope.exit();
  12600. }
  12601. isSimpleParameter(node) {
  12602. return node.type === "Identifier";
  12603. }
  12604. isSimpleParamList(params) {
  12605. for (let i = 0, len = params.length; i < len; i++) {
  12606. if (!this.isSimpleParameter(params[i])) return false;
  12607. }
  12608. return true;
  12609. }
  12610. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  12611. const checkClashes = !allowDuplicates && new Set();
  12612. const formalParameters = {
  12613. type: "FormalParameters"
  12614. };
  12615. for (const param of node.params) {
  12616. this.checkLVal(param, {
  12617. in: formalParameters,
  12618. binding: BIND_VAR,
  12619. checkClashes,
  12620. strictModeChanged
  12621. });
  12622. }
  12623. }
  12624. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  12625. const elts = [];
  12626. let first = true;
  12627. while (!this.eat(close)) {
  12628. if (first) {
  12629. first = false;
  12630. } else {
  12631. this.expect(12);
  12632. if (this.match(close)) {
  12633. if (nodeForExtra) {
  12634. this.addTrailingCommaExtraToNode(nodeForExtra);
  12635. }
  12636. this.next();
  12637. break;
  12638. }
  12639. }
  12640. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  12641. }
  12642. return elts;
  12643. }
  12644. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  12645. let elt;
  12646. if (this.match(12)) {
  12647. if (!allowEmpty) {
  12648. this.raise(Errors.UnexpectedToken, {
  12649. at: this.state.curPosition(),
  12650. unexpected: ","
  12651. });
  12652. }
  12653. elt = null;
  12654. } else if (this.match(21)) {
  12655. const spreadNodeStartLoc = this.state.startLoc;
  12656. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12657. } else if (this.match(17)) {
  12658. this.expectPlugin("partialApplication");
  12659. if (!allowPlaceholder) {
  12660. this.raise(Errors.UnexpectedArgumentPlaceholder, {
  12661. at: this.state.startLoc
  12662. });
  12663. }
  12664. const node = this.startNode();
  12665. this.next();
  12666. elt = this.finishNode(node, "ArgumentPlaceholder");
  12667. } else {
  12668. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  12669. }
  12670. return elt;
  12671. }
  12672. parseIdentifier(liberal) {
  12673. const node = this.startNode();
  12674. const name = this.parseIdentifierName(liberal);
  12675. return this.createIdentifier(node, name);
  12676. }
  12677. createIdentifier(node, name) {
  12678. node.name = name;
  12679. node.loc.identifierName = name;
  12680. return this.finishNode(node, "Identifier");
  12681. }
  12682. parseIdentifierName(liberal) {
  12683. let name;
  12684. const {
  12685. startLoc,
  12686. type
  12687. } = this.state;
  12688. if (tokenIsKeywordOrIdentifier(type)) {
  12689. name = this.state.value;
  12690. } else {
  12691. this.unexpected();
  12692. }
  12693. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12694. if (liberal) {
  12695. if (tokenIsKeyword) {
  12696. this.replaceToken(130);
  12697. }
  12698. } else {
  12699. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12700. }
  12701. this.next();
  12702. return name;
  12703. }
  12704. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12705. if (word.length > 10) {
  12706. return;
  12707. }
  12708. if (!canBeReservedWord(word)) {
  12709. return;
  12710. }
  12711. if (checkKeywords && isKeyword(word)) {
  12712. this.raise(Errors.UnexpectedKeyword, {
  12713. at: startLoc,
  12714. keyword: word
  12715. });
  12716. return;
  12717. }
  12718. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12719. if (reservedTest(word, this.inModule)) {
  12720. this.raise(Errors.UnexpectedReservedWord, {
  12721. at: startLoc,
  12722. reservedWord: word
  12723. });
  12724. return;
  12725. } else if (word === "yield") {
  12726. if (this.prodParam.hasYield) {
  12727. this.raise(Errors.YieldBindingIdentifier, {
  12728. at: startLoc
  12729. });
  12730. return;
  12731. }
  12732. } else if (word === "await") {
  12733. if (this.prodParam.hasAwait) {
  12734. this.raise(Errors.AwaitBindingIdentifier, {
  12735. at: startLoc
  12736. });
  12737. return;
  12738. }
  12739. if (this.scope.inStaticBlock) {
  12740. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, {
  12741. at: startLoc
  12742. });
  12743. return;
  12744. }
  12745. this.expressionScope.recordAsyncArrowParametersError({
  12746. at: startLoc
  12747. });
  12748. } else if (word === "arguments") {
  12749. if (this.scope.inClassAndNotInNonArrowFunction) {
  12750. this.raise(Errors.ArgumentsInClass, {
  12751. at: startLoc
  12752. });
  12753. return;
  12754. }
  12755. }
  12756. }
  12757. isAwaitAllowed() {
  12758. if (this.prodParam.hasAwait) return true;
  12759. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  12760. return true;
  12761. }
  12762. return false;
  12763. }
  12764. parseAwait(startLoc) {
  12765. const node = this.startNodeAt(startLoc);
  12766. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, {
  12767. at: node
  12768. });
  12769. if (this.eat(55)) {
  12770. this.raise(Errors.ObsoleteAwaitStar, {
  12771. at: node
  12772. });
  12773. }
  12774. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  12775. if (this.isAmbiguousAwait()) {
  12776. this.ambiguousScriptDifferentAst = true;
  12777. } else {
  12778. this.sawUnambiguousESM = true;
  12779. }
  12780. }
  12781. if (!this.state.soloAwait) {
  12782. node.argument = this.parseMaybeUnary(null, true);
  12783. }
  12784. return this.finishNode(node, "AwaitExpression");
  12785. }
  12786. isAmbiguousAwait() {
  12787. if (this.hasPrecedingLineBreak()) return true;
  12788. const {
  12789. type
  12790. } = this.state;
  12791. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 101 && !this.state.containsEsc || type === 135 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12792. }
  12793. parseYield() {
  12794. const node = this.startNode();
  12795. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, {
  12796. at: node
  12797. });
  12798. this.next();
  12799. let delegating = false;
  12800. let argument = null;
  12801. if (!this.hasPrecedingLineBreak()) {
  12802. delegating = this.eat(55);
  12803. switch (this.state.type) {
  12804. case 13:
  12805. case 137:
  12806. case 8:
  12807. case 11:
  12808. case 3:
  12809. case 9:
  12810. case 14:
  12811. case 12:
  12812. if (!delegating) break;
  12813. default:
  12814. argument = this.parseMaybeAssign();
  12815. }
  12816. }
  12817. node.delegate = delegating;
  12818. node.argument = argument;
  12819. return this.finishNode(node, "YieldExpression");
  12820. }
  12821. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12822. if (this.hasPlugin(["pipelineOperator", {
  12823. proposal: "smart"
  12824. }])) {
  12825. if (left.type === "SequenceExpression") {
  12826. this.raise(Errors.PipelineHeadSequenceExpression, {
  12827. at: leftStartLoc
  12828. });
  12829. }
  12830. }
  12831. }
  12832. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12833. if (this.isSimpleReference(childExpr)) {
  12834. const bodyNode = this.startNodeAt(startLoc);
  12835. bodyNode.callee = childExpr;
  12836. return this.finishNode(bodyNode, "PipelineBareFunction");
  12837. } else {
  12838. const bodyNode = this.startNodeAt(startLoc);
  12839. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12840. bodyNode.expression = childExpr;
  12841. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12842. }
  12843. }
  12844. isSimpleReference(expression) {
  12845. switch (expression.type) {
  12846. case "MemberExpression":
  12847. return !expression.computed && this.isSimpleReference(expression.object);
  12848. case "Identifier":
  12849. return true;
  12850. default:
  12851. return false;
  12852. }
  12853. }
  12854. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12855. if (this.match(19)) {
  12856. throw this.raise(Errors.PipelineBodyNoArrow, {
  12857. at: this.state.startLoc
  12858. });
  12859. }
  12860. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12861. this.raise(Errors.PipelineTopicUnused, {
  12862. at: startLoc
  12863. });
  12864. }
  12865. }
  12866. withTopicBindingContext(callback) {
  12867. const outerContextTopicState = this.state.topicContext;
  12868. this.state.topicContext = {
  12869. maxNumOfResolvableTopics: 1,
  12870. maxTopicIndex: null
  12871. };
  12872. try {
  12873. return callback();
  12874. } finally {
  12875. this.state.topicContext = outerContextTopicState;
  12876. }
  12877. }
  12878. withSmartMixTopicForbiddingContext(callback) {
  12879. if (this.hasPlugin(["pipelineOperator", {
  12880. proposal: "smart"
  12881. }])) {
  12882. const outerContextTopicState = this.state.topicContext;
  12883. this.state.topicContext = {
  12884. maxNumOfResolvableTopics: 0,
  12885. maxTopicIndex: null
  12886. };
  12887. try {
  12888. return callback();
  12889. } finally {
  12890. this.state.topicContext = outerContextTopicState;
  12891. }
  12892. } else {
  12893. return callback();
  12894. }
  12895. }
  12896. withSoloAwaitPermittingContext(callback) {
  12897. const outerContextSoloAwaitState = this.state.soloAwait;
  12898. this.state.soloAwait = true;
  12899. try {
  12900. return callback();
  12901. } finally {
  12902. this.state.soloAwait = outerContextSoloAwaitState;
  12903. }
  12904. }
  12905. allowInAnd(callback) {
  12906. const flags = this.prodParam.currentFlags();
  12907. const prodParamToSet = PARAM_IN & ~flags;
  12908. if (prodParamToSet) {
  12909. this.prodParam.enter(flags | PARAM_IN);
  12910. try {
  12911. return callback();
  12912. } finally {
  12913. this.prodParam.exit();
  12914. }
  12915. }
  12916. return callback();
  12917. }
  12918. disallowInAnd(callback) {
  12919. const flags = this.prodParam.currentFlags();
  12920. const prodParamToClear = PARAM_IN & flags;
  12921. if (prodParamToClear) {
  12922. this.prodParam.enter(flags & ~PARAM_IN);
  12923. try {
  12924. return callback();
  12925. } finally {
  12926. this.prodParam.exit();
  12927. }
  12928. }
  12929. return callback();
  12930. }
  12931. registerTopicReference() {
  12932. this.state.topicContext.maxTopicIndex = 0;
  12933. }
  12934. topicReferenceIsAllowedInCurrentContext() {
  12935. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12936. }
  12937. topicReferenceWasUsedInCurrentContext() {
  12938. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12939. }
  12940. parseFSharpPipelineBody(prec) {
  12941. const startLoc = this.state.startLoc;
  12942. this.state.potentialArrowAt = this.state.start;
  12943. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12944. this.state.inFSharpPipelineDirectBody = true;
  12945. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12946. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12947. return ret;
  12948. }
  12949. parseModuleExpression() {
  12950. this.expectPlugin("moduleBlocks");
  12951. const node = this.startNode();
  12952. this.next();
  12953. if (!this.match(5)) {
  12954. this.unexpected(null, 5);
  12955. }
  12956. const program = this.startNodeAt(this.state.endLoc);
  12957. this.next();
  12958. const revertScopes = this.initializeScopes(true);
  12959. this.enterInitialScopes();
  12960. try {
  12961. node.body = this.parseProgram(program, 8, "module");
  12962. } finally {
  12963. revertScopes();
  12964. }
  12965. return this.finishNode(node, "ModuleExpression");
  12966. }
  12967. parsePropertyNamePrefixOperator(prop) {}
  12968. }
  12969. const loopLabel = {
  12970. kind: "loop"
  12971. },
  12972. switchLabel = {
  12973. kind: "switch"
  12974. };
  12975. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12976. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12977. function babel7CompatTokens(tokens, input) {
  12978. for (let i = 0; i < tokens.length; i++) {
  12979. const token = tokens[i];
  12980. const {
  12981. type
  12982. } = token;
  12983. if (typeof type === "number") {
  12984. {
  12985. if (type === 136) {
  12986. const {
  12987. loc,
  12988. start,
  12989. value,
  12990. end
  12991. } = token;
  12992. const hashEndPos = start + 1;
  12993. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12994. tokens.splice(i, 1, new Token({
  12995. type: getExportedToken(27),
  12996. value: "#",
  12997. start: start,
  12998. end: hashEndPos,
  12999. startLoc: loc.start,
  13000. endLoc: hashEndLoc
  13001. }), new Token({
  13002. type: getExportedToken(130),
  13003. value: value,
  13004. start: hashEndPos,
  13005. end: end,
  13006. startLoc: hashEndLoc,
  13007. endLoc: loc.end
  13008. }));
  13009. i++;
  13010. continue;
  13011. }
  13012. if (tokenIsTemplate(type)) {
  13013. const {
  13014. loc,
  13015. start,
  13016. value,
  13017. end
  13018. } = token;
  13019. const backquoteEnd = start + 1;
  13020. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  13021. let startToken;
  13022. if (input.charCodeAt(start) === 96) {
  13023. startToken = new Token({
  13024. type: getExportedToken(22),
  13025. value: "`",
  13026. start: start,
  13027. end: backquoteEnd,
  13028. startLoc: loc.start,
  13029. endLoc: backquoteEndLoc
  13030. });
  13031. } else {
  13032. startToken = new Token({
  13033. type: getExportedToken(8),
  13034. value: "}",
  13035. start: start,
  13036. end: backquoteEnd,
  13037. startLoc: loc.start,
  13038. endLoc: backquoteEndLoc
  13039. });
  13040. }
  13041. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  13042. if (type === 24) {
  13043. templateElementEnd = end - 1;
  13044. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  13045. templateValue = value === null ? null : value.slice(1, -1);
  13046. endToken = new Token({
  13047. type: getExportedToken(22),
  13048. value: "`",
  13049. start: templateElementEnd,
  13050. end: end,
  13051. startLoc: templateElementEndLoc,
  13052. endLoc: loc.end
  13053. });
  13054. } else {
  13055. templateElementEnd = end - 2;
  13056. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  13057. templateValue = value === null ? null : value.slice(1, -2);
  13058. endToken = new Token({
  13059. type: getExportedToken(23),
  13060. value: "${",
  13061. start: templateElementEnd,
  13062. end: end,
  13063. startLoc: templateElementEndLoc,
  13064. endLoc: loc.end
  13065. });
  13066. }
  13067. tokens.splice(i, 1, startToken, new Token({
  13068. type: getExportedToken(20),
  13069. value: templateValue,
  13070. start: backquoteEnd,
  13071. end: templateElementEnd,
  13072. startLoc: backquoteEndLoc,
  13073. endLoc: templateElementEndLoc
  13074. }), endToken);
  13075. i += 2;
  13076. continue;
  13077. }
  13078. }
  13079. token.type = getExportedToken(type);
  13080. }
  13081. }
  13082. return tokens;
  13083. }
  13084. class StatementParser extends ExpressionParser {
  13085. parseTopLevel(file, program) {
  13086. file.program = this.parseProgram(program);
  13087. file.comments = this.state.comments;
  13088. if (this.options.tokens) {
  13089. file.tokens = babel7CompatTokens(this.tokens, this.input);
  13090. }
  13091. return this.finishNode(file, "File");
  13092. }
  13093. parseProgram(program, end = 137, sourceType = this.options.sourceType) {
  13094. program.sourceType = sourceType;
  13095. program.interpreter = this.parseInterpreterDirective();
  13096. this.parseBlockBody(program, true, true, end);
  13097. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  13098. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  13099. this.raise(Errors.ModuleExportUndefined, {
  13100. at,
  13101. localName
  13102. });
  13103. }
  13104. }
  13105. let finishedProgram;
  13106. if (end === 137) {
  13107. finishedProgram = this.finishNode(program, "Program");
  13108. } else {
  13109. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  13110. }
  13111. return finishedProgram;
  13112. }
  13113. stmtToDirective(stmt) {
  13114. const directive = stmt;
  13115. directive.type = "Directive";
  13116. directive.value = directive.expression;
  13117. delete directive.expression;
  13118. const directiveLiteral = directive.value;
  13119. const expressionValue = directiveLiteral.value;
  13120. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  13121. const val = directiveLiteral.value = raw.slice(1, -1);
  13122. this.addExtra(directiveLiteral, "raw", raw);
  13123. this.addExtra(directiveLiteral, "rawValue", val);
  13124. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  13125. directiveLiteral.type = "DirectiveLiteral";
  13126. return directive;
  13127. }
  13128. parseInterpreterDirective() {
  13129. if (!this.match(28)) {
  13130. return null;
  13131. }
  13132. const node = this.startNode();
  13133. node.value = this.state.value;
  13134. this.next();
  13135. return this.finishNode(node, "InterpreterDirective");
  13136. }
  13137. isLet() {
  13138. if (!this.isContextual(99)) {
  13139. return false;
  13140. }
  13141. return this.hasFollowingBindingAtom();
  13142. }
  13143. chStartsBindingIdentifier(ch, pos) {
  13144. if (isIdentifierStart(ch)) {
  13145. keywordRelationalOperator.lastIndex = pos;
  13146. if (keywordRelationalOperator.test(this.input)) {
  13147. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  13148. if (!isIdentifierChar(endCh) && endCh !== 92) {
  13149. return false;
  13150. }
  13151. }
  13152. return true;
  13153. } else if (ch === 92) {
  13154. return true;
  13155. } else {
  13156. return false;
  13157. }
  13158. }
  13159. chStartsBindingPattern(ch) {
  13160. return ch === 91 || ch === 123;
  13161. }
  13162. hasFollowingBindingAtom() {
  13163. const next = this.nextTokenStart();
  13164. const nextCh = this.codePointAtPos(next);
  13165. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  13166. }
  13167. hasFollowingBindingIdentifier() {
  13168. const next = this.nextTokenStart();
  13169. const nextCh = this.codePointAtPos(next);
  13170. return this.chStartsBindingIdentifier(nextCh, next);
  13171. }
  13172. startsUsingForOf() {
  13173. const lookahead = this.lookahead();
  13174. if (lookahead.type === 101 && !lookahead.containsEsc) {
  13175. return false;
  13176. } else {
  13177. this.expectPlugin("explicitResourceManagement");
  13178. return true;
  13179. }
  13180. }
  13181. parseModuleItem() {
  13182. return this.parseStatementLike(1 | 2 | 4 | 8);
  13183. }
  13184. parseStatementListItem() {
  13185. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  13186. }
  13187. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  13188. let flags = 0;
  13189. if (this.options.annexB && !this.state.strict) {
  13190. flags |= 4;
  13191. if (allowLabeledFunction) {
  13192. flags |= 8;
  13193. }
  13194. }
  13195. return this.parseStatementLike(flags);
  13196. }
  13197. parseStatement() {
  13198. return this.parseStatementLike(0);
  13199. }
  13200. parseStatementLike(flags) {
  13201. let decorators = null;
  13202. if (this.match(26)) {
  13203. decorators = this.parseDecorators(true);
  13204. }
  13205. return this.parseStatementContent(flags, decorators);
  13206. }
  13207. parseStatementContent(flags, decorators) {
  13208. const starttype = this.state.type;
  13209. const node = this.startNode();
  13210. const allowDeclaration = !!(flags & 2);
  13211. const allowFunctionDeclaration = !!(flags & 4);
  13212. const topLevel = flags & 1;
  13213. switch (starttype) {
  13214. case 60:
  13215. return this.parseBreakContinueStatement(node, true);
  13216. case 63:
  13217. return this.parseBreakContinueStatement(node, false);
  13218. case 64:
  13219. return this.parseDebuggerStatement(node);
  13220. case 90:
  13221. return this.parseDoWhileStatement(node);
  13222. case 91:
  13223. return this.parseForStatement(node);
  13224. case 68:
  13225. if (this.lookaheadCharCode() === 46) break;
  13226. if (!allowFunctionDeclaration) {
  13227. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, {
  13228. at: this.state.startLoc
  13229. });
  13230. }
  13231. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  13232. case 80:
  13233. if (!allowDeclaration) this.unexpected();
  13234. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  13235. case 69:
  13236. return this.parseIfStatement(node);
  13237. case 70:
  13238. return this.parseReturnStatement(node);
  13239. case 71:
  13240. return this.parseSwitchStatement(node);
  13241. case 72:
  13242. return this.parseThrowStatement(node);
  13243. case 73:
  13244. return this.parseTryStatement(node);
  13245. case 105:
  13246. if (this.hasFollowingLineBreak() || this.state.containsEsc || !this.hasFollowingBindingIdentifier()) {
  13247. break;
  13248. }
  13249. this.expectPlugin("explicitResourceManagement");
  13250. if (!this.scope.inModule && this.scope.inTopLevel) {
  13251. this.raise(Errors.UnexpectedUsingDeclaration, {
  13252. at: this.state.startLoc
  13253. });
  13254. } else if (!allowDeclaration) {
  13255. this.raise(Errors.UnexpectedLexicalDeclaration, {
  13256. at: this.state.startLoc
  13257. });
  13258. }
  13259. return this.parseVarStatement(node, "using");
  13260. case 99:
  13261. {
  13262. if (this.state.containsEsc) {
  13263. break;
  13264. }
  13265. const next = this.nextTokenStart();
  13266. const nextCh = this.codePointAtPos(next);
  13267. if (nextCh !== 91) {
  13268. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  13269. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  13270. break;
  13271. }
  13272. }
  13273. }
  13274. case 75:
  13275. {
  13276. if (!allowDeclaration) {
  13277. this.raise(Errors.UnexpectedLexicalDeclaration, {
  13278. at: this.state.startLoc
  13279. });
  13280. }
  13281. }
  13282. case 74:
  13283. {
  13284. const kind = this.state.value;
  13285. return this.parseVarStatement(node, kind);
  13286. }
  13287. case 92:
  13288. return this.parseWhileStatement(node);
  13289. case 76:
  13290. return this.parseWithStatement(node);
  13291. case 5:
  13292. return this.parseBlock();
  13293. case 13:
  13294. return this.parseEmptyStatement(node);
  13295. case 83:
  13296. {
  13297. const nextTokenCharCode = this.lookaheadCharCode();
  13298. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  13299. break;
  13300. }
  13301. }
  13302. case 82:
  13303. {
  13304. if (!this.options.allowImportExportEverywhere && !topLevel) {
  13305. this.raise(Errors.UnexpectedImportExport, {
  13306. at: this.state.startLoc
  13307. });
  13308. }
  13309. this.next();
  13310. let result;
  13311. if (starttype === 83) {
  13312. result = this.parseImport(node);
  13313. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  13314. this.sawUnambiguousESM = true;
  13315. }
  13316. } else {
  13317. result = this.parseExport(node, decorators);
  13318. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  13319. this.sawUnambiguousESM = true;
  13320. }
  13321. }
  13322. this.assertModuleNodeAllowed(result);
  13323. return result;
  13324. }
  13325. default:
  13326. {
  13327. if (this.isAsyncFunction()) {
  13328. if (!allowDeclaration) {
  13329. this.raise(Errors.AsyncFunctionInSingleStatementContext, {
  13330. at: this.state.startLoc
  13331. });
  13332. }
  13333. this.next();
  13334. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  13335. }
  13336. }
  13337. }
  13338. const maybeName = this.state.value;
  13339. const expr = this.parseExpression();
  13340. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  13341. return this.parseLabeledStatement(node, maybeName, expr, flags);
  13342. } else {
  13343. return this.parseExpressionStatement(node, expr, decorators);
  13344. }
  13345. }
  13346. assertModuleNodeAllowed(node) {
  13347. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  13348. this.raise(Errors.ImportOutsideModule, {
  13349. at: node
  13350. });
  13351. }
  13352. }
  13353. decoratorsEnabledBeforeExport() {
  13354. if (this.hasPlugin("decorators-legacy")) return true;
  13355. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  13356. }
  13357. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  13358. if (maybeDecorators) {
  13359. if (classNode.decorators && classNode.decorators.length > 0) {
  13360. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  13361. this.raise(Errors.DecoratorsBeforeAfterExport, {
  13362. at: classNode.decorators[0]
  13363. });
  13364. }
  13365. classNode.decorators.unshift(...maybeDecorators);
  13366. } else {
  13367. classNode.decorators = maybeDecorators;
  13368. }
  13369. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  13370. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  13371. }
  13372. return classNode;
  13373. }
  13374. canHaveLeadingDecorator() {
  13375. return this.match(80);
  13376. }
  13377. parseDecorators(allowExport) {
  13378. const decorators = [];
  13379. do {
  13380. decorators.push(this.parseDecorator());
  13381. } while (this.match(26));
  13382. if (this.match(82)) {
  13383. if (!allowExport) {
  13384. this.unexpected();
  13385. }
  13386. if (!this.decoratorsEnabledBeforeExport()) {
  13387. this.raise(Errors.DecoratorExportClass, {
  13388. at: this.state.startLoc
  13389. });
  13390. }
  13391. } else if (!this.canHaveLeadingDecorator()) {
  13392. throw this.raise(Errors.UnexpectedLeadingDecorator, {
  13393. at: this.state.startLoc
  13394. });
  13395. }
  13396. return decorators;
  13397. }
  13398. parseDecorator() {
  13399. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13400. const node = this.startNode();
  13401. this.next();
  13402. if (this.hasPlugin("decorators")) {
  13403. const startLoc = this.state.startLoc;
  13404. let expr;
  13405. if (this.match(10)) {
  13406. const startLoc = this.state.startLoc;
  13407. this.next();
  13408. expr = this.parseExpression();
  13409. this.expect(11);
  13410. expr = this.wrapParenthesis(startLoc, expr);
  13411. const paramsStartLoc = this.state.startLoc;
  13412. node.expression = this.parseMaybeDecoratorArguments(expr);
  13413. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  13414. this.raise(Errors.DecoratorArgumentsOutsideParentheses, {
  13415. at: paramsStartLoc
  13416. });
  13417. }
  13418. } else {
  13419. expr = this.parseIdentifier(false);
  13420. while (this.eat(16)) {
  13421. const node = this.startNodeAt(startLoc);
  13422. node.object = expr;
  13423. if (this.match(136)) {
  13424. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  13425. node.property = this.parsePrivateName();
  13426. } else {
  13427. node.property = this.parseIdentifier(true);
  13428. }
  13429. node.computed = false;
  13430. expr = this.finishNode(node, "MemberExpression");
  13431. }
  13432. node.expression = this.parseMaybeDecoratorArguments(expr);
  13433. }
  13434. } else {
  13435. node.expression = this.parseExprSubscripts();
  13436. }
  13437. return this.finishNode(node, "Decorator");
  13438. }
  13439. parseMaybeDecoratorArguments(expr) {
  13440. if (this.eat(10)) {
  13441. const node = this.startNodeAtNode(expr);
  13442. node.callee = expr;
  13443. node.arguments = this.parseCallExpressionArguments(11, false);
  13444. this.toReferencedList(node.arguments);
  13445. return this.finishNode(node, "CallExpression");
  13446. }
  13447. return expr;
  13448. }
  13449. parseBreakContinueStatement(node, isBreak) {
  13450. this.next();
  13451. if (this.isLineTerminator()) {
  13452. node.label = null;
  13453. } else {
  13454. node.label = this.parseIdentifier();
  13455. this.semicolon();
  13456. }
  13457. this.verifyBreakContinue(node, isBreak);
  13458. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  13459. }
  13460. verifyBreakContinue(node, isBreak) {
  13461. let i;
  13462. for (i = 0; i < this.state.labels.length; ++i) {
  13463. const lab = this.state.labels[i];
  13464. if (node.label == null || lab.name === node.label.name) {
  13465. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  13466. if (node.label && isBreak) break;
  13467. }
  13468. }
  13469. if (i === this.state.labels.length) {
  13470. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  13471. this.raise(Errors.IllegalBreakContinue, {
  13472. at: node,
  13473. type
  13474. });
  13475. }
  13476. }
  13477. parseDebuggerStatement(node) {
  13478. this.next();
  13479. this.semicolon();
  13480. return this.finishNode(node, "DebuggerStatement");
  13481. }
  13482. parseHeaderExpression() {
  13483. this.expect(10);
  13484. const val = this.parseExpression();
  13485. this.expect(11);
  13486. return val;
  13487. }
  13488. parseDoWhileStatement(node) {
  13489. this.next();
  13490. this.state.labels.push(loopLabel);
  13491. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13492. this.state.labels.pop();
  13493. this.expect(92);
  13494. node.test = this.parseHeaderExpression();
  13495. this.eat(13);
  13496. return this.finishNode(node, "DoWhileStatement");
  13497. }
  13498. parseForStatement(node) {
  13499. this.next();
  13500. this.state.labels.push(loopLabel);
  13501. let awaitAt = null;
  13502. if (this.isAwaitAllowed() && this.eatContextual(96)) {
  13503. awaitAt = this.state.lastTokStartLoc;
  13504. }
  13505. this.scope.enter(SCOPE_OTHER);
  13506. this.expect(10);
  13507. if (this.match(13)) {
  13508. if (awaitAt !== null) {
  13509. this.unexpected(awaitAt);
  13510. }
  13511. return this.parseFor(node, null);
  13512. }
  13513. const startsWithLet = this.isContextual(99);
  13514. const startsWithUsing = this.isContextual(105) && !this.hasFollowingLineBreak();
  13515. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || startsWithUsing && this.hasFollowingBindingIdentifier() && this.startsUsingForOf();
  13516. if (this.match(74) || this.match(75) || isLetOrUsing) {
  13517. const initNode = this.startNode();
  13518. const kind = this.state.value;
  13519. this.next();
  13520. this.parseVar(initNode, true, kind);
  13521. const init = this.finishNode(initNode, "VariableDeclaration");
  13522. const isForIn = this.match(58);
  13523. if (isForIn && startsWithUsing) {
  13524. this.raise(Errors.ForInUsing, {
  13525. at: init
  13526. });
  13527. }
  13528. if ((isForIn || this.isContextual(101)) && init.declarations.length === 1) {
  13529. return this.parseForIn(node, init, awaitAt);
  13530. }
  13531. if (awaitAt !== null) {
  13532. this.unexpected(awaitAt);
  13533. }
  13534. return this.parseFor(node, init);
  13535. }
  13536. const startsWithAsync = this.isContextual(95);
  13537. const refExpressionErrors = new ExpressionErrors();
  13538. const init = this.parseExpression(true, refExpressionErrors);
  13539. const isForOf = this.isContextual(101);
  13540. if (isForOf) {
  13541. if (startsWithLet) {
  13542. this.raise(Errors.ForOfLet, {
  13543. at: init
  13544. });
  13545. }
  13546. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  13547. this.raise(Errors.ForOfAsync, {
  13548. at: init
  13549. });
  13550. }
  13551. }
  13552. if (isForOf || this.match(58)) {
  13553. this.checkDestructuringPrivate(refExpressionErrors);
  13554. this.toAssignable(init, true);
  13555. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  13556. this.checkLVal(init, {
  13557. in: {
  13558. type
  13559. }
  13560. });
  13561. return this.parseForIn(node, init, awaitAt);
  13562. } else {
  13563. this.checkExpressionErrors(refExpressionErrors, true);
  13564. }
  13565. if (awaitAt !== null) {
  13566. this.unexpected(awaitAt);
  13567. }
  13568. return this.parseFor(node, init);
  13569. }
  13570. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  13571. this.next();
  13572. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  13573. }
  13574. parseIfStatement(node) {
  13575. this.next();
  13576. node.test = this.parseHeaderExpression();
  13577. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  13578. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  13579. return this.finishNode(node, "IfStatement");
  13580. }
  13581. parseReturnStatement(node) {
  13582. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  13583. this.raise(Errors.IllegalReturn, {
  13584. at: this.state.startLoc
  13585. });
  13586. }
  13587. this.next();
  13588. if (this.isLineTerminator()) {
  13589. node.argument = null;
  13590. } else {
  13591. node.argument = this.parseExpression();
  13592. this.semicolon();
  13593. }
  13594. return this.finishNode(node, "ReturnStatement");
  13595. }
  13596. parseSwitchStatement(node) {
  13597. this.next();
  13598. node.discriminant = this.parseHeaderExpression();
  13599. const cases = node.cases = [];
  13600. this.expect(5);
  13601. this.state.labels.push(switchLabel);
  13602. this.scope.enter(SCOPE_OTHER);
  13603. let cur;
  13604. for (let sawDefault; !this.match(8);) {
  13605. if (this.match(61) || this.match(65)) {
  13606. const isCase = this.match(61);
  13607. if (cur) this.finishNode(cur, "SwitchCase");
  13608. cases.push(cur = this.startNode());
  13609. cur.consequent = [];
  13610. this.next();
  13611. if (isCase) {
  13612. cur.test = this.parseExpression();
  13613. } else {
  13614. if (sawDefault) {
  13615. this.raise(Errors.MultipleDefaultsInSwitch, {
  13616. at: this.state.lastTokStartLoc
  13617. });
  13618. }
  13619. sawDefault = true;
  13620. cur.test = null;
  13621. }
  13622. this.expect(14);
  13623. } else {
  13624. if (cur) {
  13625. cur.consequent.push(this.parseStatementListItem());
  13626. } else {
  13627. this.unexpected();
  13628. }
  13629. }
  13630. }
  13631. this.scope.exit();
  13632. if (cur) this.finishNode(cur, "SwitchCase");
  13633. this.next();
  13634. this.state.labels.pop();
  13635. return this.finishNode(node, "SwitchStatement");
  13636. }
  13637. parseThrowStatement(node) {
  13638. this.next();
  13639. if (this.hasPrecedingLineBreak()) {
  13640. this.raise(Errors.NewlineAfterThrow, {
  13641. at: this.state.lastTokEndLoc
  13642. });
  13643. }
  13644. node.argument = this.parseExpression();
  13645. this.semicolon();
  13646. return this.finishNode(node, "ThrowStatement");
  13647. }
  13648. parseCatchClauseParam() {
  13649. const param = this.parseBindingAtom();
  13650. this.scope.enter(this.options.annexB && param.type === "Identifier" ? SCOPE_SIMPLE_CATCH : 0);
  13651. this.checkLVal(param, {
  13652. in: {
  13653. type: "CatchClause"
  13654. },
  13655. binding: BIND_CATCH_PARAM
  13656. });
  13657. return param;
  13658. }
  13659. parseTryStatement(node) {
  13660. this.next();
  13661. node.block = this.parseBlock();
  13662. node.handler = null;
  13663. if (this.match(62)) {
  13664. const clause = this.startNode();
  13665. this.next();
  13666. if (this.match(10)) {
  13667. this.expect(10);
  13668. clause.param = this.parseCatchClauseParam();
  13669. this.expect(11);
  13670. } else {
  13671. clause.param = null;
  13672. this.scope.enter(SCOPE_OTHER);
  13673. }
  13674. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13675. this.scope.exit();
  13676. node.handler = this.finishNode(clause, "CatchClause");
  13677. }
  13678. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13679. if (!node.handler && !node.finalizer) {
  13680. this.raise(Errors.NoCatchOrFinally, {
  13681. at: node
  13682. });
  13683. }
  13684. return this.finishNode(node, "TryStatement");
  13685. }
  13686. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13687. this.next();
  13688. this.parseVar(node, false, kind, allowMissingInitializer);
  13689. this.semicolon();
  13690. return this.finishNode(node, "VariableDeclaration");
  13691. }
  13692. parseWhileStatement(node) {
  13693. this.next();
  13694. node.test = this.parseHeaderExpression();
  13695. this.state.labels.push(loopLabel);
  13696. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13697. this.state.labels.pop();
  13698. return this.finishNode(node, "WhileStatement");
  13699. }
  13700. parseWithStatement(node) {
  13701. if (this.state.strict) {
  13702. this.raise(Errors.StrictWith, {
  13703. at: this.state.startLoc
  13704. });
  13705. }
  13706. this.next();
  13707. node.object = this.parseHeaderExpression();
  13708. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13709. return this.finishNode(node, "WithStatement");
  13710. }
  13711. parseEmptyStatement(node) {
  13712. this.next();
  13713. return this.finishNode(node, "EmptyStatement");
  13714. }
  13715. parseLabeledStatement(node, maybeName, expr, flags) {
  13716. for (const label of this.state.labels) {
  13717. if (label.name === maybeName) {
  13718. this.raise(Errors.LabelRedeclaration, {
  13719. at: expr,
  13720. labelName: maybeName
  13721. });
  13722. }
  13723. }
  13724. const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null;
  13725. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13726. const label = this.state.labels[i];
  13727. if (label.statementStart === node.start) {
  13728. label.statementStart = this.state.start;
  13729. label.kind = kind;
  13730. } else {
  13731. break;
  13732. }
  13733. }
  13734. this.state.labels.push({
  13735. name: maybeName,
  13736. kind: kind,
  13737. statementStart: this.state.start
  13738. });
  13739. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13740. this.state.labels.pop();
  13741. node.label = expr;
  13742. return this.finishNode(node, "LabeledStatement");
  13743. }
  13744. parseExpressionStatement(node, expr, decorators) {
  13745. node.expression = expr;
  13746. this.semicolon();
  13747. return this.finishNode(node, "ExpressionStatement");
  13748. }
  13749. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13750. const node = this.startNode();
  13751. if (allowDirectives) {
  13752. this.state.strictErrors.clear();
  13753. }
  13754. this.expect(5);
  13755. if (createNewLexicalScope) {
  13756. this.scope.enter(SCOPE_OTHER);
  13757. }
  13758. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13759. if (createNewLexicalScope) {
  13760. this.scope.exit();
  13761. }
  13762. return this.finishNode(node, "BlockStatement");
  13763. }
  13764. isValidDirective(stmt) {
  13765. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13766. }
  13767. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13768. const body = node.body = [];
  13769. const directives = node.directives = [];
  13770. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13771. }
  13772. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13773. const oldStrict = this.state.strict;
  13774. let hasStrictModeDirective = false;
  13775. let parsedNonDirective = false;
  13776. while (!this.match(end)) {
  13777. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13778. if (directives && !parsedNonDirective) {
  13779. if (this.isValidDirective(stmt)) {
  13780. const directive = this.stmtToDirective(stmt);
  13781. directives.push(directive);
  13782. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13783. hasStrictModeDirective = true;
  13784. this.setStrict(true);
  13785. }
  13786. continue;
  13787. }
  13788. parsedNonDirective = true;
  13789. this.state.strictErrors.clear();
  13790. }
  13791. body.push(stmt);
  13792. }
  13793. if (afterBlockParse) {
  13794. afterBlockParse.call(this, hasStrictModeDirective);
  13795. }
  13796. if (!oldStrict) {
  13797. this.setStrict(false);
  13798. }
  13799. this.next();
  13800. }
  13801. parseFor(node, init) {
  13802. node.init = init;
  13803. this.semicolon(false);
  13804. node.test = this.match(13) ? null : this.parseExpression();
  13805. this.semicolon(false);
  13806. node.update = this.match(11) ? null : this.parseExpression();
  13807. this.expect(11);
  13808. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13809. this.scope.exit();
  13810. this.state.labels.pop();
  13811. return this.finishNode(node, "ForStatement");
  13812. }
  13813. parseForIn(node, init, awaitAt) {
  13814. const isForIn = this.match(58);
  13815. this.next();
  13816. if (isForIn) {
  13817. if (awaitAt !== null) this.unexpected(awaitAt);
  13818. } else {
  13819. node.await = awaitAt !== null;
  13820. }
  13821. if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || !this.options.annexB || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) {
  13822. this.raise(Errors.ForInOfLoopInitializer, {
  13823. at: init,
  13824. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13825. });
  13826. }
  13827. if (init.type === "AssignmentPattern") {
  13828. this.raise(Errors.InvalidLhs, {
  13829. at: init,
  13830. ancestor: {
  13831. type: "ForStatement"
  13832. }
  13833. });
  13834. }
  13835. node.left = init;
  13836. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13837. this.expect(11);
  13838. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13839. this.scope.exit();
  13840. this.state.labels.pop();
  13841. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13842. }
  13843. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13844. const declarations = node.declarations = [];
  13845. node.kind = kind;
  13846. for (;;) {
  13847. const decl = this.startNode();
  13848. this.parseVarId(decl, kind);
  13849. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13850. if (decl.init === null && !allowMissingInitializer) {
  13851. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(101)))) {
  13852. this.raise(Errors.DeclarationMissingInitializer, {
  13853. at: this.state.lastTokEndLoc,
  13854. kind: "destructuring"
  13855. });
  13856. } else if (kind === "const" && !(this.match(58) || this.isContextual(101))) {
  13857. this.raise(Errors.DeclarationMissingInitializer, {
  13858. at: this.state.lastTokEndLoc,
  13859. kind: "const"
  13860. });
  13861. }
  13862. }
  13863. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13864. if (!this.eat(12)) break;
  13865. }
  13866. return node;
  13867. }
  13868. parseVarId(decl, kind) {
  13869. if (kind === "using" && !this.inModule && this.match(96)) {
  13870. this.raise(Errors.AwaitInUsingBinding, {
  13871. at: this.state.startLoc
  13872. });
  13873. }
  13874. const id = this.parseBindingAtom();
  13875. this.checkLVal(id, {
  13876. in: {
  13877. type: "VariableDeclarator"
  13878. },
  13879. binding: kind === "var" ? BIND_VAR : BIND_LEXICAL
  13880. });
  13881. decl.id = id;
  13882. }
  13883. parseAsyncFunctionExpression(node) {
  13884. return this.parseFunction(node, 8);
  13885. }
  13886. parseFunction(node, flags = 0) {
  13887. const hangingDeclaration = flags & 2;
  13888. const isDeclaration = !!(flags & 1);
  13889. const requireId = isDeclaration && !(flags & 4);
  13890. const isAsync = !!(flags & 8);
  13891. this.initFunction(node, isAsync);
  13892. if (this.match(55)) {
  13893. if (hangingDeclaration) {
  13894. this.raise(Errors.GeneratorInSingleStatementContext, {
  13895. at: this.state.startLoc
  13896. });
  13897. }
  13898. this.next();
  13899. node.generator = true;
  13900. }
  13901. if (isDeclaration) {
  13902. node.id = this.parseFunctionId(requireId);
  13903. }
  13904. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13905. this.state.maybeInArrowParameters = false;
  13906. this.scope.enter(SCOPE_FUNCTION);
  13907. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13908. if (!isDeclaration) {
  13909. node.id = this.parseFunctionId();
  13910. }
  13911. this.parseFunctionParams(node, false);
  13912. this.withSmartMixTopicForbiddingContext(() => {
  13913. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13914. });
  13915. this.prodParam.exit();
  13916. this.scope.exit();
  13917. if (isDeclaration && !hangingDeclaration) {
  13918. this.registerFunctionStatementId(node);
  13919. }
  13920. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13921. return node;
  13922. }
  13923. parseFunctionId(requireId) {
  13924. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13925. }
  13926. parseFunctionParams(node, isConstructor) {
  13927. this.expect(10);
  13928. this.expressionScope.enter(newParameterDeclarationScope());
  13929. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13930. this.expressionScope.exit();
  13931. }
  13932. registerFunctionStatementId(node) {
  13933. if (!node.id) return;
  13934. this.scope.declareName(node.id.name, !this.options.annexB || this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION, node.id.loc.start);
  13935. }
  13936. parseClass(node, isStatement, optionalId) {
  13937. this.next();
  13938. const oldStrict = this.state.strict;
  13939. this.state.strict = true;
  13940. this.parseClassId(node, isStatement, optionalId);
  13941. this.parseClassSuper(node);
  13942. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13943. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13944. }
  13945. isClassProperty() {
  13946. return this.match(29) || this.match(13) || this.match(8);
  13947. }
  13948. isClassMethod() {
  13949. return this.match(10);
  13950. }
  13951. isNonstaticConstructor(method) {
  13952. return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
  13953. }
  13954. parseClassBody(hadSuperClass, oldStrict) {
  13955. this.classScope.enter();
  13956. const state = {
  13957. hadConstructor: false,
  13958. hadSuperClass
  13959. };
  13960. let decorators = [];
  13961. const classBody = this.startNode();
  13962. classBody.body = [];
  13963. this.expect(5);
  13964. this.withSmartMixTopicForbiddingContext(() => {
  13965. while (!this.match(8)) {
  13966. if (this.eat(13)) {
  13967. if (decorators.length > 0) {
  13968. throw this.raise(Errors.DecoratorSemicolon, {
  13969. at: this.state.lastTokEndLoc
  13970. });
  13971. }
  13972. continue;
  13973. }
  13974. if (this.match(26)) {
  13975. decorators.push(this.parseDecorator());
  13976. continue;
  13977. }
  13978. const member = this.startNode();
  13979. if (decorators.length) {
  13980. member.decorators = decorators;
  13981. this.resetStartLocationFromNode(member, decorators[0]);
  13982. decorators = [];
  13983. }
  13984. this.parseClassMember(classBody, member, state);
  13985. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13986. this.raise(Errors.DecoratorConstructor, {
  13987. at: member
  13988. });
  13989. }
  13990. }
  13991. });
  13992. this.state.strict = oldStrict;
  13993. this.next();
  13994. if (decorators.length) {
  13995. throw this.raise(Errors.TrailingDecorator, {
  13996. at: this.state.startLoc
  13997. });
  13998. }
  13999. this.classScope.exit();
  14000. return this.finishNode(classBody, "ClassBody");
  14001. }
  14002. parseClassMemberFromModifier(classBody, member) {
  14003. const key = this.parseIdentifier(true);
  14004. if (this.isClassMethod()) {
  14005. const method = member;
  14006. method.kind = "method";
  14007. method.computed = false;
  14008. method.key = key;
  14009. method.static = false;
  14010. this.pushClassMethod(classBody, method, false, false, false, false);
  14011. return true;
  14012. } else if (this.isClassProperty()) {
  14013. const prop = member;
  14014. prop.computed = false;
  14015. prop.key = key;
  14016. prop.static = false;
  14017. classBody.body.push(this.parseClassProperty(prop));
  14018. return true;
  14019. }
  14020. this.resetPreviousNodeTrailingComments(key);
  14021. return false;
  14022. }
  14023. parseClassMember(classBody, member, state) {
  14024. const isStatic = this.isContextual(104);
  14025. if (isStatic) {
  14026. if (this.parseClassMemberFromModifier(classBody, member)) {
  14027. return;
  14028. }
  14029. if (this.eat(5)) {
  14030. this.parseClassStaticBlock(classBody, member);
  14031. return;
  14032. }
  14033. }
  14034. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  14035. }
  14036. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  14037. const publicMethod = member;
  14038. const privateMethod = member;
  14039. const publicProp = member;
  14040. const privateProp = member;
  14041. const accessorProp = member;
  14042. const method = publicMethod;
  14043. const publicMember = publicMethod;
  14044. member.static = isStatic;
  14045. this.parsePropertyNamePrefixOperator(member);
  14046. if (this.eat(55)) {
  14047. method.kind = "method";
  14048. const isPrivateName = this.match(136);
  14049. this.parseClassElementName(method);
  14050. if (isPrivateName) {
  14051. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  14052. return;
  14053. }
  14054. if (this.isNonstaticConstructor(publicMethod)) {
  14055. this.raise(Errors.ConstructorIsGenerator, {
  14056. at: publicMethod.key
  14057. });
  14058. }
  14059. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  14060. return;
  14061. }
  14062. const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
  14063. const isPrivate = this.match(136);
  14064. const key = this.parseClassElementName(member);
  14065. const maybeQuestionTokenStartLoc = this.state.startLoc;
  14066. this.parsePostMemberNameModifiers(publicMember);
  14067. if (this.isClassMethod()) {
  14068. method.kind = "method";
  14069. if (isPrivate) {
  14070. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  14071. return;
  14072. }
  14073. const isConstructor = this.isNonstaticConstructor(publicMethod);
  14074. let allowsDirectSuper = false;
  14075. if (isConstructor) {
  14076. publicMethod.kind = "constructor";
  14077. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  14078. this.raise(Errors.DuplicateConstructor, {
  14079. at: key
  14080. });
  14081. }
  14082. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  14083. this.raise(Errors.OverrideOnConstructor, {
  14084. at: key
  14085. });
  14086. }
  14087. state.hadConstructor = true;
  14088. allowsDirectSuper = state.hadSuperClass;
  14089. }
  14090. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  14091. } else if (this.isClassProperty()) {
  14092. if (isPrivate) {
  14093. this.pushClassPrivateProperty(classBody, privateProp);
  14094. } else {
  14095. this.pushClassProperty(classBody, publicProp);
  14096. }
  14097. } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
  14098. this.resetPreviousNodeTrailingComments(key);
  14099. const isGenerator = this.eat(55);
  14100. if (publicMember.optional) {
  14101. this.unexpected(maybeQuestionTokenStartLoc);
  14102. }
  14103. method.kind = "method";
  14104. const isPrivate = this.match(136);
  14105. this.parseClassElementName(method);
  14106. this.parsePostMemberNameModifiers(publicMember);
  14107. if (isPrivate) {
  14108. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  14109. } else {
  14110. if (this.isNonstaticConstructor(publicMethod)) {
  14111. this.raise(Errors.ConstructorIsAsync, {
  14112. at: publicMethod.key
  14113. });
  14114. }
  14115. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  14116. }
  14117. } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) {
  14118. this.resetPreviousNodeTrailingComments(key);
  14119. method.kind = key.name;
  14120. const isPrivate = this.match(136);
  14121. this.parseClassElementName(publicMethod);
  14122. if (isPrivate) {
  14123. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  14124. } else {
  14125. if (this.isNonstaticConstructor(publicMethod)) {
  14126. this.raise(Errors.ConstructorIsAccessor, {
  14127. at: publicMethod.key
  14128. });
  14129. }
  14130. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  14131. }
  14132. this.checkGetterSetterParams(publicMethod);
  14133. } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) {
  14134. this.expectPlugin("decoratorAutoAccessors");
  14135. this.resetPreviousNodeTrailingComments(key);
  14136. const isPrivate = this.match(136);
  14137. this.parseClassElementName(publicProp);
  14138. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  14139. } else if (this.isLineTerminator()) {
  14140. if (isPrivate) {
  14141. this.pushClassPrivateProperty(classBody, privateProp);
  14142. } else {
  14143. this.pushClassProperty(classBody, publicProp);
  14144. }
  14145. } else {
  14146. this.unexpected();
  14147. }
  14148. }
  14149. parseClassElementName(member) {
  14150. const {
  14151. type,
  14152. value
  14153. } = this.state;
  14154. if ((type === 130 || type === 131) && member.static && value === "prototype") {
  14155. this.raise(Errors.StaticPrototype, {
  14156. at: this.state.startLoc
  14157. });
  14158. }
  14159. if (type === 136) {
  14160. if (value === "constructor") {
  14161. this.raise(Errors.ConstructorClassPrivateField, {
  14162. at: this.state.startLoc
  14163. });
  14164. }
  14165. const key = this.parsePrivateName();
  14166. member.key = key;
  14167. return key;
  14168. }
  14169. return this.parsePropertyName(member);
  14170. }
  14171. parseClassStaticBlock(classBody, member) {
  14172. var _member$decorators;
  14173. this.scope.enter(SCOPE_CLASS | SCOPE_STATIC_BLOCK | SCOPE_SUPER);
  14174. const oldLabels = this.state.labels;
  14175. this.state.labels = [];
  14176. this.prodParam.enter(PARAM);
  14177. const body = member.body = [];
  14178. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  14179. this.prodParam.exit();
  14180. this.scope.exit();
  14181. this.state.labels = oldLabels;
  14182. classBody.body.push(this.finishNode(member, "StaticBlock"));
  14183. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  14184. this.raise(Errors.DecoratorStaticBlock, {
  14185. at: member
  14186. });
  14187. }
  14188. }
  14189. pushClassProperty(classBody, prop) {
  14190. if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
  14191. this.raise(Errors.ConstructorClassField, {
  14192. at: prop.key
  14193. });
  14194. }
  14195. classBody.body.push(this.parseClassProperty(prop));
  14196. }
  14197. pushClassPrivateProperty(classBody, prop) {
  14198. const node = this.parseClassPrivateProperty(prop);
  14199. classBody.body.push(node);
  14200. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.loc.start);
  14201. }
  14202. pushClassAccessorProperty(classBody, prop, isPrivate) {
  14203. if (!isPrivate && !prop.computed) {
  14204. const key = prop.key;
  14205. if (key.name === "constructor" || key.value === "constructor") {
  14206. this.raise(Errors.ConstructorClassField, {
  14207. at: key
  14208. });
  14209. }
  14210. }
  14211. const node = this.parseClassAccessorProperty(prop);
  14212. classBody.body.push(node);
  14213. if (isPrivate) {
  14214. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.loc.start);
  14215. }
  14216. }
  14217. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  14218. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  14219. }
  14220. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  14221. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  14222. classBody.body.push(node);
  14223. const kind = node.kind === "get" ? node.static ? CLASS_ELEMENT_STATIC_GETTER : CLASS_ELEMENT_INSTANCE_GETTER : node.kind === "set" ? node.static ? CLASS_ELEMENT_STATIC_SETTER : CLASS_ELEMENT_INSTANCE_SETTER : CLASS_ELEMENT_OTHER;
  14224. this.declareClassPrivateMethodInScope(node, kind);
  14225. }
  14226. declareClassPrivateMethodInScope(node, kind) {
  14227. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  14228. }
  14229. parsePostMemberNameModifiers(methodOrProp) {}
  14230. parseClassPrivateProperty(node) {
  14231. this.parseInitializer(node);
  14232. this.semicolon();
  14233. return this.finishNode(node, "ClassPrivateProperty");
  14234. }
  14235. parseClassProperty(node) {
  14236. this.parseInitializer(node);
  14237. this.semicolon();
  14238. return this.finishNode(node, "ClassProperty");
  14239. }
  14240. parseClassAccessorProperty(node) {
  14241. this.parseInitializer(node);
  14242. this.semicolon();
  14243. return this.finishNode(node, "ClassAccessorProperty");
  14244. }
  14245. parseInitializer(node) {
  14246. this.scope.enter(SCOPE_CLASS | SCOPE_SUPER);
  14247. this.expressionScope.enter(newExpressionScope());
  14248. this.prodParam.enter(PARAM);
  14249. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  14250. this.expressionScope.exit();
  14251. this.prodParam.exit();
  14252. this.scope.exit();
  14253. }
  14254. parseClassId(node, isStatement, optionalId, bindingType = BIND_CLASS) {
  14255. if (tokenIsIdentifier(this.state.type)) {
  14256. node.id = this.parseIdentifier();
  14257. if (isStatement) {
  14258. this.declareNameFromIdentifier(node.id, bindingType);
  14259. }
  14260. } else {
  14261. if (optionalId || !isStatement) {
  14262. node.id = null;
  14263. } else {
  14264. throw this.raise(Errors.MissingClassName, {
  14265. at: this.state.startLoc
  14266. });
  14267. }
  14268. }
  14269. }
  14270. parseClassSuper(node) {
  14271. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  14272. }
  14273. parseExport(node, decorators) {
  14274. const hasDefault = this.maybeParseExportDefaultSpecifier(node);
  14275. const parseAfterDefault = !hasDefault || this.eat(12);
  14276. const hasStar = parseAfterDefault && this.eatExportStar(node);
  14277. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  14278. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  14279. const isFromRequired = hasDefault || hasStar;
  14280. if (hasStar && !hasNamespace) {
  14281. if (hasDefault) this.unexpected();
  14282. if (decorators) {
  14283. throw this.raise(Errors.UnsupportedDecoratorExport, {
  14284. at: node
  14285. });
  14286. }
  14287. this.parseExportFrom(node, true);
  14288. return this.finishNode(node, "ExportAllDeclaration");
  14289. }
  14290. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  14291. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  14292. this.unexpected(null, 5);
  14293. }
  14294. if (hasNamespace && parseAfterNamespace) {
  14295. this.unexpected(null, 97);
  14296. }
  14297. let hasDeclaration;
  14298. if (isFromRequired || hasSpecifiers) {
  14299. hasDeclaration = false;
  14300. if (decorators) {
  14301. throw this.raise(Errors.UnsupportedDecoratorExport, {
  14302. at: node
  14303. });
  14304. }
  14305. this.parseExportFrom(node, isFromRequired);
  14306. } else {
  14307. hasDeclaration = this.maybeParseExportDeclaration(node);
  14308. }
  14309. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  14310. var _node2$declaration;
  14311. const node2 = node;
  14312. this.checkExport(node2, true, false, !!node2.source);
  14313. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  14314. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  14315. } else if (decorators) {
  14316. throw this.raise(Errors.UnsupportedDecoratorExport, {
  14317. at: node
  14318. });
  14319. }
  14320. return this.finishNode(node2, "ExportNamedDeclaration");
  14321. }
  14322. if (this.eat(65)) {
  14323. const node2 = node;
  14324. const decl = this.parseExportDefaultExpression();
  14325. node2.declaration = decl;
  14326. if (decl.type === "ClassDeclaration") {
  14327. this.maybeTakeDecorators(decorators, decl, node2);
  14328. } else if (decorators) {
  14329. throw this.raise(Errors.UnsupportedDecoratorExport, {
  14330. at: node
  14331. });
  14332. }
  14333. this.checkExport(node2, true, true);
  14334. return this.finishNode(node2, "ExportDefaultDeclaration");
  14335. }
  14336. this.unexpected(null, 5);
  14337. }
  14338. eatExportStar(node) {
  14339. return this.eat(55);
  14340. }
  14341. maybeParseExportDefaultSpecifier(node) {
  14342. if (this.isExportDefaultSpecifier()) {
  14343. this.expectPlugin("exportDefaultFrom");
  14344. const specifier = this.startNode();
  14345. specifier.exported = this.parseIdentifier(true);
  14346. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  14347. return true;
  14348. }
  14349. return false;
  14350. }
  14351. maybeParseExportNamespaceSpecifier(node) {
  14352. if (this.isContextual(93)) {
  14353. if (!node.specifiers) node.specifiers = [];
  14354. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  14355. this.next();
  14356. specifier.exported = this.parseModuleExportName();
  14357. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  14358. return true;
  14359. }
  14360. return false;
  14361. }
  14362. maybeParseExportNamedSpecifiers(node) {
  14363. if (this.match(5)) {
  14364. if (!node.specifiers) node.specifiers = [];
  14365. const isTypeExport = node.exportKind === "type";
  14366. node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  14367. node.source = null;
  14368. node.declaration = null;
  14369. if (this.hasPlugin("importAssertions")) {
  14370. node.assertions = [];
  14371. }
  14372. return true;
  14373. }
  14374. return false;
  14375. }
  14376. maybeParseExportDeclaration(node) {
  14377. if (this.shouldParseExportDeclaration()) {
  14378. node.specifiers = [];
  14379. node.source = null;
  14380. if (this.hasPlugin("importAssertions")) {
  14381. node.assertions = [];
  14382. }
  14383. node.declaration = this.parseExportDeclaration(node);
  14384. return true;
  14385. }
  14386. return false;
  14387. }
  14388. isAsyncFunction() {
  14389. if (!this.isContextual(95)) return false;
  14390. const next = this.nextTokenStart();
  14391. return !lineBreak.test(this.input.slice(this.state.pos, next)) && this.isUnparsedContextual(next, "function");
  14392. }
  14393. parseExportDefaultExpression() {
  14394. const expr = this.startNode();
  14395. if (this.match(68)) {
  14396. this.next();
  14397. return this.parseFunction(expr, 1 | 4);
  14398. } else if (this.isAsyncFunction()) {
  14399. this.next();
  14400. this.next();
  14401. return this.parseFunction(expr, 1 | 4 | 8);
  14402. }
  14403. if (this.match(80)) {
  14404. return this.parseClass(expr, true, true);
  14405. }
  14406. if (this.match(26)) {
  14407. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  14408. this.raise(Errors.DecoratorBeforeExport, {
  14409. at: this.state.startLoc
  14410. });
  14411. }
  14412. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  14413. }
  14414. if (this.match(75) || this.match(74) || this.isLet()) {
  14415. throw this.raise(Errors.UnsupportedDefaultExport, {
  14416. at: this.state.startLoc
  14417. });
  14418. }
  14419. const res = this.parseMaybeAssignAllowIn();
  14420. this.semicolon();
  14421. return res;
  14422. }
  14423. parseExportDeclaration(node) {
  14424. if (this.match(80)) {
  14425. const node = this.parseClass(this.startNode(), true, false);
  14426. return node;
  14427. }
  14428. return this.parseStatementListItem();
  14429. }
  14430. isExportDefaultSpecifier() {
  14431. const {
  14432. type
  14433. } = this.state;
  14434. if (tokenIsIdentifier(type)) {
  14435. if (type === 95 && !this.state.containsEsc || type === 99) {
  14436. return false;
  14437. }
  14438. if ((type === 128 || type === 127) && !this.state.containsEsc) {
  14439. const {
  14440. type: nextType
  14441. } = this.lookahead();
  14442. if (tokenIsIdentifier(nextType) && nextType !== 97 || nextType === 5) {
  14443. this.expectOnePlugin(["flow", "typescript"]);
  14444. return false;
  14445. }
  14446. }
  14447. } else if (!this.match(65)) {
  14448. return false;
  14449. }
  14450. const next = this.nextTokenStart();
  14451. const hasFrom = this.isUnparsedContextual(next, "from");
  14452. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  14453. return true;
  14454. }
  14455. if (this.match(65) && hasFrom) {
  14456. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  14457. return nextAfterFrom === 34 || nextAfterFrom === 39;
  14458. }
  14459. return false;
  14460. }
  14461. parseExportFrom(node, expect) {
  14462. if (this.eatContextual(97)) {
  14463. node.source = this.parseImportSource();
  14464. this.checkExport(node);
  14465. const assertions = this.maybeParseImportAssertions();
  14466. if (assertions) {
  14467. node.assertions = assertions;
  14468. this.checkJSONModuleImport(node);
  14469. }
  14470. } else if (expect) {
  14471. this.unexpected();
  14472. }
  14473. this.semicolon();
  14474. }
  14475. shouldParseExportDeclaration() {
  14476. const {
  14477. type
  14478. } = this.state;
  14479. if (type === 26) {
  14480. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  14481. if (this.hasPlugin("decorators")) {
  14482. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  14483. this.raise(Errors.DecoratorBeforeExport, {
  14484. at: this.state.startLoc
  14485. });
  14486. }
  14487. return true;
  14488. }
  14489. }
  14490. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  14491. }
  14492. checkExport(node, checkNames, isDefault, isFrom) {
  14493. if (checkNames) {
  14494. if (isDefault) {
  14495. this.checkDuplicateExports(node, "default");
  14496. if (this.hasPlugin("exportDefaultFrom")) {
  14497. var _declaration$extra;
  14498. const declaration = node.declaration;
  14499. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  14500. this.raise(Errors.ExportDefaultFromAsIdentifier, {
  14501. at: declaration
  14502. });
  14503. }
  14504. }
  14505. } else if (node.specifiers && node.specifiers.length) {
  14506. for (const specifier of node.specifiers) {
  14507. const {
  14508. exported
  14509. } = specifier;
  14510. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  14511. this.checkDuplicateExports(specifier, exportName);
  14512. if (!isFrom && specifier.local) {
  14513. const {
  14514. local
  14515. } = specifier;
  14516. if (local.type !== "Identifier") {
  14517. this.raise(Errors.ExportBindingIsString, {
  14518. at: specifier,
  14519. localName: local.value,
  14520. exportName
  14521. });
  14522. } else {
  14523. this.checkReservedWord(local.name, local.loc.start, true, false);
  14524. this.scope.checkLocalExport(local);
  14525. }
  14526. }
  14527. }
  14528. } else if (node.declaration) {
  14529. if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
  14530. const id = node.declaration.id;
  14531. if (!id) throw new Error("Assertion failure");
  14532. this.checkDuplicateExports(node, id.name);
  14533. } else if (node.declaration.type === "VariableDeclaration") {
  14534. for (const declaration of node.declaration.declarations) {
  14535. this.checkDeclaration(declaration.id);
  14536. }
  14537. }
  14538. }
  14539. }
  14540. }
  14541. checkDeclaration(node) {
  14542. if (node.type === "Identifier") {
  14543. this.checkDuplicateExports(node, node.name);
  14544. } else if (node.type === "ObjectPattern") {
  14545. for (const prop of node.properties) {
  14546. this.checkDeclaration(prop);
  14547. }
  14548. } else if (node.type === "ArrayPattern") {
  14549. for (const elem of node.elements) {
  14550. if (elem) {
  14551. this.checkDeclaration(elem);
  14552. }
  14553. }
  14554. } else if (node.type === "ObjectProperty") {
  14555. this.checkDeclaration(node.value);
  14556. } else if (node.type === "RestElement") {
  14557. this.checkDeclaration(node.argument);
  14558. } else if (node.type === "AssignmentPattern") {
  14559. this.checkDeclaration(node.left);
  14560. }
  14561. }
  14562. checkDuplicateExports(node, exportName) {
  14563. if (this.exportedIdentifiers.has(exportName)) {
  14564. if (exportName === "default") {
  14565. this.raise(Errors.DuplicateDefaultExport, {
  14566. at: node
  14567. });
  14568. } else {
  14569. this.raise(Errors.DuplicateExport, {
  14570. at: node,
  14571. exportName
  14572. });
  14573. }
  14574. }
  14575. this.exportedIdentifiers.add(exportName);
  14576. }
  14577. parseExportSpecifiers(isInTypeExport) {
  14578. const nodes = [];
  14579. let first = true;
  14580. this.expect(5);
  14581. while (!this.eat(8)) {
  14582. if (first) {
  14583. first = false;
  14584. } else {
  14585. this.expect(12);
  14586. if (this.eat(8)) break;
  14587. }
  14588. const isMaybeTypeOnly = this.isContextual(128);
  14589. const isString = this.match(131);
  14590. const node = this.startNode();
  14591. node.local = this.parseModuleExportName();
  14592. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  14593. }
  14594. return nodes;
  14595. }
  14596. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14597. if (this.eatContextual(93)) {
  14598. node.exported = this.parseModuleExportName();
  14599. } else if (isString) {
  14600. node.exported = cloneStringLiteral(node.local);
  14601. } else if (!node.exported) {
  14602. node.exported = cloneIdentifier(node.local);
  14603. }
  14604. return this.finishNode(node, "ExportSpecifier");
  14605. }
  14606. parseModuleExportName() {
  14607. if (this.match(131)) {
  14608. const result = this.parseStringLiteral(this.state.value);
  14609. const surrogate = result.value.match(loneSurrogate);
  14610. if (surrogate) {
  14611. this.raise(Errors.ModuleExportNameHasLoneSurrogate, {
  14612. at: result,
  14613. surrogateCharCode: surrogate[0].charCodeAt(0)
  14614. });
  14615. }
  14616. return result;
  14617. }
  14618. return this.parseIdentifier(true);
  14619. }
  14620. isJSONModuleImport(node) {
  14621. if (node.assertions != null) {
  14622. return node.assertions.some(({
  14623. key,
  14624. value
  14625. }) => {
  14626. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14627. });
  14628. }
  14629. return false;
  14630. }
  14631. checkImportReflection(node) {
  14632. if (node.module) {
  14633. var _node$assertions;
  14634. if (node.specifiers.length !== 1 || node.specifiers[0].type !== "ImportDefaultSpecifier") {
  14635. this.raise(Errors.ImportReflectionNotBinding, {
  14636. at: node.specifiers[0].loc.start
  14637. });
  14638. }
  14639. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14640. this.raise(Errors.ImportReflectionHasAssertion, {
  14641. at: node.specifiers[0].loc.start
  14642. });
  14643. }
  14644. }
  14645. }
  14646. checkJSONModuleImport(node) {
  14647. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14648. const {
  14649. specifiers
  14650. } = node;
  14651. if (specifiers != null) {
  14652. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14653. let imported;
  14654. if (specifier.type === "ExportSpecifier") {
  14655. imported = specifier.local;
  14656. } else if (specifier.type === "ImportSpecifier") {
  14657. imported = specifier.imported;
  14658. }
  14659. if (imported !== undefined) {
  14660. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14661. }
  14662. });
  14663. if (nonDefaultNamedSpecifier !== undefined) {
  14664. this.raise(Errors.ImportJSONBindingNotDefault, {
  14665. at: nonDefaultNamedSpecifier.loc.start
  14666. });
  14667. }
  14668. }
  14669. }
  14670. }
  14671. parseMaybeImportReflection(node) {
  14672. let isImportReflection = false;
  14673. if (this.isContextual(125)) {
  14674. const lookahead = this.lookahead();
  14675. const nextType = lookahead.type;
  14676. if (tokenIsIdentifier(nextType)) {
  14677. if (nextType !== 97) {
  14678. isImportReflection = true;
  14679. } else {
  14680. const nextNextTokenFirstChar = this.input.charCodeAt(this.nextTokenStartSince(lookahead.end));
  14681. if (nextNextTokenFirstChar === 102) {
  14682. isImportReflection = true;
  14683. }
  14684. }
  14685. } else if (nextType !== 12) {
  14686. isImportReflection = true;
  14687. }
  14688. }
  14689. if (isImportReflection) {
  14690. this.expectPlugin("importReflection");
  14691. this.next();
  14692. node.module = true;
  14693. } else if (this.hasPlugin("importReflection")) {
  14694. node.module = false;
  14695. }
  14696. }
  14697. parseImport(node) {
  14698. node.specifiers = [];
  14699. if (!this.match(131)) {
  14700. this.parseMaybeImportReflection(node);
  14701. const hasDefault = this.maybeParseDefaultImportSpecifier(node);
  14702. const parseNext = !hasDefault || this.eat(12);
  14703. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14704. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14705. this.expectContextual(97);
  14706. }
  14707. node.source = this.parseImportSource();
  14708. const assertions = this.maybeParseImportAssertions();
  14709. if (assertions) {
  14710. node.assertions = assertions;
  14711. } else {
  14712. const attributes = this.maybeParseModuleAttributes();
  14713. if (attributes) {
  14714. node.attributes = attributes;
  14715. }
  14716. }
  14717. this.checkImportReflection(node);
  14718. this.checkJSONModuleImport(node);
  14719. this.semicolon();
  14720. return this.finishNode(node, "ImportDeclaration");
  14721. }
  14722. parseImportSource() {
  14723. if (!this.match(131)) this.unexpected();
  14724. return this.parseExprAtom();
  14725. }
  14726. shouldParseDefaultImport(node) {
  14727. return tokenIsIdentifier(this.state.type);
  14728. }
  14729. parseImportSpecifierLocal(node, specifier, type) {
  14730. specifier.local = this.parseIdentifier();
  14731. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14732. }
  14733. finishImportSpecifier(specifier, type, bindingType = BIND_LEXICAL) {
  14734. this.checkLVal(specifier.local, {
  14735. in: {
  14736. type
  14737. },
  14738. binding: bindingType
  14739. });
  14740. return this.finishNode(specifier, type);
  14741. }
  14742. parseAssertEntries() {
  14743. const attrs = [];
  14744. const attrNames = new Set();
  14745. do {
  14746. if (this.match(8)) {
  14747. break;
  14748. }
  14749. const node = this.startNode();
  14750. const keyName = this.state.value;
  14751. if (attrNames.has(keyName)) {
  14752. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14753. at: this.state.startLoc,
  14754. key: keyName
  14755. });
  14756. }
  14757. attrNames.add(keyName);
  14758. if (this.match(131)) {
  14759. node.key = this.parseStringLiteral(keyName);
  14760. } else {
  14761. node.key = this.parseIdentifier(true);
  14762. }
  14763. this.expect(14);
  14764. if (!this.match(131)) {
  14765. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14766. at: this.state.startLoc
  14767. });
  14768. }
  14769. node.value = this.parseStringLiteral(this.state.value);
  14770. attrs.push(this.finishNode(node, "ImportAttribute"));
  14771. } while (this.eat(12));
  14772. return attrs;
  14773. }
  14774. maybeParseModuleAttributes() {
  14775. if (this.match(76) && !this.hasPrecedingLineBreak()) {
  14776. this.expectPlugin("moduleAttributes");
  14777. this.next();
  14778. } else {
  14779. if (this.hasPlugin("moduleAttributes")) return [];
  14780. return null;
  14781. }
  14782. const attrs = [];
  14783. const attributes = new Set();
  14784. do {
  14785. const node = this.startNode();
  14786. node.key = this.parseIdentifier(true);
  14787. if (node.key.name !== "type") {
  14788. this.raise(Errors.ModuleAttributeDifferentFromType, {
  14789. at: node.key
  14790. });
  14791. }
  14792. if (attributes.has(node.key.name)) {
  14793. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14794. at: node.key,
  14795. key: node.key.name
  14796. });
  14797. }
  14798. attributes.add(node.key.name);
  14799. this.expect(14);
  14800. if (!this.match(131)) {
  14801. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14802. at: this.state.startLoc
  14803. });
  14804. }
  14805. node.value = this.parseStringLiteral(this.state.value);
  14806. this.finishNode(node, "ImportAttribute");
  14807. attrs.push(node);
  14808. } while (this.eat(12));
  14809. return attrs;
  14810. }
  14811. maybeParseImportAssertions() {
  14812. if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14813. this.expectPlugin("importAssertions");
  14814. this.next();
  14815. } else {
  14816. if (this.hasPlugin("importAssertions")) return [];
  14817. return null;
  14818. }
  14819. this.eat(5);
  14820. const attrs = this.parseAssertEntries();
  14821. this.eat(8);
  14822. return attrs;
  14823. }
  14824. maybeParseDefaultImportSpecifier(node) {
  14825. if (this.shouldParseDefaultImport(node)) {
  14826. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14827. return true;
  14828. }
  14829. return false;
  14830. }
  14831. maybeParseStarImportSpecifier(node) {
  14832. if (this.match(55)) {
  14833. const specifier = this.startNode();
  14834. this.next();
  14835. this.expectContextual(93);
  14836. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14837. return true;
  14838. }
  14839. return false;
  14840. }
  14841. parseNamedImportSpecifiers(node) {
  14842. let first = true;
  14843. this.expect(5);
  14844. while (!this.eat(8)) {
  14845. if (first) {
  14846. first = false;
  14847. } else {
  14848. if (this.eat(14)) {
  14849. throw this.raise(Errors.DestructureNamedImport, {
  14850. at: this.state.startLoc
  14851. });
  14852. }
  14853. this.expect(12);
  14854. if (this.eat(8)) break;
  14855. }
  14856. const specifier = this.startNode();
  14857. const importedIsString = this.match(131);
  14858. const isMaybeTypeOnly = this.isContextual(128);
  14859. specifier.imported = this.parseModuleExportName();
  14860. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14861. node.specifiers.push(importSpecifier);
  14862. }
  14863. }
  14864. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14865. if (this.eatContextual(93)) {
  14866. specifier.local = this.parseIdentifier();
  14867. } else {
  14868. const {
  14869. imported
  14870. } = specifier;
  14871. if (importedIsString) {
  14872. throw this.raise(Errors.ImportBindingIsString, {
  14873. at: specifier,
  14874. importName: imported.value
  14875. });
  14876. }
  14877. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14878. if (!specifier.local) {
  14879. specifier.local = cloneIdentifier(imported);
  14880. }
  14881. }
  14882. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14883. }
  14884. isThisParam(param) {
  14885. return param.type === "Identifier" && param.name === "this";
  14886. }
  14887. }
  14888. let Parser$2 = class Parser extends StatementParser {
  14889. constructor(options, input) {
  14890. options = getOptions(options);
  14891. super(options, input);
  14892. this.options = options;
  14893. this.initializeScopes();
  14894. this.plugins = pluginsMap(this.options.plugins);
  14895. this.filename = options.sourceFilename;
  14896. }
  14897. getScopeHandler() {
  14898. return ScopeHandler;
  14899. }
  14900. parse() {
  14901. this.enterInitialScopes();
  14902. const file = this.startNode();
  14903. const program = this.startNode();
  14904. this.nextToken();
  14905. file.errors = null;
  14906. this.parseTopLevel(file, program);
  14907. file.errors = this.state.errors;
  14908. return file;
  14909. }
  14910. };
  14911. function pluginsMap(plugins) {
  14912. const pluginMap = new Map();
  14913. for (const plugin of plugins) {
  14914. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  14915. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  14916. }
  14917. return pluginMap;
  14918. }
  14919. function parse$9(input, options) {
  14920. var _options;
  14921. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14922. options = Object.assign({}, options);
  14923. try {
  14924. options.sourceType = "module";
  14925. const parser = getParser(options, input);
  14926. const ast = parser.parse();
  14927. if (parser.sawUnambiguousESM) {
  14928. return ast;
  14929. }
  14930. if (parser.ambiguousScriptDifferentAst) {
  14931. try {
  14932. options.sourceType = "script";
  14933. return getParser(options, input).parse();
  14934. } catch (_unused) {}
  14935. } else {
  14936. ast.program.sourceType = "script";
  14937. }
  14938. return ast;
  14939. } catch (moduleError) {
  14940. try {
  14941. options.sourceType = "script";
  14942. return getParser(options, input).parse();
  14943. } catch (_unused2) {}
  14944. throw moduleError;
  14945. }
  14946. } else {
  14947. return getParser(options, input).parse();
  14948. }
  14949. }
  14950. function parseExpression(input, options) {
  14951. const parser = getParser(options, input);
  14952. if (parser.options.strictMode) {
  14953. parser.state.strict = true;
  14954. }
  14955. return parser.getExpression();
  14956. }
  14957. function generateExportedTokenTypes(internalTokenTypes) {
  14958. const tokenTypes = {};
  14959. for (const typeName of Object.keys(internalTokenTypes)) {
  14960. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14961. }
  14962. return tokenTypes;
  14963. }
  14964. const tokTypes = generateExportedTokenTypes(tt);
  14965. function getParser(options, input) {
  14966. let cls = Parser$2;
  14967. if (options != null && options.plugins) {
  14968. validatePlugins(options.plugins);
  14969. cls = getParserClass(options.plugins);
  14970. }
  14971. return new cls(options, input);
  14972. }
  14973. const parserClassCache = {};
  14974. function getParserClass(pluginsFromOptions) {
  14975. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  14976. const key = pluginList.join("/");
  14977. let cls = parserClassCache[key];
  14978. if (!cls) {
  14979. cls = Parser$2;
  14980. for (const plugin of pluginList) {
  14981. cls = mixinPlugins[plugin](cls);
  14982. }
  14983. parserClassCache[key] = cls;
  14984. }
  14985. return cls;
  14986. }
  14987. var parse_1$1 = lib.parse = parse$9;
  14988. var parseExpression_1 = lib.parseExpression = parseExpression;
  14989. lib.tokTypes = tokTypes;
  14990. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  14991. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  14992. function isCoreComponent(tag) {
  14993. if (isBuiltInType(tag, "Teleport")) {
  14994. return TELEPORT;
  14995. } else if (isBuiltInType(tag, "Suspense")) {
  14996. return SUSPENSE;
  14997. } else if (isBuiltInType(tag, "KeepAlive")) {
  14998. return KEEP_ALIVE;
  14999. } else if (isBuiltInType(tag, "BaseTransition")) {
  15000. return BASE_TRANSITION;
  15001. }
  15002. }
  15003. const nonIdentifierRE = /^\d|[^\$\w]/;
  15004. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  15005. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  15006. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  15007. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  15008. const isMemberExpressionBrowser = (path) => {
  15009. path = path.trim().replace(whitespaceRE, (s) => s.trim());
  15010. let state = 0 /* inMemberExp */;
  15011. let stateStack = [];
  15012. let currentOpenBracketCount = 0;
  15013. let currentOpenParensCount = 0;
  15014. let currentStringType = null;
  15015. for (let i = 0; i < path.length; i++) {
  15016. const char = path.charAt(i);
  15017. switch (state) {
  15018. case 0 /* inMemberExp */:
  15019. if (char === "[") {
  15020. stateStack.push(state);
  15021. state = 1 /* inBrackets */;
  15022. currentOpenBracketCount++;
  15023. } else if (char === "(") {
  15024. stateStack.push(state);
  15025. state = 2 /* inParens */;
  15026. currentOpenParensCount++;
  15027. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  15028. return false;
  15029. }
  15030. break;
  15031. case 1 /* inBrackets */:
  15032. if (char === `'` || char === `"` || char === "`") {
  15033. stateStack.push(state);
  15034. state = 3 /* inString */;
  15035. currentStringType = char;
  15036. } else if (char === `[`) {
  15037. currentOpenBracketCount++;
  15038. } else if (char === `]`) {
  15039. if (!--currentOpenBracketCount) {
  15040. state = stateStack.pop();
  15041. }
  15042. }
  15043. break;
  15044. case 2 /* inParens */:
  15045. if (char === `'` || char === `"` || char === "`") {
  15046. stateStack.push(state);
  15047. state = 3 /* inString */;
  15048. currentStringType = char;
  15049. } else if (char === `(`) {
  15050. currentOpenParensCount++;
  15051. } else if (char === `)`) {
  15052. if (i === path.length - 1) {
  15053. return false;
  15054. }
  15055. if (!--currentOpenParensCount) {
  15056. state = stateStack.pop();
  15057. }
  15058. }
  15059. break;
  15060. case 3 /* inString */:
  15061. if (char === currentStringType) {
  15062. state = stateStack.pop();
  15063. currentStringType = null;
  15064. }
  15065. break;
  15066. }
  15067. }
  15068. return !currentOpenBracketCount && !currentOpenParensCount;
  15069. };
  15070. const isMemberExpressionNode = (path, context) => {
  15071. try {
  15072. let ret = parseExpression_1(path, {
  15073. plugins: context.expressionPlugins
  15074. });
  15075. if (ret.type === "TSAsExpression" || ret.type === "TSTypeAssertion") {
  15076. ret = ret.expression;
  15077. }
  15078. return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier";
  15079. } catch (e) {
  15080. return false;
  15081. }
  15082. };
  15083. const isMemberExpression = isMemberExpressionNode;
  15084. function getInnerRange(loc, offset, length) {
  15085. const source = loc.source.slice(offset, offset + length);
  15086. const newLoc = {
  15087. source,
  15088. start: advancePositionWithClone(loc.start, loc.source, offset),
  15089. end: loc.end
  15090. };
  15091. if (length != null) {
  15092. newLoc.end = advancePositionWithClone(
  15093. loc.start,
  15094. loc.source,
  15095. offset + length
  15096. );
  15097. }
  15098. return newLoc;
  15099. }
  15100. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  15101. return advancePositionWithMutation(
  15102. extend({}, pos),
  15103. source,
  15104. numberOfCharacters
  15105. );
  15106. }
  15107. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  15108. let linesCount = 0;
  15109. let lastNewLinePos = -1;
  15110. for (let i = 0; i < numberOfCharacters; i++) {
  15111. if (source.charCodeAt(i) === 10) {
  15112. linesCount++;
  15113. lastNewLinePos = i;
  15114. }
  15115. }
  15116. pos.offset += numberOfCharacters;
  15117. pos.line += linesCount;
  15118. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  15119. return pos;
  15120. }
  15121. function assert(condition, msg) {
  15122. if (!condition) {
  15123. throw new Error(msg || `unexpected compiler condition`);
  15124. }
  15125. }
  15126. function findDir(node, name, allowEmpty = false) {
  15127. for (let i = 0; i < node.props.length; i++) {
  15128. const p = node.props[i];
  15129. if (p.type === 7 && (allowEmpty || p.exp) && (isString$2(name) ? p.name === name : name.test(p.name))) {
  15130. return p;
  15131. }
  15132. }
  15133. }
  15134. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  15135. for (let i = 0; i < node.props.length; i++) {
  15136. const p = node.props[i];
  15137. if (p.type === 6) {
  15138. if (dynamicOnly)
  15139. continue;
  15140. if (p.name === name && (p.value || allowEmpty)) {
  15141. return p;
  15142. }
  15143. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  15144. return p;
  15145. }
  15146. }
  15147. }
  15148. function isStaticArgOf(arg, name) {
  15149. return !!(arg && isStaticExp(arg) && arg.content === name);
  15150. }
  15151. function hasDynamicKeyVBind(node) {
  15152. return node.props.some(
  15153. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  15154. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  15155. !p.arg.isStatic)
  15156. // v-bind:[foo]
  15157. );
  15158. }
  15159. function isText$1(node) {
  15160. return node.type === 5 || node.type === 2;
  15161. }
  15162. function isVSlot(p) {
  15163. return p.type === 7 && p.name === "slot";
  15164. }
  15165. function isTemplateNode(node) {
  15166. return node.type === 1 && node.tagType === 3;
  15167. }
  15168. function isSlotOutlet(node) {
  15169. return node.type === 1 && node.tagType === 2;
  15170. }
  15171. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  15172. function getUnnormalizedProps(props, callPath = []) {
  15173. if (props && !isString$2(props) && props.type === 14) {
  15174. const callee = props.callee;
  15175. if (!isString$2(callee) && propsHelperSet.has(callee)) {
  15176. return getUnnormalizedProps(
  15177. props.arguments[0],
  15178. callPath.concat(props)
  15179. );
  15180. }
  15181. }
  15182. return [props, callPath];
  15183. }
  15184. function injectProp(node, prop, context) {
  15185. let propsWithInjection;
  15186. let props = node.type === 13 ? node.props : node.arguments[2];
  15187. let callPath = [];
  15188. let parentCall;
  15189. if (props && !isString$2(props) && props.type === 14) {
  15190. const ret = getUnnormalizedProps(props);
  15191. props = ret[0];
  15192. callPath = ret[1];
  15193. parentCall = callPath[callPath.length - 1];
  15194. }
  15195. if (props == null || isString$2(props)) {
  15196. propsWithInjection = createObjectExpression([prop]);
  15197. } else if (props.type === 14) {
  15198. const first = props.arguments[0];
  15199. if (!isString$2(first) && first.type === 15) {
  15200. if (!hasProp(prop, first)) {
  15201. first.properties.unshift(prop);
  15202. }
  15203. } else {
  15204. if (props.callee === TO_HANDLERS) {
  15205. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  15206. createObjectExpression([prop]),
  15207. props
  15208. ]);
  15209. } else {
  15210. props.arguments.unshift(createObjectExpression([prop]));
  15211. }
  15212. }
  15213. !propsWithInjection && (propsWithInjection = props);
  15214. } else if (props.type === 15) {
  15215. if (!hasProp(prop, props)) {
  15216. props.properties.unshift(prop);
  15217. }
  15218. propsWithInjection = props;
  15219. } else {
  15220. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  15221. createObjectExpression([prop]),
  15222. props
  15223. ]);
  15224. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  15225. parentCall = callPath[callPath.length - 2];
  15226. }
  15227. }
  15228. if (node.type === 13) {
  15229. if (parentCall) {
  15230. parentCall.arguments[0] = propsWithInjection;
  15231. } else {
  15232. node.props = propsWithInjection;
  15233. }
  15234. } else {
  15235. if (parentCall) {
  15236. parentCall.arguments[0] = propsWithInjection;
  15237. } else {
  15238. node.arguments[2] = propsWithInjection;
  15239. }
  15240. }
  15241. }
  15242. function hasProp(prop, props) {
  15243. let result = false;
  15244. if (prop.key.type === 4) {
  15245. const propKeyName = prop.key.content;
  15246. result = props.properties.some(
  15247. (p) => p.key.type === 4 && p.key.content === propKeyName
  15248. );
  15249. }
  15250. return result;
  15251. }
  15252. function toValidAssetId(name, type) {
  15253. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  15254. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  15255. })}`;
  15256. }
  15257. function hasScopeRef(node, ids) {
  15258. if (!node || Object.keys(ids).length === 0) {
  15259. return false;
  15260. }
  15261. switch (node.type) {
  15262. case 1:
  15263. for (let i = 0; i < node.props.length; i++) {
  15264. const p = node.props[i];
  15265. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  15266. return true;
  15267. }
  15268. }
  15269. return node.children.some((c) => hasScopeRef(c, ids));
  15270. case 11:
  15271. if (hasScopeRef(node.source, ids)) {
  15272. return true;
  15273. }
  15274. return node.children.some((c) => hasScopeRef(c, ids));
  15275. case 9:
  15276. return node.branches.some((b) => hasScopeRef(b, ids));
  15277. case 10:
  15278. if (hasScopeRef(node.condition, ids)) {
  15279. return true;
  15280. }
  15281. return node.children.some((c) => hasScopeRef(c, ids));
  15282. case 4:
  15283. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  15284. case 8:
  15285. return node.children.some((c) => isObject$2(c) && hasScopeRef(c, ids));
  15286. case 5:
  15287. case 12:
  15288. return hasScopeRef(node.content, ids);
  15289. case 2:
  15290. case 3:
  15291. return false;
  15292. default:
  15293. return false;
  15294. }
  15295. }
  15296. function getMemoedVNodeCall(node) {
  15297. if (node.type === 14 && node.callee === WITH_MEMO) {
  15298. return node.arguments[1].returns;
  15299. } else {
  15300. return node;
  15301. }
  15302. }
  15303. const deprecationData = {
  15304. ["COMPILER_IS_ON_ELEMENT"]: {
  15305. message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`,
  15306. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  15307. },
  15308. ["COMPILER_V_BIND_SYNC"]: {
  15309. message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`,
  15310. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  15311. },
  15312. ["COMPILER_V_BIND_PROP"]: {
  15313. message: `.prop modifier for v-bind has been removed and no longer necessary. Vue 3 will automatically set a binding as DOM property when appropriate.`
  15314. },
  15315. ["COMPILER_V_BIND_OBJECT_ORDER"]: {
  15316. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.`,
  15317. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  15318. },
  15319. ["COMPILER_V_ON_NATIVE"]: {
  15320. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  15321. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  15322. },
  15323. ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
  15324. message: `v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.`,
  15325. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  15326. },
  15327. ["COMPILER_NATIVE_TEMPLATE"]: {
  15328. message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
  15329. },
  15330. ["COMPILER_INLINE_TEMPLATE"]: {
  15331. message: `"inline-template" has been removed in Vue 3.`,
  15332. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  15333. },
  15334. ["COMPILER_FILTER"]: {
  15335. message: `filters have been removed in Vue 3. The "|" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.`,
  15336. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  15337. }
  15338. };
  15339. function getCompatValue(key, context) {
  15340. const config = context.options ? context.options.compatConfig : context.compatConfig;
  15341. const value = config && config[key];
  15342. if (key === "MODE") {
  15343. return value || 3;
  15344. } else {
  15345. return value;
  15346. }
  15347. }
  15348. function isCompatEnabled(key, context) {
  15349. const mode = getCompatValue("MODE", context);
  15350. const value = getCompatValue(key, context);
  15351. return mode === 3 ? value === true : value !== false;
  15352. }
  15353. function checkCompatEnabled(key, context, loc, ...args) {
  15354. const enabled = isCompatEnabled(key, context);
  15355. if (enabled) {
  15356. warnDeprecation(key, context, loc, ...args);
  15357. }
  15358. return enabled;
  15359. }
  15360. function warnDeprecation(key, context, loc, ...args) {
  15361. const val = getCompatValue(key, context);
  15362. if (val === "suppress-warning") {
  15363. return;
  15364. }
  15365. const { message, link } = deprecationData[key];
  15366. const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
  15367. Details: ${link}` : ``}`;
  15368. const err = new SyntaxError(msg);
  15369. err.code = key;
  15370. if (loc)
  15371. err.loc = loc;
  15372. context.onWarn(err);
  15373. }
  15374. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  15375. const decodeMap = {
  15376. gt: ">",
  15377. lt: "<",
  15378. amp: "&",
  15379. apos: "'",
  15380. quot: '"'
  15381. };
  15382. const defaultParserOptions = {
  15383. delimiters: [`{{`, `}}`],
  15384. getNamespace: () => 0,
  15385. getTextMode: () => 0,
  15386. isVoidTag: NO,
  15387. isPreTag: NO,
  15388. isCustomElement: NO,
  15389. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  15390. onError: defaultOnError,
  15391. onWarn: defaultOnWarn,
  15392. comments: true
  15393. };
  15394. function baseParse(content, options = {}) {
  15395. const context = createParserContext(content, options);
  15396. const start = getCursor(context);
  15397. return createRoot(
  15398. parseChildren(context, 0, []),
  15399. getSelection(context, start)
  15400. );
  15401. }
  15402. function createParserContext(content, rawOptions) {
  15403. const options = extend({}, defaultParserOptions);
  15404. let key;
  15405. for (key in rawOptions) {
  15406. options[key] = rawOptions[key] === void 0 ? defaultParserOptions[key] : rawOptions[key];
  15407. }
  15408. return {
  15409. options,
  15410. column: 1,
  15411. line: 1,
  15412. offset: 0,
  15413. originalSource: content,
  15414. source: content,
  15415. inPre: false,
  15416. inVPre: false,
  15417. onWarn: options.onWarn
  15418. };
  15419. }
  15420. function parseChildren(context, mode, ancestors) {
  15421. const parent = last(ancestors);
  15422. const ns = parent ? parent.ns : 0;
  15423. const nodes = [];
  15424. while (!isEnd(context, mode, ancestors)) {
  15425. const s = context.source;
  15426. let node = void 0;
  15427. if (mode === 0 || mode === 1) {
  15428. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  15429. node = parseInterpolation(context, mode);
  15430. } else if (mode === 0 && s[0] === "<") {
  15431. if (s.length === 1) {
  15432. emitError(context, 5, 1);
  15433. } else if (s[1] === "!") {
  15434. if (startsWith(s, "<!--")) {
  15435. node = parseComment(context);
  15436. } else if (startsWith(s, "<!DOCTYPE")) {
  15437. node = parseBogusComment(context);
  15438. } else if (startsWith(s, "<![CDATA[")) {
  15439. if (ns !== 0) {
  15440. node = parseCDATA(context, ancestors);
  15441. } else {
  15442. emitError(context, 1);
  15443. node = parseBogusComment(context);
  15444. }
  15445. } else {
  15446. emitError(context, 11);
  15447. node = parseBogusComment(context);
  15448. }
  15449. } else if (s[1] === "/") {
  15450. if (s.length === 2) {
  15451. emitError(context, 5, 2);
  15452. } else if (s[2] === ">") {
  15453. emitError(context, 14, 2);
  15454. advanceBy(context, 3);
  15455. continue;
  15456. } else if (/[a-z]/i.test(s[2])) {
  15457. emitError(context, 23);
  15458. parseTag(context, TagType.End, parent);
  15459. continue;
  15460. } else {
  15461. emitError(
  15462. context,
  15463. 12,
  15464. 2
  15465. );
  15466. node = parseBogusComment(context);
  15467. }
  15468. } else if (/[a-z]/i.test(s[1])) {
  15469. node = parseElement(context, ancestors);
  15470. } else if (s[1] === "?") {
  15471. emitError(
  15472. context,
  15473. 21,
  15474. 1
  15475. );
  15476. node = parseBogusComment(context);
  15477. } else {
  15478. emitError(context, 12, 1);
  15479. }
  15480. }
  15481. }
  15482. if (!node) {
  15483. node = parseText(context, mode);
  15484. }
  15485. if (isArray$3(node)) {
  15486. for (let i = 0; i < node.length; i++) {
  15487. pushNode(nodes, node[i]);
  15488. }
  15489. } else {
  15490. pushNode(nodes, node);
  15491. }
  15492. }
  15493. let removedWhitespace = false;
  15494. if (mode !== 2 && mode !== 1) {
  15495. const shouldCondense = context.options.whitespace !== "preserve";
  15496. for (let i = 0; i < nodes.length; i++) {
  15497. const node = nodes[i];
  15498. if (node.type === 2) {
  15499. if (!context.inPre) {
  15500. if (!/[^\t\r\n\f ]/.test(node.content)) {
  15501. const prev = nodes[i - 1];
  15502. const next = nodes[i + 1];
  15503. if (!prev || !next || shouldCondense && (prev.type === 3 && next.type === 3 || prev.type === 3 && next.type === 1 || prev.type === 1 && next.type === 3 || prev.type === 1 && next.type === 1 && /[\r\n]/.test(node.content))) {
  15504. removedWhitespace = true;
  15505. nodes[i] = null;
  15506. } else {
  15507. node.content = " ";
  15508. }
  15509. } else if (shouldCondense) {
  15510. node.content = node.content.replace(/[\t\r\n\f ]+/g, " ");
  15511. }
  15512. } else {
  15513. node.content = node.content.replace(/\r\n/g, "\n");
  15514. }
  15515. } else if (node.type === 3 && !context.options.comments) {
  15516. removedWhitespace = true;
  15517. nodes[i] = null;
  15518. }
  15519. }
  15520. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  15521. const first = nodes[0];
  15522. if (first && first.type === 2) {
  15523. first.content = first.content.replace(/^\r?\n/, "");
  15524. }
  15525. }
  15526. }
  15527. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  15528. }
  15529. function pushNode(nodes, node) {
  15530. if (node.type === 2) {
  15531. const prev = last(nodes);
  15532. if (prev && prev.type === 2 && prev.loc.end.offset === node.loc.start.offset) {
  15533. prev.content += node.content;
  15534. prev.loc.end = node.loc.end;
  15535. prev.loc.source += node.loc.source;
  15536. return;
  15537. }
  15538. }
  15539. nodes.push(node);
  15540. }
  15541. function parseCDATA(context, ancestors) {
  15542. advanceBy(context, 9);
  15543. const nodes = parseChildren(context, 3, ancestors);
  15544. if (context.source.length === 0) {
  15545. emitError(context, 6);
  15546. } else {
  15547. advanceBy(context, 3);
  15548. }
  15549. return nodes;
  15550. }
  15551. function parseComment(context) {
  15552. const start = getCursor(context);
  15553. let content;
  15554. const match = /--(\!)?>/.exec(context.source);
  15555. if (!match) {
  15556. content = context.source.slice(4);
  15557. advanceBy(context, context.source.length);
  15558. emitError(context, 7);
  15559. } else {
  15560. if (match.index <= 3) {
  15561. emitError(context, 0);
  15562. }
  15563. if (match[1]) {
  15564. emitError(context, 10);
  15565. }
  15566. content = context.source.slice(4, match.index);
  15567. const s = context.source.slice(0, match.index);
  15568. let prevIndex = 1, nestedIndex = 0;
  15569. while ((nestedIndex = s.indexOf("<!--", prevIndex)) !== -1) {
  15570. advanceBy(context, nestedIndex - prevIndex + 1);
  15571. if (nestedIndex + 4 < s.length) {
  15572. emitError(context, 16);
  15573. }
  15574. prevIndex = nestedIndex + 1;
  15575. }
  15576. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  15577. }
  15578. return {
  15579. type: 3,
  15580. content,
  15581. loc: getSelection(context, start)
  15582. };
  15583. }
  15584. function parseBogusComment(context) {
  15585. const start = getCursor(context);
  15586. const contentStart = context.source[1] === "?" ? 1 : 2;
  15587. let content;
  15588. const closeIndex = context.source.indexOf(">");
  15589. if (closeIndex === -1) {
  15590. content = context.source.slice(contentStart);
  15591. advanceBy(context, context.source.length);
  15592. } else {
  15593. content = context.source.slice(contentStart, closeIndex);
  15594. advanceBy(context, closeIndex + 1);
  15595. }
  15596. return {
  15597. type: 3,
  15598. content,
  15599. loc: getSelection(context, start)
  15600. };
  15601. }
  15602. function parseElement(context, ancestors) {
  15603. const wasInPre = context.inPre;
  15604. const wasInVPre = context.inVPre;
  15605. const parent = last(ancestors);
  15606. const element = parseTag(context, TagType.Start, parent);
  15607. const isPreBoundary = context.inPre && !wasInPre;
  15608. const isVPreBoundary = context.inVPre && !wasInVPre;
  15609. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  15610. if (isPreBoundary) {
  15611. context.inPre = false;
  15612. }
  15613. if (isVPreBoundary) {
  15614. context.inVPre = false;
  15615. }
  15616. return element;
  15617. }
  15618. ancestors.push(element);
  15619. const mode = context.options.getTextMode(element, parent);
  15620. const children = parseChildren(context, mode, ancestors);
  15621. ancestors.pop();
  15622. element.children = children;
  15623. if (startsWithEndTagOpen(context.source, element.tag)) {
  15624. parseTag(context, TagType.End, parent);
  15625. } else {
  15626. emitError(context, 24, 0, element.loc.start);
  15627. if (context.source.length === 0 && element.tag.toLowerCase() === "script") {
  15628. const first = children[0];
  15629. if (first && startsWith(first.loc.source, "<!--")) {
  15630. emitError(context, 8);
  15631. }
  15632. }
  15633. }
  15634. element.loc = getSelection(context, element.loc.start);
  15635. if (isPreBoundary) {
  15636. context.inPre = false;
  15637. }
  15638. if (isVPreBoundary) {
  15639. context.inVPre = false;
  15640. }
  15641. return element;
  15642. }
  15643. var TagType = /* @__PURE__ */ ((TagType2) => {
  15644. TagType2[TagType2["Start"] = 0] = "Start";
  15645. TagType2[TagType2["End"] = 1] = "End";
  15646. return TagType2;
  15647. })(TagType || {});
  15648. const isSpecialTemplateDirective = /* @__PURE__ */ makeMap(
  15649. `if,else,else-if,for,slot`
  15650. );
  15651. function parseTag(context, type, parent) {
  15652. const start = getCursor(context);
  15653. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  15654. const tag = match[1];
  15655. const ns = context.options.getNamespace(tag, parent);
  15656. advanceBy(context, match[0].length);
  15657. advanceSpaces(context);
  15658. const cursor = getCursor(context);
  15659. const currentSource = context.source;
  15660. if (context.options.isPreTag(tag)) {
  15661. context.inPre = true;
  15662. }
  15663. let props = parseAttributes(context, type);
  15664. if (type === 0 /* Start */ && !context.inVPre && props.some((p) => p.type === 7 && p.name === "pre")) {
  15665. context.inVPre = true;
  15666. extend(context, cursor);
  15667. context.source = currentSource;
  15668. props = parseAttributes(context, type).filter((p) => p.name !== "v-pre");
  15669. }
  15670. let isSelfClosing = false;
  15671. if (context.source.length === 0) {
  15672. emitError(context, 9);
  15673. } else {
  15674. isSelfClosing = startsWith(context.source, "/>");
  15675. if (type === 1 /* End */ && isSelfClosing) {
  15676. emitError(context, 4);
  15677. }
  15678. advanceBy(context, isSelfClosing ? 2 : 1);
  15679. }
  15680. if (type === 1 /* End */) {
  15681. return;
  15682. }
  15683. let tagType = 0;
  15684. if (!context.inVPre) {
  15685. if (tag === "slot") {
  15686. tagType = 2;
  15687. } else if (tag === "template") {
  15688. if (props.some(
  15689. (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
  15690. )) {
  15691. tagType = 3;
  15692. }
  15693. } else if (isComponent(tag, props, context)) {
  15694. tagType = 1;
  15695. }
  15696. }
  15697. return {
  15698. type: 1,
  15699. ns,
  15700. tag,
  15701. tagType,
  15702. props,
  15703. isSelfClosing,
  15704. children: [],
  15705. loc: getSelection(context, start),
  15706. codegenNode: void 0
  15707. // to be created during transform phase
  15708. };
  15709. }
  15710. function isComponent(tag, props, context) {
  15711. const options = context.options;
  15712. if (options.isCustomElement(tag)) {
  15713. return false;
  15714. }
  15715. if (tag === "component" || /^[A-Z]/.test(tag) || isCoreComponent(tag) || options.isBuiltInComponent && options.isBuiltInComponent(tag) || options.isNativeTag && !options.isNativeTag(tag)) {
  15716. return true;
  15717. }
  15718. for (let i = 0; i < props.length; i++) {
  15719. const p = props[i];
  15720. if (p.type === 6) {
  15721. if (p.name === "is" && p.value) {
  15722. if (p.value.content.startsWith("vue:")) {
  15723. return true;
  15724. }
  15725. }
  15726. } else {
  15727. if (p.name === "is") {
  15728. return true;
  15729. } else if (
  15730. // :is on plain element - only treat as component in compat mode
  15731. p.name === "bind" && isStaticArgOf(p.arg, "is") && false
  15732. ) {
  15733. return true;
  15734. }
  15735. }
  15736. }
  15737. }
  15738. function parseAttributes(context, type) {
  15739. const props = [];
  15740. const attributeNames = /* @__PURE__ */ new Set();
  15741. while (context.source.length > 0 && !startsWith(context.source, ">") && !startsWith(context.source, "/>")) {
  15742. if (startsWith(context.source, "/")) {
  15743. emitError(context, 22);
  15744. advanceBy(context, 1);
  15745. advanceSpaces(context);
  15746. continue;
  15747. }
  15748. if (type === 1 /* End */) {
  15749. emitError(context, 3);
  15750. }
  15751. const attr = parseAttribute(context, attributeNames);
  15752. if (attr.type === 6 && attr.value && attr.name === "class") {
  15753. attr.value.content = attr.value.content.replace(/\s+/g, " ").trim();
  15754. }
  15755. if (type === 0 /* Start */) {
  15756. props.push(attr);
  15757. }
  15758. if (/^[^\t\r\n\f />]/.test(context.source)) {
  15759. emitError(context, 15);
  15760. }
  15761. advanceSpaces(context);
  15762. }
  15763. return props;
  15764. }
  15765. function parseAttribute(context, nameSet) {
  15766. var _a;
  15767. const start = getCursor(context);
  15768. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  15769. const name = match[0];
  15770. if (nameSet.has(name)) {
  15771. emitError(context, 2);
  15772. }
  15773. nameSet.add(name);
  15774. if (name[0] === "=") {
  15775. emitError(context, 19);
  15776. }
  15777. {
  15778. const pattern = /["'<]/g;
  15779. let m;
  15780. while (m = pattern.exec(name)) {
  15781. emitError(
  15782. context,
  15783. 17,
  15784. m.index
  15785. );
  15786. }
  15787. }
  15788. advanceBy(context, name.length);
  15789. let value = void 0;
  15790. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  15791. advanceSpaces(context);
  15792. advanceBy(context, 1);
  15793. advanceSpaces(context);
  15794. value = parseAttributeValue(context);
  15795. if (!value) {
  15796. emitError(context, 13);
  15797. }
  15798. }
  15799. const loc = getSelection(context, start);
  15800. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  15801. const match2 = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
  15802. name
  15803. );
  15804. let isPropShorthand = startsWith(name, ".");
  15805. let dirName = match2[1] || (isPropShorthand || startsWith(name, ":") ? "bind" : startsWith(name, "@") ? "on" : "slot");
  15806. let arg;
  15807. if (match2[2]) {
  15808. const isSlot = dirName === "slot";
  15809. const startOffset = name.lastIndexOf(
  15810. match2[2],
  15811. name.length - (((_a = match2[3]) == null ? void 0 : _a.length) || 0)
  15812. );
  15813. const loc2 = getSelection(
  15814. context,
  15815. getNewPosition(context, start, startOffset),
  15816. getNewPosition(
  15817. context,
  15818. start,
  15819. startOffset + match2[2].length + (isSlot && match2[3] || "").length
  15820. )
  15821. );
  15822. let content = match2[2];
  15823. let isStatic = true;
  15824. if (content.startsWith("[")) {
  15825. isStatic = false;
  15826. if (!content.endsWith("]")) {
  15827. emitError(
  15828. context,
  15829. 27
  15830. );
  15831. content = content.slice(1);
  15832. } else {
  15833. content = content.slice(1, content.length - 1);
  15834. }
  15835. } else if (isSlot) {
  15836. content += match2[3] || "";
  15837. }
  15838. arg = {
  15839. type: 4,
  15840. content,
  15841. isStatic,
  15842. constType: isStatic ? 3 : 0,
  15843. loc: loc2
  15844. };
  15845. }
  15846. if (value && value.isQuoted) {
  15847. const valueLoc = value.loc;
  15848. valueLoc.start.offset++;
  15849. valueLoc.start.column++;
  15850. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  15851. valueLoc.source = valueLoc.source.slice(1, -1);
  15852. }
  15853. const modifiers = match2[3] ? match2[3].slice(1).split(".") : [];
  15854. if (isPropShorthand)
  15855. modifiers.push("prop");
  15856. return {
  15857. type: 7,
  15858. name: dirName,
  15859. exp: value && {
  15860. type: 4,
  15861. content: value.content,
  15862. isStatic: false,
  15863. // Treat as non-constant by default. This can be potentially set to
  15864. // other values by `transformExpression` to make it eligible for hoisting.
  15865. constType: 0,
  15866. loc: value.loc
  15867. },
  15868. arg,
  15869. modifiers,
  15870. loc
  15871. };
  15872. }
  15873. if (!context.inVPre && startsWith(name, "v-")) {
  15874. emitError(context, 26);
  15875. }
  15876. return {
  15877. type: 6,
  15878. name,
  15879. value: value && {
  15880. type: 2,
  15881. content: value.content,
  15882. loc: value.loc
  15883. },
  15884. loc
  15885. };
  15886. }
  15887. function parseAttributeValue(context) {
  15888. const start = getCursor(context);
  15889. let content;
  15890. const quote = context.source[0];
  15891. const isQuoted = quote === `"` || quote === `'`;
  15892. if (isQuoted) {
  15893. advanceBy(context, 1);
  15894. const endIndex = context.source.indexOf(quote);
  15895. if (endIndex === -1) {
  15896. content = parseTextData(
  15897. context,
  15898. context.source.length,
  15899. 4
  15900. );
  15901. } else {
  15902. content = parseTextData(context, endIndex, 4);
  15903. advanceBy(context, 1);
  15904. }
  15905. } else {
  15906. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  15907. if (!match) {
  15908. return void 0;
  15909. }
  15910. const unexpectedChars = /["'<=`]/g;
  15911. let m;
  15912. while (m = unexpectedChars.exec(match[0])) {
  15913. emitError(
  15914. context,
  15915. 18,
  15916. m.index
  15917. );
  15918. }
  15919. content = parseTextData(context, match[0].length, 4);
  15920. }
  15921. return { content, isQuoted, loc: getSelection(context, start) };
  15922. }
  15923. function parseInterpolation(context, mode) {
  15924. const [open, close] = context.options.delimiters;
  15925. const closeIndex = context.source.indexOf(close, open.length);
  15926. if (closeIndex === -1) {
  15927. emitError(context, 25);
  15928. return void 0;
  15929. }
  15930. const start = getCursor(context);
  15931. advanceBy(context, open.length);
  15932. const innerStart = getCursor(context);
  15933. const innerEnd = getCursor(context);
  15934. const rawContentLength = closeIndex - open.length;
  15935. const rawContent = context.source.slice(0, rawContentLength);
  15936. const preTrimContent = parseTextData(context, rawContentLength, mode);
  15937. const content = preTrimContent.trim();
  15938. const startOffset = preTrimContent.indexOf(content);
  15939. if (startOffset > 0) {
  15940. advancePositionWithMutation(innerStart, rawContent, startOffset);
  15941. }
  15942. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  15943. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  15944. advanceBy(context, close.length);
  15945. return {
  15946. type: 5,
  15947. content: {
  15948. type: 4,
  15949. isStatic: false,
  15950. // Set `isConstant` to false by default and will decide in transformExpression
  15951. constType: 0,
  15952. content,
  15953. loc: getSelection(context, innerStart, innerEnd)
  15954. },
  15955. loc: getSelection(context, start)
  15956. };
  15957. }
  15958. function parseText(context, mode) {
  15959. const endTokens = mode === 3 ? ["]]>"] : ["<", context.options.delimiters[0]];
  15960. let endIndex = context.source.length;
  15961. for (let i = 0; i < endTokens.length; i++) {
  15962. const index = context.source.indexOf(endTokens[i], 1);
  15963. if (index !== -1 && endIndex > index) {
  15964. endIndex = index;
  15965. }
  15966. }
  15967. const start = getCursor(context);
  15968. const content = parseTextData(context, endIndex, mode);
  15969. return {
  15970. type: 2,
  15971. content,
  15972. loc: getSelection(context, start)
  15973. };
  15974. }
  15975. function parseTextData(context, length, mode) {
  15976. const rawText = context.source.slice(0, length);
  15977. advanceBy(context, length);
  15978. if (mode === 2 || mode === 3 || !rawText.includes("&")) {
  15979. return rawText;
  15980. } else {
  15981. return context.options.decodeEntities(
  15982. rawText,
  15983. mode === 4
  15984. );
  15985. }
  15986. }
  15987. function getCursor(context) {
  15988. const { column, line, offset } = context;
  15989. return { column, line, offset };
  15990. }
  15991. function getSelection(context, start, end) {
  15992. end = end || getCursor(context);
  15993. return {
  15994. start,
  15995. end,
  15996. source: context.originalSource.slice(start.offset, end.offset)
  15997. };
  15998. }
  15999. function last(xs) {
  16000. return xs[xs.length - 1];
  16001. }
  16002. function startsWith(source, searchString) {
  16003. return source.startsWith(searchString);
  16004. }
  16005. function advanceBy(context, numberOfCharacters) {
  16006. const { source } = context;
  16007. advancePositionWithMutation(context, source, numberOfCharacters);
  16008. context.source = source.slice(numberOfCharacters);
  16009. }
  16010. function advanceSpaces(context) {
  16011. const match = /^[\t\r\n\f ]+/.exec(context.source);
  16012. if (match) {
  16013. advanceBy(context, match[0].length);
  16014. }
  16015. }
  16016. function getNewPosition(context, start, numberOfCharacters) {
  16017. return advancePositionWithClone(
  16018. start,
  16019. context.originalSource.slice(start.offset, numberOfCharacters),
  16020. numberOfCharacters
  16021. );
  16022. }
  16023. function emitError(context, code, offset, loc = getCursor(context)) {
  16024. if (offset) {
  16025. loc.offset += offset;
  16026. loc.column += offset;
  16027. }
  16028. context.options.onError(
  16029. createCompilerError(code, {
  16030. start: loc,
  16031. end: loc,
  16032. source: ""
  16033. })
  16034. );
  16035. }
  16036. function isEnd(context, mode, ancestors) {
  16037. const s = context.source;
  16038. switch (mode) {
  16039. case 0:
  16040. if (startsWith(s, "</")) {
  16041. for (let i = ancestors.length - 1; i >= 0; --i) {
  16042. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  16043. return true;
  16044. }
  16045. }
  16046. }
  16047. break;
  16048. case 1:
  16049. case 2: {
  16050. const parent = last(ancestors);
  16051. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  16052. return true;
  16053. }
  16054. break;
  16055. }
  16056. case 3:
  16057. if (startsWith(s, "]]>")) {
  16058. return true;
  16059. }
  16060. break;
  16061. }
  16062. return !s;
  16063. }
  16064. function startsWithEndTagOpen(source, tag) {
  16065. return startsWith(source, "</") && source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() && /[\t\r\n\f />]/.test(source[2 + tag.length] || ">");
  16066. }
  16067. function hoistStatic(root, context) {
  16068. walk$2(
  16069. root,
  16070. context,
  16071. // Root node is unfortunately non-hoistable due to potential parent
  16072. // fallthrough attributes.
  16073. isSingleElementRoot(root, root.children[0])
  16074. );
  16075. }
  16076. function isSingleElementRoot(root, child) {
  16077. const { children } = root;
  16078. return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
  16079. }
  16080. function walk$2(node, context, doNotHoistNode = false) {
  16081. const { children } = node;
  16082. const originalCount = children.length;
  16083. let hoistedCount = 0;
  16084. for (let i = 0; i < children.length; i++) {
  16085. const child = children[i];
  16086. if (child.type === 1 && child.tagType === 0) {
  16087. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  16088. if (constantType > 0) {
  16089. if (constantType >= 2) {
  16090. child.codegenNode.patchFlag = -1 + (` /* HOISTED */` );
  16091. child.codegenNode = context.hoist(child.codegenNode);
  16092. hoistedCount++;
  16093. continue;
  16094. }
  16095. } else {
  16096. const codegenNode = child.codegenNode;
  16097. if (codegenNode.type === 13) {
  16098. const flag = getPatchFlag(codegenNode);
  16099. if ((!flag || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  16100. const props = getNodeProps(child);
  16101. if (props) {
  16102. codegenNode.props = context.hoist(props);
  16103. }
  16104. }
  16105. if (codegenNode.dynamicProps) {
  16106. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  16107. }
  16108. }
  16109. }
  16110. }
  16111. if (child.type === 1) {
  16112. const isComponent = child.tagType === 1;
  16113. if (isComponent) {
  16114. context.scopes.vSlot++;
  16115. }
  16116. walk$2(child, context);
  16117. if (isComponent) {
  16118. context.scopes.vSlot--;
  16119. }
  16120. } else if (child.type === 11) {
  16121. walk$2(child, context, child.children.length === 1);
  16122. } else if (child.type === 9) {
  16123. for (let i2 = 0; i2 < child.branches.length; i2++) {
  16124. walk$2(
  16125. child.branches[i2],
  16126. context,
  16127. child.branches[i2].children.length === 1
  16128. );
  16129. }
  16130. }
  16131. }
  16132. if (hoistedCount && context.transformHoist) {
  16133. context.transformHoist(children, context, node);
  16134. }
  16135. if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray$3(node.codegenNode.children)) {
  16136. node.codegenNode.children = context.hoist(
  16137. createArrayExpression(node.codegenNode.children)
  16138. );
  16139. }
  16140. }
  16141. function getConstantType(node, context) {
  16142. const { constantCache } = context;
  16143. switch (node.type) {
  16144. case 1:
  16145. if (node.tagType !== 0) {
  16146. return 0;
  16147. }
  16148. const cached = constantCache.get(node);
  16149. if (cached !== void 0) {
  16150. return cached;
  16151. }
  16152. const codegenNode = node.codegenNode;
  16153. if (codegenNode.type !== 13) {
  16154. return 0;
  16155. }
  16156. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
  16157. return 0;
  16158. }
  16159. const flag = getPatchFlag(codegenNode);
  16160. if (!flag) {
  16161. let returnType2 = 3;
  16162. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  16163. if (generatedPropsType === 0) {
  16164. constantCache.set(node, 0);
  16165. return 0;
  16166. }
  16167. if (generatedPropsType < returnType2) {
  16168. returnType2 = generatedPropsType;
  16169. }
  16170. for (let i = 0; i < node.children.length; i++) {
  16171. const childType = getConstantType(node.children[i], context);
  16172. if (childType === 0) {
  16173. constantCache.set(node, 0);
  16174. return 0;
  16175. }
  16176. if (childType < returnType2) {
  16177. returnType2 = childType;
  16178. }
  16179. }
  16180. if (returnType2 > 1) {
  16181. for (let i = 0; i < node.props.length; i++) {
  16182. const p = node.props[i];
  16183. if (p.type === 7 && p.name === "bind" && p.exp) {
  16184. const expType = getConstantType(p.exp, context);
  16185. if (expType === 0) {
  16186. constantCache.set(node, 0);
  16187. return 0;
  16188. }
  16189. if (expType < returnType2) {
  16190. returnType2 = expType;
  16191. }
  16192. }
  16193. }
  16194. }
  16195. if (codegenNode.isBlock) {
  16196. for (let i = 0; i < node.props.length; i++) {
  16197. const p = node.props[i];
  16198. if (p.type === 7) {
  16199. constantCache.set(node, 0);
  16200. return 0;
  16201. }
  16202. }
  16203. context.removeHelper(OPEN_BLOCK);
  16204. context.removeHelper(
  16205. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  16206. );
  16207. codegenNode.isBlock = false;
  16208. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  16209. }
  16210. constantCache.set(node, returnType2);
  16211. return returnType2;
  16212. } else {
  16213. constantCache.set(node, 0);
  16214. return 0;
  16215. }
  16216. case 2:
  16217. case 3:
  16218. return 3;
  16219. case 9:
  16220. case 11:
  16221. case 10:
  16222. return 0;
  16223. case 5:
  16224. case 12:
  16225. return getConstantType(node.content, context);
  16226. case 4:
  16227. return node.constType;
  16228. case 8:
  16229. let returnType = 3;
  16230. for (let i = 0; i < node.children.length; i++) {
  16231. const child = node.children[i];
  16232. if (isString$2(child) || isSymbol$1(child)) {
  16233. continue;
  16234. }
  16235. const childType = getConstantType(child, context);
  16236. if (childType === 0) {
  16237. return 0;
  16238. } else if (childType < returnType) {
  16239. returnType = childType;
  16240. }
  16241. }
  16242. return returnType;
  16243. default:
  16244. return 0;
  16245. }
  16246. }
  16247. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  16248. NORMALIZE_CLASS,
  16249. NORMALIZE_STYLE,
  16250. NORMALIZE_PROPS,
  16251. GUARD_REACTIVE_PROPS
  16252. ]);
  16253. function getConstantTypeOfHelperCall(value, context) {
  16254. if (value.type === 14 && !isString$2(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  16255. const arg = value.arguments[0];
  16256. if (arg.type === 4) {
  16257. return getConstantType(arg, context);
  16258. } else if (arg.type === 14) {
  16259. return getConstantTypeOfHelperCall(arg, context);
  16260. }
  16261. }
  16262. return 0;
  16263. }
  16264. function getGeneratedPropsConstantType(node, context) {
  16265. let returnType = 3;
  16266. const props = getNodeProps(node);
  16267. if (props && props.type === 15) {
  16268. const { properties } = props;
  16269. for (let i = 0; i < properties.length; i++) {
  16270. const { key, value } = properties[i];
  16271. const keyType = getConstantType(key, context);
  16272. if (keyType === 0) {
  16273. return keyType;
  16274. }
  16275. if (keyType < returnType) {
  16276. returnType = keyType;
  16277. }
  16278. let valueType;
  16279. if (value.type === 4) {
  16280. valueType = getConstantType(value, context);
  16281. } else if (value.type === 14) {
  16282. valueType = getConstantTypeOfHelperCall(value, context);
  16283. } else {
  16284. valueType = 0;
  16285. }
  16286. if (valueType === 0) {
  16287. return valueType;
  16288. }
  16289. if (valueType < returnType) {
  16290. returnType = valueType;
  16291. }
  16292. }
  16293. }
  16294. return returnType;
  16295. }
  16296. function getNodeProps(node) {
  16297. const codegenNode = node.codegenNode;
  16298. if (codegenNode.type === 13) {
  16299. return codegenNode.props;
  16300. }
  16301. }
  16302. function getPatchFlag(node) {
  16303. const flag = node.patchFlag;
  16304. return flag ? parseInt(flag, 10) : void 0;
  16305. }
  16306. function createTransformContext(root, {
  16307. filename = "",
  16308. prefixIdentifiers = false,
  16309. hoistStatic: hoistStatic2 = false,
  16310. cacheHandlers = false,
  16311. nodeTransforms = [],
  16312. directiveTransforms = {},
  16313. transformHoist = null,
  16314. isBuiltInComponent = NOOP,
  16315. isCustomElement = NOOP,
  16316. expressionPlugins = [],
  16317. scopeId = null,
  16318. slotted = true,
  16319. ssr = false,
  16320. inSSR = false,
  16321. ssrCssVars = ``,
  16322. bindingMetadata = EMPTY_OBJ,
  16323. inline = false,
  16324. isTS = false,
  16325. onError = defaultOnError,
  16326. onWarn = defaultOnWarn,
  16327. compatConfig
  16328. }) {
  16329. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  16330. const context = {
  16331. // options
  16332. selfName: nameMatch && capitalize$1(camelize(nameMatch[1])),
  16333. prefixIdentifiers,
  16334. hoistStatic: hoistStatic2,
  16335. cacheHandlers,
  16336. nodeTransforms,
  16337. directiveTransforms,
  16338. transformHoist,
  16339. isBuiltInComponent,
  16340. isCustomElement,
  16341. expressionPlugins,
  16342. scopeId,
  16343. slotted,
  16344. ssr,
  16345. inSSR,
  16346. ssrCssVars,
  16347. bindingMetadata,
  16348. inline,
  16349. isTS,
  16350. onError,
  16351. onWarn,
  16352. compatConfig,
  16353. // state
  16354. root,
  16355. helpers: /* @__PURE__ */ new Map(),
  16356. components: /* @__PURE__ */ new Set(),
  16357. directives: /* @__PURE__ */ new Set(),
  16358. hoists: [],
  16359. imports: [],
  16360. constantCache: /* @__PURE__ */ new Map(),
  16361. temps: 0,
  16362. cached: 0,
  16363. identifiers: /* @__PURE__ */ Object.create(null),
  16364. scopes: {
  16365. vFor: 0,
  16366. vSlot: 0,
  16367. vPre: 0,
  16368. vOnce: 0
  16369. },
  16370. parent: null,
  16371. currentNode: root,
  16372. childIndex: 0,
  16373. inVOnce: false,
  16374. // methods
  16375. helper(name) {
  16376. const count = context.helpers.get(name) || 0;
  16377. context.helpers.set(name, count + 1);
  16378. return name;
  16379. },
  16380. removeHelper(name) {
  16381. const count = context.helpers.get(name);
  16382. if (count) {
  16383. const currentCount = count - 1;
  16384. if (!currentCount) {
  16385. context.helpers.delete(name);
  16386. } else {
  16387. context.helpers.set(name, currentCount);
  16388. }
  16389. }
  16390. },
  16391. helperString(name) {
  16392. return `_${helperNameMap[context.helper(name)]}`;
  16393. },
  16394. replaceNode(node) {
  16395. {
  16396. if (!context.currentNode) {
  16397. throw new Error(`Node being replaced is already removed.`);
  16398. }
  16399. if (!context.parent) {
  16400. throw new Error(`Cannot replace root node.`);
  16401. }
  16402. }
  16403. context.parent.children[context.childIndex] = context.currentNode = node;
  16404. },
  16405. removeNode(node) {
  16406. if (!context.parent) {
  16407. throw new Error(`Cannot remove root node.`);
  16408. }
  16409. const list = context.parent.children;
  16410. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  16411. if (removalIndex < 0) {
  16412. throw new Error(`node being removed is not a child of current parent`);
  16413. }
  16414. if (!node || node === context.currentNode) {
  16415. context.currentNode = null;
  16416. context.onNodeRemoved();
  16417. } else {
  16418. if (context.childIndex > removalIndex) {
  16419. context.childIndex--;
  16420. context.onNodeRemoved();
  16421. }
  16422. }
  16423. context.parent.children.splice(removalIndex, 1);
  16424. },
  16425. onNodeRemoved: () => {
  16426. },
  16427. addIdentifiers(exp) {
  16428. {
  16429. if (isString$2(exp)) {
  16430. addId(exp);
  16431. } else if (exp.identifiers) {
  16432. exp.identifiers.forEach(addId);
  16433. } else if (exp.type === 4) {
  16434. addId(exp.content);
  16435. }
  16436. }
  16437. },
  16438. removeIdentifiers(exp) {
  16439. {
  16440. if (isString$2(exp)) {
  16441. removeId(exp);
  16442. } else if (exp.identifiers) {
  16443. exp.identifiers.forEach(removeId);
  16444. } else if (exp.type === 4) {
  16445. removeId(exp.content);
  16446. }
  16447. }
  16448. },
  16449. hoist(exp) {
  16450. if (isString$2(exp))
  16451. exp = createSimpleExpression(exp);
  16452. context.hoists.push(exp);
  16453. const identifier = createSimpleExpression(
  16454. `_hoisted_${context.hoists.length}`,
  16455. false,
  16456. exp.loc,
  16457. 2
  16458. );
  16459. identifier.hoisted = exp;
  16460. return identifier;
  16461. },
  16462. cache(exp, isVNode = false) {
  16463. return createCacheExpression(context.cached++, exp, isVNode);
  16464. }
  16465. };
  16466. function addId(id) {
  16467. const { identifiers } = context;
  16468. if (identifiers[id] === void 0) {
  16469. identifiers[id] = 0;
  16470. }
  16471. identifiers[id]++;
  16472. }
  16473. function removeId(id) {
  16474. context.identifiers[id]--;
  16475. }
  16476. return context;
  16477. }
  16478. function transform$1(root, options) {
  16479. const context = createTransformContext(root, options);
  16480. traverseNode(root, context);
  16481. if (options.hoistStatic) {
  16482. hoistStatic(root, context);
  16483. }
  16484. if (!options.ssr) {
  16485. createRootCodegen(root, context);
  16486. }
  16487. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  16488. root.components = [...context.components];
  16489. root.directives = [...context.directives];
  16490. root.imports = context.imports;
  16491. root.hoists = context.hoists;
  16492. root.temps = context.temps;
  16493. root.cached = context.cached;
  16494. }
  16495. function createRootCodegen(root, context) {
  16496. const { helper } = context;
  16497. const { children } = root;
  16498. if (children.length === 1) {
  16499. const child = children[0];
  16500. if (isSingleElementRoot(root, child) && child.codegenNode) {
  16501. const codegenNode = child.codegenNode;
  16502. if (codegenNode.type === 13) {
  16503. convertToBlock(codegenNode, context);
  16504. }
  16505. root.codegenNode = codegenNode;
  16506. } else {
  16507. root.codegenNode = child;
  16508. }
  16509. } else if (children.length > 1) {
  16510. let patchFlag = 64;
  16511. let patchFlagText = PatchFlagNames[64];
  16512. if (children.filter((c) => c.type !== 3).length === 1) {
  16513. patchFlag |= 2048;
  16514. patchFlagText += `, ${PatchFlagNames[2048]}`;
  16515. }
  16516. root.codegenNode = createVNodeCall(
  16517. context,
  16518. helper(FRAGMENT),
  16519. void 0,
  16520. root.children,
  16521. patchFlag + (` /* ${patchFlagText} */` ),
  16522. void 0,
  16523. void 0,
  16524. true,
  16525. void 0,
  16526. false
  16527. /* isComponent */
  16528. );
  16529. } else ;
  16530. }
  16531. function traverseChildren(parent, context) {
  16532. let i = 0;
  16533. const nodeRemoved = () => {
  16534. i--;
  16535. };
  16536. for (; i < parent.children.length; i++) {
  16537. const child = parent.children[i];
  16538. if (isString$2(child))
  16539. continue;
  16540. context.parent = parent;
  16541. context.childIndex = i;
  16542. context.onNodeRemoved = nodeRemoved;
  16543. traverseNode(child, context);
  16544. }
  16545. }
  16546. function traverseNode(node, context) {
  16547. context.currentNode = node;
  16548. const { nodeTransforms } = context;
  16549. const exitFns = [];
  16550. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  16551. const onExit = nodeTransforms[i2](node, context);
  16552. if (onExit) {
  16553. if (isArray$3(onExit)) {
  16554. exitFns.push(...onExit);
  16555. } else {
  16556. exitFns.push(onExit);
  16557. }
  16558. }
  16559. if (!context.currentNode) {
  16560. return;
  16561. } else {
  16562. node = context.currentNode;
  16563. }
  16564. }
  16565. switch (node.type) {
  16566. case 3:
  16567. if (!context.ssr) {
  16568. context.helper(CREATE_COMMENT);
  16569. }
  16570. break;
  16571. case 5:
  16572. if (!context.ssr) {
  16573. context.helper(TO_DISPLAY_STRING);
  16574. }
  16575. break;
  16576. case 9:
  16577. for (let i2 = 0; i2 < node.branches.length; i2++) {
  16578. traverseNode(node.branches[i2], context);
  16579. }
  16580. break;
  16581. case 10:
  16582. case 11:
  16583. case 1:
  16584. case 0:
  16585. traverseChildren(node, context);
  16586. break;
  16587. }
  16588. context.currentNode = node;
  16589. let i = exitFns.length;
  16590. while (i--) {
  16591. exitFns[i]();
  16592. }
  16593. }
  16594. function createStructuralDirectiveTransform(name, fn) {
  16595. const matches = isString$2(name) ? (n) => n === name : (n) => name.test(n);
  16596. return (node, context) => {
  16597. if (node.type === 1) {
  16598. const { props } = node;
  16599. if (node.tagType === 3 && props.some(isVSlot)) {
  16600. return;
  16601. }
  16602. const exitFns = [];
  16603. for (let i = 0; i < props.length; i++) {
  16604. const prop = props[i];
  16605. if (prop.type === 7 && matches(prop.name)) {
  16606. props.splice(i, 1);
  16607. i--;
  16608. const onExit = fn(node, prop, context);
  16609. if (onExit)
  16610. exitFns.push(onExit);
  16611. }
  16612. }
  16613. return exitFns;
  16614. }
  16615. };
  16616. }
  16617. var sourceMap$2 = {};
  16618. var sourceMapGenerator$1 = {};
  16619. var base64Vlq$1 = {};
  16620. var base64$3 = {};
  16621. /* -*- Mode: js; js-indent-level: 2; -*- */
  16622. /*
  16623. * Copyright 2011 Mozilla Foundation and contributors
  16624. * Licensed under the New BSD license. See LICENSE or:
  16625. * http://opensource.org/licenses/BSD-3-Clause
  16626. */
  16627. var intToCharMap$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  16628. /**
  16629. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  16630. */
  16631. base64$3.encode = function (number) {
  16632. if (0 <= number && number < intToCharMap$1.length) {
  16633. return intToCharMap$1[number];
  16634. }
  16635. throw new TypeError("Must be between 0 and 63: " + number);
  16636. };
  16637. /**
  16638. * Decode a single base 64 character code digit to an integer. Returns -1 on
  16639. * failure.
  16640. */
  16641. base64$3.decode = function (charCode) {
  16642. var bigA = 65; // 'A'
  16643. var bigZ = 90; // 'Z'
  16644. var littleA = 97; // 'a'
  16645. var littleZ = 122; // 'z'
  16646. var zero = 48; // '0'
  16647. var nine = 57; // '9'
  16648. var plus = 43; // '+'
  16649. var slash = 47; // '/'
  16650. var littleOffset = 26;
  16651. var numberOffset = 52;
  16652. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  16653. if (bigA <= charCode && charCode <= bigZ) {
  16654. return (charCode - bigA);
  16655. }
  16656. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  16657. if (littleA <= charCode && charCode <= littleZ) {
  16658. return (charCode - littleA + littleOffset);
  16659. }
  16660. // 52 - 61: 0123456789
  16661. if (zero <= charCode && charCode <= nine) {
  16662. return (charCode - zero + numberOffset);
  16663. }
  16664. // 62: +
  16665. if (charCode == plus) {
  16666. return 62;
  16667. }
  16668. // 63: /
  16669. if (charCode == slash) {
  16670. return 63;
  16671. }
  16672. // Invalid base64 digit.
  16673. return -1;
  16674. };
  16675. /* -*- Mode: js; js-indent-level: 2; -*- */
  16676. /*
  16677. * Copyright 2011 Mozilla Foundation and contributors
  16678. * Licensed under the New BSD license. See LICENSE or:
  16679. * http://opensource.org/licenses/BSD-3-Clause
  16680. *
  16681. * Based on the Base 64 VLQ implementation in Closure Compiler:
  16682. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  16683. *
  16684. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  16685. * Redistribution and use in source and binary forms, with or without
  16686. * modification, are permitted provided that the following conditions are
  16687. * met:
  16688. *
  16689. * * Redistributions of source code must retain the above copyright
  16690. * notice, this list of conditions and the following disclaimer.
  16691. * * Redistributions in binary form must reproduce the above
  16692. * copyright notice, this list of conditions and the following
  16693. * disclaimer in the documentation and/or other materials provided
  16694. * with the distribution.
  16695. * * Neither the name of Google Inc. nor the names of its
  16696. * contributors may be used to endorse or promote products derived
  16697. * from this software without specific prior written permission.
  16698. *
  16699. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16700. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16701. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16702. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  16703. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16704. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  16705. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  16706. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  16707. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  16708. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16709. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16710. */
  16711. var base64$2 = base64$3;
  16712. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  16713. // length quantities we use in the source map spec, the first bit is the sign,
  16714. // the next four bits are the actual value, and the 6th bit is the
  16715. // continuation bit. The continuation bit tells us whether there are more
  16716. // digits in this value following this digit.
  16717. //
  16718. // Continuation
  16719. // | Sign
  16720. // | |
  16721. // V V
  16722. // 101011
  16723. var VLQ_BASE_SHIFT$1 = 5;
  16724. // binary: 100000
  16725. var VLQ_BASE$1 = 1 << VLQ_BASE_SHIFT$1;
  16726. // binary: 011111
  16727. var VLQ_BASE_MASK$1 = VLQ_BASE$1 - 1;
  16728. // binary: 100000
  16729. var VLQ_CONTINUATION_BIT$1 = VLQ_BASE$1;
  16730. /**
  16731. * Converts from a two-complement value to a value where the sign bit is
  16732. * placed in the least significant bit. For example, as decimals:
  16733. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  16734. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  16735. */
  16736. function toVLQSigned$1(aValue) {
  16737. return aValue < 0
  16738. ? ((-aValue) << 1) + 1
  16739. : (aValue << 1) + 0;
  16740. }
  16741. /**
  16742. * Converts to a two-complement value from a value where the sign bit is
  16743. * placed in the least significant bit. For example, as decimals:
  16744. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  16745. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  16746. */
  16747. function fromVLQSigned$1(aValue) {
  16748. var isNegative = (aValue & 1) === 1;
  16749. var shifted = aValue >> 1;
  16750. return isNegative
  16751. ? -shifted
  16752. : shifted;
  16753. }
  16754. /**
  16755. * Returns the base 64 VLQ encoded value.
  16756. */
  16757. base64Vlq$1.encode = function base64VLQ_encode(aValue) {
  16758. var encoded = "";
  16759. var digit;
  16760. var vlq = toVLQSigned$1(aValue);
  16761. do {
  16762. digit = vlq & VLQ_BASE_MASK$1;
  16763. vlq >>>= VLQ_BASE_SHIFT$1;
  16764. if (vlq > 0) {
  16765. // There are still more digits in this value, so we must make sure the
  16766. // continuation bit is marked.
  16767. digit |= VLQ_CONTINUATION_BIT$1;
  16768. }
  16769. encoded += base64$2.encode(digit);
  16770. } while (vlq > 0);
  16771. return encoded;
  16772. };
  16773. /**
  16774. * Decodes the next base 64 VLQ value from the given string and returns the
  16775. * value and the rest of the string via the out parameter.
  16776. */
  16777. base64Vlq$1.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  16778. var strLen = aStr.length;
  16779. var result = 0;
  16780. var shift = 0;
  16781. var continuation, digit;
  16782. do {
  16783. if (aIndex >= strLen) {
  16784. throw new Error("Expected more digits in base 64 VLQ value.");
  16785. }
  16786. digit = base64$2.decode(aStr.charCodeAt(aIndex++));
  16787. if (digit === -1) {
  16788. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  16789. }
  16790. continuation = !!(digit & VLQ_CONTINUATION_BIT$1);
  16791. digit &= VLQ_BASE_MASK$1;
  16792. result = result + (digit << shift);
  16793. shift += VLQ_BASE_SHIFT$1;
  16794. } while (continuation);
  16795. aOutParam.value = fromVLQSigned$1(result);
  16796. aOutParam.rest = aIndex;
  16797. };
  16798. var util$c = {};
  16799. /* -*- Mode: js; js-indent-level: 2; -*- */
  16800. (function (exports) {
  16801. /*
  16802. * Copyright 2011 Mozilla Foundation and contributors
  16803. * Licensed under the New BSD license. See LICENSE or:
  16804. * http://opensource.org/licenses/BSD-3-Clause
  16805. */
  16806. /**
  16807. * This is a helper function for getting values from parameter/options
  16808. * objects.
  16809. *
  16810. * @param args The object we are extracting values from
  16811. * @param name The name of the property we are getting.
  16812. * @param defaultValue An optional value to return if the property is missing
  16813. * from the object. If this is not specified and the property is missing, an
  16814. * error will be thrown.
  16815. */
  16816. function getArg(aArgs, aName, aDefaultValue) {
  16817. if (aName in aArgs) {
  16818. return aArgs[aName];
  16819. } else if (arguments.length === 3) {
  16820. return aDefaultValue;
  16821. } else {
  16822. throw new Error('"' + aName + '" is a required argument.');
  16823. }
  16824. }
  16825. exports.getArg = getArg;
  16826. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  16827. var dataUrlRegexp = /^data:.+\,.+$/;
  16828. function urlParse(aUrl) {
  16829. var match = aUrl.match(urlRegexp);
  16830. if (!match) {
  16831. return null;
  16832. }
  16833. return {
  16834. scheme: match[1],
  16835. auth: match[2],
  16836. host: match[3],
  16837. port: match[4],
  16838. path: match[5]
  16839. };
  16840. }
  16841. exports.urlParse = urlParse;
  16842. function urlGenerate(aParsedUrl) {
  16843. var url = '';
  16844. if (aParsedUrl.scheme) {
  16845. url += aParsedUrl.scheme + ':';
  16846. }
  16847. url += '//';
  16848. if (aParsedUrl.auth) {
  16849. url += aParsedUrl.auth + '@';
  16850. }
  16851. if (aParsedUrl.host) {
  16852. url += aParsedUrl.host;
  16853. }
  16854. if (aParsedUrl.port) {
  16855. url += ":" + aParsedUrl.port;
  16856. }
  16857. if (aParsedUrl.path) {
  16858. url += aParsedUrl.path;
  16859. }
  16860. return url;
  16861. }
  16862. exports.urlGenerate = urlGenerate;
  16863. var MAX_CACHED_INPUTS = 32;
  16864. /**
  16865. * Takes some function `f(input) -> result` and returns a memoized version of
  16866. * `f`.
  16867. *
  16868. * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
  16869. * memoization is a dumb-simple, linear least-recently-used cache.
  16870. */
  16871. function lruMemoize(f) {
  16872. var cache = [];
  16873. return function(input) {
  16874. for (var i = 0; i < cache.length; i++) {
  16875. if (cache[i].input === input) {
  16876. var temp = cache[0];
  16877. cache[0] = cache[i];
  16878. cache[i] = temp;
  16879. return cache[0].result;
  16880. }
  16881. }
  16882. var result = f(input);
  16883. cache.unshift({
  16884. input,
  16885. result,
  16886. });
  16887. if (cache.length > MAX_CACHED_INPUTS) {
  16888. cache.pop();
  16889. }
  16890. return result;
  16891. };
  16892. }
  16893. /**
  16894. * Normalizes a path, or the path portion of a URL:
  16895. *
  16896. * - Replaces consecutive slashes with one slash.
  16897. * - Removes unnecessary '.' parts.
  16898. * - Removes unnecessary '<dir>/..' parts.
  16899. *
  16900. * Based on code in the Node.js 'path' core module.
  16901. *
  16902. * @param aPath The path or url to normalize.
  16903. */
  16904. var normalize = lruMemoize(function normalize(aPath) {
  16905. var path = aPath;
  16906. var url = urlParse(aPath);
  16907. if (url) {
  16908. if (!url.path) {
  16909. return aPath;
  16910. }
  16911. path = url.path;
  16912. }
  16913. var isAbsolute = exports.isAbsolute(path);
  16914. // Split the path into parts between `/` characters. This is much faster than
  16915. // using `.split(/\/+/g)`.
  16916. var parts = [];
  16917. var start = 0;
  16918. var i = 0;
  16919. while (true) {
  16920. start = i;
  16921. i = path.indexOf("/", start);
  16922. if (i === -1) {
  16923. parts.push(path.slice(start));
  16924. break;
  16925. } else {
  16926. parts.push(path.slice(start, i));
  16927. while (i < path.length && path[i] === "/") {
  16928. i++;
  16929. }
  16930. }
  16931. }
  16932. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  16933. part = parts[i];
  16934. if (part === '.') {
  16935. parts.splice(i, 1);
  16936. } else if (part === '..') {
  16937. up++;
  16938. } else if (up > 0) {
  16939. if (part === '') {
  16940. // The first part is blank if the path is absolute. Trying to go
  16941. // above the root is a no-op. Therefore we can remove all '..' parts
  16942. // directly after the root.
  16943. parts.splice(i + 1, up);
  16944. up = 0;
  16945. } else {
  16946. parts.splice(i, 2);
  16947. up--;
  16948. }
  16949. }
  16950. }
  16951. path = parts.join('/');
  16952. if (path === '') {
  16953. path = isAbsolute ? '/' : '.';
  16954. }
  16955. if (url) {
  16956. url.path = path;
  16957. return urlGenerate(url);
  16958. }
  16959. return path;
  16960. });
  16961. exports.normalize = normalize;
  16962. /**
  16963. * Joins two paths/URLs.
  16964. *
  16965. * @param aRoot The root path or URL.
  16966. * @param aPath The path or URL to be joined with the root.
  16967. *
  16968. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  16969. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  16970. * first.
  16971. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  16972. * is updated with the result and aRoot is returned. Otherwise the result
  16973. * is returned.
  16974. * - If aPath is absolute, the result is aPath.
  16975. * - Otherwise the two paths are joined with a slash.
  16976. * - Joining for example 'http://' and 'www.example.com' is also supported.
  16977. */
  16978. function join(aRoot, aPath) {
  16979. if (aRoot === "") {
  16980. aRoot = ".";
  16981. }
  16982. if (aPath === "") {
  16983. aPath = ".";
  16984. }
  16985. var aPathUrl = urlParse(aPath);
  16986. var aRootUrl = urlParse(aRoot);
  16987. if (aRootUrl) {
  16988. aRoot = aRootUrl.path || '/';
  16989. }
  16990. // `join(foo, '//www.example.org')`
  16991. if (aPathUrl && !aPathUrl.scheme) {
  16992. if (aRootUrl) {
  16993. aPathUrl.scheme = aRootUrl.scheme;
  16994. }
  16995. return urlGenerate(aPathUrl);
  16996. }
  16997. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  16998. return aPath;
  16999. }
  17000. // `join('http://', 'www.example.com')`
  17001. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  17002. aRootUrl.host = aPath;
  17003. return urlGenerate(aRootUrl);
  17004. }
  17005. var joined = aPath.charAt(0) === '/'
  17006. ? aPath
  17007. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  17008. if (aRootUrl) {
  17009. aRootUrl.path = joined;
  17010. return urlGenerate(aRootUrl);
  17011. }
  17012. return joined;
  17013. }
  17014. exports.join = join;
  17015. exports.isAbsolute = function (aPath) {
  17016. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  17017. };
  17018. /**
  17019. * Make a path relative to a URL or another path.
  17020. *
  17021. * @param aRoot The root path or URL.
  17022. * @param aPath The path or URL to be made relative to aRoot.
  17023. */
  17024. function relative(aRoot, aPath) {
  17025. if (aRoot === "") {
  17026. aRoot = ".";
  17027. }
  17028. aRoot = aRoot.replace(/\/$/, '');
  17029. // It is possible for the path to be above the root. In this case, simply
  17030. // checking whether the root is a prefix of the path won't work. Instead, we
  17031. // need to remove components from the root one by one, until either we find
  17032. // a prefix that fits, or we run out of components to remove.
  17033. var level = 0;
  17034. while (aPath.indexOf(aRoot + '/') !== 0) {
  17035. var index = aRoot.lastIndexOf("/");
  17036. if (index < 0) {
  17037. return aPath;
  17038. }
  17039. // If the only part of the root that is left is the scheme (i.e. http://,
  17040. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  17041. // have exhausted all components, so the path is not relative to the root.
  17042. aRoot = aRoot.slice(0, index);
  17043. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  17044. return aPath;
  17045. }
  17046. ++level;
  17047. }
  17048. // Make sure we add a "../" for each component we removed from the root.
  17049. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  17050. }
  17051. exports.relative = relative;
  17052. var supportsNullProto = (function () {
  17053. var obj = Object.create(null);
  17054. return !('__proto__' in obj);
  17055. }());
  17056. function identity (s) {
  17057. return s;
  17058. }
  17059. /**
  17060. * Because behavior goes wacky when you set `__proto__` on objects, we
  17061. * have to prefix all the strings in our set with an arbitrary character.
  17062. *
  17063. * See https://github.com/mozilla/source-map/pull/31 and
  17064. * https://github.com/mozilla/source-map/issues/30
  17065. *
  17066. * @param String aStr
  17067. */
  17068. function toSetString(aStr) {
  17069. if (isProtoString(aStr)) {
  17070. return '$' + aStr;
  17071. }
  17072. return aStr;
  17073. }
  17074. exports.toSetString = supportsNullProto ? identity : toSetString;
  17075. function fromSetString(aStr) {
  17076. if (isProtoString(aStr)) {
  17077. return aStr.slice(1);
  17078. }
  17079. return aStr;
  17080. }
  17081. exports.fromSetString = supportsNullProto ? identity : fromSetString;
  17082. function isProtoString(s) {
  17083. if (!s) {
  17084. return false;
  17085. }
  17086. var length = s.length;
  17087. if (length < 9 /* "__proto__".length */) {
  17088. return false;
  17089. }
  17090. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  17091. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  17092. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  17093. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  17094. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  17095. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  17096. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  17097. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  17098. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  17099. return false;
  17100. }
  17101. for (var i = length - 10; i >= 0; i--) {
  17102. if (s.charCodeAt(i) !== 36 /* '$' */) {
  17103. return false;
  17104. }
  17105. }
  17106. return true;
  17107. }
  17108. /**
  17109. * Comparator between two mappings where the original positions are compared.
  17110. *
  17111. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  17112. * mappings with the same original source/line/column, but different generated
  17113. * line and column the same. Useful when searching for a mapping with a
  17114. * stubbed out mapping.
  17115. */
  17116. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  17117. var cmp = strcmp(mappingA.source, mappingB.source);
  17118. if (cmp !== 0) {
  17119. return cmp;
  17120. }
  17121. cmp = mappingA.originalLine - mappingB.originalLine;
  17122. if (cmp !== 0) {
  17123. return cmp;
  17124. }
  17125. cmp = mappingA.originalColumn - mappingB.originalColumn;
  17126. if (cmp !== 0 || onlyCompareOriginal) {
  17127. return cmp;
  17128. }
  17129. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  17130. if (cmp !== 0) {
  17131. return cmp;
  17132. }
  17133. cmp = mappingA.generatedLine - mappingB.generatedLine;
  17134. if (cmp !== 0) {
  17135. return cmp;
  17136. }
  17137. return strcmp(mappingA.name, mappingB.name);
  17138. }
  17139. exports.compareByOriginalPositions = compareByOriginalPositions;
  17140. function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) {
  17141. var cmp;
  17142. cmp = mappingA.originalLine - mappingB.originalLine;
  17143. if (cmp !== 0) {
  17144. return cmp;
  17145. }
  17146. cmp = mappingA.originalColumn - mappingB.originalColumn;
  17147. if (cmp !== 0 || onlyCompareOriginal) {
  17148. return cmp;
  17149. }
  17150. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  17151. if (cmp !== 0) {
  17152. return cmp;
  17153. }
  17154. cmp = mappingA.generatedLine - mappingB.generatedLine;
  17155. if (cmp !== 0) {
  17156. return cmp;
  17157. }
  17158. return strcmp(mappingA.name, mappingB.name);
  17159. }
  17160. exports.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource;
  17161. /**
  17162. * Comparator between two mappings with deflated source and name indices where
  17163. * the generated positions are compared.
  17164. *
  17165. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  17166. * mappings with the same generated line and column, but different
  17167. * source/name/original line and column the same. Useful when searching for a
  17168. * mapping with a stubbed out mapping.
  17169. */
  17170. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  17171. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  17172. if (cmp !== 0) {
  17173. return cmp;
  17174. }
  17175. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  17176. if (cmp !== 0 || onlyCompareGenerated) {
  17177. return cmp;
  17178. }
  17179. cmp = strcmp(mappingA.source, mappingB.source);
  17180. if (cmp !== 0) {
  17181. return cmp;
  17182. }
  17183. cmp = mappingA.originalLine - mappingB.originalLine;
  17184. if (cmp !== 0) {
  17185. return cmp;
  17186. }
  17187. cmp = mappingA.originalColumn - mappingB.originalColumn;
  17188. if (cmp !== 0) {
  17189. return cmp;
  17190. }
  17191. return strcmp(mappingA.name, mappingB.name);
  17192. }
  17193. exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  17194. function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) {
  17195. var cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  17196. if (cmp !== 0 || onlyCompareGenerated) {
  17197. return cmp;
  17198. }
  17199. cmp = strcmp(mappingA.source, mappingB.source);
  17200. if (cmp !== 0) {
  17201. return cmp;
  17202. }
  17203. cmp = mappingA.originalLine - mappingB.originalLine;
  17204. if (cmp !== 0) {
  17205. return cmp;
  17206. }
  17207. cmp = mappingA.originalColumn - mappingB.originalColumn;
  17208. if (cmp !== 0) {
  17209. return cmp;
  17210. }
  17211. return strcmp(mappingA.name, mappingB.name);
  17212. }
  17213. exports.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine;
  17214. function strcmp(aStr1, aStr2) {
  17215. if (aStr1 === aStr2) {
  17216. return 0;
  17217. }
  17218. if (aStr1 === null) {
  17219. return 1; // aStr2 !== null
  17220. }
  17221. if (aStr2 === null) {
  17222. return -1; // aStr1 !== null
  17223. }
  17224. if (aStr1 > aStr2) {
  17225. return 1;
  17226. }
  17227. return -1;
  17228. }
  17229. /**
  17230. * Comparator between two mappings with inflated source and name strings where
  17231. * the generated positions are compared.
  17232. */
  17233. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  17234. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  17235. if (cmp !== 0) {
  17236. return cmp;
  17237. }
  17238. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  17239. if (cmp !== 0) {
  17240. return cmp;
  17241. }
  17242. cmp = strcmp(mappingA.source, mappingB.source);
  17243. if (cmp !== 0) {
  17244. return cmp;
  17245. }
  17246. cmp = mappingA.originalLine - mappingB.originalLine;
  17247. if (cmp !== 0) {
  17248. return cmp;
  17249. }
  17250. cmp = mappingA.originalColumn - mappingB.originalColumn;
  17251. if (cmp !== 0) {
  17252. return cmp;
  17253. }
  17254. return strcmp(mappingA.name, mappingB.name);
  17255. }
  17256. exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  17257. /**
  17258. * Strip any JSON XSSI avoidance prefix from the string (as documented
  17259. * in the source maps specification), and then parse the string as
  17260. * JSON.
  17261. */
  17262. function parseSourceMapInput(str) {
  17263. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  17264. }
  17265. exports.parseSourceMapInput = parseSourceMapInput;
  17266. /**
  17267. * Compute the URL of a source given the the source root, the source's
  17268. * URL, and the source map's URL.
  17269. */
  17270. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  17271. sourceURL = sourceURL || '';
  17272. if (sourceRoot) {
  17273. // This follows what Chrome does.
  17274. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  17275. sourceRoot += '/';
  17276. }
  17277. // The spec says:
  17278. // Line 4: An optional source root, useful for relocating source
  17279. // files on a server or removing repeated values in the
  17280. // “sources” entry. This value is prepended to the individual
  17281. // entries in the “source” field.
  17282. sourceURL = sourceRoot + sourceURL;
  17283. }
  17284. // Historically, SourceMapConsumer did not take the sourceMapURL as
  17285. // a parameter. This mode is still somewhat supported, which is why
  17286. // this code block is conditional. However, it's preferable to pass
  17287. // the source map URL to SourceMapConsumer, so that this function
  17288. // can implement the source URL resolution algorithm as outlined in
  17289. // the spec. This block is basically the equivalent of:
  17290. // new URL(sourceURL, sourceMapURL).toString()
  17291. // ... except it avoids using URL, which wasn't available in the
  17292. // older releases of node still supported by this library.
  17293. //
  17294. // The spec says:
  17295. // If the sources are not absolute URLs after prepending of the
  17296. // “sourceRoot”, the sources are resolved relative to the
  17297. // SourceMap (like resolving script src in a html document).
  17298. if (sourceMapURL) {
  17299. var parsed = urlParse(sourceMapURL);
  17300. if (!parsed) {
  17301. throw new Error("sourceMapURL could not be parsed");
  17302. }
  17303. if (parsed.path) {
  17304. // Strip the last path component, but keep the "/".
  17305. var index = parsed.path.lastIndexOf('/');
  17306. if (index >= 0) {
  17307. parsed.path = parsed.path.substring(0, index + 1);
  17308. }
  17309. }
  17310. sourceURL = join(urlGenerate(parsed), sourceURL);
  17311. }
  17312. return normalize(sourceURL);
  17313. }
  17314. exports.computeSourceURL = computeSourceURL;
  17315. } (util$c));
  17316. var arraySet$1 = {};
  17317. /* -*- Mode: js; js-indent-level: 2; -*- */
  17318. /*
  17319. * Copyright 2011 Mozilla Foundation and contributors
  17320. * Licensed under the New BSD license. See LICENSE or:
  17321. * http://opensource.org/licenses/BSD-3-Clause
  17322. */
  17323. var util$b = util$c;
  17324. var has$1 = Object.prototype.hasOwnProperty;
  17325. var hasNativeMap$1 = typeof Map !== "undefined";
  17326. /**
  17327. * A data structure which is a combination of an array and a set. Adding a new
  17328. * member is O(1), testing for membership is O(1), and finding the index of an
  17329. * element is O(1). Removing elements from the set is not supported. Only
  17330. * strings are supported for membership.
  17331. */
  17332. function ArraySet$5() {
  17333. this._array = [];
  17334. this._set = hasNativeMap$1 ? new Map() : Object.create(null);
  17335. }
  17336. /**
  17337. * Static method for creating ArraySet instances from an existing array.
  17338. */
  17339. ArraySet$5.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  17340. var set = new ArraySet$5();
  17341. for (var i = 0, len = aArray.length; i < len; i++) {
  17342. set.add(aArray[i], aAllowDuplicates);
  17343. }
  17344. return set;
  17345. };
  17346. /**
  17347. * Return how many unique items are in this ArraySet. If duplicates have been
  17348. * added, than those do not count towards the size.
  17349. *
  17350. * @returns Number
  17351. */
  17352. ArraySet$5.prototype.size = function ArraySet_size() {
  17353. return hasNativeMap$1 ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  17354. };
  17355. /**
  17356. * Add the given string to this set.
  17357. *
  17358. * @param String aStr
  17359. */
  17360. ArraySet$5.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  17361. var sStr = hasNativeMap$1 ? aStr : util$b.toSetString(aStr);
  17362. var isDuplicate = hasNativeMap$1 ? this.has(aStr) : has$1.call(this._set, sStr);
  17363. var idx = this._array.length;
  17364. if (!isDuplicate || aAllowDuplicates) {
  17365. this._array.push(aStr);
  17366. }
  17367. if (!isDuplicate) {
  17368. if (hasNativeMap$1) {
  17369. this._set.set(aStr, idx);
  17370. } else {
  17371. this._set[sStr] = idx;
  17372. }
  17373. }
  17374. };
  17375. /**
  17376. * Is the given string a member of this set?
  17377. *
  17378. * @param String aStr
  17379. */
  17380. ArraySet$5.prototype.has = function ArraySet_has(aStr) {
  17381. if (hasNativeMap$1) {
  17382. return this._set.has(aStr);
  17383. } else {
  17384. var sStr = util$b.toSetString(aStr);
  17385. return has$1.call(this._set, sStr);
  17386. }
  17387. };
  17388. /**
  17389. * What is the index of the given string in the array?
  17390. *
  17391. * @param String aStr
  17392. */
  17393. ArraySet$5.prototype.indexOf = function ArraySet_indexOf(aStr) {
  17394. if (hasNativeMap$1) {
  17395. var idx = this._set.get(aStr);
  17396. if (idx >= 0) {
  17397. return idx;
  17398. }
  17399. } else {
  17400. var sStr = util$b.toSetString(aStr);
  17401. if (has$1.call(this._set, sStr)) {
  17402. return this._set[sStr];
  17403. }
  17404. }
  17405. throw new Error('"' + aStr + '" is not in the set.');
  17406. };
  17407. /**
  17408. * What is the element at the given index?
  17409. *
  17410. * @param Number aIdx
  17411. */
  17412. ArraySet$5.prototype.at = function ArraySet_at(aIdx) {
  17413. if (aIdx >= 0 && aIdx < this._array.length) {
  17414. return this._array[aIdx];
  17415. }
  17416. throw new Error('No element indexed by ' + aIdx);
  17417. };
  17418. /**
  17419. * Returns the array representation of this set (which has the proper indices
  17420. * indicated by indexOf). Note that this is a copy of the internal array used
  17421. * for storing the members so that no one can mess with internal state.
  17422. */
  17423. ArraySet$5.prototype.toArray = function ArraySet_toArray() {
  17424. return this._array.slice();
  17425. };
  17426. arraySet$1.ArraySet = ArraySet$5;
  17427. var mappingList$1 = {};
  17428. /* -*- Mode: js; js-indent-level: 2; -*- */
  17429. /*
  17430. * Copyright 2014 Mozilla Foundation and contributors
  17431. * Licensed under the New BSD license. See LICENSE or:
  17432. * http://opensource.org/licenses/BSD-3-Clause
  17433. */
  17434. var util$a = util$c;
  17435. /**
  17436. * Determine whether mappingB is after mappingA with respect to generated
  17437. * position.
  17438. */
  17439. function generatedPositionAfter$1(mappingA, mappingB) {
  17440. // Optimized for most common case
  17441. var lineA = mappingA.generatedLine;
  17442. var lineB = mappingB.generatedLine;
  17443. var columnA = mappingA.generatedColumn;
  17444. var columnB = mappingB.generatedColumn;
  17445. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  17446. util$a.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  17447. }
  17448. /**
  17449. * A data structure to provide a sorted view of accumulated mappings in a
  17450. * performance conscious manner. It trades a neglibable overhead in general
  17451. * case for a large speedup in case of mappings being added in order.
  17452. */
  17453. function MappingList$3() {
  17454. this._array = [];
  17455. this._sorted = true;
  17456. // Serves as infimum
  17457. this._last = {generatedLine: -1, generatedColumn: 0};
  17458. }
  17459. /**
  17460. * Iterate through internal items. This method takes the same arguments that
  17461. * `Array.prototype.forEach` takes.
  17462. *
  17463. * NOTE: The order of the mappings is NOT guaranteed.
  17464. */
  17465. MappingList$3.prototype.unsortedForEach =
  17466. function MappingList_forEach(aCallback, aThisArg) {
  17467. this._array.forEach(aCallback, aThisArg);
  17468. };
  17469. /**
  17470. * Add the given source mapping.
  17471. *
  17472. * @param Object aMapping
  17473. */
  17474. MappingList$3.prototype.add = function MappingList_add(aMapping) {
  17475. if (generatedPositionAfter$1(this._last, aMapping)) {
  17476. this._last = aMapping;
  17477. this._array.push(aMapping);
  17478. } else {
  17479. this._sorted = false;
  17480. this._array.push(aMapping);
  17481. }
  17482. };
  17483. /**
  17484. * Returns the flat, sorted array of mappings. The mappings are sorted by
  17485. * generated position.
  17486. *
  17487. * WARNING: This method returns internal data without copying, for
  17488. * performance. The return value must NOT be mutated, and should be treated as
  17489. * an immutable borrow. If you want to take ownership, you must make your own
  17490. * copy.
  17491. */
  17492. MappingList$3.prototype.toArray = function MappingList_toArray() {
  17493. if (!this._sorted) {
  17494. this._array.sort(util$a.compareByGeneratedPositionsInflated);
  17495. this._sorted = true;
  17496. }
  17497. return this._array;
  17498. };
  17499. mappingList$1.MappingList = MappingList$3;
  17500. /* -*- Mode: js; js-indent-level: 2; -*- */
  17501. /*
  17502. * Copyright 2011 Mozilla Foundation and contributors
  17503. * Licensed under the New BSD license. See LICENSE or:
  17504. * http://opensource.org/licenses/BSD-3-Clause
  17505. */
  17506. var base64VLQ$3 = base64Vlq$1;
  17507. var util$9 = util$c;
  17508. var ArraySet$4 = arraySet$1.ArraySet;
  17509. var MappingList$2 = mappingList$1.MappingList;
  17510. /**
  17511. * An instance of the SourceMapGenerator represents a source map which is
  17512. * being built incrementally. You may pass an object with the following
  17513. * properties:
  17514. *
  17515. * - file: The filename of the generated source.
  17516. * - sourceRoot: A root for all relative URLs in this source map.
  17517. */
  17518. function SourceMapGenerator$8(aArgs) {
  17519. if (!aArgs) {
  17520. aArgs = {};
  17521. }
  17522. this._file = util$9.getArg(aArgs, 'file', null);
  17523. this._sourceRoot = util$9.getArg(aArgs, 'sourceRoot', null);
  17524. this._skipValidation = util$9.getArg(aArgs, 'skipValidation', false);
  17525. this._sources = new ArraySet$4();
  17526. this._names = new ArraySet$4();
  17527. this._mappings = new MappingList$2();
  17528. this._sourcesContents = null;
  17529. }
  17530. SourceMapGenerator$8.prototype._version = 3;
  17531. /**
  17532. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  17533. *
  17534. * @param aSourceMapConsumer The SourceMap.
  17535. */
  17536. SourceMapGenerator$8.fromSourceMap =
  17537. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  17538. var sourceRoot = aSourceMapConsumer.sourceRoot;
  17539. var generator = new SourceMapGenerator$8({
  17540. file: aSourceMapConsumer.file,
  17541. sourceRoot: sourceRoot
  17542. });
  17543. aSourceMapConsumer.eachMapping(function (mapping) {
  17544. var newMapping = {
  17545. generated: {
  17546. line: mapping.generatedLine,
  17547. column: mapping.generatedColumn
  17548. }
  17549. };
  17550. if (mapping.source != null) {
  17551. newMapping.source = mapping.source;
  17552. if (sourceRoot != null) {
  17553. newMapping.source = util$9.relative(sourceRoot, newMapping.source);
  17554. }
  17555. newMapping.original = {
  17556. line: mapping.originalLine,
  17557. column: mapping.originalColumn
  17558. };
  17559. if (mapping.name != null) {
  17560. newMapping.name = mapping.name;
  17561. }
  17562. }
  17563. generator.addMapping(newMapping);
  17564. });
  17565. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  17566. var sourceRelative = sourceFile;
  17567. if (sourceRoot !== null) {
  17568. sourceRelative = util$9.relative(sourceRoot, sourceFile);
  17569. }
  17570. if (!generator._sources.has(sourceRelative)) {
  17571. generator._sources.add(sourceRelative);
  17572. }
  17573. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  17574. if (content != null) {
  17575. generator.setSourceContent(sourceFile, content);
  17576. }
  17577. });
  17578. return generator;
  17579. };
  17580. /**
  17581. * Add a single mapping from original source line and column to the generated
  17582. * source's line and column for this source map being created. The mapping
  17583. * object should have the following properties:
  17584. *
  17585. * - generated: An object with the generated line and column positions.
  17586. * - original: An object with the original line and column positions.
  17587. * - source: The original source file (relative to the sourceRoot).
  17588. * - name: An optional original token name for this mapping.
  17589. */
  17590. SourceMapGenerator$8.prototype.addMapping =
  17591. function SourceMapGenerator_addMapping(aArgs) {
  17592. var generated = util$9.getArg(aArgs, 'generated');
  17593. var original = util$9.getArg(aArgs, 'original', null);
  17594. var source = util$9.getArg(aArgs, 'source', null);
  17595. var name = util$9.getArg(aArgs, 'name', null);
  17596. if (!this._skipValidation) {
  17597. this._validateMapping(generated, original, source, name);
  17598. }
  17599. if (source != null) {
  17600. source = String(source);
  17601. if (!this._sources.has(source)) {
  17602. this._sources.add(source);
  17603. }
  17604. }
  17605. if (name != null) {
  17606. name = String(name);
  17607. if (!this._names.has(name)) {
  17608. this._names.add(name);
  17609. }
  17610. }
  17611. this._mappings.add({
  17612. generatedLine: generated.line,
  17613. generatedColumn: generated.column,
  17614. originalLine: original != null && original.line,
  17615. originalColumn: original != null && original.column,
  17616. source: source,
  17617. name: name
  17618. });
  17619. };
  17620. /**
  17621. * Set the source content for a source file.
  17622. */
  17623. SourceMapGenerator$8.prototype.setSourceContent =
  17624. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  17625. var source = aSourceFile;
  17626. if (this._sourceRoot != null) {
  17627. source = util$9.relative(this._sourceRoot, source);
  17628. }
  17629. if (aSourceContent != null) {
  17630. // Add the source content to the _sourcesContents map.
  17631. // Create a new _sourcesContents map if the property is null.
  17632. if (!this._sourcesContents) {
  17633. this._sourcesContents = Object.create(null);
  17634. }
  17635. this._sourcesContents[util$9.toSetString(source)] = aSourceContent;
  17636. } else if (this._sourcesContents) {
  17637. // Remove the source file from the _sourcesContents map.
  17638. // If the _sourcesContents map is empty, set the property to null.
  17639. delete this._sourcesContents[util$9.toSetString(source)];
  17640. if (Object.keys(this._sourcesContents).length === 0) {
  17641. this._sourcesContents = null;
  17642. }
  17643. }
  17644. };
  17645. /**
  17646. * Applies the mappings of a sub-source-map for a specific source file to the
  17647. * source map being generated. Each mapping to the supplied source file is
  17648. * rewritten using the supplied source map. Note: The resolution for the
  17649. * resulting mappings is the minimium of this map and the supplied map.
  17650. *
  17651. * @param aSourceMapConsumer The source map to be applied.
  17652. * @param aSourceFile Optional. The filename of the source file.
  17653. * If omitted, SourceMapConsumer's file property will be used.
  17654. * @param aSourceMapPath Optional. The dirname of the path to the source map
  17655. * to be applied. If relative, it is relative to the SourceMapConsumer.
  17656. * This parameter is needed when the two source maps aren't in the same
  17657. * directory, and the source map to be applied contains relative source
  17658. * paths. If so, those relative source paths need to be rewritten
  17659. * relative to the SourceMapGenerator.
  17660. */
  17661. SourceMapGenerator$8.prototype.applySourceMap =
  17662. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  17663. var sourceFile = aSourceFile;
  17664. // If aSourceFile is omitted, we will use the file property of the SourceMap
  17665. if (aSourceFile == null) {
  17666. if (aSourceMapConsumer.file == null) {
  17667. throw new Error(
  17668. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  17669. 'or the source map\'s "file" property. Both were omitted.'
  17670. );
  17671. }
  17672. sourceFile = aSourceMapConsumer.file;
  17673. }
  17674. var sourceRoot = this._sourceRoot;
  17675. // Make "sourceFile" relative if an absolute Url is passed.
  17676. if (sourceRoot != null) {
  17677. sourceFile = util$9.relative(sourceRoot, sourceFile);
  17678. }
  17679. // Applying the SourceMap can add and remove items from the sources and
  17680. // the names array.
  17681. var newSources = new ArraySet$4();
  17682. var newNames = new ArraySet$4();
  17683. // Find mappings for the "sourceFile"
  17684. this._mappings.unsortedForEach(function (mapping) {
  17685. if (mapping.source === sourceFile && mapping.originalLine != null) {
  17686. // Check if it can be mapped by the source map, then update the mapping.
  17687. var original = aSourceMapConsumer.originalPositionFor({
  17688. line: mapping.originalLine,
  17689. column: mapping.originalColumn
  17690. });
  17691. if (original.source != null) {
  17692. // Copy mapping
  17693. mapping.source = original.source;
  17694. if (aSourceMapPath != null) {
  17695. mapping.source = util$9.join(aSourceMapPath, mapping.source);
  17696. }
  17697. if (sourceRoot != null) {
  17698. mapping.source = util$9.relative(sourceRoot, mapping.source);
  17699. }
  17700. mapping.originalLine = original.line;
  17701. mapping.originalColumn = original.column;
  17702. if (original.name != null) {
  17703. mapping.name = original.name;
  17704. }
  17705. }
  17706. }
  17707. var source = mapping.source;
  17708. if (source != null && !newSources.has(source)) {
  17709. newSources.add(source);
  17710. }
  17711. var name = mapping.name;
  17712. if (name != null && !newNames.has(name)) {
  17713. newNames.add(name);
  17714. }
  17715. }, this);
  17716. this._sources = newSources;
  17717. this._names = newNames;
  17718. // Copy sourcesContents of applied map.
  17719. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  17720. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  17721. if (content != null) {
  17722. if (aSourceMapPath != null) {
  17723. sourceFile = util$9.join(aSourceMapPath, sourceFile);
  17724. }
  17725. if (sourceRoot != null) {
  17726. sourceFile = util$9.relative(sourceRoot, sourceFile);
  17727. }
  17728. this.setSourceContent(sourceFile, content);
  17729. }
  17730. }, this);
  17731. };
  17732. /**
  17733. * A mapping can have one of the three levels of data:
  17734. *
  17735. * 1. Just the generated position.
  17736. * 2. The Generated position, original position, and original source.
  17737. * 3. Generated and original position, original source, as well as a name
  17738. * token.
  17739. *
  17740. * To maintain consistency, we validate that any new mapping being added falls
  17741. * in to one of these categories.
  17742. */
  17743. SourceMapGenerator$8.prototype._validateMapping =
  17744. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  17745. aName) {
  17746. // When aOriginal is truthy but has empty values for .line and .column,
  17747. // it is most likely a programmer error. In this case we throw a very
  17748. // specific error message to try to guide them the right way.
  17749. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  17750. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  17751. throw new Error(
  17752. 'original.line and original.column are not numbers -- you probably meant to omit ' +
  17753. 'the original mapping entirely and only map the generated position. If so, pass ' +
  17754. 'null for the original mapping instead of an object with empty or null values.'
  17755. );
  17756. }
  17757. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  17758. && aGenerated.line > 0 && aGenerated.column >= 0
  17759. && !aOriginal && !aSource && !aName) {
  17760. // Case 1.
  17761. return;
  17762. }
  17763. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  17764. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  17765. && aGenerated.line > 0 && aGenerated.column >= 0
  17766. && aOriginal.line > 0 && aOriginal.column >= 0
  17767. && aSource) {
  17768. // Cases 2 and 3.
  17769. return;
  17770. }
  17771. else {
  17772. throw new Error('Invalid mapping: ' + JSON.stringify({
  17773. generated: aGenerated,
  17774. source: aSource,
  17775. original: aOriginal,
  17776. name: aName
  17777. }));
  17778. }
  17779. };
  17780. /**
  17781. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  17782. * specified by the source map format.
  17783. */
  17784. SourceMapGenerator$8.prototype._serializeMappings =
  17785. function SourceMapGenerator_serializeMappings() {
  17786. var previousGeneratedColumn = 0;
  17787. var previousGeneratedLine = 1;
  17788. var previousOriginalColumn = 0;
  17789. var previousOriginalLine = 0;
  17790. var previousName = 0;
  17791. var previousSource = 0;
  17792. var result = '';
  17793. var next;
  17794. var mapping;
  17795. var nameIdx;
  17796. var sourceIdx;
  17797. var mappings = this._mappings.toArray();
  17798. for (var i = 0, len = mappings.length; i < len; i++) {
  17799. mapping = mappings[i];
  17800. next = '';
  17801. if (mapping.generatedLine !== previousGeneratedLine) {
  17802. previousGeneratedColumn = 0;
  17803. while (mapping.generatedLine !== previousGeneratedLine) {
  17804. next += ';';
  17805. previousGeneratedLine++;
  17806. }
  17807. }
  17808. else {
  17809. if (i > 0) {
  17810. if (!util$9.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  17811. continue;
  17812. }
  17813. next += ',';
  17814. }
  17815. }
  17816. next += base64VLQ$3.encode(mapping.generatedColumn
  17817. - previousGeneratedColumn);
  17818. previousGeneratedColumn = mapping.generatedColumn;
  17819. if (mapping.source != null) {
  17820. sourceIdx = this._sources.indexOf(mapping.source);
  17821. next += base64VLQ$3.encode(sourceIdx - previousSource);
  17822. previousSource = sourceIdx;
  17823. // lines are stored 0-based in SourceMap spec version 3
  17824. next += base64VLQ$3.encode(mapping.originalLine - 1
  17825. - previousOriginalLine);
  17826. previousOriginalLine = mapping.originalLine - 1;
  17827. next += base64VLQ$3.encode(mapping.originalColumn
  17828. - previousOriginalColumn);
  17829. previousOriginalColumn = mapping.originalColumn;
  17830. if (mapping.name != null) {
  17831. nameIdx = this._names.indexOf(mapping.name);
  17832. next += base64VLQ$3.encode(nameIdx - previousName);
  17833. previousName = nameIdx;
  17834. }
  17835. }
  17836. result += next;
  17837. }
  17838. return result;
  17839. };
  17840. SourceMapGenerator$8.prototype._generateSourcesContent =
  17841. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  17842. return aSources.map(function (source) {
  17843. if (!this._sourcesContents) {
  17844. return null;
  17845. }
  17846. if (aSourceRoot != null) {
  17847. source = util$9.relative(aSourceRoot, source);
  17848. }
  17849. var key = util$9.toSetString(source);
  17850. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  17851. ? this._sourcesContents[key]
  17852. : null;
  17853. }, this);
  17854. };
  17855. /**
  17856. * Externalize the source map.
  17857. */
  17858. SourceMapGenerator$8.prototype.toJSON =
  17859. function SourceMapGenerator_toJSON() {
  17860. var map = {
  17861. version: this._version,
  17862. sources: this._sources.toArray(),
  17863. names: this._names.toArray(),
  17864. mappings: this._serializeMappings()
  17865. };
  17866. if (this._file != null) {
  17867. map.file = this._file;
  17868. }
  17869. if (this._sourceRoot != null) {
  17870. map.sourceRoot = this._sourceRoot;
  17871. }
  17872. if (this._sourcesContents) {
  17873. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  17874. }
  17875. return map;
  17876. };
  17877. /**
  17878. * Render the source map being generated to a string.
  17879. */
  17880. SourceMapGenerator$8.prototype.toString =
  17881. function SourceMapGenerator_toString() {
  17882. return JSON.stringify(this.toJSON());
  17883. };
  17884. sourceMapGenerator$1.SourceMapGenerator = SourceMapGenerator$8;
  17885. var sourceMapConsumer$1 = {};
  17886. var binarySearch$3 = {};
  17887. /* -*- Mode: js; js-indent-level: 2; -*- */
  17888. (function (exports) {
  17889. /*
  17890. * Copyright 2011 Mozilla Foundation and contributors
  17891. * Licensed under the New BSD license. See LICENSE or:
  17892. * http://opensource.org/licenses/BSD-3-Clause
  17893. */
  17894. exports.GREATEST_LOWER_BOUND = 1;
  17895. exports.LEAST_UPPER_BOUND = 2;
  17896. /**
  17897. * Recursive implementation of binary search.
  17898. *
  17899. * @param aLow Indices here and lower do not contain the needle.
  17900. * @param aHigh Indices here and higher do not contain the needle.
  17901. * @param aNeedle The element being searched for.
  17902. * @param aHaystack The non-empty array being searched.
  17903. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  17904. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  17905. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  17906. * closest element that is smaller than or greater than the one we are
  17907. * searching for, respectively, if the exact element cannot be found.
  17908. */
  17909. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  17910. // This function terminates when one of the following is true:
  17911. //
  17912. // 1. We find the exact element we are looking for.
  17913. //
  17914. // 2. We did not find the exact element, but we can return the index of
  17915. // the next-closest element.
  17916. //
  17917. // 3. We did not find the exact element, and there is no next-closest
  17918. // element than the one we are searching for, so we return -1.
  17919. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  17920. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  17921. if (cmp === 0) {
  17922. // Found the element we are looking for.
  17923. return mid;
  17924. }
  17925. else if (cmp > 0) {
  17926. // Our needle is greater than aHaystack[mid].
  17927. if (aHigh - mid > 1) {
  17928. // The element is in the upper half.
  17929. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  17930. }
  17931. // The exact needle element was not found in this haystack. Determine if
  17932. // we are in termination case (3) or (2) and return the appropriate thing.
  17933. if (aBias == exports.LEAST_UPPER_BOUND) {
  17934. return aHigh < aHaystack.length ? aHigh : -1;
  17935. } else {
  17936. return mid;
  17937. }
  17938. }
  17939. else {
  17940. // Our needle is less than aHaystack[mid].
  17941. if (mid - aLow > 1) {
  17942. // The element is in the lower half.
  17943. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  17944. }
  17945. // we are in termination case (3) or (2) and return the appropriate thing.
  17946. if (aBias == exports.LEAST_UPPER_BOUND) {
  17947. return mid;
  17948. } else {
  17949. return aLow < 0 ? -1 : aLow;
  17950. }
  17951. }
  17952. }
  17953. /**
  17954. * This is an implementation of binary search which will always try and return
  17955. * the index of the closest element if there is no exact hit. This is because
  17956. * mappings between original and generated line/col pairs are single points,
  17957. * and there is an implicit region between each of them, so a miss just means
  17958. * that you aren't on the very start of a region.
  17959. *
  17960. * @param aNeedle The element you are looking for.
  17961. * @param aHaystack The array that is being searched.
  17962. * @param aCompare A function which takes the needle and an element in the
  17963. * array and returns -1, 0, or 1 depending on whether the needle is less
  17964. * than, equal to, or greater than the element, respectively.
  17965. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  17966. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  17967. * closest element that is smaller than or greater than the one we are
  17968. * searching for, respectively, if the exact element cannot be found.
  17969. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  17970. */
  17971. exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  17972. if (aHaystack.length === 0) {
  17973. return -1;
  17974. }
  17975. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  17976. aCompare, aBias || exports.GREATEST_LOWER_BOUND);
  17977. if (index < 0) {
  17978. return -1;
  17979. }
  17980. // We have found either the exact element, or the next-closest element than
  17981. // the one we are searching for. However, there may be more than one such
  17982. // element. Make sure we always return the smallest of these.
  17983. while (index - 1 >= 0) {
  17984. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  17985. break;
  17986. }
  17987. --index;
  17988. }
  17989. return index;
  17990. };
  17991. } (binarySearch$3));
  17992. var quickSort$3 = {};
  17993. /* -*- Mode: js; js-indent-level: 2; -*- */
  17994. /*
  17995. * Copyright 2011 Mozilla Foundation and contributors
  17996. * Licensed under the New BSD license. See LICENSE or:
  17997. * http://opensource.org/licenses/BSD-3-Clause
  17998. */
  17999. // It turns out that some (most?) JavaScript engines don't self-host
  18000. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  18001. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  18002. // custom comparator function, calling back and forth between the VM's C++ and
  18003. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  18004. // worse generated code for the comparator function than would be optimal. In
  18005. // fact, when sorting with a comparator, these costs outweigh the benefits of
  18006. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  18007. // a ~3500ms mean speed-up in `bench/bench.html`.
  18008. function SortTemplate(comparator) {
  18009. /**
  18010. * Swap the elements indexed by `x` and `y` in the array `ary`.
  18011. *
  18012. * @param {Array} ary
  18013. * The array.
  18014. * @param {Number} x
  18015. * The index of the first item.
  18016. * @param {Number} y
  18017. * The index of the second item.
  18018. */
  18019. function swap(ary, x, y) {
  18020. var temp = ary[x];
  18021. ary[x] = ary[y];
  18022. ary[y] = temp;
  18023. }
  18024. /**
  18025. * Returns a random integer within the range `low .. high` inclusive.
  18026. *
  18027. * @param {Number} low
  18028. * The lower bound on the range.
  18029. * @param {Number} high
  18030. * The upper bound on the range.
  18031. */
  18032. function randomIntInRange(low, high) {
  18033. return Math.round(low + (Math.random() * (high - low)));
  18034. }
  18035. /**
  18036. * The Quick Sort algorithm.
  18037. *
  18038. * @param {Array} ary
  18039. * An array to sort.
  18040. * @param {function} comparator
  18041. * Function to use to compare two items.
  18042. * @param {Number} p
  18043. * Start index of the array
  18044. * @param {Number} r
  18045. * End index of the array
  18046. */
  18047. function doQuickSort(ary, comparator, p, r) {
  18048. // If our lower bound is less than our upper bound, we (1) partition the
  18049. // array into two pieces and (2) recurse on each half. If it is not, this is
  18050. // the empty array and our base case.
  18051. if (p < r) {
  18052. // (1) Partitioning.
  18053. //
  18054. // The partitioning chooses a pivot between `p` and `r` and moves all
  18055. // elements that are less than or equal to the pivot to the before it, and
  18056. // all the elements that are greater than it after it. The effect is that
  18057. // once partition is done, the pivot is in the exact place it will be when
  18058. // the array is put in sorted order, and it will not need to be moved
  18059. // again. This runs in O(n) time.
  18060. // Always choose a random pivot so that an input array which is reverse
  18061. // sorted does not cause O(n^2) running time.
  18062. var pivotIndex = randomIntInRange(p, r);
  18063. var i = p - 1;
  18064. swap(ary, pivotIndex, r);
  18065. var pivot = ary[r];
  18066. // Immediately after `j` is incremented in this loop, the following hold
  18067. // true:
  18068. //
  18069. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  18070. //
  18071. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  18072. for (var j = p; j < r; j++) {
  18073. if (comparator(ary[j], pivot, false) <= 0) {
  18074. i += 1;
  18075. swap(ary, i, j);
  18076. }
  18077. }
  18078. swap(ary, i + 1, j);
  18079. var q = i + 1;
  18080. // (2) Recurse on each half.
  18081. doQuickSort(ary, comparator, p, q - 1);
  18082. doQuickSort(ary, comparator, q + 1, r);
  18083. }
  18084. }
  18085. return doQuickSort;
  18086. }
  18087. function cloneSort(comparator) {
  18088. let template = SortTemplate.toString();
  18089. let templateFn = new Function(`return ${template}`)();
  18090. return templateFn(comparator);
  18091. }
  18092. /**
  18093. * Sort the given array in-place with the given comparator function.
  18094. *
  18095. * @param {Array} ary
  18096. * An array to sort.
  18097. * @param {function} comparator
  18098. * Function to use to compare two items.
  18099. */
  18100. let sortCache = new WeakMap();
  18101. quickSort$3.quickSort = function (ary, comparator, start = 0) {
  18102. let doQuickSort = sortCache.get(comparator);
  18103. if (doQuickSort === void 0) {
  18104. doQuickSort = cloneSort(comparator);
  18105. sortCache.set(comparator, doQuickSort);
  18106. }
  18107. doQuickSort(ary, comparator, start, ary.length - 1);
  18108. };
  18109. /* -*- Mode: js; js-indent-level: 2; -*- */
  18110. /*
  18111. * Copyright 2011 Mozilla Foundation and contributors
  18112. * Licensed under the New BSD license. See LICENSE or:
  18113. * http://opensource.org/licenses/BSD-3-Clause
  18114. */
  18115. var util$8 = util$c;
  18116. var binarySearch$2 = binarySearch$3;
  18117. var ArraySet$3 = arraySet$1.ArraySet;
  18118. var base64VLQ$2 = base64Vlq$1;
  18119. var quickSort$2 = quickSort$3.quickSort;
  18120. function SourceMapConsumer$6(aSourceMap, aSourceMapURL) {
  18121. var sourceMap = aSourceMap;
  18122. if (typeof aSourceMap === 'string') {
  18123. sourceMap = util$8.parseSourceMapInput(aSourceMap);
  18124. }
  18125. return sourceMap.sections != null
  18126. ? new IndexedSourceMapConsumer$1(sourceMap, aSourceMapURL)
  18127. : new BasicSourceMapConsumer$1(sourceMap, aSourceMapURL);
  18128. }
  18129. SourceMapConsumer$6.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  18130. return BasicSourceMapConsumer$1.fromSourceMap(aSourceMap, aSourceMapURL);
  18131. };
  18132. /**
  18133. * The version of the source mapping spec that we are consuming.
  18134. */
  18135. SourceMapConsumer$6.prototype._version = 3;
  18136. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  18137. // parsed mapping coordinates from the source map's "mappings" attribute. They
  18138. // are lazily instantiated, accessed via the `_generatedMappings` and
  18139. // `_originalMappings` getters respectively, and we only parse the mappings
  18140. // and create these arrays once queried for a source location. We jump through
  18141. // these hoops because there can be many thousands of mappings, and parsing
  18142. // them is expensive, so we only want to do it if we must.
  18143. //
  18144. // Each object in the arrays is of the form:
  18145. //
  18146. // {
  18147. // generatedLine: The line number in the generated code,
  18148. // generatedColumn: The column number in the generated code,
  18149. // source: The path to the original source file that generated this
  18150. // chunk of code,
  18151. // originalLine: The line number in the original source that
  18152. // corresponds to this chunk of generated code,
  18153. // originalColumn: The column number in the original source that
  18154. // corresponds to this chunk of generated code,
  18155. // name: The name of the original symbol which generated this chunk of
  18156. // code.
  18157. // }
  18158. //
  18159. // All properties except for `generatedLine` and `generatedColumn` can be
  18160. // `null`.
  18161. //
  18162. // `_generatedMappings` is ordered by the generated positions.
  18163. //
  18164. // `_originalMappings` is ordered by the original positions.
  18165. SourceMapConsumer$6.prototype.__generatedMappings = null;
  18166. Object.defineProperty(SourceMapConsumer$6.prototype, '_generatedMappings', {
  18167. configurable: true,
  18168. enumerable: true,
  18169. get: function () {
  18170. if (!this.__generatedMappings) {
  18171. this._parseMappings(this._mappings, this.sourceRoot);
  18172. }
  18173. return this.__generatedMappings;
  18174. }
  18175. });
  18176. SourceMapConsumer$6.prototype.__originalMappings = null;
  18177. Object.defineProperty(SourceMapConsumer$6.prototype, '_originalMappings', {
  18178. configurable: true,
  18179. enumerable: true,
  18180. get: function () {
  18181. if (!this.__originalMappings) {
  18182. this._parseMappings(this._mappings, this.sourceRoot);
  18183. }
  18184. return this.__originalMappings;
  18185. }
  18186. });
  18187. SourceMapConsumer$6.prototype._charIsMappingSeparator =
  18188. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  18189. var c = aStr.charAt(index);
  18190. return c === ";" || c === ",";
  18191. };
  18192. /**
  18193. * Parse the mappings in a string in to a data structure which we can easily
  18194. * query (the ordered arrays in the `this.__generatedMappings` and
  18195. * `this.__originalMappings` properties).
  18196. */
  18197. SourceMapConsumer$6.prototype._parseMappings =
  18198. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  18199. throw new Error("Subclasses must implement _parseMappings");
  18200. };
  18201. SourceMapConsumer$6.GENERATED_ORDER = 1;
  18202. SourceMapConsumer$6.ORIGINAL_ORDER = 2;
  18203. SourceMapConsumer$6.GREATEST_LOWER_BOUND = 1;
  18204. SourceMapConsumer$6.LEAST_UPPER_BOUND = 2;
  18205. /**
  18206. * Iterate over each mapping between an original source/line/column and a
  18207. * generated line/column in this source map.
  18208. *
  18209. * @param Function aCallback
  18210. * The function that is called with each mapping.
  18211. * @param Object aContext
  18212. * Optional. If specified, this object will be the value of `this` every
  18213. * time that `aCallback` is called.
  18214. * @param aOrder
  18215. * Either `SourceMapConsumer.GENERATED_ORDER` or
  18216. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  18217. * iterate over the mappings sorted by the generated file's line/column
  18218. * order or the original's source/line/column order, respectively. Defaults to
  18219. * `SourceMapConsumer.GENERATED_ORDER`.
  18220. */
  18221. SourceMapConsumer$6.prototype.eachMapping =
  18222. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  18223. var context = aContext || null;
  18224. var order = aOrder || SourceMapConsumer$6.GENERATED_ORDER;
  18225. var mappings;
  18226. switch (order) {
  18227. case SourceMapConsumer$6.GENERATED_ORDER:
  18228. mappings = this._generatedMappings;
  18229. break;
  18230. case SourceMapConsumer$6.ORIGINAL_ORDER:
  18231. mappings = this._originalMappings;
  18232. break;
  18233. default:
  18234. throw new Error("Unknown order of iteration.");
  18235. }
  18236. var sourceRoot = this.sourceRoot;
  18237. var boundCallback = aCallback.bind(context);
  18238. var names = this._names;
  18239. var sources = this._sources;
  18240. var sourceMapURL = this._sourceMapURL;
  18241. for (var i = 0, n = mappings.length; i < n; i++) {
  18242. var mapping = mappings[i];
  18243. var source = mapping.source === null ? null : sources.at(mapping.source);
  18244. source = util$8.computeSourceURL(sourceRoot, source, sourceMapURL);
  18245. boundCallback({
  18246. source: source,
  18247. generatedLine: mapping.generatedLine,
  18248. generatedColumn: mapping.generatedColumn,
  18249. originalLine: mapping.originalLine,
  18250. originalColumn: mapping.originalColumn,
  18251. name: mapping.name === null ? null : names.at(mapping.name)
  18252. });
  18253. }
  18254. };
  18255. /**
  18256. * Returns all generated line and column information for the original source,
  18257. * line, and column provided. If no column is provided, returns all mappings
  18258. * corresponding to a either the line we are searching for or the next
  18259. * closest line that has any mappings. Otherwise, returns all mappings
  18260. * corresponding to the given line and either the column we are searching for
  18261. * or the next closest column that has any offsets.
  18262. *
  18263. * The only argument is an object with the following properties:
  18264. *
  18265. * - source: The filename of the original source.
  18266. * - line: The line number in the original source. The line number is 1-based.
  18267. * - column: Optional. the column number in the original source.
  18268. * The column number is 0-based.
  18269. *
  18270. * and an array of objects is returned, each with the following properties:
  18271. *
  18272. * - line: The line number in the generated source, or null. The
  18273. * line number is 1-based.
  18274. * - column: The column number in the generated source, or null.
  18275. * The column number is 0-based.
  18276. */
  18277. SourceMapConsumer$6.prototype.allGeneratedPositionsFor =
  18278. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  18279. var line = util$8.getArg(aArgs, 'line');
  18280. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  18281. // returns the index of the closest mapping less than the needle. By
  18282. // setting needle.originalColumn to 0, we thus find the last mapping for
  18283. // the given line, provided such a mapping exists.
  18284. var needle = {
  18285. source: util$8.getArg(aArgs, 'source'),
  18286. originalLine: line,
  18287. originalColumn: util$8.getArg(aArgs, 'column', 0)
  18288. };
  18289. needle.source = this._findSourceIndex(needle.source);
  18290. if (needle.source < 0) {
  18291. return [];
  18292. }
  18293. var mappings = [];
  18294. var index = this._findMapping(needle,
  18295. this._originalMappings,
  18296. "originalLine",
  18297. "originalColumn",
  18298. util$8.compareByOriginalPositions,
  18299. binarySearch$2.LEAST_UPPER_BOUND);
  18300. if (index >= 0) {
  18301. var mapping = this._originalMappings[index];
  18302. if (aArgs.column === undefined) {
  18303. var originalLine = mapping.originalLine;
  18304. // Iterate until either we run out of mappings, or we run into
  18305. // a mapping for a different line than the one we found. Since
  18306. // mappings are sorted, this is guaranteed to find all mappings for
  18307. // the line we found.
  18308. while (mapping && mapping.originalLine === originalLine) {
  18309. mappings.push({
  18310. line: util$8.getArg(mapping, 'generatedLine', null),
  18311. column: util$8.getArg(mapping, 'generatedColumn', null),
  18312. lastColumn: util$8.getArg(mapping, 'lastGeneratedColumn', null)
  18313. });
  18314. mapping = this._originalMappings[++index];
  18315. }
  18316. } else {
  18317. var originalColumn = mapping.originalColumn;
  18318. // Iterate until either we run out of mappings, or we run into
  18319. // a mapping for a different line than the one we were searching for.
  18320. // Since mappings are sorted, this is guaranteed to find all mappings for
  18321. // the line we are searching for.
  18322. while (mapping &&
  18323. mapping.originalLine === line &&
  18324. mapping.originalColumn == originalColumn) {
  18325. mappings.push({
  18326. line: util$8.getArg(mapping, 'generatedLine', null),
  18327. column: util$8.getArg(mapping, 'generatedColumn', null),
  18328. lastColumn: util$8.getArg(mapping, 'lastGeneratedColumn', null)
  18329. });
  18330. mapping = this._originalMappings[++index];
  18331. }
  18332. }
  18333. }
  18334. return mappings;
  18335. };
  18336. sourceMapConsumer$1.SourceMapConsumer = SourceMapConsumer$6;
  18337. /**
  18338. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  18339. * query for information about the original file positions by giving it a file
  18340. * position in the generated source.
  18341. *
  18342. * The first parameter is the raw source map (either as a JSON string, or
  18343. * already parsed to an object). According to the spec, source maps have the
  18344. * following attributes:
  18345. *
  18346. * - version: Which version of the source map spec this map is following.
  18347. * - sources: An array of URLs to the original source files.
  18348. * - names: An array of identifiers which can be referrenced by individual mappings.
  18349. * - sourceRoot: Optional. The URL root from which all sources are relative.
  18350. * - sourcesContent: Optional. An array of contents of the original source files.
  18351. * - mappings: A string of base64 VLQs which contain the actual mappings.
  18352. * - file: Optional. The generated file this source map is associated with.
  18353. *
  18354. * Here is an example source map, taken from the source map spec[0]:
  18355. *
  18356. * {
  18357. * version : 3,
  18358. * file: "out.js",
  18359. * sourceRoot : "",
  18360. * sources: ["foo.js", "bar.js"],
  18361. * names: ["src", "maps", "are", "fun"],
  18362. * mappings: "AA,AB;;ABCDE;"
  18363. * }
  18364. *
  18365. * The second parameter, if given, is a string whose value is the URL
  18366. * at which the source map was found. This URL is used to compute the
  18367. * sources array.
  18368. *
  18369. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  18370. */
  18371. function BasicSourceMapConsumer$1(aSourceMap, aSourceMapURL) {
  18372. var sourceMap = aSourceMap;
  18373. if (typeof aSourceMap === 'string') {
  18374. sourceMap = util$8.parseSourceMapInput(aSourceMap);
  18375. }
  18376. var version = util$8.getArg(sourceMap, 'version');
  18377. var sources = util$8.getArg(sourceMap, 'sources');
  18378. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  18379. // requires the array) to play nice here.
  18380. var names = util$8.getArg(sourceMap, 'names', []);
  18381. var sourceRoot = util$8.getArg(sourceMap, 'sourceRoot', null);
  18382. var sourcesContent = util$8.getArg(sourceMap, 'sourcesContent', null);
  18383. var mappings = util$8.getArg(sourceMap, 'mappings');
  18384. var file = util$8.getArg(sourceMap, 'file', null);
  18385. // Once again, Sass deviates from the spec and supplies the version as a
  18386. // string rather than a number, so we use loose equality checking here.
  18387. if (version != this._version) {
  18388. throw new Error('Unsupported version: ' + version);
  18389. }
  18390. if (sourceRoot) {
  18391. sourceRoot = util$8.normalize(sourceRoot);
  18392. }
  18393. sources = sources
  18394. .map(String)
  18395. // Some source maps produce relative source paths like "./foo.js" instead of
  18396. // "foo.js". Normalize these first so that future comparisons will succeed.
  18397. // See bugzil.la/1090768.
  18398. .map(util$8.normalize)
  18399. // Always ensure that absolute sources are internally stored relative to
  18400. // the source root, if the source root is absolute. Not doing this would
  18401. // be particularly problematic when the source root is a prefix of the
  18402. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  18403. .map(function (source) {
  18404. return sourceRoot && util$8.isAbsolute(sourceRoot) && util$8.isAbsolute(source)
  18405. ? util$8.relative(sourceRoot, source)
  18406. : source;
  18407. });
  18408. // Pass `true` below to allow duplicate names and sources. While source maps
  18409. // are intended to be compressed and deduplicated, the TypeScript compiler
  18410. // sometimes generates source maps with duplicates in them. See Github issue
  18411. // #72 and bugzil.la/889492.
  18412. this._names = ArraySet$3.fromArray(names.map(String), true);
  18413. this._sources = ArraySet$3.fromArray(sources, true);
  18414. this._absoluteSources = this._sources.toArray().map(function (s) {
  18415. return util$8.computeSourceURL(sourceRoot, s, aSourceMapURL);
  18416. });
  18417. this.sourceRoot = sourceRoot;
  18418. this.sourcesContent = sourcesContent;
  18419. this._mappings = mappings;
  18420. this._sourceMapURL = aSourceMapURL;
  18421. this.file = file;
  18422. }
  18423. BasicSourceMapConsumer$1.prototype = Object.create(SourceMapConsumer$6.prototype);
  18424. BasicSourceMapConsumer$1.prototype.consumer = SourceMapConsumer$6;
  18425. /**
  18426. * Utility function to find the index of a source. Returns -1 if not
  18427. * found.
  18428. */
  18429. BasicSourceMapConsumer$1.prototype._findSourceIndex = function(aSource) {
  18430. var relativeSource = aSource;
  18431. if (this.sourceRoot != null) {
  18432. relativeSource = util$8.relative(this.sourceRoot, relativeSource);
  18433. }
  18434. if (this._sources.has(relativeSource)) {
  18435. return this._sources.indexOf(relativeSource);
  18436. }
  18437. // Maybe aSource is an absolute URL as returned by |sources|. In
  18438. // this case we can't simply undo the transform.
  18439. var i;
  18440. for (i = 0; i < this._absoluteSources.length; ++i) {
  18441. if (this._absoluteSources[i] == aSource) {
  18442. return i;
  18443. }
  18444. }
  18445. return -1;
  18446. };
  18447. /**
  18448. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  18449. *
  18450. * @param SourceMapGenerator aSourceMap
  18451. * The source map that will be consumed.
  18452. * @param String aSourceMapURL
  18453. * The URL at which the source map can be found (optional)
  18454. * @returns BasicSourceMapConsumer
  18455. */
  18456. BasicSourceMapConsumer$1.fromSourceMap =
  18457. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  18458. var smc = Object.create(BasicSourceMapConsumer$1.prototype);
  18459. var names = smc._names = ArraySet$3.fromArray(aSourceMap._names.toArray(), true);
  18460. var sources = smc._sources = ArraySet$3.fromArray(aSourceMap._sources.toArray(), true);
  18461. smc.sourceRoot = aSourceMap._sourceRoot;
  18462. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  18463. smc.sourceRoot);
  18464. smc.file = aSourceMap._file;
  18465. smc._sourceMapURL = aSourceMapURL;
  18466. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  18467. return util$8.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  18468. });
  18469. // Because we are modifying the entries (by converting string sources and
  18470. // names to indices into the sources and names ArraySets), we have to make
  18471. // a copy of the entry or else bad things happen. Shared mutable state
  18472. // strikes again! See github issue #191.
  18473. var generatedMappings = aSourceMap._mappings.toArray().slice();
  18474. var destGeneratedMappings = smc.__generatedMappings = [];
  18475. var destOriginalMappings = smc.__originalMappings = [];
  18476. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  18477. var srcMapping = generatedMappings[i];
  18478. var destMapping = new Mapping$1;
  18479. destMapping.generatedLine = srcMapping.generatedLine;
  18480. destMapping.generatedColumn = srcMapping.generatedColumn;
  18481. if (srcMapping.source) {
  18482. destMapping.source = sources.indexOf(srcMapping.source);
  18483. destMapping.originalLine = srcMapping.originalLine;
  18484. destMapping.originalColumn = srcMapping.originalColumn;
  18485. if (srcMapping.name) {
  18486. destMapping.name = names.indexOf(srcMapping.name);
  18487. }
  18488. destOriginalMappings.push(destMapping);
  18489. }
  18490. destGeneratedMappings.push(destMapping);
  18491. }
  18492. quickSort$2(smc.__originalMappings, util$8.compareByOriginalPositions);
  18493. return smc;
  18494. };
  18495. /**
  18496. * The version of the source mapping spec that we are consuming.
  18497. */
  18498. BasicSourceMapConsumer$1.prototype._version = 3;
  18499. /**
  18500. * The list of original sources.
  18501. */
  18502. Object.defineProperty(BasicSourceMapConsumer$1.prototype, 'sources', {
  18503. get: function () {
  18504. return this._absoluteSources.slice();
  18505. }
  18506. });
  18507. /**
  18508. * Provide the JIT with a nice shape / hidden class.
  18509. */
  18510. function Mapping$1() {
  18511. this.generatedLine = 0;
  18512. this.generatedColumn = 0;
  18513. this.source = null;
  18514. this.originalLine = null;
  18515. this.originalColumn = null;
  18516. this.name = null;
  18517. }
  18518. /**
  18519. * Parse the mappings in a string in to a data structure which we can easily
  18520. * query (the ordered arrays in the `this.__generatedMappings` and
  18521. * `this.__originalMappings` properties).
  18522. */
  18523. const compareGenerated = util$8.compareByGeneratedPositionsDeflatedNoLine;
  18524. function sortGenerated(array, start) {
  18525. let l = array.length;
  18526. let n = array.length - start;
  18527. if (n <= 1) {
  18528. return;
  18529. } else if (n == 2) {
  18530. let a = array[start];
  18531. let b = array[start + 1];
  18532. if (compareGenerated(a, b) > 0) {
  18533. array[start] = b;
  18534. array[start + 1] = a;
  18535. }
  18536. } else if (n < 20) {
  18537. for (let i = start; i < l; i++) {
  18538. for (let j = i; j > start; j--) {
  18539. let a = array[j - 1];
  18540. let b = array[j];
  18541. if (compareGenerated(a, b) <= 0) {
  18542. break;
  18543. }
  18544. array[j - 1] = b;
  18545. array[j] = a;
  18546. }
  18547. }
  18548. } else {
  18549. quickSort$2(array, compareGenerated, start);
  18550. }
  18551. }
  18552. BasicSourceMapConsumer$1.prototype._parseMappings =
  18553. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  18554. var generatedLine = 1;
  18555. var previousGeneratedColumn = 0;
  18556. var previousOriginalLine = 0;
  18557. var previousOriginalColumn = 0;
  18558. var previousSource = 0;
  18559. var previousName = 0;
  18560. var length = aStr.length;
  18561. var index = 0;
  18562. var temp = {};
  18563. var originalMappings = [];
  18564. var generatedMappings = [];
  18565. var mapping, segment, end, value;
  18566. let subarrayStart = 0;
  18567. while (index < length) {
  18568. if (aStr.charAt(index) === ';') {
  18569. generatedLine++;
  18570. index++;
  18571. previousGeneratedColumn = 0;
  18572. sortGenerated(generatedMappings, subarrayStart);
  18573. subarrayStart = generatedMappings.length;
  18574. }
  18575. else if (aStr.charAt(index) === ',') {
  18576. index++;
  18577. }
  18578. else {
  18579. mapping = new Mapping$1();
  18580. mapping.generatedLine = generatedLine;
  18581. for (end = index; end < length; end++) {
  18582. if (this._charIsMappingSeparator(aStr, end)) {
  18583. break;
  18584. }
  18585. }
  18586. aStr.slice(index, end);
  18587. segment = [];
  18588. while (index < end) {
  18589. base64VLQ$2.decode(aStr, index, temp);
  18590. value = temp.value;
  18591. index = temp.rest;
  18592. segment.push(value);
  18593. }
  18594. if (segment.length === 2) {
  18595. throw new Error('Found a source, but no line and column');
  18596. }
  18597. if (segment.length === 3) {
  18598. throw new Error('Found a source and line, but no column');
  18599. }
  18600. // Generated column.
  18601. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  18602. previousGeneratedColumn = mapping.generatedColumn;
  18603. if (segment.length > 1) {
  18604. // Original source.
  18605. mapping.source = previousSource + segment[1];
  18606. previousSource += segment[1];
  18607. // Original line.
  18608. mapping.originalLine = previousOriginalLine + segment[2];
  18609. previousOriginalLine = mapping.originalLine;
  18610. // Lines are stored 0-based
  18611. mapping.originalLine += 1;
  18612. // Original column.
  18613. mapping.originalColumn = previousOriginalColumn + segment[3];
  18614. previousOriginalColumn = mapping.originalColumn;
  18615. if (segment.length > 4) {
  18616. // Original name.
  18617. mapping.name = previousName + segment[4];
  18618. previousName += segment[4];
  18619. }
  18620. }
  18621. generatedMappings.push(mapping);
  18622. if (typeof mapping.originalLine === 'number') {
  18623. let currentSource = mapping.source;
  18624. while (originalMappings.length <= currentSource) {
  18625. originalMappings.push(null);
  18626. }
  18627. if (originalMappings[currentSource] === null) {
  18628. originalMappings[currentSource] = [];
  18629. }
  18630. originalMappings[currentSource].push(mapping);
  18631. }
  18632. }
  18633. }
  18634. sortGenerated(generatedMappings, subarrayStart);
  18635. this.__generatedMappings = generatedMappings;
  18636. for (var i = 0; i < originalMappings.length; i++) {
  18637. if (originalMappings[i] != null) {
  18638. quickSort$2(originalMappings[i], util$8.compareByOriginalPositionsNoSource);
  18639. }
  18640. }
  18641. this.__originalMappings = [].concat(...originalMappings);
  18642. };
  18643. /**
  18644. * Find the mapping that best matches the hypothetical "needle" mapping that
  18645. * we are searching for in the given "haystack" of mappings.
  18646. */
  18647. BasicSourceMapConsumer$1.prototype._findMapping =
  18648. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  18649. aColumnName, aComparator, aBias) {
  18650. // To return the position we are searching for, we must first find the
  18651. // mapping for the given position and then return the opposite position it
  18652. // points to. Because the mappings are sorted, we can use binary search to
  18653. // find the best mapping.
  18654. if (aNeedle[aLineName] <= 0) {
  18655. throw new TypeError('Line must be greater than or equal to 1, got '
  18656. + aNeedle[aLineName]);
  18657. }
  18658. if (aNeedle[aColumnName] < 0) {
  18659. throw new TypeError('Column must be greater than or equal to 0, got '
  18660. + aNeedle[aColumnName]);
  18661. }
  18662. return binarySearch$2.search(aNeedle, aMappings, aComparator, aBias);
  18663. };
  18664. /**
  18665. * Compute the last column for each generated mapping. The last column is
  18666. * inclusive.
  18667. */
  18668. BasicSourceMapConsumer$1.prototype.computeColumnSpans =
  18669. function SourceMapConsumer_computeColumnSpans() {
  18670. for (var index = 0; index < this._generatedMappings.length; ++index) {
  18671. var mapping = this._generatedMappings[index];
  18672. // Mappings do not contain a field for the last generated columnt. We
  18673. // can come up with an optimistic estimate, however, by assuming that
  18674. // mappings are contiguous (i.e. given two consecutive mappings, the
  18675. // first mapping ends where the second one starts).
  18676. if (index + 1 < this._generatedMappings.length) {
  18677. var nextMapping = this._generatedMappings[index + 1];
  18678. if (mapping.generatedLine === nextMapping.generatedLine) {
  18679. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  18680. continue;
  18681. }
  18682. }
  18683. // The last mapping for each line spans the entire line.
  18684. mapping.lastGeneratedColumn = Infinity;
  18685. }
  18686. };
  18687. /**
  18688. * Returns the original source, line, and column information for the generated
  18689. * source's line and column positions provided. The only argument is an object
  18690. * with the following properties:
  18691. *
  18692. * - line: The line number in the generated source. The line number
  18693. * is 1-based.
  18694. * - column: The column number in the generated source. The column
  18695. * number is 0-based.
  18696. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  18697. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  18698. * closest element that is smaller than or greater than the one we are
  18699. * searching for, respectively, if the exact element cannot be found.
  18700. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  18701. *
  18702. * and an object is returned with the following properties:
  18703. *
  18704. * - source: The original source file, or null.
  18705. * - line: The line number in the original source, or null. The
  18706. * line number is 1-based.
  18707. * - column: The column number in the original source, or null. The
  18708. * column number is 0-based.
  18709. * - name: The original identifier, or null.
  18710. */
  18711. BasicSourceMapConsumer$1.prototype.originalPositionFor =
  18712. function SourceMapConsumer_originalPositionFor(aArgs) {
  18713. var needle = {
  18714. generatedLine: util$8.getArg(aArgs, 'line'),
  18715. generatedColumn: util$8.getArg(aArgs, 'column')
  18716. };
  18717. var index = this._findMapping(
  18718. needle,
  18719. this._generatedMappings,
  18720. "generatedLine",
  18721. "generatedColumn",
  18722. util$8.compareByGeneratedPositionsDeflated,
  18723. util$8.getArg(aArgs, 'bias', SourceMapConsumer$6.GREATEST_LOWER_BOUND)
  18724. );
  18725. if (index >= 0) {
  18726. var mapping = this._generatedMappings[index];
  18727. if (mapping.generatedLine === needle.generatedLine) {
  18728. var source = util$8.getArg(mapping, 'source', null);
  18729. if (source !== null) {
  18730. source = this._sources.at(source);
  18731. source = util$8.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  18732. }
  18733. var name = util$8.getArg(mapping, 'name', null);
  18734. if (name !== null) {
  18735. name = this._names.at(name);
  18736. }
  18737. return {
  18738. source: source,
  18739. line: util$8.getArg(mapping, 'originalLine', null),
  18740. column: util$8.getArg(mapping, 'originalColumn', null),
  18741. name: name
  18742. };
  18743. }
  18744. }
  18745. return {
  18746. source: null,
  18747. line: null,
  18748. column: null,
  18749. name: null
  18750. };
  18751. };
  18752. /**
  18753. * Return true if we have the source content for every source in the source
  18754. * map, false otherwise.
  18755. */
  18756. BasicSourceMapConsumer$1.prototype.hasContentsOfAllSources =
  18757. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  18758. if (!this.sourcesContent) {
  18759. return false;
  18760. }
  18761. return this.sourcesContent.length >= this._sources.size() &&
  18762. !this.sourcesContent.some(function (sc) { return sc == null; });
  18763. };
  18764. /**
  18765. * Returns the original source content. The only argument is the url of the
  18766. * original source file. Returns null if no original source content is
  18767. * available.
  18768. */
  18769. BasicSourceMapConsumer$1.prototype.sourceContentFor =
  18770. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  18771. if (!this.sourcesContent) {
  18772. return null;
  18773. }
  18774. var index = this._findSourceIndex(aSource);
  18775. if (index >= 0) {
  18776. return this.sourcesContent[index];
  18777. }
  18778. var relativeSource = aSource;
  18779. if (this.sourceRoot != null) {
  18780. relativeSource = util$8.relative(this.sourceRoot, relativeSource);
  18781. }
  18782. var url;
  18783. if (this.sourceRoot != null
  18784. && (url = util$8.urlParse(this.sourceRoot))) {
  18785. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  18786. // many users. We can help them out when they expect file:// URIs to
  18787. // behave like it would if they were running a local HTTP server. See
  18788. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  18789. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  18790. if (url.scheme == "file"
  18791. && this._sources.has(fileUriAbsPath)) {
  18792. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  18793. }
  18794. if ((!url.path || url.path == "/")
  18795. && this._sources.has("/" + relativeSource)) {
  18796. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  18797. }
  18798. }
  18799. // This function is used recursively from
  18800. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  18801. // don't want to throw if we can't find the source - we just want to
  18802. // return null, so we provide a flag to exit gracefully.
  18803. if (nullOnMissing) {
  18804. return null;
  18805. }
  18806. else {
  18807. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  18808. }
  18809. };
  18810. /**
  18811. * Returns the generated line and column information for the original source,
  18812. * line, and column positions provided. The only argument is an object with
  18813. * the following properties:
  18814. *
  18815. * - source: The filename of the original source.
  18816. * - line: The line number in the original source. The line number
  18817. * is 1-based.
  18818. * - column: The column number in the original source. The column
  18819. * number is 0-based.
  18820. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  18821. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  18822. * closest element that is smaller than or greater than the one we are
  18823. * searching for, respectively, if the exact element cannot be found.
  18824. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  18825. *
  18826. * and an object is returned with the following properties:
  18827. *
  18828. * - line: The line number in the generated source, or null. The
  18829. * line number is 1-based.
  18830. * - column: The column number in the generated source, or null.
  18831. * The column number is 0-based.
  18832. */
  18833. BasicSourceMapConsumer$1.prototype.generatedPositionFor =
  18834. function SourceMapConsumer_generatedPositionFor(aArgs) {
  18835. var source = util$8.getArg(aArgs, 'source');
  18836. source = this._findSourceIndex(source);
  18837. if (source < 0) {
  18838. return {
  18839. line: null,
  18840. column: null,
  18841. lastColumn: null
  18842. };
  18843. }
  18844. var needle = {
  18845. source: source,
  18846. originalLine: util$8.getArg(aArgs, 'line'),
  18847. originalColumn: util$8.getArg(aArgs, 'column')
  18848. };
  18849. var index = this._findMapping(
  18850. needle,
  18851. this._originalMappings,
  18852. "originalLine",
  18853. "originalColumn",
  18854. util$8.compareByOriginalPositions,
  18855. util$8.getArg(aArgs, 'bias', SourceMapConsumer$6.GREATEST_LOWER_BOUND)
  18856. );
  18857. if (index >= 0) {
  18858. var mapping = this._originalMappings[index];
  18859. if (mapping.source === needle.source) {
  18860. return {
  18861. line: util$8.getArg(mapping, 'generatedLine', null),
  18862. column: util$8.getArg(mapping, 'generatedColumn', null),
  18863. lastColumn: util$8.getArg(mapping, 'lastGeneratedColumn', null)
  18864. };
  18865. }
  18866. }
  18867. return {
  18868. line: null,
  18869. column: null,
  18870. lastColumn: null
  18871. };
  18872. };
  18873. sourceMapConsumer$1.BasicSourceMapConsumer = BasicSourceMapConsumer$1;
  18874. /**
  18875. * An IndexedSourceMapConsumer instance represents a parsed source map which
  18876. * we can query for information. It differs from BasicSourceMapConsumer in
  18877. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  18878. * input.
  18879. *
  18880. * The first parameter is a raw source map (either as a JSON string, or already
  18881. * parsed to an object). According to the spec for indexed source maps, they
  18882. * have the following attributes:
  18883. *
  18884. * - version: Which version of the source map spec this map is following.
  18885. * - file: Optional. The generated file this source map is associated with.
  18886. * - sections: A list of section definitions.
  18887. *
  18888. * Each value under the "sections" field has two fields:
  18889. * - offset: The offset into the original specified at which this section
  18890. * begins to apply, defined as an object with a "line" and "column"
  18891. * field.
  18892. * - map: A source map definition. This source map could also be indexed,
  18893. * but doesn't have to be.
  18894. *
  18895. * Instead of the "map" field, it's also possible to have a "url" field
  18896. * specifying a URL to retrieve a source map from, but that's currently
  18897. * unsupported.
  18898. *
  18899. * Here's an example source map, taken from the source map spec[0], but
  18900. * modified to omit a section which uses the "url" field.
  18901. *
  18902. * {
  18903. * version : 3,
  18904. * file: "app.js",
  18905. * sections: [{
  18906. * offset: {line:100, column:10},
  18907. * map: {
  18908. * version : 3,
  18909. * file: "section.js",
  18910. * sources: ["foo.js", "bar.js"],
  18911. * names: ["src", "maps", "are", "fun"],
  18912. * mappings: "AAAA,E;;ABCDE;"
  18913. * }
  18914. * }],
  18915. * }
  18916. *
  18917. * The second parameter, if given, is a string whose value is the URL
  18918. * at which the source map was found. This URL is used to compute the
  18919. * sources array.
  18920. *
  18921. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  18922. */
  18923. function IndexedSourceMapConsumer$1(aSourceMap, aSourceMapURL) {
  18924. var sourceMap = aSourceMap;
  18925. if (typeof aSourceMap === 'string') {
  18926. sourceMap = util$8.parseSourceMapInput(aSourceMap);
  18927. }
  18928. var version = util$8.getArg(sourceMap, 'version');
  18929. var sections = util$8.getArg(sourceMap, 'sections');
  18930. if (version != this._version) {
  18931. throw new Error('Unsupported version: ' + version);
  18932. }
  18933. this._sources = new ArraySet$3();
  18934. this._names = new ArraySet$3();
  18935. var lastOffset = {
  18936. line: -1,
  18937. column: 0
  18938. };
  18939. this._sections = sections.map(function (s) {
  18940. if (s.url) {
  18941. // The url field will require support for asynchronicity.
  18942. // See https://github.com/mozilla/source-map/issues/16
  18943. throw new Error('Support for url field in sections not implemented.');
  18944. }
  18945. var offset = util$8.getArg(s, 'offset');
  18946. var offsetLine = util$8.getArg(offset, 'line');
  18947. var offsetColumn = util$8.getArg(offset, 'column');
  18948. if (offsetLine < lastOffset.line ||
  18949. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  18950. throw new Error('Section offsets must be ordered and non-overlapping.');
  18951. }
  18952. lastOffset = offset;
  18953. return {
  18954. generatedOffset: {
  18955. // The offset fields are 0-based, but we use 1-based indices when
  18956. // encoding/decoding from VLQ.
  18957. generatedLine: offsetLine + 1,
  18958. generatedColumn: offsetColumn + 1
  18959. },
  18960. consumer: new SourceMapConsumer$6(util$8.getArg(s, 'map'), aSourceMapURL)
  18961. }
  18962. });
  18963. }
  18964. IndexedSourceMapConsumer$1.prototype = Object.create(SourceMapConsumer$6.prototype);
  18965. IndexedSourceMapConsumer$1.prototype.constructor = SourceMapConsumer$6;
  18966. /**
  18967. * The version of the source mapping spec that we are consuming.
  18968. */
  18969. IndexedSourceMapConsumer$1.prototype._version = 3;
  18970. /**
  18971. * The list of original sources.
  18972. */
  18973. Object.defineProperty(IndexedSourceMapConsumer$1.prototype, 'sources', {
  18974. get: function () {
  18975. var sources = [];
  18976. for (var i = 0; i < this._sections.length; i++) {
  18977. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  18978. sources.push(this._sections[i].consumer.sources[j]);
  18979. }
  18980. }
  18981. return sources;
  18982. }
  18983. });
  18984. /**
  18985. * Returns the original source, line, and column information for the generated
  18986. * source's line and column positions provided. The only argument is an object
  18987. * with the following properties:
  18988. *
  18989. * - line: The line number in the generated source. The line number
  18990. * is 1-based.
  18991. * - column: The column number in the generated source. The column
  18992. * number is 0-based.
  18993. *
  18994. * and an object is returned with the following properties:
  18995. *
  18996. * - source: The original source file, or null.
  18997. * - line: The line number in the original source, or null. The
  18998. * line number is 1-based.
  18999. * - column: The column number in the original source, or null. The
  19000. * column number is 0-based.
  19001. * - name: The original identifier, or null.
  19002. */
  19003. IndexedSourceMapConsumer$1.prototype.originalPositionFor =
  19004. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  19005. var needle = {
  19006. generatedLine: util$8.getArg(aArgs, 'line'),
  19007. generatedColumn: util$8.getArg(aArgs, 'column')
  19008. };
  19009. // Find the section containing the generated position we're trying to map
  19010. // to an original position.
  19011. var sectionIndex = binarySearch$2.search(needle, this._sections,
  19012. function(needle, section) {
  19013. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  19014. if (cmp) {
  19015. return cmp;
  19016. }
  19017. return (needle.generatedColumn -
  19018. section.generatedOffset.generatedColumn);
  19019. });
  19020. var section = this._sections[sectionIndex];
  19021. if (!section) {
  19022. return {
  19023. source: null,
  19024. line: null,
  19025. column: null,
  19026. name: null
  19027. };
  19028. }
  19029. return section.consumer.originalPositionFor({
  19030. line: needle.generatedLine -
  19031. (section.generatedOffset.generatedLine - 1),
  19032. column: needle.generatedColumn -
  19033. (section.generatedOffset.generatedLine === needle.generatedLine
  19034. ? section.generatedOffset.generatedColumn - 1
  19035. : 0),
  19036. bias: aArgs.bias
  19037. });
  19038. };
  19039. /**
  19040. * Return true if we have the source content for every source in the source
  19041. * map, false otherwise.
  19042. */
  19043. IndexedSourceMapConsumer$1.prototype.hasContentsOfAllSources =
  19044. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  19045. return this._sections.every(function (s) {
  19046. return s.consumer.hasContentsOfAllSources();
  19047. });
  19048. };
  19049. /**
  19050. * Returns the original source content. The only argument is the url of the
  19051. * original source file. Returns null if no original source content is
  19052. * available.
  19053. */
  19054. IndexedSourceMapConsumer$1.prototype.sourceContentFor =
  19055. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  19056. for (var i = 0; i < this._sections.length; i++) {
  19057. var section = this._sections[i];
  19058. var content = section.consumer.sourceContentFor(aSource, true);
  19059. if (content) {
  19060. return content;
  19061. }
  19062. }
  19063. if (nullOnMissing) {
  19064. return null;
  19065. }
  19066. else {
  19067. throw new Error('"' + aSource + '" is not in the SourceMap.');
  19068. }
  19069. };
  19070. /**
  19071. * Returns the generated line and column information for the original source,
  19072. * line, and column positions provided. The only argument is an object with
  19073. * the following properties:
  19074. *
  19075. * - source: The filename of the original source.
  19076. * - line: The line number in the original source. The line number
  19077. * is 1-based.
  19078. * - column: The column number in the original source. The column
  19079. * number is 0-based.
  19080. *
  19081. * and an object is returned with the following properties:
  19082. *
  19083. * - line: The line number in the generated source, or null. The
  19084. * line number is 1-based.
  19085. * - column: The column number in the generated source, or null.
  19086. * The column number is 0-based.
  19087. */
  19088. IndexedSourceMapConsumer$1.prototype.generatedPositionFor =
  19089. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  19090. for (var i = 0; i < this._sections.length; i++) {
  19091. var section = this._sections[i];
  19092. // Only consider this section if the requested source is in the list of
  19093. // sources of the consumer.
  19094. if (section.consumer._findSourceIndex(util$8.getArg(aArgs, 'source')) === -1) {
  19095. continue;
  19096. }
  19097. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  19098. if (generatedPosition) {
  19099. var ret = {
  19100. line: generatedPosition.line +
  19101. (section.generatedOffset.generatedLine - 1),
  19102. column: generatedPosition.column +
  19103. (section.generatedOffset.generatedLine === generatedPosition.line
  19104. ? section.generatedOffset.generatedColumn - 1
  19105. : 0)
  19106. };
  19107. return ret;
  19108. }
  19109. }
  19110. return {
  19111. line: null,
  19112. column: null
  19113. };
  19114. };
  19115. /**
  19116. * Parse the mappings in a string in to a data structure which we can easily
  19117. * query (the ordered arrays in the `this.__generatedMappings` and
  19118. * `this.__originalMappings` properties).
  19119. */
  19120. IndexedSourceMapConsumer$1.prototype._parseMappings =
  19121. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  19122. this.__generatedMappings = [];
  19123. this.__originalMappings = [];
  19124. for (var i = 0; i < this._sections.length; i++) {
  19125. var section = this._sections[i];
  19126. var sectionMappings = section.consumer._generatedMappings;
  19127. for (var j = 0; j < sectionMappings.length; j++) {
  19128. var mapping = sectionMappings[j];
  19129. var source = section.consumer._sources.at(mapping.source);
  19130. source = util$8.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  19131. this._sources.add(source);
  19132. source = this._sources.indexOf(source);
  19133. var name = null;
  19134. if (mapping.name) {
  19135. name = section.consumer._names.at(mapping.name);
  19136. this._names.add(name);
  19137. name = this._names.indexOf(name);
  19138. }
  19139. // The mappings coming from the consumer for the section have
  19140. // generated positions relative to the start of the section, so we
  19141. // need to offset them to be relative to the start of the concatenated
  19142. // generated file.
  19143. var adjustedMapping = {
  19144. source: source,
  19145. generatedLine: mapping.generatedLine +
  19146. (section.generatedOffset.generatedLine - 1),
  19147. generatedColumn: mapping.generatedColumn +
  19148. (section.generatedOffset.generatedLine === mapping.generatedLine
  19149. ? section.generatedOffset.generatedColumn - 1
  19150. : 0),
  19151. originalLine: mapping.originalLine,
  19152. originalColumn: mapping.originalColumn,
  19153. name: name
  19154. };
  19155. this.__generatedMappings.push(adjustedMapping);
  19156. if (typeof adjustedMapping.originalLine === 'number') {
  19157. this.__originalMappings.push(adjustedMapping);
  19158. }
  19159. }
  19160. }
  19161. quickSort$2(this.__generatedMappings, util$8.compareByGeneratedPositionsDeflated);
  19162. quickSort$2(this.__originalMappings, util$8.compareByOriginalPositions);
  19163. };
  19164. sourceMapConsumer$1.IndexedSourceMapConsumer = IndexedSourceMapConsumer$1;
  19165. var sourceNode$1 = {};
  19166. /* -*- Mode: js; js-indent-level: 2; -*- */
  19167. /*
  19168. * Copyright 2011 Mozilla Foundation and contributors
  19169. * Licensed under the New BSD license. See LICENSE or:
  19170. * http://opensource.org/licenses/BSD-3-Clause
  19171. */
  19172. var SourceMapGenerator$7 = sourceMapGenerator$1.SourceMapGenerator;
  19173. var util$7 = util$c;
  19174. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  19175. // operating systems these days (capturing the result).
  19176. var REGEX_NEWLINE$1 = /(\r?\n)/;
  19177. // Newline character code for charCodeAt() comparisons
  19178. var NEWLINE_CODE$1 = 10;
  19179. // Private symbol for identifying `SourceNode`s when multiple versions of
  19180. // the source-map library are loaded. This MUST NOT CHANGE across
  19181. // versions!
  19182. var isSourceNode$1 = "$$$isSourceNode$$$";
  19183. /**
  19184. * SourceNodes provide a way to abstract over interpolating/concatenating
  19185. * snippets of generated JavaScript source code while maintaining the line and
  19186. * column information associated with the original source code.
  19187. *
  19188. * @param aLine The original line number.
  19189. * @param aColumn The original column number.
  19190. * @param aSource The original source's filename.
  19191. * @param aChunks Optional. An array of strings which are snippets of
  19192. * generated JS, or other SourceNodes.
  19193. * @param aName The original identifier.
  19194. */
  19195. function SourceNode$1(aLine, aColumn, aSource, aChunks, aName) {
  19196. this.children = [];
  19197. this.sourceContents = {};
  19198. this.line = aLine == null ? null : aLine;
  19199. this.column = aColumn == null ? null : aColumn;
  19200. this.source = aSource == null ? null : aSource;
  19201. this.name = aName == null ? null : aName;
  19202. this[isSourceNode$1] = true;
  19203. if (aChunks != null) this.add(aChunks);
  19204. }
  19205. /**
  19206. * Creates a SourceNode from generated code and a SourceMapConsumer.
  19207. *
  19208. * @param aGeneratedCode The generated code
  19209. * @param aSourceMapConsumer The SourceMap for the generated code
  19210. * @param aRelativePath Optional. The path that relative sources in the
  19211. * SourceMapConsumer should be relative to.
  19212. */
  19213. SourceNode$1.fromStringWithSourceMap =
  19214. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  19215. // The SourceNode we want to fill with the generated code
  19216. // and the SourceMap
  19217. var node = new SourceNode$1();
  19218. // All even indices of this array are one line of the generated code,
  19219. // while all odd indices are the newlines between two adjacent lines
  19220. // (since `REGEX_NEWLINE` captures its match).
  19221. // Processed fragments are accessed by calling `shiftNextLine`.
  19222. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE$1);
  19223. var remainingLinesIndex = 0;
  19224. var shiftNextLine = function() {
  19225. var lineContents = getNextLine();
  19226. // The last line of a file might not have a newline.
  19227. var newLine = getNextLine() || "";
  19228. return lineContents + newLine;
  19229. function getNextLine() {
  19230. return remainingLinesIndex < remainingLines.length ?
  19231. remainingLines[remainingLinesIndex++] : undefined;
  19232. }
  19233. };
  19234. // We need to remember the position of "remainingLines"
  19235. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  19236. // The generate SourceNodes we need a code range.
  19237. // To extract it current and last mapping is used.
  19238. // Here we store the last mapping.
  19239. var lastMapping = null;
  19240. aSourceMapConsumer.eachMapping(function (mapping) {
  19241. if (lastMapping !== null) {
  19242. // We add the code from "lastMapping" to "mapping":
  19243. // First check if there is a new line in between.
  19244. if (lastGeneratedLine < mapping.generatedLine) {
  19245. // Associate first line with "lastMapping"
  19246. addMappingWithCode(lastMapping, shiftNextLine());
  19247. lastGeneratedLine++;
  19248. lastGeneratedColumn = 0;
  19249. // The remaining code is added without mapping
  19250. } else {
  19251. // There is no new line in between.
  19252. // Associate the code between "lastGeneratedColumn" and
  19253. // "mapping.generatedColumn" with "lastMapping"
  19254. var nextLine = remainingLines[remainingLinesIndex] || '';
  19255. var code = nextLine.substr(0, mapping.generatedColumn -
  19256. lastGeneratedColumn);
  19257. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  19258. lastGeneratedColumn);
  19259. lastGeneratedColumn = mapping.generatedColumn;
  19260. addMappingWithCode(lastMapping, code);
  19261. // No more remaining code, continue
  19262. lastMapping = mapping;
  19263. return;
  19264. }
  19265. }
  19266. // We add the generated code until the first mapping
  19267. // to the SourceNode without any mapping.
  19268. // Each line is added as separate string.
  19269. while (lastGeneratedLine < mapping.generatedLine) {
  19270. node.add(shiftNextLine());
  19271. lastGeneratedLine++;
  19272. }
  19273. if (lastGeneratedColumn < mapping.generatedColumn) {
  19274. var nextLine = remainingLines[remainingLinesIndex] || '';
  19275. node.add(nextLine.substr(0, mapping.generatedColumn));
  19276. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  19277. lastGeneratedColumn = mapping.generatedColumn;
  19278. }
  19279. lastMapping = mapping;
  19280. }, this);
  19281. // We have processed all mappings.
  19282. if (remainingLinesIndex < remainingLines.length) {
  19283. if (lastMapping) {
  19284. // Associate the remaining code in the current line with "lastMapping"
  19285. addMappingWithCode(lastMapping, shiftNextLine());
  19286. }
  19287. // and add the remaining lines without any mapping
  19288. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  19289. }
  19290. // Copy sourcesContent into SourceNode
  19291. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  19292. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  19293. if (content != null) {
  19294. if (aRelativePath != null) {
  19295. sourceFile = util$7.join(aRelativePath, sourceFile);
  19296. }
  19297. node.setSourceContent(sourceFile, content);
  19298. }
  19299. });
  19300. return node;
  19301. function addMappingWithCode(mapping, code) {
  19302. if (mapping === null || mapping.source === undefined) {
  19303. node.add(code);
  19304. } else {
  19305. var source = aRelativePath
  19306. ? util$7.join(aRelativePath, mapping.source)
  19307. : mapping.source;
  19308. node.add(new SourceNode$1(mapping.originalLine,
  19309. mapping.originalColumn,
  19310. source,
  19311. code,
  19312. mapping.name));
  19313. }
  19314. }
  19315. };
  19316. /**
  19317. * Add a chunk of generated JS to this source node.
  19318. *
  19319. * @param aChunk A string snippet of generated JS code, another instance of
  19320. * SourceNode, or an array where each member is one of those things.
  19321. */
  19322. SourceNode$1.prototype.add = function SourceNode_add(aChunk) {
  19323. if (Array.isArray(aChunk)) {
  19324. aChunk.forEach(function (chunk) {
  19325. this.add(chunk);
  19326. }, this);
  19327. }
  19328. else if (aChunk[isSourceNode$1] || typeof aChunk === "string") {
  19329. if (aChunk) {
  19330. this.children.push(aChunk);
  19331. }
  19332. }
  19333. else {
  19334. throw new TypeError(
  19335. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  19336. );
  19337. }
  19338. return this;
  19339. };
  19340. /**
  19341. * Add a chunk of generated JS to the beginning of this source node.
  19342. *
  19343. * @param aChunk A string snippet of generated JS code, another instance of
  19344. * SourceNode, or an array where each member is one of those things.
  19345. */
  19346. SourceNode$1.prototype.prepend = function SourceNode_prepend(aChunk) {
  19347. if (Array.isArray(aChunk)) {
  19348. for (var i = aChunk.length-1; i >= 0; i--) {
  19349. this.prepend(aChunk[i]);
  19350. }
  19351. }
  19352. else if (aChunk[isSourceNode$1] || typeof aChunk === "string") {
  19353. this.children.unshift(aChunk);
  19354. }
  19355. else {
  19356. throw new TypeError(
  19357. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  19358. );
  19359. }
  19360. return this;
  19361. };
  19362. /**
  19363. * Walk over the tree of JS snippets in this node and its children. The
  19364. * walking function is called once for each snippet of JS and is passed that
  19365. * snippet and the its original associated source's line/column location.
  19366. *
  19367. * @param aFn The traversal function.
  19368. */
  19369. SourceNode$1.prototype.walk = function SourceNode_walk(aFn) {
  19370. var chunk;
  19371. for (var i = 0, len = this.children.length; i < len; i++) {
  19372. chunk = this.children[i];
  19373. if (chunk[isSourceNode$1]) {
  19374. chunk.walk(aFn);
  19375. }
  19376. else {
  19377. if (chunk !== '') {
  19378. aFn(chunk, { source: this.source,
  19379. line: this.line,
  19380. column: this.column,
  19381. name: this.name });
  19382. }
  19383. }
  19384. }
  19385. };
  19386. /**
  19387. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  19388. * each of `this.children`.
  19389. *
  19390. * @param aSep The separator.
  19391. */
  19392. SourceNode$1.prototype.join = function SourceNode_join(aSep) {
  19393. var newChildren;
  19394. var i;
  19395. var len = this.children.length;
  19396. if (len > 0) {
  19397. newChildren = [];
  19398. for (i = 0; i < len-1; i++) {
  19399. newChildren.push(this.children[i]);
  19400. newChildren.push(aSep);
  19401. }
  19402. newChildren.push(this.children[i]);
  19403. this.children = newChildren;
  19404. }
  19405. return this;
  19406. };
  19407. /**
  19408. * Call String.prototype.replace on the very right-most source snippet. Useful
  19409. * for trimming whitespace from the end of a source node, etc.
  19410. *
  19411. * @param aPattern The pattern to replace.
  19412. * @param aReplacement The thing to replace the pattern with.
  19413. */
  19414. SourceNode$1.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  19415. var lastChild = this.children[this.children.length - 1];
  19416. if (lastChild[isSourceNode$1]) {
  19417. lastChild.replaceRight(aPattern, aReplacement);
  19418. }
  19419. else if (typeof lastChild === 'string') {
  19420. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  19421. }
  19422. else {
  19423. this.children.push(''.replace(aPattern, aReplacement));
  19424. }
  19425. return this;
  19426. };
  19427. /**
  19428. * Set the source content for a source file. This will be added to the SourceMapGenerator
  19429. * in the sourcesContent field.
  19430. *
  19431. * @param aSourceFile The filename of the source file
  19432. * @param aSourceContent The content of the source file
  19433. */
  19434. SourceNode$1.prototype.setSourceContent =
  19435. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  19436. this.sourceContents[util$7.toSetString(aSourceFile)] = aSourceContent;
  19437. };
  19438. /**
  19439. * Walk over the tree of SourceNodes. The walking function is called for each
  19440. * source file content and is passed the filename and source content.
  19441. *
  19442. * @param aFn The traversal function.
  19443. */
  19444. SourceNode$1.prototype.walkSourceContents =
  19445. function SourceNode_walkSourceContents(aFn) {
  19446. for (var i = 0, len = this.children.length; i < len; i++) {
  19447. if (this.children[i][isSourceNode$1]) {
  19448. this.children[i].walkSourceContents(aFn);
  19449. }
  19450. }
  19451. var sources = Object.keys(this.sourceContents);
  19452. for (var i = 0, len = sources.length; i < len; i++) {
  19453. aFn(util$7.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  19454. }
  19455. };
  19456. /**
  19457. * Return the string representation of this source node. Walks over the tree
  19458. * and concatenates all the various snippets together to one string.
  19459. */
  19460. SourceNode$1.prototype.toString = function SourceNode_toString() {
  19461. var str = "";
  19462. this.walk(function (chunk) {
  19463. str += chunk;
  19464. });
  19465. return str;
  19466. };
  19467. /**
  19468. * Returns the string representation of this source node along with a source
  19469. * map.
  19470. */
  19471. SourceNode$1.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  19472. var generated = {
  19473. code: "",
  19474. line: 1,
  19475. column: 0
  19476. };
  19477. var map = new SourceMapGenerator$7(aArgs);
  19478. var sourceMappingActive = false;
  19479. var lastOriginalSource = null;
  19480. var lastOriginalLine = null;
  19481. var lastOriginalColumn = null;
  19482. var lastOriginalName = null;
  19483. this.walk(function (chunk, original) {
  19484. generated.code += chunk;
  19485. if (original.source !== null
  19486. && original.line !== null
  19487. && original.column !== null) {
  19488. if(lastOriginalSource !== original.source
  19489. || lastOriginalLine !== original.line
  19490. || lastOriginalColumn !== original.column
  19491. || lastOriginalName !== original.name) {
  19492. map.addMapping({
  19493. source: original.source,
  19494. original: {
  19495. line: original.line,
  19496. column: original.column
  19497. },
  19498. generated: {
  19499. line: generated.line,
  19500. column: generated.column
  19501. },
  19502. name: original.name
  19503. });
  19504. }
  19505. lastOriginalSource = original.source;
  19506. lastOriginalLine = original.line;
  19507. lastOriginalColumn = original.column;
  19508. lastOriginalName = original.name;
  19509. sourceMappingActive = true;
  19510. } else if (sourceMappingActive) {
  19511. map.addMapping({
  19512. generated: {
  19513. line: generated.line,
  19514. column: generated.column
  19515. }
  19516. });
  19517. lastOriginalSource = null;
  19518. sourceMappingActive = false;
  19519. }
  19520. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  19521. if (chunk.charCodeAt(idx) === NEWLINE_CODE$1) {
  19522. generated.line++;
  19523. generated.column = 0;
  19524. // Mappings end at eol
  19525. if (idx + 1 === length) {
  19526. lastOriginalSource = null;
  19527. sourceMappingActive = false;
  19528. } else if (sourceMappingActive) {
  19529. map.addMapping({
  19530. source: original.source,
  19531. original: {
  19532. line: original.line,
  19533. column: original.column
  19534. },
  19535. generated: {
  19536. line: generated.line,
  19537. column: generated.column
  19538. },
  19539. name: original.name
  19540. });
  19541. }
  19542. } else {
  19543. generated.column++;
  19544. }
  19545. }
  19546. });
  19547. this.walkSourceContents(function (sourceFile, sourceContent) {
  19548. map.setSourceContent(sourceFile, sourceContent);
  19549. });
  19550. return { code: generated.code, map: map };
  19551. };
  19552. sourceNode$1.SourceNode = SourceNode$1;
  19553. /*
  19554. * Copyright 2009-2011 Mozilla Foundation and contributors
  19555. * Licensed under the New BSD license. See LICENSE.txt or:
  19556. * http://opensource.org/licenses/BSD-3-Clause
  19557. */
  19558. var SourceMapGenerator$6 = sourceMap$2.SourceMapGenerator = sourceMapGenerator$1.SourceMapGenerator;
  19559. var SourceMapConsumer$5 = sourceMap$2.SourceMapConsumer = sourceMapConsumer$1.SourceMapConsumer;
  19560. sourceMap$2.SourceNode = sourceNode$1.SourceNode;
  19561. const PURE_ANNOTATION = `/*#__PURE__*/`;
  19562. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  19563. function createCodegenContext(ast, {
  19564. mode = "function",
  19565. prefixIdentifiers = mode === "module",
  19566. sourceMap = false,
  19567. filename = `template.vue.html`,
  19568. scopeId = null,
  19569. optimizeImports = false,
  19570. runtimeGlobalName = `Vue`,
  19571. runtimeModuleName = `vue`,
  19572. ssrRuntimeModuleName = "vue/server-renderer",
  19573. ssr = false,
  19574. isTS = false,
  19575. inSSR = false
  19576. }) {
  19577. const context = {
  19578. mode,
  19579. prefixIdentifiers,
  19580. sourceMap,
  19581. filename,
  19582. scopeId,
  19583. optimizeImports,
  19584. runtimeGlobalName,
  19585. runtimeModuleName,
  19586. ssrRuntimeModuleName,
  19587. ssr,
  19588. isTS,
  19589. inSSR,
  19590. source: ast.loc.source,
  19591. code: ``,
  19592. column: 1,
  19593. line: 1,
  19594. offset: 0,
  19595. indentLevel: 0,
  19596. pure: false,
  19597. map: void 0,
  19598. helper(key) {
  19599. return `_${helperNameMap[key]}`;
  19600. },
  19601. push(code, node) {
  19602. context.code += code;
  19603. if (context.map) {
  19604. if (node) {
  19605. let name;
  19606. if (node.type === 4 && !node.isStatic) {
  19607. const content = node.content.replace(/^_ctx\./, "");
  19608. if (content !== node.content && isSimpleIdentifier(content)) {
  19609. name = content;
  19610. }
  19611. }
  19612. addMapping(node.loc.start, name);
  19613. }
  19614. advancePositionWithMutation(context, code);
  19615. if (node && node.loc !== locStub) {
  19616. addMapping(node.loc.end);
  19617. }
  19618. }
  19619. },
  19620. indent() {
  19621. newline(++context.indentLevel);
  19622. },
  19623. deindent(withoutNewLine = false) {
  19624. if (withoutNewLine) {
  19625. --context.indentLevel;
  19626. } else {
  19627. newline(--context.indentLevel);
  19628. }
  19629. },
  19630. newline() {
  19631. newline(context.indentLevel);
  19632. }
  19633. };
  19634. function newline(n) {
  19635. context.push("\n" + ` `.repeat(n));
  19636. }
  19637. function addMapping(loc, name) {
  19638. context.map.addMapping({
  19639. name,
  19640. source: context.filename,
  19641. original: {
  19642. line: loc.line,
  19643. column: loc.column - 1
  19644. // source-map column is 0 based
  19645. },
  19646. generated: {
  19647. line: context.line,
  19648. column: context.column - 1
  19649. }
  19650. });
  19651. }
  19652. if (sourceMap) {
  19653. context.map = new SourceMapGenerator$6();
  19654. context.map.setSourceContent(filename, context.source);
  19655. }
  19656. return context;
  19657. }
  19658. function generate(ast, options = {}) {
  19659. const context = createCodegenContext(ast, options);
  19660. if (options.onContextCreated)
  19661. options.onContextCreated(context);
  19662. const {
  19663. mode,
  19664. push,
  19665. prefixIdentifiers,
  19666. indent,
  19667. deindent,
  19668. newline,
  19669. scopeId,
  19670. ssr
  19671. } = context;
  19672. const helpers = Array.from(ast.helpers);
  19673. const hasHelpers = helpers.length > 0;
  19674. const useWithBlock = !prefixIdentifiers && mode !== "module";
  19675. const genScopeId = scopeId != null && mode === "module";
  19676. const isSetupInlined = !!options.inline;
  19677. const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
  19678. if (mode === "module") {
  19679. genModulePreamble(ast, preambleContext, genScopeId, isSetupInlined);
  19680. } else {
  19681. genFunctionPreamble(ast, preambleContext);
  19682. }
  19683. const functionName = ssr ? `ssrRender` : `render`;
  19684. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  19685. if (options.bindingMetadata && !options.inline) {
  19686. args.push("$props", "$setup", "$data", "$options");
  19687. }
  19688. const signature = options.isTS ? args.map((arg) => `${arg}: any`).join(",") : args.join(", ");
  19689. if (isSetupInlined) {
  19690. push(`(${signature}) => {`);
  19691. } else {
  19692. push(`function ${functionName}(${signature}) {`);
  19693. }
  19694. indent();
  19695. if (useWithBlock) {
  19696. push(`with (_ctx) {`);
  19697. indent();
  19698. if (hasHelpers) {
  19699. push(`const { ${helpers.map(aliasHelper).join(", ")} } = _Vue`);
  19700. push(`
  19701. `);
  19702. newline();
  19703. }
  19704. }
  19705. if (ast.components.length) {
  19706. genAssets(ast.components, "component", context);
  19707. if (ast.directives.length || ast.temps > 0) {
  19708. newline();
  19709. }
  19710. }
  19711. if (ast.directives.length) {
  19712. genAssets(ast.directives, "directive", context);
  19713. if (ast.temps > 0) {
  19714. newline();
  19715. }
  19716. }
  19717. if (ast.temps > 0) {
  19718. push(`let `);
  19719. for (let i = 0; i < ast.temps; i++) {
  19720. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  19721. }
  19722. }
  19723. if (ast.components.length || ast.directives.length || ast.temps) {
  19724. push(`
  19725. `);
  19726. newline();
  19727. }
  19728. if (!ssr) {
  19729. push(`return `);
  19730. }
  19731. if (ast.codegenNode) {
  19732. genNode(ast.codegenNode, context);
  19733. } else {
  19734. push(`null`);
  19735. }
  19736. if (useWithBlock) {
  19737. deindent();
  19738. push(`}`);
  19739. }
  19740. deindent();
  19741. push(`}`);
  19742. return {
  19743. ast,
  19744. code: context.code,
  19745. preamble: isSetupInlined ? preambleContext.code : ``,
  19746. // SourceMapGenerator does have toJSON() method but it's not in the types
  19747. map: context.map ? context.map.toJSON() : void 0
  19748. };
  19749. }
  19750. function genFunctionPreamble(ast, context) {
  19751. const {
  19752. ssr,
  19753. prefixIdentifiers,
  19754. push,
  19755. newline,
  19756. runtimeModuleName,
  19757. runtimeGlobalName,
  19758. ssrRuntimeModuleName
  19759. } = context;
  19760. const VueBinding = ssr ? `require(${JSON.stringify(runtimeModuleName)})` : runtimeGlobalName;
  19761. const helpers = Array.from(ast.helpers);
  19762. if (helpers.length > 0) {
  19763. if (prefixIdentifiers) {
  19764. push(`const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
  19765. `);
  19766. } else {
  19767. push(`const _Vue = ${VueBinding}
  19768. `);
  19769. if (ast.hoists.length) {
  19770. const staticHelpers = [
  19771. CREATE_VNODE,
  19772. CREATE_ELEMENT_VNODE,
  19773. CREATE_COMMENT,
  19774. CREATE_TEXT,
  19775. CREATE_STATIC
  19776. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  19777. push(`const { ${staticHelpers} } = _Vue
  19778. `);
  19779. }
  19780. }
  19781. }
  19782. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  19783. push(
  19784. `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
  19785. `
  19786. );
  19787. }
  19788. genHoists(ast.hoists, context);
  19789. newline();
  19790. push(`return `);
  19791. }
  19792. function genModulePreamble(ast, context, genScopeId, inline) {
  19793. const {
  19794. push,
  19795. newline,
  19796. optimizeImports,
  19797. runtimeModuleName,
  19798. ssrRuntimeModuleName
  19799. } = context;
  19800. if (genScopeId && ast.hoists.length) {
  19801. ast.helpers.add(PUSH_SCOPE_ID);
  19802. ast.helpers.add(POP_SCOPE_ID);
  19803. }
  19804. if (ast.helpers.size) {
  19805. const helpers = Array.from(ast.helpers);
  19806. if (optimizeImports) {
  19807. push(
  19808. `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  19809. `
  19810. );
  19811. push(
  19812. `
  19813. // Binding optimization for webpack code-split
  19814. const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
  19815. `
  19816. );
  19817. } else {
  19818. push(
  19819. `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  19820. `
  19821. );
  19822. }
  19823. }
  19824. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  19825. push(
  19826. `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
  19827. `
  19828. );
  19829. }
  19830. if (ast.imports.length) {
  19831. genImports(ast.imports, context);
  19832. newline();
  19833. }
  19834. genHoists(ast.hoists, context);
  19835. newline();
  19836. if (!inline) {
  19837. push(`export `);
  19838. }
  19839. }
  19840. function genAssets(assets, type, { helper, push, newline, isTS }) {
  19841. const resolver = helper(
  19842. type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  19843. );
  19844. for (let i = 0; i < assets.length; i++) {
  19845. let id = assets[i];
  19846. const maybeSelfReference = id.endsWith("__self");
  19847. if (maybeSelfReference) {
  19848. id = id.slice(0, -6);
  19849. }
  19850. push(
  19851. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  19852. );
  19853. if (i < assets.length - 1) {
  19854. newline();
  19855. }
  19856. }
  19857. }
  19858. function genHoists(hoists, context) {
  19859. if (!hoists.length) {
  19860. return;
  19861. }
  19862. context.pure = true;
  19863. const { push, newline, helper, scopeId, mode } = context;
  19864. const genScopeId = scopeId != null && mode !== "function";
  19865. newline();
  19866. if (genScopeId) {
  19867. push(
  19868. `const _withScopeId = n => (${helper(
  19869. PUSH_SCOPE_ID
  19870. )}("${scopeId}"),n=n(),${helper(POP_SCOPE_ID)}(),n)`
  19871. );
  19872. newline();
  19873. }
  19874. for (let i = 0; i < hoists.length; i++) {
  19875. const exp = hoists[i];
  19876. if (exp) {
  19877. const needScopeIdWrapper = genScopeId && exp.type === 13;
  19878. push(
  19879. `const _hoisted_${i + 1} = ${needScopeIdWrapper ? `${PURE_ANNOTATION} _withScopeId(() => ` : ``}`
  19880. );
  19881. genNode(exp, context);
  19882. if (needScopeIdWrapper) {
  19883. push(`)`);
  19884. }
  19885. newline();
  19886. }
  19887. }
  19888. context.pure = false;
  19889. }
  19890. function genImports(importsOptions, context) {
  19891. if (!importsOptions.length) {
  19892. return;
  19893. }
  19894. importsOptions.forEach((imports) => {
  19895. context.push(`import `);
  19896. genNode(imports.exp, context);
  19897. context.push(` from '${imports.path}'`);
  19898. context.newline();
  19899. });
  19900. }
  19901. function isText(n) {
  19902. return isString$2(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  19903. }
  19904. function genNodeListAsArray(nodes, context) {
  19905. const multilines = nodes.length > 3 || nodes.some((n) => isArray$3(n) || !isText(n));
  19906. context.push(`[`);
  19907. multilines && context.indent();
  19908. genNodeList(nodes, context, multilines);
  19909. multilines && context.deindent();
  19910. context.push(`]`);
  19911. }
  19912. function genNodeList(nodes, context, multilines = false, comma = true) {
  19913. const { push, newline } = context;
  19914. for (let i = 0; i < nodes.length; i++) {
  19915. const node = nodes[i];
  19916. if (isString$2(node)) {
  19917. push(node);
  19918. } else if (isArray$3(node)) {
  19919. genNodeListAsArray(node, context);
  19920. } else {
  19921. genNode(node, context);
  19922. }
  19923. if (i < nodes.length - 1) {
  19924. if (multilines) {
  19925. comma && push(",");
  19926. newline();
  19927. } else {
  19928. comma && push(", ");
  19929. }
  19930. }
  19931. }
  19932. }
  19933. function genNode(node, context) {
  19934. if (isString$2(node)) {
  19935. context.push(node);
  19936. return;
  19937. }
  19938. if (isSymbol$1(node)) {
  19939. context.push(context.helper(node));
  19940. return;
  19941. }
  19942. switch (node.type) {
  19943. case 1:
  19944. case 9:
  19945. case 11:
  19946. assert(
  19947. node.codegenNode != null,
  19948. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  19949. );
  19950. genNode(node.codegenNode, context);
  19951. break;
  19952. case 2:
  19953. genText(node, context);
  19954. break;
  19955. case 4:
  19956. genExpression(node, context);
  19957. break;
  19958. case 5:
  19959. genInterpolation(node, context);
  19960. break;
  19961. case 12:
  19962. genNode(node.codegenNode, context);
  19963. break;
  19964. case 8:
  19965. genCompoundExpression(node, context);
  19966. break;
  19967. case 3:
  19968. genComment(node, context);
  19969. break;
  19970. case 13:
  19971. genVNodeCall(node, context);
  19972. break;
  19973. case 14:
  19974. genCallExpression(node, context);
  19975. break;
  19976. case 15:
  19977. genObjectExpression(node, context);
  19978. break;
  19979. case 17:
  19980. genArrayExpression(node, context);
  19981. break;
  19982. case 18:
  19983. genFunctionExpression(node, context);
  19984. break;
  19985. case 19:
  19986. genConditionalExpression(node, context);
  19987. break;
  19988. case 20:
  19989. genCacheExpression(node, context);
  19990. break;
  19991. case 21:
  19992. genNodeList(node.body, context, true, false);
  19993. break;
  19994. case 22:
  19995. genTemplateLiteral(node, context);
  19996. break;
  19997. case 23:
  19998. genIfStatement(node, context);
  19999. break;
  20000. case 24:
  20001. genAssignmentExpression(node, context);
  20002. break;
  20003. case 25:
  20004. genSequenceExpression(node, context);
  20005. break;
  20006. case 26:
  20007. genReturnStatement(node, context);
  20008. break;
  20009. case 10:
  20010. break;
  20011. default:
  20012. {
  20013. assert(false, `unhandled codegen node type: ${node.type}`);
  20014. const exhaustiveCheck = node;
  20015. return exhaustiveCheck;
  20016. }
  20017. }
  20018. }
  20019. function genText(node, context) {
  20020. context.push(JSON.stringify(node.content), node);
  20021. }
  20022. function genExpression(node, context) {
  20023. const { content, isStatic } = node;
  20024. context.push(isStatic ? JSON.stringify(content) : content, node);
  20025. }
  20026. function genInterpolation(node, context) {
  20027. const { push, helper, pure } = context;
  20028. if (pure)
  20029. push(PURE_ANNOTATION);
  20030. push(`${helper(TO_DISPLAY_STRING)}(`);
  20031. genNode(node.content, context);
  20032. push(`)`);
  20033. }
  20034. function genCompoundExpression(node, context) {
  20035. for (let i = 0; i < node.children.length; i++) {
  20036. const child = node.children[i];
  20037. if (isString$2(child)) {
  20038. context.push(child);
  20039. } else {
  20040. genNode(child, context);
  20041. }
  20042. }
  20043. }
  20044. function genExpressionAsPropertyKey(node, context) {
  20045. const { push } = context;
  20046. if (node.type === 8) {
  20047. push(`[`);
  20048. genCompoundExpression(node, context);
  20049. push(`]`);
  20050. } else if (node.isStatic) {
  20051. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  20052. push(text, node);
  20053. } else {
  20054. push(`[${node.content}]`, node);
  20055. }
  20056. }
  20057. function genComment(node, context) {
  20058. const { push, helper, pure } = context;
  20059. if (pure) {
  20060. push(PURE_ANNOTATION);
  20061. }
  20062. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  20063. }
  20064. function genVNodeCall(node, context) {
  20065. const { push, helper, pure } = context;
  20066. const {
  20067. tag,
  20068. props,
  20069. children,
  20070. patchFlag,
  20071. dynamicProps,
  20072. directives,
  20073. isBlock,
  20074. disableTracking,
  20075. isComponent
  20076. } = node;
  20077. if (directives) {
  20078. push(helper(WITH_DIRECTIVES) + `(`);
  20079. }
  20080. if (isBlock) {
  20081. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  20082. }
  20083. if (pure) {
  20084. push(PURE_ANNOTATION);
  20085. }
  20086. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  20087. push(helper(callHelper) + `(`, node);
  20088. genNodeList(
  20089. genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
  20090. context
  20091. );
  20092. push(`)`);
  20093. if (isBlock) {
  20094. push(`)`);
  20095. }
  20096. if (directives) {
  20097. push(`, `);
  20098. genNode(directives, context);
  20099. push(`)`);
  20100. }
  20101. }
  20102. function genNullableArgs(args) {
  20103. let i = args.length;
  20104. while (i--) {
  20105. if (args[i] != null)
  20106. break;
  20107. }
  20108. return args.slice(0, i + 1).map((arg) => arg || `null`);
  20109. }
  20110. function genCallExpression(node, context) {
  20111. const { push, helper, pure } = context;
  20112. const callee = isString$2(node.callee) ? node.callee : helper(node.callee);
  20113. if (pure) {
  20114. push(PURE_ANNOTATION);
  20115. }
  20116. push(callee + `(`, node);
  20117. genNodeList(node.arguments, context);
  20118. push(`)`);
  20119. }
  20120. function genObjectExpression(node, context) {
  20121. const { push, indent, deindent, newline } = context;
  20122. const { properties } = node;
  20123. if (!properties.length) {
  20124. push(`{}`, node);
  20125. return;
  20126. }
  20127. const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
  20128. push(multilines ? `{` : `{ `);
  20129. multilines && indent();
  20130. for (let i = 0; i < properties.length; i++) {
  20131. const { key, value } = properties[i];
  20132. genExpressionAsPropertyKey(key, context);
  20133. push(`: `);
  20134. genNode(value, context);
  20135. if (i < properties.length - 1) {
  20136. push(`,`);
  20137. newline();
  20138. }
  20139. }
  20140. multilines && deindent();
  20141. push(multilines ? `}` : ` }`);
  20142. }
  20143. function genArrayExpression(node, context) {
  20144. genNodeListAsArray(node.elements, context);
  20145. }
  20146. function genFunctionExpression(node, context) {
  20147. const { push, indent, deindent } = context;
  20148. const { params, returns, body, newline, isSlot } = node;
  20149. if (isSlot) {
  20150. push(`_${helperNameMap[WITH_CTX]}(`);
  20151. }
  20152. push(`(`, node);
  20153. if (isArray$3(params)) {
  20154. genNodeList(params, context);
  20155. } else if (params) {
  20156. genNode(params, context);
  20157. }
  20158. push(`) => `);
  20159. if (newline || body) {
  20160. push(`{`);
  20161. indent();
  20162. }
  20163. if (returns) {
  20164. if (newline) {
  20165. push(`return `);
  20166. }
  20167. if (isArray$3(returns)) {
  20168. genNodeListAsArray(returns, context);
  20169. } else {
  20170. genNode(returns, context);
  20171. }
  20172. } else if (body) {
  20173. genNode(body, context);
  20174. }
  20175. if (newline || body) {
  20176. deindent();
  20177. push(`}`);
  20178. }
  20179. if (isSlot) {
  20180. push(`)`);
  20181. }
  20182. }
  20183. function genConditionalExpression(node, context) {
  20184. const { test, consequent, alternate, newline: needNewline } = node;
  20185. const { push, indent, deindent, newline } = context;
  20186. if (test.type === 4) {
  20187. const needsParens = !isSimpleIdentifier(test.content);
  20188. needsParens && push(`(`);
  20189. genExpression(test, context);
  20190. needsParens && push(`)`);
  20191. } else {
  20192. push(`(`);
  20193. genNode(test, context);
  20194. push(`)`);
  20195. }
  20196. needNewline && indent();
  20197. context.indentLevel++;
  20198. needNewline || push(` `);
  20199. push(`? `);
  20200. genNode(consequent, context);
  20201. context.indentLevel--;
  20202. needNewline && newline();
  20203. needNewline || push(` `);
  20204. push(`: `);
  20205. const isNested = alternate.type === 19;
  20206. if (!isNested) {
  20207. context.indentLevel++;
  20208. }
  20209. genNode(alternate, context);
  20210. if (!isNested) {
  20211. context.indentLevel--;
  20212. }
  20213. needNewline && deindent(
  20214. true
  20215. /* without newline */
  20216. );
  20217. }
  20218. function genCacheExpression(node, context) {
  20219. const { push, helper, indent, deindent, newline } = context;
  20220. push(`_cache[${node.index}] || (`);
  20221. if (node.isVNode) {
  20222. indent();
  20223. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  20224. newline();
  20225. }
  20226. push(`_cache[${node.index}] = `);
  20227. genNode(node.value, context);
  20228. if (node.isVNode) {
  20229. push(`,`);
  20230. newline();
  20231. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  20232. newline();
  20233. push(`_cache[${node.index}]`);
  20234. deindent();
  20235. }
  20236. push(`)`);
  20237. }
  20238. function genTemplateLiteral(node, context) {
  20239. const { push, indent, deindent } = context;
  20240. push("`");
  20241. const l = node.elements.length;
  20242. const multilines = l > 3;
  20243. for (let i = 0; i < l; i++) {
  20244. const e = node.elements[i];
  20245. if (isString$2(e)) {
  20246. push(e.replace(/(`|\$|\\)/g, "\\$1"));
  20247. } else {
  20248. push("${");
  20249. if (multilines)
  20250. indent();
  20251. genNode(e, context);
  20252. if (multilines)
  20253. deindent();
  20254. push("}");
  20255. }
  20256. }
  20257. push("`");
  20258. }
  20259. function genIfStatement(node, context) {
  20260. const { push, indent, deindent } = context;
  20261. const { test, consequent, alternate } = node;
  20262. push(`if (`);
  20263. genNode(test, context);
  20264. push(`) {`);
  20265. indent();
  20266. genNode(consequent, context);
  20267. deindent();
  20268. push(`}`);
  20269. if (alternate) {
  20270. push(` else `);
  20271. if (alternate.type === 23) {
  20272. genIfStatement(alternate, context);
  20273. } else {
  20274. push(`{`);
  20275. indent();
  20276. genNode(alternate, context);
  20277. deindent();
  20278. push(`}`);
  20279. }
  20280. }
  20281. }
  20282. function genAssignmentExpression(node, context) {
  20283. genNode(node.left, context);
  20284. context.push(` = `);
  20285. genNode(node.right, context);
  20286. }
  20287. function genSequenceExpression(node, context) {
  20288. context.push(`(`);
  20289. genNodeList(node.expressions, context);
  20290. context.push(`)`);
  20291. }
  20292. function genReturnStatement({ returns }, context) {
  20293. context.push(`return `);
  20294. if (isArray$3(returns)) {
  20295. genNodeListAsArray(returns, context);
  20296. } else {
  20297. genNode(returns, context);
  20298. }
  20299. }
  20300. // @ts-check
  20301. /** @typedef { import('estree').BaseNode} BaseNode */
  20302. /** @typedef {{
  20303. skip: () => void;
  20304. remove: () => void;
  20305. replace: (node: BaseNode) => void;
  20306. }} WalkerContext */
  20307. class WalkerBase {
  20308. constructor() {
  20309. /** @type {boolean} */
  20310. this.should_skip = false;
  20311. /** @type {boolean} */
  20312. this.should_remove = false;
  20313. /** @type {BaseNode | null} */
  20314. this.replacement = null;
  20315. /** @type {WalkerContext} */
  20316. this.context = {
  20317. skip: () => (this.should_skip = true),
  20318. remove: () => (this.should_remove = true),
  20319. replace: (node) => (this.replacement = node)
  20320. };
  20321. }
  20322. /**
  20323. *
  20324. * @param {any} parent
  20325. * @param {string} prop
  20326. * @param {number} index
  20327. * @param {BaseNode} node
  20328. */
  20329. replace(parent, prop, index, node) {
  20330. if (parent) {
  20331. if (index !== null) {
  20332. parent[prop][index] = node;
  20333. } else {
  20334. parent[prop] = node;
  20335. }
  20336. }
  20337. }
  20338. /**
  20339. *
  20340. * @param {any} parent
  20341. * @param {string} prop
  20342. * @param {number} index
  20343. */
  20344. remove(parent, prop, index) {
  20345. if (parent) {
  20346. if (index !== null) {
  20347. parent[prop].splice(index, 1);
  20348. } else {
  20349. delete parent[prop];
  20350. }
  20351. }
  20352. }
  20353. }
  20354. // @ts-check
  20355. /** @typedef { import('estree').BaseNode} BaseNode */
  20356. /** @typedef { import('./walker.js').WalkerContext} WalkerContext */
  20357. /** @typedef {(
  20358. * this: WalkerContext,
  20359. * node: BaseNode,
  20360. * parent: BaseNode,
  20361. * key: string,
  20362. * index: number
  20363. * ) => void} SyncHandler */
  20364. class SyncWalker extends WalkerBase {
  20365. /**
  20366. *
  20367. * @param {SyncHandler} enter
  20368. * @param {SyncHandler} leave
  20369. */
  20370. constructor(enter, leave) {
  20371. super();
  20372. /** @type {SyncHandler} */
  20373. this.enter = enter;
  20374. /** @type {SyncHandler} */
  20375. this.leave = leave;
  20376. }
  20377. /**
  20378. *
  20379. * @param {BaseNode} node
  20380. * @param {BaseNode} parent
  20381. * @param {string} [prop]
  20382. * @param {number} [index]
  20383. * @returns {BaseNode}
  20384. */
  20385. visit(node, parent, prop, index) {
  20386. if (node) {
  20387. if (this.enter) {
  20388. const _should_skip = this.should_skip;
  20389. const _should_remove = this.should_remove;
  20390. const _replacement = this.replacement;
  20391. this.should_skip = false;
  20392. this.should_remove = false;
  20393. this.replacement = null;
  20394. this.enter.call(this.context, node, parent, prop, index);
  20395. if (this.replacement) {
  20396. node = this.replacement;
  20397. this.replace(parent, prop, index, node);
  20398. }
  20399. if (this.should_remove) {
  20400. this.remove(parent, prop, index);
  20401. }
  20402. const skipped = this.should_skip;
  20403. const removed = this.should_remove;
  20404. this.should_skip = _should_skip;
  20405. this.should_remove = _should_remove;
  20406. this.replacement = _replacement;
  20407. if (skipped) return node;
  20408. if (removed) return null;
  20409. }
  20410. for (const key in node) {
  20411. const value = node[key];
  20412. if (typeof value !== "object") {
  20413. continue;
  20414. } else if (Array.isArray(value)) {
  20415. for (let i = 0; i < value.length; i += 1) {
  20416. if (value[i] !== null && typeof value[i].type === 'string') {
  20417. if (!this.visit(value[i], node, key, i)) {
  20418. // removed
  20419. i--;
  20420. }
  20421. }
  20422. }
  20423. } else if (value !== null && typeof value.type === "string") {
  20424. this.visit(value, node, key, null);
  20425. }
  20426. }
  20427. if (this.leave) {
  20428. const _replacement = this.replacement;
  20429. const _should_remove = this.should_remove;
  20430. this.replacement = null;
  20431. this.should_remove = false;
  20432. this.leave.call(this.context, node, parent, prop, index);
  20433. if (this.replacement) {
  20434. node = this.replacement;
  20435. this.replace(parent, prop, index, node);
  20436. }
  20437. if (this.should_remove) {
  20438. this.remove(parent, prop, index);
  20439. }
  20440. const removed = this.should_remove;
  20441. this.replacement = _replacement;
  20442. this.should_remove = _should_remove;
  20443. if (removed) return null;
  20444. }
  20445. }
  20446. return node;
  20447. }
  20448. }
  20449. // @ts-check
  20450. /** @typedef { import('estree').BaseNode} BaseNode */
  20451. /** @typedef { import('./sync.js').SyncHandler} SyncHandler */
  20452. /** @typedef { import('./async.js').AsyncHandler} AsyncHandler */
  20453. /**
  20454. *
  20455. * @param {BaseNode} ast
  20456. * @param {{
  20457. * enter?: SyncHandler
  20458. * leave?: SyncHandler
  20459. * }} walker
  20460. * @returns {BaseNode}
  20461. */
  20462. function walk$1(ast, { enter, leave }) {
  20463. const instance = new SyncWalker(enter, leave);
  20464. return instance.visit(ast, null);
  20465. }
  20466. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
  20467. const rootExp = root.type === "Program" && root.body[0].type === "ExpressionStatement" && root.body[0].expression;
  20468. walk$1(root, {
  20469. enter(node, parent) {
  20470. parent && parentStack.push(parent);
  20471. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  20472. return this.skip();
  20473. }
  20474. if (node.type === "Identifier") {
  20475. const isLocal = !!knownIds[node.name];
  20476. const isRefed = isReferencedIdentifier(node, parent, parentStack);
  20477. if (includeAll || isRefed && !isLocal) {
  20478. onIdentifier(node, parent, parentStack, isRefed, isLocal);
  20479. }
  20480. } else if (node.type === "ObjectProperty" && parent.type === "ObjectPattern") {
  20481. node.inPattern = true;
  20482. } else if (isFunctionType(node)) {
  20483. walkFunctionParams(node, (id) => markScopeIdentifier(node, id, knownIds));
  20484. } else if (node.type === "BlockStatement") {
  20485. walkBlockDeclarations(
  20486. node,
  20487. (id) => markScopeIdentifier(node, id, knownIds)
  20488. );
  20489. }
  20490. },
  20491. leave(node, parent) {
  20492. parent && parentStack.pop();
  20493. if (node !== rootExp && node.scopeIds) {
  20494. for (const id of node.scopeIds) {
  20495. knownIds[id]--;
  20496. if (knownIds[id] === 0) {
  20497. delete knownIds[id];
  20498. }
  20499. }
  20500. }
  20501. }
  20502. });
  20503. }
  20504. function isReferencedIdentifier(id, parent, parentStack) {
  20505. if (!parent) {
  20506. return true;
  20507. }
  20508. if (id.name === "arguments") {
  20509. return false;
  20510. }
  20511. if (isReferenced(id, parent)) {
  20512. return true;
  20513. }
  20514. switch (parent.type) {
  20515. case "AssignmentExpression":
  20516. case "AssignmentPattern":
  20517. return true;
  20518. case "ObjectPattern":
  20519. case "ArrayPattern":
  20520. return isInDestructureAssignment(parent, parentStack);
  20521. }
  20522. return false;
  20523. }
  20524. function isInDestructureAssignment(parent, parentStack) {
  20525. if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
  20526. let i = parentStack.length;
  20527. while (i--) {
  20528. const p = parentStack[i];
  20529. if (p.type === "AssignmentExpression") {
  20530. return true;
  20531. } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
  20532. break;
  20533. }
  20534. }
  20535. }
  20536. return false;
  20537. }
  20538. function walkFunctionParams(node, onIdent) {
  20539. for (const p of node.params) {
  20540. for (const id of extractIdentifiers(p)) {
  20541. onIdent(id);
  20542. }
  20543. }
  20544. }
  20545. function walkBlockDeclarations(block, onIdent) {
  20546. for (const stmt of block.body) {
  20547. if (stmt.type === "VariableDeclaration") {
  20548. if (stmt.declare)
  20549. continue;
  20550. for (const decl of stmt.declarations) {
  20551. for (const id of extractIdentifiers(decl.id)) {
  20552. onIdent(id);
  20553. }
  20554. }
  20555. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  20556. if (stmt.declare || !stmt.id)
  20557. continue;
  20558. onIdent(stmt.id);
  20559. }
  20560. }
  20561. }
  20562. function extractIdentifiers(param, nodes = []) {
  20563. switch (param.type) {
  20564. case "Identifier":
  20565. nodes.push(param);
  20566. break;
  20567. case "MemberExpression":
  20568. let object = param;
  20569. while (object.type === "MemberExpression") {
  20570. object = object.object;
  20571. }
  20572. nodes.push(object);
  20573. break;
  20574. case "ObjectPattern":
  20575. for (const prop of param.properties) {
  20576. if (prop.type === "RestElement") {
  20577. extractIdentifiers(prop.argument, nodes);
  20578. } else {
  20579. extractIdentifiers(prop.value, nodes);
  20580. }
  20581. }
  20582. break;
  20583. case "ArrayPattern":
  20584. param.elements.forEach((element) => {
  20585. if (element)
  20586. extractIdentifiers(element, nodes);
  20587. });
  20588. break;
  20589. case "RestElement":
  20590. extractIdentifiers(param.argument, nodes);
  20591. break;
  20592. case "AssignmentPattern":
  20593. extractIdentifiers(param.left, nodes);
  20594. break;
  20595. }
  20596. return nodes;
  20597. }
  20598. function markScopeIdentifier(node, child, knownIds) {
  20599. const { name } = child;
  20600. if (node.scopeIds && node.scopeIds.has(name)) {
  20601. return;
  20602. }
  20603. if (name in knownIds) {
  20604. knownIds[name]++;
  20605. } else {
  20606. knownIds[name] = 1;
  20607. }
  20608. (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
  20609. }
  20610. const isFunctionType = (node) => {
  20611. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  20612. };
  20613. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  20614. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  20615. function isReferenced(node, parent, grandparent) {
  20616. switch (parent.type) {
  20617. case "MemberExpression":
  20618. case "OptionalMemberExpression":
  20619. if (parent.property === node) {
  20620. return !!parent.computed;
  20621. }
  20622. return parent.object === node;
  20623. case "JSXMemberExpression":
  20624. return parent.object === node;
  20625. case "VariableDeclarator":
  20626. return parent.init === node;
  20627. case "ArrowFunctionExpression":
  20628. return parent.body === node;
  20629. case "PrivateName":
  20630. return false;
  20631. case "ClassMethod":
  20632. case "ClassPrivateMethod":
  20633. case "ObjectMethod":
  20634. if (parent.key === node) {
  20635. return !!parent.computed;
  20636. }
  20637. return false;
  20638. case "ObjectProperty":
  20639. if (parent.key === node) {
  20640. return !!parent.computed;
  20641. }
  20642. return !grandparent || grandparent.type !== "ObjectPattern";
  20643. case "ClassProperty":
  20644. if (parent.key === node) {
  20645. return !!parent.computed;
  20646. }
  20647. return true;
  20648. case "ClassPrivateProperty":
  20649. return parent.key !== node;
  20650. case "ClassDeclaration":
  20651. case "ClassExpression":
  20652. return parent.superClass === node;
  20653. case "AssignmentExpression":
  20654. return parent.right === node;
  20655. case "AssignmentPattern":
  20656. return parent.right === node;
  20657. case "LabeledStatement":
  20658. return false;
  20659. case "CatchClause":
  20660. return false;
  20661. case "RestElement":
  20662. return false;
  20663. case "BreakStatement":
  20664. case "ContinueStatement":
  20665. return false;
  20666. case "FunctionDeclaration":
  20667. case "FunctionExpression":
  20668. return false;
  20669. case "ExportNamespaceSpecifier":
  20670. case "ExportDefaultSpecifier":
  20671. return false;
  20672. case "ExportSpecifier":
  20673. if (grandparent == null ? void 0 : grandparent.source) {
  20674. return false;
  20675. }
  20676. return parent.local === node;
  20677. case "ImportDefaultSpecifier":
  20678. case "ImportNamespaceSpecifier":
  20679. case "ImportSpecifier":
  20680. return false;
  20681. case "ImportAttribute":
  20682. return false;
  20683. case "JSXAttribute":
  20684. return false;
  20685. case "ObjectPattern":
  20686. case "ArrayPattern":
  20687. return false;
  20688. case "MetaProperty":
  20689. return false;
  20690. case "ObjectTypeProperty":
  20691. return parent.key !== node;
  20692. case "TSEnumMember":
  20693. return parent.id !== node;
  20694. case "TSPropertySignature":
  20695. if (parent.key === node) {
  20696. return !!parent.computed;
  20697. }
  20698. return true;
  20699. }
  20700. return true;
  20701. }
  20702. const TS_NODE_TYPES = [
  20703. "TSAsExpression",
  20704. // foo as number
  20705. "TSTypeAssertion",
  20706. // (<number>foo)
  20707. "TSNonNullExpression",
  20708. // foo!
  20709. "TSInstantiationExpression",
  20710. // foo<string>
  20711. "TSSatisfiesExpression"
  20712. // foo satisfies T
  20713. ];
  20714. const isLiteralWhitelisted = /* @__PURE__ */ makeMap("true,false,null,this");
  20715. const constantBailRE = /\w\s*\(|\.[^\d]/;
  20716. const transformExpression = (node, context) => {
  20717. if (node.type === 5) {
  20718. node.content = processExpression(
  20719. node.content,
  20720. context
  20721. );
  20722. } else if (node.type === 1) {
  20723. for (let i = 0; i < node.props.length; i++) {
  20724. const dir = node.props[i];
  20725. if (dir.type === 7 && dir.name !== "for") {
  20726. const exp = dir.exp;
  20727. const arg = dir.arg;
  20728. if (exp && exp.type === 4 && !(dir.name === "on" && arg)) {
  20729. dir.exp = processExpression(
  20730. exp,
  20731. context,
  20732. // slot args must be processed as function params
  20733. dir.name === "slot"
  20734. );
  20735. }
  20736. if (arg && arg.type === 4 && !arg.isStatic) {
  20737. dir.arg = processExpression(arg, context);
  20738. }
  20739. }
  20740. }
  20741. }
  20742. };
  20743. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  20744. if (!context.prefixIdentifiers || !node.content.trim()) {
  20745. return node;
  20746. }
  20747. const { inline, bindingMetadata } = context;
  20748. const rewriteIdentifier = (raw, parent, id) => {
  20749. const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw];
  20750. if (inline) {
  20751. const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
  20752. const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
  20753. const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
  20754. if (isConst(type) || type === "setup-reactive-const" || localVars[raw]) {
  20755. return raw;
  20756. } else if (type === "setup-ref") {
  20757. return `${raw}.value`;
  20758. } else if (type === "setup-maybe-ref") {
  20759. return isAssignmentLVal || isUpdateArg || isDestructureAssignment ? `${raw}.value` : `${context.helperString(UNREF)}(${raw})`;
  20760. } else if (type === "setup-let") {
  20761. if (isAssignmentLVal) {
  20762. const { right: rVal, operator } = parent;
  20763. const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
  20764. const rExpString = stringifyExpression(
  20765. processExpression(
  20766. createSimpleExpression(rExp, false),
  20767. context,
  20768. false,
  20769. false,
  20770. knownIds
  20771. )
  20772. );
  20773. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  20774. ` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
  20775. } else if (isUpdateArg) {
  20776. id.start = parent.start;
  20777. id.end = parent.end;
  20778. const { prefix: isPrefix, operator } = parent;
  20779. const prefix = isPrefix ? operator : ``;
  20780. const postfix = isPrefix ? `` : operator;
  20781. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  20782. ` : ``} ? ${prefix}${raw}.value${postfix} : ${prefix}${raw}${postfix}`;
  20783. } else if (isDestructureAssignment) {
  20784. return raw;
  20785. } else {
  20786. return `${context.helperString(UNREF)}(${raw})`;
  20787. }
  20788. } else if (type === "props") {
  20789. return genPropsAccessExp(raw);
  20790. } else if (type === "props-aliased") {
  20791. return genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
  20792. }
  20793. } else {
  20794. if (type && type.startsWith("setup") || type === "literal-const") {
  20795. return `$setup.${raw}`;
  20796. } else if (type === "props-aliased") {
  20797. return `$props['${bindingMetadata.__propsAliases[raw]}']`;
  20798. } else if (type) {
  20799. return `$${type}.${raw}`;
  20800. }
  20801. }
  20802. return `_ctx.${raw}`;
  20803. };
  20804. const rawExp = node.content;
  20805. const bailConstant = constantBailRE.test(rawExp);
  20806. if (isSimpleIdentifier(rawExp)) {
  20807. const isScopeVarReference = context.identifiers[rawExp];
  20808. const isAllowedGlobal = isGloballyWhitelisted(rawExp);
  20809. const isLiteral = isLiteralWhitelisted(rawExp);
  20810. if (!asParams && !isScopeVarReference && !isAllowedGlobal && !isLiteral) {
  20811. if (isConst(bindingMetadata[node.content])) {
  20812. node.constType = 1;
  20813. }
  20814. node.content = rewriteIdentifier(rawExp);
  20815. } else if (!isScopeVarReference) {
  20816. if (isLiteral) {
  20817. node.constType = 3;
  20818. } else {
  20819. node.constType = 2;
  20820. }
  20821. }
  20822. return node;
  20823. }
  20824. let ast;
  20825. const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
  20826. try {
  20827. ast = parse_1$1(source, {
  20828. plugins: context.expressionPlugins
  20829. }).program;
  20830. } catch (e) {
  20831. context.onError(
  20832. createCompilerError(
  20833. 45,
  20834. node.loc,
  20835. void 0,
  20836. e.message
  20837. )
  20838. );
  20839. return node;
  20840. }
  20841. const ids = [];
  20842. const parentStack = [];
  20843. const knownIds = Object.create(context.identifiers);
  20844. walkIdentifiers(
  20845. ast,
  20846. (node2, parent, _, isReferenced, isLocal) => {
  20847. if (isStaticPropertyKey(node2, parent)) {
  20848. return;
  20849. }
  20850. const needPrefix = isReferenced && canPrefix(node2);
  20851. if (needPrefix && !isLocal) {
  20852. if (isStaticProperty(parent) && parent.shorthand) {
  20853. node2.prefix = `${node2.name}: `;
  20854. }
  20855. node2.name = rewriteIdentifier(node2.name, parent, node2);
  20856. ids.push(node2);
  20857. } else {
  20858. if (!(needPrefix && isLocal) && !bailConstant) {
  20859. node2.isConstant = true;
  20860. }
  20861. ids.push(node2);
  20862. }
  20863. },
  20864. true,
  20865. // invoke on ALL identifiers
  20866. parentStack,
  20867. knownIds
  20868. );
  20869. const children = [];
  20870. ids.sort((a, b) => a.start - b.start);
  20871. ids.forEach((id, i) => {
  20872. const start = id.start - 1;
  20873. const end = id.end - 1;
  20874. const last = ids[i - 1];
  20875. const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
  20876. if (leadingText.length || id.prefix) {
  20877. children.push(leadingText + (id.prefix || ``));
  20878. }
  20879. const source2 = rawExp.slice(start, end);
  20880. children.push(
  20881. createSimpleExpression(
  20882. id.name,
  20883. false,
  20884. {
  20885. source: source2,
  20886. start: advancePositionWithClone(node.loc.start, source2, start),
  20887. end: advancePositionWithClone(node.loc.start, source2, end)
  20888. },
  20889. id.isConstant ? 3 : 0
  20890. )
  20891. );
  20892. if (i === ids.length - 1 && end < rawExp.length) {
  20893. children.push(rawExp.slice(end));
  20894. }
  20895. });
  20896. let ret;
  20897. if (children.length) {
  20898. ret = createCompoundExpression(children, node.loc);
  20899. } else {
  20900. ret = node;
  20901. ret.constType = bailConstant ? 0 : 3;
  20902. }
  20903. ret.identifiers = Object.keys(knownIds);
  20904. return ret;
  20905. }
  20906. function canPrefix(id) {
  20907. if (isGloballyWhitelisted(id.name)) {
  20908. return false;
  20909. }
  20910. if (id.name === "require") {
  20911. return false;
  20912. }
  20913. return true;
  20914. }
  20915. function stringifyExpression(exp) {
  20916. if (isString$2(exp)) {
  20917. return exp;
  20918. } else if (exp.type === 4) {
  20919. return exp.content;
  20920. } else {
  20921. return exp.children.map(stringifyExpression).join("");
  20922. }
  20923. }
  20924. function isConst(type) {
  20925. return type === "setup-const" || type === "literal-const";
  20926. }
  20927. const transformIf = createStructuralDirectiveTransform(
  20928. /^(if|else|else-if)$/,
  20929. (node, dir, context) => {
  20930. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  20931. const siblings = context.parent.children;
  20932. let i = siblings.indexOf(ifNode);
  20933. let key = 0;
  20934. while (i-- >= 0) {
  20935. const sibling = siblings[i];
  20936. if (sibling && sibling.type === 9) {
  20937. key += sibling.branches.length;
  20938. }
  20939. }
  20940. return () => {
  20941. if (isRoot) {
  20942. ifNode.codegenNode = createCodegenNodeForBranch(
  20943. branch,
  20944. key,
  20945. context
  20946. );
  20947. } else {
  20948. const parentCondition = getParentCondition(ifNode.codegenNode);
  20949. parentCondition.alternate = createCodegenNodeForBranch(
  20950. branch,
  20951. key + ifNode.branches.length - 1,
  20952. context
  20953. );
  20954. }
  20955. };
  20956. });
  20957. }
  20958. );
  20959. function processIf(node, dir, context, processCodegen) {
  20960. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  20961. const loc = dir.exp ? dir.exp.loc : node.loc;
  20962. context.onError(
  20963. createCompilerError(28, dir.loc)
  20964. );
  20965. dir.exp = createSimpleExpression(`true`, false, loc);
  20966. }
  20967. if (context.prefixIdentifiers && dir.exp) {
  20968. dir.exp = processExpression(dir.exp, context);
  20969. }
  20970. if (dir.name === "if") {
  20971. const branch = createIfBranch(node, dir);
  20972. const ifNode = {
  20973. type: 9,
  20974. loc: node.loc,
  20975. branches: [branch]
  20976. };
  20977. context.replaceNode(ifNode);
  20978. if (processCodegen) {
  20979. return processCodegen(ifNode, branch, true);
  20980. }
  20981. } else {
  20982. const siblings = context.parent.children;
  20983. const comments = [];
  20984. let i = siblings.indexOf(node);
  20985. while (i-- >= -1) {
  20986. const sibling = siblings[i];
  20987. if (sibling && sibling.type === 3) {
  20988. context.removeNode(sibling);
  20989. comments.unshift(sibling);
  20990. continue;
  20991. }
  20992. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  20993. context.removeNode(sibling);
  20994. continue;
  20995. }
  20996. if (sibling && sibling.type === 9) {
  20997. if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  20998. context.onError(
  20999. createCompilerError(30, node.loc)
  21000. );
  21001. }
  21002. context.removeNode();
  21003. const branch = createIfBranch(node, dir);
  21004. if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  21005. !(context.parent && context.parent.type === 1 && isBuiltInType(context.parent.tag, "transition"))) {
  21006. branch.children = [...comments, ...branch.children];
  21007. }
  21008. {
  21009. const key = branch.userKey;
  21010. if (key) {
  21011. sibling.branches.forEach(({ userKey }) => {
  21012. if (isSameKey(userKey, key)) {
  21013. context.onError(
  21014. createCompilerError(
  21015. 29,
  21016. branch.userKey.loc
  21017. )
  21018. );
  21019. }
  21020. });
  21021. }
  21022. }
  21023. sibling.branches.push(branch);
  21024. const onExit = processCodegen && processCodegen(sibling, branch, false);
  21025. traverseNode(branch, context);
  21026. if (onExit)
  21027. onExit();
  21028. context.currentNode = null;
  21029. } else {
  21030. context.onError(
  21031. createCompilerError(30, node.loc)
  21032. );
  21033. }
  21034. break;
  21035. }
  21036. }
  21037. }
  21038. function createIfBranch(node, dir) {
  21039. const isTemplateIf = node.tagType === 3;
  21040. return {
  21041. type: 10,
  21042. loc: node.loc,
  21043. condition: dir.name === "else" ? void 0 : dir.exp,
  21044. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  21045. userKey: findProp(node, `key`),
  21046. isTemplateIf
  21047. };
  21048. }
  21049. function createCodegenNodeForBranch(branch, keyIndex, context) {
  21050. if (branch.condition) {
  21051. return createConditionalExpression(
  21052. branch.condition,
  21053. createChildrenCodegenNode(branch, keyIndex, context),
  21054. // make sure to pass in asBlock: true so that the comment node call
  21055. // closes the current block.
  21056. createCallExpression(context.helper(CREATE_COMMENT), [
  21057. '"v-if"' ,
  21058. "true"
  21059. ])
  21060. );
  21061. } else {
  21062. return createChildrenCodegenNode(branch, keyIndex, context);
  21063. }
  21064. }
  21065. function createChildrenCodegenNode(branch, keyIndex, context) {
  21066. const { helper } = context;
  21067. const keyProperty = createObjectProperty(
  21068. `key`,
  21069. createSimpleExpression(
  21070. `${keyIndex}`,
  21071. false,
  21072. locStub,
  21073. 2
  21074. )
  21075. );
  21076. const { children } = branch;
  21077. const firstChild = children[0];
  21078. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  21079. if (needFragmentWrapper) {
  21080. if (children.length === 1 && firstChild.type === 11) {
  21081. const vnodeCall = firstChild.codegenNode;
  21082. injectProp(vnodeCall, keyProperty, context);
  21083. return vnodeCall;
  21084. } else {
  21085. let patchFlag = 64;
  21086. let patchFlagText = PatchFlagNames[64];
  21087. if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  21088. patchFlag |= 2048;
  21089. patchFlagText += `, ${PatchFlagNames[2048]}`;
  21090. }
  21091. return createVNodeCall(
  21092. context,
  21093. helper(FRAGMENT),
  21094. createObjectExpression([keyProperty]),
  21095. children,
  21096. patchFlag + (` /* ${patchFlagText} */` ),
  21097. void 0,
  21098. void 0,
  21099. true,
  21100. false,
  21101. false,
  21102. branch.loc
  21103. );
  21104. }
  21105. } else {
  21106. const ret = firstChild.codegenNode;
  21107. const vnodeCall = getMemoedVNodeCall(ret);
  21108. if (vnodeCall.type === 13) {
  21109. convertToBlock(vnodeCall, context);
  21110. }
  21111. injectProp(vnodeCall, keyProperty, context);
  21112. return ret;
  21113. }
  21114. }
  21115. function isSameKey(a, b) {
  21116. if (!a || a.type !== b.type) {
  21117. return false;
  21118. }
  21119. if (a.type === 6) {
  21120. if (a.value.content !== b.value.content) {
  21121. return false;
  21122. }
  21123. } else {
  21124. const exp = a.exp;
  21125. const branchExp = b.exp;
  21126. if (exp.type !== branchExp.type) {
  21127. return false;
  21128. }
  21129. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  21130. return false;
  21131. }
  21132. }
  21133. return true;
  21134. }
  21135. function getParentCondition(node) {
  21136. while (true) {
  21137. if (node.type === 19) {
  21138. if (node.alternate.type === 19) {
  21139. node = node.alternate;
  21140. } else {
  21141. return node;
  21142. }
  21143. } else if (node.type === 20) {
  21144. node = node.value;
  21145. }
  21146. }
  21147. }
  21148. const transformFor = createStructuralDirectiveTransform(
  21149. "for",
  21150. (node, dir, context) => {
  21151. const { helper, removeHelper } = context;
  21152. return processFor(node, dir, context, (forNode) => {
  21153. const renderExp = createCallExpression(helper(RENDER_LIST), [
  21154. forNode.source
  21155. ]);
  21156. const isTemplate = isTemplateNode(node);
  21157. const memo = findDir(node, "memo");
  21158. const keyProp = findProp(node, `key`);
  21159. const keyExp = keyProp && (keyProp.type === 6 ? createSimpleExpression(keyProp.value.content, true) : keyProp.exp);
  21160. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  21161. if (isTemplate) {
  21162. if (memo) {
  21163. memo.exp = processExpression(
  21164. memo.exp,
  21165. context
  21166. );
  21167. }
  21168. if (keyProperty && keyProp.type !== 6) {
  21169. keyProperty.value = processExpression(
  21170. keyProperty.value,
  21171. context
  21172. );
  21173. }
  21174. }
  21175. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  21176. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  21177. forNode.codegenNode = createVNodeCall(
  21178. context,
  21179. helper(FRAGMENT),
  21180. void 0,
  21181. renderExp,
  21182. fragmentFlag + (` /* ${PatchFlagNames[fragmentFlag]} */` ),
  21183. void 0,
  21184. void 0,
  21185. true,
  21186. !isStableFragment,
  21187. false,
  21188. node.loc
  21189. );
  21190. return () => {
  21191. let childBlock;
  21192. const { children } = forNode;
  21193. if (isTemplate) {
  21194. node.children.some((c) => {
  21195. if (c.type === 1) {
  21196. const key = findProp(c, "key");
  21197. if (key) {
  21198. context.onError(
  21199. createCompilerError(
  21200. 33,
  21201. key.loc
  21202. )
  21203. );
  21204. return true;
  21205. }
  21206. }
  21207. });
  21208. }
  21209. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  21210. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  21211. if (slotOutlet) {
  21212. childBlock = slotOutlet.codegenNode;
  21213. if (isTemplate && keyProperty) {
  21214. injectProp(childBlock, keyProperty, context);
  21215. }
  21216. } else if (needFragmentWrapper) {
  21217. childBlock = createVNodeCall(
  21218. context,
  21219. helper(FRAGMENT),
  21220. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  21221. node.children,
  21222. 64 + (` /* ${PatchFlagNames[64]} */` ),
  21223. void 0,
  21224. void 0,
  21225. true,
  21226. void 0,
  21227. false
  21228. /* isComponent */
  21229. );
  21230. } else {
  21231. childBlock = children[0].codegenNode;
  21232. if (isTemplate && keyProperty) {
  21233. injectProp(childBlock, keyProperty, context);
  21234. }
  21235. if (childBlock.isBlock !== !isStableFragment) {
  21236. if (childBlock.isBlock) {
  21237. removeHelper(OPEN_BLOCK);
  21238. removeHelper(
  21239. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  21240. );
  21241. } else {
  21242. removeHelper(
  21243. getVNodeHelper(context.inSSR, childBlock.isComponent)
  21244. );
  21245. }
  21246. }
  21247. childBlock.isBlock = !isStableFragment;
  21248. if (childBlock.isBlock) {
  21249. helper(OPEN_BLOCK);
  21250. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  21251. } else {
  21252. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  21253. }
  21254. }
  21255. if (memo) {
  21256. const loop = createFunctionExpression(
  21257. createForLoopParams(forNode.parseResult, [
  21258. createSimpleExpression(`_cached`)
  21259. ])
  21260. );
  21261. loop.body = createBlockStatement([
  21262. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  21263. createCompoundExpression([
  21264. `if (_cached`,
  21265. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  21266. ` && ${context.helperString(
  21267. IS_MEMO_SAME
  21268. )}(_cached, _memo)) return _cached`
  21269. ]),
  21270. createCompoundExpression([`const _item = `, childBlock]),
  21271. createSimpleExpression(`_item.memo = _memo`),
  21272. createSimpleExpression(`return _item`)
  21273. ]);
  21274. renderExp.arguments.push(
  21275. loop,
  21276. createSimpleExpression(`_cache`),
  21277. createSimpleExpression(String(context.cached++))
  21278. );
  21279. } else {
  21280. renderExp.arguments.push(
  21281. createFunctionExpression(
  21282. createForLoopParams(forNode.parseResult),
  21283. childBlock,
  21284. true
  21285. /* force newline */
  21286. )
  21287. );
  21288. }
  21289. };
  21290. });
  21291. }
  21292. );
  21293. function processFor(node, dir, context, processCodegen) {
  21294. if (!dir.exp) {
  21295. context.onError(
  21296. createCompilerError(31, dir.loc)
  21297. );
  21298. return;
  21299. }
  21300. const parseResult = parseForExpression(
  21301. // can only be simple expression because vFor transform is applied
  21302. // before expression transform.
  21303. dir.exp,
  21304. context
  21305. );
  21306. if (!parseResult) {
  21307. context.onError(
  21308. createCompilerError(32, dir.loc)
  21309. );
  21310. return;
  21311. }
  21312. const { addIdentifiers, removeIdentifiers, scopes } = context;
  21313. const { source, value, key, index } = parseResult;
  21314. const forNode = {
  21315. type: 11,
  21316. loc: dir.loc,
  21317. source,
  21318. valueAlias: value,
  21319. keyAlias: key,
  21320. objectIndexAlias: index,
  21321. parseResult,
  21322. children: isTemplateNode(node) ? node.children : [node]
  21323. };
  21324. context.replaceNode(forNode);
  21325. scopes.vFor++;
  21326. if (context.prefixIdentifiers) {
  21327. value && addIdentifiers(value);
  21328. key && addIdentifiers(key);
  21329. index && addIdentifiers(index);
  21330. }
  21331. const onExit = processCodegen && processCodegen(forNode);
  21332. return () => {
  21333. scopes.vFor--;
  21334. if (context.prefixIdentifiers) {
  21335. value && removeIdentifiers(value);
  21336. key && removeIdentifiers(key);
  21337. index && removeIdentifiers(index);
  21338. }
  21339. if (onExit)
  21340. onExit();
  21341. };
  21342. }
  21343. const forAliasRE$1 = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  21344. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  21345. const stripParensRE = /^\(|\)$/g;
  21346. function parseForExpression(input, context) {
  21347. const loc = input.loc;
  21348. const exp = input.content;
  21349. const inMatch = exp.match(forAliasRE$1);
  21350. if (!inMatch)
  21351. return;
  21352. const [, LHS, RHS] = inMatch;
  21353. const result = {
  21354. source: createAliasExpression(
  21355. loc,
  21356. RHS.trim(),
  21357. exp.indexOf(RHS, LHS.length)
  21358. ),
  21359. value: void 0,
  21360. key: void 0,
  21361. index: void 0
  21362. };
  21363. if (context.prefixIdentifiers) {
  21364. result.source = processExpression(
  21365. result.source,
  21366. context
  21367. );
  21368. }
  21369. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  21370. const trimmedOffset = LHS.indexOf(valueContent);
  21371. const iteratorMatch = valueContent.match(forIteratorRE);
  21372. if (iteratorMatch) {
  21373. valueContent = valueContent.replace(forIteratorRE, "").trim();
  21374. const keyContent = iteratorMatch[1].trim();
  21375. let keyOffset;
  21376. if (keyContent) {
  21377. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  21378. result.key = createAliasExpression(loc, keyContent, keyOffset);
  21379. if (context.prefixIdentifiers) {
  21380. result.key = processExpression(result.key, context, true);
  21381. }
  21382. }
  21383. if (iteratorMatch[2]) {
  21384. const indexContent = iteratorMatch[2].trim();
  21385. if (indexContent) {
  21386. result.index = createAliasExpression(
  21387. loc,
  21388. indexContent,
  21389. exp.indexOf(
  21390. indexContent,
  21391. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  21392. )
  21393. );
  21394. if (context.prefixIdentifiers) {
  21395. result.index = processExpression(result.index, context, true);
  21396. }
  21397. }
  21398. }
  21399. }
  21400. if (valueContent) {
  21401. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  21402. if (context.prefixIdentifiers) {
  21403. result.value = processExpression(result.value, context, true);
  21404. }
  21405. }
  21406. return result;
  21407. }
  21408. function createAliasExpression(range, content, offset) {
  21409. return createSimpleExpression(
  21410. content,
  21411. false,
  21412. getInnerRange(range, offset, content.length)
  21413. );
  21414. }
  21415. function createForLoopParams({ value, key, index }, memoArgs = []) {
  21416. return createParamsList([value, key, index, ...memoArgs]);
  21417. }
  21418. function createParamsList(args) {
  21419. let i = args.length;
  21420. while (i--) {
  21421. if (args[i])
  21422. break;
  21423. }
  21424. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  21425. }
  21426. const defaultFallback = createSimpleExpression(`undefined`, false);
  21427. const trackSlotScopes = (node, context) => {
  21428. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  21429. const vSlot = findDir(node, "slot");
  21430. if (vSlot) {
  21431. const slotProps = vSlot.exp;
  21432. if (context.prefixIdentifiers) {
  21433. slotProps && context.addIdentifiers(slotProps);
  21434. }
  21435. context.scopes.vSlot++;
  21436. return () => {
  21437. if (context.prefixIdentifiers) {
  21438. slotProps && context.removeIdentifiers(slotProps);
  21439. }
  21440. context.scopes.vSlot--;
  21441. };
  21442. }
  21443. }
  21444. };
  21445. const trackVForSlotScopes = (node, context) => {
  21446. let vFor;
  21447. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  21448. const result = vFor.parseResult = parseForExpression(
  21449. vFor.exp,
  21450. context
  21451. );
  21452. if (result) {
  21453. const { value, key, index } = result;
  21454. const { addIdentifiers, removeIdentifiers } = context;
  21455. value && addIdentifiers(value);
  21456. key && addIdentifiers(key);
  21457. index && addIdentifiers(index);
  21458. return () => {
  21459. value && removeIdentifiers(value);
  21460. key && removeIdentifiers(key);
  21461. index && removeIdentifiers(index);
  21462. };
  21463. }
  21464. }
  21465. };
  21466. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(
  21467. props,
  21468. children,
  21469. false,
  21470. true,
  21471. children.length ? children[0].loc : loc
  21472. );
  21473. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  21474. context.helper(WITH_CTX);
  21475. const { children, loc } = node;
  21476. const slotsProperties = [];
  21477. const dynamicSlots = [];
  21478. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  21479. if (!context.ssr && context.prefixIdentifiers) {
  21480. hasDynamicSlots = hasScopeRef(node, context.identifiers);
  21481. }
  21482. const onComponentSlot = findDir(node, "slot", true);
  21483. if (onComponentSlot) {
  21484. const { arg, exp } = onComponentSlot;
  21485. if (arg && !isStaticExp(arg)) {
  21486. hasDynamicSlots = true;
  21487. }
  21488. slotsProperties.push(
  21489. createObjectProperty(
  21490. arg || createSimpleExpression("default", true),
  21491. buildSlotFn(exp, children, loc)
  21492. )
  21493. );
  21494. }
  21495. let hasTemplateSlots = false;
  21496. let hasNamedDefaultSlot = false;
  21497. const implicitDefaultChildren = [];
  21498. const seenSlotNames = /* @__PURE__ */ new Set();
  21499. let conditionalBranchIndex = 0;
  21500. for (let i = 0; i < children.length; i++) {
  21501. const slotElement = children[i];
  21502. let slotDir;
  21503. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  21504. if (slotElement.type !== 3) {
  21505. implicitDefaultChildren.push(slotElement);
  21506. }
  21507. continue;
  21508. }
  21509. if (onComponentSlot) {
  21510. context.onError(
  21511. createCompilerError(37, slotDir.loc)
  21512. );
  21513. break;
  21514. }
  21515. hasTemplateSlots = true;
  21516. const { children: slotChildren, loc: slotLoc } = slotElement;
  21517. const {
  21518. arg: slotName = createSimpleExpression(`default`, true),
  21519. exp: slotProps,
  21520. loc: dirLoc
  21521. } = slotDir;
  21522. let staticSlotName;
  21523. if (isStaticExp(slotName)) {
  21524. staticSlotName = slotName ? slotName.content : `default`;
  21525. } else {
  21526. hasDynamicSlots = true;
  21527. }
  21528. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  21529. let vIf;
  21530. let vElse;
  21531. let vFor;
  21532. if (vIf = findDir(slotElement, "if")) {
  21533. hasDynamicSlots = true;
  21534. dynamicSlots.push(
  21535. createConditionalExpression(
  21536. vIf.exp,
  21537. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  21538. defaultFallback
  21539. )
  21540. );
  21541. } else if (vElse = findDir(
  21542. slotElement,
  21543. /^else(-if)?$/,
  21544. true
  21545. /* allowEmpty */
  21546. )) {
  21547. let j = i;
  21548. let prev;
  21549. while (j--) {
  21550. prev = children[j];
  21551. if (prev.type !== 3) {
  21552. break;
  21553. }
  21554. }
  21555. if (prev && isTemplateNode(prev) && findDir(prev, "if")) {
  21556. children.splice(i, 1);
  21557. i--;
  21558. let conditional = dynamicSlots[dynamicSlots.length - 1];
  21559. while (conditional.alternate.type === 19) {
  21560. conditional = conditional.alternate;
  21561. }
  21562. conditional.alternate = vElse.exp ? createConditionalExpression(
  21563. vElse.exp,
  21564. buildDynamicSlot(
  21565. slotName,
  21566. slotFunction,
  21567. conditionalBranchIndex++
  21568. ),
  21569. defaultFallback
  21570. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  21571. } else {
  21572. context.onError(
  21573. createCompilerError(30, vElse.loc)
  21574. );
  21575. }
  21576. } else if (vFor = findDir(slotElement, "for")) {
  21577. hasDynamicSlots = true;
  21578. const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
  21579. if (parseResult) {
  21580. dynamicSlots.push(
  21581. createCallExpression(context.helper(RENDER_LIST), [
  21582. parseResult.source,
  21583. createFunctionExpression(
  21584. createForLoopParams(parseResult),
  21585. buildDynamicSlot(slotName, slotFunction),
  21586. true
  21587. /* force newline */
  21588. )
  21589. ])
  21590. );
  21591. } else {
  21592. context.onError(
  21593. createCompilerError(32, vFor.loc)
  21594. );
  21595. }
  21596. } else {
  21597. if (staticSlotName) {
  21598. if (seenSlotNames.has(staticSlotName)) {
  21599. context.onError(
  21600. createCompilerError(
  21601. 38,
  21602. dirLoc
  21603. )
  21604. );
  21605. continue;
  21606. }
  21607. seenSlotNames.add(staticSlotName);
  21608. if (staticSlotName === "default") {
  21609. hasNamedDefaultSlot = true;
  21610. }
  21611. }
  21612. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  21613. }
  21614. }
  21615. if (!onComponentSlot) {
  21616. const buildDefaultSlotProperty = (props, children2) => {
  21617. const fn = buildSlotFn(props, children2, loc);
  21618. return createObjectProperty(`default`, fn);
  21619. };
  21620. if (!hasTemplateSlots) {
  21621. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  21622. } else if (implicitDefaultChildren.length && // #3766
  21623. // with whitespace: 'preserve', whitespaces between slots will end up in
  21624. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  21625. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  21626. if (hasNamedDefaultSlot) {
  21627. context.onError(
  21628. createCompilerError(
  21629. 39,
  21630. implicitDefaultChildren[0].loc
  21631. )
  21632. );
  21633. } else {
  21634. slotsProperties.push(
  21635. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  21636. );
  21637. }
  21638. }
  21639. }
  21640. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  21641. let slots = createObjectExpression(
  21642. slotsProperties.concat(
  21643. createObjectProperty(
  21644. `_`,
  21645. // 2 = compiled but dynamic = can skip normalization, but must run diff
  21646. // 1 = compiled and static = can skip normalization AND diff as optimized
  21647. createSimpleExpression(
  21648. slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
  21649. false
  21650. )
  21651. )
  21652. ),
  21653. loc
  21654. );
  21655. if (dynamicSlots.length) {
  21656. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  21657. slots,
  21658. createArrayExpression(dynamicSlots)
  21659. ]);
  21660. }
  21661. return {
  21662. slots,
  21663. hasDynamicSlots
  21664. };
  21665. }
  21666. function buildDynamicSlot(name, fn, index) {
  21667. const props = [
  21668. createObjectProperty(`name`, name),
  21669. createObjectProperty(`fn`, fn)
  21670. ];
  21671. if (index != null) {
  21672. props.push(
  21673. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  21674. );
  21675. }
  21676. return createObjectExpression(props);
  21677. }
  21678. function hasForwardedSlots(children) {
  21679. for (let i = 0; i < children.length; i++) {
  21680. const child = children[i];
  21681. switch (child.type) {
  21682. case 1:
  21683. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  21684. return true;
  21685. }
  21686. break;
  21687. case 9:
  21688. if (hasForwardedSlots(child.branches))
  21689. return true;
  21690. break;
  21691. case 10:
  21692. case 11:
  21693. if (hasForwardedSlots(child.children))
  21694. return true;
  21695. break;
  21696. }
  21697. }
  21698. return false;
  21699. }
  21700. function isNonWhitespaceContent(node) {
  21701. if (node.type !== 2 && node.type !== 12)
  21702. return true;
  21703. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  21704. }
  21705. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  21706. const transformElement = (node, context) => {
  21707. return function postTransformElement() {
  21708. node = context.currentNode;
  21709. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  21710. return;
  21711. }
  21712. const { tag, props } = node;
  21713. const isComponent = node.tagType === 1;
  21714. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  21715. const isDynamicComponent = isObject$2(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  21716. let vnodeProps;
  21717. let vnodeChildren;
  21718. let vnodePatchFlag;
  21719. let patchFlag = 0;
  21720. let vnodeDynamicProps;
  21721. let dynamicPropNames;
  21722. let vnodeDirectives;
  21723. let shouldUseBlock = (
  21724. // dynamic component may resolve to plain elements
  21725. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  21726. // updates inside get proper isSVG flag at runtime. (#639, #643)
  21727. // This is technically web-specific, but splitting the logic out of core
  21728. // leads to too much unnecessary complexity.
  21729. (tag === "svg" || tag === "foreignObject")
  21730. );
  21731. if (props.length > 0) {
  21732. const propsBuildResult = buildProps(
  21733. node,
  21734. context,
  21735. void 0,
  21736. isComponent,
  21737. isDynamicComponent
  21738. );
  21739. vnodeProps = propsBuildResult.props;
  21740. patchFlag = propsBuildResult.patchFlag;
  21741. dynamicPropNames = propsBuildResult.dynamicPropNames;
  21742. const directives = propsBuildResult.directives;
  21743. vnodeDirectives = directives && directives.length ? createArrayExpression(
  21744. directives.map((dir) => buildDirectiveArgs(dir, context))
  21745. ) : void 0;
  21746. if (propsBuildResult.shouldUseBlock) {
  21747. shouldUseBlock = true;
  21748. }
  21749. }
  21750. if (node.children.length > 0) {
  21751. if (vnodeTag === KEEP_ALIVE) {
  21752. shouldUseBlock = true;
  21753. patchFlag |= 1024;
  21754. if (node.children.length > 1) {
  21755. context.onError(
  21756. createCompilerError(46, {
  21757. start: node.children[0].loc.start,
  21758. end: node.children[node.children.length - 1].loc.end,
  21759. source: ""
  21760. })
  21761. );
  21762. }
  21763. }
  21764. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  21765. vnodeTag !== TELEPORT && // explained above.
  21766. vnodeTag !== KEEP_ALIVE;
  21767. if (shouldBuildAsSlots) {
  21768. const { slots, hasDynamicSlots } = buildSlots(node, context);
  21769. vnodeChildren = slots;
  21770. if (hasDynamicSlots) {
  21771. patchFlag |= 1024;
  21772. }
  21773. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  21774. const child = node.children[0];
  21775. const type = child.type;
  21776. const hasDynamicTextChild = type === 5 || type === 8;
  21777. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  21778. patchFlag |= 1;
  21779. }
  21780. if (hasDynamicTextChild || type === 2) {
  21781. vnodeChildren = child;
  21782. } else {
  21783. vnodeChildren = node.children;
  21784. }
  21785. } else {
  21786. vnodeChildren = node.children;
  21787. }
  21788. }
  21789. if (patchFlag !== 0) {
  21790. {
  21791. if (patchFlag < 0) {
  21792. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  21793. } else {
  21794. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  21795. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  21796. }
  21797. }
  21798. if (dynamicPropNames && dynamicPropNames.length) {
  21799. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  21800. }
  21801. }
  21802. node.codegenNode = createVNodeCall(
  21803. context,
  21804. vnodeTag,
  21805. vnodeProps,
  21806. vnodeChildren,
  21807. vnodePatchFlag,
  21808. vnodeDynamicProps,
  21809. vnodeDirectives,
  21810. !!shouldUseBlock,
  21811. false,
  21812. isComponent,
  21813. node.loc
  21814. );
  21815. };
  21816. };
  21817. function resolveComponentType(node, context, ssr = false) {
  21818. let { tag } = node;
  21819. const isExplicitDynamic = isComponentTag(tag);
  21820. const isProp = findProp(node, "is");
  21821. if (isProp) {
  21822. if (isExplicitDynamic || false) {
  21823. const exp = isProp.type === 6 ? isProp.value && createSimpleExpression(isProp.value.content, true) : isProp.exp;
  21824. if (exp) {
  21825. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  21826. exp
  21827. ]);
  21828. }
  21829. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  21830. tag = isProp.value.content.slice(4);
  21831. }
  21832. }
  21833. const isDir = !isExplicitDynamic && findDir(node, "is");
  21834. if (isDir && isDir.exp) {
  21835. {
  21836. context.onWarn(
  21837. createCompilerError(52, isDir.loc)
  21838. );
  21839. }
  21840. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  21841. isDir.exp
  21842. ]);
  21843. }
  21844. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  21845. if (builtIn) {
  21846. if (!ssr)
  21847. context.helper(builtIn);
  21848. return builtIn;
  21849. }
  21850. {
  21851. const fromSetup = resolveSetupReference(tag, context);
  21852. if (fromSetup) {
  21853. return fromSetup;
  21854. }
  21855. const dotIndex = tag.indexOf(".");
  21856. if (dotIndex > 0) {
  21857. const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
  21858. if (ns) {
  21859. return ns + tag.slice(dotIndex);
  21860. }
  21861. }
  21862. }
  21863. if (context.selfName && capitalize$1(camelize(tag)) === context.selfName) {
  21864. context.helper(RESOLVE_COMPONENT);
  21865. context.components.add(tag + `__self`);
  21866. return toValidAssetId(tag, `component`);
  21867. }
  21868. context.helper(RESOLVE_COMPONENT);
  21869. context.components.add(tag);
  21870. return toValidAssetId(tag, `component`);
  21871. }
  21872. function resolveSetupReference(name, context) {
  21873. const bindings = context.bindingMetadata;
  21874. if (!bindings || bindings.__isScriptSetup === false) {
  21875. return;
  21876. }
  21877. const camelName = camelize(name);
  21878. const PascalName = capitalize$1(camelName);
  21879. const checkType = (type) => {
  21880. if (bindings[name] === type) {
  21881. return name;
  21882. }
  21883. if (bindings[camelName] === type) {
  21884. return camelName;
  21885. }
  21886. if (bindings[PascalName] === type) {
  21887. return PascalName;
  21888. }
  21889. };
  21890. const fromConst = checkType("setup-const") || checkType("setup-reactive-const") || checkType("literal-const");
  21891. if (fromConst) {
  21892. return context.inline ? (
  21893. // in inline mode, const setup bindings (e.g. imports) can be used as-is
  21894. fromConst
  21895. ) : `$setup[${JSON.stringify(fromConst)}]`;
  21896. }
  21897. const fromMaybeRef = checkType("setup-let") || checkType("setup-ref") || checkType("setup-maybe-ref");
  21898. if (fromMaybeRef) {
  21899. return context.inline ? (
  21900. // setup scope bindings that may be refs need to be unrefed
  21901. `${context.helperString(UNREF)}(${fromMaybeRef})`
  21902. ) : `$setup[${JSON.stringify(fromMaybeRef)}]`;
  21903. }
  21904. }
  21905. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  21906. const { tag, loc: elementLoc, children } = node;
  21907. let properties = [];
  21908. const mergeArgs = [];
  21909. const runtimeDirectives = [];
  21910. const hasChildren = children.length > 0;
  21911. let shouldUseBlock = false;
  21912. let patchFlag = 0;
  21913. let hasRef = false;
  21914. let hasClassBinding = false;
  21915. let hasStyleBinding = false;
  21916. let hasHydrationEventBinding = false;
  21917. let hasDynamicKeys = false;
  21918. let hasVnodeHook = false;
  21919. const dynamicPropNames = [];
  21920. const pushMergeArg = (arg) => {
  21921. if (properties.length) {
  21922. mergeArgs.push(
  21923. createObjectExpression(dedupeProperties(properties), elementLoc)
  21924. );
  21925. properties = [];
  21926. }
  21927. if (arg)
  21928. mergeArgs.push(arg);
  21929. };
  21930. const analyzePatchFlag = ({ key, value }) => {
  21931. if (isStaticExp(key)) {
  21932. const name = key.content;
  21933. const isEventHandler = isOn(name);
  21934. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  21935. // dedicated fast path.
  21936. name.toLowerCase() !== "onclick" && // omit v-model handlers
  21937. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  21938. !isReservedProp(name)) {
  21939. hasHydrationEventBinding = true;
  21940. }
  21941. if (isEventHandler && isReservedProp(name)) {
  21942. hasVnodeHook = true;
  21943. }
  21944. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  21945. return;
  21946. }
  21947. if (name === "ref") {
  21948. hasRef = true;
  21949. } else if (name === "class") {
  21950. hasClassBinding = true;
  21951. } else if (name === "style") {
  21952. hasStyleBinding = true;
  21953. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  21954. dynamicPropNames.push(name);
  21955. }
  21956. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  21957. dynamicPropNames.push(name);
  21958. }
  21959. } else {
  21960. hasDynamicKeys = true;
  21961. }
  21962. };
  21963. for (let i = 0; i < props.length; i++) {
  21964. const prop = props[i];
  21965. if (prop.type === 6) {
  21966. const { loc, name, value } = prop;
  21967. let isStatic = true;
  21968. if (name === "ref") {
  21969. hasRef = true;
  21970. if (context.scopes.vFor > 0) {
  21971. properties.push(
  21972. createObjectProperty(
  21973. createSimpleExpression("ref_for", true),
  21974. createSimpleExpression("true")
  21975. )
  21976. );
  21977. }
  21978. if (value && context.inline) {
  21979. const binding = context.bindingMetadata[value.content];
  21980. if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") {
  21981. isStatic = false;
  21982. properties.push(
  21983. createObjectProperty(
  21984. createSimpleExpression("ref_key", true),
  21985. createSimpleExpression(value.content, true, value.loc)
  21986. )
  21987. );
  21988. }
  21989. }
  21990. }
  21991. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || false)) {
  21992. continue;
  21993. }
  21994. properties.push(
  21995. createObjectProperty(
  21996. createSimpleExpression(
  21997. name,
  21998. true,
  21999. getInnerRange(loc, 0, name.length)
  22000. ),
  22001. createSimpleExpression(
  22002. value ? value.content : "",
  22003. isStatic,
  22004. value ? value.loc : loc
  22005. )
  22006. )
  22007. );
  22008. } else {
  22009. const { name, arg, exp, loc } = prop;
  22010. const isVBind = name === "bind";
  22011. const isVOn = name === "on";
  22012. if (name === "slot") {
  22013. if (!isComponent) {
  22014. context.onError(
  22015. createCompilerError(40, loc)
  22016. );
  22017. }
  22018. continue;
  22019. }
  22020. if (name === "once" || name === "memo") {
  22021. continue;
  22022. }
  22023. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || false)) {
  22024. continue;
  22025. }
  22026. if (isVOn && ssr) {
  22027. continue;
  22028. }
  22029. if (
  22030. // #938: elements with dynamic keys should be forced into blocks
  22031. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  22032. // before children
  22033. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  22034. ) {
  22035. shouldUseBlock = true;
  22036. }
  22037. if (isVBind && isStaticArgOf(arg, "ref") && context.scopes.vFor > 0) {
  22038. properties.push(
  22039. createObjectProperty(
  22040. createSimpleExpression("ref_for", true),
  22041. createSimpleExpression("true")
  22042. )
  22043. );
  22044. }
  22045. if (!arg && (isVBind || isVOn)) {
  22046. hasDynamicKeys = true;
  22047. if (exp) {
  22048. if (isVBind) {
  22049. pushMergeArg();
  22050. mergeArgs.push(exp);
  22051. } else {
  22052. pushMergeArg({
  22053. type: 14,
  22054. loc,
  22055. callee: context.helper(TO_HANDLERS),
  22056. arguments: isComponent ? [exp] : [exp, `true`]
  22057. });
  22058. }
  22059. } else {
  22060. context.onError(
  22061. createCompilerError(
  22062. isVBind ? 34 : 35,
  22063. loc
  22064. )
  22065. );
  22066. }
  22067. continue;
  22068. }
  22069. const directiveTransform = context.directiveTransforms[name];
  22070. if (directiveTransform) {
  22071. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  22072. !ssr && props2.forEach(analyzePatchFlag);
  22073. if (isVOn && arg && !isStaticExp(arg)) {
  22074. pushMergeArg(createObjectExpression(props2, elementLoc));
  22075. } else {
  22076. properties.push(...props2);
  22077. }
  22078. if (needRuntime) {
  22079. runtimeDirectives.push(prop);
  22080. if (isSymbol$1(needRuntime)) {
  22081. directiveImportMap.set(prop, needRuntime);
  22082. }
  22083. }
  22084. } else if (!isBuiltInDirective(name)) {
  22085. runtimeDirectives.push(prop);
  22086. if (hasChildren) {
  22087. shouldUseBlock = true;
  22088. }
  22089. }
  22090. }
  22091. }
  22092. let propsExpression = void 0;
  22093. if (mergeArgs.length) {
  22094. pushMergeArg();
  22095. if (mergeArgs.length > 1) {
  22096. propsExpression = createCallExpression(
  22097. context.helper(MERGE_PROPS),
  22098. mergeArgs,
  22099. elementLoc
  22100. );
  22101. } else {
  22102. propsExpression = mergeArgs[0];
  22103. }
  22104. } else if (properties.length) {
  22105. propsExpression = createObjectExpression(
  22106. dedupeProperties(properties),
  22107. elementLoc
  22108. );
  22109. }
  22110. if (hasDynamicKeys) {
  22111. patchFlag |= 16;
  22112. } else {
  22113. if (hasClassBinding && !isComponent) {
  22114. patchFlag |= 2;
  22115. }
  22116. if (hasStyleBinding && !isComponent) {
  22117. patchFlag |= 4;
  22118. }
  22119. if (dynamicPropNames.length) {
  22120. patchFlag |= 8;
  22121. }
  22122. if (hasHydrationEventBinding) {
  22123. patchFlag |= 32;
  22124. }
  22125. }
  22126. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  22127. patchFlag |= 512;
  22128. }
  22129. if (!context.inSSR && propsExpression) {
  22130. switch (propsExpression.type) {
  22131. case 15:
  22132. let classKeyIndex = -1;
  22133. let styleKeyIndex = -1;
  22134. let hasDynamicKey = false;
  22135. for (let i = 0; i < propsExpression.properties.length; i++) {
  22136. const key = propsExpression.properties[i].key;
  22137. if (isStaticExp(key)) {
  22138. if (key.content === "class") {
  22139. classKeyIndex = i;
  22140. } else if (key.content === "style") {
  22141. styleKeyIndex = i;
  22142. }
  22143. } else if (!key.isHandlerKey) {
  22144. hasDynamicKey = true;
  22145. }
  22146. }
  22147. const classProp = propsExpression.properties[classKeyIndex];
  22148. const styleProp = propsExpression.properties[styleKeyIndex];
  22149. if (!hasDynamicKey) {
  22150. if (classProp && !isStaticExp(classProp.value)) {
  22151. classProp.value = createCallExpression(
  22152. context.helper(NORMALIZE_CLASS),
  22153. [classProp.value]
  22154. );
  22155. }
  22156. if (styleProp && // the static style is compiled into an object,
  22157. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  22158. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  22159. // v-bind:style with static literal object
  22160. styleProp.value.type === 17)) {
  22161. styleProp.value = createCallExpression(
  22162. context.helper(NORMALIZE_STYLE),
  22163. [styleProp.value]
  22164. );
  22165. }
  22166. } else {
  22167. propsExpression = createCallExpression(
  22168. context.helper(NORMALIZE_PROPS),
  22169. [propsExpression]
  22170. );
  22171. }
  22172. break;
  22173. case 14:
  22174. break;
  22175. default:
  22176. propsExpression = createCallExpression(
  22177. context.helper(NORMALIZE_PROPS),
  22178. [
  22179. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  22180. propsExpression
  22181. ])
  22182. ]
  22183. );
  22184. break;
  22185. }
  22186. }
  22187. return {
  22188. props: propsExpression,
  22189. directives: runtimeDirectives,
  22190. patchFlag,
  22191. dynamicPropNames,
  22192. shouldUseBlock
  22193. };
  22194. }
  22195. function dedupeProperties(properties) {
  22196. const knownProps = /* @__PURE__ */ new Map();
  22197. const deduped = [];
  22198. for (let i = 0; i < properties.length; i++) {
  22199. const prop = properties[i];
  22200. if (prop.key.type === 8 || !prop.key.isStatic) {
  22201. deduped.push(prop);
  22202. continue;
  22203. }
  22204. const name = prop.key.content;
  22205. const existing = knownProps.get(name);
  22206. if (existing) {
  22207. if (name === "style" || name === "class" || isOn(name)) {
  22208. mergeAsArray(existing, prop);
  22209. }
  22210. } else {
  22211. knownProps.set(name, prop);
  22212. deduped.push(prop);
  22213. }
  22214. }
  22215. return deduped;
  22216. }
  22217. function mergeAsArray(existing, incoming) {
  22218. if (existing.value.type === 17) {
  22219. existing.value.elements.push(incoming.value);
  22220. } else {
  22221. existing.value = createArrayExpression(
  22222. [existing.value, incoming.value],
  22223. existing.loc
  22224. );
  22225. }
  22226. }
  22227. function buildDirectiveArgs(dir, context) {
  22228. const dirArgs = [];
  22229. const runtime = directiveImportMap.get(dir);
  22230. if (runtime) {
  22231. dirArgs.push(context.helperString(runtime));
  22232. } else {
  22233. const fromSetup = resolveSetupReference("v-" + dir.name, context);
  22234. if (fromSetup) {
  22235. dirArgs.push(fromSetup);
  22236. } else {
  22237. context.helper(RESOLVE_DIRECTIVE);
  22238. context.directives.add(dir.name);
  22239. dirArgs.push(toValidAssetId(dir.name, `directive`));
  22240. }
  22241. }
  22242. const { loc } = dir;
  22243. if (dir.exp)
  22244. dirArgs.push(dir.exp);
  22245. if (dir.arg) {
  22246. if (!dir.exp) {
  22247. dirArgs.push(`void 0`);
  22248. }
  22249. dirArgs.push(dir.arg);
  22250. }
  22251. if (Object.keys(dir.modifiers).length) {
  22252. if (!dir.arg) {
  22253. if (!dir.exp) {
  22254. dirArgs.push(`void 0`);
  22255. }
  22256. dirArgs.push(`void 0`);
  22257. }
  22258. const trueExpression = createSimpleExpression(`true`, false, loc);
  22259. dirArgs.push(
  22260. createObjectExpression(
  22261. dir.modifiers.map(
  22262. (modifier) => createObjectProperty(modifier, trueExpression)
  22263. ),
  22264. loc
  22265. )
  22266. );
  22267. }
  22268. return createArrayExpression(dirArgs, dir.loc);
  22269. }
  22270. function stringifyDynamicPropNames(props) {
  22271. let propsNamesString = `[`;
  22272. for (let i = 0, l = props.length; i < l; i++) {
  22273. propsNamesString += JSON.stringify(props[i]);
  22274. if (i < l - 1)
  22275. propsNamesString += ", ";
  22276. }
  22277. return propsNamesString + `]`;
  22278. }
  22279. function isComponentTag(tag) {
  22280. return tag === "component" || tag === "Component";
  22281. }
  22282. const transformSlotOutlet = (node, context) => {
  22283. if (isSlotOutlet(node)) {
  22284. const { children, loc } = node;
  22285. const { slotName, slotProps } = processSlotOutlet(node, context);
  22286. const slotArgs = [
  22287. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  22288. slotName,
  22289. "{}",
  22290. "undefined",
  22291. "true"
  22292. ];
  22293. let expectedLen = 2;
  22294. if (slotProps) {
  22295. slotArgs[2] = slotProps;
  22296. expectedLen = 3;
  22297. }
  22298. if (children.length) {
  22299. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  22300. expectedLen = 4;
  22301. }
  22302. if (context.scopeId && !context.slotted) {
  22303. expectedLen = 5;
  22304. }
  22305. slotArgs.splice(expectedLen);
  22306. node.codegenNode = createCallExpression(
  22307. context.helper(RENDER_SLOT),
  22308. slotArgs,
  22309. loc
  22310. );
  22311. }
  22312. };
  22313. function processSlotOutlet(node, context) {
  22314. let slotName = `"default"`;
  22315. let slotProps = void 0;
  22316. const nonNameProps = [];
  22317. for (let i = 0; i < node.props.length; i++) {
  22318. const p = node.props[i];
  22319. if (p.type === 6) {
  22320. if (p.value) {
  22321. if (p.name === "name") {
  22322. slotName = JSON.stringify(p.value.content);
  22323. } else {
  22324. p.name = camelize(p.name);
  22325. nonNameProps.push(p);
  22326. }
  22327. }
  22328. } else {
  22329. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  22330. if (p.exp)
  22331. slotName = p.exp;
  22332. } else {
  22333. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  22334. p.arg.content = camelize(p.arg.content);
  22335. }
  22336. nonNameProps.push(p);
  22337. }
  22338. }
  22339. }
  22340. if (nonNameProps.length > 0) {
  22341. const { props, directives } = buildProps(
  22342. node,
  22343. context,
  22344. nonNameProps,
  22345. false,
  22346. false
  22347. );
  22348. slotProps = props;
  22349. if (directives.length) {
  22350. context.onError(
  22351. createCompilerError(
  22352. 36,
  22353. directives[0].loc
  22354. )
  22355. );
  22356. }
  22357. }
  22358. return {
  22359. slotName,
  22360. slotProps
  22361. };
  22362. }
  22363. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  22364. const transformOn$1 = (dir, node, context, augmentor) => {
  22365. const { loc, modifiers, arg } = dir;
  22366. if (!dir.exp && !modifiers.length) {
  22367. context.onError(createCompilerError(35, loc));
  22368. }
  22369. let eventName;
  22370. if (arg.type === 4) {
  22371. if (arg.isStatic) {
  22372. let rawName = arg.content;
  22373. if (rawName.startsWith("vnode")) {
  22374. context.onWarn(
  22375. createCompilerError(51, arg.loc)
  22376. );
  22377. }
  22378. if (rawName.startsWith("vue:")) {
  22379. rawName = `vnode-${rawName.slice(4)}`;
  22380. }
  22381. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  22382. // for non-element and vnode lifecycle event listeners, auto convert
  22383. // it to camelCase. See issue #2249
  22384. toHandlerKey(camelize(rawName))
  22385. ) : (
  22386. // preserve case for plain element listeners that have uppercase
  22387. // letters, as these may be custom elements' custom events
  22388. `on:${rawName}`
  22389. );
  22390. eventName = createSimpleExpression(eventString, true, arg.loc);
  22391. } else {
  22392. eventName = createCompoundExpression([
  22393. `${context.helperString(TO_HANDLER_KEY)}(`,
  22394. arg,
  22395. `)`
  22396. ]);
  22397. }
  22398. } else {
  22399. eventName = arg;
  22400. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  22401. eventName.children.push(`)`);
  22402. }
  22403. let exp = dir.exp;
  22404. if (exp && !exp.content.trim()) {
  22405. exp = void 0;
  22406. }
  22407. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  22408. if (exp) {
  22409. const isMemberExp = isMemberExpression(exp.content, context);
  22410. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  22411. const hasMultipleStatements = exp.content.includes(`;`);
  22412. if (context.prefixIdentifiers) {
  22413. isInlineStatement && context.addIdentifiers(`$event`);
  22414. exp = dir.exp = processExpression(
  22415. exp,
  22416. context,
  22417. false,
  22418. hasMultipleStatements
  22419. );
  22420. isInlineStatement && context.removeIdentifiers(`$event`);
  22421. shouldCache = context.cacheHandlers && // unnecessary to cache inside v-once
  22422. !context.inVOnce && // runtime constants don't need to be cached
  22423. // (this is analyzed by compileScript in SFC <script setup>)
  22424. !(exp.type === 4 && exp.constType > 0) && // #1541 bail if this is a member exp handler passed to a component -
  22425. // we need to use the original function to preserve arity,
  22426. // e.g. <transition> relies on checking cb.length to determine
  22427. // transition end handling. Inline function is ok since its arity
  22428. // is preserved even when cached.
  22429. !(isMemberExp && node.tagType === 1) && // bail if the function references closure variables (v-for, v-slot)
  22430. // it must be passed fresh to avoid stale values.
  22431. !hasScopeRef(exp, context.identifiers);
  22432. if (shouldCache && isMemberExp) {
  22433. if (exp.type === 4) {
  22434. exp.content = `${exp.content} && ${exp.content}(...args)`;
  22435. } else {
  22436. exp.children = [...exp.children, ` && `, ...exp.children, `(...args)`];
  22437. }
  22438. }
  22439. }
  22440. if (isInlineStatement || shouldCache && isMemberExp) {
  22441. exp = createCompoundExpression([
  22442. `${isInlineStatement ? context.isTS ? `($event: any)` : `$event` : `${context.isTS ? `
  22443. //@ts-ignore
  22444. ` : ``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  22445. exp,
  22446. hasMultipleStatements ? `}` : `)`
  22447. ]);
  22448. }
  22449. }
  22450. let ret = {
  22451. props: [
  22452. createObjectProperty(
  22453. eventName,
  22454. exp || createSimpleExpression(`() => {}`, false, loc)
  22455. )
  22456. ]
  22457. };
  22458. if (augmentor) {
  22459. ret = augmentor(ret);
  22460. }
  22461. if (shouldCache) {
  22462. ret.props[0].value = context.cache(ret.props[0].value);
  22463. }
  22464. ret.props.forEach((p) => p.key.isHandlerKey = true);
  22465. return ret;
  22466. };
  22467. const transformBind = (dir, _node, context) => {
  22468. const { exp, modifiers, loc } = dir;
  22469. const arg = dir.arg;
  22470. if (arg.type !== 4) {
  22471. arg.children.unshift(`(`);
  22472. arg.children.push(`) || ""`);
  22473. } else if (!arg.isStatic) {
  22474. arg.content = `${arg.content} || ""`;
  22475. }
  22476. if (modifiers.includes("camel")) {
  22477. if (arg.type === 4) {
  22478. if (arg.isStatic) {
  22479. arg.content = camelize(arg.content);
  22480. } else {
  22481. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  22482. }
  22483. } else {
  22484. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  22485. arg.children.push(`)`);
  22486. }
  22487. }
  22488. if (!context.inSSR) {
  22489. if (modifiers.includes("prop")) {
  22490. injectPrefix(arg, ".");
  22491. }
  22492. if (modifiers.includes("attr")) {
  22493. injectPrefix(arg, "^");
  22494. }
  22495. }
  22496. if (!exp || exp.type === 4 && !exp.content.trim()) {
  22497. context.onError(createCompilerError(34, loc));
  22498. return {
  22499. props: [createObjectProperty(arg, createSimpleExpression("", true, loc))]
  22500. };
  22501. }
  22502. return {
  22503. props: [createObjectProperty(arg, exp)]
  22504. };
  22505. };
  22506. const injectPrefix = (arg, prefix) => {
  22507. if (arg.type === 4) {
  22508. if (arg.isStatic) {
  22509. arg.content = prefix + arg.content;
  22510. } else {
  22511. arg.content = `\`${prefix}\${${arg.content}}\``;
  22512. }
  22513. } else {
  22514. arg.children.unshift(`'${prefix}' + (`);
  22515. arg.children.push(`)`);
  22516. }
  22517. };
  22518. const transformText = (node, context) => {
  22519. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  22520. return () => {
  22521. const children = node.children;
  22522. let currentContainer = void 0;
  22523. let hasText = false;
  22524. for (let i = 0; i < children.length; i++) {
  22525. const child = children[i];
  22526. if (isText$1(child)) {
  22527. hasText = true;
  22528. for (let j = i + 1; j < children.length; j++) {
  22529. const next = children[j];
  22530. if (isText$1(next)) {
  22531. if (!currentContainer) {
  22532. currentContainer = children[i] = createCompoundExpression(
  22533. [child],
  22534. child.loc
  22535. );
  22536. }
  22537. currentContainer.children.push(` + `, next);
  22538. children.splice(j, 1);
  22539. j--;
  22540. } else {
  22541. currentContainer = void 0;
  22542. break;
  22543. }
  22544. }
  22545. }
  22546. }
  22547. if (!hasText || // if this is a plain element with a single text child, leave it
  22548. // as-is since the runtime has dedicated fast path for this by directly
  22549. // setting textContent of the element.
  22550. // for component root it's always normalized anyway.
  22551. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  22552. // custom directives can potentially add DOM elements arbitrarily,
  22553. // we need to avoid setting textContent of the element at runtime
  22554. // to avoid accidentally overwriting the DOM elements added
  22555. // by the user through custom directives.
  22556. !node.props.find(
  22557. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  22558. ) && // in compat mode, <template> tags with no special directives
  22559. // will be rendered as a fragment so its children must be
  22560. // converted into vnodes.
  22561. true)) {
  22562. return;
  22563. }
  22564. for (let i = 0; i < children.length; i++) {
  22565. const child = children[i];
  22566. if (isText$1(child) || child.type === 8) {
  22567. const callArgs = [];
  22568. if (child.type !== 2 || child.content !== " ") {
  22569. callArgs.push(child);
  22570. }
  22571. if (!context.ssr && getConstantType(child, context) === 0) {
  22572. callArgs.push(
  22573. 1 + (` /* ${PatchFlagNames[1]} */` )
  22574. );
  22575. }
  22576. children[i] = {
  22577. type: 12,
  22578. content: child,
  22579. loc: child.loc,
  22580. codegenNode: createCallExpression(
  22581. context.helper(CREATE_TEXT),
  22582. callArgs
  22583. )
  22584. };
  22585. }
  22586. }
  22587. };
  22588. }
  22589. };
  22590. const seen$1 = /* @__PURE__ */ new WeakSet();
  22591. const transformOnce = (node, context) => {
  22592. if (node.type === 1 && findDir(node, "once", true)) {
  22593. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  22594. return;
  22595. }
  22596. seen$1.add(node);
  22597. context.inVOnce = true;
  22598. context.helper(SET_BLOCK_TRACKING);
  22599. return () => {
  22600. context.inVOnce = false;
  22601. const cur = context.currentNode;
  22602. if (cur.codegenNode) {
  22603. cur.codegenNode = context.cache(
  22604. cur.codegenNode,
  22605. true
  22606. /* isVNode */
  22607. );
  22608. }
  22609. };
  22610. }
  22611. };
  22612. const transformModel$1 = (dir, node, context) => {
  22613. const { exp, arg } = dir;
  22614. if (!exp) {
  22615. context.onError(
  22616. createCompilerError(41, dir.loc)
  22617. );
  22618. return createTransformProps();
  22619. }
  22620. const rawExp = exp.loc.source;
  22621. const expString = exp.type === 4 ? exp.content : rawExp;
  22622. const bindingType = context.bindingMetadata[rawExp];
  22623. if (bindingType === "props" || bindingType === "props-aliased") {
  22624. context.onError(createCompilerError(44, exp.loc));
  22625. return createTransformProps();
  22626. }
  22627. const maybeRef = context.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
  22628. if (!expString.trim() || !isMemberExpression(expString, context) && !maybeRef) {
  22629. context.onError(
  22630. createCompilerError(42, exp.loc)
  22631. );
  22632. return createTransformProps();
  22633. }
  22634. if (context.prefixIdentifiers && isSimpleIdentifier(expString) && context.identifiers[expString]) {
  22635. context.onError(
  22636. createCompilerError(43, exp.loc)
  22637. );
  22638. return createTransformProps();
  22639. }
  22640. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  22641. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  22642. let assignmentExp;
  22643. const eventArg = context.isTS ? `($event: any)` : `$event`;
  22644. if (maybeRef) {
  22645. if (bindingType === "setup-ref") {
  22646. assignmentExp = createCompoundExpression([
  22647. `${eventArg} => ((`,
  22648. createSimpleExpression(rawExp, false, exp.loc),
  22649. `).value = $event)`
  22650. ]);
  22651. } else {
  22652. const altAssignment = bindingType === "setup-let" ? `${rawExp} = $event` : `null`;
  22653. assignmentExp = createCompoundExpression([
  22654. `${eventArg} => (${context.helperString(IS_REF)}(${rawExp}) ? (`,
  22655. createSimpleExpression(rawExp, false, exp.loc),
  22656. `).value = $event : ${altAssignment})`
  22657. ]);
  22658. }
  22659. } else {
  22660. assignmentExp = createCompoundExpression([
  22661. `${eventArg} => ((`,
  22662. exp,
  22663. `) = $event)`
  22664. ]);
  22665. }
  22666. const props = [
  22667. // modelValue: foo
  22668. createObjectProperty(propName, dir.exp),
  22669. // "onUpdate:modelValue": $event => (foo = $event)
  22670. createObjectProperty(eventName, assignmentExp)
  22671. ];
  22672. if (context.prefixIdentifiers && !context.inVOnce && context.cacheHandlers && !hasScopeRef(exp, context.identifiers)) {
  22673. props[1].value = context.cache(props[1].value);
  22674. }
  22675. if (dir.modifiers.length && node.tagType === 1) {
  22676. const modifiers = dir.modifiers.map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  22677. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  22678. props.push(
  22679. createObjectProperty(
  22680. modifiersKey,
  22681. createSimpleExpression(
  22682. `{ ${modifiers} }`,
  22683. false,
  22684. dir.loc,
  22685. 2
  22686. )
  22687. )
  22688. );
  22689. }
  22690. return createTransformProps(props);
  22691. };
  22692. function createTransformProps(props = []) {
  22693. return { props };
  22694. }
  22695. const seen = /* @__PURE__ */ new WeakSet();
  22696. const transformMemo = (node, context) => {
  22697. if (node.type === 1) {
  22698. const dir = findDir(node, "memo");
  22699. if (!dir || seen.has(node)) {
  22700. return;
  22701. }
  22702. seen.add(node);
  22703. return () => {
  22704. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  22705. if (codegenNode && codegenNode.type === 13) {
  22706. if (node.tagType !== 1) {
  22707. convertToBlock(codegenNode, context);
  22708. }
  22709. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  22710. dir.exp,
  22711. createFunctionExpression(void 0, codegenNode),
  22712. `_cache`,
  22713. String(context.cached++)
  22714. ]);
  22715. }
  22716. };
  22717. }
  22718. };
  22719. function getBaseTransformPreset(prefixIdentifiers) {
  22720. return [
  22721. [
  22722. transformOnce,
  22723. transformIf,
  22724. transformMemo,
  22725. transformFor,
  22726. ...[],
  22727. ...prefixIdentifiers ? [
  22728. // order is important
  22729. trackVForSlotScopes,
  22730. transformExpression
  22731. ] : [],
  22732. transformSlotOutlet,
  22733. transformElement,
  22734. trackSlotScopes,
  22735. transformText
  22736. ],
  22737. {
  22738. on: transformOn$1,
  22739. bind: transformBind,
  22740. model: transformModel$1
  22741. }
  22742. ];
  22743. }
  22744. function baseCompile(template, options = {}) {
  22745. const onError = options.onError || defaultOnError;
  22746. const isModuleMode = options.mode === "module";
  22747. const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
  22748. if (!prefixIdentifiers && options.cacheHandlers) {
  22749. onError(createCompilerError(49));
  22750. }
  22751. if (options.scopeId && !isModuleMode) {
  22752. onError(createCompilerError(50));
  22753. }
  22754. const ast = isString$2(template) ? baseParse(template, options) : template;
  22755. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
  22756. if (options.isTS) {
  22757. const { expressionPlugins } = options;
  22758. if (!expressionPlugins || !expressionPlugins.includes("typescript")) {
  22759. options.expressionPlugins = [...expressionPlugins || [], "typescript"];
  22760. }
  22761. }
  22762. transform$1(
  22763. ast,
  22764. extend({}, options, {
  22765. prefixIdentifiers,
  22766. nodeTransforms: [
  22767. ...nodeTransforms,
  22768. ...options.nodeTransforms || []
  22769. // user transforms
  22770. ],
  22771. directiveTransforms: extend(
  22772. {},
  22773. directiveTransforms,
  22774. options.directiveTransforms || {}
  22775. // user transforms
  22776. )
  22777. })
  22778. );
  22779. return generate(
  22780. ast,
  22781. extend({}, options, {
  22782. prefixIdentifiers
  22783. })
  22784. );
  22785. }
  22786. const noopDirectiveTransform = () => ({ props: [] });
  22787. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  22788. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  22789. const V_MODEL_TEXT = Symbol(`vModelText` );
  22790. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  22791. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  22792. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  22793. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  22794. const V_SHOW = Symbol(`vShow` );
  22795. const TRANSITION = Symbol(`Transition` );
  22796. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  22797. registerRuntimeHelpers({
  22798. [V_MODEL_RADIO]: `vModelRadio`,
  22799. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  22800. [V_MODEL_TEXT]: `vModelText`,
  22801. [V_MODEL_SELECT]: `vModelSelect`,
  22802. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  22803. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  22804. [V_ON_WITH_KEYS]: `withKeys`,
  22805. [V_SHOW]: `vShow`,
  22806. [TRANSITION]: `Transition`,
  22807. [TRANSITION_GROUP]: `TransitionGroup`
  22808. });
  22809. var namedCharacterReferences = {
  22810. GT: ">",
  22811. gt: ">",
  22812. LT: "<",
  22813. lt: "<",
  22814. "ac;": "∾",
  22815. "af;": "⁡",
  22816. AMP: "&",
  22817. amp: "&",
  22818. "ap;": "≈",
  22819. "DD;": "ⅅ",
  22820. "dd;": "ⅆ",
  22821. deg: "°",
  22822. "ee;": "ⅇ",
  22823. "eg;": "⪚",
  22824. "el;": "⪙",
  22825. ETH: "Ð",
  22826. eth: "ð",
  22827. "gE;": "≧",
  22828. "ge;": "≥",
  22829. "Gg;": "⋙",
  22830. "gg;": "≫",
  22831. "gl;": "≷",
  22832. "GT;": ">",
  22833. "Gt;": "≫",
  22834. "gt;": ">",
  22835. "ic;": "⁣",
  22836. "ii;": "ⅈ",
  22837. "Im;": "ℑ",
  22838. "in;": "∈",
  22839. "it;": "⁢",
  22840. "lE;": "≦",
  22841. "le;": "≤",
  22842. "lg;": "≶",
  22843. "Ll;": "⋘",
  22844. "ll;": "≪",
  22845. "LT;": "<",
  22846. "Lt;": "≪",
  22847. "lt;": "<",
  22848. "mp;": "∓",
  22849. "Mu;": "Μ",
  22850. "mu;": "μ",
  22851. "ne;": "≠",
  22852. "ni;": "∋",
  22853. not: "¬",
  22854. "Nu;": "Ν",
  22855. "nu;": "ν",
  22856. "Or;": "⩔",
  22857. "or;": "∨",
  22858. "oS;": "Ⓢ",
  22859. "Pi;": "Π",
  22860. "pi;": "π",
  22861. "pm;": "±",
  22862. "Pr;": "⪻",
  22863. "pr;": "≺",
  22864. "Re;": "ℜ",
  22865. REG: "®",
  22866. reg: "®",
  22867. "rx;": "℞",
  22868. "Sc;": "⪼",
  22869. "sc;": "≻",
  22870. shy: "­",
  22871. uml: "¨",
  22872. "wp;": "℘",
  22873. "wr;": "≀",
  22874. "Xi;": "Ξ",
  22875. "xi;": "ξ",
  22876. yen: "¥",
  22877. "acd;": "∿",
  22878. "acE;": "∾̳",
  22879. "Acy;": "А",
  22880. "acy;": "а",
  22881. "Afr;": "𝔄",
  22882. "afr;": "𝔞",
  22883. "AMP;": "&",
  22884. "amp;": "&",
  22885. "And;": "⩓",
  22886. "and;": "∧",
  22887. "ang;": "∠",
  22888. "apE;": "⩰",
  22889. "ape;": "≊",
  22890. "ast;": "*",
  22891. Auml: "Ä",
  22892. auml: "ä",
  22893. "Bcy;": "Б",
  22894. "bcy;": "б",
  22895. "Bfr;": "𝔅",
  22896. "bfr;": "𝔟",
  22897. "bne;": "=⃥",
  22898. "bot;": "⊥",
  22899. "Cap;": "⋒",
  22900. "cap;": "∩",
  22901. cent: "¢",
  22902. "Cfr;": "ℭ",
  22903. "cfr;": "𝔠",
  22904. "Chi;": "Χ",
  22905. "chi;": "χ",
  22906. "cir;": "○",
  22907. COPY: "©",
  22908. copy: "©",
  22909. "Cup;": "⋓",
  22910. "cup;": "∪",
  22911. "Dcy;": "Д",
  22912. "dcy;": "д",
  22913. "deg;": "°",
  22914. "Del;": "∇",
  22915. "Dfr;": "𝔇",
  22916. "dfr;": "𝔡",
  22917. "die;": "¨",
  22918. "div;": "÷",
  22919. "Dot;": "¨",
  22920. "dot;": "˙",
  22921. "Ecy;": "Э",
  22922. "ecy;": "э",
  22923. "Efr;": "𝔈",
  22924. "efr;": "𝔢",
  22925. "egs;": "⪖",
  22926. "ell;": "ℓ",
  22927. "els;": "⪕",
  22928. "ENG;": "Ŋ",
  22929. "eng;": "ŋ",
  22930. "Eta;": "Η",
  22931. "eta;": "η",
  22932. "ETH;": "Ð",
  22933. "eth;": "ð",
  22934. Euml: "Ë",
  22935. euml: "ë",
  22936. "Fcy;": "Ф",
  22937. "fcy;": "ф",
  22938. "Ffr;": "𝔉",
  22939. "ffr;": "𝔣",
  22940. "gap;": "⪆",
  22941. "Gcy;": "Г",
  22942. "gcy;": "г",
  22943. "gEl;": "⪌",
  22944. "gel;": "⋛",
  22945. "geq;": "≥",
  22946. "ges;": "⩾",
  22947. "Gfr;": "𝔊",
  22948. "gfr;": "𝔤",
  22949. "ggg;": "⋙",
  22950. "gla;": "⪥",
  22951. "glE;": "⪒",
  22952. "glj;": "⪤",
  22953. "gnE;": "≩",
  22954. "gne;": "⪈",
  22955. "Hat;": "^",
  22956. "Hfr;": "ℌ",
  22957. "hfr;": "𝔥",
  22958. "Icy;": "И",
  22959. "icy;": "и",
  22960. "iff;": "⇔",
  22961. "Ifr;": "ℑ",
  22962. "ifr;": "𝔦",
  22963. "Int;": "∬",
  22964. "int;": "∫",
  22965. Iuml: "Ï",
  22966. iuml: "ï",
  22967. "Jcy;": "Й",
  22968. "jcy;": "й",
  22969. "Jfr;": "𝔍",
  22970. "jfr;": "𝔧",
  22971. "Kcy;": "К",
  22972. "kcy;": "к",
  22973. "Kfr;": "𝔎",
  22974. "kfr;": "𝔨",
  22975. "lap;": "⪅",
  22976. "lat;": "⪫",
  22977. "Lcy;": "Л",
  22978. "lcy;": "л",
  22979. "lEg;": "⪋",
  22980. "leg;": "⋚",
  22981. "leq;": "≤",
  22982. "les;": "⩽",
  22983. "Lfr;": "𝔏",
  22984. "lfr;": "𝔩",
  22985. "lgE;": "⪑",
  22986. "lnE;": "≨",
  22987. "lne;": "⪇",
  22988. "loz;": "◊",
  22989. "lrm;": "‎",
  22990. "Lsh;": "↰",
  22991. "lsh;": "↰",
  22992. macr: "¯",
  22993. "Map;": "⤅",
  22994. "map;": "↦",
  22995. "Mcy;": "М",
  22996. "mcy;": "м",
  22997. "Mfr;": "𝔐",
  22998. "mfr;": "𝔪",
  22999. "mho;": "℧",
  23000. "mid;": "∣",
  23001. "nap;": "≉",
  23002. nbsp: " ",
  23003. "Ncy;": "Н",
  23004. "ncy;": "н",
  23005. "Nfr;": "𝔑",
  23006. "nfr;": "𝔫",
  23007. "ngE;": "≧̸",
  23008. "nge;": "≱",
  23009. "nGg;": "⋙̸",
  23010. "nGt;": "≫⃒",
  23011. "ngt;": "≯",
  23012. "nis;": "⋼",
  23013. "niv;": "∋",
  23014. "nlE;": "≦̸",
  23015. "nle;": "≰",
  23016. "nLl;": "⋘̸",
  23017. "nLt;": "≪⃒",
  23018. "nlt;": "≮",
  23019. "Not;": "⫬",
  23020. "not;": "¬",
  23021. "npr;": "⊀",
  23022. "nsc;": "⊁",
  23023. "num;": "#",
  23024. "Ocy;": "О",
  23025. "ocy;": "о",
  23026. "Ofr;": "𝔒",
  23027. "ofr;": "𝔬",
  23028. "ogt;": "⧁",
  23029. "ohm;": "Ω",
  23030. "olt;": "⧀",
  23031. "ord;": "⩝",
  23032. ordf: "ª",
  23033. ordm: "º",
  23034. "orv;": "⩛",
  23035. Ouml: "Ö",
  23036. ouml: "ö",
  23037. "par;": "∥",
  23038. para: "¶",
  23039. "Pcy;": "П",
  23040. "pcy;": "п",
  23041. "Pfr;": "𝔓",
  23042. "pfr;": "𝔭",
  23043. "Phi;": "Φ",
  23044. "phi;": "φ",
  23045. "piv;": "ϖ",
  23046. "prE;": "⪳",
  23047. "pre;": "⪯",
  23048. "Psi;": "Ψ",
  23049. "psi;": "ψ",
  23050. "Qfr;": "𝔔",
  23051. "qfr;": "𝔮",
  23052. QUOT: "\"",
  23053. quot: "\"",
  23054. "Rcy;": "Р",
  23055. "rcy;": "р",
  23056. "REG;": "®",
  23057. "reg;": "®",
  23058. "Rfr;": "ℜ",
  23059. "rfr;": "𝔯",
  23060. "Rho;": "Ρ",
  23061. "rho;": "ρ",
  23062. "rlm;": "‏",
  23063. "Rsh;": "↱",
  23064. "rsh;": "↱",
  23065. "scE;": "⪴",
  23066. "sce;": "⪰",
  23067. "Scy;": "С",
  23068. "scy;": "с",
  23069. sect: "§",
  23070. "Sfr;": "𝔖",
  23071. "sfr;": "𝔰",
  23072. "shy;": "­",
  23073. "sim;": "∼",
  23074. "smt;": "⪪",
  23075. "sol;": "/",
  23076. "squ;": "□",
  23077. "Sub;": "⋐",
  23078. "sub;": "⊂",
  23079. "Sum;": "∑",
  23080. "sum;": "∑",
  23081. "Sup;": "⋑",
  23082. "sup;": "⊃",
  23083. sup1: "¹",
  23084. sup2: "²",
  23085. sup3: "³",
  23086. "Tab;": "\t",
  23087. "Tau;": "Τ",
  23088. "tau;": "τ",
  23089. "Tcy;": "Т",
  23090. "tcy;": "т",
  23091. "Tfr;": "𝔗",
  23092. "tfr;": "𝔱",
  23093. "top;": "⊤",
  23094. "Ucy;": "У",
  23095. "ucy;": "у",
  23096. "Ufr;": "𝔘",
  23097. "ufr;": "𝔲",
  23098. "uml;": "¨",
  23099. Uuml: "Ü",
  23100. uuml: "ü",
  23101. "Vcy;": "В",
  23102. "vcy;": "в",
  23103. "Vee;": "⋁",
  23104. "vee;": "∨",
  23105. "Vfr;": "𝔙",
  23106. "vfr;": "𝔳",
  23107. "Wfr;": "𝔚",
  23108. "wfr;": "𝔴",
  23109. "Xfr;": "𝔛",
  23110. "xfr;": "𝔵",
  23111. "Ycy;": "Ы",
  23112. "ycy;": "ы",
  23113. "yen;": "¥",
  23114. "Yfr;": "𝔜",
  23115. "yfr;": "𝔶",
  23116. yuml: "ÿ",
  23117. "Zcy;": "З",
  23118. "zcy;": "з",
  23119. "Zfr;": "ℨ",
  23120. "zfr;": "𝔷",
  23121. "zwj;": "‍",
  23122. Acirc: "Â",
  23123. acirc: "â",
  23124. acute: "´",
  23125. AElig: "Æ",
  23126. aelig: "æ",
  23127. "andd;": "⩜",
  23128. "andv;": "⩚",
  23129. "ange;": "⦤",
  23130. "Aopf;": "𝔸",
  23131. "aopf;": "𝕒",
  23132. "apid;": "≋",
  23133. "apos;": "'",
  23134. Aring: "Å",
  23135. aring: "å",
  23136. "Ascr;": "𝒜",
  23137. "ascr;": "𝒶",
  23138. "Auml;": "Ä",
  23139. "auml;": "ä",
  23140. "Barv;": "⫧",
  23141. "bbrk;": "⎵",
  23142. "Beta;": "Β",
  23143. "beta;": "β",
  23144. "beth;": "ℶ",
  23145. "bNot;": "⫭",
  23146. "bnot;": "⌐",
  23147. "Bopf;": "𝔹",
  23148. "bopf;": "𝕓",
  23149. "boxH;": "═",
  23150. "boxh;": "─",
  23151. "boxV;": "║",
  23152. "boxv;": "│",
  23153. "Bscr;": "ℬ",
  23154. "bscr;": "𝒷",
  23155. "bsim;": "∽",
  23156. "bsol;": "\\",
  23157. "bull;": "•",
  23158. "bump;": "≎",
  23159. "caps;": "∩︀",
  23160. "Cdot;": "Ċ",
  23161. "cdot;": "ċ",
  23162. cedil: "¸",
  23163. "cent;": "¢",
  23164. "CHcy;": "Ч",
  23165. "chcy;": "ч",
  23166. "circ;": "ˆ",
  23167. "cirE;": "⧃",
  23168. "cire;": "≗",
  23169. "comp;": "∁",
  23170. "cong;": "≅",
  23171. "Copf;": "ℂ",
  23172. "copf;": "𝕔",
  23173. "COPY;": "©",
  23174. "copy;": "©",
  23175. "Cscr;": "𝒞",
  23176. "cscr;": "𝒸",
  23177. "csub;": "⫏",
  23178. "csup;": "⫐",
  23179. "cups;": "∪︀",
  23180. "Darr;": "↡",
  23181. "dArr;": "⇓",
  23182. "darr;": "↓",
  23183. "dash;": "‐",
  23184. "dHar;": "⥥",
  23185. "diam;": "⋄",
  23186. "DJcy;": "Ђ",
  23187. "djcy;": "ђ",
  23188. "Dopf;": "𝔻",
  23189. "dopf;": "𝕕",
  23190. "Dscr;": "𝒟",
  23191. "dscr;": "𝒹",
  23192. "DScy;": "Ѕ",
  23193. "dscy;": "ѕ",
  23194. "dsol;": "⧶",
  23195. "dtri;": "▿",
  23196. "DZcy;": "Џ",
  23197. "dzcy;": "џ",
  23198. "ecir;": "≖",
  23199. Ecirc: "Ê",
  23200. ecirc: "ê",
  23201. "Edot;": "Ė",
  23202. "eDot;": "≑",
  23203. "edot;": "ė",
  23204. "emsp;": " ",
  23205. "ensp;": " ",
  23206. "Eopf;": "𝔼",
  23207. "eopf;": "𝕖",
  23208. "epar;": "⋕",
  23209. "epsi;": "ε",
  23210. "Escr;": "ℰ",
  23211. "escr;": "ℯ",
  23212. "Esim;": "⩳",
  23213. "esim;": "≂",
  23214. "Euml;": "Ë",
  23215. "euml;": "ë",
  23216. "euro;": "€",
  23217. "excl;": "!",
  23218. "flat;": "♭",
  23219. "fnof;": "ƒ",
  23220. "Fopf;": "𝔽",
  23221. "fopf;": "𝕗",
  23222. "fork;": "⋔",
  23223. "Fscr;": "ℱ",
  23224. "fscr;": "𝒻",
  23225. "Gdot;": "Ġ",
  23226. "gdot;": "ġ",
  23227. "geqq;": "≧",
  23228. "gesl;": "⋛︀",
  23229. "GJcy;": "Ѓ",
  23230. "gjcy;": "ѓ",
  23231. "gnap;": "⪊",
  23232. "gneq;": "⪈",
  23233. "Gopf;": "𝔾",
  23234. "gopf;": "𝕘",
  23235. "Gscr;": "𝒢",
  23236. "gscr;": "ℊ",
  23237. "gsim;": "≳",
  23238. "gtcc;": "⪧",
  23239. "gvnE;": "≩︀",
  23240. "half;": "½",
  23241. "hArr;": "⇔",
  23242. "harr;": "↔",
  23243. "hbar;": "ℏ",
  23244. "Hopf;": "ℍ",
  23245. "hopf;": "𝕙",
  23246. "Hscr;": "ℋ",
  23247. "hscr;": "𝒽",
  23248. Icirc: "Î",
  23249. icirc: "î",
  23250. "Idot;": "İ",
  23251. "IEcy;": "Е",
  23252. "iecy;": "е",
  23253. iexcl: "¡",
  23254. "imof;": "⊷",
  23255. "IOcy;": "Ё",
  23256. "iocy;": "ё",
  23257. "Iopf;": "𝕀",
  23258. "iopf;": "𝕚",
  23259. "Iota;": "Ι",
  23260. "iota;": "ι",
  23261. "Iscr;": "ℐ",
  23262. "iscr;": "𝒾",
  23263. "isin;": "∈",
  23264. "Iuml;": "Ï",
  23265. "iuml;": "ï",
  23266. "Jopf;": "𝕁",
  23267. "jopf;": "𝕛",
  23268. "Jscr;": "𝒥",
  23269. "jscr;": "𝒿",
  23270. "KHcy;": "Х",
  23271. "khcy;": "х",
  23272. "KJcy;": "Ќ",
  23273. "kjcy;": "ќ",
  23274. "Kopf;": "𝕂",
  23275. "kopf;": "𝕜",
  23276. "Kscr;": "𝒦",
  23277. "kscr;": "𝓀",
  23278. "Lang;": "⟪",
  23279. "lang;": "⟨",
  23280. laquo: "«",
  23281. "Larr;": "↞",
  23282. "lArr;": "⇐",
  23283. "larr;": "←",
  23284. "late;": "⪭",
  23285. "lcub;": "{",
  23286. "ldca;": "⤶",
  23287. "ldsh;": "↲",
  23288. "leqq;": "≦",
  23289. "lesg;": "⋚︀",
  23290. "lHar;": "⥢",
  23291. "LJcy;": "Љ",
  23292. "ljcy;": "љ",
  23293. "lnap;": "⪉",
  23294. "lneq;": "⪇",
  23295. "Lopf;": "𝕃",
  23296. "lopf;": "𝕝",
  23297. "lozf;": "⧫",
  23298. "lpar;": "(",
  23299. "Lscr;": "ℒ",
  23300. "lscr;": "𝓁",
  23301. "lsim;": "≲",
  23302. "lsqb;": "[",
  23303. "ltcc;": "⪦",
  23304. "ltri;": "◃",
  23305. "lvnE;": "≨︀",
  23306. "macr;": "¯",
  23307. "male;": "♂",
  23308. "malt;": "✠",
  23309. micro: "µ",
  23310. "mlcp;": "⫛",
  23311. "mldr;": "…",
  23312. "Mopf;": "𝕄",
  23313. "mopf;": "𝕞",
  23314. "Mscr;": "ℳ",
  23315. "mscr;": "𝓂",
  23316. "nang;": "∠⃒",
  23317. "napE;": "⩰̸",
  23318. "nbsp;": " ",
  23319. "ncap;": "⩃",
  23320. "ncup;": "⩂",
  23321. "ngeq;": "≱",
  23322. "nges;": "⩾̸",
  23323. "ngtr;": "≯",
  23324. "nGtv;": "≫̸",
  23325. "nisd;": "⋺",
  23326. "NJcy;": "Њ",
  23327. "njcy;": "њ",
  23328. "nldr;": "‥",
  23329. "nleq;": "≰",
  23330. "nles;": "⩽̸",
  23331. "nLtv;": "≪̸",
  23332. "nmid;": "∤",
  23333. "Nopf;": "ℕ",
  23334. "nopf;": "𝕟",
  23335. "npar;": "∦",
  23336. "npre;": "⪯̸",
  23337. "nsce;": "⪰̸",
  23338. "Nscr;": "𝒩",
  23339. "nscr;": "𝓃",
  23340. "nsim;": "≁",
  23341. "nsub;": "⊄",
  23342. "nsup;": "⊅",
  23343. "ntgl;": "≹",
  23344. "ntlg;": "≸",
  23345. "nvap;": "≍⃒",
  23346. "nvge;": "≥⃒",
  23347. "nvgt;": ">⃒",
  23348. "nvle;": "≤⃒",
  23349. "nvlt;": "<⃒",
  23350. "oast;": "⊛",
  23351. "ocir;": "⊚",
  23352. Ocirc: "Ô",
  23353. ocirc: "ô",
  23354. "odiv;": "⨸",
  23355. "odot;": "⊙",
  23356. "ogon;": "˛",
  23357. "oint;": "∮",
  23358. "omid;": "⦶",
  23359. "Oopf;": "𝕆",
  23360. "oopf;": "𝕠",
  23361. "opar;": "⦷",
  23362. "ordf;": "ª",
  23363. "ordm;": "º",
  23364. "oror;": "⩖",
  23365. "Oscr;": "𝒪",
  23366. "oscr;": "ℴ",
  23367. "osol;": "⊘",
  23368. "Ouml;": "Ö",
  23369. "ouml;": "ö",
  23370. "para;": "¶",
  23371. "part;": "∂",
  23372. "perp;": "⊥",
  23373. "phiv;": "ϕ",
  23374. "plus;": "+",
  23375. "Popf;": "ℙ",
  23376. "popf;": "𝕡",
  23377. pound: "£",
  23378. "prap;": "⪷",
  23379. "prec;": "≺",
  23380. "prnE;": "⪵",
  23381. "prod;": "∏",
  23382. "prop;": "∝",
  23383. "Pscr;": "𝒫",
  23384. "pscr;": "𝓅",
  23385. "qint;": "⨌",
  23386. "Qopf;": "ℚ",
  23387. "qopf;": "𝕢",
  23388. "Qscr;": "𝒬",
  23389. "qscr;": "𝓆",
  23390. "QUOT;": "\"",
  23391. "quot;": "\"",
  23392. "race;": "∽̱",
  23393. "Rang;": "⟫",
  23394. "rang;": "⟩",
  23395. raquo: "»",
  23396. "Rarr;": "↠",
  23397. "rArr;": "⇒",
  23398. "rarr;": "→",
  23399. "rcub;": "}",
  23400. "rdca;": "⤷",
  23401. "rdsh;": "↳",
  23402. "real;": "ℜ",
  23403. "rect;": "▭",
  23404. "rHar;": "⥤",
  23405. "rhov;": "ϱ",
  23406. "ring;": "˚",
  23407. "Ropf;": "ℝ",
  23408. "ropf;": "𝕣",
  23409. "rpar;": ")",
  23410. "Rscr;": "ℛ",
  23411. "rscr;": "𝓇",
  23412. "rsqb;": "]",
  23413. "rtri;": "▹",
  23414. "scap;": "⪸",
  23415. "scnE;": "⪶",
  23416. "sdot;": "⋅",
  23417. "sect;": "§",
  23418. "semi;": ";",
  23419. "sext;": "✶",
  23420. "SHcy;": "Ш",
  23421. "shcy;": "ш",
  23422. "sime;": "≃",
  23423. "simg;": "⪞",
  23424. "siml;": "⪝",
  23425. "smid;": "∣",
  23426. "smte;": "⪬",
  23427. "solb;": "⧄",
  23428. "Sopf;": "𝕊",
  23429. "sopf;": "𝕤",
  23430. "spar;": "∥",
  23431. "Sqrt;": "√",
  23432. "squf;": "▪",
  23433. "Sscr;": "𝒮",
  23434. "sscr;": "𝓈",
  23435. "Star;": "⋆",
  23436. "star;": "☆",
  23437. "subE;": "⫅",
  23438. "sube;": "⊆",
  23439. "succ;": "≻",
  23440. "sung;": "♪",
  23441. "sup1;": "¹",
  23442. "sup2;": "²",
  23443. "sup3;": "³",
  23444. "supE;": "⫆",
  23445. "supe;": "⊇",
  23446. szlig: "ß",
  23447. "tbrk;": "⎴",
  23448. "tdot;": "⃛",
  23449. THORN: "Þ",
  23450. thorn: "þ",
  23451. times: "×",
  23452. "tint;": "∭",
  23453. "toea;": "⤨",
  23454. "Topf;": "𝕋",
  23455. "topf;": "𝕥",
  23456. "tosa;": "⤩",
  23457. "trie;": "≜",
  23458. "Tscr;": "𝒯",
  23459. "tscr;": "𝓉",
  23460. "TScy;": "Ц",
  23461. "tscy;": "ц",
  23462. "Uarr;": "↟",
  23463. "uArr;": "⇑",
  23464. "uarr;": "↑",
  23465. Ucirc: "Û",
  23466. ucirc: "û",
  23467. "uHar;": "⥣",
  23468. "Uopf;": "𝕌",
  23469. "uopf;": "𝕦",
  23470. "Upsi;": "ϒ",
  23471. "upsi;": "υ",
  23472. "Uscr;": "𝒰",
  23473. "uscr;": "𝓊",
  23474. "utri;": "▵",
  23475. "Uuml;": "Ü",
  23476. "uuml;": "ü",
  23477. "vArr;": "⇕",
  23478. "varr;": "↕",
  23479. "Vbar;": "⫫",
  23480. "vBar;": "⫨",
  23481. "Vert;": "‖",
  23482. "vert;": "|",
  23483. "Vopf;": "𝕍",
  23484. "vopf;": "𝕧",
  23485. "Vscr;": "𝒱",
  23486. "vscr;": "𝓋",
  23487. "Wopf;": "𝕎",
  23488. "wopf;": "𝕨",
  23489. "Wscr;": "𝒲",
  23490. "wscr;": "𝓌",
  23491. "xcap;": "⋂",
  23492. "xcup;": "⋃",
  23493. "xmap;": "⟼",
  23494. "xnis;": "⋻",
  23495. "Xopf;": "𝕏",
  23496. "xopf;": "𝕩",
  23497. "Xscr;": "𝒳",
  23498. "xscr;": "𝓍",
  23499. "xvee;": "⋁",
  23500. "YAcy;": "Я",
  23501. "yacy;": "я",
  23502. "YIcy;": "Ї",
  23503. "yicy;": "ї",
  23504. "Yopf;": "𝕐",
  23505. "yopf;": "𝕪",
  23506. "Yscr;": "𝒴",
  23507. "yscr;": "𝓎",
  23508. "YUcy;": "Ю",
  23509. "yucy;": "ю",
  23510. "Yuml;": "Ÿ",
  23511. "yuml;": "ÿ",
  23512. "Zdot;": "Ż",
  23513. "zdot;": "ż",
  23514. "Zeta;": "Ζ",
  23515. "zeta;": "ζ",
  23516. "ZHcy;": "Ж",
  23517. "zhcy;": "ж",
  23518. "Zopf;": "ℤ",
  23519. "zopf;": "𝕫",
  23520. "Zscr;": "𝒵",
  23521. "zscr;": "𝓏",
  23522. "zwnj;": "‌",
  23523. Aacute: "Á",
  23524. aacute: "á",
  23525. "Acirc;": "Â",
  23526. "acirc;": "â",
  23527. "acute;": "´",
  23528. "AElig;": "Æ",
  23529. "aelig;": "æ",
  23530. Agrave: "À",
  23531. agrave: "à",
  23532. "aleph;": "ℵ",
  23533. "Alpha;": "Α",
  23534. "alpha;": "α",
  23535. "Amacr;": "Ā",
  23536. "amacr;": "ā",
  23537. "amalg;": "⨿",
  23538. "angle;": "∠",
  23539. "angrt;": "∟",
  23540. "angst;": "Å",
  23541. "Aogon;": "Ą",
  23542. "aogon;": "ą",
  23543. "Aring;": "Å",
  23544. "aring;": "å",
  23545. "asymp;": "≈",
  23546. Atilde: "Ã",
  23547. atilde: "ã",
  23548. "awint;": "⨑",
  23549. "bcong;": "≌",
  23550. "bdquo;": "„",
  23551. "bepsi;": "϶",
  23552. "blank;": "␣",
  23553. "blk12;": "▒",
  23554. "blk14;": "░",
  23555. "blk34;": "▓",
  23556. "block;": "█",
  23557. "boxDL;": "╗",
  23558. "boxDl;": "╖",
  23559. "boxdL;": "╕",
  23560. "boxdl;": "┐",
  23561. "boxDR;": "╔",
  23562. "boxDr;": "╓",
  23563. "boxdR;": "╒",
  23564. "boxdr;": "┌",
  23565. "boxHD;": "╦",
  23566. "boxHd;": "╤",
  23567. "boxhD;": "╥",
  23568. "boxhd;": "┬",
  23569. "boxHU;": "╩",
  23570. "boxHu;": "╧",
  23571. "boxhU;": "╨",
  23572. "boxhu;": "┴",
  23573. "boxUL;": "╝",
  23574. "boxUl;": "╜",
  23575. "boxuL;": "╛",
  23576. "boxul;": "┘",
  23577. "boxUR;": "╚",
  23578. "boxUr;": "╙",
  23579. "boxuR;": "╘",
  23580. "boxur;": "└",
  23581. "boxVH;": "╬",
  23582. "boxVh;": "╫",
  23583. "boxvH;": "╪",
  23584. "boxvh;": "┼",
  23585. "boxVL;": "╣",
  23586. "boxVl;": "╢",
  23587. "boxvL;": "╡",
  23588. "boxvl;": "┤",
  23589. "boxVR;": "╠",
  23590. "boxVr;": "╟",
  23591. "boxvR;": "╞",
  23592. "boxvr;": "├",
  23593. "Breve;": "˘",
  23594. "breve;": "˘",
  23595. brvbar: "¦",
  23596. "bsemi;": "⁏",
  23597. "bsime;": "⋍",
  23598. "bsolb;": "⧅",
  23599. "bumpE;": "⪮",
  23600. "bumpe;": "≏",
  23601. "caret;": "⁁",
  23602. "caron;": "ˇ",
  23603. "ccaps;": "⩍",
  23604. Ccedil: "Ç",
  23605. ccedil: "ç",
  23606. "Ccirc;": "Ĉ",
  23607. "ccirc;": "ĉ",
  23608. "ccups;": "⩌",
  23609. "cedil;": "¸",
  23610. "check;": "✓",
  23611. "clubs;": "♣",
  23612. "Colon;": "∷",
  23613. "colon;": ":",
  23614. "comma;": ",",
  23615. "crarr;": "↵",
  23616. "Cross;": "⨯",
  23617. "cross;": "✗",
  23618. "csube;": "⫑",
  23619. "csupe;": "⫒",
  23620. "ctdot;": "⋯",
  23621. "cuepr;": "⋞",
  23622. "cuesc;": "⋟",
  23623. "cupor;": "⩅",
  23624. curren: "¤",
  23625. "cuvee;": "⋎",
  23626. "cuwed;": "⋏",
  23627. "cwint;": "∱",
  23628. "Dashv;": "⫤",
  23629. "dashv;": "⊣",
  23630. "dblac;": "˝",
  23631. "ddarr;": "⇊",
  23632. "Delta;": "Δ",
  23633. "delta;": "δ",
  23634. "dharl;": "⇃",
  23635. "dharr;": "⇂",
  23636. "diams;": "♦",
  23637. "disin;": "⋲",
  23638. divide: "÷",
  23639. "doteq;": "≐",
  23640. "dtdot;": "⋱",
  23641. "dtrif;": "▾",
  23642. "duarr;": "⇵",
  23643. "duhar;": "⥯",
  23644. Eacute: "É",
  23645. eacute: "é",
  23646. "Ecirc;": "Ê",
  23647. "ecirc;": "ê",
  23648. "eDDot;": "⩷",
  23649. "efDot;": "≒",
  23650. Egrave: "È",
  23651. egrave: "è",
  23652. "Emacr;": "Ē",
  23653. "emacr;": "ē",
  23654. "empty;": "∅",
  23655. "Eogon;": "Ę",
  23656. "eogon;": "ę",
  23657. "eplus;": "⩱",
  23658. "epsiv;": "ϵ",
  23659. "eqsim;": "≂",
  23660. "Equal;": "⩵",
  23661. "equiv;": "≡",
  23662. "erarr;": "⥱",
  23663. "erDot;": "≓",
  23664. "esdot;": "≐",
  23665. "exist;": "∃",
  23666. "fflig;": "ff",
  23667. "filig;": "fi",
  23668. "fjlig;": "fj",
  23669. "fllig;": "fl",
  23670. "fltns;": "▱",
  23671. "forkv;": "⫙",
  23672. frac12: "½",
  23673. frac14: "¼",
  23674. frac34: "¾",
  23675. "frasl;": "⁄",
  23676. "frown;": "⌢",
  23677. "Gamma;": "Γ",
  23678. "gamma;": "γ",
  23679. "Gcirc;": "Ĝ",
  23680. "gcirc;": "ĝ",
  23681. "gescc;": "⪩",
  23682. "gimel;": "ℷ",
  23683. "gneqq;": "≩",
  23684. "gnsim;": "⋧",
  23685. "grave;": "`",
  23686. "gsime;": "⪎",
  23687. "gsiml;": "⪐",
  23688. "gtcir;": "⩺",
  23689. "gtdot;": "⋗",
  23690. "Hacek;": "ˇ",
  23691. "harrw;": "↭",
  23692. "Hcirc;": "Ĥ",
  23693. "hcirc;": "ĥ",
  23694. "hoarr;": "⇿",
  23695. Iacute: "Í",
  23696. iacute: "í",
  23697. "Icirc;": "Î",
  23698. "icirc;": "î",
  23699. "iexcl;": "¡",
  23700. Igrave: "Ì",
  23701. igrave: "ì",
  23702. "iiint;": "∭",
  23703. "iiota;": "℩",
  23704. "IJlig;": "IJ",
  23705. "ijlig;": "ij",
  23706. "Imacr;": "Ī",
  23707. "imacr;": "ī",
  23708. "image;": "ℑ",
  23709. "imath;": "ı",
  23710. "imped;": "Ƶ",
  23711. "infin;": "∞",
  23712. "Iogon;": "Į",
  23713. "iogon;": "į",
  23714. "iprod;": "⨼",
  23715. iquest: "¿",
  23716. "isinE;": "⋹",
  23717. "isins;": "⋴",
  23718. "isinv;": "∈",
  23719. "Iukcy;": "І",
  23720. "iukcy;": "і",
  23721. "Jcirc;": "Ĵ",
  23722. "jcirc;": "ĵ",
  23723. "jmath;": "ȷ",
  23724. "Jukcy;": "Є",
  23725. "jukcy;": "є",
  23726. "Kappa;": "Κ",
  23727. "kappa;": "κ",
  23728. "lAarr;": "⇚",
  23729. "langd;": "⦑",
  23730. "laquo;": "«",
  23731. "larrb;": "⇤",
  23732. "lates;": "⪭︀",
  23733. "lBarr;": "⤎",
  23734. "lbarr;": "⤌",
  23735. "lbbrk;": "❲",
  23736. "lbrke;": "⦋",
  23737. "lceil;": "⌈",
  23738. "ldquo;": "“",
  23739. "lescc;": "⪨",
  23740. "lhard;": "↽",
  23741. "lharu;": "↼",
  23742. "lhblk;": "▄",
  23743. "llarr;": "⇇",
  23744. "lltri;": "◺",
  23745. "lneqq;": "≨",
  23746. "lnsim;": "⋦",
  23747. "loang;": "⟬",
  23748. "loarr;": "⇽",
  23749. "lobrk;": "⟦",
  23750. "lopar;": "⦅",
  23751. "lrarr;": "⇆",
  23752. "lrhar;": "⇋",
  23753. "lrtri;": "⊿",
  23754. "lsime;": "⪍",
  23755. "lsimg;": "⪏",
  23756. "lsquo;": "‘",
  23757. "ltcir;": "⩹",
  23758. "ltdot;": "⋖",
  23759. "ltrie;": "⊴",
  23760. "ltrif;": "◂",
  23761. "mdash;": "—",
  23762. "mDDot;": "∺",
  23763. "micro;": "µ",
  23764. middot: "·",
  23765. "minus;": "−",
  23766. "mumap;": "⊸",
  23767. "nabla;": "∇",
  23768. "napid;": "≋̸",
  23769. "napos;": "ʼn",
  23770. "natur;": "♮",
  23771. "nbump;": "≎̸",
  23772. "ncong;": "≇",
  23773. "ndash;": "–",
  23774. "neArr;": "⇗",
  23775. "nearr;": "↗",
  23776. "nedot;": "≐̸",
  23777. "nesim;": "≂̸",
  23778. "ngeqq;": "≧̸",
  23779. "ngsim;": "≵",
  23780. "nhArr;": "⇎",
  23781. "nharr;": "↮",
  23782. "nhpar;": "⫲",
  23783. "nlArr;": "⇍",
  23784. "nlarr;": "↚",
  23785. "nleqq;": "≦̸",
  23786. "nless;": "≮",
  23787. "nlsim;": "≴",
  23788. "nltri;": "⋪",
  23789. "notin;": "∉",
  23790. "notni;": "∌",
  23791. "npart;": "∂̸",
  23792. "nprec;": "⊀",
  23793. "nrArr;": "⇏",
  23794. "nrarr;": "↛",
  23795. "nrtri;": "⋫",
  23796. "nsime;": "≄",
  23797. "nsmid;": "∤",
  23798. "nspar;": "∦",
  23799. "nsubE;": "⫅̸",
  23800. "nsube;": "⊈",
  23801. "nsucc;": "⊁",
  23802. "nsupE;": "⫆̸",
  23803. "nsupe;": "⊉",
  23804. Ntilde: "Ñ",
  23805. ntilde: "ñ",
  23806. "numsp;": " ",
  23807. "nvsim;": "∼⃒",
  23808. "nwArr;": "⇖",
  23809. "nwarr;": "↖",
  23810. Oacute: "Ó",
  23811. oacute: "ó",
  23812. "Ocirc;": "Ô",
  23813. "ocirc;": "ô",
  23814. "odash;": "⊝",
  23815. "OElig;": "Œ",
  23816. "oelig;": "œ",
  23817. "ofcir;": "⦿",
  23818. Ograve: "Ò",
  23819. ograve: "ò",
  23820. "ohbar;": "⦵",
  23821. "olarr;": "↺",
  23822. "olcir;": "⦾",
  23823. "oline;": "‾",
  23824. "Omacr;": "Ō",
  23825. "omacr;": "ō",
  23826. "Omega;": "Ω",
  23827. "omega;": "ω",
  23828. "operp;": "⦹",
  23829. "oplus;": "⊕",
  23830. "orarr;": "↻",
  23831. "order;": "ℴ",
  23832. Oslash: "Ø",
  23833. oslash: "ø",
  23834. Otilde: "Õ",
  23835. otilde: "õ",
  23836. "ovbar;": "⌽",
  23837. "parsl;": "⫽",
  23838. "phone;": "☎",
  23839. "plusb;": "⊞",
  23840. "pluse;": "⩲",
  23841. plusmn: "±",
  23842. "pound;": "£",
  23843. "prcue;": "≼",
  23844. "Prime;": "″",
  23845. "prime;": "′",
  23846. "prnap;": "⪹",
  23847. "prsim;": "≾",
  23848. "quest;": "?",
  23849. "rAarr;": "⇛",
  23850. "radic;": "√",
  23851. "rangd;": "⦒",
  23852. "range;": "⦥",
  23853. "raquo;": "»",
  23854. "rarrb;": "⇥",
  23855. "rarrc;": "⤳",
  23856. "rarrw;": "↝",
  23857. "ratio;": "∶",
  23858. "RBarr;": "⤐",
  23859. "rBarr;": "⤏",
  23860. "rbarr;": "⤍",
  23861. "rbbrk;": "❳",
  23862. "rbrke;": "⦌",
  23863. "rceil;": "⌉",
  23864. "rdquo;": "”",
  23865. "reals;": "ℝ",
  23866. "rhard;": "⇁",
  23867. "rharu;": "⇀",
  23868. "rlarr;": "⇄",
  23869. "rlhar;": "⇌",
  23870. "rnmid;": "⫮",
  23871. "roang;": "⟭",
  23872. "roarr;": "⇾",
  23873. "robrk;": "⟧",
  23874. "ropar;": "⦆",
  23875. "rrarr;": "⇉",
  23876. "rsquo;": "’",
  23877. "rtrie;": "⊵",
  23878. "rtrif;": "▸",
  23879. "sbquo;": "‚",
  23880. "sccue;": "≽",
  23881. "Scirc;": "Ŝ",
  23882. "scirc;": "ŝ",
  23883. "scnap;": "⪺",
  23884. "scsim;": "≿",
  23885. "sdotb;": "⊡",
  23886. "sdote;": "⩦",
  23887. "seArr;": "⇘",
  23888. "searr;": "↘",
  23889. "setmn;": "∖",
  23890. "sharp;": "♯",
  23891. "Sigma;": "Σ",
  23892. "sigma;": "σ",
  23893. "simeq;": "≃",
  23894. "simgE;": "⪠",
  23895. "simlE;": "⪟",
  23896. "simne;": "≆",
  23897. "slarr;": "←",
  23898. "smile;": "⌣",
  23899. "smtes;": "⪬︀",
  23900. "sqcap;": "⊓",
  23901. "sqcup;": "⊔",
  23902. "sqsub;": "⊏",
  23903. "sqsup;": "⊐",
  23904. "srarr;": "→",
  23905. "starf;": "★",
  23906. "strns;": "¯",
  23907. "subnE;": "⫋",
  23908. "subne;": "⊊",
  23909. "supnE;": "⫌",
  23910. "supne;": "⊋",
  23911. "swArr;": "⇙",
  23912. "swarr;": "↙",
  23913. "szlig;": "ß",
  23914. "Theta;": "Θ",
  23915. "theta;": "θ",
  23916. "thkap;": "≈",
  23917. "THORN;": "Þ",
  23918. "thorn;": "þ",
  23919. "Tilde;": "∼",
  23920. "tilde;": "˜",
  23921. "times;": "×",
  23922. "TRADE;": "™",
  23923. "trade;": "™",
  23924. "trisb;": "⧍",
  23925. "TSHcy;": "Ћ",
  23926. "tshcy;": "ћ",
  23927. "twixt;": "≬",
  23928. Uacute: "Ú",
  23929. uacute: "ú",
  23930. "Ubrcy;": "Ў",
  23931. "ubrcy;": "ў",
  23932. "Ucirc;": "Û",
  23933. "ucirc;": "û",
  23934. "udarr;": "⇅",
  23935. "udhar;": "⥮",
  23936. Ugrave: "Ù",
  23937. ugrave: "ù",
  23938. "uharl;": "↿",
  23939. "uharr;": "↾",
  23940. "uhblk;": "▀",
  23941. "ultri;": "◸",
  23942. "Umacr;": "Ū",
  23943. "umacr;": "ū",
  23944. "Union;": "⋃",
  23945. "Uogon;": "Ų",
  23946. "uogon;": "ų",
  23947. "uplus;": "⊎",
  23948. "upsih;": "ϒ",
  23949. "UpTee;": "⊥",
  23950. "Uring;": "Ů",
  23951. "uring;": "ů",
  23952. "urtri;": "◹",
  23953. "utdot;": "⋰",
  23954. "utrif;": "▴",
  23955. "uuarr;": "⇈",
  23956. "varpi;": "ϖ",
  23957. "vBarv;": "⫩",
  23958. "VDash;": "⊫",
  23959. "Vdash;": "⊩",
  23960. "vDash;": "⊨",
  23961. "vdash;": "⊢",
  23962. "veeeq;": "≚",
  23963. "vltri;": "⊲",
  23964. "vnsub;": "⊂⃒",
  23965. "vnsup;": "⊃⃒",
  23966. "vprop;": "∝",
  23967. "vrtri;": "⊳",
  23968. "Wcirc;": "Ŵ",
  23969. "wcirc;": "ŵ",
  23970. "Wedge;": "⋀",
  23971. "wedge;": "∧",
  23972. "xcirc;": "◯",
  23973. "xdtri;": "▽",
  23974. "xhArr;": "⟺",
  23975. "xharr;": "⟷",
  23976. "xlArr;": "⟸",
  23977. "xlarr;": "⟵",
  23978. "xodot;": "⨀",
  23979. "xrArr;": "⟹",
  23980. "xrarr;": "⟶",
  23981. "xutri;": "△",
  23982. Yacute: "Ý",
  23983. yacute: "ý",
  23984. "Ycirc;": "Ŷ",
  23985. "ycirc;": "ŷ",
  23986. "Aacute;": "Á",
  23987. "aacute;": "á",
  23988. "Abreve;": "Ă",
  23989. "abreve;": "ă",
  23990. "Agrave;": "À",
  23991. "agrave;": "à",
  23992. "andand;": "⩕",
  23993. "angmsd;": "∡",
  23994. "angsph;": "∢",
  23995. "apacir;": "⩯",
  23996. "approx;": "≈",
  23997. "Assign;": "≔",
  23998. "Atilde;": "Ã",
  23999. "atilde;": "ã",
  24000. "barvee;": "⊽",
  24001. "Barwed;": "⌆",
  24002. "barwed;": "⌅",
  24003. "becaus;": "∵",
  24004. "bernou;": "ℬ",
  24005. "bigcap;": "⋂",
  24006. "bigcup;": "⋃",
  24007. "bigvee;": "⋁",
  24008. "bkarow;": "⤍",
  24009. "bottom;": "⊥",
  24010. "bowtie;": "⋈",
  24011. "boxbox;": "⧉",
  24012. "bprime;": "‵",
  24013. "brvbar;": "¦",
  24014. "bullet;": "•",
  24015. "Bumpeq;": "≎",
  24016. "bumpeq;": "≏",
  24017. "Cacute;": "Ć",
  24018. "cacute;": "ć",
  24019. "capand;": "⩄",
  24020. "capcap;": "⩋",
  24021. "capcup;": "⩇",
  24022. "capdot;": "⩀",
  24023. "Ccaron;": "Č",
  24024. "ccaron;": "č",
  24025. "Ccedil;": "Ç",
  24026. "ccedil;": "ç",
  24027. "circeq;": "≗",
  24028. "cirmid;": "⫯",
  24029. "Colone;": "⩴",
  24030. "colone;": "≔",
  24031. "commat;": "@",
  24032. "compfn;": "∘",
  24033. "Conint;": "∯",
  24034. "conint;": "∮",
  24035. "coprod;": "∐",
  24036. "copysr;": "℗",
  24037. "cularr;": "↶",
  24038. "CupCap;": "≍",
  24039. "cupcap;": "⩆",
  24040. "cupcup;": "⩊",
  24041. "cupdot;": "⊍",
  24042. "curarr;": "↷",
  24043. "curren;": "¤",
  24044. "cylcty;": "⌭",
  24045. "Dagger;": "‡",
  24046. "dagger;": "†",
  24047. "daleth;": "ℸ",
  24048. "Dcaron;": "Ď",
  24049. "dcaron;": "ď",
  24050. "dfisht;": "⥿",
  24051. "divide;": "÷",
  24052. "divonx;": "⋇",
  24053. "dlcorn;": "⌞",
  24054. "dlcrop;": "⌍",
  24055. "dollar;": "$",
  24056. "DotDot;": "⃜",
  24057. "drcorn;": "⌟",
  24058. "drcrop;": "⌌",
  24059. "Dstrok;": "Đ",
  24060. "dstrok;": "đ",
  24061. "Eacute;": "É",
  24062. "eacute;": "é",
  24063. "easter;": "⩮",
  24064. "Ecaron;": "Ě",
  24065. "ecaron;": "ě",
  24066. "ecolon;": "≕",
  24067. "Egrave;": "È",
  24068. "egrave;": "è",
  24069. "egsdot;": "⪘",
  24070. "elsdot;": "⪗",
  24071. "emptyv;": "∅",
  24072. "emsp13;": " ",
  24073. "emsp14;": " ",
  24074. "eparsl;": "⧣",
  24075. "eqcirc;": "≖",
  24076. "equals;": "=",
  24077. "equest;": "≟",
  24078. "Exists;": "∃",
  24079. "female;": "♀",
  24080. "ffilig;": "ffi",
  24081. "ffllig;": "ffl",
  24082. "ForAll;": "∀",
  24083. "forall;": "∀",
  24084. "frac12;": "½",
  24085. "frac13;": "⅓",
  24086. "frac14;": "¼",
  24087. "frac15;": "⅕",
  24088. "frac16;": "⅙",
  24089. "frac18;": "⅛",
  24090. "frac23;": "⅔",
  24091. "frac25;": "⅖",
  24092. "frac34;": "¾",
  24093. "frac35;": "⅗",
  24094. "frac38;": "⅜",
  24095. "frac45;": "⅘",
  24096. "frac56;": "⅚",
  24097. "frac58;": "⅝",
  24098. "frac78;": "⅞",
  24099. "gacute;": "ǵ",
  24100. "Gammad;": "Ϝ",
  24101. "gammad;": "ϝ",
  24102. "Gbreve;": "Ğ",
  24103. "gbreve;": "ğ",
  24104. "Gcedil;": "Ģ",
  24105. "gesdot;": "⪀",
  24106. "gesles;": "⪔",
  24107. "gtlPar;": "⦕",
  24108. "gtrarr;": "⥸",
  24109. "gtrdot;": "⋗",
  24110. "gtrsim;": "≳",
  24111. "hairsp;": " ",
  24112. "hamilt;": "ℋ",
  24113. "HARDcy;": "Ъ",
  24114. "hardcy;": "ъ",
  24115. "hearts;": "♥",
  24116. "hellip;": "…",
  24117. "hercon;": "⊹",
  24118. "homtht;": "∻",
  24119. "horbar;": "―",
  24120. "hslash;": "ℏ",
  24121. "Hstrok;": "Ħ",
  24122. "hstrok;": "ħ",
  24123. "hybull;": "⁃",
  24124. "hyphen;": "‐",
  24125. "Iacute;": "Í",
  24126. "iacute;": "í",
  24127. "Igrave;": "Ì",
  24128. "igrave;": "ì",
  24129. "iiiint;": "⨌",
  24130. "iinfin;": "⧜",
  24131. "incare;": "℅",
  24132. "inodot;": "ı",
  24133. "intcal;": "⊺",
  24134. "iquest;": "¿",
  24135. "isinsv;": "⋳",
  24136. "Itilde;": "Ĩ",
  24137. "itilde;": "ĩ",
  24138. "Jsercy;": "Ј",
  24139. "jsercy;": "ј",
  24140. "kappav;": "ϰ",
  24141. "Kcedil;": "Ķ",
  24142. "kcedil;": "ķ",
  24143. "kgreen;": "ĸ",
  24144. "Lacute;": "Ĺ",
  24145. "lacute;": "ĺ",
  24146. "lagran;": "ℒ",
  24147. "Lambda;": "Λ",
  24148. "lambda;": "λ",
  24149. "langle;": "⟨",
  24150. "larrfs;": "⤝",
  24151. "larrhk;": "↩",
  24152. "larrlp;": "↫",
  24153. "larrpl;": "⤹",
  24154. "larrtl;": "↢",
  24155. "lAtail;": "⤛",
  24156. "latail;": "⤙",
  24157. "lbrace;": "{",
  24158. "lbrack;": "[",
  24159. "Lcaron;": "Ľ",
  24160. "lcaron;": "ľ",
  24161. "Lcedil;": "Ļ",
  24162. "lcedil;": "ļ",
  24163. "ldquor;": "„",
  24164. "lesdot;": "⩿",
  24165. "lesges;": "⪓",
  24166. "lfisht;": "⥼",
  24167. "lfloor;": "⌊",
  24168. "lharul;": "⥪",
  24169. "llhard;": "⥫",
  24170. "Lmidot;": "Ŀ",
  24171. "lmidot;": "ŀ",
  24172. "lmoust;": "⎰",
  24173. "loplus;": "⨭",
  24174. "lowast;": "∗",
  24175. "lowbar;": "_",
  24176. "lparlt;": "⦓",
  24177. "lrhard;": "⥭",
  24178. "lsaquo;": "‹",
  24179. "lsquor;": "‚",
  24180. "Lstrok;": "Ł",
  24181. "lstrok;": "ł",
  24182. "lthree;": "⋋",
  24183. "ltimes;": "⋉",
  24184. "ltlarr;": "⥶",
  24185. "ltrPar;": "⦖",
  24186. "mapsto;": "↦",
  24187. "marker;": "▮",
  24188. "mcomma;": "⨩",
  24189. "midast;": "*",
  24190. "midcir;": "⫰",
  24191. "middot;": "·",
  24192. "minusb;": "⊟",
  24193. "minusd;": "∸",
  24194. "mnplus;": "∓",
  24195. "models;": "⊧",
  24196. "mstpos;": "∾",
  24197. "Nacute;": "Ń",
  24198. "nacute;": "ń",
  24199. "nbumpe;": "≏̸",
  24200. "Ncaron;": "Ň",
  24201. "ncaron;": "ň",
  24202. "Ncedil;": "Ņ",
  24203. "ncedil;": "ņ",
  24204. "nearhk;": "⤤",
  24205. "nequiv;": "≢",
  24206. "nesear;": "⤨",
  24207. "nexist;": "∄",
  24208. "nltrie;": "⋬",
  24209. "notinE;": "⋹̸",
  24210. "nparsl;": "⫽⃥",
  24211. "nprcue;": "⋠",
  24212. "nrarrc;": "⤳̸",
  24213. "nrarrw;": "↝̸",
  24214. "nrtrie;": "⋭",
  24215. "nsccue;": "⋡",
  24216. "nsimeq;": "≄",
  24217. "Ntilde;": "Ñ",
  24218. "ntilde;": "ñ",
  24219. "numero;": "№",
  24220. "nVDash;": "⊯",
  24221. "nVdash;": "⊮",
  24222. "nvDash;": "⊭",
  24223. "nvdash;": "⊬",
  24224. "nvHarr;": "⤄",
  24225. "nvlArr;": "⤂",
  24226. "nvrArr;": "⤃",
  24227. "nwarhk;": "⤣",
  24228. "nwnear;": "⤧",
  24229. "Oacute;": "Ó",
  24230. "oacute;": "ó",
  24231. "Odblac;": "Ő",
  24232. "odblac;": "ő",
  24233. "odsold;": "⦼",
  24234. "Ograve;": "Ò",
  24235. "ograve;": "ò",
  24236. "ominus;": "⊖",
  24237. "origof;": "⊶",
  24238. "Oslash;": "Ø",
  24239. "oslash;": "ø",
  24240. "Otilde;": "Õ",
  24241. "otilde;": "õ",
  24242. "Otimes;": "⨷",
  24243. "otimes;": "⊗",
  24244. "parsim;": "⫳",
  24245. "percnt;": "%",
  24246. "period;": ".",
  24247. "permil;": "‰",
  24248. "phmmat;": "ℳ",
  24249. "planck;": "ℏ",
  24250. "plankv;": "ℏ",
  24251. "plusdo;": "∔",
  24252. "plusdu;": "⨥",
  24253. "plusmn;": "±",
  24254. "preceq;": "⪯",
  24255. "primes;": "ℙ",
  24256. "prnsim;": "⋨",
  24257. "propto;": "∝",
  24258. "prurel;": "⊰",
  24259. "puncsp;": " ",
  24260. "qprime;": "⁗",
  24261. "Racute;": "Ŕ",
  24262. "racute;": "ŕ",
  24263. "rangle;": "⟩",
  24264. "rarrap;": "⥵",
  24265. "rarrfs;": "⤞",
  24266. "rarrhk;": "↪",
  24267. "rarrlp;": "↬",
  24268. "rarrpl;": "⥅",
  24269. "Rarrtl;": "⤖",
  24270. "rarrtl;": "↣",
  24271. "rAtail;": "⤜",
  24272. "ratail;": "⤚",
  24273. "rbrace;": "}",
  24274. "rbrack;": "]",
  24275. "Rcaron;": "Ř",
  24276. "rcaron;": "ř",
  24277. "Rcedil;": "Ŗ",
  24278. "rcedil;": "ŗ",
  24279. "rdquor;": "”",
  24280. "rfisht;": "⥽",
  24281. "rfloor;": "⌋",
  24282. "rharul;": "⥬",
  24283. "rmoust;": "⎱",
  24284. "roplus;": "⨮",
  24285. "rpargt;": "⦔",
  24286. "rsaquo;": "›",
  24287. "rsquor;": "’",
  24288. "rthree;": "⋌",
  24289. "rtimes;": "⋊",
  24290. "Sacute;": "Ś",
  24291. "sacute;": "ś",
  24292. "Scaron;": "Š",
  24293. "scaron;": "š",
  24294. "Scedil;": "Ş",
  24295. "scedil;": "ş",
  24296. "scnsim;": "⋩",
  24297. "searhk;": "⤥",
  24298. "seswar;": "⤩",
  24299. "sfrown;": "⌢",
  24300. "SHCHcy;": "Щ",
  24301. "shchcy;": "щ",
  24302. "sigmaf;": "ς",
  24303. "sigmav;": "ς",
  24304. "simdot;": "⩪",
  24305. "smashp;": "⨳",
  24306. "SOFTcy;": "Ь",
  24307. "softcy;": "ь",
  24308. "solbar;": "⌿",
  24309. "spades;": "♠",
  24310. "sqcaps;": "⊓︀",
  24311. "sqcups;": "⊔︀",
  24312. "sqsube;": "⊑",
  24313. "sqsupe;": "⊒",
  24314. "Square;": "□",
  24315. "square;": "□",
  24316. "squarf;": "▪",
  24317. "ssetmn;": "∖",
  24318. "ssmile;": "⌣",
  24319. "sstarf;": "⋆",
  24320. "subdot;": "⪽",
  24321. "Subset;": "⋐",
  24322. "subset;": "⊂",
  24323. "subsim;": "⫇",
  24324. "subsub;": "⫕",
  24325. "subsup;": "⫓",
  24326. "succeq;": "⪰",
  24327. "supdot;": "⪾",
  24328. "Supset;": "⋑",
  24329. "supset;": "⊃",
  24330. "supsim;": "⫈",
  24331. "supsub;": "⫔",
  24332. "supsup;": "⫖",
  24333. "swarhk;": "⤦",
  24334. "swnwar;": "⤪",
  24335. "target;": "⌖",
  24336. "Tcaron;": "Ť",
  24337. "tcaron;": "ť",
  24338. "Tcedil;": "Ţ",
  24339. "tcedil;": "ţ",
  24340. "telrec;": "⌕",
  24341. "there4;": "∴",
  24342. "thetav;": "ϑ",
  24343. "thinsp;": " ",
  24344. "thksim;": "∼",
  24345. "timesb;": "⊠",
  24346. "timesd;": "⨰",
  24347. "topbot;": "⌶",
  24348. "topcir;": "⫱",
  24349. "tprime;": "‴",
  24350. "tridot;": "◬",
  24351. "Tstrok;": "Ŧ",
  24352. "tstrok;": "ŧ",
  24353. "Uacute;": "Ú",
  24354. "uacute;": "ú",
  24355. "Ubreve;": "Ŭ",
  24356. "ubreve;": "ŭ",
  24357. "Udblac;": "Ű",
  24358. "udblac;": "ű",
  24359. "ufisht;": "⥾",
  24360. "Ugrave;": "Ù",
  24361. "ugrave;": "ù",
  24362. "ulcorn;": "⌜",
  24363. "ulcrop;": "⌏",
  24364. "urcorn;": "⌝",
  24365. "urcrop;": "⌎",
  24366. "Utilde;": "Ũ",
  24367. "utilde;": "ũ",
  24368. "vangrt;": "⦜",
  24369. "varphi;": "ϕ",
  24370. "varrho;": "ϱ",
  24371. "Vdashl;": "⫦",
  24372. "veebar;": "⊻",
  24373. "vellip;": "⋮",
  24374. "Verbar;": "‖",
  24375. "verbar;": "|",
  24376. "vsubnE;": "⫋︀",
  24377. "vsubne;": "⊊︀",
  24378. "vsupnE;": "⫌︀",
  24379. "vsupne;": "⊋︀",
  24380. "Vvdash;": "⊪",
  24381. "wedbar;": "⩟",
  24382. "wedgeq;": "≙",
  24383. "weierp;": "℘",
  24384. "wreath;": "≀",
  24385. "xoplus;": "⨁",
  24386. "xotime;": "⨂",
  24387. "xsqcup;": "⨆",
  24388. "xuplus;": "⨄",
  24389. "xwedge;": "⋀",
  24390. "Yacute;": "Ý",
  24391. "yacute;": "ý",
  24392. "Zacute;": "Ź",
  24393. "zacute;": "ź",
  24394. "Zcaron;": "Ž",
  24395. "zcaron;": "ž",
  24396. "zeetrf;": "ℨ",
  24397. "alefsym;": "ℵ",
  24398. "angrtvb;": "⊾",
  24399. "angzarr;": "⍼",
  24400. "asympeq;": "≍",
  24401. "backsim;": "∽",
  24402. "Because;": "∵",
  24403. "because;": "∵",
  24404. "bemptyv;": "⦰",
  24405. "between;": "≬",
  24406. "bigcirc;": "◯",
  24407. "bigodot;": "⨀",
  24408. "bigstar;": "★",
  24409. "bnequiv;": "≡⃥",
  24410. "boxplus;": "⊞",
  24411. "Cayleys;": "ℭ",
  24412. "Cconint;": "∰",
  24413. "ccupssm;": "⩐",
  24414. "Cedilla;": "¸",
  24415. "cemptyv;": "⦲",
  24416. "cirscir;": "⧂",
  24417. "coloneq;": "≔",
  24418. "congdot;": "⩭",
  24419. "cudarrl;": "⤸",
  24420. "cudarrr;": "⤵",
  24421. "cularrp;": "⤽",
  24422. "curarrm;": "⤼",
  24423. "dbkarow;": "⤏",
  24424. "ddagger;": "‡",
  24425. "ddotseq;": "⩷",
  24426. "demptyv;": "⦱",
  24427. "Diamond;": "⋄",
  24428. "diamond;": "⋄",
  24429. "digamma;": "ϝ",
  24430. "dotplus;": "∔",
  24431. "DownTee;": "⊤",
  24432. "dwangle;": "⦦",
  24433. "Element;": "∈",
  24434. "Epsilon;": "Ε",
  24435. "epsilon;": "ε",
  24436. "eqcolon;": "≕",
  24437. "equivDD;": "⩸",
  24438. "gesdoto;": "⪂",
  24439. "gtquest;": "⩼",
  24440. "gtrless;": "≷",
  24441. "harrcir;": "⥈",
  24442. "Implies;": "⇒",
  24443. "intprod;": "⨼",
  24444. "isindot;": "⋵",
  24445. "larrbfs;": "⤟",
  24446. "larrsim;": "⥳",
  24447. "lbrksld;": "⦏",
  24448. "lbrkslu;": "⦍",
  24449. "ldrdhar;": "⥧",
  24450. "LeftTee;": "⊣",
  24451. "lesdoto;": "⪁",
  24452. "lessdot;": "⋖",
  24453. "lessgtr;": "≶",
  24454. "lesssim;": "≲",
  24455. "lotimes;": "⨴",
  24456. "lozenge;": "◊",
  24457. "ltquest;": "⩻",
  24458. "luruhar;": "⥦",
  24459. "maltese;": "✠",
  24460. "minusdu;": "⨪",
  24461. "napprox;": "≉",
  24462. "natural;": "♮",
  24463. "nearrow;": "↗",
  24464. "NewLine;": "\n",
  24465. "nexists;": "∄",
  24466. "NoBreak;": "⁠",
  24467. "notinva;": "∉",
  24468. "notinvb;": "⋷",
  24469. "notinvc;": "⋶",
  24470. "NotLess;": "≮",
  24471. "notniva;": "∌",
  24472. "notnivb;": "⋾",
  24473. "notnivc;": "⋽",
  24474. "npolint;": "⨔",
  24475. "npreceq;": "⪯̸",
  24476. "nsqsube;": "⋢",
  24477. "nsqsupe;": "⋣",
  24478. "nsubset;": "⊂⃒",
  24479. "nsucceq;": "⪰̸",
  24480. "nsupset;": "⊃⃒",
  24481. "nvinfin;": "⧞",
  24482. "nvltrie;": "⊴⃒",
  24483. "nvrtrie;": "⊵⃒",
  24484. "nwarrow;": "↖",
  24485. "olcross;": "⦻",
  24486. "Omicron;": "Ο",
  24487. "omicron;": "ο",
  24488. "orderof;": "ℴ",
  24489. "orslope;": "⩗",
  24490. "OverBar;": "‾",
  24491. "pertenk;": "‱",
  24492. "planckh;": "ℎ",
  24493. "pluscir;": "⨢",
  24494. "plussim;": "⨦",
  24495. "plustwo;": "⨧",
  24496. "precsim;": "≾",
  24497. "Product;": "∏",
  24498. "quatint;": "⨖",
  24499. "questeq;": "≟",
  24500. "rarrbfs;": "⤠",
  24501. "rarrsim;": "⥴",
  24502. "rbrksld;": "⦎",
  24503. "rbrkslu;": "⦐",
  24504. "rdldhar;": "⥩",
  24505. "realine;": "ℛ",
  24506. "rotimes;": "⨵",
  24507. "ruluhar;": "⥨",
  24508. "searrow;": "↘",
  24509. "simplus;": "⨤",
  24510. "simrarr;": "⥲",
  24511. "subedot;": "⫃",
  24512. "submult;": "⫁",
  24513. "subplus;": "⪿",
  24514. "subrarr;": "⥹",
  24515. "succsim;": "≿",
  24516. "supdsub;": "⫘",
  24517. "supedot;": "⫄",
  24518. "suphsol;": "⟉",
  24519. "suphsub;": "⫗",
  24520. "suplarr;": "⥻",
  24521. "supmult;": "⫂",
  24522. "supplus;": "⫀",
  24523. "swarrow;": "↙",
  24524. "topfork;": "⫚",
  24525. "triplus;": "⨹",
  24526. "tritime;": "⨻",
  24527. "UpArrow;": "↑",
  24528. "Uparrow;": "⇑",
  24529. "uparrow;": "↑",
  24530. "Upsilon;": "Υ",
  24531. "upsilon;": "υ",
  24532. "uwangle;": "⦧",
  24533. "vzigzag;": "⦚",
  24534. "zigrarr;": "⇝",
  24535. "andslope;": "⩘",
  24536. "angmsdaa;": "⦨",
  24537. "angmsdab;": "⦩",
  24538. "angmsdac;": "⦪",
  24539. "angmsdad;": "⦫",
  24540. "angmsdae;": "⦬",
  24541. "angmsdaf;": "⦭",
  24542. "angmsdag;": "⦮",
  24543. "angmsdah;": "⦯",
  24544. "angrtvbd;": "⦝",
  24545. "approxeq;": "≊",
  24546. "awconint;": "∳",
  24547. "backcong;": "≌",
  24548. "barwedge;": "⌅",
  24549. "bbrktbrk;": "⎶",
  24550. "bigoplus;": "⨁",
  24551. "bigsqcup;": "⨆",
  24552. "biguplus;": "⨄",
  24553. "bigwedge;": "⋀",
  24554. "boxminus;": "⊟",
  24555. "boxtimes;": "⊠",
  24556. "bsolhsub;": "⟈",
  24557. "capbrcup;": "⩉",
  24558. "circledR;": "®",
  24559. "circledS;": "Ⓢ",
  24560. "cirfnint;": "⨐",
  24561. "clubsuit;": "♣",
  24562. "cupbrcap;": "⩈",
  24563. "curlyvee;": "⋎",
  24564. "cwconint;": "∲",
  24565. "DDotrahd;": "⤑",
  24566. "doteqdot;": "≑",
  24567. "DotEqual;": "≐",
  24568. "dotminus;": "∸",
  24569. "drbkarow;": "⤐",
  24570. "dzigrarr;": "⟿",
  24571. "elinters;": "⏧",
  24572. "emptyset;": "∅",
  24573. "eqvparsl;": "⧥",
  24574. "fpartint;": "⨍",
  24575. "geqslant;": "⩾",
  24576. "gesdotol;": "⪄",
  24577. "gnapprox;": "⪊",
  24578. "hksearow;": "⤥",
  24579. "hkswarow;": "⤦",
  24580. "imagline;": "ℐ",
  24581. "imagpart;": "ℑ",
  24582. "infintie;": "⧝",
  24583. "integers;": "ℤ",
  24584. "Integral;": "∫",
  24585. "intercal;": "⊺",
  24586. "intlarhk;": "⨗",
  24587. "laemptyv;": "⦴",
  24588. "ldrushar;": "⥋",
  24589. "leqslant;": "⩽",
  24590. "lesdotor;": "⪃",
  24591. "LessLess;": "⪡",
  24592. "llcorner;": "⌞",
  24593. "lnapprox;": "⪉",
  24594. "lrcorner;": "⌟",
  24595. "lurdshar;": "⥊",
  24596. "mapstoup;": "↥",
  24597. "multimap;": "⊸",
  24598. "naturals;": "ℕ",
  24599. "ncongdot;": "⩭̸",
  24600. "NotEqual;": "≠",
  24601. "notindot;": "⋵̸",
  24602. "NotTilde;": "≁",
  24603. "otimesas;": "⨶",
  24604. "parallel;": "∥",
  24605. "PartialD;": "∂",
  24606. "plusacir;": "⨣",
  24607. "pointint;": "⨕",
  24608. "Precedes;": "≺",
  24609. "precneqq;": "⪵",
  24610. "precnsim;": "⋨",
  24611. "profalar;": "⌮",
  24612. "profline;": "⌒",
  24613. "profsurf;": "⌓",
  24614. "raemptyv;": "⦳",
  24615. "realpart;": "ℜ",
  24616. "RightTee;": "⊢",
  24617. "rppolint;": "⨒",
  24618. "rtriltri;": "⧎",
  24619. "scpolint;": "⨓",
  24620. "setminus;": "∖",
  24621. "shortmid;": "∣",
  24622. "smeparsl;": "⧤",
  24623. "sqsubset;": "⊏",
  24624. "sqsupset;": "⊐",
  24625. "subseteq;": "⊆",
  24626. "Succeeds;": "≻",
  24627. "succneqq;": "⪶",
  24628. "succnsim;": "⋩",
  24629. "SuchThat;": "∋",
  24630. "Superset;": "⊃",
  24631. "supseteq;": "⊇",
  24632. "thetasym;": "ϑ",
  24633. "thicksim;": "∼",
  24634. "timesbar;": "⨱",
  24635. "triangle;": "▵",
  24636. "triminus;": "⨺",
  24637. "trpezium;": "⏢",
  24638. "Uarrocir;": "⥉",
  24639. "ulcorner;": "⌜",
  24640. "UnderBar;": "_",
  24641. "urcorner;": "⌝",
  24642. "varkappa;": "ϰ",
  24643. "varsigma;": "ς",
  24644. "vartheta;": "ϑ",
  24645. "backprime;": "‵",
  24646. "backsimeq;": "⋍",
  24647. "Backslash;": "∖",
  24648. "bigotimes;": "⨂",
  24649. "CenterDot;": "·",
  24650. "centerdot;": "·",
  24651. "checkmark;": "✓",
  24652. "CircleDot;": "⊙",
  24653. "complexes;": "ℂ",
  24654. "Congruent;": "≡",
  24655. "Coproduct;": "∐",
  24656. "dotsquare;": "⊡",
  24657. "DoubleDot;": "¨",
  24658. "DownArrow;": "↓",
  24659. "Downarrow;": "⇓",
  24660. "downarrow;": "↓",
  24661. "DownBreve;": "̑",
  24662. "gtrapprox;": "⪆",
  24663. "gtreqless;": "⋛",
  24664. "gvertneqq;": "≩︀",
  24665. "heartsuit;": "♥",
  24666. "HumpEqual;": "≏",
  24667. "LeftArrow;": "←",
  24668. "Leftarrow;": "⇐",
  24669. "leftarrow;": "←",
  24670. "LeftFloor;": "⌊",
  24671. "lesseqgtr;": "⋚",
  24672. "LessTilde;": "≲",
  24673. "lvertneqq;": "≨︀",
  24674. "Mellintrf;": "ℳ",
  24675. "MinusPlus;": "∓",
  24676. "ngeqslant;": "⩾̸",
  24677. "nleqslant;": "⩽̸",
  24678. "NotCupCap;": "≭",
  24679. "NotExists;": "∄",
  24680. "NotSubset;": "⊂⃒",
  24681. "nparallel;": "∦",
  24682. "nshortmid;": "∤",
  24683. "nsubseteq;": "⊈",
  24684. "nsupseteq;": "⊉",
  24685. "OverBrace;": "⏞",
  24686. "pitchfork;": "⋔",
  24687. "PlusMinus;": "±",
  24688. "rationals;": "ℚ",
  24689. "spadesuit;": "♠",
  24690. "subseteqq;": "⫅",
  24691. "subsetneq;": "⊊",
  24692. "supseteqq;": "⫆",
  24693. "supsetneq;": "⊋",
  24694. "Therefore;": "∴",
  24695. "therefore;": "∴",
  24696. "ThinSpace;": " ",
  24697. "triangleq;": "≜",
  24698. "TripleDot;": "⃛",
  24699. "UnionPlus;": "⊎",
  24700. "varpropto;": "∝",
  24701. "Bernoullis;": "ℬ",
  24702. "circledast;": "⊛",
  24703. "CirclePlus;": "⊕",
  24704. "complement;": "∁",
  24705. "curlywedge;": "⋏",
  24706. "eqslantgtr;": "⪖",
  24707. "EqualTilde;": "≂",
  24708. "Fouriertrf;": "ℱ",
  24709. "gtreqqless;": "⪌",
  24710. "ImaginaryI;": "ⅈ",
  24711. "Laplacetrf;": "ℒ",
  24712. "LeftVector;": "↼",
  24713. "lessapprox;": "⪅",
  24714. "lesseqqgtr;": "⪋",
  24715. "Lleftarrow;": "⇚",
  24716. "lmoustache;": "⎰",
  24717. "longmapsto;": "⟼",
  24718. "mapstodown;": "↧",
  24719. "mapstoleft;": "↤",
  24720. "nLeftarrow;": "⇍",
  24721. "nleftarrow;": "↚",
  24722. "NotElement;": "∉",
  24723. "NotGreater;": "≯",
  24724. "nsubseteqq;": "⫅̸",
  24725. "nsupseteqq;": "⫆̸",
  24726. "precapprox;": "⪷",
  24727. "Proportion;": "∷",
  24728. "RightArrow;": "→",
  24729. "Rightarrow;": "⇒",
  24730. "rightarrow;": "→",
  24731. "RightFloor;": "⌋",
  24732. "rmoustache;": "⎱",
  24733. "sqsubseteq;": "⊑",
  24734. "sqsupseteq;": "⊒",
  24735. "subsetneqq;": "⫋",
  24736. "succapprox;": "⪸",
  24737. "supsetneqq;": "⫌",
  24738. "ThickSpace;": "  ",
  24739. "TildeEqual;": "≃",
  24740. "TildeTilde;": "≈",
  24741. "UnderBrace;": "⏟",
  24742. "UpArrowBar;": "⤒",
  24743. "UpTeeArrow;": "↥",
  24744. "upuparrows;": "⇈",
  24745. "varepsilon;": "ϵ",
  24746. "varnothing;": "∅",
  24747. "backepsilon;": "϶",
  24748. "blacksquare;": "▪",
  24749. "circledcirc;": "⊚",
  24750. "circleddash;": "⊝",
  24751. "CircleMinus;": "⊖",
  24752. "CircleTimes;": "⊗",
  24753. "curlyeqprec;": "⋞",
  24754. "curlyeqsucc;": "⋟",
  24755. "diamondsuit;": "♦",
  24756. "eqslantless;": "⪕",
  24757. "Equilibrium;": "⇌",
  24758. "expectation;": "ℰ",
  24759. "GreaterLess;": "≷",
  24760. "LeftCeiling;": "⌈",
  24761. "LessGreater;": "≶",
  24762. "MediumSpace;": " ",
  24763. "NotLessLess;": "≪̸",
  24764. "NotPrecedes;": "⊀",
  24765. "NotSucceeds;": "⊁",
  24766. "NotSuperset;": "⊃⃒",
  24767. "nRightarrow;": "⇏",
  24768. "nrightarrow;": "↛",
  24769. "OverBracket;": "⎴",
  24770. "preccurlyeq;": "≼",
  24771. "precnapprox;": "⪹",
  24772. "quaternions;": "ℍ",
  24773. "RightVector;": "⇀",
  24774. "Rrightarrow;": "⇛",
  24775. "RuleDelayed;": "⧴",
  24776. "SmallCircle;": "∘",
  24777. "SquareUnion;": "⊔",
  24778. "straightphi;": "ϕ",
  24779. "SubsetEqual;": "⊆",
  24780. "succcurlyeq;": "≽",
  24781. "succnapprox;": "⪺",
  24782. "thickapprox;": "≈",
  24783. "UpDownArrow;": "↕",
  24784. "Updownarrow;": "⇕",
  24785. "updownarrow;": "↕",
  24786. "VerticalBar;": "∣",
  24787. "blacklozenge;": "⧫",
  24788. "DownArrowBar;": "⤓",
  24789. "DownTeeArrow;": "↧",
  24790. "ExponentialE;": "ⅇ",
  24791. "exponentiale;": "ⅇ",
  24792. "GreaterEqual;": "≥",
  24793. "GreaterTilde;": "≳",
  24794. "HilbertSpace;": "ℋ",
  24795. "HumpDownHump;": "≎",
  24796. "Intersection;": "⋂",
  24797. "LeftArrowBar;": "⇤",
  24798. "LeftTeeArrow;": "↤",
  24799. "LeftTriangle;": "⊲",
  24800. "LeftUpVector;": "↿",
  24801. "NotCongruent;": "≢",
  24802. "NotHumpEqual;": "≏̸",
  24803. "NotLessEqual;": "≰",
  24804. "NotLessTilde;": "≴",
  24805. "Proportional;": "∝",
  24806. "RightCeiling;": "⌉",
  24807. "risingdotseq;": "≓",
  24808. "RoundImplies;": "⥰",
  24809. "ShortUpArrow;": "↑",
  24810. "SquareSubset;": "⊏",
  24811. "triangledown;": "▿",
  24812. "triangleleft;": "◃",
  24813. "UnderBracket;": "⎵",
  24814. "varsubsetneq;": "⊊︀",
  24815. "varsupsetneq;": "⊋︀",
  24816. "VerticalLine;": "|",
  24817. "ApplyFunction;": "⁡",
  24818. "bigtriangleup;": "△",
  24819. "blacktriangle;": "▴",
  24820. "DifferentialD;": "ⅆ",
  24821. "divideontimes;": "⋇",
  24822. "DoubleLeftTee;": "⫤",
  24823. "DoubleUpArrow;": "⇑",
  24824. "fallingdotseq;": "≒",
  24825. "hookleftarrow;": "↩",
  24826. "leftarrowtail;": "↢",
  24827. "leftharpoonup;": "↼",
  24828. "LeftTeeVector;": "⥚",
  24829. "LeftVectorBar;": "⥒",
  24830. "LessFullEqual;": "≦",
  24831. "LongLeftArrow;": "⟵",
  24832. "Longleftarrow;": "⟸",
  24833. "longleftarrow;": "⟵",
  24834. "looparrowleft;": "↫",
  24835. "measuredangle;": "∡",
  24836. "NotEqualTilde;": "≂̸",
  24837. "NotTildeEqual;": "≄",
  24838. "NotTildeTilde;": "≉",
  24839. "ntriangleleft;": "⋪",
  24840. "Poincareplane;": "ℌ",
  24841. "PrecedesEqual;": "⪯",
  24842. "PrecedesTilde;": "≾",
  24843. "RightArrowBar;": "⇥",
  24844. "RightTeeArrow;": "↦",
  24845. "RightTriangle;": "⊳",
  24846. "RightUpVector;": "↾",
  24847. "shortparallel;": "∥",
  24848. "smallsetminus;": "∖",
  24849. "SucceedsEqual;": "⪰",
  24850. "SucceedsTilde;": "≿",
  24851. "SupersetEqual;": "⊇",
  24852. "triangleright;": "▹",
  24853. "UpEquilibrium;": "⥮",
  24854. "upharpoonleft;": "↿",
  24855. "varsubsetneqq;": "⫋︀",
  24856. "varsupsetneqq;": "⫌︀",
  24857. "VerticalTilde;": "≀",
  24858. "VeryThinSpace;": " ",
  24859. "curvearrowleft;": "↶",
  24860. "DiacriticalDot;": "˙",
  24861. "doublebarwedge;": "⌆",
  24862. "DoubleRightTee;": "⊨",
  24863. "downdownarrows;": "⇊",
  24864. "DownLeftVector;": "↽",
  24865. "GreaterGreater;": "⪢",
  24866. "hookrightarrow;": "↪",
  24867. "HorizontalLine;": "─",
  24868. "InvisibleComma;": "⁣",
  24869. "InvisibleTimes;": "⁢",
  24870. "LeftDownVector;": "⇃",
  24871. "leftleftarrows;": "⇇",
  24872. "LeftRightArrow;": "↔",
  24873. "Leftrightarrow;": "⇔",
  24874. "leftrightarrow;": "↔",
  24875. "leftthreetimes;": "⋋",
  24876. "LessSlantEqual;": "⩽",
  24877. "LongRightArrow;": "⟶",
  24878. "Longrightarrow;": "⟹",
  24879. "longrightarrow;": "⟶",
  24880. "looparrowright;": "↬",
  24881. "LowerLeftArrow;": "↙",
  24882. "NestedLessLess;": "≪",
  24883. "NotGreaterLess;": "≹",
  24884. "NotLessGreater;": "≸",
  24885. "NotSubsetEqual;": "⊈",
  24886. "NotVerticalBar;": "∤",
  24887. "nshortparallel;": "∦",
  24888. "ntriangleright;": "⋫",
  24889. "OpenCurlyQuote;": "‘",
  24890. "ReverseElement;": "∋",
  24891. "rightarrowtail;": "↣",
  24892. "rightharpoonup;": "⇀",
  24893. "RightTeeVector;": "⥛",
  24894. "RightVectorBar;": "⥓",
  24895. "ShortDownArrow;": "↓",
  24896. "ShortLeftArrow;": "←",
  24897. "SquareSuperset;": "⊐",
  24898. "TildeFullEqual;": "≅",
  24899. "trianglelefteq;": "⊴",
  24900. "upharpoonright;": "↾",
  24901. "UpperLeftArrow;": "↖",
  24902. "ZeroWidthSpace;": "​",
  24903. "bigtriangledown;": "▽",
  24904. "circlearrowleft;": "↺",
  24905. "CloseCurlyQuote;": "’",
  24906. "ContourIntegral;": "∮",
  24907. "curvearrowright;": "↷",
  24908. "DoubleDownArrow;": "⇓",
  24909. "DoubleLeftArrow;": "⇐",
  24910. "downharpoonleft;": "⇃",
  24911. "DownRightVector;": "⇁",
  24912. "leftharpoondown;": "↽",
  24913. "leftrightarrows;": "⇆",
  24914. "LeftRightVector;": "⥎",
  24915. "LeftTriangleBar;": "⧏",
  24916. "LeftUpTeeVector;": "⥠",
  24917. "LeftUpVectorBar;": "⥘",
  24918. "LowerRightArrow;": "↘",
  24919. "nLeftrightarrow;": "⇎",
  24920. "nleftrightarrow;": "↮",
  24921. "NotGreaterEqual;": "≱",
  24922. "NotGreaterTilde;": "≵",
  24923. "NotHumpDownHump;": "≎̸",
  24924. "NotLeftTriangle;": "⋪",
  24925. "NotSquareSubset;": "⊏̸",
  24926. "ntrianglelefteq;": "⋬",
  24927. "OverParenthesis;": "⏜",
  24928. "RightDownVector;": "⇂",
  24929. "rightleftarrows;": "⇄",
  24930. "rightsquigarrow;": "↝",
  24931. "rightthreetimes;": "⋌",
  24932. "ShortRightArrow;": "→",
  24933. "straightepsilon;": "ϵ",
  24934. "trianglerighteq;": "⊵",
  24935. "UpperRightArrow;": "↗",
  24936. "vartriangleleft;": "⊲",
  24937. "circlearrowright;": "↻",
  24938. "DiacriticalAcute;": "´",
  24939. "DiacriticalGrave;": "`",
  24940. "DiacriticalTilde;": "˜",
  24941. "DoubleRightArrow;": "⇒",
  24942. "DownArrowUpArrow;": "⇵",
  24943. "downharpoonright;": "⇂",
  24944. "EmptySmallSquare;": "◻",
  24945. "GreaterEqualLess;": "⋛",
  24946. "GreaterFullEqual;": "≧",
  24947. "LeftAngleBracket;": "⟨",
  24948. "LeftUpDownVector;": "⥑",
  24949. "LessEqualGreater;": "⋚",
  24950. "NonBreakingSpace;": " ",
  24951. "NotPrecedesEqual;": "⪯̸",
  24952. "NotRightTriangle;": "⋫",
  24953. "NotSucceedsEqual;": "⪰̸",
  24954. "NotSucceedsTilde;": "≿̸",
  24955. "NotSupersetEqual;": "⊉",
  24956. "ntrianglerighteq;": "⋭",
  24957. "rightharpoondown;": "⇁",
  24958. "rightrightarrows;": "⇉",
  24959. "RightTriangleBar;": "⧐",
  24960. "RightUpTeeVector;": "⥜",
  24961. "RightUpVectorBar;": "⥔",
  24962. "twoheadleftarrow;": "↞",
  24963. "UnderParenthesis;": "⏝",
  24964. "UpArrowDownArrow;": "⇅",
  24965. "vartriangleright;": "⊳",
  24966. "blacktriangledown;": "▾",
  24967. "blacktriangleleft;": "◂",
  24968. "DoubleUpDownArrow;": "⇕",
  24969. "DoubleVerticalBar;": "∥",
  24970. "DownLeftTeeVector;": "⥞",
  24971. "DownLeftVectorBar;": "⥖",
  24972. "FilledSmallSquare;": "◼",
  24973. "GreaterSlantEqual;": "⩾",
  24974. "LeftDoubleBracket;": "⟦",
  24975. "LeftDownTeeVector;": "⥡",
  24976. "LeftDownVectorBar;": "⥙",
  24977. "leftrightharpoons;": "⇋",
  24978. "LeftTriangleEqual;": "⊴",
  24979. "NegativeThinSpace;": "​",
  24980. "NotGreaterGreater;": "≫̸",
  24981. "NotLessSlantEqual;": "⩽̸",
  24982. "NotNestedLessLess;": "⪡̸",
  24983. "NotReverseElement;": "∌",
  24984. "NotSquareSuperset;": "⊐̸",
  24985. "NotTildeFullEqual;": "≇",
  24986. "RightAngleBracket;": "⟩",
  24987. "rightleftharpoons;": "⇌",
  24988. "RightUpDownVector;": "⥏",
  24989. "SquareSubsetEqual;": "⊑",
  24990. "twoheadrightarrow;": "↠",
  24991. "VerticalSeparator;": "❘",
  24992. "blacktriangleright;": "▸",
  24993. "DownRightTeeVector;": "⥟",
  24994. "DownRightVectorBar;": "⥗",
  24995. "LongLeftRightArrow;": "⟷",
  24996. "Longleftrightarrow;": "⟺",
  24997. "longleftrightarrow;": "⟷",
  24998. "NegativeThickSpace;": "​",
  24999. "NotLeftTriangleBar;": "⧏̸",
  25000. "PrecedesSlantEqual;": "≼",
  25001. "ReverseEquilibrium;": "⇋",
  25002. "RightDoubleBracket;": "⟧",
  25003. "RightDownTeeVector;": "⥝",
  25004. "RightDownVectorBar;": "⥕",
  25005. "RightTriangleEqual;": "⊵",
  25006. "SquareIntersection;": "⊓",
  25007. "SucceedsSlantEqual;": "≽",
  25008. "DoubleLongLeftArrow;": "⟸",
  25009. "DownLeftRightVector;": "⥐",
  25010. "LeftArrowRightArrow;": "⇆",
  25011. "leftrightsquigarrow;": "↭",
  25012. "NegativeMediumSpace;": "​",
  25013. "NotGreaterFullEqual;": "≧̸",
  25014. "NotRightTriangleBar;": "⧐̸",
  25015. "RightArrowLeftArrow;": "⇄",
  25016. "SquareSupersetEqual;": "⊒",
  25017. "CapitalDifferentialD;": "ⅅ",
  25018. "DoubleLeftRightArrow;": "⇔",
  25019. "DoubleLongRightArrow;": "⟹",
  25020. "EmptyVerySmallSquare;": "▫",
  25021. "NestedGreaterGreater;": "≫",
  25022. "NotDoubleVerticalBar;": "∦",
  25023. "NotGreaterSlantEqual;": "⩾̸",
  25024. "NotLeftTriangleEqual;": "⋬",
  25025. "NotSquareSubsetEqual;": "⋢",
  25026. "OpenCurlyDoubleQuote;": "“",
  25027. "ReverseUpEquilibrium;": "⥯",
  25028. "CloseCurlyDoubleQuote;": "”",
  25029. "DoubleContourIntegral;": "∯",
  25030. "FilledVerySmallSquare;": "▪",
  25031. "NegativeVeryThinSpace;": "​",
  25032. "NotPrecedesSlantEqual;": "⋠",
  25033. "NotRightTriangleEqual;": "⋭",
  25034. "NotSucceedsSlantEqual;": "⋡",
  25035. "DiacriticalDoubleAcute;": "˝",
  25036. "NotSquareSupersetEqual;": "⋣",
  25037. "NotNestedGreaterGreater;": "⪢̸",
  25038. "ClockwiseContourIntegral;": "∲",
  25039. "DoubleLongLeftRightArrow;": "⟺",
  25040. "CounterClockwiseContourIntegral;": "∳"
  25041. };
  25042. let maxCRNameLength;
  25043. const decodeHtml = (rawText, asAttr) => {
  25044. let offset = 0;
  25045. const end = rawText.length;
  25046. let decodedText = "";
  25047. function advance(length) {
  25048. offset += length;
  25049. rawText = rawText.slice(length);
  25050. }
  25051. while (offset < end) {
  25052. const head = /&(?:#x?)?/i.exec(rawText);
  25053. if (!head || offset + head.index >= end) {
  25054. const remaining = end - offset;
  25055. decodedText += rawText.slice(0, remaining);
  25056. advance(remaining);
  25057. break;
  25058. }
  25059. decodedText += rawText.slice(0, head.index);
  25060. advance(head.index);
  25061. if (head[0] === "&") {
  25062. let name = "";
  25063. let value = void 0;
  25064. if (/[0-9a-z]/i.test(rawText[1])) {
  25065. if (!maxCRNameLength) {
  25066. maxCRNameLength = Object.keys(namedCharacterReferences).reduce(
  25067. (max, name2) => Math.max(max, name2.length),
  25068. 0
  25069. );
  25070. }
  25071. for (let length = maxCRNameLength; !value && length > 0; --length) {
  25072. name = rawText.slice(1, 1 + length);
  25073. value = namedCharacterReferences[name];
  25074. }
  25075. if (value) {
  25076. const semi = name.endsWith(";");
  25077. if (asAttr && !semi && /[=a-z0-9]/i.test(rawText[name.length + 1] || "")) {
  25078. decodedText += "&" + name;
  25079. advance(1 + name.length);
  25080. } else {
  25081. decodedText += value;
  25082. advance(1 + name.length);
  25083. }
  25084. } else {
  25085. decodedText += "&" + name;
  25086. advance(1 + name.length);
  25087. }
  25088. } else {
  25089. decodedText += "&";
  25090. advance(1);
  25091. }
  25092. } else {
  25093. const hex = head[0] === "&#x";
  25094. const pattern = hex ? /^&#x([0-9a-f]+);?/i : /^&#([0-9]+);?/;
  25095. const body = pattern.exec(rawText);
  25096. if (!body) {
  25097. decodedText += head[0];
  25098. advance(head[0].length);
  25099. } else {
  25100. let cp = Number.parseInt(body[1], hex ? 16 : 10);
  25101. if (cp === 0) {
  25102. cp = 65533;
  25103. } else if (cp > 1114111) {
  25104. cp = 65533;
  25105. } else if (cp >= 55296 && cp <= 57343) {
  25106. cp = 65533;
  25107. } else if (cp >= 64976 && cp <= 65007 || (cp & 65534) === 65534) ; else if (cp >= 1 && cp <= 8 || cp === 11 || cp >= 13 && cp <= 31 || cp >= 127 && cp <= 159) {
  25108. cp = CCR_REPLACEMENTS[cp] || cp;
  25109. }
  25110. decodedText += String.fromCodePoint(cp);
  25111. advance(body[0].length);
  25112. }
  25113. }
  25114. }
  25115. return decodedText;
  25116. };
  25117. const CCR_REPLACEMENTS = {
  25118. 128: 8364,
  25119. 130: 8218,
  25120. 131: 402,
  25121. 132: 8222,
  25122. 133: 8230,
  25123. 134: 8224,
  25124. 135: 8225,
  25125. 136: 710,
  25126. 137: 8240,
  25127. 138: 352,
  25128. 139: 8249,
  25129. 140: 338,
  25130. 142: 381,
  25131. 145: 8216,
  25132. 146: 8217,
  25133. 147: 8220,
  25134. 148: 8221,
  25135. 149: 8226,
  25136. 150: 8211,
  25137. 151: 8212,
  25138. 152: 732,
  25139. 153: 8482,
  25140. 154: 353,
  25141. 155: 8250,
  25142. 156: 339,
  25143. 158: 382,
  25144. 159: 376
  25145. };
  25146. const isRawTextContainer = /* @__PURE__ */ makeMap(
  25147. "style,iframe,script,noscript",
  25148. true
  25149. );
  25150. const parserOptions = {
  25151. isVoidTag,
  25152. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  25153. isPreTag: (tag) => tag === "pre",
  25154. decodeEntities: decodeHtml,
  25155. isBuiltInComponent: (tag) => {
  25156. if (isBuiltInType(tag, `Transition`)) {
  25157. return TRANSITION;
  25158. } else if (isBuiltInType(tag, `TransitionGroup`)) {
  25159. return TRANSITION_GROUP;
  25160. }
  25161. },
  25162. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  25163. getNamespace(tag, parent) {
  25164. let ns = parent ? parent.ns : 0;
  25165. if (parent && ns === 2) {
  25166. if (parent.tag === "annotation-xml") {
  25167. if (tag === "svg") {
  25168. return 1;
  25169. }
  25170. if (parent.props.some(
  25171. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  25172. )) {
  25173. ns = 0;
  25174. }
  25175. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  25176. ns = 0;
  25177. }
  25178. } else if (parent && ns === 1) {
  25179. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  25180. ns = 0;
  25181. }
  25182. }
  25183. if (ns === 0) {
  25184. if (tag === "svg") {
  25185. return 1;
  25186. }
  25187. if (tag === "math") {
  25188. return 2;
  25189. }
  25190. }
  25191. return ns;
  25192. },
  25193. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  25194. getTextMode({ tag, ns }) {
  25195. if (ns === 0) {
  25196. if (tag === "textarea" || tag === "title") {
  25197. return 1;
  25198. }
  25199. if (isRawTextContainer(tag)) {
  25200. return 2;
  25201. }
  25202. }
  25203. return 0;
  25204. }
  25205. };
  25206. const transformStyle = (node) => {
  25207. if (node.type === 1) {
  25208. node.props.forEach((p, i) => {
  25209. if (p.type === 6 && p.name === "style" && p.value) {
  25210. node.props[i] = {
  25211. type: 7,
  25212. name: `bind`,
  25213. arg: createSimpleExpression(`style`, true, p.loc),
  25214. exp: parseInlineCSS(p.value.content, p.loc),
  25215. modifiers: [],
  25216. loc: p.loc
  25217. };
  25218. }
  25219. });
  25220. }
  25221. };
  25222. const parseInlineCSS = (cssText, loc) => {
  25223. const normalized = parseStringStyle(cssText);
  25224. return createSimpleExpression(
  25225. JSON.stringify(normalized),
  25226. false,
  25227. loc,
  25228. 3
  25229. );
  25230. };
  25231. function createDOMCompilerError(code, loc) {
  25232. return createCompilerError(
  25233. code,
  25234. loc,
  25235. DOMErrorMessages
  25236. );
  25237. }
  25238. const DOMErrorMessages = {
  25239. [53]: `v-html is missing expression.`,
  25240. [54]: `v-html will override element children.`,
  25241. [55]: `v-text is missing expression.`,
  25242. [56]: `v-text will override element children.`,
  25243. [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  25244. [58]: `v-model argument is not supported on plain elements.`,
  25245. [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  25246. [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  25247. [61]: `v-show is missing expression.`,
  25248. [62]: `<Transition> expects exactly one child element or component.`,
  25249. [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  25250. };
  25251. const transformVHtml = (dir, node, context) => {
  25252. const { exp, loc } = dir;
  25253. if (!exp) {
  25254. context.onError(
  25255. createDOMCompilerError(53, loc)
  25256. );
  25257. }
  25258. if (node.children.length) {
  25259. context.onError(
  25260. createDOMCompilerError(54, loc)
  25261. );
  25262. node.children.length = 0;
  25263. }
  25264. return {
  25265. props: [
  25266. createObjectProperty(
  25267. createSimpleExpression(`innerHTML`, true, loc),
  25268. exp || createSimpleExpression("", true)
  25269. )
  25270. ]
  25271. };
  25272. };
  25273. const transformVText = (dir, node, context) => {
  25274. const { exp, loc } = dir;
  25275. if (!exp) {
  25276. context.onError(
  25277. createDOMCompilerError(55, loc)
  25278. );
  25279. }
  25280. if (node.children.length) {
  25281. context.onError(
  25282. createDOMCompilerError(56, loc)
  25283. );
  25284. node.children.length = 0;
  25285. }
  25286. return {
  25287. props: [
  25288. createObjectProperty(
  25289. createSimpleExpression(`textContent`, true),
  25290. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  25291. context.helperString(TO_DISPLAY_STRING),
  25292. [exp],
  25293. loc
  25294. ) : createSimpleExpression("", true)
  25295. )
  25296. ]
  25297. };
  25298. };
  25299. const transformModel = (dir, node, context) => {
  25300. const baseResult = transformModel$1(dir, node, context);
  25301. if (!baseResult.props.length || node.tagType === 1) {
  25302. return baseResult;
  25303. }
  25304. if (dir.arg) {
  25305. context.onError(
  25306. createDOMCompilerError(
  25307. 58,
  25308. dir.arg.loc
  25309. )
  25310. );
  25311. }
  25312. function checkDuplicatedValue() {
  25313. const value = findProp(node, "value");
  25314. if (value) {
  25315. context.onError(
  25316. createDOMCompilerError(
  25317. 60,
  25318. value.loc
  25319. )
  25320. );
  25321. }
  25322. }
  25323. const { tag } = node;
  25324. const isCustomElement = context.isCustomElement(tag);
  25325. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  25326. let directiveToUse = V_MODEL_TEXT;
  25327. let isInvalidType = false;
  25328. if (tag === "input" || isCustomElement) {
  25329. const type = findProp(node, `type`);
  25330. if (type) {
  25331. if (type.type === 7) {
  25332. directiveToUse = V_MODEL_DYNAMIC;
  25333. } else if (type.value) {
  25334. switch (type.value.content) {
  25335. case "radio":
  25336. directiveToUse = V_MODEL_RADIO;
  25337. break;
  25338. case "checkbox":
  25339. directiveToUse = V_MODEL_CHECKBOX;
  25340. break;
  25341. case "file":
  25342. isInvalidType = true;
  25343. context.onError(
  25344. createDOMCompilerError(
  25345. 59,
  25346. dir.loc
  25347. )
  25348. );
  25349. break;
  25350. default:
  25351. checkDuplicatedValue();
  25352. break;
  25353. }
  25354. }
  25355. } else if (hasDynamicKeyVBind(node)) {
  25356. directiveToUse = V_MODEL_DYNAMIC;
  25357. } else {
  25358. checkDuplicatedValue();
  25359. }
  25360. } else if (tag === "select") {
  25361. directiveToUse = V_MODEL_SELECT;
  25362. } else {
  25363. checkDuplicatedValue();
  25364. }
  25365. if (!isInvalidType) {
  25366. baseResult.needRuntime = context.helper(directiveToUse);
  25367. }
  25368. } else {
  25369. context.onError(
  25370. createDOMCompilerError(
  25371. 57,
  25372. dir.loc
  25373. )
  25374. );
  25375. }
  25376. baseResult.props = baseResult.props.filter(
  25377. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  25378. );
  25379. return baseResult;
  25380. };
  25381. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  25382. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  25383. // event propagation management
  25384. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  25385. );
  25386. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  25387. const isKeyboardEvent = /* @__PURE__ */ makeMap(
  25388. `onkeyup,onkeydown,onkeypress`,
  25389. true
  25390. );
  25391. const resolveModifiers = (key, modifiers, context, loc) => {
  25392. const keyModifiers = [];
  25393. const nonKeyModifiers = [];
  25394. const eventOptionModifiers = [];
  25395. for (let i = 0; i < modifiers.length; i++) {
  25396. const modifier = modifiers[i];
  25397. if (isEventOptionModifier(modifier)) {
  25398. eventOptionModifiers.push(modifier);
  25399. } else {
  25400. if (maybeKeyModifier(modifier)) {
  25401. if (isStaticExp(key)) {
  25402. if (isKeyboardEvent(key.content)) {
  25403. keyModifiers.push(modifier);
  25404. } else {
  25405. nonKeyModifiers.push(modifier);
  25406. }
  25407. } else {
  25408. keyModifiers.push(modifier);
  25409. nonKeyModifiers.push(modifier);
  25410. }
  25411. } else {
  25412. if (isNonKeyModifier(modifier)) {
  25413. nonKeyModifiers.push(modifier);
  25414. } else {
  25415. keyModifiers.push(modifier);
  25416. }
  25417. }
  25418. }
  25419. }
  25420. return {
  25421. keyModifiers,
  25422. nonKeyModifiers,
  25423. eventOptionModifiers
  25424. };
  25425. };
  25426. const transformClick = (key, event) => {
  25427. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  25428. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  25429. `(`,
  25430. key,
  25431. `) === "onClick" ? "${event}" : (`,
  25432. key,
  25433. `)`
  25434. ]) : key;
  25435. };
  25436. const transformOn = (dir, node, context) => {
  25437. return transformOn$1(dir, node, context, (baseResult) => {
  25438. const { modifiers } = dir;
  25439. if (!modifiers.length)
  25440. return baseResult;
  25441. let { key, value: handlerExp } = baseResult.props[0];
  25442. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  25443. if (nonKeyModifiers.includes("right")) {
  25444. key = transformClick(key, `onContextmenu`);
  25445. }
  25446. if (nonKeyModifiers.includes("middle")) {
  25447. key = transformClick(key, `onMouseup`);
  25448. }
  25449. if (nonKeyModifiers.length) {
  25450. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  25451. handlerExp,
  25452. JSON.stringify(nonKeyModifiers)
  25453. ]);
  25454. }
  25455. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  25456. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  25457. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  25458. handlerExp,
  25459. JSON.stringify(keyModifiers)
  25460. ]);
  25461. }
  25462. if (eventOptionModifiers.length) {
  25463. const modifierPostfix = eventOptionModifiers.map(capitalize$1).join("");
  25464. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  25465. }
  25466. return {
  25467. props: [createObjectProperty(key, handlerExp)]
  25468. };
  25469. });
  25470. };
  25471. const transformShow = (dir, node, context) => {
  25472. const { exp, loc } = dir;
  25473. if (!exp) {
  25474. context.onError(
  25475. createDOMCompilerError(61, loc)
  25476. );
  25477. }
  25478. return {
  25479. props: [],
  25480. needRuntime: context.helper(V_SHOW)
  25481. };
  25482. };
  25483. const transformTransition = (node, context) => {
  25484. if (node.type === 1 && node.tagType === 1) {
  25485. const component = context.isBuiltInComponent(node.tag);
  25486. if (component === TRANSITION) {
  25487. return () => {
  25488. if (!node.children.length) {
  25489. return;
  25490. }
  25491. if (hasMultipleChildren(node)) {
  25492. context.onError(
  25493. createDOMCompilerError(
  25494. 62,
  25495. {
  25496. start: node.children[0].loc.start,
  25497. end: node.children[node.children.length - 1].loc.end,
  25498. source: ""
  25499. }
  25500. )
  25501. );
  25502. }
  25503. const child = node.children[0];
  25504. if (child.type === 1) {
  25505. for (const p of child.props) {
  25506. if (p.type === 7 && p.name === "show") {
  25507. node.props.push({
  25508. type: 6,
  25509. name: "persisted",
  25510. value: void 0,
  25511. loc: node.loc
  25512. });
  25513. }
  25514. }
  25515. }
  25516. };
  25517. }
  25518. }
  25519. };
  25520. function hasMultipleChildren(node) {
  25521. const children = node.children = node.children.filter(
  25522. (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
  25523. );
  25524. const child = children[0];
  25525. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  25526. }
  25527. const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
  25528. const stringifyStatic = (children, context, parent) => {
  25529. if (context.scopes.vSlot > 0) {
  25530. return;
  25531. }
  25532. let nc = 0;
  25533. let ec = 0;
  25534. const currentChunk = [];
  25535. const stringifyCurrentChunk = (currentIndex) => {
  25536. if (nc >= 20 || ec >= 5) {
  25537. const staticCall = createCallExpression(context.helper(CREATE_STATIC), [
  25538. JSON.stringify(
  25539. currentChunk.map((node) => stringifyNode(node, context)).join("")
  25540. ).replace(expReplaceRE, `" + $1 + "`),
  25541. // the 2nd argument indicates the number of DOM nodes this static vnode
  25542. // will insert / hydrate
  25543. String(currentChunk.length)
  25544. ]);
  25545. replaceHoist(currentChunk[0], staticCall, context);
  25546. if (currentChunk.length > 1) {
  25547. for (let i2 = 1; i2 < currentChunk.length; i2++) {
  25548. replaceHoist(currentChunk[i2], null, context);
  25549. }
  25550. const deleteCount = currentChunk.length - 1;
  25551. children.splice(currentIndex - currentChunk.length + 1, deleteCount);
  25552. return deleteCount;
  25553. }
  25554. }
  25555. return 0;
  25556. };
  25557. let i = 0;
  25558. for (; i < children.length; i++) {
  25559. const child = children[i];
  25560. const hoisted = getHoistedNode(child);
  25561. if (hoisted) {
  25562. const node = child;
  25563. const result = analyzeNode(node);
  25564. if (result) {
  25565. nc += result[0];
  25566. ec += result[1];
  25567. currentChunk.push(node);
  25568. continue;
  25569. }
  25570. }
  25571. i -= stringifyCurrentChunk(i);
  25572. nc = 0;
  25573. ec = 0;
  25574. currentChunk.length = 0;
  25575. }
  25576. stringifyCurrentChunk(i);
  25577. };
  25578. const getHoistedNode = (node) => (node.type === 1 && node.tagType === 0 || node.type == 12) && node.codegenNode && node.codegenNode.type === 4 && node.codegenNode.hoisted;
  25579. const dataAriaRE = /^(data|aria)-/;
  25580. const isStringifiableAttr = (name, ns) => {
  25581. return (ns === 0 ? isKnownHtmlAttr(name) : ns === 1 ? isKnownSvgAttr(name) : false) || dataAriaRE.test(name);
  25582. };
  25583. const replaceHoist = (node, replacement, context) => {
  25584. const hoistToReplace = node.codegenNode.hoisted;
  25585. context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement;
  25586. };
  25587. const isNonStringifiable = /* @__PURE__ */ makeMap(
  25588. `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
  25589. );
  25590. function analyzeNode(node) {
  25591. if (node.type === 1 && isNonStringifiable(node.tag)) {
  25592. return false;
  25593. }
  25594. if (node.type === 12) {
  25595. return [1, 0];
  25596. }
  25597. let nc = 1;
  25598. let ec = node.props.length > 0 ? 1 : 0;
  25599. let bailed = false;
  25600. const bail = () => {
  25601. bailed = true;
  25602. return false;
  25603. };
  25604. function walk(node2) {
  25605. for (let i = 0; i < node2.props.length; i++) {
  25606. const p = node2.props[i];
  25607. if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
  25608. return bail();
  25609. }
  25610. if (p.type === 7 && p.name === "bind") {
  25611. if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
  25612. return bail();
  25613. }
  25614. if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
  25615. return bail();
  25616. }
  25617. }
  25618. }
  25619. for (let i = 0; i < node2.children.length; i++) {
  25620. nc++;
  25621. const child = node2.children[i];
  25622. if (child.type === 1) {
  25623. if (child.props.length > 0) {
  25624. ec++;
  25625. }
  25626. walk(child);
  25627. if (bailed) {
  25628. return false;
  25629. }
  25630. }
  25631. }
  25632. return true;
  25633. }
  25634. return walk(node) ? [nc, ec] : false;
  25635. }
  25636. function stringifyNode(node, context) {
  25637. if (isString$2(node)) {
  25638. return node;
  25639. }
  25640. if (isSymbol$1(node)) {
  25641. return ``;
  25642. }
  25643. switch (node.type) {
  25644. case 1:
  25645. return stringifyElement(node, context);
  25646. case 2:
  25647. return escapeHtml(node.content);
  25648. case 3:
  25649. return `<!--${escapeHtml(node.content)}-->`;
  25650. case 5:
  25651. return escapeHtml(toDisplayString(evaluateConstant(node.content)));
  25652. case 8:
  25653. return escapeHtml(evaluateConstant(node));
  25654. case 12:
  25655. return stringifyNode(node.content, context);
  25656. default:
  25657. return "";
  25658. }
  25659. }
  25660. function stringifyElement(node, context) {
  25661. let res = `<${node.tag}`;
  25662. let innerHTML = "";
  25663. for (let i = 0; i < node.props.length; i++) {
  25664. const p = node.props[i];
  25665. if (p.type === 6) {
  25666. res += ` ${p.name}`;
  25667. if (p.value) {
  25668. res += `="${escapeHtml(p.value.content)}"`;
  25669. }
  25670. } else if (p.type === 7) {
  25671. if (p.name === "bind") {
  25672. const exp = p.exp;
  25673. if (exp.content[0] === "_") {
  25674. res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
  25675. continue;
  25676. }
  25677. if (isBooleanAttr(p.arg.content) && exp.content === "false") {
  25678. continue;
  25679. }
  25680. let evaluated = evaluateConstant(exp);
  25681. if (evaluated != null) {
  25682. const arg = p.arg && p.arg.content;
  25683. if (arg === "class") {
  25684. evaluated = normalizeClass(evaluated);
  25685. } else if (arg === "style") {
  25686. evaluated = stringifyStyle(normalizeStyle(evaluated));
  25687. }
  25688. res += ` ${p.arg.content}="${escapeHtml(
  25689. evaluated
  25690. )}"`;
  25691. }
  25692. } else if (p.name === "html") {
  25693. innerHTML = evaluateConstant(p.exp);
  25694. } else if (p.name === "text") {
  25695. innerHTML = escapeHtml(
  25696. toDisplayString(evaluateConstant(p.exp))
  25697. );
  25698. }
  25699. }
  25700. }
  25701. if (context.scopeId) {
  25702. res += ` ${context.scopeId}`;
  25703. }
  25704. res += `>`;
  25705. if (innerHTML) {
  25706. res += innerHTML;
  25707. } else {
  25708. for (let i = 0; i < node.children.length; i++) {
  25709. res += stringifyNode(node.children[i], context);
  25710. }
  25711. }
  25712. if (!isVoidTag(node.tag)) {
  25713. res += `</${node.tag}>`;
  25714. }
  25715. return res;
  25716. }
  25717. function evaluateConstant(exp) {
  25718. if (exp.type === 4) {
  25719. return new Function(`return (${exp.content})`)();
  25720. } else {
  25721. let res = ``;
  25722. exp.children.forEach((c) => {
  25723. if (isString$2(c) || isSymbol$1(c)) {
  25724. return;
  25725. }
  25726. if (c.type === 2) {
  25727. res += c.content;
  25728. } else if (c.type === 5) {
  25729. res += toDisplayString(evaluateConstant(c.content));
  25730. } else {
  25731. res += evaluateConstant(c);
  25732. }
  25733. });
  25734. return res;
  25735. }
  25736. }
  25737. const ignoreSideEffectTags = (node, context) => {
  25738. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  25739. context.onError(
  25740. createDOMCompilerError(
  25741. 63,
  25742. node.loc
  25743. )
  25744. );
  25745. context.removeNode();
  25746. }
  25747. };
  25748. const DOMNodeTransforms = [
  25749. transformStyle,
  25750. ...[transformTransition]
  25751. ];
  25752. const DOMDirectiveTransforms = {
  25753. cloak: noopDirectiveTransform,
  25754. html: transformVHtml,
  25755. text: transformVText,
  25756. model: transformModel,
  25757. // override compiler-core
  25758. on: transformOn,
  25759. // override compiler-core
  25760. show: transformShow
  25761. };
  25762. function compile$1(template, options = {}) {
  25763. return baseCompile(
  25764. template,
  25765. extend({}, parserOptions, options, {
  25766. nodeTransforms: [
  25767. // ignore <script> and <tag>
  25768. // this is not put inside DOMNodeTransforms because that list is used
  25769. // by compiler-ssr to generate vnode fallback branches
  25770. ignoreSideEffectTags,
  25771. ...DOMNodeTransforms,
  25772. ...options.nodeTransforms || []
  25773. ],
  25774. directiveTransforms: extend(
  25775. {},
  25776. DOMDirectiveTransforms,
  25777. options.directiveTransforms || {}
  25778. ),
  25779. transformHoist: stringifyStatic
  25780. })
  25781. );
  25782. }
  25783. function parse$8(template, options = {}) {
  25784. return baseParse(template, extend({}, parserOptions, options));
  25785. }
  25786. var CompilerDOM = /*#__PURE__*/Object.freeze({
  25787. __proto__: null,
  25788. BASE_TRANSITION: BASE_TRANSITION,
  25789. CAMELIZE: CAMELIZE,
  25790. CAPITALIZE: CAPITALIZE,
  25791. CREATE_BLOCK: CREATE_BLOCK,
  25792. CREATE_COMMENT: CREATE_COMMENT,
  25793. CREATE_ELEMENT_BLOCK: CREATE_ELEMENT_BLOCK,
  25794. CREATE_ELEMENT_VNODE: CREATE_ELEMENT_VNODE,
  25795. CREATE_SLOTS: CREATE_SLOTS,
  25796. CREATE_STATIC: CREATE_STATIC,
  25797. CREATE_TEXT: CREATE_TEXT,
  25798. CREATE_VNODE: CREATE_VNODE,
  25799. DOMDirectiveTransforms: DOMDirectiveTransforms,
  25800. DOMNodeTransforms: DOMNodeTransforms,
  25801. FRAGMENT: FRAGMENT,
  25802. GUARD_REACTIVE_PROPS: GUARD_REACTIVE_PROPS,
  25803. IS_MEMO_SAME: IS_MEMO_SAME,
  25804. IS_REF: IS_REF,
  25805. KEEP_ALIVE: KEEP_ALIVE,
  25806. MERGE_PROPS: MERGE_PROPS,
  25807. NORMALIZE_CLASS: NORMALIZE_CLASS,
  25808. NORMALIZE_PROPS: NORMALIZE_PROPS,
  25809. NORMALIZE_STYLE: NORMALIZE_STYLE,
  25810. OPEN_BLOCK: OPEN_BLOCK,
  25811. POP_SCOPE_ID: POP_SCOPE_ID,
  25812. PUSH_SCOPE_ID: PUSH_SCOPE_ID,
  25813. RENDER_LIST: RENDER_LIST,
  25814. RENDER_SLOT: RENDER_SLOT,
  25815. RESOLVE_COMPONENT: RESOLVE_COMPONENT,
  25816. RESOLVE_DIRECTIVE: RESOLVE_DIRECTIVE,
  25817. RESOLVE_DYNAMIC_COMPONENT: RESOLVE_DYNAMIC_COMPONENT,
  25818. RESOLVE_FILTER: RESOLVE_FILTER,
  25819. SET_BLOCK_TRACKING: SET_BLOCK_TRACKING,
  25820. SUSPENSE: SUSPENSE,
  25821. TELEPORT: TELEPORT,
  25822. TO_DISPLAY_STRING: TO_DISPLAY_STRING,
  25823. TO_HANDLERS: TO_HANDLERS,
  25824. TO_HANDLER_KEY: TO_HANDLER_KEY,
  25825. TRANSITION: TRANSITION,
  25826. TRANSITION_GROUP: TRANSITION_GROUP,
  25827. TS_NODE_TYPES: TS_NODE_TYPES,
  25828. UNREF: UNREF,
  25829. V_MODEL_CHECKBOX: V_MODEL_CHECKBOX,
  25830. V_MODEL_DYNAMIC: V_MODEL_DYNAMIC,
  25831. V_MODEL_RADIO: V_MODEL_RADIO,
  25832. V_MODEL_SELECT: V_MODEL_SELECT,
  25833. V_MODEL_TEXT: V_MODEL_TEXT,
  25834. V_ON_WITH_KEYS: V_ON_WITH_KEYS,
  25835. V_ON_WITH_MODIFIERS: V_ON_WITH_MODIFIERS,
  25836. V_SHOW: V_SHOW,
  25837. WITH_CTX: WITH_CTX,
  25838. WITH_DIRECTIVES: WITH_DIRECTIVES,
  25839. WITH_MEMO: WITH_MEMO,
  25840. advancePositionWithClone: advancePositionWithClone,
  25841. advancePositionWithMutation: advancePositionWithMutation,
  25842. assert: assert,
  25843. baseCompile: baseCompile,
  25844. baseParse: baseParse,
  25845. buildDirectiveArgs: buildDirectiveArgs,
  25846. buildProps: buildProps,
  25847. buildSlots: buildSlots,
  25848. checkCompatEnabled: checkCompatEnabled,
  25849. compile: compile$1,
  25850. convertToBlock: convertToBlock,
  25851. createArrayExpression: createArrayExpression,
  25852. createAssignmentExpression: createAssignmentExpression,
  25853. createBlockStatement: createBlockStatement,
  25854. createCacheExpression: createCacheExpression,
  25855. createCallExpression: createCallExpression,
  25856. createCompilerError: createCompilerError,
  25857. createCompoundExpression: createCompoundExpression,
  25858. createConditionalExpression: createConditionalExpression,
  25859. createDOMCompilerError: createDOMCompilerError,
  25860. createForLoopParams: createForLoopParams,
  25861. createFunctionExpression: createFunctionExpression,
  25862. createIfStatement: createIfStatement,
  25863. createInterpolation: createInterpolation,
  25864. createObjectExpression: createObjectExpression,
  25865. createObjectProperty: createObjectProperty,
  25866. createReturnStatement: createReturnStatement,
  25867. createRoot: createRoot,
  25868. createSequenceExpression: createSequenceExpression,
  25869. createSimpleExpression: createSimpleExpression,
  25870. createStructuralDirectiveTransform: createStructuralDirectiveTransform,
  25871. createTemplateLiteral: createTemplateLiteral,
  25872. createTransformContext: createTransformContext,
  25873. createVNodeCall: createVNodeCall,
  25874. extractIdentifiers: extractIdentifiers,
  25875. findDir: findDir,
  25876. findProp: findProp,
  25877. generate: generate,
  25878. generateCodeFrame: generateCodeFrame,
  25879. getBaseTransformPreset: getBaseTransformPreset,
  25880. getConstantType: getConstantType,
  25881. getInnerRange: getInnerRange,
  25882. getMemoedVNodeCall: getMemoedVNodeCall,
  25883. getVNodeBlockHelper: getVNodeBlockHelper,
  25884. getVNodeHelper: getVNodeHelper,
  25885. hasDynamicKeyVBind: hasDynamicKeyVBind,
  25886. hasScopeRef: hasScopeRef,
  25887. helperNameMap: helperNameMap,
  25888. injectProp: injectProp,
  25889. isBuiltInType: isBuiltInType,
  25890. isCoreComponent: isCoreComponent,
  25891. isFunctionType: isFunctionType,
  25892. isInDestructureAssignment: isInDestructureAssignment,
  25893. isMemberExpression: isMemberExpression,
  25894. isMemberExpressionBrowser: isMemberExpressionBrowser,
  25895. isMemberExpressionNode: isMemberExpressionNode,
  25896. isReferencedIdentifier: isReferencedIdentifier,
  25897. isSimpleIdentifier: isSimpleIdentifier,
  25898. isSlotOutlet: isSlotOutlet,
  25899. isStaticArgOf: isStaticArgOf,
  25900. isStaticExp: isStaticExp,
  25901. isStaticProperty: isStaticProperty,
  25902. isStaticPropertyKey: isStaticPropertyKey,
  25903. isTemplateNode: isTemplateNode,
  25904. isText: isText$1,
  25905. isVSlot: isVSlot,
  25906. locStub: locStub,
  25907. noopDirectiveTransform: noopDirectiveTransform,
  25908. parse: parse$8,
  25909. parserOptions: parserOptions,
  25910. processExpression: processExpression,
  25911. processFor: processFor,
  25912. processIf: processIf,
  25913. processSlotOutlet: processSlotOutlet,
  25914. registerRuntimeHelpers: registerRuntimeHelpers,
  25915. resolveComponentType: resolveComponentType,
  25916. stringifyExpression: stringifyExpression,
  25917. toValidAssetId: toValidAssetId,
  25918. trackSlotScopes: trackSlotScopes,
  25919. trackVForSlotScopes: trackVForSlotScopes,
  25920. transform: transform$1,
  25921. transformBind: transformBind,
  25922. transformElement: transformElement,
  25923. transformExpression: transformExpression,
  25924. transformModel: transformModel$1,
  25925. transformOn: transformOn$1,
  25926. transformStyle: transformStyle,
  25927. traverseNode: traverseNode,
  25928. walkBlockDeclarations: walkBlockDeclarations,
  25929. walkFunctionParams: walkFunctionParams,
  25930. walkIdentifiers: walkIdentifiers,
  25931. warnDeprecation: warnDeprecation
  25932. });
  25933. // Copyright Joyent, Inc. and other Node contributors.
  25934. //
  25935. // Permission is hereby granted, free of charge, to any person obtaining a
  25936. // copy of this software and associated documentation files (the
  25937. // "Software"), to deal in the Software without restriction, including
  25938. // without limitation the rights to use, copy, modify, merge, publish,
  25939. // distribute, sublicense, and/or sell copies of the Software, and to permit
  25940. // persons to whom the Software is furnished to do so, subject to the
  25941. // following conditions:
  25942. //
  25943. // The above copyright notice and this permission notice shall be included
  25944. // in all copies or substantial portions of the Software.
  25945. //
  25946. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  25947. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25948. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  25949. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  25950. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  25951. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  25952. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  25953. // resolves . and .. elements in a path array with directory names there
  25954. // must be no slashes, empty elements, or device names (c:\) in the array
  25955. // (so also no leading and trailing slashes - it does not distinguish
  25956. // relative and absolute paths)
  25957. function normalizeArray(parts, allowAboveRoot) {
  25958. // if the path tries to go above the root, `up` ends up > 0
  25959. var up = 0;
  25960. for (var i = parts.length - 1; i >= 0; i--) {
  25961. var last = parts[i];
  25962. if (last === '.') {
  25963. parts.splice(i, 1);
  25964. } else if (last === '..') {
  25965. parts.splice(i, 1);
  25966. up++;
  25967. } else if (up) {
  25968. parts.splice(i, 1);
  25969. up--;
  25970. }
  25971. }
  25972. // if the path is allowed to go above the root, restore leading ..s
  25973. if (allowAboveRoot) {
  25974. for (; up--; up) {
  25975. parts.unshift('..');
  25976. }
  25977. }
  25978. return parts;
  25979. }
  25980. // Split a filename into [root, dir, basename, ext], unix version
  25981. // 'root' is just a slash, or nothing.
  25982. var splitPathRe =
  25983. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  25984. var splitPath = function(filename) {
  25985. return splitPathRe.exec(filename).slice(1);
  25986. };
  25987. // path.resolve([from ...], to)
  25988. // posix version
  25989. function resolve$2() {
  25990. var resolvedPath = '',
  25991. resolvedAbsolute = false;
  25992. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  25993. var path = (i >= 0) ? arguments[i] : '/';
  25994. // Skip empty and invalid entries
  25995. if (typeof path !== 'string') {
  25996. throw new TypeError('Arguments to path.resolve must be strings');
  25997. } else if (!path) {
  25998. continue;
  25999. }
  26000. resolvedPath = path + '/' + resolvedPath;
  26001. resolvedAbsolute = path.charAt(0) === '/';
  26002. }
  26003. // At this point the path should be resolved to a full absolute path, but
  26004. // handle relative paths to be safe (might happen when process.cwd() fails)
  26005. // Normalize the path
  26006. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  26007. return !!p;
  26008. }), !resolvedAbsolute).join('/');
  26009. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  26010. }
  26011. // path.normalize(path)
  26012. // posix version
  26013. function normalize$1(path) {
  26014. var isPathAbsolute = isAbsolute$1(path),
  26015. trailingSlash = substr(path, -1) === '/';
  26016. // Normalize the path
  26017. path = normalizeArray(filter(path.split('/'), function(p) {
  26018. return !!p;
  26019. }), !isPathAbsolute).join('/');
  26020. if (!path && !isPathAbsolute) {
  26021. path = '.';
  26022. }
  26023. if (path && trailingSlash) {
  26024. path += '/';
  26025. }
  26026. return (isPathAbsolute ? '/' : '') + path;
  26027. }
  26028. // posix version
  26029. function isAbsolute$1(path) {
  26030. return path.charAt(0) === '/';
  26031. }
  26032. // posix version
  26033. function join$1() {
  26034. var paths = Array.prototype.slice.call(arguments, 0);
  26035. return normalize$1(filter(paths, function(p, index) {
  26036. if (typeof p !== 'string') {
  26037. throw new TypeError('Arguments to path.join must be strings');
  26038. }
  26039. return p;
  26040. }).join('/'));
  26041. }
  26042. // path.relative(from, to)
  26043. // posix version
  26044. function relative$1(from, to) {
  26045. from = resolve$2(from).substr(1);
  26046. to = resolve$2(to).substr(1);
  26047. function trim(arr) {
  26048. var start = 0;
  26049. for (; start < arr.length; start++) {
  26050. if (arr[start] !== '') break;
  26051. }
  26052. var end = arr.length - 1;
  26053. for (; end >= 0; end--) {
  26054. if (arr[end] !== '') break;
  26055. }
  26056. if (start > end) return [];
  26057. return arr.slice(start, end - start + 1);
  26058. }
  26059. var fromParts = trim(from.split('/'));
  26060. var toParts = trim(to.split('/'));
  26061. var length = Math.min(fromParts.length, toParts.length);
  26062. var samePartsLength = length;
  26063. for (var i = 0; i < length; i++) {
  26064. if (fromParts[i] !== toParts[i]) {
  26065. samePartsLength = i;
  26066. break;
  26067. }
  26068. }
  26069. var outputParts = [];
  26070. for (var i = samePartsLength; i < fromParts.length; i++) {
  26071. outputParts.push('..');
  26072. }
  26073. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  26074. return outputParts.join('/');
  26075. }
  26076. var sep$1 = '/';
  26077. var delimiter$1 = ':';
  26078. function dirname$2(path) {
  26079. var result = splitPath(path),
  26080. root = result[0],
  26081. dir = result[1];
  26082. if (!root && !dir) {
  26083. // No dirname whatsoever
  26084. return '.';
  26085. }
  26086. if (dir) {
  26087. // It has a dirname, strip trailing slash
  26088. dir = dir.substr(0, dir.length - 1);
  26089. }
  26090. return root + dir;
  26091. }
  26092. function basename(path, ext) {
  26093. var f = splitPath(path)[2];
  26094. // TODO: make this comparison case-insensitive on windows?
  26095. if (ext && f.substr(-1 * ext.length) === ext) {
  26096. f = f.substr(0, f.length - ext.length);
  26097. }
  26098. return f;
  26099. }
  26100. function extname(path) {
  26101. return splitPath(path)[3];
  26102. }
  26103. var path = {
  26104. extname: extname,
  26105. basename: basename,
  26106. dirname: dirname$2,
  26107. sep: sep$1,
  26108. delimiter: delimiter$1,
  26109. relative: relative$1,
  26110. join: join$1,
  26111. isAbsolute: isAbsolute$1,
  26112. normalize: normalize$1,
  26113. resolve: resolve$2
  26114. };
  26115. function filter (xs, f) {
  26116. if (xs.filter) return xs.filter(f);
  26117. var res = [];
  26118. for (var i = 0; i < xs.length; i++) {
  26119. if (f(xs[i], i, xs)) res.push(xs[i]);
  26120. }
  26121. return res;
  26122. }
  26123. // String.prototype.substr - negative index don't work in IE8
  26124. var substr = 'ab'.substr(-1) === 'b' ?
  26125. function (str, start, len) { return str.substr(start, len) } :
  26126. function (str, start, len) {
  26127. if (start < 0) start = str.length + start;
  26128. return str.substr(start, len);
  26129. }
  26130. ;
  26131. var _polyfillNode_path = /*#__PURE__*/Object.freeze({
  26132. __proto__: null,
  26133. basename: basename,
  26134. default: path,
  26135. delimiter: delimiter$1,
  26136. dirname: dirname$2,
  26137. extname: extname,
  26138. isAbsolute: isAbsolute$1,
  26139. join: join$1,
  26140. normalize: normalize$1,
  26141. relative: relative$1,
  26142. resolve: resolve$2,
  26143. sep: sep$1
  26144. });
  26145. const UNKNOWN_TYPE = "Unknown";
  26146. function resolveObjectKey(node, computed) {
  26147. switch (node.type) {
  26148. case "StringLiteral":
  26149. case "NumericLiteral":
  26150. return String(node.value);
  26151. case "Identifier":
  26152. if (!computed)
  26153. return node.name;
  26154. }
  26155. return void 0;
  26156. }
  26157. function concatStrings(strs) {
  26158. return strs.filter((s) => !!s).join(", ");
  26159. }
  26160. function isLiteralNode(node) {
  26161. return node.type.endsWith("Literal");
  26162. }
  26163. function unwrapTSNode(node) {
  26164. if (TS_NODE_TYPES.includes(node.type)) {
  26165. return unwrapTSNode(node.expression);
  26166. } else {
  26167. return node;
  26168. }
  26169. }
  26170. function isCallOf(node, test) {
  26171. return !!(node && test && node.type === "CallExpression" && node.callee.type === "Identifier" && (typeof test === "string" ? node.callee.name === test : test(node.callee.name)));
  26172. }
  26173. function toRuntimeTypeString(types) {
  26174. return types.length > 1 ? `[${types.join(", ")}]` : types[0];
  26175. }
  26176. function getImportedName(specifier) {
  26177. if (specifier.type === "ImportSpecifier")
  26178. return specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
  26179. else if (specifier.type === "ImportNamespaceSpecifier")
  26180. return "*";
  26181. return "default";
  26182. }
  26183. function getId(node) {
  26184. return node.type === "Identifier" ? node.name : node.type === "StringLiteral" ? node.value : null;
  26185. }
  26186. const normalize = (path.posix || path).normalize;
  26187. const windowsSlashRE = /\\/g;
  26188. function normalizePath(p) {
  26189. return normalize(p.replace(windowsSlashRE, "/"));
  26190. }
  26191. const joinPaths = (path.posix || path).join;
  26192. const escapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g;
  26193. function getEscapedKey(key) {
  26194. return escapeSymbolsRE.test(key) ? JSON.stringify(key) : key;
  26195. }
  26196. function pad$1 (hash, len) {
  26197. while (hash.length < len) {
  26198. hash = '0' + hash;
  26199. }
  26200. return hash;
  26201. }
  26202. function fold (hash, text) {
  26203. var i;
  26204. var chr;
  26205. var len;
  26206. if (text.length === 0) {
  26207. return hash;
  26208. }
  26209. for (i = 0, len = text.length; i < len; i++) {
  26210. chr = text.charCodeAt(i);
  26211. hash = ((hash << 5) - hash) + chr;
  26212. hash |= 0;
  26213. }
  26214. return hash < 0 ? hash * -2 : hash;
  26215. }
  26216. function foldObject (hash, o, seen) {
  26217. return Object.keys(o).sort().reduce(foldKey, hash);
  26218. function foldKey (hash, key) {
  26219. return foldValue(hash, o[key], key, seen);
  26220. }
  26221. }
  26222. function foldValue (input, value, key, seen) {
  26223. var hash = fold(fold(fold(input, key), toString$2(value)), typeof value);
  26224. if (value === null) {
  26225. return fold(hash, 'null');
  26226. }
  26227. if (value === undefined) {
  26228. return fold(hash, 'undefined');
  26229. }
  26230. if (typeof value === 'object' || typeof value === 'function') {
  26231. if (seen.indexOf(value) !== -1) {
  26232. return fold(hash, '[Circular]' + key);
  26233. }
  26234. seen.push(value);
  26235. var objHash = foldObject(hash, value, seen);
  26236. if (!('valueOf' in value) || typeof value.valueOf !== 'function') {
  26237. return objHash;
  26238. }
  26239. try {
  26240. return fold(objHash, String(value.valueOf()))
  26241. } catch (err) {
  26242. return fold(objHash, '[valueOf exception]' + (err.stack || err.message))
  26243. }
  26244. }
  26245. return fold(hash, value.toString());
  26246. }
  26247. function toString$2 (o) {
  26248. return Object.prototype.toString.call(o);
  26249. }
  26250. function sum (o) {
  26251. return pad$1(foldValue(0, o, '', []).toString(16), 8);
  26252. }
  26253. var hashSum = sum;
  26254. var hash = hashSum;
  26255. const CSS_VARS_HELPER = `useCssVars`;
  26256. function genCssVarsFromList(vars, id, isProd, isSSR = false) {
  26257. return `{
  26258. ${vars.map(
  26259. (key) => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`
  26260. ).join(",\n ")}
  26261. }`;
  26262. }
  26263. function genVarName(id, raw, isProd) {
  26264. if (isProd) {
  26265. return hash(id + raw);
  26266. } else {
  26267. return `${id}-${raw.replace(escapeSymbolsRE, (s) => `\\${s}`)}`;
  26268. }
  26269. }
  26270. function normalizeExpression(exp) {
  26271. exp = exp.trim();
  26272. if (exp[0] === `'` && exp[exp.length - 1] === `'` || exp[0] === `"` && exp[exp.length - 1] === `"`) {
  26273. return exp.slice(1, -1);
  26274. }
  26275. return exp;
  26276. }
  26277. const vBindRE = /v-bind\s*\(/g;
  26278. function parseCssVars(sfc) {
  26279. const vars = [];
  26280. sfc.styles.forEach((style) => {
  26281. let match;
  26282. const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, "");
  26283. while (match = vBindRE.exec(content)) {
  26284. const start = match.index + match[0].length;
  26285. const end = lexBinding(content, start);
  26286. if (end !== null) {
  26287. const variable = normalizeExpression(content.slice(start, end));
  26288. if (!vars.includes(variable)) {
  26289. vars.push(variable);
  26290. }
  26291. }
  26292. }
  26293. });
  26294. return vars;
  26295. }
  26296. function lexBinding(content, start) {
  26297. let state = 0 /* inParens */;
  26298. let parenDepth = 0;
  26299. for (let i = start; i < content.length; i++) {
  26300. const char = content.charAt(i);
  26301. switch (state) {
  26302. case 0 /* inParens */:
  26303. if (char === `'`) {
  26304. state = 1 /* inSingleQuoteString */;
  26305. } else if (char === `"`) {
  26306. state = 2 /* inDoubleQuoteString */;
  26307. } else if (char === `(`) {
  26308. parenDepth++;
  26309. } else if (char === `)`) {
  26310. if (parenDepth > 0) {
  26311. parenDepth--;
  26312. } else {
  26313. return i;
  26314. }
  26315. }
  26316. break;
  26317. case 1 /* inSingleQuoteString */:
  26318. if (char === `'`) {
  26319. state = 0 /* inParens */;
  26320. }
  26321. break;
  26322. case 2 /* inDoubleQuoteString */:
  26323. if (char === `"`) {
  26324. state = 0 /* inParens */;
  26325. }
  26326. break;
  26327. }
  26328. }
  26329. return null;
  26330. }
  26331. const cssVarsPlugin = (opts) => {
  26332. const { id, isProd } = opts;
  26333. return {
  26334. postcssPlugin: "vue-sfc-vars",
  26335. Declaration(decl) {
  26336. const value = decl.value;
  26337. if (vBindRE.test(value)) {
  26338. vBindRE.lastIndex = 0;
  26339. let transformed = "";
  26340. let lastIndex = 0;
  26341. let match;
  26342. while (match = vBindRE.exec(value)) {
  26343. const start = match.index + match[0].length;
  26344. const end = lexBinding(value, start);
  26345. if (end !== null) {
  26346. const variable = normalizeExpression(value.slice(start, end));
  26347. transformed += value.slice(lastIndex, match.index) + `var(--${genVarName(id, variable, isProd)})`;
  26348. lastIndex = end + 1;
  26349. }
  26350. }
  26351. decl.value = transformed + value.slice(lastIndex);
  26352. }
  26353. }
  26354. };
  26355. };
  26356. cssVarsPlugin.postcss = true;
  26357. function genCssVarsCode(vars, bindings, id, isProd) {
  26358. const varsExp = genCssVarsFromList(vars, id, isProd);
  26359. const exp = createSimpleExpression(varsExp, false);
  26360. const context = createTransformContext(createRoot([]), {
  26361. prefixIdentifiers: true,
  26362. inline: true,
  26363. bindingMetadata: bindings.__isScriptSetup === false ? void 0 : bindings
  26364. });
  26365. const transformed = processExpression(exp, context);
  26366. const transformedString = transformed.type === 4 ? transformed.content : transformed.children.map((c) => {
  26367. return typeof c === "string" ? c : c.content;
  26368. }).join("");
  26369. return `_${CSS_VARS_HELPER}(_ctx => (${transformedString}))`;
  26370. }
  26371. function genNormalScriptCssVarsCode(cssVars, bindings, id, isProd, defaultVar) {
  26372. return `
  26373. import { ${CSS_VARS_HELPER} as _${CSS_VARS_HELPER} } from 'vue'
  26374. const __injectCSSVars__ = () => {
  26375. ${genCssVarsCode(
  26376. cssVars,
  26377. bindings,
  26378. id,
  26379. isProd
  26380. )}}
  26381. const __setup__ = ${defaultVar}.setup
  26382. ${defaultVar}.setup = __setup__
  26383. ? (props, ctx) => { __injectCSSVars__();return __setup__(props, ctx) }
  26384. : __injectCSSVars__
  26385. `;
  26386. }
  26387. function createCache(size = 500) {
  26388. {
  26389. return /* @__PURE__ */ new Map();
  26390. }
  26391. }
  26392. function isImportUsed(local, sfc) {
  26393. return new RegExp(
  26394. // #4274 escape $ since it's a special char in regex
  26395. // (and is the only regex special char that is valid in identifiers)
  26396. `[^\\w$_]${local.replace(/\$/g, "\\$")}[^\\w$_]`
  26397. ).test(resolveTemplateUsageCheckString(sfc));
  26398. }
  26399. const templateUsageCheckCache = createCache();
  26400. function resolveTemplateUsageCheckString(sfc) {
  26401. const { content, ast } = sfc.template;
  26402. const cached = templateUsageCheckCache.get(content);
  26403. if (cached) {
  26404. return cached;
  26405. }
  26406. let code = "";
  26407. transform$1(createRoot([ast]), {
  26408. nodeTransforms: [
  26409. (node) => {
  26410. if (node.type === 1) {
  26411. if (!parserOptions.isNativeTag(node.tag) && !parserOptions.isBuiltInComponent(node.tag)) {
  26412. code += `,${camelize(node.tag)},${capitalize$1(camelize(node.tag))}`;
  26413. }
  26414. for (let i = 0; i < node.props.length; i++) {
  26415. const prop = node.props[i];
  26416. if (prop.type === 7) {
  26417. if (!isBuiltInDirective(prop.name)) {
  26418. code += `,v${capitalize$1(camelize(prop.name))}`;
  26419. }
  26420. if (prop.exp) {
  26421. code += `,${processExp(
  26422. prop.exp.content,
  26423. prop.name
  26424. )}`;
  26425. }
  26426. }
  26427. }
  26428. } else if (node.type === 5) {
  26429. code += `,${processExp(
  26430. node.content.content
  26431. )}`;
  26432. }
  26433. }
  26434. ]
  26435. });
  26436. code += ";";
  26437. templateUsageCheckCache.set(content, code);
  26438. return code;
  26439. }
  26440. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  26441. function processExp(exp, dir) {
  26442. if (/ as\s+\w|<.*>|:/.test(exp)) {
  26443. if (dir === "slot") {
  26444. exp = `(${exp})=>{}`;
  26445. } else if (dir === "on") {
  26446. exp = `()=>{return ${exp}}`;
  26447. } else if (dir === "for") {
  26448. const inMatch = exp.match(forAliasRE);
  26449. if (inMatch) {
  26450. let [, LHS, RHS] = inMatch;
  26451. LHS = LHS.trim().replace(/^\(|\)$/g, "");
  26452. return processExp(`(${LHS})=>{}`) + processExp(RHS);
  26453. }
  26454. }
  26455. let ret = "";
  26456. const ast = parseExpression_1(exp, { plugins: ["typescript"] });
  26457. walkIdentifiers(ast, (node) => {
  26458. ret += `,` + node.name;
  26459. });
  26460. return ret;
  26461. }
  26462. return stripStrings(exp);
  26463. }
  26464. function stripStrings(exp) {
  26465. return exp.replace(/'[^']*'|"[^"]*"/g, "").replace(/`[^`]+`/g, stripTemplateString);
  26466. }
  26467. function stripTemplateString(str) {
  26468. const interpMatch = str.match(/\${[^}]+}/g);
  26469. if (interpMatch) {
  26470. return interpMatch.map((m) => m.slice(2, -1)).join(",");
  26471. }
  26472. return "";
  26473. }
  26474. var __defProp$a = Object.defineProperty;
  26475. var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
  26476. var __hasOwnProp$a = Object.prototype.hasOwnProperty;
  26477. var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
  26478. var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  26479. var __spreadValues$a = (a, b) => {
  26480. for (var prop in b || (b = {}))
  26481. if (__hasOwnProp$a.call(b, prop))
  26482. __defNormalProp$a(a, prop, b[prop]);
  26483. if (__getOwnPropSymbols$a)
  26484. for (var prop of __getOwnPropSymbols$a(b)) {
  26485. if (__propIsEnum$a.call(b, prop))
  26486. __defNormalProp$a(a, prop, b[prop]);
  26487. }
  26488. return a;
  26489. };
  26490. const DEFAULT_FILENAME = "anonymous.vue";
  26491. const parseCache = createCache();
  26492. function parse$7(source, {
  26493. sourceMap = true,
  26494. filename = DEFAULT_FILENAME,
  26495. sourceRoot = "",
  26496. pad = false,
  26497. ignoreEmpty = true,
  26498. compiler = CompilerDOM
  26499. } = {}) {
  26500. const sourceKey = source + sourceMap + filename + sourceRoot + pad + compiler.parse;
  26501. const cache = parseCache.get(sourceKey);
  26502. if (cache) {
  26503. return cache;
  26504. }
  26505. const descriptor = {
  26506. filename,
  26507. source,
  26508. template: null,
  26509. script: null,
  26510. scriptSetup: null,
  26511. styles: [],
  26512. customBlocks: [],
  26513. cssVars: [],
  26514. slotted: false,
  26515. shouldForceReload: (prevImports) => hmrShouldReload(prevImports, descriptor)
  26516. };
  26517. const errors = [];
  26518. const ast = compiler.parse(source, {
  26519. // there are no components at SFC parsing level
  26520. isNativeTag: () => true,
  26521. // preserve all whitespaces
  26522. isPreTag: () => true,
  26523. getTextMode: ({ tag, props }, parent) => {
  26524. if (!parent && tag !== "template" || // <template lang="xxx"> should also be treated as raw text
  26525. tag === "template" && props.some(
  26526. (p) => p.type === 6 && p.name === "lang" && p.value && p.value.content && p.value.content !== "html"
  26527. )) {
  26528. return 2;
  26529. } else {
  26530. return 0;
  26531. }
  26532. },
  26533. onError: (e) => {
  26534. errors.push(e);
  26535. }
  26536. });
  26537. ast.children.forEach((node) => {
  26538. if (node.type !== 1) {
  26539. return;
  26540. }
  26541. if (ignoreEmpty && node.tag !== "template" && isEmpty(node) && !hasSrc(node)) {
  26542. return;
  26543. }
  26544. switch (node.tag) {
  26545. case "template":
  26546. if (!descriptor.template) {
  26547. const templateBlock = descriptor.template = createBlock(
  26548. node,
  26549. source,
  26550. false
  26551. );
  26552. templateBlock.ast = node;
  26553. if (templateBlock.attrs.functional) {
  26554. const err = new SyntaxError(
  26555. `<template functional> is no longer supported in Vue 3, since functional components no longer have significant performance difference from stateful ones. Just use a normal <template> instead.`
  26556. );
  26557. err.loc = node.props.find((p) => p.name === "functional").loc;
  26558. errors.push(err);
  26559. }
  26560. } else {
  26561. errors.push(createDuplicateBlockError(node));
  26562. }
  26563. break;
  26564. case "script":
  26565. const scriptBlock = createBlock(node, source, pad);
  26566. const isSetup = !!scriptBlock.attrs.setup;
  26567. if (isSetup && !descriptor.scriptSetup) {
  26568. descriptor.scriptSetup = scriptBlock;
  26569. break;
  26570. }
  26571. if (!isSetup && !descriptor.script) {
  26572. descriptor.script = scriptBlock;
  26573. break;
  26574. }
  26575. errors.push(createDuplicateBlockError(node, isSetup));
  26576. break;
  26577. case "style":
  26578. const styleBlock = createBlock(node, source, pad);
  26579. if (styleBlock.attrs.vars) {
  26580. errors.push(
  26581. new SyntaxError(
  26582. `<style vars> has been replaced by a new proposal: https://github.com/vuejs/rfcs/pull/231`
  26583. )
  26584. );
  26585. }
  26586. descriptor.styles.push(styleBlock);
  26587. break;
  26588. default:
  26589. descriptor.customBlocks.push(createBlock(node, source, pad));
  26590. break;
  26591. }
  26592. });
  26593. if (!descriptor.template && !descriptor.script && !descriptor.scriptSetup) {
  26594. errors.push(
  26595. new SyntaxError(
  26596. `At least one <template> or <script> is required in a single file component.`
  26597. )
  26598. );
  26599. }
  26600. if (descriptor.scriptSetup) {
  26601. if (descriptor.scriptSetup.src) {
  26602. errors.push(
  26603. new SyntaxError(
  26604. `<script setup> cannot use the "src" attribute because its syntax will be ambiguous outside of the component.`
  26605. )
  26606. );
  26607. descriptor.scriptSetup = null;
  26608. }
  26609. if (descriptor.script && descriptor.script.src) {
  26610. errors.push(
  26611. new SyntaxError(
  26612. `<script> cannot use the "src" attribute when <script setup> is also present because they must be processed together.`
  26613. )
  26614. );
  26615. descriptor.script = null;
  26616. }
  26617. }
  26618. if (sourceMap) {
  26619. const genMap = (block) => {
  26620. if (block && !block.src) {
  26621. block.map = generateSourceMap(
  26622. filename,
  26623. source,
  26624. block.content,
  26625. sourceRoot,
  26626. !pad || block.type === "template" ? block.loc.start.line - 1 : 0
  26627. );
  26628. }
  26629. };
  26630. genMap(descriptor.template);
  26631. genMap(descriptor.script);
  26632. descriptor.styles.forEach(genMap);
  26633. descriptor.customBlocks.forEach(genMap);
  26634. }
  26635. descriptor.cssVars = parseCssVars(descriptor);
  26636. const slottedRE = /(?:::v-|:)slotted\(/;
  26637. descriptor.slotted = descriptor.styles.some(
  26638. (s) => s.scoped && slottedRE.test(s.content)
  26639. );
  26640. const result = {
  26641. descriptor,
  26642. errors
  26643. };
  26644. parseCache.set(sourceKey, result);
  26645. return result;
  26646. }
  26647. function createDuplicateBlockError(node, isScriptSetup = false) {
  26648. const err = new SyntaxError(
  26649. `Single file component can contain only one <${node.tag}${isScriptSetup ? ` setup` : ``}> element`
  26650. );
  26651. err.loc = node.loc;
  26652. return err;
  26653. }
  26654. function createBlock(node, source, pad) {
  26655. const type = node.tag;
  26656. let { start, end } = node.loc;
  26657. let content = "";
  26658. if (node.children.length) {
  26659. start = node.children[0].loc.start;
  26660. end = node.children[node.children.length - 1].loc.end;
  26661. content = source.slice(start.offset, end.offset);
  26662. } else {
  26663. const offset = node.loc.source.indexOf(`</`);
  26664. if (offset > -1) {
  26665. start = {
  26666. line: start.line,
  26667. column: start.column + offset,
  26668. offset: start.offset + offset
  26669. };
  26670. }
  26671. end = __spreadValues$a({}, start);
  26672. }
  26673. const loc = {
  26674. source: content,
  26675. start,
  26676. end
  26677. };
  26678. const attrs = {};
  26679. const block = {
  26680. type,
  26681. content,
  26682. loc,
  26683. attrs
  26684. };
  26685. if (pad) {
  26686. block.content = padContent(source, block, pad) + block.content;
  26687. }
  26688. node.props.forEach((p) => {
  26689. if (p.type === 6) {
  26690. attrs[p.name] = p.value ? p.value.content || true : true;
  26691. if (p.name === "lang") {
  26692. block.lang = p.value && p.value.content;
  26693. } else if (p.name === "src") {
  26694. block.src = p.value && p.value.content;
  26695. } else if (type === "style") {
  26696. if (p.name === "scoped") {
  26697. block.scoped = true;
  26698. } else if (p.name === "module") {
  26699. block.module = attrs[p.name];
  26700. }
  26701. } else if (type === "script" && p.name === "setup") {
  26702. block.setup = attrs.setup;
  26703. }
  26704. }
  26705. });
  26706. return block;
  26707. }
  26708. const splitRE = /\r?\n/g;
  26709. const emptyRE = /^(?:\/\/)?\s*$/;
  26710. const replaceRE = /./g;
  26711. function generateSourceMap(filename, source, generated, sourceRoot, lineOffset) {
  26712. const map = new SourceMapGenerator$6({
  26713. file: filename.replace(/\\/g, "/"),
  26714. sourceRoot: sourceRoot.replace(/\\/g, "/")
  26715. });
  26716. map.setSourceContent(filename, source);
  26717. generated.split(splitRE).forEach((line, index) => {
  26718. if (!emptyRE.test(line)) {
  26719. const originalLine = index + 1 + lineOffset;
  26720. const generatedLine = index + 1;
  26721. for (let i = 0; i < line.length; i++) {
  26722. if (!/\s/.test(line[i])) {
  26723. map.addMapping({
  26724. source: filename,
  26725. original: {
  26726. line: originalLine,
  26727. column: i
  26728. },
  26729. generated: {
  26730. line: generatedLine,
  26731. column: i
  26732. }
  26733. });
  26734. }
  26735. }
  26736. }
  26737. });
  26738. return JSON.parse(map.toString());
  26739. }
  26740. function padContent(content, block, pad) {
  26741. content = content.slice(0, block.loc.start.offset);
  26742. if (pad === "space") {
  26743. return content.replace(replaceRE, " ");
  26744. } else {
  26745. const offset = content.split(splitRE).length;
  26746. const padChar = block.type === "script" && !block.lang ? "//\n" : "\n";
  26747. return Array(offset).join(padChar);
  26748. }
  26749. }
  26750. function hasSrc(node) {
  26751. return node.props.some((p) => {
  26752. if (p.type !== 6) {
  26753. return false;
  26754. }
  26755. return p.name === "src";
  26756. });
  26757. }
  26758. function isEmpty(node) {
  26759. for (let i = 0; i < node.children.length; i++) {
  26760. const child = node.children[i];
  26761. if (child.type !== 2 || child.content.trim() !== "") {
  26762. return false;
  26763. }
  26764. }
  26765. return true;
  26766. }
  26767. function hmrShouldReload(prevImports, next) {
  26768. if (!next.scriptSetup || next.scriptSetup.lang !== "ts" && next.scriptSetup.lang !== "tsx") {
  26769. return false;
  26770. }
  26771. for (const key in prevImports) {
  26772. if (!prevImports[key].isUsedInTemplate && isImportUsed(key, next)) {
  26773. return true;
  26774. }
  26775. }
  26776. return false;
  26777. }
  26778. var global$1 = (typeof global !== "undefined" ? global :
  26779. typeof self !== "undefined" ? self :
  26780. typeof window !== "undefined" ? window : {});
  26781. /*! https://mths.be/punycode v1.4.1 by @mathias */
  26782. /** Highest positive signed 32-bit float value */
  26783. var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
  26784. /** Bootstring parameters */
  26785. var base = 36;
  26786. var tMin = 1;
  26787. var tMax = 26;
  26788. var skew = 38;
  26789. var damp = 700;
  26790. var initialBias = 72;
  26791. var initialN = 128; // 0x80
  26792. var delimiter = '-'; // '\x2D'
  26793. var regexNonASCII = /[^\x20-\x7E]/; // unprintable ASCII chars + non-ASCII chars
  26794. var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
  26795. /** Error messages */
  26796. var errors = {
  26797. 'overflow': 'Overflow: input needs wider integers to process',
  26798. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  26799. 'invalid-input': 'Invalid input'
  26800. };
  26801. /** Convenience shortcuts */
  26802. var baseMinusTMin = base - tMin;
  26803. var floor = Math.floor;
  26804. var stringFromCharCode = String.fromCharCode;
  26805. /*--------------------------------------------------------------------------*/
  26806. /**
  26807. * A generic error utility function.
  26808. * @private
  26809. * @param {String} type The error type.
  26810. * @returns {Error} Throws a `RangeError` with the applicable error message.
  26811. */
  26812. function error(type) {
  26813. throw new RangeError(errors[type]);
  26814. }
  26815. /**
  26816. * A generic `Array#map` utility function.
  26817. * @private
  26818. * @param {Array} array The array to iterate over.
  26819. * @param {Function} callback The function that gets called for every array
  26820. * item.
  26821. * @returns {Array} A new array of values returned by the callback function.
  26822. */
  26823. function map$1(array, fn) {
  26824. var length = array.length;
  26825. var result = [];
  26826. while (length--) {
  26827. result[length] = fn(array[length]);
  26828. }
  26829. return result;
  26830. }
  26831. /**
  26832. * A simple `Array#map`-like wrapper to work with domain name strings or email
  26833. * addresses.
  26834. * @private
  26835. * @param {String} domain The domain name or email address.
  26836. * @param {Function} callback The function that gets called for every
  26837. * character.
  26838. * @returns {Array} A new string of characters returned by the callback
  26839. * function.
  26840. */
  26841. function mapDomain(string, fn) {
  26842. var parts = string.split('@');
  26843. var result = '';
  26844. if (parts.length > 1) {
  26845. // In email addresses, only the domain name should be punycoded. Leave
  26846. // the local part (i.e. everything up to `@`) intact.
  26847. result = parts[0] + '@';
  26848. string = parts[1];
  26849. }
  26850. // Avoid `split(regex)` for IE8 compatibility. See #17.
  26851. string = string.replace(regexSeparators, '\x2E');
  26852. var labels = string.split('.');
  26853. var encoded = map$1(labels, fn).join('.');
  26854. return result + encoded;
  26855. }
  26856. /**
  26857. * Creates an array containing the numeric code points of each Unicode
  26858. * character in the string. While JavaScript uses UCS-2 internally,
  26859. * this function will convert a pair of surrogate halves (each of which
  26860. * UCS-2 exposes as separate characters) into a single code point,
  26861. * matching UTF-16.
  26862. * @see `punycode.ucs2.encode`
  26863. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  26864. * @memberOf punycode.ucs2
  26865. * @name decode
  26866. * @param {String} string The Unicode input string (UCS-2).
  26867. * @returns {Array} The new array of code points.
  26868. */
  26869. function ucs2decode(string) {
  26870. var output = [],
  26871. counter = 0,
  26872. length = string.length,
  26873. value,
  26874. extra;
  26875. while (counter < length) {
  26876. value = string.charCodeAt(counter++);
  26877. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  26878. // high surrogate, and there is a next character
  26879. extra = string.charCodeAt(counter++);
  26880. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  26881. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  26882. } else {
  26883. // unmatched surrogate; only append this code unit, in case the next
  26884. // code unit is the high surrogate of a surrogate pair
  26885. output.push(value);
  26886. counter--;
  26887. }
  26888. } else {
  26889. output.push(value);
  26890. }
  26891. }
  26892. return output;
  26893. }
  26894. /**
  26895. * Converts a digit/integer into a basic code point.
  26896. * @see `basicToDigit()`
  26897. * @private
  26898. * @param {Number} digit The numeric value of a basic code point.
  26899. * @returns {Number} The basic code point whose value (when used for
  26900. * representing integers) is `digit`, which needs to be in the range
  26901. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  26902. * used; else, the lowercase form is used. The behavior is undefined
  26903. * if `flag` is non-zero and `digit` has no uppercase form.
  26904. */
  26905. function digitToBasic(digit, flag) {
  26906. // 0..25 map to ASCII a..z or A..Z
  26907. // 26..35 map to ASCII 0..9
  26908. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  26909. }
  26910. /**
  26911. * Bias adaptation function as per section 3.4 of RFC 3492.
  26912. * https://tools.ietf.org/html/rfc3492#section-3.4
  26913. * @private
  26914. */
  26915. function adapt(delta, numPoints, firstTime) {
  26916. var k = 0;
  26917. delta = firstTime ? floor(delta / damp) : delta >> 1;
  26918. delta += floor(delta / numPoints);
  26919. for ( /* no initialization */ ; delta > baseMinusTMin * tMax >> 1; k += base) {
  26920. delta = floor(delta / baseMinusTMin);
  26921. }
  26922. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  26923. }
  26924. /**
  26925. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  26926. * Punycode string of ASCII-only symbols.
  26927. * @memberOf punycode
  26928. * @param {String} input The string of Unicode symbols.
  26929. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  26930. */
  26931. function encode$1(input) {
  26932. var n,
  26933. delta,
  26934. handledCPCount,
  26935. basicLength,
  26936. bias,
  26937. j,
  26938. m,
  26939. q,
  26940. k,
  26941. t,
  26942. currentValue,
  26943. output = [],
  26944. /** `inputLength` will hold the number of code points in `input`. */
  26945. inputLength,
  26946. /** Cached calculation results */
  26947. handledCPCountPlusOne,
  26948. baseMinusT,
  26949. qMinusT;
  26950. // Convert the input in UCS-2 to Unicode
  26951. input = ucs2decode(input);
  26952. // Cache the length
  26953. inputLength = input.length;
  26954. // Initialize the state
  26955. n = initialN;
  26956. delta = 0;
  26957. bias = initialBias;
  26958. // Handle the basic code points
  26959. for (j = 0; j < inputLength; ++j) {
  26960. currentValue = input[j];
  26961. if (currentValue < 0x80) {
  26962. output.push(stringFromCharCode(currentValue));
  26963. }
  26964. }
  26965. handledCPCount = basicLength = output.length;
  26966. // `handledCPCount` is the number of code points that have been handled;
  26967. // `basicLength` is the number of basic code points.
  26968. // Finish the basic string - if it is not empty - with a delimiter
  26969. if (basicLength) {
  26970. output.push(delimiter);
  26971. }
  26972. // Main encoding loop:
  26973. while (handledCPCount < inputLength) {
  26974. // All non-basic code points < n have been handled already. Find the next
  26975. // larger one:
  26976. for (m = maxInt, j = 0; j < inputLength; ++j) {
  26977. currentValue = input[j];
  26978. if (currentValue >= n && currentValue < m) {
  26979. m = currentValue;
  26980. }
  26981. }
  26982. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  26983. // but guard against overflow
  26984. handledCPCountPlusOne = handledCPCount + 1;
  26985. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  26986. error('overflow');
  26987. }
  26988. delta += (m - n) * handledCPCountPlusOne;
  26989. n = m;
  26990. for (j = 0; j < inputLength; ++j) {
  26991. currentValue = input[j];
  26992. if (currentValue < n && ++delta > maxInt) {
  26993. error('overflow');
  26994. }
  26995. if (currentValue == n) {
  26996. // Represent delta as a generalized variable-length integer
  26997. for (q = delta, k = base; /* no condition */ ; k += base) {
  26998. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  26999. if (q < t) {
  27000. break;
  27001. }
  27002. qMinusT = q - t;
  27003. baseMinusT = base - t;
  27004. output.push(
  27005. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  27006. );
  27007. q = floor(qMinusT / baseMinusT);
  27008. }
  27009. output.push(stringFromCharCode(digitToBasic(q, 0)));
  27010. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  27011. delta = 0;
  27012. ++handledCPCount;
  27013. }
  27014. }
  27015. ++delta;
  27016. ++n;
  27017. }
  27018. return output.join('');
  27019. }
  27020. /**
  27021. * Converts a Unicode string representing a domain name or an email address to
  27022. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  27023. * i.e. it doesn't matter if you call it with a domain that's already in
  27024. * ASCII.
  27025. * @memberOf punycode
  27026. * @param {String} input The domain name or email address to convert, as a
  27027. * Unicode string.
  27028. * @returns {String} The Punycode representation of the given domain name or
  27029. * email address.
  27030. */
  27031. function toASCII(input) {
  27032. return mapDomain(input, function(string) {
  27033. return regexNonASCII.test(string) ?
  27034. 'xn--' + encode$1(string) :
  27035. string;
  27036. });
  27037. }
  27038. var lookup = [];
  27039. var revLookup = [];
  27040. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  27041. var inited = false;
  27042. function init () {
  27043. inited = true;
  27044. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  27045. for (var i = 0, len = code.length; i < len; ++i) {
  27046. lookup[i] = code[i];
  27047. revLookup[code.charCodeAt(i)] = i;
  27048. }
  27049. revLookup['-'.charCodeAt(0)] = 62;
  27050. revLookup['_'.charCodeAt(0)] = 63;
  27051. }
  27052. function toByteArray (b64) {
  27053. if (!inited) {
  27054. init();
  27055. }
  27056. var i, j, l, tmp, placeHolders, arr;
  27057. var len = b64.length;
  27058. if (len % 4 > 0) {
  27059. throw new Error('Invalid string. Length must be a multiple of 4')
  27060. }
  27061. // the number of equal signs (place holders)
  27062. // if there are two placeholders, than the two characters before it
  27063. // represent one byte
  27064. // if there is only one, then the three characters before it represent 2 bytes
  27065. // this is just a cheap hack to not do indexOf twice
  27066. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
  27067. // base64 is 4/3 + up to two characters of the original data
  27068. arr = new Arr(len * 3 / 4 - placeHolders);
  27069. // if there are placeholders, only get up to the last complete 4 chars
  27070. l = placeHolders > 0 ? len - 4 : len;
  27071. var L = 0;
  27072. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  27073. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
  27074. arr[L++] = (tmp >> 16) & 0xFF;
  27075. arr[L++] = (tmp >> 8) & 0xFF;
  27076. arr[L++] = tmp & 0xFF;
  27077. }
  27078. if (placeHolders === 2) {
  27079. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
  27080. arr[L++] = tmp & 0xFF;
  27081. } else if (placeHolders === 1) {
  27082. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
  27083. arr[L++] = (tmp >> 8) & 0xFF;
  27084. arr[L++] = tmp & 0xFF;
  27085. }
  27086. return arr
  27087. }
  27088. function tripletToBase64 (num) {
  27089. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  27090. }
  27091. function encodeChunk (uint8, start, end) {
  27092. var tmp;
  27093. var output = [];
  27094. for (var i = start; i < end; i += 3) {
  27095. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
  27096. output.push(tripletToBase64(tmp));
  27097. }
  27098. return output.join('')
  27099. }
  27100. function fromByteArray (uint8) {
  27101. if (!inited) {
  27102. init();
  27103. }
  27104. var tmp;
  27105. var len = uint8.length;
  27106. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  27107. var output = '';
  27108. var parts = [];
  27109. var maxChunkLength = 16383; // must be multiple of 3
  27110. // go through the array every three bytes, we'll deal with trailing stuff later
  27111. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  27112. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
  27113. }
  27114. // pad the end with zeros, but make sure to not forget the extra bytes
  27115. if (extraBytes === 1) {
  27116. tmp = uint8[len - 1];
  27117. output += lookup[tmp >> 2];
  27118. output += lookup[(tmp << 4) & 0x3F];
  27119. output += '==';
  27120. } else if (extraBytes === 2) {
  27121. tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
  27122. output += lookup[tmp >> 10];
  27123. output += lookup[(tmp >> 4) & 0x3F];
  27124. output += lookup[(tmp << 2) & 0x3F];
  27125. output += '=';
  27126. }
  27127. parts.push(output);
  27128. return parts.join('')
  27129. }
  27130. function read (buffer, offset, isLE, mLen, nBytes) {
  27131. var e, m;
  27132. var eLen = nBytes * 8 - mLen - 1;
  27133. var eMax = (1 << eLen) - 1;
  27134. var eBias = eMax >> 1;
  27135. var nBits = -7;
  27136. var i = isLE ? (nBytes - 1) : 0;
  27137. var d = isLE ? -1 : 1;
  27138. var s = buffer[offset + i];
  27139. i += d;
  27140. e = s & ((1 << (-nBits)) - 1);
  27141. s >>= (-nBits);
  27142. nBits += eLen;
  27143. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  27144. m = e & ((1 << (-nBits)) - 1);
  27145. e >>= (-nBits);
  27146. nBits += mLen;
  27147. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  27148. if (e === 0) {
  27149. e = 1 - eBias;
  27150. } else if (e === eMax) {
  27151. return m ? NaN : ((s ? -1 : 1) * Infinity)
  27152. } else {
  27153. m = m + Math.pow(2, mLen);
  27154. e = e - eBias;
  27155. }
  27156. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  27157. }
  27158. function write (buffer, value, offset, isLE, mLen, nBytes) {
  27159. var e, m, c;
  27160. var eLen = nBytes * 8 - mLen - 1;
  27161. var eMax = (1 << eLen) - 1;
  27162. var eBias = eMax >> 1;
  27163. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
  27164. var i = isLE ? 0 : (nBytes - 1);
  27165. var d = isLE ? 1 : -1;
  27166. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  27167. value = Math.abs(value);
  27168. if (isNaN(value) || value === Infinity) {
  27169. m = isNaN(value) ? 1 : 0;
  27170. e = eMax;
  27171. } else {
  27172. e = Math.floor(Math.log(value) / Math.LN2);
  27173. if (value * (c = Math.pow(2, -e)) < 1) {
  27174. e--;
  27175. c *= 2;
  27176. }
  27177. if (e + eBias >= 1) {
  27178. value += rt / c;
  27179. } else {
  27180. value += rt * Math.pow(2, 1 - eBias);
  27181. }
  27182. if (value * c >= 2) {
  27183. e++;
  27184. c /= 2;
  27185. }
  27186. if (e + eBias >= eMax) {
  27187. m = 0;
  27188. e = eMax;
  27189. } else if (e + eBias >= 1) {
  27190. m = (value * c - 1) * Math.pow(2, mLen);
  27191. e = e + eBias;
  27192. } else {
  27193. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  27194. e = 0;
  27195. }
  27196. }
  27197. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  27198. e = (e << mLen) | m;
  27199. eLen += mLen;
  27200. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  27201. buffer[offset + i - d] |= s * 128;
  27202. }
  27203. var toString$1 = {}.toString;
  27204. var isArray$2 = Array.isArray || function (arr) {
  27205. return toString$1.call(arr) == '[object Array]';
  27206. };
  27207. /*!
  27208. * The buffer module from node.js, for the browser.
  27209. *
  27210. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  27211. * @license MIT
  27212. */
  27213. var INSPECT_MAX_BYTES = 50;
  27214. /**
  27215. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  27216. * === true Use Uint8Array implementation (fastest)
  27217. * === false Use Object implementation (most compatible, even IE6)
  27218. *
  27219. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  27220. * Opera 11.6+, iOS 4.2+.
  27221. *
  27222. * Due to various browser bugs, sometimes the Object implementation will be used even
  27223. * when the browser supports typed arrays.
  27224. *
  27225. * Note:
  27226. *
  27227. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  27228. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  27229. *
  27230. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  27231. *
  27232. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  27233. * incorrect length in some situations.
  27234. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  27235. * get the Object implementation, which is slower but behaves correctly.
  27236. */
  27237. Buffer$1.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
  27238. ? global$1.TYPED_ARRAY_SUPPORT
  27239. : true;
  27240. /*
  27241. * Export kMaxLength after typed array support is determined.
  27242. */
  27243. kMaxLength();
  27244. function kMaxLength () {
  27245. return Buffer$1.TYPED_ARRAY_SUPPORT
  27246. ? 0x7fffffff
  27247. : 0x3fffffff
  27248. }
  27249. function createBuffer (that, length) {
  27250. if (kMaxLength() < length) {
  27251. throw new RangeError('Invalid typed array length')
  27252. }
  27253. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27254. // Return an augmented `Uint8Array` instance, for best performance
  27255. that = new Uint8Array(length);
  27256. that.__proto__ = Buffer$1.prototype;
  27257. } else {
  27258. // Fallback: Return an object instance of the Buffer class
  27259. if (that === null) {
  27260. that = new Buffer$1(length);
  27261. }
  27262. that.length = length;
  27263. }
  27264. return that
  27265. }
  27266. /**
  27267. * The Buffer constructor returns instances of `Uint8Array` that have their
  27268. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  27269. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  27270. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  27271. * returns a single octet.
  27272. *
  27273. * The `Uint8Array` prototype remains unmodified.
  27274. */
  27275. function Buffer$1 (arg, encodingOrOffset, length) {
  27276. if (!Buffer$1.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer$1)) {
  27277. return new Buffer$1(arg, encodingOrOffset, length)
  27278. }
  27279. // Common case.
  27280. if (typeof arg === 'number') {
  27281. if (typeof encodingOrOffset === 'string') {
  27282. throw new Error(
  27283. 'If encoding is specified then the first argument must be a string'
  27284. )
  27285. }
  27286. return allocUnsafe(this, arg)
  27287. }
  27288. return from(this, arg, encodingOrOffset, length)
  27289. }
  27290. Buffer$1.poolSize = 8192; // not used by this implementation
  27291. // TODO: Legacy, not needed anymore. Remove in next major version.
  27292. Buffer$1._augment = function (arr) {
  27293. arr.__proto__ = Buffer$1.prototype;
  27294. return arr
  27295. };
  27296. function from (that, value, encodingOrOffset, length) {
  27297. if (typeof value === 'number') {
  27298. throw new TypeError('"value" argument must not be a number')
  27299. }
  27300. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  27301. return fromArrayBuffer(that, value, encodingOrOffset, length)
  27302. }
  27303. if (typeof value === 'string') {
  27304. return fromString(that, value, encodingOrOffset)
  27305. }
  27306. return fromObject(that, value)
  27307. }
  27308. /**
  27309. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  27310. * if value is a number.
  27311. * Buffer.from(str[, encoding])
  27312. * Buffer.from(array)
  27313. * Buffer.from(buffer)
  27314. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  27315. **/
  27316. Buffer$1.from = function (value, encodingOrOffset, length) {
  27317. return from(null, value, encodingOrOffset, length)
  27318. };
  27319. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27320. Buffer$1.prototype.__proto__ = Uint8Array.prototype;
  27321. Buffer$1.__proto__ = Uint8Array;
  27322. if (typeof Symbol !== 'undefined' && Symbol.species &&
  27323. Buffer$1[Symbol.species] === Buffer$1) ;
  27324. }
  27325. function assertSize (size) {
  27326. if (typeof size !== 'number') {
  27327. throw new TypeError('"size" argument must be a number')
  27328. } else if (size < 0) {
  27329. throw new RangeError('"size" argument must not be negative')
  27330. }
  27331. }
  27332. function alloc (that, size, fill, encoding) {
  27333. assertSize(size);
  27334. if (size <= 0) {
  27335. return createBuffer(that, size)
  27336. }
  27337. if (fill !== undefined) {
  27338. // Only pay attention to encoding if it's a string. This
  27339. // prevents accidentally sending in a number that would
  27340. // be interpretted as a start offset.
  27341. return typeof encoding === 'string'
  27342. ? createBuffer(that, size).fill(fill, encoding)
  27343. : createBuffer(that, size).fill(fill)
  27344. }
  27345. return createBuffer(that, size)
  27346. }
  27347. /**
  27348. * Creates a new filled Buffer instance.
  27349. * alloc(size[, fill[, encoding]])
  27350. **/
  27351. Buffer$1.alloc = function (size, fill, encoding) {
  27352. return alloc(null, size, fill, encoding)
  27353. };
  27354. function allocUnsafe (that, size) {
  27355. assertSize(size);
  27356. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
  27357. if (!Buffer$1.TYPED_ARRAY_SUPPORT) {
  27358. for (var i = 0; i < size; ++i) {
  27359. that[i] = 0;
  27360. }
  27361. }
  27362. return that
  27363. }
  27364. /**
  27365. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  27366. * */
  27367. Buffer$1.allocUnsafe = function (size) {
  27368. return allocUnsafe(null, size)
  27369. };
  27370. /**
  27371. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  27372. */
  27373. Buffer$1.allocUnsafeSlow = function (size) {
  27374. return allocUnsafe(null, size)
  27375. };
  27376. function fromString (that, string, encoding) {
  27377. if (typeof encoding !== 'string' || encoding === '') {
  27378. encoding = 'utf8';
  27379. }
  27380. if (!Buffer$1.isEncoding(encoding)) {
  27381. throw new TypeError('"encoding" must be a valid string encoding')
  27382. }
  27383. var length = byteLength(string, encoding) | 0;
  27384. that = createBuffer(that, length);
  27385. var actual = that.write(string, encoding);
  27386. if (actual !== length) {
  27387. // Writing a hex string, for example, that contains invalid characters will
  27388. // cause everything after the first invalid character to be ignored. (e.g.
  27389. // 'abxxcd' will be treated as 'ab')
  27390. that = that.slice(0, actual);
  27391. }
  27392. return that
  27393. }
  27394. function fromArrayLike (that, array) {
  27395. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  27396. that = createBuffer(that, length);
  27397. for (var i = 0; i < length; i += 1) {
  27398. that[i] = array[i] & 255;
  27399. }
  27400. return that
  27401. }
  27402. function fromArrayBuffer (that, array, byteOffset, length) {
  27403. array.byteLength; // this throws if `array` is not a valid ArrayBuffer
  27404. if (byteOffset < 0 || array.byteLength < byteOffset) {
  27405. throw new RangeError('\'offset\' is out of bounds')
  27406. }
  27407. if (array.byteLength < byteOffset + (length || 0)) {
  27408. throw new RangeError('\'length\' is out of bounds')
  27409. }
  27410. if (byteOffset === undefined && length === undefined) {
  27411. array = new Uint8Array(array);
  27412. } else if (length === undefined) {
  27413. array = new Uint8Array(array, byteOffset);
  27414. } else {
  27415. array = new Uint8Array(array, byteOffset, length);
  27416. }
  27417. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27418. // Return an augmented `Uint8Array` instance, for best performance
  27419. that = array;
  27420. that.__proto__ = Buffer$1.prototype;
  27421. } else {
  27422. // Fallback: Return an object instance of the Buffer class
  27423. that = fromArrayLike(that, array);
  27424. }
  27425. return that
  27426. }
  27427. function fromObject (that, obj) {
  27428. if (internalIsBuffer(obj)) {
  27429. var len = checked(obj.length) | 0;
  27430. that = createBuffer(that, len);
  27431. if (that.length === 0) {
  27432. return that
  27433. }
  27434. obj.copy(that, 0, 0, len);
  27435. return that
  27436. }
  27437. if (obj) {
  27438. if ((typeof ArrayBuffer !== 'undefined' &&
  27439. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  27440. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  27441. return createBuffer(that, 0)
  27442. }
  27443. return fromArrayLike(that, obj)
  27444. }
  27445. if (obj.type === 'Buffer' && isArray$2(obj.data)) {
  27446. return fromArrayLike(that, obj.data)
  27447. }
  27448. }
  27449. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  27450. }
  27451. function checked (length) {
  27452. // Note: cannot use `length < kMaxLength()` here because that fails when
  27453. // length is NaN (which is otherwise coerced to zero.)
  27454. if (length >= kMaxLength()) {
  27455. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  27456. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  27457. }
  27458. return length | 0
  27459. }
  27460. Buffer$1.isBuffer = isBuffer$1;
  27461. function internalIsBuffer (b) {
  27462. return !!(b != null && b._isBuffer)
  27463. }
  27464. Buffer$1.compare = function compare (a, b) {
  27465. if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
  27466. throw new TypeError('Arguments must be Buffers')
  27467. }
  27468. if (a === b) return 0
  27469. var x = a.length;
  27470. var y = b.length;
  27471. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  27472. if (a[i] !== b[i]) {
  27473. x = a[i];
  27474. y = b[i];
  27475. break
  27476. }
  27477. }
  27478. if (x < y) return -1
  27479. if (y < x) return 1
  27480. return 0
  27481. };
  27482. Buffer$1.isEncoding = function isEncoding (encoding) {
  27483. switch (String(encoding).toLowerCase()) {
  27484. case 'hex':
  27485. case 'utf8':
  27486. case 'utf-8':
  27487. case 'ascii':
  27488. case 'latin1':
  27489. case 'binary':
  27490. case 'base64':
  27491. case 'ucs2':
  27492. case 'ucs-2':
  27493. case 'utf16le':
  27494. case 'utf-16le':
  27495. return true
  27496. default:
  27497. return false
  27498. }
  27499. };
  27500. Buffer$1.concat = function concat (list, length) {
  27501. if (!isArray$2(list)) {
  27502. throw new TypeError('"list" argument must be an Array of Buffers')
  27503. }
  27504. if (list.length === 0) {
  27505. return Buffer$1.alloc(0)
  27506. }
  27507. var i;
  27508. if (length === undefined) {
  27509. length = 0;
  27510. for (i = 0; i < list.length; ++i) {
  27511. length += list[i].length;
  27512. }
  27513. }
  27514. var buffer = Buffer$1.allocUnsafe(length);
  27515. var pos = 0;
  27516. for (i = 0; i < list.length; ++i) {
  27517. var buf = list[i];
  27518. if (!internalIsBuffer(buf)) {
  27519. throw new TypeError('"list" argument must be an Array of Buffers')
  27520. }
  27521. buf.copy(buffer, pos);
  27522. pos += buf.length;
  27523. }
  27524. return buffer
  27525. };
  27526. function byteLength (string, encoding) {
  27527. if (internalIsBuffer(string)) {
  27528. return string.length
  27529. }
  27530. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  27531. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  27532. return string.byteLength
  27533. }
  27534. if (typeof string !== 'string') {
  27535. string = '' + string;
  27536. }
  27537. var len = string.length;
  27538. if (len === 0) return 0
  27539. // Use a for loop to avoid recursion
  27540. var loweredCase = false;
  27541. for (;;) {
  27542. switch (encoding) {
  27543. case 'ascii':
  27544. case 'latin1':
  27545. case 'binary':
  27546. return len
  27547. case 'utf8':
  27548. case 'utf-8':
  27549. case undefined:
  27550. return utf8ToBytes(string).length
  27551. case 'ucs2':
  27552. case 'ucs-2':
  27553. case 'utf16le':
  27554. case 'utf-16le':
  27555. return len * 2
  27556. case 'hex':
  27557. return len >>> 1
  27558. case 'base64':
  27559. return base64ToBytes(string).length
  27560. default:
  27561. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  27562. encoding = ('' + encoding).toLowerCase();
  27563. loweredCase = true;
  27564. }
  27565. }
  27566. }
  27567. Buffer$1.byteLength = byteLength;
  27568. function slowToString (encoding, start, end) {
  27569. var loweredCase = false;
  27570. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  27571. // property of a typed array.
  27572. // This behaves neither like String nor Uint8Array in that we set start/end
  27573. // to their upper/lower bounds if the value passed is out of range.
  27574. // undefined is handled specially as per ECMA-262 6th Edition,
  27575. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  27576. if (start === undefined || start < 0) {
  27577. start = 0;
  27578. }
  27579. // Return early if start > this.length. Done here to prevent potential uint32
  27580. // coercion fail below.
  27581. if (start > this.length) {
  27582. return ''
  27583. }
  27584. if (end === undefined || end > this.length) {
  27585. end = this.length;
  27586. }
  27587. if (end <= 0) {
  27588. return ''
  27589. }
  27590. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  27591. end >>>= 0;
  27592. start >>>= 0;
  27593. if (end <= start) {
  27594. return ''
  27595. }
  27596. if (!encoding) encoding = 'utf8';
  27597. while (true) {
  27598. switch (encoding) {
  27599. case 'hex':
  27600. return hexSlice(this, start, end)
  27601. case 'utf8':
  27602. case 'utf-8':
  27603. return utf8Slice(this, start, end)
  27604. case 'ascii':
  27605. return asciiSlice(this, start, end)
  27606. case 'latin1':
  27607. case 'binary':
  27608. return latin1Slice(this, start, end)
  27609. case 'base64':
  27610. return base64Slice(this, start, end)
  27611. case 'ucs2':
  27612. case 'ucs-2':
  27613. case 'utf16le':
  27614. case 'utf-16le':
  27615. return utf16leSlice(this, start, end)
  27616. default:
  27617. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  27618. encoding = (encoding + '').toLowerCase();
  27619. loweredCase = true;
  27620. }
  27621. }
  27622. }
  27623. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  27624. // Buffer instances.
  27625. Buffer$1.prototype._isBuffer = true;
  27626. function swap$1 (b, n, m) {
  27627. var i = b[n];
  27628. b[n] = b[m];
  27629. b[m] = i;
  27630. }
  27631. Buffer$1.prototype.swap16 = function swap16 () {
  27632. var len = this.length;
  27633. if (len % 2 !== 0) {
  27634. throw new RangeError('Buffer size must be a multiple of 16-bits')
  27635. }
  27636. for (var i = 0; i < len; i += 2) {
  27637. swap$1(this, i, i + 1);
  27638. }
  27639. return this
  27640. };
  27641. Buffer$1.prototype.swap32 = function swap32 () {
  27642. var len = this.length;
  27643. if (len % 4 !== 0) {
  27644. throw new RangeError('Buffer size must be a multiple of 32-bits')
  27645. }
  27646. for (var i = 0; i < len; i += 4) {
  27647. swap$1(this, i, i + 3);
  27648. swap$1(this, i + 1, i + 2);
  27649. }
  27650. return this
  27651. };
  27652. Buffer$1.prototype.swap64 = function swap64 () {
  27653. var len = this.length;
  27654. if (len % 8 !== 0) {
  27655. throw new RangeError('Buffer size must be a multiple of 64-bits')
  27656. }
  27657. for (var i = 0; i < len; i += 8) {
  27658. swap$1(this, i, i + 7);
  27659. swap$1(this, i + 1, i + 6);
  27660. swap$1(this, i + 2, i + 5);
  27661. swap$1(this, i + 3, i + 4);
  27662. }
  27663. return this
  27664. };
  27665. Buffer$1.prototype.toString = function toString () {
  27666. var length = this.length | 0;
  27667. if (length === 0) return ''
  27668. if (arguments.length === 0) return utf8Slice(this, 0, length)
  27669. return slowToString.apply(this, arguments)
  27670. };
  27671. Buffer$1.prototype.equals = function equals (b) {
  27672. if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
  27673. if (this === b) return true
  27674. return Buffer$1.compare(this, b) === 0
  27675. };
  27676. Buffer$1.prototype.inspect = function inspect () {
  27677. var str = '';
  27678. var max = INSPECT_MAX_BYTES;
  27679. if (this.length > 0) {
  27680. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
  27681. if (this.length > max) str += ' ... ';
  27682. }
  27683. return '<Buffer ' + str + '>'
  27684. };
  27685. Buffer$1.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  27686. if (!internalIsBuffer(target)) {
  27687. throw new TypeError('Argument must be a Buffer')
  27688. }
  27689. if (start === undefined) {
  27690. start = 0;
  27691. }
  27692. if (end === undefined) {
  27693. end = target ? target.length : 0;
  27694. }
  27695. if (thisStart === undefined) {
  27696. thisStart = 0;
  27697. }
  27698. if (thisEnd === undefined) {
  27699. thisEnd = this.length;
  27700. }
  27701. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  27702. throw new RangeError('out of range index')
  27703. }
  27704. if (thisStart >= thisEnd && start >= end) {
  27705. return 0
  27706. }
  27707. if (thisStart >= thisEnd) {
  27708. return -1
  27709. }
  27710. if (start >= end) {
  27711. return 1
  27712. }
  27713. start >>>= 0;
  27714. end >>>= 0;
  27715. thisStart >>>= 0;
  27716. thisEnd >>>= 0;
  27717. if (this === target) return 0
  27718. var x = thisEnd - thisStart;
  27719. var y = end - start;
  27720. var len = Math.min(x, y);
  27721. var thisCopy = this.slice(thisStart, thisEnd);
  27722. var targetCopy = target.slice(start, end);
  27723. for (var i = 0; i < len; ++i) {
  27724. if (thisCopy[i] !== targetCopy[i]) {
  27725. x = thisCopy[i];
  27726. y = targetCopy[i];
  27727. break
  27728. }
  27729. }
  27730. if (x < y) return -1
  27731. if (y < x) return 1
  27732. return 0
  27733. };
  27734. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  27735. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  27736. //
  27737. // Arguments:
  27738. // - buffer - a Buffer to search
  27739. // - val - a string, Buffer, or number
  27740. // - byteOffset - an index into `buffer`; will be clamped to an int32
  27741. // - encoding - an optional encoding, relevant is val is a string
  27742. // - dir - true for indexOf, false for lastIndexOf
  27743. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  27744. // Empty buffer means no match
  27745. if (buffer.length === 0) return -1
  27746. // Normalize byteOffset
  27747. if (typeof byteOffset === 'string') {
  27748. encoding = byteOffset;
  27749. byteOffset = 0;
  27750. } else if (byteOffset > 0x7fffffff) {
  27751. byteOffset = 0x7fffffff;
  27752. } else if (byteOffset < -0x80000000) {
  27753. byteOffset = -0x80000000;
  27754. }
  27755. byteOffset = +byteOffset; // Coerce to Number.
  27756. if (isNaN(byteOffset)) {
  27757. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  27758. byteOffset = dir ? 0 : (buffer.length - 1);
  27759. }
  27760. // Normalize byteOffset: negative offsets start from the end of the buffer
  27761. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  27762. if (byteOffset >= buffer.length) {
  27763. if (dir) return -1
  27764. else byteOffset = buffer.length - 1;
  27765. } else if (byteOffset < 0) {
  27766. if (dir) byteOffset = 0;
  27767. else return -1
  27768. }
  27769. // Normalize val
  27770. if (typeof val === 'string') {
  27771. val = Buffer$1.from(val, encoding);
  27772. }
  27773. // Finally, search either indexOf (if dir is true) or lastIndexOf
  27774. if (internalIsBuffer(val)) {
  27775. // Special case: looking for empty string/buffer always fails
  27776. if (val.length === 0) {
  27777. return -1
  27778. }
  27779. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  27780. } else if (typeof val === 'number') {
  27781. val = val & 0xFF; // Search for a byte value [0-255]
  27782. if (Buffer$1.TYPED_ARRAY_SUPPORT &&
  27783. typeof Uint8Array.prototype.indexOf === 'function') {
  27784. if (dir) {
  27785. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  27786. } else {
  27787. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  27788. }
  27789. }
  27790. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  27791. }
  27792. throw new TypeError('val must be string, number or Buffer')
  27793. }
  27794. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  27795. var indexSize = 1;
  27796. var arrLength = arr.length;
  27797. var valLength = val.length;
  27798. if (encoding !== undefined) {
  27799. encoding = String(encoding).toLowerCase();
  27800. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  27801. encoding === 'utf16le' || encoding === 'utf-16le') {
  27802. if (arr.length < 2 || val.length < 2) {
  27803. return -1
  27804. }
  27805. indexSize = 2;
  27806. arrLength /= 2;
  27807. valLength /= 2;
  27808. byteOffset /= 2;
  27809. }
  27810. }
  27811. function read (buf, i) {
  27812. if (indexSize === 1) {
  27813. return buf[i]
  27814. } else {
  27815. return buf.readUInt16BE(i * indexSize)
  27816. }
  27817. }
  27818. var i;
  27819. if (dir) {
  27820. var foundIndex = -1;
  27821. for (i = byteOffset; i < arrLength; i++) {
  27822. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  27823. if (foundIndex === -1) foundIndex = i;
  27824. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  27825. } else {
  27826. if (foundIndex !== -1) i -= i - foundIndex;
  27827. foundIndex = -1;
  27828. }
  27829. }
  27830. } else {
  27831. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  27832. for (i = byteOffset; i >= 0; i--) {
  27833. var found = true;
  27834. for (var j = 0; j < valLength; j++) {
  27835. if (read(arr, i + j) !== read(val, j)) {
  27836. found = false;
  27837. break
  27838. }
  27839. }
  27840. if (found) return i
  27841. }
  27842. }
  27843. return -1
  27844. }
  27845. Buffer$1.prototype.includes = function includes (val, byteOffset, encoding) {
  27846. return this.indexOf(val, byteOffset, encoding) !== -1
  27847. };
  27848. Buffer$1.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  27849. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  27850. };
  27851. Buffer$1.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  27852. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  27853. };
  27854. function hexWrite (buf, string, offset, length) {
  27855. offset = Number(offset) || 0;
  27856. var remaining = buf.length - offset;
  27857. if (!length) {
  27858. length = remaining;
  27859. } else {
  27860. length = Number(length);
  27861. if (length > remaining) {
  27862. length = remaining;
  27863. }
  27864. }
  27865. // must be an even number of digits
  27866. var strLen = string.length;
  27867. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  27868. if (length > strLen / 2) {
  27869. length = strLen / 2;
  27870. }
  27871. for (var i = 0; i < length; ++i) {
  27872. var parsed = parseInt(string.substr(i * 2, 2), 16);
  27873. if (isNaN(parsed)) return i
  27874. buf[offset + i] = parsed;
  27875. }
  27876. return i
  27877. }
  27878. function utf8Write (buf, string, offset, length) {
  27879. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  27880. }
  27881. function asciiWrite (buf, string, offset, length) {
  27882. return blitBuffer(asciiToBytes(string), buf, offset, length)
  27883. }
  27884. function latin1Write (buf, string, offset, length) {
  27885. return asciiWrite(buf, string, offset, length)
  27886. }
  27887. function base64Write (buf, string, offset, length) {
  27888. return blitBuffer(base64ToBytes(string), buf, offset, length)
  27889. }
  27890. function ucs2Write (buf, string, offset, length) {
  27891. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  27892. }
  27893. Buffer$1.prototype.write = function write (string, offset, length, encoding) {
  27894. // Buffer#write(string)
  27895. if (offset === undefined) {
  27896. encoding = 'utf8';
  27897. length = this.length;
  27898. offset = 0;
  27899. // Buffer#write(string, encoding)
  27900. } else if (length === undefined && typeof offset === 'string') {
  27901. encoding = offset;
  27902. length = this.length;
  27903. offset = 0;
  27904. // Buffer#write(string, offset[, length][, encoding])
  27905. } else if (isFinite(offset)) {
  27906. offset = offset | 0;
  27907. if (isFinite(length)) {
  27908. length = length | 0;
  27909. if (encoding === undefined) encoding = 'utf8';
  27910. } else {
  27911. encoding = length;
  27912. length = undefined;
  27913. }
  27914. // legacy write(string, encoding, offset, length) - remove in v0.13
  27915. } else {
  27916. throw new Error(
  27917. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  27918. )
  27919. }
  27920. var remaining = this.length - offset;
  27921. if (length === undefined || length > remaining) length = remaining;
  27922. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  27923. throw new RangeError('Attempt to write outside buffer bounds')
  27924. }
  27925. if (!encoding) encoding = 'utf8';
  27926. var loweredCase = false;
  27927. for (;;) {
  27928. switch (encoding) {
  27929. case 'hex':
  27930. return hexWrite(this, string, offset, length)
  27931. case 'utf8':
  27932. case 'utf-8':
  27933. return utf8Write(this, string, offset, length)
  27934. case 'ascii':
  27935. return asciiWrite(this, string, offset, length)
  27936. case 'latin1':
  27937. case 'binary':
  27938. return latin1Write(this, string, offset, length)
  27939. case 'base64':
  27940. // Warning: maxLength not taken into account in base64Write
  27941. return base64Write(this, string, offset, length)
  27942. case 'ucs2':
  27943. case 'ucs-2':
  27944. case 'utf16le':
  27945. case 'utf-16le':
  27946. return ucs2Write(this, string, offset, length)
  27947. default:
  27948. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  27949. encoding = ('' + encoding).toLowerCase();
  27950. loweredCase = true;
  27951. }
  27952. }
  27953. };
  27954. Buffer$1.prototype.toJSON = function toJSON () {
  27955. return {
  27956. type: 'Buffer',
  27957. data: Array.prototype.slice.call(this._arr || this, 0)
  27958. }
  27959. };
  27960. function base64Slice (buf, start, end) {
  27961. if (start === 0 && end === buf.length) {
  27962. return fromByteArray(buf)
  27963. } else {
  27964. return fromByteArray(buf.slice(start, end))
  27965. }
  27966. }
  27967. function utf8Slice (buf, start, end) {
  27968. end = Math.min(buf.length, end);
  27969. var res = [];
  27970. var i = start;
  27971. while (i < end) {
  27972. var firstByte = buf[i];
  27973. var codePoint = null;
  27974. var bytesPerSequence = (firstByte > 0xEF) ? 4
  27975. : (firstByte > 0xDF) ? 3
  27976. : (firstByte > 0xBF) ? 2
  27977. : 1;
  27978. if (i + bytesPerSequence <= end) {
  27979. var secondByte, thirdByte, fourthByte, tempCodePoint;
  27980. switch (bytesPerSequence) {
  27981. case 1:
  27982. if (firstByte < 0x80) {
  27983. codePoint = firstByte;
  27984. }
  27985. break
  27986. case 2:
  27987. secondByte = buf[i + 1];
  27988. if ((secondByte & 0xC0) === 0x80) {
  27989. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
  27990. if (tempCodePoint > 0x7F) {
  27991. codePoint = tempCodePoint;
  27992. }
  27993. }
  27994. break
  27995. case 3:
  27996. secondByte = buf[i + 1];
  27997. thirdByte = buf[i + 2];
  27998. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  27999. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
  28000. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  28001. codePoint = tempCodePoint;
  28002. }
  28003. }
  28004. break
  28005. case 4:
  28006. secondByte = buf[i + 1];
  28007. thirdByte = buf[i + 2];
  28008. fourthByte = buf[i + 3];
  28009. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  28010. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
  28011. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  28012. codePoint = tempCodePoint;
  28013. }
  28014. }
  28015. }
  28016. }
  28017. if (codePoint === null) {
  28018. // we did not generate a valid codePoint so insert a
  28019. // replacement char (U+FFFD) and advance only 1 byte
  28020. codePoint = 0xFFFD;
  28021. bytesPerSequence = 1;
  28022. } else if (codePoint > 0xFFFF) {
  28023. // encode to utf16 (surrogate pair dance)
  28024. codePoint -= 0x10000;
  28025. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  28026. codePoint = 0xDC00 | codePoint & 0x3FF;
  28027. }
  28028. res.push(codePoint);
  28029. i += bytesPerSequence;
  28030. }
  28031. return decodeCodePointsArray(res)
  28032. }
  28033. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  28034. // the lowest limit is Chrome, with 0x10000 args.
  28035. // We go 1 magnitude less, for safety
  28036. var MAX_ARGUMENTS_LENGTH = 0x1000;
  28037. function decodeCodePointsArray (codePoints) {
  28038. var len = codePoints.length;
  28039. if (len <= MAX_ARGUMENTS_LENGTH) {
  28040. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  28041. }
  28042. // Decode in chunks to avoid "call stack size exceeded".
  28043. var res = '';
  28044. var i = 0;
  28045. while (i < len) {
  28046. res += String.fromCharCode.apply(
  28047. String,
  28048. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  28049. );
  28050. }
  28051. return res
  28052. }
  28053. function asciiSlice (buf, start, end) {
  28054. var ret = '';
  28055. end = Math.min(buf.length, end);
  28056. for (var i = start; i < end; ++i) {
  28057. ret += String.fromCharCode(buf[i] & 0x7F);
  28058. }
  28059. return ret
  28060. }
  28061. function latin1Slice (buf, start, end) {
  28062. var ret = '';
  28063. end = Math.min(buf.length, end);
  28064. for (var i = start; i < end; ++i) {
  28065. ret += String.fromCharCode(buf[i]);
  28066. }
  28067. return ret
  28068. }
  28069. function hexSlice (buf, start, end) {
  28070. var len = buf.length;
  28071. if (!start || start < 0) start = 0;
  28072. if (!end || end < 0 || end > len) end = len;
  28073. var out = '';
  28074. for (var i = start; i < end; ++i) {
  28075. out += toHex(buf[i]);
  28076. }
  28077. return out
  28078. }
  28079. function utf16leSlice (buf, start, end) {
  28080. var bytes = buf.slice(start, end);
  28081. var res = '';
  28082. for (var i = 0; i < bytes.length; i += 2) {
  28083. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  28084. }
  28085. return res
  28086. }
  28087. Buffer$1.prototype.slice = function slice (start, end) {
  28088. var len = this.length;
  28089. start = ~~start;
  28090. end = end === undefined ? len : ~~end;
  28091. if (start < 0) {
  28092. start += len;
  28093. if (start < 0) start = 0;
  28094. } else if (start > len) {
  28095. start = len;
  28096. }
  28097. if (end < 0) {
  28098. end += len;
  28099. if (end < 0) end = 0;
  28100. } else if (end > len) {
  28101. end = len;
  28102. }
  28103. if (end < start) end = start;
  28104. var newBuf;
  28105. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28106. newBuf = this.subarray(start, end);
  28107. newBuf.__proto__ = Buffer$1.prototype;
  28108. } else {
  28109. var sliceLen = end - start;
  28110. newBuf = new Buffer$1(sliceLen, undefined);
  28111. for (var i = 0; i < sliceLen; ++i) {
  28112. newBuf[i] = this[i + start];
  28113. }
  28114. }
  28115. return newBuf
  28116. };
  28117. /*
  28118. * Need to make sure that buffer isn't trying to write out of bounds.
  28119. */
  28120. function checkOffset (offset, ext, length) {
  28121. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  28122. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  28123. }
  28124. Buffer$1.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  28125. offset = offset | 0;
  28126. byteLength = byteLength | 0;
  28127. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28128. var val = this[offset];
  28129. var mul = 1;
  28130. var i = 0;
  28131. while (++i < byteLength && (mul *= 0x100)) {
  28132. val += this[offset + i] * mul;
  28133. }
  28134. return val
  28135. };
  28136. Buffer$1.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  28137. offset = offset | 0;
  28138. byteLength = byteLength | 0;
  28139. if (!noAssert) {
  28140. checkOffset(offset, byteLength, this.length);
  28141. }
  28142. var val = this[offset + --byteLength];
  28143. var mul = 1;
  28144. while (byteLength > 0 && (mul *= 0x100)) {
  28145. val += this[offset + --byteLength] * mul;
  28146. }
  28147. return val
  28148. };
  28149. Buffer$1.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  28150. if (!noAssert) checkOffset(offset, 1, this.length);
  28151. return this[offset]
  28152. };
  28153. Buffer$1.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  28154. if (!noAssert) checkOffset(offset, 2, this.length);
  28155. return this[offset] | (this[offset + 1] << 8)
  28156. };
  28157. Buffer$1.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  28158. if (!noAssert) checkOffset(offset, 2, this.length);
  28159. return (this[offset] << 8) | this[offset + 1]
  28160. };
  28161. Buffer$1.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  28162. if (!noAssert) checkOffset(offset, 4, this.length);
  28163. return ((this[offset]) |
  28164. (this[offset + 1] << 8) |
  28165. (this[offset + 2] << 16)) +
  28166. (this[offset + 3] * 0x1000000)
  28167. };
  28168. Buffer$1.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  28169. if (!noAssert) checkOffset(offset, 4, this.length);
  28170. return (this[offset] * 0x1000000) +
  28171. ((this[offset + 1] << 16) |
  28172. (this[offset + 2] << 8) |
  28173. this[offset + 3])
  28174. };
  28175. Buffer$1.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  28176. offset = offset | 0;
  28177. byteLength = byteLength | 0;
  28178. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28179. var val = this[offset];
  28180. var mul = 1;
  28181. var i = 0;
  28182. while (++i < byteLength && (mul *= 0x100)) {
  28183. val += this[offset + i] * mul;
  28184. }
  28185. mul *= 0x80;
  28186. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  28187. return val
  28188. };
  28189. Buffer$1.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  28190. offset = offset | 0;
  28191. byteLength = byteLength | 0;
  28192. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28193. var i = byteLength;
  28194. var mul = 1;
  28195. var val = this[offset + --i];
  28196. while (i > 0 && (mul *= 0x100)) {
  28197. val += this[offset + --i] * mul;
  28198. }
  28199. mul *= 0x80;
  28200. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  28201. return val
  28202. };
  28203. Buffer$1.prototype.readInt8 = function readInt8 (offset, noAssert) {
  28204. if (!noAssert) checkOffset(offset, 1, this.length);
  28205. if (!(this[offset] & 0x80)) return (this[offset])
  28206. return ((0xff - this[offset] + 1) * -1)
  28207. };
  28208. Buffer$1.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  28209. if (!noAssert) checkOffset(offset, 2, this.length);
  28210. var val = this[offset] | (this[offset + 1] << 8);
  28211. return (val & 0x8000) ? val | 0xFFFF0000 : val
  28212. };
  28213. Buffer$1.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  28214. if (!noAssert) checkOffset(offset, 2, this.length);
  28215. var val = this[offset + 1] | (this[offset] << 8);
  28216. return (val & 0x8000) ? val | 0xFFFF0000 : val
  28217. };
  28218. Buffer$1.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  28219. if (!noAssert) checkOffset(offset, 4, this.length);
  28220. return (this[offset]) |
  28221. (this[offset + 1] << 8) |
  28222. (this[offset + 2] << 16) |
  28223. (this[offset + 3] << 24)
  28224. };
  28225. Buffer$1.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  28226. if (!noAssert) checkOffset(offset, 4, this.length);
  28227. return (this[offset] << 24) |
  28228. (this[offset + 1] << 16) |
  28229. (this[offset + 2] << 8) |
  28230. (this[offset + 3])
  28231. };
  28232. Buffer$1.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  28233. if (!noAssert) checkOffset(offset, 4, this.length);
  28234. return read(this, offset, true, 23, 4)
  28235. };
  28236. Buffer$1.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  28237. if (!noAssert) checkOffset(offset, 4, this.length);
  28238. return read(this, offset, false, 23, 4)
  28239. };
  28240. Buffer$1.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  28241. if (!noAssert) checkOffset(offset, 8, this.length);
  28242. return read(this, offset, true, 52, 8)
  28243. };
  28244. Buffer$1.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  28245. if (!noAssert) checkOffset(offset, 8, this.length);
  28246. return read(this, offset, false, 52, 8)
  28247. };
  28248. function checkInt (buf, value, offset, ext, max, min) {
  28249. if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  28250. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  28251. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  28252. }
  28253. Buffer$1.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  28254. value = +value;
  28255. offset = offset | 0;
  28256. byteLength = byteLength | 0;
  28257. if (!noAssert) {
  28258. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  28259. checkInt(this, value, offset, byteLength, maxBytes, 0);
  28260. }
  28261. var mul = 1;
  28262. var i = 0;
  28263. this[offset] = value & 0xFF;
  28264. while (++i < byteLength && (mul *= 0x100)) {
  28265. this[offset + i] = (value / mul) & 0xFF;
  28266. }
  28267. return offset + byteLength
  28268. };
  28269. Buffer$1.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  28270. value = +value;
  28271. offset = offset | 0;
  28272. byteLength = byteLength | 0;
  28273. if (!noAssert) {
  28274. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  28275. checkInt(this, value, offset, byteLength, maxBytes, 0);
  28276. }
  28277. var i = byteLength - 1;
  28278. var mul = 1;
  28279. this[offset + i] = value & 0xFF;
  28280. while (--i >= 0 && (mul *= 0x100)) {
  28281. this[offset + i] = (value / mul) & 0xFF;
  28282. }
  28283. return offset + byteLength
  28284. };
  28285. Buffer$1.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  28286. value = +value;
  28287. offset = offset | 0;
  28288. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  28289. if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  28290. this[offset] = (value & 0xff);
  28291. return offset + 1
  28292. };
  28293. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  28294. if (value < 0) value = 0xffff + value + 1;
  28295. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  28296. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  28297. (littleEndian ? i : 1 - i) * 8;
  28298. }
  28299. }
  28300. Buffer$1.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  28301. value = +value;
  28302. offset = offset | 0;
  28303. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  28304. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28305. this[offset] = (value & 0xff);
  28306. this[offset + 1] = (value >>> 8);
  28307. } else {
  28308. objectWriteUInt16(this, value, offset, true);
  28309. }
  28310. return offset + 2
  28311. };
  28312. Buffer$1.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  28313. value = +value;
  28314. offset = offset | 0;
  28315. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  28316. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28317. this[offset] = (value >>> 8);
  28318. this[offset + 1] = (value & 0xff);
  28319. } else {
  28320. objectWriteUInt16(this, value, offset, false);
  28321. }
  28322. return offset + 2
  28323. };
  28324. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  28325. if (value < 0) value = 0xffffffff + value + 1;
  28326. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  28327. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
  28328. }
  28329. }
  28330. Buffer$1.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  28331. value = +value;
  28332. offset = offset | 0;
  28333. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  28334. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28335. this[offset + 3] = (value >>> 24);
  28336. this[offset + 2] = (value >>> 16);
  28337. this[offset + 1] = (value >>> 8);
  28338. this[offset] = (value & 0xff);
  28339. } else {
  28340. objectWriteUInt32(this, value, offset, true);
  28341. }
  28342. return offset + 4
  28343. };
  28344. Buffer$1.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  28345. value = +value;
  28346. offset = offset | 0;
  28347. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  28348. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28349. this[offset] = (value >>> 24);
  28350. this[offset + 1] = (value >>> 16);
  28351. this[offset + 2] = (value >>> 8);
  28352. this[offset + 3] = (value & 0xff);
  28353. } else {
  28354. objectWriteUInt32(this, value, offset, false);
  28355. }
  28356. return offset + 4
  28357. };
  28358. Buffer$1.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  28359. value = +value;
  28360. offset = offset | 0;
  28361. if (!noAssert) {
  28362. var limit = Math.pow(2, 8 * byteLength - 1);
  28363. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  28364. }
  28365. var i = 0;
  28366. var mul = 1;
  28367. var sub = 0;
  28368. this[offset] = value & 0xFF;
  28369. while (++i < byteLength && (mul *= 0x100)) {
  28370. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  28371. sub = 1;
  28372. }
  28373. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  28374. }
  28375. return offset + byteLength
  28376. };
  28377. Buffer$1.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  28378. value = +value;
  28379. offset = offset | 0;
  28380. if (!noAssert) {
  28381. var limit = Math.pow(2, 8 * byteLength - 1);
  28382. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  28383. }
  28384. var i = byteLength - 1;
  28385. var mul = 1;
  28386. var sub = 0;
  28387. this[offset + i] = value & 0xFF;
  28388. while (--i >= 0 && (mul *= 0x100)) {
  28389. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  28390. sub = 1;
  28391. }
  28392. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  28393. }
  28394. return offset + byteLength
  28395. };
  28396. Buffer$1.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  28397. value = +value;
  28398. offset = offset | 0;
  28399. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  28400. if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  28401. if (value < 0) value = 0xff + value + 1;
  28402. this[offset] = (value & 0xff);
  28403. return offset + 1
  28404. };
  28405. Buffer$1.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  28406. value = +value;
  28407. offset = offset | 0;
  28408. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  28409. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28410. this[offset] = (value & 0xff);
  28411. this[offset + 1] = (value >>> 8);
  28412. } else {
  28413. objectWriteUInt16(this, value, offset, true);
  28414. }
  28415. return offset + 2
  28416. };
  28417. Buffer$1.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  28418. value = +value;
  28419. offset = offset | 0;
  28420. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  28421. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28422. this[offset] = (value >>> 8);
  28423. this[offset + 1] = (value & 0xff);
  28424. } else {
  28425. objectWriteUInt16(this, value, offset, false);
  28426. }
  28427. return offset + 2
  28428. };
  28429. Buffer$1.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  28430. value = +value;
  28431. offset = offset | 0;
  28432. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  28433. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28434. this[offset] = (value & 0xff);
  28435. this[offset + 1] = (value >>> 8);
  28436. this[offset + 2] = (value >>> 16);
  28437. this[offset + 3] = (value >>> 24);
  28438. } else {
  28439. objectWriteUInt32(this, value, offset, true);
  28440. }
  28441. return offset + 4
  28442. };
  28443. Buffer$1.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  28444. value = +value;
  28445. offset = offset | 0;
  28446. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  28447. if (value < 0) value = 0xffffffff + value + 1;
  28448. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28449. this[offset] = (value >>> 24);
  28450. this[offset + 1] = (value >>> 16);
  28451. this[offset + 2] = (value >>> 8);
  28452. this[offset + 3] = (value & 0xff);
  28453. } else {
  28454. objectWriteUInt32(this, value, offset, false);
  28455. }
  28456. return offset + 4
  28457. };
  28458. function checkIEEE754 (buf, value, offset, ext, max, min) {
  28459. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  28460. if (offset < 0) throw new RangeError('Index out of range')
  28461. }
  28462. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  28463. if (!noAssert) {
  28464. checkIEEE754(buf, value, offset, 4);
  28465. }
  28466. write(buf, value, offset, littleEndian, 23, 4);
  28467. return offset + 4
  28468. }
  28469. Buffer$1.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  28470. return writeFloat(this, value, offset, true, noAssert)
  28471. };
  28472. Buffer$1.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  28473. return writeFloat(this, value, offset, false, noAssert)
  28474. };
  28475. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  28476. if (!noAssert) {
  28477. checkIEEE754(buf, value, offset, 8);
  28478. }
  28479. write(buf, value, offset, littleEndian, 52, 8);
  28480. return offset + 8
  28481. }
  28482. Buffer$1.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  28483. return writeDouble(this, value, offset, true, noAssert)
  28484. };
  28485. Buffer$1.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  28486. return writeDouble(this, value, offset, false, noAssert)
  28487. };
  28488. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  28489. Buffer$1.prototype.copy = function copy (target, targetStart, start, end) {
  28490. if (!start) start = 0;
  28491. if (!end && end !== 0) end = this.length;
  28492. if (targetStart >= target.length) targetStart = target.length;
  28493. if (!targetStart) targetStart = 0;
  28494. if (end > 0 && end < start) end = start;
  28495. // Copy 0 bytes; we're done
  28496. if (end === start) return 0
  28497. if (target.length === 0 || this.length === 0) return 0
  28498. // Fatal error conditions
  28499. if (targetStart < 0) {
  28500. throw new RangeError('targetStart out of bounds')
  28501. }
  28502. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  28503. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  28504. // Are we oob?
  28505. if (end > this.length) end = this.length;
  28506. if (target.length - targetStart < end - start) {
  28507. end = target.length - targetStart + start;
  28508. }
  28509. var len = end - start;
  28510. var i;
  28511. if (this === target && start < targetStart && targetStart < end) {
  28512. // descending copy from end
  28513. for (i = len - 1; i >= 0; --i) {
  28514. target[i + targetStart] = this[i + start];
  28515. }
  28516. } else if (len < 1000 || !Buffer$1.TYPED_ARRAY_SUPPORT) {
  28517. // ascending copy from start
  28518. for (i = 0; i < len; ++i) {
  28519. target[i + targetStart] = this[i + start];
  28520. }
  28521. } else {
  28522. Uint8Array.prototype.set.call(
  28523. target,
  28524. this.subarray(start, start + len),
  28525. targetStart
  28526. );
  28527. }
  28528. return len
  28529. };
  28530. // Usage:
  28531. // buffer.fill(number[, offset[, end]])
  28532. // buffer.fill(buffer[, offset[, end]])
  28533. // buffer.fill(string[, offset[, end]][, encoding])
  28534. Buffer$1.prototype.fill = function fill (val, start, end, encoding) {
  28535. // Handle string cases:
  28536. if (typeof val === 'string') {
  28537. if (typeof start === 'string') {
  28538. encoding = start;
  28539. start = 0;
  28540. end = this.length;
  28541. } else if (typeof end === 'string') {
  28542. encoding = end;
  28543. end = this.length;
  28544. }
  28545. if (val.length === 1) {
  28546. var code = val.charCodeAt(0);
  28547. if (code < 256) {
  28548. val = code;
  28549. }
  28550. }
  28551. if (encoding !== undefined && typeof encoding !== 'string') {
  28552. throw new TypeError('encoding must be a string')
  28553. }
  28554. if (typeof encoding === 'string' && !Buffer$1.isEncoding(encoding)) {
  28555. throw new TypeError('Unknown encoding: ' + encoding)
  28556. }
  28557. } else if (typeof val === 'number') {
  28558. val = val & 255;
  28559. }
  28560. // Invalid ranges are not set to a default, so can range check early.
  28561. if (start < 0 || this.length < start || this.length < end) {
  28562. throw new RangeError('Out of range index')
  28563. }
  28564. if (end <= start) {
  28565. return this
  28566. }
  28567. start = start >>> 0;
  28568. end = end === undefined ? this.length : end >>> 0;
  28569. if (!val) val = 0;
  28570. var i;
  28571. if (typeof val === 'number') {
  28572. for (i = start; i < end; ++i) {
  28573. this[i] = val;
  28574. }
  28575. } else {
  28576. var bytes = internalIsBuffer(val)
  28577. ? val
  28578. : utf8ToBytes(new Buffer$1(val, encoding).toString());
  28579. var len = bytes.length;
  28580. for (i = 0; i < end - start; ++i) {
  28581. this[i + start] = bytes[i % len];
  28582. }
  28583. }
  28584. return this
  28585. };
  28586. // HELPER FUNCTIONS
  28587. // ================
  28588. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
  28589. function base64clean (str) {
  28590. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  28591. str = stringtrim(str).replace(INVALID_BASE64_RE, '');
  28592. // Node converts strings with length < 2 to ''
  28593. if (str.length < 2) return ''
  28594. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  28595. while (str.length % 4 !== 0) {
  28596. str = str + '=';
  28597. }
  28598. return str
  28599. }
  28600. function stringtrim (str) {
  28601. if (str.trim) return str.trim()
  28602. return str.replace(/^\s+|\s+$/g, '')
  28603. }
  28604. function toHex (n) {
  28605. if (n < 16) return '0' + n.toString(16)
  28606. return n.toString(16)
  28607. }
  28608. function utf8ToBytes (string, units) {
  28609. units = units || Infinity;
  28610. var codePoint;
  28611. var length = string.length;
  28612. var leadSurrogate = null;
  28613. var bytes = [];
  28614. for (var i = 0; i < length; ++i) {
  28615. codePoint = string.charCodeAt(i);
  28616. // is surrogate component
  28617. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  28618. // last char was a lead
  28619. if (!leadSurrogate) {
  28620. // no lead yet
  28621. if (codePoint > 0xDBFF) {
  28622. // unexpected trail
  28623. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28624. continue
  28625. } else if (i + 1 === length) {
  28626. // unpaired lead
  28627. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28628. continue
  28629. }
  28630. // valid lead
  28631. leadSurrogate = codePoint;
  28632. continue
  28633. }
  28634. // 2 leads in a row
  28635. if (codePoint < 0xDC00) {
  28636. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28637. leadSurrogate = codePoint;
  28638. continue
  28639. }
  28640. // valid surrogate pair
  28641. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  28642. } else if (leadSurrogate) {
  28643. // valid bmp char, but last char was a lead
  28644. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28645. }
  28646. leadSurrogate = null;
  28647. // encode utf8
  28648. if (codePoint < 0x80) {
  28649. if ((units -= 1) < 0) break
  28650. bytes.push(codePoint);
  28651. } else if (codePoint < 0x800) {
  28652. if ((units -= 2) < 0) break
  28653. bytes.push(
  28654. codePoint >> 0x6 | 0xC0,
  28655. codePoint & 0x3F | 0x80
  28656. );
  28657. } else if (codePoint < 0x10000) {
  28658. if ((units -= 3) < 0) break
  28659. bytes.push(
  28660. codePoint >> 0xC | 0xE0,
  28661. codePoint >> 0x6 & 0x3F | 0x80,
  28662. codePoint & 0x3F | 0x80
  28663. );
  28664. } else if (codePoint < 0x110000) {
  28665. if ((units -= 4) < 0) break
  28666. bytes.push(
  28667. codePoint >> 0x12 | 0xF0,
  28668. codePoint >> 0xC & 0x3F | 0x80,
  28669. codePoint >> 0x6 & 0x3F | 0x80,
  28670. codePoint & 0x3F | 0x80
  28671. );
  28672. } else {
  28673. throw new Error('Invalid code point')
  28674. }
  28675. }
  28676. return bytes
  28677. }
  28678. function asciiToBytes (str) {
  28679. var byteArray = [];
  28680. for (var i = 0; i < str.length; ++i) {
  28681. // Node's code seems to be doing this and not & 0x7F..
  28682. byteArray.push(str.charCodeAt(i) & 0xFF);
  28683. }
  28684. return byteArray
  28685. }
  28686. function utf16leToBytes (str, units) {
  28687. var c, hi, lo;
  28688. var byteArray = [];
  28689. for (var i = 0; i < str.length; ++i) {
  28690. if ((units -= 2) < 0) break
  28691. c = str.charCodeAt(i);
  28692. hi = c >> 8;
  28693. lo = c % 256;
  28694. byteArray.push(lo);
  28695. byteArray.push(hi);
  28696. }
  28697. return byteArray
  28698. }
  28699. function base64ToBytes (str) {
  28700. return toByteArray(base64clean(str))
  28701. }
  28702. function blitBuffer (src, dst, offset, length) {
  28703. for (var i = 0; i < length; ++i) {
  28704. if ((i + offset >= dst.length) || (i >= src.length)) break
  28705. dst[i + offset] = src[i];
  28706. }
  28707. return i
  28708. }
  28709. function isnan (val) {
  28710. return val !== val // eslint-disable-line no-self-compare
  28711. }
  28712. // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
  28713. // The _isBuffer check is for Safari 5-7 support, because it's missing
  28714. // Object.prototype.constructor. Remove this eventually
  28715. function isBuffer$1(obj) {
  28716. return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
  28717. }
  28718. function isFastBuffer (obj) {
  28719. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  28720. }
  28721. // For Node v0.10 support. Remove this eventually.
  28722. function isSlowBuffer (obj) {
  28723. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
  28724. }
  28725. // shim for using process in browser
  28726. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  28727. function defaultSetTimout() {
  28728. throw new Error('setTimeout has not been defined');
  28729. }
  28730. function defaultClearTimeout () {
  28731. throw new Error('clearTimeout has not been defined');
  28732. }
  28733. var cachedSetTimeout = defaultSetTimout;
  28734. var cachedClearTimeout = defaultClearTimeout;
  28735. if (typeof global$1.setTimeout === 'function') {
  28736. cachedSetTimeout = setTimeout;
  28737. }
  28738. if (typeof global$1.clearTimeout === 'function') {
  28739. cachedClearTimeout = clearTimeout;
  28740. }
  28741. function runTimeout(fun) {
  28742. if (cachedSetTimeout === setTimeout) {
  28743. //normal enviroments in sane situations
  28744. return setTimeout(fun, 0);
  28745. }
  28746. // if setTimeout wasn't available but was latter defined
  28747. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  28748. cachedSetTimeout = setTimeout;
  28749. return setTimeout(fun, 0);
  28750. }
  28751. try {
  28752. // when when somebody has screwed with setTimeout but no I.E. maddness
  28753. return cachedSetTimeout(fun, 0);
  28754. } catch(e){
  28755. try {
  28756. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  28757. return cachedSetTimeout.call(null, fun, 0);
  28758. } catch(e){
  28759. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  28760. return cachedSetTimeout.call(this, fun, 0);
  28761. }
  28762. }
  28763. }
  28764. function runClearTimeout(marker) {
  28765. if (cachedClearTimeout === clearTimeout) {
  28766. //normal enviroments in sane situations
  28767. return clearTimeout(marker);
  28768. }
  28769. // if clearTimeout wasn't available but was latter defined
  28770. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  28771. cachedClearTimeout = clearTimeout;
  28772. return clearTimeout(marker);
  28773. }
  28774. try {
  28775. // when when somebody has screwed with setTimeout but no I.E. maddness
  28776. return cachedClearTimeout(marker);
  28777. } catch (e){
  28778. try {
  28779. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  28780. return cachedClearTimeout.call(null, marker);
  28781. } catch (e){
  28782. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  28783. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  28784. return cachedClearTimeout.call(this, marker);
  28785. }
  28786. }
  28787. }
  28788. var queue = [];
  28789. var draining = false;
  28790. var currentQueue;
  28791. var queueIndex = -1;
  28792. function cleanUpNextTick() {
  28793. if (!draining || !currentQueue) {
  28794. return;
  28795. }
  28796. draining = false;
  28797. if (currentQueue.length) {
  28798. queue = currentQueue.concat(queue);
  28799. } else {
  28800. queueIndex = -1;
  28801. }
  28802. if (queue.length) {
  28803. drainQueue();
  28804. }
  28805. }
  28806. function drainQueue() {
  28807. if (draining) {
  28808. return;
  28809. }
  28810. var timeout = runTimeout(cleanUpNextTick);
  28811. draining = true;
  28812. var len = queue.length;
  28813. while(len) {
  28814. currentQueue = queue;
  28815. queue = [];
  28816. while (++queueIndex < len) {
  28817. if (currentQueue) {
  28818. currentQueue[queueIndex].run();
  28819. }
  28820. }
  28821. queueIndex = -1;
  28822. len = queue.length;
  28823. }
  28824. currentQueue = null;
  28825. draining = false;
  28826. runClearTimeout(timeout);
  28827. }
  28828. function nextTick(fun) {
  28829. var args = new Array(arguments.length - 1);
  28830. if (arguments.length > 1) {
  28831. for (var i = 1; i < arguments.length; i++) {
  28832. args[i - 1] = arguments[i];
  28833. }
  28834. }
  28835. queue.push(new Item(fun, args));
  28836. if (queue.length === 1 && !draining) {
  28837. runTimeout(drainQueue);
  28838. }
  28839. }
  28840. // v8 likes predictible objects
  28841. function Item(fun, array) {
  28842. this.fun = fun;
  28843. this.array = array;
  28844. }
  28845. Item.prototype.run = function () {
  28846. this.fun.apply(null, this.array);
  28847. };
  28848. var title = 'browser';
  28849. var platform = 'browser';
  28850. var browser = true;
  28851. var env = {};
  28852. var argv = [];
  28853. var version$1 = ''; // empty string to avoid regexp issues
  28854. var versions = {};
  28855. var release = {};
  28856. var config = {};
  28857. function noop() {}
  28858. var on = noop;
  28859. var addListener = noop;
  28860. var once = noop;
  28861. var off = noop;
  28862. var removeListener = noop;
  28863. var removeAllListeners = noop;
  28864. var emit = noop;
  28865. function binding(name) {
  28866. throw new Error('process.binding is not supported');
  28867. }
  28868. function cwd () { return '/' }
  28869. function chdir (dir) {
  28870. throw new Error('process.chdir is not supported');
  28871. }function umask() { return 0; }
  28872. // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  28873. var performance = global$1.performance || {};
  28874. var performanceNow =
  28875. performance.now ||
  28876. performance.mozNow ||
  28877. performance.msNow ||
  28878. performance.oNow ||
  28879. performance.webkitNow ||
  28880. function(){ return (new Date()).getTime() };
  28881. // generate timestamp or delta
  28882. // see http://nodejs.org/api/process.html#process_process_hrtime
  28883. function hrtime(previousTimestamp){
  28884. var clocktime = performanceNow.call(performance)*1e-3;
  28885. var seconds = Math.floor(clocktime);
  28886. var nanoseconds = Math.floor((clocktime%1)*1e9);
  28887. if (previousTimestamp) {
  28888. seconds = seconds - previousTimestamp[0];
  28889. nanoseconds = nanoseconds - previousTimestamp[1];
  28890. if (nanoseconds<0) {
  28891. seconds--;
  28892. nanoseconds += 1e9;
  28893. }
  28894. }
  28895. return [seconds,nanoseconds]
  28896. }
  28897. var startTime = new Date();
  28898. function uptime() {
  28899. var currentTime = new Date();
  28900. var dif = currentTime - startTime;
  28901. return dif / 1000;
  28902. }
  28903. var browser$1 = {
  28904. nextTick: nextTick,
  28905. title: title,
  28906. browser: browser,
  28907. env: env,
  28908. argv: argv,
  28909. version: version$1,
  28910. versions: versions,
  28911. on: on,
  28912. addListener: addListener,
  28913. once: once,
  28914. off: off,
  28915. removeListener: removeListener,
  28916. removeAllListeners: removeAllListeners,
  28917. emit: emit,
  28918. binding: binding,
  28919. cwd: cwd,
  28920. chdir: chdir,
  28921. umask: umask,
  28922. hrtime: hrtime,
  28923. platform: platform,
  28924. release: release,
  28925. config: config,
  28926. uptime: uptime
  28927. };
  28928. var inherits;
  28929. if (typeof Object.create === 'function'){
  28930. inherits = function inherits(ctor, superCtor) {
  28931. // implementation from standard node.js 'util' module
  28932. ctor.super_ = superCtor;
  28933. ctor.prototype = Object.create(superCtor.prototype, {
  28934. constructor: {
  28935. value: ctor,
  28936. enumerable: false,
  28937. writable: true,
  28938. configurable: true
  28939. }
  28940. });
  28941. };
  28942. } else {
  28943. inherits = function inherits(ctor, superCtor) {
  28944. ctor.super_ = superCtor;
  28945. var TempCtor = function () {};
  28946. TempCtor.prototype = superCtor.prototype;
  28947. ctor.prototype = new TempCtor();
  28948. ctor.prototype.constructor = ctor;
  28949. };
  28950. }
  28951. var inherits$1 = inherits;
  28952. var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
  28953. function getOwnPropertyDescriptors(obj) {
  28954. var keys = Object.keys(obj);
  28955. var descriptors = {};
  28956. for (var i = 0; i < keys.length; i++) {
  28957. descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  28958. }
  28959. return descriptors;
  28960. };
  28961. var formatRegExp = /%[sdj%]/g;
  28962. function format$1(f) {
  28963. if (!isString$1(f)) {
  28964. var objects = [];
  28965. for (var i = 0; i < arguments.length; i++) {
  28966. objects.push(inspect(arguments[i]));
  28967. }
  28968. return objects.join(' ');
  28969. }
  28970. var i = 1;
  28971. var args = arguments;
  28972. var len = args.length;
  28973. var str = String(f).replace(formatRegExp, function(x) {
  28974. if (x === '%%') return '%';
  28975. if (i >= len) return x;
  28976. switch (x) {
  28977. case '%s': return String(args[i++]);
  28978. case '%d': return Number(args[i++]);
  28979. case '%j':
  28980. try {
  28981. return JSON.stringify(args[i++]);
  28982. } catch (_) {
  28983. return '[Circular]';
  28984. }
  28985. default:
  28986. return x;
  28987. }
  28988. });
  28989. for (var x = args[i]; i < len; x = args[++i]) {
  28990. if (isNull(x) || !isObject$1(x)) {
  28991. str += ' ' + x;
  28992. } else {
  28993. str += ' ' + inspect(x);
  28994. }
  28995. }
  28996. return str;
  28997. }
  28998. // Mark that a method should not be used.
  28999. // Returns a modified function which warns once by default.
  29000. // If --no-deprecation is set, then it is a no-op.
  29001. function deprecate(fn, msg) {
  29002. // Allow for deprecating things in the process of starting up.
  29003. if (isUndefined(global$1.process)) {
  29004. return function() {
  29005. return deprecate(fn, msg).apply(this, arguments);
  29006. };
  29007. }
  29008. if (browser$1.noDeprecation === true) {
  29009. return fn;
  29010. }
  29011. var warned = false;
  29012. function deprecated() {
  29013. if (!warned) {
  29014. if (browser$1.throwDeprecation) {
  29015. throw new Error(msg);
  29016. } else if (browser$1.traceDeprecation) {
  29017. console.trace(msg);
  29018. } else {
  29019. console.error(msg);
  29020. }
  29021. warned = true;
  29022. }
  29023. return fn.apply(this, arguments);
  29024. }
  29025. return deprecated;
  29026. }
  29027. var debugs = {};
  29028. var debugEnviron;
  29029. function debuglog(set) {
  29030. if (isUndefined(debugEnviron))
  29031. debugEnviron = browser$1.env.NODE_DEBUG || '';
  29032. set = set.toUpperCase();
  29033. if (!debugs[set]) {
  29034. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  29035. var pid = 0;
  29036. debugs[set] = function() {
  29037. var msg = format$1.apply(null, arguments);
  29038. console.error('%s %d: %s', set, pid, msg);
  29039. };
  29040. } else {
  29041. debugs[set] = function() {};
  29042. }
  29043. }
  29044. return debugs[set];
  29045. }
  29046. /**
  29047. * Echos the value of a value. Trys to print the value out
  29048. * in the best way possible given the different types.
  29049. *
  29050. * @param {Object} obj The object to print out.
  29051. * @param {Object} opts Optional options object that alters the output.
  29052. */
  29053. /* legacy: obj, showHidden, depth, colors*/
  29054. function inspect(obj, opts) {
  29055. // default options
  29056. var ctx = {
  29057. seen: [],
  29058. stylize: stylizeNoColor
  29059. };
  29060. // legacy...
  29061. if (arguments.length >= 3) ctx.depth = arguments[2];
  29062. if (arguments.length >= 4) ctx.colors = arguments[3];
  29063. if (isBoolean(opts)) {
  29064. // legacy...
  29065. ctx.showHidden = opts;
  29066. } else if (opts) {
  29067. // got an "options" object
  29068. _extend(ctx, opts);
  29069. }
  29070. // set default options
  29071. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  29072. if (isUndefined(ctx.depth)) ctx.depth = 2;
  29073. if (isUndefined(ctx.colors)) ctx.colors = false;
  29074. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  29075. if (ctx.colors) ctx.stylize = stylizeWithColor;
  29076. return formatValue(ctx, obj, ctx.depth);
  29077. }
  29078. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  29079. inspect.colors = {
  29080. 'bold' : [1, 22],
  29081. 'italic' : [3, 23],
  29082. 'underline' : [4, 24],
  29083. 'inverse' : [7, 27],
  29084. 'white' : [37, 39],
  29085. 'grey' : [90, 39],
  29086. 'black' : [30, 39],
  29087. 'blue' : [34, 39],
  29088. 'cyan' : [36, 39],
  29089. 'green' : [32, 39],
  29090. 'magenta' : [35, 39],
  29091. 'red' : [31, 39],
  29092. 'yellow' : [33, 39]
  29093. };
  29094. // Don't use 'blue' not visible on cmd.exe
  29095. inspect.styles = {
  29096. 'special': 'cyan',
  29097. 'number': 'yellow',
  29098. 'boolean': 'yellow',
  29099. 'undefined': 'grey',
  29100. 'null': 'bold',
  29101. 'string': 'green',
  29102. 'date': 'magenta',
  29103. // "name": intentionally not styling
  29104. 'regexp': 'red'
  29105. };
  29106. function stylizeWithColor(str, styleType) {
  29107. var style = inspect.styles[styleType];
  29108. if (style) {
  29109. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  29110. '\u001b[' + inspect.colors[style][1] + 'm';
  29111. } else {
  29112. return str;
  29113. }
  29114. }
  29115. function stylizeNoColor(str, styleType) {
  29116. return str;
  29117. }
  29118. function arrayToHash(array) {
  29119. var hash = {};
  29120. array.forEach(function(val, idx) {
  29121. hash[val] = true;
  29122. });
  29123. return hash;
  29124. }
  29125. function formatValue(ctx, value, recurseTimes) {
  29126. // Provide a hook for user-specified inspect functions.
  29127. // Check that value is an object with an inspect function on it
  29128. if (ctx.customInspect &&
  29129. value &&
  29130. isFunction(value.inspect) &&
  29131. // Filter out the util module, it's inspect function is special
  29132. value.inspect !== inspect &&
  29133. // Also filter out any prototype objects using the circular check.
  29134. !(value.constructor && value.constructor.prototype === value)) {
  29135. var ret = value.inspect(recurseTimes, ctx);
  29136. if (!isString$1(ret)) {
  29137. ret = formatValue(ctx, ret, recurseTimes);
  29138. }
  29139. return ret;
  29140. }
  29141. // Primitive types cannot have properties
  29142. var primitive = formatPrimitive(ctx, value);
  29143. if (primitive) {
  29144. return primitive;
  29145. }
  29146. // Look up the keys of the object.
  29147. var keys = Object.keys(value);
  29148. var visibleKeys = arrayToHash(keys);
  29149. if (ctx.showHidden) {
  29150. keys = Object.getOwnPropertyNames(value);
  29151. }
  29152. // IE doesn't make error fields non-enumerable
  29153. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  29154. if (isError(value)
  29155. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  29156. return formatError(value);
  29157. }
  29158. // Some type of object without properties can be shortcutted.
  29159. if (keys.length === 0) {
  29160. if (isFunction(value)) {
  29161. var name = value.name ? ': ' + value.name : '';
  29162. return ctx.stylize('[Function' + name + ']', 'special');
  29163. }
  29164. if (isRegExp(value)) {
  29165. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29166. }
  29167. if (isDate(value)) {
  29168. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  29169. }
  29170. if (isError(value)) {
  29171. return formatError(value);
  29172. }
  29173. }
  29174. var base = '', array = false, braces = ['{', '}'];
  29175. // Make Array say that they are Array
  29176. if (isArray$1(value)) {
  29177. array = true;
  29178. braces = ['[', ']'];
  29179. }
  29180. // Make functions say that they are functions
  29181. if (isFunction(value)) {
  29182. var n = value.name ? ': ' + value.name : '';
  29183. base = ' [Function' + n + ']';
  29184. }
  29185. // Make RegExps say that they are RegExps
  29186. if (isRegExp(value)) {
  29187. base = ' ' + RegExp.prototype.toString.call(value);
  29188. }
  29189. // Make dates with properties first say the date
  29190. if (isDate(value)) {
  29191. base = ' ' + Date.prototype.toUTCString.call(value);
  29192. }
  29193. // Make error with message first say the error
  29194. if (isError(value)) {
  29195. base = ' ' + formatError(value);
  29196. }
  29197. if (keys.length === 0 && (!array || value.length == 0)) {
  29198. return braces[0] + base + braces[1];
  29199. }
  29200. if (recurseTimes < 0) {
  29201. if (isRegExp(value)) {
  29202. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29203. } else {
  29204. return ctx.stylize('[Object]', 'special');
  29205. }
  29206. }
  29207. ctx.seen.push(value);
  29208. var output;
  29209. if (array) {
  29210. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  29211. } else {
  29212. output = keys.map(function(key) {
  29213. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  29214. });
  29215. }
  29216. ctx.seen.pop();
  29217. return reduceToSingleString(output, base, braces);
  29218. }
  29219. function formatPrimitive(ctx, value) {
  29220. if (isUndefined(value))
  29221. return ctx.stylize('undefined', 'undefined');
  29222. if (isString$1(value)) {
  29223. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  29224. .replace(/'/g, "\\'")
  29225. .replace(/\\"/g, '"') + '\'';
  29226. return ctx.stylize(simple, 'string');
  29227. }
  29228. if (isNumber(value))
  29229. return ctx.stylize('' + value, 'number');
  29230. if (isBoolean(value))
  29231. return ctx.stylize('' + value, 'boolean');
  29232. // For some reason typeof null is "object", so special case here.
  29233. if (isNull(value))
  29234. return ctx.stylize('null', 'null');
  29235. }
  29236. function formatError(value) {
  29237. return '[' + Error.prototype.toString.call(value) + ']';
  29238. }
  29239. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  29240. var output = [];
  29241. for (var i = 0, l = value.length; i < l; ++i) {
  29242. if (hasOwnProperty$2(value, String(i))) {
  29243. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29244. String(i), true));
  29245. } else {
  29246. output.push('');
  29247. }
  29248. }
  29249. keys.forEach(function(key) {
  29250. if (!key.match(/^\d+$/)) {
  29251. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29252. key, true));
  29253. }
  29254. });
  29255. return output;
  29256. }
  29257. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  29258. var name, str, desc;
  29259. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  29260. if (desc.get) {
  29261. if (desc.set) {
  29262. str = ctx.stylize('[Getter/Setter]', 'special');
  29263. } else {
  29264. str = ctx.stylize('[Getter]', 'special');
  29265. }
  29266. } else {
  29267. if (desc.set) {
  29268. str = ctx.stylize('[Setter]', 'special');
  29269. }
  29270. }
  29271. if (!hasOwnProperty$2(visibleKeys, key)) {
  29272. name = '[' + key + ']';
  29273. }
  29274. if (!str) {
  29275. if (ctx.seen.indexOf(desc.value) < 0) {
  29276. if (isNull(recurseTimes)) {
  29277. str = formatValue(ctx, desc.value, null);
  29278. } else {
  29279. str = formatValue(ctx, desc.value, recurseTimes - 1);
  29280. }
  29281. if (str.indexOf('\n') > -1) {
  29282. if (array) {
  29283. str = str.split('\n').map(function(line) {
  29284. return ' ' + line;
  29285. }).join('\n').substr(2);
  29286. } else {
  29287. str = '\n' + str.split('\n').map(function(line) {
  29288. return ' ' + line;
  29289. }).join('\n');
  29290. }
  29291. }
  29292. } else {
  29293. str = ctx.stylize('[Circular]', 'special');
  29294. }
  29295. }
  29296. if (isUndefined(name)) {
  29297. if (array && key.match(/^\d+$/)) {
  29298. return str;
  29299. }
  29300. name = JSON.stringify('' + key);
  29301. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  29302. name = name.substr(1, name.length - 2);
  29303. name = ctx.stylize(name, 'name');
  29304. } else {
  29305. name = name.replace(/'/g, "\\'")
  29306. .replace(/\\"/g, '"')
  29307. .replace(/(^"|"$)/g, "'");
  29308. name = ctx.stylize(name, 'string');
  29309. }
  29310. }
  29311. return name + ': ' + str;
  29312. }
  29313. function reduceToSingleString(output, base, braces) {
  29314. var length = output.reduce(function(prev, cur) {
  29315. if (cur.indexOf('\n') >= 0) ;
  29316. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  29317. }, 0);
  29318. if (length > 60) {
  29319. return braces[0] +
  29320. (base === '' ? '' : base + '\n ') +
  29321. ' ' +
  29322. output.join(',\n ') +
  29323. ' ' +
  29324. braces[1];
  29325. }
  29326. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  29327. }
  29328. // NOTE: These type checking functions intentionally don't use `instanceof`
  29329. // because it is fragile and can be easily faked with `Object.create()`.
  29330. function isArray$1(ar) {
  29331. return Array.isArray(ar);
  29332. }
  29333. function isBoolean(arg) {
  29334. return typeof arg === 'boolean';
  29335. }
  29336. function isNull(arg) {
  29337. return arg === null;
  29338. }
  29339. function isNullOrUndefined(arg) {
  29340. return arg == null;
  29341. }
  29342. function isNumber(arg) {
  29343. return typeof arg === 'number';
  29344. }
  29345. function isString$1(arg) {
  29346. return typeof arg === 'string';
  29347. }
  29348. function isSymbol(arg) {
  29349. return typeof arg === 'symbol';
  29350. }
  29351. function isUndefined(arg) {
  29352. return arg === void 0;
  29353. }
  29354. function isRegExp(re) {
  29355. return isObject$1(re) && objectToString(re) === '[object RegExp]';
  29356. }
  29357. function isObject$1(arg) {
  29358. return typeof arg === 'object' && arg !== null;
  29359. }
  29360. function isDate(d) {
  29361. return isObject$1(d) && objectToString(d) === '[object Date]';
  29362. }
  29363. function isError(e) {
  29364. return isObject$1(e) &&
  29365. (objectToString(e) === '[object Error]' || e instanceof Error);
  29366. }
  29367. function isFunction(arg) {
  29368. return typeof arg === 'function';
  29369. }
  29370. function isPrimitive(arg) {
  29371. return arg === null ||
  29372. typeof arg === 'boolean' ||
  29373. typeof arg === 'number' ||
  29374. typeof arg === 'string' ||
  29375. typeof arg === 'symbol' || // ES6 symbol
  29376. typeof arg === 'undefined';
  29377. }
  29378. function isBuffer(maybeBuf) {
  29379. return Buffer$1.isBuffer(maybeBuf);
  29380. }
  29381. function objectToString(o) {
  29382. return Object.prototype.toString.call(o);
  29383. }
  29384. function pad(n) {
  29385. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  29386. }
  29387. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  29388. 'Oct', 'Nov', 'Dec'];
  29389. // 26 Feb 16:19:34
  29390. function timestamp() {
  29391. var d = new Date();
  29392. var time = [pad(d.getHours()),
  29393. pad(d.getMinutes()),
  29394. pad(d.getSeconds())].join(':');
  29395. return [d.getDate(), months[d.getMonth()], time].join(' ');
  29396. }
  29397. // log is just a thin wrapper to console.log that prepends a timestamp
  29398. function log() {
  29399. console.log('%s - %s', timestamp(), format$1.apply(null, arguments));
  29400. }
  29401. function _extend(origin, add) {
  29402. // Don't do anything if add isn't an object
  29403. if (!add || !isObject$1(add)) return origin;
  29404. var keys = Object.keys(add);
  29405. var i = keys.length;
  29406. while (i--) {
  29407. origin[keys[i]] = add[keys[i]];
  29408. }
  29409. return origin;
  29410. }
  29411. function hasOwnProperty$2(obj, prop) {
  29412. return Object.prototype.hasOwnProperty.call(obj, prop);
  29413. }
  29414. var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
  29415. function promisify(original) {
  29416. if (typeof original !== 'function')
  29417. throw new TypeError('The "original" argument must be of type Function');
  29418. if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
  29419. var fn = original[kCustomPromisifiedSymbol];
  29420. if (typeof fn !== 'function') {
  29421. throw new TypeError('The "util.promisify.custom" argument must be of type Function');
  29422. }
  29423. Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29424. value: fn, enumerable: false, writable: false, configurable: true
  29425. });
  29426. return fn;
  29427. }
  29428. function fn() {
  29429. var promiseResolve, promiseReject;
  29430. var promise = new Promise(function (resolve, reject) {
  29431. promiseResolve = resolve;
  29432. promiseReject = reject;
  29433. });
  29434. var args = [];
  29435. for (var i = 0; i < arguments.length; i++) {
  29436. args.push(arguments[i]);
  29437. }
  29438. args.push(function (err, value) {
  29439. if (err) {
  29440. promiseReject(err);
  29441. } else {
  29442. promiseResolve(value);
  29443. }
  29444. });
  29445. try {
  29446. original.apply(this, args);
  29447. } catch (err) {
  29448. promiseReject(err);
  29449. }
  29450. return promise;
  29451. }
  29452. Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
  29453. if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29454. value: fn, enumerable: false, writable: false, configurable: true
  29455. });
  29456. return Object.defineProperties(
  29457. fn,
  29458. getOwnPropertyDescriptors(original)
  29459. );
  29460. }
  29461. promisify.custom = kCustomPromisifiedSymbol;
  29462. function callbackifyOnRejected(reason, cb) {
  29463. // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
  29464. // Because `null` is a special error value in callbacks which means "no error
  29465. // occurred", we error-wrap so the callback consumer can distinguish between
  29466. // "the promise rejected with null" or "the promise fulfilled with undefined".
  29467. if (!reason) {
  29468. var newReason = new Error('Promise was rejected with a falsy value');
  29469. newReason.reason = reason;
  29470. reason = newReason;
  29471. }
  29472. return cb(reason);
  29473. }
  29474. function callbackify(original) {
  29475. if (typeof original !== 'function') {
  29476. throw new TypeError('The "original" argument must be of type Function');
  29477. }
  29478. // We DO NOT return the promise as it gives the user a false sense that
  29479. // the promise is actually somehow related to the callback's execution
  29480. // and that the callback throwing will reject the promise.
  29481. function callbackified() {
  29482. var args = [];
  29483. for (var i = 0; i < arguments.length; i++) {
  29484. args.push(arguments[i]);
  29485. }
  29486. var maybeCb = args.pop();
  29487. if (typeof maybeCb !== 'function') {
  29488. throw new TypeError('The last argument must be of type Function');
  29489. }
  29490. var self = this;
  29491. var cb = function() {
  29492. return maybeCb.apply(self, arguments);
  29493. };
  29494. // In true node style we process the callback on `nextTick` with all the
  29495. // implications (stack, `uncaughtException`, `async_hooks`)
  29496. original.apply(this, args)
  29497. .then(function(ret) { browser$1.nextTick(cb.bind(null, null, ret)); },
  29498. function(rej) { browser$1.nextTick(callbackifyOnRejected.bind(null, rej, cb)); });
  29499. }
  29500. Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
  29501. Object.defineProperties(callbackified, getOwnPropertyDescriptors(original));
  29502. return callbackified;
  29503. }
  29504. var _polyfillNode_util = {
  29505. inherits: inherits$1,
  29506. _extend: _extend,
  29507. log: log,
  29508. isBuffer: isBuffer,
  29509. isPrimitive: isPrimitive,
  29510. isFunction: isFunction,
  29511. isError: isError,
  29512. isDate: isDate,
  29513. isObject: isObject$1,
  29514. isRegExp: isRegExp,
  29515. isUndefined: isUndefined,
  29516. isSymbol: isSymbol,
  29517. isString: isString$1,
  29518. isNumber: isNumber,
  29519. isNullOrUndefined: isNullOrUndefined,
  29520. isNull: isNull,
  29521. isBoolean: isBoolean,
  29522. isArray: isArray$1,
  29523. inspect: inspect,
  29524. deprecate: deprecate,
  29525. format: format$1,
  29526. debuglog: debuglog,
  29527. promisify: promisify,
  29528. callbackify: callbackify,
  29529. };
  29530. var _polyfillNode_util$1 = /*#__PURE__*/Object.freeze({
  29531. __proto__: null,
  29532. _extend: _extend,
  29533. callbackify: callbackify,
  29534. debuglog: debuglog,
  29535. default: _polyfillNode_util,
  29536. deprecate: deprecate,
  29537. format: format$1,
  29538. inherits: inherits$1,
  29539. inspect: inspect,
  29540. isArray: isArray$1,
  29541. isBoolean: isBoolean,
  29542. isBuffer: isBuffer,
  29543. isDate: isDate,
  29544. isError: isError,
  29545. isFunction: isFunction,
  29546. isNull: isNull,
  29547. isNullOrUndefined: isNullOrUndefined,
  29548. isNumber: isNumber,
  29549. isObject: isObject$1,
  29550. isPrimitive: isPrimitive,
  29551. isRegExp: isRegExp,
  29552. isString: isString$1,
  29553. isSymbol: isSymbol,
  29554. isUndefined: isUndefined,
  29555. log: log,
  29556. promisify: promisify
  29557. });
  29558. // Copyright Joyent, Inc. and other Node contributors.
  29559. //
  29560. // Permission is hereby granted, free of charge, to any person obtaining a
  29561. // copy of this software and associated documentation files (the
  29562. // "Software"), to deal in the Software without restriction, including
  29563. // without limitation the rights to use, copy, modify, merge, publish,
  29564. // distribute, sublicense, and/or sell copies of the Software, and to permit
  29565. // persons to whom the Software is furnished to do so, subject to the
  29566. // following conditions:
  29567. //
  29568. // The above copyright notice and this permission notice shall be included
  29569. // in all copies or substantial portions of the Software.
  29570. //
  29571. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  29572. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29573. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  29574. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  29575. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  29576. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  29577. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  29578. // If obj.hasOwnProperty has been overridden, then calling
  29579. // obj.hasOwnProperty(prop) will break.
  29580. // See: https://github.com/joyent/node/issues/1707
  29581. function hasOwnProperty$1(obj, prop) {
  29582. return Object.prototype.hasOwnProperty.call(obj, prop);
  29583. }
  29584. var isArray = Array.isArray || function (xs) {
  29585. return Object.prototype.toString.call(xs) === '[object Array]';
  29586. };
  29587. function stringifyPrimitive(v) {
  29588. switch (typeof v) {
  29589. case 'string':
  29590. return v;
  29591. case 'boolean':
  29592. return v ? 'true' : 'false';
  29593. case 'number':
  29594. return isFinite(v) ? v : '';
  29595. default:
  29596. return '';
  29597. }
  29598. }
  29599. function stringify$5 (obj, sep, eq, name) {
  29600. sep = sep || '&';
  29601. eq = eq || '=';
  29602. if (obj === null) {
  29603. obj = undefined;
  29604. }
  29605. if (typeof obj === 'object') {
  29606. return map(objectKeys(obj), function(k) {
  29607. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  29608. if (isArray(obj[k])) {
  29609. return map(obj[k], function(v) {
  29610. return ks + encodeURIComponent(stringifyPrimitive(v));
  29611. }).join(sep);
  29612. } else {
  29613. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  29614. }
  29615. }).join(sep);
  29616. }
  29617. if (!name) return '';
  29618. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  29619. encodeURIComponent(stringifyPrimitive(obj));
  29620. }
  29621. function map (xs, f) {
  29622. if (xs.map) return xs.map(f);
  29623. var res = [];
  29624. for (var i = 0; i < xs.length; i++) {
  29625. res.push(f(xs[i], i));
  29626. }
  29627. return res;
  29628. }
  29629. var objectKeys = Object.keys || function (obj) {
  29630. var res = [];
  29631. for (var key in obj) {
  29632. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  29633. }
  29634. return res;
  29635. };
  29636. function parse$6(qs, sep, eq, options) {
  29637. sep = sep || '&';
  29638. eq = eq || '=';
  29639. var obj = {};
  29640. if (typeof qs !== 'string' || qs.length === 0) {
  29641. return obj;
  29642. }
  29643. var regexp = /\+/g;
  29644. qs = qs.split(sep);
  29645. var maxKeys = 1000;
  29646. if (options && typeof options.maxKeys === 'number') {
  29647. maxKeys = options.maxKeys;
  29648. }
  29649. var len = qs.length;
  29650. // maxKeys <= 0 means that we should not limit keys count
  29651. if (maxKeys > 0 && len > maxKeys) {
  29652. len = maxKeys;
  29653. }
  29654. for (var i = 0; i < len; ++i) {
  29655. var x = qs[i].replace(regexp, '%20'),
  29656. idx = x.indexOf(eq),
  29657. kstr, vstr, k, v;
  29658. if (idx >= 0) {
  29659. kstr = x.substr(0, idx);
  29660. vstr = x.substr(idx + 1);
  29661. } else {
  29662. kstr = x;
  29663. vstr = '';
  29664. }
  29665. k = decodeURIComponent(kstr);
  29666. v = decodeURIComponent(vstr);
  29667. if (!hasOwnProperty$1(obj, k)) {
  29668. obj[k] = v;
  29669. } else if (isArray(obj[k])) {
  29670. obj[k].push(v);
  29671. } else {
  29672. obj[k] = [obj[k], v];
  29673. }
  29674. }
  29675. return obj;
  29676. }
  29677. // WHATWG API
  29678. const URL$1 = global$1.URL;
  29679. const URLSearchParams = global$1.URLSearchParams;
  29680. var _polyfillNode_url = {
  29681. parse: urlParse,
  29682. resolve: urlResolve,
  29683. resolveObject: urlResolveObject,
  29684. fileURLToPath: urlFileURLToPath,
  29685. format: urlFormat,
  29686. Url: Url,
  29687. // WHATWG API
  29688. URL: URL$1,
  29689. URLSearchParams,
  29690. };
  29691. function Url() {
  29692. this.protocol = null;
  29693. this.slashes = null;
  29694. this.auth = null;
  29695. this.host = null;
  29696. this.port = null;
  29697. this.hostname = null;
  29698. this.hash = null;
  29699. this.search = null;
  29700. this.query = null;
  29701. this.pathname = null;
  29702. this.path = null;
  29703. this.href = null;
  29704. }
  29705. // Reference: RFC 3986, RFC 1808, RFC 2396
  29706. // define these here so at least they only have to be
  29707. // compiled once on the first module load.
  29708. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  29709. portPattern = /:[0-9]*$/,
  29710. // Special case for a simple path URL
  29711. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  29712. // RFC 2396: characters reserved for delimiting URLs.
  29713. // We actually just auto-escape these.
  29714. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  29715. // RFC 2396: characters not allowed for various reasons.
  29716. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  29717. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  29718. autoEscape = ['\''].concat(unwise),
  29719. // Characters that are never ever allowed in a hostname.
  29720. // Note that any invalid chars are also handled, but these
  29721. // are the ones that are *expected* to be seen, so we fast-path
  29722. // them.
  29723. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  29724. hostEndingChars = ['/', '?', '#'],
  29725. hostnameMaxLen = 255,
  29726. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  29727. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  29728. // protocols that can allow "unsafe" and "unwise" chars.
  29729. unsafeProtocol = {
  29730. 'javascript': true,
  29731. 'javascript:': true
  29732. },
  29733. // protocols that never have a hostname.
  29734. hostlessProtocol = {
  29735. 'javascript': true,
  29736. 'javascript:': true
  29737. },
  29738. // protocols that always contain a // bit.
  29739. slashedProtocol = {
  29740. 'http': true,
  29741. 'https': true,
  29742. 'ftp': true,
  29743. 'gopher': true,
  29744. 'file': true,
  29745. 'http:': true,
  29746. 'https:': true,
  29747. 'ftp:': true,
  29748. 'gopher:': true,
  29749. 'file:': true
  29750. };
  29751. function urlParse(url, parseQueryString, slashesDenoteHost) {
  29752. if (url && isObject$1(url) && url instanceof Url) return url;
  29753. var u = new Url;
  29754. u.parse(url, parseQueryString, slashesDenoteHost);
  29755. return u;
  29756. }
  29757. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  29758. return parse$5(this, url, parseQueryString, slashesDenoteHost);
  29759. };
  29760. function parse$5(self, url, parseQueryString, slashesDenoteHost) {
  29761. if (!isString$1(url)) {
  29762. throw new TypeError('Parameter \'url\' must be a string, not ' + typeof url);
  29763. }
  29764. // Copy chrome, IE, opera backslash-handling behavior.
  29765. // Back slashes before the query string get converted to forward slashes
  29766. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  29767. var queryIndex = url.indexOf('?'),
  29768. splitter =
  29769. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  29770. uSplit = url.split(splitter),
  29771. slashRegex = /\\/g;
  29772. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  29773. url = uSplit.join(splitter);
  29774. var rest = url;
  29775. // trim before proceeding.
  29776. // This is to support parse stuff like " http://foo.com \n"
  29777. rest = rest.trim();
  29778. if (!slashesDenoteHost && url.split('#').length === 1) {
  29779. // Try fast path regexp
  29780. var simplePath = simplePathPattern.exec(rest);
  29781. if (simplePath) {
  29782. self.path = rest;
  29783. self.href = rest;
  29784. self.pathname = simplePath[1];
  29785. if (simplePath[2]) {
  29786. self.search = simplePath[2];
  29787. if (parseQueryString) {
  29788. self.query = parse$6(self.search.substr(1));
  29789. } else {
  29790. self.query = self.search.substr(1);
  29791. }
  29792. } else if (parseQueryString) {
  29793. self.search = '';
  29794. self.query = {};
  29795. }
  29796. return self;
  29797. }
  29798. }
  29799. var proto = protocolPattern.exec(rest);
  29800. if (proto) {
  29801. proto = proto[0];
  29802. var lowerProto = proto.toLowerCase();
  29803. self.protocol = lowerProto;
  29804. rest = rest.substr(proto.length);
  29805. }
  29806. // figure out if it's got a host
  29807. // user@server is *always* interpreted as a hostname, and url
  29808. // resolution will treat //foo/bar as host=foo,path=bar because that's
  29809. // how the browser resolves relative URLs.
  29810. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  29811. var slashes = rest.substr(0, 2) === '//';
  29812. if (slashes && !(proto && hostlessProtocol[proto])) {
  29813. rest = rest.substr(2);
  29814. self.slashes = true;
  29815. }
  29816. }
  29817. var i, hec, l, p;
  29818. if (!hostlessProtocol[proto] &&
  29819. (slashes || (proto && !slashedProtocol[proto]))) {
  29820. // there's a hostname.
  29821. // the first instance of /, ?, ;, or # ends the host.
  29822. //
  29823. // If there is an @ in the hostname, then non-host chars *are* allowed
  29824. // to the left of the last @ sign, unless some host-ending character
  29825. // comes *before* the @-sign.
  29826. // URLs are obnoxious.
  29827. //
  29828. // ex:
  29829. // http://a@b@c/ => user:a@b host:c
  29830. // http://a@b?@c => user:a host:c path:/?@c
  29831. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  29832. // Review our test case against browsers more comprehensively.
  29833. // find the first instance of any hostEndingChars
  29834. var hostEnd = -1;
  29835. for (i = 0; i < hostEndingChars.length; i++) {
  29836. hec = rest.indexOf(hostEndingChars[i]);
  29837. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  29838. hostEnd = hec;
  29839. }
  29840. // at this point, either we have an explicit point where the
  29841. // auth portion cannot go past, or the last @ char is the decider.
  29842. var auth, atSign;
  29843. if (hostEnd === -1) {
  29844. // atSign can be anywhere.
  29845. atSign = rest.lastIndexOf('@');
  29846. } else {
  29847. // atSign must be in auth portion.
  29848. // http://a@b/c@d => host:b auth:a path:/c@d
  29849. atSign = rest.lastIndexOf('@', hostEnd);
  29850. }
  29851. // Now we have a portion which is definitely the auth.
  29852. // Pull that off.
  29853. if (atSign !== -1) {
  29854. auth = rest.slice(0, atSign);
  29855. rest = rest.slice(atSign + 1);
  29856. self.auth = decodeURIComponent(auth);
  29857. }
  29858. // the host is the remaining to the left of the first non-host char
  29859. hostEnd = -1;
  29860. for (i = 0; i < nonHostChars.length; i++) {
  29861. hec = rest.indexOf(nonHostChars[i]);
  29862. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  29863. hostEnd = hec;
  29864. }
  29865. // if we still have not hit it, then the entire thing is a host.
  29866. if (hostEnd === -1)
  29867. hostEnd = rest.length;
  29868. self.host = rest.slice(0, hostEnd);
  29869. rest = rest.slice(hostEnd);
  29870. // pull out port.
  29871. parseHost(self);
  29872. // we've indicated that there is a hostname,
  29873. // so even if it's empty, it has to be present.
  29874. self.hostname = self.hostname || '';
  29875. // if hostname begins with [ and ends with ]
  29876. // assume that it's an IPv6 address.
  29877. var ipv6Hostname = self.hostname[0] === '[' &&
  29878. self.hostname[self.hostname.length - 1] === ']';
  29879. // validate a little.
  29880. if (!ipv6Hostname) {
  29881. var hostparts = self.hostname.split(/\./);
  29882. for (i = 0, l = hostparts.length; i < l; i++) {
  29883. var part = hostparts[i];
  29884. if (!part) continue;
  29885. if (!part.match(hostnamePartPattern)) {
  29886. var newpart = '';
  29887. for (var j = 0, k = part.length; j < k; j++) {
  29888. if (part.charCodeAt(j) > 127) {
  29889. // we replace non-ASCII char with a temporary placeholder
  29890. // we need this to make sure size of hostname is not
  29891. // broken by replacing non-ASCII by nothing
  29892. newpart += 'x';
  29893. } else {
  29894. newpart += part[j];
  29895. }
  29896. }
  29897. // we test again with ASCII char only
  29898. if (!newpart.match(hostnamePartPattern)) {
  29899. var validParts = hostparts.slice(0, i);
  29900. var notHost = hostparts.slice(i + 1);
  29901. var bit = part.match(hostnamePartStart);
  29902. if (bit) {
  29903. validParts.push(bit[1]);
  29904. notHost.unshift(bit[2]);
  29905. }
  29906. if (notHost.length) {
  29907. rest = '/' + notHost.join('.') + rest;
  29908. }
  29909. self.hostname = validParts.join('.');
  29910. break;
  29911. }
  29912. }
  29913. }
  29914. }
  29915. if (self.hostname.length > hostnameMaxLen) {
  29916. self.hostname = '';
  29917. } else {
  29918. // hostnames are always lower case.
  29919. self.hostname = self.hostname.toLowerCase();
  29920. }
  29921. if (!ipv6Hostname) {
  29922. // IDNA Support: Returns a punycoded representation of "domain".
  29923. // It only converts parts of the domain name that
  29924. // have non-ASCII characters, i.e. it doesn't matter if
  29925. // you call it with a domain that already is ASCII-only.
  29926. self.hostname = toASCII(self.hostname);
  29927. }
  29928. p = self.port ? ':' + self.port : '';
  29929. var h = self.hostname || '';
  29930. self.host = h + p;
  29931. self.href += self.host;
  29932. // strip [ and ] from the hostname
  29933. // the host field still retains them, though
  29934. if (ipv6Hostname) {
  29935. self.hostname = self.hostname.substr(1, self.hostname.length - 2);
  29936. if (rest[0] !== '/') {
  29937. rest = '/' + rest;
  29938. }
  29939. }
  29940. }
  29941. // now rest is set to the post-host stuff.
  29942. // chop off any delim chars.
  29943. if (!unsafeProtocol[lowerProto]) {
  29944. // First, make 100% sure that any "autoEscape" chars get
  29945. // escaped, even if encodeURIComponent doesn't think they
  29946. // need to be.
  29947. for (i = 0, l = autoEscape.length; i < l; i++) {
  29948. var ae = autoEscape[i];
  29949. if (rest.indexOf(ae) === -1)
  29950. continue;
  29951. var esc = encodeURIComponent(ae);
  29952. if (esc === ae) {
  29953. esc = escape(ae);
  29954. }
  29955. rest = rest.split(ae).join(esc);
  29956. }
  29957. }
  29958. // chop off from the tail first.
  29959. var hash = rest.indexOf('#');
  29960. if (hash !== -1) {
  29961. // got a fragment string.
  29962. self.hash = rest.substr(hash);
  29963. rest = rest.slice(0, hash);
  29964. }
  29965. var qm = rest.indexOf('?');
  29966. if (qm !== -1) {
  29967. self.search = rest.substr(qm);
  29968. self.query = rest.substr(qm + 1);
  29969. if (parseQueryString) {
  29970. self.query = parse$6(self.query);
  29971. }
  29972. rest = rest.slice(0, qm);
  29973. } else if (parseQueryString) {
  29974. // no query string, but parseQueryString still requested
  29975. self.search = '';
  29976. self.query = {};
  29977. }
  29978. if (rest) self.pathname = rest;
  29979. if (slashedProtocol[lowerProto] &&
  29980. self.hostname && !self.pathname) {
  29981. self.pathname = '/';
  29982. }
  29983. //to support http.request
  29984. if (self.pathname || self.search) {
  29985. p = self.pathname || '';
  29986. var s = self.search || '';
  29987. self.path = p + s;
  29988. }
  29989. // finally, reconstruct the href based on what has been validated.
  29990. self.href = format(self);
  29991. return self;
  29992. }
  29993. function urlFileURLToPath(path) {
  29994. if (typeof path === 'string')
  29995. path = new Url().parse(path);
  29996. else if (!(path instanceof Url))
  29997. throw new TypeError('The "path" argument must be of type string or an instance of URL. Received type ' + (typeof path) + String(path));
  29998. if (path.protocol !== 'file:')
  29999. throw new TypeError('The URL must be of scheme file');
  30000. return getPathFromURLPosix(path);
  30001. }
  30002. function getPathFromURLPosix(url) {
  30003. const pathname = url.pathname;
  30004. for (let n = 0; n < pathname.length; n++) {
  30005. if (pathname[n] === '%') {
  30006. const third = pathname.codePointAt(n + 2) | 0x20;
  30007. if (pathname[n + 1] === '2' && third === 102) {
  30008. throw new TypeError(
  30009. 'must not include encoded / characters'
  30010. );
  30011. }
  30012. }
  30013. }
  30014. return decodeURIComponent(pathname);
  30015. }
  30016. // format a parsed object into a url string
  30017. function urlFormat(obj) {
  30018. // ensure it's an object, and not a string url.
  30019. // If it's an obj, this is a no-op.
  30020. // this way, you can call url_format() on strings
  30021. // to clean up potentially wonky urls.
  30022. if (isString$1(obj)) obj = parse$5({}, obj);
  30023. return format(obj);
  30024. }
  30025. function format(self) {
  30026. var auth = self.auth || '';
  30027. if (auth) {
  30028. auth = encodeURIComponent(auth);
  30029. auth = auth.replace(/%3A/i, ':');
  30030. auth += '@';
  30031. }
  30032. var protocol = self.protocol || '',
  30033. pathname = self.pathname || '',
  30034. hash = self.hash || '',
  30035. host = false,
  30036. query = '';
  30037. if (self.host) {
  30038. host = auth + self.host;
  30039. } else if (self.hostname) {
  30040. host = auth + (self.hostname.indexOf(':') === -1 ?
  30041. self.hostname :
  30042. '[' + this.hostname + ']');
  30043. if (self.port) {
  30044. host += ':' + self.port;
  30045. }
  30046. }
  30047. if (self.query &&
  30048. isObject$1(self.query) &&
  30049. Object.keys(self.query).length) {
  30050. query = stringify$5(self.query);
  30051. }
  30052. var search = self.search || (query && ('?' + query)) || '';
  30053. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  30054. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  30055. // unless they had them to begin with.
  30056. if (self.slashes ||
  30057. (!protocol || slashedProtocol[protocol]) && host !== false) {
  30058. host = '//' + (host || '');
  30059. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  30060. } else if (!host) {
  30061. host = '';
  30062. }
  30063. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  30064. if (search && search.charAt(0) !== '?') search = '?' + search;
  30065. pathname = pathname.replace(/[?#]/g, function(match) {
  30066. return encodeURIComponent(match);
  30067. });
  30068. search = search.replace('#', '%23');
  30069. return protocol + host + pathname + search + hash;
  30070. }
  30071. Url.prototype.format = function() {
  30072. return format(this);
  30073. };
  30074. function urlResolve(source, relative) {
  30075. return urlParse(source, false, true).resolve(relative);
  30076. }
  30077. Url.prototype.resolve = function(relative) {
  30078. return this.resolveObject(urlParse(relative, false, true)).format();
  30079. };
  30080. function urlResolveObject(source, relative) {
  30081. if (!source) return relative;
  30082. return urlParse(source, false, true).resolveObject(relative);
  30083. }
  30084. Url.prototype.resolveObject = function(relative) {
  30085. if (isString$1(relative)) {
  30086. var rel = new Url();
  30087. rel.parse(relative, false, true);
  30088. relative = rel;
  30089. }
  30090. var result = new Url();
  30091. var tkeys = Object.keys(this);
  30092. for (var tk = 0; tk < tkeys.length; tk++) {
  30093. var tkey = tkeys[tk];
  30094. result[tkey] = this[tkey];
  30095. }
  30096. // hash is always overridden, no matter what.
  30097. // even href="" will remove it.
  30098. result.hash = relative.hash;
  30099. // if the relative url is empty, then there's nothing left to do here.
  30100. if (relative.href === '') {
  30101. result.href = result.format();
  30102. return result;
  30103. }
  30104. // hrefs like //foo/bar always cut to the protocol.
  30105. if (relative.slashes && !relative.protocol) {
  30106. // take everything except the protocol from relative
  30107. var rkeys = Object.keys(relative);
  30108. for (var rk = 0; rk < rkeys.length; rk++) {
  30109. var rkey = rkeys[rk];
  30110. if (rkey !== 'protocol')
  30111. result[rkey] = relative[rkey];
  30112. }
  30113. //urlParse appends trailing / to urls like http://www.example.com
  30114. if (slashedProtocol[result.protocol] &&
  30115. result.hostname && !result.pathname) {
  30116. result.path = result.pathname = '/';
  30117. }
  30118. result.href = result.format();
  30119. return result;
  30120. }
  30121. var relPath;
  30122. if (relative.protocol && relative.protocol !== result.protocol) {
  30123. // if it's a known url protocol, then changing
  30124. // the protocol does weird things
  30125. // first, if it's not file:, then we MUST have a host,
  30126. // and if there was a path
  30127. // to begin with, then we MUST have a path.
  30128. // if it is file:, then the host is dropped,
  30129. // because that's known to be hostless.
  30130. // anything else is assumed to be absolute.
  30131. if (!slashedProtocol[relative.protocol]) {
  30132. var keys = Object.keys(relative);
  30133. for (var v = 0; v < keys.length; v++) {
  30134. var k = keys[v];
  30135. result[k] = relative[k];
  30136. }
  30137. result.href = result.format();
  30138. return result;
  30139. }
  30140. result.protocol = relative.protocol;
  30141. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  30142. relPath = (relative.pathname || '').split('/');
  30143. while (relPath.length && !(relative.host = relPath.shift()));
  30144. if (!relative.host) relative.host = '';
  30145. if (!relative.hostname) relative.hostname = '';
  30146. if (relPath[0] !== '') relPath.unshift('');
  30147. if (relPath.length < 2) relPath.unshift('');
  30148. result.pathname = relPath.join('/');
  30149. } else {
  30150. result.pathname = relative.pathname;
  30151. }
  30152. result.search = relative.search;
  30153. result.query = relative.query;
  30154. result.host = relative.host || '';
  30155. result.auth = relative.auth;
  30156. result.hostname = relative.hostname || relative.host;
  30157. result.port = relative.port;
  30158. // to support http.request
  30159. if (result.pathname || result.search) {
  30160. var p = result.pathname || '';
  30161. var s = result.search || '';
  30162. result.path = p + s;
  30163. }
  30164. result.slashes = result.slashes || relative.slashes;
  30165. result.href = result.format();
  30166. return result;
  30167. }
  30168. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  30169. isRelAbs = (
  30170. relative.host ||
  30171. relative.pathname && relative.pathname.charAt(0) === '/'
  30172. ),
  30173. mustEndAbs = (isRelAbs || isSourceAbs ||
  30174. (result.host && relative.pathname)),
  30175. removeAllDots = mustEndAbs,
  30176. srcPath = result.pathname && result.pathname.split('/') || [],
  30177. psychotic = result.protocol && !slashedProtocol[result.protocol];
  30178. relPath = relative.pathname && relative.pathname.split('/') || [];
  30179. // if the url is a non-slashed url, then relative
  30180. // links like ../.. should be able
  30181. // to crawl up to the hostname, as well. This is strange.
  30182. // result.protocol has already been set by now.
  30183. // Later on, put the first path part into the host field.
  30184. if (psychotic) {
  30185. result.hostname = '';
  30186. result.port = null;
  30187. if (result.host) {
  30188. if (srcPath[0] === '') srcPath[0] = result.host;
  30189. else srcPath.unshift(result.host);
  30190. }
  30191. result.host = '';
  30192. if (relative.protocol) {
  30193. relative.hostname = null;
  30194. relative.port = null;
  30195. if (relative.host) {
  30196. if (relPath[0] === '') relPath[0] = relative.host;
  30197. else relPath.unshift(relative.host);
  30198. }
  30199. relative.host = null;
  30200. }
  30201. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  30202. }
  30203. var authInHost;
  30204. if (isRelAbs) {
  30205. // it's absolute.
  30206. result.host = (relative.host || relative.host === '') ?
  30207. relative.host : result.host;
  30208. result.hostname = (relative.hostname || relative.hostname === '') ?
  30209. relative.hostname : result.hostname;
  30210. result.search = relative.search;
  30211. result.query = relative.query;
  30212. srcPath = relPath;
  30213. // fall through to the dot-handling below.
  30214. } else if (relPath.length) {
  30215. // it's relative
  30216. // throw away the existing file, and take the new path instead.
  30217. if (!srcPath) srcPath = [];
  30218. srcPath.pop();
  30219. srcPath = srcPath.concat(relPath);
  30220. result.search = relative.search;
  30221. result.query = relative.query;
  30222. } else if (!isNullOrUndefined(relative.search)) {
  30223. // just pull out the search.
  30224. // like href='?foo'.
  30225. // Put this after the other two cases because it simplifies the booleans
  30226. if (psychotic) {
  30227. result.hostname = result.host = srcPath.shift();
  30228. //occationaly the auth can get stuck only in host
  30229. //this especially happens in cases like
  30230. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30231. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30232. result.host.split('@') : false;
  30233. if (authInHost) {
  30234. result.auth = authInHost.shift();
  30235. result.host = result.hostname = authInHost.shift();
  30236. }
  30237. }
  30238. result.search = relative.search;
  30239. result.query = relative.query;
  30240. //to support http.request
  30241. if (!isNull(result.pathname) || !isNull(result.search)) {
  30242. result.path = (result.pathname ? result.pathname : '') +
  30243. (result.search ? result.search : '');
  30244. }
  30245. result.href = result.format();
  30246. return result;
  30247. }
  30248. if (!srcPath.length) {
  30249. // no path at all. easy.
  30250. // we've already handled the other stuff above.
  30251. result.pathname = null;
  30252. //to support http.request
  30253. if (result.search) {
  30254. result.path = '/' + result.search;
  30255. } else {
  30256. result.path = null;
  30257. }
  30258. result.href = result.format();
  30259. return result;
  30260. }
  30261. // if a url ENDs in . or .., then it must get a trailing slash.
  30262. // however, if it ends in anything else non-slashy,
  30263. // then it must NOT get a trailing slash.
  30264. var last = srcPath.slice(-1)[0];
  30265. var hasTrailingSlash = (
  30266. (result.host || relative.host || srcPath.length > 1) &&
  30267. (last === '.' || last === '..') || last === '');
  30268. // strip single dots, resolve double dots to parent dir
  30269. // if the path tries to go above the root, `up` ends up > 0
  30270. var up = 0;
  30271. for (var i = srcPath.length; i >= 0; i--) {
  30272. last = srcPath[i];
  30273. if (last === '.') {
  30274. srcPath.splice(i, 1);
  30275. } else if (last === '..') {
  30276. srcPath.splice(i, 1);
  30277. up++;
  30278. } else if (up) {
  30279. srcPath.splice(i, 1);
  30280. up--;
  30281. }
  30282. }
  30283. // if the path is allowed to go above the root, restore leading ..s
  30284. if (!mustEndAbs && !removeAllDots) {
  30285. for (; up--; up) {
  30286. srcPath.unshift('..');
  30287. }
  30288. }
  30289. if (mustEndAbs && srcPath[0] !== '' &&
  30290. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  30291. srcPath.unshift('');
  30292. }
  30293. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  30294. srcPath.push('');
  30295. }
  30296. var isAbsolute = srcPath[0] === '' ||
  30297. (srcPath[0] && srcPath[0].charAt(0) === '/');
  30298. // put the host back
  30299. if (psychotic) {
  30300. result.hostname = result.host = isAbsolute ? '' :
  30301. srcPath.length ? srcPath.shift() : '';
  30302. //occationaly the auth can get stuck only in host
  30303. //this especially happens in cases like
  30304. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30305. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30306. result.host.split('@') : false;
  30307. if (authInHost) {
  30308. result.auth = authInHost.shift();
  30309. result.host = result.hostname = authInHost.shift();
  30310. }
  30311. }
  30312. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  30313. if (mustEndAbs && !isAbsolute) {
  30314. srcPath.unshift('');
  30315. }
  30316. if (!srcPath.length) {
  30317. result.pathname = null;
  30318. result.path = null;
  30319. } else {
  30320. result.pathname = srcPath.join('/');
  30321. }
  30322. //to support request.http
  30323. if (!isNull(result.pathname) || !isNull(result.search)) {
  30324. result.path = (result.pathname ? result.pathname : '') +
  30325. (result.search ? result.search : '');
  30326. }
  30327. result.auth = relative.auth || result.auth;
  30328. result.slashes = result.slashes || relative.slashes;
  30329. result.href = result.format();
  30330. return result;
  30331. };
  30332. Url.prototype.parseHost = function() {
  30333. return parseHost(this);
  30334. };
  30335. function parseHost(self) {
  30336. var host = self.host;
  30337. var port = portPattern.exec(host);
  30338. if (port) {
  30339. port = port[0];
  30340. if (port !== ':') {
  30341. self.port = port.substr(1);
  30342. }
  30343. host = host.substr(0, host.length - port.length);
  30344. }
  30345. if (host) self.hostname = host;
  30346. }
  30347. var _polyfillNode_url$1 = /*#__PURE__*/Object.freeze({
  30348. __proto__: null,
  30349. URL: URL$1,
  30350. URLSearchParams: URLSearchParams,
  30351. Url: Url,
  30352. default: _polyfillNode_url,
  30353. fileURLToPath: urlFileURLToPath,
  30354. format: urlFormat,
  30355. parse: urlParse,
  30356. resolve: urlResolve,
  30357. resolveObject: urlResolveObject
  30358. });
  30359. function isRelativeUrl(url) {
  30360. const firstChar = url.charAt(0);
  30361. return firstChar === "." || firstChar === "~" || firstChar === "@";
  30362. }
  30363. const externalRE = /^(https?:)?\/\//;
  30364. function isExternalUrl(url) {
  30365. return externalRE.test(url);
  30366. }
  30367. const dataUrlRE = /^\s*data:/i;
  30368. function isDataUrl(url) {
  30369. return dataUrlRE.test(url);
  30370. }
  30371. function parseUrl(url) {
  30372. const firstChar = url.charAt(0);
  30373. if (firstChar === "~") {
  30374. const secondChar = url.charAt(1);
  30375. url = url.slice(secondChar === "/" ? 2 : 1);
  30376. }
  30377. return parseUriParts(url);
  30378. }
  30379. function parseUriParts(urlString) {
  30380. return urlParse(isString$2(urlString) ? urlString : "", false, true);
  30381. }
  30382. var __defProp$9 = Object.defineProperty;
  30383. var __defProps$9 = Object.defineProperties;
  30384. var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
  30385. var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
  30386. var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
  30387. var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
  30388. var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  30389. var __spreadValues$9 = (a, b) => {
  30390. for (var prop in b || (b = {}))
  30391. if (__hasOwnProp$9.call(b, prop))
  30392. __defNormalProp$9(a, prop, b[prop]);
  30393. if (__getOwnPropSymbols$9)
  30394. for (var prop of __getOwnPropSymbols$9(b)) {
  30395. if (__propIsEnum$9.call(b, prop))
  30396. __defNormalProp$9(a, prop, b[prop]);
  30397. }
  30398. return a;
  30399. };
  30400. var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
  30401. const defaultAssetUrlOptions = {
  30402. base: null,
  30403. includeAbsolute: false,
  30404. tags: {
  30405. video: ["src", "poster"],
  30406. source: ["src"],
  30407. img: ["src"],
  30408. image: ["xlink:href", "href"],
  30409. use: ["xlink:href", "href"]
  30410. }
  30411. };
  30412. const normalizeOptions = (options) => {
  30413. if (Object.keys(options).some((key) => isArray$3(options[key]))) {
  30414. return __spreadProps$9(__spreadValues$9({}, defaultAssetUrlOptions), {
  30415. tags: options
  30416. });
  30417. }
  30418. return __spreadValues$9(__spreadValues$9({}, defaultAssetUrlOptions), options);
  30419. };
  30420. const createAssetUrlTransformWithOptions = (options) => {
  30421. return (node, context) => transformAssetUrl(node, context, options);
  30422. };
  30423. const transformAssetUrl = (node, context, options = defaultAssetUrlOptions) => {
  30424. if (node.type === 1) {
  30425. if (!node.props.length) {
  30426. return;
  30427. }
  30428. const tags = options.tags || defaultAssetUrlOptions.tags;
  30429. const attrs = tags[node.tag];
  30430. const wildCardAttrs = tags["*"];
  30431. if (!attrs && !wildCardAttrs) {
  30432. return;
  30433. }
  30434. const assetAttrs = (attrs || []).concat(wildCardAttrs || []);
  30435. node.props.forEach((attr, index) => {
  30436. if (attr.type !== 6 || !assetAttrs.includes(attr.name) || !attr.value || isExternalUrl(attr.value.content) || isDataUrl(attr.value.content) || attr.value.content[0] === "#" || !options.includeAbsolute && !isRelativeUrl(attr.value.content)) {
  30437. return;
  30438. }
  30439. const url = parseUrl(attr.value.content);
  30440. if (options.base && attr.value.content[0] === ".") {
  30441. const base = parseUrl(options.base);
  30442. const protocol = base.protocol || "";
  30443. const host = base.host ? protocol + "//" + base.host : "";
  30444. const basePath = base.path || "/";
  30445. attr.value.content = host + (path.posix || path).join(basePath, url.path + (url.hash || ""));
  30446. return;
  30447. }
  30448. const exp = getImportsExpressionExp(url.path, url.hash, attr.loc, context);
  30449. node.props[index] = {
  30450. type: 7,
  30451. name: "bind",
  30452. arg: createSimpleExpression(attr.name, true, attr.loc),
  30453. exp,
  30454. modifiers: [],
  30455. loc: attr.loc
  30456. };
  30457. });
  30458. }
  30459. };
  30460. function getImportsExpressionExp(path2, hash, loc, context) {
  30461. if (path2) {
  30462. let name;
  30463. let exp;
  30464. const existingIndex = context.imports.findIndex((i) => i.path === path2);
  30465. if (existingIndex > -1) {
  30466. name = `_imports_${existingIndex}`;
  30467. exp = context.imports[existingIndex].exp;
  30468. } else {
  30469. name = `_imports_${context.imports.length}`;
  30470. exp = createSimpleExpression(
  30471. name,
  30472. false,
  30473. loc,
  30474. 3
  30475. );
  30476. context.imports.push({ exp, path: path2 });
  30477. }
  30478. if (!hash) {
  30479. return exp;
  30480. }
  30481. const hashExp = `${name} + '${hash}'`;
  30482. const finalExp = createSimpleExpression(
  30483. hashExp,
  30484. false,
  30485. loc,
  30486. 3
  30487. );
  30488. if (!context.hoistStatic) {
  30489. return finalExp;
  30490. }
  30491. const existingHoistIndex = context.hoists.findIndex((h) => {
  30492. return h && h.type === 4 && !h.isStatic && h.content === hashExp;
  30493. });
  30494. if (existingHoistIndex > -1) {
  30495. return createSimpleExpression(
  30496. `_hoisted_${existingHoistIndex + 1}`,
  30497. false,
  30498. loc,
  30499. 3
  30500. );
  30501. }
  30502. return context.hoist(finalExp);
  30503. } else {
  30504. return createSimpleExpression(`''`, false, loc, 3);
  30505. }
  30506. }
  30507. const srcsetTags = ["img", "source"];
  30508. const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g;
  30509. const createSrcsetTransformWithOptions = (options) => {
  30510. return (node, context) => transformSrcset(node, context, options);
  30511. };
  30512. const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
  30513. if (node.type === 1) {
  30514. if (srcsetTags.includes(node.tag) && node.props.length) {
  30515. node.props.forEach((attr, index) => {
  30516. if (attr.name === "srcset" && attr.type === 6) {
  30517. if (!attr.value)
  30518. return;
  30519. const value = attr.value.content;
  30520. if (!value)
  30521. return;
  30522. const imageCandidates = value.split(",").map((s) => {
  30523. const [url, descriptor] = s.replace(escapedSpaceCharacters, " ").trim().split(" ", 2);
  30524. return { url, descriptor };
  30525. });
  30526. for (let i = 0; i < imageCandidates.length; i++) {
  30527. const { url } = imageCandidates[i];
  30528. if (isDataUrl(url)) {
  30529. imageCandidates[i + 1].url = url + "," + imageCandidates[i + 1].url;
  30530. imageCandidates.splice(i, 1);
  30531. }
  30532. }
  30533. const shouldProcessUrl = (url) => {
  30534. return !isExternalUrl(url) && !isDataUrl(url) && (options.includeAbsolute || isRelativeUrl(url));
  30535. };
  30536. if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
  30537. return;
  30538. }
  30539. if (options.base) {
  30540. const base = options.base;
  30541. const set = [];
  30542. let needImportTransform = false;
  30543. imageCandidates.forEach((candidate) => {
  30544. let { url, descriptor } = candidate;
  30545. descriptor = descriptor ? ` ${descriptor}` : ``;
  30546. if (url[0] === ".") {
  30547. candidate.url = (path.posix || path).join(base, url);
  30548. set.push(candidate.url + descriptor);
  30549. } else if (shouldProcessUrl(url)) {
  30550. needImportTransform = true;
  30551. } else {
  30552. set.push(url + descriptor);
  30553. }
  30554. });
  30555. if (!needImportTransform) {
  30556. attr.value.content = set.join(", ");
  30557. return;
  30558. }
  30559. }
  30560. const compoundExpression = createCompoundExpression([], attr.loc);
  30561. imageCandidates.forEach(({ url, descriptor }, index2) => {
  30562. if (shouldProcessUrl(url)) {
  30563. const { path: path2 } = parseUrl(url);
  30564. let exp2;
  30565. if (path2) {
  30566. const existingImportsIndex = context.imports.findIndex(
  30567. (i) => i.path === path2
  30568. );
  30569. if (existingImportsIndex > -1) {
  30570. exp2 = createSimpleExpression(
  30571. `_imports_${existingImportsIndex}`,
  30572. false,
  30573. attr.loc,
  30574. 3
  30575. );
  30576. } else {
  30577. exp2 = createSimpleExpression(
  30578. `_imports_${context.imports.length}`,
  30579. false,
  30580. attr.loc,
  30581. 3
  30582. );
  30583. context.imports.push({ exp: exp2, path: path2 });
  30584. }
  30585. compoundExpression.children.push(exp2);
  30586. }
  30587. } else {
  30588. const exp2 = createSimpleExpression(
  30589. `"${url}"`,
  30590. false,
  30591. attr.loc,
  30592. 3
  30593. );
  30594. compoundExpression.children.push(exp2);
  30595. }
  30596. const isNotLast = imageCandidates.length - 1 > index2;
  30597. if (descriptor && isNotLast) {
  30598. compoundExpression.children.push(` + ' ${descriptor}, ' + `);
  30599. } else if (descriptor) {
  30600. compoundExpression.children.push(` + ' ${descriptor}'`);
  30601. } else if (isNotLast) {
  30602. compoundExpression.children.push(` + ', ' + `);
  30603. }
  30604. });
  30605. let exp = compoundExpression;
  30606. if (context.hoistStatic) {
  30607. exp = context.hoist(compoundExpression);
  30608. exp.constType = 3;
  30609. }
  30610. node.props[index] = {
  30611. type: 7,
  30612. name: "bind",
  30613. arg: createSimpleExpression("srcset", true, attr.loc),
  30614. exp,
  30615. modifiers: [],
  30616. loc: attr.loc
  30617. };
  30618. }
  30619. });
  30620. }
  30621. }
  30622. };
  30623. const SSR_INTERPOLATE = Symbol(`ssrInterpolate`);
  30624. const SSR_RENDER_VNODE = Symbol(`ssrRenderVNode`);
  30625. const SSR_RENDER_COMPONENT = Symbol(`ssrRenderComponent`);
  30626. const SSR_RENDER_SLOT = Symbol(`ssrRenderSlot`);
  30627. const SSR_RENDER_SLOT_INNER = Symbol(`ssrRenderSlotInner`);
  30628. const SSR_RENDER_CLASS = Symbol(`ssrRenderClass`);
  30629. const SSR_RENDER_STYLE = Symbol(`ssrRenderStyle`);
  30630. const SSR_RENDER_ATTRS = Symbol(`ssrRenderAttrs`);
  30631. const SSR_RENDER_ATTR = Symbol(`ssrRenderAttr`);
  30632. const SSR_RENDER_DYNAMIC_ATTR = Symbol(`ssrRenderDynamicAttr`);
  30633. const SSR_RENDER_LIST = Symbol(`ssrRenderList`);
  30634. const SSR_INCLUDE_BOOLEAN_ATTR = Symbol(`ssrIncludeBooleanAttr`);
  30635. const SSR_LOOSE_EQUAL = Symbol(`ssrLooseEqual`);
  30636. const SSR_LOOSE_CONTAIN = Symbol(`ssrLooseContain`);
  30637. const SSR_RENDER_DYNAMIC_MODEL = Symbol(`ssrRenderDynamicModel`);
  30638. const SSR_GET_DYNAMIC_MODEL_PROPS = Symbol(`ssrGetDynamicModelProps`);
  30639. const SSR_RENDER_TELEPORT = Symbol(`ssrRenderTeleport`);
  30640. const SSR_RENDER_SUSPENSE = Symbol(`ssrRenderSuspense`);
  30641. const SSR_GET_DIRECTIVE_PROPS = Symbol(`ssrGetDirectiveProps`);
  30642. const ssrHelpers = {
  30643. [SSR_INTERPOLATE]: `ssrInterpolate`,
  30644. [SSR_RENDER_VNODE]: `ssrRenderVNode`,
  30645. [SSR_RENDER_COMPONENT]: `ssrRenderComponent`,
  30646. [SSR_RENDER_SLOT]: `ssrRenderSlot`,
  30647. [SSR_RENDER_SLOT_INNER]: `ssrRenderSlotInner`,
  30648. [SSR_RENDER_CLASS]: `ssrRenderClass`,
  30649. [SSR_RENDER_STYLE]: `ssrRenderStyle`,
  30650. [SSR_RENDER_ATTRS]: `ssrRenderAttrs`,
  30651. [SSR_RENDER_ATTR]: `ssrRenderAttr`,
  30652. [SSR_RENDER_DYNAMIC_ATTR]: `ssrRenderDynamicAttr`,
  30653. [SSR_RENDER_LIST]: `ssrRenderList`,
  30654. [SSR_INCLUDE_BOOLEAN_ATTR]: `ssrIncludeBooleanAttr`,
  30655. [SSR_LOOSE_EQUAL]: `ssrLooseEqual`,
  30656. [SSR_LOOSE_CONTAIN]: `ssrLooseContain`,
  30657. [SSR_RENDER_DYNAMIC_MODEL]: `ssrRenderDynamicModel`,
  30658. [SSR_GET_DYNAMIC_MODEL_PROPS]: `ssrGetDynamicModelProps`,
  30659. [SSR_RENDER_TELEPORT]: `ssrRenderTeleport`,
  30660. [SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`,
  30661. [SSR_GET_DIRECTIVE_PROPS]: `ssrGetDirectiveProps`
  30662. };
  30663. registerRuntimeHelpers(ssrHelpers);
  30664. const ssrTransformIf = createStructuralDirectiveTransform(
  30665. /^(if|else|else-if)$/,
  30666. processIf
  30667. );
  30668. function ssrProcessIf(node, context, disableNestedFragments = false) {
  30669. const [rootBranch] = node.branches;
  30670. const ifStatement = createIfStatement(
  30671. rootBranch.condition,
  30672. processIfBranch(rootBranch, context, disableNestedFragments)
  30673. );
  30674. context.pushStatement(ifStatement);
  30675. let currentIf = ifStatement;
  30676. for (let i = 1; i < node.branches.length; i++) {
  30677. const branch = node.branches[i];
  30678. const branchBlockStatement = processIfBranch(
  30679. branch,
  30680. context,
  30681. disableNestedFragments
  30682. );
  30683. if (branch.condition) {
  30684. currentIf = currentIf.alternate = createIfStatement(
  30685. branch.condition,
  30686. branchBlockStatement
  30687. );
  30688. } else {
  30689. currentIf.alternate = branchBlockStatement;
  30690. }
  30691. }
  30692. if (!currentIf.alternate) {
  30693. currentIf.alternate = createBlockStatement([
  30694. createCallExpression(`_push`, ["`<!---->`"])
  30695. ]);
  30696. }
  30697. }
  30698. function processIfBranch(branch, context, disableNestedFragments = false) {
  30699. const { children } = branch;
  30700. const needFragmentWrapper = !disableNestedFragments && (children.length !== 1 || children[0].type !== 1) && // optimize away nested fragments when the only child is a ForNode
  30701. !(children.length === 1 && children[0].type === 11);
  30702. return processChildrenAsStatement(branch, context, needFragmentWrapper);
  30703. }
  30704. const ssrTransformFor = createStructuralDirectiveTransform(
  30705. "for",
  30706. processFor
  30707. );
  30708. function ssrProcessFor(node, context, disableNestedFragments = false) {
  30709. const needFragmentWrapper = !disableNestedFragments && (node.children.length !== 1 || node.children[0].type !== 1);
  30710. const renderLoop = createFunctionExpression(
  30711. createForLoopParams(node.parseResult)
  30712. );
  30713. renderLoop.body = processChildrenAsStatement(
  30714. node,
  30715. context,
  30716. needFragmentWrapper
  30717. );
  30718. if (!disableNestedFragments) {
  30719. context.pushStringPart(`<!--[-->`);
  30720. }
  30721. context.pushStatement(
  30722. createCallExpression(context.helper(SSR_RENDER_LIST), [
  30723. node.source,
  30724. renderLoop
  30725. ])
  30726. );
  30727. if (!disableNestedFragments) {
  30728. context.pushStringPart(`<!--]-->`);
  30729. }
  30730. }
  30731. const ssrTransformSlotOutlet = (node, context) => {
  30732. if (isSlotOutlet(node)) {
  30733. const { slotName, slotProps } = processSlotOutlet(node, context);
  30734. const args = [
  30735. `_ctx.$slots`,
  30736. slotName,
  30737. slotProps || `{}`,
  30738. // fallback content placeholder. will be replaced in the process phase
  30739. `null`,
  30740. `_push`,
  30741. `_parent`
  30742. ];
  30743. if (context.scopeId && context.slotted !== false) {
  30744. args.push(`"${context.scopeId}-s"`);
  30745. }
  30746. let method = SSR_RENDER_SLOT;
  30747. const parent = context.parent;
  30748. if (parent && parent.type === 1 && parent.tagType === 1 && resolveComponentType(parent, context, true) === TRANSITION && parent.children.filter((c) => c.type === 1).length === 1) {
  30749. method = SSR_RENDER_SLOT_INNER;
  30750. if (!(context.scopeId && context.slotted !== false)) {
  30751. args.push("null");
  30752. }
  30753. args.push("true");
  30754. }
  30755. node.ssrCodegenNode = createCallExpression(context.helper(method), args);
  30756. }
  30757. };
  30758. function ssrProcessSlotOutlet(node, context) {
  30759. const renderCall = node.ssrCodegenNode;
  30760. if (node.children.length) {
  30761. const fallbackRenderFn = createFunctionExpression([]);
  30762. fallbackRenderFn.body = processChildrenAsStatement(node, context);
  30763. renderCall.arguments[3] = fallbackRenderFn;
  30764. }
  30765. if (context.withSlotScopeId) {
  30766. const slotScopeId = renderCall.arguments[6];
  30767. renderCall.arguments[6] = slotScopeId ? `${slotScopeId} + _scopeId` : `_scopeId`;
  30768. }
  30769. context.pushStatement(node.ssrCodegenNode);
  30770. }
  30771. function createSSRCompilerError(code, loc) {
  30772. return createCompilerError(code, loc, SSRErrorMessages);
  30773. }
  30774. const SSRErrorMessages = {
  30775. [65]: `Unsafe attribute name for SSR.`,
  30776. [66]: `Missing the 'to' prop on teleport element.`,
  30777. [67]: `Invalid AST node during SSR transform.`
  30778. };
  30779. function ssrProcessTeleport(node, context) {
  30780. const targetProp = findProp(node, "to");
  30781. if (!targetProp) {
  30782. context.onError(
  30783. createSSRCompilerError(66, node.loc)
  30784. );
  30785. return;
  30786. }
  30787. let target;
  30788. if (targetProp.type === 6) {
  30789. target = targetProp.value && createSimpleExpression(targetProp.value.content, true);
  30790. } else {
  30791. target = targetProp.exp;
  30792. }
  30793. if (!target) {
  30794. context.onError(
  30795. createSSRCompilerError(
  30796. 66,
  30797. targetProp.loc
  30798. )
  30799. );
  30800. return;
  30801. }
  30802. const disabledProp = findProp(
  30803. node,
  30804. "disabled",
  30805. false,
  30806. true
  30807. /* allow empty */
  30808. );
  30809. const disabled = disabledProp ? disabledProp.type === 6 ? `true` : disabledProp.exp || `false` : `false`;
  30810. const contentRenderFn = createFunctionExpression(
  30811. [`_push`],
  30812. void 0,
  30813. // Body is added later
  30814. true,
  30815. // newline
  30816. false,
  30817. // isSlot
  30818. node.loc
  30819. );
  30820. contentRenderFn.body = processChildrenAsStatement(node, context);
  30821. context.pushStatement(
  30822. createCallExpression(context.helper(SSR_RENDER_TELEPORT), [
  30823. `_push`,
  30824. contentRenderFn,
  30825. target,
  30826. disabled,
  30827. `_parent`
  30828. ])
  30829. );
  30830. }
  30831. const wipMap$2 = /* @__PURE__ */ new WeakMap();
  30832. function ssrTransformSuspense(node, context) {
  30833. return () => {
  30834. if (node.children.length) {
  30835. const wipEntry = {
  30836. slotsExp: null,
  30837. // to be immediately set
  30838. wipSlots: []
  30839. };
  30840. wipMap$2.set(node, wipEntry);
  30841. wipEntry.slotsExp = buildSlots(node, context, (_props, children, loc) => {
  30842. const fn = createFunctionExpression(
  30843. [],
  30844. void 0,
  30845. // no return, assign body later
  30846. true,
  30847. // newline
  30848. false,
  30849. // suspense slots are not treated as normal slots
  30850. loc
  30851. );
  30852. wipEntry.wipSlots.push({
  30853. fn,
  30854. children
  30855. });
  30856. return fn;
  30857. }).slots;
  30858. }
  30859. };
  30860. }
  30861. function ssrProcessSuspense(node, context) {
  30862. const wipEntry = wipMap$2.get(node);
  30863. if (!wipEntry) {
  30864. return;
  30865. }
  30866. const { slotsExp, wipSlots } = wipEntry;
  30867. for (let i = 0; i < wipSlots.length; i++) {
  30868. const slot = wipSlots[i];
  30869. slot.fn.body = processChildrenAsStatement(slot, context);
  30870. }
  30871. context.pushStatement(
  30872. createCallExpression(context.helper(SSR_RENDER_SUSPENSE), [
  30873. `_push`,
  30874. slotsExp
  30875. ])
  30876. );
  30877. }
  30878. const rawChildrenMap = /* @__PURE__ */ new WeakMap();
  30879. const ssrTransformElement = (node, context) => {
  30880. if (node.type !== 1 || node.tagType !== 0) {
  30881. return;
  30882. }
  30883. return function ssrPostTransformElement() {
  30884. const openTag = [`<${node.tag}`];
  30885. const needTagForRuntime = node.tag === "textarea" || node.tag.indexOf("-") > 0;
  30886. const hasDynamicVBind = hasDynamicKeyVBind(node);
  30887. const hasCustomDir = node.props.some(
  30888. (p) => p.type === 7 && !isBuiltInDirective(p.name)
  30889. );
  30890. const needMergeProps = hasDynamicVBind || hasCustomDir;
  30891. if (needMergeProps) {
  30892. const { props, directives } = buildProps(
  30893. node,
  30894. context,
  30895. node.props,
  30896. false,
  30897. false,
  30898. true
  30899. /* ssr */
  30900. );
  30901. if (props || directives.length) {
  30902. const mergedProps = buildSSRProps(props, directives, context);
  30903. const propsExp = createCallExpression(
  30904. context.helper(SSR_RENDER_ATTRS),
  30905. [mergedProps]
  30906. );
  30907. if (node.tag === "textarea") {
  30908. const existingText = node.children[0];
  30909. if (!existingText || existingText.type !== 5) {
  30910. const tempId = `_temp${context.temps++}`;
  30911. propsExp.arguments = [
  30912. createAssignmentExpression(
  30913. createSimpleExpression(tempId, false),
  30914. mergedProps
  30915. )
  30916. ];
  30917. rawChildrenMap.set(
  30918. node,
  30919. createCallExpression(context.helper(SSR_INTERPOLATE), [
  30920. createConditionalExpression(
  30921. createSimpleExpression(`"value" in ${tempId}`, false),
  30922. createSimpleExpression(`${tempId}.value`, false),
  30923. createSimpleExpression(
  30924. existingText ? existingText.content : ``,
  30925. true
  30926. ),
  30927. false
  30928. )
  30929. ])
  30930. );
  30931. }
  30932. } else if (node.tag === "input") {
  30933. const vModel = findVModel(node);
  30934. if (vModel) {
  30935. const tempId = `_temp${context.temps++}`;
  30936. const tempExp = createSimpleExpression(tempId, false);
  30937. propsExp.arguments = [
  30938. createSequenceExpression([
  30939. createAssignmentExpression(tempExp, mergedProps),
  30940. createCallExpression(context.helper(MERGE_PROPS), [
  30941. tempExp,
  30942. createCallExpression(
  30943. context.helper(SSR_GET_DYNAMIC_MODEL_PROPS),
  30944. [
  30945. tempExp,
  30946. // existing props
  30947. vModel.exp
  30948. // model
  30949. ]
  30950. )
  30951. ])
  30952. ])
  30953. ];
  30954. }
  30955. }
  30956. if (needTagForRuntime) {
  30957. propsExp.arguments.push(`"${node.tag}"`);
  30958. }
  30959. openTag.push(propsExp);
  30960. }
  30961. }
  30962. let dynamicClassBinding = void 0;
  30963. let staticClassBinding = void 0;
  30964. let dynamicStyleBinding = void 0;
  30965. for (let i = 0; i < node.props.length; i++) {
  30966. const prop = node.props[i];
  30967. if (node.tag === "input" && isTrueFalseValue(prop)) {
  30968. continue;
  30969. }
  30970. if (prop.type === 7) {
  30971. if (prop.name === "html" && prop.exp) {
  30972. rawChildrenMap.set(node, prop.exp);
  30973. } else if (prop.name === "text" && prop.exp) {
  30974. node.children = [createInterpolation(prop.exp, prop.loc)];
  30975. } else if (prop.name === "slot") {
  30976. context.onError(
  30977. createCompilerError(40, prop.loc)
  30978. );
  30979. } else if (isTextareaWithValue(node, prop) && prop.exp) {
  30980. if (!needMergeProps) {
  30981. node.children = [createInterpolation(prop.exp, prop.loc)];
  30982. }
  30983. } else if (!needMergeProps && prop.name !== "on") {
  30984. const directiveTransform = context.directiveTransforms[prop.name];
  30985. if (directiveTransform) {
  30986. const { props, ssrTagParts } = directiveTransform(
  30987. prop,
  30988. node,
  30989. context
  30990. );
  30991. if (ssrTagParts) {
  30992. openTag.push(...ssrTagParts);
  30993. }
  30994. for (let j = 0; j < props.length; j++) {
  30995. const { key, value } = props[j];
  30996. if (isStaticExp(key)) {
  30997. let attrName = key.content;
  30998. if (attrName === "key" || attrName === "ref") {
  30999. continue;
  31000. }
  31001. if (attrName === "class") {
  31002. openTag.push(
  31003. ` class="`,
  31004. dynamicClassBinding = createCallExpression(
  31005. context.helper(SSR_RENDER_CLASS),
  31006. [value]
  31007. ),
  31008. `"`
  31009. );
  31010. } else if (attrName === "style") {
  31011. if (dynamicStyleBinding) {
  31012. mergeCall(dynamicStyleBinding, value);
  31013. } else {
  31014. openTag.push(
  31015. ` style="`,
  31016. dynamicStyleBinding = createCallExpression(
  31017. context.helper(SSR_RENDER_STYLE),
  31018. [value]
  31019. ),
  31020. `"`
  31021. );
  31022. }
  31023. } else {
  31024. attrName = node.tag.indexOf("-") > 0 ? attrName : propsToAttrMap[attrName] || attrName.toLowerCase();
  31025. if (isBooleanAttr(attrName)) {
  31026. openTag.push(
  31027. createConditionalExpression(
  31028. createCallExpression(
  31029. context.helper(SSR_INCLUDE_BOOLEAN_ATTR),
  31030. [value]
  31031. ),
  31032. createSimpleExpression(" " + attrName, true),
  31033. createSimpleExpression("", true),
  31034. false
  31035. /* no newline */
  31036. )
  31037. );
  31038. } else if (isSSRSafeAttrName(attrName)) {
  31039. openTag.push(
  31040. createCallExpression(context.helper(SSR_RENDER_ATTR), [
  31041. key,
  31042. value
  31043. ])
  31044. );
  31045. } else {
  31046. context.onError(
  31047. createSSRCompilerError(
  31048. 65,
  31049. key.loc
  31050. )
  31051. );
  31052. }
  31053. }
  31054. } else {
  31055. const args = [key, value];
  31056. if (needTagForRuntime) {
  31057. args.push(`"${node.tag}"`);
  31058. }
  31059. openTag.push(
  31060. createCallExpression(
  31061. context.helper(SSR_RENDER_DYNAMIC_ATTR),
  31062. args
  31063. )
  31064. );
  31065. }
  31066. }
  31067. }
  31068. }
  31069. } else {
  31070. if (node.tag === "textarea" && prop.name === "value" && prop.value) {
  31071. rawChildrenMap.set(node, escapeHtml(prop.value.content));
  31072. } else if (!needMergeProps) {
  31073. if (prop.name === "key" || prop.name === "ref") {
  31074. continue;
  31075. }
  31076. if (prop.name === "class" && prop.value) {
  31077. staticClassBinding = JSON.stringify(prop.value.content);
  31078. }
  31079. openTag.push(
  31080. ` ${prop.name}` + (prop.value ? `="${escapeHtml(prop.value.content)}"` : ``)
  31081. );
  31082. }
  31083. }
  31084. }
  31085. if (dynamicClassBinding && staticClassBinding) {
  31086. mergeCall(dynamicClassBinding, staticClassBinding);
  31087. removeStaticBinding(openTag, "class");
  31088. }
  31089. if (context.scopeId) {
  31090. openTag.push(` ${context.scopeId}`);
  31091. }
  31092. node.ssrCodegenNode = createTemplateLiteral(openTag);
  31093. };
  31094. };
  31095. function buildSSRProps(props, directives, context) {
  31096. let mergePropsArgs = [];
  31097. if (props) {
  31098. if (props.type === 14) {
  31099. mergePropsArgs = props.arguments;
  31100. } else {
  31101. mergePropsArgs.push(props);
  31102. }
  31103. }
  31104. if (directives.length) {
  31105. for (const dir of directives) {
  31106. mergePropsArgs.push(
  31107. createCallExpression(context.helper(SSR_GET_DIRECTIVE_PROPS), [
  31108. `_ctx`,
  31109. ...buildDirectiveArgs(dir, context).elements
  31110. ])
  31111. );
  31112. }
  31113. }
  31114. return mergePropsArgs.length > 1 ? createCallExpression(context.helper(MERGE_PROPS), mergePropsArgs) : mergePropsArgs[0];
  31115. }
  31116. function isTrueFalseValue(prop) {
  31117. if (prop.type === 7) {
  31118. return prop.name === "bind" && prop.arg && isStaticExp(prop.arg) && (prop.arg.content === "true-value" || prop.arg.content === "false-value");
  31119. } else {
  31120. return prop.name === "true-value" || prop.name === "false-value";
  31121. }
  31122. }
  31123. function isTextareaWithValue(node, prop) {
  31124. return !!(node.tag === "textarea" && prop.name === "bind" && isStaticArgOf(prop.arg, "value"));
  31125. }
  31126. function mergeCall(call, arg) {
  31127. const existing = call.arguments[0];
  31128. if (existing.type === 17) {
  31129. existing.elements.push(arg);
  31130. } else {
  31131. call.arguments[0] = createArrayExpression([existing, arg]);
  31132. }
  31133. }
  31134. function removeStaticBinding(tag, binding) {
  31135. const regExp = new RegExp(`^ ${binding}=".+"$`);
  31136. const i = tag.findIndex((e) => typeof e === "string" && regExp.test(e));
  31137. if (i > -1) {
  31138. tag.splice(i, 1);
  31139. }
  31140. }
  31141. function findVModel(node) {
  31142. return node.props.find(
  31143. (p) => p.type === 7 && p.name === "model" && p.exp
  31144. );
  31145. }
  31146. function ssrProcessElement(node, context) {
  31147. const isVoidTag = context.options.isVoidTag || NO;
  31148. const elementsToAdd = node.ssrCodegenNode.elements;
  31149. for (let j = 0; j < elementsToAdd.length; j++) {
  31150. context.pushStringPart(elementsToAdd[j]);
  31151. }
  31152. if (context.withSlotScopeId) {
  31153. context.pushStringPart(createSimpleExpression(`_scopeId`, false));
  31154. }
  31155. context.pushStringPart(`>`);
  31156. const rawChildren = rawChildrenMap.get(node);
  31157. if (rawChildren) {
  31158. context.pushStringPart(rawChildren);
  31159. } else if (node.children.length) {
  31160. processChildren(node, context);
  31161. }
  31162. if (!isVoidTag(node.tag)) {
  31163. context.pushStringPart(`</${node.tag}>`);
  31164. }
  31165. }
  31166. const wipMap$1 = /* @__PURE__ */ new WeakMap();
  31167. function ssrTransformTransitionGroup(node, context) {
  31168. return () => {
  31169. const tag = findProp(node, "tag");
  31170. if (tag) {
  31171. const otherProps = node.props.filter((p) => p !== tag);
  31172. const { props, directives } = buildProps(
  31173. node,
  31174. context,
  31175. otherProps,
  31176. true,
  31177. false,
  31178. true
  31179. /* ssr (skip event listeners) */
  31180. );
  31181. let propsExp = null;
  31182. if (props || directives.length) {
  31183. propsExp = createCallExpression(context.helper(SSR_RENDER_ATTRS), [
  31184. buildSSRProps(props, directives, context)
  31185. ]);
  31186. }
  31187. wipMap$1.set(node, {
  31188. tag,
  31189. propsExp
  31190. });
  31191. }
  31192. };
  31193. }
  31194. function ssrProcessTransitionGroup(node, context) {
  31195. const entry = wipMap$1.get(node);
  31196. if (entry) {
  31197. const { tag, propsExp } = entry;
  31198. if (tag.type === 7) {
  31199. context.pushStringPart(`<`);
  31200. context.pushStringPart(tag.exp);
  31201. if (propsExp) {
  31202. context.pushStringPart(propsExp);
  31203. }
  31204. context.pushStringPart(`>`);
  31205. processChildren(
  31206. node,
  31207. context,
  31208. false,
  31209. /**
  31210. * TransitionGroup has the special runtime behavior of flattening and
  31211. * concatenating all children into a single fragment (in order for them to
  31212. * be patched using the same key map) so we need to account for that here
  31213. * by disabling nested fragment wrappers from being generated.
  31214. */
  31215. true
  31216. );
  31217. context.pushStringPart(`</`);
  31218. context.pushStringPart(tag.exp);
  31219. context.pushStringPart(`>`);
  31220. } else {
  31221. context.pushStringPart(`<${tag.value.content}`);
  31222. if (propsExp) {
  31223. context.pushStringPart(propsExp);
  31224. }
  31225. context.pushStringPart(`>`);
  31226. processChildren(node, context, false, true);
  31227. context.pushStringPart(`</${tag.value.content}>`);
  31228. }
  31229. } else {
  31230. processChildren(node, context, true, true);
  31231. }
  31232. }
  31233. var __defProp$8 = Object.defineProperty;
  31234. var __defProps$8 = Object.defineProperties;
  31235. var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
  31236. var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
  31237. var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
  31238. var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
  31239. var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  31240. var __spreadValues$8 = (a, b) => {
  31241. for (var prop in b || (b = {}))
  31242. if (__hasOwnProp$8.call(b, prop))
  31243. __defNormalProp$8(a, prop, b[prop]);
  31244. if (__getOwnPropSymbols$8)
  31245. for (var prop of __getOwnPropSymbols$8(b)) {
  31246. if (__propIsEnum$8.call(b, prop))
  31247. __defNormalProp$8(a, prop, b[prop]);
  31248. }
  31249. return a;
  31250. };
  31251. var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
  31252. const wipMap = /* @__PURE__ */ new WeakMap();
  31253. const WIP_SLOT = Symbol();
  31254. const componentTypeMap = /* @__PURE__ */ new WeakMap();
  31255. const ssrTransformComponent = (node, context) => {
  31256. if (node.type !== 1 || node.tagType !== 1) {
  31257. return;
  31258. }
  31259. const component = resolveComponentType(
  31260. node,
  31261. context,
  31262. true
  31263. /* ssr */
  31264. );
  31265. const isDynamicComponent = isObject$2(component) && component.callee === RESOLVE_DYNAMIC_COMPONENT;
  31266. componentTypeMap.set(node, component);
  31267. if (isSymbol$1(component)) {
  31268. if (component === SUSPENSE) {
  31269. return ssrTransformSuspense(node, context);
  31270. }
  31271. if (component === TRANSITION_GROUP) {
  31272. return ssrTransformTransitionGroup(node, context);
  31273. }
  31274. return;
  31275. }
  31276. const vnodeBranches = [];
  31277. const clonedNode = clone(node);
  31278. return function ssrPostTransformComponent() {
  31279. if (clonedNode.children.length) {
  31280. buildSlots(clonedNode, context, (props, children) => {
  31281. vnodeBranches.push(createVNodeSlotBranch(props, children, context));
  31282. return createFunctionExpression(void 0);
  31283. });
  31284. }
  31285. let propsExp = `null`;
  31286. if (node.props.length) {
  31287. const { props, directives } = buildProps(
  31288. node,
  31289. context,
  31290. void 0,
  31291. true,
  31292. isDynamicComponent
  31293. );
  31294. if (props || directives.length) {
  31295. propsExp = buildSSRProps(props, directives, context);
  31296. }
  31297. }
  31298. const wipEntries = [];
  31299. wipMap.set(node, wipEntries);
  31300. const buildSSRSlotFn = (props, children, loc) => {
  31301. const param0 = props && stringifyExpression(props) || `_`;
  31302. const fn = createFunctionExpression(
  31303. [param0, `_push`, `_parent`, `_scopeId`],
  31304. void 0,
  31305. // no return, assign body later
  31306. true,
  31307. // newline
  31308. true,
  31309. // isSlot
  31310. loc
  31311. );
  31312. wipEntries.push({
  31313. type: WIP_SLOT,
  31314. fn,
  31315. children,
  31316. // also collect the corresponding vnode branch built earlier
  31317. vnodeBranch: vnodeBranches[wipEntries.length]
  31318. });
  31319. return fn;
  31320. };
  31321. const slots = node.children.length ? buildSlots(node, context, buildSSRSlotFn).slots : `null`;
  31322. if (typeof component !== "string") {
  31323. node.ssrCodegenNode = createCallExpression(
  31324. context.helper(SSR_RENDER_VNODE),
  31325. [
  31326. `_push`,
  31327. createCallExpression(context.helper(CREATE_VNODE), [
  31328. component,
  31329. propsExp,
  31330. slots
  31331. ]),
  31332. `_parent`
  31333. ]
  31334. );
  31335. } else {
  31336. node.ssrCodegenNode = createCallExpression(
  31337. context.helper(SSR_RENDER_COMPONENT),
  31338. [component, propsExp, slots, `_parent`]
  31339. );
  31340. }
  31341. };
  31342. };
  31343. function ssrProcessComponent(node, context, parent) {
  31344. const component = componentTypeMap.get(node);
  31345. if (!node.ssrCodegenNode) {
  31346. if (component === TELEPORT) {
  31347. return ssrProcessTeleport(node, context);
  31348. } else if (component === SUSPENSE) {
  31349. return ssrProcessSuspense(node, context);
  31350. } else if (component === TRANSITION_GROUP) {
  31351. return ssrProcessTransitionGroup(node, context);
  31352. } else {
  31353. if (parent.type === WIP_SLOT) {
  31354. context.pushStringPart(``);
  31355. }
  31356. if (component === TRANSITION) {
  31357. node.children = node.children.filter((c) => c.type !== 3);
  31358. }
  31359. processChildren(node, context);
  31360. }
  31361. } else {
  31362. const wipEntries = wipMap.get(node) || [];
  31363. for (let i = 0; i < wipEntries.length; i++) {
  31364. const { fn, vnodeBranch } = wipEntries[i];
  31365. fn.body = createIfStatement(
  31366. createSimpleExpression(`_push`, false),
  31367. processChildrenAsStatement(
  31368. wipEntries[i],
  31369. context,
  31370. false,
  31371. true
  31372. /* withSlotScopeId */
  31373. ),
  31374. vnodeBranch
  31375. );
  31376. }
  31377. if (context.withSlotScopeId) {
  31378. node.ssrCodegenNode.arguments.push(`_scopeId`);
  31379. }
  31380. if (typeof component === "string") {
  31381. context.pushStatement(
  31382. createCallExpression(`_push`, [node.ssrCodegenNode])
  31383. );
  31384. } else {
  31385. context.pushStatement(node.ssrCodegenNode);
  31386. }
  31387. }
  31388. }
  31389. const rawOptionsMap = /* @__PURE__ */ new WeakMap();
  31390. const [baseNodeTransforms, baseDirectiveTransforms] = getBaseTransformPreset(true);
  31391. const vnodeNodeTransforms = [...baseNodeTransforms, ...DOMNodeTransforms];
  31392. const vnodeDirectiveTransforms = __spreadValues$8(__spreadValues$8({}, baseDirectiveTransforms), DOMDirectiveTransforms);
  31393. function createVNodeSlotBranch(props, children, parentContext) {
  31394. const rawOptions = rawOptionsMap.get(parentContext.root);
  31395. const subOptions = __spreadProps$8(__spreadValues$8({}, rawOptions), {
  31396. // overwrite with vnode-based transforms
  31397. nodeTransforms: [
  31398. ...vnodeNodeTransforms,
  31399. ...rawOptions.nodeTransforms || []
  31400. ],
  31401. directiveTransforms: __spreadValues$8(__spreadValues$8({}, vnodeDirectiveTransforms), rawOptions.directiveTransforms || {})
  31402. });
  31403. const wrapperNode = {
  31404. type: 1,
  31405. ns: 0,
  31406. tag: "template",
  31407. tagType: 3,
  31408. isSelfClosing: false,
  31409. // important: provide v-slot="props" on the wrapper for proper
  31410. // scope analysis
  31411. props: [
  31412. {
  31413. type: 7,
  31414. name: "slot",
  31415. exp: props,
  31416. arg: void 0,
  31417. modifiers: [],
  31418. loc: locStub
  31419. }
  31420. ],
  31421. children,
  31422. loc: locStub,
  31423. codegenNode: void 0
  31424. };
  31425. subTransform(wrapperNode, subOptions, parentContext);
  31426. return createReturnStatement(children);
  31427. }
  31428. function subTransform(node, options, parentContext) {
  31429. const childRoot = createRoot([node]);
  31430. const childContext = createTransformContext(childRoot, options);
  31431. childContext.ssr = false;
  31432. childContext.scopes = __spreadValues$8({}, parentContext.scopes);
  31433. childContext.identifiers = __spreadValues$8({}, parentContext.identifiers);
  31434. childContext.imports = parentContext.imports;
  31435. traverseNode(childRoot, childContext);
  31436. ["helpers", "components", "directives"].forEach((key) => {
  31437. childContext[key].forEach((value, helperKey) => {
  31438. if (key === "helpers") {
  31439. const parentCount = parentContext.helpers.get(helperKey);
  31440. if (parentCount === void 0) {
  31441. parentContext.helpers.set(helperKey, value);
  31442. } else {
  31443. parentContext.helpers.set(helperKey, value + parentCount);
  31444. }
  31445. } else {
  31446. parentContext[key].add(value);
  31447. }
  31448. });
  31449. });
  31450. }
  31451. function clone(v) {
  31452. if (isArray$3(v)) {
  31453. return v.map(clone);
  31454. } else if (isObject$2(v)) {
  31455. const res = {};
  31456. for (const key in v) {
  31457. res[key] = clone(v[key]);
  31458. }
  31459. return res;
  31460. } else {
  31461. return v;
  31462. }
  31463. }
  31464. function ssrCodegenTransform(ast, options) {
  31465. const context = createSSRTransformContext(ast, options);
  31466. if (options.ssrCssVars) {
  31467. const cssContext = createTransformContext(createRoot([]), options);
  31468. const varsExp = processExpression(
  31469. createSimpleExpression(options.ssrCssVars, false),
  31470. cssContext
  31471. );
  31472. context.body.push(
  31473. createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`])
  31474. );
  31475. Array.from(cssContext.helpers.keys()).forEach((helper) => {
  31476. ast.helpers.add(helper);
  31477. });
  31478. }
  31479. const isFragment = ast.children.length > 1 && ast.children.some((c) => !isText$1(c));
  31480. processChildren(ast, context, isFragment);
  31481. ast.codegenNode = createBlockStatement(context.body);
  31482. ast.ssrHelpers = Array.from(
  31483. /* @__PURE__ */ new Set([
  31484. ...Array.from(ast.helpers).filter((h) => h in ssrHelpers),
  31485. ...context.helpers
  31486. ])
  31487. );
  31488. ast.helpers = new Set(Array.from(ast.helpers).filter((h) => !(h in ssrHelpers)));
  31489. }
  31490. function createSSRTransformContext(root, options, helpers = /* @__PURE__ */ new Set(), withSlotScopeId = false) {
  31491. const body = [];
  31492. let currentString = null;
  31493. return {
  31494. root,
  31495. options,
  31496. body,
  31497. helpers,
  31498. withSlotScopeId,
  31499. onError: options.onError || ((e) => {
  31500. throw e;
  31501. }),
  31502. helper(name) {
  31503. helpers.add(name);
  31504. return name;
  31505. },
  31506. pushStringPart(part) {
  31507. if (!currentString) {
  31508. const currentCall = createCallExpression(`_push`);
  31509. body.push(currentCall);
  31510. currentString = createTemplateLiteral([]);
  31511. currentCall.arguments.push(currentString);
  31512. }
  31513. const bufferedElements = currentString.elements;
  31514. const lastItem = bufferedElements[bufferedElements.length - 1];
  31515. if (isString$2(part) && isString$2(lastItem)) {
  31516. bufferedElements[bufferedElements.length - 1] += part;
  31517. } else {
  31518. bufferedElements.push(part);
  31519. }
  31520. },
  31521. pushStatement(statement) {
  31522. currentString = null;
  31523. body.push(statement);
  31524. }
  31525. };
  31526. }
  31527. function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
  31528. return createSSRTransformContext(
  31529. parent.root,
  31530. parent.options,
  31531. parent.helpers,
  31532. withSlotScopeId
  31533. );
  31534. }
  31535. function processChildren(parent, context, asFragment = false, disableNestedFragments = false) {
  31536. if (asFragment) {
  31537. context.pushStringPart(`<!--[-->`);
  31538. }
  31539. const { children } = parent;
  31540. for (let i = 0; i < children.length; i++) {
  31541. const child = children[i];
  31542. switch (child.type) {
  31543. case 1:
  31544. switch (child.tagType) {
  31545. case 0:
  31546. ssrProcessElement(child, context);
  31547. break;
  31548. case 1:
  31549. ssrProcessComponent(child, context, parent);
  31550. break;
  31551. case 2:
  31552. ssrProcessSlotOutlet(child, context);
  31553. break;
  31554. case 3:
  31555. break;
  31556. default:
  31557. context.onError(
  31558. createSSRCompilerError(
  31559. 67,
  31560. child.loc
  31561. )
  31562. );
  31563. const exhaustiveCheck2 = child;
  31564. return exhaustiveCheck2;
  31565. }
  31566. break;
  31567. case 2:
  31568. context.pushStringPart(escapeHtml(child.content));
  31569. break;
  31570. case 3:
  31571. context.pushStringPart(`<!--${child.content}-->`);
  31572. break;
  31573. case 5:
  31574. context.pushStringPart(
  31575. createCallExpression(context.helper(SSR_INTERPOLATE), [child.content])
  31576. );
  31577. break;
  31578. case 9:
  31579. ssrProcessIf(child, context, disableNestedFragments);
  31580. break;
  31581. case 11:
  31582. ssrProcessFor(child, context, disableNestedFragments);
  31583. break;
  31584. case 10:
  31585. break;
  31586. case 12:
  31587. case 8:
  31588. break;
  31589. default:
  31590. context.onError(
  31591. createSSRCompilerError(
  31592. 67,
  31593. child.loc
  31594. )
  31595. );
  31596. const exhaustiveCheck = child;
  31597. return exhaustiveCheck;
  31598. }
  31599. }
  31600. if (asFragment) {
  31601. context.pushStringPart(`<!--]-->`);
  31602. }
  31603. }
  31604. function processChildrenAsStatement(parent, parentContext, asFragment = false, withSlotScopeId = parentContext.withSlotScopeId) {
  31605. const childContext = createChildContext(parentContext, withSlotScopeId);
  31606. processChildren(parent, childContext, asFragment);
  31607. return createBlockStatement(childContext.body);
  31608. }
  31609. const ssrTransformModel = (dir, node, context) => {
  31610. const model = dir.exp;
  31611. function checkDuplicatedValue() {
  31612. const value = findProp(node, "value");
  31613. if (value) {
  31614. context.onError(
  31615. createDOMCompilerError(
  31616. 60,
  31617. value.loc
  31618. )
  31619. );
  31620. }
  31621. }
  31622. if (node.tagType === 0) {
  31623. const res = { props: [] };
  31624. const defaultProps = [
  31625. // default value binding for text type inputs
  31626. createObjectProperty(`value`, model)
  31627. ];
  31628. if (node.tag === "input") {
  31629. const type = findProp(node, "type");
  31630. if (type) {
  31631. const value = findValueBinding(node);
  31632. if (type.type === 7) {
  31633. res.ssrTagParts = [
  31634. createCallExpression(context.helper(SSR_RENDER_DYNAMIC_MODEL), [
  31635. type.exp,
  31636. model,
  31637. value
  31638. ])
  31639. ];
  31640. } else if (type.value) {
  31641. switch (type.value.content) {
  31642. case "radio":
  31643. res.props = [
  31644. createObjectProperty(
  31645. `checked`,
  31646. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31647. model,
  31648. value
  31649. ])
  31650. )
  31651. ];
  31652. break;
  31653. case "checkbox":
  31654. const trueValueBinding = findProp(node, "true-value");
  31655. if (trueValueBinding) {
  31656. const trueValue = trueValueBinding.type === 6 ? JSON.stringify(trueValueBinding.value.content) : trueValueBinding.exp;
  31657. res.props = [
  31658. createObjectProperty(
  31659. `checked`,
  31660. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31661. model,
  31662. trueValue
  31663. ])
  31664. )
  31665. ];
  31666. } else {
  31667. res.props = [
  31668. createObjectProperty(
  31669. `checked`,
  31670. createConditionalExpression(
  31671. createCallExpression(`Array.isArray`, [model]),
  31672. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  31673. model,
  31674. value
  31675. ]),
  31676. model
  31677. )
  31678. )
  31679. ];
  31680. }
  31681. break;
  31682. case "file":
  31683. context.onError(
  31684. createDOMCompilerError(
  31685. 59,
  31686. dir.loc
  31687. )
  31688. );
  31689. break;
  31690. default:
  31691. checkDuplicatedValue();
  31692. res.props = defaultProps;
  31693. break;
  31694. }
  31695. }
  31696. } else if (hasDynamicKeyVBind(node)) ; else {
  31697. checkDuplicatedValue();
  31698. res.props = defaultProps;
  31699. }
  31700. } else if (node.tag === "textarea") {
  31701. checkDuplicatedValue();
  31702. node.children = [createInterpolation(model, model.loc)];
  31703. } else if (node.tag === "select") ; else {
  31704. context.onError(
  31705. createDOMCompilerError(
  31706. 57,
  31707. dir.loc
  31708. )
  31709. );
  31710. }
  31711. return res;
  31712. } else {
  31713. return transformModel$1(dir, node, context);
  31714. }
  31715. };
  31716. function findValueBinding(node) {
  31717. const valueBinding = findProp(node, "value");
  31718. return valueBinding ? valueBinding.type === 7 ? valueBinding.exp : createSimpleExpression(valueBinding.value.content, true) : createSimpleExpression(`null`, false);
  31719. }
  31720. const ssrTransformShow = (dir, node, context) => {
  31721. if (!dir.exp) {
  31722. context.onError(
  31723. createDOMCompilerError(61)
  31724. );
  31725. }
  31726. return {
  31727. props: [
  31728. createObjectProperty(
  31729. `style`,
  31730. createConditionalExpression(
  31731. dir.exp,
  31732. createSimpleExpression(`null`, false),
  31733. createObjectExpression([
  31734. createObjectProperty(
  31735. `display`,
  31736. createSimpleExpression(`none`, true)
  31737. )
  31738. ]),
  31739. false
  31740. /* no newline */
  31741. )
  31742. )
  31743. ]
  31744. };
  31745. };
  31746. const filterChild = (node) => node.children.filter((n) => n.type !== 3);
  31747. const hasSingleChild = (node) => filterChild(node).length === 1;
  31748. const ssrInjectFallthroughAttrs = (node, context) => {
  31749. if (node.type === 0) {
  31750. context.identifiers._attrs = 1;
  31751. }
  31752. if (node.type === 1 && node.tagType === 1 && (isBuiltInType(node.tag, "Transition") || isBuiltInType(node.tag, "KeepAlive"))) {
  31753. const rootChildren = filterChild(context.root);
  31754. if (rootChildren.length === 1 && rootChildren[0] === node) {
  31755. if (hasSingleChild(node)) {
  31756. injectFallthroughAttrs(node.children[0]);
  31757. }
  31758. return;
  31759. }
  31760. }
  31761. const parent = context.parent;
  31762. if (!parent || parent.type !== 0) {
  31763. return;
  31764. }
  31765. if (node.type === 10 && hasSingleChild(node)) {
  31766. let hasEncounteredIf = false;
  31767. for (const c of filterChild(parent)) {
  31768. if (c.type === 9 || c.type === 1 && findDir(c, "if")) {
  31769. if (hasEncounteredIf)
  31770. return;
  31771. hasEncounteredIf = true;
  31772. } else if (
  31773. // node before v-if
  31774. !hasEncounteredIf || // non else nodes
  31775. !(c.type === 1 && findDir(c, /else/, true))
  31776. ) {
  31777. return;
  31778. }
  31779. }
  31780. injectFallthroughAttrs(node.children[0]);
  31781. } else if (hasSingleChild(parent)) {
  31782. injectFallthroughAttrs(node);
  31783. }
  31784. };
  31785. function injectFallthroughAttrs(node) {
  31786. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  31787. node.props.push({
  31788. type: 7,
  31789. name: "bind",
  31790. arg: void 0,
  31791. exp: createSimpleExpression(`_attrs`, false),
  31792. modifiers: [],
  31793. loc: locStub
  31794. });
  31795. }
  31796. }
  31797. const ssrInjectCssVars = (node, context) => {
  31798. if (!context.ssrCssVars) {
  31799. return;
  31800. }
  31801. if (node.type === 0) {
  31802. context.identifiers._cssVars = 1;
  31803. }
  31804. const parent = context.parent;
  31805. if (!parent || parent.type !== 0) {
  31806. return;
  31807. }
  31808. if (node.type === 10) {
  31809. for (const child of node.children) {
  31810. injectCssVars(child);
  31811. }
  31812. } else {
  31813. injectCssVars(node);
  31814. }
  31815. };
  31816. function injectCssVars(node) {
  31817. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  31818. if (isBuiltInType(node.tag, "Suspense")) {
  31819. for (const child of node.children) {
  31820. if (child.type === 1 && child.tagType === 3) {
  31821. child.children.forEach(injectCssVars);
  31822. } else {
  31823. injectCssVars(child);
  31824. }
  31825. }
  31826. } else {
  31827. node.props.push({
  31828. type: 7,
  31829. name: "bind",
  31830. arg: void 0,
  31831. exp: createSimpleExpression(`_cssVars`, false),
  31832. modifiers: [],
  31833. loc: locStub
  31834. });
  31835. }
  31836. }
  31837. }
  31838. var __defProp$7 = Object.defineProperty;
  31839. var __defProps$7 = Object.defineProperties;
  31840. var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
  31841. var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
  31842. var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
  31843. var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
  31844. var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  31845. var __spreadValues$7 = (a, b) => {
  31846. for (var prop in b || (b = {}))
  31847. if (__hasOwnProp$7.call(b, prop))
  31848. __defNormalProp$7(a, prop, b[prop]);
  31849. if (__getOwnPropSymbols$7)
  31850. for (var prop of __getOwnPropSymbols$7(b)) {
  31851. if (__propIsEnum$7.call(b, prop))
  31852. __defNormalProp$7(a, prop, b[prop]);
  31853. }
  31854. return a;
  31855. };
  31856. var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
  31857. function compile(template, options = {}) {
  31858. options = __spreadProps$7(__spreadValues$7(__spreadValues$7({}, options), parserOptions), {
  31859. ssr: true,
  31860. inSSR: true,
  31861. scopeId: options.mode === "function" ? null : options.scopeId,
  31862. // always prefix since compiler-ssr doesn't have size concern
  31863. prefixIdentifiers: true,
  31864. // disable optimizations that are unnecessary for ssr
  31865. cacheHandlers: false,
  31866. hoistStatic: false
  31867. });
  31868. const ast = baseParse(template, options);
  31869. rawOptionsMap.set(ast, options);
  31870. transform$1(ast, __spreadProps$7(__spreadValues$7({}, options), {
  31871. hoistStatic: false,
  31872. nodeTransforms: [
  31873. ssrTransformIf,
  31874. ssrTransformFor,
  31875. trackVForSlotScopes,
  31876. transformExpression,
  31877. ssrTransformSlotOutlet,
  31878. ssrInjectFallthroughAttrs,
  31879. ssrInjectCssVars,
  31880. ssrTransformElement,
  31881. ssrTransformComponent,
  31882. trackSlotScopes,
  31883. transformStyle,
  31884. ...options.nodeTransforms || []
  31885. // user transforms
  31886. ],
  31887. directiveTransforms: __spreadValues$7({
  31888. // reusing core v-bind
  31889. bind: transformBind,
  31890. on: transformOn$1,
  31891. // model and show has dedicated SSR handling
  31892. model: ssrTransformModel,
  31893. show: ssrTransformShow,
  31894. // the following are ignored during SSR
  31895. // on: noopDirectiveTransform,
  31896. cloak: noopDirectiveTransform,
  31897. once: noopDirectiveTransform,
  31898. memo: noopDirectiveTransform
  31899. }, options.directiveTransforms || {})
  31900. }));
  31901. ssrCodegenTransform(ast, options);
  31902. return generate(ast, options);
  31903. }
  31904. var CompilerSSR = /*#__PURE__*/Object.freeze({
  31905. __proto__: null,
  31906. compile: compile
  31907. });
  31908. var _polyfillNode_fs = {};
  31909. var _polyfillNode_fs$1 = /*#__PURE__*/Object.freeze({
  31910. __proto__: null,
  31911. default: _polyfillNode_fs
  31912. });
  31913. var require$$0$2 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_fs$1);
  31914. var require$$2$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_path);
  31915. var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_util$1);
  31916. const hasWarned$1 = {};
  31917. function warnOnce$4(msg) {
  31918. const isNodeProd = typeof process !== "undefined" && process.env.NODE_ENV === "production";
  31919. if (!isNodeProd && true && !hasWarned$1[msg]) {
  31920. hasWarned$1[msg] = true;
  31921. warn$1(msg);
  31922. }
  31923. }
  31924. function warn$1(msg) {
  31925. console.warn(
  31926. `\x1B[1m\x1B[33m[@vue/compiler-sfc]\x1B[0m\x1B[33m ${msg}\x1B[0m
  31927. `
  31928. );
  31929. }
  31930. var __defProp$6 = Object.defineProperty;
  31931. var __defProps$6 = Object.defineProperties;
  31932. var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
  31933. var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
  31934. var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
  31935. var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
  31936. var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  31937. var __spreadValues$6 = (a, b) => {
  31938. for (var prop in b || (b = {}))
  31939. if (__hasOwnProp$6.call(b, prop))
  31940. __defNormalProp$6(a, prop, b[prop]);
  31941. if (__getOwnPropSymbols$6)
  31942. for (var prop of __getOwnPropSymbols$6(b)) {
  31943. if (__propIsEnum$6.call(b, prop))
  31944. __defNormalProp$6(a, prop, b[prop]);
  31945. }
  31946. return a;
  31947. };
  31948. var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
  31949. function preprocess$1({ source, filename, preprocessOptions }, preprocessor) {
  31950. let res = "";
  31951. let err = null;
  31952. preprocessor.render(
  31953. source,
  31954. __spreadValues$6({ filename }, preprocessOptions),
  31955. (_err, _res) => {
  31956. if (_err)
  31957. err = _err;
  31958. res = _res;
  31959. }
  31960. );
  31961. if (err)
  31962. throw err;
  31963. return res;
  31964. }
  31965. function compileTemplate(options) {
  31966. const { preprocessLang, preprocessCustomRequire } = options;
  31967. if (preprocessLang && !preprocessCustomRequire) {
  31968. throw new Error(
  31969. `[@vue/compiler-sfc] Template preprocessing in the browser build must provide the \`preprocessCustomRequire\` option to return the in-browser version of the preprocessor in the shape of { render(): string }.`
  31970. );
  31971. }
  31972. const preprocessor = preprocessLang ? preprocessCustomRequire ? preprocessCustomRequire(preprocessLang) : void 0 : false;
  31973. if (preprocessor) {
  31974. try {
  31975. return doCompileTemplate(__spreadProps$6(__spreadValues$6({}, options), {
  31976. source: preprocess$1(options, preprocessor)
  31977. }));
  31978. } catch (e) {
  31979. return {
  31980. code: `export default function render() {}`,
  31981. source: options.source,
  31982. tips: [],
  31983. errors: [e]
  31984. };
  31985. }
  31986. } else if (preprocessLang) {
  31987. return {
  31988. code: `export default function render() {}`,
  31989. source: options.source,
  31990. tips: [
  31991. `Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`
  31992. ],
  31993. errors: [
  31994. `Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`
  31995. ]
  31996. };
  31997. } else {
  31998. return doCompileTemplate(options);
  31999. }
  32000. }
  32001. function doCompileTemplate({
  32002. filename,
  32003. id,
  32004. scoped,
  32005. slotted,
  32006. inMap,
  32007. source,
  32008. ssr = false,
  32009. ssrCssVars,
  32010. isProd = false,
  32011. compiler = ssr ? CompilerSSR : CompilerDOM,
  32012. compilerOptions = {},
  32013. transformAssetUrls
  32014. }) {
  32015. const errors = [];
  32016. const warnings = [];
  32017. let nodeTransforms = [];
  32018. if (isObject$2(transformAssetUrls)) {
  32019. const assetOptions = normalizeOptions(transformAssetUrls);
  32020. nodeTransforms = [
  32021. createAssetUrlTransformWithOptions(assetOptions),
  32022. createSrcsetTransformWithOptions(assetOptions)
  32023. ];
  32024. } else if (transformAssetUrls !== false) {
  32025. nodeTransforms = [transformAssetUrl, transformSrcset];
  32026. }
  32027. if (ssr && !ssrCssVars) {
  32028. warnOnce$4(
  32029. `compileTemplate is called with \`ssr: true\` but no corresponding \`cssVars\` option.\`.`
  32030. );
  32031. }
  32032. if (!id) {
  32033. warnOnce$4(`compileTemplate now requires the \`id\` option.\`.`);
  32034. id = "";
  32035. }
  32036. const shortId = id.replace(/^data-v-/, "");
  32037. const longId = `data-v-${shortId}`;
  32038. let { code, ast, preamble, map } = compiler.compile(source, __spreadProps$6(__spreadValues$6({
  32039. mode: "module",
  32040. prefixIdentifiers: true,
  32041. hoistStatic: true,
  32042. cacheHandlers: true,
  32043. ssrCssVars: ssr && ssrCssVars && ssrCssVars.length ? genCssVarsFromList(ssrCssVars, shortId, isProd, true) : "",
  32044. scopeId: scoped ? longId : void 0,
  32045. slotted,
  32046. sourceMap: true
  32047. }, compilerOptions), {
  32048. nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
  32049. filename,
  32050. onError: (e) => errors.push(e),
  32051. onWarn: (w) => warnings.push(w)
  32052. }));
  32053. if (inMap) {
  32054. if (map) {
  32055. map = mapLines(inMap, map);
  32056. }
  32057. if (errors.length) {
  32058. patchErrors(errors, source, inMap);
  32059. }
  32060. }
  32061. const tips = warnings.map((w) => {
  32062. let msg = w.message;
  32063. if (w.loc) {
  32064. msg += `
  32065. ${generateCodeFrame(
  32066. source,
  32067. w.loc.start.offset,
  32068. w.loc.end.offset
  32069. )}`;
  32070. }
  32071. return msg;
  32072. });
  32073. return { code, ast, preamble, source, errors, tips, map };
  32074. }
  32075. function mapLines(oldMap, newMap) {
  32076. if (!oldMap)
  32077. return newMap;
  32078. if (!newMap)
  32079. return oldMap;
  32080. const oldMapConsumer = new SourceMapConsumer$5(oldMap);
  32081. const newMapConsumer = new SourceMapConsumer$5(newMap);
  32082. const mergedMapGenerator = new SourceMapGenerator$6();
  32083. newMapConsumer.eachMapping((m) => {
  32084. if (m.originalLine == null) {
  32085. return;
  32086. }
  32087. const origPosInOldMap = oldMapConsumer.originalPositionFor({
  32088. line: m.originalLine,
  32089. column: m.originalColumn
  32090. });
  32091. if (origPosInOldMap.source == null) {
  32092. return;
  32093. }
  32094. mergedMapGenerator.addMapping({
  32095. generated: {
  32096. line: m.generatedLine,
  32097. column: m.generatedColumn
  32098. },
  32099. original: {
  32100. line: origPosInOldMap.line,
  32101. // map line
  32102. // use current column, since the oldMap produced by @vue/compiler-sfc
  32103. // does not
  32104. column: m.originalColumn
  32105. },
  32106. source: origPosInOldMap.source,
  32107. name: origPosInOldMap.name
  32108. });
  32109. });
  32110. const generator = mergedMapGenerator;
  32111. oldMapConsumer.sources.forEach((sourceFile) => {
  32112. generator._sources.add(sourceFile);
  32113. const sourceContent = oldMapConsumer.sourceContentFor(sourceFile);
  32114. if (sourceContent != null) {
  32115. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  32116. }
  32117. });
  32118. generator._sourceRoot = oldMap.sourceRoot;
  32119. generator._file = oldMap.file;
  32120. return generator.toJSON();
  32121. }
  32122. function patchErrors(errors, source, inMap) {
  32123. const originalSource = inMap.sourcesContent[0];
  32124. const offset = originalSource.indexOf(source);
  32125. const lineOffset = originalSource.slice(0, offset).split(/\r?\n/).length - 1;
  32126. errors.forEach((err) => {
  32127. if (err.loc) {
  32128. err.loc.start.line += lineOffset;
  32129. err.loc.start.offset += offset;
  32130. if (err.loc.end !== err.loc.start) {
  32131. err.loc.end.line += lineOffset;
  32132. err.loc.end.offset += offset;
  32133. }
  32134. }
  32135. });
  32136. }
  32137. var picocolorsExports = {};
  32138. var picocolors = {
  32139. get exports(){ return picocolorsExports; },
  32140. set exports(v){ picocolorsExports = v; },
  32141. };
  32142. // MIT lisence
  32143. // from https://github.com/substack/tty-browserify/blob/1ba769a6429d242f36226538835b4034bf6b7886/index.js
  32144. function isatty() {
  32145. return false;
  32146. }
  32147. function ReadStream() {
  32148. throw new Error('tty.ReadStream is not implemented');
  32149. }
  32150. function WriteStream() {
  32151. throw new Error('tty.ReadStream is not implemented');
  32152. }
  32153. var _polyfillNode_tty = {
  32154. isatty: isatty,
  32155. ReadStream: ReadStream,
  32156. WriteStream: WriteStream
  32157. };
  32158. var _polyfillNode_tty$1 = /*#__PURE__*/Object.freeze({
  32159. __proto__: null,
  32160. ReadStream: ReadStream,
  32161. WriteStream: WriteStream,
  32162. default: _polyfillNode_tty,
  32163. isatty: isatty
  32164. });
  32165. var require$$0 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_tty$1);
  32166. let tty = require$$0;
  32167. let isColorSupported =
  32168. !("NO_COLOR" in ({}) || browser$1.argv.includes("--no-color")) &&
  32169. ("FORCE_COLOR" in ({}) ||
  32170. browser$1.argv.includes("--color") ||
  32171. "" === "win32" ||
  32172. (tty.isatty(1) && browser$1.env.TERM !== "dumb") ||
  32173. "CI" in ({}));
  32174. let formatter =
  32175. (open, close, replace = open) =>
  32176. input => {
  32177. let string = "" + input;
  32178. let index = string.indexOf(close, open.length);
  32179. return ~index
  32180. ? open + replaceClose(string, close, replace, index) + close
  32181. : open + string + close
  32182. };
  32183. let replaceClose = (string, close, replace, index) => {
  32184. let start = string.substring(0, index) + replace;
  32185. let end = string.substring(index + close.length);
  32186. let nextIndex = end.indexOf(close);
  32187. return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
  32188. };
  32189. let createColors = (enabled = isColorSupported) => ({
  32190. isColorSupported: enabled,
  32191. reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
  32192. bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
  32193. dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
  32194. italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
  32195. underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
  32196. inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
  32197. hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
  32198. strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
  32199. black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
  32200. red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
  32201. green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
  32202. yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
  32203. blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
  32204. magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
  32205. cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
  32206. white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
  32207. gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
  32208. bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
  32209. bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
  32210. bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
  32211. bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
  32212. bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
  32213. bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
  32214. bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
  32215. bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
  32216. });
  32217. picocolors.exports = createColors();
  32218. picocolorsExports.createColors = createColors;
  32219. const SINGLE_QUOTE = "'".charCodeAt(0);
  32220. const DOUBLE_QUOTE = '"'.charCodeAt(0);
  32221. const BACKSLASH = '\\'.charCodeAt(0);
  32222. const SLASH = '/'.charCodeAt(0);
  32223. const NEWLINE = '\n'.charCodeAt(0);
  32224. const SPACE = ' '.charCodeAt(0);
  32225. const FEED = '\f'.charCodeAt(0);
  32226. const TAB = '\t'.charCodeAt(0);
  32227. const CR = '\r'.charCodeAt(0);
  32228. const OPEN_SQUARE = '['.charCodeAt(0);
  32229. const CLOSE_SQUARE = ']'.charCodeAt(0);
  32230. const OPEN_PARENTHESES = '('.charCodeAt(0);
  32231. const CLOSE_PARENTHESES = ')'.charCodeAt(0);
  32232. const OPEN_CURLY = '{'.charCodeAt(0);
  32233. const CLOSE_CURLY = '}'.charCodeAt(0);
  32234. const SEMICOLON = ';'.charCodeAt(0);
  32235. const ASTERISK = '*'.charCodeAt(0);
  32236. const COLON = ':'.charCodeAt(0);
  32237. const AT = '@'.charCodeAt(0);
  32238. const RE_AT_END = /[\t\n\f\r "#'()/;[\\\]{}]/g;
  32239. const RE_WORD_END = /[\t\n\f\r !"#'():;@[\\\]{}]|\/(?=\*)/g;
  32240. const RE_BAD_BRACKET = /.[\n"'(/\\]/;
  32241. const RE_HEX_ESCAPE = /[\da-f]/i;
  32242. var tokenize$1 = function tokenizer(input, options = {}) {
  32243. let css = input.css.valueOf();
  32244. let ignore = options.ignoreErrors;
  32245. let code, next, quote, content, escape;
  32246. let escaped, escapePos, prev, n, currentToken;
  32247. let length = css.length;
  32248. let pos = 0;
  32249. let buffer = [];
  32250. let returned = [];
  32251. function position() {
  32252. return pos
  32253. }
  32254. function unclosed(what) {
  32255. throw input.error('Unclosed ' + what, pos)
  32256. }
  32257. function endOfFile() {
  32258. return returned.length === 0 && pos >= length
  32259. }
  32260. function nextToken(opts) {
  32261. if (returned.length) return returned.pop()
  32262. if (pos >= length) return
  32263. let ignoreUnclosed = opts ? opts.ignoreUnclosed : false;
  32264. code = css.charCodeAt(pos);
  32265. switch (code) {
  32266. case NEWLINE:
  32267. case SPACE:
  32268. case TAB:
  32269. case CR:
  32270. case FEED: {
  32271. next = pos;
  32272. do {
  32273. next += 1;
  32274. code = css.charCodeAt(next);
  32275. } while (
  32276. code === SPACE ||
  32277. code === NEWLINE ||
  32278. code === TAB ||
  32279. code === CR ||
  32280. code === FEED
  32281. )
  32282. currentToken = ['space', css.slice(pos, next)];
  32283. pos = next - 1;
  32284. break
  32285. }
  32286. case OPEN_SQUARE:
  32287. case CLOSE_SQUARE:
  32288. case OPEN_CURLY:
  32289. case CLOSE_CURLY:
  32290. case COLON:
  32291. case SEMICOLON:
  32292. case CLOSE_PARENTHESES: {
  32293. let controlChar = String.fromCharCode(code);
  32294. currentToken = [controlChar, controlChar, pos];
  32295. break
  32296. }
  32297. case OPEN_PARENTHESES: {
  32298. prev = buffer.length ? buffer.pop()[1] : '';
  32299. n = css.charCodeAt(pos + 1);
  32300. if (
  32301. prev === 'url' &&
  32302. n !== SINGLE_QUOTE &&
  32303. n !== DOUBLE_QUOTE &&
  32304. n !== SPACE &&
  32305. n !== NEWLINE &&
  32306. n !== TAB &&
  32307. n !== FEED &&
  32308. n !== CR
  32309. ) {
  32310. next = pos;
  32311. do {
  32312. escaped = false;
  32313. next = css.indexOf(')', next + 1);
  32314. if (next === -1) {
  32315. if (ignore || ignoreUnclosed) {
  32316. next = pos;
  32317. break
  32318. } else {
  32319. unclosed('bracket');
  32320. }
  32321. }
  32322. escapePos = next;
  32323. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32324. escapePos -= 1;
  32325. escaped = !escaped;
  32326. }
  32327. } while (escaped)
  32328. currentToken = ['brackets', css.slice(pos, next + 1), pos, next];
  32329. pos = next;
  32330. } else {
  32331. next = css.indexOf(')', pos + 1);
  32332. content = css.slice(pos, next + 1);
  32333. if (next === -1 || RE_BAD_BRACKET.test(content)) {
  32334. currentToken = ['(', '(', pos];
  32335. } else {
  32336. currentToken = ['brackets', content, pos, next];
  32337. pos = next;
  32338. }
  32339. }
  32340. break
  32341. }
  32342. case SINGLE_QUOTE:
  32343. case DOUBLE_QUOTE: {
  32344. quote = code === SINGLE_QUOTE ? "'" : '"';
  32345. next = pos;
  32346. do {
  32347. escaped = false;
  32348. next = css.indexOf(quote, next + 1);
  32349. if (next === -1) {
  32350. if (ignore || ignoreUnclosed) {
  32351. next = pos + 1;
  32352. break
  32353. } else {
  32354. unclosed('string');
  32355. }
  32356. }
  32357. escapePos = next;
  32358. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32359. escapePos -= 1;
  32360. escaped = !escaped;
  32361. }
  32362. } while (escaped)
  32363. currentToken = ['string', css.slice(pos, next + 1), pos, next];
  32364. pos = next;
  32365. break
  32366. }
  32367. case AT: {
  32368. RE_AT_END.lastIndex = pos + 1;
  32369. RE_AT_END.test(css);
  32370. if (RE_AT_END.lastIndex === 0) {
  32371. next = css.length - 1;
  32372. } else {
  32373. next = RE_AT_END.lastIndex - 2;
  32374. }
  32375. currentToken = ['at-word', css.slice(pos, next + 1), pos, next];
  32376. pos = next;
  32377. break
  32378. }
  32379. case BACKSLASH: {
  32380. next = pos;
  32381. escape = true;
  32382. while (css.charCodeAt(next + 1) === BACKSLASH) {
  32383. next += 1;
  32384. escape = !escape;
  32385. }
  32386. code = css.charCodeAt(next + 1);
  32387. if (
  32388. escape &&
  32389. code !== SLASH &&
  32390. code !== SPACE &&
  32391. code !== NEWLINE &&
  32392. code !== TAB &&
  32393. code !== CR &&
  32394. code !== FEED
  32395. ) {
  32396. next += 1;
  32397. if (RE_HEX_ESCAPE.test(css.charAt(next))) {
  32398. while (RE_HEX_ESCAPE.test(css.charAt(next + 1))) {
  32399. next += 1;
  32400. }
  32401. if (css.charCodeAt(next + 1) === SPACE) {
  32402. next += 1;
  32403. }
  32404. }
  32405. }
  32406. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32407. pos = next;
  32408. break
  32409. }
  32410. default: {
  32411. if (code === SLASH && css.charCodeAt(pos + 1) === ASTERISK) {
  32412. next = css.indexOf('*/', pos + 2) + 1;
  32413. if (next === 0) {
  32414. if (ignore || ignoreUnclosed) {
  32415. next = css.length;
  32416. } else {
  32417. unclosed('comment');
  32418. }
  32419. }
  32420. currentToken = ['comment', css.slice(pos, next + 1), pos, next];
  32421. pos = next;
  32422. } else {
  32423. RE_WORD_END.lastIndex = pos + 1;
  32424. RE_WORD_END.test(css);
  32425. if (RE_WORD_END.lastIndex === 0) {
  32426. next = css.length - 1;
  32427. } else {
  32428. next = RE_WORD_END.lastIndex - 2;
  32429. }
  32430. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32431. buffer.push(currentToken);
  32432. pos = next;
  32433. }
  32434. break
  32435. }
  32436. }
  32437. pos++;
  32438. return currentToken
  32439. }
  32440. function back(token) {
  32441. returned.push(token);
  32442. }
  32443. return {
  32444. back,
  32445. nextToken,
  32446. endOfFile,
  32447. position
  32448. }
  32449. };
  32450. let pico$1 = picocolorsExports;
  32451. let tokenizer$1 = tokenize$1;
  32452. let Input$5;
  32453. function registerInput(dependant) {
  32454. Input$5 = dependant;
  32455. }
  32456. const HIGHLIGHT_THEME = {
  32457. 'brackets': pico$1.cyan,
  32458. 'at-word': pico$1.cyan,
  32459. 'comment': pico$1.gray,
  32460. 'string': pico$1.green,
  32461. 'class': pico$1.yellow,
  32462. 'hash': pico$1.magenta,
  32463. 'call': pico$1.cyan,
  32464. '(': pico$1.cyan,
  32465. ')': pico$1.cyan,
  32466. '{': pico$1.yellow,
  32467. '}': pico$1.yellow,
  32468. '[': pico$1.yellow,
  32469. ']': pico$1.yellow,
  32470. ':': pico$1.yellow,
  32471. ';': pico$1.yellow
  32472. };
  32473. function getTokenType([type, value], processor) {
  32474. if (type === 'word') {
  32475. if (value[0] === '.') {
  32476. return 'class'
  32477. }
  32478. if (value[0] === '#') {
  32479. return 'hash'
  32480. }
  32481. }
  32482. if (!processor.endOfFile()) {
  32483. let next = processor.nextToken();
  32484. processor.back(next);
  32485. if (next[0] === 'brackets' || next[0] === '(') return 'call'
  32486. }
  32487. return type
  32488. }
  32489. function terminalHighlight$2(css) {
  32490. let processor = tokenizer$1(new Input$5(css), { ignoreErrors: true });
  32491. let result = '';
  32492. while (!processor.endOfFile()) {
  32493. let token = processor.nextToken();
  32494. let color = HIGHLIGHT_THEME[getTokenType(token, processor)];
  32495. if (color) {
  32496. result += token[1]
  32497. .split(/\r?\n/)
  32498. .map(i => color(i))
  32499. .join('\n');
  32500. } else {
  32501. result += token[1];
  32502. }
  32503. }
  32504. return result
  32505. }
  32506. terminalHighlight$2.registerInput = registerInput;
  32507. var terminalHighlight_1 = terminalHighlight$2;
  32508. let pico = picocolorsExports;
  32509. let terminalHighlight$1 = terminalHighlight_1;
  32510. let CssSyntaxError$3 = class CssSyntaxError extends Error {
  32511. constructor(message, line, column, source, file, plugin) {
  32512. super(message);
  32513. this.name = 'CssSyntaxError';
  32514. this.reason = message;
  32515. if (file) {
  32516. this.file = file;
  32517. }
  32518. if (source) {
  32519. this.source = source;
  32520. }
  32521. if (plugin) {
  32522. this.plugin = plugin;
  32523. }
  32524. if (typeof line !== 'undefined' && typeof column !== 'undefined') {
  32525. if (typeof line === 'number') {
  32526. this.line = line;
  32527. this.column = column;
  32528. } else {
  32529. this.line = line.line;
  32530. this.column = line.column;
  32531. this.endLine = column.line;
  32532. this.endColumn = column.column;
  32533. }
  32534. }
  32535. this.setMessage();
  32536. if (Error.captureStackTrace) {
  32537. Error.captureStackTrace(this, CssSyntaxError);
  32538. }
  32539. }
  32540. setMessage() {
  32541. this.message = this.plugin ? this.plugin + ': ' : '';
  32542. this.message += this.file ? this.file : '<css input>';
  32543. if (typeof this.line !== 'undefined') {
  32544. this.message += ':' + this.line + ':' + this.column;
  32545. }
  32546. this.message += ': ' + this.reason;
  32547. }
  32548. showSourceCode(color) {
  32549. if (!this.source) return ''
  32550. let css = this.source;
  32551. if (color == null) color = pico.isColorSupported;
  32552. if (terminalHighlight$1) {
  32553. if (color) css = terminalHighlight$1(css);
  32554. }
  32555. let lines = css.split(/\r?\n/);
  32556. let start = Math.max(this.line - 3, 0);
  32557. let end = Math.min(this.line + 2, lines.length);
  32558. let maxWidth = String(end).length;
  32559. let mark, aside;
  32560. if (color) {
  32561. let { bold, red, gray } = pico.createColors(true);
  32562. mark = text => bold(red(text));
  32563. aside = text => gray(text);
  32564. } else {
  32565. mark = aside = str => str;
  32566. }
  32567. return lines
  32568. .slice(start, end)
  32569. .map((line, index) => {
  32570. let number = start + 1 + index;
  32571. let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ';
  32572. if (number === this.line) {
  32573. let spacing =
  32574. aside(gutter.replace(/\d/g, ' ')) +
  32575. line.slice(0, this.column - 1).replace(/[^\t]/g, ' ');
  32576. return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^')
  32577. }
  32578. return ' ' + aside(gutter) + line
  32579. })
  32580. .join('\n')
  32581. }
  32582. toString() {
  32583. let code = this.showSourceCode();
  32584. if (code) {
  32585. code = '\n\n' + code + '\n';
  32586. }
  32587. return this.name + ': ' + this.message + code
  32588. }
  32589. };
  32590. var cssSyntaxError = CssSyntaxError$3;
  32591. CssSyntaxError$3.default = CssSyntaxError$3;
  32592. var symbols = {};
  32593. symbols.isClean = Symbol('isClean');
  32594. symbols.my = Symbol('my');
  32595. const DEFAULT_RAW = {
  32596. colon: ': ',
  32597. indent: ' ',
  32598. beforeDecl: '\n',
  32599. beforeRule: '\n',
  32600. beforeOpen: ' ',
  32601. beforeClose: '\n',
  32602. beforeComment: '\n',
  32603. after: '\n',
  32604. emptyBody: '',
  32605. commentLeft: ' ',
  32606. commentRight: ' ',
  32607. semicolon: false
  32608. };
  32609. function capitalize(str) {
  32610. return str[0].toUpperCase() + str.slice(1)
  32611. }
  32612. let Stringifier$2 = class Stringifier {
  32613. constructor(builder) {
  32614. this.builder = builder;
  32615. }
  32616. stringify(node, semicolon) {
  32617. /* c8 ignore start */
  32618. if (!this[node.type]) {
  32619. throw new Error(
  32620. 'Unknown AST node type ' +
  32621. node.type +
  32622. '. ' +
  32623. 'Maybe you need to change PostCSS stringifier.'
  32624. )
  32625. }
  32626. /* c8 ignore stop */
  32627. this[node.type](node, semicolon);
  32628. }
  32629. document(node) {
  32630. this.body(node);
  32631. }
  32632. root(node) {
  32633. this.body(node);
  32634. if (node.raws.after) this.builder(node.raws.after);
  32635. }
  32636. comment(node) {
  32637. let left = this.raw(node, 'left', 'commentLeft');
  32638. let right = this.raw(node, 'right', 'commentRight');
  32639. this.builder('/*' + left + node.text + right + '*/', node);
  32640. }
  32641. decl(node, semicolon) {
  32642. let between = this.raw(node, 'between', 'colon');
  32643. let string = node.prop + between + this.rawValue(node, 'value');
  32644. if (node.important) {
  32645. string += node.raws.important || ' !important';
  32646. }
  32647. if (semicolon) string += ';';
  32648. this.builder(string, node);
  32649. }
  32650. rule(node) {
  32651. this.block(node, this.rawValue(node, 'selector'));
  32652. if (node.raws.ownSemicolon) {
  32653. this.builder(node.raws.ownSemicolon, node, 'end');
  32654. }
  32655. }
  32656. atrule(node, semicolon) {
  32657. let name = '@' + node.name;
  32658. let params = node.params ? this.rawValue(node, 'params') : '';
  32659. if (typeof node.raws.afterName !== 'undefined') {
  32660. name += node.raws.afterName;
  32661. } else if (params) {
  32662. name += ' ';
  32663. }
  32664. if (node.nodes) {
  32665. this.block(node, name + params);
  32666. } else {
  32667. let end = (node.raws.between || '') + (semicolon ? ';' : '');
  32668. this.builder(name + params + end, node);
  32669. }
  32670. }
  32671. body(node) {
  32672. let last = node.nodes.length - 1;
  32673. while (last > 0) {
  32674. if (node.nodes[last].type !== 'comment') break
  32675. last -= 1;
  32676. }
  32677. let semicolon = this.raw(node, 'semicolon');
  32678. for (let i = 0; i < node.nodes.length; i++) {
  32679. let child = node.nodes[i];
  32680. let before = this.raw(child, 'before');
  32681. if (before) this.builder(before);
  32682. this.stringify(child, last !== i || semicolon);
  32683. }
  32684. }
  32685. block(node, start) {
  32686. let between = this.raw(node, 'between', 'beforeOpen');
  32687. this.builder(start + between + '{', node, 'start');
  32688. let after;
  32689. if (node.nodes && node.nodes.length) {
  32690. this.body(node);
  32691. after = this.raw(node, 'after');
  32692. } else {
  32693. after = this.raw(node, 'after', 'emptyBody');
  32694. }
  32695. if (after) this.builder(after);
  32696. this.builder('}', node, 'end');
  32697. }
  32698. raw(node, own, detect) {
  32699. let value;
  32700. if (!detect) detect = own;
  32701. // Already had
  32702. if (own) {
  32703. value = node.raws[own];
  32704. if (typeof value !== 'undefined') return value
  32705. }
  32706. let parent = node.parent;
  32707. if (detect === 'before') {
  32708. // Hack for first rule in CSS
  32709. if (!parent || (parent.type === 'root' && parent.first === node)) {
  32710. return ''
  32711. }
  32712. // `root` nodes in `document` should use only their own raws
  32713. if (parent && parent.type === 'document') {
  32714. return ''
  32715. }
  32716. }
  32717. // Floating child without parent
  32718. if (!parent) return DEFAULT_RAW[detect]
  32719. // Detect style by other nodes
  32720. let root = node.root();
  32721. if (!root.rawCache) root.rawCache = {};
  32722. if (typeof root.rawCache[detect] !== 'undefined') {
  32723. return root.rawCache[detect]
  32724. }
  32725. if (detect === 'before' || detect === 'after') {
  32726. return this.beforeAfter(node, detect)
  32727. } else {
  32728. let method = 'raw' + capitalize(detect);
  32729. if (this[method]) {
  32730. value = this[method](root, node);
  32731. } else {
  32732. root.walk(i => {
  32733. value = i.raws[own];
  32734. if (typeof value !== 'undefined') return false
  32735. });
  32736. }
  32737. }
  32738. if (typeof value === 'undefined') value = DEFAULT_RAW[detect];
  32739. root.rawCache[detect] = value;
  32740. return value
  32741. }
  32742. rawSemicolon(root) {
  32743. let value;
  32744. root.walk(i => {
  32745. if (i.nodes && i.nodes.length && i.last.type === 'decl') {
  32746. value = i.raws.semicolon;
  32747. if (typeof value !== 'undefined') return false
  32748. }
  32749. });
  32750. return value
  32751. }
  32752. rawEmptyBody(root) {
  32753. let value;
  32754. root.walk(i => {
  32755. if (i.nodes && i.nodes.length === 0) {
  32756. value = i.raws.after;
  32757. if (typeof value !== 'undefined') return false
  32758. }
  32759. });
  32760. return value
  32761. }
  32762. rawIndent(root) {
  32763. if (root.raws.indent) return root.raws.indent
  32764. let value;
  32765. root.walk(i => {
  32766. let p = i.parent;
  32767. if (p && p !== root && p.parent && p.parent === root) {
  32768. if (typeof i.raws.before !== 'undefined') {
  32769. let parts = i.raws.before.split('\n');
  32770. value = parts[parts.length - 1];
  32771. value = value.replace(/\S/g, '');
  32772. return false
  32773. }
  32774. }
  32775. });
  32776. return value
  32777. }
  32778. rawBeforeComment(root, node) {
  32779. let value;
  32780. root.walkComments(i => {
  32781. if (typeof i.raws.before !== 'undefined') {
  32782. value = i.raws.before;
  32783. if (value.includes('\n')) {
  32784. value = value.replace(/[^\n]+$/, '');
  32785. }
  32786. return false
  32787. }
  32788. });
  32789. if (typeof value === 'undefined') {
  32790. value = this.raw(node, null, 'beforeDecl');
  32791. } else if (value) {
  32792. value = value.replace(/\S/g, '');
  32793. }
  32794. return value
  32795. }
  32796. rawBeforeDecl(root, node) {
  32797. let value;
  32798. root.walkDecls(i => {
  32799. if (typeof i.raws.before !== 'undefined') {
  32800. value = i.raws.before;
  32801. if (value.includes('\n')) {
  32802. value = value.replace(/[^\n]+$/, '');
  32803. }
  32804. return false
  32805. }
  32806. });
  32807. if (typeof value === 'undefined') {
  32808. value = this.raw(node, null, 'beforeRule');
  32809. } else if (value) {
  32810. value = value.replace(/\S/g, '');
  32811. }
  32812. return value
  32813. }
  32814. rawBeforeRule(root) {
  32815. let value;
  32816. root.walk(i => {
  32817. if (i.nodes && (i.parent !== root || root.first !== i)) {
  32818. if (typeof i.raws.before !== 'undefined') {
  32819. value = i.raws.before;
  32820. if (value.includes('\n')) {
  32821. value = value.replace(/[^\n]+$/, '');
  32822. }
  32823. return false
  32824. }
  32825. }
  32826. });
  32827. if (value) value = value.replace(/\S/g, '');
  32828. return value
  32829. }
  32830. rawBeforeClose(root) {
  32831. let value;
  32832. root.walk(i => {
  32833. if (i.nodes && i.nodes.length > 0) {
  32834. if (typeof i.raws.after !== 'undefined') {
  32835. value = i.raws.after;
  32836. if (value.includes('\n')) {
  32837. value = value.replace(/[^\n]+$/, '');
  32838. }
  32839. return false
  32840. }
  32841. }
  32842. });
  32843. if (value) value = value.replace(/\S/g, '');
  32844. return value
  32845. }
  32846. rawBeforeOpen(root) {
  32847. let value;
  32848. root.walk(i => {
  32849. if (i.type !== 'decl') {
  32850. value = i.raws.between;
  32851. if (typeof value !== 'undefined') return false
  32852. }
  32853. });
  32854. return value
  32855. }
  32856. rawColon(root) {
  32857. let value;
  32858. root.walkDecls(i => {
  32859. if (typeof i.raws.between !== 'undefined') {
  32860. value = i.raws.between.replace(/[^\s:]/g, '');
  32861. return false
  32862. }
  32863. });
  32864. return value
  32865. }
  32866. beforeAfter(node, detect) {
  32867. let value;
  32868. if (node.type === 'decl') {
  32869. value = this.raw(node, null, 'beforeDecl');
  32870. } else if (node.type === 'comment') {
  32871. value = this.raw(node, null, 'beforeComment');
  32872. } else if (detect === 'before') {
  32873. value = this.raw(node, null, 'beforeRule');
  32874. } else {
  32875. value = this.raw(node, null, 'beforeClose');
  32876. }
  32877. let buf = node.parent;
  32878. let depth = 0;
  32879. while (buf && buf.type !== 'root') {
  32880. depth += 1;
  32881. buf = buf.parent;
  32882. }
  32883. if (value.includes('\n')) {
  32884. let indent = this.raw(node, null, 'indent');
  32885. if (indent.length) {
  32886. for (let step = 0; step < depth; step++) value += indent;
  32887. }
  32888. }
  32889. return value
  32890. }
  32891. rawValue(node, prop) {
  32892. let value = node[prop];
  32893. let raw = node.raws[prop];
  32894. if (raw && raw.value === value) {
  32895. return raw.raw
  32896. }
  32897. return value
  32898. }
  32899. };
  32900. var stringifier = Stringifier$2;
  32901. Stringifier$2.default = Stringifier$2;
  32902. let Stringifier$1 = stringifier;
  32903. function stringify$4(node, builder) {
  32904. let str = new Stringifier$1(builder);
  32905. str.stringify(node);
  32906. }
  32907. var stringify_1 = stringify$4;
  32908. stringify$4.default = stringify$4;
  32909. let { isClean: isClean$2, my: my$2 } = symbols;
  32910. let CssSyntaxError$2 = cssSyntaxError;
  32911. let Stringifier = stringifier;
  32912. let stringify$3 = stringify_1;
  32913. function cloneNode(obj, parent) {
  32914. let cloned = new obj.constructor();
  32915. for (let i in obj) {
  32916. if (!Object.prototype.hasOwnProperty.call(obj, i)) {
  32917. /* c8 ignore next 2 */
  32918. continue
  32919. }
  32920. if (i === 'proxyCache') continue
  32921. let value = obj[i];
  32922. let type = typeof value;
  32923. if (i === 'parent' && type === 'object') {
  32924. if (parent) cloned[i] = parent;
  32925. } else if (i === 'source') {
  32926. cloned[i] = value;
  32927. } else if (Array.isArray(value)) {
  32928. cloned[i] = value.map(j => cloneNode(j, cloned));
  32929. } else {
  32930. if (type === 'object' && value !== null) value = cloneNode(value);
  32931. cloned[i] = value;
  32932. }
  32933. }
  32934. return cloned
  32935. }
  32936. let Node$4 = class Node {
  32937. constructor(defaults = {}) {
  32938. this.raws = {};
  32939. this[isClean$2] = false;
  32940. this[my$2] = true;
  32941. for (let name in defaults) {
  32942. if (name === 'nodes') {
  32943. this.nodes = [];
  32944. for (let node of defaults[name]) {
  32945. if (typeof node.clone === 'function') {
  32946. this.append(node.clone());
  32947. } else {
  32948. this.append(node);
  32949. }
  32950. }
  32951. } else {
  32952. this[name] = defaults[name];
  32953. }
  32954. }
  32955. }
  32956. error(message, opts = {}) {
  32957. if (this.source) {
  32958. let { start, end } = this.rangeBy(opts);
  32959. return this.source.input.error(
  32960. message,
  32961. { line: start.line, column: start.column },
  32962. { line: end.line, column: end.column },
  32963. opts
  32964. )
  32965. }
  32966. return new CssSyntaxError$2(message)
  32967. }
  32968. warn(result, text, opts) {
  32969. let data = { node: this };
  32970. for (let i in opts) data[i] = opts[i];
  32971. return result.warn(text, data)
  32972. }
  32973. remove() {
  32974. if (this.parent) {
  32975. this.parent.removeChild(this);
  32976. }
  32977. this.parent = undefined;
  32978. return this
  32979. }
  32980. toString(stringifier = stringify$3) {
  32981. if (stringifier.stringify) stringifier = stringifier.stringify;
  32982. let result = '';
  32983. stringifier(this, i => {
  32984. result += i;
  32985. });
  32986. return result
  32987. }
  32988. assign(overrides = {}) {
  32989. for (let name in overrides) {
  32990. this[name] = overrides[name];
  32991. }
  32992. return this
  32993. }
  32994. clone(overrides = {}) {
  32995. let cloned = cloneNode(this);
  32996. for (let name in overrides) {
  32997. cloned[name] = overrides[name];
  32998. }
  32999. return cloned
  33000. }
  33001. cloneBefore(overrides = {}) {
  33002. let cloned = this.clone(overrides);
  33003. this.parent.insertBefore(this, cloned);
  33004. return cloned
  33005. }
  33006. cloneAfter(overrides = {}) {
  33007. let cloned = this.clone(overrides);
  33008. this.parent.insertAfter(this, cloned);
  33009. return cloned
  33010. }
  33011. replaceWith(...nodes) {
  33012. if (this.parent) {
  33013. let bookmark = this;
  33014. let foundSelf = false;
  33015. for (let node of nodes) {
  33016. if (node === this) {
  33017. foundSelf = true;
  33018. } else if (foundSelf) {
  33019. this.parent.insertAfter(bookmark, node);
  33020. bookmark = node;
  33021. } else {
  33022. this.parent.insertBefore(bookmark, node);
  33023. }
  33024. }
  33025. if (!foundSelf) {
  33026. this.remove();
  33027. }
  33028. }
  33029. return this
  33030. }
  33031. next() {
  33032. if (!this.parent) return undefined
  33033. let index = this.parent.index(this);
  33034. return this.parent.nodes[index + 1]
  33035. }
  33036. prev() {
  33037. if (!this.parent) return undefined
  33038. let index = this.parent.index(this);
  33039. return this.parent.nodes[index - 1]
  33040. }
  33041. before(add) {
  33042. this.parent.insertBefore(this, add);
  33043. return this
  33044. }
  33045. after(add) {
  33046. this.parent.insertAfter(this, add);
  33047. return this
  33048. }
  33049. root() {
  33050. let result = this;
  33051. while (result.parent && result.parent.type !== 'document') {
  33052. result = result.parent;
  33053. }
  33054. return result
  33055. }
  33056. raw(prop, defaultType) {
  33057. let str = new Stringifier();
  33058. return str.raw(this, prop, defaultType)
  33059. }
  33060. cleanRaws(keepBetween) {
  33061. delete this.raws.before;
  33062. delete this.raws.after;
  33063. if (!keepBetween) delete this.raws.between;
  33064. }
  33065. toJSON(_, inputs) {
  33066. let fixed = {};
  33067. let emitInputs = inputs == null;
  33068. inputs = inputs || new Map();
  33069. let inputsNextIndex = 0;
  33070. for (let name in this) {
  33071. if (!Object.prototype.hasOwnProperty.call(this, name)) {
  33072. /* c8 ignore next 2 */
  33073. continue
  33074. }
  33075. if (name === 'parent' || name === 'proxyCache') continue
  33076. let value = this[name];
  33077. if (Array.isArray(value)) {
  33078. fixed[name] = value.map(i => {
  33079. if (typeof i === 'object' && i.toJSON) {
  33080. return i.toJSON(null, inputs)
  33081. } else {
  33082. return i
  33083. }
  33084. });
  33085. } else if (typeof value === 'object' && value.toJSON) {
  33086. fixed[name] = value.toJSON(null, inputs);
  33087. } else if (name === 'source') {
  33088. let inputId = inputs.get(value.input);
  33089. if (inputId == null) {
  33090. inputId = inputsNextIndex;
  33091. inputs.set(value.input, inputsNextIndex);
  33092. inputsNextIndex++;
  33093. }
  33094. fixed[name] = {
  33095. inputId,
  33096. start: value.start,
  33097. end: value.end
  33098. };
  33099. } else {
  33100. fixed[name] = value;
  33101. }
  33102. }
  33103. if (emitInputs) {
  33104. fixed.inputs = [...inputs.keys()].map(input => input.toJSON());
  33105. }
  33106. return fixed
  33107. }
  33108. positionInside(index) {
  33109. let string = this.toString();
  33110. let column = this.source.start.column;
  33111. let line = this.source.start.line;
  33112. for (let i = 0; i < index; i++) {
  33113. if (string[i] === '\n') {
  33114. column = 1;
  33115. line += 1;
  33116. } else {
  33117. column += 1;
  33118. }
  33119. }
  33120. return { line, column }
  33121. }
  33122. positionBy(opts) {
  33123. let pos = this.source.start;
  33124. if (opts.index) {
  33125. pos = this.positionInside(opts.index);
  33126. } else if (opts.word) {
  33127. let index = this.toString().indexOf(opts.word);
  33128. if (index !== -1) pos = this.positionInside(index);
  33129. }
  33130. return pos
  33131. }
  33132. rangeBy(opts) {
  33133. let start = {
  33134. line: this.source.start.line,
  33135. column: this.source.start.column
  33136. };
  33137. let end = this.source.end
  33138. ? {
  33139. line: this.source.end.line,
  33140. column: this.source.end.column + 1
  33141. }
  33142. : {
  33143. line: start.line,
  33144. column: start.column + 1
  33145. };
  33146. if (opts.word) {
  33147. let index = this.toString().indexOf(opts.word);
  33148. if (index !== -1) {
  33149. start = this.positionInside(index);
  33150. end = this.positionInside(index + opts.word.length);
  33151. }
  33152. } else {
  33153. if (opts.start) {
  33154. start = {
  33155. line: opts.start.line,
  33156. column: opts.start.column
  33157. };
  33158. } else if (opts.index) {
  33159. start = this.positionInside(opts.index);
  33160. }
  33161. if (opts.end) {
  33162. end = {
  33163. line: opts.end.line,
  33164. column: opts.end.column
  33165. };
  33166. } else if (opts.endIndex) {
  33167. end = this.positionInside(opts.endIndex);
  33168. } else if (opts.index) {
  33169. end = this.positionInside(opts.index + 1);
  33170. }
  33171. }
  33172. if (
  33173. end.line < start.line ||
  33174. (end.line === start.line && end.column <= start.column)
  33175. ) {
  33176. end = { line: start.line, column: start.column + 1 };
  33177. }
  33178. return { start, end }
  33179. }
  33180. getProxyProcessor() {
  33181. return {
  33182. set(node, prop, value) {
  33183. if (node[prop] === value) return true
  33184. node[prop] = value;
  33185. if (
  33186. prop === 'prop' ||
  33187. prop === 'value' ||
  33188. prop === 'name' ||
  33189. prop === 'params' ||
  33190. prop === 'important' ||
  33191. /* c8 ignore next */
  33192. prop === 'text'
  33193. ) {
  33194. node.markDirty();
  33195. }
  33196. return true
  33197. },
  33198. get(node, prop) {
  33199. if (prop === 'proxyOf') {
  33200. return node
  33201. } else if (prop === 'root') {
  33202. return () => node.root().toProxy()
  33203. } else {
  33204. return node[prop]
  33205. }
  33206. }
  33207. }
  33208. }
  33209. toProxy() {
  33210. if (!this.proxyCache) {
  33211. this.proxyCache = new Proxy(this, this.getProxyProcessor());
  33212. }
  33213. return this.proxyCache
  33214. }
  33215. addToError(error) {
  33216. error.postcssNode = this;
  33217. if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
  33218. let s = this.source;
  33219. error.stack = error.stack.replace(
  33220. /\n\s{4}at /,
  33221. `$&${s.input.from}:${s.start.line}:${s.start.column}$&`
  33222. );
  33223. }
  33224. return error
  33225. }
  33226. markDirty() {
  33227. if (this[isClean$2]) {
  33228. this[isClean$2] = false;
  33229. let next = this;
  33230. while ((next = next.parent)) {
  33231. next[isClean$2] = false;
  33232. }
  33233. }
  33234. }
  33235. get proxyOf() {
  33236. return this
  33237. }
  33238. };
  33239. var node$2 = Node$4;
  33240. Node$4.default = Node$4;
  33241. let Node$3 = node$2;
  33242. let Declaration$4 = class Declaration extends Node$3 {
  33243. constructor(defaults) {
  33244. if (
  33245. defaults &&
  33246. typeof defaults.value !== 'undefined' &&
  33247. typeof defaults.value !== 'string'
  33248. ) {
  33249. defaults = { ...defaults, value: String(defaults.value) };
  33250. }
  33251. super(defaults);
  33252. this.type = 'decl';
  33253. }
  33254. get variable() {
  33255. return this.prop.startsWith('--') || this.prop[0] === '$'
  33256. }
  33257. };
  33258. var declaration = Declaration$4;
  33259. Declaration$4.default = Declaration$4;
  33260. var require$$2 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_url$1);
  33261. let urlAlphabet =
  33262. 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
  33263. let customAlphabet = (alphabet, defaultSize = 21) => {
  33264. return (size = defaultSize) => {
  33265. let id = '';
  33266. let i = size;
  33267. while (i--) {
  33268. id += alphabet[(Math.random() * alphabet.length) | 0];
  33269. }
  33270. return id
  33271. }
  33272. };
  33273. let nanoid$1 = (size = 21) => {
  33274. let id = '';
  33275. let i = size;
  33276. while (i--) {
  33277. id += urlAlphabet[(Math.random() * 64) | 0];
  33278. }
  33279. return id
  33280. };
  33281. var nonSecure = { nanoid: nanoid$1, customAlphabet };
  33282. let { SourceMapConsumer: SourceMapConsumer$4, SourceMapGenerator: SourceMapGenerator$5 } = sourceMap$2;
  33283. let { existsSync, readFileSync } = require$$0$2;
  33284. let { dirname: dirname$1, join } = require$$2$1;
  33285. function fromBase64(str) {
  33286. if (Buffer$1) {
  33287. return Buffer$1.from(str, 'base64').toString()
  33288. } else {
  33289. /* c8 ignore next 2 */
  33290. return window.atob(str)
  33291. }
  33292. }
  33293. let PreviousMap$2 = class PreviousMap {
  33294. constructor(css, opts) {
  33295. if (opts.map === false) return
  33296. this.loadAnnotation(css);
  33297. this.inline = this.startWith(this.annotation, 'data:');
  33298. let prev = opts.map ? opts.map.prev : undefined;
  33299. let text = this.loadMap(opts.from, prev);
  33300. if (!this.mapFile && opts.from) {
  33301. this.mapFile = opts.from;
  33302. }
  33303. if (this.mapFile) this.root = dirname$1(this.mapFile);
  33304. if (text) this.text = text;
  33305. }
  33306. consumer() {
  33307. if (!this.consumerCache) {
  33308. this.consumerCache = new SourceMapConsumer$4(this.text);
  33309. }
  33310. return this.consumerCache
  33311. }
  33312. withContent() {
  33313. return !!(
  33314. this.consumer().sourcesContent &&
  33315. this.consumer().sourcesContent.length > 0
  33316. )
  33317. }
  33318. startWith(string, start) {
  33319. if (!string) return false
  33320. return string.substr(0, start.length) === start
  33321. }
  33322. getAnnotationURL(sourceMapString) {
  33323. return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
  33324. }
  33325. loadAnnotation(css) {
  33326. let comments = css.match(/\/\*\s*# sourceMappingURL=/gm);
  33327. if (!comments) return
  33328. // sourceMappingURLs from comments, strings, etc.
  33329. let start = css.lastIndexOf(comments.pop());
  33330. let end = css.indexOf('*/', start);
  33331. if (start > -1 && end > -1) {
  33332. // Locate the last sourceMappingURL to avoid pickin
  33333. this.annotation = this.getAnnotationURL(css.substring(start, end));
  33334. }
  33335. }
  33336. decodeInline(text) {
  33337. let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
  33338. let baseUri = /^data:application\/json;base64,/;
  33339. let charsetUri = /^data:application\/json;charset=utf-?8,/;
  33340. let uri = /^data:application\/json,/;
  33341. if (charsetUri.test(text) || uri.test(text)) {
  33342. return decodeURIComponent(text.substr(RegExp.lastMatch.length))
  33343. }
  33344. if (baseCharsetUri.test(text) || baseUri.test(text)) {
  33345. return fromBase64(text.substr(RegExp.lastMatch.length))
  33346. }
  33347. let encoding = text.match(/data:application\/json;([^,]+),/)[1];
  33348. throw new Error('Unsupported source map encoding ' + encoding)
  33349. }
  33350. loadFile(path) {
  33351. this.root = dirname$1(path);
  33352. if (existsSync(path)) {
  33353. this.mapFile = path;
  33354. return readFileSync(path, 'utf-8').toString().trim()
  33355. }
  33356. }
  33357. loadMap(file, prev) {
  33358. if (prev === false) return false
  33359. if (prev) {
  33360. if (typeof prev === 'string') {
  33361. return prev
  33362. } else if (typeof prev === 'function') {
  33363. let prevPath = prev(file);
  33364. if (prevPath) {
  33365. let map = this.loadFile(prevPath);
  33366. if (!map) {
  33367. throw new Error(
  33368. 'Unable to load previous source map: ' + prevPath.toString()
  33369. )
  33370. }
  33371. return map
  33372. }
  33373. } else if (prev instanceof SourceMapConsumer$4) {
  33374. return SourceMapGenerator$5.fromSourceMap(prev).toString()
  33375. } else if (prev instanceof SourceMapGenerator$5) {
  33376. return prev.toString()
  33377. } else if (this.isMap(prev)) {
  33378. return JSON.stringify(prev)
  33379. } else {
  33380. throw new Error(
  33381. 'Unsupported previous source map format: ' + prev.toString()
  33382. )
  33383. }
  33384. } else if (this.inline) {
  33385. return this.decodeInline(this.annotation)
  33386. } else if (this.annotation) {
  33387. let map = this.annotation;
  33388. if (file) map = join(dirname$1(file), map);
  33389. return this.loadFile(map)
  33390. }
  33391. }
  33392. isMap(map) {
  33393. if (typeof map !== 'object') return false
  33394. return (
  33395. typeof map.mappings === 'string' ||
  33396. typeof map._mappings === 'string' ||
  33397. Array.isArray(map.sections)
  33398. )
  33399. }
  33400. };
  33401. var previousMap = PreviousMap$2;
  33402. PreviousMap$2.default = PreviousMap$2;
  33403. let { SourceMapConsumer: SourceMapConsumer$3, SourceMapGenerator: SourceMapGenerator$4 } = sourceMap$2;
  33404. let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
  33405. let { resolve: resolve$1, isAbsolute } = require$$2$1;
  33406. let { nanoid } = nonSecure;
  33407. let terminalHighlight = terminalHighlight_1;
  33408. let CssSyntaxError$1 = cssSyntaxError;
  33409. let PreviousMap$1 = previousMap;
  33410. let fromOffsetCache = Symbol('fromOffsetCache');
  33411. let sourceMapAvailable$1 = Boolean(SourceMapConsumer$3 && SourceMapGenerator$4);
  33412. let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
  33413. let Input$4 = class Input {
  33414. constructor(css, opts = {}) {
  33415. if (
  33416. css === null ||
  33417. typeof css === 'undefined' ||
  33418. (typeof css === 'object' && !css.toString)
  33419. ) {
  33420. throw new Error(`PostCSS received ${css} instead of CSS string`)
  33421. }
  33422. this.css = css.toString();
  33423. if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
  33424. this.hasBOM = true;
  33425. this.css = this.css.slice(1);
  33426. } else {
  33427. this.hasBOM = false;
  33428. }
  33429. if (opts.from) {
  33430. if (
  33431. !pathAvailable$1 ||
  33432. /^\w+:\/\//.test(opts.from) ||
  33433. isAbsolute(opts.from)
  33434. ) {
  33435. this.file = opts.from;
  33436. } else {
  33437. this.file = resolve$1(opts.from);
  33438. }
  33439. }
  33440. if (pathAvailable$1 && sourceMapAvailable$1) {
  33441. let map = new PreviousMap$1(this.css, opts);
  33442. if (map.text) {
  33443. this.map = map;
  33444. let file = map.consumer().file;
  33445. if (!this.file && file) this.file = this.mapResolve(file);
  33446. }
  33447. }
  33448. if (!this.file) {
  33449. this.id = '<input css ' + nanoid(6) + '>';
  33450. }
  33451. if (this.map) this.map.file = this.from;
  33452. }
  33453. fromOffset(offset) {
  33454. let lastLine, lineToIndex;
  33455. if (!this[fromOffsetCache]) {
  33456. let lines = this.css.split('\n');
  33457. lineToIndex = new Array(lines.length);
  33458. let prevIndex = 0;
  33459. for (let i = 0, l = lines.length; i < l; i++) {
  33460. lineToIndex[i] = prevIndex;
  33461. prevIndex += lines[i].length + 1;
  33462. }
  33463. this[fromOffsetCache] = lineToIndex;
  33464. } else {
  33465. lineToIndex = this[fromOffsetCache];
  33466. }
  33467. lastLine = lineToIndex[lineToIndex.length - 1];
  33468. let min = 0;
  33469. if (offset >= lastLine) {
  33470. min = lineToIndex.length - 1;
  33471. } else {
  33472. let max = lineToIndex.length - 2;
  33473. let mid;
  33474. while (min < max) {
  33475. mid = min + ((max - min) >> 1);
  33476. if (offset < lineToIndex[mid]) {
  33477. max = mid - 1;
  33478. } else if (offset >= lineToIndex[mid + 1]) {
  33479. min = mid + 1;
  33480. } else {
  33481. min = mid;
  33482. break
  33483. }
  33484. }
  33485. }
  33486. return {
  33487. line: min + 1,
  33488. col: offset - lineToIndex[min] + 1
  33489. }
  33490. }
  33491. error(message, line, column, opts = {}) {
  33492. let result, endLine, endColumn;
  33493. if (line && typeof line === 'object') {
  33494. let start = line;
  33495. let end = column;
  33496. if (typeof start.offset === 'number') {
  33497. let pos = this.fromOffset(start.offset);
  33498. line = pos.line;
  33499. column = pos.col;
  33500. } else {
  33501. line = start.line;
  33502. column = start.column;
  33503. }
  33504. if (typeof end.offset === 'number') {
  33505. let pos = this.fromOffset(end.offset);
  33506. endLine = pos.line;
  33507. endColumn = pos.col;
  33508. } else {
  33509. endLine = end.line;
  33510. endColumn = end.column;
  33511. }
  33512. } else if (!column) {
  33513. let pos = this.fromOffset(line);
  33514. line = pos.line;
  33515. column = pos.col;
  33516. }
  33517. let origin = this.origin(line, column, endLine, endColumn);
  33518. if (origin) {
  33519. result = new CssSyntaxError$1(
  33520. message,
  33521. origin.endLine === undefined
  33522. ? origin.line
  33523. : { line: origin.line, column: origin.column },
  33524. origin.endLine === undefined
  33525. ? origin.column
  33526. : { line: origin.endLine, column: origin.endColumn },
  33527. origin.source,
  33528. origin.file,
  33529. opts.plugin
  33530. );
  33531. } else {
  33532. result = new CssSyntaxError$1(
  33533. message,
  33534. endLine === undefined ? line : { line, column },
  33535. endLine === undefined ? column : { line: endLine, column: endColumn },
  33536. this.css,
  33537. this.file,
  33538. opts.plugin
  33539. );
  33540. }
  33541. result.input = { line, column, endLine, endColumn, source: this.css };
  33542. if (this.file) {
  33543. if (pathToFileURL$1) {
  33544. result.input.url = pathToFileURL$1(this.file).toString();
  33545. }
  33546. result.input.file = this.file;
  33547. }
  33548. return result
  33549. }
  33550. origin(line, column, endLine, endColumn) {
  33551. if (!this.map) return false
  33552. let consumer = this.map.consumer();
  33553. let from = consumer.originalPositionFor({ line, column });
  33554. if (!from.source) return false
  33555. let to;
  33556. if (typeof endLine === 'number') {
  33557. to = consumer.originalPositionFor({ line: endLine, column: endColumn });
  33558. }
  33559. let fromUrl;
  33560. if (isAbsolute(from.source)) {
  33561. fromUrl = pathToFileURL$1(from.source);
  33562. } else {
  33563. fromUrl = new URL(
  33564. from.source,
  33565. this.map.consumer().sourceRoot || pathToFileURL$1(this.map.mapFile)
  33566. );
  33567. }
  33568. let result = {
  33569. url: fromUrl.toString(),
  33570. line: from.line,
  33571. column: from.column,
  33572. endLine: to && to.line,
  33573. endColumn: to && to.column
  33574. };
  33575. if (fromUrl.protocol === 'file:') {
  33576. if (fileURLToPath) {
  33577. result.file = fileURLToPath(fromUrl);
  33578. } else {
  33579. /* c8 ignore next 2 */
  33580. throw new Error(`file: protocol is not available in this PostCSS build`)
  33581. }
  33582. }
  33583. let source = consumer.sourceContentFor(from.source);
  33584. if (source) result.source = source;
  33585. return result
  33586. }
  33587. mapResolve(file) {
  33588. if (/^\w+:\/\//.test(file)) {
  33589. return file
  33590. }
  33591. return resolve$1(this.map.consumer().sourceRoot || this.map.root || '.', file)
  33592. }
  33593. get from() {
  33594. return this.file || this.id
  33595. }
  33596. toJSON() {
  33597. let json = {};
  33598. for (let name of ['hasBOM', 'css', 'file', 'id']) {
  33599. if (this[name] != null) {
  33600. json[name] = this[name];
  33601. }
  33602. }
  33603. if (this.map) {
  33604. json.map = { ...this.map };
  33605. if (json.map.consumerCache) {
  33606. json.map.consumerCache = undefined;
  33607. }
  33608. }
  33609. return json
  33610. }
  33611. };
  33612. var input = Input$4;
  33613. Input$4.default = Input$4;
  33614. if (terminalHighlight && terminalHighlight.registerInput) {
  33615. terminalHighlight.registerInput(Input$4);
  33616. }
  33617. let { SourceMapConsumer: SourceMapConsumer$2, SourceMapGenerator: SourceMapGenerator$3 } = sourceMap$2;
  33618. let { dirname, resolve, relative, sep } = require$$2$1;
  33619. let { pathToFileURL } = require$$2;
  33620. let Input$3 = input;
  33621. let sourceMapAvailable = Boolean(SourceMapConsumer$2 && SourceMapGenerator$3);
  33622. let pathAvailable = Boolean(dirname && resolve && relative && sep);
  33623. let MapGenerator$2 = class MapGenerator {
  33624. constructor(stringify, root, opts, cssString) {
  33625. this.stringify = stringify;
  33626. this.mapOpts = opts.map || {};
  33627. this.root = root;
  33628. this.opts = opts;
  33629. this.css = cssString;
  33630. this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
  33631. }
  33632. isMap() {
  33633. if (typeof this.opts.map !== 'undefined') {
  33634. return !!this.opts.map
  33635. }
  33636. return this.previous().length > 0
  33637. }
  33638. previous() {
  33639. if (!this.previousMaps) {
  33640. this.previousMaps = [];
  33641. if (this.root) {
  33642. this.root.walk(node => {
  33643. if (node.source && node.source.input.map) {
  33644. let map = node.source.input.map;
  33645. if (!this.previousMaps.includes(map)) {
  33646. this.previousMaps.push(map);
  33647. }
  33648. }
  33649. });
  33650. } else {
  33651. let input = new Input$3(this.css, this.opts);
  33652. if (input.map) this.previousMaps.push(input.map);
  33653. }
  33654. }
  33655. return this.previousMaps
  33656. }
  33657. isInline() {
  33658. if (typeof this.mapOpts.inline !== 'undefined') {
  33659. return this.mapOpts.inline
  33660. }
  33661. let annotation = this.mapOpts.annotation;
  33662. if (typeof annotation !== 'undefined' && annotation !== true) {
  33663. return false
  33664. }
  33665. if (this.previous().length) {
  33666. return this.previous().some(i => i.inline)
  33667. }
  33668. return true
  33669. }
  33670. isSourcesContent() {
  33671. if (typeof this.mapOpts.sourcesContent !== 'undefined') {
  33672. return this.mapOpts.sourcesContent
  33673. }
  33674. if (this.previous().length) {
  33675. return this.previous().some(i => i.withContent())
  33676. }
  33677. return true
  33678. }
  33679. clearAnnotation() {
  33680. if (this.mapOpts.annotation === false) return
  33681. if (this.root) {
  33682. let node;
  33683. for (let i = this.root.nodes.length - 1; i >= 0; i--) {
  33684. node = this.root.nodes[i];
  33685. if (node.type !== 'comment') continue
  33686. if (node.text.indexOf('# sourceMappingURL=') === 0) {
  33687. this.root.removeChild(i);
  33688. }
  33689. }
  33690. } else if (this.css) {
  33691. this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '');
  33692. }
  33693. }
  33694. setSourcesContent() {
  33695. let already = {};
  33696. if (this.root) {
  33697. this.root.walk(node => {
  33698. if (node.source) {
  33699. let from = node.source.input.from;
  33700. if (from && !already[from]) {
  33701. already[from] = true;
  33702. let fromUrl = this.usesFileUrls
  33703. ? this.toFileUrl(from)
  33704. : this.toUrl(this.path(from));
  33705. this.map.setSourceContent(fromUrl, node.source.input.css);
  33706. }
  33707. }
  33708. });
  33709. } else if (this.css) {
  33710. let from = this.opts.from
  33711. ? this.toUrl(this.path(this.opts.from))
  33712. : '<no source>';
  33713. this.map.setSourceContent(from, this.css);
  33714. }
  33715. }
  33716. applyPrevMaps() {
  33717. for (let prev of this.previous()) {
  33718. let from = this.toUrl(this.path(prev.file));
  33719. let root = prev.root || dirname(prev.file);
  33720. let map;
  33721. if (this.mapOpts.sourcesContent === false) {
  33722. map = new SourceMapConsumer$2(prev.text);
  33723. if (map.sourcesContent) {
  33724. map.sourcesContent = map.sourcesContent.map(() => null);
  33725. }
  33726. } else {
  33727. map = prev.consumer();
  33728. }
  33729. this.map.applySourceMap(map, from, this.toUrl(this.path(root)));
  33730. }
  33731. }
  33732. isAnnotation() {
  33733. if (this.isInline()) {
  33734. return true
  33735. }
  33736. if (typeof this.mapOpts.annotation !== 'undefined') {
  33737. return this.mapOpts.annotation
  33738. }
  33739. if (this.previous().length) {
  33740. return this.previous().some(i => i.annotation)
  33741. }
  33742. return true
  33743. }
  33744. toBase64(str) {
  33745. if (Buffer$1) {
  33746. return Buffer$1.from(str).toString('base64')
  33747. } else {
  33748. return window.btoa(unescape(encodeURIComponent(str)))
  33749. }
  33750. }
  33751. addAnnotation() {
  33752. let content;
  33753. if (this.isInline()) {
  33754. content =
  33755. 'data:application/json;base64,' + this.toBase64(this.map.toString());
  33756. } else if (typeof this.mapOpts.annotation === 'string') {
  33757. content = this.mapOpts.annotation;
  33758. } else if (typeof this.mapOpts.annotation === 'function') {
  33759. content = this.mapOpts.annotation(this.opts.to, this.root);
  33760. } else {
  33761. content = this.outputFile() + '.map';
  33762. }
  33763. let eol = '\n';
  33764. if (this.css.includes('\r\n')) eol = '\r\n';
  33765. this.css += eol + '/*# sourceMappingURL=' + content + ' */';
  33766. }
  33767. outputFile() {
  33768. if (this.opts.to) {
  33769. return this.path(this.opts.to)
  33770. } else if (this.opts.from) {
  33771. return this.path(this.opts.from)
  33772. } else {
  33773. return 'to.css'
  33774. }
  33775. }
  33776. generateMap() {
  33777. if (this.root) {
  33778. this.generateString();
  33779. } else if (this.previous().length === 1) {
  33780. let prev = this.previous()[0].consumer();
  33781. prev.file = this.outputFile();
  33782. this.map = SourceMapGenerator$3.fromSourceMap(prev);
  33783. } else {
  33784. this.map = new SourceMapGenerator$3({ file: this.outputFile() });
  33785. this.map.addMapping({
  33786. source: this.opts.from
  33787. ? this.toUrl(this.path(this.opts.from))
  33788. : '<no source>',
  33789. generated: { line: 1, column: 0 },
  33790. original: { line: 1, column: 0 }
  33791. });
  33792. }
  33793. if (this.isSourcesContent()) this.setSourcesContent();
  33794. if (this.root && this.previous().length > 0) this.applyPrevMaps();
  33795. if (this.isAnnotation()) this.addAnnotation();
  33796. if (this.isInline()) {
  33797. return [this.css]
  33798. } else {
  33799. return [this.css, this.map]
  33800. }
  33801. }
  33802. path(file) {
  33803. if (file.indexOf('<') === 0) return file
  33804. if (/^\w+:\/\//.test(file)) return file
  33805. if (this.mapOpts.absolute) return file
  33806. let from = this.opts.to ? dirname(this.opts.to) : '.';
  33807. if (typeof this.mapOpts.annotation === 'string') {
  33808. from = dirname(resolve(from, this.mapOpts.annotation));
  33809. }
  33810. file = relative(from, file);
  33811. return file
  33812. }
  33813. toUrl(path) {
  33814. if (sep === '\\') {
  33815. path = path.replace(/\\/g, '/');
  33816. }
  33817. return encodeURI(path).replace(/[#?]/g, encodeURIComponent)
  33818. }
  33819. toFileUrl(path) {
  33820. if (pathToFileURL) {
  33821. return pathToFileURL(path).toString()
  33822. } else {
  33823. throw new Error(
  33824. '`map.absolute` option is not available in this PostCSS build'
  33825. )
  33826. }
  33827. }
  33828. sourcePath(node) {
  33829. if (this.mapOpts.from) {
  33830. return this.toUrl(this.mapOpts.from)
  33831. } else if (this.usesFileUrls) {
  33832. return this.toFileUrl(node.source.input.from)
  33833. } else {
  33834. return this.toUrl(this.path(node.source.input.from))
  33835. }
  33836. }
  33837. generateString() {
  33838. this.css = '';
  33839. this.map = new SourceMapGenerator$3({ file: this.outputFile() });
  33840. let line = 1;
  33841. let column = 1;
  33842. let noSource = '<no source>';
  33843. let mapping = {
  33844. source: '',
  33845. generated: { line: 0, column: 0 },
  33846. original: { line: 0, column: 0 }
  33847. };
  33848. let lines, last;
  33849. this.stringify(this.root, (str, node, type) => {
  33850. this.css += str;
  33851. if (node && type !== 'end') {
  33852. mapping.generated.line = line;
  33853. mapping.generated.column = column - 1;
  33854. if (node.source && node.source.start) {
  33855. mapping.source = this.sourcePath(node);
  33856. mapping.original.line = node.source.start.line;
  33857. mapping.original.column = node.source.start.column - 1;
  33858. this.map.addMapping(mapping);
  33859. } else {
  33860. mapping.source = noSource;
  33861. mapping.original.line = 1;
  33862. mapping.original.column = 0;
  33863. this.map.addMapping(mapping);
  33864. }
  33865. }
  33866. lines = str.match(/\n/g);
  33867. if (lines) {
  33868. line += lines.length;
  33869. last = str.lastIndexOf('\n');
  33870. column = str.length - last;
  33871. } else {
  33872. column += str.length;
  33873. }
  33874. if (node && type !== 'start') {
  33875. let p = node.parent || { raws: {} };
  33876. let childless =
  33877. node.type === 'decl' || (node.type === 'atrule' && !node.nodes);
  33878. if (!childless || node !== p.last || p.raws.semicolon) {
  33879. if (node.source && node.source.end) {
  33880. mapping.source = this.sourcePath(node);
  33881. mapping.original.line = node.source.end.line;
  33882. mapping.original.column = node.source.end.column - 1;
  33883. mapping.generated.line = line;
  33884. mapping.generated.column = column - 2;
  33885. this.map.addMapping(mapping);
  33886. } else {
  33887. mapping.source = noSource;
  33888. mapping.original.line = 1;
  33889. mapping.original.column = 0;
  33890. mapping.generated.line = line;
  33891. mapping.generated.column = column - 1;
  33892. this.map.addMapping(mapping);
  33893. }
  33894. }
  33895. }
  33896. });
  33897. }
  33898. generate() {
  33899. this.clearAnnotation();
  33900. if (pathAvailable && sourceMapAvailable && this.isMap()) {
  33901. return this.generateMap()
  33902. } else {
  33903. let result = '';
  33904. this.stringify(this.root, i => {
  33905. result += i;
  33906. });
  33907. return [result]
  33908. }
  33909. }
  33910. };
  33911. var mapGenerator = MapGenerator$2;
  33912. let Node$2 = node$2;
  33913. let Comment$4 = class Comment extends Node$2 {
  33914. constructor(defaults) {
  33915. super(defaults);
  33916. this.type = 'comment';
  33917. }
  33918. };
  33919. var comment$3 = Comment$4;
  33920. Comment$4.default = Comment$4;
  33921. let { isClean: isClean$1, my: my$1 } = symbols;
  33922. let Declaration$3 = declaration;
  33923. let Comment$3 = comment$3;
  33924. let Node$1 = node$2;
  33925. let parse$4, Rule$4, AtRule$4, Root$6;
  33926. function cleanSource(nodes) {
  33927. return nodes.map(i => {
  33928. if (i.nodes) i.nodes = cleanSource(i.nodes);
  33929. delete i.source;
  33930. return i
  33931. })
  33932. }
  33933. function markDirtyUp(node) {
  33934. node[isClean$1] = false;
  33935. if (node.proxyOf.nodes) {
  33936. for (let i of node.proxyOf.nodes) {
  33937. markDirtyUp(i);
  33938. }
  33939. }
  33940. }
  33941. let Container$7 = class Container extends Node$1 {
  33942. push(child) {
  33943. child.parent = this;
  33944. this.proxyOf.nodes.push(child);
  33945. return this
  33946. }
  33947. each(callback) {
  33948. if (!this.proxyOf.nodes) return undefined
  33949. let iterator = this.getIterator();
  33950. let index, result;
  33951. while (this.indexes[iterator] < this.proxyOf.nodes.length) {
  33952. index = this.indexes[iterator];
  33953. result = callback(this.proxyOf.nodes[index], index);
  33954. if (result === false) break
  33955. this.indexes[iterator] += 1;
  33956. }
  33957. delete this.indexes[iterator];
  33958. return result
  33959. }
  33960. walk(callback) {
  33961. return this.each((child, i) => {
  33962. let result;
  33963. try {
  33964. result = callback(child, i);
  33965. } catch (e) {
  33966. throw child.addToError(e)
  33967. }
  33968. if (result !== false && child.walk) {
  33969. result = child.walk(callback);
  33970. }
  33971. return result
  33972. })
  33973. }
  33974. walkDecls(prop, callback) {
  33975. if (!callback) {
  33976. callback = prop;
  33977. return this.walk((child, i) => {
  33978. if (child.type === 'decl') {
  33979. return callback(child, i)
  33980. }
  33981. })
  33982. }
  33983. if (prop instanceof RegExp) {
  33984. return this.walk((child, i) => {
  33985. if (child.type === 'decl' && prop.test(child.prop)) {
  33986. return callback(child, i)
  33987. }
  33988. })
  33989. }
  33990. return this.walk((child, i) => {
  33991. if (child.type === 'decl' && child.prop === prop) {
  33992. return callback(child, i)
  33993. }
  33994. })
  33995. }
  33996. walkRules(selector, callback) {
  33997. if (!callback) {
  33998. callback = selector;
  33999. return this.walk((child, i) => {
  34000. if (child.type === 'rule') {
  34001. return callback(child, i)
  34002. }
  34003. })
  34004. }
  34005. if (selector instanceof RegExp) {
  34006. return this.walk((child, i) => {
  34007. if (child.type === 'rule' && selector.test(child.selector)) {
  34008. return callback(child, i)
  34009. }
  34010. })
  34011. }
  34012. return this.walk((child, i) => {
  34013. if (child.type === 'rule' && child.selector === selector) {
  34014. return callback(child, i)
  34015. }
  34016. })
  34017. }
  34018. walkAtRules(name, callback) {
  34019. if (!callback) {
  34020. callback = name;
  34021. return this.walk((child, i) => {
  34022. if (child.type === 'atrule') {
  34023. return callback(child, i)
  34024. }
  34025. })
  34026. }
  34027. if (name instanceof RegExp) {
  34028. return this.walk((child, i) => {
  34029. if (child.type === 'atrule' && name.test(child.name)) {
  34030. return callback(child, i)
  34031. }
  34032. })
  34033. }
  34034. return this.walk((child, i) => {
  34035. if (child.type === 'atrule' && child.name === name) {
  34036. return callback(child, i)
  34037. }
  34038. })
  34039. }
  34040. walkComments(callback) {
  34041. return this.walk((child, i) => {
  34042. if (child.type === 'comment') {
  34043. return callback(child, i)
  34044. }
  34045. })
  34046. }
  34047. append(...children) {
  34048. for (let child of children) {
  34049. let nodes = this.normalize(child, this.last);
  34050. for (let node of nodes) this.proxyOf.nodes.push(node);
  34051. }
  34052. this.markDirty();
  34053. return this
  34054. }
  34055. prepend(...children) {
  34056. children = children.reverse();
  34057. for (let child of children) {
  34058. let nodes = this.normalize(child, this.first, 'prepend').reverse();
  34059. for (let node of nodes) this.proxyOf.nodes.unshift(node);
  34060. for (let id in this.indexes) {
  34061. this.indexes[id] = this.indexes[id] + nodes.length;
  34062. }
  34063. }
  34064. this.markDirty();
  34065. return this
  34066. }
  34067. cleanRaws(keepBetween) {
  34068. super.cleanRaws(keepBetween);
  34069. if (this.nodes) {
  34070. for (let node of this.nodes) node.cleanRaws(keepBetween);
  34071. }
  34072. }
  34073. insertBefore(exist, add) {
  34074. let existIndex = this.index(exist);
  34075. let type = existIndex === 0 ? 'prepend' : false;
  34076. let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse();
  34077. existIndex = this.index(exist);
  34078. for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node);
  34079. let index;
  34080. for (let id in this.indexes) {
  34081. index = this.indexes[id];
  34082. if (existIndex <= index) {
  34083. this.indexes[id] = index + nodes.length;
  34084. }
  34085. }
  34086. this.markDirty();
  34087. return this
  34088. }
  34089. insertAfter(exist, add) {
  34090. let existIndex = this.index(exist);
  34091. let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
  34092. existIndex = this.index(exist);
  34093. for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node);
  34094. let index;
  34095. for (let id in this.indexes) {
  34096. index = this.indexes[id];
  34097. if (existIndex < index) {
  34098. this.indexes[id] = index + nodes.length;
  34099. }
  34100. }
  34101. this.markDirty();
  34102. return this
  34103. }
  34104. removeChild(child) {
  34105. child = this.index(child);
  34106. this.proxyOf.nodes[child].parent = undefined;
  34107. this.proxyOf.nodes.splice(child, 1);
  34108. let index;
  34109. for (let id in this.indexes) {
  34110. index = this.indexes[id];
  34111. if (index >= child) {
  34112. this.indexes[id] = index - 1;
  34113. }
  34114. }
  34115. this.markDirty();
  34116. return this
  34117. }
  34118. removeAll() {
  34119. for (let node of this.proxyOf.nodes) node.parent = undefined;
  34120. this.proxyOf.nodes = [];
  34121. this.markDirty();
  34122. return this
  34123. }
  34124. replaceValues(pattern, opts, callback) {
  34125. if (!callback) {
  34126. callback = opts;
  34127. opts = {};
  34128. }
  34129. this.walkDecls(decl => {
  34130. if (opts.props && !opts.props.includes(decl.prop)) return
  34131. if (opts.fast && !decl.value.includes(opts.fast)) return
  34132. decl.value = decl.value.replace(pattern, callback);
  34133. });
  34134. this.markDirty();
  34135. return this
  34136. }
  34137. every(condition) {
  34138. return this.nodes.every(condition)
  34139. }
  34140. some(condition) {
  34141. return this.nodes.some(condition)
  34142. }
  34143. index(child) {
  34144. if (typeof child === 'number') return child
  34145. if (child.proxyOf) child = child.proxyOf;
  34146. return this.proxyOf.nodes.indexOf(child)
  34147. }
  34148. get first() {
  34149. if (!this.proxyOf.nodes) return undefined
  34150. return this.proxyOf.nodes[0]
  34151. }
  34152. get last() {
  34153. if (!this.proxyOf.nodes) return undefined
  34154. return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
  34155. }
  34156. normalize(nodes, sample) {
  34157. if (typeof nodes === 'string') {
  34158. nodes = cleanSource(parse$4(nodes).nodes);
  34159. } else if (Array.isArray(nodes)) {
  34160. nodes = nodes.slice(0);
  34161. for (let i of nodes) {
  34162. if (i.parent) i.parent.removeChild(i, 'ignore');
  34163. }
  34164. } else if (nodes.type === 'root' && this.type !== 'document') {
  34165. nodes = nodes.nodes.slice(0);
  34166. for (let i of nodes) {
  34167. if (i.parent) i.parent.removeChild(i, 'ignore');
  34168. }
  34169. } else if (nodes.type) {
  34170. nodes = [nodes];
  34171. } else if (nodes.prop) {
  34172. if (typeof nodes.value === 'undefined') {
  34173. throw new Error('Value field is missed in node creation')
  34174. } else if (typeof nodes.value !== 'string') {
  34175. nodes.value = String(nodes.value);
  34176. }
  34177. nodes = [new Declaration$3(nodes)];
  34178. } else if (nodes.selector) {
  34179. nodes = [new Rule$4(nodes)];
  34180. } else if (nodes.name) {
  34181. nodes = [new AtRule$4(nodes)];
  34182. } else if (nodes.text) {
  34183. nodes = [new Comment$3(nodes)];
  34184. } else {
  34185. throw new Error('Unknown node type in node creation')
  34186. }
  34187. let processed = nodes.map(i => {
  34188. /* c8 ignore next */
  34189. if (!i[my$1]) Container.rebuild(i);
  34190. i = i.proxyOf;
  34191. if (i.parent) i.parent.removeChild(i);
  34192. if (i[isClean$1]) markDirtyUp(i);
  34193. if (typeof i.raws.before === 'undefined') {
  34194. if (sample && typeof sample.raws.before !== 'undefined') {
  34195. i.raws.before = sample.raws.before.replace(/\S/g, '');
  34196. }
  34197. }
  34198. i.parent = this.proxyOf;
  34199. return i
  34200. });
  34201. return processed
  34202. }
  34203. getProxyProcessor() {
  34204. return {
  34205. set(node, prop, value) {
  34206. if (node[prop] === value) return true
  34207. node[prop] = value;
  34208. if (prop === 'name' || prop === 'params' || prop === 'selector') {
  34209. node.markDirty();
  34210. }
  34211. return true
  34212. },
  34213. get(node, prop) {
  34214. if (prop === 'proxyOf') {
  34215. return node
  34216. } else if (!node[prop]) {
  34217. return node[prop]
  34218. } else if (
  34219. prop === 'each' ||
  34220. (typeof prop === 'string' && prop.startsWith('walk'))
  34221. ) {
  34222. return (...args) => {
  34223. return node[prop](
  34224. ...args.map(i => {
  34225. if (typeof i === 'function') {
  34226. return (child, index) => i(child.toProxy(), index)
  34227. } else {
  34228. return i
  34229. }
  34230. })
  34231. )
  34232. }
  34233. } else if (prop === 'every' || prop === 'some') {
  34234. return cb => {
  34235. return node[prop]((child, ...other) =>
  34236. cb(child.toProxy(), ...other)
  34237. )
  34238. }
  34239. } else if (prop === 'root') {
  34240. return () => node.root().toProxy()
  34241. } else if (prop === 'nodes') {
  34242. return node.nodes.map(i => i.toProxy())
  34243. } else if (prop === 'first' || prop === 'last') {
  34244. return node[prop].toProxy()
  34245. } else {
  34246. return node[prop]
  34247. }
  34248. }
  34249. }
  34250. }
  34251. getIterator() {
  34252. if (!this.lastEach) this.lastEach = 0;
  34253. if (!this.indexes) this.indexes = {};
  34254. this.lastEach += 1;
  34255. let iterator = this.lastEach;
  34256. this.indexes[iterator] = 0;
  34257. return iterator
  34258. }
  34259. };
  34260. Container$7.registerParse = dependant => {
  34261. parse$4 = dependant;
  34262. };
  34263. Container$7.registerRule = dependant => {
  34264. Rule$4 = dependant;
  34265. };
  34266. Container$7.registerAtRule = dependant => {
  34267. AtRule$4 = dependant;
  34268. };
  34269. Container$7.registerRoot = dependant => {
  34270. Root$6 = dependant;
  34271. };
  34272. var container$1 = Container$7;
  34273. Container$7.default = Container$7;
  34274. /* c8 ignore start */
  34275. Container$7.rebuild = node => {
  34276. if (node.type === 'atrule') {
  34277. Object.setPrototypeOf(node, AtRule$4.prototype);
  34278. } else if (node.type === 'rule') {
  34279. Object.setPrototypeOf(node, Rule$4.prototype);
  34280. } else if (node.type === 'decl') {
  34281. Object.setPrototypeOf(node, Declaration$3.prototype);
  34282. } else if (node.type === 'comment') {
  34283. Object.setPrototypeOf(node, Comment$3.prototype);
  34284. } else if (node.type === 'root') {
  34285. Object.setPrototypeOf(node, Root$6.prototype);
  34286. }
  34287. node[my$1] = true;
  34288. if (node.nodes) {
  34289. node.nodes.forEach(child => {
  34290. Container$7.rebuild(child);
  34291. });
  34292. }
  34293. };
  34294. let Container$6 = container$1;
  34295. let LazyResult$4, Processor$3;
  34296. let Document$3 = class Document extends Container$6 {
  34297. constructor(defaults) {
  34298. // type needs to be passed to super, otherwise child roots won't be normalized correctly
  34299. super({ type: 'document', ...defaults });
  34300. if (!this.nodes) {
  34301. this.nodes = [];
  34302. }
  34303. }
  34304. toResult(opts = {}) {
  34305. let lazy = new LazyResult$4(new Processor$3(), this, opts);
  34306. return lazy.stringify()
  34307. }
  34308. };
  34309. Document$3.registerLazyResult = dependant => {
  34310. LazyResult$4 = dependant;
  34311. };
  34312. Document$3.registerProcessor = dependant => {
  34313. Processor$3 = dependant;
  34314. };
  34315. var document = Document$3;
  34316. Document$3.default = Document$3;
  34317. /* eslint-disable no-console */
  34318. let printed = {};
  34319. var warnOnce$3 = function warnOnce(message) {
  34320. if (printed[message]) return
  34321. printed[message] = true;
  34322. if (typeof console !== 'undefined' && console.warn) {
  34323. console.warn(message);
  34324. }
  34325. };
  34326. let Warning$2 = class Warning {
  34327. constructor(text, opts = {}) {
  34328. this.type = 'warning';
  34329. this.text = text;
  34330. if (opts.node && opts.node.source) {
  34331. let range = opts.node.rangeBy(opts);
  34332. this.line = range.start.line;
  34333. this.column = range.start.column;
  34334. this.endLine = range.end.line;
  34335. this.endColumn = range.end.column;
  34336. }
  34337. for (let opt in opts) this[opt] = opts[opt];
  34338. }
  34339. toString() {
  34340. if (this.node) {
  34341. return this.node.error(this.text, {
  34342. plugin: this.plugin,
  34343. index: this.index,
  34344. word: this.word
  34345. }).message
  34346. }
  34347. if (this.plugin) {
  34348. return this.plugin + ': ' + this.text
  34349. }
  34350. return this.text
  34351. }
  34352. };
  34353. var warning = Warning$2;
  34354. Warning$2.default = Warning$2;
  34355. let Warning$1 = warning;
  34356. let Result$3 = class Result {
  34357. constructor(processor, root, opts) {
  34358. this.processor = processor;
  34359. this.messages = [];
  34360. this.root = root;
  34361. this.opts = opts;
  34362. this.css = undefined;
  34363. this.map = undefined;
  34364. }
  34365. toString() {
  34366. return this.css
  34367. }
  34368. warn(text, opts = {}) {
  34369. if (!opts.plugin) {
  34370. if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
  34371. opts.plugin = this.lastPlugin.postcssPlugin;
  34372. }
  34373. }
  34374. let warning = new Warning$1(text, opts);
  34375. this.messages.push(warning);
  34376. return warning
  34377. }
  34378. warnings() {
  34379. return this.messages.filter(i => i.type === 'warning')
  34380. }
  34381. get content() {
  34382. return this.css
  34383. }
  34384. };
  34385. var result = Result$3;
  34386. Result$3.default = Result$3;
  34387. let Container$5 = container$1;
  34388. let AtRule$3 = class AtRule extends Container$5 {
  34389. constructor(defaults) {
  34390. super(defaults);
  34391. this.type = 'atrule';
  34392. }
  34393. append(...children) {
  34394. if (!this.proxyOf.nodes) this.nodes = [];
  34395. return super.append(...children)
  34396. }
  34397. prepend(...children) {
  34398. if (!this.proxyOf.nodes) this.nodes = [];
  34399. return super.prepend(...children)
  34400. }
  34401. };
  34402. var atRule = AtRule$3;
  34403. AtRule$3.default = AtRule$3;
  34404. Container$5.registerAtRule(AtRule$3);
  34405. let Container$4 = container$1;
  34406. let LazyResult$3, Processor$2;
  34407. let Root$5 = class Root extends Container$4 {
  34408. constructor(defaults) {
  34409. super(defaults);
  34410. this.type = 'root';
  34411. if (!this.nodes) this.nodes = [];
  34412. }
  34413. removeChild(child, ignore) {
  34414. let index = this.index(child);
  34415. if (!ignore && index === 0 && this.nodes.length > 1) {
  34416. this.nodes[1].raws.before = this.nodes[index].raws.before;
  34417. }
  34418. return super.removeChild(child)
  34419. }
  34420. normalize(child, sample, type) {
  34421. let nodes = super.normalize(child);
  34422. if (sample) {
  34423. if (type === 'prepend') {
  34424. if (this.nodes.length > 1) {
  34425. sample.raws.before = this.nodes[1].raws.before;
  34426. } else {
  34427. delete sample.raws.before;
  34428. }
  34429. } else if (this.first !== sample) {
  34430. for (let node of nodes) {
  34431. node.raws.before = sample.raws.before;
  34432. }
  34433. }
  34434. }
  34435. return nodes
  34436. }
  34437. toResult(opts = {}) {
  34438. let lazy = new LazyResult$3(new Processor$2(), this, opts);
  34439. return lazy.stringify()
  34440. }
  34441. };
  34442. Root$5.registerLazyResult = dependant => {
  34443. LazyResult$3 = dependant;
  34444. };
  34445. Root$5.registerProcessor = dependant => {
  34446. Processor$2 = dependant;
  34447. };
  34448. var root$2 = Root$5;
  34449. Root$5.default = Root$5;
  34450. Container$4.registerRoot(Root$5);
  34451. let list$2 = {
  34452. split(string, separators, last) {
  34453. let array = [];
  34454. let current = '';
  34455. let split = false;
  34456. let func = 0;
  34457. let inQuote = false;
  34458. let prevQuote = '';
  34459. let escape = false;
  34460. for (let letter of string) {
  34461. if (escape) {
  34462. escape = false;
  34463. } else if (letter === '\\') {
  34464. escape = true;
  34465. } else if (inQuote) {
  34466. if (letter === prevQuote) {
  34467. inQuote = false;
  34468. }
  34469. } else if (letter === '"' || letter === "'") {
  34470. inQuote = true;
  34471. prevQuote = letter;
  34472. } else if (letter === '(') {
  34473. func += 1;
  34474. } else if (letter === ')') {
  34475. if (func > 0) func -= 1;
  34476. } else if (func === 0) {
  34477. if (separators.includes(letter)) split = true;
  34478. }
  34479. if (split) {
  34480. if (current !== '') array.push(current.trim());
  34481. current = '';
  34482. split = false;
  34483. } else {
  34484. current += letter;
  34485. }
  34486. }
  34487. if (last || current !== '') array.push(current.trim());
  34488. return array
  34489. },
  34490. space(string) {
  34491. let spaces = [' ', '\n', '\t'];
  34492. return list$2.split(string, spaces)
  34493. },
  34494. comma(string) {
  34495. return list$2.split(string, [','], true)
  34496. }
  34497. };
  34498. var list_1 = list$2;
  34499. list$2.default = list$2;
  34500. let Container$3 = container$1;
  34501. let list$1 = list_1;
  34502. let Rule$3 = class Rule extends Container$3 {
  34503. constructor(defaults) {
  34504. super(defaults);
  34505. this.type = 'rule';
  34506. if (!this.nodes) this.nodes = [];
  34507. }
  34508. get selectors() {
  34509. return list$1.comma(this.selector)
  34510. }
  34511. set selectors(values) {
  34512. let match = this.selector ? this.selector.match(/,\s*/) : null;
  34513. let sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
  34514. this.selector = values.join(sep);
  34515. }
  34516. };
  34517. var rule = Rule$3;
  34518. Rule$3.default = Rule$3;
  34519. Container$3.registerRule(Rule$3);
  34520. let Declaration$2 = declaration;
  34521. let tokenizer = tokenize$1;
  34522. let Comment$2 = comment$3;
  34523. let AtRule$2 = atRule;
  34524. let Root$4 = root$2;
  34525. let Rule$2 = rule;
  34526. const SAFE_COMMENT_NEIGHBOR = {
  34527. empty: true,
  34528. space: true
  34529. };
  34530. function findLastWithPosition(tokens) {
  34531. for (let i = tokens.length - 1; i >= 0; i--) {
  34532. let token = tokens[i];
  34533. let pos = token[3] || token[2];
  34534. if (pos) return pos
  34535. }
  34536. }
  34537. let Parser$1 = class Parser {
  34538. constructor(input) {
  34539. this.input = input;
  34540. this.root = new Root$4();
  34541. this.current = this.root;
  34542. this.spaces = '';
  34543. this.semicolon = false;
  34544. this.customProperty = false;
  34545. this.createTokenizer();
  34546. this.root.source = { input, start: { offset: 0, line: 1, column: 1 } };
  34547. }
  34548. createTokenizer() {
  34549. this.tokenizer = tokenizer(this.input);
  34550. }
  34551. parse() {
  34552. let token;
  34553. while (!this.tokenizer.endOfFile()) {
  34554. token = this.tokenizer.nextToken();
  34555. switch (token[0]) {
  34556. case 'space':
  34557. this.spaces += token[1];
  34558. break
  34559. case ';':
  34560. this.freeSemicolon(token);
  34561. break
  34562. case '}':
  34563. this.end(token);
  34564. break
  34565. case 'comment':
  34566. this.comment(token);
  34567. break
  34568. case 'at-word':
  34569. this.atrule(token);
  34570. break
  34571. case '{':
  34572. this.emptyRule(token);
  34573. break
  34574. default:
  34575. this.other(token);
  34576. break
  34577. }
  34578. }
  34579. this.endFile();
  34580. }
  34581. comment(token) {
  34582. let node = new Comment$2();
  34583. this.init(node, token[2]);
  34584. node.source.end = this.getPosition(token[3] || token[2]);
  34585. let text = token[1].slice(2, -2);
  34586. if (/^\s*$/.test(text)) {
  34587. node.text = '';
  34588. node.raws.left = text;
  34589. node.raws.right = '';
  34590. } else {
  34591. let match = text.match(/^(\s*)([^]*\S)(\s*)$/);
  34592. node.text = match[2];
  34593. node.raws.left = match[1];
  34594. node.raws.right = match[3];
  34595. }
  34596. }
  34597. emptyRule(token) {
  34598. let node = new Rule$2();
  34599. this.init(node, token[2]);
  34600. node.selector = '';
  34601. node.raws.between = '';
  34602. this.current = node;
  34603. }
  34604. other(start) {
  34605. let end = false;
  34606. let type = null;
  34607. let colon = false;
  34608. let bracket = null;
  34609. let brackets = [];
  34610. let customProperty = start[1].startsWith('--');
  34611. let tokens = [];
  34612. let token = start;
  34613. while (token) {
  34614. type = token[0];
  34615. tokens.push(token);
  34616. if (type === '(' || type === '[') {
  34617. if (!bracket) bracket = token;
  34618. brackets.push(type === '(' ? ')' : ']');
  34619. } else if (customProperty && colon && type === '{') {
  34620. if (!bracket) bracket = token;
  34621. brackets.push('}');
  34622. } else if (brackets.length === 0) {
  34623. if (type === ';') {
  34624. if (colon) {
  34625. this.decl(tokens, customProperty);
  34626. return
  34627. } else {
  34628. break
  34629. }
  34630. } else if (type === '{') {
  34631. this.rule(tokens);
  34632. return
  34633. } else if (type === '}') {
  34634. this.tokenizer.back(tokens.pop());
  34635. end = true;
  34636. break
  34637. } else if (type === ':') {
  34638. colon = true;
  34639. }
  34640. } else if (type === brackets[brackets.length - 1]) {
  34641. brackets.pop();
  34642. if (brackets.length === 0) bracket = null;
  34643. }
  34644. token = this.tokenizer.nextToken();
  34645. }
  34646. if (this.tokenizer.endOfFile()) end = true;
  34647. if (brackets.length > 0) this.unclosedBracket(bracket);
  34648. if (end && colon) {
  34649. if (!customProperty) {
  34650. while (tokens.length) {
  34651. token = tokens[tokens.length - 1][0];
  34652. if (token !== 'space' && token !== 'comment') break
  34653. this.tokenizer.back(tokens.pop());
  34654. }
  34655. }
  34656. this.decl(tokens, customProperty);
  34657. } else {
  34658. this.unknownWord(tokens);
  34659. }
  34660. }
  34661. rule(tokens) {
  34662. tokens.pop();
  34663. let node = new Rule$2();
  34664. this.init(node, tokens[0][2]);
  34665. node.raws.between = this.spacesAndCommentsFromEnd(tokens);
  34666. this.raw(node, 'selector', tokens);
  34667. this.current = node;
  34668. }
  34669. decl(tokens, customProperty) {
  34670. let node = new Declaration$2();
  34671. this.init(node, tokens[0][2]);
  34672. let last = tokens[tokens.length - 1];
  34673. if (last[0] === ';') {
  34674. this.semicolon = true;
  34675. tokens.pop();
  34676. }
  34677. node.source.end = this.getPosition(
  34678. last[3] || last[2] || findLastWithPosition(tokens)
  34679. );
  34680. while (tokens[0][0] !== 'word') {
  34681. if (tokens.length === 1) this.unknownWord(tokens);
  34682. node.raws.before += tokens.shift()[1];
  34683. }
  34684. node.source.start = this.getPosition(tokens[0][2]);
  34685. node.prop = '';
  34686. while (tokens.length) {
  34687. let type = tokens[0][0];
  34688. if (type === ':' || type === 'space' || type === 'comment') {
  34689. break
  34690. }
  34691. node.prop += tokens.shift()[1];
  34692. }
  34693. node.raws.between = '';
  34694. let token;
  34695. while (tokens.length) {
  34696. token = tokens.shift();
  34697. if (token[0] === ':') {
  34698. node.raws.between += token[1];
  34699. break
  34700. } else {
  34701. if (token[0] === 'word' && /\w/.test(token[1])) {
  34702. this.unknownWord([token]);
  34703. }
  34704. node.raws.between += token[1];
  34705. }
  34706. }
  34707. if (node.prop[0] === '_' || node.prop[0] === '*') {
  34708. node.raws.before += node.prop[0];
  34709. node.prop = node.prop.slice(1);
  34710. }
  34711. let firstSpaces = [];
  34712. let next;
  34713. while (tokens.length) {
  34714. next = tokens[0][0];
  34715. if (next !== 'space' && next !== 'comment') break
  34716. firstSpaces.push(tokens.shift());
  34717. }
  34718. this.precheckMissedSemicolon(tokens);
  34719. for (let i = tokens.length - 1; i >= 0; i--) {
  34720. token = tokens[i];
  34721. if (token[1].toLowerCase() === '!important') {
  34722. node.important = true;
  34723. let string = this.stringFrom(tokens, i);
  34724. string = this.spacesFromEnd(tokens) + string;
  34725. if (string !== ' !important') node.raws.important = string;
  34726. break
  34727. } else if (token[1].toLowerCase() === 'important') {
  34728. let cache = tokens.slice(0);
  34729. let str = '';
  34730. for (let j = i; j > 0; j--) {
  34731. let type = cache[j][0];
  34732. if (str.trim().indexOf('!') === 0 && type !== 'space') {
  34733. break
  34734. }
  34735. str = cache.pop()[1] + str;
  34736. }
  34737. if (str.trim().indexOf('!') === 0) {
  34738. node.important = true;
  34739. node.raws.important = str;
  34740. tokens = cache;
  34741. }
  34742. }
  34743. if (token[0] !== 'space' && token[0] !== 'comment') {
  34744. break
  34745. }
  34746. }
  34747. let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment');
  34748. if (hasWord) {
  34749. node.raws.between += firstSpaces.map(i => i[1]).join('');
  34750. firstSpaces = [];
  34751. }
  34752. this.raw(node, 'value', firstSpaces.concat(tokens), customProperty);
  34753. if (node.value.includes(':') && !customProperty) {
  34754. this.checkMissedSemicolon(tokens);
  34755. }
  34756. }
  34757. atrule(token) {
  34758. let node = new AtRule$2();
  34759. node.name = token[1].slice(1);
  34760. if (node.name === '') {
  34761. this.unnamedAtrule(node, token);
  34762. }
  34763. this.init(node, token[2]);
  34764. let type;
  34765. let prev;
  34766. let shift;
  34767. let last = false;
  34768. let open = false;
  34769. let params = [];
  34770. let brackets = [];
  34771. while (!this.tokenizer.endOfFile()) {
  34772. token = this.tokenizer.nextToken();
  34773. type = token[0];
  34774. if (type === '(' || type === '[') {
  34775. brackets.push(type === '(' ? ')' : ']');
  34776. } else if (type === '{' && brackets.length > 0) {
  34777. brackets.push('}');
  34778. } else if (type === brackets[brackets.length - 1]) {
  34779. brackets.pop();
  34780. }
  34781. if (brackets.length === 0) {
  34782. if (type === ';') {
  34783. node.source.end = this.getPosition(token[2]);
  34784. this.semicolon = true;
  34785. break
  34786. } else if (type === '{') {
  34787. open = true;
  34788. break
  34789. } else if (type === '}') {
  34790. if (params.length > 0) {
  34791. shift = params.length - 1;
  34792. prev = params[shift];
  34793. while (prev && prev[0] === 'space') {
  34794. prev = params[--shift];
  34795. }
  34796. if (prev) {
  34797. node.source.end = this.getPosition(prev[3] || prev[2]);
  34798. }
  34799. }
  34800. this.end(token);
  34801. break
  34802. } else {
  34803. params.push(token);
  34804. }
  34805. } else {
  34806. params.push(token);
  34807. }
  34808. if (this.tokenizer.endOfFile()) {
  34809. last = true;
  34810. break
  34811. }
  34812. }
  34813. node.raws.between = this.spacesAndCommentsFromEnd(params);
  34814. if (params.length) {
  34815. node.raws.afterName = this.spacesAndCommentsFromStart(params);
  34816. this.raw(node, 'params', params);
  34817. if (last) {
  34818. token = params[params.length - 1];
  34819. node.source.end = this.getPosition(token[3] || token[2]);
  34820. this.spaces = node.raws.between;
  34821. node.raws.between = '';
  34822. }
  34823. } else {
  34824. node.raws.afterName = '';
  34825. node.params = '';
  34826. }
  34827. if (open) {
  34828. node.nodes = [];
  34829. this.current = node;
  34830. }
  34831. }
  34832. end(token) {
  34833. if (this.current.nodes && this.current.nodes.length) {
  34834. this.current.raws.semicolon = this.semicolon;
  34835. }
  34836. this.semicolon = false;
  34837. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  34838. this.spaces = '';
  34839. if (this.current.parent) {
  34840. this.current.source.end = this.getPosition(token[2]);
  34841. this.current = this.current.parent;
  34842. } else {
  34843. this.unexpectedClose(token);
  34844. }
  34845. }
  34846. endFile() {
  34847. if (this.current.parent) this.unclosedBlock();
  34848. if (this.current.nodes && this.current.nodes.length) {
  34849. this.current.raws.semicolon = this.semicolon;
  34850. }
  34851. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  34852. }
  34853. freeSemicolon(token) {
  34854. this.spaces += token[1];
  34855. if (this.current.nodes) {
  34856. let prev = this.current.nodes[this.current.nodes.length - 1];
  34857. if (prev && prev.type === 'rule' && !prev.raws.ownSemicolon) {
  34858. prev.raws.ownSemicolon = this.spaces;
  34859. this.spaces = '';
  34860. }
  34861. }
  34862. }
  34863. // Helpers
  34864. getPosition(offset) {
  34865. let pos = this.input.fromOffset(offset);
  34866. return {
  34867. offset,
  34868. line: pos.line,
  34869. column: pos.col
  34870. }
  34871. }
  34872. init(node, offset) {
  34873. this.current.push(node);
  34874. node.source = {
  34875. start: this.getPosition(offset),
  34876. input: this.input
  34877. };
  34878. node.raws.before = this.spaces;
  34879. this.spaces = '';
  34880. if (node.type !== 'comment') this.semicolon = false;
  34881. }
  34882. raw(node, prop, tokens, customProperty) {
  34883. let token, type;
  34884. let length = tokens.length;
  34885. let value = '';
  34886. let clean = true;
  34887. let next, prev;
  34888. for (let i = 0; i < length; i += 1) {
  34889. token = tokens[i];
  34890. type = token[0];
  34891. if (type === 'space' && i === length - 1 && !customProperty) {
  34892. clean = false;
  34893. } else if (type === 'comment') {
  34894. prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty';
  34895. next = tokens[i + 1] ? tokens[i + 1][0] : 'empty';
  34896. if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) {
  34897. if (value.slice(-1) === ',') {
  34898. clean = false;
  34899. } else {
  34900. value += token[1];
  34901. }
  34902. } else {
  34903. clean = false;
  34904. }
  34905. } else {
  34906. value += token[1];
  34907. }
  34908. }
  34909. if (!clean) {
  34910. let raw = tokens.reduce((all, i) => all + i[1], '');
  34911. node.raws[prop] = { value, raw };
  34912. }
  34913. node[prop] = value;
  34914. }
  34915. spacesAndCommentsFromEnd(tokens) {
  34916. let lastTokenType;
  34917. let spaces = '';
  34918. while (tokens.length) {
  34919. lastTokenType = tokens[tokens.length - 1][0];
  34920. if (lastTokenType !== 'space' && lastTokenType !== 'comment') break
  34921. spaces = tokens.pop()[1] + spaces;
  34922. }
  34923. return spaces
  34924. }
  34925. spacesAndCommentsFromStart(tokens) {
  34926. let next;
  34927. let spaces = '';
  34928. while (tokens.length) {
  34929. next = tokens[0][0];
  34930. if (next !== 'space' && next !== 'comment') break
  34931. spaces += tokens.shift()[1];
  34932. }
  34933. return spaces
  34934. }
  34935. spacesFromEnd(tokens) {
  34936. let lastTokenType;
  34937. let spaces = '';
  34938. while (tokens.length) {
  34939. lastTokenType = tokens[tokens.length - 1][0];
  34940. if (lastTokenType !== 'space') break
  34941. spaces = tokens.pop()[1] + spaces;
  34942. }
  34943. return spaces
  34944. }
  34945. stringFrom(tokens, from) {
  34946. let result = '';
  34947. for (let i = from; i < tokens.length; i++) {
  34948. result += tokens[i][1];
  34949. }
  34950. tokens.splice(from, tokens.length - from);
  34951. return result
  34952. }
  34953. colon(tokens) {
  34954. let brackets = 0;
  34955. let token, type, prev;
  34956. for (let [i, element] of tokens.entries()) {
  34957. token = element;
  34958. type = token[0];
  34959. if (type === '(') {
  34960. brackets += 1;
  34961. }
  34962. if (type === ')') {
  34963. brackets -= 1;
  34964. }
  34965. if (brackets === 0 && type === ':') {
  34966. if (!prev) {
  34967. this.doubleColon(token);
  34968. } else if (prev[0] === 'word' && prev[1] === 'progid') {
  34969. continue
  34970. } else {
  34971. return i
  34972. }
  34973. }
  34974. prev = token;
  34975. }
  34976. return false
  34977. }
  34978. // Errors
  34979. unclosedBracket(bracket) {
  34980. throw this.input.error(
  34981. 'Unclosed bracket',
  34982. { offset: bracket[2] },
  34983. { offset: bracket[2] + 1 }
  34984. )
  34985. }
  34986. unknownWord(tokens) {
  34987. throw this.input.error(
  34988. 'Unknown word',
  34989. { offset: tokens[0][2] },
  34990. { offset: tokens[0][2] + tokens[0][1].length }
  34991. )
  34992. }
  34993. unexpectedClose(token) {
  34994. throw this.input.error(
  34995. 'Unexpected }',
  34996. { offset: token[2] },
  34997. { offset: token[2] + 1 }
  34998. )
  34999. }
  35000. unclosedBlock() {
  35001. let pos = this.current.source.start;
  35002. throw this.input.error('Unclosed block', pos.line, pos.column)
  35003. }
  35004. doubleColon(token) {
  35005. throw this.input.error(
  35006. 'Double colon',
  35007. { offset: token[2] },
  35008. { offset: token[2] + token[1].length }
  35009. )
  35010. }
  35011. unnamedAtrule(node, token) {
  35012. throw this.input.error(
  35013. 'At-rule without name',
  35014. { offset: token[2] },
  35015. { offset: token[2] + token[1].length }
  35016. )
  35017. }
  35018. precheckMissedSemicolon(/* tokens */) {
  35019. // Hook for Safe Parser
  35020. }
  35021. checkMissedSemicolon(tokens) {
  35022. let colon = this.colon(tokens);
  35023. if (colon === false) return
  35024. let founded = 0;
  35025. let token;
  35026. for (let j = colon - 1; j >= 0; j--) {
  35027. token = tokens[j];
  35028. if (token[0] !== 'space') {
  35029. founded += 1;
  35030. if (founded === 2) break
  35031. }
  35032. }
  35033. // If the token is a word, e.g. `!important`, `red` or any other valid property's value.
  35034. // Then we need to return the colon after that word token. [3] is the "end" colon of that word.
  35035. // And because we need it after that one we do +1 to get the next one.
  35036. throw this.input.error(
  35037. 'Missed semicolon',
  35038. token[0] === 'word' ? token[3] + 1 : token[2]
  35039. )
  35040. }
  35041. };
  35042. var parser$1 = Parser$1;
  35043. let Container$2 = container$1;
  35044. let Parser = parser$1;
  35045. let Input$2 = input;
  35046. function parse$3(css, opts) {
  35047. let input = new Input$2(css, opts);
  35048. let parser = new Parser(input);
  35049. try {
  35050. parser.parse();
  35051. } catch (e) {
  35052. if (browser$1.env.NODE_ENV !== 'production') {
  35053. if (e.name === 'CssSyntaxError' && opts && opts.from) {
  35054. if (/\.scss$/i.test(opts.from)) {
  35055. e.message +=
  35056. '\nYou tried to parse SCSS with ' +
  35057. 'the standard CSS parser; ' +
  35058. 'try again with the postcss-scss parser';
  35059. } else if (/\.sass/i.test(opts.from)) {
  35060. e.message +=
  35061. '\nYou tried to parse Sass with ' +
  35062. 'the standard CSS parser; ' +
  35063. 'try again with the postcss-sass parser';
  35064. } else if (/\.less$/i.test(opts.from)) {
  35065. e.message +=
  35066. '\nYou tried to parse Less with ' +
  35067. 'the standard CSS parser; ' +
  35068. 'try again with the postcss-less parser';
  35069. }
  35070. }
  35071. }
  35072. throw e
  35073. }
  35074. return parser.root
  35075. }
  35076. var parse_1 = parse$3;
  35077. parse$3.default = parse$3;
  35078. Container$2.registerParse(parse$3);
  35079. let { isClean, my } = symbols;
  35080. let MapGenerator$1 = mapGenerator;
  35081. let stringify$2 = stringify_1;
  35082. let Container$1 = container$1;
  35083. let Document$2 = document;
  35084. let warnOnce$2 = warnOnce$3;
  35085. let Result$2 = result;
  35086. let parse$2 = parse_1;
  35087. let Root$3 = root$2;
  35088. const TYPE_TO_CLASS_NAME = {
  35089. document: 'Document',
  35090. root: 'Root',
  35091. atrule: 'AtRule',
  35092. rule: 'Rule',
  35093. decl: 'Declaration',
  35094. comment: 'Comment'
  35095. };
  35096. const PLUGIN_PROPS = {
  35097. postcssPlugin: true,
  35098. prepare: true,
  35099. Once: true,
  35100. Document: true,
  35101. Root: true,
  35102. Declaration: true,
  35103. Rule: true,
  35104. AtRule: true,
  35105. Comment: true,
  35106. DeclarationExit: true,
  35107. RuleExit: true,
  35108. AtRuleExit: true,
  35109. CommentExit: true,
  35110. RootExit: true,
  35111. DocumentExit: true,
  35112. OnceExit: true
  35113. };
  35114. const NOT_VISITORS = {
  35115. postcssPlugin: true,
  35116. prepare: true,
  35117. Once: true
  35118. };
  35119. const CHILDREN = 0;
  35120. function isPromise(obj) {
  35121. return typeof obj === 'object' && typeof obj.then === 'function'
  35122. }
  35123. function getEvents(node) {
  35124. let key = false;
  35125. let type = TYPE_TO_CLASS_NAME[node.type];
  35126. if (node.type === 'decl') {
  35127. key = node.prop.toLowerCase();
  35128. } else if (node.type === 'atrule') {
  35129. key = node.name.toLowerCase();
  35130. }
  35131. if (key && node.append) {
  35132. return [
  35133. type,
  35134. type + '-' + key,
  35135. CHILDREN,
  35136. type + 'Exit',
  35137. type + 'Exit-' + key
  35138. ]
  35139. } else if (key) {
  35140. return [type, type + '-' + key, type + 'Exit', type + 'Exit-' + key]
  35141. } else if (node.append) {
  35142. return [type, CHILDREN, type + 'Exit']
  35143. } else {
  35144. return [type, type + 'Exit']
  35145. }
  35146. }
  35147. function toStack(node) {
  35148. let events;
  35149. if (node.type === 'document') {
  35150. events = ['Document', CHILDREN, 'DocumentExit'];
  35151. } else if (node.type === 'root') {
  35152. events = ['Root', CHILDREN, 'RootExit'];
  35153. } else {
  35154. events = getEvents(node);
  35155. }
  35156. return {
  35157. node,
  35158. events,
  35159. eventIndex: 0,
  35160. visitors: [],
  35161. visitorIndex: 0,
  35162. iterator: 0
  35163. }
  35164. }
  35165. function cleanMarks(node) {
  35166. node[isClean] = false;
  35167. if (node.nodes) node.nodes.forEach(i => cleanMarks(i));
  35168. return node
  35169. }
  35170. let postcss$2 = {};
  35171. let LazyResult$2 = class LazyResult {
  35172. constructor(processor, css, opts) {
  35173. this.stringified = false;
  35174. this.processed = false;
  35175. let root;
  35176. if (
  35177. typeof css === 'object' &&
  35178. css !== null &&
  35179. (css.type === 'root' || css.type === 'document')
  35180. ) {
  35181. root = cleanMarks(css);
  35182. } else if (css instanceof LazyResult || css instanceof Result$2) {
  35183. root = cleanMarks(css.root);
  35184. if (css.map) {
  35185. if (typeof opts.map === 'undefined') opts.map = {};
  35186. if (!opts.map.inline) opts.map.inline = false;
  35187. opts.map.prev = css.map;
  35188. }
  35189. } else {
  35190. let parser = parse$2;
  35191. if (opts.syntax) parser = opts.syntax.parse;
  35192. if (opts.parser) parser = opts.parser;
  35193. if (parser.parse) parser = parser.parse;
  35194. try {
  35195. root = parser(css, opts);
  35196. } catch (error) {
  35197. this.processed = true;
  35198. this.error = error;
  35199. }
  35200. if (root && !root[my]) {
  35201. /* c8 ignore next 2 */
  35202. Container$1.rebuild(root);
  35203. }
  35204. }
  35205. this.result = new Result$2(processor, root, opts);
  35206. this.helpers = { ...postcss$2, result: this.result, postcss: postcss$2 };
  35207. this.plugins = this.processor.plugins.map(plugin => {
  35208. if (typeof plugin === 'object' && plugin.prepare) {
  35209. return { ...plugin, ...plugin.prepare(this.result) }
  35210. } else {
  35211. return plugin
  35212. }
  35213. });
  35214. }
  35215. get [Symbol.toStringTag]() {
  35216. return 'LazyResult'
  35217. }
  35218. get processor() {
  35219. return this.result.processor
  35220. }
  35221. get opts() {
  35222. return this.result.opts
  35223. }
  35224. get css() {
  35225. return this.stringify().css
  35226. }
  35227. get content() {
  35228. return this.stringify().content
  35229. }
  35230. get map() {
  35231. return this.stringify().map
  35232. }
  35233. get root() {
  35234. return this.sync().root
  35235. }
  35236. get messages() {
  35237. return this.sync().messages
  35238. }
  35239. warnings() {
  35240. return this.sync().warnings()
  35241. }
  35242. toString() {
  35243. return this.css
  35244. }
  35245. then(onFulfilled, onRejected) {
  35246. if (browser$1.env.NODE_ENV !== 'production') {
  35247. if (!('from' in this.opts)) {
  35248. warnOnce$2(
  35249. 'Without `from` option PostCSS could generate wrong source map ' +
  35250. 'and will not find Browserslist config. Set it to CSS file path ' +
  35251. 'or to `undefined` to prevent this warning.'
  35252. );
  35253. }
  35254. }
  35255. return this.async().then(onFulfilled, onRejected)
  35256. }
  35257. catch(onRejected) {
  35258. return this.async().catch(onRejected)
  35259. }
  35260. finally(onFinally) {
  35261. return this.async().then(onFinally, onFinally)
  35262. }
  35263. async() {
  35264. if (this.error) return Promise.reject(this.error)
  35265. if (this.processed) return Promise.resolve(this.result)
  35266. if (!this.processing) {
  35267. this.processing = this.runAsync();
  35268. }
  35269. return this.processing
  35270. }
  35271. sync() {
  35272. if (this.error) throw this.error
  35273. if (this.processed) return this.result
  35274. this.processed = true;
  35275. if (this.processing) {
  35276. throw this.getAsyncError()
  35277. }
  35278. for (let plugin of this.plugins) {
  35279. let promise = this.runOnRoot(plugin);
  35280. if (isPromise(promise)) {
  35281. throw this.getAsyncError()
  35282. }
  35283. }
  35284. this.prepareVisitors();
  35285. if (this.hasListener) {
  35286. let root = this.result.root;
  35287. while (!root[isClean]) {
  35288. root[isClean] = true;
  35289. this.walkSync(root);
  35290. }
  35291. if (this.listeners.OnceExit) {
  35292. if (root.type === 'document') {
  35293. for (let subRoot of root.nodes) {
  35294. this.visitSync(this.listeners.OnceExit, subRoot);
  35295. }
  35296. } else {
  35297. this.visitSync(this.listeners.OnceExit, root);
  35298. }
  35299. }
  35300. }
  35301. return this.result
  35302. }
  35303. stringify() {
  35304. if (this.error) throw this.error
  35305. if (this.stringified) return this.result
  35306. this.stringified = true;
  35307. this.sync();
  35308. let opts = this.result.opts;
  35309. let str = stringify$2;
  35310. if (opts.syntax) str = opts.syntax.stringify;
  35311. if (opts.stringifier) str = opts.stringifier;
  35312. if (str.stringify) str = str.stringify;
  35313. let map = new MapGenerator$1(str, this.result.root, this.result.opts);
  35314. let data = map.generate();
  35315. this.result.css = data[0];
  35316. this.result.map = data[1];
  35317. return this.result
  35318. }
  35319. walkSync(node) {
  35320. node[isClean] = true;
  35321. let events = getEvents(node);
  35322. for (let event of events) {
  35323. if (event === CHILDREN) {
  35324. if (node.nodes) {
  35325. node.each(child => {
  35326. if (!child[isClean]) this.walkSync(child);
  35327. });
  35328. }
  35329. } else {
  35330. let visitors = this.listeners[event];
  35331. if (visitors) {
  35332. if (this.visitSync(visitors, node.toProxy())) return
  35333. }
  35334. }
  35335. }
  35336. }
  35337. visitSync(visitors, node) {
  35338. for (let [plugin, visitor] of visitors) {
  35339. this.result.lastPlugin = plugin;
  35340. let promise;
  35341. try {
  35342. promise = visitor(node, this.helpers);
  35343. } catch (e) {
  35344. throw this.handleError(e, node.proxyOf)
  35345. }
  35346. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  35347. return true
  35348. }
  35349. if (isPromise(promise)) {
  35350. throw this.getAsyncError()
  35351. }
  35352. }
  35353. }
  35354. runOnRoot(plugin) {
  35355. this.result.lastPlugin = plugin;
  35356. try {
  35357. if (typeof plugin === 'object' && plugin.Once) {
  35358. if (this.result.root.type === 'document') {
  35359. let roots = this.result.root.nodes.map(root =>
  35360. plugin.Once(root, this.helpers)
  35361. );
  35362. if (isPromise(roots[0])) {
  35363. return Promise.all(roots)
  35364. }
  35365. return roots
  35366. }
  35367. return plugin.Once(this.result.root, this.helpers)
  35368. } else if (typeof plugin === 'function') {
  35369. return plugin(this.result.root, this.result)
  35370. }
  35371. } catch (error) {
  35372. throw this.handleError(error)
  35373. }
  35374. }
  35375. getAsyncError() {
  35376. throw new Error('Use process(css).then(cb) to work with async plugins')
  35377. }
  35378. handleError(error, node) {
  35379. let plugin = this.result.lastPlugin;
  35380. try {
  35381. if (node) node.addToError(error);
  35382. this.error = error;
  35383. if (error.name === 'CssSyntaxError' && !error.plugin) {
  35384. error.plugin = plugin.postcssPlugin;
  35385. error.setMessage();
  35386. } else if (plugin.postcssVersion) {
  35387. if (browser$1.env.NODE_ENV !== 'production') {
  35388. let pluginName = plugin.postcssPlugin;
  35389. let pluginVer = plugin.postcssVersion;
  35390. let runtimeVer = this.result.processor.version;
  35391. let a = pluginVer.split('.');
  35392. let b = runtimeVer.split('.');
  35393. if (a[0] !== b[0] || parseInt(a[1]) > parseInt(b[1])) {
  35394. // eslint-disable-next-line no-console
  35395. console.error(
  35396. 'Unknown error from PostCSS plugin. Your current PostCSS ' +
  35397. 'version is ' +
  35398. runtimeVer +
  35399. ', but ' +
  35400. pluginName +
  35401. ' uses ' +
  35402. pluginVer +
  35403. '. Perhaps this is the source of the error below.'
  35404. );
  35405. }
  35406. }
  35407. }
  35408. } catch (err) {
  35409. /* c8 ignore next 3 */
  35410. // eslint-disable-next-line no-console
  35411. if (console && console.error) console.error(err);
  35412. }
  35413. return error
  35414. }
  35415. async runAsync() {
  35416. this.plugin = 0;
  35417. for (let i = 0; i < this.plugins.length; i++) {
  35418. let plugin = this.plugins[i];
  35419. let promise = this.runOnRoot(plugin);
  35420. if (isPromise(promise)) {
  35421. try {
  35422. await promise;
  35423. } catch (error) {
  35424. throw this.handleError(error)
  35425. }
  35426. }
  35427. }
  35428. this.prepareVisitors();
  35429. if (this.hasListener) {
  35430. let root = this.result.root;
  35431. while (!root[isClean]) {
  35432. root[isClean] = true;
  35433. let stack = [toStack(root)];
  35434. while (stack.length > 0) {
  35435. let promise = this.visitTick(stack);
  35436. if (isPromise(promise)) {
  35437. try {
  35438. await promise;
  35439. } catch (e) {
  35440. let node = stack[stack.length - 1].node;
  35441. throw this.handleError(e, node)
  35442. }
  35443. }
  35444. }
  35445. }
  35446. if (this.listeners.OnceExit) {
  35447. for (let [plugin, visitor] of this.listeners.OnceExit) {
  35448. this.result.lastPlugin = plugin;
  35449. try {
  35450. if (root.type === 'document') {
  35451. let roots = root.nodes.map(subRoot =>
  35452. visitor(subRoot, this.helpers)
  35453. );
  35454. await Promise.all(roots);
  35455. } else {
  35456. await visitor(root, this.helpers);
  35457. }
  35458. } catch (e) {
  35459. throw this.handleError(e)
  35460. }
  35461. }
  35462. }
  35463. }
  35464. this.processed = true;
  35465. return this.stringify()
  35466. }
  35467. prepareVisitors() {
  35468. this.listeners = {};
  35469. let add = (plugin, type, cb) => {
  35470. if (!this.listeners[type]) this.listeners[type] = [];
  35471. this.listeners[type].push([plugin, cb]);
  35472. };
  35473. for (let plugin of this.plugins) {
  35474. if (typeof plugin === 'object') {
  35475. for (let event in plugin) {
  35476. if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
  35477. throw new Error(
  35478. `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
  35479. `Try to update PostCSS (${this.processor.version} now).`
  35480. )
  35481. }
  35482. if (!NOT_VISITORS[event]) {
  35483. if (typeof plugin[event] === 'object') {
  35484. for (let filter in plugin[event]) {
  35485. if (filter === '*') {
  35486. add(plugin, event, plugin[event][filter]);
  35487. } else {
  35488. add(
  35489. plugin,
  35490. event + '-' + filter.toLowerCase(),
  35491. plugin[event][filter]
  35492. );
  35493. }
  35494. }
  35495. } else if (typeof plugin[event] === 'function') {
  35496. add(plugin, event, plugin[event]);
  35497. }
  35498. }
  35499. }
  35500. }
  35501. }
  35502. this.hasListener = Object.keys(this.listeners).length > 0;
  35503. }
  35504. visitTick(stack) {
  35505. let visit = stack[stack.length - 1];
  35506. let { node, visitors } = visit;
  35507. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  35508. stack.pop();
  35509. return
  35510. }
  35511. if (visitors.length > 0 && visit.visitorIndex < visitors.length) {
  35512. let [plugin, visitor] = visitors[visit.visitorIndex];
  35513. visit.visitorIndex += 1;
  35514. if (visit.visitorIndex === visitors.length) {
  35515. visit.visitors = [];
  35516. visit.visitorIndex = 0;
  35517. }
  35518. this.result.lastPlugin = plugin;
  35519. try {
  35520. return visitor(node.toProxy(), this.helpers)
  35521. } catch (e) {
  35522. throw this.handleError(e, node)
  35523. }
  35524. }
  35525. if (visit.iterator !== 0) {
  35526. let iterator = visit.iterator;
  35527. let child;
  35528. while ((child = node.nodes[node.indexes[iterator]])) {
  35529. node.indexes[iterator] += 1;
  35530. if (!child[isClean]) {
  35531. child[isClean] = true;
  35532. stack.push(toStack(child));
  35533. return
  35534. }
  35535. }
  35536. visit.iterator = 0;
  35537. delete node.indexes[iterator];
  35538. }
  35539. let events = visit.events;
  35540. while (visit.eventIndex < events.length) {
  35541. let event = events[visit.eventIndex];
  35542. visit.eventIndex += 1;
  35543. if (event === CHILDREN) {
  35544. if (node.nodes && node.nodes.length) {
  35545. node[isClean] = true;
  35546. visit.iterator = node.getIterator();
  35547. }
  35548. return
  35549. } else if (this.listeners[event]) {
  35550. visit.visitors = this.listeners[event];
  35551. return
  35552. }
  35553. }
  35554. stack.pop();
  35555. }
  35556. };
  35557. LazyResult$2.registerPostcss = dependant => {
  35558. postcss$2 = dependant;
  35559. };
  35560. var lazyResult = LazyResult$2;
  35561. LazyResult$2.default = LazyResult$2;
  35562. Root$3.registerLazyResult(LazyResult$2);
  35563. Document$2.registerLazyResult(LazyResult$2);
  35564. let MapGenerator = mapGenerator;
  35565. let stringify$1 = stringify_1;
  35566. let warnOnce$1 = warnOnce$3;
  35567. let parse$1 = parse_1;
  35568. const Result$1 = result;
  35569. let NoWorkResult$1 = class NoWorkResult {
  35570. constructor(processor, css, opts) {
  35571. css = css.toString();
  35572. this.stringified = false;
  35573. this._processor = processor;
  35574. this._css = css;
  35575. this._opts = opts;
  35576. this._map = undefined;
  35577. let root;
  35578. let str = stringify$1;
  35579. this.result = new Result$1(this._processor, root, this._opts);
  35580. this.result.css = css;
  35581. let self = this;
  35582. Object.defineProperty(this.result, 'root', {
  35583. get() {
  35584. return self.root
  35585. }
  35586. });
  35587. let map = new MapGenerator(str, root, this._opts, css);
  35588. if (map.isMap()) {
  35589. let [generatedCSS, generatedMap] = map.generate();
  35590. if (generatedCSS) {
  35591. this.result.css = generatedCSS;
  35592. }
  35593. if (generatedMap) {
  35594. this.result.map = generatedMap;
  35595. }
  35596. }
  35597. }
  35598. get [Symbol.toStringTag]() {
  35599. return 'NoWorkResult'
  35600. }
  35601. get processor() {
  35602. return this.result.processor
  35603. }
  35604. get opts() {
  35605. return this.result.opts
  35606. }
  35607. get css() {
  35608. return this.result.css
  35609. }
  35610. get content() {
  35611. return this.result.css
  35612. }
  35613. get map() {
  35614. return this.result.map
  35615. }
  35616. get root() {
  35617. if (this._root) {
  35618. return this._root
  35619. }
  35620. let root;
  35621. let parser = parse$1;
  35622. try {
  35623. root = parser(this._css, this._opts);
  35624. } catch (error) {
  35625. this.error = error;
  35626. }
  35627. if (this.error) {
  35628. throw this.error
  35629. } else {
  35630. this._root = root;
  35631. return root
  35632. }
  35633. }
  35634. get messages() {
  35635. return []
  35636. }
  35637. warnings() {
  35638. return []
  35639. }
  35640. toString() {
  35641. return this._css
  35642. }
  35643. then(onFulfilled, onRejected) {
  35644. if (browser$1.env.NODE_ENV !== 'production') {
  35645. if (!('from' in this._opts)) {
  35646. warnOnce$1(
  35647. 'Without `from` option PostCSS could generate wrong source map ' +
  35648. 'and will not find Browserslist config. Set it to CSS file path ' +
  35649. 'or to `undefined` to prevent this warning.'
  35650. );
  35651. }
  35652. }
  35653. return this.async().then(onFulfilled, onRejected)
  35654. }
  35655. catch(onRejected) {
  35656. return this.async().catch(onRejected)
  35657. }
  35658. finally(onFinally) {
  35659. return this.async().then(onFinally, onFinally)
  35660. }
  35661. async() {
  35662. if (this.error) return Promise.reject(this.error)
  35663. return Promise.resolve(this.result)
  35664. }
  35665. sync() {
  35666. if (this.error) throw this.error
  35667. return this.result
  35668. }
  35669. };
  35670. var noWorkResult = NoWorkResult$1;
  35671. NoWorkResult$1.default = NoWorkResult$1;
  35672. let NoWorkResult = noWorkResult;
  35673. let LazyResult$1 = lazyResult;
  35674. let Document$1 = document;
  35675. let Root$2 = root$2;
  35676. let Processor$1 = class Processor {
  35677. constructor(plugins = []) {
  35678. this.version = '8.4.21';
  35679. this.plugins = this.normalize(plugins);
  35680. }
  35681. use(plugin) {
  35682. this.plugins = this.plugins.concat(this.normalize([plugin]));
  35683. return this
  35684. }
  35685. process(css, opts = {}) {
  35686. if (
  35687. this.plugins.length === 0 &&
  35688. typeof opts.parser === 'undefined' &&
  35689. typeof opts.stringifier === 'undefined' &&
  35690. typeof opts.syntax === 'undefined'
  35691. ) {
  35692. return new NoWorkResult(this, css, opts)
  35693. } else {
  35694. return new LazyResult$1(this, css, opts)
  35695. }
  35696. }
  35697. normalize(plugins) {
  35698. let normalized = [];
  35699. for (let i of plugins) {
  35700. if (i.postcss === true) {
  35701. i = i();
  35702. } else if (i.postcss) {
  35703. i = i.postcss;
  35704. }
  35705. if (typeof i === 'object' && Array.isArray(i.plugins)) {
  35706. normalized = normalized.concat(i.plugins);
  35707. } else if (typeof i === 'object' && i.postcssPlugin) {
  35708. normalized.push(i);
  35709. } else if (typeof i === 'function') {
  35710. normalized.push(i);
  35711. } else if (typeof i === 'object' && (i.parse || i.stringify)) {
  35712. if (browser$1.env.NODE_ENV !== 'production') {
  35713. throw new Error(
  35714. 'PostCSS syntaxes cannot be used as plugins. Instead, please use ' +
  35715. 'one of the syntax/parser/stringifier options as outlined ' +
  35716. 'in your PostCSS runner documentation.'
  35717. )
  35718. }
  35719. } else {
  35720. throw new Error(i + ' is not a PostCSS plugin')
  35721. }
  35722. }
  35723. return normalized
  35724. }
  35725. };
  35726. var processor$1 = Processor$1;
  35727. Processor$1.default = Processor$1;
  35728. Root$2.registerProcessor(Processor$1);
  35729. Document$1.registerProcessor(Processor$1);
  35730. let Declaration$1 = declaration;
  35731. let PreviousMap = previousMap;
  35732. let Comment$1 = comment$3;
  35733. let AtRule$1 = atRule;
  35734. let Input$1 = input;
  35735. let Root$1 = root$2;
  35736. let Rule$1 = rule;
  35737. function fromJSON$1(json, inputs) {
  35738. if (Array.isArray(json)) return json.map(n => fromJSON$1(n))
  35739. let { inputs: ownInputs, ...defaults } = json;
  35740. if (ownInputs) {
  35741. inputs = [];
  35742. for (let input of ownInputs) {
  35743. let inputHydrated = { ...input, __proto__: Input$1.prototype };
  35744. if (inputHydrated.map) {
  35745. inputHydrated.map = {
  35746. ...inputHydrated.map,
  35747. __proto__: PreviousMap.prototype
  35748. };
  35749. }
  35750. inputs.push(inputHydrated);
  35751. }
  35752. }
  35753. if (defaults.nodes) {
  35754. defaults.nodes = json.nodes.map(n => fromJSON$1(n, inputs));
  35755. }
  35756. if (defaults.source) {
  35757. let { inputId, ...source } = defaults.source;
  35758. defaults.source = source;
  35759. if (inputId != null) {
  35760. defaults.source.input = inputs[inputId];
  35761. }
  35762. }
  35763. if (defaults.type === 'root') {
  35764. return new Root$1(defaults)
  35765. } else if (defaults.type === 'decl') {
  35766. return new Declaration$1(defaults)
  35767. } else if (defaults.type === 'rule') {
  35768. return new Rule$1(defaults)
  35769. } else if (defaults.type === 'comment') {
  35770. return new Comment$1(defaults)
  35771. } else if (defaults.type === 'atrule') {
  35772. return new AtRule$1(defaults)
  35773. } else {
  35774. throw new Error('Unknown node type: ' + json.type)
  35775. }
  35776. }
  35777. var fromJSON_1 = fromJSON$1;
  35778. fromJSON$1.default = fromJSON$1;
  35779. let CssSyntaxError = cssSyntaxError;
  35780. let Declaration = declaration;
  35781. let LazyResult = lazyResult;
  35782. let Container = container$1;
  35783. let Processor = processor$1;
  35784. let stringify = stringify_1;
  35785. let fromJSON = fromJSON_1;
  35786. let Document = document;
  35787. let Warning = warning;
  35788. let Comment = comment$3;
  35789. let AtRule = atRule;
  35790. let Result = result;
  35791. let Input = input;
  35792. let parse = parse_1;
  35793. let list = list_1;
  35794. let Rule = rule;
  35795. let Root = root$2;
  35796. let Node = node$2;
  35797. function postcss(...plugins) {
  35798. if (plugins.length === 1 && Array.isArray(plugins[0])) {
  35799. plugins = plugins[0];
  35800. }
  35801. return new Processor(plugins)
  35802. }
  35803. postcss.plugin = function plugin(name, initializer) {
  35804. let warningPrinted = false;
  35805. function creator(...args) {
  35806. // eslint-disable-next-line no-console
  35807. if (console && console.warn && !warningPrinted) {
  35808. warningPrinted = true;
  35809. // eslint-disable-next-line no-console
  35810. console.warn(
  35811. name +
  35812. ': postcss.plugin was deprecated. Migration guide:\n' +
  35813. 'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
  35814. );
  35815. if (browser$1.env.LANG && browser$1.env.LANG.startsWith('cn')) {
  35816. /* c8 ignore next 7 */
  35817. // eslint-disable-next-line no-console
  35818. console.warn(
  35819. name +
  35820. ': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
  35821. 'https://www.w3ctech.com/topic/2226'
  35822. );
  35823. }
  35824. }
  35825. let transformer = initializer(...args);
  35826. transformer.postcssPlugin = name;
  35827. transformer.postcssVersion = new Processor().version;
  35828. return transformer
  35829. }
  35830. let cache;
  35831. Object.defineProperty(creator, 'postcss', {
  35832. get() {
  35833. if (!cache) cache = creator();
  35834. return cache
  35835. }
  35836. });
  35837. creator.process = function (css, processOpts, pluginOpts) {
  35838. return postcss([creator(pluginOpts)]).process(css, processOpts)
  35839. };
  35840. return creator
  35841. };
  35842. postcss.stringify = stringify;
  35843. postcss.parse = parse;
  35844. postcss.fromJSON = fromJSON;
  35845. postcss.list = list;
  35846. postcss.comment = defaults => new Comment(defaults);
  35847. postcss.atRule = defaults => new AtRule(defaults);
  35848. postcss.decl = defaults => new Declaration(defaults);
  35849. postcss.rule = defaults => new Rule(defaults);
  35850. postcss.root = defaults => new Root(defaults);
  35851. postcss.document = defaults => new Document(defaults);
  35852. postcss.CssSyntaxError = CssSyntaxError;
  35853. postcss.Declaration = Declaration;
  35854. postcss.Container = Container;
  35855. postcss.Processor = Processor;
  35856. postcss.Document = Document;
  35857. postcss.Comment = Comment;
  35858. postcss.Warning = Warning;
  35859. postcss.AtRule = AtRule;
  35860. postcss.Result = Result;
  35861. postcss.Input = Input;
  35862. postcss.Rule = Rule;
  35863. postcss.Root = Root;
  35864. postcss.Node = Node;
  35865. LazyResult.registerPostcss(postcss);
  35866. var postcss_1 = postcss;
  35867. postcss.default = postcss;
  35868. var postcss$1 = postcss_1;
  35869. postcss$1.stringify;
  35870. postcss$1.fromJSON;
  35871. postcss$1.plugin;
  35872. postcss$1.parse;
  35873. postcss$1.list;
  35874. postcss$1.document;
  35875. postcss$1.comment;
  35876. postcss$1.atRule;
  35877. postcss$1.rule;
  35878. postcss$1.decl;
  35879. postcss$1.root;
  35880. postcss$1.CssSyntaxError;
  35881. postcss$1.Declaration;
  35882. postcss$1.Container;
  35883. postcss$1.Processor;
  35884. postcss$1.Document;
  35885. postcss$1.Comment;
  35886. postcss$1.Warning;
  35887. postcss$1.AtRule;
  35888. postcss$1.Result;
  35889. postcss$1.Input;
  35890. postcss$1.Rule;
  35891. postcss$1.Root;
  35892. postcss$1.Node;
  35893. const trimPlugin = () => {
  35894. return {
  35895. postcssPlugin: "vue-sfc-trim",
  35896. Once(root) {
  35897. root.walk(({ type, raws }) => {
  35898. if (type === "rule" || type === "atrule") {
  35899. if (raws.before)
  35900. raws.before = "\n";
  35901. if ("after" in raws && raws.after)
  35902. raws.after = "\n";
  35903. }
  35904. });
  35905. }
  35906. };
  35907. };
  35908. trimPlugin.postcss = true;
  35909. var trimPlugin$1 = trimPlugin;
  35910. var distExports = {};
  35911. var dist = {
  35912. get exports(){ return distExports; },
  35913. set exports(v){ distExports = v; },
  35914. };
  35915. var processorExports = {};
  35916. var processor = {
  35917. get exports(){ return processorExports; },
  35918. set exports(v){ processorExports = v; },
  35919. };
  35920. var parserExports = {};
  35921. var parser = {
  35922. get exports(){ return parserExports; },
  35923. set exports(v){ parserExports = v; },
  35924. };
  35925. var rootExports = {};
  35926. var root$1 = {
  35927. get exports(){ return rootExports; },
  35928. set exports(v){ rootExports = v; },
  35929. };
  35930. var containerExports = {};
  35931. var container = {
  35932. get exports(){ return containerExports; },
  35933. set exports(v){ containerExports = v; },
  35934. };
  35935. var nodeExports = {};
  35936. var node$1 = {
  35937. get exports(){ return nodeExports; },
  35938. set exports(v){ nodeExports = v; },
  35939. };
  35940. var util$6 = {};
  35941. var unescExports = {};
  35942. var unesc = {
  35943. get exports(){ return unescExports; },
  35944. set exports(v){ unescExports = v; },
  35945. };
  35946. (function (module, exports) {
  35947. exports.__esModule = true;
  35948. exports["default"] = unesc;
  35949. // Many thanks for this post which made this migration much easier.
  35950. // https://mathiasbynens.be/notes/css-escapes
  35951. /**
  35952. *
  35953. * @param {string} str
  35954. * @returns {[string, number]|undefined}
  35955. */
  35956. function gobbleHex(str) {
  35957. var lower = str.toLowerCase();
  35958. var hex = '';
  35959. var spaceTerminated = false;
  35960. for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
  35961. var code = lower.charCodeAt(i); // check to see if we are dealing with a valid hex char [a-f|0-9]
  35962. var valid = code >= 97 && code <= 102 || code >= 48 && code <= 57; // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
  35963. spaceTerminated = code === 32;
  35964. if (!valid) {
  35965. break;
  35966. }
  35967. hex += lower[i];
  35968. }
  35969. if (hex.length === 0) {
  35970. return undefined;
  35971. }
  35972. var codePoint = parseInt(hex, 16);
  35973. var isSurrogate = codePoint >= 0xD800 && codePoint <= 0xDFFF; // Add special case for
  35974. // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
  35975. // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
  35976. if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10FFFF) {
  35977. return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
  35978. }
  35979. return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
  35980. }
  35981. var CONTAINS_ESCAPE = /\\/;
  35982. function unesc(str) {
  35983. var needToProcess = CONTAINS_ESCAPE.test(str);
  35984. if (!needToProcess) {
  35985. return str;
  35986. }
  35987. var ret = "";
  35988. for (var i = 0; i < str.length; i++) {
  35989. if (str[i] === "\\") {
  35990. var gobbled = gobbleHex(str.slice(i + 1, i + 7));
  35991. if (gobbled !== undefined) {
  35992. ret += gobbled[0];
  35993. i += gobbled[1];
  35994. continue;
  35995. } // Retain a pair of \\ if double escaped `\\\\`
  35996. // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
  35997. if (str[i + 1] === "\\") {
  35998. ret += "\\";
  35999. i++;
  36000. continue;
  36001. } // if \\ is at the end of the string retain it
  36002. // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
  36003. if (str.length === i + 1) {
  36004. ret += str[i];
  36005. }
  36006. continue;
  36007. }
  36008. ret += str[i];
  36009. }
  36010. return ret;
  36011. }
  36012. module.exports = exports.default;
  36013. } (unesc, unescExports));
  36014. var getPropExports = {};
  36015. var getProp = {
  36016. get exports(){ return getPropExports; },
  36017. set exports(v){ getPropExports = v; },
  36018. };
  36019. (function (module, exports) {
  36020. exports.__esModule = true;
  36021. exports["default"] = getProp;
  36022. function getProp(obj) {
  36023. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36024. props[_key - 1] = arguments[_key];
  36025. }
  36026. while (props.length > 0) {
  36027. var prop = props.shift();
  36028. if (!obj[prop]) {
  36029. return undefined;
  36030. }
  36031. obj = obj[prop];
  36032. }
  36033. return obj;
  36034. }
  36035. module.exports = exports.default;
  36036. } (getProp, getPropExports));
  36037. var ensureObjectExports = {};
  36038. var ensureObject = {
  36039. get exports(){ return ensureObjectExports; },
  36040. set exports(v){ ensureObjectExports = v; },
  36041. };
  36042. (function (module, exports) {
  36043. exports.__esModule = true;
  36044. exports["default"] = ensureObject;
  36045. function ensureObject(obj) {
  36046. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36047. props[_key - 1] = arguments[_key];
  36048. }
  36049. while (props.length > 0) {
  36050. var prop = props.shift();
  36051. if (!obj[prop]) {
  36052. obj[prop] = {};
  36053. }
  36054. obj = obj[prop];
  36055. }
  36056. }
  36057. module.exports = exports.default;
  36058. } (ensureObject, ensureObjectExports));
  36059. var stripCommentsExports = {};
  36060. var stripComments = {
  36061. get exports(){ return stripCommentsExports; },
  36062. set exports(v){ stripCommentsExports = v; },
  36063. };
  36064. (function (module, exports) {
  36065. exports.__esModule = true;
  36066. exports["default"] = stripComments;
  36067. function stripComments(str) {
  36068. var s = "";
  36069. var commentStart = str.indexOf("/*");
  36070. var lastEnd = 0;
  36071. while (commentStart >= 0) {
  36072. s = s + str.slice(lastEnd, commentStart);
  36073. var commentEnd = str.indexOf("*/", commentStart + 2);
  36074. if (commentEnd < 0) {
  36075. return s;
  36076. }
  36077. lastEnd = commentEnd + 2;
  36078. commentStart = str.indexOf("/*", lastEnd);
  36079. }
  36080. s = s + str.slice(lastEnd);
  36081. return s;
  36082. }
  36083. module.exports = exports.default;
  36084. } (stripComments, stripCommentsExports));
  36085. util$6.__esModule = true;
  36086. util$6.stripComments = util$6.ensureObject = util$6.getProp = util$6.unesc = void 0;
  36087. var _unesc = _interopRequireDefault$1(unescExports);
  36088. util$6.unesc = _unesc["default"];
  36089. var _getProp = _interopRequireDefault$1(getPropExports);
  36090. util$6.getProp = _getProp["default"];
  36091. var _ensureObject = _interopRequireDefault$1(ensureObjectExports);
  36092. util$6.ensureObject = _ensureObject["default"];
  36093. var _stripComments = _interopRequireDefault$1(stripCommentsExports);
  36094. util$6.stripComments = _stripComments["default"];
  36095. function _interopRequireDefault$1(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36096. (function (module, exports) {
  36097. exports.__esModule = true;
  36098. exports["default"] = void 0;
  36099. var _util = util$6;
  36100. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  36101. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  36102. var cloneNode = function cloneNode(obj, parent) {
  36103. if (typeof obj !== 'object' || obj === null) {
  36104. return obj;
  36105. }
  36106. var cloned = new obj.constructor();
  36107. for (var i in obj) {
  36108. if (!obj.hasOwnProperty(i)) {
  36109. continue;
  36110. }
  36111. var value = obj[i];
  36112. var type = typeof value;
  36113. if (i === 'parent' && type === 'object') {
  36114. if (parent) {
  36115. cloned[i] = parent;
  36116. }
  36117. } else if (value instanceof Array) {
  36118. cloned[i] = value.map(function (j) {
  36119. return cloneNode(j, cloned);
  36120. });
  36121. } else {
  36122. cloned[i] = cloneNode(value, cloned);
  36123. }
  36124. }
  36125. return cloned;
  36126. };
  36127. var Node = /*#__PURE__*/function () {
  36128. function Node(opts) {
  36129. if (opts === void 0) {
  36130. opts = {};
  36131. }
  36132. Object.assign(this, opts);
  36133. this.spaces = this.spaces || {};
  36134. this.spaces.before = this.spaces.before || '';
  36135. this.spaces.after = this.spaces.after || '';
  36136. }
  36137. var _proto = Node.prototype;
  36138. _proto.remove = function remove() {
  36139. if (this.parent) {
  36140. this.parent.removeChild(this);
  36141. }
  36142. this.parent = undefined;
  36143. return this;
  36144. };
  36145. _proto.replaceWith = function replaceWith() {
  36146. if (this.parent) {
  36147. for (var index in arguments) {
  36148. this.parent.insertBefore(this, arguments[index]);
  36149. }
  36150. this.remove();
  36151. }
  36152. return this;
  36153. };
  36154. _proto.next = function next() {
  36155. return this.parent.at(this.parent.index(this) + 1);
  36156. };
  36157. _proto.prev = function prev() {
  36158. return this.parent.at(this.parent.index(this) - 1);
  36159. };
  36160. _proto.clone = function clone(overrides) {
  36161. if (overrides === void 0) {
  36162. overrides = {};
  36163. }
  36164. var cloned = cloneNode(this);
  36165. for (var name in overrides) {
  36166. cloned[name] = overrides[name];
  36167. }
  36168. return cloned;
  36169. }
  36170. /**
  36171. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36172. * This allows non standard syntax to be appended to an existing property
  36173. * by specifying the escaped value. By specifying the escaped value,
  36174. * illegal characters are allowed to be directly inserted into css output.
  36175. * @param {string} name the property to set
  36176. * @param {any} value the unescaped value of the property
  36177. * @param {string} valueEscaped optional. the escaped value of the property.
  36178. */
  36179. ;
  36180. _proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
  36181. if (!this.raws) {
  36182. this.raws = {};
  36183. }
  36184. var originalValue = this[name];
  36185. var originalEscaped = this.raws[name];
  36186. this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
  36187. if (originalEscaped || valueEscaped !== value) {
  36188. this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
  36189. } else {
  36190. delete this.raws[name]; // delete any escaped value that was created by the setter.
  36191. }
  36192. }
  36193. /**
  36194. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36195. * This allows the escaped value to be specified directly, allowing illegal
  36196. * characters to be directly inserted into css output.
  36197. * @param {string} name the property to set
  36198. * @param {any} value the unescaped value of the property
  36199. * @param {string} valueEscaped the escaped value of the property.
  36200. */
  36201. ;
  36202. _proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
  36203. if (!this.raws) {
  36204. this.raws = {};
  36205. }
  36206. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  36207. this.raws[name] = valueEscaped;
  36208. }
  36209. /**
  36210. * When you want a value to passed through to CSS directly. This method
  36211. * deletes the corresponding raw value causing the stringifier to fallback
  36212. * to the unescaped value.
  36213. * @param {string} name the property to set.
  36214. * @param {any} value The value that is both escaped and unescaped.
  36215. */
  36216. ;
  36217. _proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
  36218. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  36219. if (this.raws) {
  36220. delete this.raws[name];
  36221. }
  36222. }
  36223. /**
  36224. *
  36225. * @param {number} line The number (starting with 1)
  36226. * @param {number} column The column number (starting with 1)
  36227. */
  36228. ;
  36229. _proto.isAtPosition = function isAtPosition(line, column) {
  36230. if (this.source && this.source.start && this.source.end) {
  36231. if (this.source.start.line > line) {
  36232. return false;
  36233. }
  36234. if (this.source.end.line < line) {
  36235. return false;
  36236. }
  36237. if (this.source.start.line === line && this.source.start.column > column) {
  36238. return false;
  36239. }
  36240. if (this.source.end.line === line && this.source.end.column < column) {
  36241. return false;
  36242. }
  36243. return true;
  36244. }
  36245. return undefined;
  36246. };
  36247. _proto.stringifyProperty = function stringifyProperty(name) {
  36248. return this.raws && this.raws[name] || this[name];
  36249. };
  36250. _proto.valueToString = function valueToString() {
  36251. return String(this.stringifyProperty("value"));
  36252. };
  36253. _proto.toString = function toString() {
  36254. return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
  36255. };
  36256. _createClass(Node, [{
  36257. key: "rawSpaceBefore",
  36258. get: function get() {
  36259. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
  36260. if (rawSpace === undefined) {
  36261. rawSpace = this.spaces && this.spaces.before;
  36262. }
  36263. return rawSpace || "";
  36264. },
  36265. set: function set(raw) {
  36266. (0, _util.ensureObject)(this, "raws", "spaces");
  36267. this.raws.spaces.before = raw;
  36268. }
  36269. }, {
  36270. key: "rawSpaceAfter",
  36271. get: function get() {
  36272. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
  36273. if (rawSpace === undefined) {
  36274. rawSpace = this.spaces.after;
  36275. }
  36276. return rawSpace || "";
  36277. },
  36278. set: function set(raw) {
  36279. (0, _util.ensureObject)(this, "raws", "spaces");
  36280. this.raws.spaces.after = raw;
  36281. }
  36282. }]);
  36283. return Node;
  36284. }();
  36285. exports["default"] = Node;
  36286. module.exports = exports.default;
  36287. } (node$1, nodeExports));
  36288. var types = {};
  36289. types.__esModule = true;
  36290. types.UNIVERSAL = types.ATTRIBUTE = types.CLASS = types.COMBINATOR = types.COMMENT = types.ID = types.NESTING = types.PSEUDO = types.ROOT = types.SELECTOR = types.STRING = types.TAG = void 0;
  36291. var TAG = 'tag';
  36292. types.TAG = TAG;
  36293. var STRING = 'string';
  36294. types.STRING = STRING;
  36295. var SELECTOR = 'selector';
  36296. types.SELECTOR = SELECTOR;
  36297. var ROOT = 'root';
  36298. types.ROOT = ROOT;
  36299. var PSEUDO = 'pseudo';
  36300. types.PSEUDO = PSEUDO;
  36301. var NESTING = 'nesting';
  36302. types.NESTING = NESTING;
  36303. var ID = 'id';
  36304. types.ID = ID;
  36305. var COMMENT = 'comment';
  36306. types.COMMENT = COMMENT;
  36307. var COMBINATOR = 'combinator';
  36308. types.COMBINATOR = COMBINATOR;
  36309. var CLASS = 'class';
  36310. types.CLASS = CLASS;
  36311. var ATTRIBUTE = 'attribute';
  36312. types.ATTRIBUTE = ATTRIBUTE;
  36313. var UNIVERSAL = 'universal';
  36314. types.UNIVERSAL = UNIVERSAL;
  36315. (function (module, exports) {
  36316. exports.__esModule = true;
  36317. exports["default"] = void 0;
  36318. var _node = _interopRequireDefault(nodeExports);
  36319. var types$1 = _interopRequireWildcard(types);
  36320. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
  36321. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  36322. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36323. function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); }
  36324. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  36325. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  36326. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  36327. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  36328. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36329. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36330. var Container = /*#__PURE__*/function (_Node) {
  36331. _inheritsLoose(Container, _Node);
  36332. function Container(opts) {
  36333. var _this;
  36334. _this = _Node.call(this, opts) || this;
  36335. if (!_this.nodes) {
  36336. _this.nodes = [];
  36337. }
  36338. return _this;
  36339. }
  36340. var _proto = Container.prototype;
  36341. _proto.append = function append(selector) {
  36342. selector.parent = this;
  36343. this.nodes.push(selector);
  36344. return this;
  36345. };
  36346. _proto.prepend = function prepend(selector) {
  36347. selector.parent = this;
  36348. this.nodes.unshift(selector);
  36349. return this;
  36350. };
  36351. _proto.at = function at(index) {
  36352. return this.nodes[index];
  36353. };
  36354. _proto.index = function index(child) {
  36355. if (typeof child === 'number') {
  36356. return child;
  36357. }
  36358. return this.nodes.indexOf(child);
  36359. };
  36360. _proto.removeChild = function removeChild(child) {
  36361. child = this.index(child);
  36362. this.at(child).parent = undefined;
  36363. this.nodes.splice(child, 1);
  36364. var index;
  36365. for (var id in this.indexes) {
  36366. index = this.indexes[id];
  36367. if (index >= child) {
  36368. this.indexes[id] = index - 1;
  36369. }
  36370. }
  36371. return this;
  36372. };
  36373. _proto.removeAll = function removeAll() {
  36374. for (var _iterator = _createForOfIteratorHelperLoose(this.nodes), _step; !(_step = _iterator()).done;) {
  36375. var node = _step.value;
  36376. node.parent = undefined;
  36377. }
  36378. this.nodes = [];
  36379. return this;
  36380. };
  36381. _proto.empty = function empty() {
  36382. return this.removeAll();
  36383. };
  36384. _proto.insertAfter = function insertAfter(oldNode, newNode) {
  36385. newNode.parent = this;
  36386. var oldIndex = this.index(oldNode);
  36387. this.nodes.splice(oldIndex + 1, 0, newNode);
  36388. newNode.parent = this;
  36389. var index;
  36390. for (var id in this.indexes) {
  36391. index = this.indexes[id];
  36392. if (oldIndex <= index) {
  36393. this.indexes[id] = index + 1;
  36394. }
  36395. }
  36396. return this;
  36397. };
  36398. _proto.insertBefore = function insertBefore(oldNode, newNode) {
  36399. newNode.parent = this;
  36400. var oldIndex = this.index(oldNode);
  36401. this.nodes.splice(oldIndex, 0, newNode);
  36402. newNode.parent = this;
  36403. var index;
  36404. for (var id in this.indexes) {
  36405. index = this.indexes[id];
  36406. if (index <= oldIndex) {
  36407. this.indexes[id] = index + 1;
  36408. }
  36409. }
  36410. return this;
  36411. };
  36412. _proto._findChildAtPosition = function _findChildAtPosition(line, col) {
  36413. var found = undefined;
  36414. this.each(function (node) {
  36415. if (node.atPosition) {
  36416. var foundChild = node.atPosition(line, col);
  36417. if (foundChild) {
  36418. found = foundChild;
  36419. return false;
  36420. }
  36421. } else if (node.isAtPosition(line, col)) {
  36422. found = node;
  36423. return false;
  36424. }
  36425. });
  36426. return found;
  36427. }
  36428. /**
  36429. * Return the most specific node at the line and column number given.
  36430. * The source location is based on the original parsed location, locations aren't
  36431. * updated as selector nodes are mutated.
  36432. *
  36433. * Note that this location is relative to the location of the first character
  36434. * of the selector, and not the location of the selector in the overall document
  36435. * when used in conjunction with postcss.
  36436. *
  36437. * If not found, returns undefined.
  36438. * @param {number} line The line number of the node to find. (1-based index)
  36439. * @param {number} col The column number of the node to find. (1-based index)
  36440. */
  36441. ;
  36442. _proto.atPosition = function atPosition(line, col) {
  36443. if (this.isAtPosition(line, col)) {
  36444. return this._findChildAtPosition(line, col) || this;
  36445. } else {
  36446. return undefined;
  36447. }
  36448. };
  36449. _proto._inferEndPosition = function _inferEndPosition() {
  36450. if (this.last && this.last.source && this.last.source.end) {
  36451. this.source = this.source || {};
  36452. this.source.end = this.source.end || {};
  36453. Object.assign(this.source.end, this.last.source.end);
  36454. }
  36455. };
  36456. _proto.each = function each(callback) {
  36457. if (!this.lastEach) {
  36458. this.lastEach = 0;
  36459. }
  36460. if (!this.indexes) {
  36461. this.indexes = {};
  36462. }
  36463. this.lastEach++;
  36464. var id = this.lastEach;
  36465. this.indexes[id] = 0;
  36466. if (!this.length) {
  36467. return undefined;
  36468. }
  36469. var index, result;
  36470. while (this.indexes[id] < this.length) {
  36471. index = this.indexes[id];
  36472. result = callback(this.at(index), index);
  36473. if (result === false) {
  36474. break;
  36475. }
  36476. this.indexes[id] += 1;
  36477. }
  36478. delete this.indexes[id];
  36479. if (result === false) {
  36480. return false;
  36481. }
  36482. };
  36483. _proto.walk = function walk(callback) {
  36484. return this.each(function (node, i) {
  36485. var result = callback(node, i);
  36486. if (result !== false && node.length) {
  36487. result = node.walk(callback);
  36488. }
  36489. if (result === false) {
  36490. return false;
  36491. }
  36492. });
  36493. };
  36494. _proto.walkAttributes = function walkAttributes(callback) {
  36495. var _this2 = this;
  36496. return this.walk(function (selector) {
  36497. if (selector.type === types$1.ATTRIBUTE) {
  36498. return callback.call(_this2, selector);
  36499. }
  36500. });
  36501. };
  36502. _proto.walkClasses = function walkClasses(callback) {
  36503. var _this3 = this;
  36504. return this.walk(function (selector) {
  36505. if (selector.type === types$1.CLASS) {
  36506. return callback.call(_this3, selector);
  36507. }
  36508. });
  36509. };
  36510. _proto.walkCombinators = function walkCombinators(callback) {
  36511. var _this4 = this;
  36512. return this.walk(function (selector) {
  36513. if (selector.type === types$1.COMBINATOR) {
  36514. return callback.call(_this4, selector);
  36515. }
  36516. });
  36517. };
  36518. _proto.walkComments = function walkComments(callback) {
  36519. var _this5 = this;
  36520. return this.walk(function (selector) {
  36521. if (selector.type === types$1.COMMENT) {
  36522. return callback.call(_this5, selector);
  36523. }
  36524. });
  36525. };
  36526. _proto.walkIds = function walkIds(callback) {
  36527. var _this6 = this;
  36528. return this.walk(function (selector) {
  36529. if (selector.type === types$1.ID) {
  36530. return callback.call(_this6, selector);
  36531. }
  36532. });
  36533. };
  36534. _proto.walkNesting = function walkNesting(callback) {
  36535. var _this7 = this;
  36536. return this.walk(function (selector) {
  36537. if (selector.type === types$1.NESTING) {
  36538. return callback.call(_this7, selector);
  36539. }
  36540. });
  36541. };
  36542. _proto.walkPseudos = function walkPseudos(callback) {
  36543. var _this8 = this;
  36544. return this.walk(function (selector) {
  36545. if (selector.type === types$1.PSEUDO) {
  36546. return callback.call(_this8, selector);
  36547. }
  36548. });
  36549. };
  36550. _proto.walkTags = function walkTags(callback) {
  36551. var _this9 = this;
  36552. return this.walk(function (selector) {
  36553. if (selector.type === types$1.TAG) {
  36554. return callback.call(_this9, selector);
  36555. }
  36556. });
  36557. };
  36558. _proto.walkUniversals = function walkUniversals(callback) {
  36559. var _this10 = this;
  36560. return this.walk(function (selector) {
  36561. if (selector.type === types$1.UNIVERSAL) {
  36562. return callback.call(_this10, selector);
  36563. }
  36564. });
  36565. };
  36566. _proto.split = function split(callback) {
  36567. var _this11 = this;
  36568. var current = [];
  36569. return this.reduce(function (memo, node, index) {
  36570. var split = callback.call(_this11, node);
  36571. current.push(node);
  36572. if (split) {
  36573. memo.push(current);
  36574. current = [];
  36575. } else if (index === _this11.length - 1) {
  36576. memo.push(current);
  36577. }
  36578. return memo;
  36579. }, []);
  36580. };
  36581. _proto.map = function map(callback) {
  36582. return this.nodes.map(callback);
  36583. };
  36584. _proto.reduce = function reduce(callback, memo) {
  36585. return this.nodes.reduce(callback, memo);
  36586. };
  36587. _proto.every = function every(callback) {
  36588. return this.nodes.every(callback);
  36589. };
  36590. _proto.some = function some(callback) {
  36591. return this.nodes.some(callback);
  36592. };
  36593. _proto.filter = function filter(callback) {
  36594. return this.nodes.filter(callback);
  36595. };
  36596. _proto.sort = function sort(callback) {
  36597. return this.nodes.sort(callback);
  36598. };
  36599. _proto.toString = function toString() {
  36600. return this.map(String).join('');
  36601. };
  36602. _createClass(Container, [{
  36603. key: "first",
  36604. get: function get() {
  36605. return this.at(0);
  36606. }
  36607. }, {
  36608. key: "last",
  36609. get: function get() {
  36610. return this.at(this.length - 1);
  36611. }
  36612. }, {
  36613. key: "length",
  36614. get: function get() {
  36615. return this.nodes.length;
  36616. }
  36617. }]);
  36618. return Container;
  36619. }(_node["default"]);
  36620. exports["default"] = Container;
  36621. module.exports = exports.default;
  36622. } (container, containerExports));
  36623. (function (module, exports) {
  36624. exports.__esModule = true;
  36625. exports["default"] = void 0;
  36626. var _container = _interopRequireDefault(containerExports);
  36627. var _types = types;
  36628. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36629. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  36630. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  36631. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36632. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36633. var Root = /*#__PURE__*/function (_Container) {
  36634. _inheritsLoose(Root, _Container);
  36635. function Root(opts) {
  36636. var _this;
  36637. _this = _Container.call(this, opts) || this;
  36638. _this.type = _types.ROOT;
  36639. return _this;
  36640. }
  36641. var _proto = Root.prototype;
  36642. _proto.toString = function toString() {
  36643. var str = this.reduce(function (memo, selector) {
  36644. memo.push(String(selector));
  36645. return memo;
  36646. }, []).join(',');
  36647. return this.trailingComma ? str + ',' : str;
  36648. };
  36649. _proto.error = function error(message, options) {
  36650. if (this._error) {
  36651. return this._error(message, options);
  36652. } else {
  36653. return new Error(message);
  36654. }
  36655. };
  36656. _createClass(Root, [{
  36657. key: "errorGenerator",
  36658. set: function set(handler) {
  36659. this._error = handler;
  36660. }
  36661. }]);
  36662. return Root;
  36663. }(_container["default"]);
  36664. exports["default"] = Root;
  36665. module.exports = exports.default;
  36666. } (root$1, rootExports));
  36667. var selectorExports = {};
  36668. var selector$1 = {
  36669. get exports(){ return selectorExports; },
  36670. set exports(v){ selectorExports = v; },
  36671. };
  36672. (function (module, exports) {
  36673. exports.__esModule = true;
  36674. exports["default"] = void 0;
  36675. var _container = _interopRequireDefault(containerExports);
  36676. var _types = types;
  36677. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36678. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36679. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36680. var Selector = /*#__PURE__*/function (_Container) {
  36681. _inheritsLoose(Selector, _Container);
  36682. function Selector(opts) {
  36683. var _this;
  36684. _this = _Container.call(this, opts) || this;
  36685. _this.type = _types.SELECTOR;
  36686. return _this;
  36687. }
  36688. return Selector;
  36689. }(_container["default"]);
  36690. exports["default"] = Selector;
  36691. module.exports = exports.default;
  36692. } (selector$1, selectorExports));
  36693. var classNameExports = {};
  36694. var className$1 = {
  36695. get exports(){ return classNameExports; },
  36696. set exports(v){ classNameExports = v; },
  36697. };
  36698. /*! https://mths.be/cssesc v3.0.0 by @mathias */
  36699. var object = {};
  36700. var hasOwnProperty = object.hasOwnProperty;
  36701. var merge$2 = function merge(options, defaults) {
  36702. if (!options) {
  36703. return defaults;
  36704. }
  36705. var result = {};
  36706. for (var key in defaults) {
  36707. // `if (defaults.hasOwnProperty(key) { … }` is not needed here, since
  36708. // only recognized option names are used.
  36709. result[key] = hasOwnProperty.call(options, key) ? options[key] : defaults[key];
  36710. }
  36711. return result;
  36712. };
  36713. var regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
  36714. var regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
  36715. var regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
  36716. // https://mathiasbynens.be/notes/css-escapes#css
  36717. var cssesc = function cssesc(string, options) {
  36718. options = merge$2(options, cssesc.options);
  36719. if (options.quotes != 'single' && options.quotes != 'double') {
  36720. options.quotes = 'single';
  36721. }
  36722. var quote = options.quotes == 'double' ? '"' : '\'';
  36723. var isIdentifier = options.isIdentifier;
  36724. var firstChar = string.charAt(0);
  36725. var output = '';
  36726. var counter = 0;
  36727. var length = string.length;
  36728. while (counter < length) {
  36729. var character = string.charAt(counter++);
  36730. var codePoint = character.charCodeAt();
  36731. var value = void 0;
  36732. // If it’s not a printable ASCII character…
  36733. if (codePoint < 0x20 || codePoint > 0x7E) {
  36734. if (codePoint >= 0xD800 && codePoint <= 0xDBFF && counter < length) {
  36735. // It’s a high surrogate, and there is a next character.
  36736. var extra = string.charCodeAt(counter++);
  36737. if ((extra & 0xFC00) == 0xDC00) {
  36738. // next character is low surrogate
  36739. codePoint = ((codePoint & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
  36740. } else {
  36741. // It’s an unmatched surrogate; only append this code unit, in case
  36742. // the next code unit is the high surrogate of a surrogate pair.
  36743. counter--;
  36744. }
  36745. }
  36746. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  36747. } else {
  36748. if (options.escapeEverything) {
  36749. if (regexAnySingleEscape.test(character)) {
  36750. value = '\\' + character;
  36751. } else {
  36752. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  36753. }
  36754. } else if (/[\t\n\f\r\x0B]/.test(character)) {
  36755. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  36756. } else if (character == '\\' || !isIdentifier && (character == '"' && quote == character || character == '\'' && quote == character) || isIdentifier && regexSingleEscape.test(character)) {
  36757. value = '\\' + character;
  36758. } else {
  36759. value = character;
  36760. }
  36761. }
  36762. output += value;
  36763. }
  36764. if (isIdentifier) {
  36765. if (/^-[-\d]/.test(output)) {
  36766. output = '\\-' + output.slice(1);
  36767. } else if (/\d/.test(firstChar)) {
  36768. output = '\\3' + firstChar + ' ' + output.slice(1);
  36769. }
  36770. }
  36771. // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
  36772. // since they’re redundant. Note that this is only possible if the escape
  36773. // sequence isn’t preceded by an odd number of backslashes.
  36774. output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
  36775. if ($1 && $1.length % 2) {
  36776. // It’s not safe to remove the space, so don’t.
  36777. return $0;
  36778. }
  36779. // Strip the space.
  36780. return ($1 || '') + $2;
  36781. });
  36782. if (!isIdentifier && options.wrap) {
  36783. return quote + output + quote;
  36784. }
  36785. return output;
  36786. };
  36787. // Expose default options (so they can be overridden globally).
  36788. cssesc.options = {
  36789. 'escapeEverything': false,
  36790. 'isIdentifier': false,
  36791. 'quotes': 'single',
  36792. 'wrap': false
  36793. };
  36794. cssesc.version = '3.0.0';
  36795. var cssesc_1 = cssesc;
  36796. (function (module, exports) {
  36797. exports.__esModule = true;
  36798. exports["default"] = void 0;
  36799. var _cssesc = _interopRequireDefault(cssesc_1);
  36800. var _util = util$6;
  36801. var _node = _interopRequireDefault(nodeExports);
  36802. var _types = types;
  36803. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36804. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  36805. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  36806. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36807. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36808. var ClassName = /*#__PURE__*/function (_Node) {
  36809. _inheritsLoose(ClassName, _Node);
  36810. function ClassName(opts) {
  36811. var _this;
  36812. _this = _Node.call(this, opts) || this;
  36813. _this.type = _types.CLASS;
  36814. _this._constructed = true;
  36815. return _this;
  36816. }
  36817. var _proto = ClassName.prototype;
  36818. _proto.valueToString = function valueToString() {
  36819. return '.' + _Node.prototype.valueToString.call(this);
  36820. };
  36821. _createClass(ClassName, [{
  36822. key: "value",
  36823. get: function get() {
  36824. return this._value;
  36825. },
  36826. set: function set(v) {
  36827. if (this._constructed) {
  36828. var escaped = (0, _cssesc["default"])(v, {
  36829. isIdentifier: true
  36830. });
  36831. if (escaped !== v) {
  36832. (0, _util.ensureObject)(this, "raws");
  36833. this.raws.value = escaped;
  36834. } else if (this.raws) {
  36835. delete this.raws.value;
  36836. }
  36837. }
  36838. this._value = v;
  36839. }
  36840. }]);
  36841. return ClassName;
  36842. }(_node["default"]);
  36843. exports["default"] = ClassName;
  36844. module.exports = exports.default;
  36845. } (className$1, classNameExports));
  36846. var commentExports = {};
  36847. var comment$2 = {
  36848. get exports(){ return commentExports; },
  36849. set exports(v){ commentExports = v; },
  36850. };
  36851. (function (module, exports) {
  36852. exports.__esModule = true;
  36853. exports["default"] = void 0;
  36854. var _node = _interopRequireDefault(nodeExports);
  36855. var _types = types;
  36856. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36857. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36858. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36859. var Comment = /*#__PURE__*/function (_Node) {
  36860. _inheritsLoose(Comment, _Node);
  36861. function Comment(opts) {
  36862. var _this;
  36863. _this = _Node.call(this, opts) || this;
  36864. _this.type = _types.COMMENT;
  36865. return _this;
  36866. }
  36867. return Comment;
  36868. }(_node["default"]);
  36869. exports["default"] = Comment;
  36870. module.exports = exports.default;
  36871. } (comment$2, commentExports));
  36872. var idExports = {};
  36873. var id$1 = {
  36874. get exports(){ return idExports; },
  36875. set exports(v){ idExports = v; },
  36876. };
  36877. (function (module, exports) {
  36878. exports.__esModule = true;
  36879. exports["default"] = void 0;
  36880. var _node = _interopRequireDefault(nodeExports);
  36881. var _types = types;
  36882. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36883. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36884. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36885. var ID = /*#__PURE__*/function (_Node) {
  36886. _inheritsLoose(ID, _Node);
  36887. function ID(opts) {
  36888. var _this;
  36889. _this = _Node.call(this, opts) || this;
  36890. _this.type = _types.ID;
  36891. return _this;
  36892. }
  36893. var _proto = ID.prototype;
  36894. _proto.valueToString = function valueToString() {
  36895. return '#' + _Node.prototype.valueToString.call(this);
  36896. };
  36897. return ID;
  36898. }(_node["default"]);
  36899. exports["default"] = ID;
  36900. module.exports = exports.default;
  36901. } (id$1, idExports));
  36902. var tagExports = {};
  36903. var tag$1 = {
  36904. get exports(){ return tagExports; },
  36905. set exports(v){ tagExports = v; },
  36906. };
  36907. var namespaceExports = {};
  36908. var namespace = {
  36909. get exports(){ return namespaceExports; },
  36910. set exports(v){ namespaceExports = v; },
  36911. };
  36912. (function (module, exports) {
  36913. exports.__esModule = true;
  36914. exports["default"] = void 0;
  36915. var _cssesc = _interopRequireDefault(cssesc_1);
  36916. var _util = util$6;
  36917. var _node = _interopRequireDefault(nodeExports);
  36918. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36919. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  36920. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  36921. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36922. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36923. var Namespace = /*#__PURE__*/function (_Node) {
  36924. _inheritsLoose(Namespace, _Node);
  36925. function Namespace() {
  36926. return _Node.apply(this, arguments) || this;
  36927. }
  36928. var _proto = Namespace.prototype;
  36929. _proto.qualifiedName = function qualifiedName(value) {
  36930. if (this.namespace) {
  36931. return this.namespaceString + "|" + value;
  36932. } else {
  36933. return value;
  36934. }
  36935. };
  36936. _proto.valueToString = function valueToString() {
  36937. return this.qualifiedName(_Node.prototype.valueToString.call(this));
  36938. };
  36939. _createClass(Namespace, [{
  36940. key: "namespace",
  36941. get: function get() {
  36942. return this._namespace;
  36943. },
  36944. set: function set(namespace) {
  36945. if (namespace === true || namespace === "*" || namespace === "&") {
  36946. this._namespace = namespace;
  36947. if (this.raws) {
  36948. delete this.raws.namespace;
  36949. }
  36950. return;
  36951. }
  36952. var escaped = (0, _cssesc["default"])(namespace, {
  36953. isIdentifier: true
  36954. });
  36955. this._namespace = namespace;
  36956. if (escaped !== namespace) {
  36957. (0, _util.ensureObject)(this, "raws");
  36958. this.raws.namespace = escaped;
  36959. } else if (this.raws) {
  36960. delete this.raws.namespace;
  36961. }
  36962. }
  36963. }, {
  36964. key: "ns",
  36965. get: function get() {
  36966. return this._namespace;
  36967. },
  36968. set: function set(namespace) {
  36969. this.namespace = namespace;
  36970. }
  36971. }, {
  36972. key: "namespaceString",
  36973. get: function get() {
  36974. if (this.namespace) {
  36975. var ns = this.stringifyProperty("namespace");
  36976. if (ns === true) {
  36977. return '';
  36978. } else {
  36979. return ns;
  36980. }
  36981. } else {
  36982. return '';
  36983. }
  36984. }
  36985. }]);
  36986. return Namespace;
  36987. }(_node["default"]);
  36988. exports["default"] = Namespace;
  36989. module.exports = exports.default;
  36990. } (namespace, namespaceExports));
  36991. (function (module, exports) {
  36992. exports.__esModule = true;
  36993. exports["default"] = void 0;
  36994. var _namespace = _interopRequireDefault(namespaceExports);
  36995. var _types = types;
  36996. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36997. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36998. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36999. var Tag = /*#__PURE__*/function (_Namespace) {
  37000. _inheritsLoose(Tag, _Namespace);
  37001. function Tag(opts) {
  37002. var _this;
  37003. _this = _Namespace.call(this, opts) || this;
  37004. _this.type = _types.TAG;
  37005. return _this;
  37006. }
  37007. return Tag;
  37008. }(_namespace["default"]);
  37009. exports["default"] = Tag;
  37010. module.exports = exports.default;
  37011. } (tag$1, tagExports));
  37012. var stringExports = {};
  37013. var string$1 = {
  37014. get exports(){ return stringExports; },
  37015. set exports(v){ stringExports = v; },
  37016. };
  37017. (function (module, exports) {
  37018. exports.__esModule = true;
  37019. exports["default"] = void 0;
  37020. var _node = _interopRequireDefault(nodeExports);
  37021. var _types = types;
  37022. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37023. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37024. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37025. var String = /*#__PURE__*/function (_Node) {
  37026. _inheritsLoose(String, _Node);
  37027. function String(opts) {
  37028. var _this;
  37029. _this = _Node.call(this, opts) || this;
  37030. _this.type = _types.STRING;
  37031. return _this;
  37032. }
  37033. return String;
  37034. }(_node["default"]);
  37035. exports["default"] = String;
  37036. module.exports = exports.default;
  37037. } (string$1, stringExports));
  37038. var pseudoExports = {};
  37039. var pseudo$1 = {
  37040. get exports(){ return pseudoExports; },
  37041. set exports(v){ pseudoExports = v; },
  37042. };
  37043. (function (module, exports) {
  37044. exports.__esModule = true;
  37045. exports["default"] = void 0;
  37046. var _container = _interopRequireDefault(containerExports);
  37047. var _types = types;
  37048. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37049. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37050. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37051. var Pseudo = /*#__PURE__*/function (_Container) {
  37052. _inheritsLoose(Pseudo, _Container);
  37053. function Pseudo(opts) {
  37054. var _this;
  37055. _this = _Container.call(this, opts) || this;
  37056. _this.type = _types.PSEUDO;
  37057. return _this;
  37058. }
  37059. var _proto = Pseudo.prototype;
  37060. _proto.toString = function toString() {
  37061. var params = this.length ? '(' + this.map(String).join(',') + ')' : '';
  37062. return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
  37063. };
  37064. return Pseudo;
  37065. }(_container["default"]);
  37066. exports["default"] = Pseudo;
  37067. module.exports = exports.default;
  37068. } (pseudo$1, pseudoExports));
  37069. var attribute$1 = {};
  37070. /**
  37071. * For Node.js, simply re-export the core `util.deprecate` function.
  37072. */
  37073. var node = require$$0$1.deprecate;
  37074. (function (exports) {
  37075. exports.__esModule = true;
  37076. exports.unescapeValue = unescapeValue;
  37077. exports["default"] = void 0;
  37078. var _cssesc = _interopRequireDefault(cssesc_1);
  37079. var _unesc = _interopRequireDefault(unescExports);
  37080. var _namespace = _interopRequireDefault(namespaceExports);
  37081. var _types = types;
  37082. var _CSSESC_QUOTE_OPTIONS;
  37083. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37084. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  37085. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  37086. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37087. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37088. var deprecate = node;
  37089. var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
  37090. var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
  37091. var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
  37092. var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
  37093. function unescapeValue(value) {
  37094. var deprecatedUsage = false;
  37095. var quoteMark = null;
  37096. var unescaped = value;
  37097. var m = unescaped.match(WRAPPED_IN_QUOTES);
  37098. if (m) {
  37099. quoteMark = m[1];
  37100. unescaped = m[2];
  37101. }
  37102. unescaped = (0, _unesc["default"])(unescaped);
  37103. if (unescaped !== value) {
  37104. deprecatedUsage = true;
  37105. }
  37106. return {
  37107. deprecatedUsage: deprecatedUsage,
  37108. unescaped: unescaped,
  37109. quoteMark: quoteMark
  37110. };
  37111. }
  37112. function handleDeprecatedContructorOpts(opts) {
  37113. if (opts.quoteMark !== undefined) {
  37114. return opts;
  37115. }
  37116. if (opts.value === undefined) {
  37117. return opts;
  37118. }
  37119. warnOfDeprecatedConstructor();
  37120. var _unescapeValue = unescapeValue(opts.value),
  37121. quoteMark = _unescapeValue.quoteMark,
  37122. unescaped = _unescapeValue.unescaped;
  37123. if (!opts.raws) {
  37124. opts.raws = {};
  37125. }
  37126. if (opts.raws.value === undefined) {
  37127. opts.raws.value = opts.value;
  37128. }
  37129. opts.value = unescaped;
  37130. opts.quoteMark = quoteMark;
  37131. return opts;
  37132. }
  37133. var Attribute = /*#__PURE__*/function (_Namespace) {
  37134. _inheritsLoose(Attribute, _Namespace);
  37135. function Attribute(opts) {
  37136. var _this;
  37137. if (opts === void 0) {
  37138. opts = {};
  37139. }
  37140. _this = _Namespace.call(this, handleDeprecatedContructorOpts(opts)) || this;
  37141. _this.type = _types.ATTRIBUTE;
  37142. _this.raws = _this.raws || {};
  37143. Object.defineProperty(_this.raws, 'unquoted', {
  37144. get: deprecate(function () {
  37145. return _this.value;
  37146. }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
  37147. set: deprecate(function () {
  37148. return _this.value;
  37149. }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
  37150. });
  37151. _this._constructed = true;
  37152. return _this;
  37153. }
  37154. /**
  37155. * Returns the Attribute's value quoted such that it would be legal to use
  37156. * in the value of a css file. The original value's quotation setting
  37157. * used for stringification is left unchanged. See `setValue(value, options)`
  37158. * if you want to control the quote settings of a new value for the attribute.
  37159. *
  37160. * You can also change the quotation used for the current value by setting quoteMark.
  37161. *
  37162. * Options:
  37163. * * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
  37164. * option is not set, the original value for quoteMark will be used. If
  37165. * indeterminate, a double quote is used. The legal values are:
  37166. * * `null` - the value will be unquoted and characters will be escaped as necessary.
  37167. * * `'` - the value will be quoted with a single quote and single quotes are escaped.
  37168. * * `"` - the value will be quoted with a double quote and double quotes are escaped.
  37169. * * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
  37170. * over the quoteMark option value.
  37171. * * smart {boolean} - if true, will select a quote mark based on the value
  37172. * and the other options specified here. See the `smartQuoteMark()`
  37173. * method.
  37174. **/
  37175. var _proto = Attribute.prototype;
  37176. _proto.getQuotedValue = function getQuotedValue(options) {
  37177. if (options === void 0) {
  37178. options = {};
  37179. }
  37180. var quoteMark = this._determineQuoteMark(options);
  37181. var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
  37182. var escaped = (0, _cssesc["default"])(this._value, cssescopts);
  37183. return escaped;
  37184. };
  37185. _proto._determineQuoteMark = function _determineQuoteMark(options) {
  37186. return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
  37187. }
  37188. /**
  37189. * Set the unescaped value with the specified quotation options. The value
  37190. * provided must not include any wrapping quote marks -- those quotes will
  37191. * be interpreted as part of the value and escaped accordingly.
  37192. */
  37193. ;
  37194. _proto.setValue = function setValue(value, options) {
  37195. if (options === void 0) {
  37196. options = {};
  37197. }
  37198. this._value = value;
  37199. this._quoteMark = this._determineQuoteMark(options);
  37200. this._syncRawValue();
  37201. }
  37202. /**
  37203. * Intelligently select a quoteMark value based on the value's contents. If
  37204. * the value is a legal CSS ident, it will not be quoted. Otherwise a quote
  37205. * mark will be picked that minimizes the number of escapes.
  37206. *
  37207. * If there's no clear winner, the quote mark from these options is used,
  37208. * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
  37209. * true). If the quoteMark is unspecified, a double quote is used.
  37210. *
  37211. * @param options This takes the quoteMark and preferCurrentQuoteMark options
  37212. * from the quoteValue method.
  37213. */
  37214. ;
  37215. _proto.smartQuoteMark = function smartQuoteMark(options) {
  37216. var v = this.value;
  37217. var numSingleQuotes = v.replace(/[^']/g, '').length;
  37218. var numDoubleQuotes = v.replace(/[^"]/g, '').length;
  37219. if (numSingleQuotes + numDoubleQuotes === 0) {
  37220. var escaped = (0, _cssesc["default"])(v, {
  37221. isIdentifier: true
  37222. });
  37223. if (escaped === v) {
  37224. return Attribute.NO_QUOTE;
  37225. } else {
  37226. var pref = this.preferredQuoteMark(options);
  37227. if (pref === Attribute.NO_QUOTE) {
  37228. // pick a quote mark that isn't none and see if it's smaller
  37229. var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
  37230. var opts = CSSESC_QUOTE_OPTIONS[quote];
  37231. var quoteValue = (0, _cssesc["default"])(v, opts);
  37232. if (quoteValue.length < escaped.length) {
  37233. return quote;
  37234. }
  37235. }
  37236. return pref;
  37237. }
  37238. } else if (numDoubleQuotes === numSingleQuotes) {
  37239. return this.preferredQuoteMark(options);
  37240. } else if (numDoubleQuotes < numSingleQuotes) {
  37241. return Attribute.DOUBLE_QUOTE;
  37242. } else {
  37243. return Attribute.SINGLE_QUOTE;
  37244. }
  37245. }
  37246. /**
  37247. * Selects the preferred quote mark based on the options and the current quote mark value.
  37248. * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
  37249. * instead.
  37250. */
  37251. ;
  37252. _proto.preferredQuoteMark = function preferredQuoteMark(options) {
  37253. var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
  37254. if (quoteMark === undefined) {
  37255. quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
  37256. }
  37257. if (quoteMark === undefined) {
  37258. quoteMark = Attribute.DOUBLE_QUOTE;
  37259. }
  37260. return quoteMark;
  37261. };
  37262. _proto._syncRawValue = function _syncRawValue() {
  37263. var rawValue = (0, _cssesc["default"])(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
  37264. if (rawValue === this._value) {
  37265. if (this.raws) {
  37266. delete this.raws.value;
  37267. }
  37268. } else {
  37269. this.raws.value = rawValue;
  37270. }
  37271. };
  37272. _proto._handleEscapes = function _handleEscapes(prop, value) {
  37273. if (this._constructed) {
  37274. var escaped = (0, _cssesc["default"])(value, {
  37275. isIdentifier: true
  37276. });
  37277. if (escaped !== value) {
  37278. this.raws[prop] = escaped;
  37279. } else {
  37280. delete this.raws[prop];
  37281. }
  37282. }
  37283. };
  37284. _proto._spacesFor = function _spacesFor(name) {
  37285. var attrSpaces = {
  37286. before: '',
  37287. after: ''
  37288. };
  37289. var spaces = this.spaces[name] || {};
  37290. var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
  37291. return Object.assign(attrSpaces, spaces, rawSpaces);
  37292. };
  37293. _proto._stringFor = function _stringFor(name, spaceName, concat) {
  37294. if (spaceName === void 0) {
  37295. spaceName = name;
  37296. }
  37297. if (concat === void 0) {
  37298. concat = defaultAttrConcat;
  37299. }
  37300. var attrSpaces = this._spacesFor(spaceName);
  37301. return concat(this.stringifyProperty(name), attrSpaces);
  37302. }
  37303. /**
  37304. * returns the offset of the attribute part specified relative to the
  37305. * start of the node of the output string.
  37306. *
  37307. * * "ns" - alias for "namespace"
  37308. * * "namespace" - the namespace if it exists.
  37309. * * "attribute" - the attribute name
  37310. * * "attributeNS" - the start of the attribute or its namespace
  37311. * * "operator" - the match operator of the attribute
  37312. * * "value" - The value (string or identifier)
  37313. * * "insensitive" - the case insensitivity flag;
  37314. * @param part One of the possible values inside an attribute.
  37315. * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
  37316. */
  37317. ;
  37318. _proto.offsetOf = function offsetOf(name) {
  37319. var count = 1;
  37320. var attributeSpaces = this._spacesFor("attribute");
  37321. count += attributeSpaces.before.length;
  37322. if (name === "namespace" || name === "ns") {
  37323. return this.namespace ? count : -1;
  37324. }
  37325. if (name === "attributeNS") {
  37326. return count;
  37327. }
  37328. count += this.namespaceString.length;
  37329. if (this.namespace) {
  37330. count += 1;
  37331. }
  37332. if (name === "attribute") {
  37333. return count;
  37334. }
  37335. count += this.stringifyProperty("attribute").length;
  37336. count += attributeSpaces.after.length;
  37337. var operatorSpaces = this._spacesFor("operator");
  37338. count += operatorSpaces.before.length;
  37339. var operator = this.stringifyProperty("operator");
  37340. if (name === "operator") {
  37341. return operator ? count : -1;
  37342. }
  37343. count += operator.length;
  37344. count += operatorSpaces.after.length;
  37345. var valueSpaces = this._spacesFor("value");
  37346. count += valueSpaces.before.length;
  37347. var value = this.stringifyProperty("value");
  37348. if (name === "value") {
  37349. return value ? count : -1;
  37350. }
  37351. count += value.length;
  37352. count += valueSpaces.after.length;
  37353. var insensitiveSpaces = this._spacesFor("insensitive");
  37354. count += insensitiveSpaces.before.length;
  37355. if (name === "insensitive") {
  37356. return this.insensitive ? count : -1;
  37357. }
  37358. return -1;
  37359. };
  37360. _proto.toString = function toString() {
  37361. var _this2 = this;
  37362. var selector = [this.rawSpaceBefore, '['];
  37363. selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
  37364. if (this.operator && (this.value || this.value === '')) {
  37365. selector.push(this._stringFor('operator'));
  37366. selector.push(this._stringFor('value'));
  37367. selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
  37368. if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
  37369. attrSpaces.before = " ";
  37370. }
  37371. return defaultAttrConcat(attrValue, attrSpaces);
  37372. }));
  37373. }
  37374. selector.push(']');
  37375. selector.push(this.rawSpaceAfter);
  37376. return selector.join('');
  37377. };
  37378. _createClass(Attribute, [{
  37379. key: "quoted",
  37380. get: function get() {
  37381. var qm = this.quoteMark;
  37382. return qm === "'" || qm === '"';
  37383. },
  37384. set: function set(value) {
  37385. warnOfDeprecatedQuotedAssignment();
  37386. }
  37387. /**
  37388. * returns a single (`'`) or double (`"`) quote character if the value is quoted.
  37389. * returns `null` if the value is not quoted.
  37390. * returns `undefined` if the quotation state is unknown (this can happen when
  37391. * the attribute is constructed without specifying a quote mark.)
  37392. */
  37393. }, {
  37394. key: "quoteMark",
  37395. get: function get() {
  37396. return this._quoteMark;
  37397. }
  37398. /**
  37399. * Set the quote mark to be used by this attribute's value.
  37400. * If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
  37401. * value is updated accordingly.
  37402. *
  37403. * @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
  37404. */
  37405. ,
  37406. set: function set(quoteMark) {
  37407. if (!this._constructed) {
  37408. this._quoteMark = quoteMark;
  37409. return;
  37410. }
  37411. if (this._quoteMark !== quoteMark) {
  37412. this._quoteMark = quoteMark;
  37413. this._syncRawValue();
  37414. }
  37415. }
  37416. }, {
  37417. key: "qualifiedAttribute",
  37418. get: function get() {
  37419. return this.qualifiedName(this.raws.attribute || this.attribute);
  37420. }
  37421. }, {
  37422. key: "insensitiveFlag",
  37423. get: function get() {
  37424. return this.insensitive ? 'i' : '';
  37425. }
  37426. }, {
  37427. key: "value",
  37428. get: function get() {
  37429. return this._value;
  37430. },
  37431. set:
  37432. /**
  37433. * Before 3.0, the value had to be set to an escaped value including any wrapped
  37434. * quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
  37435. * is unescaped during parsing and any quote marks are removed.
  37436. *
  37437. * Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
  37438. * a deprecation warning is raised when the new value contains any characters that would
  37439. * require escaping (including if it contains wrapped quotes).
  37440. *
  37441. * Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
  37442. * how the new value is quoted.
  37443. */
  37444. function set(v) {
  37445. if (this._constructed) {
  37446. var _unescapeValue2 = unescapeValue(v),
  37447. deprecatedUsage = _unescapeValue2.deprecatedUsage,
  37448. unescaped = _unescapeValue2.unescaped,
  37449. quoteMark = _unescapeValue2.quoteMark;
  37450. if (deprecatedUsage) {
  37451. warnOfDeprecatedValueAssignment();
  37452. }
  37453. if (unescaped === this._value && quoteMark === this._quoteMark) {
  37454. return;
  37455. }
  37456. this._value = unescaped;
  37457. this._quoteMark = quoteMark;
  37458. this._syncRawValue();
  37459. } else {
  37460. this._value = v;
  37461. }
  37462. }
  37463. }, {
  37464. key: "insensitive",
  37465. get: function get() {
  37466. return this._insensitive;
  37467. }
  37468. /**
  37469. * Set the case insensitive flag.
  37470. * If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
  37471. * of the attribute is updated accordingly.
  37472. *
  37473. * @param {true | false} insensitive true if the attribute should match case-insensitively.
  37474. */
  37475. ,
  37476. set: function set(insensitive) {
  37477. if (!insensitive) {
  37478. this._insensitive = false; // "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
  37479. // When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
  37480. if (this.raws && (this.raws.insensitiveFlag === 'I' || this.raws.insensitiveFlag === 'i')) {
  37481. this.raws.insensitiveFlag = undefined;
  37482. }
  37483. }
  37484. this._insensitive = insensitive;
  37485. }
  37486. }, {
  37487. key: "attribute",
  37488. get: function get() {
  37489. return this._attribute;
  37490. },
  37491. set: function set(name) {
  37492. this._handleEscapes("attribute", name);
  37493. this._attribute = name;
  37494. }
  37495. }]);
  37496. return Attribute;
  37497. }(_namespace["default"]);
  37498. exports["default"] = Attribute;
  37499. Attribute.NO_QUOTE = null;
  37500. Attribute.SINGLE_QUOTE = "'";
  37501. Attribute.DOUBLE_QUOTE = '"';
  37502. var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
  37503. "'": {
  37504. quotes: 'single',
  37505. wrap: true
  37506. },
  37507. '"': {
  37508. quotes: 'double',
  37509. wrap: true
  37510. }
  37511. }, _CSSESC_QUOTE_OPTIONS[null] = {
  37512. isIdentifier: true
  37513. }, _CSSESC_QUOTE_OPTIONS);
  37514. function defaultAttrConcat(attrValue, attrSpaces) {
  37515. return "" + attrSpaces.before + attrValue + attrSpaces.after;
  37516. }
  37517. } (attribute$1));
  37518. var universalExports = {};
  37519. var universal$1 = {
  37520. get exports(){ return universalExports; },
  37521. set exports(v){ universalExports = v; },
  37522. };
  37523. (function (module, exports) {
  37524. exports.__esModule = true;
  37525. exports["default"] = void 0;
  37526. var _namespace = _interopRequireDefault(namespaceExports);
  37527. var _types = types;
  37528. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37529. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37530. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37531. var Universal = /*#__PURE__*/function (_Namespace) {
  37532. _inheritsLoose(Universal, _Namespace);
  37533. function Universal(opts) {
  37534. var _this;
  37535. _this = _Namespace.call(this, opts) || this;
  37536. _this.type = _types.UNIVERSAL;
  37537. _this.value = '*';
  37538. return _this;
  37539. }
  37540. return Universal;
  37541. }(_namespace["default"]);
  37542. exports["default"] = Universal;
  37543. module.exports = exports.default;
  37544. } (universal$1, universalExports));
  37545. var combinatorExports = {};
  37546. var combinator$2 = {
  37547. get exports(){ return combinatorExports; },
  37548. set exports(v){ combinatorExports = v; },
  37549. };
  37550. (function (module, exports) {
  37551. exports.__esModule = true;
  37552. exports["default"] = void 0;
  37553. var _node = _interopRequireDefault(nodeExports);
  37554. var _types = types;
  37555. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37556. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37557. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37558. var Combinator = /*#__PURE__*/function (_Node) {
  37559. _inheritsLoose(Combinator, _Node);
  37560. function Combinator(opts) {
  37561. var _this;
  37562. _this = _Node.call(this, opts) || this;
  37563. _this.type = _types.COMBINATOR;
  37564. return _this;
  37565. }
  37566. return Combinator;
  37567. }(_node["default"]);
  37568. exports["default"] = Combinator;
  37569. module.exports = exports.default;
  37570. } (combinator$2, combinatorExports));
  37571. var nestingExports = {};
  37572. var nesting$1 = {
  37573. get exports(){ return nestingExports; },
  37574. set exports(v){ nestingExports = v; },
  37575. };
  37576. (function (module, exports) {
  37577. exports.__esModule = true;
  37578. exports["default"] = void 0;
  37579. var _node = _interopRequireDefault(nodeExports);
  37580. var _types = types;
  37581. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37582. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37583. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37584. var Nesting = /*#__PURE__*/function (_Node) {
  37585. _inheritsLoose(Nesting, _Node);
  37586. function Nesting(opts) {
  37587. var _this;
  37588. _this = _Node.call(this, opts) || this;
  37589. _this.type = _types.NESTING;
  37590. _this.value = '&';
  37591. return _this;
  37592. }
  37593. return Nesting;
  37594. }(_node["default"]);
  37595. exports["default"] = Nesting;
  37596. module.exports = exports.default;
  37597. } (nesting$1, nestingExports));
  37598. var sortAscendingExports = {};
  37599. var sortAscending = {
  37600. get exports(){ return sortAscendingExports; },
  37601. set exports(v){ sortAscendingExports = v; },
  37602. };
  37603. (function (module, exports) {
  37604. exports.__esModule = true;
  37605. exports["default"] = sortAscending;
  37606. function sortAscending(list) {
  37607. return list.sort(function (a, b) {
  37608. return a - b;
  37609. });
  37610. }
  37611. module.exports = exports.default;
  37612. } (sortAscending, sortAscendingExports));
  37613. var tokenize = {};
  37614. var tokenTypes = {};
  37615. tokenTypes.__esModule = true;
  37616. tokenTypes.combinator = tokenTypes.word = tokenTypes.comment = tokenTypes.str = tokenTypes.tab = tokenTypes.newline = tokenTypes.feed = tokenTypes.cr = tokenTypes.backslash = tokenTypes.bang = tokenTypes.slash = tokenTypes.doubleQuote = tokenTypes.singleQuote = tokenTypes.space = tokenTypes.greaterThan = tokenTypes.pipe = tokenTypes.equals = tokenTypes.plus = tokenTypes.caret = tokenTypes.tilde = tokenTypes.dollar = tokenTypes.closeSquare = tokenTypes.openSquare = tokenTypes.closeParenthesis = tokenTypes.openParenthesis = tokenTypes.semicolon = tokenTypes.colon = tokenTypes.comma = tokenTypes.at = tokenTypes.asterisk = tokenTypes.ampersand = void 0;
  37617. var ampersand = 38; // `&`.charCodeAt(0);
  37618. tokenTypes.ampersand = ampersand;
  37619. var asterisk = 42; // `*`.charCodeAt(0);
  37620. tokenTypes.asterisk = asterisk;
  37621. var at = 64; // `@`.charCodeAt(0);
  37622. tokenTypes.at = at;
  37623. var comma$1 = 44; // `,`.charCodeAt(0);
  37624. tokenTypes.comma = comma$1;
  37625. var colon = 58; // `:`.charCodeAt(0);
  37626. tokenTypes.colon = colon;
  37627. var semicolon$1 = 59; // `;`.charCodeAt(0);
  37628. tokenTypes.semicolon = semicolon$1;
  37629. var openParenthesis = 40; // `(`.charCodeAt(0);
  37630. tokenTypes.openParenthesis = openParenthesis;
  37631. var closeParenthesis = 41; // `)`.charCodeAt(0);
  37632. tokenTypes.closeParenthesis = closeParenthesis;
  37633. var openSquare = 91; // `[`.charCodeAt(0);
  37634. tokenTypes.openSquare = openSquare;
  37635. var closeSquare = 93; // `]`.charCodeAt(0);
  37636. tokenTypes.closeSquare = closeSquare;
  37637. var dollar = 36; // `$`.charCodeAt(0);
  37638. tokenTypes.dollar = dollar;
  37639. var tilde = 126; // `~`.charCodeAt(0);
  37640. tokenTypes.tilde = tilde;
  37641. var caret = 94; // `^`.charCodeAt(0);
  37642. tokenTypes.caret = caret;
  37643. var plus = 43; // `+`.charCodeAt(0);
  37644. tokenTypes.plus = plus;
  37645. var equals = 61; // `=`.charCodeAt(0);
  37646. tokenTypes.equals = equals;
  37647. var pipe = 124; // `|`.charCodeAt(0);
  37648. tokenTypes.pipe = pipe;
  37649. var greaterThan = 62; // `>`.charCodeAt(0);
  37650. tokenTypes.greaterThan = greaterThan;
  37651. var space = 32; // ` `.charCodeAt(0);
  37652. tokenTypes.space = space;
  37653. var singleQuote = 39; // `'`.charCodeAt(0);
  37654. tokenTypes.singleQuote = singleQuote;
  37655. var doubleQuote = 34; // `"`.charCodeAt(0);
  37656. tokenTypes.doubleQuote = doubleQuote;
  37657. var slash = 47; // `/`.charCodeAt(0);
  37658. tokenTypes.slash = slash;
  37659. var bang = 33; // `!`.charCodeAt(0);
  37660. tokenTypes.bang = bang;
  37661. var backslash = 92; // '\\'.charCodeAt(0);
  37662. tokenTypes.backslash = backslash;
  37663. var cr = 13; // '\r'.charCodeAt(0);
  37664. tokenTypes.cr = cr;
  37665. var feed = 12; // '\f'.charCodeAt(0);
  37666. tokenTypes.feed = feed;
  37667. var newline = 10; // '\n'.charCodeAt(0);
  37668. tokenTypes.newline = newline;
  37669. var tab = 9; // '\t'.charCodeAt(0);
  37670. // Expose aliases primarily for readability.
  37671. tokenTypes.tab = tab;
  37672. var str = singleQuote; // No good single character representation!
  37673. tokenTypes.str = str;
  37674. var comment$1 = -1;
  37675. tokenTypes.comment = comment$1;
  37676. var word = -2;
  37677. tokenTypes.word = word;
  37678. var combinator$1 = -3;
  37679. tokenTypes.combinator = combinator$1;
  37680. (function (exports) {
  37681. exports.__esModule = true;
  37682. exports["default"] = tokenize;
  37683. exports.FIELDS = void 0;
  37684. var t = _interopRequireWildcard(tokenTypes);
  37685. var _unescapable, _wordDelimiters;
  37686. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
  37687. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  37688. var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
  37689. var wordDelimiters = (_wordDelimiters = {}, _wordDelimiters[t.space] = true, _wordDelimiters[t.tab] = true, _wordDelimiters[t.newline] = true, _wordDelimiters[t.cr] = true, _wordDelimiters[t.feed] = true, _wordDelimiters[t.ampersand] = true, _wordDelimiters[t.asterisk] = true, _wordDelimiters[t.bang] = true, _wordDelimiters[t.comma] = true, _wordDelimiters[t.colon] = true, _wordDelimiters[t.semicolon] = true, _wordDelimiters[t.openParenthesis] = true, _wordDelimiters[t.closeParenthesis] = true, _wordDelimiters[t.openSquare] = true, _wordDelimiters[t.closeSquare] = true, _wordDelimiters[t.singleQuote] = true, _wordDelimiters[t.doubleQuote] = true, _wordDelimiters[t.plus] = true, _wordDelimiters[t.pipe] = true, _wordDelimiters[t.tilde] = true, _wordDelimiters[t.greaterThan] = true, _wordDelimiters[t.equals] = true, _wordDelimiters[t.dollar] = true, _wordDelimiters[t.caret] = true, _wordDelimiters[t.slash] = true, _wordDelimiters);
  37690. var hex = {};
  37691. var hexChars = "0123456789abcdefABCDEF";
  37692. for (var i = 0; i < hexChars.length; i++) {
  37693. hex[hexChars.charCodeAt(i)] = true;
  37694. }
  37695. /**
  37696. * Returns the last index of the bar css word
  37697. * @param {string} css The string in which the word begins
  37698. * @param {number} start The index into the string where word's first letter occurs
  37699. */
  37700. function consumeWord(css, start) {
  37701. var next = start;
  37702. var code;
  37703. do {
  37704. code = css.charCodeAt(next);
  37705. if (wordDelimiters[code]) {
  37706. return next - 1;
  37707. } else if (code === t.backslash) {
  37708. next = consumeEscape(css, next) + 1;
  37709. } else {
  37710. // All other characters are part of the word
  37711. next++;
  37712. }
  37713. } while (next < css.length);
  37714. return next - 1;
  37715. }
  37716. /**
  37717. * Returns the last index of the escape sequence
  37718. * @param {string} css The string in which the sequence begins
  37719. * @param {number} start The index into the string where escape character (`\`) occurs.
  37720. */
  37721. function consumeEscape(css, start) {
  37722. var next = start;
  37723. var code = css.charCodeAt(next + 1);
  37724. if (unescapable[code]) ; else if (hex[code]) {
  37725. var hexDigits = 0; // consume up to 6 hex chars
  37726. do {
  37727. next++;
  37728. hexDigits++;
  37729. code = css.charCodeAt(next + 1);
  37730. } while (hex[code] && hexDigits < 6); // if fewer than 6 hex chars, a trailing space ends the escape
  37731. if (hexDigits < 6 && code === t.space) {
  37732. next++;
  37733. }
  37734. } else {
  37735. // the next char is part of the current word
  37736. next++;
  37737. }
  37738. return next;
  37739. }
  37740. var FIELDS = {
  37741. TYPE: 0,
  37742. START_LINE: 1,
  37743. START_COL: 2,
  37744. END_LINE: 3,
  37745. END_COL: 4,
  37746. START_POS: 5,
  37747. END_POS: 6
  37748. };
  37749. exports.FIELDS = FIELDS;
  37750. function tokenize(input) {
  37751. var tokens = [];
  37752. var css = input.css.valueOf();
  37753. var _css = css,
  37754. length = _css.length;
  37755. var offset = -1;
  37756. var line = 1;
  37757. var start = 0;
  37758. var end = 0;
  37759. var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
  37760. function unclosed(what, fix) {
  37761. if (input.safe) {
  37762. // fyi: this is never set to true.
  37763. css += fix;
  37764. next = css.length - 1;
  37765. } else {
  37766. throw input.error('Unclosed ' + what, line, start - offset, start);
  37767. }
  37768. }
  37769. while (start < length) {
  37770. code = css.charCodeAt(start);
  37771. if (code === t.newline) {
  37772. offset = start;
  37773. line += 1;
  37774. }
  37775. switch (code) {
  37776. case t.space:
  37777. case t.tab:
  37778. case t.newline:
  37779. case t.cr:
  37780. case t.feed:
  37781. next = start;
  37782. do {
  37783. next += 1;
  37784. code = css.charCodeAt(next);
  37785. if (code === t.newline) {
  37786. offset = next;
  37787. line += 1;
  37788. }
  37789. } while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
  37790. tokenType = t.space;
  37791. endLine = line;
  37792. endColumn = next - offset - 1;
  37793. end = next;
  37794. break;
  37795. case t.plus:
  37796. case t.greaterThan:
  37797. case t.tilde:
  37798. case t.pipe:
  37799. next = start;
  37800. do {
  37801. next += 1;
  37802. code = css.charCodeAt(next);
  37803. } while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
  37804. tokenType = t.combinator;
  37805. endLine = line;
  37806. endColumn = start - offset;
  37807. end = next;
  37808. break;
  37809. // Consume these characters as single tokens.
  37810. case t.asterisk:
  37811. case t.ampersand:
  37812. case t.bang:
  37813. case t.comma:
  37814. case t.equals:
  37815. case t.dollar:
  37816. case t.caret:
  37817. case t.openSquare:
  37818. case t.closeSquare:
  37819. case t.colon:
  37820. case t.semicolon:
  37821. case t.openParenthesis:
  37822. case t.closeParenthesis:
  37823. next = start;
  37824. tokenType = code;
  37825. endLine = line;
  37826. endColumn = start - offset;
  37827. end = next + 1;
  37828. break;
  37829. case t.singleQuote:
  37830. case t.doubleQuote:
  37831. quote = code === t.singleQuote ? "'" : '"';
  37832. next = start;
  37833. do {
  37834. escaped = false;
  37835. next = css.indexOf(quote, next + 1);
  37836. if (next === -1) {
  37837. unclosed('quote', quote);
  37838. }
  37839. escapePos = next;
  37840. while (css.charCodeAt(escapePos - 1) === t.backslash) {
  37841. escapePos -= 1;
  37842. escaped = !escaped;
  37843. }
  37844. } while (escaped);
  37845. tokenType = t.str;
  37846. endLine = line;
  37847. endColumn = start - offset;
  37848. end = next + 1;
  37849. break;
  37850. default:
  37851. if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
  37852. next = css.indexOf('*/', start + 2) + 1;
  37853. if (next === 0) {
  37854. unclosed('comment', '*/');
  37855. }
  37856. content = css.slice(start, next + 1);
  37857. lines = content.split('\n');
  37858. last = lines.length - 1;
  37859. if (last > 0) {
  37860. nextLine = line + last;
  37861. nextOffset = next - lines[last].length;
  37862. } else {
  37863. nextLine = line;
  37864. nextOffset = offset;
  37865. }
  37866. tokenType = t.comment;
  37867. line = nextLine;
  37868. endLine = nextLine;
  37869. endColumn = next - nextOffset;
  37870. } else if (code === t.slash) {
  37871. next = start;
  37872. tokenType = code;
  37873. endLine = line;
  37874. endColumn = start - offset;
  37875. end = next + 1;
  37876. } else {
  37877. next = consumeWord(css, start);
  37878. tokenType = t.word;
  37879. endLine = line;
  37880. endColumn = next - offset;
  37881. }
  37882. end = next + 1;
  37883. break;
  37884. } // Ensure that the token structure remains consistent
  37885. tokens.push([tokenType, // [0] Token type
  37886. line, // [1] Starting line
  37887. start - offset, // [2] Starting column
  37888. endLine, // [3] Ending line
  37889. endColumn, // [4] Ending column
  37890. start, // [5] Start position / Source index
  37891. end // [6] End position
  37892. ]); // Reset offset for the next token
  37893. if (nextOffset) {
  37894. offset = nextOffset;
  37895. nextOffset = null;
  37896. }
  37897. start = end;
  37898. }
  37899. return tokens;
  37900. }
  37901. } (tokenize));
  37902. (function (module, exports) {
  37903. exports.__esModule = true;
  37904. exports["default"] = void 0;
  37905. var _root = _interopRequireDefault(rootExports);
  37906. var _selector = _interopRequireDefault(selectorExports);
  37907. var _className = _interopRequireDefault(classNameExports);
  37908. var _comment = _interopRequireDefault(commentExports);
  37909. var _id = _interopRequireDefault(idExports);
  37910. var _tag = _interopRequireDefault(tagExports);
  37911. var _string = _interopRequireDefault(stringExports);
  37912. var _pseudo = _interopRequireDefault(pseudoExports);
  37913. var _attribute = _interopRequireWildcard(attribute$1);
  37914. var _universal = _interopRequireDefault(universalExports);
  37915. var _combinator = _interopRequireDefault(combinatorExports);
  37916. var _nesting = _interopRequireDefault(nestingExports);
  37917. var _sortAscending = _interopRequireDefault(sortAscendingExports);
  37918. var _tokenize = _interopRequireWildcard(tokenize);
  37919. var tokens = _interopRequireWildcard(tokenTypes);
  37920. var types$1 = _interopRequireWildcard(types);
  37921. var _util = util$6;
  37922. var _WHITESPACE_TOKENS, _Object$assign;
  37923. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
  37924. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  37925. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37926. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  37927. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  37928. var WHITESPACE_TOKENS = (_WHITESPACE_TOKENS = {}, _WHITESPACE_TOKENS[tokens.space] = true, _WHITESPACE_TOKENS[tokens.cr] = true, _WHITESPACE_TOKENS[tokens.feed] = true, _WHITESPACE_TOKENS[tokens.newline] = true, _WHITESPACE_TOKENS[tokens.tab] = true, _WHITESPACE_TOKENS);
  37929. var WHITESPACE_EQUIV_TOKENS = Object.assign({}, WHITESPACE_TOKENS, (_Object$assign = {}, _Object$assign[tokens.comment] = true, _Object$assign));
  37930. function tokenStart(token) {
  37931. return {
  37932. line: token[_tokenize.FIELDS.START_LINE],
  37933. column: token[_tokenize.FIELDS.START_COL]
  37934. };
  37935. }
  37936. function tokenEnd(token) {
  37937. return {
  37938. line: token[_tokenize.FIELDS.END_LINE],
  37939. column: token[_tokenize.FIELDS.END_COL]
  37940. };
  37941. }
  37942. function getSource(startLine, startColumn, endLine, endColumn) {
  37943. return {
  37944. start: {
  37945. line: startLine,
  37946. column: startColumn
  37947. },
  37948. end: {
  37949. line: endLine,
  37950. column: endColumn
  37951. }
  37952. };
  37953. }
  37954. function getTokenSource(token) {
  37955. return getSource(token[_tokenize.FIELDS.START_LINE], token[_tokenize.FIELDS.START_COL], token[_tokenize.FIELDS.END_LINE], token[_tokenize.FIELDS.END_COL]);
  37956. }
  37957. function getTokenSourceSpan(startToken, endToken) {
  37958. if (!startToken) {
  37959. return undefined;
  37960. }
  37961. return getSource(startToken[_tokenize.FIELDS.START_LINE], startToken[_tokenize.FIELDS.START_COL], endToken[_tokenize.FIELDS.END_LINE], endToken[_tokenize.FIELDS.END_COL]);
  37962. }
  37963. function unescapeProp(node, prop) {
  37964. var value = node[prop];
  37965. if (typeof value !== "string") {
  37966. return;
  37967. }
  37968. if (value.indexOf("\\") !== -1) {
  37969. (0, _util.ensureObject)(node, 'raws');
  37970. node[prop] = (0, _util.unesc)(value);
  37971. if (node.raws[prop] === undefined) {
  37972. node.raws[prop] = value;
  37973. }
  37974. }
  37975. return node;
  37976. }
  37977. function indexesOf(array, item) {
  37978. var i = -1;
  37979. var indexes = [];
  37980. while ((i = array.indexOf(item, i + 1)) !== -1) {
  37981. indexes.push(i);
  37982. }
  37983. return indexes;
  37984. }
  37985. function uniqs() {
  37986. var list = Array.prototype.concat.apply([], arguments);
  37987. return list.filter(function (item, i) {
  37988. return i === list.indexOf(item);
  37989. });
  37990. }
  37991. var Parser = /*#__PURE__*/function () {
  37992. function Parser(rule, options) {
  37993. if (options === void 0) {
  37994. options = {};
  37995. }
  37996. this.rule = rule;
  37997. this.options = Object.assign({
  37998. lossy: false,
  37999. safe: false
  38000. }, options);
  38001. this.position = 0;
  38002. this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
  38003. this.tokens = (0, _tokenize["default"])({
  38004. css: this.css,
  38005. error: this._errorGenerator(),
  38006. safe: this.options.safe
  38007. });
  38008. var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
  38009. this.root = new _root["default"]({
  38010. source: rootSource
  38011. });
  38012. this.root.errorGenerator = this._errorGenerator();
  38013. var selector = new _selector["default"]({
  38014. source: {
  38015. start: {
  38016. line: 1,
  38017. column: 1
  38018. }
  38019. }
  38020. });
  38021. this.root.append(selector);
  38022. this.current = selector;
  38023. this.loop();
  38024. }
  38025. var _proto = Parser.prototype;
  38026. _proto._errorGenerator = function _errorGenerator() {
  38027. var _this = this;
  38028. return function (message, errorOptions) {
  38029. if (typeof _this.rule === 'string') {
  38030. return new Error(message);
  38031. }
  38032. return _this.rule.error(message, errorOptions);
  38033. };
  38034. };
  38035. _proto.attribute = function attribute() {
  38036. var attr = [];
  38037. var startingToken = this.currToken;
  38038. this.position++;
  38039. while (this.position < this.tokens.length && this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38040. attr.push(this.currToken);
  38041. this.position++;
  38042. }
  38043. if (this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38044. return this.expected('closing square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  38045. }
  38046. var len = attr.length;
  38047. var node = {
  38048. source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
  38049. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  38050. };
  38051. if (len === 1 && !~[tokens.word].indexOf(attr[0][_tokenize.FIELDS.TYPE])) {
  38052. return this.expected('attribute', attr[0][_tokenize.FIELDS.START_POS]);
  38053. }
  38054. var pos = 0;
  38055. var spaceBefore = '';
  38056. var commentBefore = '';
  38057. var lastAdded = null;
  38058. var spaceAfterMeaningfulToken = false;
  38059. while (pos < len) {
  38060. var token = attr[pos];
  38061. var content = this.content(token);
  38062. var next = attr[pos + 1];
  38063. switch (token[_tokenize.FIELDS.TYPE]) {
  38064. case tokens.space:
  38065. // if (
  38066. // len === 1 ||
  38067. // pos === 0 && this.content(next) === '|'
  38068. // ) {
  38069. // return this.expected('attribute', token[TOKEN.START_POS], content);
  38070. // }
  38071. spaceAfterMeaningfulToken = true;
  38072. if (this.options.lossy) {
  38073. break;
  38074. }
  38075. if (lastAdded) {
  38076. (0, _util.ensureObject)(node, 'spaces', lastAdded);
  38077. var prevContent = node.spaces[lastAdded].after || '';
  38078. node.spaces[lastAdded].after = prevContent + content;
  38079. var existingComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || null;
  38080. if (existingComment) {
  38081. node.raws.spaces[lastAdded].after = existingComment + content;
  38082. }
  38083. } else {
  38084. spaceBefore = spaceBefore + content;
  38085. commentBefore = commentBefore + content;
  38086. }
  38087. break;
  38088. case tokens.asterisk:
  38089. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38090. node.operator = content;
  38091. lastAdded = 'operator';
  38092. } else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
  38093. if (spaceBefore) {
  38094. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  38095. node.spaces.attribute.before = spaceBefore;
  38096. spaceBefore = '';
  38097. }
  38098. if (commentBefore) {
  38099. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  38100. node.raws.spaces.attribute.before = spaceBefore;
  38101. commentBefore = '';
  38102. }
  38103. node.namespace = (node.namespace || "") + content;
  38104. var rawValue = (0, _util.getProp)(node, 'raws', 'namespace') || null;
  38105. if (rawValue) {
  38106. node.raws.namespace += content;
  38107. }
  38108. lastAdded = 'namespace';
  38109. }
  38110. spaceAfterMeaningfulToken = false;
  38111. break;
  38112. case tokens.dollar:
  38113. if (lastAdded === "value") {
  38114. var oldRawValue = (0, _util.getProp)(node, 'raws', 'value');
  38115. node.value += "$";
  38116. if (oldRawValue) {
  38117. node.raws.value = oldRawValue + "$";
  38118. }
  38119. break;
  38120. }
  38121. // Falls through
  38122. case tokens.caret:
  38123. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38124. node.operator = content;
  38125. lastAdded = 'operator';
  38126. }
  38127. spaceAfterMeaningfulToken = false;
  38128. break;
  38129. case tokens.combinator:
  38130. if (content === '~' && next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38131. node.operator = content;
  38132. lastAdded = 'operator';
  38133. }
  38134. if (content !== '|') {
  38135. spaceAfterMeaningfulToken = false;
  38136. break;
  38137. }
  38138. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38139. node.operator = content;
  38140. lastAdded = 'operator';
  38141. } else if (!node.namespace && !node.attribute) {
  38142. node.namespace = true;
  38143. }
  38144. spaceAfterMeaningfulToken = false;
  38145. break;
  38146. case tokens.word:
  38147. if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][_tokenize.FIELDS.TYPE] !== tokens.equals && // this look-ahead probably fails with comment nodes involved.
  38148. !node.operator && !node.namespace) {
  38149. node.namespace = content;
  38150. lastAdded = 'namespace';
  38151. } else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
  38152. if (spaceBefore) {
  38153. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  38154. node.spaces.attribute.before = spaceBefore;
  38155. spaceBefore = '';
  38156. }
  38157. if (commentBefore) {
  38158. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  38159. node.raws.spaces.attribute.before = commentBefore;
  38160. commentBefore = '';
  38161. }
  38162. node.attribute = (node.attribute || "") + content;
  38163. var _rawValue = (0, _util.getProp)(node, 'raws', 'attribute') || null;
  38164. if (_rawValue) {
  38165. node.raws.attribute += content;
  38166. }
  38167. lastAdded = 'attribute';
  38168. } else if (!node.value && node.value !== "" || lastAdded === "value" && !(spaceAfterMeaningfulToken || node.quoteMark)) {
  38169. var _unescaped = (0, _util.unesc)(content);
  38170. var _oldRawValue = (0, _util.getProp)(node, 'raws', 'value') || '';
  38171. var oldValue = node.value || '';
  38172. node.value = oldValue + _unescaped;
  38173. node.quoteMark = null;
  38174. if (_unescaped !== content || _oldRawValue) {
  38175. (0, _util.ensureObject)(node, 'raws');
  38176. node.raws.value = (_oldRawValue || oldValue) + content;
  38177. }
  38178. lastAdded = 'value';
  38179. } else {
  38180. var insensitive = content === 'i' || content === "I";
  38181. if ((node.value || node.value === '') && (node.quoteMark || spaceAfterMeaningfulToken)) {
  38182. node.insensitive = insensitive;
  38183. if (!insensitive || content === "I") {
  38184. (0, _util.ensureObject)(node, 'raws');
  38185. node.raws.insensitiveFlag = content;
  38186. }
  38187. lastAdded = 'insensitive';
  38188. if (spaceBefore) {
  38189. (0, _util.ensureObject)(node, 'spaces', 'insensitive');
  38190. node.spaces.insensitive.before = spaceBefore;
  38191. spaceBefore = '';
  38192. }
  38193. if (commentBefore) {
  38194. (0, _util.ensureObject)(node, 'raws', 'spaces', 'insensitive');
  38195. node.raws.spaces.insensitive.before = commentBefore;
  38196. commentBefore = '';
  38197. }
  38198. } else if (node.value || node.value === '') {
  38199. lastAdded = 'value';
  38200. node.value += content;
  38201. if (node.raws.value) {
  38202. node.raws.value += content;
  38203. }
  38204. }
  38205. }
  38206. spaceAfterMeaningfulToken = false;
  38207. break;
  38208. case tokens.str:
  38209. if (!node.attribute || !node.operator) {
  38210. return this.error("Expected an attribute followed by an operator preceding the string.", {
  38211. index: token[_tokenize.FIELDS.START_POS]
  38212. });
  38213. }
  38214. var _unescapeValue = (0, _attribute.unescapeValue)(content),
  38215. unescaped = _unescapeValue.unescaped,
  38216. quoteMark = _unescapeValue.quoteMark;
  38217. node.value = unescaped;
  38218. node.quoteMark = quoteMark;
  38219. lastAdded = 'value';
  38220. (0, _util.ensureObject)(node, 'raws');
  38221. node.raws.value = content;
  38222. spaceAfterMeaningfulToken = false;
  38223. break;
  38224. case tokens.equals:
  38225. if (!node.attribute) {
  38226. return this.expected('attribute', token[_tokenize.FIELDS.START_POS], content);
  38227. }
  38228. if (node.value) {
  38229. return this.error('Unexpected "=" found; an operator was already defined.', {
  38230. index: token[_tokenize.FIELDS.START_POS]
  38231. });
  38232. }
  38233. node.operator = node.operator ? node.operator + content : content;
  38234. lastAdded = 'operator';
  38235. spaceAfterMeaningfulToken = false;
  38236. break;
  38237. case tokens.comment:
  38238. if (lastAdded) {
  38239. if (spaceAfterMeaningfulToken || next && next[_tokenize.FIELDS.TYPE] === tokens.space || lastAdded === 'insensitive') {
  38240. var lastComment = (0, _util.getProp)(node, 'spaces', lastAdded, 'after') || '';
  38241. var rawLastComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;
  38242. (0, _util.ensureObject)(node, 'raws', 'spaces', lastAdded);
  38243. node.raws.spaces[lastAdded].after = rawLastComment + content;
  38244. } else {
  38245. var lastValue = node[lastAdded] || '';
  38246. var rawLastValue = (0, _util.getProp)(node, 'raws', lastAdded) || lastValue;
  38247. (0, _util.ensureObject)(node, 'raws');
  38248. node.raws[lastAdded] = rawLastValue + content;
  38249. }
  38250. } else {
  38251. commentBefore = commentBefore + content;
  38252. }
  38253. break;
  38254. default:
  38255. return this.error("Unexpected \"" + content + "\" found.", {
  38256. index: token[_tokenize.FIELDS.START_POS]
  38257. });
  38258. }
  38259. pos++;
  38260. }
  38261. unescapeProp(node, "attribute");
  38262. unescapeProp(node, "namespace");
  38263. this.newNode(new _attribute["default"](node));
  38264. this.position++;
  38265. }
  38266. /**
  38267. * return a node containing meaningless garbage up to (but not including) the specified token position.
  38268. * if the token position is negative, all remaining tokens are consumed.
  38269. *
  38270. * This returns an array containing a single string node if all whitespace,
  38271. * otherwise an array of comment nodes with space before and after.
  38272. *
  38273. * These tokens are not added to the current selector, the caller can add them or use them to amend
  38274. * a previous node's space metadata.
  38275. *
  38276. * In lossy mode, this returns only comments.
  38277. */
  38278. ;
  38279. _proto.parseWhitespaceEquivalentTokens = function parseWhitespaceEquivalentTokens(stopPosition) {
  38280. if (stopPosition < 0) {
  38281. stopPosition = this.tokens.length;
  38282. }
  38283. var startPosition = this.position;
  38284. var nodes = [];
  38285. var space = "";
  38286. var lastComment = undefined;
  38287. do {
  38288. if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
  38289. if (!this.options.lossy) {
  38290. space += this.content();
  38291. }
  38292. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.comment) {
  38293. var spaces = {};
  38294. if (space) {
  38295. spaces.before = space;
  38296. space = "";
  38297. }
  38298. lastComment = new _comment["default"]({
  38299. value: this.content(),
  38300. source: getTokenSource(this.currToken),
  38301. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  38302. spaces: spaces
  38303. });
  38304. nodes.push(lastComment);
  38305. }
  38306. } while (++this.position < stopPosition);
  38307. if (space) {
  38308. if (lastComment) {
  38309. lastComment.spaces.after = space;
  38310. } else if (!this.options.lossy) {
  38311. var firstToken = this.tokens[startPosition];
  38312. var lastToken = this.tokens[this.position - 1];
  38313. nodes.push(new _string["default"]({
  38314. value: '',
  38315. source: getSource(firstToken[_tokenize.FIELDS.START_LINE], firstToken[_tokenize.FIELDS.START_COL], lastToken[_tokenize.FIELDS.END_LINE], lastToken[_tokenize.FIELDS.END_COL]),
  38316. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  38317. spaces: {
  38318. before: space,
  38319. after: ''
  38320. }
  38321. }));
  38322. }
  38323. }
  38324. return nodes;
  38325. }
  38326. /**
  38327. *
  38328. * @param {*} nodes
  38329. */
  38330. ;
  38331. _proto.convertWhitespaceNodesToSpace = function convertWhitespaceNodesToSpace(nodes, requiredSpace) {
  38332. var _this2 = this;
  38333. if (requiredSpace === void 0) {
  38334. requiredSpace = false;
  38335. }
  38336. var space = "";
  38337. var rawSpace = "";
  38338. nodes.forEach(function (n) {
  38339. var spaceBefore = _this2.lossySpace(n.spaces.before, requiredSpace);
  38340. var rawSpaceBefore = _this2.lossySpace(n.rawSpaceBefore, requiredSpace);
  38341. space += spaceBefore + _this2.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
  38342. rawSpace += spaceBefore + n.value + _this2.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
  38343. });
  38344. if (rawSpace === space) {
  38345. rawSpace = undefined;
  38346. }
  38347. var result = {
  38348. space: space,
  38349. rawSpace: rawSpace
  38350. };
  38351. return result;
  38352. };
  38353. _proto.isNamedCombinator = function isNamedCombinator(position) {
  38354. if (position === void 0) {
  38355. position = this.position;
  38356. }
  38357. return this.tokens[position + 0] && this.tokens[position + 0][_tokenize.FIELDS.TYPE] === tokens.slash && this.tokens[position + 1] && this.tokens[position + 1][_tokenize.FIELDS.TYPE] === tokens.word && this.tokens[position + 2] && this.tokens[position + 2][_tokenize.FIELDS.TYPE] === tokens.slash;
  38358. };
  38359. _proto.namedCombinator = function namedCombinator() {
  38360. if (this.isNamedCombinator()) {
  38361. var nameRaw = this.content(this.tokens[this.position + 1]);
  38362. var name = (0, _util.unesc)(nameRaw).toLowerCase();
  38363. var raws = {};
  38364. if (name !== nameRaw) {
  38365. raws.value = "/" + nameRaw + "/";
  38366. }
  38367. var node = new _combinator["default"]({
  38368. value: "/" + name + "/",
  38369. source: getSource(this.currToken[_tokenize.FIELDS.START_LINE], this.currToken[_tokenize.FIELDS.START_COL], this.tokens[this.position + 2][_tokenize.FIELDS.END_LINE], this.tokens[this.position + 2][_tokenize.FIELDS.END_COL]),
  38370. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  38371. raws: raws
  38372. });
  38373. this.position = this.position + 3;
  38374. return node;
  38375. } else {
  38376. this.unexpected();
  38377. }
  38378. };
  38379. _proto.combinator = function combinator() {
  38380. var _this3 = this;
  38381. if (this.content() === '|') {
  38382. return this.namespace();
  38383. } // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
  38384. var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
  38385. if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma) {
  38386. var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  38387. if (nodes.length > 0) {
  38388. var last = this.current.last;
  38389. if (last) {
  38390. var _this$convertWhitespa = this.convertWhitespaceNodesToSpace(nodes),
  38391. space = _this$convertWhitespa.space,
  38392. rawSpace = _this$convertWhitespa.rawSpace;
  38393. if (rawSpace !== undefined) {
  38394. last.rawSpaceAfter += rawSpace;
  38395. }
  38396. last.spaces.after += space;
  38397. } else {
  38398. nodes.forEach(function (n) {
  38399. return _this3.newNode(n);
  38400. });
  38401. }
  38402. }
  38403. return;
  38404. }
  38405. var firstToken = this.currToken;
  38406. var spaceOrDescendantSelectorNodes = undefined;
  38407. if (nextSigTokenPos > this.position) {
  38408. spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  38409. }
  38410. var node;
  38411. if (this.isNamedCombinator()) {
  38412. node = this.namedCombinator();
  38413. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.combinator) {
  38414. node = new _combinator["default"]({
  38415. value: this.content(),
  38416. source: getTokenSource(this.currToken),
  38417. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS]
  38418. });
  38419. this.position++;
  38420. } else if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) ; else if (!spaceOrDescendantSelectorNodes) {
  38421. this.unexpected();
  38422. }
  38423. if (node) {
  38424. if (spaceOrDescendantSelectorNodes) {
  38425. var _this$convertWhitespa2 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes),
  38426. _space = _this$convertWhitespa2.space,
  38427. _rawSpace = _this$convertWhitespa2.rawSpace;
  38428. node.spaces.before = _space;
  38429. node.rawSpaceBefore = _rawSpace;
  38430. }
  38431. } else {
  38432. // descendant combinator
  38433. var _this$convertWhitespa3 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true),
  38434. _space2 = _this$convertWhitespa3.space,
  38435. _rawSpace2 = _this$convertWhitespa3.rawSpace;
  38436. if (!_rawSpace2) {
  38437. _rawSpace2 = _space2;
  38438. }
  38439. var spaces = {};
  38440. var raws = {
  38441. spaces: {}
  38442. };
  38443. if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
  38444. spaces.before = _space2.slice(0, _space2.length - 1);
  38445. raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
  38446. } else if (_space2.startsWith(' ') && _rawSpace2.startsWith(' ')) {
  38447. spaces.after = _space2.slice(1);
  38448. raws.spaces.after = _rawSpace2.slice(1);
  38449. } else {
  38450. raws.value = _rawSpace2;
  38451. }
  38452. node = new _combinator["default"]({
  38453. value: ' ',
  38454. source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
  38455. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  38456. spaces: spaces,
  38457. raws: raws
  38458. });
  38459. }
  38460. if (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.space) {
  38461. node.spaces.after = this.optionalSpace(this.content());
  38462. this.position++;
  38463. }
  38464. return this.newNode(node);
  38465. };
  38466. _proto.comma = function comma() {
  38467. if (this.position === this.tokens.length - 1) {
  38468. this.root.trailingComma = true;
  38469. this.position++;
  38470. return;
  38471. }
  38472. this.current._inferEndPosition();
  38473. var selector = new _selector["default"]({
  38474. source: {
  38475. start: tokenStart(this.tokens[this.position + 1])
  38476. }
  38477. });
  38478. this.current.parent.append(selector);
  38479. this.current = selector;
  38480. this.position++;
  38481. };
  38482. _proto.comment = function comment() {
  38483. var current = this.currToken;
  38484. this.newNode(new _comment["default"]({
  38485. value: this.content(),
  38486. source: getTokenSource(current),
  38487. sourceIndex: current[_tokenize.FIELDS.START_POS]
  38488. }));
  38489. this.position++;
  38490. };
  38491. _proto.error = function error(message, opts) {
  38492. throw this.root.error(message, opts);
  38493. };
  38494. _proto.missingBackslash = function missingBackslash() {
  38495. return this.error('Expected a backslash preceding the semicolon.', {
  38496. index: this.currToken[_tokenize.FIELDS.START_POS]
  38497. });
  38498. };
  38499. _proto.missingParenthesis = function missingParenthesis() {
  38500. return this.expected('opening parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  38501. };
  38502. _proto.missingSquareBracket = function missingSquareBracket() {
  38503. return this.expected('opening square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  38504. };
  38505. _proto.unexpected = function unexpected() {
  38506. return this.error("Unexpected '" + this.content() + "'. Escaping special characters with \\ may help.", this.currToken[_tokenize.FIELDS.START_POS]);
  38507. };
  38508. _proto.namespace = function namespace() {
  38509. var before = this.prevToken && this.content(this.prevToken) || true;
  38510. if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  38511. this.position++;
  38512. return this.word(before);
  38513. } else if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.asterisk) {
  38514. this.position++;
  38515. return this.universal(before);
  38516. }
  38517. };
  38518. _proto.nesting = function nesting() {
  38519. if (this.nextToken) {
  38520. var nextContent = this.content(this.nextToken);
  38521. if (nextContent === "|") {
  38522. this.position++;
  38523. return;
  38524. }
  38525. }
  38526. var current = this.currToken;
  38527. this.newNode(new _nesting["default"]({
  38528. value: this.content(),
  38529. source: getTokenSource(current),
  38530. sourceIndex: current[_tokenize.FIELDS.START_POS]
  38531. }));
  38532. this.position++;
  38533. };
  38534. _proto.parentheses = function parentheses() {
  38535. var last = this.current.last;
  38536. var unbalanced = 1;
  38537. this.position++;
  38538. if (last && last.type === types$1.PSEUDO) {
  38539. var selector = new _selector["default"]({
  38540. source: {
  38541. start: tokenStart(this.tokens[this.position - 1])
  38542. }
  38543. });
  38544. var cache = this.current;
  38545. last.append(selector);
  38546. this.current = selector;
  38547. while (this.position < this.tokens.length && unbalanced) {
  38548. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  38549. unbalanced++;
  38550. }
  38551. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  38552. unbalanced--;
  38553. }
  38554. if (unbalanced) {
  38555. this.parse();
  38556. } else {
  38557. this.current.source.end = tokenEnd(this.currToken);
  38558. this.current.parent.source.end = tokenEnd(this.currToken);
  38559. this.position++;
  38560. }
  38561. }
  38562. this.current = cache;
  38563. } else {
  38564. // I think this case should be an error. It's used to implement a basic parse of media queries
  38565. // but I don't think it's a good idea.
  38566. var parenStart = this.currToken;
  38567. var parenValue = "(";
  38568. var parenEnd;
  38569. while (this.position < this.tokens.length && unbalanced) {
  38570. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  38571. unbalanced++;
  38572. }
  38573. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  38574. unbalanced--;
  38575. }
  38576. parenEnd = this.currToken;
  38577. parenValue += this.parseParenthesisToken(this.currToken);
  38578. this.position++;
  38579. }
  38580. if (last) {
  38581. last.appendToPropertyAndEscape("value", parenValue, parenValue);
  38582. } else {
  38583. this.newNode(new _string["default"]({
  38584. value: parenValue,
  38585. source: getSource(parenStart[_tokenize.FIELDS.START_LINE], parenStart[_tokenize.FIELDS.START_COL], parenEnd[_tokenize.FIELDS.END_LINE], parenEnd[_tokenize.FIELDS.END_COL]),
  38586. sourceIndex: parenStart[_tokenize.FIELDS.START_POS]
  38587. }));
  38588. }
  38589. }
  38590. if (unbalanced) {
  38591. return this.expected('closing parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  38592. }
  38593. };
  38594. _proto.pseudo = function pseudo() {
  38595. var _this4 = this;
  38596. var pseudoStr = '';
  38597. var startingToken = this.currToken;
  38598. while (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.colon) {
  38599. pseudoStr += this.content();
  38600. this.position++;
  38601. }
  38602. if (!this.currToken) {
  38603. return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
  38604. }
  38605. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  38606. this.splitWord(false, function (first, length) {
  38607. pseudoStr += first;
  38608. _this4.newNode(new _pseudo["default"]({
  38609. value: pseudoStr,
  38610. source: getTokenSourceSpan(startingToken, _this4.currToken),
  38611. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  38612. }));
  38613. if (length > 1 && _this4.nextToken && _this4.nextToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  38614. _this4.error('Misplaced parenthesis.', {
  38615. index: _this4.nextToken[_tokenize.FIELDS.START_POS]
  38616. });
  38617. }
  38618. });
  38619. } else {
  38620. return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[_tokenize.FIELDS.START_POS]);
  38621. }
  38622. };
  38623. _proto.space = function space() {
  38624. var content = this.content(); // Handle space before and after the selector
  38625. if (this.position === 0 || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis || this.current.nodes.every(function (node) {
  38626. return node.type === 'comment';
  38627. })) {
  38628. this.spaces = this.optionalSpace(content);
  38629. this.position++;
  38630. } else if (this.position === this.tokens.length - 1 || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  38631. this.current.last.spaces.after = this.optionalSpace(content);
  38632. this.position++;
  38633. } else {
  38634. this.combinator();
  38635. }
  38636. };
  38637. _proto.string = function string() {
  38638. var current = this.currToken;
  38639. this.newNode(new _string["default"]({
  38640. value: this.content(),
  38641. source: getTokenSource(current),
  38642. sourceIndex: current[_tokenize.FIELDS.START_POS]
  38643. }));
  38644. this.position++;
  38645. };
  38646. _proto.universal = function universal(namespace) {
  38647. var nextToken = this.nextToken;
  38648. if (nextToken && this.content(nextToken) === '|') {
  38649. this.position++;
  38650. return this.namespace();
  38651. }
  38652. var current = this.currToken;
  38653. this.newNode(new _universal["default"]({
  38654. value: this.content(),
  38655. source: getTokenSource(current),
  38656. sourceIndex: current[_tokenize.FIELDS.START_POS]
  38657. }), namespace);
  38658. this.position++;
  38659. };
  38660. _proto.splitWord = function splitWord(namespace, firstCallback) {
  38661. var _this5 = this;
  38662. var nextToken = this.nextToken;
  38663. var word = this.content();
  38664. while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[_tokenize.FIELDS.TYPE])) {
  38665. this.position++;
  38666. var current = this.content();
  38667. word += current;
  38668. if (current.lastIndexOf('\\') === current.length - 1) {
  38669. var next = this.nextToken;
  38670. if (next && next[_tokenize.FIELDS.TYPE] === tokens.space) {
  38671. word += this.requiredSpace(this.content(next));
  38672. this.position++;
  38673. }
  38674. }
  38675. nextToken = this.nextToken;
  38676. }
  38677. var hasClass = indexesOf(word, '.').filter(function (i) {
  38678. // Allow escaped dot within class name
  38679. var escapedDot = word[i - 1] === '\\'; // Allow decimal numbers percent in @keyframes
  38680. var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
  38681. return !escapedDot && !isKeyframesPercent;
  38682. });
  38683. var hasId = indexesOf(word, '#').filter(function (i) {
  38684. return word[i - 1] !== '\\';
  38685. }); // Eliminate Sass interpolations from the list of id indexes
  38686. var interpolations = indexesOf(word, '#{');
  38687. if (interpolations.length) {
  38688. hasId = hasId.filter(function (hashIndex) {
  38689. return !~interpolations.indexOf(hashIndex);
  38690. });
  38691. }
  38692. var indices = (0, _sortAscending["default"])(uniqs([0].concat(hasClass, hasId)));
  38693. indices.forEach(function (ind, i) {
  38694. var index = indices[i + 1] || word.length;
  38695. var value = word.slice(ind, index);
  38696. if (i === 0 && firstCallback) {
  38697. return firstCallback.call(_this5, value, indices.length);
  38698. }
  38699. var node;
  38700. var current = _this5.currToken;
  38701. var sourceIndex = current[_tokenize.FIELDS.START_POS] + indices[i];
  38702. var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
  38703. if (~hasClass.indexOf(ind)) {
  38704. var classNameOpts = {
  38705. value: value.slice(1),
  38706. source: source,
  38707. sourceIndex: sourceIndex
  38708. };
  38709. node = new _className["default"](unescapeProp(classNameOpts, "value"));
  38710. } else if (~hasId.indexOf(ind)) {
  38711. var idOpts = {
  38712. value: value.slice(1),
  38713. source: source,
  38714. sourceIndex: sourceIndex
  38715. };
  38716. node = new _id["default"](unescapeProp(idOpts, "value"));
  38717. } else {
  38718. var tagOpts = {
  38719. value: value,
  38720. source: source,
  38721. sourceIndex: sourceIndex
  38722. };
  38723. unescapeProp(tagOpts, "value");
  38724. node = new _tag["default"](tagOpts);
  38725. }
  38726. _this5.newNode(node, namespace); // Ensure that the namespace is used only once
  38727. namespace = null;
  38728. });
  38729. this.position++;
  38730. };
  38731. _proto.word = function word(namespace) {
  38732. var nextToken = this.nextToken;
  38733. if (nextToken && this.content(nextToken) === '|') {
  38734. this.position++;
  38735. return this.namespace();
  38736. }
  38737. return this.splitWord(namespace);
  38738. };
  38739. _proto.loop = function loop() {
  38740. while (this.position < this.tokens.length) {
  38741. this.parse(true);
  38742. }
  38743. this.current._inferEndPosition();
  38744. return this.root;
  38745. };
  38746. _proto.parse = function parse(throwOnParenthesis) {
  38747. switch (this.currToken[_tokenize.FIELDS.TYPE]) {
  38748. case tokens.space:
  38749. this.space();
  38750. break;
  38751. case tokens.comment:
  38752. this.comment();
  38753. break;
  38754. case tokens.openParenthesis:
  38755. this.parentheses();
  38756. break;
  38757. case tokens.closeParenthesis:
  38758. if (throwOnParenthesis) {
  38759. this.missingParenthesis();
  38760. }
  38761. break;
  38762. case tokens.openSquare:
  38763. this.attribute();
  38764. break;
  38765. case tokens.dollar:
  38766. case tokens.caret:
  38767. case tokens.equals:
  38768. case tokens.word:
  38769. this.word();
  38770. break;
  38771. case tokens.colon:
  38772. this.pseudo();
  38773. break;
  38774. case tokens.comma:
  38775. this.comma();
  38776. break;
  38777. case tokens.asterisk:
  38778. this.universal();
  38779. break;
  38780. case tokens.ampersand:
  38781. this.nesting();
  38782. break;
  38783. case tokens.slash:
  38784. case tokens.combinator:
  38785. this.combinator();
  38786. break;
  38787. case tokens.str:
  38788. this.string();
  38789. break;
  38790. // These cases throw; no break needed.
  38791. case tokens.closeSquare:
  38792. this.missingSquareBracket();
  38793. case tokens.semicolon:
  38794. this.missingBackslash();
  38795. default:
  38796. this.unexpected();
  38797. }
  38798. }
  38799. /**
  38800. * Helpers
  38801. */
  38802. ;
  38803. _proto.expected = function expected(description, index, found) {
  38804. if (Array.isArray(description)) {
  38805. var last = description.pop();
  38806. description = description.join(', ') + " or " + last;
  38807. }
  38808. var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
  38809. if (!found) {
  38810. return this.error("Expected " + an + " " + description + ".", {
  38811. index: index
  38812. });
  38813. }
  38814. return this.error("Expected " + an + " " + description + ", found \"" + found + "\" instead.", {
  38815. index: index
  38816. });
  38817. };
  38818. _proto.requiredSpace = function requiredSpace(space) {
  38819. return this.options.lossy ? ' ' : space;
  38820. };
  38821. _proto.optionalSpace = function optionalSpace(space) {
  38822. return this.options.lossy ? '' : space;
  38823. };
  38824. _proto.lossySpace = function lossySpace(space, required) {
  38825. if (this.options.lossy) {
  38826. return required ? ' ' : '';
  38827. } else {
  38828. return space;
  38829. }
  38830. };
  38831. _proto.parseParenthesisToken = function parseParenthesisToken(token) {
  38832. var content = this.content(token);
  38833. if (token[_tokenize.FIELDS.TYPE] === tokens.space) {
  38834. return this.requiredSpace(content);
  38835. } else {
  38836. return content;
  38837. }
  38838. };
  38839. _proto.newNode = function newNode(node, namespace) {
  38840. if (namespace) {
  38841. if (/^ +$/.test(namespace)) {
  38842. if (!this.options.lossy) {
  38843. this.spaces = (this.spaces || '') + namespace;
  38844. }
  38845. namespace = true;
  38846. }
  38847. node.namespace = namespace;
  38848. unescapeProp(node, "namespace");
  38849. }
  38850. if (this.spaces) {
  38851. node.spaces.before = this.spaces;
  38852. this.spaces = '';
  38853. }
  38854. return this.current.append(node);
  38855. };
  38856. _proto.content = function content(token) {
  38857. if (token === void 0) {
  38858. token = this.currToken;
  38859. }
  38860. return this.css.slice(token[_tokenize.FIELDS.START_POS], token[_tokenize.FIELDS.END_POS]);
  38861. };
  38862. /**
  38863. * returns the index of the next non-whitespace, non-comment token.
  38864. * returns -1 if no meaningful token is found.
  38865. */
  38866. _proto.locateNextMeaningfulToken = function locateNextMeaningfulToken(startPosition) {
  38867. if (startPosition === void 0) {
  38868. startPosition = this.position + 1;
  38869. }
  38870. var searchPosition = startPosition;
  38871. while (searchPosition < this.tokens.length) {
  38872. if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][_tokenize.FIELDS.TYPE]]) {
  38873. searchPosition++;
  38874. continue;
  38875. } else {
  38876. return searchPosition;
  38877. }
  38878. }
  38879. return -1;
  38880. };
  38881. _createClass(Parser, [{
  38882. key: "currToken",
  38883. get: function get() {
  38884. return this.tokens[this.position];
  38885. }
  38886. }, {
  38887. key: "nextToken",
  38888. get: function get() {
  38889. return this.tokens[this.position + 1];
  38890. }
  38891. }, {
  38892. key: "prevToken",
  38893. get: function get() {
  38894. return this.tokens[this.position - 1];
  38895. }
  38896. }]);
  38897. return Parser;
  38898. }();
  38899. exports["default"] = Parser;
  38900. module.exports = exports.default;
  38901. } (parser, parserExports));
  38902. (function (module, exports) {
  38903. exports.__esModule = true;
  38904. exports["default"] = void 0;
  38905. var _parser = _interopRequireDefault(parserExports);
  38906. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38907. var Processor = /*#__PURE__*/function () {
  38908. function Processor(func, options) {
  38909. this.func = func || function noop() {};
  38910. this.funcRes = null;
  38911. this.options = options;
  38912. }
  38913. var _proto = Processor.prototype;
  38914. _proto._shouldUpdateSelector = function _shouldUpdateSelector(rule, options) {
  38915. if (options === void 0) {
  38916. options = {};
  38917. }
  38918. var merged = Object.assign({}, this.options, options);
  38919. if (merged.updateSelector === false) {
  38920. return false;
  38921. } else {
  38922. return typeof rule !== "string";
  38923. }
  38924. };
  38925. _proto._isLossy = function _isLossy(options) {
  38926. if (options === void 0) {
  38927. options = {};
  38928. }
  38929. var merged = Object.assign({}, this.options, options);
  38930. if (merged.lossless === false) {
  38931. return true;
  38932. } else {
  38933. return false;
  38934. }
  38935. };
  38936. _proto._root = function _root(rule, options) {
  38937. if (options === void 0) {
  38938. options = {};
  38939. }
  38940. var parser = new _parser["default"](rule, this._parseOptions(options));
  38941. return parser.root;
  38942. };
  38943. _proto._parseOptions = function _parseOptions(options) {
  38944. return {
  38945. lossy: this._isLossy(options)
  38946. };
  38947. };
  38948. _proto._run = function _run(rule, options) {
  38949. var _this = this;
  38950. if (options === void 0) {
  38951. options = {};
  38952. }
  38953. return new Promise(function (resolve, reject) {
  38954. try {
  38955. var root = _this._root(rule, options);
  38956. Promise.resolve(_this.func(root)).then(function (transform) {
  38957. var string = undefined;
  38958. if (_this._shouldUpdateSelector(rule, options)) {
  38959. string = root.toString();
  38960. rule.selector = string;
  38961. }
  38962. return {
  38963. transform: transform,
  38964. root: root,
  38965. string: string
  38966. };
  38967. }).then(resolve, reject);
  38968. } catch (e) {
  38969. reject(e);
  38970. return;
  38971. }
  38972. });
  38973. };
  38974. _proto._runSync = function _runSync(rule, options) {
  38975. if (options === void 0) {
  38976. options = {};
  38977. }
  38978. var root = this._root(rule, options);
  38979. var transform = this.func(root);
  38980. if (transform && typeof transform.then === "function") {
  38981. throw new Error("Selector processor returned a promise to a synchronous call.");
  38982. }
  38983. var string = undefined;
  38984. if (options.updateSelector && typeof rule !== "string") {
  38985. string = root.toString();
  38986. rule.selector = string;
  38987. }
  38988. return {
  38989. transform: transform,
  38990. root: root,
  38991. string: string
  38992. };
  38993. }
  38994. /**
  38995. * Process rule into a selector AST.
  38996. *
  38997. * @param rule {postcss.Rule | string} The css selector to be processed
  38998. * @param options The options for processing
  38999. * @returns {Promise<parser.Root>} The AST of the selector after processing it.
  39000. */
  39001. ;
  39002. _proto.ast = function ast(rule, options) {
  39003. return this._run(rule, options).then(function (result) {
  39004. return result.root;
  39005. });
  39006. }
  39007. /**
  39008. * Process rule into a selector AST synchronously.
  39009. *
  39010. * @param rule {postcss.Rule | string} The css selector to be processed
  39011. * @param options The options for processing
  39012. * @returns {parser.Root} The AST of the selector after processing it.
  39013. */
  39014. ;
  39015. _proto.astSync = function astSync(rule, options) {
  39016. return this._runSync(rule, options).root;
  39017. }
  39018. /**
  39019. * Process a selector into a transformed value asynchronously
  39020. *
  39021. * @param rule {postcss.Rule | string} The css selector to be processed
  39022. * @param options The options for processing
  39023. * @returns {Promise<any>} The value returned by the processor.
  39024. */
  39025. ;
  39026. _proto.transform = function transform(rule, options) {
  39027. return this._run(rule, options).then(function (result) {
  39028. return result.transform;
  39029. });
  39030. }
  39031. /**
  39032. * Process a selector into a transformed value synchronously.
  39033. *
  39034. * @param rule {postcss.Rule | string} The css selector to be processed
  39035. * @param options The options for processing
  39036. * @returns {any} The value returned by the processor.
  39037. */
  39038. ;
  39039. _proto.transformSync = function transformSync(rule, options) {
  39040. return this._runSync(rule, options).transform;
  39041. }
  39042. /**
  39043. * Process a selector into a new selector string asynchronously.
  39044. *
  39045. * @param rule {postcss.Rule | string} The css selector to be processed
  39046. * @param options The options for processing
  39047. * @returns {string} the selector after processing.
  39048. */
  39049. ;
  39050. _proto.process = function process(rule, options) {
  39051. return this._run(rule, options).then(function (result) {
  39052. return result.string || result.root.toString();
  39053. });
  39054. }
  39055. /**
  39056. * Process a selector into a new selector string synchronously.
  39057. *
  39058. * @param rule {postcss.Rule | string} The css selector to be processed
  39059. * @param options The options for processing
  39060. * @returns {string} the selector after processing.
  39061. */
  39062. ;
  39063. _proto.processSync = function processSync(rule, options) {
  39064. var result = this._runSync(rule, options);
  39065. return result.string || result.root.toString();
  39066. };
  39067. return Processor;
  39068. }();
  39069. exports["default"] = Processor;
  39070. module.exports = exports.default;
  39071. } (processor, processorExports));
  39072. var selectors = {};
  39073. var constructors = {};
  39074. constructors.__esModule = true;
  39075. constructors.universal = constructors.tag = constructors.string = constructors.selector = constructors.root = constructors.pseudo = constructors.nesting = constructors.id = constructors.comment = constructors.combinator = constructors.className = constructors.attribute = void 0;
  39076. var _attribute = _interopRequireDefault(attribute$1);
  39077. var _className = _interopRequireDefault(classNameExports);
  39078. var _combinator = _interopRequireDefault(combinatorExports);
  39079. var _comment = _interopRequireDefault(commentExports);
  39080. var _id = _interopRequireDefault(idExports);
  39081. var _nesting = _interopRequireDefault(nestingExports);
  39082. var _pseudo = _interopRequireDefault(pseudoExports);
  39083. var _root = _interopRequireDefault(rootExports);
  39084. var _selector = _interopRequireDefault(selectorExports);
  39085. var _string = _interopRequireDefault(stringExports);
  39086. var _tag = _interopRequireDefault(tagExports);
  39087. var _universal = _interopRequireDefault(universalExports);
  39088. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39089. var attribute = function attribute(opts) {
  39090. return new _attribute["default"](opts);
  39091. };
  39092. constructors.attribute = attribute;
  39093. var className = function className(opts) {
  39094. return new _className["default"](opts);
  39095. };
  39096. constructors.className = className;
  39097. var combinator = function combinator(opts) {
  39098. return new _combinator["default"](opts);
  39099. };
  39100. constructors.combinator = combinator;
  39101. var comment = function comment(opts) {
  39102. return new _comment["default"](opts);
  39103. };
  39104. constructors.comment = comment;
  39105. var id = function id(opts) {
  39106. return new _id["default"](opts);
  39107. };
  39108. constructors.id = id;
  39109. var nesting = function nesting(opts) {
  39110. return new _nesting["default"](opts);
  39111. };
  39112. constructors.nesting = nesting;
  39113. var pseudo = function pseudo(opts) {
  39114. return new _pseudo["default"](opts);
  39115. };
  39116. constructors.pseudo = pseudo;
  39117. var root = function root(opts) {
  39118. return new _root["default"](opts);
  39119. };
  39120. constructors.root = root;
  39121. var selector = function selector(opts) {
  39122. return new _selector["default"](opts);
  39123. };
  39124. constructors.selector = selector;
  39125. var string = function string(opts) {
  39126. return new _string["default"](opts);
  39127. };
  39128. constructors.string = string;
  39129. var tag = function tag(opts) {
  39130. return new _tag["default"](opts);
  39131. };
  39132. constructors.tag = tag;
  39133. var universal = function universal(opts) {
  39134. return new _universal["default"](opts);
  39135. };
  39136. constructors.universal = universal;
  39137. var guards = {};
  39138. guards.__esModule = true;
  39139. guards.isNode = isNode;
  39140. guards.isPseudoElement = isPseudoElement;
  39141. guards.isPseudoClass = isPseudoClass;
  39142. guards.isContainer = isContainer;
  39143. guards.isNamespace = isNamespace;
  39144. guards.isUniversal = guards.isTag = guards.isString = guards.isSelector = guards.isRoot = guards.isPseudo = guards.isNesting = guards.isIdentifier = guards.isComment = guards.isCombinator = guards.isClassName = guards.isAttribute = void 0;
  39145. var _types = types;
  39146. var _IS_TYPE;
  39147. var IS_TYPE = (_IS_TYPE = {}, _IS_TYPE[_types.ATTRIBUTE] = true, _IS_TYPE[_types.CLASS] = true, _IS_TYPE[_types.COMBINATOR] = true, _IS_TYPE[_types.COMMENT] = true, _IS_TYPE[_types.ID] = true, _IS_TYPE[_types.NESTING] = true, _IS_TYPE[_types.PSEUDO] = true, _IS_TYPE[_types.ROOT] = true, _IS_TYPE[_types.SELECTOR] = true, _IS_TYPE[_types.STRING] = true, _IS_TYPE[_types.TAG] = true, _IS_TYPE[_types.UNIVERSAL] = true, _IS_TYPE);
  39148. function isNode(node) {
  39149. return typeof node === "object" && IS_TYPE[node.type];
  39150. }
  39151. function isNodeType(type, node) {
  39152. return isNode(node) && node.type === type;
  39153. }
  39154. var isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
  39155. guards.isAttribute = isAttribute;
  39156. var isClassName = isNodeType.bind(null, _types.CLASS);
  39157. guards.isClassName = isClassName;
  39158. var isCombinator = isNodeType.bind(null, _types.COMBINATOR);
  39159. guards.isCombinator = isCombinator;
  39160. var isComment = isNodeType.bind(null, _types.COMMENT);
  39161. guards.isComment = isComment;
  39162. var isIdentifier = isNodeType.bind(null, _types.ID);
  39163. guards.isIdentifier = isIdentifier;
  39164. var isNesting = isNodeType.bind(null, _types.NESTING);
  39165. guards.isNesting = isNesting;
  39166. var isPseudo = isNodeType.bind(null, _types.PSEUDO);
  39167. guards.isPseudo = isPseudo;
  39168. var isRoot = isNodeType.bind(null, _types.ROOT);
  39169. guards.isRoot = isRoot;
  39170. var isSelector = isNodeType.bind(null, _types.SELECTOR);
  39171. guards.isSelector = isSelector;
  39172. var isString = isNodeType.bind(null, _types.STRING);
  39173. guards.isString = isString;
  39174. var isTag = isNodeType.bind(null, _types.TAG);
  39175. guards.isTag = isTag;
  39176. var isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
  39177. guards.isUniversal = isUniversal;
  39178. function isPseudoElement(node) {
  39179. return isPseudo(node) && node.value && (node.value.startsWith("::") || node.value.toLowerCase() === ":before" || node.value.toLowerCase() === ":after" || node.value.toLowerCase() === ":first-letter" || node.value.toLowerCase() === ":first-line");
  39180. }
  39181. function isPseudoClass(node) {
  39182. return isPseudo(node) && !isPseudoElement(node);
  39183. }
  39184. function isContainer(node) {
  39185. return !!(isNode(node) && node.walk);
  39186. }
  39187. function isNamespace(node) {
  39188. return isAttribute(node) || isTag(node);
  39189. }
  39190. (function (exports) {
  39191. exports.__esModule = true;
  39192. var _types = types;
  39193. Object.keys(_types).forEach(function (key) {
  39194. if (key === "default" || key === "__esModule") return;
  39195. if (key in exports && exports[key] === _types[key]) return;
  39196. exports[key] = _types[key];
  39197. });
  39198. var _constructors = constructors;
  39199. Object.keys(_constructors).forEach(function (key) {
  39200. if (key === "default" || key === "__esModule") return;
  39201. if (key in exports && exports[key] === _constructors[key]) return;
  39202. exports[key] = _constructors[key];
  39203. });
  39204. var _guards = guards;
  39205. Object.keys(_guards).forEach(function (key) {
  39206. if (key === "default" || key === "__esModule") return;
  39207. if (key in exports && exports[key] === _guards[key]) return;
  39208. exports[key] = _guards[key];
  39209. });
  39210. } (selectors));
  39211. (function (module, exports) {
  39212. exports.__esModule = true;
  39213. exports["default"] = void 0;
  39214. var _processor = _interopRequireDefault(processorExports);
  39215. var selectors$1 = _interopRequireWildcard(selectors);
  39216. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
  39217. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  39218. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39219. var parser = function parser(processor) {
  39220. return new _processor["default"](processor);
  39221. };
  39222. Object.assign(parser, selectors$1);
  39223. delete parser.__esModule;
  39224. var _default = parser;
  39225. exports["default"] = _default;
  39226. module.exports = exports.default;
  39227. } (dist, distExports));
  39228. var selectorParser = /*@__PURE__*/getDefaultExportFromCjs(distExports);
  39229. const animationNameRE = /^(-\w+-)?animation-name$/;
  39230. const animationRE = /^(-\w+-)?animation$/;
  39231. const scopedPlugin = (id = "") => {
  39232. const keyframes = /* @__PURE__ */ Object.create(null);
  39233. const shortId = id.replace(/^data-v-/, "");
  39234. return {
  39235. postcssPlugin: "vue-sfc-scoped",
  39236. Rule(rule) {
  39237. processRule(id, rule);
  39238. },
  39239. AtRule(node) {
  39240. if (/-?keyframes$/.test(node.name) && !node.params.endsWith(`-${shortId}`)) {
  39241. keyframes[node.params] = node.params = node.params + "-" + shortId;
  39242. }
  39243. },
  39244. OnceExit(root) {
  39245. if (Object.keys(keyframes).length) {
  39246. root.walkDecls((decl) => {
  39247. if (animationNameRE.test(decl.prop)) {
  39248. decl.value = decl.value.split(",").map((v) => keyframes[v.trim()] || v.trim()).join(",");
  39249. }
  39250. if (animationRE.test(decl.prop)) {
  39251. decl.value = decl.value.split(",").map((v) => {
  39252. const vals = v.trim().split(/\s+/);
  39253. const i = vals.findIndex((val) => keyframes[val]);
  39254. if (i !== -1) {
  39255. vals.splice(i, 1, keyframes[vals[i]]);
  39256. return vals.join(" ");
  39257. } else {
  39258. return v;
  39259. }
  39260. }).join(",");
  39261. }
  39262. });
  39263. }
  39264. }
  39265. };
  39266. };
  39267. const processedRules = /* @__PURE__ */ new WeakSet();
  39268. function processRule(id, rule) {
  39269. if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" && /-?keyframes$/.test(rule.parent.name)) {
  39270. return;
  39271. }
  39272. processedRules.add(rule);
  39273. rule.selector = selectorParser((selectorRoot) => {
  39274. selectorRoot.each((selector) => {
  39275. rewriteSelector(id, selector, selectorRoot);
  39276. });
  39277. }).processSync(rule.selector);
  39278. }
  39279. function rewriteSelector(id, selector, selectorRoot, slotted = false) {
  39280. let node = null;
  39281. let shouldInject = true;
  39282. selector.each((n) => {
  39283. if (n.type === "combinator" && (n.value === ">>>" || n.value === "/deep/")) {
  39284. n.value = " ";
  39285. n.spaces.before = n.spaces.after = "";
  39286. warn$1(
  39287. `the >>> and /deep/ combinators have been deprecated. Use :deep() instead.`
  39288. );
  39289. return false;
  39290. }
  39291. if (n.type === "pseudo") {
  39292. const { value } = n;
  39293. if (value === ":deep" || value === "::v-deep") {
  39294. if (n.nodes.length) {
  39295. let last = n;
  39296. n.nodes[0].each((ss) => {
  39297. selector.insertAfter(last, ss);
  39298. last = ss;
  39299. });
  39300. const prev = selector.at(selector.index(n) - 1);
  39301. if (!prev || !isSpaceCombinator(prev)) {
  39302. selector.insertAfter(
  39303. n,
  39304. selectorParser.combinator({
  39305. value: " "
  39306. })
  39307. );
  39308. }
  39309. selector.removeChild(n);
  39310. } else {
  39311. warn$1(
  39312. `::v-deep usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead.`
  39313. );
  39314. const prev = selector.at(selector.index(n) - 1);
  39315. if (prev && isSpaceCombinator(prev)) {
  39316. selector.removeChild(prev);
  39317. }
  39318. selector.removeChild(n);
  39319. }
  39320. return false;
  39321. }
  39322. if (value === ":slotted" || value === "::v-slotted") {
  39323. rewriteSelector(
  39324. id,
  39325. n.nodes[0],
  39326. selectorRoot,
  39327. true
  39328. /* slotted */
  39329. );
  39330. let last = n;
  39331. n.nodes[0].each((ss) => {
  39332. selector.insertAfter(last, ss);
  39333. last = ss;
  39334. });
  39335. selector.removeChild(n);
  39336. shouldInject = false;
  39337. return false;
  39338. }
  39339. if (value === ":global" || value === "::v-global") {
  39340. selectorRoot.insertAfter(selector, n.nodes[0]);
  39341. selectorRoot.removeChild(selector);
  39342. return false;
  39343. }
  39344. }
  39345. if (n.type !== "pseudo" && n.type !== "combinator") {
  39346. node = n;
  39347. }
  39348. });
  39349. if (node) {
  39350. node.spaces.after = "";
  39351. } else {
  39352. selector.first.spaces.before = "";
  39353. }
  39354. if (shouldInject) {
  39355. const idToAdd = slotted ? id + "-s" : id;
  39356. selector.insertAfter(
  39357. // If node is null it means we need to inject [id] at the start
  39358. // insertAfter can handle `null` here
  39359. node,
  39360. selectorParser.attribute({
  39361. attribute: idToAdd,
  39362. value: idToAdd,
  39363. raws: {},
  39364. quoteMark: `"`
  39365. })
  39366. );
  39367. }
  39368. }
  39369. function isSpaceCombinator(node) {
  39370. return node.type === "combinator" && /^\s+$/.test(node.value);
  39371. }
  39372. scopedPlugin.postcss = true;
  39373. var scopedPlugin$1 = scopedPlugin;
  39374. var sourceMap$1 = {};
  39375. var sourceMapGenerator = {};
  39376. var base64Vlq = {};
  39377. var base64$1 = {};
  39378. /* -*- Mode: js; js-indent-level: 2; -*- */
  39379. /*
  39380. * Copyright 2011 Mozilla Foundation and contributors
  39381. * Licensed under the New BSD license. See LICENSE or:
  39382. * http://opensource.org/licenses/BSD-3-Clause
  39383. */
  39384. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  39385. /**
  39386. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  39387. */
  39388. base64$1.encode = function (number) {
  39389. if (0 <= number && number < intToCharMap.length) {
  39390. return intToCharMap[number];
  39391. }
  39392. throw new TypeError("Must be between 0 and 63: " + number);
  39393. };
  39394. /**
  39395. * Decode a single base 64 character code digit to an integer. Returns -1 on
  39396. * failure.
  39397. */
  39398. base64$1.decode = function (charCode) {
  39399. var bigA = 65; // 'A'
  39400. var bigZ = 90; // 'Z'
  39401. var littleA = 97; // 'a'
  39402. var littleZ = 122; // 'z'
  39403. var zero = 48; // '0'
  39404. var nine = 57; // '9'
  39405. var plus = 43; // '+'
  39406. var slash = 47; // '/'
  39407. var littleOffset = 26;
  39408. var numberOffset = 52;
  39409. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  39410. if (bigA <= charCode && charCode <= bigZ) {
  39411. return (charCode - bigA);
  39412. }
  39413. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  39414. if (littleA <= charCode && charCode <= littleZ) {
  39415. return (charCode - littleA + littleOffset);
  39416. }
  39417. // 52 - 61: 0123456789
  39418. if (zero <= charCode && charCode <= nine) {
  39419. return (charCode - zero + numberOffset);
  39420. }
  39421. // 62: +
  39422. if (charCode == plus) {
  39423. return 62;
  39424. }
  39425. // 63: /
  39426. if (charCode == slash) {
  39427. return 63;
  39428. }
  39429. // Invalid base64 digit.
  39430. return -1;
  39431. };
  39432. /* -*- Mode: js; js-indent-level: 2; -*- */
  39433. /*
  39434. * Copyright 2011 Mozilla Foundation and contributors
  39435. * Licensed under the New BSD license. See LICENSE or:
  39436. * http://opensource.org/licenses/BSD-3-Clause
  39437. *
  39438. * Based on the Base 64 VLQ implementation in Closure Compiler:
  39439. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  39440. *
  39441. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  39442. * Redistribution and use in source and binary forms, with or without
  39443. * modification, are permitted provided that the following conditions are
  39444. * met:
  39445. *
  39446. * * Redistributions of source code must retain the above copyright
  39447. * notice, this list of conditions and the following disclaimer.
  39448. * * Redistributions in binary form must reproduce the above
  39449. * copyright notice, this list of conditions and the following
  39450. * disclaimer in the documentation and/or other materials provided
  39451. * with the distribution.
  39452. * * Neither the name of Google Inc. nor the names of its
  39453. * contributors may be used to endorse or promote products derived
  39454. * from this software without specific prior written permission.
  39455. *
  39456. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  39457. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39458. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  39459. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  39460. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39461. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  39462. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  39463. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  39464. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39465. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39466. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39467. */
  39468. var base64 = base64$1;
  39469. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  39470. // length quantities we use in the source map spec, the first bit is the sign,
  39471. // the next four bits are the actual value, and the 6th bit is the
  39472. // continuation bit. The continuation bit tells us whether there are more
  39473. // digits in this value following this digit.
  39474. //
  39475. // Continuation
  39476. // | Sign
  39477. // | |
  39478. // V V
  39479. // 101011
  39480. var VLQ_BASE_SHIFT = 5;
  39481. // binary: 100000
  39482. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  39483. // binary: 011111
  39484. var VLQ_BASE_MASK = VLQ_BASE - 1;
  39485. // binary: 100000
  39486. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  39487. /**
  39488. * Converts from a two-complement value to a value where the sign bit is
  39489. * placed in the least significant bit. For example, as decimals:
  39490. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  39491. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  39492. */
  39493. function toVLQSigned(aValue) {
  39494. return aValue < 0
  39495. ? ((-aValue) << 1) + 1
  39496. : (aValue << 1) + 0;
  39497. }
  39498. /**
  39499. * Converts to a two-complement value from a value where the sign bit is
  39500. * placed in the least significant bit. For example, as decimals:
  39501. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  39502. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  39503. */
  39504. function fromVLQSigned(aValue) {
  39505. var isNegative = (aValue & 1) === 1;
  39506. var shifted = aValue >> 1;
  39507. return isNegative
  39508. ? -shifted
  39509. : shifted;
  39510. }
  39511. /**
  39512. * Returns the base 64 VLQ encoded value.
  39513. */
  39514. base64Vlq.encode = function base64VLQ_encode(aValue) {
  39515. var encoded = "";
  39516. var digit;
  39517. var vlq = toVLQSigned(aValue);
  39518. do {
  39519. digit = vlq & VLQ_BASE_MASK;
  39520. vlq >>>= VLQ_BASE_SHIFT;
  39521. if (vlq > 0) {
  39522. // There are still more digits in this value, so we must make sure the
  39523. // continuation bit is marked.
  39524. digit |= VLQ_CONTINUATION_BIT;
  39525. }
  39526. encoded += base64.encode(digit);
  39527. } while (vlq > 0);
  39528. return encoded;
  39529. };
  39530. /**
  39531. * Decodes the next base 64 VLQ value from the given string and returns the
  39532. * value and the rest of the string via the out parameter.
  39533. */
  39534. base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  39535. var strLen = aStr.length;
  39536. var result = 0;
  39537. var shift = 0;
  39538. var continuation, digit;
  39539. do {
  39540. if (aIndex >= strLen) {
  39541. throw new Error("Expected more digits in base 64 VLQ value.");
  39542. }
  39543. digit = base64.decode(aStr.charCodeAt(aIndex++));
  39544. if (digit === -1) {
  39545. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  39546. }
  39547. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  39548. digit &= VLQ_BASE_MASK;
  39549. result = result + (digit << shift);
  39550. shift += VLQ_BASE_SHIFT;
  39551. } while (continuation);
  39552. aOutParam.value = fromVLQSigned(result);
  39553. aOutParam.rest = aIndex;
  39554. };
  39555. var util$5 = {};
  39556. /* -*- Mode: js; js-indent-level: 2; -*- */
  39557. (function (exports) {
  39558. /*
  39559. * Copyright 2011 Mozilla Foundation and contributors
  39560. * Licensed under the New BSD license. See LICENSE or:
  39561. * http://opensource.org/licenses/BSD-3-Clause
  39562. */
  39563. /**
  39564. * This is a helper function for getting values from parameter/options
  39565. * objects.
  39566. *
  39567. * @param args The object we are extracting values from
  39568. * @param name The name of the property we are getting.
  39569. * @param defaultValue An optional value to return if the property is missing
  39570. * from the object. If this is not specified and the property is missing, an
  39571. * error will be thrown.
  39572. */
  39573. function getArg(aArgs, aName, aDefaultValue) {
  39574. if (aName in aArgs) {
  39575. return aArgs[aName];
  39576. } else if (arguments.length === 3) {
  39577. return aDefaultValue;
  39578. } else {
  39579. throw new Error('"' + aName + '" is a required argument.');
  39580. }
  39581. }
  39582. exports.getArg = getArg;
  39583. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  39584. var dataUrlRegexp = /^data:.+\,.+$/;
  39585. function urlParse(aUrl) {
  39586. var match = aUrl.match(urlRegexp);
  39587. if (!match) {
  39588. return null;
  39589. }
  39590. return {
  39591. scheme: match[1],
  39592. auth: match[2],
  39593. host: match[3],
  39594. port: match[4],
  39595. path: match[5]
  39596. };
  39597. }
  39598. exports.urlParse = urlParse;
  39599. function urlGenerate(aParsedUrl) {
  39600. var url = '';
  39601. if (aParsedUrl.scheme) {
  39602. url += aParsedUrl.scheme + ':';
  39603. }
  39604. url += '//';
  39605. if (aParsedUrl.auth) {
  39606. url += aParsedUrl.auth + '@';
  39607. }
  39608. if (aParsedUrl.host) {
  39609. url += aParsedUrl.host;
  39610. }
  39611. if (aParsedUrl.port) {
  39612. url += ":" + aParsedUrl.port;
  39613. }
  39614. if (aParsedUrl.path) {
  39615. url += aParsedUrl.path;
  39616. }
  39617. return url;
  39618. }
  39619. exports.urlGenerate = urlGenerate;
  39620. /**
  39621. * Normalizes a path, or the path portion of a URL:
  39622. *
  39623. * - Replaces consecutive slashes with one slash.
  39624. * - Removes unnecessary '.' parts.
  39625. * - Removes unnecessary '<dir>/..' parts.
  39626. *
  39627. * Based on code in the Node.js 'path' core module.
  39628. *
  39629. * @param aPath The path or url to normalize.
  39630. */
  39631. function normalize(aPath) {
  39632. var path = aPath;
  39633. var url = urlParse(aPath);
  39634. if (url) {
  39635. if (!url.path) {
  39636. return aPath;
  39637. }
  39638. path = url.path;
  39639. }
  39640. var isAbsolute = exports.isAbsolute(path);
  39641. var parts = path.split(/\/+/);
  39642. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  39643. part = parts[i];
  39644. if (part === '.') {
  39645. parts.splice(i, 1);
  39646. } else if (part === '..') {
  39647. up++;
  39648. } else if (up > 0) {
  39649. if (part === '') {
  39650. // The first part is blank if the path is absolute. Trying to go
  39651. // above the root is a no-op. Therefore we can remove all '..' parts
  39652. // directly after the root.
  39653. parts.splice(i + 1, up);
  39654. up = 0;
  39655. } else {
  39656. parts.splice(i, 2);
  39657. up--;
  39658. }
  39659. }
  39660. }
  39661. path = parts.join('/');
  39662. if (path === '') {
  39663. path = isAbsolute ? '/' : '.';
  39664. }
  39665. if (url) {
  39666. url.path = path;
  39667. return urlGenerate(url);
  39668. }
  39669. return path;
  39670. }
  39671. exports.normalize = normalize;
  39672. /**
  39673. * Joins two paths/URLs.
  39674. *
  39675. * @param aRoot The root path or URL.
  39676. * @param aPath The path or URL to be joined with the root.
  39677. *
  39678. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  39679. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  39680. * first.
  39681. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  39682. * is updated with the result and aRoot is returned. Otherwise the result
  39683. * is returned.
  39684. * - If aPath is absolute, the result is aPath.
  39685. * - Otherwise the two paths are joined with a slash.
  39686. * - Joining for example 'http://' and 'www.example.com' is also supported.
  39687. */
  39688. function join(aRoot, aPath) {
  39689. if (aRoot === "") {
  39690. aRoot = ".";
  39691. }
  39692. if (aPath === "") {
  39693. aPath = ".";
  39694. }
  39695. var aPathUrl = urlParse(aPath);
  39696. var aRootUrl = urlParse(aRoot);
  39697. if (aRootUrl) {
  39698. aRoot = aRootUrl.path || '/';
  39699. }
  39700. // `join(foo, '//www.example.org')`
  39701. if (aPathUrl && !aPathUrl.scheme) {
  39702. if (aRootUrl) {
  39703. aPathUrl.scheme = aRootUrl.scheme;
  39704. }
  39705. return urlGenerate(aPathUrl);
  39706. }
  39707. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  39708. return aPath;
  39709. }
  39710. // `join('http://', 'www.example.com')`
  39711. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  39712. aRootUrl.host = aPath;
  39713. return urlGenerate(aRootUrl);
  39714. }
  39715. var joined = aPath.charAt(0) === '/'
  39716. ? aPath
  39717. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  39718. if (aRootUrl) {
  39719. aRootUrl.path = joined;
  39720. return urlGenerate(aRootUrl);
  39721. }
  39722. return joined;
  39723. }
  39724. exports.join = join;
  39725. exports.isAbsolute = function (aPath) {
  39726. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  39727. };
  39728. /**
  39729. * Make a path relative to a URL or another path.
  39730. *
  39731. * @param aRoot The root path or URL.
  39732. * @param aPath The path or URL to be made relative to aRoot.
  39733. */
  39734. function relative(aRoot, aPath) {
  39735. if (aRoot === "") {
  39736. aRoot = ".";
  39737. }
  39738. aRoot = aRoot.replace(/\/$/, '');
  39739. // It is possible for the path to be above the root. In this case, simply
  39740. // checking whether the root is a prefix of the path won't work. Instead, we
  39741. // need to remove components from the root one by one, until either we find
  39742. // a prefix that fits, or we run out of components to remove.
  39743. var level = 0;
  39744. while (aPath.indexOf(aRoot + '/') !== 0) {
  39745. var index = aRoot.lastIndexOf("/");
  39746. if (index < 0) {
  39747. return aPath;
  39748. }
  39749. // If the only part of the root that is left is the scheme (i.e. http://,
  39750. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  39751. // have exhausted all components, so the path is not relative to the root.
  39752. aRoot = aRoot.slice(0, index);
  39753. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  39754. return aPath;
  39755. }
  39756. ++level;
  39757. }
  39758. // Make sure we add a "../" for each component we removed from the root.
  39759. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  39760. }
  39761. exports.relative = relative;
  39762. var supportsNullProto = (function () {
  39763. var obj = Object.create(null);
  39764. return !('__proto__' in obj);
  39765. }());
  39766. function identity (s) {
  39767. return s;
  39768. }
  39769. /**
  39770. * Because behavior goes wacky when you set `__proto__` on objects, we
  39771. * have to prefix all the strings in our set with an arbitrary character.
  39772. *
  39773. * See https://github.com/mozilla/source-map/pull/31 and
  39774. * https://github.com/mozilla/source-map/issues/30
  39775. *
  39776. * @param String aStr
  39777. */
  39778. function toSetString(aStr) {
  39779. if (isProtoString(aStr)) {
  39780. return '$' + aStr;
  39781. }
  39782. return aStr;
  39783. }
  39784. exports.toSetString = supportsNullProto ? identity : toSetString;
  39785. function fromSetString(aStr) {
  39786. if (isProtoString(aStr)) {
  39787. return aStr.slice(1);
  39788. }
  39789. return aStr;
  39790. }
  39791. exports.fromSetString = supportsNullProto ? identity : fromSetString;
  39792. function isProtoString(s) {
  39793. if (!s) {
  39794. return false;
  39795. }
  39796. var length = s.length;
  39797. if (length < 9 /* "__proto__".length */) {
  39798. return false;
  39799. }
  39800. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  39801. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  39802. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  39803. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  39804. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  39805. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  39806. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  39807. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  39808. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  39809. return false;
  39810. }
  39811. for (var i = length - 10; i >= 0; i--) {
  39812. if (s.charCodeAt(i) !== 36 /* '$' */) {
  39813. return false;
  39814. }
  39815. }
  39816. return true;
  39817. }
  39818. /**
  39819. * Comparator between two mappings where the original positions are compared.
  39820. *
  39821. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  39822. * mappings with the same original source/line/column, but different generated
  39823. * line and column the same. Useful when searching for a mapping with a
  39824. * stubbed out mapping.
  39825. */
  39826. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  39827. var cmp = strcmp(mappingA.source, mappingB.source);
  39828. if (cmp !== 0) {
  39829. return cmp;
  39830. }
  39831. cmp = mappingA.originalLine - mappingB.originalLine;
  39832. if (cmp !== 0) {
  39833. return cmp;
  39834. }
  39835. cmp = mappingA.originalColumn - mappingB.originalColumn;
  39836. if (cmp !== 0 || onlyCompareOriginal) {
  39837. return cmp;
  39838. }
  39839. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  39840. if (cmp !== 0) {
  39841. return cmp;
  39842. }
  39843. cmp = mappingA.generatedLine - mappingB.generatedLine;
  39844. if (cmp !== 0) {
  39845. return cmp;
  39846. }
  39847. return strcmp(mappingA.name, mappingB.name);
  39848. }
  39849. exports.compareByOriginalPositions = compareByOriginalPositions;
  39850. /**
  39851. * Comparator between two mappings with deflated source and name indices where
  39852. * the generated positions are compared.
  39853. *
  39854. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  39855. * mappings with the same generated line and column, but different
  39856. * source/name/original line and column the same. Useful when searching for a
  39857. * mapping with a stubbed out mapping.
  39858. */
  39859. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  39860. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  39861. if (cmp !== 0) {
  39862. return cmp;
  39863. }
  39864. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  39865. if (cmp !== 0 || onlyCompareGenerated) {
  39866. return cmp;
  39867. }
  39868. cmp = strcmp(mappingA.source, mappingB.source);
  39869. if (cmp !== 0) {
  39870. return cmp;
  39871. }
  39872. cmp = mappingA.originalLine - mappingB.originalLine;
  39873. if (cmp !== 0) {
  39874. return cmp;
  39875. }
  39876. cmp = mappingA.originalColumn - mappingB.originalColumn;
  39877. if (cmp !== 0) {
  39878. return cmp;
  39879. }
  39880. return strcmp(mappingA.name, mappingB.name);
  39881. }
  39882. exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  39883. function strcmp(aStr1, aStr2) {
  39884. if (aStr1 === aStr2) {
  39885. return 0;
  39886. }
  39887. if (aStr1 === null) {
  39888. return 1; // aStr2 !== null
  39889. }
  39890. if (aStr2 === null) {
  39891. return -1; // aStr1 !== null
  39892. }
  39893. if (aStr1 > aStr2) {
  39894. return 1;
  39895. }
  39896. return -1;
  39897. }
  39898. /**
  39899. * Comparator between two mappings with inflated source and name strings where
  39900. * the generated positions are compared.
  39901. */
  39902. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  39903. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  39904. if (cmp !== 0) {
  39905. return cmp;
  39906. }
  39907. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  39908. if (cmp !== 0) {
  39909. return cmp;
  39910. }
  39911. cmp = strcmp(mappingA.source, mappingB.source);
  39912. if (cmp !== 0) {
  39913. return cmp;
  39914. }
  39915. cmp = mappingA.originalLine - mappingB.originalLine;
  39916. if (cmp !== 0) {
  39917. return cmp;
  39918. }
  39919. cmp = mappingA.originalColumn - mappingB.originalColumn;
  39920. if (cmp !== 0) {
  39921. return cmp;
  39922. }
  39923. return strcmp(mappingA.name, mappingB.name);
  39924. }
  39925. exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  39926. /**
  39927. * Strip any JSON XSSI avoidance prefix from the string (as documented
  39928. * in the source maps specification), and then parse the string as
  39929. * JSON.
  39930. */
  39931. function parseSourceMapInput(str) {
  39932. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  39933. }
  39934. exports.parseSourceMapInput = parseSourceMapInput;
  39935. /**
  39936. * Compute the URL of a source given the the source root, the source's
  39937. * URL, and the source map's URL.
  39938. */
  39939. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  39940. sourceURL = sourceURL || '';
  39941. if (sourceRoot) {
  39942. // This follows what Chrome does.
  39943. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  39944. sourceRoot += '/';
  39945. }
  39946. // The spec says:
  39947. // Line 4: An optional source root, useful for relocating source
  39948. // files on a server or removing repeated values in the
  39949. // “sources” entry. This value is prepended to the individual
  39950. // entries in the “source” field.
  39951. sourceURL = sourceRoot + sourceURL;
  39952. }
  39953. // Historically, SourceMapConsumer did not take the sourceMapURL as
  39954. // a parameter. This mode is still somewhat supported, which is why
  39955. // this code block is conditional. However, it's preferable to pass
  39956. // the source map URL to SourceMapConsumer, so that this function
  39957. // can implement the source URL resolution algorithm as outlined in
  39958. // the spec. This block is basically the equivalent of:
  39959. // new URL(sourceURL, sourceMapURL).toString()
  39960. // ... except it avoids using URL, which wasn't available in the
  39961. // older releases of node still supported by this library.
  39962. //
  39963. // The spec says:
  39964. // If the sources are not absolute URLs after prepending of the
  39965. // “sourceRoot”, the sources are resolved relative to the
  39966. // SourceMap (like resolving script src in a html document).
  39967. if (sourceMapURL) {
  39968. var parsed = urlParse(sourceMapURL);
  39969. if (!parsed) {
  39970. throw new Error("sourceMapURL could not be parsed");
  39971. }
  39972. if (parsed.path) {
  39973. // Strip the last path component, but keep the "/".
  39974. var index = parsed.path.lastIndexOf('/');
  39975. if (index >= 0) {
  39976. parsed.path = parsed.path.substring(0, index + 1);
  39977. }
  39978. }
  39979. sourceURL = join(urlGenerate(parsed), sourceURL);
  39980. }
  39981. return normalize(sourceURL);
  39982. }
  39983. exports.computeSourceURL = computeSourceURL;
  39984. } (util$5));
  39985. var arraySet = {};
  39986. /* -*- Mode: js; js-indent-level: 2; -*- */
  39987. /*
  39988. * Copyright 2011 Mozilla Foundation and contributors
  39989. * Licensed under the New BSD license. See LICENSE or:
  39990. * http://opensource.org/licenses/BSD-3-Clause
  39991. */
  39992. var util$4 = util$5;
  39993. var has = Object.prototype.hasOwnProperty;
  39994. var hasNativeMap = typeof Map !== "undefined";
  39995. /**
  39996. * A data structure which is a combination of an array and a set. Adding a new
  39997. * member is O(1), testing for membership is O(1), and finding the index of an
  39998. * element is O(1). Removing elements from the set is not supported. Only
  39999. * strings are supported for membership.
  40000. */
  40001. function ArraySet$2() {
  40002. this._array = [];
  40003. this._set = hasNativeMap ? new Map() : Object.create(null);
  40004. }
  40005. /**
  40006. * Static method for creating ArraySet instances from an existing array.
  40007. */
  40008. ArraySet$2.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  40009. var set = new ArraySet$2();
  40010. for (var i = 0, len = aArray.length; i < len; i++) {
  40011. set.add(aArray[i], aAllowDuplicates);
  40012. }
  40013. return set;
  40014. };
  40015. /**
  40016. * Return how many unique items are in this ArraySet. If duplicates have been
  40017. * added, than those do not count towards the size.
  40018. *
  40019. * @returns Number
  40020. */
  40021. ArraySet$2.prototype.size = function ArraySet_size() {
  40022. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  40023. };
  40024. /**
  40025. * Add the given string to this set.
  40026. *
  40027. * @param String aStr
  40028. */
  40029. ArraySet$2.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  40030. var sStr = hasNativeMap ? aStr : util$4.toSetString(aStr);
  40031. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  40032. var idx = this._array.length;
  40033. if (!isDuplicate || aAllowDuplicates) {
  40034. this._array.push(aStr);
  40035. }
  40036. if (!isDuplicate) {
  40037. if (hasNativeMap) {
  40038. this._set.set(aStr, idx);
  40039. } else {
  40040. this._set[sStr] = idx;
  40041. }
  40042. }
  40043. };
  40044. /**
  40045. * Is the given string a member of this set?
  40046. *
  40047. * @param String aStr
  40048. */
  40049. ArraySet$2.prototype.has = function ArraySet_has(aStr) {
  40050. if (hasNativeMap) {
  40051. return this._set.has(aStr);
  40052. } else {
  40053. var sStr = util$4.toSetString(aStr);
  40054. return has.call(this._set, sStr);
  40055. }
  40056. };
  40057. /**
  40058. * What is the index of the given string in the array?
  40059. *
  40060. * @param String aStr
  40061. */
  40062. ArraySet$2.prototype.indexOf = function ArraySet_indexOf(aStr) {
  40063. if (hasNativeMap) {
  40064. var idx = this._set.get(aStr);
  40065. if (idx >= 0) {
  40066. return idx;
  40067. }
  40068. } else {
  40069. var sStr = util$4.toSetString(aStr);
  40070. if (has.call(this._set, sStr)) {
  40071. return this._set[sStr];
  40072. }
  40073. }
  40074. throw new Error('"' + aStr + '" is not in the set.');
  40075. };
  40076. /**
  40077. * What is the element at the given index?
  40078. *
  40079. * @param Number aIdx
  40080. */
  40081. ArraySet$2.prototype.at = function ArraySet_at(aIdx) {
  40082. if (aIdx >= 0 && aIdx < this._array.length) {
  40083. return this._array[aIdx];
  40084. }
  40085. throw new Error('No element indexed by ' + aIdx);
  40086. };
  40087. /**
  40088. * Returns the array representation of this set (which has the proper indices
  40089. * indicated by indexOf). Note that this is a copy of the internal array used
  40090. * for storing the members so that no one can mess with internal state.
  40091. */
  40092. ArraySet$2.prototype.toArray = function ArraySet_toArray() {
  40093. return this._array.slice();
  40094. };
  40095. arraySet.ArraySet = ArraySet$2;
  40096. var mappingList = {};
  40097. /* -*- Mode: js; js-indent-level: 2; -*- */
  40098. /*
  40099. * Copyright 2014 Mozilla Foundation and contributors
  40100. * Licensed under the New BSD license. See LICENSE or:
  40101. * http://opensource.org/licenses/BSD-3-Clause
  40102. */
  40103. var util$3 = util$5;
  40104. /**
  40105. * Determine whether mappingB is after mappingA with respect to generated
  40106. * position.
  40107. */
  40108. function generatedPositionAfter(mappingA, mappingB) {
  40109. // Optimized for most common case
  40110. var lineA = mappingA.generatedLine;
  40111. var lineB = mappingB.generatedLine;
  40112. var columnA = mappingA.generatedColumn;
  40113. var columnB = mappingB.generatedColumn;
  40114. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  40115. util$3.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  40116. }
  40117. /**
  40118. * A data structure to provide a sorted view of accumulated mappings in a
  40119. * performance conscious manner. It trades a neglibable overhead in general
  40120. * case for a large speedup in case of mappings being added in order.
  40121. */
  40122. function MappingList$1() {
  40123. this._array = [];
  40124. this._sorted = true;
  40125. // Serves as infimum
  40126. this._last = {generatedLine: -1, generatedColumn: 0};
  40127. }
  40128. /**
  40129. * Iterate through internal items. This method takes the same arguments that
  40130. * `Array.prototype.forEach` takes.
  40131. *
  40132. * NOTE: The order of the mappings is NOT guaranteed.
  40133. */
  40134. MappingList$1.prototype.unsortedForEach =
  40135. function MappingList_forEach(aCallback, aThisArg) {
  40136. this._array.forEach(aCallback, aThisArg);
  40137. };
  40138. /**
  40139. * Add the given source mapping.
  40140. *
  40141. * @param Object aMapping
  40142. */
  40143. MappingList$1.prototype.add = function MappingList_add(aMapping) {
  40144. if (generatedPositionAfter(this._last, aMapping)) {
  40145. this._last = aMapping;
  40146. this._array.push(aMapping);
  40147. } else {
  40148. this._sorted = false;
  40149. this._array.push(aMapping);
  40150. }
  40151. };
  40152. /**
  40153. * Returns the flat, sorted array of mappings. The mappings are sorted by
  40154. * generated position.
  40155. *
  40156. * WARNING: This method returns internal data without copying, for
  40157. * performance. The return value must NOT be mutated, and should be treated as
  40158. * an immutable borrow. If you want to take ownership, you must make your own
  40159. * copy.
  40160. */
  40161. MappingList$1.prototype.toArray = function MappingList_toArray() {
  40162. if (!this._sorted) {
  40163. this._array.sort(util$3.compareByGeneratedPositionsInflated);
  40164. this._sorted = true;
  40165. }
  40166. return this._array;
  40167. };
  40168. mappingList.MappingList = MappingList$1;
  40169. /* -*- Mode: js; js-indent-level: 2; -*- */
  40170. /*
  40171. * Copyright 2011 Mozilla Foundation and contributors
  40172. * Licensed under the New BSD license. See LICENSE or:
  40173. * http://opensource.org/licenses/BSD-3-Clause
  40174. */
  40175. var base64VLQ$1 = base64Vlq;
  40176. var util$2 = util$5;
  40177. var ArraySet$1 = arraySet.ArraySet;
  40178. var MappingList = mappingList.MappingList;
  40179. /**
  40180. * An instance of the SourceMapGenerator represents a source map which is
  40181. * being built incrementally. You may pass an object with the following
  40182. * properties:
  40183. *
  40184. * - file: The filename of the generated source.
  40185. * - sourceRoot: A root for all relative URLs in this source map.
  40186. */
  40187. function SourceMapGenerator$2(aArgs) {
  40188. if (!aArgs) {
  40189. aArgs = {};
  40190. }
  40191. this._file = util$2.getArg(aArgs, 'file', null);
  40192. this._sourceRoot = util$2.getArg(aArgs, 'sourceRoot', null);
  40193. this._skipValidation = util$2.getArg(aArgs, 'skipValidation', false);
  40194. this._sources = new ArraySet$1();
  40195. this._names = new ArraySet$1();
  40196. this._mappings = new MappingList();
  40197. this._sourcesContents = null;
  40198. }
  40199. SourceMapGenerator$2.prototype._version = 3;
  40200. /**
  40201. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  40202. *
  40203. * @param aSourceMapConsumer The SourceMap.
  40204. */
  40205. SourceMapGenerator$2.fromSourceMap =
  40206. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  40207. var sourceRoot = aSourceMapConsumer.sourceRoot;
  40208. var generator = new SourceMapGenerator$2({
  40209. file: aSourceMapConsumer.file,
  40210. sourceRoot: sourceRoot
  40211. });
  40212. aSourceMapConsumer.eachMapping(function (mapping) {
  40213. var newMapping = {
  40214. generated: {
  40215. line: mapping.generatedLine,
  40216. column: mapping.generatedColumn
  40217. }
  40218. };
  40219. if (mapping.source != null) {
  40220. newMapping.source = mapping.source;
  40221. if (sourceRoot != null) {
  40222. newMapping.source = util$2.relative(sourceRoot, newMapping.source);
  40223. }
  40224. newMapping.original = {
  40225. line: mapping.originalLine,
  40226. column: mapping.originalColumn
  40227. };
  40228. if (mapping.name != null) {
  40229. newMapping.name = mapping.name;
  40230. }
  40231. }
  40232. generator.addMapping(newMapping);
  40233. });
  40234. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  40235. var sourceRelative = sourceFile;
  40236. if (sourceRoot !== null) {
  40237. sourceRelative = util$2.relative(sourceRoot, sourceFile);
  40238. }
  40239. if (!generator._sources.has(sourceRelative)) {
  40240. generator._sources.add(sourceRelative);
  40241. }
  40242. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  40243. if (content != null) {
  40244. generator.setSourceContent(sourceFile, content);
  40245. }
  40246. });
  40247. return generator;
  40248. };
  40249. /**
  40250. * Add a single mapping from original source line and column to the generated
  40251. * source's line and column for this source map being created. The mapping
  40252. * object should have the following properties:
  40253. *
  40254. * - generated: An object with the generated line and column positions.
  40255. * - original: An object with the original line and column positions.
  40256. * - source: The original source file (relative to the sourceRoot).
  40257. * - name: An optional original token name for this mapping.
  40258. */
  40259. SourceMapGenerator$2.prototype.addMapping =
  40260. function SourceMapGenerator_addMapping(aArgs) {
  40261. var generated = util$2.getArg(aArgs, 'generated');
  40262. var original = util$2.getArg(aArgs, 'original', null);
  40263. var source = util$2.getArg(aArgs, 'source', null);
  40264. var name = util$2.getArg(aArgs, 'name', null);
  40265. if (!this._skipValidation) {
  40266. this._validateMapping(generated, original, source, name);
  40267. }
  40268. if (source != null) {
  40269. source = String(source);
  40270. if (!this._sources.has(source)) {
  40271. this._sources.add(source);
  40272. }
  40273. }
  40274. if (name != null) {
  40275. name = String(name);
  40276. if (!this._names.has(name)) {
  40277. this._names.add(name);
  40278. }
  40279. }
  40280. this._mappings.add({
  40281. generatedLine: generated.line,
  40282. generatedColumn: generated.column,
  40283. originalLine: original != null && original.line,
  40284. originalColumn: original != null && original.column,
  40285. source: source,
  40286. name: name
  40287. });
  40288. };
  40289. /**
  40290. * Set the source content for a source file.
  40291. */
  40292. SourceMapGenerator$2.prototype.setSourceContent =
  40293. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  40294. var source = aSourceFile;
  40295. if (this._sourceRoot != null) {
  40296. source = util$2.relative(this._sourceRoot, source);
  40297. }
  40298. if (aSourceContent != null) {
  40299. // Add the source content to the _sourcesContents map.
  40300. // Create a new _sourcesContents map if the property is null.
  40301. if (!this._sourcesContents) {
  40302. this._sourcesContents = Object.create(null);
  40303. }
  40304. this._sourcesContents[util$2.toSetString(source)] = aSourceContent;
  40305. } else if (this._sourcesContents) {
  40306. // Remove the source file from the _sourcesContents map.
  40307. // If the _sourcesContents map is empty, set the property to null.
  40308. delete this._sourcesContents[util$2.toSetString(source)];
  40309. if (Object.keys(this._sourcesContents).length === 0) {
  40310. this._sourcesContents = null;
  40311. }
  40312. }
  40313. };
  40314. /**
  40315. * Applies the mappings of a sub-source-map for a specific source file to the
  40316. * source map being generated. Each mapping to the supplied source file is
  40317. * rewritten using the supplied source map. Note: The resolution for the
  40318. * resulting mappings is the minimium of this map and the supplied map.
  40319. *
  40320. * @param aSourceMapConsumer The source map to be applied.
  40321. * @param aSourceFile Optional. The filename of the source file.
  40322. * If omitted, SourceMapConsumer's file property will be used.
  40323. * @param aSourceMapPath Optional. The dirname of the path to the source map
  40324. * to be applied. If relative, it is relative to the SourceMapConsumer.
  40325. * This parameter is needed when the two source maps aren't in the same
  40326. * directory, and the source map to be applied contains relative source
  40327. * paths. If so, those relative source paths need to be rewritten
  40328. * relative to the SourceMapGenerator.
  40329. */
  40330. SourceMapGenerator$2.prototype.applySourceMap =
  40331. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  40332. var sourceFile = aSourceFile;
  40333. // If aSourceFile is omitted, we will use the file property of the SourceMap
  40334. if (aSourceFile == null) {
  40335. if (aSourceMapConsumer.file == null) {
  40336. throw new Error(
  40337. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  40338. 'or the source map\'s "file" property. Both were omitted.'
  40339. );
  40340. }
  40341. sourceFile = aSourceMapConsumer.file;
  40342. }
  40343. var sourceRoot = this._sourceRoot;
  40344. // Make "sourceFile" relative if an absolute Url is passed.
  40345. if (sourceRoot != null) {
  40346. sourceFile = util$2.relative(sourceRoot, sourceFile);
  40347. }
  40348. // Applying the SourceMap can add and remove items from the sources and
  40349. // the names array.
  40350. var newSources = new ArraySet$1();
  40351. var newNames = new ArraySet$1();
  40352. // Find mappings for the "sourceFile"
  40353. this._mappings.unsortedForEach(function (mapping) {
  40354. if (mapping.source === sourceFile && mapping.originalLine != null) {
  40355. // Check if it can be mapped by the source map, then update the mapping.
  40356. var original = aSourceMapConsumer.originalPositionFor({
  40357. line: mapping.originalLine,
  40358. column: mapping.originalColumn
  40359. });
  40360. if (original.source != null) {
  40361. // Copy mapping
  40362. mapping.source = original.source;
  40363. if (aSourceMapPath != null) {
  40364. mapping.source = util$2.join(aSourceMapPath, mapping.source);
  40365. }
  40366. if (sourceRoot != null) {
  40367. mapping.source = util$2.relative(sourceRoot, mapping.source);
  40368. }
  40369. mapping.originalLine = original.line;
  40370. mapping.originalColumn = original.column;
  40371. if (original.name != null) {
  40372. mapping.name = original.name;
  40373. }
  40374. }
  40375. }
  40376. var source = mapping.source;
  40377. if (source != null && !newSources.has(source)) {
  40378. newSources.add(source);
  40379. }
  40380. var name = mapping.name;
  40381. if (name != null && !newNames.has(name)) {
  40382. newNames.add(name);
  40383. }
  40384. }, this);
  40385. this._sources = newSources;
  40386. this._names = newNames;
  40387. // Copy sourcesContents of applied map.
  40388. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  40389. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  40390. if (content != null) {
  40391. if (aSourceMapPath != null) {
  40392. sourceFile = util$2.join(aSourceMapPath, sourceFile);
  40393. }
  40394. if (sourceRoot != null) {
  40395. sourceFile = util$2.relative(sourceRoot, sourceFile);
  40396. }
  40397. this.setSourceContent(sourceFile, content);
  40398. }
  40399. }, this);
  40400. };
  40401. /**
  40402. * A mapping can have one of the three levels of data:
  40403. *
  40404. * 1. Just the generated position.
  40405. * 2. The Generated position, original position, and original source.
  40406. * 3. Generated and original position, original source, as well as a name
  40407. * token.
  40408. *
  40409. * To maintain consistency, we validate that any new mapping being added falls
  40410. * in to one of these categories.
  40411. */
  40412. SourceMapGenerator$2.prototype._validateMapping =
  40413. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  40414. aName) {
  40415. // When aOriginal is truthy but has empty values for .line and .column,
  40416. // it is most likely a programmer error. In this case we throw a very
  40417. // specific error message to try to guide them the right way.
  40418. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  40419. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  40420. throw new Error(
  40421. 'original.line and original.column are not numbers -- you probably meant to omit ' +
  40422. 'the original mapping entirely and only map the generated position. If so, pass ' +
  40423. 'null for the original mapping instead of an object with empty or null values.'
  40424. );
  40425. }
  40426. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  40427. && aGenerated.line > 0 && aGenerated.column >= 0
  40428. && !aOriginal && !aSource && !aName) {
  40429. // Case 1.
  40430. return;
  40431. }
  40432. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  40433. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  40434. && aGenerated.line > 0 && aGenerated.column >= 0
  40435. && aOriginal.line > 0 && aOriginal.column >= 0
  40436. && aSource) {
  40437. // Cases 2 and 3.
  40438. return;
  40439. }
  40440. else {
  40441. throw new Error('Invalid mapping: ' + JSON.stringify({
  40442. generated: aGenerated,
  40443. source: aSource,
  40444. original: aOriginal,
  40445. name: aName
  40446. }));
  40447. }
  40448. };
  40449. /**
  40450. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  40451. * specified by the source map format.
  40452. */
  40453. SourceMapGenerator$2.prototype._serializeMappings =
  40454. function SourceMapGenerator_serializeMappings() {
  40455. var previousGeneratedColumn = 0;
  40456. var previousGeneratedLine = 1;
  40457. var previousOriginalColumn = 0;
  40458. var previousOriginalLine = 0;
  40459. var previousName = 0;
  40460. var previousSource = 0;
  40461. var result = '';
  40462. var next;
  40463. var mapping;
  40464. var nameIdx;
  40465. var sourceIdx;
  40466. var mappings = this._mappings.toArray();
  40467. for (var i = 0, len = mappings.length; i < len; i++) {
  40468. mapping = mappings[i];
  40469. next = '';
  40470. if (mapping.generatedLine !== previousGeneratedLine) {
  40471. previousGeneratedColumn = 0;
  40472. while (mapping.generatedLine !== previousGeneratedLine) {
  40473. next += ';';
  40474. previousGeneratedLine++;
  40475. }
  40476. }
  40477. else {
  40478. if (i > 0) {
  40479. if (!util$2.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  40480. continue;
  40481. }
  40482. next += ',';
  40483. }
  40484. }
  40485. next += base64VLQ$1.encode(mapping.generatedColumn
  40486. - previousGeneratedColumn);
  40487. previousGeneratedColumn = mapping.generatedColumn;
  40488. if (mapping.source != null) {
  40489. sourceIdx = this._sources.indexOf(mapping.source);
  40490. next += base64VLQ$1.encode(sourceIdx - previousSource);
  40491. previousSource = sourceIdx;
  40492. // lines are stored 0-based in SourceMap spec version 3
  40493. next += base64VLQ$1.encode(mapping.originalLine - 1
  40494. - previousOriginalLine);
  40495. previousOriginalLine = mapping.originalLine - 1;
  40496. next += base64VLQ$1.encode(mapping.originalColumn
  40497. - previousOriginalColumn);
  40498. previousOriginalColumn = mapping.originalColumn;
  40499. if (mapping.name != null) {
  40500. nameIdx = this._names.indexOf(mapping.name);
  40501. next += base64VLQ$1.encode(nameIdx - previousName);
  40502. previousName = nameIdx;
  40503. }
  40504. }
  40505. result += next;
  40506. }
  40507. return result;
  40508. };
  40509. SourceMapGenerator$2.prototype._generateSourcesContent =
  40510. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  40511. return aSources.map(function (source) {
  40512. if (!this._sourcesContents) {
  40513. return null;
  40514. }
  40515. if (aSourceRoot != null) {
  40516. source = util$2.relative(aSourceRoot, source);
  40517. }
  40518. var key = util$2.toSetString(source);
  40519. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  40520. ? this._sourcesContents[key]
  40521. : null;
  40522. }, this);
  40523. };
  40524. /**
  40525. * Externalize the source map.
  40526. */
  40527. SourceMapGenerator$2.prototype.toJSON =
  40528. function SourceMapGenerator_toJSON() {
  40529. var map = {
  40530. version: this._version,
  40531. sources: this._sources.toArray(),
  40532. names: this._names.toArray(),
  40533. mappings: this._serializeMappings()
  40534. };
  40535. if (this._file != null) {
  40536. map.file = this._file;
  40537. }
  40538. if (this._sourceRoot != null) {
  40539. map.sourceRoot = this._sourceRoot;
  40540. }
  40541. if (this._sourcesContents) {
  40542. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  40543. }
  40544. return map;
  40545. };
  40546. /**
  40547. * Render the source map being generated to a string.
  40548. */
  40549. SourceMapGenerator$2.prototype.toString =
  40550. function SourceMapGenerator_toString() {
  40551. return JSON.stringify(this.toJSON());
  40552. };
  40553. sourceMapGenerator.SourceMapGenerator = SourceMapGenerator$2;
  40554. var sourceMapConsumer = {};
  40555. var binarySearch$1 = {};
  40556. /* -*- Mode: js; js-indent-level: 2; -*- */
  40557. (function (exports) {
  40558. /*
  40559. * Copyright 2011 Mozilla Foundation and contributors
  40560. * Licensed under the New BSD license. See LICENSE or:
  40561. * http://opensource.org/licenses/BSD-3-Clause
  40562. */
  40563. exports.GREATEST_LOWER_BOUND = 1;
  40564. exports.LEAST_UPPER_BOUND = 2;
  40565. /**
  40566. * Recursive implementation of binary search.
  40567. *
  40568. * @param aLow Indices here and lower do not contain the needle.
  40569. * @param aHigh Indices here and higher do not contain the needle.
  40570. * @param aNeedle The element being searched for.
  40571. * @param aHaystack The non-empty array being searched.
  40572. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  40573. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  40574. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  40575. * closest element that is smaller than or greater than the one we are
  40576. * searching for, respectively, if the exact element cannot be found.
  40577. */
  40578. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  40579. // This function terminates when one of the following is true:
  40580. //
  40581. // 1. We find the exact element we are looking for.
  40582. //
  40583. // 2. We did not find the exact element, but we can return the index of
  40584. // the next-closest element.
  40585. //
  40586. // 3. We did not find the exact element, and there is no next-closest
  40587. // element than the one we are searching for, so we return -1.
  40588. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  40589. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  40590. if (cmp === 0) {
  40591. // Found the element we are looking for.
  40592. return mid;
  40593. }
  40594. else if (cmp > 0) {
  40595. // Our needle is greater than aHaystack[mid].
  40596. if (aHigh - mid > 1) {
  40597. // The element is in the upper half.
  40598. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  40599. }
  40600. // The exact needle element was not found in this haystack. Determine if
  40601. // we are in termination case (3) or (2) and return the appropriate thing.
  40602. if (aBias == exports.LEAST_UPPER_BOUND) {
  40603. return aHigh < aHaystack.length ? aHigh : -1;
  40604. } else {
  40605. return mid;
  40606. }
  40607. }
  40608. else {
  40609. // Our needle is less than aHaystack[mid].
  40610. if (mid - aLow > 1) {
  40611. // The element is in the lower half.
  40612. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  40613. }
  40614. // we are in termination case (3) or (2) and return the appropriate thing.
  40615. if (aBias == exports.LEAST_UPPER_BOUND) {
  40616. return mid;
  40617. } else {
  40618. return aLow < 0 ? -1 : aLow;
  40619. }
  40620. }
  40621. }
  40622. /**
  40623. * This is an implementation of binary search which will always try and return
  40624. * the index of the closest element if there is no exact hit. This is because
  40625. * mappings between original and generated line/col pairs are single points,
  40626. * and there is an implicit region between each of them, so a miss just means
  40627. * that you aren't on the very start of a region.
  40628. *
  40629. * @param aNeedle The element you are looking for.
  40630. * @param aHaystack The array that is being searched.
  40631. * @param aCompare A function which takes the needle and an element in the
  40632. * array and returns -1, 0, or 1 depending on whether the needle is less
  40633. * than, equal to, or greater than the element, respectively.
  40634. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  40635. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  40636. * closest element that is smaller than or greater than the one we are
  40637. * searching for, respectively, if the exact element cannot be found.
  40638. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  40639. */
  40640. exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  40641. if (aHaystack.length === 0) {
  40642. return -1;
  40643. }
  40644. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  40645. aCompare, aBias || exports.GREATEST_LOWER_BOUND);
  40646. if (index < 0) {
  40647. return -1;
  40648. }
  40649. // We have found either the exact element, or the next-closest element than
  40650. // the one we are searching for. However, there may be more than one such
  40651. // element. Make sure we always return the smallest of these.
  40652. while (index - 1 >= 0) {
  40653. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  40654. break;
  40655. }
  40656. --index;
  40657. }
  40658. return index;
  40659. };
  40660. } (binarySearch$1));
  40661. var quickSort$1 = {};
  40662. /* -*- Mode: js; js-indent-level: 2; -*- */
  40663. /*
  40664. * Copyright 2011 Mozilla Foundation and contributors
  40665. * Licensed under the New BSD license. See LICENSE or:
  40666. * http://opensource.org/licenses/BSD-3-Clause
  40667. */
  40668. // It turns out that some (most?) JavaScript engines don't self-host
  40669. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  40670. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  40671. // custom comparator function, calling back and forth between the VM's C++ and
  40672. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  40673. // worse generated code for the comparator function than would be optimal. In
  40674. // fact, when sorting with a comparator, these costs outweigh the benefits of
  40675. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  40676. // a ~3500ms mean speed-up in `bench/bench.html`.
  40677. /**
  40678. * Swap the elements indexed by `x` and `y` in the array `ary`.
  40679. *
  40680. * @param {Array} ary
  40681. * The array.
  40682. * @param {Number} x
  40683. * The index of the first item.
  40684. * @param {Number} y
  40685. * The index of the second item.
  40686. */
  40687. function swap(ary, x, y) {
  40688. var temp = ary[x];
  40689. ary[x] = ary[y];
  40690. ary[y] = temp;
  40691. }
  40692. /**
  40693. * Returns a random integer within the range `low .. high` inclusive.
  40694. *
  40695. * @param {Number} low
  40696. * The lower bound on the range.
  40697. * @param {Number} high
  40698. * The upper bound on the range.
  40699. */
  40700. function randomIntInRange(low, high) {
  40701. return Math.round(low + (Math.random() * (high - low)));
  40702. }
  40703. /**
  40704. * The Quick Sort algorithm.
  40705. *
  40706. * @param {Array} ary
  40707. * An array to sort.
  40708. * @param {function} comparator
  40709. * Function to use to compare two items.
  40710. * @param {Number} p
  40711. * Start index of the array
  40712. * @param {Number} r
  40713. * End index of the array
  40714. */
  40715. function doQuickSort(ary, comparator, p, r) {
  40716. // If our lower bound is less than our upper bound, we (1) partition the
  40717. // array into two pieces and (2) recurse on each half. If it is not, this is
  40718. // the empty array and our base case.
  40719. if (p < r) {
  40720. // (1) Partitioning.
  40721. //
  40722. // The partitioning chooses a pivot between `p` and `r` and moves all
  40723. // elements that are less than or equal to the pivot to the before it, and
  40724. // all the elements that are greater than it after it. The effect is that
  40725. // once partition is done, the pivot is in the exact place it will be when
  40726. // the array is put in sorted order, and it will not need to be moved
  40727. // again. This runs in O(n) time.
  40728. // Always choose a random pivot so that an input array which is reverse
  40729. // sorted does not cause O(n^2) running time.
  40730. var pivotIndex = randomIntInRange(p, r);
  40731. var i = p - 1;
  40732. swap(ary, pivotIndex, r);
  40733. var pivot = ary[r];
  40734. // Immediately after `j` is incremented in this loop, the following hold
  40735. // true:
  40736. //
  40737. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  40738. //
  40739. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  40740. for (var j = p; j < r; j++) {
  40741. if (comparator(ary[j], pivot) <= 0) {
  40742. i += 1;
  40743. swap(ary, i, j);
  40744. }
  40745. }
  40746. swap(ary, i + 1, j);
  40747. var q = i + 1;
  40748. // (2) Recurse on each half.
  40749. doQuickSort(ary, comparator, p, q - 1);
  40750. doQuickSort(ary, comparator, q + 1, r);
  40751. }
  40752. }
  40753. /**
  40754. * Sort the given array in-place with the given comparator function.
  40755. *
  40756. * @param {Array} ary
  40757. * An array to sort.
  40758. * @param {function} comparator
  40759. * Function to use to compare two items.
  40760. */
  40761. quickSort$1.quickSort = function (ary, comparator) {
  40762. doQuickSort(ary, comparator, 0, ary.length - 1);
  40763. };
  40764. /* -*- Mode: js; js-indent-level: 2; -*- */
  40765. /*
  40766. * Copyright 2011 Mozilla Foundation and contributors
  40767. * Licensed under the New BSD license. See LICENSE or:
  40768. * http://opensource.org/licenses/BSD-3-Clause
  40769. */
  40770. var util$1 = util$5;
  40771. var binarySearch = binarySearch$1;
  40772. var ArraySet = arraySet.ArraySet;
  40773. var base64VLQ = base64Vlq;
  40774. var quickSort = quickSort$1.quickSort;
  40775. function SourceMapConsumer$1(aSourceMap, aSourceMapURL) {
  40776. var sourceMap = aSourceMap;
  40777. if (typeof aSourceMap === 'string') {
  40778. sourceMap = util$1.parseSourceMapInput(aSourceMap);
  40779. }
  40780. return sourceMap.sections != null
  40781. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  40782. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  40783. }
  40784. SourceMapConsumer$1.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  40785. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  40786. };
  40787. /**
  40788. * The version of the source mapping spec that we are consuming.
  40789. */
  40790. SourceMapConsumer$1.prototype._version = 3;
  40791. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  40792. // parsed mapping coordinates from the source map's "mappings" attribute. They
  40793. // are lazily instantiated, accessed via the `_generatedMappings` and
  40794. // `_originalMappings` getters respectively, and we only parse the mappings
  40795. // and create these arrays once queried for a source location. We jump through
  40796. // these hoops because there can be many thousands of mappings, and parsing
  40797. // them is expensive, so we only want to do it if we must.
  40798. //
  40799. // Each object in the arrays is of the form:
  40800. //
  40801. // {
  40802. // generatedLine: The line number in the generated code,
  40803. // generatedColumn: The column number in the generated code,
  40804. // source: The path to the original source file that generated this
  40805. // chunk of code,
  40806. // originalLine: The line number in the original source that
  40807. // corresponds to this chunk of generated code,
  40808. // originalColumn: The column number in the original source that
  40809. // corresponds to this chunk of generated code,
  40810. // name: The name of the original symbol which generated this chunk of
  40811. // code.
  40812. // }
  40813. //
  40814. // All properties except for `generatedLine` and `generatedColumn` can be
  40815. // `null`.
  40816. //
  40817. // `_generatedMappings` is ordered by the generated positions.
  40818. //
  40819. // `_originalMappings` is ordered by the original positions.
  40820. SourceMapConsumer$1.prototype.__generatedMappings = null;
  40821. Object.defineProperty(SourceMapConsumer$1.prototype, '_generatedMappings', {
  40822. configurable: true,
  40823. enumerable: true,
  40824. get: function () {
  40825. if (!this.__generatedMappings) {
  40826. this._parseMappings(this._mappings, this.sourceRoot);
  40827. }
  40828. return this.__generatedMappings;
  40829. }
  40830. });
  40831. SourceMapConsumer$1.prototype.__originalMappings = null;
  40832. Object.defineProperty(SourceMapConsumer$1.prototype, '_originalMappings', {
  40833. configurable: true,
  40834. enumerable: true,
  40835. get: function () {
  40836. if (!this.__originalMappings) {
  40837. this._parseMappings(this._mappings, this.sourceRoot);
  40838. }
  40839. return this.__originalMappings;
  40840. }
  40841. });
  40842. SourceMapConsumer$1.prototype._charIsMappingSeparator =
  40843. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  40844. var c = aStr.charAt(index);
  40845. return c === ";" || c === ",";
  40846. };
  40847. /**
  40848. * Parse the mappings in a string in to a data structure which we can easily
  40849. * query (the ordered arrays in the `this.__generatedMappings` and
  40850. * `this.__originalMappings` properties).
  40851. */
  40852. SourceMapConsumer$1.prototype._parseMappings =
  40853. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  40854. throw new Error("Subclasses must implement _parseMappings");
  40855. };
  40856. SourceMapConsumer$1.GENERATED_ORDER = 1;
  40857. SourceMapConsumer$1.ORIGINAL_ORDER = 2;
  40858. SourceMapConsumer$1.GREATEST_LOWER_BOUND = 1;
  40859. SourceMapConsumer$1.LEAST_UPPER_BOUND = 2;
  40860. /**
  40861. * Iterate over each mapping between an original source/line/column and a
  40862. * generated line/column in this source map.
  40863. *
  40864. * @param Function aCallback
  40865. * The function that is called with each mapping.
  40866. * @param Object aContext
  40867. * Optional. If specified, this object will be the value of `this` every
  40868. * time that `aCallback` is called.
  40869. * @param aOrder
  40870. * Either `SourceMapConsumer.GENERATED_ORDER` or
  40871. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  40872. * iterate over the mappings sorted by the generated file's line/column
  40873. * order or the original's source/line/column order, respectively. Defaults to
  40874. * `SourceMapConsumer.GENERATED_ORDER`.
  40875. */
  40876. SourceMapConsumer$1.prototype.eachMapping =
  40877. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  40878. var context = aContext || null;
  40879. var order = aOrder || SourceMapConsumer$1.GENERATED_ORDER;
  40880. var mappings;
  40881. switch (order) {
  40882. case SourceMapConsumer$1.GENERATED_ORDER:
  40883. mappings = this._generatedMappings;
  40884. break;
  40885. case SourceMapConsumer$1.ORIGINAL_ORDER:
  40886. mappings = this._originalMappings;
  40887. break;
  40888. default:
  40889. throw new Error("Unknown order of iteration.");
  40890. }
  40891. var sourceRoot = this.sourceRoot;
  40892. mappings.map(function (mapping) {
  40893. var source = mapping.source === null ? null : this._sources.at(mapping.source);
  40894. source = util$1.computeSourceURL(sourceRoot, source, this._sourceMapURL);
  40895. return {
  40896. source: source,
  40897. generatedLine: mapping.generatedLine,
  40898. generatedColumn: mapping.generatedColumn,
  40899. originalLine: mapping.originalLine,
  40900. originalColumn: mapping.originalColumn,
  40901. name: mapping.name === null ? null : this._names.at(mapping.name)
  40902. };
  40903. }, this).forEach(aCallback, context);
  40904. };
  40905. /**
  40906. * Returns all generated line and column information for the original source,
  40907. * line, and column provided. If no column is provided, returns all mappings
  40908. * corresponding to a either the line we are searching for or the next
  40909. * closest line that has any mappings. Otherwise, returns all mappings
  40910. * corresponding to the given line and either the column we are searching for
  40911. * or the next closest column that has any offsets.
  40912. *
  40913. * The only argument is an object with the following properties:
  40914. *
  40915. * - source: The filename of the original source.
  40916. * - line: The line number in the original source. The line number is 1-based.
  40917. * - column: Optional. the column number in the original source.
  40918. * The column number is 0-based.
  40919. *
  40920. * and an array of objects is returned, each with the following properties:
  40921. *
  40922. * - line: The line number in the generated source, or null. The
  40923. * line number is 1-based.
  40924. * - column: The column number in the generated source, or null.
  40925. * The column number is 0-based.
  40926. */
  40927. SourceMapConsumer$1.prototype.allGeneratedPositionsFor =
  40928. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  40929. var line = util$1.getArg(aArgs, 'line');
  40930. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  40931. // returns the index of the closest mapping less than the needle. By
  40932. // setting needle.originalColumn to 0, we thus find the last mapping for
  40933. // the given line, provided such a mapping exists.
  40934. var needle = {
  40935. source: util$1.getArg(aArgs, 'source'),
  40936. originalLine: line,
  40937. originalColumn: util$1.getArg(aArgs, 'column', 0)
  40938. };
  40939. needle.source = this._findSourceIndex(needle.source);
  40940. if (needle.source < 0) {
  40941. return [];
  40942. }
  40943. var mappings = [];
  40944. var index = this._findMapping(needle,
  40945. this._originalMappings,
  40946. "originalLine",
  40947. "originalColumn",
  40948. util$1.compareByOriginalPositions,
  40949. binarySearch.LEAST_UPPER_BOUND);
  40950. if (index >= 0) {
  40951. var mapping = this._originalMappings[index];
  40952. if (aArgs.column === undefined) {
  40953. var originalLine = mapping.originalLine;
  40954. // Iterate until either we run out of mappings, or we run into
  40955. // a mapping for a different line than the one we found. Since
  40956. // mappings are sorted, this is guaranteed to find all mappings for
  40957. // the line we found.
  40958. while (mapping && mapping.originalLine === originalLine) {
  40959. mappings.push({
  40960. line: util$1.getArg(mapping, 'generatedLine', null),
  40961. column: util$1.getArg(mapping, 'generatedColumn', null),
  40962. lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
  40963. });
  40964. mapping = this._originalMappings[++index];
  40965. }
  40966. } else {
  40967. var originalColumn = mapping.originalColumn;
  40968. // Iterate until either we run out of mappings, or we run into
  40969. // a mapping for a different line than the one we were searching for.
  40970. // Since mappings are sorted, this is guaranteed to find all mappings for
  40971. // the line we are searching for.
  40972. while (mapping &&
  40973. mapping.originalLine === line &&
  40974. mapping.originalColumn == originalColumn) {
  40975. mappings.push({
  40976. line: util$1.getArg(mapping, 'generatedLine', null),
  40977. column: util$1.getArg(mapping, 'generatedColumn', null),
  40978. lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
  40979. });
  40980. mapping = this._originalMappings[++index];
  40981. }
  40982. }
  40983. }
  40984. return mappings;
  40985. };
  40986. sourceMapConsumer.SourceMapConsumer = SourceMapConsumer$1;
  40987. /**
  40988. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  40989. * query for information about the original file positions by giving it a file
  40990. * position in the generated source.
  40991. *
  40992. * The first parameter is the raw source map (either as a JSON string, or
  40993. * already parsed to an object). According to the spec, source maps have the
  40994. * following attributes:
  40995. *
  40996. * - version: Which version of the source map spec this map is following.
  40997. * - sources: An array of URLs to the original source files.
  40998. * - names: An array of identifiers which can be referrenced by individual mappings.
  40999. * - sourceRoot: Optional. The URL root from which all sources are relative.
  41000. * - sourcesContent: Optional. An array of contents of the original source files.
  41001. * - mappings: A string of base64 VLQs which contain the actual mappings.
  41002. * - file: Optional. The generated file this source map is associated with.
  41003. *
  41004. * Here is an example source map, taken from the source map spec[0]:
  41005. *
  41006. * {
  41007. * version : 3,
  41008. * file: "out.js",
  41009. * sourceRoot : "",
  41010. * sources: ["foo.js", "bar.js"],
  41011. * names: ["src", "maps", "are", "fun"],
  41012. * mappings: "AA,AB;;ABCDE;"
  41013. * }
  41014. *
  41015. * The second parameter, if given, is a string whose value is the URL
  41016. * at which the source map was found. This URL is used to compute the
  41017. * sources array.
  41018. *
  41019. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  41020. */
  41021. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  41022. var sourceMap = aSourceMap;
  41023. if (typeof aSourceMap === 'string') {
  41024. sourceMap = util$1.parseSourceMapInput(aSourceMap);
  41025. }
  41026. var version = util$1.getArg(sourceMap, 'version');
  41027. var sources = util$1.getArg(sourceMap, 'sources');
  41028. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  41029. // requires the array) to play nice here.
  41030. var names = util$1.getArg(sourceMap, 'names', []);
  41031. var sourceRoot = util$1.getArg(sourceMap, 'sourceRoot', null);
  41032. var sourcesContent = util$1.getArg(sourceMap, 'sourcesContent', null);
  41033. var mappings = util$1.getArg(sourceMap, 'mappings');
  41034. var file = util$1.getArg(sourceMap, 'file', null);
  41035. // Once again, Sass deviates from the spec and supplies the version as a
  41036. // string rather than a number, so we use loose equality checking here.
  41037. if (version != this._version) {
  41038. throw new Error('Unsupported version: ' + version);
  41039. }
  41040. if (sourceRoot) {
  41041. sourceRoot = util$1.normalize(sourceRoot);
  41042. }
  41043. sources = sources
  41044. .map(String)
  41045. // Some source maps produce relative source paths like "./foo.js" instead of
  41046. // "foo.js". Normalize these first so that future comparisons will succeed.
  41047. // See bugzil.la/1090768.
  41048. .map(util$1.normalize)
  41049. // Always ensure that absolute sources are internally stored relative to
  41050. // the source root, if the source root is absolute. Not doing this would
  41051. // be particularly problematic when the source root is a prefix of the
  41052. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  41053. .map(function (source) {
  41054. return sourceRoot && util$1.isAbsolute(sourceRoot) && util$1.isAbsolute(source)
  41055. ? util$1.relative(sourceRoot, source)
  41056. : source;
  41057. });
  41058. // Pass `true` below to allow duplicate names and sources. While source maps
  41059. // are intended to be compressed and deduplicated, the TypeScript compiler
  41060. // sometimes generates source maps with duplicates in them. See Github issue
  41061. // #72 and bugzil.la/889492.
  41062. this._names = ArraySet.fromArray(names.map(String), true);
  41063. this._sources = ArraySet.fromArray(sources, true);
  41064. this._absoluteSources = this._sources.toArray().map(function (s) {
  41065. return util$1.computeSourceURL(sourceRoot, s, aSourceMapURL);
  41066. });
  41067. this.sourceRoot = sourceRoot;
  41068. this.sourcesContent = sourcesContent;
  41069. this._mappings = mappings;
  41070. this._sourceMapURL = aSourceMapURL;
  41071. this.file = file;
  41072. }
  41073. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer$1.prototype);
  41074. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer$1;
  41075. /**
  41076. * Utility function to find the index of a source. Returns -1 if not
  41077. * found.
  41078. */
  41079. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  41080. var relativeSource = aSource;
  41081. if (this.sourceRoot != null) {
  41082. relativeSource = util$1.relative(this.sourceRoot, relativeSource);
  41083. }
  41084. if (this._sources.has(relativeSource)) {
  41085. return this._sources.indexOf(relativeSource);
  41086. }
  41087. // Maybe aSource is an absolute URL as returned by |sources|. In
  41088. // this case we can't simply undo the transform.
  41089. var i;
  41090. for (i = 0; i < this._absoluteSources.length; ++i) {
  41091. if (this._absoluteSources[i] == aSource) {
  41092. return i;
  41093. }
  41094. }
  41095. return -1;
  41096. };
  41097. /**
  41098. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  41099. *
  41100. * @param SourceMapGenerator aSourceMap
  41101. * The source map that will be consumed.
  41102. * @param String aSourceMapURL
  41103. * The URL at which the source map can be found (optional)
  41104. * @returns BasicSourceMapConsumer
  41105. */
  41106. BasicSourceMapConsumer.fromSourceMap =
  41107. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  41108. var smc = Object.create(BasicSourceMapConsumer.prototype);
  41109. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  41110. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  41111. smc.sourceRoot = aSourceMap._sourceRoot;
  41112. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  41113. smc.sourceRoot);
  41114. smc.file = aSourceMap._file;
  41115. smc._sourceMapURL = aSourceMapURL;
  41116. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  41117. return util$1.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  41118. });
  41119. // Because we are modifying the entries (by converting string sources and
  41120. // names to indices into the sources and names ArraySets), we have to make
  41121. // a copy of the entry or else bad things happen. Shared mutable state
  41122. // strikes again! See github issue #191.
  41123. var generatedMappings = aSourceMap._mappings.toArray().slice();
  41124. var destGeneratedMappings = smc.__generatedMappings = [];
  41125. var destOriginalMappings = smc.__originalMappings = [];
  41126. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  41127. var srcMapping = generatedMappings[i];
  41128. var destMapping = new Mapping;
  41129. destMapping.generatedLine = srcMapping.generatedLine;
  41130. destMapping.generatedColumn = srcMapping.generatedColumn;
  41131. if (srcMapping.source) {
  41132. destMapping.source = sources.indexOf(srcMapping.source);
  41133. destMapping.originalLine = srcMapping.originalLine;
  41134. destMapping.originalColumn = srcMapping.originalColumn;
  41135. if (srcMapping.name) {
  41136. destMapping.name = names.indexOf(srcMapping.name);
  41137. }
  41138. destOriginalMappings.push(destMapping);
  41139. }
  41140. destGeneratedMappings.push(destMapping);
  41141. }
  41142. quickSort(smc.__originalMappings, util$1.compareByOriginalPositions);
  41143. return smc;
  41144. };
  41145. /**
  41146. * The version of the source mapping spec that we are consuming.
  41147. */
  41148. BasicSourceMapConsumer.prototype._version = 3;
  41149. /**
  41150. * The list of original sources.
  41151. */
  41152. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  41153. get: function () {
  41154. return this._absoluteSources.slice();
  41155. }
  41156. });
  41157. /**
  41158. * Provide the JIT with a nice shape / hidden class.
  41159. */
  41160. function Mapping() {
  41161. this.generatedLine = 0;
  41162. this.generatedColumn = 0;
  41163. this.source = null;
  41164. this.originalLine = null;
  41165. this.originalColumn = null;
  41166. this.name = null;
  41167. }
  41168. /**
  41169. * Parse the mappings in a string in to a data structure which we can easily
  41170. * query (the ordered arrays in the `this.__generatedMappings` and
  41171. * `this.__originalMappings` properties).
  41172. */
  41173. BasicSourceMapConsumer.prototype._parseMappings =
  41174. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  41175. var generatedLine = 1;
  41176. var previousGeneratedColumn = 0;
  41177. var previousOriginalLine = 0;
  41178. var previousOriginalColumn = 0;
  41179. var previousSource = 0;
  41180. var previousName = 0;
  41181. var length = aStr.length;
  41182. var index = 0;
  41183. var cachedSegments = {};
  41184. var temp = {};
  41185. var originalMappings = [];
  41186. var generatedMappings = [];
  41187. var mapping, str, segment, end, value;
  41188. while (index < length) {
  41189. if (aStr.charAt(index) === ';') {
  41190. generatedLine++;
  41191. index++;
  41192. previousGeneratedColumn = 0;
  41193. }
  41194. else if (aStr.charAt(index) === ',') {
  41195. index++;
  41196. }
  41197. else {
  41198. mapping = new Mapping();
  41199. mapping.generatedLine = generatedLine;
  41200. // Because each offset is encoded relative to the previous one,
  41201. // many segments often have the same encoding. We can exploit this
  41202. // fact by caching the parsed variable length fields of each segment,
  41203. // allowing us to avoid a second parse if we encounter the same
  41204. // segment again.
  41205. for (end = index; end < length; end++) {
  41206. if (this._charIsMappingSeparator(aStr, end)) {
  41207. break;
  41208. }
  41209. }
  41210. str = aStr.slice(index, end);
  41211. segment = cachedSegments[str];
  41212. if (segment) {
  41213. index += str.length;
  41214. } else {
  41215. segment = [];
  41216. while (index < end) {
  41217. base64VLQ.decode(aStr, index, temp);
  41218. value = temp.value;
  41219. index = temp.rest;
  41220. segment.push(value);
  41221. }
  41222. if (segment.length === 2) {
  41223. throw new Error('Found a source, but no line and column');
  41224. }
  41225. if (segment.length === 3) {
  41226. throw new Error('Found a source and line, but no column');
  41227. }
  41228. cachedSegments[str] = segment;
  41229. }
  41230. // Generated column.
  41231. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  41232. previousGeneratedColumn = mapping.generatedColumn;
  41233. if (segment.length > 1) {
  41234. // Original source.
  41235. mapping.source = previousSource + segment[1];
  41236. previousSource += segment[1];
  41237. // Original line.
  41238. mapping.originalLine = previousOriginalLine + segment[2];
  41239. previousOriginalLine = mapping.originalLine;
  41240. // Lines are stored 0-based
  41241. mapping.originalLine += 1;
  41242. // Original column.
  41243. mapping.originalColumn = previousOriginalColumn + segment[3];
  41244. previousOriginalColumn = mapping.originalColumn;
  41245. if (segment.length > 4) {
  41246. // Original name.
  41247. mapping.name = previousName + segment[4];
  41248. previousName += segment[4];
  41249. }
  41250. }
  41251. generatedMappings.push(mapping);
  41252. if (typeof mapping.originalLine === 'number') {
  41253. originalMappings.push(mapping);
  41254. }
  41255. }
  41256. }
  41257. quickSort(generatedMappings, util$1.compareByGeneratedPositionsDeflated);
  41258. this.__generatedMappings = generatedMappings;
  41259. quickSort(originalMappings, util$1.compareByOriginalPositions);
  41260. this.__originalMappings = originalMappings;
  41261. };
  41262. /**
  41263. * Find the mapping that best matches the hypothetical "needle" mapping that
  41264. * we are searching for in the given "haystack" of mappings.
  41265. */
  41266. BasicSourceMapConsumer.prototype._findMapping =
  41267. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  41268. aColumnName, aComparator, aBias) {
  41269. // To return the position we are searching for, we must first find the
  41270. // mapping for the given position and then return the opposite position it
  41271. // points to. Because the mappings are sorted, we can use binary search to
  41272. // find the best mapping.
  41273. if (aNeedle[aLineName] <= 0) {
  41274. throw new TypeError('Line must be greater than or equal to 1, got '
  41275. + aNeedle[aLineName]);
  41276. }
  41277. if (aNeedle[aColumnName] < 0) {
  41278. throw new TypeError('Column must be greater than or equal to 0, got '
  41279. + aNeedle[aColumnName]);
  41280. }
  41281. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  41282. };
  41283. /**
  41284. * Compute the last column for each generated mapping. The last column is
  41285. * inclusive.
  41286. */
  41287. BasicSourceMapConsumer.prototype.computeColumnSpans =
  41288. function SourceMapConsumer_computeColumnSpans() {
  41289. for (var index = 0; index < this._generatedMappings.length; ++index) {
  41290. var mapping = this._generatedMappings[index];
  41291. // Mappings do not contain a field for the last generated columnt. We
  41292. // can come up with an optimistic estimate, however, by assuming that
  41293. // mappings are contiguous (i.e. given two consecutive mappings, the
  41294. // first mapping ends where the second one starts).
  41295. if (index + 1 < this._generatedMappings.length) {
  41296. var nextMapping = this._generatedMappings[index + 1];
  41297. if (mapping.generatedLine === nextMapping.generatedLine) {
  41298. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  41299. continue;
  41300. }
  41301. }
  41302. // The last mapping for each line spans the entire line.
  41303. mapping.lastGeneratedColumn = Infinity;
  41304. }
  41305. };
  41306. /**
  41307. * Returns the original source, line, and column information for the generated
  41308. * source's line and column positions provided. The only argument is an object
  41309. * with the following properties:
  41310. *
  41311. * - line: The line number in the generated source. The line number
  41312. * is 1-based.
  41313. * - column: The column number in the generated source. The column
  41314. * number is 0-based.
  41315. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  41316. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  41317. * closest element that is smaller than or greater than the one we are
  41318. * searching for, respectively, if the exact element cannot be found.
  41319. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  41320. *
  41321. * and an object is returned with the following properties:
  41322. *
  41323. * - source: The original source file, or null.
  41324. * - line: The line number in the original source, or null. The
  41325. * line number is 1-based.
  41326. * - column: The column number in the original source, or null. The
  41327. * column number is 0-based.
  41328. * - name: The original identifier, or null.
  41329. */
  41330. BasicSourceMapConsumer.prototype.originalPositionFor =
  41331. function SourceMapConsumer_originalPositionFor(aArgs) {
  41332. var needle = {
  41333. generatedLine: util$1.getArg(aArgs, 'line'),
  41334. generatedColumn: util$1.getArg(aArgs, 'column')
  41335. };
  41336. var index = this._findMapping(
  41337. needle,
  41338. this._generatedMappings,
  41339. "generatedLine",
  41340. "generatedColumn",
  41341. util$1.compareByGeneratedPositionsDeflated,
  41342. util$1.getArg(aArgs, 'bias', SourceMapConsumer$1.GREATEST_LOWER_BOUND)
  41343. );
  41344. if (index >= 0) {
  41345. var mapping = this._generatedMappings[index];
  41346. if (mapping.generatedLine === needle.generatedLine) {
  41347. var source = util$1.getArg(mapping, 'source', null);
  41348. if (source !== null) {
  41349. source = this._sources.at(source);
  41350. source = util$1.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  41351. }
  41352. var name = util$1.getArg(mapping, 'name', null);
  41353. if (name !== null) {
  41354. name = this._names.at(name);
  41355. }
  41356. return {
  41357. source: source,
  41358. line: util$1.getArg(mapping, 'originalLine', null),
  41359. column: util$1.getArg(mapping, 'originalColumn', null),
  41360. name: name
  41361. };
  41362. }
  41363. }
  41364. return {
  41365. source: null,
  41366. line: null,
  41367. column: null,
  41368. name: null
  41369. };
  41370. };
  41371. /**
  41372. * Return true if we have the source content for every source in the source
  41373. * map, false otherwise.
  41374. */
  41375. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  41376. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  41377. if (!this.sourcesContent) {
  41378. return false;
  41379. }
  41380. return this.sourcesContent.length >= this._sources.size() &&
  41381. !this.sourcesContent.some(function (sc) { return sc == null; });
  41382. };
  41383. /**
  41384. * Returns the original source content. The only argument is the url of the
  41385. * original source file. Returns null if no original source content is
  41386. * available.
  41387. */
  41388. BasicSourceMapConsumer.prototype.sourceContentFor =
  41389. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  41390. if (!this.sourcesContent) {
  41391. return null;
  41392. }
  41393. var index = this._findSourceIndex(aSource);
  41394. if (index >= 0) {
  41395. return this.sourcesContent[index];
  41396. }
  41397. var relativeSource = aSource;
  41398. if (this.sourceRoot != null) {
  41399. relativeSource = util$1.relative(this.sourceRoot, relativeSource);
  41400. }
  41401. var url;
  41402. if (this.sourceRoot != null
  41403. && (url = util$1.urlParse(this.sourceRoot))) {
  41404. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  41405. // many users. We can help them out when they expect file:// URIs to
  41406. // behave like it would if they were running a local HTTP server. See
  41407. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  41408. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  41409. if (url.scheme == "file"
  41410. && this._sources.has(fileUriAbsPath)) {
  41411. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  41412. }
  41413. if ((!url.path || url.path == "/")
  41414. && this._sources.has("/" + relativeSource)) {
  41415. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  41416. }
  41417. }
  41418. // This function is used recursively from
  41419. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  41420. // don't want to throw if we can't find the source - we just want to
  41421. // return null, so we provide a flag to exit gracefully.
  41422. if (nullOnMissing) {
  41423. return null;
  41424. }
  41425. else {
  41426. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  41427. }
  41428. };
  41429. /**
  41430. * Returns the generated line and column information for the original source,
  41431. * line, and column positions provided. The only argument is an object with
  41432. * the following properties:
  41433. *
  41434. * - source: The filename of the original source.
  41435. * - line: The line number in the original source. The line number
  41436. * is 1-based.
  41437. * - column: The column number in the original source. The column
  41438. * number is 0-based.
  41439. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  41440. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  41441. * closest element that is smaller than or greater than the one we are
  41442. * searching for, respectively, if the exact element cannot be found.
  41443. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  41444. *
  41445. * and an object is returned with the following properties:
  41446. *
  41447. * - line: The line number in the generated source, or null. The
  41448. * line number is 1-based.
  41449. * - column: The column number in the generated source, or null.
  41450. * The column number is 0-based.
  41451. */
  41452. BasicSourceMapConsumer.prototype.generatedPositionFor =
  41453. function SourceMapConsumer_generatedPositionFor(aArgs) {
  41454. var source = util$1.getArg(aArgs, 'source');
  41455. source = this._findSourceIndex(source);
  41456. if (source < 0) {
  41457. return {
  41458. line: null,
  41459. column: null,
  41460. lastColumn: null
  41461. };
  41462. }
  41463. var needle = {
  41464. source: source,
  41465. originalLine: util$1.getArg(aArgs, 'line'),
  41466. originalColumn: util$1.getArg(aArgs, 'column')
  41467. };
  41468. var index = this._findMapping(
  41469. needle,
  41470. this._originalMappings,
  41471. "originalLine",
  41472. "originalColumn",
  41473. util$1.compareByOriginalPositions,
  41474. util$1.getArg(aArgs, 'bias', SourceMapConsumer$1.GREATEST_LOWER_BOUND)
  41475. );
  41476. if (index >= 0) {
  41477. var mapping = this._originalMappings[index];
  41478. if (mapping.source === needle.source) {
  41479. return {
  41480. line: util$1.getArg(mapping, 'generatedLine', null),
  41481. column: util$1.getArg(mapping, 'generatedColumn', null),
  41482. lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
  41483. };
  41484. }
  41485. }
  41486. return {
  41487. line: null,
  41488. column: null,
  41489. lastColumn: null
  41490. };
  41491. };
  41492. sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
  41493. /**
  41494. * An IndexedSourceMapConsumer instance represents a parsed source map which
  41495. * we can query for information. It differs from BasicSourceMapConsumer in
  41496. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  41497. * input.
  41498. *
  41499. * The first parameter is a raw source map (either as a JSON string, or already
  41500. * parsed to an object). According to the spec for indexed source maps, they
  41501. * have the following attributes:
  41502. *
  41503. * - version: Which version of the source map spec this map is following.
  41504. * - file: Optional. The generated file this source map is associated with.
  41505. * - sections: A list of section definitions.
  41506. *
  41507. * Each value under the "sections" field has two fields:
  41508. * - offset: The offset into the original specified at which this section
  41509. * begins to apply, defined as an object with a "line" and "column"
  41510. * field.
  41511. * - map: A source map definition. This source map could also be indexed,
  41512. * but doesn't have to be.
  41513. *
  41514. * Instead of the "map" field, it's also possible to have a "url" field
  41515. * specifying a URL to retrieve a source map from, but that's currently
  41516. * unsupported.
  41517. *
  41518. * Here's an example source map, taken from the source map spec[0], but
  41519. * modified to omit a section which uses the "url" field.
  41520. *
  41521. * {
  41522. * version : 3,
  41523. * file: "app.js",
  41524. * sections: [{
  41525. * offset: {line:100, column:10},
  41526. * map: {
  41527. * version : 3,
  41528. * file: "section.js",
  41529. * sources: ["foo.js", "bar.js"],
  41530. * names: ["src", "maps", "are", "fun"],
  41531. * mappings: "AAAA,E;;ABCDE;"
  41532. * }
  41533. * }],
  41534. * }
  41535. *
  41536. * The second parameter, if given, is a string whose value is the URL
  41537. * at which the source map was found. This URL is used to compute the
  41538. * sources array.
  41539. *
  41540. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  41541. */
  41542. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  41543. var sourceMap = aSourceMap;
  41544. if (typeof aSourceMap === 'string') {
  41545. sourceMap = util$1.parseSourceMapInput(aSourceMap);
  41546. }
  41547. var version = util$1.getArg(sourceMap, 'version');
  41548. var sections = util$1.getArg(sourceMap, 'sections');
  41549. if (version != this._version) {
  41550. throw new Error('Unsupported version: ' + version);
  41551. }
  41552. this._sources = new ArraySet();
  41553. this._names = new ArraySet();
  41554. var lastOffset = {
  41555. line: -1,
  41556. column: 0
  41557. };
  41558. this._sections = sections.map(function (s) {
  41559. if (s.url) {
  41560. // The url field will require support for asynchronicity.
  41561. // See https://github.com/mozilla/source-map/issues/16
  41562. throw new Error('Support for url field in sections not implemented.');
  41563. }
  41564. var offset = util$1.getArg(s, 'offset');
  41565. var offsetLine = util$1.getArg(offset, 'line');
  41566. var offsetColumn = util$1.getArg(offset, 'column');
  41567. if (offsetLine < lastOffset.line ||
  41568. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  41569. throw new Error('Section offsets must be ordered and non-overlapping.');
  41570. }
  41571. lastOffset = offset;
  41572. return {
  41573. generatedOffset: {
  41574. // The offset fields are 0-based, but we use 1-based indices when
  41575. // encoding/decoding from VLQ.
  41576. generatedLine: offsetLine + 1,
  41577. generatedColumn: offsetColumn + 1
  41578. },
  41579. consumer: new SourceMapConsumer$1(util$1.getArg(s, 'map'), aSourceMapURL)
  41580. }
  41581. });
  41582. }
  41583. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer$1.prototype);
  41584. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer$1;
  41585. /**
  41586. * The version of the source mapping spec that we are consuming.
  41587. */
  41588. IndexedSourceMapConsumer.prototype._version = 3;
  41589. /**
  41590. * The list of original sources.
  41591. */
  41592. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  41593. get: function () {
  41594. var sources = [];
  41595. for (var i = 0; i < this._sections.length; i++) {
  41596. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  41597. sources.push(this._sections[i].consumer.sources[j]);
  41598. }
  41599. }
  41600. return sources;
  41601. }
  41602. });
  41603. /**
  41604. * Returns the original source, line, and column information for the generated
  41605. * source's line and column positions provided. The only argument is an object
  41606. * with the following properties:
  41607. *
  41608. * - line: The line number in the generated source. The line number
  41609. * is 1-based.
  41610. * - column: The column number in the generated source. The column
  41611. * number is 0-based.
  41612. *
  41613. * and an object is returned with the following properties:
  41614. *
  41615. * - source: The original source file, or null.
  41616. * - line: The line number in the original source, or null. The
  41617. * line number is 1-based.
  41618. * - column: The column number in the original source, or null. The
  41619. * column number is 0-based.
  41620. * - name: The original identifier, or null.
  41621. */
  41622. IndexedSourceMapConsumer.prototype.originalPositionFor =
  41623. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  41624. var needle = {
  41625. generatedLine: util$1.getArg(aArgs, 'line'),
  41626. generatedColumn: util$1.getArg(aArgs, 'column')
  41627. };
  41628. // Find the section containing the generated position we're trying to map
  41629. // to an original position.
  41630. var sectionIndex = binarySearch.search(needle, this._sections,
  41631. function(needle, section) {
  41632. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  41633. if (cmp) {
  41634. return cmp;
  41635. }
  41636. return (needle.generatedColumn -
  41637. section.generatedOffset.generatedColumn);
  41638. });
  41639. var section = this._sections[sectionIndex];
  41640. if (!section) {
  41641. return {
  41642. source: null,
  41643. line: null,
  41644. column: null,
  41645. name: null
  41646. };
  41647. }
  41648. return section.consumer.originalPositionFor({
  41649. line: needle.generatedLine -
  41650. (section.generatedOffset.generatedLine - 1),
  41651. column: needle.generatedColumn -
  41652. (section.generatedOffset.generatedLine === needle.generatedLine
  41653. ? section.generatedOffset.generatedColumn - 1
  41654. : 0),
  41655. bias: aArgs.bias
  41656. });
  41657. };
  41658. /**
  41659. * Return true if we have the source content for every source in the source
  41660. * map, false otherwise.
  41661. */
  41662. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  41663. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  41664. return this._sections.every(function (s) {
  41665. return s.consumer.hasContentsOfAllSources();
  41666. });
  41667. };
  41668. /**
  41669. * Returns the original source content. The only argument is the url of the
  41670. * original source file. Returns null if no original source content is
  41671. * available.
  41672. */
  41673. IndexedSourceMapConsumer.prototype.sourceContentFor =
  41674. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  41675. for (var i = 0; i < this._sections.length; i++) {
  41676. var section = this._sections[i];
  41677. var content = section.consumer.sourceContentFor(aSource, true);
  41678. if (content) {
  41679. return content;
  41680. }
  41681. }
  41682. if (nullOnMissing) {
  41683. return null;
  41684. }
  41685. else {
  41686. throw new Error('"' + aSource + '" is not in the SourceMap.');
  41687. }
  41688. };
  41689. /**
  41690. * Returns the generated line and column information for the original source,
  41691. * line, and column positions provided. The only argument is an object with
  41692. * the following properties:
  41693. *
  41694. * - source: The filename of the original source.
  41695. * - line: The line number in the original source. The line number
  41696. * is 1-based.
  41697. * - column: The column number in the original source. The column
  41698. * number is 0-based.
  41699. *
  41700. * and an object is returned with the following properties:
  41701. *
  41702. * - line: The line number in the generated source, or null. The
  41703. * line number is 1-based.
  41704. * - column: The column number in the generated source, or null.
  41705. * The column number is 0-based.
  41706. */
  41707. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  41708. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  41709. for (var i = 0; i < this._sections.length; i++) {
  41710. var section = this._sections[i];
  41711. // Only consider this section if the requested source is in the list of
  41712. // sources of the consumer.
  41713. if (section.consumer._findSourceIndex(util$1.getArg(aArgs, 'source')) === -1) {
  41714. continue;
  41715. }
  41716. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  41717. if (generatedPosition) {
  41718. var ret = {
  41719. line: generatedPosition.line +
  41720. (section.generatedOffset.generatedLine - 1),
  41721. column: generatedPosition.column +
  41722. (section.generatedOffset.generatedLine === generatedPosition.line
  41723. ? section.generatedOffset.generatedColumn - 1
  41724. : 0)
  41725. };
  41726. return ret;
  41727. }
  41728. }
  41729. return {
  41730. line: null,
  41731. column: null
  41732. };
  41733. };
  41734. /**
  41735. * Parse the mappings in a string in to a data structure which we can easily
  41736. * query (the ordered arrays in the `this.__generatedMappings` and
  41737. * `this.__originalMappings` properties).
  41738. */
  41739. IndexedSourceMapConsumer.prototype._parseMappings =
  41740. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  41741. this.__generatedMappings = [];
  41742. this.__originalMappings = [];
  41743. for (var i = 0; i < this._sections.length; i++) {
  41744. var section = this._sections[i];
  41745. var sectionMappings = section.consumer._generatedMappings;
  41746. for (var j = 0; j < sectionMappings.length; j++) {
  41747. var mapping = sectionMappings[j];
  41748. var source = section.consumer._sources.at(mapping.source);
  41749. source = util$1.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  41750. this._sources.add(source);
  41751. source = this._sources.indexOf(source);
  41752. var name = null;
  41753. if (mapping.name) {
  41754. name = section.consumer._names.at(mapping.name);
  41755. this._names.add(name);
  41756. name = this._names.indexOf(name);
  41757. }
  41758. // The mappings coming from the consumer for the section have
  41759. // generated positions relative to the start of the section, so we
  41760. // need to offset them to be relative to the start of the concatenated
  41761. // generated file.
  41762. var adjustedMapping = {
  41763. source: source,
  41764. generatedLine: mapping.generatedLine +
  41765. (section.generatedOffset.generatedLine - 1),
  41766. generatedColumn: mapping.generatedColumn +
  41767. (section.generatedOffset.generatedLine === mapping.generatedLine
  41768. ? section.generatedOffset.generatedColumn - 1
  41769. : 0),
  41770. originalLine: mapping.originalLine,
  41771. originalColumn: mapping.originalColumn,
  41772. name: name
  41773. };
  41774. this.__generatedMappings.push(adjustedMapping);
  41775. if (typeof adjustedMapping.originalLine === 'number') {
  41776. this.__originalMappings.push(adjustedMapping);
  41777. }
  41778. }
  41779. }
  41780. quickSort(this.__generatedMappings, util$1.compareByGeneratedPositionsDeflated);
  41781. quickSort(this.__originalMappings, util$1.compareByOriginalPositions);
  41782. };
  41783. sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  41784. var sourceNode = {};
  41785. /* -*- Mode: js; js-indent-level: 2; -*- */
  41786. /*
  41787. * Copyright 2011 Mozilla Foundation and contributors
  41788. * Licensed under the New BSD license. See LICENSE or:
  41789. * http://opensource.org/licenses/BSD-3-Clause
  41790. */
  41791. var SourceMapGenerator$1 = sourceMapGenerator.SourceMapGenerator;
  41792. var util = util$5;
  41793. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  41794. // operating systems these days (capturing the result).
  41795. var REGEX_NEWLINE = /(\r?\n)/;
  41796. // Newline character code for charCodeAt() comparisons
  41797. var NEWLINE_CODE = 10;
  41798. // Private symbol for identifying `SourceNode`s when multiple versions of
  41799. // the source-map library are loaded. This MUST NOT CHANGE across
  41800. // versions!
  41801. var isSourceNode = "$$$isSourceNode$$$";
  41802. /**
  41803. * SourceNodes provide a way to abstract over interpolating/concatenating
  41804. * snippets of generated JavaScript source code while maintaining the line and
  41805. * column information associated with the original source code.
  41806. *
  41807. * @param aLine The original line number.
  41808. * @param aColumn The original column number.
  41809. * @param aSource The original source's filename.
  41810. * @param aChunks Optional. An array of strings which are snippets of
  41811. * generated JS, or other SourceNodes.
  41812. * @param aName The original identifier.
  41813. */
  41814. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  41815. this.children = [];
  41816. this.sourceContents = {};
  41817. this.line = aLine == null ? null : aLine;
  41818. this.column = aColumn == null ? null : aColumn;
  41819. this.source = aSource == null ? null : aSource;
  41820. this.name = aName == null ? null : aName;
  41821. this[isSourceNode] = true;
  41822. if (aChunks != null) this.add(aChunks);
  41823. }
  41824. /**
  41825. * Creates a SourceNode from generated code and a SourceMapConsumer.
  41826. *
  41827. * @param aGeneratedCode The generated code
  41828. * @param aSourceMapConsumer The SourceMap for the generated code
  41829. * @param aRelativePath Optional. The path that relative sources in the
  41830. * SourceMapConsumer should be relative to.
  41831. */
  41832. SourceNode.fromStringWithSourceMap =
  41833. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  41834. // The SourceNode we want to fill with the generated code
  41835. // and the SourceMap
  41836. var node = new SourceNode();
  41837. // All even indices of this array are one line of the generated code,
  41838. // while all odd indices are the newlines between two adjacent lines
  41839. // (since `REGEX_NEWLINE` captures its match).
  41840. // Processed fragments are accessed by calling `shiftNextLine`.
  41841. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  41842. var remainingLinesIndex = 0;
  41843. var shiftNextLine = function() {
  41844. var lineContents = getNextLine();
  41845. // The last line of a file might not have a newline.
  41846. var newLine = getNextLine() || "";
  41847. return lineContents + newLine;
  41848. function getNextLine() {
  41849. return remainingLinesIndex < remainingLines.length ?
  41850. remainingLines[remainingLinesIndex++] : undefined;
  41851. }
  41852. };
  41853. // We need to remember the position of "remainingLines"
  41854. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  41855. // The generate SourceNodes we need a code range.
  41856. // To extract it current and last mapping is used.
  41857. // Here we store the last mapping.
  41858. var lastMapping = null;
  41859. aSourceMapConsumer.eachMapping(function (mapping) {
  41860. if (lastMapping !== null) {
  41861. // We add the code from "lastMapping" to "mapping":
  41862. // First check if there is a new line in between.
  41863. if (lastGeneratedLine < mapping.generatedLine) {
  41864. // Associate first line with "lastMapping"
  41865. addMappingWithCode(lastMapping, shiftNextLine());
  41866. lastGeneratedLine++;
  41867. lastGeneratedColumn = 0;
  41868. // The remaining code is added without mapping
  41869. } else {
  41870. // There is no new line in between.
  41871. // Associate the code between "lastGeneratedColumn" and
  41872. // "mapping.generatedColumn" with "lastMapping"
  41873. var nextLine = remainingLines[remainingLinesIndex] || '';
  41874. var code = nextLine.substr(0, mapping.generatedColumn -
  41875. lastGeneratedColumn);
  41876. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  41877. lastGeneratedColumn);
  41878. lastGeneratedColumn = mapping.generatedColumn;
  41879. addMappingWithCode(lastMapping, code);
  41880. // No more remaining code, continue
  41881. lastMapping = mapping;
  41882. return;
  41883. }
  41884. }
  41885. // We add the generated code until the first mapping
  41886. // to the SourceNode without any mapping.
  41887. // Each line is added as separate string.
  41888. while (lastGeneratedLine < mapping.generatedLine) {
  41889. node.add(shiftNextLine());
  41890. lastGeneratedLine++;
  41891. }
  41892. if (lastGeneratedColumn < mapping.generatedColumn) {
  41893. var nextLine = remainingLines[remainingLinesIndex] || '';
  41894. node.add(nextLine.substr(0, mapping.generatedColumn));
  41895. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  41896. lastGeneratedColumn = mapping.generatedColumn;
  41897. }
  41898. lastMapping = mapping;
  41899. }, this);
  41900. // We have processed all mappings.
  41901. if (remainingLinesIndex < remainingLines.length) {
  41902. if (lastMapping) {
  41903. // Associate the remaining code in the current line with "lastMapping"
  41904. addMappingWithCode(lastMapping, shiftNextLine());
  41905. }
  41906. // and add the remaining lines without any mapping
  41907. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  41908. }
  41909. // Copy sourcesContent into SourceNode
  41910. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41911. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41912. if (content != null) {
  41913. if (aRelativePath != null) {
  41914. sourceFile = util.join(aRelativePath, sourceFile);
  41915. }
  41916. node.setSourceContent(sourceFile, content);
  41917. }
  41918. });
  41919. return node;
  41920. function addMappingWithCode(mapping, code) {
  41921. if (mapping === null || mapping.source === undefined) {
  41922. node.add(code);
  41923. } else {
  41924. var source = aRelativePath
  41925. ? util.join(aRelativePath, mapping.source)
  41926. : mapping.source;
  41927. node.add(new SourceNode(mapping.originalLine,
  41928. mapping.originalColumn,
  41929. source,
  41930. code,
  41931. mapping.name));
  41932. }
  41933. }
  41934. };
  41935. /**
  41936. * Add a chunk of generated JS to this source node.
  41937. *
  41938. * @param aChunk A string snippet of generated JS code, another instance of
  41939. * SourceNode, or an array where each member is one of those things.
  41940. */
  41941. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  41942. if (Array.isArray(aChunk)) {
  41943. aChunk.forEach(function (chunk) {
  41944. this.add(chunk);
  41945. }, this);
  41946. }
  41947. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  41948. if (aChunk) {
  41949. this.children.push(aChunk);
  41950. }
  41951. }
  41952. else {
  41953. throw new TypeError(
  41954. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  41955. );
  41956. }
  41957. return this;
  41958. };
  41959. /**
  41960. * Add a chunk of generated JS to the beginning of this source node.
  41961. *
  41962. * @param aChunk A string snippet of generated JS code, another instance of
  41963. * SourceNode, or an array where each member is one of those things.
  41964. */
  41965. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  41966. if (Array.isArray(aChunk)) {
  41967. for (var i = aChunk.length-1; i >= 0; i--) {
  41968. this.prepend(aChunk[i]);
  41969. }
  41970. }
  41971. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  41972. this.children.unshift(aChunk);
  41973. }
  41974. else {
  41975. throw new TypeError(
  41976. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  41977. );
  41978. }
  41979. return this;
  41980. };
  41981. /**
  41982. * Walk over the tree of JS snippets in this node and its children. The
  41983. * walking function is called once for each snippet of JS and is passed that
  41984. * snippet and the its original associated source's line/column location.
  41985. *
  41986. * @param aFn The traversal function.
  41987. */
  41988. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  41989. var chunk;
  41990. for (var i = 0, len = this.children.length; i < len; i++) {
  41991. chunk = this.children[i];
  41992. if (chunk[isSourceNode]) {
  41993. chunk.walk(aFn);
  41994. }
  41995. else {
  41996. if (chunk !== '') {
  41997. aFn(chunk, { source: this.source,
  41998. line: this.line,
  41999. column: this.column,
  42000. name: this.name });
  42001. }
  42002. }
  42003. }
  42004. };
  42005. /**
  42006. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  42007. * each of `this.children`.
  42008. *
  42009. * @param aSep The separator.
  42010. */
  42011. SourceNode.prototype.join = function SourceNode_join(aSep) {
  42012. var newChildren;
  42013. var i;
  42014. var len = this.children.length;
  42015. if (len > 0) {
  42016. newChildren = [];
  42017. for (i = 0; i < len-1; i++) {
  42018. newChildren.push(this.children[i]);
  42019. newChildren.push(aSep);
  42020. }
  42021. newChildren.push(this.children[i]);
  42022. this.children = newChildren;
  42023. }
  42024. return this;
  42025. };
  42026. /**
  42027. * Call String.prototype.replace on the very right-most source snippet. Useful
  42028. * for trimming whitespace from the end of a source node, etc.
  42029. *
  42030. * @param aPattern The pattern to replace.
  42031. * @param aReplacement The thing to replace the pattern with.
  42032. */
  42033. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  42034. var lastChild = this.children[this.children.length - 1];
  42035. if (lastChild[isSourceNode]) {
  42036. lastChild.replaceRight(aPattern, aReplacement);
  42037. }
  42038. else if (typeof lastChild === 'string') {
  42039. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  42040. }
  42041. else {
  42042. this.children.push(''.replace(aPattern, aReplacement));
  42043. }
  42044. return this;
  42045. };
  42046. /**
  42047. * Set the source content for a source file. This will be added to the SourceMapGenerator
  42048. * in the sourcesContent field.
  42049. *
  42050. * @param aSourceFile The filename of the source file
  42051. * @param aSourceContent The content of the source file
  42052. */
  42053. SourceNode.prototype.setSourceContent =
  42054. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  42055. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  42056. };
  42057. /**
  42058. * Walk over the tree of SourceNodes. The walking function is called for each
  42059. * source file content and is passed the filename and source content.
  42060. *
  42061. * @param aFn The traversal function.
  42062. */
  42063. SourceNode.prototype.walkSourceContents =
  42064. function SourceNode_walkSourceContents(aFn) {
  42065. for (var i = 0, len = this.children.length; i < len; i++) {
  42066. if (this.children[i][isSourceNode]) {
  42067. this.children[i].walkSourceContents(aFn);
  42068. }
  42069. }
  42070. var sources = Object.keys(this.sourceContents);
  42071. for (var i = 0, len = sources.length; i < len; i++) {
  42072. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  42073. }
  42074. };
  42075. /**
  42076. * Return the string representation of this source node. Walks over the tree
  42077. * and concatenates all the various snippets together to one string.
  42078. */
  42079. SourceNode.prototype.toString = function SourceNode_toString() {
  42080. var str = "";
  42081. this.walk(function (chunk) {
  42082. str += chunk;
  42083. });
  42084. return str;
  42085. };
  42086. /**
  42087. * Returns the string representation of this source node along with a source
  42088. * map.
  42089. */
  42090. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  42091. var generated = {
  42092. code: "",
  42093. line: 1,
  42094. column: 0
  42095. };
  42096. var map = new SourceMapGenerator$1(aArgs);
  42097. var sourceMappingActive = false;
  42098. var lastOriginalSource = null;
  42099. var lastOriginalLine = null;
  42100. var lastOriginalColumn = null;
  42101. var lastOriginalName = null;
  42102. this.walk(function (chunk, original) {
  42103. generated.code += chunk;
  42104. if (original.source !== null
  42105. && original.line !== null
  42106. && original.column !== null) {
  42107. if(lastOriginalSource !== original.source
  42108. || lastOriginalLine !== original.line
  42109. || lastOriginalColumn !== original.column
  42110. || lastOriginalName !== original.name) {
  42111. map.addMapping({
  42112. source: original.source,
  42113. original: {
  42114. line: original.line,
  42115. column: original.column
  42116. },
  42117. generated: {
  42118. line: generated.line,
  42119. column: generated.column
  42120. },
  42121. name: original.name
  42122. });
  42123. }
  42124. lastOriginalSource = original.source;
  42125. lastOriginalLine = original.line;
  42126. lastOriginalColumn = original.column;
  42127. lastOriginalName = original.name;
  42128. sourceMappingActive = true;
  42129. } else if (sourceMappingActive) {
  42130. map.addMapping({
  42131. generated: {
  42132. line: generated.line,
  42133. column: generated.column
  42134. }
  42135. });
  42136. lastOriginalSource = null;
  42137. sourceMappingActive = false;
  42138. }
  42139. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  42140. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  42141. generated.line++;
  42142. generated.column = 0;
  42143. // Mappings end at eol
  42144. if (idx + 1 === length) {
  42145. lastOriginalSource = null;
  42146. sourceMappingActive = false;
  42147. } else if (sourceMappingActive) {
  42148. map.addMapping({
  42149. source: original.source,
  42150. original: {
  42151. line: original.line,
  42152. column: original.column
  42153. },
  42154. generated: {
  42155. line: generated.line,
  42156. column: generated.column
  42157. },
  42158. name: original.name
  42159. });
  42160. }
  42161. } else {
  42162. generated.column++;
  42163. }
  42164. }
  42165. });
  42166. this.walkSourceContents(function (sourceFile, sourceContent) {
  42167. map.setSourceContent(sourceFile, sourceContent);
  42168. });
  42169. return { code: generated.code, map: map };
  42170. };
  42171. sourceNode.SourceNode = SourceNode;
  42172. /*
  42173. * Copyright 2009-2011 Mozilla Foundation and contributors
  42174. * Licensed under the New BSD license. See LICENSE.txt or:
  42175. * http://opensource.org/licenses/BSD-3-Clause
  42176. */
  42177. sourceMap$1.SourceMapGenerator = sourceMapGenerator.SourceMapGenerator;
  42178. sourceMap$1.SourceMapConsumer = sourceMapConsumer.SourceMapConsumer;
  42179. sourceMap$1.SourceNode = sourceNode.SourceNode;
  42180. var sourceMap = sourceMap$1;
  42181. var SourceMapConsumer = sourceMap.SourceMapConsumer;
  42182. var SourceMapGenerator = sourceMap.SourceMapGenerator;
  42183. var mergeSourceMap = merge;
  42184. /**
  42185. * Merge old source map and new source map and return merged.
  42186. * If old or new source map value is falsy, return another one as it is.
  42187. *
  42188. * @param {object|string} [oldMap] old source map object
  42189. * @param {object|string} [newmap] new source map object
  42190. * @return {object|undefined} merged source map object, or undefined when both old and new source map are undefined
  42191. */
  42192. function merge(oldMap, newMap) {
  42193. if (!oldMap) return newMap
  42194. if (!newMap) return oldMap
  42195. var oldMapConsumer = new SourceMapConsumer(oldMap);
  42196. var newMapConsumer = new SourceMapConsumer(newMap);
  42197. var mergedMapGenerator = new SourceMapGenerator();
  42198. // iterate on new map and overwrite original position of new map with one of old map
  42199. newMapConsumer.eachMapping(function(m) {
  42200. // pass when `originalLine` is null.
  42201. // It occurs in case that the node does not have origin in original code.
  42202. if (m.originalLine == null) return
  42203. var origPosInOldMap = oldMapConsumer.originalPositionFor({
  42204. line: m.originalLine,
  42205. column: m.originalColumn
  42206. });
  42207. if (origPosInOldMap.source == null) return
  42208. mergedMapGenerator.addMapping({
  42209. original: {
  42210. line: origPosInOldMap.line,
  42211. column: origPosInOldMap.column
  42212. },
  42213. generated: {
  42214. line: m.generatedLine,
  42215. column: m.generatedColumn
  42216. },
  42217. source: origPosInOldMap.source,
  42218. name: origPosInOldMap.name
  42219. });
  42220. });
  42221. var consumers = [oldMapConsumer, newMapConsumer];
  42222. consumers.forEach(function(consumer) {
  42223. consumer.sources.forEach(function(sourceFile) {
  42224. mergedMapGenerator._sources.add(sourceFile);
  42225. var sourceContent = consumer.sourceContentFor(sourceFile);
  42226. if (sourceContent != null) {
  42227. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  42228. }
  42229. });
  42230. });
  42231. mergedMapGenerator._sourceRoot = oldMap.sourceRoot;
  42232. mergedMapGenerator._file = oldMap.file;
  42233. return JSON.parse(mergedMapGenerator.toString())
  42234. }
  42235. var merge$1 = mergeSourceMap;
  42236. var __defProp$5 = Object.defineProperty;
  42237. var __defProps$5 = Object.defineProperties;
  42238. var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
  42239. var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
  42240. var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
  42241. var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
  42242. var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  42243. var __spreadValues$5 = (a, b) => {
  42244. for (var prop in b || (b = {}))
  42245. if (__hasOwnProp$5.call(b, prop))
  42246. __defNormalProp$5(a, prop, b[prop]);
  42247. if (__getOwnPropSymbols$5)
  42248. for (var prop of __getOwnPropSymbols$5(b)) {
  42249. if (__propIsEnum$5.call(b, prop))
  42250. __defNormalProp$5(a, prop, b[prop]);
  42251. }
  42252. return a;
  42253. };
  42254. var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
  42255. const scss = (source, map, options, load = require) => {
  42256. const nodeSass = load("sass");
  42257. const finalOptions = __spreadProps$5(__spreadValues$5({}, options), {
  42258. data: getSource(source, options.filename, options.additionalData),
  42259. file: options.filename,
  42260. outFile: options.filename,
  42261. sourceMap: !!map
  42262. });
  42263. try {
  42264. const result = nodeSass.renderSync(finalOptions);
  42265. const dependencies = result.stats.includedFiles;
  42266. if (map) {
  42267. return {
  42268. code: result.css.toString(),
  42269. map: merge$1(map, JSON.parse(result.map.toString())),
  42270. errors: [],
  42271. dependencies
  42272. };
  42273. }
  42274. return { code: result.css.toString(), errors: [], dependencies };
  42275. } catch (e) {
  42276. return { code: "", errors: [e], dependencies: [] };
  42277. }
  42278. };
  42279. const sass = (source, map, options, load) => scss(
  42280. source,
  42281. map,
  42282. __spreadProps$5(__spreadValues$5({}, options), {
  42283. indentedSyntax: true
  42284. }),
  42285. load
  42286. );
  42287. const less = (source, map, options, load = require) => {
  42288. const nodeLess = load("less");
  42289. let result;
  42290. let error = null;
  42291. nodeLess.render(
  42292. getSource(source, options.filename, options.additionalData),
  42293. __spreadProps$5(__spreadValues$5({}, options), { syncImport: true }),
  42294. (err, output) => {
  42295. error = err;
  42296. result = output;
  42297. }
  42298. );
  42299. if (error)
  42300. return { code: "", errors: [error], dependencies: [] };
  42301. const dependencies = result.imports;
  42302. if (map) {
  42303. return {
  42304. code: result.css.toString(),
  42305. map: merge$1(map, result.map),
  42306. errors: [],
  42307. dependencies
  42308. };
  42309. }
  42310. return {
  42311. code: result.css.toString(),
  42312. errors: [],
  42313. dependencies
  42314. };
  42315. };
  42316. const styl = (source, map, options, load = require) => {
  42317. const nodeStylus = load("stylus");
  42318. try {
  42319. const ref = nodeStylus(source);
  42320. Object.keys(options).forEach((key) => ref.set(key, options[key]));
  42321. if (map)
  42322. ref.set("sourcemap", { inline: false, comment: false });
  42323. const result = ref.render();
  42324. const dependencies = ref.deps();
  42325. if (map) {
  42326. return {
  42327. code: result,
  42328. map: merge$1(map, ref.sourcemap),
  42329. errors: [],
  42330. dependencies
  42331. };
  42332. }
  42333. return { code: result, errors: [], dependencies };
  42334. } catch (e) {
  42335. return { code: "", errors: [e], dependencies: [] };
  42336. }
  42337. };
  42338. function getSource(source, filename, additionalData) {
  42339. if (!additionalData)
  42340. return source;
  42341. if (isFunction$1(additionalData)) {
  42342. return additionalData(source, filename);
  42343. }
  42344. return additionalData + source;
  42345. }
  42346. const processors = {
  42347. less,
  42348. sass,
  42349. scss,
  42350. styl,
  42351. stylus: styl
  42352. };
  42353. var __defProp$4 = Object.defineProperty;
  42354. var __defProps$4 = Object.defineProperties;
  42355. var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
  42356. var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
  42357. var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
  42358. var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
  42359. var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  42360. var __spreadValues$4 = (a, b) => {
  42361. for (var prop in b || (b = {}))
  42362. if (__hasOwnProp$4.call(b, prop))
  42363. __defNormalProp$4(a, prop, b[prop]);
  42364. if (__getOwnPropSymbols$4)
  42365. for (var prop of __getOwnPropSymbols$4(b)) {
  42366. if (__propIsEnum$4.call(b, prop))
  42367. __defNormalProp$4(a, prop, b[prop]);
  42368. }
  42369. return a;
  42370. };
  42371. var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
  42372. function compileStyle(options) {
  42373. return doCompileStyle(__spreadProps$4(__spreadValues$4({}, options), {
  42374. isAsync: false
  42375. }));
  42376. }
  42377. function compileStyleAsync(options) {
  42378. return doCompileStyle(__spreadProps$4(__spreadValues$4({}, options), {
  42379. isAsync: true
  42380. }));
  42381. }
  42382. function doCompileStyle(options) {
  42383. const {
  42384. filename,
  42385. id,
  42386. scoped = false,
  42387. trim = true,
  42388. isProd = false,
  42389. modules = false,
  42390. modulesOptions = {},
  42391. preprocessLang,
  42392. postcssOptions,
  42393. postcssPlugins
  42394. } = options;
  42395. const preprocessor = preprocessLang && processors[preprocessLang];
  42396. const preProcessedSource = preprocessor && preprocess(options, preprocessor);
  42397. const map = preProcessedSource ? preProcessedSource.map : options.inMap || options.map;
  42398. const source = preProcessedSource ? preProcessedSource.code : options.source;
  42399. const shortId = id.replace(/^data-v-/, "");
  42400. const longId = `data-v-${shortId}`;
  42401. const plugins = (postcssPlugins || []).slice();
  42402. plugins.unshift(cssVarsPlugin({ id: shortId, isProd }));
  42403. if (trim) {
  42404. plugins.push(trimPlugin$1());
  42405. }
  42406. if (scoped) {
  42407. plugins.push(scopedPlugin$1(longId));
  42408. }
  42409. let cssModules;
  42410. if (modules) {
  42411. {
  42412. throw new Error(
  42413. "[@vue/compiler-sfc] `modules` option is not supported in the browser build."
  42414. );
  42415. }
  42416. }
  42417. const postCSSOptions = __spreadProps$4(__spreadValues$4({}, postcssOptions), {
  42418. to: filename,
  42419. from: filename
  42420. });
  42421. if (map) {
  42422. postCSSOptions.map = {
  42423. inline: false,
  42424. annotation: false,
  42425. prev: map
  42426. };
  42427. }
  42428. let result;
  42429. let code;
  42430. let outMap;
  42431. const dependencies = new Set(
  42432. preProcessedSource ? preProcessedSource.dependencies : []
  42433. );
  42434. dependencies.delete(filename);
  42435. const errors = [];
  42436. if (preProcessedSource && preProcessedSource.errors.length) {
  42437. errors.push(...preProcessedSource.errors);
  42438. }
  42439. const recordPlainCssDependencies = (messages) => {
  42440. messages.forEach((msg) => {
  42441. if (msg.type === "dependency") {
  42442. dependencies.add(msg.file);
  42443. }
  42444. });
  42445. return dependencies;
  42446. };
  42447. try {
  42448. result = postcss$1(plugins).process(source, postCSSOptions);
  42449. if (options.isAsync) {
  42450. return result.then((result2) => ({
  42451. code: result2.css || "",
  42452. map: result2.map && result2.map.toJSON(),
  42453. errors,
  42454. modules: cssModules,
  42455. rawResult: result2,
  42456. dependencies: recordPlainCssDependencies(result2.messages)
  42457. })).catch((error) => ({
  42458. code: "",
  42459. map: void 0,
  42460. errors: [...errors, error],
  42461. rawResult: void 0,
  42462. dependencies
  42463. }));
  42464. }
  42465. recordPlainCssDependencies(result.messages);
  42466. code = result.css;
  42467. outMap = result.map;
  42468. } catch (e) {
  42469. errors.push(e);
  42470. }
  42471. return {
  42472. code: code || ``,
  42473. map: outMap && outMap.toJSON(),
  42474. errors,
  42475. rawResult: result,
  42476. dependencies
  42477. };
  42478. }
  42479. function preprocess(options, preprocessor) {
  42480. if (!options.preprocessCustomRequire) {
  42481. throw new Error(
  42482. `[@vue/compiler-sfc] Style preprocessing in the browser build must provide the \`preprocessCustomRequire\` option to return the in-browser version of the preprocessor.`
  42483. );
  42484. }
  42485. return preprocessor(
  42486. options.source,
  42487. options.inMap || options.map,
  42488. __spreadValues$4({
  42489. filename: options.filename
  42490. }, options.preprocessOptions),
  42491. options.preprocessCustomRequire
  42492. );
  42493. }
  42494. const comma = ','.charCodeAt(0);
  42495. const semicolon = ';'.charCodeAt(0);
  42496. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  42497. const intToChar = new Uint8Array(64); // 64 possible chars.
  42498. const charToInt = new Uint8Array(128); // z is 122 in ASCII
  42499. for (let i = 0; i < chars.length; i++) {
  42500. const c = chars.charCodeAt(i);
  42501. intToChar[i] = c;
  42502. charToInt[c] = i;
  42503. }
  42504. // Provide a fallback for older environments.
  42505. const td = typeof TextDecoder !== 'undefined'
  42506. ? /* #__PURE__ */ new TextDecoder()
  42507. : typeof Buffer !== 'undefined'
  42508. ? {
  42509. decode(buf) {
  42510. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  42511. return out.toString();
  42512. },
  42513. }
  42514. : {
  42515. decode(buf) {
  42516. let out = '';
  42517. for (let i = 0; i < buf.length; i++) {
  42518. out += String.fromCharCode(buf[i]);
  42519. }
  42520. return out;
  42521. },
  42522. };
  42523. function encode(decoded) {
  42524. const state = new Int32Array(5);
  42525. const bufLength = 1024 * 16;
  42526. const subLength = bufLength - 36;
  42527. const buf = new Uint8Array(bufLength);
  42528. const sub = buf.subarray(0, subLength);
  42529. let pos = 0;
  42530. let out = '';
  42531. for (let i = 0; i < decoded.length; i++) {
  42532. const line = decoded[i];
  42533. if (i > 0) {
  42534. if (pos === bufLength) {
  42535. out += td.decode(buf);
  42536. pos = 0;
  42537. }
  42538. buf[pos++] = semicolon;
  42539. }
  42540. if (line.length === 0)
  42541. continue;
  42542. state[0] = 0;
  42543. for (let j = 0; j < line.length; j++) {
  42544. const segment = line[j];
  42545. // We can push up to 5 ints, each int can take at most 7 chars, and we
  42546. // may push a comma.
  42547. if (pos > subLength) {
  42548. out += td.decode(sub);
  42549. buf.copyWithin(0, subLength, pos);
  42550. pos -= subLength;
  42551. }
  42552. if (j > 0)
  42553. buf[pos++] = comma;
  42554. pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
  42555. if (segment.length === 1)
  42556. continue;
  42557. pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
  42558. pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
  42559. pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
  42560. if (segment.length === 4)
  42561. continue;
  42562. pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
  42563. }
  42564. }
  42565. return out + td.decode(buf.subarray(0, pos));
  42566. }
  42567. function encodeInteger(buf, pos, state, segment, j) {
  42568. const next = segment[j];
  42569. let num = next - state[j];
  42570. state[j] = next;
  42571. num = num < 0 ? (-num << 1) | 1 : num << 1;
  42572. do {
  42573. let clamped = num & 0b011111;
  42574. num >>>= 5;
  42575. if (num > 0)
  42576. clamped |= 0b100000;
  42577. buf[pos++] = intToChar[clamped];
  42578. } while (num > 0);
  42579. return pos;
  42580. }
  42581. class BitSet {
  42582. constructor(arg) {
  42583. this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
  42584. }
  42585. add(n) {
  42586. this.bits[n >> 5] |= 1 << (n & 31);
  42587. }
  42588. has(n) {
  42589. return !!(this.bits[n >> 5] & (1 << (n & 31)));
  42590. }
  42591. }
  42592. class Chunk {
  42593. constructor(start, end, content) {
  42594. this.start = start;
  42595. this.end = end;
  42596. this.original = content;
  42597. this.intro = '';
  42598. this.outro = '';
  42599. this.content = content;
  42600. this.storeName = false;
  42601. this.edited = false;
  42602. {
  42603. this.previous = null;
  42604. this.next = null;
  42605. }
  42606. }
  42607. appendLeft(content) {
  42608. this.outro += content;
  42609. }
  42610. appendRight(content) {
  42611. this.intro = this.intro + content;
  42612. }
  42613. clone() {
  42614. const chunk = new Chunk(this.start, this.end, this.original);
  42615. chunk.intro = this.intro;
  42616. chunk.outro = this.outro;
  42617. chunk.content = this.content;
  42618. chunk.storeName = this.storeName;
  42619. chunk.edited = this.edited;
  42620. return chunk;
  42621. }
  42622. contains(index) {
  42623. return this.start < index && index < this.end;
  42624. }
  42625. eachNext(fn) {
  42626. let chunk = this;
  42627. while (chunk) {
  42628. fn(chunk);
  42629. chunk = chunk.next;
  42630. }
  42631. }
  42632. eachPrevious(fn) {
  42633. let chunk = this;
  42634. while (chunk) {
  42635. fn(chunk);
  42636. chunk = chunk.previous;
  42637. }
  42638. }
  42639. edit(content, storeName, contentOnly) {
  42640. this.content = content;
  42641. if (!contentOnly) {
  42642. this.intro = '';
  42643. this.outro = '';
  42644. }
  42645. this.storeName = storeName;
  42646. this.edited = true;
  42647. return this;
  42648. }
  42649. prependLeft(content) {
  42650. this.outro = content + this.outro;
  42651. }
  42652. prependRight(content) {
  42653. this.intro = content + this.intro;
  42654. }
  42655. split(index) {
  42656. const sliceIndex = index - this.start;
  42657. const originalBefore = this.original.slice(0, sliceIndex);
  42658. const originalAfter = this.original.slice(sliceIndex);
  42659. this.original = originalBefore;
  42660. const newChunk = new Chunk(index, this.end, originalAfter);
  42661. newChunk.outro = this.outro;
  42662. this.outro = '';
  42663. this.end = index;
  42664. if (this.edited) {
  42665. // TODO is this block necessary?...
  42666. newChunk.edit('', false);
  42667. this.content = '';
  42668. } else {
  42669. this.content = originalBefore;
  42670. }
  42671. newChunk.next = this.next;
  42672. if (newChunk.next) newChunk.next.previous = newChunk;
  42673. newChunk.previous = this;
  42674. this.next = newChunk;
  42675. return newChunk;
  42676. }
  42677. toString() {
  42678. return this.intro + this.content + this.outro;
  42679. }
  42680. trimEnd(rx) {
  42681. this.outro = this.outro.replace(rx, '');
  42682. if (this.outro.length) return true;
  42683. const trimmed = this.content.replace(rx, '');
  42684. if (trimmed.length) {
  42685. if (trimmed !== this.content) {
  42686. this.split(this.start + trimmed.length).edit('', undefined, true);
  42687. }
  42688. return true;
  42689. } else {
  42690. this.edit('', undefined, true);
  42691. this.intro = this.intro.replace(rx, '');
  42692. if (this.intro.length) return true;
  42693. }
  42694. }
  42695. trimStart(rx) {
  42696. this.intro = this.intro.replace(rx, '');
  42697. if (this.intro.length) return true;
  42698. const trimmed = this.content.replace(rx, '');
  42699. if (trimmed.length) {
  42700. if (trimmed !== this.content) {
  42701. this.split(this.end - trimmed.length);
  42702. this.edit('', undefined, true);
  42703. }
  42704. return true;
  42705. } else {
  42706. this.edit('', undefined, true);
  42707. this.outro = this.outro.replace(rx, '');
  42708. if (this.outro.length) return true;
  42709. }
  42710. }
  42711. }
  42712. function getBtoa () {
  42713. if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
  42714. return (str) => window.btoa(unescape(encodeURIComponent(str)));
  42715. } else if (typeof Buffer === 'function') {
  42716. return (str) => Buffer.from(str, 'utf-8').toString('base64');
  42717. } else {
  42718. return () => {
  42719. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  42720. };
  42721. }
  42722. }
  42723. const btoa = /*#__PURE__*/ getBtoa();
  42724. class SourceMap {
  42725. constructor(properties) {
  42726. this.version = 3;
  42727. this.file = properties.file;
  42728. this.sources = properties.sources;
  42729. this.sourcesContent = properties.sourcesContent;
  42730. this.names = properties.names;
  42731. this.mappings = encode(properties.mappings);
  42732. if (typeof properties.x_google_ignoreList !== 'undefined') {
  42733. this.x_google_ignoreList = properties.x_google_ignoreList;
  42734. }
  42735. }
  42736. toString() {
  42737. return JSON.stringify(this);
  42738. }
  42739. toUrl() {
  42740. return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
  42741. }
  42742. }
  42743. function guessIndent(code) {
  42744. const lines = code.split('\n');
  42745. const tabbed = lines.filter((line) => /^\t+/.test(line));
  42746. const spaced = lines.filter((line) => /^ {2,}/.test(line));
  42747. if (tabbed.length === 0 && spaced.length === 0) {
  42748. return null;
  42749. }
  42750. // More lines tabbed than spaced? Assume tabs, and
  42751. // default to tabs in the case of a tie (or nothing
  42752. // to go on)
  42753. if (tabbed.length >= spaced.length) {
  42754. return '\t';
  42755. }
  42756. // Otherwise, we need to guess the multiple
  42757. const min = spaced.reduce((previous, current) => {
  42758. const numSpaces = /^ +/.exec(current)[0].length;
  42759. return Math.min(numSpaces, previous);
  42760. }, Infinity);
  42761. return new Array(min + 1).join(' ');
  42762. }
  42763. function getRelativePath(from, to) {
  42764. const fromParts = from.split(/[/\\]/);
  42765. const toParts = to.split(/[/\\]/);
  42766. fromParts.pop(); // get dirname
  42767. while (fromParts[0] === toParts[0]) {
  42768. fromParts.shift();
  42769. toParts.shift();
  42770. }
  42771. if (fromParts.length) {
  42772. let i = fromParts.length;
  42773. while (i--) fromParts[i] = '..';
  42774. }
  42775. return fromParts.concat(toParts).join('/');
  42776. }
  42777. const toString = Object.prototype.toString;
  42778. function isObject(thing) {
  42779. return toString.call(thing) === '[object Object]';
  42780. }
  42781. function getLocator(source) {
  42782. const originalLines = source.split('\n');
  42783. const lineOffsets = [];
  42784. for (let i = 0, pos = 0; i < originalLines.length; i++) {
  42785. lineOffsets.push(pos);
  42786. pos += originalLines[i].length + 1;
  42787. }
  42788. return function locate(index) {
  42789. let i = 0;
  42790. let j = lineOffsets.length;
  42791. while (i < j) {
  42792. const m = (i + j) >> 1;
  42793. if (index < lineOffsets[m]) {
  42794. j = m;
  42795. } else {
  42796. i = m + 1;
  42797. }
  42798. }
  42799. const line = i - 1;
  42800. const column = index - lineOffsets[line];
  42801. return { line, column };
  42802. };
  42803. }
  42804. class Mappings {
  42805. constructor(hires) {
  42806. this.hires = hires;
  42807. this.generatedCodeLine = 0;
  42808. this.generatedCodeColumn = 0;
  42809. this.raw = [];
  42810. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  42811. this.pending = null;
  42812. }
  42813. addEdit(sourceIndex, content, loc, nameIndex) {
  42814. if (content.length) {
  42815. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  42816. if (nameIndex >= 0) {
  42817. segment.push(nameIndex);
  42818. }
  42819. this.rawSegments.push(segment);
  42820. } else if (this.pending) {
  42821. this.rawSegments.push(this.pending);
  42822. }
  42823. this.advance(content);
  42824. this.pending = null;
  42825. }
  42826. addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
  42827. let originalCharIndex = chunk.start;
  42828. let first = true;
  42829. while (originalCharIndex < chunk.end) {
  42830. if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
  42831. this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
  42832. }
  42833. if (original[originalCharIndex] === '\n') {
  42834. loc.line += 1;
  42835. loc.column = 0;
  42836. this.generatedCodeLine += 1;
  42837. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  42838. this.generatedCodeColumn = 0;
  42839. first = true;
  42840. } else {
  42841. loc.column += 1;
  42842. this.generatedCodeColumn += 1;
  42843. first = false;
  42844. }
  42845. originalCharIndex += 1;
  42846. }
  42847. this.pending = null;
  42848. }
  42849. advance(str) {
  42850. if (!str) return;
  42851. const lines = str.split('\n');
  42852. if (lines.length > 1) {
  42853. for (let i = 0; i < lines.length - 1; i++) {
  42854. this.generatedCodeLine++;
  42855. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  42856. }
  42857. this.generatedCodeColumn = 0;
  42858. }
  42859. this.generatedCodeColumn += lines[lines.length - 1].length;
  42860. }
  42861. }
  42862. const n = '\n';
  42863. const warned = {
  42864. insertLeft: false,
  42865. insertRight: false,
  42866. storeName: false,
  42867. };
  42868. class MagicString {
  42869. constructor(string, options = {}) {
  42870. const chunk = new Chunk(0, string.length, string);
  42871. Object.defineProperties(this, {
  42872. original: { writable: true, value: string },
  42873. outro: { writable: true, value: '' },
  42874. intro: { writable: true, value: '' },
  42875. firstChunk: { writable: true, value: chunk },
  42876. lastChunk: { writable: true, value: chunk },
  42877. lastSearchedChunk: { writable: true, value: chunk },
  42878. byStart: { writable: true, value: {} },
  42879. byEnd: { writable: true, value: {} },
  42880. filename: { writable: true, value: options.filename },
  42881. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  42882. sourcemapLocations: { writable: true, value: new BitSet() },
  42883. storedNames: { writable: true, value: {} },
  42884. indentStr: { writable: true, value: undefined },
  42885. ignoreList: { writable: true, value: options.ignoreList },
  42886. });
  42887. this.byStart[0] = chunk;
  42888. this.byEnd[string.length] = chunk;
  42889. }
  42890. addSourcemapLocation(char) {
  42891. this.sourcemapLocations.add(char);
  42892. }
  42893. append(content) {
  42894. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  42895. this.outro += content;
  42896. return this;
  42897. }
  42898. appendLeft(index, content) {
  42899. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  42900. this._split(index);
  42901. const chunk = this.byEnd[index];
  42902. if (chunk) {
  42903. chunk.appendLeft(content);
  42904. } else {
  42905. this.intro += content;
  42906. }
  42907. return this;
  42908. }
  42909. appendRight(index, content) {
  42910. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  42911. this._split(index);
  42912. const chunk = this.byStart[index];
  42913. if (chunk) {
  42914. chunk.appendRight(content);
  42915. } else {
  42916. this.outro += content;
  42917. }
  42918. return this;
  42919. }
  42920. clone() {
  42921. const cloned = new MagicString(this.original, { filename: this.filename });
  42922. let originalChunk = this.firstChunk;
  42923. let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  42924. while (originalChunk) {
  42925. cloned.byStart[clonedChunk.start] = clonedChunk;
  42926. cloned.byEnd[clonedChunk.end] = clonedChunk;
  42927. const nextOriginalChunk = originalChunk.next;
  42928. const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  42929. if (nextClonedChunk) {
  42930. clonedChunk.next = nextClonedChunk;
  42931. nextClonedChunk.previous = clonedChunk;
  42932. clonedChunk = nextClonedChunk;
  42933. }
  42934. originalChunk = nextOriginalChunk;
  42935. }
  42936. cloned.lastChunk = clonedChunk;
  42937. if (this.indentExclusionRanges) {
  42938. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  42939. }
  42940. cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
  42941. cloned.intro = this.intro;
  42942. cloned.outro = this.outro;
  42943. return cloned;
  42944. }
  42945. generateDecodedMap(options) {
  42946. options = options || {};
  42947. const sourceIndex = 0;
  42948. const names = Object.keys(this.storedNames);
  42949. const mappings = new Mappings(options.hires);
  42950. const locate = getLocator(this.original);
  42951. if (this.intro) {
  42952. mappings.advance(this.intro);
  42953. }
  42954. this.firstChunk.eachNext((chunk) => {
  42955. const loc = locate(chunk.start);
  42956. if (chunk.intro.length) mappings.advance(chunk.intro);
  42957. if (chunk.edited) {
  42958. mappings.addEdit(
  42959. sourceIndex,
  42960. chunk.content,
  42961. loc,
  42962. chunk.storeName ? names.indexOf(chunk.original) : -1
  42963. );
  42964. } else {
  42965. mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
  42966. }
  42967. if (chunk.outro.length) mappings.advance(chunk.outro);
  42968. });
  42969. return {
  42970. file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
  42971. sources: [options.source ? getRelativePath(options.file || '', options.source) : (options.file || '')],
  42972. sourcesContent: options.includeContent ? [this.original] : undefined,
  42973. names,
  42974. mappings: mappings.raw,
  42975. x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined
  42976. };
  42977. }
  42978. generateMap(options) {
  42979. return new SourceMap(this.generateDecodedMap(options));
  42980. }
  42981. _ensureindentStr() {
  42982. if (this.indentStr === undefined) {
  42983. this.indentStr = guessIndent(this.original);
  42984. }
  42985. }
  42986. _getRawIndentString() {
  42987. this._ensureindentStr();
  42988. return this.indentStr;
  42989. }
  42990. getIndentString() {
  42991. this._ensureindentStr();
  42992. return this.indentStr === null ? '\t' : this.indentStr;
  42993. }
  42994. indent(indentStr, options) {
  42995. const pattern = /^[^\r\n]/gm;
  42996. if (isObject(indentStr)) {
  42997. options = indentStr;
  42998. indentStr = undefined;
  42999. }
  43000. if (indentStr === undefined) {
  43001. this._ensureindentStr();
  43002. indentStr = this.indentStr || '\t';
  43003. }
  43004. if (indentStr === '') return this; // noop
  43005. options = options || {};
  43006. // Process exclusion ranges
  43007. const isExcluded = {};
  43008. if (options.exclude) {
  43009. const exclusions =
  43010. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  43011. exclusions.forEach((exclusion) => {
  43012. for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
  43013. isExcluded[i] = true;
  43014. }
  43015. });
  43016. }
  43017. let shouldIndentNextCharacter = options.indentStart !== false;
  43018. const replacer = (match) => {
  43019. if (shouldIndentNextCharacter) return `${indentStr}${match}`;
  43020. shouldIndentNextCharacter = true;
  43021. return match;
  43022. };
  43023. this.intro = this.intro.replace(pattern, replacer);
  43024. let charIndex = 0;
  43025. let chunk = this.firstChunk;
  43026. while (chunk) {
  43027. const end = chunk.end;
  43028. if (chunk.edited) {
  43029. if (!isExcluded[charIndex]) {
  43030. chunk.content = chunk.content.replace(pattern, replacer);
  43031. if (chunk.content.length) {
  43032. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  43033. }
  43034. }
  43035. } else {
  43036. charIndex = chunk.start;
  43037. while (charIndex < end) {
  43038. if (!isExcluded[charIndex]) {
  43039. const char = this.original[charIndex];
  43040. if (char === '\n') {
  43041. shouldIndentNextCharacter = true;
  43042. } else if (char !== '\r' && shouldIndentNextCharacter) {
  43043. shouldIndentNextCharacter = false;
  43044. if (charIndex === chunk.start) {
  43045. chunk.prependRight(indentStr);
  43046. } else {
  43047. this._splitChunk(chunk, charIndex);
  43048. chunk = chunk.next;
  43049. chunk.prependRight(indentStr);
  43050. }
  43051. }
  43052. }
  43053. charIndex += 1;
  43054. }
  43055. }
  43056. charIndex = chunk.end;
  43057. chunk = chunk.next;
  43058. }
  43059. this.outro = this.outro.replace(pattern, replacer);
  43060. return this;
  43061. }
  43062. insert() {
  43063. throw new Error(
  43064. 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
  43065. );
  43066. }
  43067. insertLeft(index, content) {
  43068. if (!warned.insertLeft) {
  43069. console.warn(
  43070. 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
  43071. ); // eslint-disable-line no-console
  43072. warned.insertLeft = true;
  43073. }
  43074. return this.appendLeft(index, content);
  43075. }
  43076. insertRight(index, content) {
  43077. if (!warned.insertRight) {
  43078. console.warn(
  43079. 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
  43080. ); // eslint-disable-line no-console
  43081. warned.insertRight = true;
  43082. }
  43083. return this.prependRight(index, content);
  43084. }
  43085. move(start, end, index) {
  43086. if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
  43087. this._split(start);
  43088. this._split(end);
  43089. this._split(index);
  43090. const first = this.byStart[start];
  43091. const last = this.byEnd[end];
  43092. const oldLeft = first.previous;
  43093. const oldRight = last.next;
  43094. const newRight = this.byStart[index];
  43095. if (!newRight && last === this.lastChunk) return this;
  43096. const newLeft = newRight ? newRight.previous : this.lastChunk;
  43097. if (oldLeft) oldLeft.next = oldRight;
  43098. if (oldRight) oldRight.previous = oldLeft;
  43099. if (newLeft) newLeft.next = first;
  43100. if (newRight) newRight.previous = last;
  43101. if (!first.previous) this.firstChunk = last.next;
  43102. if (!last.next) {
  43103. this.lastChunk = first.previous;
  43104. this.lastChunk.next = null;
  43105. }
  43106. first.previous = newLeft;
  43107. last.next = newRight || null;
  43108. if (!newLeft) this.firstChunk = first;
  43109. if (!newRight) this.lastChunk = last;
  43110. return this;
  43111. }
  43112. overwrite(start, end, content, options) {
  43113. options = options || {};
  43114. return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
  43115. }
  43116. update(start, end, content, options) {
  43117. if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
  43118. while (start < 0) start += this.original.length;
  43119. while (end < 0) end += this.original.length;
  43120. if (end > this.original.length) throw new Error('end is out of bounds');
  43121. if (start === end)
  43122. throw new Error(
  43123. 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
  43124. );
  43125. this._split(start);
  43126. this._split(end);
  43127. if (options === true) {
  43128. if (!warned.storeName) {
  43129. console.warn(
  43130. 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
  43131. ); // eslint-disable-line no-console
  43132. warned.storeName = true;
  43133. }
  43134. options = { storeName: true };
  43135. }
  43136. const storeName = options !== undefined ? options.storeName : false;
  43137. const overwrite = options !== undefined ? options.overwrite : false;
  43138. if (storeName) {
  43139. const original = this.original.slice(start, end);
  43140. Object.defineProperty(this.storedNames, original, {
  43141. writable: true,
  43142. value: true,
  43143. enumerable: true,
  43144. });
  43145. }
  43146. const first = this.byStart[start];
  43147. const last = this.byEnd[end];
  43148. if (first) {
  43149. let chunk = first;
  43150. while (chunk !== last) {
  43151. if (chunk.next !== this.byStart[chunk.end]) {
  43152. throw new Error('Cannot overwrite across a split point');
  43153. }
  43154. chunk = chunk.next;
  43155. chunk.edit('', false);
  43156. }
  43157. first.edit(content, storeName, !overwrite);
  43158. } else {
  43159. // must be inserting at the end
  43160. const newChunk = new Chunk(start, end, '').edit(content, storeName);
  43161. // TODO last chunk in the array may not be the last chunk, if it's moved...
  43162. last.next = newChunk;
  43163. newChunk.previous = last;
  43164. }
  43165. return this;
  43166. }
  43167. prepend(content) {
  43168. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  43169. this.intro = content + this.intro;
  43170. return this;
  43171. }
  43172. prependLeft(index, content) {
  43173. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  43174. this._split(index);
  43175. const chunk = this.byEnd[index];
  43176. if (chunk) {
  43177. chunk.prependLeft(content);
  43178. } else {
  43179. this.intro = content + this.intro;
  43180. }
  43181. return this;
  43182. }
  43183. prependRight(index, content) {
  43184. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  43185. this._split(index);
  43186. const chunk = this.byStart[index];
  43187. if (chunk) {
  43188. chunk.prependRight(content);
  43189. } else {
  43190. this.outro = content + this.outro;
  43191. }
  43192. return this;
  43193. }
  43194. remove(start, end) {
  43195. while (start < 0) start += this.original.length;
  43196. while (end < 0) end += this.original.length;
  43197. if (start === end) return this;
  43198. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  43199. if (start > end) throw new Error('end must be greater than start');
  43200. this._split(start);
  43201. this._split(end);
  43202. let chunk = this.byStart[start];
  43203. while (chunk) {
  43204. chunk.intro = '';
  43205. chunk.outro = '';
  43206. chunk.edit('');
  43207. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  43208. }
  43209. return this;
  43210. }
  43211. lastChar() {
  43212. if (this.outro.length) return this.outro[this.outro.length - 1];
  43213. let chunk = this.lastChunk;
  43214. do {
  43215. if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
  43216. if (chunk.content.length) return chunk.content[chunk.content.length - 1];
  43217. if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
  43218. } while ((chunk = chunk.previous));
  43219. if (this.intro.length) return this.intro[this.intro.length - 1];
  43220. return '';
  43221. }
  43222. lastLine() {
  43223. let lineIndex = this.outro.lastIndexOf(n);
  43224. if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
  43225. let lineStr = this.outro;
  43226. let chunk = this.lastChunk;
  43227. do {
  43228. if (chunk.outro.length > 0) {
  43229. lineIndex = chunk.outro.lastIndexOf(n);
  43230. if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
  43231. lineStr = chunk.outro + lineStr;
  43232. }
  43233. if (chunk.content.length > 0) {
  43234. lineIndex = chunk.content.lastIndexOf(n);
  43235. if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
  43236. lineStr = chunk.content + lineStr;
  43237. }
  43238. if (chunk.intro.length > 0) {
  43239. lineIndex = chunk.intro.lastIndexOf(n);
  43240. if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
  43241. lineStr = chunk.intro + lineStr;
  43242. }
  43243. } while ((chunk = chunk.previous));
  43244. lineIndex = this.intro.lastIndexOf(n);
  43245. if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
  43246. return this.intro + lineStr;
  43247. }
  43248. slice(start = 0, end = this.original.length) {
  43249. while (start < 0) start += this.original.length;
  43250. while (end < 0) end += this.original.length;
  43251. let result = '';
  43252. // find start chunk
  43253. let chunk = this.firstChunk;
  43254. while (chunk && (chunk.start > start || chunk.end <= start)) {
  43255. // found end chunk before start
  43256. if (chunk.start < end && chunk.end >= end) {
  43257. return result;
  43258. }
  43259. chunk = chunk.next;
  43260. }
  43261. if (chunk && chunk.edited && chunk.start !== start)
  43262. throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
  43263. const startChunk = chunk;
  43264. while (chunk) {
  43265. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  43266. result += chunk.intro;
  43267. }
  43268. const containsEnd = chunk.start < end && chunk.end >= end;
  43269. if (containsEnd && chunk.edited && chunk.end !== end)
  43270. throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
  43271. const sliceStart = startChunk === chunk ? start - chunk.start : 0;
  43272. const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  43273. result += chunk.content.slice(sliceStart, sliceEnd);
  43274. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  43275. result += chunk.outro;
  43276. }
  43277. if (containsEnd) {
  43278. break;
  43279. }
  43280. chunk = chunk.next;
  43281. }
  43282. return result;
  43283. }
  43284. // TODO deprecate this? not really very useful
  43285. snip(start, end) {
  43286. const clone = this.clone();
  43287. clone.remove(0, start);
  43288. clone.remove(end, clone.original.length);
  43289. return clone;
  43290. }
  43291. _split(index) {
  43292. if (this.byStart[index] || this.byEnd[index]) return;
  43293. let chunk = this.lastSearchedChunk;
  43294. const searchForward = index > chunk.end;
  43295. while (chunk) {
  43296. if (chunk.contains(index)) return this._splitChunk(chunk, index);
  43297. chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
  43298. }
  43299. }
  43300. _splitChunk(chunk, index) {
  43301. if (chunk.edited && chunk.content.length) {
  43302. // zero-length edited chunks are a special case (overlapping replacements)
  43303. const loc = getLocator(this.original)(index);
  43304. throw new Error(
  43305. `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
  43306. );
  43307. }
  43308. const newChunk = chunk.split(index);
  43309. this.byEnd[index] = chunk;
  43310. this.byStart[index] = newChunk;
  43311. this.byEnd[newChunk.end] = newChunk;
  43312. if (chunk === this.lastChunk) this.lastChunk = newChunk;
  43313. this.lastSearchedChunk = chunk;
  43314. return true;
  43315. }
  43316. toString() {
  43317. let str = this.intro;
  43318. let chunk = this.firstChunk;
  43319. while (chunk) {
  43320. str += chunk.toString();
  43321. chunk = chunk.next;
  43322. }
  43323. return str + this.outro;
  43324. }
  43325. isEmpty() {
  43326. let chunk = this.firstChunk;
  43327. do {
  43328. if (
  43329. (chunk.intro.length && chunk.intro.trim()) ||
  43330. (chunk.content.length && chunk.content.trim()) ||
  43331. (chunk.outro.length && chunk.outro.trim())
  43332. )
  43333. return false;
  43334. } while ((chunk = chunk.next));
  43335. return true;
  43336. }
  43337. length() {
  43338. let chunk = this.firstChunk;
  43339. let length = 0;
  43340. do {
  43341. length += chunk.intro.length + chunk.content.length + chunk.outro.length;
  43342. } while ((chunk = chunk.next));
  43343. return length;
  43344. }
  43345. trimLines() {
  43346. return this.trim('[\\r\\n]');
  43347. }
  43348. trim(charType) {
  43349. return this.trimStart(charType).trimEnd(charType);
  43350. }
  43351. trimEndAborted(charType) {
  43352. const rx = new RegExp((charType || '\\s') + '+$');
  43353. this.outro = this.outro.replace(rx, '');
  43354. if (this.outro.length) return true;
  43355. let chunk = this.lastChunk;
  43356. do {
  43357. const end = chunk.end;
  43358. const aborted = chunk.trimEnd(rx);
  43359. // if chunk was trimmed, we have a new lastChunk
  43360. if (chunk.end !== end) {
  43361. if (this.lastChunk === chunk) {
  43362. this.lastChunk = chunk.next;
  43363. }
  43364. this.byEnd[chunk.end] = chunk;
  43365. this.byStart[chunk.next.start] = chunk.next;
  43366. this.byEnd[chunk.next.end] = chunk.next;
  43367. }
  43368. if (aborted) return true;
  43369. chunk = chunk.previous;
  43370. } while (chunk);
  43371. return false;
  43372. }
  43373. trimEnd(charType) {
  43374. this.trimEndAborted(charType);
  43375. return this;
  43376. }
  43377. trimStartAborted(charType) {
  43378. const rx = new RegExp('^' + (charType || '\\s') + '+');
  43379. this.intro = this.intro.replace(rx, '');
  43380. if (this.intro.length) return true;
  43381. let chunk = this.firstChunk;
  43382. do {
  43383. const end = chunk.end;
  43384. const aborted = chunk.trimStart(rx);
  43385. if (chunk.end !== end) {
  43386. // special case...
  43387. if (chunk === this.lastChunk) this.lastChunk = chunk.next;
  43388. this.byEnd[chunk.end] = chunk;
  43389. this.byStart[chunk.next.start] = chunk.next;
  43390. this.byEnd[chunk.next.end] = chunk.next;
  43391. }
  43392. if (aborted) return true;
  43393. chunk = chunk.next;
  43394. } while (chunk);
  43395. return false;
  43396. }
  43397. trimStart(charType) {
  43398. this.trimStartAborted(charType);
  43399. return this;
  43400. }
  43401. hasChanged() {
  43402. return this.original !== this.toString();
  43403. }
  43404. _replaceRegexp(searchValue, replacement) {
  43405. function getReplacement(match, str) {
  43406. if (typeof replacement === 'string') {
  43407. return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
  43408. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
  43409. if (i === '$') return '$';
  43410. if (i === '&') return match[0];
  43411. const num = +i;
  43412. if (num < match.length) return match[+i];
  43413. return `$${i}`;
  43414. });
  43415. } else {
  43416. return replacement(...match, match.index, str, match.groups);
  43417. }
  43418. }
  43419. function matchAll(re, str) {
  43420. let match;
  43421. const matches = [];
  43422. while ((match = re.exec(str))) {
  43423. matches.push(match);
  43424. }
  43425. return matches;
  43426. }
  43427. if (searchValue.global) {
  43428. const matches = matchAll(searchValue, this.original);
  43429. matches.forEach((match) => {
  43430. if (match.index != null)
  43431. this.overwrite(
  43432. match.index,
  43433. match.index + match[0].length,
  43434. getReplacement(match, this.original)
  43435. );
  43436. });
  43437. } else {
  43438. const match = this.original.match(searchValue);
  43439. if (match && match.index != null)
  43440. this.overwrite(
  43441. match.index,
  43442. match.index + match[0].length,
  43443. getReplacement(match, this.original)
  43444. );
  43445. }
  43446. return this;
  43447. }
  43448. _replaceString(string, replacement) {
  43449. const { original } = this;
  43450. const index = original.indexOf(string);
  43451. if (index !== -1) {
  43452. this.overwrite(index, index + string.length, replacement);
  43453. }
  43454. return this;
  43455. }
  43456. replace(searchValue, replacement) {
  43457. if (typeof searchValue === 'string') {
  43458. return this._replaceString(searchValue, replacement);
  43459. }
  43460. return this._replaceRegexp(searchValue, replacement);
  43461. }
  43462. _replaceAllString(string, replacement) {
  43463. const { original } = this;
  43464. const stringLength = string.length;
  43465. for (
  43466. let index = original.indexOf(string);
  43467. index !== -1;
  43468. index = original.indexOf(string, index + stringLength)
  43469. ) {
  43470. this.overwrite(index, index + stringLength, replacement);
  43471. }
  43472. return this;
  43473. }
  43474. replaceAll(searchValue, replacement) {
  43475. if (typeof searchValue === 'string') {
  43476. return this._replaceAllString(searchValue, replacement);
  43477. }
  43478. if (!searchValue.global) {
  43479. throw new TypeError(
  43480. 'MagicString.prototype.replaceAll called with a non-global RegExp argument'
  43481. );
  43482. }
  43483. return this._replaceRegexp(searchValue, replacement);
  43484. }
  43485. }
  43486. var __defProp$3 = Object.defineProperty;
  43487. var __defProps$3 = Object.defineProperties;
  43488. var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
  43489. var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
  43490. var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
  43491. var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
  43492. var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43493. var __spreadValues$3 = (a, b) => {
  43494. for (var prop in b || (b = {}))
  43495. if (__hasOwnProp$3.call(b, prop))
  43496. __defNormalProp$3(a, prop, b[prop]);
  43497. if (__getOwnPropSymbols$3)
  43498. for (var prop of __getOwnPropSymbols$3(b)) {
  43499. if (__propIsEnum$3.call(b, prop))
  43500. __defNormalProp$3(a, prop, b[prop]);
  43501. }
  43502. return a;
  43503. };
  43504. var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
  43505. const CONVERT_SYMBOL = "$";
  43506. const ESCAPE_SYMBOL = "$$";
  43507. const IMPORT_SOURCE = "vue/macros";
  43508. const shorthands = ["ref", "computed", "shallowRef", "toRef", "customRef"];
  43509. const transformCheckRE = /[^\w]\$(?:\$|ref|computed|shallowRef)?\s*(\(|\<)/;
  43510. function shouldTransform(src) {
  43511. return transformCheckRE.test(src);
  43512. }
  43513. function transform(src, {
  43514. filename,
  43515. sourceMap,
  43516. parserPlugins,
  43517. importHelpersFrom = "vue"
  43518. } = {}) {
  43519. const plugins = parserPlugins || [];
  43520. if (filename) {
  43521. if (/\.tsx?$/.test(filename)) {
  43522. plugins.push("typescript");
  43523. }
  43524. if (filename.endsWith("x")) {
  43525. plugins.push("jsx");
  43526. }
  43527. }
  43528. const ast = parse_1$1(src, {
  43529. sourceType: "module",
  43530. plugins
  43531. });
  43532. const s = new MagicString(src);
  43533. const res = transformAST(ast.program, s, 0);
  43534. if (res.importedHelpers.length) {
  43535. s.prepend(
  43536. `import { ${res.importedHelpers.map((h) => `${h} as _${h}`).join(", ")} } from '${importHelpersFrom}'
  43537. `
  43538. );
  43539. }
  43540. return __spreadProps$3(__spreadValues$3({}, res), {
  43541. code: s.toString(),
  43542. map: sourceMap ? s.generateMap({
  43543. source: filename,
  43544. hires: true,
  43545. includeContent: true
  43546. }) : null
  43547. });
  43548. }
  43549. function transformAST(ast, s, offset = 0, knownRefs, knownProps) {
  43550. warnExperimental();
  43551. const userImports = /* @__PURE__ */ Object.create(null);
  43552. for (const node of ast.body) {
  43553. if (node.type !== "ImportDeclaration")
  43554. continue;
  43555. walkImportDeclaration(node);
  43556. }
  43557. let convertSymbol;
  43558. let escapeSymbol;
  43559. for (const { local, imported, source, specifier } of Object.values(
  43560. userImports
  43561. )) {
  43562. if (source === IMPORT_SOURCE) {
  43563. if (imported === ESCAPE_SYMBOL) {
  43564. escapeSymbol = local;
  43565. } else if (imported === CONVERT_SYMBOL) {
  43566. convertSymbol = local;
  43567. } else if (imported !== local) {
  43568. error(
  43569. `macro imports for ref-creating methods do not support aliasing.`,
  43570. specifier
  43571. );
  43572. }
  43573. }
  43574. }
  43575. if (!convertSymbol && !userImports[CONVERT_SYMBOL]) {
  43576. convertSymbol = CONVERT_SYMBOL;
  43577. }
  43578. if (!escapeSymbol && !userImports[ESCAPE_SYMBOL]) {
  43579. escapeSymbol = ESCAPE_SYMBOL;
  43580. }
  43581. const importedHelpers = /* @__PURE__ */ new Set();
  43582. const rootScope = {};
  43583. const scopeStack = [rootScope];
  43584. let currentScope = rootScope;
  43585. let escapeScope;
  43586. const excludedIds = /* @__PURE__ */ new WeakSet();
  43587. const parentStack = [];
  43588. const propsLocalToPublicMap = /* @__PURE__ */ Object.create(null);
  43589. if (knownRefs) {
  43590. for (const key of knownRefs) {
  43591. rootScope[key] = {};
  43592. }
  43593. }
  43594. if (knownProps) {
  43595. for (const key in knownProps) {
  43596. const { local, isConst } = knownProps[key];
  43597. rootScope[local] = {
  43598. isProp: true,
  43599. isConst: !!isConst
  43600. };
  43601. propsLocalToPublicMap[local] = key;
  43602. }
  43603. }
  43604. function walkImportDeclaration(node) {
  43605. const source = node.source.value;
  43606. if (source === IMPORT_SOURCE) {
  43607. s.remove(node.start + offset, node.end + offset);
  43608. }
  43609. for (const specifier of node.specifiers) {
  43610. const local = specifier.local.name;
  43611. const imported = specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name || "default";
  43612. userImports[local] = {
  43613. source,
  43614. local,
  43615. imported,
  43616. specifier
  43617. };
  43618. }
  43619. }
  43620. function isRefCreationCall(callee) {
  43621. if (!convertSymbol || currentScope[convertSymbol] !== void 0) {
  43622. return false;
  43623. }
  43624. if (callee === convertSymbol) {
  43625. return convertSymbol;
  43626. }
  43627. if (callee[0] === "$" && shorthands.includes(callee.slice(1))) {
  43628. return callee;
  43629. }
  43630. return false;
  43631. }
  43632. function error(msg, node) {
  43633. const e = new Error(msg);
  43634. e.node = node;
  43635. throw e;
  43636. }
  43637. function helper(msg) {
  43638. importedHelpers.add(msg);
  43639. return `_${msg}`;
  43640. }
  43641. function registerBinding(id, binding) {
  43642. excludedIds.add(id);
  43643. if (currentScope) {
  43644. currentScope[id.name] = binding ? binding : false;
  43645. } else {
  43646. error(
  43647. "registerBinding called without active scope, something is wrong.",
  43648. id
  43649. );
  43650. }
  43651. }
  43652. const registerRefBinding = (id, isConst = false) => registerBinding(id, { isConst });
  43653. let tempVarCount = 0;
  43654. function genTempVar() {
  43655. return `__$temp_${++tempVarCount}`;
  43656. }
  43657. function snip(node) {
  43658. return s.original.slice(node.start + offset, node.end + offset);
  43659. }
  43660. function walkScope(node, isRoot = false) {
  43661. for (const stmt of node.body) {
  43662. if (stmt.type === "VariableDeclaration") {
  43663. walkVariableDeclaration(stmt, isRoot);
  43664. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  43665. if (stmt.declare || !stmt.id)
  43666. continue;
  43667. registerBinding(stmt.id);
  43668. } else if ((stmt.type === "ForOfStatement" || stmt.type === "ForInStatement") && stmt.left.type === "VariableDeclaration") {
  43669. walkVariableDeclaration(stmt.left);
  43670. } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration && stmt.declaration.type === "VariableDeclaration") {
  43671. walkVariableDeclaration(stmt.declaration, isRoot);
  43672. } else if (stmt.type === "LabeledStatement" && stmt.body.type === "VariableDeclaration") {
  43673. walkVariableDeclaration(stmt.body, isRoot);
  43674. }
  43675. }
  43676. }
  43677. function walkVariableDeclaration(stmt, isRoot = false) {
  43678. if (stmt.declare) {
  43679. return;
  43680. }
  43681. for (const decl of stmt.declarations) {
  43682. let refCall;
  43683. const isCall = decl.init && decl.init.type === "CallExpression" && decl.init.callee.type === "Identifier";
  43684. if (isCall && (refCall = isRefCreationCall(decl.init.callee.name))) {
  43685. processRefDeclaration(
  43686. refCall,
  43687. decl.id,
  43688. decl.init,
  43689. stmt.kind === "const"
  43690. );
  43691. } else {
  43692. const isProps = isRoot && isCall && decl.init.callee.name === "defineProps";
  43693. for (const id of extractIdentifiers(decl.id)) {
  43694. if (isProps) {
  43695. excludedIds.add(id);
  43696. } else {
  43697. registerBinding(id);
  43698. }
  43699. }
  43700. }
  43701. }
  43702. }
  43703. function processRefDeclaration(method, id, call, isConst) {
  43704. excludedIds.add(call.callee);
  43705. if (method === convertSymbol) {
  43706. s.remove(call.callee.start + offset, call.callee.end + offset);
  43707. if (id.type === "Identifier") {
  43708. registerRefBinding(id, isConst);
  43709. } else if (id.type === "ObjectPattern") {
  43710. processRefObjectPattern(id, call, isConst);
  43711. } else if (id.type === "ArrayPattern") {
  43712. processRefArrayPattern(id, call, isConst);
  43713. }
  43714. } else {
  43715. if (id.type === "Identifier") {
  43716. registerRefBinding(id, isConst);
  43717. s.overwrite(
  43718. call.start + offset,
  43719. call.start + method.length + offset,
  43720. helper(method.slice(1))
  43721. );
  43722. } else {
  43723. error(`${method}() cannot be used with destructure patterns.`, call);
  43724. }
  43725. }
  43726. }
  43727. function processRefObjectPattern(pattern, call, isConst, tempVar, path = []) {
  43728. if (!tempVar) {
  43729. tempVar = genTempVar();
  43730. s.overwrite(pattern.start + offset, pattern.end + offset, tempVar);
  43731. }
  43732. let nameId;
  43733. for (const p of pattern.properties) {
  43734. let key;
  43735. let defaultValue;
  43736. if (p.type === "ObjectProperty") {
  43737. if (p.key.start === p.value.start) {
  43738. nameId = p.key;
  43739. if (p.value.type === "Identifier") {
  43740. excludedIds.add(p.value);
  43741. } else if (p.value.type === "AssignmentPattern" && p.value.left.type === "Identifier") {
  43742. excludedIds.add(p.value.left);
  43743. defaultValue = p.value.right;
  43744. }
  43745. } else {
  43746. key = p.computed ? p.key : p.key.name;
  43747. if (p.value.type === "Identifier") {
  43748. nameId = p.value;
  43749. } else if (p.value.type === "ObjectPattern") {
  43750. processRefObjectPattern(p.value, call, isConst, tempVar, [
  43751. ...path,
  43752. key
  43753. ]);
  43754. } else if (p.value.type === "ArrayPattern") {
  43755. processRefArrayPattern(p.value, call, isConst, tempVar, [
  43756. ...path,
  43757. key
  43758. ]);
  43759. } else if (p.value.type === "AssignmentPattern") {
  43760. if (p.value.left.type === "Identifier") {
  43761. nameId = p.value.left;
  43762. defaultValue = p.value.right;
  43763. } else if (p.value.left.type === "ObjectPattern") {
  43764. processRefObjectPattern(p.value.left, call, isConst, tempVar, [
  43765. ...path,
  43766. [key, p.value.right]
  43767. ]);
  43768. } else if (p.value.left.type === "ArrayPattern") {
  43769. processRefArrayPattern(p.value.left, call, isConst, tempVar, [
  43770. ...path,
  43771. [key, p.value.right]
  43772. ]);
  43773. } else ;
  43774. }
  43775. }
  43776. } else {
  43777. error(`reactivity destructure does not support rest elements.`, p);
  43778. }
  43779. if (nameId) {
  43780. registerRefBinding(nameId, isConst);
  43781. const source = pathToString(tempVar, path);
  43782. const keyStr = isString$2(key) ? `'${key}'` : key ? snip(key) : `'${nameId.name}'`;
  43783. const defaultStr = defaultValue ? `, ${snip(defaultValue)}` : ``;
  43784. s.appendLeft(
  43785. call.end + offset,
  43786. `,
  43787. ${nameId.name} = ${helper(
  43788. "toRef"
  43789. )}(${source}, ${keyStr}${defaultStr})`
  43790. );
  43791. }
  43792. }
  43793. if (nameId) {
  43794. s.appendLeft(call.end + offset, ";");
  43795. }
  43796. }
  43797. function processRefArrayPattern(pattern, call, isConst, tempVar, path = []) {
  43798. if (!tempVar) {
  43799. tempVar = genTempVar();
  43800. s.overwrite(pattern.start + offset, pattern.end + offset, tempVar);
  43801. }
  43802. let nameId;
  43803. for (let i = 0; i < pattern.elements.length; i++) {
  43804. const e = pattern.elements[i];
  43805. if (!e)
  43806. continue;
  43807. let defaultValue;
  43808. if (e.type === "Identifier") {
  43809. nameId = e;
  43810. } else if (e.type === "AssignmentPattern") {
  43811. nameId = e.left;
  43812. defaultValue = e.right;
  43813. } else if (e.type === "RestElement") {
  43814. error(`reactivity destructure does not support rest elements.`, e);
  43815. } else if (e.type === "ObjectPattern") {
  43816. processRefObjectPattern(e, call, isConst, tempVar, [...path, i]);
  43817. } else if (e.type === "ArrayPattern") {
  43818. processRefArrayPattern(e, call, isConst, tempVar, [...path, i]);
  43819. }
  43820. if (nameId) {
  43821. registerRefBinding(nameId, isConst);
  43822. const source = pathToString(tempVar, path);
  43823. const defaultStr = defaultValue ? `, ${snip(defaultValue)}` : ``;
  43824. s.appendLeft(
  43825. call.end + offset,
  43826. `,
  43827. ${nameId.name} = ${helper(
  43828. "toRef"
  43829. )}(${source}, ${i}${defaultStr})`
  43830. );
  43831. }
  43832. }
  43833. if (nameId) {
  43834. s.appendLeft(call.end + offset, ";");
  43835. }
  43836. }
  43837. function pathToString(source, path) {
  43838. if (path.length) {
  43839. for (const seg of path) {
  43840. if (isArray$3(seg)) {
  43841. source = `(${source}${segToString(seg[0])} || ${snip(seg[1])})`;
  43842. } else {
  43843. source += segToString(seg);
  43844. }
  43845. }
  43846. }
  43847. return source;
  43848. }
  43849. function segToString(seg) {
  43850. if (typeof seg === "number") {
  43851. return `[${seg}]`;
  43852. } else if (typeof seg === "string") {
  43853. return `.${seg}`;
  43854. } else {
  43855. return snip(seg);
  43856. }
  43857. }
  43858. function rewriteId(scope, id, parent, parentStack2) {
  43859. if (hasOwn(scope, id.name)) {
  43860. const binding = scope[id.name];
  43861. if (binding) {
  43862. if (binding.isConst && (parent.type === "AssignmentExpression" && id === parent.left || parent.type === "UpdateExpression")) {
  43863. error(`Assignment to constant variable.`, id);
  43864. }
  43865. const { isProp } = binding;
  43866. if (isStaticProperty(parent) && parent.shorthand) {
  43867. if (!parent.inPattern || isInDestructureAssignment(parent, parentStack2)) {
  43868. if (isProp) {
  43869. if (escapeScope) {
  43870. registerEscapedPropBinding(id);
  43871. s.appendLeft(
  43872. id.end + offset,
  43873. `: __props_${propsLocalToPublicMap[id.name]}`
  43874. );
  43875. } else {
  43876. s.appendLeft(
  43877. id.end + offset,
  43878. `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`
  43879. );
  43880. }
  43881. } else {
  43882. s.appendLeft(id.end + offset, `: ${id.name}.value`);
  43883. }
  43884. }
  43885. } else {
  43886. if (isProp) {
  43887. if (escapeScope) {
  43888. registerEscapedPropBinding(id);
  43889. s.overwrite(
  43890. id.start + offset,
  43891. id.end + offset,
  43892. `__props_${propsLocalToPublicMap[id.name]}`
  43893. );
  43894. } else {
  43895. s.overwrite(
  43896. id.start + offset,
  43897. id.end + offset,
  43898. genPropsAccessExp(propsLocalToPublicMap[id.name])
  43899. );
  43900. }
  43901. } else {
  43902. s.appendLeft(id.end + offset, ".value");
  43903. }
  43904. }
  43905. }
  43906. return true;
  43907. }
  43908. return false;
  43909. }
  43910. const propBindingRefs = {};
  43911. function registerEscapedPropBinding(id) {
  43912. if (!propBindingRefs.hasOwnProperty(id.name)) {
  43913. propBindingRefs[id.name] = true;
  43914. const publicKey = propsLocalToPublicMap[id.name];
  43915. s.prependRight(
  43916. offset,
  43917. `const __props_${publicKey} = ${helper(
  43918. `toRef`
  43919. )}(__props, '${publicKey}');
  43920. `
  43921. );
  43922. }
  43923. }
  43924. walkScope(ast, true);
  43925. walk$1(ast, {
  43926. enter(node, parent) {
  43927. parent && parentStack.push(parent);
  43928. if (isFunctionType(node)) {
  43929. scopeStack.push(currentScope = {});
  43930. walkFunctionParams(node, registerBinding);
  43931. if (node.body.type === "BlockStatement") {
  43932. walkScope(node.body);
  43933. }
  43934. return;
  43935. }
  43936. if (node.type === "CatchClause") {
  43937. scopeStack.push(currentScope = {});
  43938. if (node.param && node.param.type === "Identifier") {
  43939. registerBinding(node.param);
  43940. }
  43941. walkScope(node.body);
  43942. return;
  43943. }
  43944. if (node.type === "BlockStatement" && !isFunctionType(parent)) {
  43945. scopeStack.push(currentScope = {});
  43946. walkScope(node);
  43947. return;
  43948. }
  43949. if (parent && parent.type.startsWith("TS") && parent.type !== "TSAsExpression" && parent.type !== "TSNonNullExpression" && parent.type !== "TSTypeAssertion") {
  43950. return this.skip();
  43951. }
  43952. if (node.type === "Identifier") {
  43953. const binding = rootScope[node.name];
  43954. if (
  43955. // if inside $$(), skip unless this is a destructured prop binding
  43956. !(escapeScope && (!binding || !binding.isProp)) && isReferencedIdentifier(node, parent, parentStack) && !excludedIds.has(node)
  43957. ) {
  43958. let i = scopeStack.length;
  43959. while (i--) {
  43960. if (rewriteId(scopeStack[i], node, parent, parentStack)) {
  43961. return;
  43962. }
  43963. }
  43964. }
  43965. }
  43966. if (node.type === "CallExpression" && node.callee.type === "Identifier") {
  43967. const callee = node.callee.name;
  43968. const refCall = isRefCreationCall(callee);
  43969. if (refCall && (!parent || parent.type !== "VariableDeclarator")) {
  43970. return error(
  43971. `${refCall} can only be used as the initializer of a variable declaration.`,
  43972. node
  43973. );
  43974. }
  43975. if (escapeSymbol && currentScope[escapeSymbol] === void 0 && callee === escapeSymbol) {
  43976. escapeScope = node;
  43977. s.remove(node.callee.start + offset, node.callee.end + offset);
  43978. if ((parent == null ? void 0 : parent.type) === "ExpressionStatement") {
  43979. let i = (node.leadingComments ? node.leadingComments[0].start : node.start) + offset;
  43980. while (i--) {
  43981. const char = s.original.charAt(i);
  43982. if (char === "\n") {
  43983. s.prependRight(node.start + offset, ";");
  43984. break;
  43985. } else if (!/\s/.test(char)) {
  43986. break;
  43987. }
  43988. }
  43989. }
  43990. }
  43991. }
  43992. },
  43993. leave(node, parent) {
  43994. parent && parentStack.pop();
  43995. if (node.type === "BlockStatement" && !isFunctionType(parent) || isFunctionType(node)) {
  43996. scopeStack.pop();
  43997. currentScope = scopeStack[scopeStack.length - 1] || null;
  43998. }
  43999. if (node === escapeScope) {
  44000. escapeScope = void 0;
  44001. }
  44002. }
  44003. });
  44004. return {
  44005. rootRefs: Object.keys(rootScope).filter((key) => {
  44006. const binding = rootScope[key];
  44007. return binding && !binding.isProp;
  44008. }),
  44009. importedHelpers: [...importedHelpers]
  44010. };
  44011. }
  44012. const hasWarned = {};
  44013. function warnExperimental() {
  44014. if (typeof window !== "undefined") {
  44015. return;
  44016. }
  44017. warnOnce(
  44018. `Reactivity Transform was an experimental feature and has now been deprecated. It will be removed from Vue core in 3.4. If you intend to continue using it, switch to https://vue-macros.sxzz.moe/features/reactivity-transform.html.
  44019. See reason for deprecation here: https://github.com/vuejs/rfcs/discussions/369#discussioncomment-5059028`
  44020. );
  44021. }
  44022. function warnOnce(msg) {
  44023. const isNodeProd = typeof process !== "undefined" && process.env.NODE_ENV === "production";
  44024. if (!isNodeProd && true && !hasWarned[msg]) {
  44025. hasWarned[msg] = true;
  44026. warn(msg);
  44027. }
  44028. }
  44029. function warn(msg) {
  44030. console.warn(
  44031. `\x1B[1m\x1B[33m[@vue/reactivity-transform]\x1B[0m\x1B[33m ${msg}\x1B[0m
  44032. `
  44033. );
  44034. }
  44035. function analyzeScriptBindings(ast) {
  44036. for (const node of ast) {
  44037. if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "ObjectExpression") {
  44038. return analyzeBindingsFromOptions(node.declaration);
  44039. }
  44040. }
  44041. return {};
  44042. }
  44043. function analyzeBindingsFromOptions(node) {
  44044. const bindings = {};
  44045. Object.defineProperty(bindings, "__isScriptSetup", {
  44046. enumerable: false,
  44047. value: false
  44048. });
  44049. for (const property of node.properties) {
  44050. if (property.type === "ObjectProperty" && !property.computed && property.key.type === "Identifier") {
  44051. if (property.key.name === "props") {
  44052. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  44053. bindings[key] = "props";
  44054. }
  44055. } else if (property.key.name === "inject") {
  44056. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  44057. bindings[key] = "options";
  44058. }
  44059. } else if (property.value.type === "ObjectExpression" && (property.key.name === "computed" || property.key.name === "methods")) {
  44060. for (const key of getObjectExpressionKeys(property.value)) {
  44061. bindings[key] = "options";
  44062. }
  44063. }
  44064. } else if (property.type === "ObjectMethod" && property.key.type === "Identifier" && (property.key.name === "setup" || property.key.name === "data")) {
  44065. for (const bodyItem of property.body.body) {
  44066. if (bodyItem.type === "ReturnStatement" && bodyItem.argument && bodyItem.argument.type === "ObjectExpression") {
  44067. for (const key of getObjectExpressionKeys(bodyItem.argument)) {
  44068. bindings[key] = property.key.name === "setup" ? "setup-maybe-ref" : "data";
  44069. }
  44070. }
  44071. }
  44072. }
  44073. }
  44074. return bindings;
  44075. }
  44076. function getObjectExpressionKeys(node) {
  44077. const keys = [];
  44078. for (const prop of node.properties) {
  44079. if (prop.type === "SpreadElement")
  44080. continue;
  44081. const key = resolveObjectKey(prop.key, prop.computed);
  44082. if (key)
  44083. keys.push(String(key));
  44084. }
  44085. return keys;
  44086. }
  44087. function getArrayExpressionKeys(node) {
  44088. const keys = [];
  44089. for (const element of node.elements) {
  44090. if (element && element.type === "StringLiteral") {
  44091. keys.push(element.value);
  44092. }
  44093. }
  44094. return keys;
  44095. }
  44096. function getObjectOrArrayExpressionKeys(value) {
  44097. if (value.type === "ArrayExpression") {
  44098. return getArrayExpressionKeys(value);
  44099. }
  44100. if (value.type === "ObjectExpression") {
  44101. return getObjectExpressionKeys(value);
  44102. }
  44103. return [];
  44104. }
  44105. function rewriteDefault(input, as, parserPlugins) {
  44106. const ast = parse_1$1(input, {
  44107. sourceType: "module",
  44108. plugins: parserPlugins
  44109. }).program.body;
  44110. const s = new MagicString(input);
  44111. rewriteDefaultAST(ast, s, as);
  44112. return s.toString();
  44113. }
  44114. function rewriteDefaultAST(ast, s, as) {
  44115. if (!hasDefaultExport(ast)) {
  44116. s.append(`
  44117. const ${as} = {}`);
  44118. return;
  44119. }
  44120. ast.forEach((node) => {
  44121. if (node.type === "ExportDefaultDeclaration") {
  44122. if (node.declaration.type === "ClassDeclaration") {
  44123. let start = node.declaration.decorators && node.declaration.decorators.length > 0 ? node.declaration.decorators[node.declaration.decorators.length - 1].end : node.start;
  44124. s.overwrite(start, node.declaration.id.start, ` class `);
  44125. s.append(`
  44126. const ${as} = ${node.declaration.id.name}`);
  44127. } else {
  44128. s.overwrite(node.start, node.declaration.start, `const ${as} = `);
  44129. }
  44130. } else if (node.type === "ExportNamedDeclaration") {
  44131. for (const specifier of node.specifiers) {
  44132. if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier" && specifier.exported.name === "default") {
  44133. if (node.source) {
  44134. if (specifier.local.name === "default") {
  44135. s.prepend(
  44136. `import { default as __VUE_DEFAULT__ } from '${node.source.value}'
  44137. `
  44138. );
  44139. const end2 = specifierEnd(s, specifier.local.end, node.end);
  44140. s.remove(specifier.start, end2);
  44141. s.append(`
  44142. const ${as} = __VUE_DEFAULT__`);
  44143. continue;
  44144. } else {
  44145. s.prepend(
  44146. `import { ${s.slice(
  44147. specifier.local.start,
  44148. specifier.local.end
  44149. )} as __VUE_DEFAULT__ } from '${node.source.value}'
  44150. `
  44151. );
  44152. const end2 = specifierEnd(s, specifier.exported.end, node.end);
  44153. s.remove(specifier.start, end2);
  44154. s.append(`
  44155. const ${as} = __VUE_DEFAULT__`);
  44156. continue;
  44157. }
  44158. }
  44159. const end = specifierEnd(s, specifier.end, node.end);
  44160. s.remove(specifier.start, end);
  44161. s.append(`
  44162. const ${as} = ${specifier.local.name}`);
  44163. }
  44164. }
  44165. }
  44166. });
  44167. }
  44168. function hasDefaultExport(ast) {
  44169. for (const stmt of ast) {
  44170. if (stmt.type === "ExportDefaultDeclaration") {
  44171. return true;
  44172. } else if (stmt.type === "ExportNamedDeclaration" && stmt.specifiers.some(
  44173. (spec) => spec.exported.name === "default"
  44174. )) {
  44175. return true;
  44176. }
  44177. }
  44178. return false;
  44179. }
  44180. function specifierEnd(s, end, nodeEnd) {
  44181. let hasCommas = false;
  44182. let oldEnd = end;
  44183. while (end < nodeEnd) {
  44184. if (/\s/.test(s.slice(end, end + 1))) {
  44185. end++;
  44186. } else if (s.slice(end, end + 1) === ",") {
  44187. end++;
  44188. hasCommas = true;
  44189. break;
  44190. } else if (s.slice(end, end + 1) === "}") {
  44191. break;
  44192. }
  44193. }
  44194. return hasCommas ? end : oldEnd;
  44195. }
  44196. var __defProp$2 = Object.defineProperty;
  44197. var __defProps$2 = Object.defineProperties;
  44198. var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
  44199. var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
  44200. var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
  44201. var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
  44202. var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  44203. var __spreadValues$2 = (a, b) => {
  44204. for (var prop in b || (b = {}))
  44205. if (__hasOwnProp$2.call(b, prop))
  44206. __defNormalProp$2(a, prop, b[prop]);
  44207. if (__getOwnPropSymbols$2)
  44208. for (var prop of __getOwnPropSymbols$2(b)) {
  44209. if (__propIsEnum$2.call(b, prop))
  44210. __defNormalProp$2(a, prop, b[prop]);
  44211. }
  44212. return a;
  44213. };
  44214. var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
  44215. const normalScriptDefaultVar = `__default__`;
  44216. function processNormalScript(ctx, scopeId) {
  44217. const script = ctx.descriptor.script;
  44218. if (script.lang && !ctx.isJS && !ctx.isTS) {
  44219. return script;
  44220. }
  44221. try {
  44222. let content = script.content;
  44223. let map = script.map;
  44224. const scriptAst = ctx.scriptAst;
  44225. const bindings = analyzeScriptBindings(scriptAst.body);
  44226. const { source, filename, cssVars } = ctx.descriptor;
  44227. const { sourceMap, genDefaultAs, isProd } = ctx.options;
  44228. if (ctx.options.reactivityTransform && shouldTransform(content)) {
  44229. const s = new MagicString(source);
  44230. const startOffset = script.loc.start.offset;
  44231. const endOffset = script.loc.end.offset;
  44232. const { importedHelpers } = transformAST(scriptAst, s, startOffset);
  44233. if (importedHelpers.length) {
  44234. s.prepend(
  44235. `import { ${importedHelpers.map((h) => `${h} as _${h}`).join(", ")} } from 'vue'
  44236. `
  44237. );
  44238. }
  44239. s.remove(0, startOffset);
  44240. s.remove(endOffset, source.length);
  44241. content = s.toString();
  44242. if (sourceMap !== false) {
  44243. map = s.generateMap({
  44244. source: filename,
  44245. hires: true,
  44246. includeContent: true
  44247. });
  44248. }
  44249. }
  44250. if (cssVars.length || genDefaultAs) {
  44251. const defaultVar = genDefaultAs || normalScriptDefaultVar;
  44252. const s = new MagicString(content);
  44253. rewriteDefaultAST(scriptAst.body, s, defaultVar);
  44254. content = s.toString();
  44255. if (cssVars.length) {
  44256. content += genNormalScriptCssVarsCode(
  44257. cssVars,
  44258. bindings,
  44259. scopeId,
  44260. !!isProd,
  44261. defaultVar
  44262. );
  44263. }
  44264. if (!genDefaultAs) {
  44265. content += `
  44266. export default ${defaultVar}`;
  44267. }
  44268. }
  44269. return __spreadProps$2(__spreadValues$2({}, script), {
  44270. content,
  44271. map,
  44272. bindings,
  44273. scriptAst: scriptAst.body
  44274. });
  44275. } catch (e) {
  44276. return script;
  44277. }
  44278. }
  44279. var _a, _b;
  44280. class ScriptCompileContext {
  44281. constructor(descriptor, options) {
  44282. this.descriptor = descriptor;
  44283. this.options = options;
  44284. this.source = this.descriptor.source;
  44285. this.filename = this.descriptor.filename;
  44286. this.s = new MagicString(this.source);
  44287. this.startOffset = (_a = this.descriptor.scriptSetup) == null ? void 0 : _a.loc.start.offset;
  44288. this.endOffset = (_b = this.descriptor.scriptSetup) == null ? void 0 : _b.loc.end.offset;
  44289. this.userImports = /* @__PURE__ */ Object.create(null);
  44290. // macros presence check
  44291. this.hasDefinePropsCall = false;
  44292. this.hasDefineEmitCall = false;
  44293. this.hasDefineExposeCall = false;
  44294. this.hasDefaultExportName = false;
  44295. this.hasDefaultExportRender = false;
  44296. this.hasDefineOptionsCall = false;
  44297. this.hasDefineSlotsCall = false;
  44298. this.hasDefineModelCall = false;
  44299. this.propsDestructuredBindings = /* @__PURE__ */ Object.create(null);
  44300. // defineModel
  44301. this.modelDecls = {};
  44302. // codegen
  44303. this.bindingMetadata = {};
  44304. this.helperImports = /* @__PURE__ */ new Set();
  44305. const { script, scriptSetup } = descriptor;
  44306. const scriptLang = script && script.lang;
  44307. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  44308. this.isJS = scriptLang === "js" || scriptLang === "jsx" || scriptSetupLang === "js" || scriptSetupLang === "jsx";
  44309. this.isTS = scriptLang === "ts" || scriptLang === "tsx" || scriptSetupLang === "ts" || scriptSetupLang === "tsx";
  44310. const plugins = resolveParserPlugins(
  44311. scriptLang || scriptSetupLang,
  44312. options.babelParserPlugins
  44313. );
  44314. function parse(input, offset) {
  44315. try {
  44316. return parse_1$1(input, {
  44317. plugins,
  44318. sourceType: "module"
  44319. }).program;
  44320. } catch (e) {
  44321. e.message = `[vue/compiler-sfc] ${e.message}
  44322. ${descriptor.filename}
  44323. ${generateCodeFrame(
  44324. descriptor.source,
  44325. e.pos + offset,
  44326. e.pos + offset + 1
  44327. )}`;
  44328. throw e;
  44329. }
  44330. }
  44331. this.scriptAst = descriptor.script && parse(descriptor.script.content, descriptor.script.loc.start.offset);
  44332. this.scriptSetupAst = descriptor.scriptSetup && parse(descriptor.scriptSetup.content, this.startOffset);
  44333. }
  44334. helper(key) {
  44335. this.helperImports.add(key);
  44336. return `_${key}`;
  44337. }
  44338. getString(node, scriptSetup = true) {
  44339. const block = scriptSetup ? this.descriptor.scriptSetup : this.descriptor.script;
  44340. return block.content.slice(node.start, node.end);
  44341. }
  44342. error(msg, node, scope) {
  44343. const offset = scope ? scope.offset : this.startOffset;
  44344. throw new Error(
  44345. `[@vue/compiler-sfc] ${msg}
  44346. ${(scope || this.descriptor).filename}
  44347. ${generateCodeFrame(
  44348. (scope || this.descriptor).source,
  44349. node.start + offset,
  44350. node.end + offset
  44351. )}`
  44352. );
  44353. }
  44354. }
  44355. function resolveParserPlugins(lang, userPlugins, dts = false) {
  44356. const plugins = [];
  44357. if (lang === "jsx" || lang === "tsx") {
  44358. plugins.push("jsx");
  44359. } else if (userPlugins) {
  44360. userPlugins = userPlugins.filter((p) => p !== "jsx");
  44361. }
  44362. if (lang === "ts" || lang === "tsx") {
  44363. plugins.push(["typescript", { dts }]);
  44364. if (!plugins.includes("decorators")) {
  44365. plugins.push("decorators-legacy");
  44366. }
  44367. }
  44368. if (userPlugins) {
  44369. plugins.push(...userPlugins);
  44370. }
  44371. return plugins;
  44372. }
  44373. var __defProp$1 = Object.defineProperty;
  44374. var __defProps$1 = Object.defineProperties;
  44375. var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
  44376. var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
  44377. var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
  44378. var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
  44379. var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  44380. var __spreadValues$1 = (a, b) => {
  44381. for (var prop in b || (b = {}))
  44382. if (__hasOwnProp$1.call(b, prop))
  44383. __defNormalProp$1(a, prop, b[prop]);
  44384. if (__getOwnPropSymbols$1)
  44385. for (var prop of __getOwnPropSymbols$1(b)) {
  44386. if (__propIsEnum$1.call(b, prop))
  44387. __defNormalProp$1(a, prop, b[prop]);
  44388. }
  44389. return a;
  44390. };
  44391. var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
  44392. class TypeScope {
  44393. constructor(filename, source, offset = 0, imports = /* @__PURE__ */ Object.create(null), types = /* @__PURE__ */ Object.create(null), declares = /* @__PURE__ */ Object.create(null)) {
  44394. this.filename = filename;
  44395. this.source = source;
  44396. this.offset = offset;
  44397. this.imports = imports;
  44398. this.types = types;
  44399. this.declares = declares;
  44400. this.resolvedImportSources = /* @__PURE__ */ Object.create(null);
  44401. this.exportedTypes = /* @__PURE__ */ Object.create(null);
  44402. this.exportedDeclares = /* @__PURE__ */ Object.create(null);
  44403. }
  44404. }
  44405. function resolveTypeElements(ctx, node, scope) {
  44406. if (node._resolvedElements) {
  44407. return node._resolvedElements;
  44408. }
  44409. return node._resolvedElements = innerResolveTypeElements(
  44410. ctx,
  44411. node,
  44412. node._ownerScope || scope || ctxToScope(ctx)
  44413. );
  44414. }
  44415. function innerResolveTypeElements(ctx, node, scope) {
  44416. var _a, _b;
  44417. switch (node.type) {
  44418. case "TSTypeLiteral":
  44419. return typeElementsToMap(ctx, node.members, scope);
  44420. case "TSInterfaceDeclaration":
  44421. return resolveInterfaceMembers(ctx, node, scope);
  44422. case "TSTypeAliasDeclaration":
  44423. case "TSParenthesizedType":
  44424. return resolveTypeElements(ctx, node.typeAnnotation, scope);
  44425. case "TSFunctionType": {
  44426. return { props: {}, calls: [node] };
  44427. }
  44428. case "TSUnionType":
  44429. case "TSIntersectionType":
  44430. return mergeElements(
  44431. node.types.map((t) => resolveTypeElements(ctx, t, scope)),
  44432. node.type
  44433. );
  44434. case "TSMappedType":
  44435. return resolveMappedType(ctx, node, scope);
  44436. case "TSIndexedAccessType": {
  44437. const types = resolveIndexType(ctx, node, scope);
  44438. return mergeElements(
  44439. types.map((t) => resolveTypeElements(ctx, t, t._ownerScope)),
  44440. "TSUnionType"
  44441. );
  44442. }
  44443. case "TSExpressionWithTypeArguments":
  44444. case "TSTypeReference": {
  44445. const typeName = getReferenceName(node);
  44446. if ((typeName === "ExtractPropTypes" || typeName === "ExtractPublicPropTypes") && node.typeParameters && ((_a = scope.imports[typeName]) == null ? void 0 : _a.source) === "vue") {
  44447. return resolveExtractPropTypes(
  44448. resolveTypeElements(ctx, node.typeParameters.params[0], scope),
  44449. scope
  44450. );
  44451. }
  44452. const resolved = resolveTypeReference(ctx, node, scope);
  44453. if (resolved) {
  44454. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  44455. } else {
  44456. if (typeof typeName === "string") {
  44457. if (
  44458. // @ts-ignore
  44459. SupportedBuiltinsSet.has(typeName)
  44460. ) {
  44461. return resolveBuiltin(ctx, node, typeName, scope);
  44462. } else if (typeName === "ReturnType" && node.typeParameters) {
  44463. const ret = resolveReturnType(
  44464. ctx,
  44465. node.typeParameters.params[0],
  44466. scope
  44467. );
  44468. if (ret) {
  44469. return resolveTypeElements(ctx, ret, scope);
  44470. }
  44471. }
  44472. }
  44473. return ctx.error(
  44474. `Unresolvable type reference or unsupported built-in utility type`,
  44475. node,
  44476. scope
  44477. );
  44478. }
  44479. }
  44480. case "TSImportType": {
  44481. if (getId(node.argument) === "vue" && ((_b = node.qualifier) == null ? void 0 : _b.type) === "Identifier" && node.qualifier.name === "ExtractPropTypes" && node.typeParameters) {
  44482. return resolveExtractPropTypes(
  44483. resolveTypeElements(ctx, node.typeParameters.params[0], scope),
  44484. scope
  44485. );
  44486. }
  44487. const sourceScope = importSourceToScope(
  44488. ctx,
  44489. node.argument,
  44490. scope,
  44491. node.argument.value
  44492. );
  44493. const resolved = resolveTypeReference(ctx, node, sourceScope);
  44494. if (resolved) {
  44495. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  44496. }
  44497. }
  44498. case "TSTypeQuery": {
  44499. const resolved = resolveTypeReference(ctx, node, scope);
  44500. if (resolved) {
  44501. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  44502. }
  44503. }
  44504. }
  44505. return ctx.error(`Unresolvable type: ${node.type}`, node, scope);
  44506. }
  44507. function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx)) {
  44508. const res = { props: {} };
  44509. for (const e of elements) {
  44510. if (e.type === "TSPropertySignature" || e.type === "TSMethodSignature") {
  44511. e._ownerScope = scope;
  44512. const name = getId(e.key);
  44513. if (name && !e.computed) {
  44514. res.props[name] = e;
  44515. } else if (e.key.type === "TemplateLiteral") {
  44516. for (const key of resolveTemplateKeys(ctx, e.key, scope)) {
  44517. res.props[key] = e;
  44518. }
  44519. } else {
  44520. ctx.error(
  44521. `Unsupported computed key in type referenced by a macro`,
  44522. e.key,
  44523. scope
  44524. );
  44525. }
  44526. } else if (e.type === "TSCallSignatureDeclaration") {
  44527. (res.calls || (res.calls = [])).push(e);
  44528. }
  44529. }
  44530. return res;
  44531. }
  44532. function mergeElements(maps, type) {
  44533. if (maps.length === 1)
  44534. return maps[0];
  44535. const res = { props: {} };
  44536. const { props: baseProps } = res;
  44537. for (const { props, calls } of maps) {
  44538. for (const key in props) {
  44539. if (!hasOwn(baseProps, key)) {
  44540. baseProps[key] = props[key];
  44541. } else {
  44542. baseProps[key] = createProperty(
  44543. baseProps[key].key,
  44544. {
  44545. type,
  44546. // @ts-ignore
  44547. types: [baseProps[key], props[key]]
  44548. },
  44549. baseProps[key]._ownerScope,
  44550. baseProps[key].optional || props[key].optional
  44551. );
  44552. }
  44553. }
  44554. if (calls) {
  44555. (res.calls || (res.calls = [])).push(...calls);
  44556. }
  44557. }
  44558. return res;
  44559. }
  44560. function createProperty(key, typeAnnotation, scope, optional) {
  44561. return {
  44562. type: "TSPropertySignature",
  44563. key,
  44564. kind: "get",
  44565. optional,
  44566. typeAnnotation: {
  44567. type: "TSTypeAnnotation",
  44568. typeAnnotation
  44569. },
  44570. _ownerScope: scope
  44571. };
  44572. }
  44573. function resolveInterfaceMembers(ctx, node, scope) {
  44574. const base = typeElementsToMap(ctx, node.body.body, node._ownerScope);
  44575. if (node.extends) {
  44576. for (const ext of node.extends) {
  44577. if (ext.leadingComments && ext.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
  44578. continue;
  44579. }
  44580. try {
  44581. const { props } = resolveTypeElements(ctx, ext, scope);
  44582. for (const key in props) {
  44583. if (!hasOwn(base.props, key)) {
  44584. base.props[key] = props[key];
  44585. }
  44586. }
  44587. } catch (e) {
  44588. ctx.error(
  44589. `Failed to resolve extends base type.
  44590. If this previously worked in 3.2, you can instruct the compiler to ignore this extend by adding /* @vue-ignore */ before it, for example:
  44591. interface Props extends /* @vue-ignore */ Base {}
  44592. Note: both in 3.2 or with the ignore, the properties in the base type are treated as fallthrough attrs at runtime.`,
  44593. ext
  44594. );
  44595. }
  44596. }
  44597. }
  44598. return base;
  44599. }
  44600. function resolveMappedType(ctx, node, scope) {
  44601. const res = { props: {} };
  44602. const keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
  44603. for (const key of keys) {
  44604. res.props[key] = createProperty(
  44605. {
  44606. type: "Identifier",
  44607. name: key
  44608. },
  44609. node.typeAnnotation,
  44610. scope,
  44611. !!node.optional
  44612. );
  44613. }
  44614. return res;
  44615. }
  44616. function resolveIndexType(ctx, node, scope) {
  44617. var _a, _b;
  44618. if (node.indexType.type === "TSNumberKeyword") {
  44619. return resolveArrayElementType(ctx, node.objectType, scope);
  44620. }
  44621. const { indexType, objectType } = node;
  44622. const types = [];
  44623. let keys;
  44624. let resolved;
  44625. if (indexType.type === "TSStringKeyword") {
  44626. resolved = resolveTypeElements(ctx, objectType, scope);
  44627. keys = Object.keys(resolved.props);
  44628. } else {
  44629. keys = resolveStringType(ctx, indexType, scope);
  44630. resolved = resolveTypeElements(ctx, objectType, scope);
  44631. }
  44632. for (const key of keys) {
  44633. const targetType = (_b = (_a = resolved.props[key]) == null ? void 0 : _a.typeAnnotation) == null ? void 0 : _b.typeAnnotation;
  44634. if (targetType) {
  44635. targetType._ownerScope = resolved.props[key]._ownerScope;
  44636. types.push(targetType);
  44637. }
  44638. }
  44639. return types;
  44640. }
  44641. function resolveArrayElementType(ctx, node, scope) {
  44642. if (node.type === "TSArrayType") {
  44643. return [node.elementType];
  44644. }
  44645. if (node.type === "TSTupleType") {
  44646. return node.elementTypes.map(
  44647. (t) => t.type === "TSNamedTupleMember" ? t.elementType : t
  44648. );
  44649. }
  44650. if (node.type === "TSTypeReference") {
  44651. if (getReferenceName(node) === "Array" && node.typeParameters) {
  44652. return node.typeParameters.params;
  44653. } else {
  44654. const resolved = resolveTypeReference(ctx, node, scope);
  44655. if (resolved) {
  44656. return resolveArrayElementType(ctx, resolved, scope);
  44657. }
  44658. }
  44659. }
  44660. return ctx.error(
  44661. "Failed to resolve element type from target type",
  44662. node,
  44663. scope
  44664. );
  44665. }
  44666. function resolveStringType(ctx, node, scope) {
  44667. switch (node.type) {
  44668. case "StringLiteral":
  44669. return [node.value];
  44670. case "TSLiteralType":
  44671. return resolveStringType(ctx, node.literal, scope);
  44672. case "TSUnionType":
  44673. return node.types.map((t) => resolveStringType(ctx, t, scope)).flat();
  44674. case "TemplateLiteral": {
  44675. return resolveTemplateKeys(ctx, node, scope);
  44676. }
  44677. case "TSTypeReference": {
  44678. const resolved = resolveTypeReference(ctx, node, scope);
  44679. if (resolved) {
  44680. return resolveStringType(ctx, resolved, scope);
  44681. }
  44682. if (node.typeName.type === "Identifier") {
  44683. const getParam = (index = 0) => resolveStringType(ctx, node.typeParameters.params[index], scope);
  44684. switch (node.typeName.name) {
  44685. case "Extract":
  44686. return getParam(1);
  44687. case "Exclude": {
  44688. const excluded = getParam(1);
  44689. return getParam().filter((s) => !excluded.includes(s));
  44690. }
  44691. case "Uppercase":
  44692. return getParam().map((s) => s.toUpperCase());
  44693. case "Lowercase":
  44694. return getParam().map((s) => s.toLowerCase());
  44695. case "Capitalize":
  44696. return getParam().map(capitalize$1);
  44697. case "Uncapitalize":
  44698. return getParam().map((s) => s[0].toLowerCase() + s.slice(1));
  44699. default:
  44700. ctx.error(
  44701. "Unsupported type when resolving index type",
  44702. node.typeName,
  44703. scope
  44704. );
  44705. }
  44706. }
  44707. }
  44708. }
  44709. return ctx.error("Failed to resolve index type into finite keys", node, scope);
  44710. }
  44711. function resolveTemplateKeys(ctx, node, scope) {
  44712. if (!node.expressions.length) {
  44713. return [node.quasis[0].value.raw];
  44714. }
  44715. const res = [];
  44716. const e = node.expressions[0];
  44717. const q = node.quasis[0];
  44718. const leading = q ? q.value.raw : ``;
  44719. const resolved = resolveStringType(ctx, e, scope);
  44720. const restResolved = resolveTemplateKeys(
  44721. ctx,
  44722. __spreadProps$1(__spreadValues$1({}, node), {
  44723. expressions: node.expressions.slice(1),
  44724. quasis: q ? node.quasis.slice(1) : node.quasis
  44725. }),
  44726. scope
  44727. );
  44728. for (const r of resolved) {
  44729. for (const rr of restResolved) {
  44730. res.push(leading + r + rr);
  44731. }
  44732. }
  44733. return res;
  44734. }
  44735. const SupportedBuiltinsSet = /* @__PURE__ */ new Set([
  44736. "Partial",
  44737. "Required",
  44738. "Readonly",
  44739. "Pick",
  44740. "Omit"
  44741. ]);
  44742. function resolveBuiltin(ctx, node, name, scope) {
  44743. const t = resolveTypeElements(ctx, node.typeParameters.params[0], scope);
  44744. switch (name) {
  44745. case "Partial": {
  44746. const res2 = { props: {}, calls: t.calls };
  44747. Object.keys(t.props).forEach((key) => {
  44748. res2.props[key] = __spreadProps$1(__spreadValues$1({}, t.props[key]), { optional: true });
  44749. });
  44750. return res2;
  44751. }
  44752. case "Required": {
  44753. const res2 = { props: {}, calls: t.calls };
  44754. Object.keys(t.props).forEach((key) => {
  44755. res2.props[key] = __spreadProps$1(__spreadValues$1({}, t.props[key]), { optional: false });
  44756. });
  44757. return res2;
  44758. }
  44759. case "Readonly":
  44760. return t;
  44761. case "Pick": {
  44762. const picked = resolveStringType(
  44763. ctx,
  44764. node.typeParameters.params[1],
  44765. scope
  44766. );
  44767. const res2 = { props: {}, calls: t.calls };
  44768. for (const key of picked) {
  44769. res2.props[key] = t.props[key];
  44770. }
  44771. return res2;
  44772. }
  44773. case "Omit":
  44774. const omitted = resolveStringType(
  44775. ctx,
  44776. node.typeParameters.params[1],
  44777. scope
  44778. );
  44779. const res = { props: {}, calls: t.calls };
  44780. for (const key in t.props) {
  44781. if (!omitted.includes(key)) {
  44782. res.props[key] = t.props[key];
  44783. }
  44784. }
  44785. return res;
  44786. }
  44787. }
  44788. function resolveTypeReference(ctx, node, scope, name, onlyExported = false) {
  44789. if (node._resolvedReference) {
  44790. return node._resolvedReference;
  44791. }
  44792. return node._resolvedReference = innerResolveTypeReference(
  44793. ctx,
  44794. scope || ctxToScope(ctx),
  44795. name || getReferenceName(node),
  44796. node,
  44797. onlyExported
  44798. );
  44799. }
  44800. function innerResolveTypeReference(ctx, scope, name, node, onlyExported) {
  44801. if (typeof name === "string") {
  44802. if (scope.imports[name]) {
  44803. return resolveTypeFromImport(ctx, node, name, scope);
  44804. } else {
  44805. const lookupSource = node.type === "TSTypeQuery" ? onlyExported ? scope.exportedDeclares : scope.declares : onlyExported ? scope.exportedTypes : scope.types;
  44806. if (lookupSource[name]) {
  44807. return lookupSource[name];
  44808. } else {
  44809. const globalScopes = resolveGlobalScope(ctx);
  44810. if (globalScopes) {
  44811. for (const s of globalScopes) {
  44812. const src = node.type === "TSTypeQuery" ? s.declares : s.types;
  44813. if (src[name]) {
  44814. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(s.filename);
  44815. return src[name];
  44816. }
  44817. }
  44818. }
  44819. }
  44820. }
  44821. } else {
  44822. let ns = innerResolveTypeReference(ctx, scope, name[0], node, onlyExported);
  44823. if (ns) {
  44824. if (ns.type !== "TSModuleDeclaration") {
  44825. ns = ns._ns;
  44826. }
  44827. if (ns) {
  44828. const childScope = moduleDeclToScope(ctx, ns, ns._ownerScope || scope);
  44829. return innerResolveTypeReference(
  44830. ctx,
  44831. childScope,
  44832. name.length > 2 ? name.slice(1) : name[name.length - 1],
  44833. node,
  44834. !ns.declare
  44835. );
  44836. }
  44837. }
  44838. }
  44839. }
  44840. function getReferenceName(node) {
  44841. const ref = node.type === "TSTypeReference" ? node.typeName : node.type === "TSExpressionWithTypeArguments" ? node.expression : node.type === "TSImportType" ? node.qualifier : node.exprName;
  44842. if ((ref == null ? void 0 : ref.type) === "Identifier") {
  44843. return ref.name;
  44844. } else if ((ref == null ? void 0 : ref.type) === "TSQualifiedName") {
  44845. return qualifiedNameToPath(ref);
  44846. } else {
  44847. return "default";
  44848. }
  44849. }
  44850. function qualifiedNameToPath(node) {
  44851. if (node.type === "Identifier") {
  44852. return [node.name];
  44853. } else {
  44854. return [...qualifiedNameToPath(node.left), node.right.name];
  44855. }
  44856. }
  44857. function resolveGlobalScope(ctx) {
  44858. if (ctx.options.globalTypeFiles) {
  44859. const fs = resolveFS(ctx);
  44860. if (!fs) {
  44861. throw new Error("[vue/compiler-sfc] globalTypeFiles requires fs access.");
  44862. }
  44863. return ctx.options.globalTypeFiles.map(
  44864. (file) => fileToScope(ctx, normalizePath(file), true)
  44865. );
  44866. }
  44867. }
  44868. let ts;
  44869. function registerTS(_ts) {
  44870. ts = _ts;
  44871. }
  44872. function resolveFS(ctx) {
  44873. if (ctx.fs) {
  44874. return ctx.fs;
  44875. }
  44876. const fs = ctx.options.fs || ts.sys;
  44877. if (!fs) {
  44878. return;
  44879. }
  44880. return ctx.fs = {
  44881. fileExists(file) {
  44882. if (file.endsWith(".vue.ts")) {
  44883. file = file.replace(/\.ts$/, "");
  44884. }
  44885. return fs.fileExists(file);
  44886. },
  44887. readFile(file) {
  44888. if (file.endsWith(".vue.ts")) {
  44889. file = file.replace(/\.ts$/, "");
  44890. }
  44891. return fs.readFile(file);
  44892. }
  44893. };
  44894. }
  44895. function resolveTypeFromImport(ctx, node, name, scope) {
  44896. const { source, imported } = scope.imports[name];
  44897. const sourceScope = importSourceToScope(ctx, node, scope, source);
  44898. return resolveTypeReference(ctx, node, sourceScope, imported, true);
  44899. }
  44900. function importSourceToScope(ctx, node, scope, source) {
  44901. const fs = resolveFS(ctx);
  44902. if (!fs) {
  44903. return ctx.error(
  44904. `No fs option provided to \`compileScript\` in non-Node environment. File system access is required for resolving imported types.`,
  44905. node,
  44906. scope
  44907. );
  44908. }
  44909. let resolved = scope.resolvedImportSources[source];
  44910. if (!resolved) {
  44911. if (source.startsWith(".")) {
  44912. const filename = joinPaths(scope.filename, "..", source);
  44913. resolved = resolveExt(filename, fs);
  44914. } else {
  44915. {
  44916. ctx.error(
  44917. `Type import from non-relative sources is not supported in the browser build.`,
  44918. node,
  44919. scope
  44920. );
  44921. }
  44922. if (!ts) {
  44923. ctx.error(
  44924. `Failed to resolve import source ${JSON.stringify(source)}. typescript is required as a peer dep for vue in order to support resolving types from module imports.`,
  44925. node,
  44926. scope
  44927. );
  44928. }
  44929. resolved = resolveWithTS(scope.filename);
  44930. }
  44931. if (resolved) {
  44932. resolved = scope.resolvedImportSources[source] = normalizePath(resolved);
  44933. }
  44934. }
  44935. if (resolved) {
  44936. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(resolved);
  44937. return fileToScope(ctx, resolved);
  44938. } else {
  44939. return ctx.error(
  44940. `Failed to resolve import source ${JSON.stringify(source)}.`,
  44941. node,
  44942. scope
  44943. );
  44944. }
  44945. }
  44946. function resolveExt(filename, fs) {
  44947. filename = filename.replace(/\.js$/, "");
  44948. const tryResolve = (filename2) => {
  44949. if (fs.fileExists(filename2))
  44950. return filename2;
  44951. };
  44952. return tryResolve(filename) || tryResolve(filename + `.ts`) || tryResolve(filename + `.d.ts`) || tryResolve(joinPaths(filename, `index.ts`)) || tryResolve(joinPaths(filename, `index.d.ts`));
  44953. }
  44954. const tsConfigCache = createCache();
  44955. const tsConfigRefMap = /* @__PURE__ */ new Map();
  44956. function resolveWithTS(containingFile, source, fs) {
  44957. return;
  44958. }
  44959. const fileToScopeCache = createCache();
  44960. function invalidateTypeCache(filename) {
  44961. filename = normalizePath(filename);
  44962. fileToScopeCache.delete(filename);
  44963. tsConfigCache.delete(filename);
  44964. const affectedConfig = tsConfigRefMap.get(filename);
  44965. if (affectedConfig)
  44966. tsConfigCache.delete(affectedConfig);
  44967. }
  44968. function fileToScope(ctx, filename, asGlobal = false) {
  44969. const cached = fileToScopeCache.get(filename);
  44970. if (cached) {
  44971. return cached;
  44972. }
  44973. const fs = resolveFS(ctx);
  44974. const source = fs.readFile(filename) || "";
  44975. const body = parseFile(filename, source, ctx.options.babelParserPlugins);
  44976. const scope = new TypeScope(filename, source, 0, recordImports(body));
  44977. recordTypes(ctx, body, scope, asGlobal);
  44978. fileToScopeCache.set(filename, scope);
  44979. return scope;
  44980. }
  44981. function parseFile(filename, content, parserPlugins) {
  44982. const ext = extname(filename);
  44983. if (ext === ".ts" || ext === ".tsx") {
  44984. return parse_1$1(content, {
  44985. plugins: resolveParserPlugins(
  44986. ext.slice(1),
  44987. parserPlugins,
  44988. filename.endsWith(".d.ts")
  44989. ),
  44990. sourceType: "module"
  44991. }).program.body;
  44992. } else if (ext === ".vue") {
  44993. const {
  44994. descriptor: { script, scriptSetup }
  44995. } = parse$7(content);
  44996. if (!script && !scriptSetup) {
  44997. return [];
  44998. }
  44999. const scriptOffset = script ? script.loc.start.offset : Infinity;
  45000. const scriptSetupOffset = scriptSetup ? scriptSetup.loc.start.offset : Infinity;
  45001. const firstBlock = scriptOffset < scriptSetupOffset ? script : scriptSetup;
  45002. const secondBlock = scriptOffset < scriptSetupOffset ? scriptSetup : script;
  45003. let scriptContent = " ".repeat(Math.min(scriptOffset, scriptSetupOffset)) + firstBlock.content;
  45004. if (secondBlock) {
  45005. scriptContent += " ".repeat(secondBlock.loc.start.offset - script.loc.end.offset) + secondBlock.content;
  45006. }
  45007. const lang = (script == null ? void 0 : script.lang) || (scriptSetup == null ? void 0 : scriptSetup.lang);
  45008. return parse_1$1(scriptContent, {
  45009. plugins: resolveParserPlugins(lang, parserPlugins),
  45010. sourceType: "module"
  45011. }).program.body;
  45012. }
  45013. return [];
  45014. }
  45015. function ctxToScope(ctx) {
  45016. if (ctx.scope) {
  45017. return ctx.scope;
  45018. }
  45019. const body = "ast" in ctx ? ctx.ast : ctx.scriptAst ? [...ctx.scriptAst.body, ...ctx.scriptSetupAst.body] : ctx.scriptSetupAst.body;
  45020. const scope = new TypeScope(
  45021. ctx.filename,
  45022. ctx.source,
  45023. "startOffset" in ctx ? ctx.startOffset : 0,
  45024. "userImports" in ctx ? Object.create(ctx.userImports) : recordImports(body)
  45025. );
  45026. recordTypes(ctx, body, scope);
  45027. return ctx.scope = scope;
  45028. }
  45029. function moduleDeclToScope(ctx, node, parentScope) {
  45030. if (node._resolvedChildScope) {
  45031. return node._resolvedChildScope;
  45032. }
  45033. const scope = new TypeScope(
  45034. parentScope.filename,
  45035. parentScope.source,
  45036. parentScope.offset,
  45037. Object.create(parentScope.imports),
  45038. Object.create(parentScope.types),
  45039. Object.create(parentScope.declares)
  45040. );
  45041. if (node.body.type === "TSModuleDeclaration") {
  45042. const decl = node.body;
  45043. decl._ownerScope = scope;
  45044. const id = getId(decl.id);
  45045. scope.types[id] = scope.exportedTypes[id] = decl;
  45046. } else {
  45047. recordTypes(ctx, node.body.body, scope);
  45048. }
  45049. return node._resolvedChildScope = scope;
  45050. }
  45051. const importExportRE = /^Import|^Export/;
  45052. function recordTypes(ctx, body, scope, asGlobal = false) {
  45053. const { types, declares, exportedTypes, exportedDeclares, imports } = scope;
  45054. const isAmbient = asGlobal ? !body.some((s) => importExportRE.test(s.type)) : false;
  45055. for (const stmt of body) {
  45056. if (asGlobal) {
  45057. if (isAmbient) {
  45058. if (stmt.declare) {
  45059. recordType(stmt, types, declares);
  45060. }
  45061. } else if (stmt.type === "TSModuleDeclaration" && stmt.global) {
  45062. for (const s of stmt.body.body) {
  45063. recordType(s, types, declares);
  45064. }
  45065. }
  45066. } else {
  45067. recordType(stmt, types, declares);
  45068. }
  45069. }
  45070. if (!asGlobal) {
  45071. for (const stmt of body) {
  45072. if (stmt.type === "ExportNamedDeclaration") {
  45073. if (stmt.declaration) {
  45074. recordType(stmt.declaration, types, declares);
  45075. recordType(stmt.declaration, exportedTypes, exportedDeclares);
  45076. } else {
  45077. for (const spec of stmt.specifiers) {
  45078. if (spec.type === "ExportSpecifier") {
  45079. const local = spec.local.name;
  45080. const exported = getId(spec.exported);
  45081. if (stmt.source) {
  45082. imports[local] = {
  45083. source: stmt.source.value,
  45084. imported: local
  45085. };
  45086. exportedTypes[exported] = {
  45087. type: "TSTypeReference",
  45088. typeName: {
  45089. type: "Identifier",
  45090. name: local
  45091. },
  45092. _ownerScope: scope
  45093. };
  45094. } else if (types[local]) {
  45095. exportedTypes[exported] = types[local];
  45096. }
  45097. }
  45098. }
  45099. }
  45100. } else if (stmt.type === "ExportAllDeclaration") {
  45101. const sourceScope = importSourceToScope(
  45102. ctx,
  45103. stmt.source,
  45104. scope,
  45105. stmt.source.value
  45106. );
  45107. Object.assign(scope.exportedTypes, sourceScope.exportedTypes);
  45108. } else if (stmt.type === "ExportDefaultDeclaration" && stmt.declaration) {
  45109. if (stmt.declaration.type !== "Identifier") {
  45110. recordType(stmt.declaration, types, declares, "default");
  45111. recordType(
  45112. stmt.declaration,
  45113. exportedTypes,
  45114. exportedDeclares,
  45115. "default"
  45116. );
  45117. } else if (types[stmt.declaration.name]) {
  45118. exportedTypes["default"] = types[stmt.declaration.name];
  45119. }
  45120. }
  45121. }
  45122. }
  45123. for (const key of Object.keys(types)) {
  45124. const node = types[key];
  45125. node._ownerScope = scope;
  45126. if (node._ns)
  45127. node._ns._ownerScope = scope;
  45128. }
  45129. for (const key of Object.keys(declares)) {
  45130. declares[key]._ownerScope = scope;
  45131. }
  45132. }
  45133. function recordType(node, types, declares, overwriteId) {
  45134. switch (node.type) {
  45135. case "TSInterfaceDeclaration":
  45136. case "TSEnumDeclaration":
  45137. case "TSModuleDeclaration": {
  45138. const id = overwriteId || getId(node.id);
  45139. let existing = types[id];
  45140. if (existing) {
  45141. if (node.type === "TSModuleDeclaration") {
  45142. if (existing.type === "TSModuleDeclaration") {
  45143. mergeNamespaces(existing, node);
  45144. } else {
  45145. attachNamespace(existing, node);
  45146. }
  45147. break;
  45148. }
  45149. if (existing.type === "TSModuleDeclaration") {
  45150. types[id] = node;
  45151. attachNamespace(node, existing);
  45152. break;
  45153. }
  45154. if (existing.type !== node.type) {
  45155. break;
  45156. }
  45157. if (node.type === "TSInterfaceDeclaration") {
  45158. existing.body.body.push(...node.body.body);
  45159. } else {
  45160. existing.members.push(...node.members);
  45161. }
  45162. } else {
  45163. types[id] = node;
  45164. }
  45165. break;
  45166. }
  45167. case "ClassDeclaration":
  45168. types[overwriteId || getId(node.id)] = node;
  45169. break;
  45170. case "TSTypeAliasDeclaration":
  45171. types[node.id.name] = node.typeAnnotation;
  45172. break;
  45173. case "TSDeclareFunction":
  45174. if (node.id)
  45175. declares[node.id.name] = node;
  45176. break;
  45177. case "VariableDeclaration": {
  45178. if (node.declare) {
  45179. for (const decl of node.declarations) {
  45180. if (decl.id.type === "Identifier" && decl.id.typeAnnotation) {
  45181. declares[decl.id.name] = decl.id.typeAnnotation.typeAnnotation;
  45182. }
  45183. }
  45184. }
  45185. break;
  45186. }
  45187. }
  45188. }
  45189. function mergeNamespaces(to, from) {
  45190. const toBody = to.body;
  45191. const fromBody = from.body;
  45192. if (toBody.type === "TSModuleDeclaration") {
  45193. if (fromBody.type === "TSModuleDeclaration") {
  45194. mergeNamespaces(toBody, fromBody);
  45195. } else {
  45196. fromBody.body.push({
  45197. type: "ExportNamedDeclaration",
  45198. declaration: toBody,
  45199. exportKind: "type",
  45200. specifiers: []
  45201. });
  45202. }
  45203. } else if (fromBody.type === "TSModuleDeclaration") {
  45204. toBody.body.push({
  45205. type: "ExportNamedDeclaration",
  45206. declaration: fromBody,
  45207. exportKind: "type",
  45208. specifiers: []
  45209. });
  45210. } else {
  45211. toBody.body.push(...fromBody.body);
  45212. }
  45213. }
  45214. function attachNamespace(to, ns) {
  45215. if (!to._ns) {
  45216. to._ns = ns;
  45217. } else {
  45218. mergeNamespaces(to._ns, ns);
  45219. }
  45220. }
  45221. function recordImports(body) {
  45222. const imports = /* @__PURE__ */ Object.create(null);
  45223. for (const s of body) {
  45224. recordImport(s, imports);
  45225. }
  45226. return imports;
  45227. }
  45228. function recordImport(node, imports) {
  45229. if (node.type !== "ImportDeclaration") {
  45230. return;
  45231. }
  45232. for (const s of node.specifiers) {
  45233. imports[s.local.name] = {
  45234. imported: getImportedName(s),
  45235. source: node.source.value
  45236. };
  45237. }
  45238. }
  45239. function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)) {
  45240. try {
  45241. switch (node.type) {
  45242. case "TSStringKeyword":
  45243. return ["String"];
  45244. case "TSNumberKeyword":
  45245. return ["Number"];
  45246. case "TSBooleanKeyword":
  45247. return ["Boolean"];
  45248. case "TSObjectKeyword":
  45249. return ["Object"];
  45250. case "TSNullKeyword":
  45251. return ["null"];
  45252. case "TSTypeLiteral":
  45253. case "TSInterfaceDeclaration": {
  45254. const types = /* @__PURE__ */ new Set();
  45255. const members = node.type === "TSTypeLiteral" ? node.members : node.body.body;
  45256. for (const m of members) {
  45257. if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
  45258. types.add("Function");
  45259. } else {
  45260. types.add("Object");
  45261. }
  45262. }
  45263. return types.size ? Array.from(types) : ["Object"];
  45264. }
  45265. case "TSPropertySignature":
  45266. if (node.typeAnnotation) {
  45267. return inferRuntimeType(
  45268. ctx,
  45269. node.typeAnnotation.typeAnnotation,
  45270. scope
  45271. );
  45272. }
  45273. case "TSMethodSignature":
  45274. case "TSFunctionType":
  45275. return ["Function"];
  45276. case "TSArrayType":
  45277. case "TSTupleType":
  45278. return ["Array"];
  45279. case "TSLiteralType":
  45280. switch (node.literal.type) {
  45281. case "StringLiteral":
  45282. return ["String"];
  45283. case "BooleanLiteral":
  45284. return ["Boolean"];
  45285. case "NumericLiteral":
  45286. case "BigIntLiteral":
  45287. return ["Number"];
  45288. default:
  45289. return [UNKNOWN_TYPE];
  45290. }
  45291. case "TSTypeReference": {
  45292. const resolved = resolveTypeReference(ctx, node, scope);
  45293. if (resolved) {
  45294. return inferRuntimeType(ctx, resolved, resolved._ownerScope);
  45295. }
  45296. if (node.typeName.type === "Identifier") {
  45297. switch (node.typeName.name) {
  45298. case "Array":
  45299. case "Function":
  45300. case "Object":
  45301. case "Set":
  45302. case "Map":
  45303. case "WeakSet":
  45304. case "WeakMap":
  45305. case "Date":
  45306. case "Promise":
  45307. return [node.typeName.name];
  45308. case "Partial":
  45309. case "Required":
  45310. case "Readonly":
  45311. case "Record":
  45312. case "Pick":
  45313. case "Omit":
  45314. case "InstanceType":
  45315. return ["Object"];
  45316. case "Uppercase":
  45317. case "Lowercase":
  45318. case "Capitalize":
  45319. case "Uncapitalize":
  45320. return ["String"];
  45321. case "Parameters":
  45322. case "ConstructorParameters":
  45323. return ["Array"];
  45324. case "NonNullable":
  45325. if (node.typeParameters && node.typeParameters.params[0]) {
  45326. return inferRuntimeType(
  45327. ctx,
  45328. node.typeParameters.params[0],
  45329. scope
  45330. ).filter((t) => t !== "null");
  45331. }
  45332. break;
  45333. case "Extract":
  45334. if (node.typeParameters && node.typeParameters.params[1]) {
  45335. return inferRuntimeType(
  45336. ctx,
  45337. node.typeParameters.params[1],
  45338. scope
  45339. );
  45340. }
  45341. break;
  45342. case "Exclude":
  45343. case "OmitThisParameter":
  45344. if (node.typeParameters && node.typeParameters.params[0]) {
  45345. return inferRuntimeType(
  45346. ctx,
  45347. node.typeParameters.params[0],
  45348. scope
  45349. );
  45350. }
  45351. break;
  45352. }
  45353. }
  45354. break;
  45355. }
  45356. case "TSParenthesizedType":
  45357. return inferRuntimeType(ctx, node.typeAnnotation, scope);
  45358. case "TSUnionType":
  45359. return flattenTypes(ctx, node.types, scope);
  45360. case "TSIntersectionType": {
  45361. return flattenTypes(ctx, node.types, scope).filter(
  45362. (t) => t !== UNKNOWN_TYPE
  45363. );
  45364. }
  45365. case "TSEnumDeclaration":
  45366. return inferEnumType(node);
  45367. case "TSSymbolKeyword":
  45368. return ["Symbol"];
  45369. case "TSIndexedAccessType": {
  45370. const types = resolveIndexType(ctx, node, scope);
  45371. return flattenTypes(ctx, types, scope);
  45372. }
  45373. case "ClassDeclaration":
  45374. return ["Object"];
  45375. case "TSImportType": {
  45376. const sourceScope = importSourceToScope(
  45377. ctx,
  45378. node.argument,
  45379. scope,
  45380. node.argument.value
  45381. );
  45382. const resolved = resolveTypeReference(ctx, node, sourceScope);
  45383. if (resolved) {
  45384. return inferRuntimeType(ctx, resolved, resolved._ownerScope);
  45385. }
  45386. break;
  45387. }
  45388. case "TSTypeQuery": {
  45389. const id = node.exprName;
  45390. if (id.type === "Identifier") {
  45391. const matched = scope.declares[id.name];
  45392. if (matched) {
  45393. return inferRuntimeType(ctx, matched, matched._ownerScope);
  45394. }
  45395. }
  45396. break;
  45397. }
  45398. }
  45399. } catch (e) {
  45400. }
  45401. return [UNKNOWN_TYPE];
  45402. }
  45403. function flattenTypes(ctx, types, scope) {
  45404. if (types.length === 1) {
  45405. return inferRuntimeType(ctx, types[0], scope);
  45406. }
  45407. return [
  45408. ...new Set(
  45409. [].concat(
  45410. ...types.map((t) => inferRuntimeType(ctx, t, scope))
  45411. )
  45412. )
  45413. ];
  45414. }
  45415. function inferEnumType(node) {
  45416. const types = /* @__PURE__ */ new Set();
  45417. for (const m of node.members) {
  45418. if (m.initializer) {
  45419. switch (m.initializer.type) {
  45420. case "StringLiteral":
  45421. types.add("String");
  45422. break;
  45423. case "NumericLiteral":
  45424. types.add("Number");
  45425. break;
  45426. }
  45427. }
  45428. }
  45429. return types.size ? [...types] : ["Number"];
  45430. }
  45431. function resolveExtractPropTypes({ props }, scope) {
  45432. const res = { props: {} };
  45433. for (const key in props) {
  45434. const raw = props[key];
  45435. res.props[key] = reverseInferType(
  45436. raw.key,
  45437. raw.typeAnnotation.typeAnnotation,
  45438. scope
  45439. );
  45440. }
  45441. return res;
  45442. }
  45443. function reverseInferType(key, node, scope, optional = true, checkObjectSyntax = true) {
  45444. if (checkObjectSyntax && node.type === "TSTypeLiteral") {
  45445. const typeType = findStaticPropertyType(node, "type");
  45446. if (typeType) {
  45447. const requiredType = findStaticPropertyType(node, "required");
  45448. const optional2 = requiredType && requiredType.type === "TSLiteralType" && requiredType.literal.type === "BooleanLiteral" ? !requiredType.literal.value : true;
  45449. return reverseInferType(key, typeType, scope, optional2, false);
  45450. }
  45451. } else if (node.type === "TSTypeReference" && node.typeName.type === "Identifier") {
  45452. if (node.typeName.name.endsWith("Constructor")) {
  45453. return createProperty(
  45454. key,
  45455. ctorToType(node.typeName.name),
  45456. scope,
  45457. optional
  45458. );
  45459. } else if (node.typeName.name === "PropType" && node.typeParameters) {
  45460. return createProperty(key, node.typeParameters.params[0], scope, optional);
  45461. }
  45462. }
  45463. if ((node.type === "TSTypeReference" || node.type === "TSImportType") && node.typeParameters) {
  45464. for (const t of node.typeParameters.params) {
  45465. const inferred = reverseInferType(key, t, scope, optional);
  45466. if (inferred)
  45467. return inferred;
  45468. }
  45469. }
  45470. return createProperty(key, { type: `TSNullKeyword` }, scope, optional);
  45471. }
  45472. function ctorToType(ctorType) {
  45473. const ctor = ctorType.slice(0, -11);
  45474. switch (ctor) {
  45475. case "String":
  45476. case "Number":
  45477. case "Boolean":
  45478. return { type: `TS${ctor}Keyword` };
  45479. case "Array":
  45480. case "Function":
  45481. case "Object":
  45482. case "Set":
  45483. case "Map":
  45484. case "WeakSet":
  45485. case "WeakMap":
  45486. case "Date":
  45487. case "Promise":
  45488. return {
  45489. type: "TSTypeReference",
  45490. typeName: { type: "Identifier", name: ctor }
  45491. };
  45492. }
  45493. return { type: `TSNullKeyword` };
  45494. }
  45495. function findStaticPropertyType(node, key) {
  45496. const prop = node.members.find(
  45497. (m) => m.type === "TSPropertySignature" && !m.computed && getId(m.key) === key && m.typeAnnotation
  45498. );
  45499. return prop && prop.typeAnnotation.typeAnnotation;
  45500. }
  45501. function resolveReturnType(ctx, arg, scope) {
  45502. var _a;
  45503. let resolved = arg;
  45504. if (arg.type === "TSTypeReference" || arg.type === "TSTypeQuery" || arg.type === "TSImportType") {
  45505. resolved = resolveTypeReference(ctx, arg, scope);
  45506. }
  45507. if (!resolved)
  45508. return;
  45509. if (resolved.type === "TSFunctionType") {
  45510. return (_a = resolved.typeAnnotation) == null ? void 0 : _a.typeAnnotation;
  45511. }
  45512. if (resolved.type === "TSDeclareFunction") {
  45513. return resolved.returnType;
  45514. }
  45515. }
  45516. function resolveUnionType(ctx, node, scope) {
  45517. if (node.type === "TSTypeReference") {
  45518. const resolved = resolveTypeReference(ctx, node, scope);
  45519. if (resolved)
  45520. node = resolved;
  45521. }
  45522. let types;
  45523. if (node.type === "TSUnionType") {
  45524. types = node.types.flatMap((node2) => resolveUnionType(ctx, node2, scope));
  45525. } else {
  45526. types = [node];
  45527. }
  45528. return types;
  45529. }
  45530. const DEFINE_MODEL = "defineModel";
  45531. function processDefineModel(ctx, node, declId) {
  45532. if (!ctx.options.defineModel || !isCallOf(node, DEFINE_MODEL)) {
  45533. return false;
  45534. }
  45535. warnOnce$4(
  45536. `This project is using defineModel(), which is an experimental feature. It may receive breaking changes or be removed in the future, so use at your own risk.
  45537. To stay updated, follow the RFC at https://github.com/vuejs/rfcs/discussions/503.`
  45538. );
  45539. ctx.hasDefineModelCall = true;
  45540. const type = node.typeParameters && node.typeParameters.params[0] || void 0;
  45541. let modelName;
  45542. let options;
  45543. const arg0 = node.arguments[0] && unwrapTSNode(node.arguments[0]);
  45544. if (arg0 && arg0.type === "StringLiteral") {
  45545. modelName = arg0.value;
  45546. options = node.arguments[1];
  45547. } else {
  45548. modelName = "modelValue";
  45549. options = arg0;
  45550. }
  45551. if (ctx.modelDecls[modelName]) {
  45552. ctx.error(`duplicate model name ${JSON.stringify(modelName)}`, node);
  45553. }
  45554. const optionsString = options && ctx.getString(options);
  45555. ctx.modelDecls[modelName] = {
  45556. type,
  45557. options: optionsString,
  45558. identifier: declId && declId.type === "Identifier" ? declId.name : void 0
  45559. };
  45560. ctx.bindingMetadata[modelName] = "props";
  45561. let runtimeOptions = "";
  45562. if (options) {
  45563. if (options.type === "ObjectExpression") {
  45564. const local = options.properties.find(
  45565. (p) => p.type === "ObjectProperty" && (p.key.type === "Identifier" && p.key.name === "local" || p.key.type === "StringLiteral" && p.key.value === "local")
  45566. );
  45567. if (local) {
  45568. runtimeOptions = `{ ${ctx.getString(local)} }`;
  45569. } else {
  45570. for (const p of options.properties) {
  45571. if (p.type === "SpreadElement" || p.computed) {
  45572. runtimeOptions = optionsString;
  45573. break;
  45574. }
  45575. }
  45576. }
  45577. } else {
  45578. runtimeOptions = optionsString;
  45579. }
  45580. }
  45581. ctx.s.overwrite(
  45582. ctx.startOffset + node.start,
  45583. ctx.startOffset + node.end,
  45584. `${ctx.helper("useModel")}(__props, ${JSON.stringify(modelName)}${runtimeOptions ? `, ${runtimeOptions}` : ``})`
  45585. );
  45586. return true;
  45587. }
  45588. function genModelProps(ctx) {
  45589. if (!ctx.hasDefineModelCall)
  45590. return;
  45591. const isProd = !!ctx.options.isProd;
  45592. let modelPropsDecl = "";
  45593. for (const [name, { type, options }] of Object.entries(ctx.modelDecls)) {
  45594. let skipCheck = false;
  45595. let runtimeTypes = type && inferRuntimeType(ctx, type);
  45596. if (runtimeTypes) {
  45597. const hasUnknownType = runtimeTypes.includes(UNKNOWN_TYPE);
  45598. runtimeTypes = runtimeTypes.filter((el) => {
  45599. if (el === UNKNOWN_TYPE)
  45600. return false;
  45601. return isProd ? el === "Boolean" || el === "Function" && options : true;
  45602. });
  45603. skipCheck = !isProd && hasUnknownType && runtimeTypes.length > 0;
  45604. }
  45605. let runtimeType = runtimeTypes && runtimeTypes.length > 0 && toRuntimeTypeString(runtimeTypes) || void 0;
  45606. const codegenOptions = concatStrings([
  45607. runtimeType && `type: ${runtimeType}`,
  45608. skipCheck && "skipCheck: true"
  45609. ]);
  45610. let decl;
  45611. if (runtimeType && options) {
  45612. decl = ctx.isTS ? `{ ${codegenOptions}, ...${options} }` : `Object.assign({ ${codegenOptions} }, ${options})`;
  45613. } else {
  45614. decl = options || (runtimeType ? `{ ${codegenOptions} }` : "{}");
  45615. }
  45616. modelPropsDecl += `
  45617. ${JSON.stringify(name)}: ${decl},`;
  45618. }
  45619. return `{${modelPropsDecl}
  45620. }`;
  45621. }
  45622. const DEFINE_PROPS = "defineProps";
  45623. const WITH_DEFAULTS = "withDefaults";
  45624. function processDefineProps(ctx, node, declId) {
  45625. if (!isCallOf(node, DEFINE_PROPS)) {
  45626. return processWithDefaults(ctx, node, declId);
  45627. }
  45628. if (ctx.hasDefinePropsCall) {
  45629. ctx.error(`duplicate ${DEFINE_PROPS}() call`, node);
  45630. }
  45631. ctx.hasDefinePropsCall = true;
  45632. ctx.propsRuntimeDecl = node.arguments[0];
  45633. if (ctx.propsRuntimeDecl) {
  45634. for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) {
  45635. if (!(key in ctx.bindingMetadata)) {
  45636. ctx.bindingMetadata[key] = "props";
  45637. }
  45638. }
  45639. }
  45640. if (node.typeParameters) {
  45641. if (ctx.propsRuntimeDecl) {
  45642. ctx.error(
  45643. `${DEFINE_PROPS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  45644. node
  45645. );
  45646. }
  45647. ctx.propsTypeDecl = node.typeParameters.params[0];
  45648. }
  45649. if (declId) {
  45650. if (declId.type === "ObjectPattern") {
  45651. processPropsDestructure(ctx, declId);
  45652. } else {
  45653. ctx.propsIdentifier = ctx.getString(declId);
  45654. }
  45655. }
  45656. return true;
  45657. }
  45658. function processWithDefaults(ctx, node, declId) {
  45659. if (!isCallOf(node, WITH_DEFAULTS)) {
  45660. return false;
  45661. }
  45662. if (processDefineProps(ctx, node.arguments[0], declId)) {
  45663. if (ctx.propsRuntimeDecl) {
  45664. ctx.error(
  45665. `${WITH_DEFAULTS} can only be used with type-based ${DEFINE_PROPS} declaration.`,
  45666. node
  45667. );
  45668. }
  45669. if (ctx.propsDestructureDecl) {
  45670. ctx.error(
  45671. `${WITH_DEFAULTS}() is unnecessary when using destructure with ${DEFINE_PROPS}().
  45672. Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(...).`,
  45673. node.callee
  45674. );
  45675. }
  45676. ctx.propsRuntimeDefaults = node.arguments[1];
  45677. if (!ctx.propsRuntimeDefaults) {
  45678. ctx.error(`The 2nd argument of ${WITH_DEFAULTS} is required.`, node);
  45679. }
  45680. } else {
  45681. ctx.error(
  45682. `${WITH_DEFAULTS}' first argument must be a ${DEFINE_PROPS} call.`,
  45683. node.arguments[0] || node
  45684. );
  45685. }
  45686. return true;
  45687. }
  45688. function genRuntimeProps(ctx) {
  45689. let propsDecls;
  45690. if (ctx.propsRuntimeDecl) {
  45691. propsDecls = ctx.getString(ctx.propsRuntimeDecl).trim();
  45692. if (ctx.propsDestructureDecl) {
  45693. const defaults = [];
  45694. for (const key in ctx.propsDestructuredBindings) {
  45695. const d = genDestructuredDefaultValue(ctx, key);
  45696. const finalKey = getEscapedKey(key);
  45697. if (d)
  45698. defaults.push(
  45699. `${finalKey}: ${d.valueString}${d.needSkipFactory ? `, __skip_${finalKey}: true` : ``}`
  45700. );
  45701. }
  45702. if (defaults.length) {
  45703. propsDecls = `${ctx.helper(
  45704. `mergeDefaults`
  45705. )}(${propsDecls}, {
  45706. ${defaults.join(",\n ")}
  45707. })`;
  45708. }
  45709. }
  45710. } else if (ctx.propsTypeDecl) {
  45711. propsDecls = genRuntimePropsFromTypes(ctx);
  45712. }
  45713. const modelsDecls = genModelProps(ctx);
  45714. if (propsDecls && modelsDecls) {
  45715. return `${ctx.helper("mergeModels")}(${propsDecls}, ${modelsDecls})`;
  45716. } else {
  45717. return modelsDecls || propsDecls;
  45718. }
  45719. }
  45720. function genRuntimePropsFromTypes(ctx) {
  45721. const props = resolveRuntimePropsFromType(ctx, ctx.propsTypeDecl);
  45722. if (!props.length) {
  45723. return;
  45724. }
  45725. const propStrings = [];
  45726. const hasStaticDefaults = hasStaticWithDefaults(ctx);
  45727. for (const prop of props) {
  45728. propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults));
  45729. if (!(prop.key in ctx.bindingMetadata)) {
  45730. ctx.bindingMetadata[prop.key] = "props";
  45731. }
  45732. }
  45733. let propsDecls = `{
  45734. ${propStrings.join(",\n ")}
  45735. }`;
  45736. if (ctx.propsRuntimeDefaults && !hasStaticDefaults) {
  45737. propsDecls = `${ctx.helper("mergeDefaults")}(${propsDecls}, ${ctx.getString(
  45738. ctx.propsRuntimeDefaults
  45739. )})`;
  45740. }
  45741. return propsDecls;
  45742. }
  45743. function resolveRuntimePropsFromType(ctx, node) {
  45744. const props = [];
  45745. const elements = resolveTypeElements(ctx, node);
  45746. for (const key in elements.props) {
  45747. const e = elements.props[key];
  45748. let type = inferRuntimeType(ctx, e);
  45749. let skipCheck = false;
  45750. if (type.includes(UNKNOWN_TYPE)) {
  45751. if (type.includes("Boolean") || type.includes("Function")) {
  45752. type = type.filter((t) => t !== UNKNOWN_TYPE);
  45753. skipCheck = true;
  45754. } else {
  45755. type = ["null"];
  45756. }
  45757. }
  45758. props.push({
  45759. key,
  45760. required: !e.optional,
  45761. type: type || [`null`],
  45762. skipCheck
  45763. });
  45764. }
  45765. return props;
  45766. }
  45767. function genRuntimePropFromType(ctx, { key, required, type, skipCheck }, hasStaticDefaults) {
  45768. let defaultString;
  45769. const destructured = genDestructuredDefaultValue(ctx, key, type);
  45770. if (destructured) {
  45771. defaultString = `default: ${destructured.valueString}${destructured.needSkipFactory ? `, skipFactory: true` : ``}`;
  45772. } else if (hasStaticDefaults) {
  45773. const prop = ctx.propsRuntimeDefaults.properties.find(
  45774. (node) => {
  45775. if (node.type === "SpreadElement")
  45776. return false;
  45777. return resolveObjectKey(node.key, node.computed) === key;
  45778. }
  45779. );
  45780. if (prop) {
  45781. if (prop.type === "ObjectProperty") {
  45782. defaultString = `default: ${ctx.getString(prop.value)}`;
  45783. } else {
  45784. defaultString = `${prop.async ? "async " : ""}${prop.kind !== "method" ? `${prop.kind} ` : ""}default() ${ctx.getString(prop.body)}`;
  45785. }
  45786. }
  45787. }
  45788. const finalKey = getEscapedKey(key);
  45789. if (!ctx.options.isProd) {
  45790. return `${finalKey}: { ${concatStrings([
  45791. `type: ${toRuntimeTypeString(type)}`,
  45792. `required: ${required}`,
  45793. skipCheck && "skipCheck: true",
  45794. defaultString
  45795. ])} }`;
  45796. } else if (type.some(
  45797. (el) => el === "Boolean" || (!hasStaticDefaults || defaultString) && el === "Function"
  45798. )) {
  45799. return `${finalKey}: { ${concatStrings([
  45800. `type: ${toRuntimeTypeString(type)}`,
  45801. defaultString
  45802. ])} }`;
  45803. } else {
  45804. return `${finalKey}: ${defaultString ? `{ ${defaultString} }` : `{}`}`;
  45805. }
  45806. }
  45807. function hasStaticWithDefaults(ctx) {
  45808. return !!(ctx.propsRuntimeDefaults && ctx.propsRuntimeDefaults.type === "ObjectExpression" && ctx.propsRuntimeDefaults.properties.every(
  45809. (node) => node.type !== "SpreadElement" && (!node.computed || node.key.type.endsWith("Literal"))
  45810. ));
  45811. }
  45812. function genDestructuredDefaultValue(ctx, key, inferredType) {
  45813. const destructured = ctx.propsDestructuredBindings[key];
  45814. const defaultVal = destructured && destructured.default;
  45815. if (defaultVal) {
  45816. const value = ctx.getString(defaultVal);
  45817. const unwrapped = unwrapTSNode(defaultVal);
  45818. if (inferredType && inferredType.length && !inferredType.includes("null")) {
  45819. const valueType = inferValueType(unwrapped);
  45820. if (valueType && !inferredType.includes(valueType)) {
  45821. ctx.error(
  45822. `Default value of prop "${key}" does not match declared type.`,
  45823. unwrapped
  45824. );
  45825. }
  45826. }
  45827. const needSkipFactory = !inferredType && (isFunctionType(unwrapped) || unwrapped.type === "Identifier");
  45828. const needFactoryWrap = !needSkipFactory && !isLiteralNode(unwrapped) && !(inferredType == null ? void 0 : inferredType.includes("Function"));
  45829. return {
  45830. valueString: needFactoryWrap ? `() => (${value})` : value,
  45831. needSkipFactory
  45832. };
  45833. }
  45834. }
  45835. function inferValueType(node) {
  45836. switch (node.type) {
  45837. case "StringLiteral":
  45838. return "String";
  45839. case "NumericLiteral":
  45840. return "Number";
  45841. case "BooleanLiteral":
  45842. return "Boolean";
  45843. case "ObjectExpression":
  45844. return "Object";
  45845. case "ArrayExpression":
  45846. return "Array";
  45847. case "FunctionExpression":
  45848. case "ArrowFunctionExpression":
  45849. return "Function";
  45850. }
  45851. }
  45852. function processPropsDestructure(ctx, declId) {
  45853. if (!ctx.options.propsDestructure && !ctx.options.reactivityTransform) {
  45854. ctx.propsIdentifier = ctx.getString(declId);
  45855. return;
  45856. }
  45857. warnOnce$4(
  45858. `This project is using reactive props destructure, which is an experimental feature. It may receive breaking changes or be removed in the future, so use at your own risk.
  45859. To stay updated, follow the RFC at https://github.com/vuejs/rfcs/discussions/502.`
  45860. );
  45861. ctx.propsDestructureDecl = declId;
  45862. const registerBinding = (key, local, defaultValue) => {
  45863. ctx.propsDestructuredBindings[key] = { local, default: defaultValue };
  45864. if (local !== key) {
  45865. ctx.bindingMetadata[local] = "props-aliased";
  45866. (ctx.bindingMetadata.__propsAliases || (ctx.bindingMetadata.__propsAliases = {}))[local] = key;
  45867. }
  45868. };
  45869. for (const prop of declId.properties) {
  45870. if (prop.type === "ObjectProperty") {
  45871. const propKey = resolveObjectKey(prop.key, prop.computed);
  45872. if (!propKey) {
  45873. ctx.error(
  45874. `${DEFINE_PROPS}() destructure cannot use computed key.`,
  45875. prop.key
  45876. );
  45877. }
  45878. if (prop.value.type === "AssignmentPattern") {
  45879. const { left, right } = prop.value;
  45880. if (left.type !== "Identifier") {
  45881. ctx.error(
  45882. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  45883. left
  45884. );
  45885. }
  45886. registerBinding(propKey, left.name, right);
  45887. } else if (prop.value.type === "Identifier") {
  45888. registerBinding(propKey, prop.value.name);
  45889. } else {
  45890. ctx.error(
  45891. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  45892. prop.value
  45893. );
  45894. }
  45895. } else {
  45896. ctx.propsDestructureRestId = prop.argument.name;
  45897. ctx.bindingMetadata[ctx.propsDestructureRestId] = "setup-reactive-const";
  45898. }
  45899. }
  45900. }
  45901. function transformDestructuredProps(ctx, vueImportAliases) {
  45902. if (!ctx.options.propsDestructure && !ctx.options.reactivityTransform) {
  45903. return;
  45904. }
  45905. const rootScope = {};
  45906. const scopeStack = [rootScope];
  45907. let currentScope = rootScope;
  45908. const excludedIds = /* @__PURE__ */ new WeakSet();
  45909. const parentStack = [];
  45910. const propsLocalToPublicMap = /* @__PURE__ */ Object.create(null);
  45911. for (const key in ctx.propsDestructuredBindings) {
  45912. const { local } = ctx.propsDestructuredBindings[key];
  45913. rootScope[local] = true;
  45914. propsLocalToPublicMap[local] = key;
  45915. }
  45916. function pushScope() {
  45917. scopeStack.push(currentScope = Object.create(currentScope));
  45918. }
  45919. function popScope() {
  45920. scopeStack.pop();
  45921. currentScope = scopeStack[scopeStack.length - 1] || null;
  45922. }
  45923. function registerLocalBinding(id) {
  45924. excludedIds.add(id);
  45925. if (currentScope) {
  45926. currentScope[id.name] = false;
  45927. } else {
  45928. ctx.error(
  45929. "registerBinding called without active scope, something is wrong.",
  45930. id
  45931. );
  45932. }
  45933. }
  45934. function walkScope(node, isRoot = false) {
  45935. for (const stmt of node.body) {
  45936. if (stmt.type === "VariableDeclaration") {
  45937. walkVariableDeclaration(stmt, isRoot);
  45938. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  45939. if (stmt.declare || !stmt.id)
  45940. continue;
  45941. registerLocalBinding(stmt.id);
  45942. } else if ((stmt.type === "ForOfStatement" || stmt.type === "ForInStatement") && stmt.left.type === "VariableDeclaration") {
  45943. walkVariableDeclaration(stmt.left);
  45944. } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration && stmt.declaration.type === "VariableDeclaration") {
  45945. walkVariableDeclaration(stmt.declaration, isRoot);
  45946. } else if (stmt.type === "LabeledStatement" && stmt.body.type === "VariableDeclaration") {
  45947. walkVariableDeclaration(stmt.body, isRoot);
  45948. }
  45949. }
  45950. }
  45951. function walkVariableDeclaration(stmt, isRoot = false) {
  45952. if (stmt.declare) {
  45953. return;
  45954. }
  45955. for (const decl of stmt.declarations) {
  45956. const isDefineProps = isRoot && decl.init && isCallOf(unwrapTSNode(decl.init), "defineProps");
  45957. for (const id of extractIdentifiers(decl.id)) {
  45958. if (isDefineProps) {
  45959. excludedIds.add(id);
  45960. } else {
  45961. registerLocalBinding(id);
  45962. }
  45963. }
  45964. }
  45965. }
  45966. function rewriteId(id, parent, parentStack2) {
  45967. if (parent.type === "AssignmentExpression" && id === parent.left || parent.type === "UpdateExpression") {
  45968. ctx.error(`Cannot assign to destructured props as they are readonly.`, id);
  45969. }
  45970. if (isStaticProperty(parent) && parent.shorthand) {
  45971. if (!parent.inPattern || isInDestructureAssignment(parent, parentStack2)) {
  45972. ctx.s.appendLeft(
  45973. id.end + ctx.startOffset,
  45974. `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`
  45975. );
  45976. }
  45977. } else {
  45978. ctx.s.overwrite(
  45979. id.start + ctx.startOffset,
  45980. id.end + ctx.startOffset,
  45981. genPropsAccessExp(propsLocalToPublicMap[id.name])
  45982. );
  45983. }
  45984. }
  45985. function checkUsage(node, method, alias = method) {
  45986. if (isCallOf(node, alias)) {
  45987. const arg = unwrapTSNode(node.arguments[0]);
  45988. if (arg.type === "Identifier" && currentScope[arg.name]) {
  45989. ctx.error(
  45990. `"${arg.name}" is a destructured prop and should not be passed directly to ${method}(). Pass a getter () => ${arg.name} instead.`,
  45991. arg
  45992. );
  45993. }
  45994. }
  45995. }
  45996. const ast = ctx.scriptSetupAst;
  45997. walkScope(ast, true);
  45998. walk$1(ast, {
  45999. enter(node, parent) {
  46000. parent && parentStack.push(parent);
  46001. if (parent && parent.type.startsWith("TS") && parent.type !== "TSAsExpression" && parent.type !== "TSNonNullExpression" && parent.type !== "TSTypeAssertion") {
  46002. return this.skip();
  46003. }
  46004. checkUsage(node, "watch", vueImportAliases.watch);
  46005. checkUsage(node, "toRef", vueImportAliases.toRef);
  46006. if (isFunctionType(node)) {
  46007. pushScope();
  46008. walkFunctionParams(node, registerLocalBinding);
  46009. if (node.body.type === "BlockStatement") {
  46010. walkScope(node.body);
  46011. }
  46012. return;
  46013. }
  46014. if (node.type === "CatchClause") {
  46015. pushScope();
  46016. if (node.param && node.param.type === "Identifier") {
  46017. registerLocalBinding(node.param);
  46018. }
  46019. walkScope(node.body);
  46020. return;
  46021. }
  46022. if (node.type === "BlockStatement" && !isFunctionType(parent)) {
  46023. pushScope();
  46024. walkScope(node);
  46025. return;
  46026. }
  46027. if (node.type === "Identifier") {
  46028. if (isReferencedIdentifier(node, parent, parentStack) && !excludedIds.has(node)) {
  46029. if (currentScope[node.name]) {
  46030. rewriteId(node, parent, parentStack);
  46031. }
  46032. }
  46033. }
  46034. },
  46035. leave(node, parent) {
  46036. parent && parentStack.pop();
  46037. if (node.type === "BlockStatement" && !isFunctionType(parent) || isFunctionType(node)) {
  46038. popScope();
  46039. }
  46040. }
  46041. });
  46042. }
  46043. const DEFINE_EMITS = "defineEmits";
  46044. function processDefineEmits(ctx, node, declId) {
  46045. if (!isCallOf(node, DEFINE_EMITS)) {
  46046. return false;
  46047. }
  46048. if (ctx.hasDefineEmitCall) {
  46049. ctx.error(`duplicate ${DEFINE_EMITS}() call`, node);
  46050. }
  46051. ctx.hasDefineEmitCall = true;
  46052. ctx.emitsRuntimeDecl = node.arguments[0];
  46053. if (node.typeParameters) {
  46054. if (ctx.emitsRuntimeDecl) {
  46055. ctx.error(
  46056. `${DEFINE_EMITS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  46057. node
  46058. );
  46059. }
  46060. ctx.emitsTypeDecl = node.typeParameters.params[0];
  46061. }
  46062. if (declId) {
  46063. ctx.emitIdentifier = declId.type === "Identifier" ? declId.name : ctx.getString(declId);
  46064. }
  46065. return true;
  46066. }
  46067. function genRuntimeEmits(ctx) {
  46068. let emitsDecl = "";
  46069. if (ctx.emitsRuntimeDecl) {
  46070. emitsDecl = ctx.getString(ctx.emitsRuntimeDecl).trim();
  46071. } else if (ctx.emitsTypeDecl) {
  46072. const typeDeclaredEmits = extractRuntimeEmits(ctx);
  46073. emitsDecl = typeDeclaredEmits.size ? `[${Array.from(typeDeclaredEmits).map((k) => JSON.stringify(k)).join(", ")}]` : ``;
  46074. }
  46075. if (ctx.hasDefineModelCall) {
  46076. let modelEmitsDecl = `[${Object.keys(ctx.modelDecls).map((n) => JSON.stringify(`update:${n}`)).join(", ")}]`;
  46077. emitsDecl = emitsDecl ? `${ctx.helper("mergeModels")}(${emitsDecl}, ${modelEmitsDecl})` : modelEmitsDecl;
  46078. }
  46079. return emitsDecl;
  46080. }
  46081. function extractRuntimeEmits(ctx) {
  46082. const emits = /* @__PURE__ */ new Set();
  46083. const node = ctx.emitsTypeDecl;
  46084. if (node.type === "TSFunctionType") {
  46085. extractEventNames(ctx, node.parameters[0], emits);
  46086. return emits;
  46087. }
  46088. const { props, calls } = resolveTypeElements(ctx, node);
  46089. let hasProperty = false;
  46090. for (const key in props) {
  46091. emits.add(key);
  46092. hasProperty = true;
  46093. }
  46094. if (calls) {
  46095. if (hasProperty) {
  46096. ctx.error(
  46097. `defineEmits() type cannot mixed call signature and property syntax.`,
  46098. node
  46099. );
  46100. }
  46101. for (const call of calls) {
  46102. extractEventNames(ctx, call.parameters[0], emits);
  46103. }
  46104. }
  46105. return emits;
  46106. }
  46107. function extractEventNames(ctx, eventName, emits) {
  46108. if (eventName.type === "Identifier" && eventName.typeAnnotation && eventName.typeAnnotation.type === "TSTypeAnnotation") {
  46109. const types = resolveUnionType(ctx, eventName.typeAnnotation.typeAnnotation);
  46110. for (const type of types) {
  46111. if (type.type === "TSLiteralType") {
  46112. if (type.literal.type !== "UnaryExpression" && type.literal.type !== "TemplateLiteral") {
  46113. emits.add(String(type.literal.value));
  46114. }
  46115. }
  46116. }
  46117. }
  46118. }
  46119. const DEFINE_EXPOSE = "defineExpose";
  46120. function processDefineExpose(ctx, node) {
  46121. if (isCallOf(node, DEFINE_EXPOSE)) {
  46122. if (ctx.hasDefineExposeCall) {
  46123. ctx.error(`duplicate ${DEFINE_EXPOSE}() call`, node);
  46124. }
  46125. ctx.hasDefineExposeCall = true;
  46126. return true;
  46127. }
  46128. return false;
  46129. }
  46130. const DEFINE_SLOTS = "defineSlots";
  46131. function processDefineSlots(ctx, node, declId) {
  46132. if (!isCallOf(node, DEFINE_SLOTS)) {
  46133. return false;
  46134. }
  46135. if (ctx.hasDefineSlotsCall) {
  46136. ctx.error(`duplicate ${DEFINE_SLOTS}() call`, node);
  46137. }
  46138. ctx.hasDefineSlotsCall = true;
  46139. if (node.arguments.length > 0) {
  46140. ctx.error(`${DEFINE_SLOTS}() cannot accept arguments`, node);
  46141. }
  46142. if (declId) {
  46143. ctx.s.overwrite(
  46144. ctx.startOffset + node.start,
  46145. ctx.startOffset + node.end,
  46146. `${ctx.helper("useSlots")}()`
  46147. );
  46148. }
  46149. return true;
  46150. }
  46151. const DEFINE_OPTIONS = "defineOptions";
  46152. function processDefineOptions(ctx, node) {
  46153. if (!isCallOf(node, DEFINE_OPTIONS)) {
  46154. return false;
  46155. }
  46156. if (ctx.hasDefineOptionsCall) {
  46157. ctx.error(`duplicate ${DEFINE_OPTIONS}() call`, node);
  46158. }
  46159. if (node.typeParameters) {
  46160. ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node);
  46161. }
  46162. if (!node.arguments[0])
  46163. return true;
  46164. ctx.hasDefineOptionsCall = true;
  46165. ctx.optionsRuntimeDecl = unwrapTSNode(node.arguments[0]);
  46166. let propsOption = void 0;
  46167. let emitsOption = void 0;
  46168. let exposeOption = void 0;
  46169. let slotsOption = void 0;
  46170. if (ctx.optionsRuntimeDecl.type === "ObjectExpression") {
  46171. for (const prop of ctx.optionsRuntimeDecl.properties) {
  46172. if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
  46173. if (prop.key.name === "props")
  46174. propsOption = prop;
  46175. if (prop.key.name === "emits")
  46176. emitsOption = prop;
  46177. if (prop.key.name === "expose")
  46178. exposeOption = prop;
  46179. if (prop.key.name === "slots")
  46180. slotsOption = prop;
  46181. }
  46182. }
  46183. }
  46184. if (propsOption) {
  46185. ctx.error(
  46186. `${DEFINE_OPTIONS}() cannot be used to declare props. Use ${DEFINE_PROPS}() instead.`,
  46187. propsOption
  46188. );
  46189. }
  46190. if (emitsOption) {
  46191. ctx.error(
  46192. `${DEFINE_OPTIONS}() cannot be used to declare emits. Use ${DEFINE_EMITS}() instead.`,
  46193. emitsOption
  46194. );
  46195. }
  46196. if (exposeOption) {
  46197. ctx.error(
  46198. `${DEFINE_OPTIONS}() cannot be used to declare expose. Use ${DEFINE_EXPOSE}() instead.`,
  46199. exposeOption
  46200. );
  46201. }
  46202. if (slotsOption) {
  46203. ctx.error(
  46204. `${DEFINE_OPTIONS}() cannot be used to declare slots. Use ${DEFINE_SLOTS}() instead.`,
  46205. slotsOption
  46206. );
  46207. }
  46208. return true;
  46209. }
  46210. function processAwait(ctx, node, needSemi, isStatement) {
  46211. const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? node.argument.extra.parenStart : node.argument.start;
  46212. const startOffset = ctx.startOffset;
  46213. const argumentStr = ctx.descriptor.source.slice(
  46214. argumentStart + startOffset,
  46215. node.argument.end + startOffset
  46216. );
  46217. const containsNestedAwait = /\bawait\b/.test(argumentStr);
  46218. ctx.s.overwrite(
  46219. node.start + startOffset,
  46220. argumentStart + startOffset,
  46221. `${needSemi ? `;` : ``}(
  46222. ([__temp,__restore] = ${ctx.helper(
  46223. `withAsyncContext`
  46224. )}(${containsNestedAwait ? `async ` : ``}() => `
  46225. );
  46226. ctx.s.appendLeft(
  46227. node.end + startOffset,
  46228. `)),
  46229. ${isStatement ? `` : `__temp = `}await __temp,
  46230. __restore()${isStatement ? `` : `,
  46231. __temp`}
  46232. )`
  46233. );
  46234. }
  46235. var __defProp = Object.defineProperty;
  46236. var __defProps = Object.defineProperties;
  46237. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  46238. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  46239. var __hasOwnProp = Object.prototype.hasOwnProperty;
  46240. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  46241. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  46242. var __spreadValues = (a, b) => {
  46243. for (var prop in b || (b = {}))
  46244. if (__hasOwnProp.call(b, prop))
  46245. __defNormalProp(a, prop, b[prop]);
  46246. if (__getOwnPropSymbols)
  46247. for (var prop of __getOwnPropSymbols(b)) {
  46248. if (__propIsEnum.call(b, prop))
  46249. __defNormalProp(a, prop, b[prop]);
  46250. }
  46251. return a;
  46252. };
  46253. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  46254. function compileScript(sfc, options) {
  46255. var _a;
  46256. if (!options.id) {
  46257. warnOnce$4(
  46258. `compileScript now requires passing the \`id\` option.
  46259. Upgrade your vite or vue-loader version for compatibility with the latest experimental proposals.`
  46260. );
  46261. }
  46262. const ctx = new ScriptCompileContext(sfc, options);
  46263. const { script, scriptSetup, source, filename } = sfc;
  46264. const hoistStatic = options.hoistStatic !== false && !script;
  46265. const scopeId = options.id ? options.id.replace(/^data-v-/, "") : "";
  46266. const scriptLang = script && script.lang;
  46267. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  46268. const enableReactivityTransform = !!options.reactivityTransform;
  46269. let refBindings;
  46270. if (!scriptSetup) {
  46271. if (!script) {
  46272. throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`);
  46273. }
  46274. return processNormalScript(ctx, scopeId);
  46275. }
  46276. if (script && scriptLang !== scriptSetupLang) {
  46277. throw new Error(
  46278. `[@vue/compiler-sfc] <script> and <script setup> must have the same language type.`
  46279. );
  46280. }
  46281. if (scriptSetupLang && !ctx.isJS && !ctx.isTS) {
  46282. return scriptSetup;
  46283. }
  46284. const scriptBindings = /* @__PURE__ */ Object.create(null);
  46285. const setupBindings = /* @__PURE__ */ Object.create(null);
  46286. let defaultExport;
  46287. let hasAwait = false;
  46288. let hasInlinedSsrRenderFn = false;
  46289. const startOffset = ctx.startOffset;
  46290. const endOffset = ctx.endOffset;
  46291. const scriptStartOffset = script && script.loc.start.offset;
  46292. const scriptEndOffset = script && script.loc.end.offset;
  46293. function hoistNode(node) {
  46294. const start = node.start + startOffset;
  46295. let end = node.end + startOffset;
  46296. if (node.trailingComments && node.trailingComments.length > 0) {
  46297. const lastCommentNode = node.trailingComments[node.trailingComments.length - 1];
  46298. end = lastCommentNode.end + startOffset;
  46299. }
  46300. while (end <= source.length) {
  46301. if (!/\s/.test(source.charAt(end))) {
  46302. break;
  46303. }
  46304. end++;
  46305. }
  46306. ctx.s.move(start, end, 0);
  46307. }
  46308. function registerUserImport(source2, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
  46309. let isUsedInTemplate = needTemplateUsageCheck;
  46310. if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
  46311. isUsedInTemplate = isImportUsed(local, sfc);
  46312. }
  46313. ctx.userImports[local] = {
  46314. isType,
  46315. imported,
  46316. local,
  46317. source: source2,
  46318. isFromSetup,
  46319. isUsedInTemplate
  46320. };
  46321. }
  46322. function checkInvalidScopeReference(node, method) {
  46323. if (!node)
  46324. return;
  46325. walkIdentifiers(node, (id) => {
  46326. const binding = setupBindings[id.name];
  46327. if (binding && binding !== "literal-const") {
  46328. ctx.error(
  46329. `\`${method}()\` in <script setup> cannot reference locally declared variables because it will be hoisted outside of the setup() function. If your component options require initialization in the module scope, use a separate normal <script> to export the options instead.`,
  46330. id
  46331. );
  46332. }
  46333. });
  46334. }
  46335. const scriptAst = ctx.scriptAst;
  46336. const scriptSetupAst = ctx.scriptSetupAst;
  46337. if (scriptAst) {
  46338. for (const node of scriptAst.body) {
  46339. if (node.type === "ImportDeclaration") {
  46340. for (const specifier of node.specifiers) {
  46341. const imported = getImportedName(specifier);
  46342. registerUserImport(
  46343. node.source.value,
  46344. specifier.local.name,
  46345. imported,
  46346. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  46347. false,
  46348. !options.inlineTemplate
  46349. );
  46350. }
  46351. }
  46352. }
  46353. }
  46354. for (const node of scriptSetupAst.body) {
  46355. if (node.type === "ImportDeclaration") {
  46356. hoistNode(node);
  46357. let removed = 0;
  46358. const removeSpecifier = (i) => {
  46359. const removeLeft = i > removed;
  46360. removed++;
  46361. const current = node.specifiers[i];
  46362. const next = node.specifiers[i + 1];
  46363. ctx.s.remove(
  46364. removeLeft ? node.specifiers[i - 1].end + startOffset : current.start + startOffset,
  46365. next && !removeLeft ? next.start + startOffset : current.end + startOffset
  46366. );
  46367. };
  46368. for (let i = 0; i < node.specifiers.length; i++) {
  46369. const specifier = node.specifiers[i];
  46370. const local = specifier.local.name;
  46371. const imported = getImportedName(specifier);
  46372. const source2 = node.source.value;
  46373. const existing = ctx.userImports[local];
  46374. if (source2 === "vue" && (imported === DEFINE_PROPS || imported === DEFINE_EMITS || imported === DEFINE_EXPOSE)) {
  46375. warnOnce$4(
  46376. `\`${imported}\` is a compiler macro and no longer needs to be imported.`
  46377. );
  46378. removeSpecifier(i);
  46379. } else if (existing) {
  46380. if (existing.source === source2 && existing.imported === imported) {
  46381. removeSpecifier(i);
  46382. } else {
  46383. ctx.error(
  46384. `different imports aliased to same local name.`,
  46385. specifier
  46386. );
  46387. }
  46388. } else {
  46389. registerUserImport(
  46390. source2,
  46391. local,
  46392. imported,
  46393. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  46394. true,
  46395. !options.inlineTemplate
  46396. );
  46397. }
  46398. }
  46399. if (node.specifiers.length && removed === node.specifiers.length) {
  46400. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  46401. }
  46402. }
  46403. }
  46404. const vueImportAliases = {};
  46405. for (const key in ctx.userImports) {
  46406. const { source: source2, imported, local } = ctx.userImports[key];
  46407. if (source2 === "vue")
  46408. vueImportAliases[imported] = local;
  46409. }
  46410. if (script && scriptAst) {
  46411. for (const node of scriptAst.body) {
  46412. if (node.type === "ExportDefaultDeclaration") {
  46413. defaultExport = node;
  46414. let optionProperties;
  46415. if (defaultExport.declaration.type === "ObjectExpression") {
  46416. optionProperties = defaultExport.declaration.properties;
  46417. } else if (defaultExport.declaration.type === "CallExpression" && defaultExport.declaration.arguments[0] && defaultExport.declaration.arguments[0].type === "ObjectExpression") {
  46418. optionProperties = defaultExport.declaration.arguments[0].properties;
  46419. }
  46420. if (optionProperties) {
  46421. for (const p of optionProperties) {
  46422. if (p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name") {
  46423. ctx.hasDefaultExportName = true;
  46424. }
  46425. if ((p.type === "ObjectMethod" || p.type === "ObjectProperty") && p.key.type === "Identifier" && p.key.name === "render") {
  46426. ctx.hasDefaultExportRender = true;
  46427. }
  46428. }
  46429. }
  46430. const start = node.start + scriptStartOffset;
  46431. const end = node.declaration.start + scriptStartOffset;
  46432. ctx.s.overwrite(start, end, `const ${normalScriptDefaultVar} = `);
  46433. } else if (node.type === "ExportNamedDeclaration") {
  46434. const defaultSpecifier = node.specifiers.find(
  46435. (s) => s.exported.type === "Identifier" && s.exported.name === "default"
  46436. );
  46437. if (defaultSpecifier) {
  46438. defaultExport = node;
  46439. if (node.specifiers.length > 1) {
  46440. ctx.s.remove(
  46441. defaultSpecifier.start + scriptStartOffset,
  46442. defaultSpecifier.end + scriptStartOffset
  46443. );
  46444. } else {
  46445. ctx.s.remove(
  46446. node.start + scriptStartOffset,
  46447. node.end + scriptStartOffset
  46448. );
  46449. }
  46450. if (node.source) {
  46451. ctx.s.prepend(
  46452. `import { ${defaultSpecifier.local.name} as ${normalScriptDefaultVar} } from '${node.source.value}'
  46453. `
  46454. );
  46455. } else {
  46456. ctx.s.appendLeft(
  46457. scriptEndOffset,
  46458. `
  46459. const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
  46460. `
  46461. );
  46462. }
  46463. }
  46464. if (node.declaration) {
  46465. walkDeclaration(
  46466. "script",
  46467. node.declaration,
  46468. scriptBindings,
  46469. vueImportAliases,
  46470. hoistStatic
  46471. );
  46472. }
  46473. } else if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  46474. walkDeclaration(
  46475. "script",
  46476. node,
  46477. scriptBindings,
  46478. vueImportAliases,
  46479. hoistStatic
  46480. );
  46481. }
  46482. }
  46483. if (enableReactivityTransform && shouldTransform(script.content)) {
  46484. const { rootRefs, importedHelpers } = transformAST(
  46485. scriptAst,
  46486. ctx.s,
  46487. scriptStartOffset
  46488. );
  46489. refBindings = rootRefs;
  46490. for (const h of importedHelpers) {
  46491. ctx.helperImports.add(h);
  46492. }
  46493. }
  46494. if (scriptStartOffset > startOffset) {
  46495. if (!/\n$/.test(script.content.trim())) {
  46496. ctx.s.appendLeft(scriptEndOffset, `
  46497. `);
  46498. }
  46499. ctx.s.move(scriptStartOffset, scriptEndOffset, 0);
  46500. }
  46501. }
  46502. for (const node of scriptSetupAst.body) {
  46503. if (node.type === "ExpressionStatement") {
  46504. const expr = unwrapTSNode(node.expression);
  46505. if (processDefineProps(ctx, expr) || processDefineEmits(ctx, expr) || processDefineOptions(ctx, expr) || processDefineSlots(ctx, expr)) {
  46506. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  46507. } else if (processDefineExpose(ctx, expr)) {
  46508. const callee = expr.callee;
  46509. ctx.s.overwrite(
  46510. callee.start + startOffset,
  46511. callee.end + startOffset,
  46512. "__expose"
  46513. );
  46514. } else {
  46515. processDefineModel(ctx, expr);
  46516. }
  46517. }
  46518. if (node.type === "VariableDeclaration" && !node.declare) {
  46519. const total = node.declarations.length;
  46520. let left = total;
  46521. let lastNonRemoved;
  46522. for (let i = 0; i < total; i++) {
  46523. const decl = node.declarations[i];
  46524. const init = decl.init && unwrapTSNode(decl.init);
  46525. if (init) {
  46526. if (processDefineOptions(ctx, init)) {
  46527. ctx.error(
  46528. `${DEFINE_OPTIONS}() has no returning value, it cannot be assigned.`,
  46529. node
  46530. );
  46531. }
  46532. const isDefineProps = processDefineProps(ctx, init, decl.id);
  46533. const isDefineEmits = !isDefineProps && processDefineEmits(ctx, init, decl.id);
  46534. !isDefineEmits && (processDefineSlots(ctx, init, decl.id) || processDefineModel(ctx, init, decl.id));
  46535. if (isDefineProps || isDefineEmits) {
  46536. if (left === 1) {
  46537. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  46538. } else {
  46539. let start = decl.start + startOffset;
  46540. let end = decl.end + startOffset;
  46541. if (i === total - 1) {
  46542. start = node.declarations[lastNonRemoved].end + startOffset;
  46543. } else {
  46544. end = node.declarations[i + 1].start + startOffset;
  46545. }
  46546. ctx.s.remove(start, end);
  46547. left--;
  46548. }
  46549. } else {
  46550. lastNonRemoved = i;
  46551. }
  46552. }
  46553. }
  46554. }
  46555. let isAllLiteral = false;
  46556. if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  46557. isAllLiteral = walkDeclaration(
  46558. "scriptSetup",
  46559. node,
  46560. setupBindings,
  46561. vueImportAliases,
  46562. hoistStatic
  46563. );
  46564. }
  46565. if (hoistStatic && isAllLiteral) {
  46566. hoistNode(node);
  46567. }
  46568. if (node.type === "VariableDeclaration" && !node.declare || node.type.endsWith("Statement")) {
  46569. const scope = [scriptSetupAst.body];
  46570. walk$1(node, {
  46571. enter(child, parent) {
  46572. if (isFunctionType(child)) {
  46573. this.skip();
  46574. }
  46575. if (child.type === "BlockStatement") {
  46576. scope.push(child.body);
  46577. }
  46578. if (child.type === "AwaitExpression") {
  46579. hasAwait = true;
  46580. const currentScope = scope[scope.length - 1];
  46581. const needsSemi = currentScope.some((n, i) => {
  46582. return (scope.length === 1 || i > 0) && n.type === "ExpressionStatement" && n.start === child.start;
  46583. });
  46584. processAwait(
  46585. ctx,
  46586. child,
  46587. needsSemi,
  46588. parent.type === "ExpressionStatement"
  46589. );
  46590. }
  46591. },
  46592. exit(node2) {
  46593. if (node2.type === "BlockStatement")
  46594. scope.pop();
  46595. }
  46596. });
  46597. }
  46598. if (node.type === "ExportNamedDeclaration" && node.exportKind !== "type" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration") {
  46599. ctx.error(
  46600. `<script setup> cannot contain ES module exports. If you are using a previous version of <script setup>, please consult the updated RFC at https://github.com/vuejs/rfcs/pull/227.`,
  46601. node
  46602. );
  46603. }
  46604. if (ctx.isTS) {
  46605. if (node.type.startsWith("TS") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "VariableDeclaration" && node.declare) {
  46606. if (node.type !== "TSEnumDeclaration") {
  46607. hoistNode(node);
  46608. }
  46609. }
  46610. }
  46611. }
  46612. if (ctx.propsDestructureDecl) {
  46613. transformDestructuredProps(ctx, vueImportAliases);
  46614. }
  46615. if (enableReactivityTransform && // normal <script> had ref bindings that maybe used in <script setup>
  46616. (refBindings || shouldTransform(scriptSetup.content))) {
  46617. const { rootRefs, importedHelpers } = transformAST(
  46618. scriptSetupAst,
  46619. ctx.s,
  46620. startOffset,
  46621. refBindings
  46622. );
  46623. refBindings = refBindings ? [...refBindings, ...rootRefs] : rootRefs;
  46624. for (const h of importedHelpers) {
  46625. ctx.helperImports.add(h);
  46626. }
  46627. }
  46628. checkInvalidScopeReference(ctx.propsRuntimeDecl, DEFINE_PROPS);
  46629. checkInvalidScopeReference(ctx.propsRuntimeDefaults, DEFINE_PROPS);
  46630. checkInvalidScopeReference(ctx.propsDestructureDecl, DEFINE_PROPS);
  46631. checkInvalidScopeReference(ctx.emitsRuntimeDecl, DEFINE_EMITS);
  46632. checkInvalidScopeReference(ctx.optionsRuntimeDecl, DEFINE_OPTIONS);
  46633. if (script) {
  46634. if (startOffset < scriptStartOffset) {
  46635. ctx.s.remove(0, startOffset);
  46636. ctx.s.remove(endOffset, scriptStartOffset);
  46637. ctx.s.remove(scriptEndOffset, source.length);
  46638. } else {
  46639. ctx.s.remove(0, scriptStartOffset);
  46640. ctx.s.remove(scriptEndOffset, startOffset);
  46641. ctx.s.remove(endOffset, source.length);
  46642. }
  46643. } else {
  46644. ctx.s.remove(0, startOffset);
  46645. ctx.s.remove(endOffset, source.length);
  46646. }
  46647. if (scriptAst) {
  46648. Object.assign(ctx.bindingMetadata, analyzeScriptBindings(scriptAst.body));
  46649. }
  46650. for (const [key, { isType, imported, source: source2 }] of Object.entries(
  46651. ctx.userImports
  46652. )) {
  46653. if (isType)
  46654. continue;
  46655. ctx.bindingMetadata[key] = imported === "*" || imported === "default" && source2.endsWith(".vue") || source2 === "vue" ? "setup-const" : "setup-maybe-ref";
  46656. }
  46657. for (const key in scriptBindings) {
  46658. ctx.bindingMetadata[key] = scriptBindings[key];
  46659. }
  46660. for (const key in setupBindings) {
  46661. ctx.bindingMetadata[key] = setupBindings[key];
  46662. }
  46663. if (refBindings) {
  46664. for (const key of refBindings) {
  46665. ctx.bindingMetadata[key] = "setup-ref";
  46666. }
  46667. }
  46668. if (sfc.cssVars.length && // no need to do this when targeting SSR
  46669. !(options.inlineTemplate && ((_a = options.templateOptions) == null ? void 0 : _a.ssr))) {
  46670. ctx.helperImports.add(CSS_VARS_HELPER);
  46671. ctx.helperImports.add("unref");
  46672. ctx.s.prependLeft(
  46673. startOffset,
  46674. `
  46675. ${genCssVarsCode(
  46676. sfc.cssVars,
  46677. ctx.bindingMetadata,
  46678. scopeId,
  46679. !!options.isProd
  46680. )}
  46681. `
  46682. );
  46683. }
  46684. let args = `__props`;
  46685. if (ctx.propsTypeDecl) {
  46686. args += `: any`;
  46687. }
  46688. if (ctx.propsIdentifier) {
  46689. ctx.s.prependLeft(
  46690. startOffset,
  46691. `
  46692. const ${ctx.propsIdentifier} = __props;
  46693. `
  46694. );
  46695. }
  46696. if (ctx.propsDestructureRestId) {
  46697. ctx.s.prependLeft(
  46698. startOffset,
  46699. `
  46700. const ${ctx.propsDestructureRestId} = ${ctx.helper(
  46701. `createPropsRestProxy`
  46702. )}(__props, ${JSON.stringify(
  46703. Object.keys(ctx.propsDestructuredBindings)
  46704. )});
  46705. `
  46706. );
  46707. }
  46708. if (hasAwait) {
  46709. const any = ctx.isTS ? `: any` : ``;
  46710. ctx.s.prependLeft(startOffset, `
  46711. let __temp${any}, __restore${any}
  46712. `);
  46713. }
  46714. const destructureElements = ctx.hasDefineExposeCall || !options.inlineTemplate ? [`expose: __expose`] : [];
  46715. if (ctx.emitIdentifier) {
  46716. destructureElements.push(
  46717. ctx.emitIdentifier === `emit` ? `emit` : `emit: ${ctx.emitIdentifier}`
  46718. );
  46719. }
  46720. if (destructureElements.length) {
  46721. args += `, { ${destructureElements.join(", ")} }`;
  46722. }
  46723. let returned;
  46724. if (!options.inlineTemplate || !sfc.template && ctx.hasDefaultExportRender) {
  46725. const allBindings = __spreadValues(__spreadValues({}, scriptBindings), setupBindings);
  46726. for (const key in ctx.userImports) {
  46727. if (!ctx.userImports[key].isType && ctx.userImports[key].isUsedInTemplate) {
  46728. allBindings[key] = true;
  46729. }
  46730. }
  46731. returned = `{ `;
  46732. for (const key in allBindings) {
  46733. if (allBindings[key] === true && ctx.userImports[key].source !== "vue" && !ctx.userImports[key].source.endsWith(".vue")) {
  46734. returned += `get ${key}() { return ${key} }, `;
  46735. } else if (ctx.bindingMetadata[key] === "setup-let") {
  46736. const setArg = key === "v" ? `_v` : `v`;
  46737. returned += `get ${key}() { return ${key} }, set ${key}(${setArg}) { ${key} = ${setArg} }, `;
  46738. } else {
  46739. returned += `${key}, `;
  46740. }
  46741. }
  46742. returned = returned.replace(/, $/, "") + ` }`;
  46743. } else {
  46744. if (sfc.template && !sfc.template.src) {
  46745. if (options.templateOptions && options.templateOptions.ssr) {
  46746. hasInlinedSsrRenderFn = true;
  46747. }
  46748. const { code, ast, preamble, tips, errors } = compileTemplate(__spreadProps(__spreadValues({
  46749. filename,
  46750. source: sfc.template.content,
  46751. inMap: sfc.template.map
  46752. }, options.templateOptions), {
  46753. id: scopeId,
  46754. scoped: sfc.styles.some((s) => s.scoped),
  46755. isProd: options.isProd,
  46756. ssrCssVars: sfc.cssVars,
  46757. compilerOptions: __spreadProps(__spreadValues({}, options.templateOptions && options.templateOptions.compilerOptions), {
  46758. inline: true,
  46759. isTS: ctx.isTS,
  46760. bindingMetadata: ctx.bindingMetadata
  46761. })
  46762. }));
  46763. if (tips.length) {
  46764. tips.forEach(warnOnce$4);
  46765. }
  46766. const err = errors[0];
  46767. if (typeof err === "string") {
  46768. throw new Error(err);
  46769. } else if (err) {
  46770. if (err.loc) {
  46771. err.message += `
  46772. ` + sfc.filename + "\n" + generateCodeFrame(
  46773. source,
  46774. err.loc.start.offset,
  46775. err.loc.end.offset
  46776. ) + `
  46777. `;
  46778. }
  46779. throw err;
  46780. }
  46781. if (preamble) {
  46782. ctx.s.prepend(preamble);
  46783. }
  46784. if (ast && ast.helpers.has(UNREF)) {
  46785. ctx.helperImports.delete("unref");
  46786. }
  46787. returned = code;
  46788. } else {
  46789. returned = `() => {}`;
  46790. }
  46791. }
  46792. if (!options.inlineTemplate && true) {
  46793. ctx.s.appendRight(
  46794. endOffset,
  46795. `
  46796. const __returned__ = ${returned}
  46797. Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true })
  46798. return __returned__
  46799. }
  46800. `
  46801. );
  46802. } else {
  46803. ctx.s.appendRight(endOffset, `
  46804. return ${returned}
  46805. }
  46806. `);
  46807. }
  46808. const genDefaultAs = options.genDefaultAs ? `const ${options.genDefaultAs} =` : `export default`;
  46809. let runtimeOptions = ``;
  46810. if (!ctx.hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
  46811. const match = filename.match(/([^/\\]+)\.\w+$/);
  46812. if (match) {
  46813. runtimeOptions += `
  46814. __name: '${match[1]}',`;
  46815. }
  46816. }
  46817. if (hasInlinedSsrRenderFn) {
  46818. runtimeOptions += `
  46819. __ssrInlineRender: true,`;
  46820. }
  46821. const propsDecl = genRuntimeProps(ctx);
  46822. if (propsDecl)
  46823. runtimeOptions += `
  46824. props: ${propsDecl},`;
  46825. const emitsDecl = genRuntimeEmits(ctx);
  46826. if (emitsDecl)
  46827. runtimeOptions += `
  46828. emits: ${emitsDecl},`;
  46829. let definedOptions = "";
  46830. if (ctx.optionsRuntimeDecl) {
  46831. definedOptions = scriptSetup.content.slice(ctx.optionsRuntimeDecl.start, ctx.optionsRuntimeDecl.end).trim();
  46832. }
  46833. const exposeCall = ctx.hasDefineExposeCall || options.inlineTemplate ? `` : ` __expose();
  46834. `;
  46835. if (ctx.isTS) {
  46836. const def = (defaultExport ? `
  46837. ...${normalScriptDefaultVar},` : ``) + (definedOptions ? `
  46838. ...${definedOptions},` : "");
  46839. ctx.s.prependLeft(
  46840. startOffset,
  46841. `
  46842. ${genDefaultAs} /*#__PURE__*/${ctx.helper(
  46843. `defineComponent`
  46844. )}({${def}${runtimeOptions}
  46845. ${hasAwait ? `async ` : ``}setup(${args}) {
  46846. ${exposeCall}`
  46847. );
  46848. ctx.s.appendRight(endOffset, `})`);
  46849. } else {
  46850. if (defaultExport || definedOptions) {
  46851. ctx.s.prependLeft(
  46852. startOffset,
  46853. `
  46854. ${genDefaultAs} /*#__PURE__*/Object.assign(${defaultExport ? `${normalScriptDefaultVar}, ` : ""}${definedOptions ? `${definedOptions}, ` : ""}{${runtimeOptions}
  46855. ${hasAwait ? `async ` : ``}setup(${args}) {
  46856. ${exposeCall}`
  46857. );
  46858. ctx.s.appendRight(endOffset, `})`);
  46859. } else {
  46860. ctx.s.prependLeft(
  46861. startOffset,
  46862. `
  46863. ${genDefaultAs} {${runtimeOptions}
  46864. ${hasAwait ? `async ` : ``}setup(${args}) {
  46865. ${exposeCall}`
  46866. );
  46867. ctx.s.appendRight(endOffset, `}`);
  46868. }
  46869. }
  46870. if (ctx.helperImports.size > 0) {
  46871. ctx.s.prepend(
  46872. `import { ${[...ctx.helperImports].map((h) => `${h} as _${h}`).join(", ")} } from 'vue'
  46873. `
  46874. );
  46875. }
  46876. ctx.s.trim();
  46877. return __spreadProps(__spreadValues({}, scriptSetup), {
  46878. bindings: ctx.bindingMetadata,
  46879. imports: ctx.userImports,
  46880. content: ctx.s.toString(),
  46881. map: options.sourceMap !== false ? ctx.s.generateMap({
  46882. source: filename,
  46883. hires: true,
  46884. includeContent: true
  46885. }) : void 0,
  46886. scriptAst: scriptAst == null ? void 0 : scriptAst.body,
  46887. scriptSetupAst: scriptSetupAst == null ? void 0 : scriptSetupAst.body,
  46888. deps: ctx.deps ? [...ctx.deps] : void 0
  46889. });
  46890. }
  46891. function registerBinding(bindings, node, type) {
  46892. bindings[node.name] = type;
  46893. }
  46894. function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic) {
  46895. let isAllLiteral = false;
  46896. if (node.type === "VariableDeclaration") {
  46897. const isConst = node.kind === "const";
  46898. isAllLiteral = isConst && node.declarations.every(
  46899. (decl) => decl.id.type === "Identifier" && isStaticNode(decl.init)
  46900. );
  46901. for (const { id, init: _init } of node.declarations) {
  46902. const init = _init && unwrapTSNode(_init);
  46903. const isDefineCall = !!(isConst && isCallOf(
  46904. init,
  46905. (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS
  46906. ));
  46907. if (id.type === "Identifier") {
  46908. let bindingType;
  46909. const userReactiveBinding = userImportAliases["reactive"];
  46910. if ((hoistStatic || from === "script") && (isAllLiteral || isConst && isStaticNode(init))) {
  46911. bindingType = "literal-const";
  46912. } else if (isCallOf(init, userReactiveBinding)) {
  46913. bindingType = isConst ? "setup-reactive-const" : "setup-let";
  46914. } else if (
  46915. // if a declaration is a const literal, we can mark it so that
  46916. // the generated render fn code doesn't need to unref() it
  46917. isDefineCall || isConst && canNeverBeRef(init, userReactiveBinding)
  46918. ) {
  46919. bindingType = isCallOf(init, DEFINE_PROPS) ? "setup-reactive-const" : "setup-const";
  46920. } else if (isConst) {
  46921. if (isCallOf(
  46922. init,
  46923. (m) => m === userImportAliases["ref"] || m === userImportAliases["computed"] || m === userImportAliases["shallowRef"] || m === userImportAliases["customRef"] || m === userImportAliases["toRef"] || m === DEFINE_MODEL
  46924. )) {
  46925. bindingType = "setup-ref";
  46926. } else {
  46927. bindingType = "setup-maybe-ref";
  46928. }
  46929. } else {
  46930. bindingType = "setup-let";
  46931. }
  46932. registerBinding(bindings, id, bindingType);
  46933. } else {
  46934. if (isCallOf(init, DEFINE_PROPS)) {
  46935. continue;
  46936. }
  46937. if (id.type === "ObjectPattern") {
  46938. walkObjectPattern(id, bindings, isConst, isDefineCall);
  46939. } else if (id.type === "ArrayPattern") {
  46940. walkArrayPattern(id, bindings, isConst, isDefineCall);
  46941. }
  46942. }
  46943. }
  46944. } else if (node.type === "TSEnumDeclaration") {
  46945. isAllLiteral = node.members.every(
  46946. (member) => !member.initializer || isStaticNode(member.initializer)
  46947. );
  46948. bindings[node.id.name] = isAllLiteral ? "literal-const" : "setup-const";
  46949. } else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
  46950. bindings[node.id.name] = "setup-const";
  46951. }
  46952. return isAllLiteral;
  46953. }
  46954. function walkObjectPattern(node, bindings, isConst, isDefineCall = false) {
  46955. for (const p of node.properties) {
  46956. if (p.type === "ObjectProperty") {
  46957. if (p.key.type === "Identifier" && p.key === p.value) {
  46958. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  46959. registerBinding(bindings, p.key, type);
  46960. } else {
  46961. walkPattern(p.value, bindings, isConst, isDefineCall);
  46962. }
  46963. } else {
  46964. const type = isConst ? "setup-const" : "setup-let";
  46965. registerBinding(bindings, p.argument, type);
  46966. }
  46967. }
  46968. }
  46969. function walkArrayPattern(node, bindings, isConst, isDefineCall = false) {
  46970. for (const e of node.elements) {
  46971. e && walkPattern(e, bindings, isConst, isDefineCall);
  46972. }
  46973. }
  46974. function walkPattern(node, bindings, isConst, isDefineCall = false) {
  46975. if (node.type === "Identifier") {
  46976. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  46977. registerBinding(bindings, node, type);
  46978. } else if (node.type === "RestElement") {
  46979. const type = isConst ? "setup-const" : "setup-let";
  46980. registerBinding(bindings, node.argument, type);
  46981. } else if (node.type === "ObjectPattern") {
  46982. walkObjectPattern(node, bindings, isConst);
  46983. } else if (node.type === "ArrayPattern") {
  46984. walkArrayPattern(node, bindings, isConst);
  46985. } else if (node.type === "AssignmentPattern") {
  46986. if (node.left.type === "Identifier") {
  46987. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  46988. registerBinding(bindings, node.left, type);
  46989. } else {
  46990. walkPattern(node.left, bindings, isConst);
  46991. }
  46992. }
  46993. }
  46994. function canNeverBeRef(node, userReactiveImport) {
  46995. if (isCallOf(node, userReactiveImport)) {
  46996. return true;
  46997. }
  46998. switch (node.type) {
  46999. case "UnaryExpression":
  47000. case "BinaryExpression":
  47001. case "ArrayExpression":
  47002. case "ObjectExpression":
  47003. case "FunctionExpression":
  47004. case "ArrowFunctionExpression":
  47005. case "UpdateExpression":
  47006. case "ClassExpression":
  47007. case "TaggedTemplateExpression":
  47008. return true;
  47009. case "SequenceExpression":
  47010. return canNeverBeRef(
  47011. node.expressions[node.expressions.length - 1],
  47012. userReactiveImport
  47013. );
  47014. default:
  47015. if (isLiteralNode(node)) {
  47016. return true;
  47017. }
  47018. return false;
  47019. }
  47020. }
  47021. function isStaticNode(node) {
  47022. node = unwrapTSNode(node);
  47023. switch (node.type) {
  47024. case "UnaryExpression":
  47025. return isStaticNode(node.argument);
  47026. case "LogicalExpression":
  47027. case "BinaryExpression":
  47028. return isStaticNode(node.left) && isStaticNode(node.right);
  47029. case "ConditionalExpression": {
  47030. return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
  47031. }
  47032. case "SequenceExpression":
  47033. case "TemplateLiteral":
  47034. return node.expressions.every((expr) => isStaticNode(expr));
  47035. case "ParenthesizedExpression":
  47036. return isStaticNode(node.expression);
  47037. case "StringLiteral":
  47038. case "NumericLiteral":
  47039. case "BooleanLiteral":
  47040. case "NullLiteral":
  47041. case "BigIntLiteral":
  47042. return true;
  47043. }
  47044. return false;
  47045. }
  47046. const version = "3.3.4";
  47047. const walk = walk$1;
  47048. export { MagicString, parse_1$1 as babelParse, compileScript, compileStyle, compileStyleAsync, compileTemplate, extractIdentifiers, generateCodeFrame, inferRuntimeType, invalidateTypeCache, isInDestructureAssignment, isStaticProperty, parse$7 as parse, parseCache, registerTS, resolveTypeElements, rewriteDefault, rewriteDefaultAST, shouldTransform as shouldTransformRef, transform as transformRef, transformAST as transformRefAST, version, walk, walkIdentifiers };