compiler-sfc.esm-browser.js 1.6 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852
  1. /**
  2. * @vue/compiler-sfc v3.5.27
  3. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  4. * @license MIT
  5. **/
  6. // @__NO_SIDE_EFFECTS__
  7. function makeMap(str) {
  8. const map = /* @__PURE__ */ Object.create(null);
  9. for (const key of str.split(",")) map[key] = 1;
  10. return (val) => val in map;
  11. }
  12. const EMPTY_OBJ = Object.freeze({}) ;
  13. const NOOP = () => {
  14. };
  15. const NO = () => false;
  16. const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && // uppercase letter
  17. (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
  18. const extend = Object.assign;
  19. const hasOwnProperty$3 = Object.prototype.hasOwnProperty;
  20. const hasOwn = (val, key) => hasOwnProperty$3.call(val, key);
  21. const isArray$3 = Array.isArray;
  22. const isMap = (val) => toTypeString(val) === "[object Map]";
  23. const isSet = (val) => toTypeString(val) === "[object Set]";
  24. const isFunction$1 = (val) => typeof val === "function";
  25. const isString$1 = (val) => typeof val === "string";
  26. const isSymbol$1 = (val) => typeof val === "symbol";
  27. const isObject$2 = (val) => val !== null && typeof val === "object";
  28. const objectToString$1 = Object.prototype.toString;
  29. const toTypeString = (value) => objectToString$1.call(value);
  30. const isPlainObject = (val) => toTypeString(val) === "[object Object]";
  31. const isReservedProp = /* @__PURE__ */ makeMap(
  32. // the leading comma is intentional so empty string "" is also included
  33. ",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"
  34. );
  35. const isBuiltInDirective = /* @__PURE__ */ makeMap(
  36. "bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"
  37. );
  38. const cacheStringFunction = (fn) => {
  39. const cache = /* @__PURE__ */ Object.create(null);
  40. return ((str) => {
  41. const hit = cache[str];
  42. return hit || (cache[str] = fn(str));
  43. });
  44. };
  45. const camelizeRE = /-\w/g;
  46. const camelize = cacheStringFunction(
  47. (str) => {
  48. return str.replace(camelizeRE, (c) => c.slice(1).toUpperCase());
  49. }
  50. );
  51. const hyphenateRE = /\B([A-Z])/g;
  52. const hyphenate = cacheStringFunction(
  53. (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
  54. );
  55. const capitalize = cacheStringFunction((str) => {
  56. return str.charAt(0).toUpperCase() + str.slice(1);
  57. });
  58. const toHandlerKey = cacheStringFunction(
  59. (str) => {
  60. const s = str ? `on${capitalize(str)}` : ``;
  61. return s;
  62. }
  63. );
  64. const identRE = /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/;
  65. function genPropsAccessExp(name) {
  66. return identRE.test(name) ? `__props.${name}` : `__props[${JSON.stringify(name)}]`;
  67. }
  68. function genCacheKey(source, options) {
  69. return source + JSON.stringify(
  70. options,
  71. (_, val) => typeof val === "function" ? val.toString() : val
  72. );
  73. }
  74. const PatchFlagNames = {
  75. [1]: `TEXT`,
  76. [2]: `CLASS`,
  77. [4]: `STYLE`,
  78. [8]: `PROPS`,
  79. [16]: `FULL_PROPS`,
  80. [32]: `NEED_HYDRATION`,
  81. [64]: `STABLE_FRAGMENT`,
  82. [128]: `KEYED_FRAGMENT`,
  83. [256]: `UNKEYED_FRAGMENT`,
  84. [512]: `NEED_PATCH`,
  85. [1024]: `DYNAMIC_SLOTS`,
  86. [2048]: `DEV_ROOT_FRAGMENT`,
  87. [-1]: `CACHED`,
  88. [-2]: `BAIL`
  89. };
  90. const slotFlagsText = {
  91. [1]: "STABLE",
  92. [2]: "DYNAMIC",
  93. [3]: "FORWARDED"
  94. };
  95. const GLOBALS_ALLOWED = "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,Error,Symbol";
  96. const isGloballyAllowed = /* @__PURE__ */ makeMap(GLOBALS_ALLOWED);
  97. const range = 2;
  98. function generateCodeFrame(source, start = 0, end = source.length) {
  99. start = Math.max(0, Math.min(start, source.length));
  100. end = Math.max(0, Math.min(end, source.length));
  101. if (start > end) return "";
  102. let lines = source.split(/(\r?\n)/);
  103. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  104. lines = lines.filter((_, idx) => idx % 2 === 0);
  105. let count = 0;
  106. const res = [];
  107. for (let i = 0; i < lines.length; i++) {
  108. count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
  109. if (count >= start) {
  110. for (let j = i - range; j <= i + range || end > count; j++) {
  111. if (j < 0 || j >= lines.length) continue;
  112. const line = j + 1;
  113. res.push(
  114. `${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
  115. );
  116. const lineLength = lines[j].length;
  117. const newLineSeqLength = newlineSequences[j] && newlineSequences[j].length || 0;
  118. if (j === i) {
  119. const pad = start - (count - (lineLength + newLineSeqLength));
  120. const length = Math.max(
  121. 1,
  122. end > count ? lineLength - pad : end - start
  123. );
  124. res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
  125. } else if (j > i) {
  126. if (end > count) {
  127. const length = Math.max(Math.min(end - count, lineLength), 1);
  128. res.push(` | ` + "^".repeat(length));
  129. }
  130. count += lineLength + newLineSeqLength;
  131. }
  132. }
  133. break;
  134. }
  135. }
  136. return res.join("\n");
  137. }
  138. function normalizeStyle(value) {
  139. if (isArray$3(value)) {
  140. const res = {};
  141. for (let i = 0; i < value.length; i++) {
  142. const item = value[i];
  143. const normalized = isString$1(item) ? parseStringStyle(item) : normalizeStyle(item);
  144. if (normalized) {
  145. for (const key in normalized) {
  146. res[key] = normalized[key];
  147. }
  148. }
  149. }
  150. return res;
  151. } else if (isString$1(value) || isObject$2(value)) {
  152. return value;
  153. }
  154. }
  155. const listDelimiterRE = /;(?![^(]*\))/g;
  156. const propertyDelimiterRE = /:([^]+)/;
  157. const styleCommentRE = /\/\*[^]*?\*\//g;
  158. function parseStringStyle(cssText) {
  159. const ret = {};
  160. cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
  161. if (item) {
  162. const tmp = item.split(propertyDelimiterRE);
  163. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  164. }
  165. });
  166. return ret;
  167. }
  168. function stringifyStyle(styles) {
  169. if (!styles) return "";
  170. if (isString$1(styles)) return styles;
  171. let ret = "";
  172. for (const key in styles) {
  173. const value = styles[key];
  174. if (isString$1(value) || typeof value === "number") {
  175. const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
  176. ret += `${normalizedKey}:${value};`;
  177. }
  178. }
  179. return ret;
  180. }
  181. function normalizeClass(value) {
  182. let res = "";
  183. if (isString$1(value)) {
  184. res = value;
  185. } else if (isArray$3(value)) {
  186. for (let i = 0; i < value.length; i++) {
  187. const normalized = normalizeClass(value[i]);
  188. if (normalized) {
  189. res += normalized + " ";
  190. }
  191. }
  192. } else if (isObject$2(value)) {
  193. for (const name in value) {
  194. if (value[name]) {
  195. res += name + " ";
  196. }
  197. }
  198. }
  199. return res.trim();
  200. }
  201. 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";
  202. 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";
  203. const MATH_TAGS = "annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics";
  204. const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
  205. const isHTMLTag = /* @__PURE__ */ makeMap(HTML_TAGS);
  206. const isSVGTag = /* @__PURE__ */ makeMap(SVG_TAGS);
  207. const isMathMLTag = /* @__PURE__ */ makeMap(MATH_TAGS);
  208. const isVoidTag = /* @__PURE__ */ makeMap(VOID_TAGS);
  209. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  210. const isBooleanAttr = /* @__PURE__ */ makeMap(
  211. specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`
  212. );
  213. const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/;
  214. const attrValidationCache = {};
  215. function isSSRSafeAttrName(name) {
  216. if (attrValidationCache.hasOwnProperty(name)) {
  217. return attrValidationCache[name];
  218. }
  219. const isUnsafe = unsafeAttrCharRE.test(name);
  220. if (isUnsafe) {
  221. console.error(`unsafe attribute name: ${name}`);
  222. }
  223. return attrValidationCache[name] = !isUnsafe;
  224. }
  225. const propsToAttrMap = {
  226. acceptCharset: "accept-charset",
  227. className: "class",
  228. htmlFor: "for",
  229. httpEquiv: "http-equiv"
  230. };
  231. const isKnownHtmlAttr = /* @__PURE__ */ makeMap(
  232. `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`
  233. );
  234. const isKnownSvgAttr = /* @__PURE__ */ makeMap(
  235. `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,xmlns:xlink,xml:base,xml:lang,xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan`
  236. );
  237. const isKnownMathMLAttr = /* @__PURE__ */ makeMap(
  238. `accent,accentunder,actiontype,align,alignmentscope,altimg,altimg-height,altimg-valign,altimg-width,alttext,bevelled,close,columnsalign,columnlines,columnspan,denomalign,depth,dir,display,displaystyle,encoding,equalcolumns,equalrows,fence,fontstyle,fontweight,form,frame,framespacing,groupalign,height,href,id,indentalign,indentalignfirst,indentalignlast,indentshift,indentshiftfirst,indentshiftlast,indextype,justify,largetop,largeop,lquote,lspace,mathbackground,mathcolor,mathsize,mathvariant,maxsize,minlabelspacing,mode,other,overflow,position,rowalign,rowlines,rowspan,rquote,rspace,scriptlevel,scriptminsize,scriptsizemultiplier,selection,separator,separators,shift,side,src,stackalign,stretchy,subscriptshift,superscriptshift,symmetric,voffset,width,widths,xlink:href,xlink:show,xlink:type,xmlns`
  239. );
  240. const escapeRE = /["'&<>]/;
  241. function escapeHtml(string) {
  242. const str = "" + string;
  243. const match = escapeRE.exec(str);
  244. if (!match) {
  245. return str;
  246. }
  247. let html = "";
  248. let escaped;
  249. let index;
  250. let lastIndex = 0;
  251. for (index = match.index; index < str.length; index++) {
  252. switch (str.charCodeAt(index)) {
  253. case 34:
  254. escaped = "&quot;";
  255. break;
  256. case 38:
  257. escaped = "&amp;";
  258. break;
  259. case 39:
  260. escaped = "&#39;";
  261. break;
  262. case 60:
  263. escaped = "&lt;";
  264. break;
  265. case 62:
  266. escaped = "&gt;";
  267. break;
  268. default:
  269. continue;
  270. }
  271. if (lastIndex !== index) {
  272. html += str.slice(lastIndex, index);
  273. }
  274. lastIndex = index + 1;
  275. html += escaped;
  276. }
  277. return lastIndex !== index ? html + str.slice(lastIndex, index) : html;
  278. }
  279. const cssVarNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g;
  280. function getEscapedCssVarName(key, doubleEscape) {
  281. return key.replace(
  282. cssVarNameEscapeSymbolsRE,
  283. (s) => doubleEscape ? s === '"' ? '\\\\\\"' : `\\\\${s}` : `\\${s}`
  284. );
  285. }
  286. const isRef = (val) => {
  287. return !!(val && val["__v_isRef"] === true);
  288. };
  289. const toDisplayString = (val) => {
  290. return isString$1(val) ? val : val == null ? "" : isArray$3(val) || isObject$2(val) && (val.toString === objectToString$1 || !isFunction$1(val.toString)) ? isRef(val) ? toDisplayString(val.value) : JSON.stringify(val, replacer, 2) : String(val);
  291. };
  292. const replacer = (_key, val) => {
  293. if (isRef(val)) {
  294. return replacer(_key, val.value);
  295. } else if (isMap(val)) {
  296. return {
  297. [`Map(${val.size})`]: [...val.entries()].reduce(
  298. (entries, [key, val2], i) => {
  299. entries[stringifySymbol(key, i) + " =>"] = val2;
  300. return entries;
  301. },
  302. {}
  303. )
  304. };
  305. } else if (isSet(val)) {
  306. return {
  307. [`Set(${val.size})`]: [...val.values()].map((v) => stringifySymbol(v))
  308. };
  309. } else if (isSymbol$1(val)) {
  310. return stringifySymbol(val);
  311. } else if (isObject$2(val) && !isArray$3(val) && !isPlainObject(val)) {
  312. return String(val);
  313. }
  314. return val;
  315. };
  316. const stringifySymbol = (v, i = "") => {
  317. var _a;
  318. return (
  319. // Symbol.description in es2019+ so we need to cast here to pass
  320. // the lib: es2016 check
  321. isSymbol$1(v) ? `Symbol(${(_a = v.description) != null ? _a : i})` : v
  322. );
  323. };
  324. const FRAGMENT = /* @__PURE__ */ Symbol(`Fragment` );
  325. const TELEPORT = /* @__PURE__ */ Symbol(`Teleport` );
  326. const SUSPENSE = /* @__PURE__ */ Symbol(`Suspense` );
  327. const KEEP_ALIVE = /* @__PURE__ */ Symbol(`KeepAlive` );
  328. const BASE_TRANSITION = /* @__PURE__ */ Symbol(
  329. `BaseTransition`
  330. );
  331. const OPEN_BLOCK = /* @__PURE__ */ Symbol(`openBlock` );
  332. const CREATE_BLOCK = /* @__PURE__ */ Symbol(`createBlock` );
  333. const CREATE_ELEMENT_BLOCK = /* @__PURE__ */ Symbol(
  334. `createElementBlock`
  335. );
  336. const CREATE_VNODE = /* @__PURE__ */ Symbol(`createVNode` );
  337. const CREATE_ELEMENT_VNODE = /* @__PURE__ */ Symbol(
  338. `createElementVNode`
  339. );
  340. const CREATE_COMMENT = /* @__PURE__ */ Symbol(
  341. `createCommentVNode`
  342. );
  343. const CREATE_TEXT = /* @__PURE__ */ Symbol(
  344. `createTextVNode`
  345. );
  346. const CREATE_STATIC = /* @__PURE__ */ Symbol(
  347. `createStaticVNode`
  348. );
  349. const RESOLVE_COMPONENT = /* @__PURE__ */ Symbol(
  350. `resolveComponent`
  351. );
  352. const RESOLVE_DYNAMIC_COMPONENT = /* @__PURE__ */ Symbol(
  353. `resolveDynamicComponent`
  354. );
  355. const RESOLVE_DIRECTIVE = /* @__PURE__ */ Symbol(
  356. `resolveDirective`
  357. );
  358. const RESOLVE_FILTER = /* @__PURE__ */ Symbol(
  359. `resolveFilter`
  360. );
  361. const WITH_DIRECTIVES = /* @__PURE__ */ Symbol(
  362. `withDirectives`
  363. );
  364. const RENDER_LIST = /* @__PURE__ */ Symbol(`renderList` );
  365. const RENDER_SLOT = /* @__PURE__ */ Symbol(`renderSlot` );
  366. const CREATE_SLOTS = /* @__PURE__ */ Symbol(`createSlots` );
  367. const TO_DISPLAY_STRING = /* @__PURE__ */ Symbol(
  368. `toDisplayString`
  369. );
  370. const MERGE_PROPS = /* @__PURE__ */ Symbol(`mergeProps` );
  371. const NORMALIZE_CLASS = /* @__PURE__ */ Symbol(
  372. `normalizeClass`
  373. );
  374. const NORMALIZE_STYLE = /* @__PURE__ */ Symbol(
  375. `normalizeStyle`
  376. );
  377. const NORMALIZE_PROPS = /* @__PURE__ */ Symbol(
  378. `normalizeProps`
  379. );
  380. const GUARD_REACTIVE_PROPS = /* @__PURE__ */ Symbol(
  381. `guardReactiveProps`
  382. );
  383. const TO_HANDLERS = /* @__PURE__ */ Symbol(`toHandlers` );
  384. const CAMELIZE = /* @__PURE__ */ Symbol(`camelize` );
  385. const CAPITALIZE = /* @__PURE__ */ Symbol(`capitalize` );
  386. const TO_HANDLER_KEY = /* @__PURE__ */ Symbol(
  387. `toHandlerKey`
  388. );
  389. const SET_BLOCK_TRACKING = /* @__PURE__ */ Symbol(
  390. `setBlockTracking`
  391. );
  392. const PUSH_SCOPE_ID = /* @__PURE__ */ Symbol(`pushScopeId` );
  393. const POP_SCOPE_ID = /* @__PURE__ */ Symbol(`popScopeId` );
  394. const WITH_CTX = /* @__PURE__ */ Symbol(`withCtx` );
  395. const UNREF = /* @__PURE__ */ Symbol(`unref` );
  396. const IS_REF = /* @__PURE__ */ Symbol(`isRef` );
  397. const WITH_MEMO = /* @__PURE__ */ Symbol(`withMemo` );
  398. const IS_MEMO_SAME = /* @__PURE__ */ Symbol(`isMemoSame` );
  399. const helperNameMap = {
  400. [FRAGMENT]: `Fragment`,
  401. [TELEPORT]: `Teleport`,
  402. [SUSPENSE]: `Suspense`,
  403. [KEEP_ALIVE]: `KeepAlive`,
  404. [BASE_TRANSITION]: `BaseTransition`,
  405. [OPEN_BLOCK]: `openBlock`,
  406. [CREATE_BLOCK]: `createBlock`,
  407. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  408. [CREATE_VNODE]: `createVNode`,
  409. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  410. [CREATE_COMMENT]: `createCommentVNode`,
  411. [CREATE_TEXT]: `createTextVNode`,
  412. [CREATE_STATIC]: `createStaticVNode`,
  413. [RESOLVE_COMPONENT]: `resolveComponent`,
  414. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  415. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  416. [RESOLVE_FILTER]: `resolveFilter`,
  417. [WITH_DIRECTIVES]: `withDirectives`,
  418. [RENDER_LIST]: `renderList`,
  419. [RENDER_SLOT]: `renderSlot`,
  420. [CREATE_SLOTS]: `createSlots`,
  421. [TO_DISPLAY_STRING]: `toDisplayString`,
  422. [MERGE_PROPS]: `mergeProps`,
  423. [NORMALIZE_CLASS]: `normalizeClass`,
  424. [NORMALIZE_STYLE]: `normalizeStyle`,
  425. [NORMALIZE_PROPS]: `normalizeProps`,
  426. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  427. [TO_HANDLERS]: `toHandlers`,
  428. [CAMELIZE]: `camelize`,
  429. [CAPITALIZE]: `capitalize`,
  430. [TO_HANDLER_KEY]: `toHandlerKey`,
  431. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  432. [PUSH_SCOPE_ID]: `pushScopeId`,
  433. [POP_SCOPE_ID]: `popScopeId`,
  434. [WITH_CTX]: `withCtx`,
  435. [UNREF]: `unref`,
  436. [IS_REF]: `isRef`,
  437. [WITH_MEMO]: `withMemo`,
  438. [IS_MEMO_SAME]: `isMemoSame`
  439. };
  440. function registerRuntimeHelpers(helpers) {
  441. Object.getOwnPropertySymbols(helpers).forEach((s) => {
  442. helperNameMap[s] = helpers[s];
  443. });
  444. }
  445. const Namespaces = {
  446. "HTML": 0,
  447. "0": "HTML",
  448. "SVG": 1,
  449. "1": "SVG",
  450. "MATH_ML": 2,
  451. "2": "MATH_ML"
  452. };
  453. const NodeTypes = {
  454. "ROOT": 0,
  455. "0": "ROOT",
  456. "ELEMENT": 1,
  457. "1": "ELEMENT",
  458. "TEXT": 2,
  459. "2": "TEXT",
  460. "COMMENT": 3,
  461. "3": "COMMENT",
  462. "SIMPLE_EXPRESSION": 4,
  463. "4": "SIMPLE_EXPRESSION",
  464. "INTERPOLATION": 5,
  465. "5": "INTERPOLATION",
  466. "ATTRIBUTE": 6,
  467. "6": "ATTRIBUTE",
  468. "DIRECTIVE": 7,
  469. "7": "DIRECTIVE",
  470. "COMPOUND_EXPRESSION": 8,
  471. "8": "COMPOUND_EXPRESSION",
  472. "IF": 9,
  473. "9": "IF",
  474. "IF_BRANCH": 10,
  475. "10": "IF_BRANCH",
  476. "FOR": 11,
  477. "11": "FOR",
  478. "TEXT_CALL": 12,
  479. "12": "TEXT_CALL",
  480. "VNODE_CALL": 13,
  481. "13": "VNODE_CALL",
  482. "JS_CALL_EXPRESSION": 14,
  483. "14": "JS_CALL_EXPRESSION",
  484. "JS_OBJECT_EXPRESSION": 15,
  485. "15": "JS_OBJECT_EXPRESSION",
  486. "JS_PROPERTY": 16,
  487. "16": "JS_PROPERTY",
  488. "JS_ARRAY_EXPRESSION": 17,
  489. "17": "JS_ARRAY_EXPRESSION",
  490. "JS_FUNCTION_EXPRESSION": 18,
  491. "18": "JS_FUNCTION_EXPRESSION",
  492. "JS_CONDITIONAL_EXPRESSION": 19,
  493. "19": "JS_CONDITIONAL_EXPRESSION",
  494. "JS_CACHE_EXPRESSION": 20,
  495. "20": "JS_CACHE_EXPRESSION",
  496. "JS_BLOCK_STATEMENT": 21,
  497. "21": "JS_BLOCK_STATEMENT",
  498. "JS_TEMPLATE_LITERAL": 22,
  499. "22": "JS_TEMPLATE_LITERAL",
  500. "JS_IF_STATEMENT": 23,
  501. "23": "JS_IF_STATEMENT",
  502. "JS_ASSIGNMENT_EXPRESSION": 24,
  503. "24": "JS_ASSIGNMENT_EXPRESSION",
  504. "JS_SEQUENCE_EXPRESSION": 25,
  505. "25": "JS_SEQUENCE_EXPRESSION",
  506. "JS_RETURN_STATEMENT": 26,
  507. "26": "JS_RETURN_STATEMENT"
  508. };
  509. const ElementTypes = {
  510. "ELEMENT": 0,
  511. "0": "ELEMENT",
  512. "COMPONENT": 1,
  513. "1": "COMPONENT",
  514. "SLOT": 2,
  515. "2": "SLOT",
  516. "TEMPLATE": 3,
  517. "3": "TEMPLATE"
  518. };
  519. const ConstantTypes = {
  520. "NOT_CONSTANT": 0,
  521. "0": "NOT_CONSTANT",
  522. "CAN_SKIP_PATCH": 1,
  523. "1": "CAN_SKIP_PATCH",
  524. "CAN_CACHE": 2,
  525. "2": "CAN_CACHE",
  526. "CAN_STRINGIFY": 3,
  527. "3": "CAN_STRINGIFY"
  528. };
  529. const locStub = {
  530. start: { line: 1, column: 1, offset: 0 },
  531. end: { line: 1, column: 1, offset: 0 },
  532. source: ""
  533. };
  534. function createRoot(children, source = "") {
  535. return {
  536. type: 0,
  537. source,
  538. children,
  539. helpers: /* @__PURE__ */ new Set(),
  540. components: [],
  541. directives: [],
  542. hoists: [],
  543. imports: [],
  544. cached: [],
  545. temps: 0,
  546. codegenNode: void 0,
  547. loc: locStub
  548. };
  549. }
  550. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  551. if (context) {
  552. if (isBlock) {
  553. context.helper(OPEN_BLOCK);
  554. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  555. } else {
  556. context.helper(getVNodeHelper(context.inSSR, isComponent));
  557. }
  558. if (directives) {
  559. context.helper(WITH_DIRECTIVES);
  560. }
  561. }
  562. return {
  563. type: 13,
  564. tag,
  565. props,
  566. children,
  567. patchFlag,
  568. dynamicProps,
  569. directives,
  570. isBlock,
  571. disableTracking,
  572. isComponent,
  573. loc
  574. };
  575. }
  576. function createArrayExpression(elements, loc = locStub) {
  577. return {
  578. type: 17,
  579. loc,
  580. elements
  581. };
  582. }
  583. function createObjectExpression(properties, loc = locStub) {
  584. return {
  585. type: 15,
  586. loc,
  587. properties
  588. };
  589. }
  590. function createObjectProperty(key, value) {
  591. return {
  592. type: 16,
  593. loc: locStub,
  594. key: isString$1(key) ? createSimpleExpression(key, true) : key,
  595. value
  596. };
  597. }
  598. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
  599. return {
  600. type: 4,
  601. loc,
  602. content,
  603. isStatic,
  604. constType: isStatic ? 3 : constType
  605. };
  606. }
  607. function createInterpolation(content, loc) {
  608. return {
  609. type: 5,
  610. loc,
  611. content: isString$1(content) ? createSimpleExpression(content, false, loc) : content
  612. };
  613. }
  614. function createCompoundExpression(children, loc = locStub) {
  615. return {
  616. type: 8,
  617. loc,
  618. children
  619. };
  620. }
  621. function createCallExpression(callee, args = [], loc = locStub) {
  622. return {
  623. type: 14,
  624. loc,
  625. callee,
  626. arguments: args
  627. };
  628. }
  629. function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
  630. return {
  631. type: 18,
  632. params,
  633. returns,
  634. newline,
  635. isSlot,
  636. loc
  637. };
  638. }
  639. function createConditionalExpression(test, consequent, alternate, newline = true) {
  640. return {
  641. type: 19,
  642. test,
  643. consequent,
  644. alternate,
  645. newline,
  646. loc: locStub
  647. };
  648. }
  649. function createCacheExpression(index, value, needPauseTracking = false, inVOnce = false) {
  650. return {
  651. type: 20,
  652. index,
  653. value,
  654. needPauseTracking,
  655. inVOnce,
  656. needArraySpread: false,
  657. loc: locStub
  658. };
  659. }
  660. function createBlockStatement(body) {
  661. return {
  662. type: 21,
  663. body,
  664. loc: locStub
  665. };
  666. }
  667. function createTemplateLiteral(elements) {
  668. return {
  669. type: 22,
  670. elements,
  671. loc: locStub
  672. };
  673. }
  674. function createIfStatement(test, consequent, alternate) {
  675. return {
  676. type: 23,
  677. test,
  678. consequent,
  679. alternate,
  680. loc: locStub
  681. };
  682. }
  683. function createAssignmentExpression(left, right) {
  684. return {
  685. type: 24,
  686. left,
  687. right,
  688. loc: locStub
  689. };
  690. }
  691. function createSequenceExpression(expressions) {
  692. return {
  693. type: 25,
  694. expressions,
  695. loc: locStub
  696. };
  697. }
  698. function createReturnStatement(returns) {
  699. return {
  700. type: 26,
  701. returns,
  702. loc: locStub
  703. };
  704. }
  705. function getVNodeHelper(ssr, isComponent) {
  706. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  707. }
  708. function getVNodeBlockHelper(ssr, isComponent) {
  709. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  710. }
  711. function convertToBlock(node, { helper, removeHelper, inSSR }) {
  712. if (!node.isBlock) {
  713. node.isBlock = true;
  714. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  715. helper(OPEN_BLOCK);
  716. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  717. }
  718. }
  719. // Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134
  720. var _a$1;
  721. const decodeMap = new Map([
  722. [0, 65533],
  723. // C1 Unicode control character reference replacements
  724. [128, 8364],
  725. [130, 8218],
  726. [131, 402],
  727. [132, 8222],
  728. [133, 8230],
  729. [134, 8224],
  730. [135, 8225],
  731. [136, 710],
  732. [137, 8240],
  733. [138, 352],
  734. [139, 8249],
  735. [140, 338],
  736. [142, 381],
  737. [145, 8216],
  738. [146, 8217],
  739. [147, 8220],
  740. [148, 8221],
  741. [149, 8226],
  742. [150, 8211],
  743. [151, 8212],
  744. [152, 732],
  745. [153, 8482],
  746. [154, 353],
  747. [155, 8250],
  748. [156, 339],
  749. [158, 382],
  750. [159, 376],
  751. ]);
  752. /**
  753. * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point.
  754. */
  755. const fromCodePoint =
  756. // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, n/no-unsupported-features/es-builtins
  757. (_a$1 = String.fromCodePoint) !== null && _a$1 !== void 0 ? _a$1 : ((codePoint) => {
  758. let output = "";
  759. if (codePoint > 65535) {
  760. codePoint -= 65536;
  761. output += String.fromCharCode(((codePoint >>> 10) & 1023) | 55296);
  762. codePoint = 56320 | (codePoint & 1023);
  763. }
  764. output += String.fromCharCode(codePoint);
  765. return output;
  766. });
  767. /**
  768. * Replace the given code point with a replacement character if it is a
  769. * surrogate or is outside the valid range. Otherwise return the code
  770. * point unchanged.
  771. */
  772. function replaceCodePoint(codePoint) {
  773. var _a;
  774. if ((codePoint >= 55296 && codePoint <= 57343) ||
  775. codePoint > 1114111) {
  776. return 65533;
  777. }
  778. return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
  779. }
  780. var global$1 = (typeof global !== "undefined" ? global :
  781. typeof self !== "undefined" ? self :
  782. typeof window !== "undefined" ? window : {});
  783. var lookup = [];
  784. var revLookup = [];
  785. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  786. var inited = false;
  787. function init () {
  788. inited = true;
  789. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  790. for (var i = 0, len = code.length; i < len; ++i) {
  791. lookup[i] = code[i];
  792. revLookup[code.charCodeAt(i)] = i;
  793. }
  794. revLookup['-'.charCodeAt(0)] = 62;
  795. revLookup['_'.charCodeAt(0)] = 63;
  796. }
  797. function toByteArray (b64) {
  798. if (!inited) {
  799. init();
  800. }
  801. var i, j, l, tmp, placeHolders, arr;
  802. var len = b64.length;
  803. if (len % 4 > 0) {
  804. throw new Error('Invalid string. Length must be a multiple of 4')
  805. }
  806. // the number of equal signs (place holders)
  807. // if there are two placeholders, than the two characters before it
  808. // represent one byte
  809. // if there is only one, then the three characters before it represent 2 bytes
  810. // this is just a cheap hack to not do indexOf twice
  811. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
  812. // base64 is 4/3 + up to two characters of the original data
  813. arr = new Arr(len * 3 / 4 - placeHolders);
  814. // if there are placeholders, only get up to the last complete 4 chars
  815. l = placeHolders > 0 ? len - 4 : len;
  816. var L = 0;
  817. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  818. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
  819. arr[L++] = (tmp >> 16) & 0xFF;
  820. arr[L++] = (tmp >> 8) & 0xFF;
  821. arr[L++] = tmp & 0xFF;
  822. }
  823. if (placeHolders === 2) {
  824. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
  825. arr[L++] = tmp & 0xFF;
  826. } else if (placeHolders === 1) {
  827. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
  828. arr[L++] = (tmp >> 8) & 0xFF;
  829. arr[L++] = tmp & 0xFF;
  830. }
  831. return arr
  832. }
  833. function tripletToBase64 (num) {
  834. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  835. }
  836. function encodeChunk (uint8, start, end) {
  837. var tmp;
  838. var output = [];
  839. for (var i = start; i < end; i += 3) {
  840. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
  841. output.push(tripletToBase64(tmp));
  842. }
  843. return output.join('')
  844. }
  845. function fromByteArray (uint8) {
  846. if (!inited) {
  847. init();
  848. }
  849. var tmp;
  850. var len = uint8.length;
  851. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  852. var output = '';
  853. var parts = [];
  854. var maxChunkLength = 16383; // must be multiple of 3
  855. // go through the array every three bytes, we'll deal with trailing stuff later
  856. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  857. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
  858. }
  859. // pad the end with zeros, but make sure to not forget the extra bytes
  860. if (extraBytes === 1) {
  861. tmp = uint8[len - 1];
  862. output += lookup[tmp >> 2];
  863. output += lookup[(tmp << 4) & 0x3F];
  864. output += '==';
  865. } else if (extraBytes === 2) {
  866. tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
  867. output += lookup[tmp >> 10];
  868. output += lookup[(tmp >> 4) & 0x3F];
  869. output += lookup[(tmp << 2) & 0x3F];
  870. output += '=';
  871. }
  872. parts.push(output);
  873. return parts.join('')
  874. }
  875. function read (buffer, offset, isLE, mLen, nBytes) {
  876. var e, m;
  877. var eLen = nBytes * 8 - mLen - 1;
  878. var eMax = (1 << eLen) - 1;
  879. var eBias = eMax >> 1;
  880. var nBits = -7;
  881. var i = isLE ? (nBytes - 1) : 0;
  882. var d = isLE ? -1 : 1;
  883. var s = buffer[offset + i];
  884. i += d;
  885. e = s & ((1 << (-nBits)) - 1);
  886. s >>= (-nBits);
  887. nBits += eLen;
  888. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  889. m = e & ((1 << (-nBits)) - 1);
  890. e >>= (-nBits);
  891. nBits += mLen;
  892. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  893. if (e === 0) {
  894. e = 1 - eBias;
  895. } else if (e === eMax) {
  896. return m ? NaN : ((s ? -1 : 1) * Infinity)
  897. } else {
  898. m = m + Math.pow(2, mLen);
  899. e = e - eBias;
  900. }
  901. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  902. }
  903. function write (buffer, value, offset, isLE, mLen, nBytes) {
  904. var e, m, c;
  905. var eLen = nBytes * 8 - mLen - 1;
  906. var eMax = (1 << eLen) - 1;
  907. var eBias = eMax >> 1;
  908. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
  909. var i = isLE ? 0 : (nBytes - 1);
  910. var d = isLE ? 1 : -1;
  911. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  912. value = Math.abs(value);
  913. if (isNaN(value) || value === Infinity) {
  914. m = isNaN(value) ? 1 : 0;
  915. e = eMax;
  916. } else {
  917. e = Math.floor(Math.log(value) / Math.LN2);
  918. if (value * (c = Math.pow(2, -e)) < 1) {
  919. e--;
  920. c *= 2;
  921. }
  922. if (e + eBias >= 1) {
  923. value += rt / c;
  924. } else {
  925. value += rt * Math.pow(2, 1 - eBias);
  926. }
  927. if (value * c >= 2) {
  928. e++;
  929. c /= 2;
  930. }
  931. if (e + eBias >= eMax) {
  932. m = 0;
  933. e = eMax;
  934. } else if (e + eBias >= 1) {
  935. m = (value * c - 1) * Math.pow(2, mLen);
  936. e = e + eBias;
  937. } else {
  938. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  939. e = 0;
  940. }
  941. }
  942. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  943. e = (e << mLen) | m;
  944. eLen += mLen;
  945. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  946. buffer[offset + i - d] |= s * 128;
  947. }
  948. var toString$1 = {}.toString;
  949. var isArray$2 = Array.isArray || function (arr) {
  950. return toString$1.call(arr) == '[object Array]';
  951. };
  952. /*!
  953. * The buffer module from node.js, for the browser.
  954. *
  955. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  956. * @license MIT
  957. */
  958. /* eslint-disable no-proto */
  959. var INSPECT_MAX_BYTES = 50;
  960. /**
  961. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  962. * === true Use Uint8Array implementation (fastest)
  963. * === false Use Object implementation (most compatible, even IE6)
  964. *
  965. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  966. * Opera 11.6+, iOS 4.2+.
  967. *
  968. * Due to various browser bugs, sometimes the Object implementation will be used even
  969. * when the browser supports typed arrays.
  970. *
  971. * Note:
  972. *
  973. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  974. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  975. *
  976. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  977. *
  978. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  979. * incorrect length in some situations.
  980. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  981. * get the Object implementation, which is slower but behaves correctly.
  982. */
  983. Buffer$1.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
  984. ? global$1.TYPED_ARRAY_SUPPORT
  985. : true;
  986. /*
  987. * Export kMaxLength after typed array support is determined.
  988. */
  989. kMaxLength();
  990. function kMaxLength () {
  991. return Buffer$1.TYPED_ARRAY_SUPPORT
  992. ? 0x7fffffff
  993. : 0x3fffffff
  994. }
  995. function createBuffer (that, length) {
  996. if (kMaxLength() < length) {
  997. throw new RangeError('Invalid typed array length')
  998. }
  999. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  1000. // Return an augmented `Uint8Array` instance, for best performance
  1001. that = new Uint8Array(length);
  1002. that.__proto__ = Buffer$1.prototype;
  1003. } else {
  1004. // Fallback: Return an object instance of the Buffer class
  1005. if (that === null) {
  1006. that = new Buffer$1(length);
  1007. }
  1008. that.length = length;
  1009. }
  1010. return that
  1011. }
  1012. /**
  1013. * The Buffer constructor returns instances of `Uint8Array` that have their
  1014. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  1015. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  1016. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  1017. * returns a single octet.
  1018. *
  1019. * The `Uint8Array` prototype remains unmodified.
  1020. */
  1021. function Buffer$1 (arg, encodingOrOffset, length) {
  1022. if (!Buffer$1.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer$1)) {
  1023. return new Buffer$1(arg, encodingOrOffset, length)
  1024. }
  1025. // Common case.
  1026. if (typeof arg === 'number') {
  1027. if (typeof encodingOrOffset === 'string') {
  1028. throw new Error(
  1029. 'If encoding is specified then the first argument must be a string'
  1030. )
  1031. }
  1032. return allocUnsafe(this, arg)
  1033. }
  1034. return from(this, arg, encodingOrOffset, length)
  1035. }
  1036. Buffer$1.poolSize = 8192; // not used by this implementation
  1037. // TODO: Legacy, not needed anymore. Remove in next major version.
  1038. Buffer$1._augment = function (arr) {
  1039. arr.__proto__ = Buffer$1.prototype;
  1040. return arr
  1041. };
  1042. function from (that, value, encodingOrOffset, length) {
  1043. if (typeof value === 'number') {
  1044. throw new TypeError('"value" argument must not be a number')
  1045. }
  1046. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  1047. return fromArrayBuffer(that, value, encodingOrOffset, length)
  1048. }
  1049. if (typeof value === 'string') {
  1050. return fromString(that, value, encodingOrOffset)
  1051. }
  1052. return fromObject(that, value)
  1053. }
  1054. /**
  1055. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  1056. * if value is a number.
  1057. * Buffer.from(str[, encoding])
  1058. * Buffer.from(array)
  1059. * Buffer.from(buffer)
  1060. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  1061. **/
  1062. Buffer$1.from = function (value, encodingOrOffset, length) {
  1063. return from(null, value, encodingOrOffset, length)
  1064. };
  1065. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  1066. Buffer$1.prototype.__proto__ = Uint8Array.prototype;
  1067. Buffer$1.__proto__ = Uint8Array;
  1068. if (typeof Symbol !== 'undefined' && Symbol.species &&
  1069. Buffer$1[Symbol.species] === Buffer$1) ;
  1070. }
  1071. function assertSize (size) {
  1072. if (typeof size !== 'number') {
  1073. throw new TypeError('"size" argument must be a number')
  1074. } else if (size < 0) {
  1075. throw new RangeError('"size" argument must not be negative')
  1076. }
  1077. }
  1078. function alloc (that, size, fill, encoding) {
  1079. assertSize(size);
  1080. if (size <= 0) {
  1081. return createBuffer(that, size)
  1082. }
  1083. if (fill !== undefined) {
  1084. // Only pay attention to encoding if it's a string. This
  1085. // prevents accidentally sending in a number that would
  1086. // be interpretted as a start offset.
  1087. return typeof encoding === 'string'
  1088. ? createBuffer(that, size).fill(fill, encoding)
  1089. : createBuffer(that, size).fill(fill)
  1090. }
  1091. return createBuffer(that, size)
  1092. }
  1093. /**
  1094. * Creates a new filled Buffer instance.
  1095. * alloc(size[, fill[, encoding]])
  1096. **/
  1097. Buffer$1.alloc = function (size, fill, encoding) {
  1098. return alloc(null, size, fill, encoding)
  1099. };
  1100. function allocUnsafe (that, size) {
  1101. assertSize(size);
  1102. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
  1103. if (!Buffer$1.TYPED_ARRAY_SUPPORT) {
  1104. for (var i = 0; i < size; ++i) {
  1105. that[i] = 0;
  1106. }
  1107. }
  1108. return that
  1109. }
  1110. /**
  1111. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  1112. * */
  1113. Buffer$1.allocUnsafe = function (size) {
  1114. return allocUnsafe(null, size)
  1115. };
  1116. /**
  1117. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  1118. */
  1119. Buffer$1.allocUnsafeSlow = function (size) {
  1120. return allocUnsafe(null, size)
  1121. };
  1122. function fromString (that, string, encoding) {
  1123. if (typeof encoding !== 'string' || encoding === '') {
  1124. encoding = 'utf8';
  1125. }
  1126. if (!Buffer$1.isEncoding(encoding)) {
  1127. throw new TypeError('"encoding" must be a valid string encoding')
  1128. }
  1129. var length = byteLength(string, encoding) | 0;
  1130. that = createBuffer(that, length);
  1131. var actual = that.write(string, encoding);
  1132. if (actual !== length) {
  1133. // Writing a hex string, for example, that contains invalid characters will
  1134. // cause everything after the first invalid character to be ignored. (e.g.
  1135. // 'abxxcd' will be treated as 'ab')
  1136. that = that.slice(0, actual);
  1137. }
  1138. return that
  1139. }
  1140. function fromArrayLike (that, array) {
  1141. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  1142. that = createBuffer(that, length);
  1143. for (var i = 0; i < length; i += 1) {
  1144. that[i] = array[i] & 255;
  1145. }
  1146. return that
  1147. }
  1148. function fromArrayBuffer (that, array, byteOffset, length) {
  1149. array.byteLength; // this throws if `array` is not a valid ArrayBuffer
  1150. if (byteOffset < 0 || array.byteLength < byteOffset) {
  1151. throw new RangeError('\'offset\' is out of bounds')
  1152. }
  1153. if (array.byteLength < byteOffset + (length || 0)) {
  1154. throw new RangeError('\'length\' is out of bounds')
  1155. }
  1156. if (byteOffset === undefined && length === undefined) {
  1157. array = new Uint8Array(array);
  1158. } else if (length === undefined) {
  1159. array = new Uint8Array(array, byteOffset);
  1160. } else {
  1161. array = new Uint8Array(array, byteOffset, length);
  1162. }
  1163. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  1164. // Return an augmented `Uint8Array` instance, for best performance
  1165. that = array;
  1166. that.__proto__ = Buffer$1.prototype;
  1167. } else {
  1168. // Fallback: Return an object instance of the Buffer class
  1169. that = fromArrayLike(that, array);
  1170. }
  1171. return that
  1172. }
  1173. function fromObject (that, obj) {
  1174. if (internalIsBuffer(obj)) {
  1175. var len = checked(obj.length) | 0;
  1176. that = createBuffer(that, len);
  1177. if (that.length === 0) {
  1178. return that
  1179. }
  1180. obj.copy(that, 0, 0, len);
  1181. return that
  1182. }
  1183. if (obj) {
  1184. if ((typeof ArrayBuffer !== 'undefined' &&
  1185. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  1186. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  1187. return createBuffer(that, 0)
  1188. }
  1189. return fromArrayLike(that, obj)
  1190. }
  1191. if (obj.type === 'Buffer' && isArray$2(obj.data)) {
  1192. return fromArrayLike(that, obj.data)
  1193. }
  1194. }
  1195. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  1196. }
  1197. function checked (length) {
  1198. // Note: cannot use `length < kMaxLength()` here because that fails when
  1199. // length is NaN (which is otherwise coerced to zero.)
  1200. if (length >= kMaxLength()) {
  1201. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  1202. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  1203. }
  1204. return length | 0
  1205. }
  1206. Buffer$1.isBuffer = isBuffer$1;
  1207. function internalIsBuffer (b) {
  1208. return !!(b != null && b._isBuffer)
  1209. }
  1210. Buffer$1.compare = function compare (a, b) {
  1211. if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
  1212. throw new TypeError('Arguments must be Buffers')
  1213. }
  1214. if (a === b) return 0
  1215. var x = a.length;
  1216. var y = b.length;
  1217. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  1218. if (a[i] !== b[i]) {
  1219. x = a[i];
  1220. y = b[i];
  1221. break
  1222. }
  1223. }
  1224. if (x < y) return -1
  1225. if (y < x) return 1
  1226. return 0
  1227. };
  1228. Buffer$1.isEncoding = function isEncoding (encoding) {
  1229. switch (String(encoding).toLowerCase()) {
  1230. case 'hex':
  1231. case 'utf8':
  1232. case 'utf-8':
  1233. case 'ascii':
  1234. case 'latin1':
  1235. case 'binary':
  1236. case 'base64':
  1237. case 'ucs2':
  1238. case 'ucs-2':
  1239. case 'utf16le':
  1240. case 'utf-16le':
  1241. return true
  1242. default:
  1243. return false
  1244. }
  1245. };
  1246. Buffer$1.concat = function concat (list, length) {
  1247. if (!isArray$2(list)) {
  1248. throw new TypeError('"list" argument must be an Array of Buffers')
  1249. }
  1250. if (list.length === 0) {
  1251. return Buffer$1.alloc(0)
  1252. }
  1253. var i;
  1254. if (length === undefined) {
  1255. length = 0;
  1256. for (i = 0; i < list.length; ++i) {
  1257. length += list[i].length;
  1258. }
  1259. }
  1260. var buffer = Buffer$1.allocUnsafe(length);
  1261. var pos = 0;
  1262. for (i = 0; i < list.length; ++i) {
  1263. var buf = list[i];
  1264. if (!internalIsBuffer(buf)) {
  1265. throw new TypeError('"list" argument must be an Array of Buffers')
  1266. }
  1267. buf.copy(buffer, pos);
  1268. pos += buf.length;
  1269. }
  1270. return buffer
  1271. };
  1272. function byteLength (string, encoding) {
  1273. if (internalIsBuffer(string)) {
  1274. return string.length
  1275. }
  1276. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  1277. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  1278. return string.byteLength
  1279. }
  1280. if (typeof string !== 'string') {
  1281. string = '' + string;
  1282. }
  1283. var len = string.length;
  1284. if (len === 0) return 0
  1285. // Use a for loop to avoid recursion
  1286. var loweredCase = false;
  1287. for (;;) {
  1288. switch (encoding) {
  1289. case 'ascii':
  1290. case 'latin1':
  1291. case 'binary':
  1292. return len
  1293. case 'utf8':
  1294. case 'utf-8':
  1295. case undefined:
  1296. return utf8ToBytes(string).length
  1297. case 'ucs2':
  1298. case 'ucs-2':
  1299. case 'utf16le':
  1300. case 'utf-16le':
  1301. return len * 2
  1302. case 'hex':
  1303. return len >>> 1
  1304. case 'base64':
  1305. return base64ToBytes(string).length
  1306. default:
  1307. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  1308. encoding = ('' + encoding).toLowerCase();
  1309. loweredCase = true;
  1310. }
  1311. }
  1312. }
  1313. Buffer$1.byteLength = byteLength;
  1314. function slowToString (encoding, start, end) {
  1315. var loweredCase = false;
  1316. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  1317. // property of a typed array.
  1318. // This behaves neither like String nor Uint8Array in that we set start/end
  1319. // to their upper/lower bounds if the value passed is out of range.
  1320. // undefined is handled specially as per ECMA-262 6th Edition,
  1321. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  1322. if (start === undefined || start < 0) {
  1323. start = 0;
  1324. }
  1325. // Return early if start > this.length. Done here to prevent potential uint32
  1326. // coercion fail below.
  1327. if (start > this.length) {
  1328. return ''
  1329. }
  1330. if (end === undefined || end > this.length) {
  1331. end = this.length;
  1332. }
  1333. if (end <= 0) {
  1334. return ''
  1335. }
  1336. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  1337. end >>>= 0;
  1338. start >>>= 0;
  1339. if (end <= start) {
  1340. return ''
  1341. }
  1342. if (!encoding) encoding = 'utf8';
  1343. while (true) {
  1344. switch (encoding) {
  1345. case 'hex':
  1346. return hexSlice(this, start, end)
  1347. case 'utf8':
  1348. case 'utf-8':
  1349. return utf8Slice(this, start, end)
  1350. case 'ascii':
  1351. return asciiSlice(this, start, end)
  1352. case 'latin1':
  1353. case 'binary':
  1354. return latin1Slice(this, start, end)
  1355. case 'base64':
  1356. return base64Slice(this, start, end)
  1357. case 'ucs2':
  1358. case 'ucs-2':
  1359. case 'utf16le':
  1360. case 'utf-16le':
  1361. return utf16leSlice(this, start, end)
  1362. default:
  1363. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  1364. encoding = (encoding + '').toLowerCase();
  1365. loweredCase = true;
  1366. }
  1367. }
  1368. }
  1369. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  1370. // Buffer instances.
  1371. Buffer$1.prototype._isBuffer = true;
  1372. function swap (b, n, m) {
  1373. var i = b[n];
  1374. b[n] = b[m];
  1375. b[m] = i;
  1376. }
  1377. Buffer$1.prototype.swap16 = function swap16 () {
  1378. var len = this.length;
  1379. if (len % 2 !== 0) {
  1380. throw new RangeError('Buffer size must be a multiple of 16-bits')
  1381. }
  1382. for (var i = 0; i < len; i += 2) {
  1383. swap(this, i, i + 1);
  1384. }
  1385. return this
  1386. };
  1387. Buffer$1.prototype.swap32 = function swap32 () {
  1388. var len = this.length;
  1389. if (len % 4 !== 0) {
  1390. throw new RangeError('Buffer size must be a multiple of 32-bits')
  1391. }
  1392. for (var i = 0; i < len; i += 4) {
  1393. swap(this, i, i + 3);
  1394. swap(this, i + 1, i + 2);
  1395. }
  1396. return this
  1397. };
  1398. Buffer$1.prototype.swap64 = function swap64 () {
  1399. var len = this.length;
  1400. if (len % 8 !== 0) {
  1401. throw new RangeError('Buffer size must be a multiple of 64-bits')
  1402. }
  1403. for (var i = 0; i < len; i += 8) {
  1404. swap(this, i, i + 7);
  1405. swap(this, i + 1, i + 6);
  1406. swap(this, i + 2, i + 5);
  1407. swap(this, i + 3, i + 4);
  1408. }
  1409. return this
  1410. };
  1411. Buffer$1.prototype.toString = function toString () {
  1412. var length = this.length | 0;
  1413. if (length === 0) return ''
  1414. if (arguments.length === 0) return utf8Slice(this, 0, length)
  1415. return slowToString.apply(this, arguments)
  1416. };
  1417. Buffer$1.prototype.equals = function equals (b) {
  1418. if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
  1419. if (this === b) return true
  1420. return Buffer$1.compare(this, b) === 0
  1421. };
  1422. Buffer$1.prototype.inspect = function inspect () {
  1423. var str = '';
  1424. var max = INSPECT_MAX_BYTES;
  1425. if (this.length > 0) {
  1426. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
  1427. if (this.length > max) str += ' ... ';
  1428. }
  1429. return '<Buffer ' + str + '>'
  1430. };
  1431. Buffer$1.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  1432. if (!internalIsBuffer(target)) {
  1433. throw new TypeError('Argument must be a Buffer')
  1434. }
  1435. if (start === undefined) {
  1436. start = 0;
  1437. }
  1438. if (end === undefined) {
  1439. end = target ? target.length : 0;
  1440. }
  1441. if (thisStart === undefined) {
  1442. thisStart = 0;
  1443. }
  1444. if (thisEnd === undefined) {
  1445. thisEnd = this.length;
  1446. }
  1447. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  1448. throw new RangeError('out of range index')
  1449. }
  1450. if (thisStart >= thisEnd && start >= end) {
  1451. return 0
  1452. }
  1453. if (thisStart >= thisEnd) {
  1454. return -1
  1455. }
  1456. if (start >= end) {
  1457. return 1
  1458. }
  1459. start >>>= 0;
  1460. end >>>= 0;
  1461. thisStart >>>= 0;
  1462. thisEnd >>>= 0;
  1463. if (this === target) return 0
  1464. var x = thisEnd - thisStart;
  1465. var y = end - start;
  1466. var len = Math.min(x, y);
  1467. var thisCopy = this.slice(thisStart, thisEnd);
  1468. var targetCopy = target.slice(start, end);
  1469. for (var i = 0; i < len; ++i) {
  1470. if (thisCopy[i] !== targetCopy[i]) {
  1471. x = thisCopy[i];
  1472. y = targetCopy[i];
  1473. break
  1474. }
  1475. }
  1476. if (x < y) return -1
  1477. if (y < x) return 1
  1478. return 0
  1479. };
  1480. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  1481. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  1482. //
  1483. // Arguments:
  1484. // - buffer - a Buffer to search
  1485. // - val - a string, Buffer, or number
  1486. // - byteOffset - an index into `buffer`; will be clamped to an int32
  1487. // - encoding - an optional encoding, relevant is val is a string
  1488. // - dir - true for indexOf, false for lastIndexOf
  1489. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  1490. // Empty buffer means no match
  1491. if (buffer.length === 0) return -1
  1492. // Normalize byteOffset
  1493. if (typeof byteOffset === 'string') {
  1494. encoding = byteOffset;
  1495. byteOffset = 0;
  1496. } else if (byteOffset > 0x7fffffff) {
  1497. byteOffset = 0x7fffffff;
  1498. } else if (byteOffset < -2147483648) {
  1499. byteOffset = -2147483648;
  1500. }
  1501. byteOffset = +byteOffset; // Coerce to Number.
  1502. if (isNaN(byteOffset)) {
  1503. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  1504. byteOffset = dir ? 0 : (buffer.length - 1);
  1505. }
  1506. // Normalize byteOffset: negative offsets start from the end of the buffer
  1507. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  1508. if (byteOffset >= buffer.length) {
  1509. if (dir) return -1
  1510. else byteOffset = buffer.length - 1;
  1511. } else if (byteOffset < 0) {
  1512. if (dir) byteOffset = 0;
  1513. else return -1
  1514. }
  1515. // Normalize val
  1516. if (typeof val === 'string') {
  1517. val = Buffer$1.from(val, encoding);
  1518. }
  1519. // Finally, search either indexOf (if dir is true) or lastIndexOf
  1520. if (internalIsBuffer(val)) {
  1521. // Special case: looking for empty string/buffer always fails
  1522. if (val.length === 0) {
  1523. return -1
  1524. }
  1525. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  1526. } else if (typeof val === 'number') {
  1527. val = val & 0xFF; // Search for a byte value [0-255]
  1528. if (Buffer$1.TYPED_ARRAY_SUPPORT &&
  1529. typeof Uint8Array.prototype.indexOf === 'function') {
  1530. if (dir) {
  1531. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  1532. } else {
  1533. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  1534. }
  1535. }
  1536. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  1537. }
  1538. throw new TypeError('val must be string, number or Buffer')
  1539. }
  1540. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  1541. var indexSize = 1;
  1542. var arrLength = arr.length;
  1543. var valLength = val.length;
  1544. if (encoding !== undefined) {
  1545. encoding = String(encoding).toLowerCase();
  1546. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  1547. encoding === 'utf16le' || encoding === 'utf-16le') {
  1548. if (arr.length < 2 || val.length < 2) {
  1549. return -1
  1550. }
  1551. indexSize = 2;
  1552. arrLength /= 2;
  1553. valLength /= 2;
  1554. byteOffset /= 2;
  1555. }
  1556. }
  1557. function read (buf, i) {
  1558. if (indexSize === 1) {
  1559. return buf[i]
  1560. } else {
  1561. return buf.readUInt16BE(i * indexSize)
  1562. }
  1563. }
  1564. var i;
  1565. if (dir) {
  1566. var foundIndex = -1;
  1567. for (i = byteOffset; i < arrLength; i++) {
  1568. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  1569. if (foundIndex === -1) foundIndex = i;
  1570. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  1571. } else {
  1572. if (foundIndex !== -1) i -= i - foundIndex;
  1573. foundIndex = -1;
  1574. }
  1575. }
  1576. } else {
  1577. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  1578. for (i = byteOffset; i >= 0; i--) {
  1579. var found = true;
  1580. for (var j = 0; j < valLength; j++) {
  1581. if (read(arr, i + j) !== read(val, j)) {
  1582. found = false;
  1583. break
  1584. }
  1585. }
  1586. if (found) return i
  1587. }
  1588. }
  1589. return -1
  1590. }
  1591. Buffer$1.prototype.includes = function includes (val, byteOffset, encoding) {
  1592. return this.indexOf(val, byteOffset, encoding) !== -1
  1593. };
  1594. Buffer$1.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  1595. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  1596. };
  1597. Buffer$1.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  1598. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  1599. };
  1600. function hexWrite (buf, string, offset, length) {
  1601. offset = Number(offset) || 0;
  1602. var remaining = buf.length - offset;
  1603. if (!length) {
  1604. length = remaining;
  1605. } else {
  1606. length = Number(length);
  1607. if (length > remaining) {
  1608. length = remaining;
  1609. }
  1610. }
  1611. // must be an even number of digits
  1612. var strLen = string.length;
  1613. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  1614. if (length > strLen / 2) {
  1615. length = strLen / 2;
  1616. }
  1617. for (var i = 0; i < length; ++i) {
  1618. var parsed = parseInt(string.substr(i * 2, 2), 16);
  1619. if (isNaN(parsed)) return i
  1620. buf[offset + i] = parsed;
  1621. }
  1622. return i
  1623. }
  1624. function utf8Write (buf, string, offset, length) {
  1625. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  1626. }
  1627. function asciiWrite (buf, string, offset, length) {
  1628. return blitBuffer(asciiToBytes(string), buf, offset, length)
  1629. }
  1630. function latin1Write (buf, string, offset, length) {
  1631. return asciiWrite(buf, string, offset, length)
  1632. }
  1633. function base64Write (buf, string, offset, length) {
  1634. return blitBuffer(base64ToBytes(string), buf, offset, length)
  1635. }
  1636. function ucs2Write (buf, string, offset, length) {
  1637. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  1638. }
  1639. Buffer$1.prototype.write = function write (string, offset, length, encoding) {
  1640. // Buffer#write(string)
  1641. if (offset === undefined) {
  1642. encoding = 'utf8';
  1643. length = this.length;
  1644. offset = 0;
  1645. // Buffer#write(string, encoding)
  1646. } else if (length === undefined && typeof offset === 'string') {
  1647. encoding = offset;
  1648. length = this.length;
  1649. offset = 0;
  1650. // Buffer#write(string, offset[, length][, encoding])
  1651. } else if (isFinite(offset)) {
  1652. offset = offset | 0;
  1653. if (isFinite(length)) {
  1654. length = length | 0;
  1655. if (encoding === undefined) encoding = 'utf8';
  1656. } else {
  1657. encoding = length;
  1658. length = undefined;
  1659. }
  1660. // legacy write(string, encoding, offset, length) - remove in v0.13
  1661. } else {
  1662. throw new Error(
  1663. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  1664. )
  1665. }
  1666. var remaining = this.length - offset;
  1667. if (length === undefined || length > remaining) length = remaining;
  1668. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  1669. throw new RangeError('Attempt to write outside buffer bounds')
  1670. }
  1671. if (!encoding) encoding = 'utf8';
  1672. var loweredCase = false;
  1673. for (;;) {
  1674. switch (encoding) {
  1675. case 'hex':
  1676. return hexWrite(this, string, offset, length)
  1677. case 'utf8':
  1678. case 'utf-8':
  1679. return utf8Write(this, string, offset, length)
  1680. case 'ascii':
  1681. return asciiWrite(this, string, offset, length)
  1682. case 'latin1':
  1683. case 'binary':
  1684. return latin1Write(this, string, offset, length)
  1685. case 'base64':
  1686. // Warning: maxLength not taken into account in base64Write
  1687. return base64Write(this, string, offset, length)
  1688. case 'ucs2':
  1689. case 'ucs-2':
  1690. case 'utf16le':
  1691. case 'utf-16le':
  1692. return ucs2Write(this, string, offset, length)
  1693. default:
  1694. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  1695. encoding = ('' + encoding).toLowerCase();
  1696. loweredCase = true;
  1697. }
  1698. }
  1699. };
  1700. Buffer$1.prototype.toJSON = function toJSON () {
  1701. return {
  1702. type: 'Buffer',
  1703. data: Array.prototype.slice.call(this._arr || this, 0)
  1704. }
  1705. };
  1706. function base64Slice (buf, start, end) {
  1707. if (start === 0 && end === buf.length) {
  1708. return fromByteArray(buf)
  1709. } else {
  1710. return fromByteArray(buf.slice(start, end))
  1711. }
  1712. }
  1713. function utf8Slice (buf, start, end) {
  1714. end = Math.min(buf.length, end);
  1715. var res = [];
  1716. var i = start;
  1717. while (i < end) {
  1718. var firstByte = buf[i];
  1719. var codePoint = null;
  1720. var bytesPerSequence = (firstByte > 0xEF) ? 4
  1721. : (firstByte > 0xDF) ? 3
  1722. : (firstByte > 0xBF) ? 2
  1723. : 1;
  1724. if (i + bytesPerSequence <= end) {
  1725. var secondByte, thirdByte, fourthByte, tempCodePoint;
  1726. switch (bytesPerSequence) {
  1727. case 1:
  1728. if (firstByte < 0x80) {
  1729. codePoint = firstByte;
  1730. }
  1731. break
  1732. case 2:
  1733. secondByte = buf[i + 1];
  1734. if ((secondByte & 0xC0) === 0x80) {
  1735. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
  1736. if (tempCodePoint > 0x7F) {
  1737. codePoint = tempCodePoint;
  1738. }
  1739. }
  1740. break
  1741. case 3:
  1742. secondByte = buf[i + 1];
  1743. thirdByte = buf[i + 2];
  1744. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  1745. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
  1746. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  1747. codePoint = tempCodePoint;
  1748. }
  1749. }
  1750. break
  1751. case 4:
  1752. secondByte = buf[i + 1];
  1753. thirdByte = buf[i + 2];
  1754. fourthByte = buf[i + 3];
  1755. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  1756. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
  1757. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  1758. codePoint = tempCodePoint;
  1759. }
  1760. }
  1761. }
  1762. }
  1763. if (codePoint === null) {
  1764. // we did not generate a valid codePoint so insert a
  1765. // replacement char (U+FFFD) and advance only 1 byte
  1766. codePoint = 0xFFFD;
  1767. bytesPerSequence = 1;
  1768. } else if (codePoint > 0xFFFF) {
  1769. // encode to utf16 (surrogate pair dance)
  1770. codePoint -= 0x10000;
  1771. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  1772. codePoint = 0xDC00 | codePoint & 0x3FF;
  1773. }
  1774. res.push(codePoint);
  1775. i += bytesPerSequence;
  1776. }
  1777. return decodeCodePointsArray(res)
  1778. }
  1779. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  1780. // the lowest limit is Chrome, with 0x10000 args.
  1781. // We go 1 magnitude less, for safety
  1782. var MAX_ARGUMENTS_LENGTH = 0x1000;
  1783. function decodeCodePointsArray (codePoints) {
  1784. var len = codePoints.length;
  1785. if (len <= MAX_ARGUMENTS_LENGTH) {
  1786. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  1787. }
  1788. // Decode in chunks to avoid "call stack size exceeded".
  1789. var res = '';
  1790. var i = 0;
  1791. while (i < len) {
  1792. res += String.fromCharCode.apply(
  1793. String,
  1794. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  1795. );
  1796. }
  1797. return res
  1798. }
  1799. function asciiSlice (buf, start, end) {
  1800. var ret = '';
  1801. end = Math.min(buf.length, end);
  1802. for (var i = start; i < end; ++i) {
  1803. ret += String.fromCharCode(buf[i] & 0x7F);
  1804. }
  1805. return ret
  1806. }
  1807. function latin1Slice (buf, start, end) {
  1808. var ret = '';
  1809. end = Math.min(buf.length, end);
  1810. for (var i = start; i < end; ++i) {
  1811. ret += String.fromCharCode(buf[i]);
  1812. }
  1813. return ret
  1814. }
  1815. function hexSlice (buf, start, end) {
  1816. var len = buf.length;
  1817. if (!start || start < 0) start = 0;
  1818. if (!end || end < 0 || end > len) end = len;
  1819. var out = '';
  1820. for (var i = start; i < end; ++i) {
  1821. out += toHex(buf[i]);
  1822. }
  1823. return out
  1824. }
  1825. function utf16leSlice (buf, start, end) {
  1826. var bytes = buf.slice(start, end);
  1827. var res = '';
  1828. for (var i = 0; i < bytes.length; i += 2) {
  1829. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  1830. }
  1831. return res
  1832. }
  1833. Buffer$1.prototype.slice = function slice (start, end) {
  1834. var len = this.length;
  1835. start = ~~start;
  1836. end = end === undefined ? len : ~~end;
  1837. if (start < 0) {
  1838. start += len;
  1839. if (start < 0) start = 0;
  1840. } else if (start > len) {
  1841. start = len;
  1842. }
  1843. if (end < 0) {
  1844. end += len;
  1845. if (end < 0) end = 0;
  1846. } else if (end > len) {
  1847. end = len;
  1848. }
  1849. if (end < start) end = start;
  1850. var newBuf;
  1851. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  1852. newBuf = this.subarray(start, end);
  1853. newBuf.__proto__ = Buffer$1.prototype;
  1854. } else {
  1855. var sliceLen = end - start;
  1856. newBuf = new Buffer$1(sliceLen, undefined);
  1857. for (var i = 0; i < sliceLen; ++i) {
  1858. newBuf[i] = this[i + start];
  1859. }
  1860. }
  1861. return newBuf
  1862. };
  1863. /*
  1864. * Need to make sure that buffer isn't trying to write out of bounds.
  1865. */
  1866. function checkOffset (offset, ext, length) {
  1867. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  1868. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  1869. }
  1870. Buffer$1.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  1871. offset = offset | 0;
  1872. byteLength = byteLength | 0;
  1873. if (!noAssert) checkOffset(offset, byteLength, this.length);
  1874. var val = this[offset];
  1875. var mul = 1;
  1876. var i = 0;
  1877. while (++i < byteLength && (mul *= 0x100)) {
  1878. val += this[offset + i] * mul;
  1879. }
  1880. return val
  1881. };
  1882. Buffer$1.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  1883. offset = offset | 0;
  1884. byteLength = byteLength | 0;
  1885. if (!noAssert) {
  1886. checkOffset(offset, byteLength, this.length);
  1887. }
  1888. var val = this[offset + --byteLength];
  1889. var mul = 1;
  1890. while (byteLength > 0 && (mul *= 0x100)) {
  1891. val += this[offset + --byteLength] * mul;
  1892. }
  1893. return val
  1894. };
  1895. Buffer$1.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  1896. if (!noAssert) checkOffset(offset, 1, this.length);
  1897. return this[offset]
  1898. };
  1899. Buffer$1.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  1900. if (!noAssert) checkOffset(offset, 2, this.length);
  1901. return this[offset] | (this[offset + 1] << 8)
  1902. };
  1903. Buffer$1.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  1904. if (!noAssert) checkOffset(offset, 2, this.length);
  1905. return (this[offset] << 8) | this[offset + 1]
  1906. };
  1907. Buffer$1.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  1908. if (!noAssert) checkOffset(offset, 4, this.length);
  1909. return ((this[offset]) |
  1910. (this[offset + 1] << 8) |
  1911. (this[offset + 2] << 16)) +
  1912. (this[offset + 3] * 0x1000000)
  1913. };
  1914. Buffer$1.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  1915. if (!noAssert) checkOffset(offset, 4, this.length);
  1916. return (this[offset] * 0x1000000) +
  1917. ((this[offset + 1] << 16) |
  1918. (this[offset + 2] << 8) |
  1919. this[offset + 3])
  1920. };
  1921. Buffer$1.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  1922. offset = offset | 0;
  1923. byteLength = byteLength | 0;
  1924. if (!noAssert) checkOffset(offset, byteLength, this.length);
  1925. var val = this[offset];
  1926. var mul = 1;
  1927. var i = 0;
  1928. while (++i < byteLength && (mul *= 0x100)) {
  1929. val += this[offset + i] * mul;
  1930. }
  1931. mul *= 0x80;
  1932. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  1933. return val
  1934. };
  1935. Buffer$1.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  1936. offset = offset | 0;
  1937. byteLength = byteLength | 0;
  1938. if (!noAssert) checkOffset(offset, byteLength, this.length);
  1939. var i = byteLength;
  1940. var mul = 1;
  1941. var val = this[offset + --i];
  1942. while (i > 0 && (mul *= 0x100)) {
  1943. val += this[offset + --i] * mul;
  1944. }
  1945. mul *= 0x80;
  1946. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  1947. return val
  1948. };
  1949. Buffer$1.prototype.readInt8 = function readInt8 (offset, noAssert) {
  1950. if (!noAssert) checkOffset(offset, 1, this.length);
  1951. if (!(this[offset] & 0x80)) return (this[offset])
  1952. return ((0xff - this[offset] + 1) * -1)
  1953. };
  1954. Buffer$1.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  1955. if (!noAssert) checkOffset(offset, 2, this.length);
  1956. var val = this[offset] | (this[offset + 1] << 8);
  1957. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1958. };
  1959. Buffer$1.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  1960. if (!noAssert) checkOffset(offset, 2, this.length);
  1961. var val = this[offset + 1] | (this[offset] << 8);
  1962. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1963. };
  1964. Buffer$1.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  1965. if (!noAssert) checkOffset(offset, 4, this.length);
  1966. return (this[offset]) |
  1967. (this[offset + 1] << 8) |
  1968. (this[offset + 2] << 16) |
  1969. (this[offset + 3] << 24)
  1970. };
  1971. Buffer$1.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  1972. if (!noAssert) checkOffset(offset, 4, this.length);
  1973. return (this[offset] << 24) |
  1974. (this[offset + 1] << 16) |
  1975. (this[offset + 2] << 8) |
  1976. (this[offset + 3])
  1977. };
  1978. Buffer$1.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  1979. if (!noAssert) checkOffset(offset, 4, this.length);
  1980. return read(this, offset, true, 23, 4)
  1981. };
  1982. Buffer$1.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  1983. if (!noAssert) checkOffset(offset, 4, this.length);
  1984. return read(this, offset, false, 23, 4)
  1985. };
  1986. Buffer$1.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  1987. if (!noAssert) checkOffset(offset, 8, this.length);
  1988. return read(this, offset, true, 52, 8)
  1989. };
  1990. Buffer$1.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  1991. if (!noAssert) checkOffset(offset, 8, this.length);
  1992. return read(this, offset, false, 52, 8)
  1993. };
  1994. function checkInt (buf, value, offset, ext, max, min) {
  1995. if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  1996. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  1997. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1998. }
  1999. Buffer$1.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  2000. value = +value;
  2001. offset = offset | 0;
  2002. byteLength = byteLength | 0;
  2003. if (!noAssert) {
  2004. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  2005. checkInt(this, value, offset, byteLength, maxBytes, 0);
  2006. }
  2007. var mul = 1;
  2008. var i = 0;
  2009. this[offset] = value & 0xFF;
  2010. while (++i < byteLength && (mul *= 0x100)) {
  2011. this[offset + i] = (value / mul) & 0xFF;
  2012. }
  2013. return offset + byteLength
  2014. };
  2015. Buffer$1.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  2016. value = +value;
  2017. offset = offset | 0;
  2018. byteLength = byteLength | 0;
  2019. if (!noAssert) {
  2020. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  2021. checkInt(this, value, offset, byteLength, maxBytes, 0);
  2022. }
  2023. var i = byteLength - 1;
  2024. var mul = 1;
  2025. this[offset + i] = value & 0xFF;
  2026. while (--i >= 0 && (mul *= 0x100)) {
  2027. this[offset + i] = (value / mul) & 0xFF;
  2028. }
  2029. return offset + byteLength
  2030. };
  2031. Buffer$1.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  2032. value = +value;
  2033. offset = offset | 0;
  2034. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  2035. if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  2036. this[offset] = (value & 0xff);
  2037. return offset + 1
  2038. };
  2039. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  2040. if (value < 0) value = 0xffff + value + 1;
  2041. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  2042. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  2043. (littleEndian ? i : 1 - i) * 8;
  2044. }
  2045. }
  2046. Buffer$1.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  2047. value = +value;
  2048. offset = offset | 0;
  2049. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  2050. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  2051. this[offset] = (value & 0xff);
  2052. this[offset + 1] = (value >>> 8);
  2053. } else {
  2054. objectWriteUInt16(this, value, offset, true);
  2055. }
  2056. return offset + 2
  2057. };
  2058. Buffer$1.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  2059. value = +value;
  2060. offset = offset | 0;
  2061. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  2062. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  2063. this[offset] = (value >>> 8);
  2064. this[offset + 1] = (value & 0xff);
  2065. } else {
  2066. objectWriteUInt16(this, value, offset, false);
  2067. }
  2068. return offset + 2
  2069. };
  2070. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  2071. if (value < 0) value = 0xffffffff + value + 1;
  2072. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  2073. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
  2074. }
  2075. }
  2076. Buffer$1.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  2077. value = +value;
  2078. offset = offset | 0;
  2079. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  2080. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  2081. this[offset + 3] = (value >>> 24);
  2082. this[offset + 2] = (value >>> 16);
  2083. this[offset + 1] = (value >>> 8);
  2084. this[offset] = (value & 0xff);
  2085. } else {
  2086. objectWriteUInt32(this, value, offset, true);
  2087. }
  2088. return offset + 4
  2089. };
  2090. Buffer$1.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  2091. value = +value;
  2092. offset = offset | 0;
  2093. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  2094. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  2095. this[offset] = (value >>> 24);
  2096. this[offset + 1] = (value >>> 16);
  2097. this[offset + 2] = (value >>> 8);
  2098. this[offset + 3] = (value & 0xff);
  2099. } else {
  2100. objectWriteUInt32(this, value, offset, false);
  2101. }
  2102. return offset + 4
  2103. };
  2104. Buffer$1.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  2105. value = +value;
  2106. offset = offset | 0;
  2107. if (!noAssert) {
  2108. var limit = Math.pow(2, 8 * byteLength - 1);
  2109. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  2110. }
  2111. var i = 0;
  2112. var mul = 1;
  2113. var sub = 0;
  2114. this[offset] = value & 0xFF;
  2115. while (++i < byteLength && (mul *= 0x100)) {
  2116. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  2117. sub = 1;
  2118. }
  2119. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  2120. }
  2121. return offset + byteLength
  2122. };
  2123. Buffer$1.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  2124. value = +value;
  2125. offset = offset | 0;
  2126. if (!noAssert) {
  2127. var limit = Math.pow(2, 8 * byteLength - 1);
  2128. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  2129. }
  2130. var i = byteLength - 1;
  2131. var mul = 1;
  2132. var sub = 0;
  2133. this[offset + i] = value & 0xFF;
  2134. while (--i >= 0 && (mul *= 0x100)) {
  2135. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  2136. sub = 1;
  2137. }
  2138. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  2139. }
  2140. return offset + byteLength
  2141. };
  2142. Buffer$1.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  2143. value = +value;
  2144. offset = offset | 0;
  2145. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
  2146. if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  2147. if (value < 0) value = 0xff + value + 1;
  2148. this[offset] = (value & 0xff);
  2149. return offset + 1
  2150. };
  2151. Buffer$1.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  2152. value = +value;
  2153. offset = offset | 0;
  2154. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
  2155. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  2156. this[offset] = (value & 0xff);
  2157. this[offset + 1] = (value >>> 8);
  2158. } else {
  2159. objectWriteUInt16(this, value, offset, true);
  2160. }
  2161. return offset + 2
  2162. };
  2163. Buffer$1.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  2164. value = +value;
  2165. offset = offset | 0;
  2166. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
  2167. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  2168. this[offset] = (value >>> 8);
  2169. this[offset + 1] = (value & 0xff);
  2170. } else {
  2171. objectWriteUInt16(this, value, offset, false);
  2172. }
  2173. return offset + 2
  2174. };
  2175. Buffer$1.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  2176. value = +value;
  2177. offset = offset | 0;
  2178. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
  2179. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  2180. this[offset] = (value & 0xff);
  2181. this[offset + 1] = (value >>> 8);
  2182. this[offset + 2] = (value >>> 16);
  2183. this[offset + 3] = (value >>> 24);
  2184. } else {
  2185. objectWriteUInt32(this, value, offset, true);
  2186. }
  2187. return offset + 4
  2188. };
  2189. Buffer$1.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  2190. value = +value;
  2191. offset = offset | 0;
  2192. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
  2193. if (value < 0) value = 0xffffffff + value + 1;
  2194. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  2195. this[offset] = (value >>> 24);
  2196. this[offset + 1] = (value >>> 16);
  2197. this[offset + 2] = (value >>> 8);
  2198. this[offset + 3] = (value & 0xff);
  2199. } else {
  2200. objectWriteUInt32(this, value, offset, false);
  2201. }
  2202. return offset + 4
  2203. };
  2204. function checkIEEE754 (buf, value, offset, ext, max, min) {
  2205. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  2206. if (offset < 0) throw new RangeError('Index out of range')
  2207. }
  2208. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  2209. if (!noAssert) {
  2210. checkIEEE754(buf, value, offset, 4);
  2211. }
  2212. write(buf, value, offset, littleEndian, 23, 4);
  2213. return offset + 4
  2214. }
  2215. Buffer$1.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  2216. return writeFloat(this, value, offset, true, noAssert)
  2217. };
  2218. Buffer$1.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  2219. return writeFloat(this, value, offset, false, noAssert)
  2220. };
  2221. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  2222. if (!noAssert) {
  2223. checkIEEE754(buf, value, offset, 8);
  2224. }
  2225. write(buf, value, offset, littleEndian, 52, 8);
  2226. return offset + 8
  2227. }
  2228. Buffer$1.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  2229. return writeDouble(this, value, offset, true, noAssert)
  2230. };
  2231. Buffer$1.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  2232. return writeDouble(this, value, offset, false, noAssert)
  2233. };
  2234. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  2235. Buffer$1.prototype.copy = function copy (target, targetStart, start, end) {
  2236. if (!start) start = 0;
  2237. if (!end && end !== 0) end = this.length;
  2238. if (targetStart >= target.length) targetStart = target.length;
  2239. if (!targetStart) targetStart = 0;
  2240. if (end > 0 && end < start) end = start;
  2241. // Copy 0 bytes; we're done
  2242. if (end === start) return 0
  2243. if (target.length === 0 || this.length === 0) return 0
  2244. // Fatal error conditions
  2245. if (targetStart < 0) {
  2246. throw new RangeError('targetStart out of bounds')
  2247. }
  2248. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  2249. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  2250. // Are we oob?
  2251. if (end > this.length) end = this.length;
  2252. if (target.length - targetStart < end - start) {
  2253. end = target.length - targetStart + start;
  2254. }
  2255. var len = end - start;
  2256. var i;
  2257. if (this === target && start < targetStart && targetStart < end) {
  2258. // descending copy from end
  2259. for (i = len - 1; i >= 0; --i) {
  2260. target[i + targetStart] = this[i + start];
  2261. }
  2262. } else if (len < 1000 || !Buffer$1.TYPED_ARRAY_SUPPORT) {
  2263. // ascending copy from start
  2264. for (i = 0; i < len; ++i) {
  2265. target[i + targetStart] = this[i + start];
  2266. }
  2267. } else {
  2268. Uint8Array.prototype.set.call(
  2269. target,
  2270. this.subarray(start, start + len),
  2271. targetStart
  2272. );
  2273. }
  2274. return len
  2275. };
  2276. // Usage:
  2277. // buffer.fill(number[, offset[, end]])
  2278. // buffer.fill(buffer[, offset[, end]])
  2279. // buffer.fill(string[, offset[, end]][, encoding])
  2280. Buffer$1.prototype.fill = function fill (val, start, end, encoding) {
  2281. // Handle string cases:
  2282. if (typeof val === 'string') {
  2283. if (typeof start === 'string') {
  2284. encoding = start;
  2285. start = 0;
  2286. end = this.length;
  2287. } else if (typeof end === 'string') {
  2288. encoding = end;
  2289. end = this.length;
  2290. }
  2291. if (val.length === 1) {
  2292. var code = val.charCodeAt(0);
  2293. if (code < 256) {
  2294. val = code;
  2295. }
  2296. }
  2297. if (encoding !== undefined && typeof encoding !== 'string') {
  2298. throw new TypeError('encoding must be a string')
  2299. }
  2300. if (typeof encoding === 'string' && !Buffer$1.isEncoding(encoding)) {
  2301. throw new TypeError('Unknown encoding: ' + encoding)
  2302. }
  2303. } else if (typeof val === 'number') {
  2304. val = val & 255;
  2305. }
  2306. // Invalid ranges are not set to a default, so can range check early.
  2307. if (start < 0 || this.length < start || this.length < end) {
  2308. throw new RangeError('Out of range index')
  2309. }
  2310. if (end <= start) {
  2311. return this
  2312. }
  2313. start = start >>> 0;
  2314. end = end === undefined ? this.length : end >>> 0;
  2315. if (!val) val = 0;
  2316. var i;
  2317. if (typeof val === 'number') {
  2318. for (i = start; i < end; ++i) {
  2319. this[i] = val;
  2320. }
  2321. } else {
  2322. var bytes = internalIsBuffer(val)
  2323. ? val
  2324. : utf8ToBytes(new Buffer$1(val, encoding).toString());
  2325. var len = bytes.length;
  2326. for (i = 0; i < end - start; ++i) {
  2327. this[i + start] = bytes[i % len];
  2328. }
  2329. }
  2330. return this
  2331. };
  2332. // HELPER FUNCTIONS
  2333. // ================
  2334. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
  2335. function base64clean (str) {
  2336. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  2337. str = stringtrim(str).replace(INVALID_BASE64_RE, '');
  2338. // Node converts strings with length < 2 to ''
  2339. if (str.length < 2) return ''
  2340. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  2341. while (str.length % 4 !== 0) {
  2342. str = str + '=';
  2343. }
  2344. return str
  2345. }
  2346. function stringtrim (str) {
  2347. if (str.trim) return str.trim()
  2348. return str.replace(/^\s+|\s+$/g, '')
  2349. }
  2350. function toHex (n) {
  2351. if (n < 16) return '0' + n.toString(16)
  2352. return n.toString(16)
  2353. }
  2354. function utf8ToBytes (string, units) {
  2355. units = units || Infinity;
  2356. var codePoint;
  2357. var length = string.length;
  2358. var leadSurrogate = null;
  2359. var bytes = [];
  2360. for (var i = 0; i < length; ++i) {
  2361. codePoint = string.charCodeAt(i);
  2362. // is surrogate component
  2363. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  2364. // last char was a lead
  2365. if (!leadSurrogate) {
  2366. // no lead yet
  2367. if (codePoint > 0xDBFF) {
  2368. // unexpected trail
  2369. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  2370. continue
  2371. } else if (i + 1 === length) {
  2372. // unpaired lead
  2373. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  2374. continue
  2375. }
  2376. // valid lead
  2377. leadSurrogate = codePoint;
  2378. continue
  2379. }
  2380. // 2 leads in a row
  2381. if (codePoint < 0xDC00) {
  2382. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  2383. leadSurrogate = codePoint;
  2384. continue
  2385. }
  2386. // valid surrogate pair
  2387. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  2388. } else if (leadSurrogate) {
  2389. // valid bmp char, but last char was a lead
  2390. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  2391. }
  2392. leadSurrogate = null;
  2393. // encode utf8
  2394. if (codePoint < 0x80) {
  2395. if ((units -= 1) < 0) break
  2396. bytes.push(codePoint);
  2397. } else if (codePoint < 0x800) {
  2398. if ((units -= 2) < 0) break
  2399. bytes.push(
  2400. codePoint >> 0x6 | 0xC0,
  2401. codePoint & 0x3F | 0x80
  2402. );
  2403. } else if (codePoint < 0x10000) {
  2404. if ((units -= 3) < 0) break
  2405. bytes.push(
  2406. codePoint >> 0xC | 0xE0,
  2407. codePoint >> 0x6 & 0x3F | 0x80,
  2408. codePoint & 0x3F | 0x80
  2409. );
  2410. } else if (codePoint < 0x110000) {
  2411. if ((units -= 4) < 0) break
  2412. bytes.push(
  2413. codePoint >> 0x12 | 0xF0,
  2414. codePoint >> 0xC & 0x3F | 0x80,
  2415. codePoint >> 0x6 & 0x3F | 0x80,
  2416. codePoint & 0x3F | 0x80
  2417. );
  2418. } else {
  2419. throw new Error('Invalid code point')
  2420. }
  2421. }
  2422. return bytes
  2423. }
  2424. function asciiToBytes (str) {
  2425. var byteArray = [];
  2426. for (var i = 0; i < str.length; ++i) {
  2427. // Node's code seems to be doing this and not & 0x7F..
  2428. byteArray.push(str.charCodeAt(i) & 0xFF);
  2429. }
  2430. return byteArray
  2431. }
  2432. function utf16leToBytes (str, units) {
  2433. var c, hi, lo;
  2434. var byteArray = [];
  2435. for (var i = 0; i < str.length; ++i) {
  2436. if ((units -= 2) < 0) break
  2437. c = str.charCodeAt(i);
  2438. hi = c >> 8;
  2439. lo = c % 256;
  2440. byteArray.push(lo);
  2441. byteArray.push(hi);
  2442. }
  2443. return byteArray
  2444. }
  2445. function base64ToBytes (str) {
  2446. return toByteArray(base64clean(str))
  2447. }
  2448. function blitBuffer (src, dst, offset, length) {
  2449. for (var i = 0; i < length; ++i) {
  2450. if ((i + offset >= dst.length) || (i >= src.length)) break
  2451. dst[i + offset] = src[i];
  2452. }
  2453. return i
  2454. }
  2455. function isnan (val) {
  2456. return val !== val // eslint-disable-line no-self-compare
  2457. }
  2458. // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
  2459. // The _isBuffer check is for Safari 5-7 support, because it's missing
  2460. // Object.prototype.constructor. Remove this eventually
  2461. function isBuffer$1(obj) {
  2462. return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
  2463. }
  2464. function isFastBuffer (obj) {
  2465. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  2466. }
  2467. // For Node v0.10 support. Remove this eventually.
  2468. function isSlowBuffer (obj) {
  2469. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
  2470. }
  2471. /*
  2472. * Shared base64 decode helper for generated decode data.
  2473. * Assumes global atob is available.
  2474. */
  2475. function decodeBase64(input) {
  2476. const binary =
  2477. // eslint-disable-next-line n/no-unsupported-features/node-builtins
  2478. typeof atob === "function"
  2479. ? // Browser (and Node >=16)
  2480. // eslint-disable-next-line n/no-unsupported-features/node-builtins
  2481. atob(input)
  2482. : // Older Node versions (<16)
  2483. // eslint-disable-next-line n/no-unsupported-features/node-builtins
  2484. typeof Buffer$1.from === "function"
  2485. ? // eslint-disable-next-line n/no-unsupported-features/node-builtins
  2486. Buffer$1.from(input, "base64").toString("binary")
  2487. : // eslint-disable-next-line unicorn/no-new-buffer, n/no-deprecated-api
  2488. new Buffer$1(input, "base64").toString("binary");
  2489. const evenLength = binary.length & -2; // Round down to even length
  2490. const out = new Uint16Array(evenLength / 2);
  2491. for (let index = 0, outIndex = 0; index < evenLength; index += 2) {
  2492. const lo = binary.charCodeAt(index);
  2493. const hi = binary.charCodeAt(index + 1);
  2494. out[outIndex++] = lo | (hi << 8);
  2495. }
  2496. return out;
  2497. }
  2498. // Generated using scripts/write-decode-map.ts
  2499. const htmlDecodeTree = /* #__PURE__ */ decodeBase64("QR08ALkAAgH6AYsDNQR2BO0EPgXZBQEGLAbdBxMISQrvCmQLfQurDKQNLw4fD4YPpA+6D/IPAAAAAAAAAAAAAAAAKhBMEY8TmxUWF2EYLBkxGuAa3RsJHDscWR8YIC8jSCSIJcMl6ie3Ku8rEC0CLjoupS7kLgAIRU1hYmNmZ2xtbm9wcnN0dVQAWgBeAGUAaQBzAHcAfgCBAIQAhwCSAJoAoACsALMAbABpAGcAO4DGAMZAUAA7gCYAJkBjAHUAdABlADuAwQDBQHIiZXZlAAJhAAFpeW0AcgByAGMAO4DCAMJAEGRyAADgNdgE3XIAYQB2AGUAO4DAAMBA8CFoYZFj4SFjcgBhZAAAoFMqAAFncIsAjgBvAG4ABGFmAADgNdg43fAlbHlGdW5jdGlvbgCgYSBpAG4AZwA7gMUAxUAAAWNzpACoAHIAAOA12Jzc6SFnbgCgVCJpAGwAZABlADuAwwDDQG0AbAA7gMQAxEAABGFjZWZvcnN1xQDYANoA7QDxAPYA+QD8AAABY3LJAM8AayNzbGFzaAAAoBYidgHTANUAAKDnKmUAZAAAoAYjeQARZIABY3J0AOAA5QDrAGEidXNlAACgNSLuI291bGxpcwCgLCFhAJJjcgAA4DXYBd1wAGYAAOA12Dnd5SF2ZdhiYwDyAOoAbSJwZXEAAKBOIgAHSE9hY2RlZmhpbG9yc3UXARoBHwE6AVIBVQFiAWQBZgGCAakB6QHtAfIBYwB5ACdkUABZADuAqQCpQIABY3B5ACUBKAE1AfUhdGUGYWmg0iJ0KGFsRGlmZmVyZW50aWFsRAAAoEUhbCJleXMAAKAtIQACYWVpb0EBRAFKAU0B8iFvbgxhZABpAGwAO4DHAMdAcgBjAAhhbiJpbnQAAKAwIm8AdAAKYQABZG5ZAV0BaSJsbGEAuGB0I2VyRG90ALdg8gA5AWkAp2NyImNsZQAAAkRNUFRwAXQBeQF9AW8AdAAAoJkiaSJudXMAAKCWIuwhdXMAoJUiaSJtZXMAAKCXIm8AAAFjc4cBlAFrKndpc2VDb250b3VySW50ZWdyYWwAAKAyImUjQ3VybHkAAAFEUZwBpAFvJXVibGVRdW90ZQAAoB0gdSJvdGUAAKAZIAACbG5wdbABtgHNAdgBbwBuAGWgNyIAoHQqgAFnaXQAvAHBAcUB8iJ1ZW50AKBhIm4AdAAAoC8i7yV1ckludGVncmFsAKAuIgABZnLRAdMBAKACIe8iZHVjdACgECJuLnRlckNsb2Nrd2lzZUNvbnRvdXJJbnRlZ3JhbAAAoDMi7yFzcwCgLypjAHIAAOA12J7ccABDoNMiYQBwAACgTSKABURKU1phY2VmaW9zAAsCEgIVAhgCGwIsAjQCOQI9AnMCfwNvoEUh9CJyYWhkAKARKWMAeQACZGMAeQAFZGMAeQAPZIABZ3JzACECJQIoAuchZXIAoCEgcgAAoKEhaAB2AACg5CoAAWF5MAIzAvIhb24OYRRkbAB0oAciYQCUY3IAAOA12AfdAAFhZkECawIAAWNtRQJnAvIjaXRpY2FsAAJBREdUUAJUAl8CYwJjInV0ZQC0YG8AdAFZAloC2WJiJGxlQWN1dGUA3WJyImF2ZQBgYGkibGRlANxi7yFuZACgxCJmJWVyZW50aWFsRAAAoEYhcAR9AgAAAAAAAIECjgIAABoDZgAA4DXYO91EoagAhQKJAm8AdAAAoNwgcSJ1YWwAAKBQIuIhbGUAA0NETFJVVpkCqAK1Au8C/wIRA28AbgB0AG8AdQByAEkAbgB0AGUAZwByAGEA7ADEAW8AdAKvAgAAAACwAqhgbiNBcnJvdwAAoNMhAAFlb7kC0AJmAHQAgAFBUlQAwQLGAs0CciJyb3cAAKDQIekkZ2h0QXJyb3cAoNQhZQDlACsCbgBnAAABTFLWAugC5SFmdAABQVLcAuECciJyb3cAAKD4J+kkZ2h0QXJyb3cAoPon6SRnaHRBcnJvdwCg+SdpImdodAAAAUFU9gL7AnIicm93AACg0iFlAGUAAKCoInAAQQIGAwAAAAALA3Iicm93AACg0SFvJHduQXJyb3cAAKDVIWUlcnRpY2FsQmFyAACgJSJuAAADQUJMUlRhJAM2AzoDWgNxA3oDciJyb3cAAKGTIUJVLAMwA2EAcgAAoBMpcCNBcnJvdwAAoPUhciJldmUAEWPlIWZ00gJDAwAASwMAAFIDaSVnaHRWZWN0b3IAAKBQKWUkZVZlY3RvcgAAoF4p5SJjdG9yQqC9IWEAcgAAoFYpaSJnaHQA1AFiAwAAaQNlJGVWZWN0b3IAAKBfKeUiY3RvckKgwSFhAHIAAKBXKWUAZQBBoKQiciJyb3cAAKCnIXIAcgBvAPcAtAIAAWN0gwOHA3IAAOA12J/c8iFvaxBhAAhOVGFjZGZnbG1vcHFzdHV4owOlA6kDsAO/A8IDxgPNA9ID8gP9AwEEFAQeBCAEJQRHAEphSAA7gNAA0EBjAHUAdABlADuAyQDJQIABYWl5ALYDuQO+A/Ihb24aYXIAYwA7gMoAykAtZG8AdAAWYXIAAOA12AjdcgBhAHYAZQA7gMgAyEDlIm1lbnQAoAgiAAFhcNYD2QNjAHIAEmF0AHkAUwLhAwAAAADpA20lYWxsU3F1YXJlAACg+yVlJ3J5U21hbGxTcXVhcmUAAKCrJQABZ3D2A/kDbwBuABhhZgAA4DXYPN3zImlsb26VY3UAAAFhaQYEDgRsAFSgdSppImxkZQAAoEIi7CNpYnJpdW0AoMwhAAFjaRgEGwRyAACgMCFtAACgcyphAJdjbQBsADuAywDLQAABaXApBC0E8yF0cwCgAyLvJG5lbnRpYWxFAKBHIYACY2Zpb3MAPQQ/BEMEXQRyBHkAJGRyAADgNdgJ3WwibGVkAFMCTAQAAAAAVARtJWFsbFNxdWFyZQAAoPwlZSdyeVNtYWxsU3F1YXJlAACgqiVwA2UEAABpBAAAAABtBGYAAOA12D3dwSFsbACgACLyI2llcnRyZgCgMSFjAPIAcQQABkpUYWJjZGZnb3JzdIgEiwSOBJMElwSkBKcEqwStBLIE5QTqBGMAeQADZDuAPgA+QO0hbWFkoJMD3GNyImV2ZQAeYYABZWl5AJ0EoASjBOQhaWwiYXIAYwAcYRNkbwB0ACBhcgAA4DXYCt0AoNkicABmAADgNdg+3eUiYXRlcgADRUZHTFNUvwTIBM8E1QTZBOAEcSJ1YWwATKBlIuUhc3MAoNsidSRsbEVxdWFsAACgZyJyI2VhdGVyAACgoirlIXNzAKB3IuwkYW50RXF1YWwAoH4qaSJsZGUAAKBzImMAcgAA4DXYotwAoGsiAARBYWNmaW9zdfkE/QQFBQgFCwUTBSIFKwVSIkRjeQAqZAABY3QBBQQFZQBrAMdiXmDpIXJjJGFyAACgDCFsJWJlcnRTcGFjZQAAoAsh8AEYBQAAGwVmAACgDSHpJXpvbnRhbExpbmUAoAAlAAFjdCYFKAXyABIF8iFvayZhbQBwAEQBMQU5BW8AdwBuAEgAdQBtAPAAAAFxInVhbAAAoE8iAAdFSk9hY2RmZ21ub3N0dVMFVgVZBVwFYwVtBXAFcwV6BZAFtgXFBckFzQVjAHkAFWTsIWlnMmFjAHkAAWRjAHUAdABlADuAzQDNQAABaXlnBWwFcgBjADuAzgDOQBhkbwB0ADBhcgAAoBEhcgBhAHYAZQA7gMwAzEAAoREhYXB/BYsFAAFjZ4MFhQVyACphaSNuYXJ5SQAAoEghbABpAGUA8wD6AvQBlQUAAKUFZaAsIgABZ3KaBZ4F8iFhbACgKyLzI2VjdGlvbgCgwiJpI3NpYmxlAAABQ1SsBbEFbyJtbWEAAKBjIGkibWVzAACgYiCAAWdwdAC8Bb8FwwVvAG4ALmFmAADgNdhA3WEAmWNjAHIAAKAQIWkibGRlAChh6wHSBQAA1QVjAHkABmRsADuAzwDPQIACY2Zvc3UA4QXpBe0F8gX9BQABaXnlBegFcgBjADRhGWRyAADgNdgN3XAAZgAA4DXYQd3jAfcFAAD7BXIAAOA12KXc8iFjeQhk6yFjeQRkgANISmFjZm9zAAwGDwYSBhUGHQYhBiYGYwB5ACVkYwB5AAxk8CFwYZpjAAFleRkGHAbkIWlsNmEaZHIAAOA12A7dcABmAADgNdhC3WMAcgAA4DXYptyABUpUYWNlZmxtb3N0AD0GQAZDBl4GawZkB2gHcAd0B80H2gdjAHkACWQ7gDwAPECAAmNtbnByAEwGTwZSBlUGWwb1IXRlOWHiIWRhm2NnAACg6ifsI2FjZXRyZgCgEiFyAACgniGAAWFleQBkBmcGagbyIW9uPWHkIWlsO2EbZAABZnNvBjQHdAAABUFDREZSVFVWYXKABp4GpAbGBssG3AYDByEHwQIqBwABbnKEBowGZyVsZUJyYWNrZXQAAKDoJ/Ihb3cAoZAhQlKTBpcGYQByAACg5CHpJGdodEFycm93AKDGIWUjaWxpbmcAAKAII28A9QGqBgAAsgZiJWxlQnJhY2tldAAAoOYnbgDUAbcGAAC+BmUkZVZlY3RvcgAAoGEp5SJjdG9yQqDDIWEAcgAAoFkpbCJvb3IAAKAKI2kiZ2h0AAABQVbSBtcGciJyb3cAAKCUIeUiY3RvcgCgTikAAWVy4AbwBmUAAKGjIkFW5gbrBnIicm93AACgpCHlImN0b3IAoFopaSNhbmdsZQBCorIi+wYAAAAA/wZhAHIAAKDPKXEidWFsAACgtCJwAIABRFRWAAoHEQcYB+8kd25WZWN0b3IAoFEpZSRlVmVjdG9yAACgYCnlImN0b3JCoL8hYQByAACgWCnlImN0b3JCoLwhYQByAACgUilpAGcAaAB0AGEAcgByAG8A9wDMAnMAAANFRkdMU1Q/B0cHTgdUB1gHXwfxJXVhbEdyZWF0ZXIAoNoidSRsbEVxdWFsAACgZiJyI2VhdGVyAACgdiLlIXNzAKChKuwkYW50RXF1YWwAoH0qaSJsZGUAAKByInIAAOA12A/dZaDYIuYjdGFycm93AKDaIWkiZG90AD9hgAFucHcAege1B7kHZwAAAkxSbHKCB5QHmwerB+UhZnQAAUFSiAeNB3Iicm93AACg9SfpJGdodEFycm93AKD3J+kkZ2h0QXJyb3cAoPYn5SFmdAABYXLcAqEHaQBnAGgAdABhAHIAcgBvAPcA5wJpAGcAaAB0AGEAcgByAG8A9wDuAmYAAOA12EPdZQByAAABTFK/B8YHZSRmdEFycm93AACgmSHpJGdodEFycm93AKCYIYABY2h0ANMH1QfXB/IAWgYAoLAh8iFva0FhAKBqIgAEYWNlZmlvc3XpB+wH7gf/BwMICQgOCBEIcAAAoAUpeQAcZAABZGzyB/kHaSR1bVNwYWNlAACgXyBsI2ludHJmAACgMyFyAADgNdgQ3e4jdXNQbHVzAKATInAAZgAA4DXYRN1jAPIA/gecY4AESmFjZWZvc3R1ACEIJAgoCDUIgQiFCDsKQApHCmMAeQAKZGMidXRlAENhgAFhZXkALggxCDQI8iFvbkdh5CFpbEVhHWSAAWdzdwA7CGEIfQjhInRpdmWAAU1UVgBECEwIWQhlJWRpdW1TcGFjZQAAoAsgaABpAAABY25SCFMIawBTAHAAYQBjAOUASwhlAHIAeQBUAGgAaQDuAFQI9CFlZAABR0xnCHUIcgBlAGEAdABlAHIARwByAGUAYQB0AGUA8gDrBGUAcwBzAEwAZQBzAPMA2wdMImluZQAKYHIAAOA12BHdAAJCbnB0jAiRCJkInAhyImVhawAAoGAgwiZyZWFraW5nU3BhY2WgYGYAAKAVIUOq7CqzCMIIzQgAAOcIGwkAAAAAAAAtCQAAbwkAAIcJAACdCcAJGQoAADQKAAFvdbYIvAjuI2dydWVudACgYiJwIkNhcAAAoG0ibyh1YmxlVmVydGljYWxCYXIAAKAmIoABbHF4ANII1wjhCOUibWVudACgCSL1IWFsVKBgImkibGRlAADgQiI4A2kic3RzAACgBCJyI2VhdGVyAACjbyJFRkdMU1T1CPoIAgkJCQ0JFQlxInVhbAAAoHEidSRsbEVxdWFsAADgZyI4A3IjZWF0ZXIAAOBrIjgD5SFzcwCgeSLsJGFudEVxdWFsAOB+KjgDaSJsZGUAAKB1IvUhbXBEASAJJwnvI3duSHVtcADgTiI4A3EidWFsAADgTyI4A2UAAAFmczEJRgn0JFRyaWFuZ2xlQqLqIj0JAAAAAEIJYQByAADgzyk4A3EidWFsAACg7CJzAICibiJFR0xTVABRCVYJXAlhCWkJcSJ1YWwAAKBwInIjZWF0ZXIAAKB4IuUhc3MA4GoiOAPsJGFudEVxdWFsAOB9KjgDaSJsZGUAAKB0IuUic3RlZAABR0x1CX8J8iZlYXRlckdyZWF0ZXIA4KIqOAPlI3NzTGVzcwDgoSo4A/IjZWNlZGVzAKGAIkVTjwmVCXEidWFsAADgryo4A+wkYW50RXF1YWwAoOAiAAFlaaAJqQl2JmVyc2VFbGVtZW50AACgDCLnJWh0VHJpYW5nbGVCousitgkAAAAAuwlhAHIAAODQKTgDcSJ1YWwAAKDtIgABcXXDCeAJdSNhcmVTdQAAAWJwywnVCfMhZXRF4I8iOANxInVhbAAAoOIi5SJyc2V0ReCQIjgDcSJ1YWwAAKDjIoABYmNwAOYJ8AkNCvMhZXRF4IIi0iBxInVhbAAAoIgi4yJlZWRzgKGBIkVTVAD6CQAKBwpxInVhbAAA4LAqOAPsJGFudEVxdWFsAKDhImkibGRlAADgfyI4A+UicnNldEXggyLSIHEidWFsAACgiSJpImxkZQCAoUEiRUZUACIKJwouCnEidWFsAACgRCJ1JGxsRXF1YWwAAKBHImkibGRlAACgSSJlJXJ0aWNhbEJhcgAAoCQiYwByAADgNdip3GkAbABkAGUAO4DRANFAnWMAB0VhY2RmZ21vcHJzdHV2XgphCmgKcgp2CnoKgQqRCpYKqwqtCrsKyArNCuwhaWdSYWMAdQB0AGUAO4DTANNAAAFpeWwKcQpyAGMAO4DUANRAHmRiImxhYwBQYXIAAOA12BLdcgBhAHYAZQA7gNIA0kCAAWFlaQCHCooKjQpjAHIATGFnAGEAqWNjInJvbgCfY3AAZgAA4DXYRt3lI25DdXJseQABRFGeCqYKbyV1YmxlUXVvdGUAAKAcIHUib3RlAACgGCAAoFQqAAFjbLEKtQpyAADgNdiq3GEAcwBoADuA2ADYQGkAbAHACsUKZABlADuA1QDVQGUAcwAAoDcqbQBsADuA1gDWQGUAcgAAAUJQ0wrmCgABYXLXCtoKcgAAoD4gYQBjAAABZWvgCuIKAKDeI2UAdAAAoLQjYSVyZW50aGVzaXMAAKDcI4AEYWNmaGlsb3JzAP0KAwsFCwkLCwsMCxELIwtaC3IjdGlhbEQAAKACInkAH2RyAADgNdgT3WkApmOgY/Ujc01pbnVzsWAAAWlwFQsgC24AYwBhAHIAZQBwAGwAYQBuAOUACgVmAACgGSGAobsqZWlvACoLRQtJC+MiZWRlc4CheiJFU1QANAs5C0ALcSJ1YWwAAKCvKuwkYW50RXF1YWwAoHwiaSJsZGUAAKB+Im0AZQAAoDMgAAFkcE0LUQv1IWN0AKAPIm8jcnRpb24AYaA3ImwAAKAdIgABY2leC2ILcgAA4DXYq9yoYwACVWZvc2oLbwtzC3cLTwBUADuAIgAiQHIAAOA12BTdcABmAACgGiFjAHIAAOA12KzcAAZCRWFjZWZoaW9yc3WPC5MLlwupC7YL2AvbC90LhQyTDJoMowzhIXJyAKAQKUcAO4CuAK5AgAFjbnIAnQugC6ML9SF0ZVRhZwAAoOsncgB0oKAhbAAAoBYpgAFhZXkArwuyC7UL8iFvblhh5CFpbFZhIGR2oBwhZSJyc2UAAAFFVb8LzwsAAWxxwwvIC+UibWVudACgCyL1JGlsaWJyaXVtAKDLIXAmRXF1aWxpYnJpdW0AAKBvKXIAAKAcIW8AoWPnIWh0AARBQ0RGVFVWYewLCgwQDDIMNwxeDHwM9gIAAW5y8Av4C2clbGVCcmFja2V0AACg6SfyIW93AKGSIUJM/wsDDGEAcgAAoOUhZSRmdEFycm93AACgxCFlI2lsaW5nAACgCSNvAPUBFgwAAB4MYiVsZUJyYWNrZXQAAKDnJ24A1AEjDAAAKgxlJGVWZWN0b3IAAKBdKeUiY3RvckKgwiFhAHIAAKBVKWwib29yAACgCyMAAWVyOwxLDGUAAKGiIkFWQQxGDHIicm93AACgpiHlImN0b3IAoFspaSNhbmdsZQBCorMiVgwAAAAAWgxhAHIAAKDQKXEidWFsAACgtSJwAIABRFRWAGUMbAxzDO8kd25WZWN0b3IAoE8pZSRlVmVjdG9yAACgXCnlImN0b3JCoL4hYQByAACgVCnlImN0b3JCoMAhYQByAACgUykAAXB1iQyMDGYAAKAdIe4kZEltcGxpZXMAoHAp6SRnaHRhcnJvdwCg2yEAAWNongyhDHIAAKAbIQCgsSHsJGVEZWxheWVkAKD0KYAGSE9hY2ZoaW1vcXN0dQC/DMgMzAzQDOIM5gwKDQ0NFA0ZDU8NVA1YDQABQ2PDDMYMyCFjeSlkeQAoZEYiVGN5ACxkYyJ1dGUAWmEAorwqYWVpedgM2wzeDOEM8iFvbmBh5CFpbF5hcgBjAFxhIWRyAADgNdgW3e8hcnQAAkRMUlXvDPYM/QwEDW8kd25BcnJvdwAAoJMhZSRmdEFycm93AACgkCHpJGdodEFycm93AKCSIXAjQXJyb3cAAKCRIechbWGjY+EkbGxDaXJjbGUAoBgicABmAADgNdhK3XICHw0AAAAAIg10AACgGiLhIXJlgKGhJUlTVQAqDTINSg3uJXRlcnNlY3Rpb24AoJMidQAAAWJwNw1ADfMhZXRFoI8icSJ1YWwAAKCRIuUicnNldEWgkCJxInVhbAAAoJIibiJpb24AAKCUImMAcgAA4DXYrtxhAHIAAKDGIgACYmNtcF8Nag2ODZANc6DQImUAdABFoNAicSJ1YWwAAKCGIgABY2huDYkNZSJlZHMAgKF7IkVTVAB4DX0NhA1xInVhbAAAoLAq7CRhbnRFcXVhbACgfSJpImxkZQAAoH8iVABoAGEA9ADHCwCgESIAodEiZXOVDZ8NciJzZXQARaCDInEidWFsAACghyJlAHQAAKDRIoAFSFJTYWNmaGlvcnMAtQ27Db8NyA3ODdsN3w3+DRgOHQ4jDk8AUgBOADuA3gDeQMEhREUAoCIhAAFIY8MNxg1jAHkAC2R5ACZkAAFidcwNzQ0JYKRjgAFhZXkA1A3XDdoN8iFvbmRh5CFpbGJhImRyAADgNdgX3QABZWnjDe4N8gHoDQAA7Q3lImZvcmUAoDQiYQCYYwABY27yDfkNayNTcGFjZQAA4F8gCiDTInBhY2UAoAkg7CFkZYChPCJFRlQABw4MDhMOcSJ1YWwAAKBDInUkbGxFcXVhbAAAoEUiaSJsZGUAAKBIInAAZgAA4DXYS93pI3BsZURvdACg2yAAAWN0Jw4rDnIAAOA12K/c8iFva2Zh4QpFDlYOYA5qDgAAbg5yDgAAAAAAAAAAAAB5DnwOqA6zDgAADg8RDxYPGg8AAWNySA5ODnUAdABlADuA2gDaQHIAb6CfIeMhaXIAoEkpcgDjAVsOAABdDnkADmR2AGUAbGEAAWl5Yw5oDnIAYwA7gNsA20AjZGIibGFjAHBhcgAA4DXYGN1yAGEAdgBlADuA2QDZQOEhY3JqYQABZGl/Dp8OZQByAAABQlCFDpcOAAFhcokOiw5yAF9gYQBjAAABZWuRDpMOAKDfI2UAdAAAoLUjYSVyZW50aGVzaXMAAKDdI28AbgBQoMMi7CF1cwCgjiIAAWdwqw6uDm8AbgByYWYAAOA12EzdAARBREVUYWRwc78O0g7ZDuEOBQPqDvMOBw9yInJvdwDCoZEhyA4AAMwOYQByAACgEilvJHduQXJyb3cAAKDFIW8kd25BcnJvdwAAoJUhcSV1aWxpYnJpdW0AAKBuKWUAZQBBoKUiciJyb3cAAKClIW8AdwBuAGEAcgByAG8A9wAQA2UAcgAAAUxS+Q4AD2UkZnRBcnJvdwAAoJYh6SRnaHRBcnJvdwCglyFpAGyg0gNvAG4ApWPpIW5nbmFjAHIAAOA12LDcaSJsZGUAaGFtAGwAO4DcANxAgAREYmNkZWZvc3YALQ8xDzUPNw89D3IPdg97D4AP4SFzaACgqyJhAHIAAKDrKnkAEmThIXNobKCpIgCg5ioAAWVyQQ9DDwCgwSKAAWJ0eQBJD00Paw9hAHIAAKAWIGmgFiDjIWFsAAJCTFNUWA9cD18PZg9hAHIAAKAjIukhbmV8YGUkcGFyYXRvcgAAoFgnaSJsZGUAAKBAItQkaGluU3BhY2UAoAogcgAA4DXYGd1wAGYAAOA12E3dYwByAADgNdix3GQiYXNoAACgqiKAAmNlZm9zAI4PkQ+VD5kPng/pIXJjdGHkIWdlAKDAInIAAOA12BrdcABmAADgNdhO3WMAcgAA4DXYstwAAmZpb3OqD64Prw+0D3IAAOA12BvdnmNwAGYAAOA12E/dYwByAADgNdiz3IAEQUlVYWNmb3N1AMgPyw/OD9EP2A/gD+QP6Q/uD2MAeQAvZGMAeQAHZGMAeQAuZGMAdQB0AGUAO4DdAN1AAAFpedwP3w9yAGMAdmErZHIAAOA12BzdcABmAADgNdhQ3WMAcgAA4DXYtNxtAGwAeGEABEhhY2RlZm9z/g8BEAUQDRAQEB0QIBAkEGMAeQAWZGMidXRlAHlhAAFheQkQDBDyIW9ufWEXZG8AdAB7YfIBFRAAABwQbwBXAGkAZAB0AOgAVAhhAJZjcgAAoCghcABmAACgJCFjAHIAAOA12LXc4QtCEEkQTRAAAGcQbRByEAAAAAAAAAAAeRCKEJcQ8hD9EAAAGxEhETIROREAAD4RYwB1AHQAZQA7gOEA4UByImV2ZQADYYCiPiJFZGl1eQBWEFkQWxBgEGUQAOA+IjMDAKA/InIAYwA7gOIA4kB0AGUAO4C0ALRAMGRsAGkAZwA7gOYA5kByoGEgAOA12B7dcgBhAHYAZQA7gOAA4EAAAWVwfBCGEAABZnCAEIQQ8yF5bQCgNSHoAIMQaABhALFjAAFhcI0QWwAAAWNskRCTEHIAAWFnAACgPypkApwQAAAAALEQAKInImFkc3ajEKcQqRCuEG4AZAAAoFUqAKBcKmwib3BlAACgWCoAoFoqAKMgImVsbXJzersQvRDAEN0Q5RDtEACgpCllAACgICJzAGQAYaAhImEEzhDQENIQ1BDWENgQ2hDcEACgqCkAoKkpAKCqKQCgqykAoKwpAKCtKQCgrikAoK8pdAB2oB8iYgBkoL4iAKCdKQABcHTpEOwQaAAAoCIixWDhIXJyAKB8IwABZ3D1EPgQbwBuAAVhZgAA4DXYUt0Ao0giRWFlaW9wBxEJEQ0RDxESERQRAKBwKuMhaXIAoG8qAKBKImQAAKBLInMAJ2DyIW94ZaBIIvEADhFpAG4AZwA7gOUA5UCAAWN0eQAmESoRKxFyAADgNdi23CpgbQBwAGWgSCLxAPgBaQBsAGQAZQA7gOMA40BtAGwAO4DkAORAAAFjaUERRxFvAG4AaQBuAPQA6AFuAHQAAKARKgAITmFiY2RlZmlrbG5vcHJzdWQRaBGXEZ8RpxGrEdIR1hErEjASexKKEn0RThNbE3oTbwB0AACg7SoAAWNybBGJEWsAAAJjZXBzdBF4EX0RghHvIW5nAKBMInAjc2lsb24A9mNyImltZQAAoDUgaQBtAGWgPSJxAACgzSJ2AY0RkRFlAGUAAKC9ImUAZABnoAUjZQAAoAUjcgBrAHSgtSPiIXJrAKC2IwABb3mjEaYRbgDnAHcRMWTxIXVvAKAeIIACY21wcnQAtBG5Eb4RwRHFEeEhdXPloDUi5ABwInR5dgAAoLApcwDpAH0RbgBvAPUA6gCAAWFodwDLEcwRzhGyYwCgNiHlIWVuAKBsInIAAOA12B/dZwCAA2Nvc3R1dncA4xHyEQUSEhIhEiYSKRKAAWFpdQDpEesR7xHwAKMFcgBjAACg7yVwAACgwyKAAWRwdAD4EfwRABJvAHQAAKAAKuwhdXMAoAEqaSJtZXMAAKACKnECCxIAAAAADxLjIXVwAKAGKmEAcgAAoAUm8iNpYW5nbGUAAWR1GhIeEu8hd24AoL0lcAAAoLMlcCJsdXMAAKAEKmUA5QBCD+UAkg9hInJvdwAAoA0pgAFha28ANhJoEncSAAFjbjoSZRJrAIABbHN0AEESRxJNEm8jemVuZ2UAAKDrKXEAdQBhAHIA5QBcBPIjaWFuZ2xlgKG0JWRscgBYElwSYBLvIXduAKC+JeUhZnQAoMIlaSJnaHQAAKC4JWsAAKAjJLEBbRIAAHUSsgFxEgAAcxIAoJIlAKCRJTQAAKCTJWMAawAAoIglAAFlb38ShxJx4D0A5SD1IWl2AOBhIuUgdAAAoBAjAAJwdHd4kRKVEpsSnxJmAADgNdhT3XSgpSJvAG0AAKClIvQhaWUAoMgiAAZESFVWYmRobXB0dXayEsES0RLgEvcS+xIKExoTHxMjEygTNxMAAkxSbHK5ErsSvRK/EgCgVyUAoFQlAKBWJQCgUyUAolAlRFVkdckSyxLNEs8SAKBmJQCgaSUAoGQlAKBnJQACTFJsctgS2hLcEt4SAKBdJQCgWiUAoFwlAKBZJQCjUSVITFJobHLrEu0S7xLxEvMS9RIAoGwlAKBjJQCgYCUAoGslAKBiJQCgXyVvAHgAAKDJKQACTFJscgITBBMGEwgTAKBVJQCgUiUAoBAlAKAMJQCiACVEVWR1EhMUExYTGBMAoGUlAKBoJQCgLCUAoDQlaSJudXMAAKCfIuwhdXMAoJ4iaSJtZXMAAKCgIgACTFJsci8TMRMzEzUTAKBbJQCgWCUAoBglAKAUJQCjAiVITFJobHJCE0QTRhNIE0oTTBMAoGolAKBhJQCgXiUAoDwlAKAkJQCgHCUAAWV2UhNVE3YA5QD5AGIAYQByADuApgCmQAACY2Vpb2ITZhNqE24TcgAA4DXYt9xtAGkAAKBPIG0A5aA9IogRbAAAoVwAYmh0E3YTAKDFKfMhdWIAoMgnbAF+E4QTbABloCIgdAAAoCIgcAAAoU4iRWWJE4sTAKCuKvGgTyI8BeEMqRMAAN8TABQDFB8UAAAjFDQUAAAAAIUUAAAAAI0UAAAAANcU4xT3FPsUAACIFQAAlhWAAWNwcgCuE7ET1RP1IXRlB2GAoikiYWJjZHMAuxO/E8QTzhPSE24AZAAAoEQqciJjdXAAAKBJKgABYXXIE8sTcAAAoEsqcAAAoEcqbwB0AACgQCoA4CkiAP4AAWVv2RPcE3QAAKBBIO4ABAUAAmFlaXXlE+8T9RP4E/AB6hMAAO0TcwAAoE0qbwBuAA1hZABpAGwAO4DnAOdAcgBjAAlhcABzAHOgTCptAACgUCpvAHQAC2GAAWRtbgAIFA0UEhRpAGwAO4C4ALhAcCJ0eXYAAKCyKXQAAIGiADtlGBQZFKJAcgBkAG8A9ABiAXIAAOA12CDdgAFjZWkAKBQqFDIUeQBHZGMAawBtoBMn4SFyawCgEyfHY3IAAKPLJUVjZWZtcz8UQRRHFHcUfBSAFACgwykAocYCZWxGFEkUcQAAoFciZQBhAlAUAAAAAGAUciJyb3cAAAFsclYUWhTlIWZ0AKC6IWkiZ2h0AACguyGAAlJTYWNkAGgUaRRrFG8UcxSuYACgyCRzAHQAAKCbIukhcmMAoJoi4SFzaACgnSJuImludAAAoBAqaQBkAACg7yrjIWlyAKDCKfUhYnN1oGMmaQB0AACgYybsApMUmhS2FAAAwxRvAG4AZaA6APGgVCKrAG0CnxQAAAAAoxRhAHSgLABAYAChASJmbKcUqRTuABMNZQAAAW14rhSyFOUhbnQAoAEiZQDzANIB5wG6FAAAwBRkoEUibwB0AACgbSpuAPQAzAGAAWZyeQDIFMsUzhQA4DXYVN1vAOQA1wEAgakAO3MeAdMUcgAAoBchAAFhb9oU3hRyAHIAAKC1IXMAcwAAoBcnAAFjdeYU6hRyAADgNdi43AABYnDuFPIUZaDPKgCg0SploNAqAKDSKuQhb3QAoO8igANkZWxwcnZ3AAYVEBUbFSEVRBVlFYQV4SFycgABbHIMFQ4VAKA4KQCgNSlwAhYVAAAAABkVcgAAoN4iYwAAoN8i4SFycnCgtiEAoD0pgKIqImJjZG9zACsVMBU6FT4VQRVyImNhcAAAoEgqAAFhdTQVNxVwAACgRipwAACgSipvAHQAAKCNInIAAKBFKgDgKiIA/gACYWxydksVURVuFXMVcgByAG2gtyEAoDwpeQCAAWV2dwBYFWUVaRVxAHACXxUAAAAAYxVyAGUA4wAXFXUA4wAZFWUAZQAAoM4iZSJkZ2UAAKDPImUAbgA7gKQApEBlI2Fycm93AAABbHJ7FX8V5SFmdACgtiFpImdodAAAoLchZQDkAG0VAAFjaYsVkRVvAG4AaQBuAPQAkwFuAHQAAKAxImwiY3R5AACgLSOACUFIYWJjZGVmaGlqbG9yc3R1d3oAuBW7Fb8V1RXgFegV+RUKFhUWHxZUFlcWZRbFFtsW7xb7FgUXChdyAPIAtAJhAHIAAKBlKQACZ2xyc8YVyhXOFdAV5yFlcgCgICDlIXRoAKA4IfIA9QxoAHagECAAoKMiawHZFd4VYSJyb3cAAKAPKWEA4wBfAgABYXnkFecV8iFvbg9hNGQAoUYhYW/tFfQVAAFnciEC8RVyAACgyiF0InNlcQAAoHcqgAFnbG0A/xUCFgUWO4CwALBAdABhALRjcCJ0eXYAAKCxKQABaXIOFhIW8yFodACgfykA4DXYId1hAHIAAAFschsWHRYAoMMhAKDCIYACYWVnc3YAKBauAjYWOhY+Fm0AAKHEIm9zLhY0Fm4AZABzoMQi9SFpdACgZiZhIm1tYQDdY2kAbgAAoPIiAKH3AGlvQxZRFmQAZQAAgfcAO29KFksW90BuI3RpbWVzAACgxyJuAPgAUBZjAHkAUmRjAG8CXhYAAAAAYhZyAG4AAKAeI28AcAAAoA0jgAJscHR1dwBuFnEWdRaSFp4W7CFhciRgZgAA4DXYVd0AotkCZW1wc30WhBaJFo0WcQBkoFAibwB0AACgUSJpIm51cwAAoDgi7CF1cwCgFCLxInVhcmUAoKEiYgBsAGUAYgBhAHIAdwBlAGQAZwDlANcAbgCAAWFkaAClFqoWtBZyAHIAbwD3APUMbwB3AG4AYQByAHIAbwB3APMA8xVhI3Jwb29uAAABbHK8FsAWZQBmAPQAHBZpAGcAaAD0AB4WYgHJFs8WawBhAHIAbwD3AJILbwLUFgAAAADYFnIAbgAAoB8jbwBwAACgDCOAAWNvdADhFukW7BYAAXJ55RboFgDgNdi53FVkbAAAoPYp8iFvaxFhAAFkcvMW9xZvAHQAAKDxImkA5qC/JVsSAAFhaP8WAhdyAPIANQNhAPIA1wvhIm5nbGUAoKYpAAFjaQ4XEBd5AF9k5yJyYXJyAKD/JwAJRGFjZGVmZ2xtbm9wcXJzdHV4MRc4F0YXWxcyBF4XaRd5F40XrBe0F78X2RcVGCEYLRg1GEAYAAFEbzUXgRZvAPQA+BUAAWNzPBdCF3UAdABlADuA6QDpQPQhZXIAoG4qAAJhaW95TRdQF1YXWhfyIW9uG2FyAGOgViI7gOoA6kDsIW9uAKBVIk1kbwB0ABdhAAFEcmIXZhdvAHQAAKBSIgDgNdgi3XKhmipuF3QXYQB2AGUAO4DoAOhAZKCWKm8AdAAAoJgqgKGZKmlscwCAF4UXhxfuInRlcnMAoOcjAKATIWSglSpvAHQAAKCXKoABYXBzAJMXlheiF2MAcgATYXQAeQBzogUinxcAAAAAoRdlAHQAAKAFInAAMaADIDMBqRerFwCgBCAAoAUgAAFnc7AXsRdLYXAAAKACIAABZ3C4F7sXbwBuABlhZgAA4DXYVt2AAWFscwDFF8sXzxdyAHOg1SJsAACg4yl1AHMAAKBxKmkAAKG1A2x21RfYF28AbgC1Y/VjAAJjc3V24BfoF/0XEBgAAWlv5BdWF3IAYwAAoFYiaQLuFwAAAADwF+0ADQThIW50AAFnbPUX+Rd0AHIAAKCWKuUhc3MAoJUqgAFhZWkAAxgGGAoYbABzAD1gcwB0AACgXyJ2AESgYSJEAACgeCrwImFyc2wAoOUpAAFEYRkYHRhvAHQAAKBTInIAcgAAoHEpgAFjZGkAJxgqGO0XcgAAoC8hbwD0AIwCAAFhaDEYMhi3YzuA8ADwQAABbXI5GD0YbAA7gOsA60BvAACgrCCAAWNpcABGGEgYSxhsACFgcwD0ACwEAAFlb08YVxhjAHQAYQB0AGkAbwDuABoEbgBlAG4AdABpAGEAbADlADME4Ql1GAAAgRgAAIMYiBgAAAAAoRilGAAAqhgAALsYvhjRGAAA1xgnGWwAbABpAG4AZwBkAG8AdABzAGUA8QBlF3kARGRtImFsZQAAoEAmgAFpbHIAjRiRGJ0Y7CFpZwCgA/tpApcYAAAAAJoYZwAAoAD7aQBnAACgBPsA4DXYI93sIWlnAKAB++whaWcA4GYAagCAAWFsdACvGLIYthh0AACgbSZpAGcAAKAC+24AcwAAoLElbwBmAJJh8AHCGAAAxhhmAADgNdhX3QABYWvJGMwYbADsAGsEdqDUIgCg2SphI3J0aW50AACgDSoAAWFv2hgiGQABY3PeGB8ZsQPnGP0YBRkSGRUZAAAdGbID7xjyGPQY9xj5GAAA+xg7gL0AvUAAoFMhO4C8ALxAAKBVIQCgWSEAoFshswEBGQAAAxkAoFQhAKBWIbQCCxkOGQAAAAAQGTuAvgC+QACgVyEAoFwhNQAAoFghtgEZGQAAGxkAoFohAKBdITgAAKBeIWwAAKBEIHcAbgAAoCIjYwByAADgNdi73IAIRWFiY2RlZmdpamxub3JzdHYARhlKGVoZXhlmGWkZkhmWGZkZnRmgGa0ZxhnLGc8Z4BkjGmygZyIAoIwqgAFjbXAAUBlTGVgZ9SF0ZfVhbQBhAOSgswM6FgCghipyImV2ZQAfYQABaXliGWUZcgBjAB1hM2RvAHQAIWGAoWUibHFzAMYEcBl6GfGhZSLOBAAAdhlsAGEAbgD0AN8EgKF+KmNkbACBGYQZjBljAACgqSpvAHQAb6CAKmyggioAoIQqZeDbIgD+cwAAoJQqcgAA4DXYJN3noGsirATtIWVsAKA3IWMAeQBTZIChdyJFYWoApxmpGasZAKCSKgCgpSoAoKQqAAJFYWVztBm2Gb0ZwhkAoGkicABwoIoq8iFveACgiipxoIgq8aCIKrUZaQBtAACg5yJwAGYAAOA12FjdYQB2AOUAYwIAAWNp0xnWGXIAAKAKIW0AAKFzImVs3BneGQCgjioAoJAqAIM+ADtjZGxxco0E6xn0GfgZ/BkBGgABY2nvGfEZAKCnKnIAAKB6Km8AdAAAoNci0CFhcgCglSl1ImVzdAAAoHwqgAJhZGVscwAKGvQZFhrVBCAa8AEPGgAAFBpwAHIAbwD4AFkZcgAAoHgpcQAAAWxxxAQbGmwAZQBzAPMASRlpAO0A5AQAAWVuJxouGnIjdG5lcXEAAOBpIgD+xQAsGgAFQWFiY2Vma29zeUAaQxpmGmoabRqDGocalhrCGtMacgDyAMwCAAJpbG1yShpOGlAaVBpyAHMA8ABxD2YAvWBpAGwA9AASBQABZHJYGlsaYwB5AEpkAKGUIWN3YBpkGmkAcgAAoEgpAKCtIWEAcgAAoA8h6SFyYyVhgAFhbHIAcxp7Gn8a8iF0c3WgZSZpAHQAAKBlJuwhaXAAoCYg4yFvbgCguSJyAADgNdgl3XMAAAFld4wakRphInJvdwAAoCUpYSJyb3cAAKAmKYACYW1vcHIAnxqjGqcauhq+GnIAcgAAoP8h9CFodACgOyJrAAABbHKsGrMaZSRmdGFycm93AACgqSHpJGdodGFycm93AKCqIWYAAOA12Fnd4iFhcgCgFSCAAWNsdADIGswa0BpyAADgNdi93GEAcwDoAGka8iFvaydhAAFicNca2xr1IWxsAKBDIOghZW4AoBAg4Qr2GgAA/RoAAAgbExsaGwAAIRs7GwAAAAA+G2IbmRuVG6sbAACyG80b0htjAHUAdABlADuA7QDtQAChYyBpeQEbBhtyAGMAO4DuAO5AOGQAAWN4CxsNG3kANWRjAGwAO4ChAKFAAAFmcssCFhsA4DXYJt1yAGEAdgBlADuA7ADsQIChSCFpbm8AJxsyGzYbAAFpbisbLxtuAHQAAKAMKnQAAKAtIuYhaW4AoNwpdABhAACgKSHsIWlnM2GAAWFvcABDG1sbXhuAAWNndABJG0sbWRtyACthgAFlbHAAcQVRG1UbaQBuAOUAyAVhAHIA9AByBWgAMWFmAACgtyJlAGQAtWEAoggiY2ZvdGkbbRt1G3kb4SFyZQCgBSFpAG4AdKAeImkAZQAAoN0pZABvAPQAWxsAoisiY2VscIEbhRuPG5QbYQBsAACguiIAAWdyiRuNG2UAcgDzACMQ4wCCG2EicmhrAACgFyryIW9kAKA8KgACY2dwdJ8boRukG6gbeQBRZG8AbgAvYWYAAOA12FrdYQC5Y3UAZQBzAHQAO4C/AL9AAAFjabUbuRtyAADgNdi+3G4AAKIIIkVkc3bCG8QbyBvQAwCg+SJvAHQAAKD1Inag9CIAoPMiaaBiIOwhZGUpYesB1hsAANkbYwB5AFZkbAA7gO8A70AAA2NmbW9zdeYb7hvyG/Ub+hsFHAABaXnqG+0bcgBjADVhOWRyAADgNdgn3eEhdGg3YnAAZgAA4DXYW93jAf8bAAADHHIAAOA12L/c8iFjeVhk6yFjeVRkAARhY2ZnaGpvcxUcGhwiHCYcKhwtHDAcNRzwIXBhdqC6A/BjAAFleR4cIRzkIWlsN2E6ZHIAAOA12CjdciJlZW4AOGFjAHkARWRjAHkAXGRwAGYAAOA12FzdYwByAADgNdjA3IALQUJFSGFiY2RlZmdoamxtbm9wcnN0dXYAXhxtHHEcdRx5HN8cBx0dHTwd3B3tHfEdAR4EHh0eLB5FHrwewx7hHgkfPR9LH4ABYXJ0AGQcZxxpHHIA8gBvB/IAxQLhIWlsAKAbKeEhcnIAoA4pZ6BmIgCgiyphAHIAAKBiKWMJjRwAAJAcAACVHAAAAAAAAAAAAACZHJwcAACmHKgcrRwAANIc9SF0ZTph7SJwdHl2AKC0KXIAYQDuAFoG4iFkYbtjZwAAoegnZGyhHKMcAKCRKeUAiwYAoIUqdQBvADuAqwCrQHIAgKOQIWJmaGxwc3QAuhy/HMIcxBzHHMoczhxmoOQhcwAAoB8pcwAAoB0p6wCyGnAAAKCrIWwAAKA5KWkAbQAAoHMpbAAAoKIhAKGrKmFl1hzaHGkAbAAAoBkpc6CtKgDgrSoA/oABYWJyAOUc6RztHHIAcgAAoAwpcgBrAACgcicAAWFr8Rz4HGMAAAFla/Yc9xx7YFtgAAFlc/wc/hwAoIspbAAAAWR1Ax0FHQCgjykAoI0pAAJhZXV5Dh0RHRodHB3yIW9uPmEAAWRpFR0YHWkAbAA8YewAowbiAPccO2QAAmNxcnMkHScdLB05HWEAAKA2KXUAbwDyoBwgqhEAAWR1MB00HeghYXIAoGcpcyJoYXIAAKBLKWgAAKCyIQCiZCJmZ3FzRB1FB5Qdnh10AIACYWhscnQATh1WHWUdbB2NHXIicm93AHSgkCFhAOkAzxxhI3Jwb29uAAABZHVeHWId7yF3bgCgvSFwAACgvCHlJGZ0YXJyb3dzAKDHIWkiZ2h0AIABYWhzAHUdex2DHXIicm93APOglCGdBmEAcgBwAG8AbwBuAPMAzgtxAHUAaQBnAGEAcgByAG8A9wBlGugkcmVldGltZXMAoMsi8aFkIk0HAACaHWwAYQBuAPQAXgcAon0qY2Rnc6YdqR2xHbcdYwAAoKgqbwB0AG+gfypyoIEqAKCDKmXg2iIA/nMAAKCTKoACYWRlZ3MAwB3GHcod1h3ZHXAAcAByAG8A+ACmHG8AdAAAoNYicQAAAWdxzx3SHXQA8gBGB2cAdADyAHQcdADyAFMHaQDtAGMHgAFpbHIA4h3mHeod8yFodACgfClvAG8A8gDKBgDgNdgp3UWgdiIAoJEqYQH1Hf4dcgAAAWR1YB35HWygvCEAoGopbABrAACghCVjAHkAWWQAomoiYWNodAweDx4VHhkecgDyAGsdbwByAG4AZQDyAGAW4SFyZACgaylyAGkAAKD6JQABaW8hHiQe5CFvdEBh9SFzdGGgsCPjIWhlAKCwIwACRWFlczMeNR48HkEeAKBoInAAcKCJKvIhb3gAoIkqcaCHKvGghyo0HmkAbQAAoOYiAARhYm5vcHR3elIeXB5fHoUelh6mHqsetB4AAW5yVh5ZHmcAAKDsJ3IAAKD9IXIA6wCwBmcAgAFsbXIAZh52Hnse5SFmdAABYXKIB2weaQBnAGgAdABhAHIAcgBvAPcAkwfhInBzdG8AoPwnaQBnAGgAdABhAHIAcgBvAPcAmgdwI2Fycm93AAABbHKNHpEeZQBmAPQAxhxpImdodAAAoKwhgAFhZmwAnB6fHqIecgAAoIUpAOA12F3ddQBzAACgLSppIm1lcwAAoDQqYQGvHrMecwB0AACgFyLhAIoOZaHKJbkeRhLuIWdlAKDKJWEAcgBsoCgAdAAAoJMpgAJhY2htdADMHs8e1R7bHt0ecgDyAJ0GbwByAG4AZQDyANYWYQByAGSgyyEAoG0pAKAOIHIAaQAAoL8iAANhY2hpcXTrHu8e1QfzHv0eBh/xIXVvAKA5IHIAAOA12MHcbQDloXIi+h4AAPweAKCNKgCgjyoAAWJ19xwBH28AcqAYIACgGiDyIW9rQmEAhDwAO2NkaGlscXJCBhcfxh0gHyQfKB8sHzEfAAFjaRsfHR8AoKYqcgAAoHkqcgBlAOUAkx3tIWVzAKDJIuEhcnIAoHYpdSJlc3QAAKB7KgABUGk1HzkfYQByAACglillocMlAgdfEnIAAAFkdUIfRx9zImhhcgAAoEop6CFhcgCgZikAAWVuTx9WH3IjdG5lcXEAAOBoIgD+xQBUHwAHRGFjZGVmaGlsbm9wc3VuH3Ifoh+rH68ftx+7H74f5h/uH/MfBwj/HwsgxCFvdACgOiIAAmNscHJ5H30fiR+eH3IAO4CvAK9AAAFldIEfgx8AoEImZaAgJ3MAZQAAoCAnc6CmIXQAbwCAoaYhZGx1AJQfmB+cH28AdwDuAHkDZQBmAPQA6gbwAOkO6yFlcgCgriUAAW95ph+qH+0hbWEAoCkqPGThIXNoAKAUIOElc3VyZWRhbmdsZQCgISJyAADgNdgq3W8AAKAnIYABY2RuAMQfyR/bH3IAbwA7gLUAtUBhoiMi0B8AANMf1x9zAPQAKxFpAHIAAKDwKm8AdAA7gLcAt0B1AHMA4qESIh4TAADjH3WgOCIAoCoqYwHqH+0fcAAAoNsq8gB+GnAAbAB1APMACAgAAWRw9x/7H+UhbHMAoKciZgAA4DXYXt0AAWN0AyAHIHIAAOA12MLc8CFvcwCgPiJsobwDECAVIPQiaW1hcACguCJhAPAAEyAADEdMUlZhYmNkZWZnaGlqbG1vcHJzdHV2dzwgRyBmIG0geSCqILgg2iDeIBEhFSEyIUMhTSFQIZwhnyHSIQAiIyKLIrEivyIUIwABZ3RAIEMgAODZIjgD9uBrItIgBwmAAWVsdABNIF8gYiBmAHQAAAFhclMgWCByInJvdwAAoM0h6SRnaHRhcnJvdwCgziEA4NgiOAP24Goi0iBfCekkZ2h0YXJyb3cAoM8hAAFEZHEgdSDhIXNoAKCvIuEhc2gAoK4igAJiY25wdACCIIYgiSCNIKIgbABhAACgByL1IXRlRGFnAADgICLSIACiSSJFaW9wlSCYIJwgniAA4HAqOANkAADgSyI4A3MASWFyAG8A+AAyCnUAcgBhoG4mbADzoG4mmwjzAa8gAACzIHAAO4CgAKBAbQBwAOXgTiI4AyoJgAJhZW91eQDBIMogzSDWINkg8AHGIAAAyCAAoEMqbwBuAEhh5CFpbEZhbgBnAGSgRyJvAHQAAOBtKjgDcAAAoEIqPWThIXNoAKATIACjYCJBYWRxc3jpIO0g+SD+IAIhDCFyAHIAAKDXIXIAAAFocvIg9SBrAACgJClvoJch9wAGD28AdAAA4FAiOAN1AGkA9gC7CAABZWkGIQohYQByAACgKCntAN8I6SFzdPOgBCLlCHIAAOA12CvdAAJFZXN0/wgcISshLiHxoXEiIiEAABMJ8aFxIgAJAAAnIWwAYQBuAPQAEwlpAO0AGQlyoG8iAKBvIoABQWFwADghOyE/IXIA8gBeIHIAcgAAoK4hYQByAACg8ipzogsiSiEAAAAAxwtkoPwiAKD6ImMAeQBaZIADQUVhZGVzdABcIV8hYiFmIWkhkyGWIXIA8gBXIADgZiI4A3IAcgAAoJohcgAAoCUggKFwImZxcwBwIYQhjiF0AAABYXJ1IXohcgByAG8A9wBlIWkAZwBoAHQAYQByAHIAbwD3AD4h8aFwImAhAACKIWwAYQBuAPQAZwlz4H0qOAMAoG4iaQDtAG0JcqBuImkA5aDqIkUJaQDkADoKAAFwdKMhpyFmAADgNdhf3YCBrAA7aW4AriGvIcchrEBuAIChCSJFZHYAtyG6Ib8hAOD5IjgDbwB0AADg9SI4A+EB1gjEIcYhAKD3IgCg9iJpAHagDCLhAagJzyHRIQCg/iIAoP0igAFhb3IA2CHsIfEhcgCAoSYiYXN0AOAh5SHpIWwAbABlAOwAywhsAADg/SrlIADgAiI4A2wiaW50AACgFCrjoYAi9yEAAPohdQDlAJsJY+CvKjgDZaCAIvEAkwkAAkFhaXQHIgoiFyIeInIA8gBsIHIAcgAAoZshY3cRIhQiAOAzKTgDAOCdITgDZyRodGFycm93AACgmyFyAGkA5aDrIr4JgANjaGltcHF1AC8iPCJHIpwhTSJQIloigKGBImNlcgA2Iv0JOSJ1AOUABgoA4DXYw9zvIXJ0bQKdIQAAAABEImEAcgDhAOEhbQBloEEi8aBEIiYKYQDyAMsIcwB1AAABYnBWIlgi5QDUCeUA3wmAAWJjcABgInMieCKAoYQiRWVzAGci7glqIgDgxSo4A2UAdABl4IIi0iBxAPGgiCJoImMAZaCBIvEA/gmAoYUiRWVzAH8iFgqCIgDgxio4A2UAdABl4IMi0iBxAPGgiSKAIgACZ2lscpIilCKaIpwi7AAMCWwAZABlADuA8QDxQOcAWwlpI2FuZ2xlAAABbHKkIqoi5SFmdGWg6iLxAEUJaSJnaHQAZaDrIvEAvgltoL0DAKEjAGVzuCK8InIAbwAAoBYhcAAAoAcggARESGFkZ2lscnMAziLSItYi2iLeIugi7SICIw8j4SFzaACgrSLhIXJyAKAEKXAAAOBNItIg4SFzaACgrCIAAWV04iLlIgDgZSLSIADgPgDSIG4iZmluAACg3imAAUFldADzIvci+iJyAHIAAKACKQDgZCLSIHLgPADSIGkAZQAA4LQi0iAAAUF0BiMKI3IAcgAAoAMp8iFpZQDgtSLSIGkAbQAA4Dwi0iCAAUFhbgAaIx4jKiNyAHIAAKDWIXIAAAFociMjJiNrAACgIylvoJYh9wD/DuUhYXIAoCcpUxJqFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVCMAAF4jaSN/I4IjjSOeI8AUAAAAAKYjwCMAANoj3yMAAO8jHiQvJD8kRCQAAWNzVyNsFHUAdABlADuA8wDzQAABaXlhI2cjcgBjoJoiO4D0APRAPmSAAmFiaW9zAHEjdCN3I3EBeiNzAOgAdhTsIWFjUWF2AACgOCrvIWxkAKC8KewhaWdTYQABY3KFI4kjaQByAACgvykA4DXYLN1vA5QjAAAAAJYjAACcI24A22JhAHYAZQA7gPIA8kAAoMEpAAFibaEjjAphAHIAAKC1KQACYWNpdKwjryO6I70jcgDyAFkUAAFpcrMjtiNyAACgvinvIXNzAKC7KW4A5QDZCgCgwCmAAWFlaQDFI8gjyyNjAHIATWFnAGEAyWOAAWNkbgDRI9Qj1iPyIW9uv2MAoLYpdQDzAHgBcABmAADgNdhg3YABYWVsAOQj5yPrI3IAAKC3KXIAcAAAoLkpdQDzAHwBAKMoImFkaW9zdvkj/CMPJBMkFiQbJHIA8gBeFIChXSplZm0AAyQJJAwkcgBvoDQhZgAAoDQhO4CqAKpAO4C6ALpA5yFvZgCgtiJyAACgVipsIm9wZQAAoFcqAKBbKoABY2xvACMkJSQrJPIACCRhAHMAaAA7gPgA+EBsAACgmCJpAGwBMyQ4JGQAZQA7gPUA9UBlAHMAYaCXInMAAKA2Km0AbAA7gPYA9kDiIWFyAKA9I+EKXiQAAHokAAB8JJQkAACYJKkkAAAAALUkEQsAAPAkAAAAAAQleiUAAIMlcgCAoSUiYXN0AGUkbyQBCwCBtgA7bGokayS2QGwAZQDsABgDaQJ1JAAAAAB4JG0AAKDzKgCg/Sp5AD9kcgCAAmNpbXB0AIUkiCSLJJkSjyRuAHQAJWBvAGQALmBpAGwAAKAwIOUhbmsAoDEgcgAA4DXYLd2AAWltbwCdJKAkpCR2oMYD1WNtAGEA9AD+B24AZQAAoA4m9KHAA64kAAC0JGMjaGZvcmsAAKDUItZjAAFhdbgkxCRuAAABY2u9JMIkawBooA8hAKAOIfYAaRpzAACkKwBhYmNkZW1zdNMkIRPXJNsk4STjJOck6yTjIWlyAKAjKmkAcgAAoCIqAAFvdYsW3yQAoCUqAKByKm4AO4CxALFAaQBtAACgJip3AG8AAKAnKoABaXB1APUk+iT+JO4idGludACgFSpmAADgNdhh3W4AZAA7gKMAo0CApHoiRWFjZWlub3N1ABMlFSUYJRslTCVRJVklSSV1JQCgsypwAACgtyp1AOUAPwtjoK8qgKJ6ImFjZW5zACclLSU0JTYlSSVwAHAAcgBvAPgAFyV1AHIAbAB5AGUA8QA/C/EAOAuAAWFlcwA8JUElRSXwInByb3gAoLkqcQBxAACgtSppAG0AAKDoImkA7QBEC20AZQDzoDIgIguAAUVhcwBDJVclRSXwAEAlgAFkZnAATwtfJXElgAFhbHMAZSVpJW0l7CFhcgCgLiPpIW5lAKASI/UhcmYAoBMjdKAdIu8AWQvyIWVsAKCwIgABY2l9JYElcgAA4DXYxdzIY24iY3NwAACgCCAAA2Zpb3BzdZElKxuVJZolnyWkJXIAAOA12C7dcABmAADgNdhi3XIiaW1lAACgVyBjAHIAAOA12MbcgAFhZW8AqiW6JcAldAAAAWVpryW2JXIAbgBpAG8AbgDzABkFbgB0AACgFipzAHQAZaA/APEACRj0AG0LgApBQkhhYmNkZWZoaWxtbm9wcnN0dXgA4yXyJfYl+iVpJpAmpia9JtUm5ib4JlonaCdxJ3UnnietJ7EnyCfiJ+cngAFhcnQA6SXsJe4lcgDyAJkM8gD6AuEhaWwAoBwpYQByAPIA3BVhAHIAAKBkKYADY2RlbnFydAAGJhAmEyYYJiYmKyZaJgABZXUKJg0mAOA9IjEDdABlAFVhaQDjACAN7SJwdHl2AKCzKWcAgKHpJ2RlbAAgJiImJCYAoJIpAKClKeUA9wt1AG8AO4C7ALtAcgAApZIhYWJjZmhscHN0dz0mQCZFJkcmSiZMJk4mUSZVJlgmcAAAoHUpZqDlIXMAAKAgKQCgMylzAACgHinrALka8ACVHmwAAKBFKWkAbQAAoHQpbAAAoKMhAKCdIQABYWleJmImaQBsAACgGilvAG6gNiJhAGwA8wB2C4ABYWJyAG8mciZ2JnIA8gAvEnIAawAAoHMnAAFha3omgSZjAAABZWt/JoAmfWBdYAABZXOFJocmAKCMKWwAAAFkdYwmjiYAoI4pAKCQKQACYWV1eZcmmiajJqUm8iFvbllhAAFkaZ4moSZpAGwAV2HsAA8M4gCAJkBkAAJjbHFzrSawJrUmuiZhAACgNylkImhhcgAAoGkpdQBvAPKgHSCjAWgAAKCzIYABYWNnAMMm0iaUC2wAgKEcIWlwcwDLJs4migxuAOUAoAxhAHIA9ADaC3QAAKCtJYABaWxyANsm3ybjJvMhaHQAoH0pbwBvAPIANgwA4DXYL90AAWFv6ib1JnIAAAFkde8m8SYAoMEhbKDAIQCgbCl2oMED8WOAAWducwD+Jk4nUCdoAHQAAANhaGxyc3QKJxInISc1Jz0nRydyInJvdwB0oJIhYQDpAFYmYSNycG9vbgAAAWR1GiceJ28AdwDuAPAmcAAAoMAh5SFmdAABYWgnJy0ncgByAG8AdwDzAAkMYQByAHAAbwBvAG4A8wATBGklZ2h0YXJyb3dzAACgySFxAHUAaQBnAGEAcgByAG8A9wBZJugkcmVldGltZXMAoMwiZwDaYmkAbgBnAGQAbwB0AHMAZQDxABwYgAFhaG0AYCdjJ2YncgDyAAkMYQDyABMEAKAPIG8idXN0AGGgsSPjIWhlAKCxI+0haWQAoO4qAAJhYnB0fCeGJ4knmScAAW5ygCeDJ2cAAKDtJ3IAAKD+IXIA6wAcDIABYWZsAI8nkieVJ3IAAKCGKQDgNdhj3XUAcwAAoC4qaSJtZXMAAKA1KgABYXCiJ6gncgBnoCkAdAAAoJQp7yJsaW50AKASKmEAcgDyADwnAAJhY2hxuCe8J6EMwCfxIXVvAKA6IHIAAOA12MfcAAFidYAmxCdvAPKgGSCoAYABaGlyAM4n0ifWJ3IAZQDlAE0n7SFlcwCgyiJpAIChuSVlZmwAXAxjEt4n9CFyaQCgzinsInVoYXIAoGgpAKAeIWENBSgJKA0oSyhVKIYoAACLKLAoAAAAAOMo5ygAABApJCkxKW0pcSmHKaYpAACYKgAAAACxKmMidXRlAFthcQB1AO8ABR+ApHsiRWFjZWlucHN5ABwoHignKCooLygyKEEoRihJKACgtCrwASMoAAAlKACguCpvAG4AYWF1AOUAgw1koLAqaQBsAF9hcgBjAF1hgAFFYXMAOCg6KD0oAKC2KnAAAKC6KmkAbQAAoOki7yJsaW50AKATKmkA7QCIDUFkbwB0AGKixSKRFgAAAABTKACgZiqAA0FhY21zdHgAYChkKG8ocyh1KHkogihyAHIAAKDYIXIAAAFocmkoayjrAJAab6CYIfcAzAd0ADuApwCnQGkAO2D3IWFyAKApKW0AAAFpbn4ozQBuAHUA8wDOAHQAAKA2J3IA7+A12DDdIxkAAmFjb3mRKJUonSisKHIAcAAAoG8mAAFoeZkonChjAHkASWRIZHIAdABtAqUoAAAAAKgoaQDkAFsPYQByAGEA7ABsJDuArQCtQAABZ22zKLsobQBhAAChwwNmdroouijCY4CjPCJkZWdsbnByAMgozCjPKNMo1yjaKN4obwB0AACgairxoEMiCw5FoJ4qAKCgKkWgnSoAoJ8qZQAAoEYi7CF1cwCgJCrhIXJyAKByKWEAcgDyAPwMAAJhZWl07Sj8KAEpCCkAAWxz8Sj4KGwAcwBlAHQAbQDpAH8oaABwAACgMyrwImFyc2wAoOQpAAFkbFoPBSllAACgIyNloKoqc6CsKgDgrCoA/oABZmxwABUpGCkfKfQhY3lMZGKgLwBhoMQpcgAAoD8jZgAA4DXYZN1hAAABZHIoKRcDZQBzAHWgYCZpAHQAAKBgJoABY3N1ADYpRilhKQABYXU6KUApcABzoJMiAOCTIgD+cABzoJQiAOCUIgD+dQAAAWJwSylWKQChjyJlcz4NUCllAHQAZaCPIvEAPw0AoZAiZXNIDVspZQB0AGWgkCLxAEkNAKGhJWFmZilbBHIAZQFrKVwEAKChJWEAcgDyAAMNAAJjZW10dyl7KX8pgilyAADgNdjI3HQAbQDuAM4AaQDsAAYpYQByAOYAVw0AAWFyiimOKXIA5qAGJhESAAFhbpIpoylpImdodAAAAWVwmSmgKXAAcwBpAGwAbwDuANkXaADpAKAkcwCvYIACYmNtbnAArin8KY4NJSooKgCkgiJFZGVtbnByc7wpvinCKcgpzCnUKdgp3CkAoMUqbwB0AACgvSpkoIYibwB0AACgwyr1IWx0AKDBKgABRWXQKdIpAKDLKgCgiiLsIXVzAKC/KuEhcnIAoHkpgAFlaXUA4inxKfQpdAAAoYIiZW7oKewpcQDxoIYivSllAHEA8aCKItEpbQAAoMcqAAFicPgp+ikAoNUqAKDTKmMAgKJ7ImFjZW5zAAcqDSoUKhYqRihwAHAAcgBvAPgAIyh1AHIAbAB5AGUA8QCDDfEAfA2AAWFlcwAcKiIqPShwAHAAcgBvAPgAPChxAPEAOShnAACgaiYApoMiMTIzRWRlaGxtbnBzPCo/KkIqRSpHKlIqWCpjKmcqaypzKncqO4C5ALlAO4CyALJAO4CzALNAAKDGKgABb3NLKk4qdAAAoL4qdQBiAACg2CpkoIcibwB0AACgxCpzAAABb3VdKmAqbAAAoMknYgAAoNcq4SFycgCgeyn1IWx0AKDCKgABRWVvKnEqAKDMKgCgiyLsIXVzAKDAKoABZWl1AH0qjCqPKnQAAKGDImVugyqHKnEA8aCHIkYqZQBxAPGgiyJwKm0AAKDIKgABYnCTKpUqAKDUKgCg1iqAAUFhbgCdKqEqrCpyAHIAAKDZIXIAAAFocqYqqCrrAJUab6CZIfcAxQf3IWFyAKAqKWwAaQBnADuA3wDfQOELzyrZKtwq6SrsKvEqAAD1KjQrAAAAAAAAAAAAAEwrbCsAAHErvSsAAAAAAADRK3IC1CoAAAAA2CrnIWV0AKAWI8RjcgDrAOUKgAFhZXkA4SrkKucq8iFvbmVh5CFpbGNhQmRvAPQAIg5sInJlYwAAoBUjcgAA4DXYMd0AAmVpa2/7KhIrKCsuK/IBACsAAAkrZQAAATRm6g0EK28AcgDlAOsNYQBzorgDECsAAAAAEit5AG0A0WMAAWNuFislK2sAAAFhcxsrIStwAHAAcgBvAPgAFw5pAG0AAKA8InMA8AD9DQABYXMsKyEr8AAXDnIAbgA7gP4A/kDsATgrOyswG2QA5QBnAmUAcwCAgdcAO2JkAEMrRCtJK9dAYaCgInIAAKAxKgCgMCqAAWVwcwBRK1MraSvhAAkh4qKkIlsrXysAAAAAYytvAHQAAKA2I2kAcgAAoPEqb+A12GXdcgBrAACg2irhAHgociJpbWUAAKA0IIABYWlwAHYreSu3K2QA5QC+DYADYWRlbXBzdACFK6MrmiunK6wrsCuzK24iZ2xlAACitSVkbHFykCuUK5ornCvvIXduAKC/JeUhZnRloMMl8QACBwCgXCJpImdodABloLkl8QBdDG8AdAAAoOwlaSJudXMAAKA6KuwhdXMAoDkqYgAAoM0p6SFtZQCgOyrlInppdW0AoOIjgAFjaHQAwivKK80rAAFyecYrySsA4DXYydxGZGMAeQBbZPIhb2tnYQABaW/UK9creAD0ANERaCJlYWQAAAFsct4r5ytlAGYAdABhAHIAcgBvAPcAXQbpJGdodGFycm93AKCgIQAJQUhhYmNkZmdobG1vcHJzdHV3CiwNLBEsHSwnLDEsQCxLLFIsYix6LIQsjyzLLOgs7Sz/LAotcgDyAAkDYQByAACgYykAAWNyFSwbLHUAdABlADuA+gD6QPIACQ1yAOMBIywAACUseQBeZHYAZQBtYQABaXkrLDAscgBjADuA+wD7QENkgAFhYmgANyw6LD0scgDyANEO7CFhY3FhYQDyAOAOAAFpckQsSCzzIWh0AKB+KQDgNdgy3XIAYQB2AGUAO4D5APlAYQFWLF8scgAAAWxyWixcLACgvyEAoL4hbABrAACggCUAAWN0Zix2LG8CbCwAAAAAcyxyAG4AZaAcI3IAAKAcI28AcAAAoA8jcgBpAACg+CUAAWFsfiyBLGMAcgBrYTuAqACoQAABZ3CILIssbwBuAHNhZgAA4DXYZt0AA2FkaGxzdZksniynLLgsuyzFLHIAcgBvAPcACQ1vAHcAbgBhAHIAcgBvAPcA2A5hI3Jwb29uAAABbHKvLLMsZQBmAPQAWyxpAGcAaAD0AF0sdQDzAKYOaQAAocUDaGzBLMIs0mNvAG4AxWPwI2Fycm93cwCgyCGAAWNpdADRLOEs5CxvAtcsAAAAAN4scgBuAGWgHSNyAACgHSNvAHAAAKAOI24AZwBvYXIAaQAAoPklYwByAADgNdjK3IABZGlyAPMs9yz6LG8AdAAAoPAi7CFkZWlhaQBmoLUlAKC0JQABYW0DLQYtcgDyAMosbAA7gPwA/EDhIm5nbGUAoKcpgAdBQkRhY2RlZmxub3Byc3oAJy0qLTAtNC2bLZ0toS2/LcMtxy3TLdgt3C3gLfwtcgDyABADYQByAHag6CoAoOkqYQBzAOgA/gIAAW5yOC08LechcnQAoJwpgANla25wcnN0AJkpSC1NLVQtXi1iLYItYQBwAHAA4QAaHG8AdABoAGkAbgDnAKEXgAFoaXIAoSmzJFotbwBwAPQAdCVooJUh7wD4JgABaXVmLWotZwBtAOEAuygAAWJwbi14LXMjZXRuZXEAceCKIgD+AODLKgD+cyNldG5lcQBx4IsiAP4A4MwqAP4AAWhyhi2KLWUAdADhABIraSNhbmdsZQAAAWxyki2WLeUhZnQAoLIiaSJnaHQAAKCzInkAMmThIXNoAKCiIoABZWxyAKcttC24LWKiKCKuLQAAAACyLWEAcgAAoLsicQAAoFoi7CFpcACg7iIAAWJ0vC1eD2EA8gBfD3IAAOA12DPddAByAOkAlS1zAHUAAAFicM0t0C0A4IIi0iAA4IMi0iBwAGYAAOA12GfdcgBvAPAAWQt0AHIA6QCaLQABY3XkLegtcgAA4DXYy9wAAWJw7C30LW4AAAFFZXUt8S0A4IoiAP5uAAABRWV/LfktAOCLIgD+6SJnemFnAKCaKYADY2Vmb3BycwANLhAuJS4pLiMuLi40LukhcmN1YQABZGkULiEuAAFiZxguHC5hAHIAAKBfKmUAcaAnIgCgWSLlIXJwAKAYIXIAAOA12DTdcABmAADgNdho3WWgQCJhAHQA6ABqD2MAcgAA4DXYzNzjCuQRUC4AAFQuAABYLmIuAAAAAGMubS5wLnQuAAAAAIguki4AAJouJxIqEnQAcgDpAB0ScgAA4DXYNd0AAUFhWy5eLnIA8gDnAnIA8gCTB75jAAFBYWYuaS5yAPIA4AJyAPIAjAdhAPAAeh5pAHMAAKD7IoABZHB0APgReS6DLgABZmx9LoAuAOA12GnddQDzAP8RaQBtAOUABBIAAUFhiy6OLnIA8gDuAnIA8gCaBwABY3GVLgoScgAA4DXYzdwAAXB0nS6hLmwAdQDzACUScgDpACASAARhY2VmaW9zdbEuvC7ELsguzC7PLtQu2S5jAAABdXm2LrsudABlADuA/QD9QE9kAAFpecAuwy5yAGMAd2FLZG4AO4ClAKVAcgAA4DXYNt1jAHkAV2RwAGYAAOA12GrdYwByAADgNdjO3AABY23dLt8ueQBOZGwAO4D/AP9AAAVhY2RlZmhpb3N38y73Lv8uAi8MLxAvEy8YLx0vIi9jInV0ZQB6YQABYXn7Lv4u8iFvbn5hN2RvAHQAfGEAAWV0Bi8KL3QAcgDmAB8QYQC2Y3IAAOA12DfdYwB5ADZk5yJyYXJyAKDdIXAAZgAA4DXYa91jAHIAAOA12M/cAAFqbiYvKC8AoA0gagAAoAwg");
  2500. /**
  2501. * Bit flags & masks for the binary trie encoding used for entity decoding.
  2502. *
  2503. * Bit layout (16 bits total):
  2504. * 15..14 VALUE_LENGTH (+1 encoding; 0 => no value)
  2505. * 13 FLAG13. If valueLength>0: semicolon required flag (implicit ';').
  2506. * If valueLength==0: compact run flag.
  2507. * 12..7 BRANCH_LENGTH Branch length (0 => single branch in 6..0 if jumpOffset==char) OR run length (when compact run)
  2508. * 6..0 JUMP_TABLE Jump offset (jump table) OR single-branch char code OR first run char
  2509. */
  2510. var BinTrieFlags;
  2511. (function (BinTrieFlags) {
  2512. BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH";
  2513. BinTrieFlags[BinTrieFlags["FLAG13"] = 8192] = "FLAG13";
  2514. BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] = 8064] = "BRANCH_LENGTH";
  2515. BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE";
  2516. })(BinTrieFlags || (BinTrieFlags = {}));
  2517. var CharCodes;
  2518. (function (CharCodes) {
  2519. CharCodes[CharCodes["NUM"] = 35] = "NUM";
  2520. CharCodes[CharCodes["SEMI"] = 59] = "SEMI";
  2521. CharCodes[CharCodes["EQUALS"] = 61] = "EQUALS";
  2522. CharCodes[CharCodes["ZERO"] = 48] = "ZERO";
  2523. CharCodes[CharCodes["NINE"] = 57] = "NINE";
  2524. CharCodes[CharCodes["LOWER_A"] = 97] = "LOWER_A";
  2525. CharCodes[CharCodes["LOWER_F"] = 102] = "LOWER_F";
  2526. CharCodes[CharCodes["LOWER_X"] = 120] = "LOWER_X";
  2527. CharCodes[CharCodes["LOWER_Z"] = 122] = "LOWER_Z";
  2528. CharCodes[CharCodes["UPPER_A"] = 65] = "UPPER_A";
  2529. CharCodes[CharCodes["UPPER_F"] = 70] = "UPPER_F";
  2530. CharCodes[CharCodes["UPPER_Z"] = 90] = "UPPER_Z";
  2531. })(CharCodes || (CharCodes = {}));
  2532. /** Bit that needs to be set to convert an upper case ASCII character to lower case */
  2533. const TO_LOWER_BIT = 32;
  2534. function isNumber$1(code) {
  2535. return code >= CharCodes.ZERO && code <= CharCodes.NINE;
  2536. }
  2537. function isHexadecimalCharacter(code) {
  2538. return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F) ||
  2539. (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F));
  2540. }
  2541. function isAsciiAlphaNumeric(code) {
  2542. return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z) ||
  2543. (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z) ||
  2544. isNumber$1(code));
  2545. }
  2546. /**
  2547. * Checks if the given character is a valid end character for an entity in an attribute.
  2548. *
  2549. * Attribute values that aren't terminated properly aren't parsed, and shouldn't lead to a parser error.
  2550. * See the example in https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state
  2551. */
  2552. function isEntityInAttributeInvalidEnd(code) {
  2553. return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code);
  2554. }
  2555. var EntityDecoderState;
  2556. (function (EntityDecoderState) {
  2557. EntityDecoderState[EntityDecoderState["EntityStart"] = 0] = "EntityStart";
  2558. EntityDecoderState[EntityDecoderState["NumericStart"] = 1] = "NumericStart";
  2559. EntityDecoderState[EntityDecoderState["NumericDecimal"] = 2] = "NumericDecimal";
  2560. EntityDecoderState[EntityDecoderState["NumericHex"] = 3] = "NumericHex";
  2561. EntityDecoderState[EntityDecoderState["NamedEntity"] = 4] = "NamedEntity";
  2562. })(EntityDecoderState || (EntityDecoderState = {}));
  2563. var DecodingMode;
  2564. (function (DecodingMode) {
  2565. /** Entities in text nodes that can end with any character. */
  2566. DecodingMode[DecodingMode["Legacy"] = 0] = "Legacy";
  2567. /** Only allow entities terminated with a semicolon. */
  2568. DecodingMode[DecodingMode["Strict"] = 1] = "Strict";
  2569. /** Entities in attributes have limitations on ending characters. */
  2570. DecodingMode[DecodingMode["Attribute"] = 2] = "Attribute";
  2571. })(DecodingMode || (DecodingMode = {}));
  2572. /**
  2573. * Token decoder with support of writing partial entities.
  2574. */
  2575. class EntityDecoder {
  2576. constructor(
  2577. /** The tree used to decode entities. */
  2578. // biome-ignore lint/correctness/noUnusedPrivateClassMembers: False positive
  2579. decodeTree,
  2580. /**
  2581. * The function that is called when a codepoint is decoded.
  2582. *
  2583. * For multi-byte named entities, this will be called multiple times,
  2584. * with the second codepoint, and the same `consumed` value.
  2585. *
  2586. * @param codepoint The decoded codepoint.
  2587. * @param consumed The number of bytes consumed by the decoder.
  2588. */
  2589. emitCodePoint,
  2590. /** An object that is used to produce errors. */
  2591. errors) {
  2592. this.decodeTree = decodeTree;
  2593. this.emitCodePoint = emitCodePoint;
  2594. this.errors = errors;
  2595. /** The current state of the decoder. */
  2596. this.state = EntityDecoderState.EntityStart;
  2597. /** Characters that were consumed while parsing an entity. */
  2598. this.consumed = 1;
  2599. /**
  2600. * The result of the entity.
  2601. *
  2602. * Either the result index of a numeric entity, or the codepoint of a
  2603. * numeric entity.
  2604. */
  2605. this.result = 0;
  2606. /** The current index in the decode tree. */
  2607. this.treeIndex = 0;
  2608. /** The number of characters that were consumed in excess. */
  2609. this.excess = 1;
  2610. /** The mode in which the decoder is operating. */
  2611. this.decodeMode = DecodingMode.Strict;
  2612. }
  2613. /** Resets the instance to make it reusable. */
  2614. startEntity(decodeMode) {
  2615. this.decodeMode = decodeMode;
  2616. this.state = EntityDecoderState.EntityStart;
  2617. this.result = 0;
  2618. this.treeIndex = 0;
  2619. this.excess = 1;
  2620. this.consumed = 1;
  2621. }
  2622. /**
  2623. * Write an entity to the decoder. This can be called multiple times with partial entities.
  2624. * If the entity is incomplete, the decoder will return -1.
  2625. *
  2626. * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
  2627. * entity is incomplete, and resume when the next string is written.
  2628. *
  2629. * @param input The string containing the entity (or a continuation of the entity).
  2630. * @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
  2631. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  2632. */
  2633. write(input, offset) {
  2634. switch (this.state) {
  2635. case EntityDecoderState.EntityStart: {
  2636. if (input.charCodeAt(offset) === CharCodes.NUM) {
  2637. this.state = EntityDecoderState.NumericStart;
  2638. this.consumed += 1;
  2639. return this.stateNumericStart(input, offset + 1);
  2640. }
  2641. this.state = EntityDecoderState.NamedEntity;
  2642. return this.stateNamedEntity(input, offset);
  2643. }
  2644. case EntityDecoderState.NumericStart: {
  2645. return this.stateNumericStart(input, offset);
  2646. }
  2647. case EntityDecoderState.NumericDecimal: {
  2648. return this.stateNumericDecimal(input, offset);
  2649. }
  2650. case EntityDecoderState.NumericHex: {
  2651. return this.stateNumericHex(input, offset);
  2652. }
  2653. case EntityDecoderState.NamedEntity: {
  2654. return this.stateNamedEntity(input, offset);
  2655. }
  2656. }
  2657. }
  2658. /**
  2659. * Switches between the numeric decimal and hexadecimal states.
  2660. *
  2661. * Equivalent to the `Numeric character reference state` in the HTML spec.
  2662. *
  2663. * @param input The string containing the entity (or a continuation of the entity).
  2664. * @param offset The current offset.
  2665. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  2666. */
  2667. stateNumericStart(input, offset) {
  2668. if (offset >= input.length) {
  2669. return -1;
  2670. }
  2671. if ((input.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) {
  2672. this.state = EntityDecoderState.NumericHex;
  2673. this.consumed += 1;
  2674. return this.stateNumericHex(input, offset + 1);
  2675. }
  2676. this.state = EntityDecoderState.NumericDecimal;
  2677. return this.stateNumericDecimal(input, offset);
  2678. }
  2679. /**
  2680. * Parses a hexadecimal numeric entity.
  2681. *
  2682. * Equivalent to the `Hexademical character reference state` in the HTML spec.
  2683. *
  2684. * @param input The string containing the entity (or a continuation of the entity).
  2685. * @param offset The current offset.
  2686. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  2687. */
  2688. stateNumericHex(input, offset) {
  2689. while (offset < input.length) {
  2690. const char = input.charCodeAt(offset);
  2691. if (isNumber$1(char) || isHexadecimalCharacter(char)) {
  2692. // Convert hex digit to value (0-15); 'a'/'A' -> 10.
  2693. const digit = char <= CharCodes.NINE
  2694. ? char - CharCodes.ZERO
  2695. : (char | TO_LOWER_BIT) - CharCodes.LOWER_A + 10;
  2696. this.result = this.result * 16 + digit;
  2697. this.consumed++;
  2698. offset++;
  2699. }
  2700. else {
  2701. return this.emitNumericEntity(char, 3);
  2702. }
  2703. }
  2704. return -1; // Incomplete entity
  2705. }
  2706. /**
  2707. * Parses a decimal numeric entity.
  2708. *
  2709. * Equivalent to the `Decimal character reference state` in the HTML spec.
  2710. *
  2711. * @param input The string containing the entity (or a continuation of the entity).
  2712. * @param offset The current offset.
  2713. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  2714. */
  2715. stateNumericDecimal(input, offset) {
  2716. while (offset < input.length) {
  2717. const char = input.charCodeAt(offset);
  2718. if (isNumber$1(char)) {
  2719. this.result = this.result * 10 + (char - CharCodes.ZERO);
  2720. this.consumed++;
  2721. offset++;
  2722. }
  2723. else {
  2724. return this.emitNumericEntity(char, 2);
  2725. }
  2726. }
  2727. return -1; // Incomplete entity
  2728. }
  2729. /**
  2730. * Validate and emit a numeric entity.
  2731. *
  2732. * Implements the logic from the `Hexademical character reference start
  2733. * state` and `Numeric character reference end state` in the HTML spec.
  2734. *
  2735. * @param lastCp The last code point of the entity. Used to see if the
  2736. * entity was terminated with a semicolon.
  2737. * @param expectedLength The minimum number of characters that should be
  2738. * consumed. Used to validate that at least one digit
  2739. * was consumed.
  2740. * @returns The number of characters that were consumed.
  2741. */
  2742. emitNumericEntity(lastCp, expectedLength) {
  2743. var _a;
  2744. // Ensure we consumed at least one digit.
  2745. if (this.consumed <= expectedLength) {
  2746. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);
  2747. return 0;
  2748. }
  2749. // Figure out if this is a legit end of the entity
  2750. if (lastCp === CharCodes.SEMI) {
  2751. this.consumed += 1;
  2752. }
  2753. else if (this.decodeMode === DecodingMode.Strict) {
  2754. return 0;
  2755. }
  2756. this.emitCodePoint(replaceCodePoint(this.result), this.consumed);
  2757. if (this.errors) {
  2758. if (lastCp !== CharCodes.SEMI) {
  2759. this.errors.missingSemicolonAfterCharacterReference();
  2760. }
  2761. this.errors.validateNumericCharacterReference(this.result);
  2762. }
  2763. return this.consumed;
  2764. }
  2765. /**
  2766. * Parses a named entity.
  2767. *
  2768. * Equivalent to the `Named character reference state` in the HTML spec.
  2769. *
  2770. * @param input The string containing the entity (or a continuation of the entity).
  2771. * @param offset The current offset.
  2772. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  2773. */
  2774. stateNamedEntity(input, offset) {
  2775. const { decodeTree } = this;
  2776. let current = decodeTree[this.treeIndex];
  2777. // The length is the number of bytes of the value, including the current byte.
  2778. let valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
  2779. while (offset < input.length) {
  2780. // Handle compact runs (possibly inline): valueLength == 0 and SEMI_REQUIRED bit set.
  2781. if (valueLength === 0 && (current & BinTrieFlags.FLAG13) !== 0) {
  2782. const runLength = (current & BinTrieFlags.BRANCH_LENGTH) >> 7; /* 2..63 */
  2783. const firstChar = current & BinTrieFlags.JUMP_TABLE;
  2784. // Fast-fail if we don't have enough remaining input for the full run (incomplete entity)
  2785. if (offset + runLength > input.length)
  2786. return -1;
  2787. // Verify first char
  2788. if (input.charCodeAt(offset) !== firstChar) {
  2789. return this.result === 0
  2790. ? 0
  2791. : this.emitNotTerminatedNamedEntity();
  2792. }
  2793. offset++;
  2794. this.excess++;
  2795. // Remaining characters after the first
  2796. const remaining = runLength - 1;
  2797. // Iterate over packed 2-char words
  2798. for (let runPos = 1; runPos < runLength; runPos += 2) {
  2799. const packedWord = decodeTree[this.treeIndex + 1 + ((runPos - 1) >> 1)];
  2800. const low = packedWord & 0xff;
  2801. if (input.charCodeAt(offset) !== low) {
  2802. return this.result === 0
  2803. ? 0
  2804. : this.emitNotTerminatedNamedEntity();
  2805. }
  2806. offset++;
  2807. this.excess++;
  2808. const high = (packedWord >> 8) & 0xff;
  2809. if (runPos + 1 < runLength) {
  2810. if (input.charCodeAt(offset) !== high) {
  2811. return this.result === 0
  2812. ? 0
  2813. : this.emitNotTerminatedNamedEntity();
  2814. }
  2815. offset++;
  2816. this.excess++;
  2817. }
  2818. }
  2819. this.treeIndex += 1 + ((remaining + 1) >> 1);
  2820. current = decodeTree[this.treeIndex];
  2821. valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
  2822. }
  2823. if (offset >= input.length)
  2824. break;
  2825. const char = input.charCodeAt(offset);
  2826. /*
  2827. * Implicit semicolon handling for nodes that require a semicolon but
  2828. * don't have an explicit ';' branch stored in the trie. If we have
  2829. * a value on the current node, it requires a semicolon, and the
  2830. * current input character is a semicolon, emit the entity using the
  2831. * current node (without descending further).
  2832. */
  2833. if (char === CharCodes.SEMI &&
  2834. valueLength !== 0 &&
  2835. (current & BinTrieFlags.FLAG13) !== 0) {
  2836. return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess);
  2837. }
  2838. this.treeIndex = determineBranch(decodeTree, current, this.treeIndex + Math.max(1, valueLength), char);
  2839. if (this.treeIndex < 0) {
  2840. return this.result === 0 ||
  2841. // If we are parsing an attribute
  2842. (this.decodeMode === DecodingMode.Attribute &&
  2843. // We shouldn't have consumed any characters after the entity,
  2844. (valueLength === 0 ||
  2845. // And there should be no invalid characters.
  2846. isEntityInAttributeInvalidEnd(char)))
  2847. ? 0
  2848. : this.emitNotTerminatedNamedEntity();
  2849. }
  2850. current = decodeTree[this.treeIndex];
  2851. valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
  2852. // If the branch is a value, store it and continue
  2853. if (valueLength !== 0) {
  2854. // If the entity is terminated by a semicolon, we are done.
  2855. if (char === CharCodes.SEMI) {
  2856. return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess);
  2857. }
  2858. // If we encounter a non-terminated (legacy) entity while parsing strictly, then ignore it.
  2859. if (this.decodeMode !== DecodingMode.Strict &&
  2860. (current & BinTrieFlags.FLAG13) === 0) {
  2861. this.result = this.treeIndex;
  2862. this.consumed += this.excess;
  2863. this.excess = 0;
  2864. }
  2865. }
  2866. // Increment offset & excess for next iteration
  2867. offset++;
  2868. this.excess++;
  2869. }
  2870. return -1;
  2871. }
  2872. /**
  2873. * Emit a named entity that was not terminated with a semicolon.
  2874. *
  2875. * @returns The number of characters consumed.
  2876. */
  2877. emitNotTerminatedNamedEntity() {
  2878. var _a;
  2879. const { result, decodeTree } = this;
  2880. const valueLength = (decodeTree[result] & BinTrieFlags.VALUE_LENGTH) >> 14;
  2881. this.emitNamedEntityData(result, valueLength, this.consumed);
  2882. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.missingSemicolonAfterCharacterReference();
  2883. return this.consumed;
  2884. }
  2885. /**
  2886. * Emit a named entity.
  2887. *
  2888. * @param result The index of the entity in the decode tree.
  2889. * @param valueLength The number of bytes in the entity.
  2890. * @param consumed The number of characters consumed.
  2891. *
  2892. * @returns The number of characters consumed.
  2893. */
  2894. emitNamedEntityData(result, valueLength, consumed) {
  2895. const { decodeTree } = this;
  2896. this.emitCodePoint(valueLength === 1
  2897. ? decodeTree[result] &
  2898. ~(BinTrieFlags.VALUE_LENGTH | BinTrieFlags.FLAG13)
  2899. : decodeTree[result + 1], consumed);
  2900. if (valueLength === 3) {
  2901. // For multi-byte values, we need to emit the second byte.
  2902. this.emitCodePoint(decodeTree[result + 2], consumed);
  2903. }
  2904. return consumed;
  2905. }
  2906. /**
  2907. * Signal to the parser that the end of the input was reached.
  2908. *
  2909. * Remaining data will be emitted and relevant errors will be produced.
  2910. *
  2911. * @returns The number of characters consumed.
  2912. */
  2913. end() {
  2914. var _a;
  2915. switch (this.state) {
  2916. case EntityDecoderState.NamedEntity: {
  2917. // Emit a named entity if we have one.
  2918. return this.result !== 0 &&
  2919. (this.decodeMode !== DecodingMode.Attribute ||
  2920. this.result === this.treeIndex)
  2921. ? this.emitNotTerminatedNamedEntity()
  2922. : 0;
  2923. }
  2924. // Otherwise, emit a numeric entity if we have one.
  2925. case EntityDecoderState.NumericDecimal: {
  2926. return this.emitNumericEntity(0, 2);
  2927. }
  2928. case EntityDecoderState.NumericHex: {
  2929. return this.emitNumericEntity(0, 3);
  2930. }
  2931. case EntityDecoderState.NumericStart: {
  2932. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);
  2933. return 0;
  2934. }
  2935. case EntityDecoderState.EntityStart: {
  2936. // Return 0 if we have no entity.
  2937. return 0;
  2938. }
  2939. }
  2940. }
  2941. }
  2942. /**
  2943. * Creates a function that decodes entities in a string.
  2944. *
  2945. * @param decodeTree The decode tree.
  2946. * @returns A function that decodes entities in a string.
  2947. */
  2948. function getDecoder(decodeTree) {
  2949. let returnValue = "";
  2950. const decoder = new EntityDecoder(decodeTree, (data) => (returnValue += fromCodePoint(data)));
  2951. return function decodeWithTrie(input, decodeMode) {
  2952. let lastIndex = 0;
  2953. let offset = 0;
  2954. while ((offset = input.indexOf("&", offset)) >= 0) {
  2955. returnValue += input.slice(lastIndex, offset);
  2956. decoder.startEntity(decodeMode);
  2957. const length = decoder.write(input,
  2958. // Skip the "&"
  2959. offset + 1);
  2960. if (length < 0) {
  2961. lastIndex = offset + decoder.end();
  2962. break;
  2963. }
  2964. lastIndex = offset + length;
  2965. // If `length` is 0, skip the current `&` and continue.
  2966. offset = length === 0 ? lastIndex + 1 : lastIndex;
  2967. }
  2968. const result = returnValue + input.slice(lastIndex);
  2969. // Make sure we don't keep a reference to the final string.
  2970. returnValue = "";
  2971. return result;
  2972. };
  2973. }
  2974. /**
  2975. * Determines the branch of the current node that is taken given the current
  2976. * character. This function is used to traverse the trie.
  2977. *
  2978. * @param decodeTree The trie.
  2979. * @param current The current node.
  2980. * @param nodeIdx The index right after the current node and its value.
  2981. * @param char The current character.
  2982. * @returns The index of the next node, or -1 if no branch is taken.
  2983. */
  2984. function determineBranch(decodeTree, current, nodeIndex, char) {
  2985. const branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
  2986. const jumpOffset = current & BinTrieFlags.JUMP_TABLE;
  2987. // Case 1: Single branch encoded in jump offset
  2988. if (branchCount === 0) {
  2989. return jumpOffset !== 0 && char === jumpOffset ? nodeIndex : -1;
  2990. }
  2991. // Case 2: Multiple branches encoded in jump table
  2992. if (jumpOffset) {
  2993. const value = char - jumpOffset;
  2994. return value < 0 || value >= branchCount
  2995. ? -1
  2996. : decodeTree[nodeIndex + value] - 1;
  2997. }
  2998. // Case 3: Multiple branches encoded in packed dictionary (two keys per uint16)
  2999. const packedKeySlots = (branchCount + 1) >> 1;
  3000. /*
  3001. * Treat packed keys as a virtual sorted array of length `branchCount`.
  3002. * Key(i) = low byte for even i, high byte for odd i in slot i>>1.
  3003. */
  3004. let lo = 0;
  3005. let hi = branchCount - 1;
  3006. while (lo <= hi) {
  3007. const mid = (lo + hi) >>> 1;
  3008. const slot = mid >> 1;
  3009. const packed = decodeTree[nodeIndex + slot];
  3010. const midKey = (packed >> ((mid & 1) * 8)) & 0xff;
  3011. if (midKey < char) {
  3012. lo = mid + 1;
  3013. }
  3014. else if (midKey > char) {
  3015. hi = mid - 1;
  3016. }
  3017. else {
  3018. return decodeTree[nodeIndex + packedKeySlots + mid];
  3019. }
  3020. }
  3021. return -1;
  3022. }
  3023. const htmlDecoder = /* #__PURE__ */ getDecoder(htmlDecodeTree);
  3024. /**
  3025. * Decodes an HTML string.
  3026. *
  3027. * @param htmlString The string to decode.
  3028. * @param mode The decoding mode.
  3029. * @returns The decoded string.
  3030. */
  3031. function decodeHTML(htmlString, mode = DecodingMode.Legacy) {
  3032. return htmlDecoder(htmlString, mode);
  3033. }
  3034. const defaultDelimitersOpen = new Uint8Array([123, 123]);
  3035. const defaultDelimitersClose = new Uint8Array([125, 125]);
  3036. function isTagStartChar(c) {
  3037. return c >= 97 && c <= 122 || c >= 65 && c <= 90;
  3038. }
  3039. function isWhitespace(c) {
  3040. return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
  3041. }
  3042. function isEndOfTagSection(c) {
  3043. return c === 47 || c === 62 || isWhitespace(c);
  3044. }
  3045. function toCharCodes(str) {
  3046. const ret = new Uint8Array(str.length);
  3047. for (let i = 0; i < str.length; i++) {
  3048. ret[i] = str.charCodeAt(i);
  3049. }
  3050. return ret;
  3051. }
  3052. const Sequences = {
  3053. Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
  3054. // CDATA[
  3055. CdataEnd: new Uint8Array([93, 93, 62]),
  3056. // ]]>
  3057. CommentEnd: new Uint8Array([45, 45, 62]),
  3058. // `-->`
  3059. ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
  3060. // `<\/script`
  3061. StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
  3062. // `</style`
  3063. TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
  3064. // `</title`
  3065. TextareaEnd: new Uint8Array([
  3066. 60,
  3067. 47,
  3068. 116,
  3069. 101,
  3070. 120,
  3071. 116,
  3072. 97,
  3073. 114,
  3074. 101,
  3075. 97
  3076. ])
  3077. // `</textarea
  3078. };
  3079. class Tokenizer {
  3080. constructor(stack, cbs) {
  3081. this.stack = stack;
  3082. this.cbs = cbs;
  3083. /** The current state the tokenizer is in. */
  3084. this.state = 1;
  3085. /** The read buffer. */
  3086. this.buffer = "";
  3087. /** The beginning of the section that is currently being read. */
  3088. this.sectionStart = 0;
  3089. /** The index within the buffer that we are currently looking at. */
  3090. this.index = 0;
  3091. /** The start of the last entity. */
  3092. this.entityStart = 0;
  3093. /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
  3094. this.baseState = 1;
  3095. /** For special parsing behavior inside of script and style tags. */
  3096. this.inRCDATA = false;
  3097. /** For disabling RCDATA tags handling */
  3098. this.inXML = false;
  3099. /** For disabling interpolation parsing in v-pre */
  3100. this.inVPre = false;
  3101. /** Record newline positions for fast line / column calculation */
  3102. this.newlines = [];
  3103. this.mode = 0;
  3104. this.delimiterOpen = defaultDelimitersOpen;
  3105. this.delimiterClose = defaultDelimitersClose;
  3106. this.delimiterIndex = -1;
  3107. this.currentSequence = void 0;
  3108. this.sequenceIndex = 0;
  3109. {
  3110. this.entityDecoder = new EntityDecoder(
  3111. htmlDecodeTree,
  3112. (cp, consumed) => this.emitCodePoint(cp, consumed)
  3113. );
  3114. }
  3115. }
  3116. get inSFCRoot() {
  3117. return this.mode === 2 && this.stack.length === 0;
  3118. }
  3119. reset() {
  3120. this.state = 1;
  3121. this.mode = 0;
  3122. this.buffer = "";
  3123. this.sectionStart = 0;
  3124. this.index = 0;
  3125. this.baseState = 1;
  3126. this.inRCDATA = false;
  3127. this.currentSequence = void 0;
  3128. this.newlines.length = 0;
  3129. this.delimiterOpen = defaultDelimitersOpen;
  3130. this.delimiterClose = defaultDelimitersClose;
  3131. }
  3132. /**
  3133. * Generate Position object with line / column information using recorded
  3134. * newline positions. We know the index is always going to be an already
  3135. * processed index, so all the newlines up to this index should have been
  3136. * recorded.
  3137. */
  3138. getPos(index) {
  3139. let line = 1;
  3140. let column = index + 1;
  3141. const length = this.newlines.length;
  3142. let j = -1;
  3143. if (length > 100) {
  3144. let l = -1;
  3145. let r = length;
  3146. while (l + 1 < r) {
  3147. const m = l + r >>> 1;
  3148. this.newlines[m] < index ? l = m : r = m;
  3149. }
  3150. j = l;
  3151. } else {
  3152. for (let i = length - 1; i >= 0; i--) {
  3153. if (index > this.newlines[i]) {
  3154. j = i;
  3155. break;
  3156. }
  3157. }
  3158. }
  3159. if (j >= 0) {
  3160. line = j + 2;
  3161. column = index - this.newlines[j];
  3162. }
  3163. return {
  3164. column,
  3165. line,
  3166. offset: index
  3167. };
  3168. }
  3169. peek() {
  3170. return this.buffer.charCodeAt(this.index + 1);
  3171. }
  3172. stateText(c) {
  3173. if (c === 60) {
  3174. if (this.index > this.sectionStart) {
  3175. this.cbs.ontext(this.sectionStart, this.index);
  3176. }
  3177. this.state = 5;
  3178. this.sectionStart = this.index;
  3179. } else if (c === 38) {
  3180. this.startEntity();
  3181. } else if (!this.inVPre && c === this.delimiterOpen[0]) {
  3182. this.state = 2;
  3183. this.delimiterIndex = 0;
  3184. this.stateInterpolationOpen(c);
  3185. }
  3186. }
  3187. stateInterpolationOpen(c) {
  3188. if (c === this.delimiterOpen[this.delimiterIndex]) {
  3189. if (this.delimiterIndex === this.delimiterOpen.length - 1) {
  3190. const start = this.index + 1 - this.delimiterOpen.length;
  3191. if (start > this.sectionStart) {
  3192. this.cbs.ontext(this.sectionStart, start);
  3193. }
  3194. this.state = 3;
  3195. this.sectionStart = start;
  3196. } else {
  3197. this.delimiterIndex++;
  3198. }
  3199. } else if (this.inRCDATA) {
  3200. this.state = 32;
  3201. this.stateInRCDATA(c);
  3202. } else {
  3203. this.state = 1;
  3204. this.stateText(c);
  3205. }
  3206. }
  3207. stateInterpolation(c) {
  3208. if (c === this.delimiterClose[0]) {
  3209. this.state = 4;
  3210. this.delimiterIndex = 0;
  3211. this.stateInterpolationClose(c);
  3212. }
  3213. }
  3214. stateInterpolationClose(c) {
  3215. if (c === this.delimiterClose[this.delimiterIndex]) {
  3216. if (this.delimiterIndex === this.delimiterClose.length - 1) {
  3217. this.cbs.oninterpolation(this.sectionStart, this.index + 1);
  3218. if (this.inRCDATA) {
  3219. this.state = 32;
  3220. } else {
  3221. this.state = 1;
  3222. }
  3223. this.sectionStart = this.index + 1;
  3224. } else {
  3225. this.delimiterIndex++;
  3226. }
  3227. } else {
  3228. this.state = 3;
  3229. this.stateInterpolation(c);
  3230. }
  3231. }
  3232. stateSpecialStartSequence(c) {
  3233. const isEnd = this.sequenceIndex === this.currentSequence.length;
  3234. const isMatch = isEnd ? (
  3235. // If we are at the end of the sequence, make sure the tag name has ended
  3236. isEndOfTagSection(c)
  3237. ) : (
  3238. // Otherwise, do a case-insensitive comparison
  3239. (c | 32) === this.currentSequence[this.sequenceIndex]
  3240. );
  3241. if (!isMatch) {
  3242. this.inRCDATA = false;
  3243. } else if (!isEnd) {
  3244. this.sequenceIndex++;
  3245. return;
  3246. }
  3247. this.sequenceIndex = 0;
  3248. this.state = 6;
  3249. this.stateInTagName(c);
  3250. }
  3251. /** Look for an end tag. For <title> and <textarea>, also decode entities. */
  3252. stateInRCDATA(c) {
  3253. if (this.sequenceIndex === this.currentSequence.length) {
  3254. if (c === 62 || isWhitespace(c)) {
  3255. const endOfText = this.index - this.currentSequence.length;
  3256. if (this.sectionStart < endOfText) {
  3257. const actualIndex = this.index;
  3258. this.index = endOfText;
  3259. this.cbs.ontext(this.sectionStart, endOfText);
  3260. this.index = actualIndex;
  3261. }
  3262. this.sectionStart = endOfText + 2;
  3263. this.stateInClosingTagName(c);
  3264. this.inRCDATA = false;
  3265. return;
  3266. }
  3267. this.sequenceIndex = 0;
  3268. }
  3269. if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
  3270. this.sequenceIndex += 1;
  3271. } else if (this.sequenceIndex === 0) {
  3272. if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
  3273. if (c === 38) {
  3274. this.startEntity();
  3275. } else if (!this.inVPre && c === this.delimiterOpen[0]) {
  3276. this.state = 2;
  3277. this.delimiterIndex = 0;
  3278. this.stateInterpolationOpen(c);
  3279. }
  3280. } else if (this.fastForwardTo(60)) {
  3281. this.sequenceIndex = 1;
  3282. }
  3283. } else {
  3284. this.sequenceIndex = Number(c === 60);
  3285. }
  3286. }
  3287. stateCDATASequence(c) {
  3288. if (c === Sequences.Cdata[this.sequenceIndex]) {
  3289. if (++this.sequenceIndex === Sequences.Cdata.length) {
  3290. this.state = 28;
  3291. this.currentSequence = Sequences.CdataEnd;
  3292. this.sequenceIndex = 0;
  3293. this.sectionStart = this.index + 1;
  3294. }
  3295. } else {
  3296. this.sequenceIndex = 0;
  3297. this.state = 23;
  3298. this.stateInDeclaration(c);
  3299. }
  3300. }
  3301. /**
  3302. * When we wait for one specific character, we can speed things up
  3303. * by skipping through the buffer until we find it.
  3304. *
  3305. * @returns Whether the character was found.
  3306. */
  3307. fastForwardTo(c) {
  3308. while (++this.index < this.buffer.length) {
  3309. const cc = this.buffer.charCodeAt(this.index);
  3310. if (cc === 10) {
  3311. this.newlines.push(this.index);
  3312. }
  3313. if (cc === c) {
  3314. return true;
  3315. }
  3316. }
  3317. this.index = this.buffer.length - 1;
  3318. return false;
  3319. }
  3320. /**
  3321. * Comments and CDATA end with `-->` and `]]>`.
  3322. *
  3323. * Their common qualities are:
  3324. * - Their end sequences have a distinct character they start with.
  3325. * - That character is then repeated, so we have to check multiple repeats.
  3326. * - All characters but the start character of the sequence can be skipped.
  3327. */
  3328. stateInCommentLike(c) {
  3329. if (c === this.currentSequence[this.sequenceIndex]) {
  3330. if (++this.sequenceIndex === this.currentSequence.length) {
  3331. if (this.currentSequence === Sequences.CdataEnd) {
  3332. this.cbs.oncdata(this.sectionStart, this.index - 2);
  3333. } else {
  3334. this.cbs.oncomment(this.sectionStart, this.index - 2);
  3335. }
  3336. this.sequenceIndex = 0;
  3337. this.sectionStart = this.index + 1;
  3338. this.state = 1;
  3339. }
  3340. } else if (this.sequenceIndex === 0) {
  3341. if (this.fastForwardTo(this.currentSequence[0])) {
  3342. this.sequenceIndex = 1;
  3343. }
  3344. } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
  3345. this.sequenceIndex = 0;
  3346. }
  3347. }
  3348. startSpecial(sequence, offset) {
  3349. this.enterRCDATA(sequence, offset);
  3350. this.state = 31;
  3351. }
  3352. enterRCDATA(sequence, offset) {
  3353. this.inRCDATA = true;
  3354. this.currentSequence = sequence;
  3355. this.sequenceIndex = offset;
  3356. }
  3357. stateBeforeTagName(c) {
  3358. if (c === 33) {
  3359. this.state = 22;
  3360. this.sectionStart = this.index + 1;
  3361. } else if (c === 63) {
  3362. this.state = 24;
  3363. this.sectionStart = this.index + 1;
  3364. } else if (isTagStartChar(c)) {
  3365. this.sectionStart = this.index;
  3366. if (this.mode === 0) {
  3367. this.state = 6;
  3368. } else if (this.inSFCRoot) {
  3369. this.state = 34;
  3370. } else if (!this.inXML) {
  3371. if (c === 116) {
  3372. this.state = 30;
  3373. } else {
  3374. this.state = c === 115 ? 29 : 6;
  3375. }
  3376. } else {
  3377. this.state = 6;
  3378. }
  3379. } else if (c === 47) {
  3380. this.state = 8;
  3381. } else {
  3382. this.state = 1;
  3383. this.stateText(c);
  3384. }
  3385. }
  3386. stateInTagName(c) {
  3387. if (isEndOfTagSection(c)) {
  3388. this.handleTagName(c);
  3389. }
  3390. }
  3391. stateInSFCRootTagName(c) {
  3392. if (isEndOfTagSection(c)) {
  3393. const tag = this.buffer.slice(this.sectionStart, this.index);
  3394. if (tag !== "template") {
  3395. this.enterRCDATA(toCharCodes(`</` + tag), 0);
  3396. }
  3397. this.handleTagName(c);
  3398. }
  3399. }
  3400. handleTagName(c) {
  3401. this.cbs.onopentagname(this.sectionStart, this.index);
  3402. this.sectionStart = -1;
  3403. this.state = 11;
  3404. this.stateBeforeAttrName(c);
  3405. }
  3406. stateBeforeClosingTagName(c) {
  3407. if (isWhitespace(c)) ; else if (c === 62) {
  3408. {
  3409. this.cbs.onerr(14, this.index);
  3410. }
  3411. this.state = 1;
  3412. this.sectionStart = this.index + 1;
  3413. } else {
  3414. this.state = isTagStartChar(c) ? 9 : 27;
  3415. this.sectionStart = this.index;
  3416. }
  3417. }
  3418. stateInClosingTagName(c) {
  3419. if (c === 62 || isWhitespace(c)) {
  3420. this.cbs.onclosetag(this.sectionStart, this.index);
  3421. this.sectionStart = -1;
  3422. this.state = 10;
  3423. this.stateAfterClosingTagName(c);
  3424. }
  3425. }
  3426. stateAfterClosingTagName(c) {
  3427. if (c === 62) {
  3428. this.state = 1;
  3429. this.sectionStart = this.index + 1;
  3430. }
  3431. }
  3432. stateBeforeAttrName(c) {
  3433. if (c === 62) {
  3434. this.cbs.onopentagend(this.index);
  3435. if (this.inRCDATA) {
  3436. this.state = 32;
  3437. } else {
  3438. this.state = 1;
  3439. }
  3440. this.sectionStart = this.index + 1;
  3441. } else if (c === 47) {
  3442. this.state = 7;
  3443. if (this.peek() !== 62) {
  3444. this.cbs.onerr(22, this.index);
  3445. }
  3446. } else if (c === 60 && this.peek() === 47) {
  3447. this.cbs.onopentagend(this.index);
  3448. this.state = 5;
  3449. this.sectionStart = this.index;
  3450. } else if (!isWhitespace(c)) {
  3451. if (c === 61) {
  3452. this.cbs.onerr(
  3453. 19,
  3454. this.index
  3455. );
  3456. }
  3457. this.handleAttrStart(c);
  3458. }
  3459. }
  3460. handleAttrStart(c) {
  3461. if (c === 118 && this.peek() === 45) {
  3462. this.state = 13;
  3463. this.sectionStart = this.index;
  3464. } else if (c === 46 || c === 58 || c === 64 || c === 35) {
  3465. this.cbs.ondirname(this.index, this.index + 1);
  3466. this.state = 14;
  3467. this.sectionStart = this.index + 1;
  3468. } else {
  3469. this.state = 12;
  3470. this.sectionStart = this.index;
  3471. }
  3472. }
  3473. stateInSelfClosingTag(c) {
  3474. if (c === 62) {
  3475. this.cbs.onselfclosingtag(this.index);
  3476. this.state = 1;
  3477. this.sectionStart = this.index + 1;
  3478. this.inRCDATA = false;
  3479. } else if (!isWhitespace(c)) {
  3480. this.state = 11;
  3481. this.stateBeforeAttrName(c);
  3482. }
  3483. }
  3484. stateInAttrName(c) {
  3485. if (c === 61 || isEndOfTagSection(c)) {
  3486. this.cbs.onattribname(this.sectionStart, this.index);
  3487. this.handleAttrNameEnd(c);
  3488. } else if (c === 34 || c === 39 || c === 60) {
  3489. this.cbs.onerr(
  3490. 17,
  3491. this.index
  3492. );
  3493. }
  3494. }
  3495. stateInDirName(c) {
  3496. if (c === 61 || isEndOfTagSection(c)) {
  3497. this.cbs.ondirname(this.sectionStart, this.index);
  3498. this.handleAttrNameEnd(c);
  3499. } else if (c === 58) {
  3500. this.cbs.ondirname(this.sectionStart, this.index);
  3501. this.state = 14;
  3502. this.sectionStart = this.index + 1;
  3503. } else if (c === 46) {
  3504. this.cbs.ondirname(this.sectionStart, this.index);
  3505. this.state = 16;
  3506. this.sectionStart = this.index + 1;
  3507. }
  3508. }
  3509. stateInDirArg(c) {
  3510. if (c === 61 || isEndOfTagSection(c)) {
  3511. this.cbs.ondirarg(this.sectionStart, this.index);
  3512. this.handleAttrNameEnd(c);
  3513. } else if (c === 91) {
  3514. this.state = 15;
  3515. } else if (c === 46) {
  3516. this.cbs.ondirarg(this.sectionStart, this.index);
  3517. this.state = 16;
  3518. this.sectionStart = this.index + 1;
  3519. }
  3520. }
  3521. stateInDynamicDirArg(c) {
  3522. if (c === 93) {
  3523. this.state = 14;
  3524. } else if (c === 61 || isEndOfTagSection(c)) {
  3525. this.cbs.ondirarg(this.sectionStart, this.index + 1);
  3526. this.handleAttrNameEnd(c);
  3527. {
  3528. this.cbs.onerr(
  3529. 27,
  3530. this.index
  3531. );
  3532. }
  3533. }
  3534. }
  3535. stateInDirModifier(c) {
  3536. if (c === 61 || isEndOfTagSection(c)) {
  3537. this.cbs.ondirmodifier(this.sectionStart, this.index);
  3538. this.handleAttrNameEnd(c);
  3539. } else if (c === 46) {
  3540. this.cbs.ondirmodifier(this.sectionStart, this.index);
  3541. this.sectionStart = this.index + 1;
  3542. }
  3543. }
  3544. handleAttrNameEnd(c) {
  3545. this.sectionStart = this.index;
  3546. this.state = 17;
  3547. this.cbs.onattribnameend(this.index);
  3548. this.stateAfterAttrName(c);
  3549. }
  3550. stateAfterAttrName(c) {
  3551. if (c === 61) {
  3552. this.state = 18;
  3553. } else if (c === 47 || c === 62) {
  3554. this.cbs.onattribend(0, this.sectionStart);
  3555. this.sectionStart = -1;
  3556. this.state = 11;
  3557. this.stateBeforeAttrName(c);
  3558. } else if (!isWhitespace(c)) {
  3559. this.cbs.onattribend(0, this.sectionStart);
  3560. this.handleAttrStart(c);
  3561. }
  3562. }
  3563. stateBeforeAttrValue(c) {
  3564. if (c === 34) {
  3565. this.state = 19;
  3566. this.sectionStart = this.index + 1;
  3567. } else if (c === 39) {
  3568. this.state = 20;
  3569. this.sectionStart = this.index + 1;
  3570. } else if (!isWhitespace(c)) {
  3571. this.sectionStart = this.index;
  3572. this.state = 21;
  3573. this.stateInAttrValueNoQuotes(c);
  3574. }
  3575. }
  3576. handleInAttrValue(c, quote) {
  3577. if (c === quote || false) {
  3578. this.cbs.onattribdata(this.sectionStart, this.index);
  3579. this.sectionStart = -1;
  3580. this.cbs.onattribend(
  3581. quote === 34 ? 3 : 2,
  3582. this.index + 1
  3583. );
  3584. this.state = 11;
  3585. } else if (c === 38) {
  3586. this.startEntity();
  3587. }
  3588. }
  3589. stateInAttrValueDoubleQuotes(c) {
  3590. this.handleInAttrValue(c, 34);
  3591. }
  3592. stateInAttrValueSingleQuotes(c) {
  3593. this.handleInAttrValue(c, 39);
  3594. }
  3595. stateInAttrValueNoQuotes(c) {
  3596. if (isWhitespace(c) || c === 62) {
  3597. this.cbs.onattribdata(this.sectionStart, this.index);
  3598. this.sectionStart = -1;
  3599. this.cbs.onattribend(1, this.index);
  3600. this.state = 11;
  3601. this.stateBeforeAttrName(c);
  3602. } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
  3603. this.cbs.onerr(
  3604. 18,
  3605. this.index
  3606. );
  3607. } else if (c === 38) {
  3608. this.startEntity();
  3609. }
  3610. }
  3611. stateBeforeDeclaration(c) {
  3612. if (c === 91) {
  3613. this.state = 26;
  3614. this.sequenceIndex = 0;
  3615. } else {
  3616. this.state = c === 45 ? 25 : 23;
  3617. }
  3618. }
  3619. stateInDeclaration(c) {
  3620. if (c === 62 || this.fastForwardTo(62)) {
  3621. this.state = 1;
  3622. this.sectionStart = this.index + 1;
  3623. }
  3624. }
  3625. stateInProcessingInstruction(c) {
  3626. if (c === 62 || this.fastForwardTo(62)) {
  3627. this.cbs.onprocessinginstruction(this.sectionStart, this.index);
  3628. this.state = 1;
  3629. this.sectionStart = this.index + 1;
  3630. }
  3631. }
  3632. stateBeforeComment(c) {
  3633. if (c === 45) {
  3634. this.state = 28;
  3635. this.currentSequence = Sequences.CommentEnd;
  3636. this.sequenceIndex = 2;
  3637. this.sectionStart = this.index + 1;
  3638. } else {
  3639. this.state = 23;
  3640. }
  3641. }
  3642. stateInSpecialComment(c) {
  3643. if (c === 62 || this.fastForwardTo(62)) {
  3644. this.cbs.oncomment(this.sectionStart, this.index);
  3645. this.state = 1;
  3646. this.sectionStart = this.index + 1;
  3647. }
  3648. }
  3649. stateBeforeSpecialS(c) {
  3650. if (c === Sequences.ScriptEnd[3]) {
  3651. this.startSpecial(Sequences.ScriptEnd, 4);
  3652. } else if (c === Sequences.StyleEnd[3]) {
  3653. this.startSpecial(Sequences.StyleEnd, 4);
  3654. } else {
  3655. this.state = 6;
  3656. this.stateInTagName(c);
  3657. }
  3658. }
  3659. stateBeforeSpecialT(c) {
  3660. if (c === Sequences.TitleEnd[3]) {
  3661. this.startSpecial(Sequences.TitleEnd, 4);
  3662. } else if (c === Sequences.TextareaEnd[3]) {
  3663. this.startSpecial(Sequences.TextareaEnd, 4);
  3664. } else {
  3665. this.state = 6;
  3666. this.stateInTagName(c);
  3667. }
  3668. }
  3669. startEntity() {
  3670. {
  3671. this.baseState = this.state;
  3672. this.state = 33;
  3673. this.entityStart = this.index;
  3674. this.entityDecoder.startEntity(
  3675. this.baseState === 1 || this.baseState === 32 ? DecodingMode.Legacy : DecodingMode.Attribute
  3676. );
  3677. }
  3678. }
  3679. stateInEntity() {
  3680. {
  3681. const length = this.entityDecoder.write(this.buffer, this.index);
  3682. if (length >= 0) {
  3683. this.state = this.baseState;
  3684. if (length === 0) {
  3685. this.index = this.entityStart;
  3686. }
  3687. } else {
  3688. this.index = this.buffer.length - 1;
  3689. }
  3690. }
  3691. }
  3692. /**
  3693. * Iterates through the buffer, calling the function corresponding to the current state.
  3694. *
  3695. * States that are more likely to be hit are higher up, as a performance improvement.
  3696. */
  3697. parse(input) {
  3698. this.buffer = input;
  3699. while (this.index < this.buffer.length) {
  3700. const c = this.buffer.charCodeAt(this.index);
  3701. if (c === 10 && this.state !== 33) {
  3702. this.newlines.push(this.index);
  3703. }
  3704. switch (this.state) {
  3705. case 1: {
  3706. this.stateText(c);
  3707. break;
  3708. }
  3709. case 2: {
  3710. this.stateInterpolationOpen(c);
  3711. break;
  3712. }
  3713. case 3: {
  3714. this.stateInterpolation(c);
  3715. break;
  3716. }
  3717. case 4: {
  3718. this.stateInterpolationClose(c);
  3719. break;
  3720. }
  3721. case 31: {
  3722. this.stateSpecialStartSequence(c);
  3723. break;
  3724. }
  3725. case 32: {
  3726. this.stateInRCDATA(c);
  3727. break;
  3728. }
  3729. case 26: {
  3730. this.stateCDATASequence(c);
  3731. break;
  3732. }
  3733. case 19: {
  3734. this.stateInAttrValueDoubleQuotes(c);
  3735. break;
  3736. }
  3737. case 12: {
  3738. this.stateInAttrName(c);
  3739. break;
  3740. }
  3741. case 13: {
  3742. this.stateInDirName(c);
  3743. break;
  3744. }
  3745. case 14: {
  3746. this.stateInDirArg(c);
  3747. break;
  3748. }
  3749. case 15: {
  3750. this.stateInDynamicDirArg(c);
  3751. break;
  3752. }
  3753. case 16: {
  3754. this.stateInDirModifier(c);
  3755. break;
  3756. }
  3757. case 28: {
  3758. this.stateInCommentLike(c);
  3759. break;
  3760. }
  3761. case 27: {
  3762. this.stateInSpecialComment(c);
  3763. break;
  3764. }
  3765. case 11: {
  3766. this.stateBeforeAttrName(c);
  3767. break;
  3768. }
  3769. case 6: {
  3770. this.stateInTagName(c);
  3771. break;
  3772. }
  3773. case 34: {
  3774. this.stateInSFCRootTagName(c);
  3775. break;
  3776. }
  3777. case 9: {
  3778. this.stateInClosingTagName(c);
  3779. break;
  3780. }
  3781. case 5: {
  3782. this.stateBeforeTagName(c);
  3783. break;
  3784. }
  3785. case 17: {
  3786. this.stateAfterAttrName(c);
  3787. break;
  3788. }
  3789. case 20: {
  3790. this.stateInAttrValueSingleQuotes(c);
  3791. break;
  3792. }
  3793. case 18: {
  3794. this.stateBeforeAttrValue(c);
  3795. break;
  3796. }
  3797. case 8: {
  3798. this.stateBeforeClosingTagName(c);
  3799. break;
  3800. }
  3801. case 10: {
  3802. this.stateAfterClosingTagName(c);
  3803. break;
  3804. }
  3805. case 29: {
  3806. this.stateBeforeSpecialS(c);
  3807. break;
  3808. }
  3809. case 30: {
  3810. this.stateBeforeSpecialT(c);
  3811. break;
  3812. }
  3813. case 21: {
  3814. this.stateInAttrValueNoQuotes(c);
  3815. break;
  3816. }
  3817. case 7: {
  3818. this.stateInSelfClosingTag(c);
  3819. break;
  3820. }
  3821. case 23: {
  3822. this.stateInDeclaration(c);
  3823. break;
  3824. }
  3825. case 22: {
  3826. this.stateBeforeDeclaration(c);
  3827. break;
  3828. }
  3829. case 25: {
  3830. this.stateBeforeComment(c);
  3831. break;
  3832. }
  3833. case 24: {
  3834. this.stateInProcessingInstruction(c);
  3835. break;
  3836. }
  3837. case 33: {
  3838. this.stateInEntity();
  3839. break;
  3840. }
  3841. }
  3842. this.index++;
  3843. }
  3844. this.cleanup();
  3845. this.finish();
  3846. }
  3847. /**
  3848. * Remove data that has already been consumed from the buffer.
  3849. */
  3850. cleanup() {
  3851. if (this.sectionStart !== this.index) {
  3852. if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
  3853. this.cbs.ontext(this.sectionStart, this.index);
  3854. this.sectionStart = this.index;
  3855. } else if (this.state === 19 || this.state === 20 || this.state === 21) {
  3856. this.cbs.onattribdata(this.sectionStart, this.index);
  3857. this.sectionStart = this.index;
  3858. }
  3859. }
  3860. }
  3861. finish() {
  3862. if (this.state === 33) {
  3863. this.entityDecoder.end();
  3864. this.state = this.baseState;
  3865. }
  3866. this.handleTrailingData();
  3867. this.cbs.onend();
  3868. }
  3869. /** Handle any trailing data. */
  3870. handleTrailingData() {
  3871. const endIndex = this.buffer.length;
  3872. if (this.sectionStart >= endIndex) {
  3873. return;
  3874. }
  3875. if (this.state === 28) {
  3876. if (this.currentSequence === Sequences.CdataEnd) {
  3877. this.cbs.oncdata(this.sectionStart, endIndex);
  3878. } else {
  3879. this.cbs.oncomment(this.sectionStart, endIndex);
  3880. }
  3881. } else if (this.state === 6 || this.state === 11 || this.state === 18 || this.state === 17 || this.state === 12 || this.state === 13 || this.state === 14 || this.state === 15 || this.state === 16 || this.state === 20 || this.state === 19 || this.state === 21 || this.state === 9) ; else {
  3882. this.cbs.ontext(this.sectionStart, endIndex);
  3883. }
  3884. }
  3885. emitCodePoint(cp, consumed) {
  3886. {
  3887. if (this.baseState !== 1 && this.baseState !== 32) {
  3888. if (this.sectionStart < this.entityStart) {
  3889. this.cbs.onattribdata(this.sectionStart, this.entityStart);
  3890. }
  3891. this.sectionStart = this.entityStart + consumed;
  3892. this.index = this.sectionStart - 1;
  3893. this.cbs.onattribentity(
  3894. fromCodePoint(cp),
  3895. this.entityStart,
  3896. this.sectionStart
  3897. );
  3898. } else {
  3899. if (this.sectionStart < this.entityStart) {
  3900. this.cbs.ontext(this.sectionStart, this.entityStart);
  3901. }
  3902. this.sectionStart = this.entityStart + consumed;
  3903. this.index = this.sectionStart - 1;
  3904. this.cbs.ontextentity(
  3905. fromCodePoint(cp),
  3906. this.entityStart,
  3907. this.sectionStart
  3908. );
  3909. }
  3910. }
  3911. }
  3912. }
  3913. const CompilerDeprecationTypes = {
  3914. "COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT",
  3915. "COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC",
  3916. "COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER",
  3917. "COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE",
  3918. "COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE",
  3919. "COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE",
  3920. "COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE",
  3921. "COMPILER_FILTERS": "COMPILER_FILTERS"
  3922. };
  3923. const deprecationData = {
  3924. ["COMPILER_IS_ON_ELEMENT"]: {
  3925. 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:".`,
  3926. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  3927. },
  3928. ["COMPILER_V_BIND_SYNC"]: {
  3929. 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}\`.`,
  3930. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  3931. },
  3932. ["COMPILER_V_BIND_OBJECT_ORDER"]: {
  3933. 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.`,
  3934. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  3935. },
  3936. ["COMPILER_V_ON_NATIVE"]: {
  3937. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  3938. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  3939. },
  3940. ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
  3941. 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.`,
  3942. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  3943. },
  3944. ["COMPILER_NATIVE_TEMPLATE"]: {
  3945. message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
  3946. },
  3947. ["COMPILER_INLINE_TEMPLATE"]: {
  3948. message: `"inline-template" has been removed in Vue 3.`,
  3949. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  3950. },
  3951. ["COMPILER_FILTERS"]: {
  3952. 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.`,
  3953. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  3954. }
  3955. };
  3956. function getCompatValue(key, { compatConfig }) {
  3957. const value = compatConfig && compatConfig[key];
  3958. if (key === "MODE") {
  3959. return value || 3;
  3960. } else {
  3961. return value;
  3962. }
  3963. }
  3964. function isCompatEnabled(key, context) {
  3965. const mode = getCompatValue("MODE", context);
  3966. const value = getCompatValue(key, context);
  3967. return mode === 3 ? value === true : value !== false;
  3968. }
  3969. function checkCompatEnabled(key, context, loc, ...args) {
  3970. const enabled = isCompatEnabled(key, context);
  3971. if (enabled) {
  3972. warnDeprecation(key, context, loc, ...args);
  3973. }
  3974. return enabled;
  3975. }
  3976. function warnDeprecation(key, context, loc, ...args) {
  3977. const val = getCompatValue(key, context);
  3978. if (val === "suppress-warning") {
  3979. return;
  3980. }
  3981. const { message, link } = deprecationData[key];
  3982. const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
  3983. Details: ${link}` : ``}`;
  3984. const err = new SyntaxError(msg);
  3985. err.code = key;
  3986. if (loc) err.loc = loc;
  3987. context.onWarn(err);
  3988. }
  3989. function defaultOnError(error) {
  3990. throw error;
  3991. }
  3992. function defaultOnWarn(msg) {
  3993. console.warn(`[Vue warn] ${msg.message}`);
  3994. }
  3995. function createCompilerError(code, loc, messages, additionalMessage) {
  3996. const msg = (messages || errorMessages$1)[code] + (additionalMessage || ``) ;
  3997. const error = new SyntaxError(String(msg));
  3998. error.code = code;
  3999. error.loc = loc;
  4000. return error;
  4001. }
  4002. const ErrorCodes = {
  4003. "ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
  4004. "0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
  4005. "CDATA_IN_HTML_CONTENT": 1,
  4006. "1": "CDATA_IN_HTML_CONTENT",
  4007. "DUPLICATE_ATTRIBUTE": 2,
  4008. "2": "DUPLICATE_ATTRIBUTE",
  4009. "END_TAG_WITH_ATTRIBUTES": 3,
  4010. "3": "END_TAG_WITH_ATTRIBUTES",
  4011. "END_TAG_WITH_TRAILING_SOLIDUS": 4,
  4012. "4": "END_TAG_WITH_TRAILING_SOLIDUS",
  4013. "EOF_BEFORE_TAG_NAME": 5,
  4014. "5": "EOF_BEFORE_TAG_NAME",
  4015. "EOF_IN_CDATA": 6,
  4016. "6": "EOF_IN_CDATA",
  4017. "EOF_IN_COMMENT": 7,
  4018. "7": "EOF_IN_COMMENT",
  4019. "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
  4020. "8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
  4021. "EOF_IN_TAG": 9,
  4022. "9": "EOF_IN_TAG",
  4023. "INCORRECTLY_CLOSED_COMMENT": 10,
  4024. "10": "INCORRECTLY_CLOSED_COMMENT",
  4025. "INCORRECTLY_OPENED_COMMENT": 11,
  4026. "11": "INCORRECTLY_OPENED_COMMENT",
  4027. "INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
  4028. "12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
  4029. "MISSING_ATTRIBUTE_VALUE": 13,
  4030. "13": "MISSING_ATTRIBUTE_VALUE",
  4031. "MISSING_END_TAG_NAME": 14,
  4032. "14": "MISSING_END_TAG_NAME",
  4033. "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
  4034. "15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
  4035. "NESTED_COMMENT": 16,
  4036. "16": "NESTED_COMMENT",
  4037. "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
  4038. "17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
  4039. "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
  4040. "18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
  4041. "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
  4042. "19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
  4043. "UNEXPECTED_NULL_CHARACTER": 20,
  4044. "20": "UNEXPECTED_NULL_CHARACTER",
  4045. "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
  4046. "21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
  4047. "UNEXPECTED_SOLIDUS_IN_TAG": 22,
  4048. "22": "UNEXPECTED_SOLIDUS_IN_TAG",
  4049. "X_INVALID_END_TAG": 23,
  4050. "23": "X_INVALID_END_TAG",
  4051. "X_MISSING_END_TAG": 24,
  4052. "24": "X_MISSING_END_TAG",
  4053. "X_MISSING_INTERPOLATION_END": 25,
  4054. "25": "X_MISSING_INTERPOLATION_END",
  4055. "X_MISSING_DIRECTIVE_NAME": 26,
  4056. "26": "X_MISSING_DIRECTIVE_NAME",
  4057. "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
  4058. "27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
  4059. "X_V_IF_NO_EXPRESSION": 28,
  4060. "28": "X_V_IF_NO_EXPRESSION",
  4061. "X_V_IF_SAME_KEY": 29,
  4062. "29": "X_V_IF_SAME_KEY",
  4063. "X_V_ELSE_NO_ADJACENT_IF": 30,
  4064. "30": "X_V_ELSE_NO_ADJACENT_IF",
  4065. "X_V_FOR_NO_EXPRESSION": 31,
  4066. "31": "X_V_FOR_NO_EXPRESSION",
  4067. "X_V_FOR_MALFORMED_EXPRESSION": 32,
  4068. "32": "X_V_FOR_MALFORMED_EXPRESSION",
  4069. "X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
  4070. "33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
  4071. "X_V_BIND_NO_EXPRESSION": 34,
  4072. "34": "X_V_BIND_NO_EXPRESSION",
  4073. "X_V_ON_NO_EXPRESSION": 35,
  4074. "35": "X_V_ON_NO_EXPRESSION",
  4075. "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
  4076. "36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
  4077. "X_V_SLOT_MIXED_SLOT_USAGE": 37,
  4078. "37": "X_V_SLOT_MIXED_SLOT_USAGE",
  4079. "X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
  4080. "38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
  4081. "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
  4082. "39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
  4083. "X_V_SLOT_MISPLACED": 40,
  4084. "40": "X_V_SLOT_MISPLACED",
  4085. "X_V_MODEL_NO_EXPRESSION": 41,
  4086. "41": "X_V_MODEL_NO_EXPRESSION",
  4087. "X_V_MODEL_MALFORMED_EXPRESSION": 42,
  4088. "42": "X_V_MODEL_MALFORMED_EXPRESSION",
  4089. "X_V_MODEL_ON_SCOPE_VARIABLE": 43,
  4090. "43": "X_V_MODEL_ON_SCOPE_VARIABLE",
  4091. "X_V_MODEL_ON_PROPS": 44,
  4092. "44": "X_V_MODEL_ON_PROPS",
  4093. "X_V_MODEL_ON_CONST": 45,
  4094. "45": "X_V_MODEL_ON_CONST",
  4095. "X_INVALID_EXPRESSION": 46,
  4096. "46": "X_INVALID_EXPRESSION",
  4097. "X_KEEP_ALIVE_INVALID_CHILDREN": 47,
  4098. "47": "X_KEEP_ALIVE_INVALID_CHILDREN",
  4099. "X_PREFIX_ID_NOT_SUPPORTED": 48,
  4100. "48": "X_PREFIX_ID_NOT_SUPPORTED",
  4101. "X_MODULE_MODE_NOT_SUPPORTED": 49,
  4102. "49": "X_MODULE_MODE_NOT_SUPPORTED",
  4103. "X_CACHE_HANDLER_NOT_SUPPORTED": 50,
  4104. "50": "X_CACHE_HANDLER_NOT_SUPPORTED",
  4105. "X_SCOPE_ID_NOT_SUPPORTED": 51,
  4106. "51": "X_SCOPE_ID_NOT_SUPPORTED",
  4107. "X_VNODE_HOOKS": 52,
  4108. "52": "X_VNODE_HOOKS",
  4109. "X_V_BIND_INVALID_SAME_NAME_ARGUMENT": 53,
  4110. "53": "X_V_BIND_INVALID_SAME_NAME_ARGUMENT",
  4111. "__EXTEND_POINT__": 54,
  4112. "54": "__EXTEND_POINT__"
  4113. };
  4114. const errorMessages$1 = {
  4115. // parse errors
  4116. [0]: "Illegal comment.",
  4117. [1]: "CDATA section is allowed only in XML context.",
  4118. [2]: "Duplicate attribute.",
  4119. [3]: "End tag cannot have attributes.",
  4120. [4]: "Illegal '/' in tags.",
  4121. [5]: "Unexpected EOF in tag.",
  4122. [6]: "Unexpected EOF in CDATA section.",
  4123. [7]: "Unexpected EOF in comment.",
  4124. [8]: "Unexpected EOF in script.",
  4125. [9]: "Unexpected EOF in tag.",
  4126. [10]: "Incorrectly closed comment.",
  4127. [11]: "Incorrectly opened comment.",
  4128. [12]: "Illegal tag name. Use '&lt;' to print '<'.",
  4129. [13]: "Attribute value was expected.",
  4130. [14]: "End tag name was expected.",
  4131. [15]: "Whitespace was expected.",
  4132. [16]: "Unexpected '<!--' in comment.",
  4133. [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
  4134. [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
  4135. [19]: "Attribute name cannot start with '='.",
  4136. [21]: "'<?' is allowed only in XML context.",
  4137. [20]: `Unexpected null character.`,
  4138. [22]: "Illegal '/' in tags.",
  4139. // Vue-specific parse errors
  4140. [23]: "Invalid end tag.",
  4141. [24]: "Element is missing end tag.",
  4142. [25]: "Interpolation end sign was not found.",
  4143. [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
  4144. [26]: "Legal directive name was expected.",
  4145. // transform errors
  4146. [28]: `v-if/v-else-if is missing expression.`,
  4147. [29]: `v-if/else branches must use unique keys.`,
  4148. [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  4149. [31]: `v-for is missing expression.`,
  4150. [32]: `v-for has invalid expression.`,
  4151. [33]: `<template v-for> key should be placed on the <template> tag.`,
  4152. [34]: `v-bind is missing expression.`,
  4153. [53]: `v-bind with same-name shorthand only allows static argument.`,
  4154. [35]: `v-on is missing expression.`,
  4155. [36]: `Unexpected custom directive on <slot> outlet.`,
  4156. [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.`,
  4157. [38]: `Duplicate slot names found. `,
  4158. [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
  4159. [40]: `v-slot can only be used on components or <template> tags.`,
  4160. [41]: `v-model is missing expression.`,
  4161. [42]: `v-model value must be a valid JavaScript member expression.`,
  4162. [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  4163. [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
  4164. Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  4165. [45]: `v-model cannot be used on a const binding because it is not writable.`,
  4166. [46]: `Error parsing JavaScript expression: `,
  4167. [47]: `<KeepAlive> expects exactly one child component.`,
  4168. [52]: `@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.`,
  4169. // generic errors
  4170. [48]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  4171. [49]: `ES module mode is not supported in this build of compiler.`,
  4172. [50]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  4173. [51]: `"scopeId" option is only supported in module mode.`,
  4174. // just to fulfill types
  4175. [54]: ``
  4176. };
  4177. function getDefaultExportFromCjs (x) {
  4178. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  4179. }
  4180. function getAugmentedNamespace(n) {
  4181. if (Object.prototype.hasOwnProperty.call(n, '__esModule')) return n;
  4182. var f = n.default;
  4183. if (typeof f == "function") {
  4184. var a = function a () {
  4185. var isInstance = false;
  4186. try {
  4187. isInstance = this instanceof a;
  4188. } catch {}
  4189. if (isInstance) {
  4190. return Reflect.construct(f, arguments, this.constructor);
  4191. }
  4192. return f.apply(this, arguments);
  4193. };
  4194. a.prototype = f.prototype;
  4195. } else a = {};
  4196. Object.defineProperty(a, '__esModule', {value: true});
  4197. Object.keys(n).forEach(function (k) {
  4198. var d = Object.getOwnPropertyDescriptor(n, k);
  4199. Object.defineProperty(a, k, d.get ? d : {
  4200. enumerable: true,
  4201. get: function () {
  4202. return n[k];
  4203. }
  4204. });
  4205. });
  4206. return a;
  4207. }
  4208. var lib = {};
  4209. var hasRequiredLib;
  4210. function requireLib () {
  4211. if (hasRequiredLib) return lib;
  4212. hasRequiredLib = 1;
  4213. Object.defineProperty(lib, '__esModule', {
  4214. value: true
  4215. });
  4216. function _objectWithoutPropertiesLoose(r, e) {
  4217. if (null == r) return {};
  4218. var t = {};
  4219. for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
  4220. if (-1 !== e.indexOf(n)) continue;
  4221. t[n] = r[n];
  4222. }
  4223. return t;
  4224. }
  4225. class Position {
  4226. constructor(line, col, index) {
  4227. this.line = void 0;
  4228. this.column = void 0;
  4229. this.index = void 0;
  4230. this.line = line;
  4231. this.column = col;
  4232. this.index = index;
  4233. }
  4234. }
  4235. class SourceLocation {
  4236. constructor(start, end) {
  4237. this.start = void 0;
  4238. this.end = void 0;
  4239. this.filename = void 0;
  4240. this.identifierName = void 0;
  4241. this.start = start;
  4242. this.end = end;
  4243. }
  4244. }
  4245. function createPositionWithColumnOffset(position, columnOffset) {
  4246. const {
  4247. line,
  4248. column,
  4249. index
  4250. } = position;
  4251. return new Position(line, column + columnOffset, index + columnOffset);
  4252. }
  4253. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  4254. var ModuleErrors = {
  4255. ImportMetaOutsideModule: {
  4256. message: `import.meta may appear only with 'sourceType: "module"'`,
  4257. code
  4258. },
  4259. ImportOutsideModule: {
  4260. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  4261. code
  4262. }
  4263. };
  4264. const NodeDescriptions = {
  4265. ArrayPattern: "array destructuring pattern",
  4266. AssignmentExpression: "assignment expression",
  4267. AssignmentPattern: "assignment expression",
  4268. ArrowFunctionExpression: "arrow function expression",
  4269. ConditionalExpression: "conditional expression",
  4270. CatchClause: "catch clause",
  4271. ForOfStatement: "for-of statement",
  4272. ForInStatement: "for-in statement",
  4273. ForStatement: "for-loop",
  4274. FormalParameters: "function parameter list",
  4275. Identifier: "identifier",
  4276. ImportSpecifier: "import specifier",
  4277. ImportDefaultSpecifier: "import default specifier",
  4278. ImportNamespaceSpecifier: "import namespace specifier",
  4279. ObjectPattern: "object destructuring pattern",
  4280. ParenthesizedExpression: "parenthesized expression",
  4281. RestElement: "rest element",
  4282. UpdateExpression: {
  4283. true: "prefix operation",
  4284. false: "postfix operation"
  4285. },
  4286. VariableDeclarator: "variable declaration",
  4287. YieldExpression: "yield expression"
  4288. };
  4289. const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type];
  4290. var StandardErrors = {
  4291. AccessorIsGenerator: ({
  4292. kind
  4293. }) => `A ${kind}ter cannot be a generator.`,
  4294. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  4295. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  4296. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  4297. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  4298. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  4299. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  4300. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  4301. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  4302. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  4303. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  4304. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  4305. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  4306. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  4307. ConstructorIsAsync: "Constructor can't be an async function.",
  4308. ConstructorIsGenerator: "Constructor can't be a generator.",
  4309. DeclarationMissingInitializer: ({
  4310. kind
  4311. }) => `Missing initializer in ${kind} declaration.`,
  4312. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  4313. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  4314. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  4315. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  4316. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  4317. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  4318. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  4319. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  4320. DeletePrivateField: "Deleting a private field is not allowed.",
  4321. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  4322. DuplicateConstructor: "Duplicate constructor in the same class.",
  4323. DuplicateDefaultExport: "Only one default export allowed per module.",
  4324. DuplicateExport: ({
  4325. exportName
  4326. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  4327. DuplicateProto: "Redefinition of __proto__ property.",
  4328. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  4329. ElementAfterRest: "Rest element must be last element.",
  4330. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  4331. ExportBindingIsString: ({
  4332. localName,
  4333. exportName
  4334. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  4335. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  4336. ForInOfLoopInitializer: ({
  4337. type
  4338. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  4339. ForInUsing: "For-in loop may not start with 'using' declaration.",
  4340. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  4341. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  4342. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  4343. IllegalBreakContinue: ({
  4344. type
  4345. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  4346. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  4347. IllegalReturn: "'return' outside of function.",
  4348. ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedImportAssert` parser plugin to suppress this error.",
  4349. ImportBindingIsString: ({
  4350. importName
  4351. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  4352. ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
  4353. ImportCallNotNewExpression: "Cannot use new with import(...).",
  4354. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  4355. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  4356. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  4357. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  4358. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  4359. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  4360. InvalidCodePoint: "Code point out of bounds.",
  4361. InvalidCoverDiscardElement: "'void' must be followed by an expression when not used in a binding position.",
  4362. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  4363. InvalidDecimal: "Invalid decimal.",
  4364. InvalidDigit: ({
  4365. radix
  4366. }) => `Expected number in radix ${radix}.`,
  4367. InvalidEscapeSequence: "Bad character escape sequence.",
  4368. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  4369. InvalidEscapedReservedWord: ({
  4370. reservedWord
  4371. }) => `Escape sequence in keyword ${reservedWord}.`,
  4372. InvalidIdentifier: ({
  4373. identifierName
  4374. }) => `Invalid identifier ${identifierName}.`,
  4375. InvalidLhs: ({
  4376. ancestor
  4377. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  4378. InvalidLhsBinding: ({
  4379. ancestor
  4380. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  4381. InvalidLhsOptionalChaining: ({
  4382. ancestor
  4383. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  4384. InvalidNumber: "Invalid number.",
  4385. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  4386. InvalidOrUnexpectedToken: ({
  4387. unexpected
  4388. }) => `Unexpected character '${unexpected}'.`,
  4389. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  4390. InvalidPrivateFieldResolution: ({
  4391. identifierName
  4392. }) => `Private name #${identifierName} is not defined.`,
  4393. InvalidPropertyBindingPattern: "Binding member expression.",
  4394. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  4395. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  4396. LabelRedeclaration: ({
  4397. labelName
  4398. }) => `Label '${labelName}' is already declared.`,
  4399. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  4400. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  4401. MalformedRegExpFlags: "Invalid regular expression flag.",
  4402. MissingClassName: "A class name is required.",
  4403. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  4404. MissingSemicolon: "Missing semicolon.",
  4405. MissingPlugin: ({
  4406. missingPlugin
  4407. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  4408. MissingOneOfPlugins: ({
  4409. missingPlugin
  4410. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  4411. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  4412. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  4413. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  4414. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  4415. ModuleAttributesWithDuplicateKeys: ({
  4416. key
  4417. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  4418. ModuleExportNameHasLoneSurrogate: ({
  4419. surrogateCharCode
  4420. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  4421. ModuleExportUndefined: ({
  4422. localName
  4423. }) => `Export '${localName}' is not defined.`,
  4424. MultipleDefaultsInSwitch: "Multiple default clauses.",
  4425. NewlineAfterThrow: "Illegal newline after throw.",
  4426. NoCatchOrFinally: "Missing catch or finally clause.",
  4427. NumberIdentifier: "Identifier directly after number.",
  4428. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  4429. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  4430. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  4431. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  4432. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  4433. ParamDupe: "Argument name clash.",
  4434. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  4435. PatternHasMethod: "Object pattern can't contain methods.",
  4436. PrivateInExpectedIn: ({
  4437. identifierName
  4438. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  4439. PrivateNameRedeclaration: ({
  4440. identifierName
  4441. }) => `Duplicate private name #${identifierName}.`,
  4442. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  4443. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  4444. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  4445. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  4446. RestTrailingComma: "Unexpected trailing comma after rest element.",
  4447. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  4448. 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.",
  4449. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  4450. StaticPrototype: "Classes may not have static property named prototype.",
  4451. 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?",
  4452. SuperPrivateField: "Private fields can't be accessed on super.",
  4453. TrailingDecorator: "Decorators must be attached to a class element.",
  4454. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  4455. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  4456. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  4457. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  4458. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  4459. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  4460. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  4461. UnexpectedKeyword: ({
  4462. keyword
  4463. }) => `Unexpected keyword '${keyword}'.`,
  4464. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  4465. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  4466. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  4467. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  4468. UnexpectedPrivateField: "Unexpected private name.",
  4469. UnexpectedReservedWord: ({
  4470. reservedWord
  4471. }) => `Unexpected reserved word '${reservedWord}'.`,
  4472. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  4473. UnexpectedToken: ({
  4474. expected,
  4475. unexpected
  4476. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  4477. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  4478. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement.",
  4479. UnexpectedVoidPattern: "Unexpected void binding.",
  4480. UnsupportedBind: "Binding should be performed on object property.",
  4481. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  4482. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  4483. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  4484. UnsupportedMetaProperty: ({
  4485. target,
  4486. onlyValidPropertyName
  4487. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  4488. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  4489. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  4490. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  4491. UnterminatedComment: "Unterminated comment.",
  4492. UnterminatedRegExp: "Unterminated regular expression.",
  4493. UnterminatedString: "Unterminated string constant.",
  4494. UnterminatedTemplate: "Unterminated template.",
  4495. UsingDeclarationExport: "Using declaration cannot be exported.",
  4496. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  4497. VarRedeclaration: ({
  4498. identifierName
  4499. }) => `Identifier '${identifierName}' has already been declared.`,
  4500. VoidPatternCatchClauseParam: "A void binding can not be the catch clause parameter. Use `try { ... } catch { ... }` if you want to discard the caught error.",
  4501. VoidPatternInitializer: "A void binding may not have an initializer.",
  4502. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  4503. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  4504. YieldNotInGeneratorFunction: "'yield' is only allowed within generator functions.",
  4505. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  4506. };
  4507. var StrictModeErrors = {
  4508. StrictDelete: "Deleting local variable in strict mode.",
  4509. StrictEvalArguments: ({
  4510. referenceName
  4511. }) => `Assigning to '${referenceName}' in strict mode.`,
  4512. StrictEvalArgumentsBinding: ({
  4513. bindingName
  4514. }) => `Binding '${bindingName}' in strict mode.`,
  4515. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  4516. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  4517. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  4518. StrictWith: "'with' in strict mode."
  4519. };
  4520. var ParseExpressionErrors = {
  4521. ParseExpressionEmptyInput: "Unexpected parseExpression() input: The input is empty or contains only comments.",
  4522. ParseExpressionExpectsEOF: ({
  4523. unexpected
  4524. }) => `Unexpected parseExpression() input: The input should contain exactly one expression, but the first expression is followed by the unexpected character \`${String.fromCodePoint(unexpected)}\`.`
  4525. };
  4526. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  4527. var PipelineOperatorErrors = Object.assign({
  4528. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  4529. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  4530. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  4531. PipeTopicUnconfiguredToken: ({
  4532. token
  4533. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  4534. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  4535. PipeUnparenthesizedBody: ({
  4536. type
  4537. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  4538. type
  4539. })}; please wrap it in parentheses.`
  4540. }, {
  4541. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  4542. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  4543. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  4544. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  4545. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  4546. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  4547. });
  4548. const _excluded = ["message"];
  4549. function defineHidden(obj, key, value) {
  4550. Object.defineProperty(obj, key, {
  4551. enumerable: false,
  4552. configurable: true,
  4553. value
  4554. });
  4555. }
  4556. function toParseErrorConstructor({
  4557. toMessage,
  4558. code,
  4559. reasonCode,
  4560. syntaxPlugin
  4561. }) {
  4562. const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
  4563. {
  4564. const oldReasonCodes = {
  4565. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  4566. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  4567. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  4568. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  4569. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  4570. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  4571. };
  4572. if (oldReasonCodes[reasonCode]) {
  4573. reasonCode = oldReasonCodes[reasonCode];
  4574. }
  4575. }
  4576. return function constructor(loc, details) {
  4577. const error = new SyntaxError();
  4578. error.code = code;
  4579. error.reasonCode = reasonCode;
  4580. error.loc = loc;
  4581. error.pos = loc.index;
  4582. error.syntaxPlugin = syntaxPlugin;
  4583. if (hasMissingPlugin) {
  4584. error.missingPlugin = details.missingPlugin;
  4585. }
  4586. defineHidden(error, "clone", function clone(overrides = {}) {
  4587. var _overrides$loc;
  4588. const {
  4589. line,
  4590. column,
  4591. index
  4592. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  4593. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  4594. });
  4595. defineHidden(error, "details", details);
  4596. Object.defineProperty(error, "message", {
  4597. configurable: true,
  4598. get() {
  4599. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  4600. this.message = message;
  4601. return message;
  4602. },
  4603. set(value) {
  4604. Object.defineProperty(this, "message", {
  4605. value,
  4606. writable: true
  4607. });
  4608. }
  4609. });
  4610. return error;
  4611. };
  4612. }
  4613. function ParseErrorEnum(argument, syntaxPlugin) {
  4614. if (Array.isArray(argument)) {
  4615. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  4616. }
  4617. const ParseErrorConstructors = {};
  4618. for (const reasonCode of Object.keys(argument)) {
  4619. const template = argument[reasonCode];
  4620. const _ref = typeof template === "string" ? {
  4621. message: () => template
  4622. } : typeof template === "function" ? {
  4623. message: template
  4624. } : template,
  4625. {
  4626. message
  4627. } = _ref,
  4628. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  4629. const toMessage = typeof message === "string" ? () => message : message;
  4630. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  4631. code: "BABEL_PARSER_SYNTAX_ERROR",
  4632. reasonCode,
  4633. toMessage
  4634. }, syntaxPlugin ? {
  4635. syntaxPlugin
  4636. } : {}, rest));
  4637. }
  4638. return ParseErrorConstructors;
  4639. }
  4640. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum(ParseExpressionErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  4641. function createDefaultOptions() {
  4642. return {
  4643. sourceType: "script",
  4644. sourceFilename: undefined,
  4645. startIndex: 0,
  4646. startColumn: 0,
  4647. startLine: 1,
  4648. allowAwaitOutsideFunction: false,
  4649. allowReturnOutsideFunction: false,
  4650. allowNewTargetOutsideFunction: false,
  4651. allowImportExportEverywhere: false,
  4652. allowSuperOutsideMethod: false,
  4653. allowUndeclaredExports: false,
  4654. allowYieldOutsideFunction: false,
  4655. plugins: [],
  4656. strictMode: undefined,
  4657. ranges: false,
  4658. tokens: false,
  4659. createImportExpressions: false,
  4660. createParenthesizedExpressions: false,
  4661. errorRecovery: false,
  4662. attachComment: true,
  4663. annexB: true
  4664. };
  4665. }
  4666. function getOptions(opts) {
  4667. const options = createDefaultOptions();
  4668. if (opts == null) {
  4669. return options;
  4670. }
  4671. if (opts.annexB != null && opts.annexB !== false) {
  4672. throw new Error("The `annexB` option can only be set to `false`.");
  4673. }
  4674. for (const key of Object.keys(options)) {
  4675. if (opts[key] != null) options[key] = opts[key];
  4676. }
  4677. if (options.startLine === 1) {
  4678. if (opts.startIndex == null && options.startColumn > 0) {
  4679. options.startIndex = options.startColumn;
  4680. } else if (opts.startColumn == null && options.startIndex > 0) {
  4681. options.startColumn = options.startIndex;
  4682. }
  4683. } else if (opts.startColumn == null || opts.startIndex == null) {
  4684. if (opts.startIndex != null) {
  4685. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  4686. }
  4687. }
  4688. if (options.sourceType === "commonjs") {
  4689. if (opts.allowAwaitOutsideFunction != null) {
  4690. throw new Error("The `allowAwaitOutsideFunction` option cannot be used with `sourceType: 'commonjs'`.");
  4691. }
  4692. if (opts.allowReturnOutsideFunction != null) {
  4693. throw new Error("`sourceType: 'commonjs'` implies `allowReturnOutsideFunction: true`, please remove the `allowReturnOutsideFunction` option or use `sourceType: 'script'`.");
  4694. }
  4695. if (opts.allowNewTargetOutsideFunction != null) {
  4696. throw new Error("`sourceType: 'commonjs'` implies `allowNewTargetOutsideFunction: true`, please remove the `allowNewTargetOutsideFunction` option or use `sourceType: 'script'`.");
  4697. }
  4698. }
  4699. return options;
  4700. }
  4701. const {
  4702. defineProperty
  4703. } = Object;
  4704. const toUnenumerable = (object, key) => {
  4705. if (object) {
  4706. defineProperty(object, key, {
  4707. enumerable: false,
  4708. value: object[key]
  4709. });
  4710. }
  4711. };
  4712. function toESTreeLocation(node) {
  4713. toUnenumerable(node.loc.start, "index");
  4714. toUnenumerable(node.loc.end, "index");
  4715. return node;
  4716. }
  4717. var estree = superClass => class ESTreeParserMixin extends superClass {
  4718. parse() {
  4719. const file = toESTreeLocation(super.parse());
  4720. if (this.optionFlags & 256) {
  4721. file.tokens = file.tokens.map(toESTreeLocation);
  4722. }
  4723. return file;
  4724. }
  4725. parseRegExpLiteral({
  4726. pattern,
  4727. flags
  4728. }) {
  4729. let regex = null;
  4730. try {
  4731. regex = new RegExp(pattern, flags);
  4732. } catch (_) {}
  4733. const node = this.estreeParseLiteral(regex);
  4734. node.regex = {
  4735. pattern,
  4736. flags
  4737. };
  4738. return node;
  4739. }
  4740. parseBigIntLiteral(value) {
  4741. let bigInt;
  4742. try {
  4743. bigInt = BigInt(value);
  4744. } catch (_unused) {
  4745. bigInt = null;
  4746. }
  4747. const node = this.estreeParseLiteral(bigInt);
  4748. node.bigint = String(node.value || value);
  4749. return node;
  4750. }
  4751. parseDecimalLiteral(value) {
  4752. const decimal = null;
  4753. const node = this.estreeParseLiteral(decimal);
  4754. node.decimal = String(node.value || value);
  4755. return node;
  4756. }
  4757. estreeParseLiteral(value) {
  4758. return this.parseLiteral(value, "Literal");
  4759. }
  4760. parseStringLiteral(value) {
  4761. return this.estreeParseLiteral(value);
  4762. }
  4763. parseNumericLiteral(value) {
  4764. return this.estreeParseLiteral(value);
  4765. }
  4766. parseNullLiteral() {
  4767. return this.estreeParseLiteral(null);
  4768. }
  4769. parseBooleanLiteral(value) {
  4770. return this.estreeParseLiteral(value);
  4771. }
  4772. estreeParseChainExpression(node, endLoc) {
  4773. const chain = this.startNodeAtNode(node);
  4774. chain.expression = node;
  4775. return this.finishNodeAt(chain, "ChainExpression", endLoc);
  4776. }
  4777. directiveToStmt(directive) {
  4778. const expression = directive.value;
  4779. delete directive.value;
  4780. this.castNodeTo(expression, "Literal");
  4781. expression.raw = expression.extra.raw;
  4782. expression.value = expression.extra.expressionValue;
  4783. const stmt = this.castNodeTo(directive, "ExpressionStatement");
  4784. stmt.expression = expression;
  4785. stmt.directive = expression.extra.rawValue;
  4786. delete expression.extra;
  4787. return stmt;
  4788. }
  4789. fillOptionalPropertiesForTSESLint(node) {}
  4790. cloneEstreeStringLiteral(node) {
  4791. const {
  4792. start,
  4793. end,
  4794. loc,
  4795. range,
  4796. raw,
  4797. value
  4798. } = node;
  4799. const cloned = Object.create(node.constructor.prototype);
  4800. cloned.type = "Literal";
  4801. cloned.start = start;
  4802. cloned.end = end;
  4803. cloned.loc = loc;
  4804. cloned.range = range;
  4805. cloned.raw = raw;
  4806. cloned.value = value;
  4807. return cloned;
  4808. }
  4809. initFunction(node, isAsync) {
  4810. super.initFunction(node, isAsync);
  4811. node.expression = false;
  4812. }
  4813. checkDeclaration(node) {
  4814. if (node != null && this.isObjectProperty(node)) {
  4815. this.checkDeclaration(node.value);
  4816. } else {
  4817. super.checkDeclaration(node);
  4818. }
  4819. }
  4820. getObjectOrClassMethodParams(method) {
  4821. return method.value.params;
  4822. }
  4823. isValidDirective(stmt) {
  4824. var _stmt$expression$extr;
  4825. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  4826. }
  4827. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  4828. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  4829. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  4830. node.body = directiveStatements.concat(node.body);
  4831. delete node.directives;
  4832. }
  4833. parsePrivateName() {
  4834. const node = super.parsePrivateName();
  4835. {
  4836. if (!this.getPluginOption("estree", "classFeatures")) {
  4837. return node;
  4838. }
  4839. }
  4840. return this.convertPrivateNameToPrivateIdentifier(node);
  4841. }
  4842. convertPrivateNameToPrivateIdentifier(node) {
  4843. const name = super.getPrivateNameSV(node);
  4844. delete node.id;
  4845. node.name = name;
  4846. return this.castNodeTo(node, "PrivateIdentifier");
  4847. }
  4848. isPrivateName(node) {
  4849. {
  4850. if (!this.getPluginOption("estree", "classFeatures")) {
  4851. return super.isPrivateName(node);
  4852. }
  4853. }
  4854. return node.type === "PrivateIdentifier";
  4855. }
  4856. getPrivateNameSV(node) {
  4857. {
  4858. if (!this.getPluginOption("estree", "classFeatures")) {
  4859. return super.getPrivateNameSV(node);
  4860. }
  4861. }
  4862. return node.name;
  4863. }
  4864. parseLiteral(value, type) {
  4865. const node = super.parseLiteral(value, type);
  4866. node.raw = node.extra.raw;
  4867. delete node.extra;
  4868. return node;
  4869. }
  4870. parseFunctionBody(node, allowExpression, isMethod = false) {
  4871. super.parseFunctionBody(node, allowExpression, isMethod);
  4872. node.expression = node.body.type !== "BlockStatement";
  4873. }
  4874. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  4875. let funcNode = this.startNode();
  4876. funcNode.kind = node.kind;
  4877. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  4878. delete funcNode.kind;
  4879. const {
  4880. typeParameters
  4881. } = node;
  4882. if (typeParameters) {
  4883. delete node.typeParameters;
  4884. funcNode.typeParameters = typeParameters;
  4885. this.resetStartLocationFromNode(funcNode, typeParameters);
  4886. }
  4887. const valueNode = this.castNodeTo(funcNode, "FunctionExpression");
  4888. node.value = valueNode;
  4889. if (type === "ClassPrivateMethod") {
  4890. node.computed = false;
  4891. }
  4892. if (type === "ObjectMethod") {
  4893. if (node.kind === "method") {
  4894. node.kind = "init";
  4895. }
  4896. node.shorthand = false;
  4897. return this.finishNode(node, "Property");
  4898. } else {
  4899. return this.finishNode(node, "MethodDefinition");
  4900. }
  4901. }
  4902. nameIsConstructor(key) {
  4903. if (key.type === "Literal") return key.value === "constructor";
  4904. return super.nameIsConstructor(key);
  4905. }
  4906. parseClassProperty(...args) {
  4907. const propertyNode = super.parseClassProperty(...args);
  4908. {
  4909. if (!this.getPluginOption("estree", "classFeatures")) {
  4910. return propertyNode;
  4911. }
  4912. }
  4913. {
  4914. this.castNodeTo(propertyNode, "PropertyDefinition");
  4915. }
  4916. return propertyNode;
  4917. }
  4918. parseClassPrivateProperty(...args) {
  4919. const propertyNode = super.parseClassPrivateProperty(...args);
  4920. {
  4921. if (!this.getPluginOption("estree", "classFeatures")) {
  4922. return propertyNode;
  4923. }
  4924. }
  4925. {
  4926. this.castNodeTo(propertyNode, "PropertyDefinition");
  4927. }
  4928. propertyNode.computed = false;
  4929. return propertyNode;
  4930. }
  4931. parseClassAccessorProperty(node) {
  4932. const accessorPropertyNode = super.parseClassAccessorProperty(node);
  4933. {
  4934. if (!this.getPluginOption("estree", "classFeatures")) {
  4935. return accessorPropertyNode;
  4936. }
  4937. }
  4938. if (accessorPropertyNode.abstract && this.hasPlugin("typescript")) {
  4939. delete accessorPropertyNode.abstract;
  4940. this.castNodeTo(accessorPropertyNode, "TSAbstractAccessorProperty");
  4941. } else {
  4942. this.castNodeTo(accessorPropertyNode, "AccessorProperty");
  4943. }
  4944. return accessorPropertyNode;
  4945. }
  4946. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  4947. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  4948. if (node) {
  4949. node.kind = "init";
  4950. this.castNodeTo(node, "Property");
  4951. }
  4952. return node;
  4953. }
  4954. finishObjectProperty(node) {
  4955. node.kind = "init";
  4956. return this.finishNode(node, "Property");
  4957. }
  4958. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  4959. return type === "Property" ? "value" : super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  4960. }
  4961. isAssignable(node, isBinding) {
  4962. if (node != null && this.isObjectProperty(node)) {
  4963. return this.isAssignable(node.value, isBinding);
  4964. }
  4965. return super.isAssignable(node, isBinding);
  4966. }
  4967. toAssignable(node, isLHS = false) {
  4968. if (node != null && this.isObjectProperty(node)) {
  4969. const {
  4970. key,
  4971. value
  4972. } = node;
  4973. if (this.isPrivateName(key)) {
  4974. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  4975. }
  4976. this.toAssignable(value, isLHS);
  4977. } else {
  4978. super.toAssignable(node, isLHS);
  4979. }
  4980. }
  4981. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  4982. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  4983. this.raise(Errors.PatternHasAccessor, prop.key);
  4984. } else if (prop.type === "Property" && prop.method) {
  4985. this.raise(Errors.PatternHasMethod, prop.key);
  4986. } else {
  4987. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  4988. }
  4989. }
  4990. finishCallExpression(unfinished, optional) {
  4991. const node = super.finishCallExpression(unfinished, optional);
  4992. if (node.callee.type === "Import") {
  4993. var _ref;
  4994. this.castNodeTo(node, "ImportExpression");
  4995. node.source = node.arguments[0];
  4996. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  4997. {
  4998. var _ref2;
  4999. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  5000. }
  5001. delete node.arguments;
  5002. delete node.callee;
  5003. } else if (node.type === "OptionalCallExpression") {
  5004. this.castNodeTo(node, "CallExpression");
  5005. } else {
  5006. node.optional = false;
  5007. }
  5008. return node;
  5009. }
  5010. toReferencedArguments(node) {
  5011. if (node.type === "ImportExpression") {
  5012. return;
  5013. }
  5014. super.toReferencedArguments(node);
  5015. }
  5016. parseExport(unfinished, decorators) {
  5017. const exportStartLoc = this.state.lastTokStartLoc;
  5018. const node = super.parseExport(unfinished, decorators);
  5019. switch (node.type) {
  5020. case "ExportAllDeclaration":
  5021. node.exported = null;
  5022. break;
  5023. case "ExportNamedDeclaration":
  5024. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  5025. this.castNodeTo(node, "ExportAllDeclaration");
  5026. node.exported = node.specifiers[0].exported;
  5027. delete node.specifiers;
  5028. }
  5029. case "ExportDefaultDeclaration":
  5030. {
  5031. var _declaration$decorato;
  5032. const {
  5033. declaration
  5034. } = node;
  5035. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  5036. this.resetStartLocation(node, exportStartLoc);
  5037. }
  5038. }
  5039. break;
  5040. }
  5041. return node;
  5042. }
  5043. stopParseSubscript(base, state) {
  5044. const node = super.stopParseSubscript(base, state);
  5045. if (state.optionalChainMember) {
  5046. return this.estreeParseChainExpression(node, base.loc.end);
  5047. }
  5048. return node;
  5049. }
  5050. parseMember(base, startLoc, state, computed, optional) {
  5051. const node = super.parseMember(base, startLoc, state, computed, optional);
  5052. if (node.type === "OptionalMemberExpression") {
  5053. this.castNodeTo(node, "MemberExpression");
  5054. } else {
  5055. node.optional = false;
  5056. }
  5057. return node;
  5058. }
  5059. isOptionalMemberExpression(node) {
  5060. if (node.type === "ChainExpression") {
  5061. return node.expression.type === "MemberExpression";
  5062. }
  5063. return super.isOptionalMemberExpression(node);
  5064. }
  5065. hasPropertyAsPrivateName(node) {
  5066. if (node.type === "ChainExpression") {
  5067. node = node.expression;
  5068. }
  5069. return super.hasPropertyAsPrivateName(node);
  5070. }
  5071. isObjectProperty(node) {
  5072. return node.type === "Property" && node.kind === "init" && !node.method;
  5073. }
  5074. isObjectMethod(node) {
  5075. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  5076. }
  5077. castNodeTo(node, type) {
  5078. const result = super.castNodeTo(node, type);
  5079. this.fillOptionalPropertiesForTSESLint(result);
  5080. return result;
  5081. }
  5082. cloneIdentifier(node) {
  5083. const cloned = super.cloneIdentifier(node);
  5084. this.fillOptionalPropertiesForTSESLint(cloned);
  5085. return cloned;
  5086. }
  5087. cloneStringLiteral(node) {
  5088. if (node.type === "Literal") {
  5089. return this.cloneEstreeStringLiteral(node);
  5090. }
  5091. return super.cloneStringLiteral(node);
  5092. }
  5093. finishNodeAt(node, type, endLoc) {
  5094. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  5095. }
  5096. finishNode(node, type) {
  5097. const result = super.finishNode(node, type);
  5098. this.fillOptionalPropertiesForTSESLint(result);
  5099. return result;
  5100. }
  5101. resetStartLocation(node, startLoc) {
  5102. super.resetStartLocation(node, startLoc);
  5103. toESTreeLocation(node);
  5104. }
  5105. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  5106. super.resetEndLocation(node, endLoc);
  5107. toESTreeLocation(node);
  5108. }
  5109. };
  5110. class TokContext {
  5111. constructor(token, preserveSpace) {
  5112. this.token = void 0;
  5113. this.preserveSpace = void 0;
  5114. this.token = token;
  5115. this.preserveSpace = !!preserveSpace;
  5116. }
  5117. }
  5118. const types = {
  5119. brace: new TokContext("{"),
  5120. j_oTag: new TokContext("<tag"),
  5121. j_cTag: new TokContext("</tag"),
  5122. j_expr: new TokContext("<tag>...</tag>", true)
  5123. };
  5124. {
  5125. types.template = new TokContext("`", true);
  5126. }
  5127. const beforeExpr = true;
  5128. const startsExpr = true;
  5129. const isLoop = true;
  5130. const isAssign = true;
  5131. const prefix = true;
  5132. const postfix = true;
  5133. class ExportedTokenType {
  5134. constructor(label, conf = {}) {
  5135. this.label = void 0;
  5136. this.keyword = void 0;
  5137. this.beforeExpr = void 0;
  5138. this.startsExpr = void 0;
  5139. this.rightAssociative = void 0;
  5140. this.isLoop = void 0;
  5141. this.isAssign = void 0;
  5142. this.prefix = void 0;
  5143. this.postfix = void 0;
  5144. this.binop = void 0;
  5145. this.label = label;
  5146. this.keyword = conf.keyword;
  5147. this.beforeExpr = !!conf.beforeExpr;
  5148. this.startsExpr = !!conf.startsExpr;
  5149. this.rightAssociative = !!conf.rightAssociative;
  5150. this.isLoop = !!conf.isLoop;
  5151. this.isAssign = !!conf.isAssign;
  5152. this.prefix = !!conf.prefix;
  5153. this.postfix = !!conf.postfix;
  5154. this.binop = conf.binop != null ? conf.binop : null;
  5155. {
  5156. this.updateContext = null;
  5157. }
  5158. }
  5159. }
  5160. const keywords$1 = new Map();
  5161. function createKeyword(name, options = {}) {
  5162. options.keyword = name;
  5163. const token = createToken(name, options);
  5164. keywords$1.set(name, token);
  5165. return token;
  5166. }
  5167. function createBinop(name, binop) {
  5168. return createToken(name, {
  5169. beforeExpr,
  5170. binop
  5171. });
  5172. }
  5173. let tokenTypeCounter = -1;
  5174. const tokenTypes = [];
  5175. const tokenLabels = [];
  5176. const tokenBinops = [];
  5177. const tokenBeforeExprs = [];
  5178. const tokenStartsExprs = [];
  5179. const tokenPrefixes = [];
  5180. function createToken(name, options = {}) {
  5181. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  5182. ++tokenTypeCounter;
  5183. tokenLabels.push(name);
  5184. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  5185. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  5186. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  5187. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  5188. tokenTypes.push(new ExportedTokenType(name, options));
  5189. return tokenTypeCounter;
  5190. }
  5191. function createKeywordLike(name, options = {}) {
  5192. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  5193. ++tokenTypeCounter;
  5194. keywords$1.set(name, tokenTypeCounter);
  5195. tokenLabels.push(name);
  5196. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  5197. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  5198. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  5199. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  5200. tokenTypes.push(new ExportedTokenType("name", options));
  5201. return tokenTypeCounter;
  5202. }
  5203. const tt = {
  5204. bracketL: createToken("[", {
  5205. beforeExpr,
  5206. startsExpr
  5207. }),
  5208. bracketHashL: createToken("#[", {
  5209. beforeExpr,
  5210. startsExpr
  5211. }),
  5212. bracketBarL: createToken("[|", {
  5213. beforeExpr,
  5214. startsExpr
  5215. }),
  5216. bracketR: createToken("]"),
  5217. bracketBarR: createToken("|]"),
  5218. braceL: createToken("{", {
  5219. beforeExpr,
  5220. startsExpr
  5221. }),
  5222. braceBarL: createToken("{|", {
  5223. beforeExpr,
  5224. startsExpr
  5225. }),
  5226. braceHashL: createToken("#{", {
  5227. beforeExpr,
  5228. startsExpr
  5229. }),
  5230. braceR: createToken("}"),
  5231. braceBarR: createToken("|}"),
  5232. parenL: createToken("(", {
  5233. beforeExpr,
  5234. startsExpr
  5235. }),
  5236. parenR: createToken(")"),
  5237. comma: createToken(",", {
  5238. beforeExpr
  5239. }),
  5240. semi: createToken(";", {
  5241. beforeExpr
  5242. }),
  5243. colon: createToken(":", {
  5244. beforeExpr
  5245. }),
  5246. doubleColon: createToken("::", {
  5247. beforeExpr
  5248. }),
  5249. dot: createToken("."),
  5250. question: createToken("?", {
  5251. beforeExpr
  5252. }),
  5253. questionDot: createToken("?."),
  5254. arrow: createToken("=>", {
  5255. beforeExpr
  5256. }),
  5257. template: createToken("template"),
  5258. ellipsis: createToken("...", {
  5259. beforeExpr
  5260. }),
  5261. backQuote: createToken("`", {
  5262. startsExpr
  5263. }),
  5264. dollarBraceL: createToken("${", {
  5265. beforeExpr,
  5266. startsExpr
  5267. }),
  5268. templateTail: createToken("...`", {
  5269. startsExpr
  5270. }),
  5271. templateNonTail: createToken("...${", {
  5272. beforeExpr,
  5273. startsExpr
  5274. }),
  5275. at: createToken("@"),
  5276. hash: createToken("#", {
  5277. startsExpr
  5278. }),
  5279. interpreterDirective: createToken("#!..."),
  5280. eq: createToken("=", {
  5281. beforeExpr,
  5282. isAssign
  5283. }),
  5284. assign: createToken("_=", {
  5285. beforeExpr,
  5286. isAssign
  5287. }),
  5288. slashAssign: createToken("_=", {
  5289. beforeExpr,
  5290. isAssign
  5291. }),
  5292. xorAssign: createToken("_=", {
  5293. beforeExpr,
  5294. isAssign
  5295. }),
  5296. moduloAssign: createToken("_=", {
  5297. beforeExpr,
  5298. isAssign
  5299. }),
  5300. incDec: createToken("++/--", {
  5301. prefix,
  5302. postfix,
  5303. startsExpr
  5304. }),
  5305. bang: createToken("!", {
  5306. beforeExpr,
  5307. prefix,
  5308. startsExpr
  5309. }),
  5310. tilde: createToken("~", {
  5311. beforeExpr,
  5312. prefix,
  5313. startsExpr
  5314. }),
  5315. doubleCaret: createToken("^^", {
  5316. startsExpr
  5317. }),
  5318. doubleAt: createToken("@@", {
  5319. startsExpr
  5320. }),
  5321. pipeline: createBinop("|>", 0),
  5322. nullishCoalescing: createBinop("??", 1),
  5323. logicalOR: createBinop("||", 1),
  5324. logicalAND: createBinop("&&", 2),
  5325. bitwiseOR: createBinop("|", 3),
  5326. bitwiseXOR: createBinop("^", 4),
  5327. bitwiseAND: createBinop("&", 5),
  5328. equality: createBinop("==/!=/===/!==", 6),
  5329. lt: createBinop("</>/<=/>=", 7),
  5330. gt: createBinop("</>/<=/>=", 7),
  5331. relational: createBinop("</>/<=/>=", 7),
  5332. bitShift: createBinop("<</>>/>>>", 8),
  5333. bitShiftL: createBinop("<</>>/>>>", 8),
  5334. bitShiftR: createBinop("<</>>/>>>", 8),
  5335. plusMin: createToken("+/-", {
  5336. beforeExpr,
  5337. binop: 9,
  5338. prefix,
  5339. startsExpr
  5340. }),
  5341. modulo: createToken("%", {
  5342. binop: 10,
  5343. startsExpr
  5344. }),
  5345. star: createToken("*", {
  5346. binop: 10
  5347. }),
  5348. slash: createBinop("/", 10),
  5349. exponent: createToken("**", {
  5350. beforeExpr,
  5351. binop: 11,
  5352. rightAssociative: true
  5353. }),
  5354. _in: createKeyword("in", {
  5355. beforeExpr,
  5356. binop: 7
  5357. }),
  5358. _instanceof: createKeyword("instanceof", {
  5359. beforeExpr,
  5360. binop: 7
  5361. }),
  5362. _break: createKeyword("break"),
  5363. _case: createKeyword("case", {
  5364. beforeExpr
  5365. }),
  5366. _catch: createKeyword("catch"),
  5367. _continue: createKeyword("continue"),
  5368. _debugger: createKeyword("debugger"),
  5369. _default: createKeyword("default", {
  5370. beforeExpr
  5371. }),
  5372. _else: createKeyword("else", {
  5373. beforeExpr
  5374. }),
  5375. _finally: createKeyword("finally"),
  5376. _function: createKeyword("function", {
  5377. startsExpr
  5378. }),
  5379. _if: createKeyword("if"),
  5380. _return: createKeyword("return", {
  5381. beforeExpr
  5382. }),
  5383. _switch: createKeyword("switch"),
  5384. _throw: createKeyword("throw", {
  5385. beforeExpr,
  5386. prefix,
  5387. startsExpr
  5388. }),
  5389. _try: createKeyword("try"),
  5390. _var: createKeyword("var"),
  5391. _const: createKeyword("const"),
  5392. _with: createKeyword("with"),
  5393. _new: createKeyword("new", {
  5394. beforeExpr,
  5395. startsExpr
  5396. }),
  5397. _this: createKeyword("this", {
  5398. startsExpr
  5399. }),
  5400. _super: createKeyword("super", {
  5401. startsExpr
  5402. }),
  5403. _class: createKeyword("class", {
  5404. startsExpr
  5405. }),
  5406. _extends: createKeyword("extends", {
  5407. beforeExpr
  5408. }),
  5409. _export: createKeyword("export"),
  5410. _import: createKeyword("import", {
  5411. startsExpr
  5412. }),
  5413. _null: createKeyword("null", {
  5414. startsExpr
  5415. }),
  5416. _true: createKeyword("true", {
  5417. startsExpr
  5418. }),
  5419. _false: createKeyword("false", {
  5420. startsExpr
  5421. }),
  5422. _typeof: createKeyword("typeof", {
  5423. beforeExpr,
  5424. prefix,
  5425. startsExpr
  5426. }),
  5427. _void: createKeyword("void", {
  5428. beforeExpr,
  5429. prefix,
  5430. startsExpr
  5431. }),
  5432. _delete: createKeyword("delete", {
  5433. beforeExpr,
  5434. prefix,
  5435. startsExpr
  5436. }),
  5437. _do: createKeyword("do", {
  5438. isLoop,
  5439. beforeExpr
  5440. }),
  5441. _for: createKeyword("for", {
  5442. isLoop
  5443. }),
  5444. _while: createKeyword("while", {
  5445. isLoop
  5446. }),
  5447. _as: createKeywordLike("as", {
  5448. startsExpr
  5449. }),
  5450. _assert: createKeywordLike("assert", {
  5451. startsExpr
  5452. }),
  5453. _async: createKeywordLike("async", {
  5454. startsExpr
  5455. }),
  5456. _await: createKeywordLike("await", {
  5457. startsExpr
  5458. }),
  5459. _defer: createKeywordLike("defer", {
  5460. startsExpr
  5461. }),
  5462. _from: createKeywordLike("from", {
  5463. startsExpr
  5464. }),
  5465. _get: createKeywordLike("get", {
  5466. startsExpr
  5467. }),
  5468. _let: createKeywordLike("let", {
  5469. startsExpr
  5470. }),
  5471. _meta: createKeywordLike("meta", {
  5472. startsExpr
  5473. }),
  5474. _of: createKeywordLike("of", {
  5475. startsExpr
  5476. }),
  5477. _sent: createKeywordLike("sent", {
  5478. startsExpr
  5479. }),
  5480. _set: createKeywordLike("set", {
  5481. startsExpr
  5482. }),
  5483. _source: createKeywordLike("source", {
  5484. startsExpr
  5485. }),
  5486. _static: createKeywordLike("static", {
  5487. startsExpr
  5488. }),
  5489. _using: createKeywordLike("using", {
  5490. startsExpr
  5491. }),
  5492. _yield: createKeywordLike("yield", {
  5493. startsExpr
  5494. }),
  5495. _asserts: createKeywordLike("asserts", {
  5496. startsExpr
  5497. }),
  5498. _checks: createKeywordLike("checks", {
  5499. startsExpr
  5500. }),
  5501. _exports: createKeywordLike("exports", {
  5502. startsExpr
  5503. }),
  5504. _global: createKeywordLike("global", {
  5505. startsExpr
  5506. }),
  5507. _implements: createKeywordLike("implements", {
  5508. startsExpr
  5509. }),
  5510. _intrinsic: createKeywordLike("intrinsic", {
  5511. startsExpr
  5512. }),
  5513. _infer: createKeywordLike("infer", {
  5514. startsExpr
  5515. }),
  5516. _is: createKeywordLike("is", {
  5517. startsExpr
  5518. }),
  5519. _mixins: createKeywordLike("mixins", {
  5520. startsExpr
  5521. }),
  5522. _proto: createKeywordLike("proto", {
  5523. startsExpr
  5524. }),
  5525. _require: createKeywordLike("require", {
  5526. startsExpr
  5527. }),
  5528. _satisfies: createKeywordLike("satisfies", {
  5529. startsExpr
  5530. }),
  5531. _keyof: createKeywordLike("keyof", {
  5532. startsExpr
  5533. }),
  5534. _readonly: createKeywordLike("readonly", {
  5535. startsExpr
  5536. }),
  5537. _unique: createKeywordLike("unique", {
  5538. startsExpr
  5539. }),
  5540. _abstract: createKeywordLike("abstract", {
  5541. startsExpr
  5542. }),
  5543. _declare: createKeywordLike("declare", {
  5544. startsExpr
  5545. }),
  5546. _enum: createKeywordLike("enum", {
  5547. startsExpr
  5548. }),
  5549. _module: createKeywordLike("module", {
  5550. startsExpr
  5551. }),
  5552. _namespace: createKeywordLike("namespace", {
  5553. startsExpr
  5554. }),
  5555. _interface: createKeywordLike("interface", {
  5556. startsExpr
  5557. }),
  5558. _type: createKeywordLike("type", {
  5559. startsExpr
  5560. }),
  5561. _opaque: createKeywordLike("opaque", {
  5562. startsExpr
  5563. }),
  5564. name: createToken("name", {
  5565. startsExpr
  5566. }),
  5567. placeholder: createToken("%%", {
  5568. startsExpr
  5569. }),
  5570. string: createToken("string", {
  5571. startsExpr
  5572. }),
  5573. num: createToken("num", {
  5574. startsExpr
  5575. }),
  5576. bigint: createToken("bigint", {
  5577. startsExpr
  5578. }),
  5579. decimal: createToken("decimal", {
  5580. startsExpr
  5581. }),
  5582. regexp: createToken("regexp", {
  5583. startsExpr
  5584. }),
  5585. privateName: createToken("#name", {
  5586. startsExpr
  5587. }),
  5588. eof: createToken("eof"),
  5589. jsxName: createToken("jsxName"),
  5590. jsxText: createToken("jsxText", {
  5591. beforeExpr
  5592. }),
  5593. jsxTagStart: createToken("jsxTagStart", {
  5594. startsExpr
  5595. }),
  5596. jsxTagEnd: createToken("jsxTagEnd")
  5597. };
  5598. function tokenIsIdentifier(token) {
  5599. return token >= 93 && token <= 133;
  5600. }
  5601. function tokenKeywordOrIdentifierIsKeyword(token) {
  5602. return token <= 92;
  5603. }
  5604. function tokenIsKeywordOrIdentifier(token) {
  5605. return token >= 58 && token <= 133;
  5606. }
  5607. function tokenIsLiteralPropertyName(token) {
  5608. return token >= 58 && token <= 137;
  5609. }
  5610. function tokenComesBeforeExpression(token) {
  5611. return tokenBeforeExprs[token];
  5612. }
  5613. function tokenCanStartExpression(token) {
  5614. return tokenStartsExprs[token];
  5615. }
  5616. function tokenIsAssignment(token) {
  5617. return token >= 29 && token <= 33;
  5618. }
  5619. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  5620. return token >= 129 && token <= 131;
  5621. }
  5622. function tokenIsLoop(token) {
  5623. return token >= 90 && token <= 92;
  5624. }
  5625. function tokenIsKeyword(token) {
  5626. return token >= 58 && token <= 92;
  5627. }
  5628. function tokenIsOperator(token) {
  5629. return token >= 39 && token <= 59;
  5630. }
  5631. function tokenIsPostfix(token) {
  5632. return token === 34;
  5633. }
  5634. function tokenIsPrefix(token) {
  5635. return tokenPrefixes[token];
  5636. }
  5637. function tokenIsTSTypeOperator(token) {
  5638. return token >= 121 && token <= 123;
  5639. }
  5640. function tokenIsTSDeclarationStart(token) {
  5641. return token >= 124 && token <= 130;
  5642. }
  5643. function tokenLabelName(token) {
  5644. return tokenLabels[token];
  5645. }
  5646. function tokenOperatorPrecedence(token) {
  5647. return tokenBinops[token];
  5648. }
  5649. function tokenIsRightAssociative(token) {
  5650. return token === 57;
  5651. }
  5652. function tokenIsTemplate(token) {
  5653. return token >= 24 && token <= 25;
  5654. }
  5655. function getExportedToken(token) {
  5656. return tokenTypes[token];
  5657. }
  5658. {
  5659. tokenTypes[8].updateContext = context => {
  5660. context.pop();
  5661. };
  5662. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  5663. context.push(types.brace);
  5664. };
  5665. tokenTypes[22].updateContext = context => {
  5666. if (context[context.length - 1] === types.template) {
  5667. context.pop();
  5668. } else {
  5669. context.push(types.template);
  5670. }
  5671. };
  5672. tokenTypes[143].updateContext = context => {
  5673. context.push(types.j_expr, types.j_oTag);
  5674. };
  5675. }
  5676. 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-\u088f\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\u0c5c\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdc-\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-\u1c8a\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-\ua7dc\ua7f1-\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";
  5677. let nonASCIIidentifierChars = "\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\u0897-\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-\u1add\u1ae0-\u1aeb\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\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\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\uff65";
  5678. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  5679. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  5680. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  5681. 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, 4, 51, 13, 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, 7, 25, 39, 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, 39, 27, 10, 22, 251, 41, 7, 1, 17, 5, 57, 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, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 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, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 24, 43, 261, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7381, 42, 31, 98, 114, 8702, 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, 229, 29, 3, 0, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 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, 4381, 3, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489];
  5682. 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, 7, 9, 32, 4, 318, 1, 78, 5, 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, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 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, 199, 7, 137, 9, 54, 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, 55, 9, 266, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 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, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  5683. function isInAstralSet(code, set) {
  5684. let pos = 0x10000;
  5685. for (let i = 0, length = set.length; i < length; i += 2) {
  5686. pos += set[i];
  5687. if (pos > code) return false;
  5688. pos += set[i + 1];
  5689. if (pos >= code) return true;
  5690. }
  5691. return false;
  5692. }
  5693. function isIdentifierStart(code) {
  5694. if (code < 65) return code === 36;
  5695. if (code <= 90) return true;
  5696. if (code < 97) return code === 95;
  5697. if (code <= 122) return true;
  5698. if (code <= 0xffff) {
  5699. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  5700. }
  5701. return isInAstralSet(code, astralIdentifierStartCodes);
  5702. }
  5703. function isIdentifierChar(code) {
  5704. if (code < 48) return code === 36;
  5705. if (code < 58) return true;
  5706. if (code < 65) return false;
  5707. if (code <= 90) return true;
  5708. if (code < 97) return code === 95;
  5709. if (code <= 122) return true;
  5710. if (code <= 0xffff) {
  5711. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  5712. }
  5713. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  5714. }
  5715. const reservedWords = {
  5716. 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"],
  5717. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  5718. strictBind: ["eval", "arguments"]
  5719. };
  5720. const keywords = new Set(reservedWords.keyword);
  5721. const reservedWordsStrictSet = new Set(reservedWords.strict);
  5722. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  5723. function isReservedWord(word, inModule) {
  5724. return inModule && word === "await" || word === "enum";
  5725. }
  5726. function isStrictReservedWord(word, inModule) {
  5727. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  5728. }
  5729. function isStrictBindOnlyReservedWord(word) {
  5730. return reservedWordsStrictBindSet.has(word);
  5731. }
  5732. function isStrictBindReservedWord(word, inModule) {
  5733. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  5734. }
  5735. function isKeyword(word) {
  5736. return keywords.has(word);
  5737. }
  5738. function isIteratorStart(current, next, next2) {
  5739. return current === 64 && next === 64 && isIdentifierStart(next2);
  5740. }
  5741. 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"]);
  5742. function canBeReservedWord(word) {
  5743. return reservedWordLikeSet.has(word);
  5744. }
  5745. class Scope {
  5746. constructor(flags) {
  5747. this.flags = 0;
  5748. this.names = new Map();
  5749. this.firstLexicalName = "";
  5750. this.flags = flags;
  5751. }
  5752. }
  5753. class ScopeHandler {
  5754. constructor(parser, inModule) {
  5755. this.parser = void 0;
  5756. this.scopeStack = [];
  5757. this.inModule = void 0;
  5758. this.undefinedExports = new Map();
  5759. this.parser = parser;
  5760. this.inModule = inModule;
  5761. }
  5762. get inTopLevel() {
  5763. return (this.currentScope().flags & 1) > 0;
  5764. }
  5765. get inFunction() {
  5766. return (this.currentVarScopeFlags() & 2) > 0;
  5767. }
  5768. get allowSuper() {
  5769. return (this.currentThisScopeFlags() & 16) > 0;
  5770. }
  5771. get allowDirectSuper() {
  5772. return (this.currentThisScopeFlags() & 32) > 0;
  5773. }
  5774. get allowNewTarget() {
  5775. return (this.currentThisScopeFlags() & 512) > 0;
  5776. }
  5777. get inClass() {
  5778. return (this.currentThisScopeFlags() & 64) > 0;
  5779. }
  5780. get inClassAndNotInNonArrowFunction() {
  5781. const flags = this.currentThisScopeFlags();
  5782. return (flags & 64) > 0 && (flags & 2) === 0;
  5783. }
  5784. get inStaticBlock() {
  5785. for (let i = this.scopeStack.length - 1;; i--) {
  5786. const {
  5787. flags
  5788. } = this.scopeStack[i];
  5789. if (flags & 128) {
  5790. return true;
  5791. }
  5792. if (flags & (1667 | 64)) {
  5793. return false;
  5794. }
  5795. }
  5796. }
  5797. get inNonArrowFunction() {
  5798. return (this.currentThisScopeFlags() & 2) > 0;
  5799. }
  5800. get inBareCaseStatement() {
  5801. return (this.currentScope().flags & 256) > 0;
  5802. }
  5803. get treatFunctionsAsVar() {
  5804. return this.treatFunctionsAsVarInScope(this.currentScope());
  5805. }
  5806. createScope(flags) {
  5807. return new Scope(flags);
  5808. }
  5809. enter(flags) {
  5810. this.scopeStack.push(this.createScope(flags));
  5811. }
  5812. exit() {
  5813. const scope = this.scopeStack.pop();
  5814. return scope.flags;
  5815. }
  5816. treatFunctionsAsVarInScope(scope) {
  5817. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  5818. }
  5819. declareName(name, bindingType, loc) {
  5820. let scope = this.currentScope();
  5821. if (bindingType & 8 || bindingType & 16) {
  5822. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  5823. let type = scope.names.get(name) || 0;
  5824. if (bindingType & 16) {
  5825. type = type | 4;
  5826. } else {
  5827. if (!scope.firstLexicalName) {
  5828. scope.firstLexicalName = name;
  5829. }
  5830. type = type | 2;
  5831. }
  5832. scope.names.set(name, type);
  5833. if (bindingType & 8) {
  5834. this.maybeExportDefined(scope, name);
  5835. }
  5836. } else if (bindingType & 4) {
  5837. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  5838. scope = this.scopeStack[i];
  5839. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  5840. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  5841. this.maybeExportDefined(scope, name);
  5842. if (scope.flags & 1667) break;
  5843. }
  5844. }
  5845. if (this.parser.inModule && scope.flags & 1) {
  5846. this.undefinedExports.delete(name);
  5847. }
  5848. }
  5849. maybeExportDefined(scope, name) {
  5850. if (this.parser.inModule && scope.flags & 1) {
  5851. this.undefinedExports.delete(name);
  5852. }
  5853. }
  5854. checkRedeclarationInScope(scope, name, bindingType, loc) {
  5855. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  5856. this.parser.raise(Errors.VarRedeclaration, loc, {
  5857. identifierName: name
  5858. });
  5859. }
  5860. }
  5861. isRedeclaredInScope(scope, name, bindingType) {
  5862. if (!(bindingType & 1)) return false;
  5863. if (bindingType & 8) {
  5864. return scope.names.has(name);
  5865. }
  5866. const type = scope.names.get(name) || 0;
  5867. if (bindingType & 16) {
  5868. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  5869. }
  5870. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  5871. }
  5872. checkLocalExport(id) {
  5873. const {
  5874. name
  5875. } = id;
  5876. const topLevelScope = this.scopeStack[0];
  5877. if (!topLevelScope.names.has(name)) {
  5878. this.undefinedExports.set(name, id.loc.start);
  5879. }
  5880. }
  5881. currentScope() {
  5882. return this.scopeStack[this.scopeStack.length - 1];
  5883. }
  5884. currentVarScopeFlags() {
  5885. for (let i = this.scopeStack.length - 1;; i--) {
  5886. const {
  5887. flags
  5888. } = this.scopeStack[i];
  5889. if (flags & 1667) {
  5890. return flags;
  5891. }
  5892. }
  5893. }
  5894. currentThisScopeFlags() {
  5895. for (let i = this.scopeStack.length - 1;; i--) {
  5896. const {
  5897. flags
  5898. } = this.scopeStack[i];
  5899. if (flags & (1667 | 64) && !(flags & 4)) {
  5900. return flags;
  5901. }
  5902. }
  5903. }
  5904. }
  5905. class FlowScope extends Scope {
  5906. constructor(...args) {
  5907. super(...args);
  5908. this.declareFunctions = new Set();
  5909. }
  5910. }
  5911. class FlowScopeHandler extends ScopeHandler {
  5912. createScope(flags) {
  5913. return new FlowScope(flags);
  5914. }
  5915. declareName(name, bindingType, loc) {
  5916. const scope = this.currentScope();
  5917. if (bindingType & 2048) {
  5918. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  5919. this.maybeExportDefined(scope, name);
  5920. scope.declareFunctions.add(name);
  5921. return;
  5922. }
  5923. super.declareName(name, bindingType, loc);
  5924. }
  5925. isRedeclaredInScope(scope, name, bindingType) {
  5926. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  5927. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  5928. const type = scope.names.get(name);
  5929. return (type & 4) > 0 || (type & 2) > 0;
  5930. }
  5931. return false;
  5932. }
  5933. checkLocalExport(id) {
  5934. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  5935. super.checkLocalExport(id);
  5936. }
  5937. }
  5938. }
  5939. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  5940. const FlowErrors = ParseErrorEnum`flow`({
  5941. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  5942. 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.",
  5943. AssignReservedType: ({
  5944. reservedType
  5945. }) => `Cannot overwrite reserved type ${reservedType}.`,
  5946. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  5947. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  5948. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  5949. EnumBooleanMemberNotInitialized: ({
  5950. memberName,
  5951. enumName
  5952. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  5953. EnumDuplicateMemberName: ({
  5954. memberName,
  5955. enumName
  5956. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  5957. EnumInconsistentMemberValues: ({
  5958. enumName
  5959. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  5960. EnumInvalidExplicitType: ({
  5961. invalidEnumType,
  5962. enumName
  5963. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  5964. EnumInvalidExplicitTypeUnknownSupplied: ({
  5965. enumName
  5966. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  5967. EnumInvalidMemberInitializerPrimaryType: ({
  5968. enumName,
  5969. memberName,
  5970. explicitType
  5971. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  5972. EnumInvalidMemberInitializerSymbolType: ({
  5973. enumName,
  5974. memberName
  5975. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  5976. EnumInvalidMemberInitializerUnknownType: ({
  5977. enumName,
  5978. memberName
  5979. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  5980. EnumInvalidMemberName: ({
  5981. enumName,
  5982. memberName,
  5983. suggestion
  5984. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  5985. EnumNumberMemberNotInitialized: ({
  5986. enumName,
  5987. memberName
  5988. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  5989. EnumStringMemberInconsistentlyInitialized: ({
  5990. enumName
  5991. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  5992. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  5993. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  5994. 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.",
  5995. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  5996. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  5997. InexactVariance: "Explicit inexact syntax cannot have variance.",
  5998. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  5999. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  6000. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  6001. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  6002. PatternIsOptional: Object.assign({
  6003. message: "A binding pattern parameter cannot be optional in an implementation signature."
  6004. }, {
  6005. reasonCode: "OptionalBindingPattern"
  6006. }),
  6007. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  6008. SpreadVariance: "Spread properties cannot have variance.",
  6009. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  6010. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  6011. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  6012. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  6013. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  6014. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  6015. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  6016. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  6017. UnexpectedReservedType: ({
  6018. reservedType
  6019. }) => `Unexpected reserved type ${reservedType}.`,
  6020. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  6021. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  6022. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  6023. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  6024. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  6025. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  6026. UnsupportedDeclareExportKind: ({
  6027. unsupportedExportKind,
  6028. suggestion
  6029. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  6030. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  6031. UnterminatedFlowComment: "Unterminated flow-comment."
  6032. });
  6033. function isEsModuleType(bodyElement) {
  6034. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  6035. }
  6036. function hasTypeImportKind(node) {
  6037. return node.importKind === "type" || node.importKind === "typeof";
  6038. }
  6039. const exportSuggestions = {
  6040. const: "declare export var",
  6041. let: "declare export var",
  6042. type: "export type",
  6043. interface: "export interface"
  6044. };
  6045. function partition(list, test) {
  6046. const list1 = [];
  6047. const list2 = [];
  6048. for (let i = 0; i < list.length; i++) {
  6049. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  6050. }
  6051. return [list1, list2];
  6052. }
  6053. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  6054. var flow = superClass => class FlowParserMixin extends superClass {
  6055. constructor(...args) {
  6056. super(...args);
  6057. this.flowPragma = undefined;
  6058. }
  6059. getScopeHandler() {
  6060. return FlowScopeHandler;
  6061. }
  6062. shouldParseTypes() {
  6063. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  6064. }
  6065. finishToken(type, val) {
  6066. if (type !== 134 && type !== 13 && type !== 28) {
  6067. if (this.flowPragma === undefined) {
  6068. this.flowPragma = null;
  6069. }
  6070. }
  6071. super.finishToken(type, val);
  6072. }
  6073. addComment(comment) {
  6074. if (this.flowPragma === undefined) {
  6075. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  6076. if (!matches) ;else if (matches[1] === "flow") {
  6077. this.flowPragma = "flow";
  6078. } else if (matches[1] === "noflow") {
  6079. this.flowPragma = "noflow";
  6080. } else {
  6081. throw new Error("Unexpected flow pragma");
  6082. }
  6083. }
  6084. super.addComment(comment);
  6085. }
  6086. flowParseTypeInitialiser(tok) {
  6087. const oldInType = this.state.inType;
  6088. this.state.inType = true;
  6089. this.expect(tok || 14);
  6090. const type = this.flowParseType();
  6091. this.state.inType = oldInType;
  6092. return type;
  6093. }
  6094. flowParsePredicate() {
  6095. const node = this.startNode();
  6096. const moduloLoc = this.state.startLoc;
  6097. this.next();
  6098. this.expectContextual(110);
  6099. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  6100. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  6101. }
  6102. if (this.eat(10)) {
  6103. node.value = super.parseExpression();
  6104. this.expect(11);
  6105. return this.finishNode(node, "DeclaredPredicate");
  6106. } else {
  6107. return this.finishNode(node, "InferredPredicate");
  6108. }
  6109. }
  6110. flowParseTypeAndPredicateInitialiser() {
  6111. const oldInType = this.state.inType;
  6112. this.state.inType = true;
  6113. this.expect(14);
  6114. let type = null;
  6115. let predicate = null;
  6116. if (this.match(54)) {
  6117. this.state.inType = oldInType;
  6118. predicate = this.flowParsePredicate();
  6119. } else {
  6120. type = this.flowParseType();
  6121. this.state.inType = oldInType;
  6122. if (this.match(54)) {
  6123. predicate = this.flowParsePredicate();
  6124. }
  6125. }
  6126. return [type, predicate];
  6127. }
  6128. flowParseDeclareClass(node) {
  6129. this.next();
  6130. this.flowParseInterfaceish(node, true);
  6131. return this.finishNode(node, "DeclareClass");
  6132. }
  6133. flowParseDeclareFunction(node) {
  6134. this.next();
  6135. const id = node.id = this.parseIdentifier();
  6136. const typeNode = this.startNode();
  6137. const typeContainer = this.startNode();
  6138. if (this.match(47)) {
  6139. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  6140. } else {
  6141. typeNode.typeParameters = null;
  6142. }
  6143. this.expect(10);
  6144. const tmp = this.flowParseFunctionTypeParams();
  6145. typeNode.params = tmp.params;
  6146. typeNode.rest = tmp.rest;
  6147. typeNode.this = tmp._this;
  6148. this.expect(11);
  6149. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  6150. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  6151. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  6152. this.resetEndLocation(id);
  6153. this.semicolon();
  6154. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  6155. return this.finishNode(node, "DeclareFunction");
  6156. }
  6157. flowParseDeclare(node, insideModule) {
  6158. if (this.match(80)) {
  6159. return this.flowParseDeclareClass(node);
  6160. } else if (this.match(68)) {
  6161. return this.flowParseDeclareFunction(node);
  6162. } else if (this.match(74)) {
  6163. return this.flowParseDeclareVariable(node);
  6164. } else if (this.eatContextual(127)) {
  6165. if (this.match(16)) {
  6166. return this.flowParseDeclareModuleExports(node);
  6167. } else {
  6168. if (insideModule) {
  6169. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  6170. }
  6171. return this.flowParseDeclareModule(node);
  6172. }
  6173. } else if (this.isContextual(130)) {
  6174. return this.flowParseDeclareTypeAlias(node);
  6175. } else if (this.isContextual(131)) {
  6176. return this.flowParseDeclareOpaqueType(node);
  6177. } else if (this.isContextual(129)) {
  6178. return this.flowParseDeclareInterface(node);
  6179. } else if (this.match(82)) {
  6180. return this.flowParseDeclareExportDeclaration(node, insideModule);
  6181. }
  6182. throw this.unexpected();
  6183. }
  6184. flowParseDeclareVariable(node) {
  6185. this.next();
  6186. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  6187. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  6188. this.semicolon();
  6189. return this.finishNode(node, "DeclareVariable");
  6190. }
  6191. flowParseDeclareModule(node) {
  6192. this.scope.enter(0);
  6193. if (this.match(134)) {
  6194. node.id = super.parseExprAtom();
  6195. } else {
  6196. node.id = this.parseIdentifier();
  6197. }
  6198. const bodyNode = node.body = this.startNode();
  6199. const body = bodyNode.body = [];
  6200. this.expect(5);
  6201. while (!this.match(8)) {
  6202. const bodyNode = this.startNode();
  6203. if (this.match(83)) {
  6204. this.next();
  6205. if (!this.isContextual(130) && !this.match(87)) {
  6206. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  6207. }
  6208. body.push(super.parseImport(bodyNode));
  6209. } else {
  6210. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  6211. body.push(this.flowParseDeclare(bodyNode, true));
  6212. }
  6213. }
  6214. this.scope.exit();
  6215. this.expect(8);
  6216. this.finishNode(bodyNode, "BlockStatement");
  6217. let kind = null;
  6218. let hasModuleExport = false;
  6219. body.forEach(bodyElement => {
  6220. if (isEsModuleType(bodyElement)) {
  6221. if (kind === "CommonJS") {
  6222. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  6223. }
  6224. kind = "ES";
  6225. } else if (bodyElement.type === "DeclareModuleExports") {
  6226. if (hasModuleExport) {
  6227. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  6228. }
  6229. if (kind === "ES") {
  6230. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  6231. }
  6232. kind = "CommonJS";
  6233. hasModuleExport = true;
  6234. }
  6235. });
  6236. node.kind = kind || "CommonJS";
  6237. return this.finishNode(node, "DeclareModule");
  6238. }
  6239. flowParseDeclareExportDeclaration(node, insideModule) {
  6240. this.expect(82);
  6241. if (this.eat(65)) {
  6242. if (this.match(68) || this.match(80)) {
  6243. node.declaration = this.flowParseDeclare(this.startNode());
  6244. } else {
  6245. node.declaration = this.flowParseType();
  6246. this.semicolon();
  6247. }
  6248. node.default = true;
  6249. return this.finishNode(node, "DeclareExportDeclaration");
  6250. } else {
  6251. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  6252. const label = this.state.value;
  6253. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  6254. unsupportedExportKind: label,
  6255. suggestion: exportSuggestions[label]
  6256. });
  6257. }
  6258. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  6259. node.declaration = this.flowParseDeclare(this.startNode());
  6260. node.default = false;
  6261. return this.finishNode(node, "DeclareExportDeclaration");
  6262. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  6263. node = this.parseExport(node, null);
  6264. if (node.type === "ExportNamedDeclaration") {
  6265. node.default = false;
  6266. delete node.exportKind;
  6267. return this.castNodeTo(node, "DeclareExportDeclaration");
  6268. } else {
  6269. return this.castNodeTo(node, "DeclareExportAllDeclaration");
  6270. }
  6271. }
  6272. }
  6273. throw this.unexpected();
  6274. }
  6275. flowParseDeclareModuleExports(node) {
  6276. this.next();
  6277. this.expectContextual(111);
  6278. node.typeAnnotation = this.flowParseTypeAnnotation();
  6279. this.semicolon();
  6280. return this.finishNode(node, "DeclareModuleExports");
  6281. }
  6282. flowParseDeclareTypeAlias(node) {
  6283. this.next();
  6284. const finished = this.flowParseTypeAlias(node);
  6285. this.castNodeTo(finished, "DeclareTypeAlias");
  6286. return finished;
  6287. }
  6288. flowParseDeclareOpaqueType(node) {
  6289. this.next();
  6290. const finished = this.flowParseOpaqueType(node, true);
  6291. this.castNodeTo(finished, "DeclareOpaqueType");
  6292. return finished;
  6293. }
  6294. flowParseDeclareInterface(node) {
  6295. this.next();
  6296. this.flowParseInterfaceish(node, false);
  6297. return this.finishNode(node, "DeclareInterface");
  6298. }
  6299. flowParseInterfaceish(node, isClass) {
  6300. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  6301. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  6302. if (this.match(47)) {
  6303. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6304. } else {
  6305. node.typeParameters = null;
  6306. }
  6307. node.extends = [];
  6308. if (this.eat(81)) {
  6309. do {
  6310. node.extends.push(this.flowParseInterfaceExtends());
  6311. } while (!isClass && this.eat(12));
  6312. }
  6313. if (isClass) {
  6314. node.implements = [];
  6315. node.mixins = [];
  6316. if (this.eatContextual(117)) {
  6317. do {
  6318. node.mixins.push(this.flowParseInterfaceExtends());
  6319. } while (this.eat(12));
  6320. }
  6321. if (this.eatContextual(113)) {
  6322. do {
  6323. node.implements.push(this.flowParseInterfaceExtends());
  6324. } while (this.eat(12));
  6325. }
  6326. }
  6327. node.body = this.flowParseObjectType({
  6328. allowStatic: isClass,
  6329. allowExact: false,
  6330. allowSpread: false,
  6331. allowProto: isClass,
  6332. allowInexact: false
  6333. });
  6334. }
  6335. flowParseInterfaceExtends() {
  6336. const node = this.startNode();
  6337. node.id = this.flowParseQualifiedTypeIdentifier();
  6338. if (this.match(47)) {
  6339. node.typeParameters = this.flowParseTypeParameterInstantiation();
  6340. } else {
  6341. node.typeParameters = null;
  6342. }
  6343. return this.finishNode(node, "InterfaceExtends");
  6344. }
  6345. flowParseInterface(node) {
  6346. this.flowParseInterfaceish(node, false);
  6347. return this.finishNode(node, "InterfaceDeclaration");
  6348. }
  6349. checkNotUnderscore(word) {
  6350. if (word === "_") {
  6351. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  6352. }
  6353. }
  6354. checkReservedType(word, startLoc, declaration) {
  6355. if (!reservedTypes.has(word)) return;
  6356. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  6357. reservedType: word
  6358. });
  6359. }
  6360. flowParseRestrictedIdentifier(liberal, declaration) {
  6361. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  6362. return this.parseIdentifier(liberal);
  6363. }
  6364. flowParseTypeAlias(node) {
  6365. node.id = this.flowParseRestrictedIdentifier(false, true);
  6366. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  6367. if (this.match(47)) {
  6368. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6369. } else {
  6370. node.typeParameters = null;
  6371. }
  6372. node.right = this.flowParseTypeInitialiser(29);
  6373. this.semicolon();
  6374. return this.finishNode(node, "TypeAlias");
  6375. }
  6376. flowParseOpaqueType(node, declare) {
  6377. this.expectContextual(130);
  6378. node.id = this.flowParseRestrictedIdentifier(true, true);
  6379. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  6380. if (this.match(47)) {
  6381. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6382. } else {
  6383. node.typeParameters = null;
  6384. }
  6385. node.supertype = null;
  6386. if (this.match(14)) {
  6387. node.supertype = this.flowParseTypeInitialiser(14);
  6388. }
  6389. node.impltype = null;
  6390. if (!declare) {
  6391. node.impltype = this.flowParseTypeInitialiser(29);
  6392. }
  6393. this.semicolon();
  6394. return this.finishNode(node, "OpaqueType");
  6395. }
  6396. flowParseTypeParameter(requireDefault = false) {
  6397. const nodeStartLoc = this.state.startLoc;
  6398. const node = this.startNode();
  6399. const variance = this.flowParseVariance();
  6400. const ident = this.flowParseTypeAnnotatableIdentifier();
  6401. node.name = ident.name;
  6402. node.variance = variance;
  6403. node.bound = ident.typeAnnotation;
  6404. if (this.match(29)) {
  6405. this.eat(29);
  6406. node.default = this.flowParseType();
  6407. } else {
  6408. if (requireDefault) {
  6409. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  6410. }
  6411. }
  6412. return this.finishNode(node, "TypeParameter");
  6413. }
  6414. flowParseTypeParameterDeclaration() {
  6415. const oldInType = this.state.inType;
  6416. const node = this.startNode();
  6417. node.params = [];
  6418. this.state.inType = true;
  6419. if (this.match(47) || this.match(143)) {
  6420. this.next();
  6421. } else {
  6422. this.unexpected();
  6423. }
  6424. let defaultRequired = false;
  6425. do {
  6426. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  6427. node.params.push(typeParameter);
  6428. if (typeParameter.default) {
  6429. defaultRequired = true;
  6430. }
  6431. if (!this.match(48)) {
  6432. this.expect(12);
  6433. }
  6434. } while (!this.match(48));
  6435. this.expect(48);
  6436. this.state.inType = oldInType;
  6437. return this.finishNode(node, "TypeParameterDeclaration");
  6438. }
  6439. flowInTopLevelContext(cb) {
  6440. if (this.curContext() !== types.brace) {
  6441. const oldContext = this.state.context;
  6442. this.state.context = [oldContext[0]];
  6443. try {
  6444. return cb();
  6445. } finally {
  6446. this.state.context = oldContext;
  6447. }
  6448. } else {
  6449. return cb();
  6450. }
  6451. }
  6452. flowParseTypeParameterInstantiationInExpression() {
  6453. if (this.reScan_lt() !== 47) return;
  6454. return this.flowParseTypeParameterInstantiation();
  6455. }
  6456. flowParseTypeParameterInstantiation() {
  6457. const node = this.startNode();
  6458. const oldInType = this.state.inType;
  6459. this.state.inType = true;
  6460. node.params = [];
  6461. this.flowInTopLevelContext(() => {
  6462. this.expect(47);
  6463. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  6464. this.state.noAnonFunctionType = false;
  6465. while (!this.match(48)) {
  6466. node.params.push(this.flowParseType());
  6467. if (!this.match(48)) {
  6468. this.expect(12);
  6469. }
  6470. }
  6471. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6472. });
  6473. this.state.inType = oldInType;
  6474. if (!this.state.inType && this.curContext() === types.brace) {
  6475. this.reScan_lt_gt();
  6476. }
  6477. this.expect(48);
  6478. return this.finishNode(node, "TypeParameterInstantiation");
  6479. }
  6480. flowParseTypeParameterInstantiationCallOrNew() {
  6481. if (this.reScan_lt() !== 47) return null;
  6482. const node = this.startNode();
  6483. const oldInType = this.state.inType;
  6484. node.params = [];
  6485. this.state.inType = true;
  6486. this.expect(47);
  6487. while (!this.match(48)) {
  6488. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  6489. if (!this.match(48)) {
  6490. this.expect(12);
  6491. }
  6492. }
  6493. this.expect(48);
  6494. this.state.inType = oldInType;
  6495. return this.finishNode(node, "TypeParameterInstantiation");
  6496. }
  6497. flowParseInterfaceType() {
  6498. const node = this.startNode();
  6499. this.expectContextual(129);
  6500. node.extends = [];
  6501. if (this.eat(81)) {
  6502. do {
  6503. node.extends.push(this.flowParseInterfaceExtends());
  6504. } while (this.eat(12));
  6505. }
  6506. node.body = this.flowParseObjectType({
  6507. allowStatic: false,
  6508. allowExact: false,
  6509. allowSpread: false,
  6510. allowProto: false,
  6511. allowInexact: false
  6512. });
  6513. return this.finishNode(node, "InterfaceTypeAnnotation");
  6514. }
  6515. flowParseObjectPropertyKey() {
  6516. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  6517. }
  6518. flowParseObjectTypeIndexer(node, isStatic, variance) {
  6519. node.static = isStatic;
  6520. if (this.lookahead().type === 14) {
  6521. node.id = this.flowParseObjectPropertyKey();
  6522. node.key = this.flowParseTypeInitialiser();
  6523. } else {
  6524. node.id = null;
  6525. node.key = this.flowParseType();
  6526. }
  6527. this.expect(3);
  6528. node.value = this.flowParseTypeInitialiser();
  6529. node.variance = variance;
  6530. return this.finishNode(node, "ObjectTypeIndexer");
  6531. }
  6532. flowParseObjectTypeInternalSlot(node, isStatic) {
  6533. node.static = isStatic;
  6534. node.id = this.flowParseObjectPropertyKey();
  6535. this.expect(3);
  6536. this.expect(3);
  6537. if (this.match(47) || this.match(10)) {
  6538. node.method = true;
  6539. node.optional = false;
  6540. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  6541. } else {
  6542. node.method = false;
  6543. if (this.eat(17)) {
  6544. node.optional = true;
  6545. }
  6546. node.value = this.flowParseTypeInitialiser();
  6547. }
  6548. return this.finishNode(node, "ObjectTypeInternalSlot");
  6549. }
  6550. flowParseObjectTypeMethodish(node) {
  6551. node.params = [];
  6552. node.rest = null;
  6553. node.typeParameters = null;
  6554. node.this = null;
  6555. if (this.match(47)) {
  6556. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6557. }
  6558. this.expect(10);
  6559. if (this.match(78)) {
  6560. node.this = this.flowParseFunctionTypeParam(true);
  6561. node.this.name = null;
  6562. if (!this.match(11)) {
  6563. this.expect(12);
  6564. }
  6565. }
  6566. while (!this.match(11) && !this.match(21)) {
  6567. node.params.push(this.flowParseFunctionTypeParam(false));
  6568. if (!this.match(11)) {
  6569. this.expect(12);
  6570. }
  6571. }
  6572. if (this.eat(21)) {
  6573. node.rest = this.flowParseFunctionTypeParam(false);
  6574. }
  6575. this.expect(11);
  6576. node.returnType = this.flowParseTypeInitialiser();
  6577. return this.finishNode(node, "FunctionTypeAnnotation");
  6578. }
  6579. flowParseObjectTypeCallProperty(node, isStatic) {
  6580. const valueNode = this.startNode();
  6581. node.static = isStatic;
  6582. node.value = this.flowParseObjectTypeMethodish(valueNode);
  6583. return this.finishNode(node, "ObjectTypeCallProperty");
  6584. }
  6585. flowParseObjectType({
  6586. allowStatic,
  6587. allowExact,
  6588. allowSpread,
  6589. allowProto,
  6590. allowInexact
  6591. }) {
  6592. const oldInType = this.state.inType;
  6593. this.state.inType = true;
  6594. const nodeStart = this.startNode();
  6595. nodeStart.callProperties = [];
  6596. nodeStart.properties = [];
  6597. nodeStart.indexers = [];
  6598. nodeStart.internalSlots = [];
  6599. let endDelim;
  6600. let exact;
  6601. let inexact = false;
  6602. if (allowExact && this.match(6)) {
  6603. this.expect(6);
  6604. endDelim = 9;
  6605. exact = true;
  6606. } else {
  6607. this.expect(5);
  6608. endDelim = 8;
  6609. exact = false;
  6610. }
  6611. nodeStart.exact = exact;
  6612. while (!this.match(endDelim)) {
  6613. let isStatic = false;
  6614. let protoStartLoc = null;
  6615. let inexactStartLoc = null;
  6616. const node = this.startNode();
  6617. if (allowProto && this.isContextual(118)) {
  6618. const lookahead = this.lookahead();
  6619. if (lookahead.type !== 14 && lookahead.type !== 17) {
  6620. this.next();
  6621. protoStartLoc = this.state.startLoc;
  6622. allowStatic = false;
  6623. }
  6624. }
  6625. if (allowStatic && this.isContextual(106)) {
  6626. const lookahead = this.lookahead();
  6627. if (lookahead.type !== 14 && lookahead.type !== 17) {
  6628. this.next();
  6629. isStatic = true;
  6630. }
  6631. }
  6632. const variance = this.flowParseVariance();
  6633. if (this.eat(0)) {
  6634. if (protoStartLoc != null) {
  6635. this.unexpected(protoStartLoc);
  6636. }
  6637. if (this.eat(0)) {
  6638. if (variance) {
  6639. this.unexpected(variance.loc.start);
  6640. }
  6641. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  6642. } else {
  6643. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  6644. }
  6645. } else if (this.match(10) || this.match(47)) {
  6646. if (protoStartLoc != null) {
  6647. this.unexpected(protoStartLoc);
  6648. }
  6649. if (variance) {
  6650. this.unexpected(variance.loc.start);
  6651. }
  6652. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  6653. } else {
  6654. let kind = "init";
  6655. if (this.isContextual(99) || this.isContextual(104)) {
  6656. const lookahead = this.lookahead();
  6657. if (tokenIsLiteralPropertyName(lookahead.type)) {
  6658. kind = this.state.value;
  6659. this.next();
  6660. }
  6661. }
  6662. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  6663. if (propOrInexact === null) {
  6664. inexact = true;
  6665. inexactStartLoc = this.state.lastTokStartLoc;
  6666. } else {
  6667. nodeStart.properties.push(propOrInexact);
  6668. }
  6669. }
  6670. this.flowObjectTypeSemicolon();
  6671. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  6672. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  6673. }
  6674. }
  6675. this.expect(endDelim);
  6676. if (allowSpread) {
  6677. nodeStart.inexact = inexact;
  6678. }
  6679. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  6680. this.state.inType = oldInType;
  6681. return out;
  6682. }
  6683. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  6684. if (this.eat(21)) {
  6685. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  6686. if (isInexactToken) {
  6687. if (!allowSpread) {
  6688. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  6689. } else if (!allowInexact) {
  6690. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  6691. }
  6692. if (variance) {
  6693. this.raise(FlowErrors.InexactVariance, variance);
  6694. }
  6695. return null;
  6696. }
  6697. if (!allowSpread) {
  6698. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  6699. }
  6700. if (protoStartLoc != null) {
  6701. this.unexpected(protoStartLoc);
  6702. }
  6703. if (variance) {
  6704. this.raise(FlowErrors.SpreadVariance, variance);
  6705. }
  6706. node.argument = this.flowParseType();
  6707. return this.finishNode(node, "ObjectTypeSpreadProperty");
  6708. } else {
  6709. node.key = this.flowParseObjectPropertyKey();
  6710. node.static = isStatic;
  6711. node.proto = protoStartLoc != null;
  6712. node.kind = kind;
  6713. let optional = false;
  6714. if (this.match(47) || this.match(10)) {
  6715. node.method = true;
  6716. if (protoStartLoc != null) {
  6717. this.unexpected(protoStartLoc);
  6718. }
  6719. if (variance) {
  6720. this.unexpected(variance.loc.start);
  6721. }
  6722. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  6723. if (kind === "get" || kind === "set") {
  6724. this.flowCheckGetterSetterParams(node);
  6725. }
  6726. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  6727. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  6728. }
  6729. } else {
  6730. if (kind !== "init") this.unexpected();
  6731. node.method = false;
  6732. if (this.eat(17)) {
  6733. optional = true;
  6734. }
  6735. node.value = this.flowParseTypeInitialiser();
  6736. node.variance = variance;
  6737. }
  6738. node.optional = optional;
  6739. return this.finishNode(node, "ObjectTypeProperty");
  6740. }
  6741. }
  6742. flowCheckGetterSetterParams(property) {
  6743. const paramCount = property.kind === "get" ? 0 : 1;
  6744. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  6745. if (property.value.this) {
  6746. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  6747. }
  6748. if (length !== paramCount) {
  6749. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  6750. }
  6751. if (property.kind === "set" && property.value.rest) {
  6752. this.raise(Errors.BadSetterRestParameter, property);
  6753. }
  6754. }
  6755. flowObjectTypeSemicolon() {
  6756. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  6757. this.unexpected();
  6758. }
  6759. }
  6760. flowParseQualifiedTypeIdentifier(startLoc, id) {
  6761. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  6762. let node = id || this.flowParseRestrictedIdentifier(true);
  6763. while (this.eat(16)) {
  6764. const node2 = this.startNodeAt(startLoc);
  6765. node2.qualification = node;
  6766. node2.id = this.flowParseRestrictedIdentifier(true);
  6767. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  6768. }
  6769. return node;
  6770. }
  6771. flowParseGenericType(startLoc, id) {
  6772. const node = this.startNodeAt(startLoc);
  6773. node.typeParameters = null;
  6774. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  6775. if (this.match(47)) {
  6776. node.typeParameters = this.flowParseTypeParameterInstantiation();
  6777. }
  6778. return this.finishNode(node, "GenericTypeAnnotation");
  6779. }
  6780. flowParseTypeofType() {
  6781. const node = this.startNode();
  6782. this.expect(87);
  6783. node.argument = this.flowParsePrimaryType();
  6784. return this.finishNode(node, "TypeofTypeAnnotation");
  6785. }
  6786. flowParseTupleType() {
  6787. const node = this.startNode();
  6788. node.types = [];
  6789. this.expect(0);
  6790. while (this.state.pos < this.length && !this.match(3)) {
  6791. node.types.push(this.flowParseType());
  6792. if (this.match(3)) break;
  6793. this.expect(12);
  6794. }
  6795. this.expect(3);
  6796. return this.finishNode(node, "TupleTypeAnnotation");
  6797. }
  6798. flowParseFunctionTypeParam(first) {
  6799. let name = null;
  6800. let optional = false;
  6801. let typeAnnotation = null;
  6802. const node = this.startNode();
  6803. const lh = this.lookahead();
  6804. const isThis = this.state.type === 78;
  6805. if (lh.type === 14 || lh.type === 17) {
  6806. if (isThis && !first) {
  6807. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  6808. }
  6809. name = this.parseIdentifier(isThis);
  6810. if (this.eat(17)) {
  6811. optional = true;
  6812. if (isThis) {
  6813. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  6814. }
  6815. }
  6816. typeAnnotation = this.flowParseTypeInitialiser();
  6817. } else {
  6818. typeAnnotation = this.flowParseType();
  6819. }
  6820. node.name = name;
  6821. node.optional = optional;
  6822. node.typeAnnotation = typeAnnotation;
  6823. return this.finishNode(node, "FunctionTypeParam");
  6824. }
  6825. reinterpretTypeAsFunctionTypeParam(type) {
  6826. const node = this.startNodeAt(type.loc.start);
  6827. node.name = null;
  6828. node.optional = false;
  6829. node.typeAnnotation = type;
  6830. return this.finishNode(node, "FunctionTypeParam");
  6831. }
  6832. flowParseFunctionTypeParams(params = []) {
  6833. let rest = null;
  6834. let _this = null;
  6835. if (this.match(78)) {
  6836. _this = this.flowParseFunctionTypeParam(true);
  6837. _this.name = null;
  6838. if (!this.match(11)) {
  6839. this.expect(12);
  6840. }
  6841. }
  6842. while (!this.match(11) && !this.match(21)) {
  6843. params.push(this.flowParseFunctionTypeParam(false));
  6844. if (!this.match(11)) {
  6845. this.expect(12);
  6846. }
  6847. }
  6848. if (this.eat(21)) {
  6849. rest = this.flowParseFunctionTypeParam(false);
  6850. }
  6851. return {
  6852. params,
  6853. rest,
  6854. _this
  6855. };
  6856. }
  6857. flowIdentToTypeAnnotation(startLoc, node, id) {
  6858. switch (id.name) {
  6859. case "any":
  6860. return this.finishNode(node, "AnyTypeAnnotation");
  6861. case "bool":
  6862. case "boolean":
  6863. return this.finishNode(node, "BooleanTypeAnnotation");
  6864. case "mixed":
  6865. return this.finishNode(node, "MixedTypeAnnotation");
  6866. case "empty":
  6867. return this.finishNode(node, "EmptyTypeAnnotation");
  6868. case "number":
  6869. return this.finishNode(node, "NumberTypeAnnotation");
  6870. case "string":
  6871. return this.finishNode(node, "StringTypeAnnotation");
  6872. case "symbol":
  6873. return this.finishNode(node, "SymbolTypeAnnotation");
  6874. default:
  6875. this.checkNotUnderscore(id.name);
  6876. return this.flowParseGenericType(startLoc, id);
  6877. }
  6878. }
  6879. flowParsePrimaryType() {
  6880. const startLoc = this.state.startLoc;
  6881. const node = this.startNode();
  6882. let tmp;
  6883. let type;
  6884. let isGroupedType = false;
  6885. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  6886. switch (this.state.type) {
  6887. case 5:
  6888. return this.flowParseObjectType({
  6889. allowStatic: false,
  6890. allowExact: false,
  6891. allowSpread: true,
  6892. allowProto: false,
  6893. allowInexact: true
  6894. });
  6895. case 6:
  6896. return this.flowParseObjectType({
  6897. allowStatic: false,
  6898. allowExact: true,
  6899. allowSpread: true,
  6900. allowProto: false,
  6901. allowInexact: false
  6902. });
  6903. case 0:
  6904. this.state.noAnonFunctionType = false;
  6905. type = this.flowParseTupleType();
  6906. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6907. return type;
  6908. case 47:
  6909. {
  6910. const node = this.startNode();
  6911. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6912. this.expect(10);
  6913. tmp = this.flowParseFunctionTypeParams();
  6914. node.params = tmp.params;
  6915. node.rest = tmp.rest;
  6916. node.this = tmp._this;
  6917. this.expect(11);
  6918. this.expect(19);
  6919. node.returnType = this.flowParseType();
  6920. return this.finishNode(node, "FunctionTypeAnnotation");
  6921. }
  6922. case 10:
  6923. {
  6924. const node = this.startNode();
  6925. this.next();
  6926. if (!this.match(11) && !this.match(21)) {
  6927. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  6928. const token = this.lookahead().type;
  6929. isGroupedType = token !== 17 && token !== 14;
  6930. } else {
  6931. isGroupedType = true;
  6932. }
  6933. }
  6934. if (isGroupedType) {
  6935. this.state.noAnonFunctionType = false;
  6936. type = this.flowParseType();
  6937. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6938. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  6939. this.expect(11);
  6940. return type;
  6941. } else {
  6942. this.eat(12);
  6943. }
  6944. }
  6945. if (type) {
  6946. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  6947. } else {
  6948. tmp = this.flowParseFunctionTypeParams();
  6949. }
  6950. node.params = tmp.params;
  6951. node.rest = tmp.rest;
  6952. node.this = tmp._this;
  6953. this.expect(11);
  6954. this.expect(19);
  6955. node.returnType = this.flowParseType();
  6956. node.typeParameters = null;
  6957. return this.finishNode(node, "FunctionTypeAnnotation");
  6958. }
  6959. case 134:
  6960. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  6961. case 85:
  6962. case 86:
  6963. node.value = this.match(85);
  6964. this.next();
  6965. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  6966. case 53:
  6967. if (this.state.value === "-") {
  6968. this.next();
  6969. if (this.match(135)) {
  6970. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  6971. }
  6972. if (this.match(136)) {
  6973. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  6974. }
  6975. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  6976. }
  6977. throw this.unexpected();
  6978. case 135:
  6979. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  6980. case 136:
  6981. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  6982. case 88:
  6983. this.next();
  6984. return this.finishNode(node, "VoidTypeAnnotation");
  6985. case 84:
  6986. this.next();
  6987. return this.finishNode(node, "NullLiteralTypeAnnotation");
  6988. case 78:
  6989. this.next();
  6990. return this.finishNode(node, "ThisTypeAnnotation");
  6991. case 55:
  6992. this.next();
  6993. return this.finishNode(node, "ExistsTypeAnnotation");
  6994. case 87:
  6995. return this.flowParseTypeofType();
  6996. default:
  6997. if (tokenIsKeyword(this.state.type)) {
  6998. const label = tokenLabelName(this.state.type);
  6999. this.next();
  7000. return super.createIdentifier(node, label);
  7001. } else if (tokenIsIdentifier(this.state.type)) {
  7002. if (this.isContextual(129)) {
  7003. return this.flowParseInterfaceType();
  7004. }
  7005. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  7006. }
  7007. }
  7008. throw this.unexpected();
  7009. }
  7010. flowParsePostfixType() {
  7011. const startLoc = this.state.startLoc;
  7012. let type = this.flowParsePrimaryType();
  7013. let seenOptionalIndexedAccess = false;
  7014. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  7015. const node = this.startNodeAt(startLoc);
  7016. const optional = this.eat(18);
  7017. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  7018. this.expect(0);
  7019. if (!optional && this.match(3)) {
  7020. node.elementType = type;
  7021. this.next();
  7022. type = this.finishNode(node, "ArrayTypeAnnotation");
  7023. } else {
  7024. node.objectType = type;
  7025. node.indexType = this.flowParseType();
  7026. this.expect(3);
  7027. if (seenOptionalIndexedAccess) {
  7028. node.optional = optional;
  7029. type = this.finishNode(node, "OptionalIndexedAccessType");
  7030. } else {
  7031. type = this.finishNode(node, "IndexedAccessType");
  7032. }
  7033. }
  7034. }
  7035. return type;
  7036. }
  7037. flowParsePrefixType() {
  7038. const node = this.startNode();
  7039. if (this.eat(17)) {
  7040. node.typeAnnotation = this.flowParsePrefixType();
  7041. return this.finishNode(node, "NullableTypeAnnotation");
  7042. } else {
  7043. return this.flowParsePostfixType();
  7044. }
  7045. }
  7046. flowParseAnonFunctionWithoutParens() {
  7047. const param = this.flowParsePrefixType();
  7048. if (!this.state.noAnonFunctionType && this.eat(19)) {
  7049. const node = this.startNodeAt(param.loc.start);
  7050. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  7051. node.rest = null;
  7052. node.this = null;
  7053. node.returnType = this.flowParseType();
  7054. node.typeParameters = null;
  7055. return this.finishNode(node, "FunctionTypeAnnotation");
  7056. }
  7057. return param;
  7058. }
  7059. flowParseIntersectionType() {
  7060. const node = this.startNode();
  7061. this.eat(45);
  7062. const type = this.flowParseAnonFunctionWithoutParens();
  7063. node.types = [type];
  7064. while (this.eat(45)) {
  7065. node.types.push(this.flowParseAnonFunctionWithoutParens());
  7066. }
  7067. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  7068. }
  7069. flowParseUnionType() {
  7070. const node = this.startNode();
  7071. this.eat(43);
  7072. const type = this.flowParseIntersectionType();
  7073. node.types = [type];
  7074. while (this.eat(43)) {
  7075. node.types.push(this.flowParseIntersectionType());
  7076. }
  7077. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  7078. }
  7079. flowParseType() {
  7080. const oldInType = this.state.inType;
  7081. this.state.inType = true;
  7082. const type = this.flowParseUnionType();
  7083. this.state.inType = oldInType;
  7084. return type;
  7085. }
  7086. flowParseTypeOrImplicitInstantiation() {
  7087. if (this.state.type === 132 && this.state.value === "_") {
  7088. const startLoc = this.state.startLoc;
  7089. const node = this.parseIdentifier();
  7090. return this.flowParseGenericType(startLoc, node);
  7091. } else {
  7092. return this.flowParseType();
  7093. }
  7094. }
  7095. flowParseTypeAnnotation() {
  7096. const node = this.startNode();
  7097. node.typeAnnotation = this.flowParseTypeInitialiser();
  7098. return this.finishNode(node, "TypeAnnotation");
  7099. }
  7100. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  7101. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  7102. if (this.match(14)) {
  7103. ident.typeAnnotation = this.flowParseTypeAnnotation();
  7104. this.resetEndLocation(ident);
  7105. }
  7106. return ident;
  7107. }
  7108. typeCastToParameter(node) {
  7109. node.expression.typeAnnotation = node.typeAnnotation;
  7110. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  7111. return node.expression;
  7112. }
  7113. flowParseVariance() {
  7114. let variance = null;
  7115. if (this.match(53)) {
  7116. variance = this.startNode();
  7117. if (this.state.value === "+") {
  7118. variance.kind = "plus";
  7119. } else {
  7120. variance.kind = "minus";
  7121. }
  7122. this.next();
  7123. return this.finishNode(variance, "Variance");
  7124. }
  7125. return variance;
  7126. }
  7127. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  7128. if (allowExpressionBody) {
  7129. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  7130. return;
  7131. }
  7132. super.parseFunctionBody(node, false, isMethod);
  7133. }
  7134. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  7135. if (this.match(14)) {
  7136. const typeNode = this.startNode();
  7137. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  7138. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  7139. }
  7140. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  7141. }
  7142. parseStatementLike(flags) {
  7143. if (this.state.strict && this.isContextual(129)) {
  7144. const lookahead = this.lookahead();
  7145. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  7146. const node = this.startNode();
  7147. this.next();
  7148. return this.flowParseInterface(node);
  7149. }
  7150. } else if (this.isContextual(126)) {
  7151. const node = this.startNode();
  7152. this.next();
  7153. return this.flowParseEnumDeclaration(node);
  7154. }
  7155. const stmt = super.parseStatementLike(flags);
  7156. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  7157. this.flowPragma = null;
  7158. }
  7159. return stmt;
  7160. }
  7161. parseExpressionStatement(node, expr, decorators) {
  7162. if (expr.type === "Identifier") {
  7163. if (expr.name === "declare") {
  7164. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  7165. return this.flowParseDeclare(node);
  7166. }
  7167. } else if (tokenIsIdentifier(this.state.type)) {
  7168. if (expr.name === "interface") {
  7169. return this.flowParseInterface(node);
  7170. } else if (expr.name === "type") {
  7171. return this.flowParseTypeAlias(node);
  7172. } else if (expr.name === "opaque") {
  7173. return this.flowParseOpaqueType(node, false);
  7174. }
  7175. }
  7176. }
  7177. return super.parseExpressionStatement(node, expr, decorators);
  7178. }
  7179. shouldParseExportDeclaration() {
  7180. const {
  7181. type
  7182. } = this.state;
  7183. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  7184. return !this.state.containsEsc;
  7185. }
  7186. return super.shouldParseExportDeclaration();
  7187. }
  7188. isExportDefaultSpecifier() {
  7189. const {
  7190. type
  7191. } = this.state;
  7192. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  7193. return this.state.containsEsc;
  7194. }
  7195. return super.isExportDefaultSpecifier();
  7196. }
  7197. parseExportDefaultExpression() {
  7198. if (this.isContextual(126)) {
  7199. const node = this.startNode();
  7200. this.next();
  7201. return this.flowParseEnumDeclaration(node);
  7202. }
  7203. return super.parseExportDefaultExpression();
  7204. }
  7205. parseConditional(expr, startLoc, refExpressionErrors) {
  7206. if (!this.match(17)) return expr;
  7207. if (this.state.maybeInArrowParameters) {
  7208. const nextCh = this.lookaheadCharCode();
  7209. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  7210. this.setOptionalParametersError(refExpressionErrors);
  7211. return expr;
  7212. }
  7213. }
  7214. this.expect(17);
  7215. const state = this.state.clone();
  7216. const originalNoArrowAt = this.state.noArrowAt;
  7217. const node = this.startNodeAt(startLoc);
  7218. let {
  7219. consequent,
  7220. failed
  7221. } = this.tryParseConditionalConsequent();
  7222. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  7223. if (failed || invalid.length > 0) {
  7224. const noArrowAt = [...originalNoArrowAt];
  7225. if (invalid.length > 0) {
  7226. this.state = state;
  7227. this.state.noArrowAt = noArrowAt;
  7228. for (let i = 0; i < invalid.length; i++) {
  7229. noArrowAt.push(invalid[i].start);
  7230. }
  7231. ({
  7232. consequent,
  7233. failed
  7234. } = this.tryParseConditionalConsequent());
  7235. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  7236. }
  7237. if (failed && valid.length > 1) {
  7238. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  7239. }
  7240. if (failed && valid.length === 1) {
  7241. this.state = state;
  7242. noArrowAt.push(valid[0].start);
  7243. this.state.noArrowAt = noArrowAt;
  7244. ({
  7245. consequent,
  7246. failed
  7247. } = this.tryParseConditionalConsequent());
  7248. }
  7249. }
  7250. this.getArrowLikeExpressions(consequent, true);
  7251. this.state.noArrowAt = originalNoArrowAt;
  7252. this.expect(14);
  7253. node.test = expr;
  7254. node.consequent = consequent;
  7255. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  7256. return this.finishNode(node, "ConditionalExpression");
  7257. }
  7258. tryParseConditionalConsequent() {
  7259. this.state.noArrowParamsConversionAt.push(this.state.start);
  7260. const consequent = this.parseMaybeAssignAllowIn();
  7261. const failed = !this.match(14);
  7262. this.state.noArrowParamsConversionAt.pop();
  7263. return {
  7264. consequent,
  7265. failed
  7266. };
  7267. }
  7268. getArrowLikeExpressions(node, disallowInvalid) {
  7269. const stack = [node];
  7270. const arrows = [];
  7271. while (stack.length !== 0) {
  7272. const node = stack.pop();
  7273. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  7274. if (node.typeParameters || !node.returnType) {
  7275. this.finishArrowValidation(node);
  7276. } else {
  7277. arrows.push(node);
  7278. }
  7279. stack.push(node.body);
  7280. } else if (node.type === "ConditionalExpression") {
  7281. stack.push(node.consequent);
  7282. stack.push(node.alternate);
  7283. }
  7284. }
  7285. if (disallowInvalid) {
  7286. arrows.forEach(node => this.finishArrowValidation(node));
  7287. return [arrows, []];
  7288. }
  7289. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  7290. }
  7291. finishArrowValidation(node) {
  7292. var _node$extra;
  7293. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  7294. this.scope.enter(514 | 4);
  7295. super.checkParams(node, false, true);
  7296. this.scope.exit();
  7297. }
  7298. forwardNoArrowParamsConversionAt(node, parse) {
  7299. let result;
  7300. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  7301. this.state.noArrowParamsConversionAt.push(this.state.start);
  7302. result = parse();
  7303. this.state.noArrowParamsConversionAt.pop();
  7304. } else {
  7305. result = parse();
  7306. }
  7307. return result;
  7308. }
  7309. parseParenItem(node, startLoc) {
  7310. const newNode = super.parseParenItem(node, startLoc);
  7311. if (this.eat(17)) {
  7312. newNode.optional = true;
  7313. this.resetEndLocation(node);
  7314. }
  7315. if (this.match(14)) {
  7316. const typeCastNode = this.startNodeAt(startLoc);
  7317. typeCastNode.expression = newNode;
  7318. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  7319. return this.finishNode(typeCastNode, "TypeCastExpression");
  7320. }
  7321. return newNode;
  7322. }
  7323. assertModuleNodeAllowed(node) {
  7324. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  7325. return;
  7326. }
  7327. super.assertModuleNodeAllowed(node);
  7328. }
  7329. parseExportDeclaration(node) {
  7330. if (this.isContextual(130)) {
  7331. node.exportKind = "type";
  7332. const declarationNode = this.startNode();
  7333. this.next();
  7334. if (this.match(5)) {
  7335. node.specifiers = this.parseExportSpecifiers(true);
  7336. super.parseExportFrom(node);
  7337. return null;
  7338. } else {
  7339. return this.flowParseTypeAlias(declarationNode);
  7340. }
  7341. } else if (this.isContextual(131)) {
  7342. node.exportKind = "type";
  7343. const declarationNode = this.startNode();
  7344. this.next();
  7345. return this.flowParseOpaqueType(declarationNode, false);
  7346. } else if (this.isContextual(129)) {
  7347. node.exportKind = "type";
  7348. const declarationNode = this.startNode();
  7349. this.next();
  7350. return this.flowParseInterface(declarationNode);
  7351. } else if (this.isContextual(126)) {
  7352. node.exportKind = "value";
  7353. const declarationNode = this.startNode();
  7354. this.next();
  7355. return this.flowParseEnumDeclaration(declarationNode);
  7356. } else {
  7357. return super.parseExportDeclaration(node);
  7358. }
  7359. }
  7360. eatExportStar(node) {
  7361. if (super.eatExportStar(node)) return true;
  7362. if (this.isContextual(130) && this.lookahead().type === 55) {
  7363. node.exportKind = "type";
  7364. this.next();
  7365. this.next();
  7366. return true;
  7367. }
  7368. return false;
  7369. }
  7370. maybeParseExportNamespaceSpecifier(node) {
  7371. const {
  7372. startLoc
  7373. } = this.state;
  7374. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  7375. if (hasNamespace && node.exportKind === "type") {
  7376. this.unexpected(startLoc);
  7377. }
  7378. return hasNamespace;
  7379. }
  7380. parseClassId(node, isStatement, optionalId) {
  7381. super.parseClassId(node, isStatement, optionalId);
  7382. if (this.match(47)) {
  7383. node.typeParameters = this.flowParseTypeParameterDeclaration();
  7384. }
  7385. }
  7386. parseClassMember(classBody, member, state) {
  7387. const {
  7388. startLoc
  7389. } = this.state;
  7390. if (this.isContextual(125)) {
  7391. if (super.parseClassMemberFromModifier(classBody, member)) {
  7392. return;
  7393. }
  7394. member.declare = true;
  7395. }
  7396. super.parseClassMember(classBody, member, state);
  7397. if (member.declare) {
  7398. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  7399. this.raise(FlowErrors.DeclareClassElement, startLoc);
  7400. } else if (member.value) {
  7401. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  7402. }
  7403. }
  7404. }
  7405. isIterator(word) {
  7406. return word === "iterator" || word === "asyncIterator";
  7407. }
  7408. readIterator() {
  7409. const word = super.readWord1();
  7410. const fullWord = "@@" + word;
  7411. if (!this.isIterator(word) || !this.state.inType) {
  7412. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  7413. identifierName: fullWord
  7414. });
  7415. }
  7416. this.finishToken(132, fullWord);
  7417. }
  7418. getTokenFromCode(code) {
  7419. const next = this.input.charCodeAt(this.state.pos + 1);
  7420. if (code === 123 && next === 124) {
  7421. this.finishOp(6, 2);
  7422. } else if (this.state.inType && (code === 62 || code === 60)) {
  7423. this.finishOp(code === 62 ? 48 : 47, 1);
  7424. } else if (this.state.inType && code === 63) {
  7425. if (next === 46) {
  7426. this.finishOp(18, 2);
  7427. } else {
  7428. this.finishOp(17, 1);
  7429. }
  7430. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  7431. this.state.pos += 2;
  7432. this.readIterator();
  7433. } else {
  7434. super.getTokenFromCode(code);
  7435. }
  7436. }
  7437. isAssignable(node, isBinding) {
  7438. if (node.type === "TypeCastExpression") {
  7439. return this.isAssignable(node.expression, isBinding);
  7440. } else {
  7441. return super.isAssignable(node, isBinding);
  7442. }
  7443. }
  7444. toAssignable(node, isLHS = false) {
  7445. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  7446. node.left = this.typeCastToParameter(node.left);
  7447. }
  7448. super.toAssignable(node, isLHS);
  7449. }
  7450. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7451. for (let i = 0; i < exprList.length; i++) {
  7452. const expr = exprList[i];
  7453. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  7454. exprList[i] = this.typeCastToParameter(expr);
  7455. }
  7456. }
  7457. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  7458. }
  7459. toReferencedList(exprList, isParenthesizedExpr) {
  7460. for (let i = 0; i < exprList.length; i++) {
  7461. var _expr$extra;
  7462. const expr = exprList[i];
  7463. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  7464. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  7465. }
  7466. }
  7467. return exprList;
  7468. }
  7469. parseArrayLike(close, isTuple, refExpressionErrors) {
  7470. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  7471. if (refExpressionErrors != null && !this.state.maybeInArrowParameters) {
  7472. this.toReferencedList(node.elements);
  7473. }
  7474. return node;
  7475. }
  7476. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  7477. return type === "TypeCastExpression" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  7478. }
  7479. parseClassProperty(node) {
  7480. if (this.match(14)) {
  7481. node.typeAnnotation = this.flowParseTypeAnnotation();
  7482. }
  7483. return super.parseClassProperty(node);
  7484. }
  7485. parseClassPrivateProperty(node) {
  7486. if (this.match(14)) {
  7487. node.typeAnnotation = this.flowParseTypeAnnotation();
  7488. }
  7489. return super.parseClassPrivateProperty(node);
  7490. }
  7491. isClassMethod() {
  7492. return this.match(47) || super.isClassMethod();
  7493. }
  7494. isClassProperty() {
  7495. return this.match(14) || super.isClassProperty();
  7496. }
  7497. isNonstaticConstructor(method) {
  7498. return !this.match(14) && super.isNonstaticConstructor(method);
  7499. }
  7500. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  7501. if (method.variance) {
  7502. this.unexpected(method.variance.loc.start);
  7503. }
  7504. delete method.variance;
  7505. if (this.match(47)) {
  7506. method.typeParameters = this.flowParseTypeParameterDeclaration();
  7507. }
  7508. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  7509. if (method.params && isConstructor) {
  7510. const params = method.params;
  7511. if (params.length > 0 && this.isThisParam(params[0])) {
  7512. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  7513. }
  7514. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  7515. const params = method.value.params;
  7516. if (params.length > 0 && this.isThisParam(params[0])) {
  7517. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  7518. }
  7519. }
  7520. }
  7521. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  7522. if (method.variance) {
  7523. this.unexpected(method.variance.loc.start);
  7524. }
  7525. delete method.variance;
  7526. if (this.match(47)) {
  7527. method.typeParameters = this.flowParseTypeParameterDeclaration();
  7528. }
  7529. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  7530. }
  7531. parseClassSuper(node) {
  7532. super.parseClassSuper(node);
  7533. if (node.superClass && (this.match(47) || this.match(51))) {
  7534. {
  7535. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  7536. }
  7537. }
  7538. if (this.isContextual(113)) {
  7539. this.next();
  7540. const implemented = node.implements = [];
  7541. do {
  7542. const node = this.startNode();
  7543. node.id = this.flowParseRestrictedIdentifier(true);
  7544. if (this.match(47)) {
  7545. node.typeParameters = this.flowParseTypeParameterInstantiation();
  7546. } else {
  7547. node.typeParameters = null;
  7548. }
  7549. implemented.push(this.finishNode(node, "ClassImplements"));
  7550. } while (this.eat(12));
  7551. }
  7552. }
  7553. checkGetterSetterParams(method) {
  7554. super.checkGetterSetterParams(method);
  7555. const params = this.getObjectOrClassMethodParams(method);
  7556. if (params.length > 0) {
  7557. const param = params[0];
  7558. if (this.isThisParam(param) && method.kind === "get") {
  7559. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  7560. } else if (this.isThisParam(param)) {
  7561. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  7562. }
  7563. }
  7564. }
  7565. parsePropertyNamePrefixOperator(node) {
  7566. node.variance = this.flowParseVariance();
  7567. }
  7568. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  7569. if (prop.variance) {
  7570. this.unexpected(prop.variance.loc.start);
  7571. }
  7572. delete prop.variance;
  7573. let typeParameters;
  7574. if (this.match(47) && !isAccessor) {
  7575. typeParameters = this.flowParseTypeParameterDeclaration();
  7576. if (!this.match(10)) this.unexpected();
  7577. }
  7578. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  7579. if (typeParameters) {
  7580. (result.value || result).typeParameters = typeParameters;
  7581. }
  7582. return result;
  7583. }
  7584. parseFunctionParamType(param) {
  7585. if (this.eat(17)) {
  7586. if (param.type !== "Identifier") {
  7587. this.raise(FlowErrors.PatternIsOptional, param);
  7588. }
  7589. if (this.isThisParam(param)) {
  7590. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  7591. }
  7592. param.optional = true;
  7593. }
  7594. if (this.match(14)) {
  7595. param.typeAnnotation = this.flowParseTypeAnnotation();
  7596. } else if (this.isThisParam(param)) {
  7597. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  7598. }
  7599. if (this.match(29) && this.isThisParam(param)) {
  7600. this.raise(FlowErrors.ThisParamNoDefault, param);
  7601. }
  7602. this.resetEndLocation(param);
  7603. return param;
  7604. }
  7605. parseMaybeDefault(startLoc, left) {
  7606. const node = super.parseMaybeDefault(startLoc, left);
  7607. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  7608. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  7609. }
  7610. return node;
  7611. }
  7612. checkImportReflection(node) {
  7613. super.checkImportReflection(node);
  7614. if (node.module && node.importKind !== "value") {
  7615. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  7616. }
  7617. }
  7618. parseImportSpecifierLocal(node, specifier, type) {
  7619. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  7620. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  7621. }
  7622. isPotentialImportPhase(isExport) {
  7623. if (super.isPotentialImportPhase(isExport)) return true;
  7624. if (this.isContextual(130)) {
  7625. if (!isExport) return true;
  7626. const ch = this.lookaheadCharCode();
  7627. return ch === 123 || ch === 42;
  7628. }
  7629. return !isExport && this.isContextual(87);
  7630. }
  7631. applyImportPhase(node, isExport, phase, loc) {
  7632. super.applyImportPhase(node, isExport, phase, loc);
  7633. if (isExport) {
  7634. if (!phase && this.match(65)) {
  7635. return;
  7636. }
  7637. node.exportKind = phase === "type" ? phase : "value";
  7638. } else {
  7639. if (phase === "type" && this.match(55)) this.unexpected();
  7640. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  7641. }
  7642. }
  7643. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  7644. const firstIdent = specifier.imported;
  7645. let specifierTypeKind = null;
  7646. if (firstIdent.type === "Identifier") {
  7647. if (firstIdent.name === "type") {
  7648. specifierTypeKind = "type";
  7649. } else if (firstIdent.name === "typeof") {
  7650. specifierTypeKind = "typeof";
  7651. }
  7652. }
  7653. let isBinding = false;
  7654. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  7655. const as_ident = this.parseIdentifier(true);
  7656. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  7657. specifier.imported = as_ident;
  7658. specifier.importKind = specifierTypeKind;
  7659. specifier.local = this.cloneIdentifier(as_ident);
  7660. } else {
  7661. specifier.imported = firstIdent;
  7662. specifier.importKind = null;
  7663. specifier.local = this.parseIdentifier();
  7664. }
  7665. } else {
  7666. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  7667. specifier.imported = this.parseIdentifier(true);
  7668. specifier.importKind = specifierTypeKind;
  7669. } else {
  7670. if (importedIsString) {
  7671. throw this.raise(Errors.ImportBindingIsString, specifier, {
  7672. importName: firstIdent.value
  7673. });
  7674. }
  7675. specifier.imported = firstIdent;
  7676. specifier.importKind = null;
  7677. }
  7678. if (this.eatContextual(93)) {
  7679. specifier.local = this.parseIdentifier();
  7680. } else {
  7681. isBinding = true;
  7682. specifier.local = this.cloneIdentifier(specifier.imported);
  7683. }
  7684. }
  7685. const specifierIsTypeImport = hasTypeImportKind(specifier);
  7686. if (isInTypeOnlyImport && specifierIsTypeImport) {
  7687. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  7688. }
  7689. if (isInTypeOnlyImport || specifierIsTypeImport) {
  7690. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  7691. }
  7692. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  7693. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  7694. }
  7695. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  7696. }
  7697. parseBindingAtom() {
  7698. switch (this.state.type) {
  7699. case 78:
  7700. return this.parseIdentifier(true);
  7701. default:
  7702. return super.parseBindingAtom();
  7703. }
  7704. }
  7705. parseFunctionParams(node, isConstructor) {
  7706. const kind = node.kind;
  7707. if (kind !== "get" && kind !== "set" && this.match(47)) {
  7708. node.typeParameters = this.flowParseTypeParameterDeclaration();
  7709. }
  7710. super.parseFunctionParams(node, isConstructor);
  7711. }
  7712. parseVarId(decl, kind) {
  7713. super.parseVarId(decl, kind);
  7714. if (this.match(14)) {
  7715. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  7716. this.resetEndLocation(decl.id);
  7717. }
  7718. }
  7719. parseAsyncArrowFromCallExpression(node, call) {
  7720. if (this.match(14)) {
  7721. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  7722. this.state.noAnonFunctionType = true;
  7723. node.returnType = this.flowParseTypeAnnotation();
  7724. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  7725. }
  7726. return super.parseAsyncArrowFromCallExpression(node, call);
  7727. }
  7728. shouldParseAsyncArrow() {
  7729. return this.match(14) || super.shouldParseAsyncArrow();
  7730. }
  7731. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  7732. var _jsx;
  7733. let state = null;
  7734. let jsx;
  7735. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  7736. state = this.state.clone();
  7737. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  7738. if (!jsx.error) return jsx.node;
  7739. const {
  7740. context
  7741. } = this.state;
  7742. const currentContext = context[context.length - 1];
  7743. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  7744. context.pop();
  7745. }
  7746. }
  7747. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  7748. var _jsx2, _jsx3;
  7749. state = state || this.state.clone();
  7750. let typeParameters;
  7751. const arrow = this.tryParse(abort => {
  7752. var _arrowExpression$extr;
  7753. typeParameters = this.flowParseTypeParameterDeclaration();
  7754. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  7755. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  7756. this.resetStartLocationFromNode(result, typeParameters);
  7757. return result;
  7758. });
  7759. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  7760. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  7761. if (expr.type !== "ArrowFunctionExpression") abort();
  7762. expr.typeParameters = typeParameters;
  7763. this.resetStartLocationFromNode(expr, typeParameters);
  7764. return arrowExpression;
  7765. }, state);
  7766. let arrowExpression = null;
  7767. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  7768. if (!arrow.error && !arrow.aborted) {
  7769. if (arrow.node.async) {
  7770. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  7771. }
  7772. return arrow.node;
  7773. }
  7774. arrowExpression = arrow.node;
  7775. }
  7776. if ((_jsx2 = jsx) != null && _jsx2.node) {
  7777. this.state = jsx.failState;
  7778. return jsx.node;
  7779. }
  7780. if (arrowExpression) {
  7781. this.state = arrow.failState;
  7782. return arrowExpression;
  7783. }
  7784. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  7785. if (arrow.thrown) throw arrow.error;
  7786. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  7787. }
  7788. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  7789. }
  7790. parseArrow(node) {
  7791. if (this.match(14)) {
  7792. const result = this.tryParse(() => {
  7793. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  7794. this.state.noAnonFunctionType = true;
  7795. const typeNode = this.startNode();
  7796. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  7797. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  7798. if (this.canInsertSemicolon()) this.unexpected();
  7799. if (!this.match(19)) this.unexpected();
  7800. return typeNode;
  7801. });
  7802. if (result.thrown) return null;
  7803. if (result.error) this.state = result.failState;
  7804. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  7805. }
  7806. return super.parseArrow(node);
  7807. }
  7808. shouldParseArrow(params) {
  7809. return this.match(14) || super.shouldParseArrow(params);
  7810. }
  7811. setArrowFunctionParameters(node, params) {
  7812. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  7813. node.params = params;
  7814. } else {
  7815. super.setArrowFunctionParameters(node, params);
  7816. }
  7817. }
  7818. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  7819. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  7820. return;
  7821. }
  7822. for (let i = 0; i < node.params.length; i++) {
  7823. if (this.isThisParam(node.params[i]) && i > 0) {
  7824. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  7825. }
  7826. }
  7827. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  7828. }
  7829. parseParenAndDistinguishExpression(canBeArrow) {
  7830. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  7831. }
  7832. parseSubscripts(base, startLoc, noCalls) {
  7833. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  7834. this.next();
  7835. const node = this.startNodeAt(startLoc);
  7836. node.callee = base;
  7837. node.arguments = super.parseCallExpressionArguments();
  7838. base = this.finishNode(node, "CallExpression");
  7839. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  7840. const state = this.state.clone();
  7841. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  7842. if (!arrow.error && !arrow.aborted) return arrow.node;
  7843. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  7844. if (result.node && !result.error) return result.node;
  7845. if (arrow.node) {
  7846. this.state = arrow.failState;
  7847. return arrow.node;
  7848. }
  7849. if (result.node) {
  7850. this.state = result.failState;
  7851. return result.node;
  7852. }
  7853. throw arrow.error || result.error;
  7854. }
  7855. return super.parseSubscripts(base, startLoc, noCalls);
  7856. }
  7857. parseSubscript(base, startLoc, noCalls, subscriptState) {
  7858. if (this.match(18) && this.isLookaheadToken_lt()) {
  7859. subscriptState.optionalChainMember = true;
  7860. if (noCalls) {
  7861. subscriptState.stop = true;
  7862. return base;
  7863. }
  7864. this.next();
  7865. const node = this.startNodeAt(startLoc);
  7866. node.callee = base;
  7867. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  7868. this.expect(10);
  7869. node.arguments = this.parseCallExpressionArguments();
  7870. node.optional = true;
  7871. return this.finishCallExpression(node, true);
  7872. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  7873. const node = this.startNodeAt(startLoc);
  7874. node.callee = base;
  7875. const result = this.tryParse(() => {
  7876. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  7877. this.expect(10);
  7878. node.arguments = super.parseCallExpressionArguments();
  7879. if (subscriptState.optionalChainMember) {
  7880. node.optional = false;
  7881. }
  7882. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  7883. });
  7884. if (result.node) {
  7885. if (result.error) this.state = result.failState;
  7886. return result.node;
  7887. }
  7888. }
  7889. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  7890. }
  7891. parseNewCallee(node) {
  7892. super.parseNewCallee(node);
  7893. let targs = null;
  7894. if (this.shouldParseTypes() && this.match(47)) {
  7895. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  7896. }
  7897. node.typeArguments = targs;
  7898. }
  7899. parseAsyncArrowWithTypeParameters(startLoc) {
  7900. const node = this.startNodeAt(startLoc);
  7901. this.parseFunctionParams(node, false);
  7902. if (!this.parseArrow(node)) return;
  7903. return super.parseArrowExpression(node, undefined, true);
  7904. }
  7905. readToken_mult_modulo(code) {
  7906. const next = this.input.charCodeAt(this.state.pos + 1);
  7907. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  7908. this.state.hasFlowComment = false;
  7909. this.state.pos += 2;
  7910. this.nextToken();
  7911. return;
  7912. }
  7913. super.readToken_mult_modulo(code);
  7914. }
  7915. readToken_pipe_amp(code) {
  7916. const next = this.input.charCodeAt(this.state.pos + 1);
  7917. if (code === 124 && next === 125) {
  7918. this.finishOp(9, 2);
  7919. return;
  7920. }
  7921. super.readToken_pipe_amp(code);
  7922. }
  7923. parseTopLevel(file, program) {
  7924. const fileNode = super.parseTopLevel(file, program);
  7925. if (this.state.hasFlowComment) {
  7926. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  7927. }
  7928. return fileNode;
  7929. }
  7930. skipBlockComment() {
  7931. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  7932. if (this.state.hasFlowComment) {
  7933. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  7934. }
  7935. this.hasFlowCommentCompletion();
  7936. const commentSkip = this.skipFlowComment();
  7937. if (commentSkip) {
  7938. this.state.pos += commentSkip;
  7939. this.state.hasFlowComment = true;
  7940. }
  7941. return;
  7942. }
  7943. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  7944. }
  7945. skipFlowComment() {
  7946. const {
  7947. pos
  7948. } = this.state;
  7949. let shiftToFirstNonWhiteSpace = 2;
  7950. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  7951. shiftToFirstNonWhiteSpace++;
  7952. }
  7953. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  7954. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  7955. if (ch2 === 58 && ch3 === 58) {
  7956. return shiftToFirstNonWhiteSpace + 2;
  7957. }
  7958. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  7959. return shiftToFirstNonWhiteSpace + 12;
  7960. }
  7961. if (ch2 === 58 && ch3 !== 58) {
  7962. return shiftToFirstNonWhiteSpace;
  7963. }
  7964. return false;
  7965. }
  7966. hasFlowCommentCompletion() {
  7967. const end = this.input.indexOf("*/", this.state.pos);
  7968. if (end === -1) {
  7969. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  7970. }
  7971. }
  7972. flowEnumErrorBooleanMemberNotInitialized(loc, {
  7973. enumName,
  7974. memberName
  7975. }) {
  7976. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  7977. memberName,
  7978. enumName
  7979. });
  7980. }
  7981. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  7982. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  7983. }
  7984. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  7985. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  7986. }
  7987. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  7988. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  7989. }
  7990. flowEnumMemberInit() {
  7991. const startLoc = this.state.startLoc;
  7992. const endOfInit = () => this.match(12) || this.match(8);
  7993. switch (this.state.type) {
  7994. case 135:
  7995. {
  7996. const literal = this.parseNumericLiteral(this.state.value);
  7997. if (endOfInit()) {
  7998. return {
  7999. type: "number",
  8000. loc: literal.loc.start,
  8001. value: literal
  8002. };
  8003. }
  8004. return {
  8005. type: "invalid",
  8006. loc: startLoc
  8007. };
  8008. }
  8009. case 134:
  8010. {
  8011. const literal = this.parseStringLiteral(this.state.value);
  8012. if (endOfInit()) {
  8013. return {
  8014. type: "string",
  8015. loc: literal.loc.start,
  8016. value: literal
  8017. };
  8018. }
  8019. return {
  8020. type: "invalid",
  8021. loc: startLoc
  8022. };
  8023. }
  8024. case 85:
  8025. case 86:
  8026. {
  8027. const literal = this.parseBooleanLiteral(this.match(85));
  8028. if (endOfInit()) {
  8029. return {
  8030. type: "boolean",
  8031. loc: literal.loc.start,
  8032. value: literal
  8033. };
  8034. }
  8035. return {
  8036. type: "invalid",
  8037. loc: startLoc
  8038. };
  8039. }
  8040. default:
  8041. return {
  8042. type: "invalid",
  8043. loc: startLoc
  8044. };
  8045. }
  8046. }
  8047. flowEnumMemberRaw() {
  8048. const loc = this.state.startLoc;
  8049. const id = this.parseIdentifier(true);
  8050. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  8051. type: "none",
  8052. loc
  8053. };
  8054. return {
  8055. id,
  8056. init
  8057. };
  8058. }
  8059. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  8060. const {
  8061. explicitType
  8062. } = context;
  8063. if (explicitType === null) {
  8064. return;
  8065. }
  8066. if (explicitType !== expectedType) {
  8067. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  8068. }
  8069. }
  8070. flowEnumMembers({
  8071. enumName,
  8072. explicitType
  8073. }) {
  8074. const seenNames = new Set();
  8075. const members = {
  8076. booleanMembers: [],
  8077. numberMembers: [],
  8078. stringMembers: [],
  8079. defaultedMembers: []
  8080. };
  8081. let hasUnknownMembers = false;
  8082. while (!this.match(8)) {
  8083. if (this.eat(21)) {
  8084. hasUnknownMembers = true;
  8085. break;
  8086. }
  8087. const memberNode = this.startNode();
  8088. const {
  8089. id,
  8090. init
  8091. } = this.flowEnumMemberRaw();
  8092. const memberName = id.name;
  8093. if (memberName === "") {
  8094. continue;
  8095. }
  8096. if (/^[a-z]/.test(memberName)) {
  8097. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  8098. memberName,
  8099. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  8100. enumName
  8101. });
  8102. }
  8103. if (seenNames.has(memberName)) {
  8104. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  8105. memberName,
  8106. enumName
  8107. });
  8108. }
  8109. seenNames.add(memberName);
  8110. const context = {
  8111. enumName,
  8112. explicitType,
  8113. memberName
  8114. };
  8115. memberNode.id = id;
  8116. switch (init.type) {
  8117. case "boolean":
  8118. {
  8119. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  8120. memberNode.init = init.value;
  8121. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  8122. break;
  8123. }
  8124. case "number":
  8125. {
  8126. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  8127. memberNode.init = init.value;
  8128. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  8129. break;
  8130. }
  8131. case "string":
  8132. {
  8133. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  8134. memberNode.init = init.value;
  8135. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  8136. break;
  8137. }
  8138. case "invalid":
  8139. {
  8140. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  8141. }
  8142. case "none":
  8143. {
  8144. switch (explicitType) {
  8145. case "boolean":
  8146. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  8147. break;
  8148. case "number":
  8149. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  8150. break;
  8151. default:
  8152. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  8153. }
  8154. }
  8155. }
  8156. if (!this.match(8)) {
  8157. this.expect(12);
  8158. }
  8159. }
  8160. return {
  8161. members,
  8162. hasUnknownMembers
  8163. };
  8164. }
  8165. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  8166. enumName
  8167. }) {
  8168. if (initializedMembers.length === 0) {
  8169. return defaultedMembers;
  8170. } else if (defaultedMembers.length === 0) {
  8171. return initializedMembers;
  8172. } else if (defaultedMembers.length > initializedMembers.length) {
  8173. for (const member of initializedMembers) {
  8174. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  8175. enumName
  8176. });
  8177. }
  8178. return defaultedMembers;
  8179. } else {
  8180. for (const member of defaultedMembers) {
  8181. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  8182. enumName
  8183. });
  8184. }
  8185. return initializedMembers;
  8186. }
  8187. }
  8188. flowEnumParseExplicitType({
  8189. enumName
  8190. }) {
  8191. if (!this.eatContextual(102)) return null;
  8192. if (!tokenIsIdentifier(this.state.type)) {
  8193. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  8194. enumName
  8195. });
  8196. }
  8197. const {
  8198. value
  8199. } = this.state;
  8200. this.next();
  8201. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  8202. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  8203. enumName,
  8204. invalidEnumType: value
  8205. });
  8206. }
  8207. return value;
  8208. }
  8209. flowEnumBody(node, id) {
  8210. const enumName = id.name;
  8211. const nameLoc = id.loc.start;
  8212. const explicitType = this.flowEnumParseExplicitType({
  8213. enumName
  8214. });
  8215. this.expect(5);
  8216. const {
  8217. members,
  8218. hasUnknownMembers
  8219. } = this.flowEnumMembers({
  8220. enumName,
  8221. explicitType
  8222. });
  8223. node.hasUnknownMembers = hasUnknownMembers;
  8224. switch (explicitType) {
  8225. case "boolean":
  8226. node.explicitType = true;
  8227. node.members = members.booleanMembers;
  8228. this.expect(8);
  8229. return this.finishNode(node, "EnumBooleanBody");
  8230. case "number":
  8231. node.explicitType = true;
  8232. node.members = members.numberMembers;
  8233. this.expect(8);
  8234. return this.finishNode(node, "EnumNumberBody");
  8235. case "string":
  8236. node.explicitType = true;
  8237. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  8238. enumName
  8239. });
  8240. this.expect(8);
  8241. return this.finishNode(node, "EnumStringBody");
  8242. case "symbol":
  8243. node.members = members.defaultedMembers;
  8244. this.expect(8);
  8245. return this.finishNode(node, "EnumSymbolBody");
  8246. default:
  8247. {
  8248. const empty = () => {
  8249. node.members = [];
  8250. this.expect(8);
  8251. return this.finishNode(node, "EnumStringBody");
  8252. };
  8253. node.explicitType = false;
  8254. const boolsLen = members.booleanMembers.length;
  8255. const numsLen = members.numberMembers.length;
  8256. const strsLen = members.stringMembers.length;
  8257. const defaultedLen = members.defaultedMembers.length;
  8258. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  8259. return empty();
  8260. } else if (!boolsLen && !numsLen) {
  8261. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  8262. enumName
  8263. });
  8264. this.expect(8);
  8265. return this.finishNode(node, "EnumStringBody");
  8266. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  8267. for (const member of members.defaultedMembers) {
  8268. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  8269. enumName,
  8270. memberName: member.id.name
  8271. });
  8272. }
  8273. node.members = members.booleanMembers;
  8274. this.expect(8);
  8275. return this.finishNode(node, "EnumBooleanBody");
  8276. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  8277. for (const member of members.defaultedMembers) {
  8278. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  8279. enumName,
  8280. memberName: member.id.name
  8281. });
  8282. }
  8283. node.members = members.numberMembers;
  8284. this.expect(8);
  8285. return this.finishNode(node, "EnumNumberBody");
  8286. } else {
  8287. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  8288. enumName
  8289. });
  8290. return empty();
  8291. }
  8292. }
  8293. }
  8294. }
  8295. flowParseEnumDeclaration(node) {
  8296. const id = this.parseIdentifier();
  8297. node.id = id;
  8298. node.body = this.flowEnumBody(this.startNode(), id);
  8299. return this.finishNode(node, "EnumDeclaration");
  8300. }
  8301. jsxParseOpeningElementAfterName(node) {
  8302. if (this.shouldParseTypes()) {
  8303. if (this.match(47) || this.match(51)) {
  8304. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  8305. }
  8306. }
  8307. return super.jsxParseOpeningElementAfterName(node);
  8308. }
  8309. isLookaheadToken_lt() {
  8310. const next = this.nextTokenStart();
  8311. if (this.input.charCodeAt(next) === 60) {
  8312. const afterNext = this.input.charCodeAt(next + 1);
  8313. return afterNext !== 60 && afterNext !== 61;
  8314. }
  8315. return false;
  8316. }
  8317. reScan_lt_gt() {
  8318. const {
  8319. type
  8320. } = this.state;
  8321. if (type === 47) {
  8322. this.state.pos -= 1;
  8323. this.readToken_lt();
  8324. } else if (type === 48) {
  8325. this.state.pos -= 1;
  8326. this.readToken_gt();
  8327. }
  8328. }
  8329. reScan_lt() {
  8330. const {
  8331. type
  8332. } = this.state;
  8333. if (type === 51) {
  8334. this.state.pos -= 2;
  8335. this.finishOp(47, 1);
  8336. return 47;
  8337. }
  8338. return type;
  8339. }
  8340. maybeUnwrapTypeCastExpression(node) {
  8341. return node.type === "TypeCastExpression" ? node.expression : node;
  8342. }
  8343. };
  8344. const entities = {
  8345. __proto__: null,
  8346. quot: "\u0022",
  8347. amp: "&",
  8348. apos: "\u0027",
  8349. lt: "<",
  8350. gt: ">",
  8351. nbsp: "\u00A0",
  8352. iexcl: "\u00A1",
  8353. cent: "\u00A2",
  8354. pound: "\u00A3",
  8355. curren: "\u00A4",
  8356. yen: "\u00A5",
  8357. brvbar: "\u00A6",
  8358. sect: "\u00A7",
  8359. uml: "\u00A8",
  8360. copy: "\u00A9",
  8361. ordf: "\u00AA",
  8362. laquo: "\u00AB",
  8363. not: "\u00AC",
  8364. shy: "\u00AD",
  8365. reg: "\u00AE",
  8366. macr: "\u00AF",
  8367. deg: "\u00B0",
  8368. plusmn: "\u00B1",
  8369. sup2: "\u00B2",
  8370. sup3: "\u00B3",
  8371. acute: "\u00B4",
  8372. micro: "\u00B5",
  8373. para: "\u00B6",
  8374. middot: "\u00B7",
  8375. cedil: "\u00B8",
  8376. sup1: "\u00B9",
  8377. ordm: "\u00BA",
  8378. raquo: "\u00BB",
  8379. frac14: "\u00BC",
  8380. frac12: "\u00BD",
  8381. frac34: "\u00BE",
  8382. iquest: "\u00BF",
  8383. Agrave: "\u00C0",
  8384. Aacute: "\u00C1",
  8385. Acirc: "\u00C2",
  8386. Atilde: "\u00C3",
  8387. Auml: "\u00C4",
  8388. Aring: "\u00C5",
  8389. AElig: "\u00C6",
  8390. Ccedil: "\u00C7",
  8391. Egrave: "\u00C8",
  8392. Eacute: "\u00C9",
  8393. Ecirc: "\u00CA",
  8394. Euml: "\u00CB",
  8395. Igrave: "\u00CC",
  8396. Iacute: "\u00CD",
  8397. Icirc: "\u00CE",
  8398. Iuml: "\u00CF",
  8399. ETH: "\u00D0",
  8400. Ntilde: "\u00D1",
  8401. Ograve: "\u00D2",
  8402. Oacute: "\u00D3",
  8403. Ocirc: "\u00D4",
  8404. Otilde: "\u00D5",
  8405. Ouml: "\u00D6",
  8406. times: "\u00D7",
  8407. Oslash: "\u00D8",
  8408. Ugrave: "\u00D9",
  8409. Uacute: "\u00DA",
  8410. Ucirc: "\u00DB",
  8411. Uuml: "\u00DC",
  8412. Yacute: "\u00DD",
  8413. THORN: "\u00DE",
  8414. szlig: "\u00DF",
  8415. agrave: "\u00E0",
  8416. aacute: "\u00E1",
  8417. acirc: "\u00E2",
  8418. atilde: "\u00E3",
  8419. auml: "\u00E4",
  8420. aring: "\u00E5",
  8421. aelig: "\u00E6",
  8422. ccedil: "\u00E7",
  8423. egrave: "\u00E8",
  8424. eacute: "\u00E9",
  8425. ecirc: "\u00EA",
  8426. euml: "\u00EB",
  8427. igrave: "\u00EC",
  8428. iacute: "\u00ED",
  8429. icirc: "\u00EE",
  8430. iuml: "\u00EF",
  8431. eth: "\u00F0",
  8432. ntilde: "\u00F1",
  8433. ograve: "\u00F2",
  8434. oacute: "\u00F3",
  8435. ocirc: "\u00F4",
  8436. otilde: "\u00F5",
  8437. ouml: "\u00F6",
  8438. divide: "\u00F7",
  8439. oslash: "\u00F8",
  8440. ugrave: "\u00F9",
  8441. uacute: "\u00FA",
  8442. ucirc: "\u00FB",
  8443. uuml: "\u00FC",
  8444. yacute: "\u00FD",
  8445. thorn: "\u00FE",
  8446. yuml: "\u00FF",
  8447. OElig: "\u0152",
  8448. oelig: "\u0153",
  8449. Scaron: "\u0160",
  8450. scaron: "\u0161",
  8451. Yuml: "\u0178",
  8452. fnof: "\u0192",
  8453. circ: "\u02C6",
  8454. tilde: "\u02DC",
  8455. Alpha: "\u0391",
  8456. Beta: "\u0392",
  8457. Gamma: "\u0393",
  8458. Delta: "\u0394",
  8459. Epsilon: "\u0395",
  8460. Zeta: "\u0396",
  8461. Eta: "\u0397",
  8462. Theta: "\u0398",
  8463. Iota: "\u0399",
  8464. Kappa: "\u039A",
  8465. Lambda: "\u039B",
  8466. Mu: "\u039C",
  8467. Nu: "\u039D",
  8468. Xi: "\u039E",
  8469. Omicron: "\u039F",
  8470. Pi: "\u03A0",
  8471. Rho: "\u03A1",
  8472. Sigma: "\u03A3",
  8473. Tau: "\u03A4",
  8474. Upsilon: "\u03A5",
  8475. Phi: "\u03A6",
  8476. Chi: "\u03A7",
  8477. Psi: "\u03A8",
  8478. Omega: "\u03A9",
  8479. alpha: "\u03B1",
  8480. beta: "\u03B2",
  8481. gamma: "\u03B3",
  8482. delta: "\u03B4",
  8483. epsilon: "\u03B5",
  8484. zeta: "\u03B6",
  8485. eta: "\u03B7",
  8486. theta: "\u03B8",
  8487. iota: "\u03B9",
  8488. kappa: "\u03BA",
  8489. lambda: "\u03BB",
  8490. mu: "\u03BC",
  8491. nu: "\u03BD",
  8492. xi: "\u03BE",
  8493. omicron: "\u03BF",
  8494. pi: "\u03C0",
  8495. rho: "\u03C1",
  8496. sigmaf: "\u03C2",
  8497. sigma: "\u03C3",
  8498. tau: "\u03C4",
  8499. upsilon: "\u03C5",
  8500. phi: "\u03C6",
  8501. chi: "\u03C7",
  8502. psi: "\u03C8",
  8503. omega: "\u03C9",
  8504. thetasym: "\u03D1",
  8505. upsih: "\u03D2",
  8506. piv: "\u03D6",
  8507. ensp: "\u2002",
  8508. emsp: "\u2003",
  8509. thinsp: "\u2009",
  8510. zwnj: "\u200C",
  8511. zwj: "\u200D",
  8512. lrm: "\u200E",
  8513. rlm: "\u200F",
  8514. ndash: "\u2013",
  8515. mdash: "\u2014",
  8516. lsquo: "\u2018",
  8517. rsquo: "\u2019",
  8518. sbquo: "\u201A",
  8519. ldquo: "\u201C",
  8520. rdquo: "\u201D",
  8521. bdquo: "\u201E",
  8522. dagger: "\u2020",
  8523. Dagger: "\u2021",
  8524. bull: "\u2022",
  8525. hellip: "\u2026",
  8526. permil: "\u2030",
  8527. prime: "\u2032",
  8528. Prime: "\u2033",
  8529. lsaquo: "\u2039",
  8530. rsaquo: "\u203A",
  8531. oline: "\u203E",
  8532. frasl: "\u2044",
  8533. euro: "\u20AC",
  8534. image: "\u2111",
  8535. weierp: "\u2118",
  8536. real: "\u211C",
  8537. trade: "\u2122",
  8538. alefsym: "\u2135",
  8539. larr: "\u2190",
  8540. uarr: "\u2191",
  8541. rarr: "\u2192",
  8542. darr: "\u2193",
  8543. harr: "\u2194",
  8544. crarr: "\u21B5",
  8545. lArr: "\u21D0",
  8546. uArr: "\u21D1",
  8547. rArr: "\u21D2",
  8548. dArr: "\u21D3",
  8549. hArr: "\u21D4",
  8550. forall: "\u2200",
  8551. part: "\u2202",
  8552. exist: "\u2203",
  8553. empty: "\u2205",
  8554. nabla: "\u2207",
  8555. isin: "\u2208",
  8556. notin: "\u2209",
  8557. ni: "\u220B",
  8558. prod: "\u220F",
  8559. sum: "\u2211",
  8560. minus: "\u2212",
  8561. lowast: "\u2217",
  8562. radic: "\u221A",
  8563. prop: "\u221D",
  8564. infin: "\u221E",
  8565. ang: "\u2220",
  8566. and: "\u2227",
  8567. or: "\u2228",
  8568. cap: "\u2229",
  8569. cup: "\u222A",
  8570. int: "\u222B",
  8571. there4: "\u2234",
  8572. sim: "\u223C",
  8573. cong: "\u2245",
  8574. asymp: "\u2248",
  8575. ne: "\u2260",
  8576. equiv: "\u2261",
  8577. le: "\u2264",
  8578. ge: "\u2265",
  8579. sub: "\u2282",
  8580. sup: "\u2283",
  8581. nsub: "\u2284",
  8582. sube: "\u2286",
  8583. supe: "\u2287",
  8584. oplus: "\u2295",
  8585. otimes: "\u2297",
  8586. perp: "\u22A5",
  8587. sdot: "\u22C5",
  8588. lceil: "\u2308",
  8589. rceil: "\u2309",
  8590. lfloor: "\u230A",
  8591. rfloor: "\u230B",
  8592. lang: "\u2329",
  8593. rang: "\u232A",
  8594. loz: "\u25CA",
  8595. spades: "\u2660",
  8596. clubs: "\u2663",
  8597. hearts: "\u2665",
  8598. diams: "\u2666"
  8599. };
  8600. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  8601. const lineBreakG = new RegExp(lineBreak.source, "g");
  8602. function isNewLine(code) {
  8603. switch (code) {
  8604. case 10:
  8605. case 13:
  8606. case 8232:
  8607. case 8233:
  8608. return true;
  8609. default:
  8610. return false;
  8611. }
  8612. }
  8613. function hasNewLine(input, start, end) {
  8614. for (let i = start; i < end; i++) {
  8615. if (isNewLine(input.charCodeAt(i))) {
  8616. return true;
  8617. }
  8618. }
  8619. return false;
  8620. }
  8621. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  8622. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  8623. function isWhitespace(code) {
  8624. switch (code) {
  8625. case 0x0009:
  8626. case 0x000b:
  8627. case 0x000c:
  8628. case 32:
  8629. case 160:
  8630. case 5760:
  8631. case 0x2000:
  8632. case 0x2001:
  8633. case 0x2002:
  8634. case 0x2003:
  8635. case 0x2004:
  8636. case 0x2005:
  8637. case 0x2006:
  8638. case 0x2007:
  8639. case 0x2008:
  8640. case 0x2009:
  8641. case 0x200a:
  8642. case 0x202f:
  8643. case 0x205f:
  8644. case 0x3000:
  8645. case 0xfeff:
  8646. return true;
  8647. default:
  8648. return false;
  8649. }
  8650. }
  8651. const JsxErrors = ParseErrorEnum`jsx`({
  8652. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  8653. MissingClosingTagElement: ({
  8654. openingTagName
  8655. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  8656. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  8657. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  8658. UnexpectedToken: ({
  8659. unexpected,
  8660. HTMLEntity
  8661. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  8662. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  8663. UnterminatedJsxContent: "Unterminated JSX contents.",
  8664. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  8665. });
  8666. function isFragment(object) {
  8667. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  8668. }
  8669. function getQualifiedJSXName(object) {
  8670. if (object.type === "JSXIdentifier") {
  8671. return object.name;
  8672. }
  8673. if (object.type === "JSXNamespacedName") {
  8674. return object.namespace.name + ":" + object.name.name;
  8675. }
  8676. if (object.type === "JSXMemberExpression") {
  8677. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  8678. }
  8679. throw new Error("Node had unexpected type: " + object.type);
  8680. }
  8681. var jsx = superClass => class JSXParserMixin extends superClass {
  8682. jsxReadToken() {
  8683. let out = "";
  8684. let chunkStart = this.state.pos;
  8685. for (;;) {
  8686. if (this.state.pos >= this.length) {
  8687. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  8688. }
  8689. const ch = this.input.charCodeAt(this.state.pos);
  8690. switch (ch) {
  8691. case 60:
  8692. case 123:
  8693. if (this.state.pos === this.state.start) {
  8694. if (ch === 60 && this.state.canStartJSXElement) {
  8695. ++this.state.pos;
  8696. this.finishToken(143);
  8697. } else {
  8698. super.getTokenFromCode(ch);
  8699. }
  8700. return;
  8701. }
  8702. out += this.input.slice(chunkStart, this.state.pos);
  8703. this.finishToken(142, out);
  8704. return;
  8705. case 38:
  8706. out += this.input.slice(chunkStart, this.state.pos);
  8707. out += this.jsxReadEntity();
  8708. chunkStart = this.state.pos;
  8709. break;
  8710. case 62:
  8711. case 125:
  8712. default:
  8713. if (isNewLine(ch)) {
  8714. out += this.input.slice(chunkStart, this.state.pos);
  8715. out += this.jsxReadNewLine(true);
  8716. chunkStart = this.state.pos;
  8717. } else {
  8718. ++this.state.pos;
  8719. }
  8720. }
  8721. }
  8722. }
  8723. jsxReadNewLine(normalizeCRLF) {
  8724. const ch = this.input.charCodeAt(this.state.pos);
  8725. let out;
  8726. ++this.state.pos;
  8727. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  8728. ++this.state.pos;
  8729. out = normalizeCRLF ? "\n" : "\r\n";
  8730. } else {
  8731. out = String.fromCharCode(ch);
  8732. }
  8733. ++this.state.curLine;
  8734. this.state.lineStart = this.state.pos;
  8735. return out;
  8736. }
  8737. jsxReadString(quote) {
  8738. let out = "";
  8739. let chunkStart = ++this.state.pos;
  8740. for (;;) {
  8741. if (this.state.pos >= this.length) {
  8742. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  8743. }
  8744. const ch = this.input.charCodeAt(this.state.pos);
  8745. if (ch === quote) break;
  8746. if (ch === 38) {
  8747. out += this.input.slice(chunkStart, this.state.pos);
  8748. out += this.jsxReadEntity();
  8749. chunkStart = this.state.pos;
  8750. } else if (isNewLine(ch)) {
  8751. out += this.input.slice(chunkStart, this.state.pos);
  8752. out += this.jsxReadNewLine(false);
  8753. chunkStart = this.state.pos;
  8754. } else {
  8755. ++this.state.pos;
  8756. }
  8757. }
  8758. out += this.input.slice(chunkStart, this.state.pos++);
  8759. this.finishToken(134, out);
  8760. }
  8761. jsxReadEntity() {
  8762. const startPos = ++this.state.pos;
  8763. if (this.codePointAtPos(this.state.pos) === 35) {
  8764. ++this.state.pos;
  8765. let radix = 10;
  8766. if (this.codePointAtPos(this.state.pos) === 120) {
  8767. radix = 16;
  8768. ++this.state.pos;
  8769. }
  8770. const codePoint = this.readInt(radix, undefined, false, "bail");
  8771. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  8772. ++this.state.pos;
  8773. return String.fromCodePoint(codePoint);
  8774. }
  8775. } else {
  8776. let count = 0;
  8777. let semi = false;
  8778. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  8779. ++this.state.pos;
  8780. }
  8781. if (semi) {
  8782. const desc = this.input.slice(startPos, this.state.pos);
  8783. const entity = entities[desc];
  8784. ++this.state.pos;
  8785. if (entity) {
  8786. return entity;
  8787. }
  8788. }
  8789. }
  8790. this.state.pos = startPos;
  8791. return "&";
  8792. }
  8793. jsxReadWord() {
  8794. let ch;
  8795. const start = this.state.pos;
  8796. do {
  8797. ch = this.input.charCodeAt(++this.state.pos);
  8798. } while (isIdentifierChar(ch) || ch === 45);
  8799. this.finishToken(141, this.input.slice(start, this.state.pos));
  8800. }
  8801. jsxParseIdentifier() {
  8802. const node = this.startNode();
  8803. if (this.match(141)) {
  8804. node.name = this.state.value;
  8805. } else if (tokenIsKeyword(this.state.type)) {
  8806. node.name = tokenLabelName(this.state.type);
  8807. } else {
  8808. this.unexpected();
  8809. }
  8810. this.next();
  8811. return this.finishNode(node, "JSXIdentifier");
  8812. }
  8813. jsxParseNamespacedName() {
  8814. const startLoc = this.state.startLoc;
  8815. const name = this.jsxParseIdentifier();
  8816. if (!this.eat(14)) return name;
  8817. const node = this.startNodeAt(startLoc);
  8818. node.namespace = name;
  8819. node.name = this.jsxParseIdentifier();
  8820. return this.finishNode(node, "JSXNamespacedName");
  8821. }
  8822. jsxParseElementName() {
  8823. const startLoc = this.state.startLoc;
  8824. let node = this.jsxParseNamespacedName();
  8825. if (node.type === "JSXNamespacedName") {
  8826. return node;
  8827. }
  8828. while (this.eat(16)) {
  8829. const newNode = this.startNodeAt(startLoc);
  8830. newNode.object = node;
  8831. newNode.property = this.jsxParseIdentifier();
  8832. node = this.finishNode(newNode, "JSXMemberExpression");
  8833. }
  8834. return node;
  8835. }
  8836. jsxParseAttributeValue() {
  8837. let node;
  8838. switch (this.state.type) {
  8839. case 5:
  8840. node = this.startNode();
  8841. this.setContext(types.brace);
  8842. this.next();
  8843. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  8844. if (node.expression.type === "JSXEmptyExpression") {
  8845. this.raise(JsxErrors.AttributeIsEmpty, node);
  8846. }
  8847. return node;
  8848. case 143:
  8849. case 134:
  8850. return this.parseExprAtom();
  8851. default:
  8852. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  8853. }
  8854. }
  8855. jsxParseEmptyExpression() {
  8856. const node = this.startNodeAt(this.state.lastTokEndLoc);
  8857. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  8858. }
  8859. jsxParseSpreadChild(node) {
  8860. this.next();
  8861. node.expression = this.parseExpression();
  8862. this.setContext(types.j_expr);
  8863. this.state.canStartJSXElement = true;
  8864. this.expect(8);
  8865. return this.finishNode(node, "JSXSpreadChild");
  8866. }
  8867. jsxParseExpressionContainer(node, previousContext) {
  8868. if (this.match(8)) {
  8869. node.expression = this.jsxParseEmptyExpression();
  8870. } else {
  8871. const expression = this.parseExpression();
  8872. node.expression = expression;
  8873. }
  8874. this.setContext(previousContext);
  8875. this.state.canStartJSXElement = true;
  8876. this.expect(8);
  8877. return this.finishNode(node, "JSXExpressionContainer");
  8878. }
  8879. jsxParseAttribute() {
  8880. const node = this.startNode();
  8881. if (this.match(5)) {
  8882. this.setContext(types.brace);
  8883. this.next();
  8884. this.expect(21);
  8885. node.argument = this.parseMaybeAssignAllowIn();
  8886. this.setContext(types.j_oTag);
  8887. this.state.canStartJSXElement = true;
  8888. this.expect(8);
  8889. return this.finishNode(node, "JSXSpreadAttribute");
  8890. }
  8891. node.name = this.jsxParseNamespacedName();
  8892. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  8893. return this.finishNode(node, "JSXAttribute");
  8894. }
  8895. jsxParseOpeningElementAt(startLoc) {
  8896. const node = this.startNodeAt(startLoc);
  8897. if (this.eat(144)) {
  8898. return this.finishNode(node, "JSXOpeningFragment");
  8899. }
  8900. node.name = this.jsxParseElementName();
  8901. return this.jsxParseOpeningElementAfterName(node);
  8902. }
  8903. jsxParseOpeningElementAfterName(node) {
  8904. const attributes = [];
  8905. while (!this.match(56) && !this.match(144)) {
  8906. attributes.push(this.jsxParseAttribute());
  8907. }
  8908. node.attributes = attributes;
  8909. node.selfClosing = this.eat(56);
  8910. this.expect(144);
  8911. return this.finishNode(node, "JSXOpeningElement");
  8912. }
  8913. jsxParseClosingElementAt(startLoc) {
  8914. const node = this.startNodeAt(startLoc);
  8915. if (this.eat(144)) {
  8916. return this.finishNode(node, "JSXClosingFragment");
  8917. }
  8918. node.name = this.jsxParseElementName();
  8919. this.expect(144);
  8920. return this.finishNode(node, "JSXClosingElement");
  8921. }
  8922. jsxParseElementAt(startLoc) {
  8923. const node = this.startNodeAt(startLoc);
  8924. const children = [];
  8925. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  8926. let closingElement = null;
  8927. if (!openingElement.selfClosing) {
  8928. contents: for (;;) {
  8929. switch (this.state.type) {
  8930. case 143:
  8931. startLoc = this.state.startLoc;
  8932. this.next();
  8933. if (this.eat(56)) {
  8934. closingElement = this.jsxParseClosingElementAt(startLoc);
  8935. break contents;
  8936. }
  8937. children.push(this.jsxParseElementAt(startLoc));
  8938. break;
  8939. case 142:
  8940. children.push(this.parseLiteral(this.state.value, "JSXText"));
  8941. break;
  8942. case 5:
  8943. {
  8944. const node = this.startNode();
  8945. this.setContext(types.brace);
  8946. this.next();
  8947. if (this.match(21)) {
  8948. children.push(this.jsxParseSpreadChild(node));
  8949. } else {
  8950. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  8951. }
  8952. break;
  8953. }
  8954. default:
  8955. this.unexpected();
  8956. }
  8957. }
  8958. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  8959. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  8960. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  8961. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  8962. openingTagName: getQualifiedJSXName(openingElement.name)
  8963. });
  8964. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  8965. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  8966. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  8967. openingTagName: getQualifiedJSXName(openingElement.name)
  8968. });
  8969. }
  8970. }
  8971. }
  8972. if (isFragment(openingElement)) {
  8973. node.openingFragment = openingElement;
  8974. node.closingFragment = closingElement;
  8975. } else {
  8976. node.openingElement = openingElement;
  8977. node.closingElement = closingElement;
  8978. }
  8979. node.children = children;
  8980. if (this.match(47)) {
  8981. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  8982. }
  8983. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  8984. }
  8985. jsxParseElement() {
  8986. const startLoc = this.state.startLoc;
  8987. this.next();
  8988. return this.jsxParseElementAt(startLoc);
  8989. }
  8990. setContext(newContext) {
  8991. const {
  8992. context
  8993. } = this.state;
  8994. context[context.length - 1] = newContext;
  8995. }
  8996. parseExprAtom(refExpressionErrors) {
  8997. if (this.match(143)) {
  8998. return this.jsxParseElement();
  8999. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  9000. this.replaceToken(143);
  9001. return this.jsxParseElement();
  9002. } else {
  9003. return super.parseExprAtom(refExpressionErrors);
  9004. }
  9005. }
  9006. skipSpace() {
  9007. const curContext = this.curContext();
  9008. if (!curContext.preserveSpace) super.skipSpace();
  9009. }
  9010. getTokenFromCode(code) {
  9011. const context = this.curContext();
  9012. if (context === types.j_expr) {
  9013. this.jsxReadToken();
  9014. return;
  9015. }
  9016. if (context === types.j_oTag || context === types.j_cTag) {
  9017. if (isIdentifierStart(code)) {
  9018. this.jsxReadWord();
  9019. return;
  9020. }
  9021. if (code === 62) {
  9022. ++this.state.pos;
  9023. this.finishToken(144);
  9024. return;
  9025. }
  9026. if ((code === 34 || code === 39) && context === types.j_oTag) {
  9027. this.jsxReadString(code);
  9028. return;
  9029. }
  9030. }
  9031. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  9032. ++this.state.pos;
  9033. this.finishToken(143);
  9034. return;
  9035. }
  9036. super.getTokenFromCode(code);
  9037. }
  9038. updateContext(prevType) {
  9039. const {
  9040. context,
  9041. type
  9042. } = this.state;
  9043. if (type === 56 && prevType === 143) {
  9044. context.splice(-2, 2, types.j_cTag);
  9045. this.state.canStartJSXElement = false;
  9046. } else if (type === 143) {
  9047. context.push(types.j_oTag);
  9048. } else if (type === 144) {
  9049. const out = context[context.length - 1];
  9050. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  9051. context.pop();
  9052. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  9053. } else {
  9054. this.setContext(types.j_expr);
  9055. this.state.canStartJSXElement = true;
  9056. }
  9057. } else {
  9058. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  9059. }
  9060. }
  9061. };
  9062. class TypeScriptScope extends Scope {
  9063. constructor(...args) {
  9064. super(...args);
  9065. this.tsNames = new Map();
  9066. }
  9067. }
  9068. class TypeScriptScopeHandler extends ScopeHandler {
  9069. constructor(...args) {
  9070. super(...args);
  9071. this.importsStack = [];
  9072. }
  9073. createScope(flags) {
  9074. this.importsStack.push(new Set());
  9075. return new TypeScriptScope(flags);
  9076. }
  9077. enter(flags) {
  9078. if (flags === 1024) {
  9079. this.importsStack.push(new Set());
  9080. }
  9081. super.enter(flags);
  9082. }
  9083. exit() {
  9084. const flags = super.exit();
  9085. if (flags === 1024) {
  9086. this.importsStack.pop();
  9087. }
  9088. return flags;
  9089. }
  9090. hasImport(name, allowShadow) {
  9091. const len = this.importsStack.length;
  9092. if (this.importsStack[len - 1].has(name)) {
  9093. return true;
  9094. }
  9095. if (!allowShadow && len > 1) {
  9096. for (let i = 0; i < len - 1; i++) {
  9097. if (this.importsStack[i].has(name)) return true;
  9098. }
  9099. }
  9100. return false;
  9101. }
  9102. declareName(name, bindingType, loc) {
  9103. if (bindingType & 4096) {
  9104. if (this.hasImport(name, true)) {
  9105. this.parser.raise(Errors.VarRedeclaration, loc, {
  9106. identifierName: name
  9107. });
  9108. }
  9109. this.importsStack[this.importsStack.length - 1].add(name);
  9110. return;
  9111. }
  9112. const scope = this.currentScope();
  9113. let type = scope.tsNames.get(name) || 0;
  9114. if (bindingType & 1024) {
  9115. this.maybeExportDefined(scope, name);
  9116. scope.tsNames.set(name, type | 16);
  9117. return;
  9118. }
  9119. super.declareName(name, bindingType, loc);
  9120. if (bindingType & 2) {
  9121. if (!(bindingType & 1)) {
  9122. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  9123. this.maybeExportDefined(scope, name);
  9124. }
  9125. type = type | 1;
  9126. }
  9127. if (bindingType & 256) {
  9128. type = type | 2;
  9129. }
  9130. if (bindingType & 512) {
  9131. type = type | 4;
  9132. }
  9133. if (bindingType & 128) {
  9134. type = type | 8;
  9135. }
  9136. if (type) scope.tsNames.set(name, type);
  9137. }
  9138. isRedeclaredInScope(scope, name, bindingType) {
  9139. const type = scope.tsNames.get(name);
  9140. if ((type & 2) > 0) {
  9141. if (bindingType & 256) {
  9142. const isConst = !!(bindingType & 512);
  9143. const wasConst = (type & 4) > 0;
  9144. return isConst !== wasConst;
  9145. }
  9146. return true;
  9147. }
  9148. if (bindingType & 128 && (type & 8) > 0) {
  9149. if (scope.names.get(name) & 2) {
  9150. return !!(bindingType & 1);
  9151. } else {
  9152. return false;
  9153. }
  9154. }
  9155. if (bindingType & 2 && (type & 1) > 0) {
  9156. return true;
  9157. }
  9158. return super.isRedeclaredInScope(scope, name, bindingType);
  9159. }
  9160. checkLocalExport(id) {
  9161. const {
  9162. name
  9163. } = id;
  9164. if (this.hasImport(name)) return;
  9165. const len = this.scopeStack.length;
  9166. for (let i = len - 1; i >= 0; i--) {
  9167. const scope = this.scopeStack[i];
  9168. const type = scope.tsNames.get(name);
  9169. if ((type & 1) > 0 || (type & 16) > 0) {
  9170. return;
  9171. }
  9172. }
  9173. super.checkLocalExport(id);
  9174. }
  9175. }
  9176. class ProductionParameterHandler {
  9177. constructor() {
  9178. this.stacks = [];
  9179. }
  9180. enter(flags) {
  9181. this.stacks.push(flags);
  9182. }
  9183. exit() {
  9184. this.stacks.pop();
  9185. }
  9186. currentFlags() {
  9187. return this.stacks[this.stacks.length - 1];
  9188. }
  9189. get hasAwait() {
  9190. return (this.currentFlags() & 2) > 0;
  9191. }
  9192. get hasYield() {
  9193. return (this.currentFlags() & 1) > 0;
  9194. }
  9195. get hasReturn() {
  9196. return (this.currentFlags() & 4) > 0;
  9197. }
  9198. get hasIn() {
  9199. return (this.currentFlags() & 8) > 0;
  9200. }
  9201. }
  9202. function functionFlags(isAsync, isGenerator) {
  9203. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  9204. }
  9205. class BaseParser {
  9206. constructor() {
  9207. this.sawUnambiguousESM = false;
  9208. this.ambiguousScriptDifferentAst = false;
  9209. }
  9210. sourceToOffsetPos(sourcePos) {
  9211. return sourcePos + this.startIndex;
  9212. }
  9213. offsetToSourcePos(offsetPos) {
  9214. return offsetPos - this.startIndex;
  9215. }
  9216. hasPlugin(pluginConfig) {
  9217. if (typeof pluginConfig === "string") {
  9218. return this.plugins.has(pluginConfig);
  9219. } else {
  9220. const [pluginName, pluginOptions] = pluginConfig;
  9221. if (!this.hasPlugin(pluginName)) {
  9222. return false;
  9223. }
  9224. const actualOptions = this.plugins.get(pluginName);
  9225. for (const key of Object.keys(pluginOptions)) {
  9226. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  9227. return false;
  9228. }
  9229. }
  9230. return true;
  9231. }
  9232. }
  9233. getPluginOption(plugin, name) {
  9234. var _this$plugins$get;
  9235. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  9236. }
  9237. }
  9238. function setTrailingComments(node, comments) {
  9239. if (node.trailingComments === undefined) {
  9240. node.trailingComments = comments;
  9241. } else {
  9242. node.trailingComments.unshift(...comments);
  9243. }
  9244. }
  9245. function setLeadingComments(node, comments) {
  9246. if (node.leadingComments === undefined) {
  9247. node.leadingComments = comments;
  9248. } else {
  9249. node.leadingComments.unshift(...comments);
  9250. }
  9251. }
  9252. function setInnerComments(node, comments) {
  9253. if (node.innerComments === undefined) {
  9254. node.innerComments = comments;
  9255. } else {
  9256. node.innerComments.unshift(...comments);
  9257. }
  9258. }
  9259. function adjustInnerComments(node, elements, commentWS) {
  9260. let lastElement = null;
  9261. let i = elements.length;
  9262. while (lastElement === null && i > 0) {
  9263. lastElement = elements[--i];
  9264. }
  9265. if (lastElement === null || lastElement.start > commentWS.start) {
  9266. setInnerComments(node, commentWS.comments);
  9267. } else {
  9268. setTrailingComments(lastElement, commentWS.comments);
  9269. }
  9270. }
  9271. class CommentsParser extends BaseParser {
  9272. addComment(comment) {
  9273. if (this.filename) comment.loc.filename = this.filename;
  9274. const {
  9275. commentsLen
  9276. } = this.state;
  9277. if (this.comments.length !== commentsLen) {
  9278. this.comments.length = commentsLen;
  9279. }
  9280. this.comments.push(comment);
  9281. this.state.commentsLen++;
  9282. }
  9283. processComment(node) {
  9284. const {
  9285. commentStack
  9286. } = this.state;
  9287. const commentStackLength = commentStack.length;
  9288. if (commentStackLength === 0) return;
  9289. let i = commentStackLength - 1;
  9290. const lastCommentWS = commentStack[i];
  9291. if (lastCommentWS.start === node.end) {
  9292. lastCommentWS.leadingNode = node;
  9293. i--;
  9294. }
  9295. const {
  9296. start: nodeStart
  9297. } = node;
  9298. for (; i >= 0; i--) {
  9299. const commentWS = commentStack[i];
  9300. const commentEnd = commentWS.end;
  9301. if (commentEnd > nodeStart) {
  9302. commentWS.containingNode = node;
  9303. this.finalizeComment(commentWS);
  9304. commentStack.splice(i, 1);
  9305. } else {
  9306. if (commentEnd === nodeStart) {
  9307. commentWS.trailingNode = node;
  9308. }
  9309. break;
  9310. }
  9311. }
  9312. }
  9313. finalizeComment(commentWS) {
  9314. var _node$options;
  9315. const {
  9316. comments
  9317. } = commentWS;
  9318. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  9319. if (commentWS.leadingNode !== null) {
  9320. setTrailingComments(commentWS.leadingNode, comments);
  9321. }
  9322. if (commentWS.trailingNode !== null) {
  9323. setLeadingComments(commentWS.trailingNode, comments);
  9324. }
  9325. } else {
  9326. const node = commentWS.containingNode;
  9327. const commentStart = commentWS.start;
  9328. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  9329. switch (node.type) {
  9330. case "ObjectExpression":
  9331. case "ObjectPattern":
  9332. case "RecordExpression":
  9333. adjustInnerComments(node, node.properties, commentWS);
  9334. break;
  9335. case "CallExpression":
  9336. case "OptionalCallExpression":
  9337. adjustInnerComments(node, node.arguments, commentWS);
  9338. break;
  9339. case "ImportExpression":
  9340. adjustInnerComments(node, [node.source, (_node$options = node.options) != null ? _node$options : null], commentWS);
  9341. break;
  9342. case "FunctionDeclaration":
  9343. case "FunctionExpression":
  9344. case "ArrowFunctionExpression":
  9345. case "ObjectMethod":
  9346. case "ClassMethod":
  9347. case "ClassPrivateMethod":
  9348. adjustInnerComments(node, node.params, commentWS);
  9349. break;
  9350. case "ArrayExpression":
  9351. case "ArrayPattern":
  9352. case "TupleExpression":
  9353. adjustInnerComments(node, node.elements, commentWS);
  9354. break;
  9355. case "ExportNamedDeclaration":
  9356. case "ImportDeclaration":
  9357. adjustInnerComments(node, node.specifiers, commentWS);
  9358. break;
  9359. case "TSEnumDeclaration":
  9360. {
  9361. adjustInnerComments(node, node.members, commentWS);
  9362. }
  9363. break;
  9364. case "TSEnumBody":
  9365. adjustInnerComments(node, node.members, commentWS);
  9366. break;
  9367. default:
  9368. {
  9369. setInnerComments(node, comments);
  9370. }
  9371. }
  9372. } else {
  9373. setInnerComments(node, comments);
  9374. }
  9375. }
  9376. }
  9377. finalizeRemainingComments() {
  9378. const {
  9379. commentStack
  9380. } = this.state;
  9381. for (let i = commentStack.length - 1; i >= 0; i--) {
  9382. this.finalizeComment(commentStack[i]);
  9383. }
  9384. this.state.commentStack = [];
  9385. }
  9386. resetPreviousNodeTrailingComments(node) {
  9387. const {
  9388. commentStack
  9389. } = this.state;
  9390. const {
  9391. length
  9392. } = commentStack;
  9393. if (length === 0) return;
  9394. const commentWS = commentStack[length - 1];
  9395. if (commentWS.leadingNode === node) {
  9396. commentWS.leadingNode = null;
  9397. }
  9398. }
  9399. takeSurroundingComments(node, start, end) {
  9400. const {
  9401. commentStack
  9402. } = this.state;
  9403. const commentStackLength = commentStack.length;
  9404. if (commentStackLength === 0) return;
  9405. let i = commentStackLength - 1;
  9406. for (; i >= 0; i--) {
  9407. const commentWS = commentStack[i];
  9408. const commentEnd = commentWS.end;
  9409. const commentStart = commentWS.start;
  9410. if (commentStart === end) {
  9411. commentWS.leadingNode = node;
  9412. } else if (commentEnd === start) {
  9413. commentWS.trailingNode = node;
  9414. } else if (commentEnd < start) {
  9415. break;
  9416. }
  9417. }
  9418. }
  9419. }
  9420. class State {
  9421. constructor() {
  9422. this.flags = 1024;
  9423. this.startIndex = void 0;
  9424. this.curLine = void 0;
  9425. this.lineStart = void 0;
  9426. this.startLoc = void 0;
  9427. this.endLoc = void 0;
  9428. this.errors = [];
  9429. this.potentialArrowAt = -1;
  9430. this.noArrowAt = [];
  9431. this.noArrowParamsConversionAt = [];
  9432. this.topicContext = {
  9433. maxNumOfResolvableTopics: 0,
  9434. maxTopicIndex: null
  9435. };
  9436. this.labels = [];
  9437. this.commentsLen = 0;
  9438. this.commentStack = [];
  9439. this.pos = 0;
  9440. this.type = 140;
  9441. this.value = null;
  9442. this.start = 0;
  9443. this.end = 0;
  9444. this.lastTokEndLoc = null;
  9445. this.lastTokStartLoc = null;
  9446. this.context = [types.brace];
  9447. this.firstInvalidTemplateEscapePos = null;
  9448. this.strictErrors = new Map();
  9449. this.tokensLength = 0;
  9450. }
  9451. get strict() {
  9452. return (this.flags & 1) > 0;
  9453. }
  9454. set strict(v) {
  9455. if (v) this.flags |= 1;else this.flags &= -2;
  9456. }
  9457. init({
  9458. strictMode,
  9459. sourceType,
  9460. startIndex,
  9461. startLine,
  9462. startColumn
  9463. }) {
  9464. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  9465. this.startIndex = startIndex;
  9466. this.curLine = startLine;
  9467. this.lineStart = -startColumn;
  9468. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  9469. }
  9470. get maybeInArrowParameters() {
  9471. return (this.flags & 2) > 0;
  9472. }
  9473. set maybeInArrowParameters(v) {
  9474. if (v) this.flags |= 2;else this.flags &= -3;
  9475. }
  9476. get inType() {
  9477. return (this.flags & 4) > 0;
  9478. }
  9479. set inType(v) {
  9480. if (v) this.flags |= 4;else this.flags &= -5;
  9481. }
  9482. get noAnonFunctionType() {
  9483. return (this.flags & 8) > 0;
  9484. }
  9485. set noAnonFunctionType(v) {
  9486. if (v) this.flags |= 8;else this.flags &= -9;
  9487. }
  9488. get hasFlowComment() {
  9489. return (this.flags & 16) > 0;
  9490. }
  9491. set hasFlowComment(v) {
  9492. if (v) this.flags |= 16;else this.flags &= -17;
  9493. }
  9494. get isAmbientContext() {
  9495. return (this.flags & 32) > 0;
  9496. }
  9497. set isAmbientContext(v) {
  9498. if (v) this.flags |= 32;else this.flags &= -33;
  9499. }
  9500. get inAbstractClass() {
  9501. return (this.flags & 64) > 0;
  9502. }
  9503. set inAbstractClass(v) {
  9504. if (v) this.flags |= 64;else this.flags &= -65;
  9505. }
  9506. get inDisallowConditionalTypesContext() {
  9507. return (this.flags & 128) > 0;
  9508. }
  9509. set inDisallowConditionalTypesContext(v) {
  9510. if (v) this.flags |= 128;else this.flags &= -129;
  9511. }
  9512. get soloAwait() {
  9513. return (this.flags & 256) > 0;
  9514. }
  9515. set soloAwait(v) {
  9516. if (v) this.flags |= 256;else this.flags &= -257;
  9517. }
  9518. get inFSharpPipelineDirectBody() {
  9519. return (this.flags & 512) > 0;
  9520. }
  9521. set inFSharpPipelineDirectBody(v) {
  9522. if (v) this.flags |= 512;else this.flags &= -513;
  9523. }
  9524. get canStartJSXElement() {
  9525. return (this.flags & 1024) > 0;
  9526. }
  9527. set canStartJSXElement(v) {
  9528. if (v) this.flags |= 1024;else this.flags &= -1025;
  9529. }
  9530. get containsEsc() {
  9531. return (this.flags & 2048) > 0;
  9532. }
  9533. set containsEsc(v) {
  9534. if (v) this.flags |= 2048;else this.flags &= -2049;
  9535. }
  9536. get hasTopLevelAwait() {
  9537. return (this.flags & 4096) > 0;
  9538. }
  9539. set hasTopLevelAwait(v) {
  9540. if (v) this.flags |= 4096;else this.flags &= -4097;
  9541. }
  9542. curPosition() {
  9543. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  9544. }
  9545. clone() {
  9546. const state = new State();
  9547. state.flags = this.flags;
  9548. state.startIndex = this.startIndex;
  9549. state.curLine = this.curLine;
  9550. state.lineStart = this.lineStart;
  9551. state.startLoc = this.startLoc;
  9552. state.endLoc = this.endLoc;
  9553. state.errors = this.errors.slice();
  9554. state.potentialArrowAt = this.potentialArrowAt;
  9555. state.noArrowAt = this.noArrowAt.slice();
  9556. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  9557. state.topicContext = this.topicContext;
  9558. state.labels = this.labels.slice();
  9559. state.commentsLen = this.commentsLen;
  9560. state.commentStack = this.commentStack.slice();
  9561. state.pos = this.pos;
  9562. state.type = this.type;
  9563. state.value = this.value;
  9564. state.start = this.start;
  9565. state.end = this.end;
  9566. state.lastTokEndLoc = this.lastTokEndLoc;
  9567. state.lastTokStartLoc = this.lastTokStartLoc;
  9568. state.context = this.context.slice();
  9569. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  9570. state.strictErrors = this.strictErrors;
  9571. state.tokensLength = this.tokensLength;
  9572. return state;
  9573. }
  9574. }
  9575. var _isDigit = function isDigit(code) {
  9576. return code >= 48 && code <= 57;
  9577. };
  9578. const forbiddenNumericSeparatorSiblings = {
  9579. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  9580. hex: new Set([46, 88, 95, 120])
  9581. };
  9582. const isAllowedNumericSeparatorSibling = {
  9583. bin: ch => ch === 48 || ch === 49,
  9584. oct: ch => ch >= 48 && ch <= 55,
  9585. dec: ch => ch >= 48 && ch <= 57,
  9586. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  9587. };
  9588. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  9589. const initialPos = pos;
  9590. const initialLineStart = lineStart;
  9591. const initialCurLine = curLine;
  9592. let out = "";
  9593. let firstInvalidLoc = null;
  9594. let chunkStart = pos;
  9595. const {
  9596. length
  9597. } = input;
  9598. for (;;) {
  9599. if (pos >= length) {
  9600. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  9601. out += input.slice(chunkStart, pos);
  9602. break;
  9603. }
  9604. const ch = input.charCodeAt(pos);
  9605. if (isStringEnd(type, ch, input, pos)) {
  9606. out += input.slice(chunkStart, pos);
  9607. break;
  9608. }
  9609. if (ch === 92) {
  9610. out += input.slice(chunkStart, pos);
  9611. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  9612. if (res.ch === null && !firstInvalidLoc) {
  9613. firstInvalidLoc = {
  9614. pos,
  9615. lineStart,
  9616. curLine
  9617. };
  9618. } else {
  9619. out += res.ch;
  9620. }
  9621. ({
  9622. pos,
  9623. lineStart,
  9624. curLine
  9625. } = res);
  9626. chunkStart = pos;
  9627. } else if (ch === 8232 || ch === 8233) {
  9628. ++pos;
  9629. ++curLine;
  9630. lineStart = pos;
  9631. } else if (ch === 10 || ch === 13) {
  9632. if (type === "template") {
  9633. out += input.slice(chunkStart, pos) + "\n";
  9634. ++pos;
  9635. if (ch === 13 && input.charCodeAt(pos) === 10) {
  9636. ++pos;
  9637. }
  9638. ++curLine;
  9639. chunkStart = lineStart = pos;
  9640. } else {
  9641. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  9642. }
  9643. } else {
  9644. ++pos;
  9645. }
  9646. }
  9647. return {
  9648. pos,
  9649. str: out,
  9650. firstInvalidLoc,
  9651. lineStart,
  9652. curLine,
  9653. containsInvalid: !!firstInvalidLoc
  9654. };
  9655. }
  9656. function isStringEnd(type, ch, input, pos) {
  9657. if (type === "template") {
  9658. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  9659. }
  9660. return ch === (type === "double" ? 34 : 39);
  9661. }
  9662. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  9663. const throwOnInvalid = !inTemplate;
  9664. pos++;
  9665. const res = ch => ({
  9666. pos,
  9667. ch,
  9668. lineStart,
  9669. curLine
  9670. });
  9671. const ch = input.charCodeAt(pos++);
  9672. switch (ch) {
  9673. case 110:
  9674. return res("\n");
  9675. case 114:
  9676. return res("\r");
  9677. case 120:
  9678. {
  9679. let code;
  9680. ({
  9681. code,
  9682. pos
  9683. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  9684. return res(code === null ? null : String.fromCharCode(code));
  9685. }
  9686. case 117:
  9687. {
  9688. let code;
  9689. ({
  9690. code,
  9691. pos
  9692. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  9693. return res(code === null ? null : String.fromCodePoint(code));
  9694. }
  9695. case 116:
  9696. return res("\t");
  9697. case 98:
  9698. return res("\b");
  9699. case 118:
  9700. return res("\u000b");
  9701. case 102:
  9702. return res("\f");
  9703. case 13:
  9704. if (input.charCodeAt(pos) === 10) {
  9705. ++pos;
  9706. }
  9707. case 10:
  9708. lineStart = pos;
  9709. ++curLine;
  9710. case 8232:
  9711. case 8233:
  9712. return res("");
  9713. case 56:
  9714. case 57:
  9715. if (inTemplate) {
  9716. return res(null);
  9717. } else {
  9718. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  9719. }
  9720. default:
  9721. if (ch >= 48 && ch <= 55) {
  9722. const startPos = pos - 1;
  9723. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  9724. let octalStr = match[0];
  9725. let octal = parseInt(octalStr, 8);
  9726. if (octal > 255) {
  9727. octalStr = octalStr.slice(0, -1);
  9728. octal = parseInt(octalStr, 8);
  9729. }
  9730. pos += octalStr.length - 1;
  9731. const next = input.charCodeAt(pos);
  9732. if (octalStr !== "0" || next === 56 || next === 57) {
  9733. if (inTemplate) {
  9734. return res(null);
  9735. } else {
  9736. errors.strictNumericEscape(startPos, lineStart, curLine);
  9737. }
  9738. }
  9739. return res(String.fromCharCode(octal));
  9740. }
  9741. return res(String.fromCharCode(ch));
  9742. }
  9743. }
  9744. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  9745. const initialPos = pos;
  9746. let n;
  9747. ({
  9748. n,
  9749. pos
  9750. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  9751. if (n === null) {
  9752. if (throwOnInvalid) {
  9753. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  9754. } else {
  9755. pos = initialPos - 1;
  9756. }
  9757. }
  9758. return {
  9759. code: n,
  9760. pos
  9761. };
  9762. }
  9763. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  9764. const start = pos;
  9765. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  9766. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  9767. let invalid = false;
  9768. let total = 0;
  9769. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  9770. const code = input.charCodeAt(pos);
  9771. let val;
  9772. if (code === 95 && allowNumSeparator !== "bail") {
  9773. const prev = input.charCodeAt(pos - 1);
  9774. const next = input.charCodeAt(pos + 1);
  9775. if (!allowNumSeparator) {
  9776. if (bailOnError) return {
  9777. n: null,
  9778. pos
  9779. };
  9780. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  9781. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  9782. if (bailOnError) return {
  9783. n: null,
  9784. pos
  9785. };
  9786. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  9787. }
  9788. ++pos;
  9789. continue;
  9790. }
  9791. if (code >= 97) {
  9792. val = code - 97 + 10;
  9793. } else if (code >= 65) {
  9794. val = code - 65 + 10;
  9795. } else if (_isDigit(code)) {
  9796. val = code - 48;
  9797. } else {
  9798. val = Infinity;
  9799. }
  9800. if (val >= radix) {
  9801. if (val <= 9 && bailOnError) {
  9802. return {
  9803. n: null,
  9804. pos
  9805. };
  9806. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  9807. val = 0;
  9808. } else if (forceLen) {
  9809. val = 0;
  9810. invalid = true;
  9811. } else {
  9812. break;
  9813. }
  9814. }
  9815. ++pos;
  9816. total = total * radix + val;
  9817. }
  9818. if (pos === start || len != null && pos - start !== len || invalid) {
  9819. return {
  9820. n: null,
  9821. pos
  9822. };
  9823. }
  9824. return {
  9825. n: total,
  9826. pos
  9827. };
  9828. }
  9829. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  9830. const ch = input.charCodeAt(pos);
  9831. let code;
  9832. if (ch === 123) {
  9833. ++pos;
  9834. ({
  9835. code,
  9836. pos
  9837. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  9838. ++pos;
  9839. if (code !== null && code > 0x10ffff) {
  9840. if (throwOnInvalid) {
  9841. errors.invalidCodePoint(pos, lineStart, curLine);
  9842. } else {
  9843. return {
  9844. code: null,
  9845. pos
  9846. };
  9847. }
  9848. }
  9849. } else {
  9850. ({
  9851. code,
  9852. pos
  9853. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  9854. }
  9855. return {
  9856. code,
  9857. pos
  9858. };
  9859. }
  9860. function buildPosition(pos, lineStart, curLine) {
  9861. return new Position(curLine, pos - lineStart, pos);
  9862. }
  9863. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  9864. class Token {
  9865. constructor(state) {
  9866. const startIndex = state.startIndex || 0;
  9867. this.type = state.type;
  9868. this.value = state.value;
  9869. this.start = startIndex + state.start;
  9870. this.end = startIndex + state.end;
  9871. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  9872. }
  9873. }
  9874. class Tokenizer extends CommentsParser {
  9875. constructor(options, input) {
  9876. super();
  9877. this.isLookahead = void 0;
  9878. this.tokens = [];
  9879. this.errorHandlers_readInt = {
  9880. invalidDigit: (pos, lineStart, curLine, radix) => {
  9881. if (!(this.optionFlags & 2048)) return false;
  9882. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  9883. radix
  9884. });
  9885. return true;
  9886. },
  9887. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  9888. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  9889. };
  9890. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  9891. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  9892. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  9893. });
  9894. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  9895. strictNumericEscape: (pos, lineStart, curLine) => {
  9896. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  9897. },
  9898. unterminated: (pos, lineStart, curLine) => {
  9899. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  9900. }
  9901. });
  9902. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  9903. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  9904. unterminated: (pos, lineStart, curLine) => {
  9905. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  9906. }
  9907. });
  9908. this.state = new State();
  9909. this.state.init(options);
  9910. this.input = input;
  9911. this.length = input.length;
  9912. this.comments = [];
  9913. this.isLookahead = false;
  9914. }
  9915. pushToken(token) {
  9916. this.tokens.length = this.state.tokensLength;
  9917. this.tokens.push(token);
  9918. ++this.state.tokensLength;
  9919. }
  9920. next() {
  9921. this.checkKeywordEscapes();
  9922. if (this.optionFlags & 256) {
  9923. this.pushToken(new Token(this.state));
  9924. }
  9925. this.state.lastTokEndLoc = this.state.endLoc;
  9926. this.state.lastTokStartLoc = this.state.startLoc;
  9927. this.nextToken();
  9928. }
  9929. eat(type) {
  9930. if (this.match(type)) {
  9931. this.next();
  9932. return true;
  9933. } else {
  9934. return false;
  9935. }
  9936. }
  9937. match(type) {
  9938. return this.state.type === type;
  9939. }
  9940. createLookaheadState(state) {
  9941. return {
  9942. pos: state.pos,
  9943. value: null,
  9944. type: state.type,
  9945. start: state.start,
  9946. end: state.end,
  9947. context: [this.curContext()],
  9948. inType: state.inType,
  9949. startLoc: state.startLoc,
  9950. lastTokEndLoc: state.lastTokEndLoc,
  9951. curLine: state.curLine,
  9952. lineStart: state.lineStart,
  9953. curPosition: state.curPosition
  9954. };
  9955. }
  9956. lookahead() {
  9957. const old = this.state;
  9958. this.state = this.createLookaheadState(old);
  9959. this.isLookahead = true;
  9960. this.nextToken();
  9961. this.isLookahead = false;
  9962. const curr = this.state;
  9963. this.state = old;
  9964. return curr;
  9965. }
  9966. nextTokenStart() {
  9967. return this.nextTokenStartSince(this.state.pos);
  9968. }
  9969. nextTokenStartSince(pos) {
  9970. skipWhiteSpace.lastIndex = pos;
  9971. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  9972. }
  9973. lookaheadCharCode() {
  9974. return this.lookaheadCharCodeSince(this.state.pos);
  9975. }
  9976. lookaheadCharCodeSince(pos) {
  9977. return this.input.charCodeAt(this.nextTokenStartSince(pos));
  9978. }
  9979. nextTokenInLineStart() {
  9980. return this.nextTokenInLineStartSince(this.state.pos);
  9981. }
  9982. nextTokenInLineStartSince(pos) {
  9983. skipWhiteSpaceInLine.lastIndex = pos;
  9984. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  9985. }
  9986. lookaheadInLineCharCode() {
  9987. return this.input.charCodeAt(this.nextTokenInLineStart());
  9988. }
  9989. codePointAtPos(pos) {
  9990. let cp = this.input.charCodeAt(pos);
  9991. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  9992. const trail = this.input.charCodeAt(pos);
  9993. if ((trail & 0xfc00) === 0xdc00) {
  9994. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  9995. }
  9996. }
  9997. return cp;
  9998. }
  9999. setStrict(strict) {
  10000. this.state.strict = strict;
  10001. if (strict) {
  10002. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  10003. this.state.strictErrors.clear();
  10004. }
  10005. }
  10006. curContext() {
  10007. return this.state.context[this.state.context.length - 1];
  10008. }
  10009. nextToken() {
  10010. this.skipSpace();
  10011. this.state.start = this.state.pos;
  10012. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  10013. if (this.state.pos >= this.length) {
  10014. this.finishToken(140);
  10015. return;
  10016. }
  10017. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  10018. }
  10019. skipBlockComment(commentEnd) {
  10020. let startLoc;
  10021. if (!this.isLookahead) startLoc = this.state.curPosition();
  10022. const start = this.state.pos;
  10023. const end = this.input.indexOf(commentEnd, start + 2);
  10024. if (end === -1) {
  10025. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  10026. }
  10027. this.state.pos = end + commentEnd.length;
  10028. lineBreakG.lastIndex = start + 2;
  10029. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  10030. ++this.state.curLine;
  10031. this.state.lineStart = lineBreakG.lastIndex;
  10032. }
  10033. if (this.isLookahead) return;
  10034. const comment = {
  10035. type: "CommentBlock",
  10036. value: this.input.slice(start + 2, end),
  10037. start: this.sourceToOffsetPos(start),
  10038. end: this.sourceToOffsetPos(end + commentEnd.length),
  10039. loc: new SourceLocation(startLoc, this.state.curPosition())
  10040. };
  10041. if (this.optionFlags & 256) this.pushToken(comment);
  10042. return comment;
  10043. }
  10044. skipLineComment(startSkip) {
  10045. const start = this.state.pos;
  10046. let startLoc;
  10047. if (!this.isLookahead) startLoc = this.state.curPosition();
  10048. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  10049. if (this.state.pos < this.length) {
  10050. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  10051. ch = this.input.charCodeAt(this.state.pos);
  10052. }
  10053. }
  10054. if (this.isLookahead) return;
  10055. const end = this.state.pos;
  10056. const value = this.input.slice(start + startSkip, end);
  10057. const comment = {
  10058. type: "CommentLine",
  10059. value,
  10060. start: this.sourceToOffsetPos(start),
  10061. end: this.sourceToOffsetPos(end),
  10062. loc: new SourceLocation(startLoc, this.state.curPosition())
  10063. };
  10064. if (this.optionFlags & 256) this.pushToken(comment);
  10065. return comment;
  10066. }
  10067. skipSpace() {
  10068. const spaceStart = this.state.pos;
  10069. const comments = this.optionFlags & 4096 ? [] : null;
  10070. loop: while (this.state.pos < this.length) {
  10071. const ch = this.input.charCodeAt(this.state.pos);
  10072. switch (ch) {
  10073. case 32:
  10074. case 160:
  10075. case 9:
  10076. ++this.state.pos;
  10077. break;
  10078. case 13:
  10079. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  10080. ++this.state.pos;
  10081. }
  10082. case 10:
  10083. case 8232:
  10084. case 8233:
  10085. ++this.state.pos;
  10086. ++this.state.curLine;
  10087. this.state.lineStart = this.state.pos;
  10088. break;
  10089. case 47:
  10090. switch (this.input.charCodeAt(this.state.pos + 1)) {
  10091. case 42:
  10092. {
  10093. const comment = this.skipBlockComment("*/");
  10094. if (comment !== undefined) {
  10095. this.addComment(comment);
  10096. comments == null || comments.push(comment);
  10097. }
  10098. break;
  10099. }
  10100. case 47:
  10101. {
  10102. const comment = this.skipLineComment(2);
  10103. if (comment !== undefined) {
  10104. this.addComment(comment);
  10105. comments == null || comments.push(comment);
  10106. }
  10107. break;
  10108. }
  10109. default:
  10110. break loop;
  10111. }
  10112. break;
  10113. default:
  10114. if (isWhitespace(ch)) {
  10115. ++this.state.pos;
  10116. } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
  10117. const pos = this.state.pos;
  10118. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  10119. const comment = this.skipLineComment(3);
  10120. if (comment !== undefined) {
  10121. this.addComment(comment);
  10122. comments == null || comments.push(comment);
  10123. }
  10124. } else {
  10125. break loop;
  10126. }
  10127. } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
  10128. const pos = this.state.pos;
  10129. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  10130. const comment = this.skipLineComment(4);
  10131. if (comment !== undefined) {
  10132. this.addComment(comment);
  10133. comments == null || comments.push(comment);
  10134. }
  10135. } else {
  10136. break loop;
  10137. }
  10138. } else {
  10139. break loop;
  10140. }
  10141. }
  10142. }
  10143. if ((comments == null ? void 0 : comments.length) > 0) {
  10144. const end = this.state.pos;
  10145. const commentWhitespace = {
  10146. start: this.sourceToOffsetPos(spaceStart),
  10147. end: this.sourceToOffsetPos(end),
  10148. comments: comments,
  10149. leadingNode: null,
  10150. trailingNode: null,
  10151. containingNode: null
  10152. };
  10153. this.state.commentStack.push(commentWhitespace);
  10154. }
  10155. }
  10156. finishToken(type, val) {
  10157. this.state.end = this.state.pos;
  10158. this.state.endLoc = this.state.curPosition();
  10159. const prevType = this.state.type;
  10160. this.state.type = type;
  10161. this.state.value = val;
  10162. if (!this.isLookahead) {
  10163. this.updateContext(prevType);
  10164. }
  10165. }
  10166. replaceToken(type) {
  10167. this.state.type = type;
  10168. this.updateContext();
  10169. }
  10170. readToken_numberSign() {
  10171. if (this.state.pos === 0 && this.readToken_interpreter()) {
  10172. return;
  10173. }
  10174. const nextPos = this.state.pos + 1;
  10175. const next = this.codePointAtPos(nextPos);
  10176. if (next >= 48 && next <= 57) {
  10177. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  10178. }
  10179. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  10180. this.expectPlugin("recordAndTuple");
  10181. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  10182. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  10183. }
  10184. this.state.pos += 2;
  10185. if (next === 123) {
  10186. this.finishToken(7);
  10187. } else {
  10188. this.finishToken(1);
  10189. }
  10190. } else if (isIdentifierStart(next)) {
  10191. ++this.state.pos;
  10192. this.finishToken(139, this.readWord1(next));
  10193. } else if (next === 92) {
  10194. ++this.state.pos;
  10195. this.finishToken(139, this.readWord1());
  10196. } else {
  10197. this.finishOp(27, 1);
  10198. }
  10199. }
  10200. readToken_dot() {
  10201. const next = this.input.charCodeAt(this.state.pos + 1);
  10202. if (next >= 48 && next <= 57) {
  10203. this.readNumber(true);
  10204. return;
  10205. }
  10206. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  10207. this.state.pos += 3;
  10208. this.finishToken(21);
  10209. } else {
  10210. ++this.state.pos;
  10211. this.finishToken(16);
  10212. }
  10213. }
  10214. readToken_slash() {
  10215. const next = this.input.charCodeAt(this.state.pos + 1);
  10216. if (next === 61) {
  10217. this.finishOp(31, 2);
  10218. } else {
  10219. this.finishOp(56, 1);
  10220. }
  10221. }
  10222. readToken_interpreter() {
  10223. if (this.state.pos !== 0 || this.length < 2) return false;
  10224. let ch = this.input.charCodeAt(this.state.pos + 1);
  10225. if (ch !== 33) return false;
  10226. const start = this.state.pos;
  10227. this.state.pos += 1;
  10228. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  10229. ch = this.input.charCodeAt(this.state.pos);
  10230. }
  10231. const value = this.input.slice(start + 2, this.state.pos);
  10232. this.finishToken(28, value);
  10233. return true;
  10234. }
  10235. readToken_mult_modulo(code) {
  10236. let type = code === 42 ? 55 : 54;
  10237. let width = 1;
  10238. let next = this.input.charCodeAt(this.state.pos + 1);
  10239. if (code === 42 && next === 42) {
  10240. width++;
  10241. next = this.input.charCodeAt(this.state.pos + 2);
  10242. type = 57;
  10243. }
  10244. if (next === 61 && !this.state.inType) {
  10245. width++;
  10246. type = code === 37 ? 33 : 30;
  10247. }
  10248. this.finishOp(type, width);
  10249. }
  10250. readToken_pipe_amp(code) {
  10251. const next = this.input.charCodeAt(this.state.pos + 1);
  10252. if (next === code) {
  10253. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  10254. this.finishOp(30, 3);
  10255. } else {
  10256. this.finishOp(code === 124 ? 41 : 42, 2);
  10257. }
  10258. return;
  10259. }
  10260. if (code === 124) {
  10261. if (next === 62) {
  10262. this.finishOp(39, 2);
  10263. return;
  10264. }
  10265. if (this.hasPlugin("recordAndTuple") && next === 125) {
  10266. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  10267. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  10268. }
  10269. this.state.pos += 2;
  10270. this.finishToken(9);
  10271. return;
  10272. }
  10273. if (this.hasPlugin("recordAndTuple") && next === 93) {
  10274. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  10275. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  10276. }
  10277. this.state.pos += 2;
  10278. this.finishToken(4);
  10279. return;
  10280. }
  10281. }
  10282. if (next === 61) {
  10283. this.finishOp(30, 2);
  10284. return;
  10285. }
  10286. this.finishOp(code === 124 ? 43 : 45, 1);
  10287. }
  10288. readToken_caret() {
  10289. const next = this.input.charCodeAt(this.state.pos + 1);
  10290. if (next === 61 && !this.state.inType) {
  10291. this.finishOp(32, 2);
  10292. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  10293. proposal: "hack",
  10294. topicToken: "^^"
  10295. }])) {
  10296. this.finishOp(37, 2);
  10297. const lookaheadCh = this.input.codePointAt(this.state.pos);
  10298. if (lookaheadCh === 94) {
  10299. this.unexpected();
  10300. }
  10301. } else {
  10302. this.finishOp(44, 1);
  10303. }
  10304. }
  10305. readToken_atSign() {
  10306. const next = this.input.charCodeAt(this.state.pos + 1);
  10307. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  10308. proposal: "hack",
  10309. topicToken: "@@"
  10310. }])) {
  10311. this.finishOp(38, 2);
  10312. } else {
  10313. this.finishOp(26, 1);
  10314. }
  10315. }
  10316. readToken_plus_min(code) {
  10317. const next = this.input.charCodeAt(this.state.pos + 1);
  10318. if (next === code) {
  10319. this.finishOp(34, 2);
  10320. return;
  10321. }
  10322. if (next === 61) {
  10323. this.finishOp(30, 2);
  10324. } else {
  10325. this.finishOp(53, 1);
  10326. }
  10327. }
  10328. readToken_lt() {
  10329. const {
  10330. pos
  10331. } = this.state;
  10332. const next = this.input.charCodeAt(pos + 1);
  10333. if (next === 60) {
  10334. if (this.input.charCodeAt(pos + 2) === 61) {
  10335. this.finishOp(30, 3);
  10336. return;
  10337. }
  10338. this.finishOp(51, 2);
  10339. return;
  10340. }
  10341. if (next === 61) {
  10342. this.finishOp(49, 2);
  10343. return;
  10344. }
  10345. this.finishOp(47, 1);
  10346. }
  10347. readToken_gt() {
  10348. const {
  10349. pos
  10350. } = this.state;
  10351. const next = this.input.charCodeAt(pos + 1);
  10352. if (next === 62) {
  10353. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  10354. if (this.input.charCodeAt(pos + size) === 61) {
  10355. this.finishOp(30, size + 1);
  10356. return;
  10357. }
  10358. this.finishOp(52, size);
  10359. return;
  10360. }
  10361. if (next === 61) {
  10362. this.finishOp(49, 2);
  10363. return;
  10364. }
  10365. this.finishOp(48, 1);
  10366. }
  10367. readToken_eq_excl(code) {
  10368. const next = this.input.charCodeAt(this.state.pos + 1);
  10369. if (next === 61) {
  10370. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  10371. return;
  10372. }
  10373. if (code === 61 && next === 62) {
  10374. this.state.pos += 2;
  10375. this.finishToken(19);
  10376. return;
  10377. }
  10378. this.finishOp(code === 61 ? 29 : 35, 1);
  10379. }
  10380. readToken_question() {
  10381. const next = this.input.charCodeAt(this.state.pos + 1);
  10382. const next2 = this.input.charCodeAt(this.state.pos + 2);
  10383. if (next === 63) {
  10384. if (next2 === 61) {
  10385. this.finishOp(30, 3);
  10386. } else {
  10387. this.finishOp(40, 2);
  10388. }
  10389. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  10390. this.state.pos += 2;
  10391. this.finishToken(18);
  10392. } else {
  10393. ++this.state.pos;
  10394. this.finishToken(17);
  10395. }
  10396. }
  10397. getTokenFromCode(code) {
  10398. switch (code) {
  10399. case 46:
  10400. this.readToken_dot();
  10401. return;
  10402. case 40:
  10403. ++this.state.pos;
  10404. this.finishToken(10);
  10405. return;
  10406. case 41:
  10407. ++this.state.pos;
  10408. this.finishToken(11);
  10409. return;
  10410. case 59:
  10411. ++this.state.pos;
  10412. this.finishToken(13);
  10413. return;
  10414. case 44:
  10415. ++this.state.pos;
  10416. this.finishToken(12);
  10417. return;
  10418. case 91:
  10419. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  10420. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  10421. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  10422. }
  10423. this.state.pos += 2;
  10424. this.finishToken(2);
  10425. } else {
  10426. ++this.state.pos;
  10427. this.finishToken(0);
  10428. }
  10429. return;
  10430. case 93:
  10431. ++this.state.pos;
  10432. this.finishToken(3);
  10433. return;
  10434. case 123:
  10435. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  10436. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  10437. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  10438. }
  10439. this.state.pos += 2;
  10440. this.finishToken(6);
  10441. } else {
  10442. ++this.state.pos;
  10443. this.finishToken(5);
  10444. }
  10445. return;
  10446. case 125:
  10447. ++this.state.pos;
  10448. this.finishToken(8);
  10449. return;
  10450. case 58:
  10451. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  10452. this.finishOp(15, 2);
  10453. } else {
  10454. ++this.state.pos;
  10455. this.finishToken(14);
  10456. }
  10457. return;
  10458. case 63:
  10459. this.readToken_question();
  10460. return;
  10461. case 96:
  10462. this.readTemplateToken();
  10463. return;
  10464. case 48:
  10465. {
  10466. const next = this.input.charCodeAt(this.state.pos + 1);
  10467. if (next === 120 || next === 88) {
  10468. this.readRadixNumber(16);
  10469. return;
  10470. }
  10471. if (next === 111 || next === 79) {
  10472. this.readRadixNumber(8);
  10473. return;
  10474. }
  10475. if (next === 98 || next === 66) {
  10476. this.readRadixNumber(2);
  10477. return;
  10478. }
  10479. }
  10480. case 49:
  10481. case 50:
  10482. case 51:
  10483. case 52:
  10484. case 53:
  10485. case 54:
  10486. case 55:
  10487. case 56:
  10488. case 57:
  10489. this.readNumber(false);
  10490. return;
  10491. case 34:
  10492. case 39:
  10493. this.readString(code);
  10494. return;
  10495. case 47:
  10496. this.readToken_slash();
  10497. return;
  10498. case 37:
  10499. case 42:
  10500. this.readToken_mult_modulo(code);
  10501. return;
  10502. case 124:
  10503. case 38:
  10504. this.readToken_pipe_amp(code);
  10505. return;
  10506. case 94:
  10507. this.readToken_caret();
  10508. return;
  10509. case 43:
  10510. case 45:
  10511. this.readToken_plus_min(code);
  10512. return;
  10513. case 60:
  10514. this.readToken_lt();
  10515. return;
  10516. case 62:
  10517. this.readToken_gt();
  10518. return;
  10519. case 61:
  10520. case 33:
  10521. this.readToken_eq_excl(code);
  10522. return;
  10523. case 126:
  10524. this.finishOp(36, 1);
  10525. return;
  10526. case 64:
  10527. this.readToken_atSign();
  10528. return;
  10529. case 35:
  10530. this.readToken_numberSign();
  10531. return;
  10532. case 92:
  10533. this.readWord();
  10534. return;
  10535. default:
  10536. if (isIdentifierStart(code)) {
  10537. this.readWord(code);
  10538. return;
  10539. }
  10540. }
  10541. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  10542. unexpected: String.fromCodePoint(code)
  10543. });
  10544. }
  10545. finishOp(type, size) {
  10546. const str = this.input.slice(this.state.pos, this.state.pos + size);
  10547. this.state.pos += size;
  10548. this.finishToken(type, str);
  10549. }
  10550. readRegexp() {
  10551. const startLoc = this.state.startLoc;
  10552. const start = this.state.start + 1;
  10553. let escaped, inClass;
  10554. let {
  10555. pos
  10556. } = this.state;
  10557. for (;; ++pos) {
  10558. if (pos >= this.length) {
  10559. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  10560. }
  10561. const ch = this.input.charCodeAt(pos);
  10562. if (isNewLine(ch)) {
  10563. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  10564. }
  10565. if (escaped) {
  10566. escaped = false;
  10567. } else {
  10568. if (ch === 91) {
  10569. inClass = true;
  10570. } else if (ch === 93 && inClass) {
  10571. inClass = false;
  10572. } else if (ch === 47 && !inClass) {
  10573. break;
  10574. }
  10575. escaped = ch === 92;
  10576. }
  10577. }
  10578. const content = this.input.slice(start, pos);
  10579. ++pos;
  10580. let mods = "";
  10581. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  10582. while (pos < this.length) {
  10583. const cp = this.codePointAtPos(pos);
  10584. const char = String.fromCharCode(cp);
  10585. if (VALID_REGEX_FLAGS.has(cp)) {
  10586. if (cp === 118) {
  10587. if (mods.includes("u")) {
  10588. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  10589. }
  10590. } else if (cp === 117) {
  10591. if (mods.includes("v")) {
  10592. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  10593. }
  10594. }
  10595. if (mods.includes(char)) {
  10596. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  10597. }
  10598. } else if (isIdentifierChar(cp) || cp === 92) {
  10599. this.raise(Errors.MalformedRegExpFlags, nextPos());
  10600. } else {
  10601. break;
  10602. }
  10603. ++pos;
  10604. mods += char;
  10605. }
  10606. this.state.pos = pos;
  10607. this.finishToken(138, {
  10608. pattern: content,
  10609. flags: mods
  10610. });
  10611. }
  10612. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  10613. const {
  10614. n,
  10615. pos
  10616. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  10617. this.state.pos = pos;
  10618. return n;
  10619. }
  10620. readRadixNumber(radix) {
  10621. const start = this.state.pos;
  10622. const startLoc = this.state.curPosition();
  10623. let isBigInt = false;
  10624. this.state.pos += 2;
  10625. const val = this.readInt(radix);
  10626. if (val == null) {
  10627. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  10628. radix
  10629. });
  10630. }
  10631. const next = this.input.charCodeAt(this.state.pos);
  10632. if (next === 110) {
  10633. ++this.state.pos;
  10634. isBigInt = true;
  10635. } else if (next === 109) {
  10636. throw this.raise(Errors.InvalidDecimal, startLoc);
  10637. }
  10638. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  10639. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  10640. }
  10641. if (isBigInt) {
  10642. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  10643. this.finishToken(136, str);
  10644. return;
  10645. }
  10646. this.finishToken(135, val);
  10647. }
  10648. readNumber(startsWithDot) {
  10649. const start = this.state.pos;
  10650. const startLoc = this.state.curPosition();
  10651. let isFloat = false;
  10652. let isBigInt = false;
  10653. let hasExponent = false;
  10654. let isOctal = false;
  10655. if (!startsWithDot && this.readInt(10) === null) {
  10656. this.raise(Errors.InvalidNumber, this.state.curPosition());
  10657. }
  10658. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  10659. if (hasLeadingZero) {
  10660. const integer = this.input.slice(start, this.state.pos);
  10661. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  10662. if (!this.state.strict) {
  10663. const underscorePos = integer.indexOf("_");
  10664. if (underscorePos > 0) {
  10665. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  10666. }
  10667. }
  10668. isOctal = hasLeadingZero && !/[89]/.test(integer);
  10669. }
  10670. let next = this.input.charCodeAt(this.state.pos);
  10671. if (next === 46 && !isOctal) {
  10672. ++this.state.pos;
  10673. this.readInt(10);
  10674. isFloat = true;
  10675. next = this.input.charCodeAt(this.state.pos);
  10676. }
  10677. if ((next === 69 || next === 101) && !isOctal) {
  10678. next = this.input.charCodeAt(++this.state.pos);
  10679. if (next === 43 || next === 45) {
  10680. ++this.state.pos;
  10681. }
  10682. if (this.readInt(10) === null) {
  10683. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  10684. }
  10685. isFloat = true;
  10686. hasExponent = true;
  10687. next = this.input.charCodeAt(this.state.pos);
  10688. }
  10689. if (next === 110) {
  10690. if (isFloat || hasLeadingZero) {
  10691. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  10692. }
  10693. ++this.state.pos;
  10694. isBigInt = true;
  10695. }
  10696. if (next === 109) {
  10697. this.expectPlugin("decimal", this.state.curPosition());
  10698. if (hasExponent || hasLeadingZero) {
  10699. this.raise(Errors.InvalidDecimal, startLoc);
  10700. }
  10701. ++this.state.pos;
  10702. var isDecimal = true;
  10703. }
  10704. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  10705. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  10706. }
  10707. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  10708. if (isBigInt) {
  10709. this.finishToken(136, str);
  10710. return;
  10711. }
  10712. if (isDecimal) {
  10713. this.finishToken(137, str);
  10714. return;
  10715. }
  10716. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  10717. this.finishToken(135, val);
  10718. }
  10719. readCodePoint(throwOnInvalid) {
  10720. const {
  10721. code,
  10722. pos
  10723. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  10724. this.state.pos = pos;
  10725. return code;
  10726. }
  10727. readString(quote) {
  10728. const {
  10729. str,
  10730. pos,
  10731. curLine,
  10732. lineStart
  10733. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  10734. this.state.pos = pos + 1;
  10735. this.state.lineStart = lineStart;
  10736. this.state.curLine = curLine;
  10737. this.finishToken(134, str);
  10738. }
  10739. readTemplateContinuation() {
  10740. if (!this.match(8)) {
  10741. this.unexpected(null, 8);
  10742. }
  10743. this.state.pos--;
  10744. this.readTemplateToken();
  10745. }
  10746. readTemplateToken() {
  10747. const opening = this.input[this.state.pos];
  10748. const {
  10749. str,
  10750. firstInvalidLoc,
  10751. pos,
  10752. curLine,
  10753. lineStart
  10754. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  10755. this.state.pos = pos + 1;
  10756. this.state.lineStart = lineStart;
  10757. this.state.curLine = curLine;
  10758. if (firstInvalidLoc) {
  10759. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  10760. }
  10761. if (this.input.codePointAt(pos) === 96) {
  10762. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  10763. } else {
  10764. this.state.pos++;
  10765. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  10766. }
  10767. }
  10768. recordStrictModeErrors(toParseError, at) {
  10769. const index = at.index;
  10770. if (this.state.strict && !this.state.strictErrors.has(index)) {
  10771. this.raise(toParseError, at);
  10772. } else {
  10773. this.state.strictErrors.set(index, [toParseError, at]);
  10774. }
  10775. }
  10776. readWord1(firstCode) {
  10777. this.state.containsEsc = false;
  10778. let word = "";
  10779. const start = this.state.pos;
  10780. let chunkStart = this.state.pos;
  10781. if (firstCode !== undefined) {
  10782. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  10783. }
  10784. while (this.state.pos < this.length) {
  10785. const ch = this.codePointAtPos(this.state.pos);
  10786. if (isIdentifierChar(ch)) {
  10787. this.state.pos += ch <= 0xffff ? 1 : 2;
  10788. } else if (ch === 92) {
  10789. this.state.containsEsc = true;
  10790. word += this.input.slice(chunkStart, this.state.pos);
  10791. const escStart = this.state.curPosition();
  10792. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  10793. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  10794. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  10795. chunkStart = this.state.pos - 1;
  10796. continue;
  10797. }
  10798. ++this.state.pos;
  10799. const esc = this.readCodePoint(true);
  10800. if (esc !== null) {
  10801. if (!identifierCheck(esc)) {
  10802. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  10803. }
  10804. word += String.fromCodePoint(esc);
  10805. }
  10806. chunkStart = this.state.pos;
  10807. } else {
  10808. break;
  10809. }
  10810. }
  10811. return word + this.input.slice(chunkStart, this.state.pos);
  10812. }
  10813. readWord(firstCode) {
  10814. const word = this.readWord1(firstCode);
  10815. const type = keywords$1.get(word);
  10816. if (type !== undefined) {
  10817. this.finishToken(type, tokenLabelName(type));
  10818. } else {
  10819. this.finishToken(132, word);
  10820. }
  10821. }
  10822. checkKeywordEscapes() {
  10823. const {
  10824. type
  10825. } = this.state;
  10826. if (tokenIsKeyword(type) && this.state.containsEsc) {
  10827. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  10828. reservedWord: tokenLabelName(type)
  10829. });
  10830. }
  10831. }
  10832. raise(toParseError, at, details = {}) {
  10833. const loc = at instanceof Position ? at : at.loc.start;
  10834. const error = toParseError(loc, details);
  10835. if (!(this.optionFlags & 2048)) throw error;
  10836. if (!this.isLookahead) this.state.errors.push(error);
  10837. return error;
  10838. }
  10839. raiseOverwrite(toParseError, at, details = {}) {
  10840. const loc = at instanceof Position ? at : at.loc.start;
  10841. const pos = loc.index;
  10842. const errors = this.state.errors;
  10843. for (let i = errors.length - 1; i >= 0; i--) {
  10844. const error = errors[i];
  10845. if (error.loc.index === pos) {
  10846. return errors[i] = toParseError(loc, details);
  10847. }
  10848. if (error.loc.index < pos) break;
  10849. }
  10850. return this.raise(toParseError, at, details);
  10851. }
  10852. updateContext(prevType) {}
  10853. unexpected(loc, type) {
  10854. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  10855. expected: type ? tokenLabelName(type) : null
  10856. });
  10857. }
  10858. expectPlugin(pluginName, loc) {
  10859. if (this.hasPlugin(pluginName)) {
  10860. return true;
  10861. }
  10862. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  10863. missingPlugin: [pluginName]
  10864. });
  10865. }
  10866. expectOnePlugin(pluginNames) {
  10867. if (!pluginNames.some(name => this.hasPlugin(name))) {
  10868. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  10869. missingPlugin: pluginNames
  10870. });
  10871. }
  10872. }
  10873. errorBuilder(error) {
  10874. return (pos, lineStart, curLine) => {
  10875. this.raise(error, buildPosition(pos, lineStart, curLine));
  10876. };
  10877. }
  10878. }
  10879. class ClassScope {
  10880. constructor() {
  10881. this.privateNames = new Set();
  10882. this.loneAccessors = new Map();
  10883. this.undefinedPrivateNames = new Map();
  10884. }
  10885. }
  10886. class ClassScopeHandler {
  10887. constructor(parser) {
  10888. this.parser = void 0;
  10889. this.stack = [];
  10890. this.undefinedPrivateNames = new Map();
  10891. this.parser = parser;
  10892. }
  10893. current() {
  10894. return this.stack[this.stack.length - 1];
  10895. }
  10896. enter() {
  10897. this.stack.push(new ClassScope());
  10898. }
  10899. exit() {
  10900. const oldClassScope = this.stack.pop();
  10901. const current = this.current();
  10902. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  10903. if (current) {
  10904. if (!current.undefinedPrivateNames.has(name)) {
  10905. current.undefinedPrivateNames.set(name, loc);
  10906. }
  10907. } else {
  10908. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  10909. identifierName: name
  10910. });
  10911. }
  10912. }
  10913. }
  10914. declarePrivateName(name, elementType, loc) {
  10915. const {
  10916. privateNames,
  10917. loneAccessors,
  10918. undefinedPrivateNames
  10919. } = this.current();
  10920. let redefined = privateNames.has(name);
  10921. if (elementType & 3) {
  10922. const accessor = redefined && loneAccessors.get(name);
  10923. if (accessor) {
  10924. const oldStatic = accessor & 4;
  10925. const newStatic = elementType & 4;
  10926. const oldKind = accessor & 3;
  10927. const newKind = elementType & 3;
  10928. redefined = oldKind === newKind || oldStatic !== newStatic;
  10929. if (!redefined) loneAccessors.delete(name);
  10930. } else if (!redefined) {
  10931. loneAccessors.set(name, elementType);
  10932. }
  10933. }
  10934. if (redefined) {
  10935. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  10936. identifierName: name
  10937. });
  10938. }
  10939. privateNames.add(name);
  10940. undefinedPrivateNames.delete(name);
  10941. }
  10942. usePrivateName(name, loc) {
  10943. let classScope;
  10944. for (classScope of this.stack) {
  10945. if (classScope.privateNames.has(name)) return;
  10946. }
  10947. if (classScope) {
  10948. classScope.undefinedPrivateNames.set(name, loc);
  10949. } else {
  10950. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  10951. identifierName: name
  10952. });
  10953. }
  10954. }
  10955. }
  10956. class ExpressionScope {
  10957. constructor(type = 0) {
  10958. this.type = type;
  10959. }
  10960. canBeArrowParameterDeclaration() {
  10961. return this.type === 2 || this.type === 1;
  10962. }
  10963. isCertainlyParameterDeclaration() {
  10964. return this.type === 3;
  10965. }
  10966. }
  10967. class ArrowHeadParsingScope extends ExpressionScope {
  10968. constructor(type) {
  10969. super(type);
  10970. this.declarationErrors = new Map();
  10971. }
  10972. recordDeclarationError(ParsingErrorClass, at) {
  10973. const index = at.index;
  10974. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  10975. }
  10976. clearDeclarationError(index) {
  10977. this.declarationErrors.delete(index);
  10978. }
  10979. iterateErrors(iterator) {
  10980. this.declarationErrors.forEach(iterator);
  10981. }
  10982. }
  10983. class ExpressionScopeHandler {
  10984. constructor(parser) {
  10985. this.parser = void 0;
  10986. this.stack = [new ExpressionScope()];
  10987. this.parser = parser;
  10988. }
  10989. enter(scope) {
  10990. this.stack.push(scope);
  10991. }
  10992. exit() {
  10993. this.stack.pop();
  10994. }
  10995. recordParameterInitializerError(toParseError, node) {
  10996. const origin = node.loc.start;
  10997. const {
  10998. stack
  10999. } = this;
  11000. let i = stack.length - 1;
  11001. let scope = stack[i];
  11002. while (!scope.isCertainlyParameterDeclaration()) {
  11003. if (scope.canBeArrowParameterDeclaration()) {
  11004. scope.recordDeclarationError(toParseError, origin);
  11005. } else {
  11006. return;
  11007. }
  11008. scope = stack[--i];
  11009. }
  11010. this.parser.raise(toParseError, origin);
  11011. }
  11012. recordArrowParameterBindingError(error, node) {
  11013. const {
  11014. stack
  11015. } = this;
  11016. const scope = stack[stack.length - 1];
  11017. const origin = node.loc.start;
  11018. if (scope.isCertainlyParameterDeclaration()) {
  11019. this.parser.raise(error, origin);
  11020. } else if (scope.canBeArrowParameterDeclaration()) {
  11021. scope.recordDeclarationError(error, origin);
  11022. } else {
  11023. return;
  11024. }
  11025. }
  11026. recordAsyncArrowParametersError(at) {
  11027. const {
  11028. stack
  11029. } = this;
  11030. let i = stack.length - 1;
  11031. let scope = stack[i];
  11032. while (scope.canBeArrowParameterDeclaration()) {
  11033. if (scope.type === 2) {
  11034. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  11035. }
  11036. scope = stack[--i];
  11037. }
  11038. }
  11039. validateAsPattern() {
  11040. const {
  11041. stack
  11042. } = this;
  11043. const currentScope = stack[stack.length - 1];
  11044. if (!currentScope.canBeArrowParameterDeclaration()) return;
  11045. currentScope.iterateErrors(([toParseError, loc]) => {
  11046. this.parser.raise(toParseError, loc);
  11047. let i = stack.length - 2;
  11048. let scope = stack[i];
  11049. while (scope.canBeArrowParameterDeclaration()) {
  11050. scope.clearDeclarationError(loc.index);
  11051. scope = stack[--i];
  11052. }
  11053. });
  11054. }
  11055. }
  11056. function newParameterDeclarationScope() {
  11057. return new ExpressionScope(3);
  11058. }
  11059. function newArrowHeadScope() {
  11060. return new ArrowHeadParsingScope(1);
  11061. }
  11062. function newAsyncArrowScope() {
  11063. return new ArrowHeadParsingScope(2);
  11064. }
  11065. function newExpressionScope() {
  11066. return new ExpressionScope();
  11067. }
  11068. class UtilParser extends Tokenizer {
  11069. addExtra(node, key, value, enumerable = true) {
  11070. if (!node) return;
  11071. let {
  11072. extra
  11073. } = node;
  11074. if (extra == null) {
  11075. extra = {};
  11076. node.extra = extra;
  11077. }
  11078. if (enumerable) {
  11079. extra[key] = value;
  11080. } else {
  11081. Object.defineProperty(extra, key, {
  11082. enumerable,
  11083. value
  11084. });
  11085. }
  11086. }
  11087. isContextual(token) {
  11088. return this.state.type === token && !this.state.containsEsc;
  11089. }
  11090. isUnparsedContextual(nameStart, name) {
  11091. if (this.input.startsWith(name, nameStart)) {
  11092. const nextCh = this.input.charCodeAt(nameStart + name.length);
  11093. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  11094. }
  11095. return false;
  11096. }
  11097. isLookaheadContextual(name) {
  11098. const next = this.nextTokenStart();
  11099. return this.isUnparsedContextual(next, name);
  11100. }
  11101. eatContextual(token) {
  11102. if (this.isContextual(token)) {
  11103. this.next();
  11104. return true;
  11105. }
  11106. return false;
  11107. }
  11108. expectContextual(token, toParseError) {
  11109. if (!this.eatContextual(token)) {
  11110. if (toParseError != null) {
  11111. throw this.raise(toParseError, this.state.startLoc);
  11112. }
  11113. this.unexpected(null, token);
  11114. }
  11115. }
  11116. canInsertSemicolon() {
  11117. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  11118. }
  11119. hasPrecedingLineBreak() {
  11120. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  11121. }
  11122. hasFollowingLineBreak() {
  11123. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  11124. }
  11125. isLineTerminator() {
  11126. return this.eat(13) || this.canInsertSemicolon();
  11127. }
  11128. semicolon(allowAsi = true) {
  11129. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  11130. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  11131. }
  11132. expect(type, loc) {
  11133. if (!this.eat(type)) {
  11134. this.unexpected(loc, type);
  11135. }
  11136. }
  11137. tryParse(fn, oldState = this.state.clone()) {
  11138. const abortSignal = {
  11139. node: null
  11140. };
  11141. try {
  11142. const node = fn((node = null) => {
  11143. abortSignal.node = node;
  11144. throw abortSignal;
  11145. });
  11146. if (this.state.errors.length > oldState.errors.length) {
  11147. const failState = this.state;
  11148. this.state = oldState;
  11149. this.state.tokensLength = failState.tokensLength;
  11150. return {
  11151. node,
  11152. error: failState.errors[oldState.errors.length],
  11153. thrown: false,
  11154. aborted: false,
  11155. failState
  11156. };
  11157. }
  11158. return {
  11159. node: node,
  11160. error: null,
  11161. thrown: false,
  11162. aborted: false,
  11163. failState: null
  11164. };
  11165. } catch (error) {
  11166. const failState = this.state;
  11167. this.state = oldState;
  11168. if (error instanceof SyntaxError) {
  11169. return {
  11170. node: null,
  11171. error,
  11172. thrown: true,
  11173. aborted: false,
  11174. failState
  11175. };
  11176. }
  11177. if (error === abortSignal) {
  11178. return {
  11179. node: abortSignal.node,
  11180. error: null,
  11181. thrown: false,
  11182. aborted: true,
  11183. failState
  11184. };
  11185. }
  11186. throw error;
  11187. }
  11188. }
  11189. checkExpressionErrors(refExpressionErrors, andThrow) {
  11190. if (!refExpressionErrors) return false;
  11191. const {
  11192. shorthandAssignLoc,
  11193. doubleProtoLoc,
  11194. privateKeyLoc,
  11195. optionalParametersLoc,
  11196. voidPatternLoc
  11197. } = refExpressionErrors;
  11198. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc || !!voidPatternLoc;
  11199. if (!andThrow) {
  11200. return hasErrors;
  11201. }
  11202. if (shorthandAssignLoc != null) {
  11203. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11204. }
  11205. if (doubleProtoLoc != null) {
  11206. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  11207. }
  11208. if (privateKeyLoc != null) {
  11209. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  11210. }
  11211. if (optionalParametersLoc != null) {
  11212. this.unexpected(optionalParametersLoc);
  11213. }
  11214. if (voidPatternLoc != null) {
  11215. this.raise(Errors.InvalidCoverDiscardElement, voidPatternLoc);
  11216. }
  11217. }
  11218. isLiteralPropertyName() {
  11219. return tokenIsLiteralPropertyName(this.state.type);
  11220. }
  11221. isPrivateName(node) {
  11222. return node.type === "PrivateName";
  11223. }
  11224. getPrivateNameSV(node) {
  11225. return node.id.name;
  11226. }
  11227. hasPropertyAsPrivateName(node) {
  11228. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  11229. }
  11230. isObjectProperty(node) {
  11231. return node.type === "ObjectProperty";
  11232. }
  11233. isObjectMethod(node) {
  11234. return node.type === "ObjectMethod";
  11235. }
  11236. initializeScopes(inModule = this.options.sourceType === "module") {
  11237. const oldLabels = this.state.labels;
  11238. this.state.labels = [];
  11239. const oldExportedIdentifiers = this.exportedIdentifiers;
  11240. this.exportedIdentifiers = new Set();
  11241. const oldInModule = this.inModule;
  11242. this.inModule = inModule;
  11243. const oldScope = this.scope;
  11244. const ScopeHandler = this.getScopeHandler();
  11245. this.scope = new ScopeHandler(this, inModule);
  11246. const oldProdParam = this.prodParam;
  11247. this.prodParam = new ProductionParameterHandler();
  11248. const oldClassScope = this.classScope;
  11249. this.classScope = new ClassScopeHandler(this);
  11250. const oldExpressionScope = this.expressionScope;
  11251. this.expressionScope = new ExpressionScopeHandler(this);
  11252. return () => {
  11253. this.state.labels = oldLabels;
  11254. this.exportedIdentifiers = oldExportedIdentifiers;
  11255. this.inModule = oldInModule;
  11256. this.scope = oldScope;
  11257. this.prodParam = oldProdParam;
  11258. this.classScope = oldClassScope;
  11259. this.expressionScope = oldExpressionScope;
  11260. };
  11261. }
  11262. enterInitialScopes() {
  11263. let paramFlags = 0;
  11264. if (this.inModule || this.optionFlags & 1) {
  11265. paramFlags |= 2;
  11266. }
  11267. if (this.optionFlags & 32) {
  11268. paramFlags |= 1;
  11269. }
  11270. const isCommonJS = !this.inModule && this.options.sourceType === "commonjs";
  11271. if (isCommonJS || this.optionFlags & 2) {
  11272. paramFlags |= 4;
  11273. }
  11274. this.prodParam.enter(paramFlags);
  11275. let scopeFlags = isCommonJS ? 514 : 1;
  11276. if (this.optionFlags & 4) {
  11277. scopeFlags |= 512;
  11278. }
  11279. this.scope.enter(scopeFlags);
  11280. }
  11281. checkDestructuringPrivate(refExpressionErrors) {
  11282. const {
  11283. privateKeyLoc
  11284. } = refExpressionErrors;
  11285. if (privateKeyLoc !== null) {
  11286. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  11287. }
  11288. }
  11289. }
  11290. class ExpressionErrors {
  11291. constructor() {
  11292. this.shorthandAssignLoc = null;
  11293. this.doubleProtoLoc = null;
  11294. this.privateKeyLoc = null;
  11295. this.optionalParametersLoc = null;
  11296. this.voidPatternLoc = null;
  11297. }
  11298. }
  11299. class Node {
  11300. constructor(parser, pos, loc) {
  11301. this.type = "";
  11302. this.start = pos;
  11303. this.end = 0;
  11304. this.loc = new SourceLocation(loc);
  11305. if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
  11306. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  11307. }
  11308. }
  11309. const NodePrototype = Node.prototype;
  11310. {
  11311. NodePrototype.__clone = function () {
  11312. const newNode = new Node(undefined, this.start, this.loc.start);
  11313. const keys = Object.keys(this);
  11314. for (let i = 0, length = keys.length; i < length; i++) {
  11315. const key = keys[i];
  11316. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  11317. newNode[key] = this[key];
  11318. }
  11319. }
  11320. return newNode;
  11321. };
  11322. }
  11323. class NodeUtils extends UtilParser {
  11324. startNode() {
  11325. const loc = this.state.startLoc;
  11326. return new Node(this, loc.index, loc);
  11327. }
  11328. startNodeAt(loc) {
  11329. return new Node(this, loc.index, loc);
  11330. }
  11331. startNodeAtNode(type) {
  11332. return this.startNodeAt(type.loc.start);
  11333. }
  11334. finishNode(node, type) {
  11335. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  11336. }
  11337. finishNodeAt(node, type, endLoc) {
  11338. node.type = type;
  11339. node.end = endLoc.index;
  11340. node.loc.end = endLoc;
  11341. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  11342. if (this.optionFlags & 4096) {
  11343. this.processComment(node);
  11344. }
  11345. return node;
  11346. }
  11347. resetStartLocation(node, startLoc) {
  11348. node.start = startLoc.index;
  11349. node.loc.start = startLoc;
  11350. if (this.optionFlags & 128) node.range[0] = startLoc.index;
  11351. }
  11352. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  11353. node.end = endLoc.index;
  11354. node.loc.end = endLoc;
  11355. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  11356. }
  11357. resetStartLocationFromNode(node, locationNode) {
  11358. this.resetStartLocation(node, locationNode.loc.start);
  11359. }
  11360. castNodeTo(node, type) {
  11361. node.type = type;
  11362. return node;
  11363. }
  11364. cloneIdentifier(node) {
  11365. const {
  11366. type,
  11367. start,
  11368. end,
  11369. loc,
  11370. range,
  11371. name
  11372. } = node;
  11373. const cloned = Object.create(NodePrototype);
  11374. cloned.type = type;
  11375. cloned.start = start;
  11376. cloned.end = end;
  11377. cloned.loc = loc;
  11378. cloned.range = range;
  11379. cloned.name = name;
  11380. if (node.extra) cloned.extra = node.extra;
  11381. return cloned;
  11382. }
  11383. cloneStringLiteral(node) {
  11384. const {
  11385. type,
  11386. start,
  11387. end,
  11388. loc,
  11389. range,
  11390. extra
  11391. } = node;
  11392. const cloned = Object.create(NodePrototype);
  11393. cloned.type = type;
  11394. cloned.start = start;
  11395. cloned.end = end;
  11396. cloned.loc = loc;
  11397. cloned.range = range;
  11398. cloned.extra = extra;
  11399. cloned.value = node.value;
  11400. return cloned;
  11401. }
  11402. }
  11403. const unwrapParenthesizedExpression = node => {
  11404. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  11405. };
  11406. class LValParser extends NodeUtils {
  11407. toAssignable(node, isLHS = false) {
  11408. var _node$extra, _node$extra3;
  11409. let parenthesized = undefined;
  11410. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  11411. parenthesized = unwrapParenthesizedExpression(node);
  11412. if (isLHS) {
  11413. if (parenthesized.type === "Identifier") {
  11414. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  11415. } else if (parenthesized.type !== "CallExpression" && parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  11416. this.raise(Errors.InvalidParenthesizedAssignment, node);
  11417. }
  11418. } else {
  11419. this.raise(Errors.InvalidParenthesizedAssignment, node);
  11420. }
  11421. }
  11422. switch (node.type) {
  11423. case "Identifier":
  11424. case "ObjectPattern":
  11425. case "ArrayPattern":
  11426. case "AssignmentPattern":
  11427. case "RestElement":
  11428. case "VoidPattern":
  11429. break;
  11430. case "ObjectExpression":
  11431. this.castNodeTo(node, "ObjectPattern");
  11432. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  11433. var _node$extra2;
  11434. const prop = node.properties[i];
  11435. const isLast = i === last;
  11436. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  11437. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  11438. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  11439. }
  11440. }
  11441. break;
  11442. case "ObjectProperty":
  11443. {
  11444. const {
  11445. key,
  11446. value
  11447. } = node;
  11448. if (this.isPrivateName(key)) {
  11449. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  11450. }
  11451. this.toAssignable(value, isLHS);
  11452. break;
  11453. }
  11454. case "SpreadElement":
  11455. {
  11456. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  11457. }
  11458. case "ArrayExpression":
  11459. this.castNodeTo(node, "ArrayPattern");
  11460. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  11461. break;
  11462. case "AssignmentExpression":
  11463. if (node.operator !== "=") {
  11464. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  11465. }
  11466. this.castNodeTo(node, "AssignmentPattern");
  11467. delete node.operator;
  11468. if (node.left.type === "VoidPattern") {
  11469. this.raise(Errors.VoidPatternInitializer, node.left);
  11470. }
  11471. this.toAssignable(node.left, isLHS);
  11472. break;
  11473. case "ParenthesizedExpression":
  11474. this.toAssignable(parenthesized, isLHS);
  11475. break;
  11476. }
  11477. }
  11478. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  11479. if (prop.type === "ObjectMethod") {
  11480. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  11481. } else if (prop.type === "SpreadElement") {
  11482. this.castNodeTo(prop, "RestElement");
  11483. const arg = prop.argument;
  11484. this.checkToRestConversion(arg, false);
  11485. this.toAssignable(arg, isLHS);
  11486. if (!isLast) {
  11487. this.raise(Errors.RestTrailingComma, prop);
  11488. }
  11489. } else {
  11490. this.toAssignable(prop, isLHS);
  11491. }
  11492. }
  11493. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  11494. const end = exprList.length - 1;
  11495. for (let i = 0; i <= end; i++) {
  11496. const elt = exprList[i];
  11497. if (!elt) continue;
  11498. this.toAssignableListItem(exprList, i, isLHS);
  11499. if (elt.type === "RestElement") {
  11500. if (i < end) {
  11501. this.raise(Errors.RestTrailingComma, elt);
  11502. } else if (trailingCommaLoc) {
  11503. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  11504. }
  11505. }
  11506. }
  11507. }
  11508. toAssignableListItem(exprList, index, isLHS) {
  11509. const node = exprList[index];
  11510. if (node.type === "SpreadElement") {
  11511. this.castNodeTo(node, "RestElement");
  11512. const arg = node.argument;
  11513. this.checkToRestConversion(arg, true);
  11514. this.toAssignable(arg, isLHS);
  11515. } else {
  11516. this.toAssignable(node, isLHS);
  11517. }
  11518. }
  11519. isAssignable(node, isBinding) {
  11520. switch (node.type) {
  11521. case "Identifier":
  11522. case "ObjectPattern":
  11523. case "ArrayPattern":
  11524. case "AssignmentPattern":
  11525. case "RestElement":
  11526. case "VoidPattern":
  11527. return true;
  11528. case "ObjectExpression":
  11529. {
  11530. const last = node.properties.length - 1;
  11531. return node.properties.every((prop, i) => {
  11532. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  11533. });
  11534. }
  11535. case "ObjectProperty":
  11536. return this.isAssignable(node.value);
  11537. case "SpreadElement":
  11538. return this.isAssignable(node.argument);
  11539. case "ArrayExpression":
  11540. return node.elements.every(element => element === null || this.isAssignable(element));
  11541. case "AssignmentExpression":
  11542. return node.operator === "=";
  11543. case "ParenthesizedExpression":
  11544. return this.isAssignable(node.expression);
  11545. case "MemberExpression":
  11546. case "OptionalMemberExpression":
  11547. return !isBinding;
  11548. default:
  11549. return false;
  11550. }
  11551. }
  11552. toReferencedList(exprList, isParenthesizedExpr) {
  11553. return exprList;
  11554. }
  11555. toReferencedListDeep(exprList, isParenthesizedExpr) {
  11556. this.toReferencedList(exprList, isParenthesizedExpr);
  11557. for (const expr of exprList) {
  11558. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  11559. this.toReferencedListDeep(expr.elements);
  11560. }
  11561. }
  11562. }
  11563. parseSpread(refExpressionErrors) {
  11564. const node = this.startNode();
  11565. this.next();
  11566. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  11567. return this.finishNode(node, "SpreadElement");
  11568. }
  11569. parseRestBinding() {
  11570. const node = this.startNode();
  11571. this.next();
  11572. const argument = this.parseBindingAtom();
  11573. if (argument.type === "VoidPattern") {
  11574. this.raise(Errors.UnexpectedVoidPattern, argument);
  11575. }
  11576. node.argument = argument;
  11577. return this.finishNode(node, "RestElement");
  11578. }
  11579. parseBindingAtom() {
  11580. switch (this.state.type) {
  11581. case 0:
  11582. {
  11583. const node = this.startNode();
  11584. this.next();
  11585. node.elements = this.parseBindingList(3, 93, 1);
  11586. return this.finishNode(node, "ArrayPattern");
  11587. }
  11588. case 5:
  11589. return this.parseObjectLike(8, true);
  11590. case 88:
  11591. return this.parseVoidPattern(null);
  11592. }
  11593. return this.parseIdentifier();
  11594. }
  11595. parseBindingList(close, closeCharCode, flags) {
  11596. const allowEmpty = flags & 1;
  11597. const elts = [];
  11598. let first = true;
  11599. while (!this.eat(close)) {
  11600. if (first) {
  11601. first = false;
  11602. } else {
  11603. this.expect(12);
  11604. }
  11605. if (allowEmpty && this.match(12)) {
  11606. elts.push(null);
  11607. } else if (this.eat(close)) {
  11608. break;
  11609. } else if (this.match(21)) {
  11610. let rest = this.parseRestBinding();
  11611. if (this.hasPlugin("flow") || flags & 2) {
  11612. rest = this.parseFunctionParamType(rest);
  11613. }
  11614. elts.push(rest);
  11615. if (!this.checkCommaAfterRest(closeCharCode)) {
  11616. this.expect(close);
  11617. break;
  11618. }
  11619. } else {
  11620. const decorators = [];
  11621. if (flags & 2) {
  11622. if (this.match(26) && this.hasPlugin("decorators")) {
  11623. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  11624. }
  11625. while (this.match(26)) {
  11626. decorators.push(this.parseDecorator());
  11627. }
  11628. }
  11629. elts.push(this.parseBindingElement(flags, decorators));
  11630. }
  11631. }
  11632. return elts;
  11633. }
  11634. parseBindingRestProperty(prop) {
  11635. this.next();
  11636. if (this.hasPlugin("discardBinding") && this.match(88)) {
  11637. prop.argument = this.parseVoidPattern(null);
  11638. this.raise(Errors.UnexpectedVoidPattern, prop.argument);
  11639. } else {
  11640. prop.argument = this.parseIdentifier();
  11641. }
  11642. this.checkCommaAfterRest(125);
  11643. return this.finishNode(prop, "RestElement");
  11644. }
  11645. parseBindingProperty() {
  11646. const {
  11647. type,
  11648. startLoc
  11649. } = this.state;
  11650. if (type === 21) {
  11651. return this.parseBindingRestProperty(this.startNode());
  11652. }
  11653. const prop = this.startNode();
  11654. if (type === 139) {
  11655. this.expectPlugin("destructuringPrivate", startLoc);
  11656. this.classScope.usePrivateName(this.state.value, startLoc);
  11657. prop.key = this.parsePrivateName();
  11658. } else {
  11659. this.parsePropertyName(prop);
  11660. }
  11661. prop.method = false;
  11662. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  11663. }
  11664. parseBindingElement(flags, decorators) {
  11665. const left = this.parseMaybeDefault();
  11666. if (this.hasPlugin("flow") || flags & 2) {
  11667. this.parseFunctionParamType(left);
  11668. }
  11669. if (decorators.length) {
  11670. left.decorators = decorators;
  11671. this.resetStartLocationFromNode(left, decorators[0]);
  11672. }
  11673. const elt = this.parseMaybeDefault(left.loc.start, left);
  11674. return elt;
  11675. }
  11676. parseFunctionParamType(param) {
  11677. return param;
  11678. }
  11679. parseMaybeDefault(startLoc, left) {
  11680. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  11681. left = left != null ? left : this.parseBindingAtom();
  11682. if (!this.eat(29)) return left;
  11683. const node = this.startNodeAt(startLoc);
  11684. if (left.type === "VoidPattern") {
  11685. this.raise(Errors.VoidPatternInitializer, left);
  11686. }
  11687. node.left = left;
  11688. node.right = this.parseMaybeAssignAllowIn();
  11689. return this.finishNode(node, "AssignmentPattern");
  11690. }
  11691. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  11692. switch (type) {
  11693. case "AssignmentPattern":
  11694. return "left";
  11695. case "RestElement":
  11696. return "argument";
  11697. case "ObjectProperty":
  11698. return "value";
  11699. case "ParenthesizedExpression":
  11700. return "expression";
  11701. case "ArrayPattern":
  11702. return "elements";
  11703. case "ObjectPattern":
  11704. return "properties";
  11705. case "VoidPattern":
  11706. return true;
  11707. case "CallExpression":
  11708. if (!disallowCallExpression && !this.state.strict && this.optionFlags & 8192) {
  11709. return true;
  11710. }
  11711. }
  11712. return false;
  11713. }
  11714. isOptionalMemberExpression(expression) {
  11715. return expression.type === "OptionalMemberExpression";
  11716. }
  11717. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false, disallowCallExpression = false) {
  11718. var _expression$extra;
  11719. const type = expression.type;
  11720. if (this.isObjectMethod(expression)) return;
  11721. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  11722. if (isOptionalMemberExpression || type === "MemberExpression") {
  11723. if (isOptionalMemberExpression) {
  11724. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  11725. if (ancestor.type !== "AssignmentExpression") {
  11726. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  11727. ancestor
  11728. });
  11729. }
  11730. }
  11731. if (binding !== 64) {
  11732. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  11733. }
  11734. return;
  11735. }
  11736. if (type === "Identifier") {
  11737. this.checkIdentifier(expression, binding, strictModeChanged);
  11738. const {
  11739. name
  11740. } = expression;
  11741. if (checkClashes) {
  11742. if (checkClashes.has(name)) {
  11743. this.raise(Errors.ParamDupe, expression);
  11744. } else {
  11745. checkClashes.add(name);
  11746. }
  11747. }
  11748. return;
  11749. } else if (type === "VoidPattern" && ancestor.type === "CatchClause") {
  11750. this.raise(Errors.VoidPatternCatchClauseParam, expression);
  11751. }
  11752. const unwrappedExpression = unwrapParenthesizedExpression(expression);
  11753. disallowCallExpression || (disallowCallExpression = unwrappedExpression.type === "CallExpression" && (unwrappedExpression.callee.type === "Import" || unwrappedExpression.callee.type === "Super"));
  11754. const validity = this.isValidLVal(type, disallowCallExpression, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  11755. if (validity === true) return;
  11756. if (validity === false) {
  11757. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  11758. this.raise(ParseErrorClass, expression, {
  11759. ancestor
  11760. });
  11761. return;
  11762. }
  11763. let key, isParenthesizedExpression;
  11764. if (typeof validity === "string") {
  11765. key = validity;
  11766. isParenthesizedExpression = type === "ParenthesizedExpression";
  11767. } else {
  11768. [key, isParenthesizedExpression] = validity;
  11769. }
  11770. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  11771. type
  11772. } : ancestor;
  11773. const val = expression[key];
  11774. if (Array.isArray(val)) {
  11775. for (const child of val) {
  11776. if (child) {
  11777. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, true);
  11778. }
  11779. }
  11780. } else if (val) {
  11781. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, disallowCallExpression);
  11782. }
  11783. }
  11784. checkIdentifier(at, bindingType, strictModeChanged = false) {
  11785. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  11786. if (bindingType === 64) {
  11787. this.raise(Errors.StrictEvalArguments, at, {
  11788. referenceName: at.name
  11789. });
  11790. } else {
  11791. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  11792. bindingName: at.name
  11793. });
  11794. }
  11795. }
  11796. if (bindingType & 8192 && at.name === "let") {
  11797. this.raise(Errors.LetInLexicalBinding, at);
  11798. }
  11799. if (!(bindingType & 64)) {
  11800. this.declareNameFromIdentifier(at, bindingType);
  11801. }
  11802. }
  11803. declareNameFromIdentifier(identifier, binding) {
  11804. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  11805. }
  11806. checkToRestConversion(node, allowPattern) {
  11807. switch (node.type) {
  11808. case "ParenthesizedExpression":
  11809. this.checkToRestConversion(node.expression, allowPattern);
  11810. break;
  11811. case "Identifier":
  11812. case "MemberExpression":
  11813. break;
  11814. case "ArrayExpression":
  11815. case "ObjectExpression":
  11816. if (allowPattern) break;
  11817. default:
  11818. this.raise(Errors.InvalidRestAssignmentPattern, node);
  11819. }
  11820. }
  11821. checkCommaAfterRest(close) {
  11822. if (!this.match(12)) {
  11823. return false;
  11824. }
  11825. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  11826. return true;
  11827. }
  11828. }
  11829. const keywordAndTSRelationalOperator = /in(?:stanceof)?|as|satisfies/y;
  11830. function nonNull(x) {
  11831. if (x == null) {
  11832. throw new Error(`Unexpected ${x} value.`);
  11833. }
  11834. return x;
  11835. }
  11836. function assert(x) {
  11837. if (!x) {
  11838. throw new Error("Assert fail");
  11839. }
  11840. }
  11841. const TSErrors = ParseErrorEnum`typescript`({
  11842. AbstractMethodHasImplementation: ({
  11843. methodName
  11844. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  11845. AbstractPropertyHasInitializer: ({
  11846. propertyName
  11847. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  11848. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  11849. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  11850. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  11851. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  11852. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  11853. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  11854. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  11855. DeclareAccessor: ({
  11856. kind
  11857. }) => `'declare' is not allowed in ${kind}ters.`,
  11858. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  11859. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  11860. DuplicateAccessibilityModifier: ({
  11861. modifier
  11862. }) => `Accessibility modifier already seen: '${modifier}'.`,
  11863. DuplicateModifier: ({
  11864. modifier
  11865. }) => `Duplicate modifier: '${modifier}'.`,
  11866. EmptyHeritageClauseType: ({
  11867. token
  11868. }) => `'${token}' list cannot be empty.`,
  11869. EmptyTypeArguments: "Type argument list cannot be empty.",
  11870. EmptyTypeParameters: "Type parameter list cannot be empty.",
  11871. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  11872. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  11873. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  11874. IncompatibleModifiers: ({
  11875. modifiers
  11876. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  11877. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  11878. IndexSignatureHasAccessibility: ({
  11879. modifier
  11880. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  11881. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  11882. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  11883. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  11884. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  11885. InvalidHeritageClauseType: ({
  11886. token
  11887. }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
  11888. InvalidModifierOnAwaitUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on an await using declaration.`,
  11889. InvalidModifierOnTypeMember: ({
  11890. modifier
  11891. }) => `'${modifier}' modifier cannot appear on a type member.`,
  11892. InvalidModifierOnTypeParameter: ({
  11893. modifier
  11894. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  11895. InvalidModifierOnTypeParameterPositions: ({
  11896. modifier
  11897. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  11898. InvalidModifierOnUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on a using declaration.`,
  11899. InvalidModifiersOrder: ({
  11900. orderedModifiers
  11901. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  11902. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  11903. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  11904. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  11905. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  11906. NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
  11907. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  11908. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  11909. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  11910. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  11911. PrivateElementHasAccessibility: ({
  11912. modifier
  11913. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  11914. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  11915. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  11916. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  11917. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  11918. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  11919. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  11920. SingleTypeParameterWithoutTrailingComma: ({
  11921. typeParameterName
  11922. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  11923. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  11924. 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?`).",
  11925. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  11926. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  11927. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  11928. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  11929. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  11930. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  11931. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  11932. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  11933. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  11934. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  11935. UnsupportedSignatureParameterKind: ({
  11936. type
  11937. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
  11938. UsingDeclarationInAmbientContext: kind => `'${kind}' declarations are not allowed in ambient contexts.`
  11939. });
  11940. function keywordTypeFromName(value) {
  11941. switch (value) {
  11942. case "any":
  11943. return "TSAnyKeyword";
  11944. case "boolean":
  11945. return "TSBooleanKeyword";
  11946. case "bigint":
  11947. return "TSBigIntKeyword";
  11948. case "never":
  11949. return "TSNeverKeyword";
  11950. case "number":
  11951. return "TSNumberKeyword";
  11952. case "object":
  11953. return "TSObjectKeyword";
  11954. case "string":
  11955. return "TSStringKeyword";
  11956. case "symbol":
  11957. return "TSSymbolKeyword";
  11958. case "undefined":
  11959. return "TSUndefinedKeyword";
  11960. case "unknown":
  11961. return "TSUnknownKeyword";
  11962. default:
  11963. return undefined;
  11964. }
  11965. }
  11966. function tsIsAccessModifier(modifier) {
  11967. return modifier === "private" || modifier === "public" || modifier === "protected";
  11968. }
  11969. function tsIsVarianceAnnotations(modifier) {
  11970. return modifier === "in" || modifier === "out";
  11971. }
  11972. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  11973. constructor(...args) {
  11974. super(...args);
  11975. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  11976. allowedModifiers: ["in", "out"],
  11977. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  11978. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  11979. });
  11980. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  11981. allowedModifiers: ["const"],
  11982. disallowedModifiers: ["in", "out"],
  11983. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  11984. });
  11985. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  11986. allowedModifiers: ["in", "out", "const"],
  11987. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  11988. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  11989. });
  11990. }
  11991. getScopeHandler() {
  11992. return TypeScriptScopeHandler;
  11993. }
  11994. tsIsIdentifier() {
  11995. return tokenIsIdentifier(this.state.type);
  11996. }
  11997. tsTokenCanFollowModifier() {
  11998. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  11999. }
  12000. tsNextTokenOnSameLineAndCanFollowModifier() {
  12001. this.next();
  12002. if (this.hasPrecedingLineBreak()) {
  12003. return false;
  12004. }
  12005. return this.tsTokenCanFollowModifier();
  12006. }
  12007. tsNextTokenCanFollowModifier() {
  12008. if (this.match(106)) {
  12009. this.next();
  12010. return this.tsTokenCanFollowModifier();
  12011. }
  12012. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  12013. }
  12014. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
  12015. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  12016. return undefined;
  12017. }
  12018. const modifier = this.state.value;
  12019. if (allowedModifiers.includes(modifier)) {
  12020. if (hasSeenStaticModifier && this.match(106)) {
  12021. return undefined;
  12022. }
  12023. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  12024. return undefined;
  12025. }
  12026. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  12027. return modifier;
  12028. }
  12029. }
  12030. return undefined;
  12031. }
  12032. tsParseModifiers({
  12033. allowedModifiers,
  12034. disallowedModifiers,
  12035. stopOnStartOfClassStaticBlock,
  12036. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  12037. }, modified) {
  12038. const enforceOrder = (loc, modifier, before, after) => {
  12039. if (modifier === before && modified[after]) {
  12040. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  12041. orderedModifiers: [before, after]
  12042. });
  12043. }
  12044. };
  12045. const incompatible = (loc, modifier, mod1, mod2) => {
  12046. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  12047. this.raise(TSErrors.IncompatibleModifiers, loc, {
  12048. modifiers: [mod1, mod2]
  12049. });
  12050. }
  12051. };
  12052. for (;;) {
  12053. const {
  12054. startLoc
  12055. } = this.state;
  12056. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock, modified.static);
  12057. if (!modifier) break;
  12058. if (tsIsAccessModifier(modifier)) {
  12059. if (modified.accessibility) {
  12060. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  12061. modifier
  12062. });
  12063. } else {
  12064. enforceOrder(startLoc, modifier, modifier, "override");
  12065. enforceOrder(startLoc, modifier, modifier, "static");
  12066. enforceOrder(startLoc, modifier, modifier, "readonly");
  12067. modified.accessibility = modifier;
  12068. }
  12069. } else if (tsIsVarianceAnnotations(modifier)) {
  12070. if (modified[modifier]) {
  12071. this.raise(TSErrors.DuplicateModifier, startLoc, {
  12072. modifier
  12073. });
  12074. }
  12075. modified[modifier] = true;
  12076. enforceOrder(startLoc, modifier, "in", "out");
  12077. } else {
  12078. if (hasOwnProperty.call(modified, modifier)) {
  12079. this.raise(TSErrors.DuplicateModifier, startLoc, {
  12080. modifier
  12081. });
  12082. } else {
  12083. enforceOrder(startLoc, modifier, "static", "readonly");
  12084. enforceOrder(startLoc, modifier, "static", "override");
  12085. enforceOrder(startLoc, modifier, "override", "readonly");
  12086. enforceOrder(startLoc, modifier, "abstract", "override");
  12087. incompatible(startLoc, modifier, "declare", "override");
  12088. incompatible(startLoc, modifier, "static", "abstract");
  12089. }
  12090. modified[modifier] = true;
  12091. }
  12092. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  12093. this.raise(errorTemplate, startLoc, {
  12094. modifier
  12095. });
  12096. }
  12097. }
  12098. }
  12099. tsIsListTerminator(kind) {
  12100. switch (kind) {
  12101. case "EnumMembers":
  12102. case "TypeMembers":
  12103. return this.match(8);
  12104. case "HeritageClauseElement":
  12105. return this.match(5);
  12106. case "TupleElementTypes":
  12107. return this.match(3);
  12108. case "TypeParametersOrArguments":
  12109. return this.match(48);
  12110. }
  12111. }
  12112. tsParseList(kind, parseElement) {
  12113. const result = [];
  12114. while (!this.tsIsListTerminator(kind)) {
  12115. result.push(parseElement());
  12116. }
  12117. return result;
  12118. }
  12119. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  12120. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  12121. }
  12122. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  12123. const result = [];
  12124. let trailingCommaPos = -1;
  12125. for (;;) {
  12126. if (this.tsIsListTerminator(kind)) {
  12127. break;
  12128. }
  12129. trailingCommaPos = -1;
  12130. const element = parseElement();
  12131. if (element == null) {
  12132. return undefined;
  12133. }
  12134. result.push(element);
  12135. if (this.eat(12)) {
  12136. trailingCommaPos = this.state.lastTokStartLoc.index;
  12137. continue;
  12138. }
  12139. if (this.tsIsListTerminator(kind)) {
  12140. break;
  12141. }
  12142. if (expectSuccess) {
  12143. this.expect(12);
  12144. }
  12145. return undefined;
  12146. }
  12147. if (refTrailingCommaPos) {
  12148. refTrailingCommaPos.value = trailingCommaPos;
  12149. }
  12150. return result;
  12151. }
  12152. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  12153. if (!skipFirstToken) {
  12154. if (bracket) {
  12155. this.expect(0);
  12156. } else {
  12157. this.expect(47);
  12158. }
  12159. }
  12160. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  12161. if (bracket) {
  12162. this.expect(3);
  12163. } else {
  12164. this.expect(48);
  12165. }
  12166. return result;
  12167. }
  12168. tsParseImportType() {
  12169. const node = this.startNode();
  12170. this.expect(83);
  12171. this.expect(10);
  12172. if (!this.match(134)) {
  12173. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  12174. {
  12175. node.argument = super.parseExprAtom();
  12176. }
  12177. } else {
  12178. {
  12179. node.argument = this.parseStringLiteral(this.state.value);
  12180. }
  12181. }
  12182. if (this.eat(12)) {
  12183. node.options = this.tsParseImportTypeOptions();
  12184. } else {
  12185. node.options = null;
  12186. }
  12187. this.expect(11);
  12188. if (this.eat(16)) {
  12189. node.qualifier = this.tsParseEntityName(1 | 2);
  12190. }
  12191. if (this.match(47)) {
  12192. {
  12193. node.typeParameters = this.tsParseTypeArguments();
  12194. }
  12195. }
  12196. return this.finishNode(node, "TSImportType");
  12197. }
  12198. tsParseImportTypeOptions() {
  12199. const node = this.startNode();
  12200. this.expect(5);
  12201. const withProperty = this.startNode();
  12202. if (this.isContextual(76)) {
  12203. withProperty.method = false;
  12204. withProperty.key = this.parseIdentifier(true);
  12205. withProperty.computed = false;
  12206. withProperty.shorthand = false;
  12207. } else {
  12208. this.unexpected(null, 76);
  12209. }
  12210. this.expect(14);
  12211. withProperty.value = this.tsParseImportTypeWithPropertyValue();
  12212. node.properties = [this.finishObjectProperty(withProperty)];
  12213. this.eat(12);
  12214. this.expect(8);
  12215. return this.finishNode(node, "ObjectExpression");
  12216. }
  12217. tsParseImportTypeWithPropertyValue() {
  12218. const node = this.startNode();
  12219. const properties = [];
  12220. this.expect(5);
  12221. while (!this.match(8)) {
  12222. const type = this.state.type;
  12223. if (tokenIsIdentifier(type) || type === 134) {
  12224. properties.push(super.parsePropertyDefinition(null));
  12225. } else {
  12226. this.unexpected();
  12227. }
  12228. this.eat(12);
  12229. }
  12230. node.properties = properties;
  12231. this.next();
  12232. return this.finishNode(node, "ObjectExpression");
  12233. }
  12234. tsParseEntityName(flags) {
  12235. let entity;
  12236. if (flags & 1 && this.match(78)) {
  12237. if (flags & 2) {
  12238. entity = this.parseIdentifier(true);
  12239. } else {
  12240. const node = this.startNode();
  12241. this.next();
  12242. entity = this.finishNode(node, "ThisExpression");
  12243. }
  12244. } else {
  12245. entity = this.parseIdentifier(!!(flags & 1));
  12246. }
  12247. while (this.eat(16)) {
  12248. const node = this.startNodeAtNode(entity);
  12249. node.left = entity;
  12250. node.right = this.parseIdentifier(!!(flags & 1));
  12251. entity = this.finishNode(node, "TSQualifiedName");
  12252. }
  12253. return entity;
  12254. }
  12255. tsParseTypeReference() {
  12256. const node = this.startNode();
  12257. node.typeName = this.tsParseEntityName(1);
  12258. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  12259. {
  12260. node.typeParameters = this.tsParseTypeArguments();
  12261. }
  12262. }
  12263. return this.finishNode(node, "TSTypeReference");
  12264. }
  12265. tsParseThisTypePredicate(lhs) {
  12266. this.next();
  12267. const node = this.startNodeAtNode(lhs);
  12268. node.parameterName = lhs;
  12269. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  12270. node.asserts = false;
  12271. return this.finishNode(node, "TSTypePredicate");
  12272. }
  12273. tsParseThisTypeNode() {
  12274. const node = this.startNode();
  12275. this.next();
  12276. return this.finishNode(node, "TSThisType");
  12277. }
  12278. tsParseTypeQuery() {
  12279. const node = this.startNode();
  12280. this.expect(87);
  12281. if (this.match(83)) {
  12282. node.exprName = this.tsParseImportType();
  12283. } else {
  12284. {
  12285. node.exprName = this.tsParseEntityName(1 | 2);
  12286. }
  12287. }
  12288. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  12289. {
  12290. node.typeParameters = this.tsParseTypeArguments();
  12291. }
  12292. }
  12293. return this.finishNode(node, "TSTypeQuery");
  12294. }
  12295. tsParseTypeParameter(parseModifiers) {
  12296. const node = this.startNode();
  12297. parseModifiers(node);
  12298. node.name = this.tsParseTypeParameterName();
  12299. node.constraint = this.tsEatThenParseType(81);
  12300. node.default = this.tsEatThenParseType(29);
  12301. return this.finishNode(node, "TSTypeParameter");
  12302. }
  12303. tsTryParseTypeParameters(parseModifiers) {
  12304. if (this.match(47)) {
  12305. return this.tsParseTypeParameters(parseModifiers);
  12306. }
  12307. }
  12308. tsParseTypeParameters(parseModifiers) {
  12309. const node = this.startNode();
  12310. if (this.match(47) || this.match(143)) {
  12311. this.next();
  12312. } else {
  12313. this.unexpected();
  12314. }
  12315. const refTrailingCommaPos = {
  12316. value: -1
  12317. };
  12318. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  12319. if (node.params.length === 0) {
  12320. this.raise(TSErrors.EmptyTypeParameters, node);
  12321. }
  12322. if (refTrailingCommaPos.value !== -1) {
  12323. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  12324. }
  12325. return this.finishNode(node, "TSTypeParameterDeclaration");
  12326. }
  12327. tsFillSignature(returnToken, signature) {
  12328. const returnTokenRequired = returnToken === 19;
  12329. const paramsKey = "parameters";
  12330. const returnTypeKey = "typeAnnotation";
  12331. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  12332. this.expect(10);
  12333. signature[paramsKey] = this.tsParseBindingListForSignature();
  12334. if (returnTokenRequired) {
  12335. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  12336. } else if (this.match(returnToken)) {
  12337. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  12338. }
  12339. }
  12340. tsParseBindingListForSignature() {
  12341. const list = super.parseBindingList(11, 41, 2);
  12342. for (const pattern of list) {
  12343. const {
  12344. type
  12345. } = pattern;
  12346. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  12347. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  12348. type
  12349. });
  12350. }
  12351. }
  12352. return list;
  12353. }
  12354. tsParseTypeMemberSemicolon() {
  12355. if (!this.eat(12) && !this.isLineTerminator()) {
  12356. this.expect(13);
  12357. }
  12358. }
  12359. tsParseSignatureMember(kind, node) {
  12360. this.tsFillSignature(14, node);
  12361. this.tsParseTypeMemberSemicolon();
  12362. return this.finishNode(node, kind);
  12363. }
  12364. tsIsUnambiguouslyIndexSignature() {
  12365. this.next();
  12366. if (tokenIsIdentifier(this.state.type)) {
  12367. this.next();
  12368. return this.match(14);
  12369. }
  12370. return false;
  12371. }
  12372. tsTryParseIndexSignature(node) {
  12373. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  12374. return;
  12375. }
  12376. this.expect(0);
  12377. const id = this.parseIdentifier();
  12378. id.typeAnnotation = this.tsParseTypeAnnotation();
  12379. this.resetEndLocation(id);
  12380. this.expect(3);
  12381. node.parameters = [id];
  12382. const type = this.tsTryParseTypeAnnotation();
  12383. if (type) node.typeAnnotation = type;
  12384. this.tsParseTypeMemberSemicolon();
  12385. return this.finishNode(node, "TSIndexSignature");
  12386. }
  12387. tsParsePropertyOrMethodSignature(node, readonly) {
  12388. if (this.eat(17)) node.optional = true;
  12389. if (this.match(10) || this.match(47)) {
  12390. if (readonly) {
  12391. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  12392. }
  12393. const method = node;
  12394. if (method.kind && this.match(47)) {
  12395. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  12396. }
  12397. this.tsFillSignature(14, method);
  12398. this.tsParseTypeMemberSemicolon();
  12399. const paramsKey = "parameters";
  12400. const returnTypeKey = "typeAnnotation";
  12401. if (method.kind === "get") {
  12402. if (method[paramsKey].length > 0) {
  12403. this.raise(Errors.BadGetterArity, this.state.curPosition());
  12404. if (this.isThisParam(method[paramsKey][0])) {
  12405. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  12406. }
  12407. }
  12408. } else if (method.kind === "set") {
  12409. if (method[paramsKey].length !== 1) {
  12410. this.raise(Errors.BadSetterArity, this.state.curPosition());
  12411. } else {
  12412. const firstParameter = method[paramsKey][0];
  12413. if (this.isThisParam(firstParameter)) {
  12414. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  12415. }
  12416. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  12417. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  12418. }
  12419. if (firstParameter.type === "RestElement") {
  12420. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  12421. }
  12422. }
  12423. if (method[returnTypeKey]) {
  12424. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  12425. }
  12426. } else {
  12427. method.kind = "method";
  12428. }
  12429. return this.finishNode(method, "TSMethodSignature");
  12430. } else {
  12431. const property = node;
  12432. if (readonly) property.readonly = true;
  12433. const type = this.tsTryParseTypeAnnotation();
  12434. if (type) property.typeAnnotation = type;
  12435. this.tsParseTypeMemberSemicolon();
  12436. return this.finishNode(property, "TSPropertySignature");
  12437. }
  12438. }
  12439. tsParseTypeMember() {
  12440. const node = this.startNode();
  12441. if (this.match(10) || this.match(47)) {
  12442. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  12443. }
  12444. if (this.match(77)) {
  12445. const id = this.startNode();
  12446. this.next();
  12447. if (this.match(10) || this.match(47)) {
  12448. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  12449. } else {
  12450. node.key = this.createIdentifier(id, "new");
  12451. return this.tsParsePropertyOrMethodSignature(node, false);
  12452. }
  12453. }
  12454. this.tsParseModifiers({
  12455. allowedModifiers: ["readonly"],
  12456. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  12457. }, node);
  12458. const idx = this.tsTryParseIndexSignature(node);
  12459. if (idx) {
  12460. return idx;
  12461. }
  12462. super.parsePropertyName(node);
  12463. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  12464. node.kind = node.key.name;
  12465. super.parsePropertyName(node);
  12466. if (!this.match(10) && !this.match(47)) {
  12467. this.unexpected(null, 10);
  12468. }
  12469. }
  12470. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  12471. }
  12472. tsParseTypeLiteral() {
  12473. const node = this.startNode();
  12474. node.members = this.tsParseObjectTypeMembers();
  12475. return this.finishNode(node, "TSTypeLiteral");
  12476. }
  12477. tsParseObjectTypeMembers() {
  12478. this.expect(5);
  12479. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  12480. this.expect(8);
  12481. return members;
  12482. }
  12483. tsIsStartOfMappedType() {
  12484. this.next();
  12485. if (this.eat(53)) {
  12486. return this.isContextual(122);
  12487. }
  12488. if (this.isContextual(122)) {
  12489. this.next();
  12490. }
  12491. if (!this.match(0)) {
  12492. return false;
  12493. }
  12494. this.next();
  12495. if (!this.tsIsIdentifier()) {
  12496. return false;
  12497. }
  12498. this.next();
  12499. return this.match(58);
  12500. }
  12501. tsParseMappedType() {
  12502. const node = this.startNode();
  12503. this.expect(5);
  12504. if (this.match(53)) {
  12505. node.readonly = this.state.value;
  12506. this.next();
  12507. this.expectContextual(122);
  12508. } else if (this.eatContextual(122)) {
  12509. node.readonly = true;
  12510. }
  12511. this.expect(0);
  12512. {
  12513. const typeParameter = this.startNode();
  12514. typeParameter.name = this.tsParseTypeParameterName();
  12515. typeParameter.constraint = this.tsExpectThenParseType(58);
  12516. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  12517. }
  12518. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  12519. this.expect(3);
  12520. if (this.match(53)) {
  12521. node.optional = this.state.value;
  12522. this.next();
  12523. this.expect(17);
  12524. } else if (this.eat(17)) {
  12525. node.optional = true;
  12526. }
  12527. node.typeAnnotation = this.tsTryParseType();
  12528. this.semicolon();
  12529. this.expect(8);
  12530. return this.finishNode(node, "TSMappedType");
  12531. }
  12532. tsParseTupleType() {
  12533. const node = this.startNode();
  12534. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  12535. let seenOptionalElement = false;
  12536. node.elementTypes.forEach(elementNode => {
  12537. const {
  12538. type
  12539. } = elementNode;
  12540. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  12541. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  12542. }
  12543. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  12544. });
  12545. return this.finishNode(node, "TSTupleType");
  12546. }
  12547. tsParseTupleElementType() {
  12548. const restStartLoc = this.state.startLoc;
  12549. const rest = this.eat(21);
  12550. const {
  12551. startLoc
  12552. } = this.state;
  12553. let labeled;
  12554. let label;
  12555. let optional;
  12556. let type;
  12557. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  12558. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  12559. if (chAfterWord === 58) {
  12560. labeled = true;
  12561. optional = false;
  12562. label = this.parseIdentifier(true);
  12563. this.expect(14);
  12564. type = this.tsParseType();
  12565. } else if (chAfterWord === 63) {
  12566. optional = true;
  12567. const wordName = this.state.value;
  12568. const typeOrLabel = this.tsParseNonArrayType();
  12569. if (this.lookaheadCharCode() === 58) {
  12570. labeled = true;
  12571. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  12572. this.expect(17);
  12573. this.expect(14);
  12574. type = this.tsParseType();
  12575. } else {
  12576. labeled = false;
  12577. type = typeOrLabel;
  12578. this.expect(17);
  12579. }
  12580. } else {
  12581. type = this.tsParseType();
  12582. optional = this.eat(17);
  12583. labeled = this.eat(14);
  12584. }
  12585. if (labeled) {
  12586. let labeledNode;
  12587. if (label) {
  12588. labeledNode = this.startNodeAt(startLoc);
  12589. labeledNode.optional = optional;
  12590. labeledNode.label = label;
  12591. labeledNode.elementType = type;
  12592. if (this.eat(17)) {
  12593. labeledNode.optional = true;
  12594. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  12595. }
  12596. } else {
  12597. labeledNode = this.startNodeAt(startLoc);
  12598. labeledNode.optional = optional;
  12599. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  12600. labeledNode.label = type;
  12601. labeledNode.elementType = this.tsParseType();
  12602. }
  12603. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  12604. } else if (optional) {
  12605. const optionalTypeNode = this.startNodeAt(startLoc);
  12606. optionalTypeNode.typeAnnotation = type;
  12607. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  12608. }
  12609. if (rest) {
  12610. const restNode = this.startNodeAt(restStartLoc);
  12611. restNode.typeAnnotation = type;
  12612. type = this.finishNode(restNode, "TSRestType");
  12613. }
  12614. return type;
  12615. }
  12616. tsParseParenthesizedType() {
  12617. const node = this.startNode();
  12618. this.expect(10);
  12619. node.typeAnnotation = this.tsParseType();
  12620. this.expect(11);
  12621. return this.finishNode(node, "TSParenthesizedType");
  12622. }
  12623. tsParseFunctionOrConstructorType(type, abstract) {
  12624. const node = this.startNode();
  12625. if (type === "TSConstructorType") {
  12626. node.abstract = !!abstract;
  12627. if (abstract) this.next();
  12628. this.next();
  12629. }
  12630. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  12631. return this.finishNode(node, type);
  12632. }
  12633. tsParseLiteralTypeNode() {
  12634. const node = this.startNode();
  12635. switch (this.state.type) {
  12636. case 135:
  12637. case 136:
  12638. case 134:
  12639. case 85:
  12640. case 86:
  12641. node.literal = super.parseExprAtom();
  12642. break;
  12643. default:
  12644. this.unexpected();
  12645. }
  12646. return this.finishNode(node, "TSLiteralType");
  12647. }
  12648. tsParseTemplateLiteralType() {
  12649. {
  12650. const node = this.startNode();
  12651. node.literal = super.parseTemplate(false);
  12652. return this.finishNode(node, "TSLiteralType");
  12653. }
  12654. }
  12655. parseTemplateSubstitution() {
  12656. if (this.state.inType) return this.tsParseType();
  12657. return super.parseTemplateSubstitution();
  12658. }
  12659. tsParseThisTypeOrThisTypePredicate() {
  12660. const thisKeyword = this.tsParseThisTypeNode();
  12661. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  12662. return this.tsParseThisTypePredicate(thisKeyword);
  12663. } else {
  12664. return thisKeyword;
  12665. }
  12666. }
  12667. tsParseNonArrayType() {
  12668. switch (this.state.type) {
  12669. case 134:
  12670. case 135:
  12671. case 136:
  12672. case 85:
  12673. case 86:
  12674. return this.tsParseLiteralTypeNode();
  12675. case 53:
  12676. if (this.state.value === "-") {
  12677. const node = this.startNode();
  12678. const nextToken = this.lookahead();
  12679. if (nextToken.type !== 135 && nextToken.type !== 136) {
  12680. this.unexpected();
  12681. }
  12682. node.literal = this.parseMaybeUnary();
  12683. return this.finishNode(node, "TSLiteralType");
  12684. }
  12685. break;
  12686. case 78:
  12687. return this.tsParseThisTypeOrThisTypePredicate();
  12688. case 87:
  12689. return this.tsParseTypeQuery();
  12690. case 83:
  12691. return this.tsParseImportType();
  12692. case 5:
  12693. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  12694. case 0:
  12695. return this.tsParseTupleType();
  12696. case 10:
  12697. return this.tsParseParenthesizedType();
  12698. case 25:
  12699. case 24:
  12700. return this.tsParseTemplateLiteralType();
  12701. default:
  12702. {
  12703. const {
  12704. type
  12705. } = this.state;
  12706. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  12707. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  12708. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  12709. const node = this.startNode();
  12710. this.next();
  12711. return this.finishNode(node, nodeType);
  12712. }
  12713. return this.tsParseTypeReference();
  12714. }
  12715. }
  12716. }
  12717. throw this.unexpected();
  12718. }
  12719. tsParseArrayTypeOrHigher() {
  12720. const {
  12721. startLoc
  12722. } = this.state;
  12723. let type = this.tsParseNonArrayType();
  12724. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  12725. if (this.match(3)) {
  12726. const node = this.startNodeAt(startLoc);
  12727. node.elementType = type;
  12728. this.expect(3);
  12729. type = this.finishNode(node, "TSArrayType");
  12730. } else {
  12731. const node = this.startNodeAt(startLoc);
  12732. node.objectType = type;
  12733. node.indexType = this.tsParseType();
  12734. this.expect(3);
  12735. type = this.finishNode(node, "TSIndexedAccessType");
  12736. }
  12737. }
  12738. return type;
  12739. }
  12740. tsParseTypeOperator() {
  12741. const node = this.startNode();
  12742. const operator = this.state.value;
  12743. this.next();
  12744. node.operator = operator;
  12745. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  12746. if (operator === "readonly") {
  12747. this.tsCheckTypeAnnotationForReadOnly(node);
  12748. }
  12749. return this.finishNode(node, "TSTypeOperator");
  12750. }
  12751. tsCheckTypeAnnotationForReadOnly(node) {
  12752. switch (node.typeAnnotation.type) {
  12753. case "TSTupleType":
  12754. case "TSArrayType":
  12755. return;
  12756. default:
  12757. this.raise(TSErrors.UnexpectedReadonly, node);
  12758. }
  12759. }
  12760. tsParseInferType() {
  12761. const node = this.startNode();
  12762. this.expectContextual(115);
  12763. const typeParameter = this.startNode();
  12764. typeParameter.name = this.tsParseTypeParameterName();
  12765. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  12766. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  12767. return this.finishNode(node, "TSInferType");
  12768. }
  12769. tsParseConstraintForInferType() {
  12770. if (this.eat(81)) {
  12771. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  12772. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  12773. return constraint;
  12774. }
  12775. }
  12776. }
  12777. tsParseTypeOperatorOrHigher() {
  12778. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  12779. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  12780. }
  12781. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  12782. const node = this.startNode();
  12783. const hasLeadingOperator = this.eat(operator);
  12784. const types = [];
  12785. do {
  12786. types.push(parseConstituentType());
  12787. } while (this.eat(operator));
  12788. if (types.length === 1 && !hasLeadingOperator) {
  12789. return types[0];
  12790. }
  12791. node.types = types;
  12792. return this.finishNode(node, kind);
  12793. }
  12794. tsParseIntersectionTypeOrHigher() {
  12795. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  12796. }
  12797. tsParseUnionTypeOrHigher() {
  12798. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  12799. }
  12800. tsIsStartOfFunctionType() {
  12801. if (this.match(47)) {
  12802. return true;
  12803. }
  12804. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  12805. }
  12806. tsSkipParameterStart() {
  12807. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  12808. this.next();
  12809. return true;
  12810. }
  12811. if (this.match(5)) {
  12812. const {
  12813. errors
  12814. } = this.state;
  12815. const previousErrorCount = errors.length;
  12816. try {
  12817. this.parseObjectLike(8, true);
  12818. return errors.length === previousErrorCount;
  12819. } catch (_unused) {
  12820. return false;
  12821. }
  12822. }
  12823. if (this.match(0)) {
  12824. this.next();
  12825. const {
  12826. errors
  12827. } = this.state;
  12828. const previousErrorCount = errors.length;
  12829. try {
  12830. super.parseBindingList(3, 93, 1);
  12831. return errors.length === previousErrorCount;
  12832. } catch (_unused2) {
  12833. return false;
  12834. }
  12835. }
  12836. return false;
  12837. }
  12838. tsIsUnambiguouslyStartOfFunctionType() {
  12839. this.next();
  12840. if (this.match(11) || this.match(21)) {
  12841. return true;
  12842. }
  12843. if (this.tsSkipParameterStart()) {
  12844. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  12845. return true;
  12846. }
  12847. if (this.match(11)) {
  12848. this.next();
  12849. if (this.match(19)) {
  12850. return true;
  12851. }
  12852. }
  12853. }
  12854. return false;
  12855. }
  12856. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  12857. return this.tsInType(() => {
  12858. const t = this.startNode();
  12859. this.expect(returnToken);
  12860. const node = this.startNode();
  12861. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  12862. if (asserts && this.match(78)) {
  12863. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  12864. if (thisTypePredicate.type === "TSThisType") {
  12865. node.parameterName = thisTypePredicate;
  12866. node.asserts = true;
  12867. node.typeAnnotation = null;
  12868. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  12869. } else {
  12870. this.resetStartLocationFromNode(thisTypePredicate, node);
  12871. thisTypePredicate.asserts = true;
  12872. }
  12873. t.typeAnnotation = thisTypePredicate;
  12874. return this.finishNode(t, "TSTypeAnnotation");
  12875. }
  12876. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  12877. if (!typePredicateVariable) {
  12878. if (!asserts) {
  12879. return this.tsParseTypeAnnotation(false, t);
  12880. }
  12881. node.parameterName = this.parseIdentifier();
  12882. node.asserts = asserts;
  12883. node.typeAnnotation = null;
  12884. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  12885. return this.finishNode(t, "TSTypeAnnotation");
  12886. }
  12887. const type = this.tsParseTypeAnnotation(false);
  12888. node.parameterName = typePredicateVariable;
  12889. node.typeAnnotation = type;
  12890. node.asserts = asserts;
  12891. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  12892. return this.finishNode(t, "TSTypeAnnotation");
  12893. });
  12894. }
  12895. tsTryParseTypeOrTypePredicateAnnotation() {
  12896. if (this.match(14)) {
  12897. return this.tsParseTypeOrTypePredicateAnnotation(14);
  12898. }
  12899. }
  12900. tsTryParseTypeAnnotation() {
  12901. if (this.match(14)) {
  12902. return this.tsParseTypeAnnotation();
  12903. }
  12904. }
  12905. tsTryParseType() {
  12906. return this.tsEatThenParseType(14);
  12907. }
  12908. tsParseTypePredicatePrefix() {
  12909. const id = this.parseIdentifier();
  12910. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  12911. this.next();
  12912. return id;
  12913. }
  12914. }
  12915. tsParseTypePredicateAsserts() {
  12916. if (this.state.type !== 109) {
  12917. return false;
  12918. }
  12919. const containsEsc = this.state.containsEsc;
  12920. this.next();
  12921. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  12922. return false;
  12923. }
  12924. if (containsEsc) {
  12925. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  12926. reservedWord: "asserts"
  12927. });
  12928. }
  12929. return true;
  12930. }
  12931. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  12932. this.tsInType(() => {
  12933. if (eatColon) this.expect(14);
  12934. t.typeAnnotation = this.tsParseType();
  12935. });
  12936. return this.finishNode(t, "TSTypeAnnotation");
  12937. }
  12938. tsParseType() {
  12939. assert(this.state.inType);
  12940. const type = this.tsParseNonConditionalType();
  12941. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  12942. return type;
  12943. }
  12944. const node = this.startNodeAtNode(type);
  12945. node.checkType = type;
  12946. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  12947. this.expect(17);
  12948. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  12949. this.expect(14);
  12950. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  12951. return this.finishNode(node, "TSConditionalType");
  12952. }
  12953. isAbstractConstructorSignature() {
  12954. return this.isContextual(124) && this.isLookaheadContextual("new");
  12955. }
  12956. tsParseNonConditionalType() {
  12957. if (this.tsIsStartOfFunctionType()) {
  12958. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  12959. }
  12960. if (this.match(77)) {
  12961. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  12962. } else if (this.isAbstractConstructorSignature()) {
  12963. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  12964. }
  12965. return this.tsParseUnionTypeOrHigher();
  12966. }
  12967. tsParseTypeAssertion() {
  12968. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  12969. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  12970. }
  12971. const node = this.startNode();
  12972. node.typeAnnotation = this.tsInType(() => {
  12973. this.next();
  12974. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  12975. });
  12976. this.expect(48);
  12977. node.expression = this.parseMaybeUnary();
  12978. return this.finishNode(node, "TSTypeAssertion");
  12979. }
  12980. tsParseHeritageClause(token) {
  12981. const originalStartLoc = this.state.startLoc;
  12982. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  12983. {
  12984. const node = this.startNode();
  12985. node.expression = this.tsParseEntityName(1 | 2);
  12986. if (this.match(47)) {
  12987. node.typeParameters = this.tsParseTypeArguments();
  12988. }
  12989. return this.finishNode(node, "TSExpressionWithTypeArguments");
  12990. }
  12991. });
  12992. if (!delimitedList.length) {
  12993. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  12994. token
  12995. });
  12996. }
  12997. return delimitedList;
  12998. }
  12999. tsParseInterfaceDeclaration(node, properties = {}) {
  13000. if (this.hasFollowingLineBreak()) return null;
  13001. this.expectContextual(129);
  13002. if (properties.declare) node.declare = true;
  13003. if (tokenIsIdentifier(this.state.type)) {
  13004. node.id = this.parseIdentifier();
  13005. this.checkIdentifier(node.id, 130);
  13006. } else {
  13007. node.id = null;
  13008. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  13009. }
  13010. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  13011. if (this.eat(81)) {
  13012. node.extends = this.tsParseHeritageClause("extends");
  13013. }
  13014. const body = this.startNode();
  13015. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  13016. node.body = this.finishNode(body, "TSInterfaceBody");
  13017. return this.finishNode(node, "TSInterfaceDeclaration");
  13018. }
  13019. tsParseTypeAliasDeclaration(node) {
  13020. node.id = this.parseIdentifier();
  13021. this.checkIdentifier(node.id, 2);
  13022. node.typeAnnotation = this.tsInType(() => {
  13023. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  13024. this.expect(29);
  13025. if (this.isContextual(114) && this.lookaheadCharCode() !== 46) {
  13026. const node = this.startNode();
  13027. this.next();
  13028. return this.finishNode(node, "TSIntrinsicKeyword");
  13029. }
  13030. return this.tsParseType();
  13031. });
  13032. this.semicolon();
  13033. return this.finishNode(node, "TSTypeAliasDeclaration");
  13034. }
  13035. tsInTopLevelContext(cb) {
  13036. if (this.curContext() !== types.brace) {
  13037. const oldContext = this.state.context;
  13038. this.state.context = [oldContext[0]];
  13039. try {
  13040. return cb();
  13041. } finally {
  13042. this.state.context = oldContext;
  13043. }
  13044. } else {
  13045. return cb();
  13046. }
  13047. }
  13048. tsInType(cb) {
  13049. const oldInType = this.state.inType;
  13050. this.state.inType = true;
  13051. try {
  13052. return cb();
  13053. } finally {
  13054. this.state.inType = oldInType;
  13055. }
  13056. }
  13057. tsInDisallowConditionalTypesContext(cb) {
  13058. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  13059. this.state.inDisallowConditionalTypesContext = true;
  13060. try {
  13061. return cb();
  13062. } finally {
  13063. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  13064. }
  13065. }
  13066. tsInAllowConditionalTypesContext(cb) {
  13067. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  13068. this.state.inDisallowConditionalTypesContext = false;
  13069. try {
  13070. return cb();
  13071. } finally {
  13072. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  13073. }
  13074. }
  13075. tsEatThenParseType(token) {
  13076. if (this.match(token)) {
  13077. return this.tsNextThenParseType();
  13078. }
  13079. }
  13080. tsExpectThenParseType(token) {
  13081. return this.tsInType(() => {
  13082. this.expect(token);
  13083. return this.tsParseType();
  13084. });
  13085. }
  13086. tsNextThenParseType() {
  13087. return this.tsInType(() => {
  13088. this.next();
  13089. return this.tsParseType();
  13090. });
  13091. }
  13092. tsParseEnumMember() {
  13093. const node = this.startNode();
  13094. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  13095. if (this.eat(29)) {
  13096. node.initializer = super.parseMaybeAssignAllowIn();
  13097. }
  13098. return this.finishNode(node, "TSEnumMember");
  13099. }
  13100. tsParseEnumDeclaration(node, properties = {}) {
  13101. if (properties.const) node.const = true;
  13102. if (properties.declare) node.declare = true;
  13103. this.expectContextual(126);
  13104. node.id = this.parseIdentifier();
  13105. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  13106. {
  13107. this.expect(5);
  13108. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  13109. this.expect(8);
  13110. }
  13111. return this.finishNode(node, "TSEnumDeclaration");
  13112. }
  13113. tsParseEnumBody() {
  13114. const node = this.startNode();
  13115. this.expect(5);
  13116. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  13117. this.expect(8);
  13118. return this.finishNode(node, "TSEnumBody");
  13119. }
  13120. tsParseModuleBlock() {
  13121. const node = this.startNode();
  13122. this.scope.enter(0);
  13123. this.expect(5);
  13124. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  13125. this.scope.exit();
  13126. return this.finishNode(node, "TSModuleBlock");
  13127. }
  13128. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  13129. node.id = this.parseIdentifier();
  13130. if (!nested) {
  13131. this.checkIdentifier(node.id, 1024);
  13132. }
  13133. if (this.eat(16)) {
  13134. const inner = this.startNode();
  13135. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  13136. node.body = inner;
  13137. } else {
  13138. this.scope.enter(1024);
  13139. this.prodParam.enter(0);
  13140. node.body = this.tsParseModuleBlock();
  13141. this.prodParam.exit();
  13142. this.scope.exit();
  13143. }
  13144. return this.finishNode(node, "TSModuleDeclaration");
  13145. }
  13146. tsParseAmbientExternalModuleDeclaration(node) {
  13147. if (this.isContextual(112)) {
  13148. node.kind = "global";
  13149. {
  13150. node.global = true;
  13151. }
  13152. node.id = this.parseIdentifier();
  13153. } else if (this.match(134)) {
  13154. node.kind = "module";
  13155. node.id = super.parseStringLiteral(this.state.value);
  13156. } else {
  13157. this.unexpected();
  13158. }
  13159. if (this.match(5)) {
  13160. this.scope.enter(1024);
  13161. this.prodParam.enter(0);
  13162. node.body = this.tsParseModuleBlock();
  13163. this.prodParam.exit();
  13164. this.scope.exit();
  13165. } else {
  13166. this.semicolon();
  13167. }
  13168. return this.finishNode(node, "TSModuleDeclaration");
  13169. }
  13170. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  13171. {
  13172. node.isExport = isExport || false;
  13173. }
  13174. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  13175. this.checkIdentifier(node.id, 4096);
  13176. this.expect(29);
  13177. const moduleReference = this.tsParseModuleReference();
  13178. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  13179. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  13180. }
  13181. node.moduleReference = moduleReference;
  13182. this.semicolon();
  13183. return this.finishNode(node, "TSImportEqualsDeclaration");
  13184. }
  13185. tsIsExternalModuleReference() {
  13186. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  13187. }
  13188. tsParseModuleReference() {
  13189. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  13190. }
  13191. tsParseExternalModuleReference() {
  13192. const node = this.startNode();
  13193. this.expectContextual(119);
  13194. this.expect(10);
  13195. if (!this.match(134)) {
  13196. this.unexpected();
  13197. }
  13198. node.expression = super.parseExprAtom();
  13199. this.expect(11);
  13200. this.sawUnambiguousESM = true;
  13201. return this.finishNode(node, "TSExternalModuleReference");
  13202. }
  13203. tsLookAhead(f) {
  13204. const state = this.state.clone();
  13205. const res = f();
  13206. this.state = state;
  13207. return res;
  13208. }
  13209. tsTryParseAndCatch(f) {
  13210. const result = this.tryParse(abort => f() || abort());
  13211. if (result.aborted || !result.node) return;
  13212. if (result.error) this.state = result.failState;
  13213. return result.node;
  13214. }
  13215. tsTryParse(f) {
  13216. const state = this.state.clone();
  13217. const result = f();
  13218. if (result !== undefined && result !== false) {
  13219. return result;
  13220. }
  13221. this.state = state;
  13222. }
  13223. tsTryParseDeclare(node) {
  13224. if (this.isLineTerminator()) {
  13225. return;
  13226. }
  13227. const startType = this.state.type;
  13228. return this.tsInAmbientContext(() => {
  13229. switch (startType) {
  13230. case 68:
  13231. node.declare = true;
  13232. return super.parseFunctionStatement(node, false, false);
  13233. case 80:
  13234. node.declare = true;
  13235. return this.parseClass(node, true, false);
  13236. case 126:
  13237. return this.tsParseEnumDeclaration(node, {
  13238. declare: true
  13239. });
  13240. case 112:
  13241. return this.tsParseAmbientExternalModuleDeclaration(node);
  13242. case 100:
  13243. if (this.state.containsEsc) {
  13244. return;
  13245. }
  13246. case 75:
  13247. case 74:
  13248. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  13249. node.declare = true;
  13250. return this.parseVarStatement(node, this.state.value, true);
  13251. }
  13252. this.expect(75);
  13253. return this.tsParseEnumDeclaration(node, {
  13254. const: true,
  13255. declare: true
  13256. });
  13257. case 107:
  13258. if (this.isUsing()) {
  13259. this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
  13260. node.declare = true;
  13261. return this.parseVarStatement(node, "using", true);
  13262. }
  13263. break;
  13264. case 96:
  13265. if (this.isAwaitUsing()) {
  13266. this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
  13267. node.declare = true;
  13268. this.next();
  13269. return this.parseVarStatement(node, "await using", true);
  13270. }
  13271. break;
  13272. case 129:
  13273. {
  13274. const result = this.tsParseInterfaceDeclaration(node, {
  13275. declare: true
  13276. });
  13277. if (result) return result;
  13278. }
  13279. default:
  13280. if (tokenIsIdentifier(startType)) {
  13281. return this.tsParseDeclaration(node, this.state.type, true, null);
  13282. }
  13283. }
  13284. });
  13285. }
  13286. tsTryParseExportDeclaration() {
  13287. return this.tsParseDeclaration(this.startNode(), this.state.type, true, null);
  13288. }
  13289. tsParseDeclaration(node, type, next, decorators) {
  13290. switch (type) {
  13291. case 124:
  13292. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  13293. return this.tsParseAbstractDeclaration(node, decorators);
  13294. }
  13295. break;
  13296. case 127:
  13297. if (this.tsCheckLineTerminator(next)) {
  13298. if (this.match(134)) {
  13299. return this.tsParseAmbientExternalModuleDeclaration(node);
  13300. } else if (tokenIsIdentifier(this.state.type)) {
  13301. node.kind = "module";
  13302. return this.tsParseModuleOrNamespaceDeclaration(node);
  13303. }
  13304. }
  13305. break;
  13306. case 128:
  13307. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  13308. node.kind = "namespace";
  13309. return this.tsParseModuleOrNamespaceDeclaration(node);
  13310. }
  13311. break;
  13312. case 130:
  13313. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  13314. return this.tsParseTypeAliasDeclaration(node);
  13315. }
  13316. break;
  13317. }
  13318. }
  13319. tsCheckLineTerminator(next) {
  13320. if (next) {
  13321. if (this.hasFollowingLineBreak()) return false;
  13322. this.next();
  13323. return true;
  13324. }
  13325. return !this.isLineTerminator();
  13326. }
  13327. tsTryParseGenericAsyncArrowFunction(startLoc) {
  13328. if (!this.match(47)) return;
  13329. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13330. this.state.maybeInArrowParameters = true;
  13331. const res = this.tsTryParseAndCatch(() => {
  13332. const node = this.startNodeAt(startLoc);
  13333. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  13334. super.parseFunctionParams(node);
  13335. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  13336. this.expect(19);
  13337. return node;
  13338. });
  13339. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13340. if (!res) return;
  13341. return super.parseArrowExpression(res, null, true);
  13342. }
  13343. tsParseTypeArgumentsInExpression() {
  13344. if (this.reScan_lt() !== 47) return;
  13345. return this.tsParseTypeArguments();
  13346. }
  13347. tsParseTypeArguments() {
  13348. const node = this.startNode();
  13349. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  13350. this.expect(47);
  13351. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  13352. }));
  13353. if (node.params.length === 0) {
  13354. this.raise(TSErrors.EmptyTypeArguments, node);
  13355. } else if (!this.state.inType && this.curContext() === types.brace) {
  13356. this.reScan_lt_gt();
  13357. }
  13358. this.expect(48);
  13359. return this.finishNode(node, "TSTypeParameterInstantiation");
  13360. }
  13361. tsIsDeclarationStart() {
  13362. return tokenIsTSDeclarationStart(this.state.type);
  13363. }
  13364. isExportDefaultSpecifier() {
  13365. if (this.tsIsDeclarationStart()) return false;
  13366. return super.isExportDefaultSpecifier();
  13367. }
  13368. parseBindingElement(flags, decorators) {
  13369. const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
  13370. const modified = {};
  13371. this.tsParseModifiers({
  13372. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  13373. }, modified);
  13374. const accessibility = modified.accessibility;
  13375. const override = modified.override;
  13376. const readonly = modified.readonly;
  13377. if (!(flags & 4) && (accessibility || readonly || override)) {
  13378. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  13379. }
  13380. const left = this.parseMaybeDefault();
  13381. if (flags & 2) {
  13382. this.parseFunctionParamType(left);
  13383. }
  13384. const elt = this.parseMaybeDefault(left.loc.start, left);
  13385. if (accessibility || readonly || override) {
  13386. const pp = this.startNodeAt(startLoc);
  13387. if (decorators.length) {
  13388. pp.decorators = decorators;
  13389. }
  13390. if (accessibility) pp.accessibility = accessibility;
  13391. if (readonly) pp.readonly = readonly;
  13392. if (override) pp.override = override;
  13393. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  13394. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  13395. }
  13396. pp.parameter = elt;
  13397. return this.finishNode(pp, "TSParameterProperty");
  13398. }
  13399. if (decorators.length) {
  13400. left.decorators = decorators;
  13401. }
  13402. return elt;
  13403. }
  13404. isSimpleParameter(node) {
  13405. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  13406. }
  13407. tsDisallowOptionalPattern(node) {
  13408. for (const param of node.params) {
  13409. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  13410. this.raise(TSErrors.PatternIsOptional, param);
  13411. }
  13412. }
  13413. }
  13414. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  13415. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  13416. this.tsDisallowOptionalPattern(node);
  13417. }
  13418. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  13419. if (this.match(14)) {
  13420. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  13421. }
  13422. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  13423. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  13424. return this.finishNode(node, bodilessType);
  13425. }
  13426. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  13427. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  13428. if (node.declare) {
  13429. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  13430. }
  13431. }
  13432. this.tsDisallowOptionalPattern(node);
  13433. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  13434. }
  13435. registerFunctionStatementId(node) {
  13436. if (!node.body && node.id) {
  13437. this.checkIdentifier(node.id, 1024);
  13438. } else {
  13439. super.registerFunctionStatementId(node);
  13440. }
  13441. }
  13442. tsCheckForInvalidTypeCasts(items) {
  13443. items.forEach(node => {
  13444. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  13445. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  13446. }
  13447. });
  13448. }
  13449. toReferencedList(exprList, isInParens) {
  13450. this.tsCheckForInvalidTypeCasts(exprList);
  13451. return exprList;
  13452. }
  13453. parseArrayLike(close, isTuple, refExpressionErrors) {
  13454. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  13455. if (node.type === "ArrayExpression") {
  13456. this.tsCheckForInvalidTypeCasts(node.elements);
  13457. }
  13458. return node;
  13459. }
  13460. parseSubscript(base, startLoc, noCalls, state) {
  13461. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  13462. this.state.canStartJSXElement = false;
  13463. this.next();
  13464. const nonNullExpression = this.startNodeAt(startLoc);
  13465. nonNullExpression.expression = base;
  13466. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  13467. }
  13468. let isOptionalCall = false;
  13469. if (this.match(18) && this.lookaheadCharCode() === 60) {
  13470. if (noCalls) {
  13471. state.stop = true;
  13472. return base;
  13473. }
  13474. state.optionalChainMember = isOptionalCall = true;
  13475. this.next();
  13476. }
  13477. if (this.match(47) || this.match(51)) {
  13478. let missingParenErrorLoc;
  13479. const result = this.tsTryParseAndCatch(() => {
  13480. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  13481. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  13482. if (asyncArrowFn) {
  13483. state.stop = true;
  13484. return asyncArrowFn;
  13485. }
  13486. }
  13487. const typeArguments = this.tsParseTypeArgumentsInExpression();
  13488. if (!typeArguments) return;
  13489. if (isOptionalCall && !this.match(10)) {
  13490. missingParenErrorLoc = this.state.curPosition();
  13491. return;
  13492. }
  13493. if (tokenIsTemplate(this.state.type)) {
  13494. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  13495. {
  13496. result.typeParameters = typeArguments;
  13497. }
  13498. return result;
  13499. }
  13500. if (!noCalls && this.eat(10)) {
  13501. const node = this.startNodeAt(startLoc);
  13502. node.callee = base;
  13503. node.arguments = this.parseCallExpressionArguments();
  13504. this.tsCheckForInvalidTypeCasts(node.arguments);
  13505. {
  13506. node.typeParameters = typeArguments;
  13507. }
  13508. if (state.optionalChainMember) {
  13509. node.optional = isOptionalCall;
  13510. }
  13511. return this.finishCallExpression(node, state.optionalChainMember);
  13512. }
  13513. const tokenType = this.state.type;
  13514. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  13515. return;
  13516. }
  13517. const node = this.startNodeAt(startLoc);
  13518. node.expression = base;
  13519. {
  13520. node.typeParameters = typeArguments;
  13521. }
  13522. return this.finishNode(node, "TSInstantiationExpression");
  13523. });
  13524. if (missingParenErrorLoc) {
  13525. this.unexpected(missingParenErrorLoc, 10);
  13526. }
  13527. if (result) {
  13528. if (result.type === "TSInstantiationExpression") {
  13529. if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
  13530. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  13531. }
  13532. if (!this.match(16) && !this.match(18)) {
  13533. result.expression = super.stopParseSubscript(base, state);
  13534. }
  13535. }
  13536. return result;
  13537. }
  13538. }
  13539. return super.parseSubscript(base, startLoc, noCalls, state);
  13540. }
  13541. parseNewCallee(node) {
  13542. var _callee$extra;
  13543. super.parseNewCallee(node);
  13544. const {
  13545. callee
  13546. } = node;
  13547. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  13548. {
  13549. node.typeParameters = callee.typeParameters;
  13550. }
  13551. node.callee = callee.expression;
  13552. }
  13553. }
  13554. parseExprOp(left, leftStartLoc, minPrec) {
  13555. let isSatisfies;
  13556. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  13557. const node = this.startNodeAt(leftStartLoc);
  13558. node.expression = left;
  13559. node.typeAnnotation = this.tsInType(() => {
  13560. this.next();
  13561. if (this.match(75)) {
  13562. if (isSatisfies) {
  13563. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  13564. keyword: "const"
  13565. });
  13566. }
  13567. return this.tsParseTypeReference();
  13568. }
  13569. return this.tsParseType();
  13570. });
  13571. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  13572. this.reScan_lt_gt();
  13573. return this.parseExprOp(node, leftStartLoc, minPrec);
  13574. }
  13575. return super.parseExprOp(left, leftStartLoc, minPrec);
  13576. }
  13577. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  13578. if (!this.state.isAmbientContext) {
  13579. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  13580. }
  13581. }
  13582. checkImportReflection(node) {
  13583. super.checkImportReflection(node);
  13584. if (node.module && node.importKind !== "value") {
  13585. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  13586. }
  13587. }
  13588. checkDuplicateExports() {}
  13589. isPotentialImportPhase(isExport) {
  13590. if (super.isPotentialImportPhase(isExport)) return true;
  13591. if (this.isContextual(130)) {
  13592. const ch = this.lookaheadCharCode();
  13593. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  13594. }
  13595. return !isExport && this.isContextual(87);
  13596. }
  13597. applyImportPhase(node, isExport, phase, loc) {
  13598. super.applyImportPhase(node, isExport, phase, loc);
  13599. if (isExport) {
  13600. node.exportKind = phase === "type" ? "type" : "value";
  13601. } else {
  13602. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  13603. }
  13604. }
  13605. parseImport(node) {
  13606. if (this.match(134)) {
  13607. node.importKind = "value";
  13608. return super.parseImport(node);
  13609. }
  13610. let importNode;
  13611. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  13612. node.importKind = "value";
  13613. return this.tsParseImportEqualsDeclaration(node);
  13614. } else if (this.isContextual(130)) {
  13615. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  13616. if (this.lookaheadCharCode() === 61) {
  13617. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  13618. } else {
  13619. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  13620. }
  13621. } else {
  13622. importNode = super.parseImport(node);
  13623. }
  13624. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  13625. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  13626. }
  13627. return importNode;
  13628. }
  13629. parseExport(node, decorators) {
  13630. if (this.match(83)) {
  13631. const nodeImportEquals = node;
  13632. this.next();
  13633. let maybeDefaultIdentifier = null;
  13634. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  13635. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  13636. } else {
  13637. nodeImportEquals.importKind = "value";
  13638. }
  13639. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  13640. {
  13641. return declaration;
  13642. }
  13643. } else if (this.eat(29)) {
  13644. const assign = node;
  13645. assign.expression = super.parseExpression();
  13646. this.semicolon();
  13647. this.sawUnambiguousESM = true;
  13648. return this.finishNode(assign, "TSExportAssignment");
  13649. } else if (this.eatContextual(93)) {
  13650. const decl = node;
  13651. this.expectContextual(128);
  13652. decl.id = this.parseIdentifier();
  13653. this.semicolon();
  13654. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  13655. } else {
  13656. return super.parseExport(node, decorators);
  13657. }
  13658. }
  13659. isAbstractClass() {
  13660. return this.isContextual(124) && this.isLookaheadContextual("class");
  13661. }
  13662. parseExportDefaultExpression() {
  13663. if (this.isAbstractClass()) {
  13664. const cls = this.startNode();
  13665. this.next();
  13666. cls.abstract = true;
  13667. return this.parseClass(cls, true, true);
  13668. }
  13669. if (this.match(129)) {
  13670. const result = this.tsParseInterfaceDeclaration(this.startNode());
  13671. if (result) return result;
  13672. }
  13673. return super.parseExportDefaultExpression();
  13674. }
  13675. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13676. const {
  13677. isAmbientContext
  13678. } = this.state;
  13679. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  13680. if (!isAmbientContext) return declaration;
  13681. if (!node.declare && (kind === "using" || kind === "await using")) {
  13682. this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
  13683. return declaration;
  13684. }
  13685. for (const {
  13686. id,
  13687. init
  13688. } of declaration.declarations) {
  13689. if (!init) continue;
  13690. if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
  13691. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  13692. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  13693. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  13694. }
  13695. }
  13696. return declaration;
  13697. }
  13698. parseStatementContent(flags, decorators) {
  13699. if (!this.state.containsEsc) {
  13700. switch (this.state.type) {
  13701. case 75:
  13702. {
  13703. if (this.isLookaheadContextual("enum")) {
  13704. const node = this.startNode();
  13705. this.expect(75);
  13706. return this.tsParseEnumDeclaration(node, {
  13707. const: true
  13708. });
  13709. }
  13710. break;
  13711. }
  13712. case 124:
  13713. case 125:
  13714. {
  13715. if (this.nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine()) {
  13716. const token = this.state.type;
  13717. const node = this.startNode();
  13718. this.next();
  13719. const declaration = token === 125 ? this.tsTryParseDeclare(node) : this.tsParseAbstractDeclaration(node, decorators);
  13720. if (declaration) {
  13721. if (token === 125) {
  13722. declaration.declare = true;
  13723. }
  13724. return declaration;
  13725. } else {
  13726. node.expression = this.createIdentifier(this.startNodeAt(node.loc.start), token === 125 ? "declare" : "abstract");
  13727. this.semicolon(false);
  13728. return this.finishNode(node, "ExpressionStatement");
  13729. }
  13730. }
  13731. break;
  13732. }
  13733. case 126:
  13734. return this.tsParseEnumDeclaration(this.startNode());
  13735. case 112:
  13736. {
  13737. const nextCh = this.lookaheadCharCode();
  13738. if (nextCh === 123) {
  13739. const node = this.startNode();
  13740. return this.tsParseAmbientExternalModuleDeclaration(node);
  13741. }
  13742. break;
  13743. }
  13744. case 129:
  13745. {
  13746. const result = this.tsParseInterfaceDeclaration(this.startNode());
  13747. if (result) return result;
  13748. break;
  13749. }
  13750. case 127:
  13751. {
  13752. if (this.nextTokenIsIdentifierOrStringLiteralOnSameLine()) {
  13753. const node = this.startNode();
  13754. this.next();
  13755. return this.tsParseDeclaration(node, 127, false, decorators);
  13756. }
  13757. break;
  13758. }
  13759. case 128:
  13760. {
  13761. if (this.nextTokenIsIdentifierOnSameLine()) {
  13762. const node = this.startNode();
  13763. this.next();
  13764. return this.tsParseDeclaration(node, 128, false, decorators);
  13765. }
  13766. break;
  13767. }
  13768. case 130:
  13769. {
  13770. if (this.nextTokenIsIdentifierOnSameLine()) {
  13771. const node = this.startNode();
  13772. this.next();
  13773. return this.tsParseTypeAliasDeclaration(node);
  13774. }
  13775. break;
  13776. }
  13777. }
  13778. }
  13779. return super.parseStatementContent(flags, decorators);
  13780. }
  13781. parseAccessModifier() {
  13782. return this.tsParseModifier(["public", "protected", "private"]);
  13783. }
  13784. tsHasSomeModifiers(member, modifiers) {
  13785. return modifiers.some(modifier => {
  13786. if (tsIsAccessModifier(modifier)) {
  13787. return member.accessibility === modifier;
  13788. }
  13789. return !!member[modifier];
  13790. });
  13791. }
  13792. tsIsStartOfStaticBlocks() {
  13793. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  13794. }
  13795. parseClassMember(classBody, member, state) {
  13796. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  13797. this.tsParseModifiers({
  13798. allowedModifiers: modifiers,
  13799. disallowedModifiers: ["in", "out"],
  13800. stopOnStartOfClassStaticBlock: true,
  13801. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  13802. }, member);
  13803. const callParseClassMemberWithIsStatic = () => {
  13804. if (this.tsIsStartOfStaticBlocks()) {
  13805. this.next();
  13806. this.next();
  13807. if (this.tsHasSomeModifiers(member, modifiers)) {
  13808. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  13809. }
  13810. super.parseClassStaticBlock(classBody, member);
  13811. } else {
  13812. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  13813. }
  13814. };
  13815. if (member.declare) {
  13816. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  13817. } else {
  13818. callParseClassMemberWithIsStatic();
  13819. }
  13820. }
  13821. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13822. const idx = this.tsTryParseIndexSignature(member);
  13823. if (idx) {
  13824. classBody.body.push(idx);
  13825. if (member.abstract) {
  13826. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  13827. }
  13828. if (member.accessibility) {
  13829. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  13830. modifier: member.accessibility
  13831. });
  13832. }
  13833. if (member.declare) {
  13834. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  13835. }
  13836. if (member.override) {
  13837. this.raise(TSErrors.IndexSignatureHasOverride, member);
  13838. }
  13839. return;
  13840. }
  13841. if (!this.state.inAbstractClass && member.abstract) {
  13842. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  13843. }
  13844. if (member.override) {
  13845. if (!state.hadSuperClass) {
  13846. this.raise(TSErrors.OverrideNotInSubClass, member);
  13847. }
  13848. }
  13849. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13850. }
  13851. parsePostMemberNameModifiers(methodOrProp) {
  13852. const optional = this.eat(17);
  13853. if (optional) methodOrProp.optional = true;
  13854. if (methodOrProp.readonly && this.match(10)) {
  13855. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  13856. }
  13857. if (methodOrProp.declare && this.match(10)) {
  13858. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  13859. }
  13860. }
  13861. shouldParseExportDeclaration() {
  13862. if (this.tsIsDeclarationStart()) return true;
  13863. return super.shouldParseExportDeclaration();
  13864. }
  13865. parseConditional(expr, startLoc, refExpressionErrors) {
  13866. if (!this.match(17)) return expr;
  13867. if (this.state.maybeInArrowParameters) {
  13868. const nextCh = this.lookaheadCharCode();
  13869. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  13870. this.setOptionalParametersError(refExpressionErrors);
  13871. return expr;
  13872. }
  13873. }
  13874. return super.parseConditional(expr, startLoc, refExpressionErrors);
  13875. }
  13876. parseParenItem(node, startLoc) {
  13877. const newNode = super.parseParenItem(node, startLoc);
  13878. if (this.eat(17)) {
  13879. newNode.optional = true;
  13880. this.resetEndLocation(node);
  13881. }
  13882. if (this.match(14)) {
  13883. const typeCastNode = this.startNodeAt(startLoc);
  13884. typeCastNode.expression = node;
  13885. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  13886. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  13887. }
  13888. return node;
  13889. }
  13890. parseExportDeclaration(node) {
  13891. if (!this.state.isAmbientContext && this.isContextual(125)) {
  13892. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  13893. }
  13894. const startLoc = this.state.startLoc;
  13895. const isDeclare = this.eatContextual(125);
  13896. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  13897. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  13898. }
  13899. const isIdentifier = tokenIsIdentifier(this.state.type);
  13900. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  13901. if (!declaration) return null;
  13902. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  13903. node.exportKind = "type";
  13904. }
  13905. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  13906. this.resetStartLocation(declaration, startLoc);
  13907. declaration.declare = true;
  13908. }
  13909. return declaration;
  13910. }
  13911. parseClassId(node, isStatement, optionalId, bindingType) {
  13912. if ((!isStatement || optionalId) && this.isContextual(113)) {
  13913. return;
  13914. }
  13915. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  13916. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  13917. if (typeParameters) node.typeParameters = typeParameters;
  13918. }
  13919. parseClassPropertyAnnotation(node) {
  13920. if (!node.optional) {
  13921. if (this.eat(35)) {
  13922. node.definite = true;
  13923. } else if (this.eat(17)) {
  13924. node.optional = true;
  13925. }
  13926. }
  13927. const type = this.tsTryParseTypeAnnotation();
  13928. if (type) node.typeAnnotation = type;
  13929. }
  13930. parseClassProperty(node) {
  13931. this.parseClassPropertyAnnotation(node);
  13932. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  13933. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  13934. }
  13935. if (node.abstract && this.match(29)) {
  13936. const {
  13937. key
  13938. } = node;
  13939. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  13940. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  13941. });
  13942. }
  13943. return super.parseClassProperty(node);
  13944. }
  13945. parseClassPrivateProperty(node) {
  13946. if (node.abstract) {
  13947. this.raise(TSErrors.PrivateElementHasAbstract, node);
  13948. }
  13949. if (node.accessibility) {
  13950. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  13951. modifier: node.accessibility
  13952. });
  13953. }
  13954. this.parseClassPropertyAnnotation(node);
  13955. return super.parseClassPrivateProperty(node);
  13956. }
  13957. parseClassAccessorProperty(node) {
  13958. this.parseClassPropertyAnnotation(node);
  13959. if (node.optional) {
  13960. this.raise(TSErrors.AccessorCannotBeOptional, node);
  13961. }
  13962. return super.parseClassAccessorProperty(node);
  13963. }
  13964. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13965. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  13966. if (typeParameters && isConstructor) {
  13967. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  13968. }
  13969. const {
  13970. declare = false,
  13971. kind
  13972. } = method;
  13973. if (declare && (kind === "get" || kind === "set")) {
  13974. this.raise(TSErrors.DeclareAccessor, method, {
  13975. kind
  13976. });
  13977. }
  13978. if (typeParameters) method.typeParameters = typeParameters;
  13979. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  13980. }
  13981. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13982. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  13983. if (typeParameters) method.typeParameters = typeParameters;
  13984. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  13985. }
  13986. declareClassPrivateMethodInScope(node, kind) {
  13987. if (node.type === "TSDeclareMethod") return;
  13988. if (node.type === "MethodDefinition" && node.value.body == null) {
  13989. return;
  13990. }
  13991. super.declareClassPrivateMethodInScope(node, kind);
  13992. }
  13993. parseClassSuper(node) {
  13994. super.parseClassSuper(node);
  13995. if (node.superClass && (this.match(47) || this.match(51))) {
  13996. {
  13997. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  13998. }
  13999. }
  14000. if (this.eatContextual(113)) {
  14001. node.implements = this.tsParseHeritageClause("implements");
  14002. }
  14003. }
  14004. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  14005. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  14006. if (typeParameters) prop.typeParameters = typeParameters;
  14007. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  14008. }
  14009. parseFunctionParams(node, isConstructor) {
  14010. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  14011. if (typeParameters) node.typeParameters = typeParameters;
  14012. super.parseFunctionParams(node, isConstructor);
  14013. }
  14014. parseVarId(decl, kind) {
  14015. super.parseVarId(decl, kind);
  14016. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  14017. decl.definite = true;
  14018. }
  14019. const type = this.tsTryParseTypeAnnotation();
  14020. if (type) {
  14021. decl.id.typeAnnotation = type;
  14022. this.resetEndLocation(decl.id);
  14023. }
  14024. }
  14025. parseAsyncArrowFromCallExpression(node, call) {
  14026. if (this.match(14)) {
  14027. node.returnType = this.tsParseTypeAnnotation();
  14028. }
  14029. return super.parseAsyncArrowFromCallExpression(node, call);
  14030. }
  14031. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  14032. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  14033. let state;
  14034. let jsx;
  14035. let typeCast;
  14036. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  14037. state = this.state.clone();
  14038. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  14039. if (!jsx.error) return jsx.node;
  14040. const {
  14041. context
  14042. } = this.state;
  14043. const currentContext = context[context.length - 1];
  14044. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  14045. context.pop();
  14046. }
  14047. }
  14048. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  14049. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  14050. }
  14051. if (!state || state === this.state) state = this.state.clone();
  14052. let typeParameters;
  14053. const arrow = this.tryParse(abort => {
  14054. var _expr$extra, _typeParameters;
  14055. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  14056. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  14057. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  14058. abort();
  14059. }
  14060. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  14061. this.resetStartLocationFromNode(expr, typeParameters);
  14062. }
  14063. expr.typeParameters = typeParameters;
  14064. return expr;
  14065. }, state);
  14066. if (!arrow.error && !arrow.aborted) {
  14067. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  14068. return arrow.node;
  14069. }
  14070. if (!jsx) {
  14071. assert(!this.hasPlugin("jsx"));
  14072. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  14073. if (!typeCast.error) return typeCast.node;
  14074. }
  14075. if ((_jsx2 = jsx) != null && _jsx2.node) {
  14076. this.state = jsx.failState;
  14077. return jsx.node;
  14078. }
  14079. if (arrow.node) {
  14080. this.state = arrow.failState;
  14081. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  14082. return arrow.node;
  14083. }
  14084. if ((_typeCast = typeCast) != null && _typeCast.node) {
  14085. this.state = typeCast.failState;
  14086. return typeCast.node;
  14087. }
  14088. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  14089. }
  14090. reportReservedArrowTypeParam(node) {
  14091. var _node$extra2;
  14092. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  14093. this.raise(TSErrors.ReservedArrowTypeParam, node);
  14094. }
  14095. }
  14096. parseMaybeUnary(refExpressionErrors, sawUnary) {
  14097. if (!this.hasPlugin("jsx") && this.match(47)) {
  14098. return this.tsParseTypeAssertion();
  14099. }
  14100. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  14101. }
  14102. parseArrow(node) {
  14103. if (this.match(14)) {
  14104. const result = this.tryParse(abort => {
  14105. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  14106. if (this.canInsertSemicolon() || !this.match(19)) abort();
  14107. return returnType;
  14108. });
  14109. if (result.aborted) return;
  14110. if (!result.thrown) {
  14111. if (result.error) this.state = result.failState;
  14112. node.returnType = result.node;
  14113. }
  14114. }
  14115. return super.parseArrow(node);
  14116. }
  14117. parseFunctionParamType(param) {
  14118. if (this.eat(17)) {
  14119. param.optional = true;
  14120. }
  14121. const type = this.tsTryParseTypeAnnotation();
  14122. if (type) param.typeAnnotation = type;
  14123. this.resetEndLocation(param);
  14124. return param;
  14125. }
  14126. isAssignable(node, isBinding) {
  14127. switch (node.type) {
  14128. case "TSTypeCastExpression":
  14129. return this.isAssignable(node.expression, isBinding);
  14130. case "TSParameterProperty":
  14131. return true;
  14132. default:
  14133. return super.isAssignable(node, isBinding);
  14134. }
  14135. }
  14136. toAssignable(node, isLHS = false) {
  14137. switch (node.type) {
  14138. case "ParenthesizedExpression":
  14139. this.toAssignableParenthesizedExpression(node, isLHS);
  14140. break;
  14141. case "TSAsExpression":
  14142. case "TSSatisfiesExpression":
  14143. case "TSNonNullExpression":
  14144. case "TSTypeAssertion":
  14145. if (isLHS) {
  14146. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  14147. } else {
  14148. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  14149. }
  14150. this.toAssignable(node.expression, isLHS);
  14151. break;
  14152. case "AssignmentExpression":
  14153. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  14154. node.left = this.typeCastToParameter(node.left);
  14155. }
  14156. default:
  14157. super.toAssignable(node, isLHS);
  14158. }
  14159. }
  14160. toAssignableParenthesizedExpression(node, isLHS) {
  14161. switch (node.expression.type) {
  14162. case "TSAsExpression":
  14163. case "TSSatisfiesExpression":
  14164. case "TSNonNullExpression":
  14165. case "TSTypeAssertion":
  14166. case "ParenthesizedExpression":
  14167. this.toAssignable(node.expression, isLHS);
  14168. break;
  14169. default:
  14170. super.toAssignable(node, isLHS);
  14171. }
  14172. }
  14173. checkToRestConversion(node, allowPattern) {
  14174. switch (node.type) {
  14175. case "TSAsExpression":
  14176. case "TSSatisfiesExpression":
  14177. case "TSTypeAssertion":
  14178. case "TSNonNullExpression":
  14179. this.checkToRestConversion(node.expression, false);
  14180. break;
  14181. default:
  14182. super.checkToRestConversion(node, allowPattern);
  14183. }
  14184. }
  14185. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  14186. switch (type) {
  14187. case "TSTypeCastExpression":
  14188. return true;
  14189. case "TSParameterProperty":
  14190. return "parameter";
  14191. case "TSNonNullExpression":
  14192. return "expression";
  14193. case "TSAsExpression":
  14194. case "TSSatisfiesExpression":
  14195. case "TSTypeAssertion":
  14196. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  14197. default:
  14198. return super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  14199. }
  14200. }
  14201. parseBindingAtom() {
  14202. if (this.state.type === 78) {
  14203. return this.parseIdentifier(true);
  14204. }
  14205. return super.parseBindingAtom();
  14206. }
  14207. parseMaybeDecoratorArguments(expr, startLoc) {
  14208. if (this.match(47) || this.match(51)) {
  14209. const typeArguments = this.tsParseTypeArgumentsInExpression();
  14210. if (this.match(10)) {
  14211. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  14212. {
  14213. call.typeParameters = typeArguments;
  14214. }
  14215. return call;
  14216. }
  14217. this.unexpected(null, 10);
  14218. }
  14219. return super.parseMaybeDecoratorArguments(expr, startLoc);
  14220. }
  14221. checkCommaAfterRest(close) {
  14222. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  14223. this.next();
  14224. return false;
  14225. }
  14226. return super.checkCommaAfterRest(close);
  14227. }
  14228. isClassMethod() {
  14229. return this.match(47) || super.isClassMethod();
  14230. }
  14231. isClassProperty() {
  14232. return this.match(35) || this.match(14) || super.isClassProperty();
  14233. }
  14234. parseMaybeDefault(startLoc, left) {
  14235. const node = super.parseMaybeDefault(startLoc, left);
  14236. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  14237. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  14238. }
  14239. return node;
  14240. }
  14241. getTokenFromCode(code) {
  14242. if (this.state.inType) {
  14243. if (code === 62) {
  14244. this.finishOp(48, 1);
  14245. return;
  14246. }
  14247. if (code === 60) {
  14248. this.finishOp(47, 1);
  14249. return;
  14250. }
  14251. }
  14252. super.getTokenFromCode(code);
  14253. }
  14254. reScan_lt_gt() {
  14255. const {
  14256. type
  14257. } = this.state;
  14258. if (type === 47) {
  14259. this.state.pos -= 1;
  14260. this.readToken_lt();
  14261. } else if (type === 48) {
  14262. this.state.pos -= 1;
  14263. this.readToken_gt();
  14264. }
  14265. }
  14266. reScan_lt() {
  14267. const {
  14268. type
  14269. } = this.state;
  14270. if (type === 51) {
  14271. this.state.pos -= 2;
  14272. this.finishOp(47, 1);
  14273. return 47;
  14274. }
  14275. return type;
  14276. }
  14277. toAssignableListItem(exprList, index, isLHS) {
  14278. const node = exprList[index];
  14279. if (node.type === "TSTypeCastExpression") {
  14280. exprList[index] = this.typeCastToParameter(node);
  14281. }
  14282. super.toAssignableListItem(exprList, index, isLHS);
  14283. }
  14284. typeCastToParameter(node) {
  14285. node.expression.typeAnnotation = node.typeAnnotation;
  14286. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  14287. return node.expression;
  14288. }
  14289. shouldParseArrow(params) {
  14290. if (this.match(14)) {
  14291. return params.every(expr => this.isAssignable(expr, true));
  14292. }
  14293. return super.shouldParseArrow(params);
  14294. }
  14295. shouldParseAsyncArrow() {
  14296. return this.match(14) || super.shouldParseAsyncArrow();
  14297. }
  14298. canHaveLeadingDecorator() {
  14299. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  14300. }
  14301. jsxParseOpeningElementAfterName(node) {
  14302. if (this.match(47) || this.match(51)) {
  14303. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  14304. if (typeArguments) {
  14305. {
  14306. node.typeParameters = typeArguments;
  14307. }
  14308. }
  14309. }
  14310. return super.jsxParseOpeningElementAfterName(node);
  14311. }
  14312. getGetterSetterExpectedParamCount(method) {
  14313. const baseCount = super.getGetterSetterExpectedParamCount(method);
  14314. const params = this.getObjectOrClassMethodParams(method);
  14315. const firstParam = params[0];
  14316. const hasContextParam = firstParam && this.isThisParam(firstParam);
  14317. return hasContextParam ? baseCount + 1 : baseCount;
  14318. }
  14319. parseCatchClauseParam() {
  14320. const param = super.parseCatchClauseParam();
  14321. const type = this.tsTryParseTypeAnnotation();
  14322. if (type) {
  14323. param.typeAnnotation = type;
  14324. this.resetEndLocation(param);
  14325. }
  14326. return param;
  14327. }
  14328. tsInAmbientContext(cb) {
  14329. const {
  14330. isAmbientContext: oldIsAmbientContext,
  14331. strict: oldStrict
  14332. } = this.state;
  14333. this.state.isAmbientContext = true;
  14334. this.state.strict = false;
  14335. try {
  14336. return cb();
  14337. } finally {
  14338. this.state.isAmbientContext = oldIsAmbientContext;
  14339. this.state.strict = oldStrict;
  14340. }
  14341. }
  14342. parseClass(node, isStatement, optionalId) {
  14343. const oldInAbstractClass = this.state.inAbstractClass;
  14344. this.state.inAbstractClass = !!node.abstract;
  14345. try {
  14346. return super.parseClass(node, isStatement, optionalId);
  14347. } finally {
  14348. this.state.inAbstractClass = oldInAbstractClass;
  14349. }
  14350. }
  14351. tsParseAbstractDeclaration(node, decorators) {
  14352. if (this.match(80)) {
  14353. node.abstract = true;
  14354. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  14355. } else if (this.isContextual(129)) {
  14356. if (!this.hasFollowingLineBreak()) {
  14357. node.abstract = true;
  14358. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
  14359. return this.tsParseInterfaceDeclaration(node);
  14360. } else {
  14361. return null;
  14362. }
  14363. }
  14364. throw this.unexpected(null, 80);
  14365. }
  14366. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  14367. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  14368. if (method.abstract || method.type === "TSAbstractMethodDefinition") {
  14369. const hasEstreePlugin = this.hasPlugin("estree");
  14370. const methodFn = hasEstreePlugin ? method.value : method;
  14371. if (methodFn.body) {
  14372. const {
  14373. key
  14374. } = method;
  14375. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  14376. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  14377. });
  14378. }
  14379. }
  14380. return method;
  14381. }
  14382. tsParseTypeParameterName() {
  14383. const typeName = this.parseIdentifier();
  14384. return typeName.name;
  14385. }
  14386. shouldParseAsAmbientContext() {
  14387. return !!this.getPluginOption("typescript", "dts");
  14388. }
  14389. parse() {
  14390. if (this.shouldParseAsAmbientContext()) {
  14391. this.state.isAmbientContext = true;
  14392. }
  14393. return super.parse();
  14394. }
  14395. getExpression() {
  14396. if (this.shouldParseAsAmbientContext()) {
  14397. this.state.isAmbientContext = true;
  14398. }
  14399. return super.getExpression();
  14400. }
  14401. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14402. if (!isString && isMaybeTypeOnly) {
  14403. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  14404. return this.finishNode(node, "ExportSpecifier");
  14405. }
  14406. node.exportKind = "value";
  14407. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  14408. }
  14409. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14410. if (!importedIsString && isMaybeTypeOnly) {
  14411. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  14412. return this.finishNode(specifier, "ImportSpecifier");
  14413. }
  14414. specifier.importKind = "value";
  14415. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  14416. }
  14417. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  14418. const leftOfAsKey = isImport ? "imported" : "local";
  14419. const rightOfAsKey = isImport ? "local" : "exported";
  14420. let leftOfAs = node[leftOfAsKey];
  14421. let rightOfAs;
  14422. let hasTypeSpecifier = false;
  14423. let canParseAsKeyword = true;
  14424. const loc = leftOfAs.loc.start;
  14425. if (this.isContextual(93)) {
  14426. const firstAs = this.parseIdentifier();
  14427. if (this.isContextual(93)) {
  14428. const secondAs = this.parseIdentifier();
  14429. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14430. hasTypeSpecifier = true;
  14431. leftOfAs = firstAs;
  14432. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  14433. canParseAsKeyword = false;
  14434. } else {
  14435. rightOfAs = secondAs;
  14436. canParseAsKeyword = false;
  14437. }
  14438. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14439. canParseAsKeyword = false;
  14440. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  14441. } else {
  14442. hasTypeSpecifier = true;
  14443. leftOfAs = firstAs;
  14444. }
  14445. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14446. hasTypeSpecifier = true;
  14447. if (isImport) {
  14448. leftOfAs = this.parseIdentifier(true);
  14449. if (!this.isContextual(93)) {
  14450. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  14451. }
  14452. } else {
  14453. leftOfAs = this.parseModuleExportName();
  14454. }
  14455. }
  14456. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  14457. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  14458. }
  14459. node[leftOfAsKey] = leftOfAs;
  14460. node[rightOfAsKey] = rightOfAs;
  14461. const kindKey = isImport ? "importKind" : "exportKind";
  14462. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  14463. if (canParseAsKeyword && this.eatContextual(93)) {
  14464. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  14465. }
  14466. if (!node[rightOfAsKey]) {
  14467. node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
  14468. }
  14469. if (isImport) {
  14470. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  14471. }
  14472. }
  14473. fillOptionalPropertiesForTSESLint(node) {
  14474. var _node$directive, _node$decorators, _node$optional, _node$typeAnnotation, _node$accessibility, _node$decorators2, _node$override, _node$readonly, _node$static, _node$declare, _node$returnType, _node$typeParameters, _node$optional2, _node$optional3, _node$accessibility2, _node$readonly2, _node$static2, _node$declare2, _node$definite, _node$readonly3, _node$typeAnnotation2, _node$accessibility3, _node$decorators3, _node$override2, _node$optional4, _node$id, _node$abstract, _node$declare3, _node$decorators4, _node$implements, _node$superTypeArgume, _node$typeParameters2, _node$declare4, _node$definite2, _node$const, _node$declare5, _node$computed, _node$qualifier, _node$options, _node$declare6, _node$extends, _node$optional5, _node$readonly4, _node$declare7, _node$global, _node$const2, _node$in, _node$out;
  14475. switch (node.type) {
  14476. case "ExpressionStatement":
  14477. (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
  14478. return;
  14479. case "RestElement":
  14480. node.value = undefined;
  14481. case "Identifier":
  14482. case "ArrayPattern":
  14483. case "AssignmentPattern":
  14484. case "ObjectPattern":
  14485. (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
  14486. (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
  14487. (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
  14488. return;
  14489. case "TSParameterProperty":
  14490. (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
  14491. (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
  14492. (_node$override = node.override) != null ? _node$override : node.override = false;
  14493. (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
  14494. (_node$static = node.static) != null ? _node$static : node.static = false;
  14495. return;
  14496. case "TSEmptyBodyFunctionExpression":
  14497. node.body = null;
  14498. case "TSDeclareFunction":
  14499. case "FunctionDeclaration":
  14500. case "FunctionExpression":
  14501. case "ClassMethod":
  14502. case "ClassPrivateMethod":
  14503. (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
  14504. (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
  14505. (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
  14506. return;
  14507. case "Property":
  14508. (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
  14509. return;
  14510. case "TSMethodSignature":
  14511. case "TSPropertySignature":
  14512. (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
  14513. case "TSIndexSignature":
  14514. (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
  14515. (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
  14516. (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
  14517. return;
  14518. case "TSAbstractPropertyDefinition":
  14519. case "PropertyDefinition":
  14520. case "TSAbstractAccessorProperty":
  14521. case "AccessorProperty":
  14522. (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
  14523. (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
  14524. (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
  14525. (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
  14526. case "TSAbstractMethodDefinition":
  14527. case "MethodDefinition":
  14528. (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
  14529. (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
  14530. (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
  14531. (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
  14532. return;
  14533. case "ClassExpression":
  14534. (_node$id = node.id) != null ? _node$id : node.id = null;
  14535. case "ClassDeclaration":
  14536. (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
  14537. (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
  14538. (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
  14539. (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
  14540. (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
  14541. (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
  14542. return;
  14543. case "TSTypeAliasDeclaration":
  14544. case "VariableDeclaration":
  14545. (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
  14546. return;
  14547. case "VariableDeclarator":
  14548. (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
  14549. return;
  14550. case "TSEnumDeclaration":
  14551. (_node$const = node.const) != null ? _node$const : node.const = false;
  14552. (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
  14553. return;
  14554. case "TSEnumMember":
  14555. (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
  14556. return;
  14557. case "TSImportType":
  14558. (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
  14559. (_node$options = node.options) != null ? _node$options : node.options = null;
  14560. return;
  14561. case "TSInterfaceDeclaration":
  14562. (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
  14563. (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
  14564. return;
  14565. case "TSMappedType":
  14566. (_node$optional5 = node.optional) != null ? _node$optional5 : node.optional = false;
  14567. (_node$readonly4 = node.readonly) != null ? _node$readonly4 : node.readonly = undefined;
  14568. return;
  14569. case "TSModuleDeclaration":
  14570. (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
  14571. (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
  14572. return;
  14573. case "TSTypeParameter":
  14574. (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
  14575. (_node$in = node.in) != null ? _node$in : node.in = false;
  14576. (_node$out = node.out) != null ? _node$out : node.out = false;
  14577. return;
  14578. }
  14579. }
  14580. chStartsBindingIdentifierAndNotRelationalOperator(ch, pos) {
  14581. if (isIdentifierStart(ch)) {
  14582. keywordAndTSRelationalOperator.lastIndex = pos;
  14583. if (keywordAndTSRelationalOperator.test(this.input)) {
  14584. const endCh = this.codePointAtPos(keywordAndTSRelationalOperator.lastIndex);
  14585. if (!isIdentifierChar(endCh) && endCh !== 92) {
  14586. return false;
  14587. }
  14588. }
  14589. return true;
  14590. } else if (ch === 92) {
  14591. return true;
  14592. } else {
  14593. return false;
  14594. }
  14595. }
  14596. nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine() {
  14597. const next = this.nextTokenInLineStart();
  14598. const nextCh = this.codePointAtPos(next);
  14599. return this.chStartsBindingIdentifierAndNotRelationalOperator(nextCh, next);
  14600. }
  14601. nextTokenIsIdentifierOrStringLiteralOnSameLine() {
  14602. const next = this.nextTokenInLineStart();
  14603. const nextCh = this.codePointAtPos(next);
  14604. return this.chStartsBindingIdentifier(nextCh, next) || nextCh === 34 || nextCh === 39;
  14605. }
  14606. };
  14607. function isPossiblyLiteralEnum(expression) {
  14608. if (expression.type !== "MemberExpression") return false;
  14609. const {
  14610. computed,
  14611. property
  14612. } = expression;
  14613. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  14614. return false;
  14615. }
  14616. return isUncomputedMemberExpressionChain(expression.object);
  14617. }
  14618. function isValidAmbientConstInitializer(expression, estree) {
  14619. var _expression$extra;
  14620. const {
  14621. type
  14622. } = expression;
  14623. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  14624. return false;
  14625. }
  14626. if (estree) {
  14627. if (type === "Literal") {
  14628. const {
  14629. value
  14630. } = expression;
  14631. if (typeof value === "string" || typeof value === "boolean") {
  14632. return true;
  14633. }
  14634. }
  14635. } else {
  14636. if (type === "StringLiteral" || type === "BooleanLiteral") {
  14637. return true;
  14638. }
  14639. }
  14640. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  14641. return true;
  14642. }
  14643. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  14644. return true;
  14645. }
  14646. if (isPossiblyLiteralEnum(expression)) {
  14647. return true;
  14648. }
  14649. return false;
  14650. }
  14651. function isNumber(expression, estree) {
  14652. if (estree) {
  14653. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  14654. }
  14655. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  14656. }
  14657. function isNegativeNumber(expression, estree) {
  14658. if (expression.type === "UnaryExpression") {
  14659. const {
  14660. operator,
  14661. argument
  14662. } = expression;
  14663. if (operator === "-" && isNumber(argument, estree)) {
  14664. return true;
  14665. }
  14666. }
  14667. return false;
  14668. }
  14669. function isUncomputedMemberExpressionChain(expression) {
  14670. if (expression.type === "Identifier") return true;
  14671. if (expression.type !== "MemberExpression" || expression.computed) {
  14672. return false;
  14673. }
  14674. return isUncomputedMemberExpressionChain(expression.object);
  14675. }
  14676. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  14677. ClassNameIsRequired: "A class name is required.",
  14678. UnexpectedSpace: "Unexpected space in placeholder."
  14679. });
  14680. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  14681. parsePlaceholder(expectedNode) {
  14682. if (this.match(133)) {
  14683. const node = this.startNode();
  14684. this.next();
  14685. this.assertNoSpace();
  14686. node.name = super.parseIdentifier(true);
  14687. this.assertNoSpace();
  14688. this.expect(133);
  14689. return this.finishPlaceholder(node, expectedNode);
  14690. }
  14691. }
  14692. finishPlaceholder(node, expectedNode) {
  14693. let placeholder = node;
  14694. if (!placeholder.expectedNode || !placeholder.type) {
  14695. placeholder = this.finishNode(placeholder, "Placeholder");
  14696. }
  14697. placeholder.expectedNode = expectedNode;
  14698. return placeholder;
  14699. }
  14700. getTokenFromCode(code) {
  14701. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  14702. this.finishOp(133, 2);
  14703. } else {
  14704. super.getTokenFromCode(code);
  14705. }
  14706. }
  14707. parseExprAtom(refExpressionErrors) {
  14708. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  14709. }
  14710. parseIdentifier(liberal) {
  14711. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  14712. }
  14713. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  14714. if (word !== undefined) {
  14715. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  14716. }
  14717. }
  14718. cloneIdentifier(node) {
  14719. const cloned = super.cloneIdentifier(node);
  14720. if (cloned.type === "Placeholder") {
  14721. cloned.expectedNode = node.expectedNode;
  14722. }
  14723. return cloned;
  14724. }
  14725. cloneStringLiteral(node) {
  14726. if (node.type === "Placeholder") {
  14727. return this.cloneIdentifier(node);
  14728. }
  14729. return super.cloneStringLiteral(node);
  14730. }
  14731. parseBindingAtom() {
  14732. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  14733. }
  14734. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  14735. return type === "Placeholder" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  14736. }
  14737. toAssignable(node, isLHS) {
  14738. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  14739. node.expectedNode = "Pattern";
  14740. } else {
  14741. super.toAssignable(node, isLHS);
  14742. }
  14743. }
  14744. chStartsBindingIdentifier(ch, pos) {
  14745. if (super.chStartsBindingIdentifier(ch, pos)) {
  14746. return true;
  14747. }
  14748. const next = this.nextTokenStart();
  14749. if (this.input.charCodeAt(next) === 37 && this.input.charCodeAt(next + 1) === 37) {
  14750. return true;
  14751. }
  14752. return false;
  14753. }
  14754. verifyBreakContinue(node, isBreak) {
  14755. if (node.label && node.label.type === "Placeholder") return;
  14756. super.verifyBreakContinue(node, isBreak);
  14757. }
  14758. parseExpressionStatement(node, expr) {
  14759. var _expr$extra;
  14760. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  14761. return super.parseExpressionStatement(node, expr);
  14762. }
  14763. if (this.match(14)) {
  14764. const stmt = node;
  14765. stmt.label = this.finishPlaceholder(expr, "Identifier");
  14766. this.next();
  14767. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  14768. return this.finishNode(stmt, "LabeledStatement");
  14769. }
  14770. this.semicolon();
  14771. const stmtPlaceholder = node;
  14772. stmtPlaceholder.name = expr.name;
  14773. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  14774. }
  14775. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  14776. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  14777. }
  14778. parseFunctionId(requireId) {
  14779. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  14780. }
  14781. parseClass(node, isStatement, optionalId) {
  14782. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  14783. this.next();
  14784. const oldStrict = this.state.strict;
  14785. const placeholder = this.parsePlaceholder("Identifier");
  14786. if (placeholder) {
  14787. if (this.match(81) || this.match(133) || this.match(5)) {
  14788. node.id = placeholder;
  14789. } else if (optionalId || !isStatement) {
  14790. node.id = null;
  14791. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  14792. return this.finishNode(node, type);
  14793. } else {
  14794. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  14795. }
  14796. } else {
  14797. this.parseClassId(node, isStatement, optionalId);
  14798. }
  14799. super.parseClassSuper(node);
  14800. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  14801. return this.finishNode(node, type);
  14802. }
  14803. parseExport(node, decorators) {
  14804. const placeholder = this.parsePlaceholder("Identifier");
  14805. if (!placeholder) return super.parseExport(node, decorators);
  14806. const node2 = node;
  14807. if (!this.isContextual(98) && !this.match(12)) {
  14808. node2.specifiers = [];
  14809. node2.source = null;
  14810. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  14811. return this.finishNode(node2, "ExportNamedDeclaration");
  14812. }
  14813. this.expectPlugin("exportDefaultFrom");
  14814. const specifier = this.startNode();
  14815. specifier.exported = placeholder;
  14816. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  14817. return super.parseExport(node2, decorators);
  14818. }
  14819. isExportDefaultSpecifier() {
  14820. if (this.match(65)) {
  14821. const next = this.nextTokenStart();
  14822. if (this.isUnparsedContextual(next, "from")) {
  14823. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  14824. return true;
  14825. }
  14826. }
  14827. }
  14828. return super.isExportDefaultSpecifier();
  14829. }
  14830. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  14831. var _specifiers;
  14832. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  14833. return true;
  14834. }
  14835. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  14836. }
  14837. checkExport(node) {
  14838. const {
  14839. specifiers
  14840. } = node;
  14841. if (specifiers != null && specifiers.length) {
  14842. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  14843. }
  14844. super.checkExport(node);
  14845. node.specifiers = specifiers;
  14846. }
  14847. parseImport(node) {
  14848. const placeholder = this.parsePlaceholder("Identifier");
  14849. if (!placeholder) return super.parseImport(node);
  14850. node.specifiers = [];
  14851. if (!this.isContextual(98) && !this.match(12)) {
  14852. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  14853. this.semicolon();
  14854. return this.finishNode(node, "ImportDeclaration");
  14855. }
  14856. const specifier = this.startNodeAtNode(placeholder);
  14857. specifier.local = placeholder;
  14858. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  14859. if (this.eat(12)) {
  14860. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  14861. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  14862. }
  14863. this.expectContextual(98);
  14864. node.source = this.parseImportSource();
  14865. this.semicolon();
  14866. return this.finishNode(node, "ImportDeclaration");
  14867. }
  14868. parseImportSource() {
  14869. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  14870. }
  14871. assertNoSpace() {
  14872. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  14873. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  14874. }
  14875. }
  14876. };
  14877. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  14878. parseV8Intrinsic() {
  14879. if (this.match(54)) {
  14880. const v8IntrinsicStartLoc = this.state.startLoc;
  14881. const node = this.startNode();
  14882. this.next();
  14883. if (tokenIsIdentifier(this.state.type)) {
  14884. const name = this.parseIdentifierName();
  14885. const identifier = this.createIdentifier(node, name);
  14886. this.castNodeTo(identifier, "V8IntrinsicIdentifier");
  14887. if (this.match(10)) {
  14888. return identifier;
  14889. }
  14890. }
  14891. this.unexpected(v8IntrinsicStartLoc);
  14892. }
  14893. }
  14894. parseExprAtom(refExpressionErrors) {
  14895. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  14896. }
  14897. };
  14898. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  14899. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  14900. function validatePlugins(pluginsMap) {
  14901. if (pluginsMap.has("decorators")) {
  14902. if (pluginsMap.has("decorators-legacy")) {
  14903. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  14904. }
  14905. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  14906. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  14907. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  14908. }
  14909. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  14910. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  14911. throw new Error("'allowCallParenthesized' must be a boolean.");
  14912. }
  14913. }
  14914. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  14915. throw new Error("Cannot combine flow and typescript plugins.");
  14916. }
  14917. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  14918. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  14919. }
  14920. if (pluginsMap.has("pipelineOperator")) {
  14921. var _pluginsMap$get2;
  14922. const proposal = pluginsMap.get("pipelineOperator").proposal;
  14923. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  14924. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  14925. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  14926. }
  14927. if (proposal === "hack") {
  14928. if (pluginsMap.has("placeholders")) {
  14929. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  14930. }
  14931. if (pluginsMap.has("v8intrinsic")) {
  14932. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  14933. }
  14934. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  14935. if (!TOPIC_TOKENS.includes(topicToken)) {
  14936. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  14937. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  14938. }
  14939. {
  14940. var _pluginsMap$get;
  14941. if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
  14942. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  14943. }
  14944. }
  14945. } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
  14946. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  14947. }
  14948. }
  14949. if (pluginsMap.has("moduleAttributes")) {
  14950. {
  14951. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  14952. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  14953. }
  14954. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  14955. if (moduleAttributesVersionPluginOption !== "may-2020") {
  14956. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  14957. }
  14958. }
  14959. }
  14960. if (pluginsMap.has("importAssertions")) {
  14961. if (pluginsMap.has("deprecatedImportAssert")) {
  14962. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  14963. }
  14964. }
  14965. if (!pluginsMap.has("deprecatedImportAssert") && pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  14966. {
  14967. pluginsMap.set("deprecatedImportAssert", {});
  14968. }
  14969. }
  14970. if (pluginsMap.has("recordAndTuple")) {
  14971. {
  14972. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  14973. if (syntaxType != null) {
  14974. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  14975. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  14976. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  14977. }
  14978. }
  14979. }
  14980. }
  14981. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  14982. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  14983. error.missingPlugins = "doExpressions";
  14984. throw error;
  14985. }
  14986. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  14987. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  14988. }
  14989. if (pluginsMap.has("discardBinding") && pluginsMap.get("discardBinding").syntaxType !== "void") {
  14990. throw new Error("The 'discardBinding' plugin requires a 'syntaxType' option. Currently the only supported value is 'void'.");
  14991. }
  14992. }
  14993. const mixinPlugins = {
  14994. estree,
  14995. jsx,
  14996. flow,
  14997. typescript,
  14998. v8intrinsic,
  14999. placeholders
  15000. };
  15001. const mixinPluginNames = Object.keys(mixinPlugins);
  15002. class ExpressionParser extends LValParser {
  15003. checkProto(prop, isRecord, sawProto, refExpressionErrors) {
  15004. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  15005. return sawProto;
  15006. }
  15007. const key = prop.key;
  15008. const name = key.type === "Identifier" ? key.name : key.value;
  15009. if (name === "__proto__") {
  15010. if (isRecord) {
  15011. this.raise(Errors.RecordNoProto, key);
  15012. return true;
  15013. }
  15014. if (sawProto) {
  15015. if (refExpressionErrors) {
  15016. if (refExpressionErrors.doubleProtoLoc === null) {
  15017. refExpressionErrors.doubleProtoLoc = key.loc.start;
  15018. }
  15019. } else {
  15020. this.raise(Errors.DuplicateProto, key);
  15021. }
  15022. }
  15023. return true;
  15024. }
  15025. return sawProto;
  15026. }
  15027. shouldExitDescending(expr, potentialArrowAt) {
  15028. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  15029. }
  15030. getExpression() {
  15031. this.enterInitialScopes();
  15032. this.nextToken();
  15033. if (this.match(140)) {
  15034. throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
  15035. }
  15036. const expr = this.parseExpression();
  15037. if (!this.match(140)) {
  15038. throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
  15039. unexpected: this.input.codePointAt(this.state.start)
  15040. });
  15041. }
  15042. this.finalizeRemainingComments();
  15043. expr.comments = this.comments;
  15044. expr.errors = this.state.errors;
  15045. if (this.optionFlags & 256) {
  15046. expr.tokens = this.tokens;
  15047. }
  15048. return expr;
  15049. }
  15050. parseExpression(disallowIn, refExpressionErrors) {
  15051. if (disallowIn) {
  15052. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  15053. }
  15054. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  15055. }
  15056. parseExpressionBase(refExpressionErrors) {
  15057. const startLoc = this.state.startLoc;
  15058. const expr = this.parseMaybeAssign(refExpressionErrors);
  15059. if (this.match(12)) {
  15060. const node = this.startNodeAt(startLoc);
  15061. node.expressions = [expr];
  15062. while (this.eat(12)) {
  15063. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  15064. }
  15065. this.toReferencedList(node.expressions);
  15066. return this.finishNode(node, "SequenceExpression");
  15067. }
  15068. return expr;
  15069. }
  15070. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  15071. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  15072. }
  15073. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  15074. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  15075. }
  15076. setOptionalParametersError(refExpressionErrors) {
  15077. refExpressionErrors.optionalParametersLoc = this.state.startLoc;
  15078. }
  15079. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  15080. const startLoc = this.state.startLoc;
  15081. const isYield = this.isContextual(108);
  15082. if (isYield) {
  15083. if (this.prodParam.hasYield) {
  15084. this.next();
  15085. let left = this.parseYield(startLoc);
  15086. if (afterLeftParse) {
  15087. left = afterLeftParse.call(this, left, startLoc);
  15088. }
  15089. return left;
  15090. }
  15091. }
  15092. let ownExpressionErrors;
  15093. if (refExpressionErrors) {
  15094. ownExpressionErrors = false;
  15095. } else {
  15096. refExpressionErrors = new ExpressionErrors();
  15097. ownExpressionErrors = true;
  15098. }
  15099. const {
  15100. type
  15101. } = this.state;
  15102. if (type === 10 || tokenIsIdentifier(type)) {
  15103. this.state.potentialArrowAt = this.state.start;
  15104. }
  15105. let left = this.parseMaybeConditional(refExpressionErrors);
  15106. if (afterLeftParse) {
  15107. left = afterLeftParse.call(this, left, startLoc);
  15108. }
  15109. if (tokenIsAssignment(this.state.type)) {
  15110. const node = this.startNodeAt(startLoc);
  15111. const operator = this.state.value;
  15112. node.operator = operator;
  15113. if (this.match(29)) {
  15114. this.toAssignable(left, true);
  15115. node.left = left;
  15116. const startIndex = startLoc.index;
  15117. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  15118. refExpressionErrors.doubleProtoLoc = null;
  15119. }
  15120. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  15121. refExpressionErrors.shorthandAssignLoc = null;
  15122. }
  15123. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  15124. this.checkDestructuringPrivate(refExpressionErrors);
  15125. refExpressionErrors.privateKeyLoc = null;
  15126. }
  15127. if (refExpressionErrors.voidPatternLoc != null && refExpressionErrors.voidPatternLoc.index >= startIndex) {
  15128. refExpressionErrors.voidPatternLoc = null;
  15129. }
  15130. } else {
  15131. node.left = left;
  15132. }
  15133. this.next();
  15134. node.right = this.parseMaybeAssign();
  15135. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"), undefined, undefined, undefined, undefined, operator === "||=" || operator === "&&=" || operator === "??=");
  15136. return node;
  15137. } else if (ownExpressionErrors) {
  15138. this.checkExpressionErrors(refExpressionErrors, true);
  15139. }
  15140. if (isYield) {
  15141. const {
  15142. type
  15143. } = this.state;
  15144. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  15145. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  15146. this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
  15147. return this.parseYield(startLoc);
  15148. }
  15149. }
  15150. return left;
  15151. }
  15152. parseMaybeConditional(refExpressionErrors) {
  15153. const startLoc = this.state.startLoc;
  15154. const potentialArrowAt = this.state.potentialArrowAt;
  15155. const expr = this.parseExprOps(refExpressionErrors);
  15156. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  15157. return expr;
  15158. }
  15159. return this.parseConditional(expr, startLoc, refExpressionErrors);
  15160. }
  15161. parseConditional(expr, startLoc, refExpressionErrors) {
  15162. if (this.eat(17)) {
  15163. const node = this.startNodeAt(startLoc);
  15164. node.test = expr;
  15165. node.consequent = this.parseMaybeAssignAllowIn();
  15166. this.expect(14);
  15167. node.alternate = this.parseMaybeAssign();
  15168. return this.finishNode(node, "ConditionalExpression");
  15169. }
  15170. return expr;
  15171. }
  15172. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  15173. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  15174. }
  15175. parseExprOps(refExpressionErrors) {
  15176. const startLoc = this.state.startLoc;
  15177. const potentialArrowAt = this.state.potentialArrowAt;
  15178. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  15179. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  15180. return expr;
  15181. }
  15182. return this.parseExprOp(expr, startLoc, -1);
  15183. }
  15184. parseExprOp(left, leftStartLoc, minPrec) {
  15185. if (this.isPrivateName(left)) {
  15186. const value = this.getPrivateNameSV(left);
  15187. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  15188. this.raise(Errors.PrivateInExpectedIn, left, {
  15189. identifierName: value
  15190. });
  15191. }
  15192. this.classScope.usePrivateName(value, left.loc.start);
  15193. }
  15194. const op = this.state.type;
  15195. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  15196. let prec = tokenOperatorPrecedence(op);
  15197. if (prec > minPrec) {
  15198. if (op === 39) {
  15199. this.expectPlugin("pipelineOperator");
  15200. if (this.state.inFSharpPipelineDirectBody) {
  15201. return left;
  15202. }
  15203. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  15204. }
  15205. const node = this.startNodeAt(leftStartLoc);
  15206. node.left = left;
  15207. node.operator = this.state.value;
  15208. const logical = op === 41 || op === 42;
  15209. const coalesce = op === 40;
  15210. if (coalesce) {
  15211. prec = tokenOperatorPrecedence(42);
  15212. }
  15213. this.next();
  15214. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  15215. proposal: "minimal"
  15216. }])) {
  15217. if (this.state.type === 96 && this.prodParam.hasAwait) {
  15218. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  15219. }
  15220. }
  15221. node.right = this.parseExprOpRightExpr(op, prec);
  15222. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  15223. const nextOp = this.state.type;
  15224. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  15225. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  15226. }
  15227. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  15228. }
  15229. }
  15230. return left;
  15231. }
  15232. parseExprOpRightExpr(op, prec) {
  15233. const startLoc = this.state.startLoc;
  15234. switch (op) {
  15235. case 39:
  15236. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  15237. case "hack":
  15238. return this.withTopicBindingContext(() => {
  15239. return this.parseHackPipeBody();
  15240. });
  15241. case "fsharp":
  15242. return this.withSoloAwaitPermittingContext(() => {
  15243. return this.parseFSharpPipelineBody(prec);
  15244. });
  15245. }
  15246. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  15247. return this.withTopicBindingContext(() => {
  15248. if (this.prodParam.hasYield && this.isContextual(108)) {
  15249. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  15250. }
  15251. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  15252. });
  15253. }
  15254. default:
  15255. return this.parseExprOpBaseRightExpr(op, prec);
  15256. }
  15257. }
  15258. parseExprOpBaseRightExpr(op, prec) {
  15259. const startLoc = this.state.startLoc;
  15260. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  15261. }
  15262. parseHackPipeBody() {
  15263. var _body$extra;
  15264. const {
  15265. startLoc
  15266. } = this.state;
  15267. const body = this.parseMaybeAssign();
  15268. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  15269. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  15270. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  15271. type: body.type
  15272. });
  15273. }
  15274. if (!this.topicReferenceWasUsedInCurrentContext()) {
  15275. this.raise(Errors.PipeTopicUnused, startLoc);
  15276. }
  15277. return body;
  15278. }
  15279. checkExponentialAfterUnary(node) {
  15280. if (this.match(57)) {
  15281. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  15282. }
  15283. }
  15284. parseMaybeUnary(refExpressionErrors, sawUnary) {
  15285. const startLoc = this.state.startLoc;
  15286. const isAwait = this.isContextual(96);
  15287. if (isAwait && this.recordAwaitIfAllowed()) {
  15288. this.next();
  15289. const expr = this.parseAwait(startLoc);
  15290. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  15291. return expr;
  15292. }
  15293. const update = this.match(34);
  15294. const node = this.startNode();
  15295. if (tokenIsPrefix(this.state.type)) {
  15296. node.operator = this.state.value;
  15297. node.prefix = true;
  15298. if (this.match(72)) {
  15299. this.expectPlugin("throwExpressions");
  15300. }
  15301. const isDelete = this.match(89);
  15302. this.next();
  15303. node.argument = this.parseMaybeUnary(null, true);
  15304. this.checkExpressionErrors(refExpressionErrors, true);
  15305. if (this.state.strict && isDelete) {
  15306. const arg = node.argument;
  15307. if (arg.type === "Identifier") {
  15308. this.raise(Errors.StrictDelete, node);
  15309. } else if (this.hasPropertyAsPrivateName(arg)) {
  15310. this.raise(Errors.DeletePrivateField, node);
  15311. }
  15312. }
  15313. if (!update) {
  15314. if (!sawUnary) {
  15315. this.checkExponentialAfterUnary(node);
  15316. }
  15317. return this.finishNode(node, "UnaryExpression");
  15318. }
  15319. }
  15320. const expr = this.parseUpdate(node, update, refExpressionErrors);
  15321. if (isAwait) {
  15322. const {
  15323. type
  15324. } = this.state;
  15325. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  15326. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  15327. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  15328. return this.parseAwait(startLoc);
  15329. }
  15330. }
  15331. return expr;
  15332. }
  15333. parseUpdate(node, update, refExpressionErrors) {
  15334. if (update) {
  15335. const updateExpressionNode = node;
  15336. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  15337. return node;
  15338. }
  15339. const startLoc = this.state.startLoc;
  15340. let expr = this.parseExprSubscripts(refExpressionErrors);
  15341. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  15342. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  15343. const node = this.startNodeAt(startLoc);
  15344. node.operator = this.state.value;
  15345. node.prefix = false;
  15346. node.argument = expr;
  15347. this.next();
  15348. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  15349. }
  15350. return expr;
  15351. }
  15352. parseExprSubscripts(refExpressionErrors) {
  15353. const startLoc = this.state.startLoc;
  15354. const potentialArrowAt = this.state.potentialArrowAt;
  15355. const expr = this.parseExprAtom(refExpressionErrors);
  15356. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  15357. return expr;
  15358. }
  15359. return this.parseSubscripts(expr, startLoc);
  15360. }
  15361. parseSubscripts(base, startLoc, noCalls) {
  15362. const state = {
  15363. optionalChainMember: false,
  15364. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  15365. stop: false
  15366. };
  15367. do {
  15368. base = this.parseSubscript(base, startLoc, noCalls, state);
  15369. state.maybeAsyncArrow = false;
  15370. } while (!state.stop);
  15371. return base;
  15372. }
  15373. parseSubscript(base, startLoc, noCalls, state) {
  15374. const {
  15375. type
  15376. } = this.state;
  15377. if (!noCalls && type === 15) {
  15378. return this.parseBind(base, startLoc, noCalls, state);
  15379. } else if (tokenIsTemplate(type)) {
  15380. return this.parseTaggedTemplateExpression(base, startLoc, state);
  15381. }
  15382. let optional = false;
  15383. if (type === 18) {
  15384. if (noCalls) {
  15385. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  15386. if (this.lookaheadCharCode() === 40) {
  15387. return this.stopParseSubscript(base, state);
  15388. }
  15389. }
  15390. state.optionalChainMember = optional = true;
  15391. this.next();
  15392. }
  15393. if (!noCalls && this.match(10)) {
  15394. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  15395. } else {
  15396. const computed = this.eat(0);
  15397. if (computed || optional || this.eat(16)) {
  15398. return this.parseMember(base, startLoc, state, computed, optional);
  15399. } else {
  15400. return this.stopParseSubscript(base, state);
  15401. }
  15402. }
  15403. }
  15404. stopParseSubscript(base, state) {
  15405. state.stop = true;
  15406. return base;
  15407. }
  15408. parseMember(base, startLoc, state, computed, optional) {
  15409. const node = this.startNodeAt(startLoc);
  15410. node.object = base;
  15411. node.computed = computed;
  15412. if (computed) {
  15413. node.property = this.parseExpression();
  15414. this.expect(3);
  15415. } else if (this.match(139)) {
  15416. if (base.type === "Super") {
  15417. this.raise(Errors.SuperPrivateField, startLoc);
  15418. }
  15419. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  15420. node.property = this.parsePrivateName();
  15421. } else {
  15422. node.property = this.parseIdentifier(true);
  15423. }
  15424. if (state.optionalChainMember) {
  15425. node.optional = optional;
  15426. return this.finishNode(node, "OptionalMemberExpression");
  15427. } else {
  15428. return this.finishNode(node, "MemberExpression");
  15429. }
  15430. }
  15431. parseBind(base, startLoc, noCalls, state) {
  15432. const node = this.startNodeAt(startLoc);
  15433. node.object = base;
  15434. this.next();
  15435. node.callee = this.parseNoCallExpr();
  15436. state.stop = true;
  15437. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  15438. }
  15439. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  15440. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  15441. let refExpressionErrors = null;
  15442. this.state.maybeInArrowParameters = true;
  15443. this.next();
  15444. const node = this.startNodeAt(startLoc);
  15445. node.callee = base;
  15446. const {
  15447. maybeAsyncArrow,
  15448. optionalChainMember
  15449. } = state;
  15450. if (maybeAsyncArrow) {
  15451. this.expressionScope.enter(newAsyncArrowScope());
  15452. refExpressionErrors = new ExpressionErrors();
  15453. }
  15454. if (optionalChainMember) {
  15455. node.optional = optional;
  15456. }
  15457. if (optional) {
  15458. node.arguments = this.parseCallExpressionArguments();
  15459. } else {
  15460. node.arguments = this.parseCallExpressionArguments(base.type !== "Super", node, refExpressionErrors);
  15461. }
  15462. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  15463. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  15464. state.stop = true;
  15465. this.checkDestructuringPrivate(refExpressionErrors);
  15466. this.expressionScope.validateAsPattern();
  15467. this.expressionScope.exit();
  15468. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  15469. } else {
  15470. if (maybeAsyncArrow) {
  15471. this.checkExpressionErrors(refExpressionErrors, true);
  15472. this.expressionScope.exit();
  15473. }
  15474. this.toReferencedArguments(finishedNode);
  15475. }
  15476. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  15477. return finishedNode;
  15478. }
  15479. toReferencedArguments(node, isParenthesizedExpr) {
  15480. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  15481. }
  15482. parseTaggedTemplateExpression(base, startLoc, state) {
  15483. const node = this.startNodeAt(startLoc);
  15484. node.tag = base;
  15485. node.quasi = this.parseTemplate(true);
  15486. if (state.optionalChainMember) {
  15487. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  15488. }
  15489. return this.finishNode(node, "TaggedTemplateExpression");
  15490. }
  15491. atPossibleAsyncArrow(base) {
  15492. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && this.offsetToSourcePos(base.start) === this.state.potentialArrowAt;
  15493. }
  15494. finishCallExpression(node, optional) {
  15495. if (node.callee.type === "Import") {
  15496. if (node.arguments.length === 0 || node.arguments.length > 2) {
  15497. this.raise(Errors.ImportCallArity, node);
  15498. } else {
  15499. for (const arg of node.arguments) {
  15500. if (arg.type === "SpreadElement") {
  15501. this.raise(Errors.ImportCallSpreadArgument, arg);
  15502. }
  15503. }
  15504. }
  15505. }
  15506. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  15507. }
  15508. parseCallExpressionArguments(allowPlaceholder, nodeForExtra, refExpressionErrors) {
  15509. const elts = [];
  15510. let first = true;
  15511. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  15512. this.state.inFSharpPipelineDirectBody = false;
  15513. while (!this.eat(11)) {
  15514. if (first) {
  15515. first = false;
  15516. } else {
  15517. this.expect(12);
  15518. if (this.match(11)) {
  15519. if (nodeForExtra) {
  15520. this.addTrailingCommaExtraToNode(nodeForExtra);
  15521. }
  15522. this.next();
  15523. break;
  15524. }
  15525. }
  15526. elts.push(this.parseExprListItem(11, false, refExpressionErrors, allowPlaceholder));
  15527. }
  15528. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  15529. return elts;
  15530. }
  15531. shouldParseAsyncArrow() {
  15532. return this.match(19) && !this.canInsertSemicolon();
  15533. }
  15534. parseAsyncArrowFromCallExpression(node, call) {
  15535. var _call$extra;
  15536. this.resetPreviousNodeTrailingComments(call);
  15537. this.expect(19);
  15538. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  15539. if (call.innerComments) {
  15540. setInnerComments(node, call.innerComments);
  15541. }
  15542. if (call.callee.trailingComments) {
  15543. setInnerComments(node, call.callee.trailingComments);
  15544. }
  15545. return node;
  15546. }
  15547. parseNoCallExpr() {
  15548. const startLoc = this.state.startLoc;
  15549. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  15550. }
  15551. parseExprAtom(refExpressionErrors) {
  15552. let node;
  15553. let decorators = null;
  15554. const {
  15555. type
  15556. } = this.state;
  15557. switch (type) {
  15558. case 79:
  15559. return this.parseSuper();
  15560. case 83:
  15561. node = this.startNode();
  15562. this.next();
  15563. if (this.match(16)) {
  15564. return this.parseImportMetaPropertyOrPhaseCall(node);
  15565. }
  15566. if (this.match(10)) {
  15567. if (this.optionFlags & 512) {
  15568. return this.parseImportCall(node);
  15569. } else {
  15570. return this.finishNode(node, "Import");
  15571. }
  15572. } else {
  15573. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  15574. return this.finishNode(node, "Import");
  15575. }
  15576. case 78:
  15577. node = this.startNode();
  15578. this.next();
  15579. return this.finishNode(node, "ThisExpression");
  15580. case 90:
  15581. {
  15582. return this.parseDo(this.startNode(), false);
  15583. }
  15584. case 56:
  15585. case 31:
  15586. {
  15587. this.readRegexp();
  15588. return this.parseRegExpLiteral(this.state.value);
  15589. }
  15590. case 135:
  15591. return this.parseNumericLiteral(this.state.value);
  15592. case 136:
  15593. return this.parseBigIntLiteral(this.state.value);
  15594. case 134:
  15595. return this.parseStringLiteral(this.state.value);
  15596. case 84:
  15597. return this.parseNullLiteral();
  15598. case 85:
  15599. return this.parseBooleanLiteral(true);
  15600. case 86:
  15601. return this.parseBooleanLiteral(false);
  15602. case 10:
  15603. {
  15604. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  15605. return this.parseParenAndDistinguishExpression(canBeArrow);
  15606. }
  15607. case 0:
  15608. {
  15609. return this.parseArrayLike(3, false, refExpressionErrors);
  15610. }
  15611. case 5:
  15612. {
  15613. return this.parseObjectLike(8, false, false, refExpressionErrors);
  15614. }
  15615. case 68:
  15616. return this.parseFunctionOrFunctionSent();
  15617. case 26:
  15618. decorators = this.parseDecorators();
  15619. case 80:
  15620. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  15621. case 77:
  15622. return this.parseNewOrNewTarget();
  15623. case 25:
  15624. case 24:
  15625. return this.parseTemplate(false);
  15626. case 15:
  15627. {
  15628. node = this.startNode();
  15629. this.next();
  15630. node.object = null;
  15631. const callee = node.callee = this.parseNoCallExpr();
  15632. if (callee.type === "MemberExpression") {
  15633. return this.finishNode(node, "BindExpression");
  15634. } else {
  15635. throw this.raise(Errors.UnsupportedBind, callee);
  15636. }
  15637. }
  15638. case 139:
  15639. {
  15640. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  15641. identifierName: this.state.value
  15642. });
  15643. return this.parsePrivateName();
  15644. }
  15645. case 33:
  15646. {
  15647. return this.parseTopicReferenceThenEqualsSign(54, "%");
  15648. }
  15649. case 32:
  15650. {
  15651. return this.parseTopicReferenceThenEqualsSign(44, "^");
  15652. }
  15653. case 37:
  15654. case 38:
  15655. {
  15656. return this.parseTopicReference("hack");
  15657. }
  15658. case 44:
  15659. case 54:
  15660. case 27:
  15661. {
  15662. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  15663. if (pipeProposal) {
  15664. return this.parseTopicReference(pipeProposal);
  15665. }
  15666. throw this.unexpected();
  15667. }
  15668. case 47:
  15669. {
  15670. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  15671. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  15672. throw this.expectOnePlugin(["jsx", "flow", "typescript"]);
  15673. }
  15674. throw this.unexpected();
  15675. }
  15676. default:
  15677. {
  15678. if (type === 137) {
  15679. return this.parseDecimalLiteral(this.state.value);
  15680. } else if (type === 2 || type === 1) {
  15681. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, true);
  15682. } else if (type === 6 || type === 7) {
  15683. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  15684. }
  15685. }
  15686. if (tokenIsIdentifier(type)) {
  15687. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  15688. return this.parseModuleExpression();
  15689. }
  15690. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  15691. const containsEsc = this.state.containsEsc;
  15692. const id = this.parseIdentifier();
  15693. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  15694. const {
  15695. type
  15696. } = this.state;
  15697. if (type === 68) {
  15698. this.resetPreviousNodeTrailingComments(id);
  15699. this.next();
  15700. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  15701. } else if (tokenIsIdentifier(type)) {
  15702. if (this.lookaheadCharCode() === 61) {
  15703. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  15704. } else {
  15705. return id;
  15706. }
  15707. } else if (type === 90) {
  15708. this.resetPreviousNodeTrailingComments(id);
  15709. return this.parseDo(this.startNodeAtNode(id), true);
  15710. }
  15711. }
  15712. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  15713. this.next();
  15714. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  15715. }
  15716. return id;
  15717. } else {
  15718. throw this.unexpected();
  15719. }
  15720. }
  15721. }
  15722. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  15723. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  15724. if (pipeProposal) {
  15725. this.state.type = topicTokenType;
  15726. this.state.value = topicTokenValue;
  15727. this.state.pos--;
  15728. this.state.end--;
  15729. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  15730. return this.parseTopicReference(pipeProposal);
  15731. }
  15732. throw this.unexpected();
  15733. }
  15734. parseTopicReference(pipeProposal) {
  15735. const node = this.startNode();
  15736. const startLoc = this.state.startLoc;
  15737. const tokenType = this.state.type;
  15738. this.next();
  15739. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  15740. }
  15741. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  15742. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  15743. if (pipeProposal === "hack") {
  15744. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  15745. this.raise(Errors.PipeTopicUnbound, startLoc);
  15746. }
  15747. this.registerTopicReference();
  15748. return this.finishNode(node, "TopicReference");
  15749. } else {
  15750. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  15751. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  15752. }
  15753. this.registerTopicReference();
  15754. return this.finishNode(node, "PipelinePrimaryTopicReference");
  15755. }
  15756. } else {
  15757. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  15758. token: tokenLabelName(tokenType)
  15759. });
  15760. }
  15761. }
  15762. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  15763. switch (pipeProposal) {
  15764. case "hack":
  15765. {
  15766. return this.hasPlugin(["pipelineOperator", {
  15767. topicToken: tokenLabelName(tokenType)
  15768. }]);
  15769. }
  15770. case "smart":
  15771. return tokenType === 27;
  15772. default:
  15773. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  15774. }
  15775. }
  15776. parseAsyncArrowUnaryFunction(node) {
  15777. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  15778. const params = [this.parseIdentifier()];
  15779. this.prodParam.exit();
  15780. if (this.hasPrecedingLineBreak()) {
  15781. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  15782. }
  15783. this.expect(19);
  15784. return this.parseArrowExpression(node, params, true);
  15785. }
  15786. parseDo(node, isAsync) {
  15787. this.expectPlugin("doExpressions");
  15788. if (isAsync) {
  15789. this.expectPlugin("asyncDoExpressions");
  15790. }
  15791. node.async = isAsync;
  15792. this.next();
  15793. const oldLabels = this.state.labels;
  15794. this.state.labels = [];
  15795. if (isAsync) {
  15796. this.prodParam.enter(2);
  15797. node.body = this.parseBlock();
  15798. this.prodParam.exit();
  15799. } else {
  15800. node.body = this.parseBlock();
  15801. }
  15802. this.state.labels = oldLabels;
  15803. return this.finishNode(node, "DoExpression");
  15804. }
  15805. parseSuper() {
  15806. const node = this.startNode();
  15807. this.next();
  15808. if (this.match(10) && !this.scope.allowDirectSuper) {
  15809. {
  15810. if (!(this.optionFlags & 16)) {
  15811. this.raise(Errors.SuperNotAllowed, node);
  15812. }
  15813. }
  15814. } else if (!this.scope.allowSuper) {
  15815. {
  15816. if (!(this.optionFlags & 16)) {
  15817. this.raise(Errors.UnexpectedSuper, node);
  15818. }
  15819. }
  15820. }
  15821. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  15822. this.raise(Errors.UnsupportedSuper, node);
  15823. }
  15824. return this.finishNode(node, "Super");
  15825. }
  15826. parsePrivateName() {
  15827. const node = this.startNode();
  15828. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  15829. const name = this.state.value;
  15830. this.next();
  15831. node.id = this.createIdentifier(id, name);
  15832. return this.finishNode(node, "PrivateName");
  15833. }
  15834. parseFunctionOrFunctionSent() {
  15835. const node = this.startNode();
  15836. this.next();
  15837. if (this.prodParam.hasYield && this.match(16)) {
  15838. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  15839. this.next();
  15840. if (this.match(103)) {
  15841. this.expectPlugin("functionSent");
  15842. } else if (!this.hasPlugin("functionSent")) {
  15843. this.unexpected();
  15844. }
  15845. return this.parseMetaProperty(node, meta, "sent");
  15846. }
  15847. return this.parseFunction(node);
  15848. }
  15849. parseMetaProperty(node, meta, propertyName) {
  15850. node.meta = meta;
  15851. const containsEsc = this.state.containsEsc;
  15852. node.property = this.parseIdentifier(true);
  15853. if (node.property.name !== propertyName || containsEsc) {
  15854. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  15855. target: meta.name,
  15856. onlyValidPropertyName: propertyName
  15857. });
  15858. }
  15859. return this.finishNode(node, "MetaProperty");
  15860. }
  15861. parseImportMetaPropertyOrPhaseCall(node) {
  15862. this.next();
  15863. if (this.isContextual(105) || this.isContextual(97)) {
  15864. const isSource = this.isContextual(105);
  15865. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  15866. this.next();
  15867. node.phase = isSource ? "source" : "defer";
  15868. return this.parseImportCall(node);
  15869. } else {
  15870. const id = this.createIdentifierAt(this.startNodeAtNode(node), "import", this.state.lastTokStartLoc);
  15871. if (this.isContextual(101)) {
  15872. if (!this.inModule) {
  15873. this.raise(Errors.ImportMetaOutsideModule, id);
  15874. }
  15875. this.sawUnambiguousESM = true;
  15876. }
  15877. return this.parseMetaProperty(node, id, "meta");
  15878. }
  15879. }
  15880. parseLiteralAtNode(value, type, node) {
  15881. this.addExtra(node, "rawValue", value);
  15882. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  15883. node.value = value;
  15884. this.next();
  15885. return this.finishNode(node, type);
  15886. }
  15887. parseLiteral(value, type) {
  15888. const node = this.startNode();
  15889. return this.parseLiteralAtNode(value, type, node);
  15890. }
  15891. parseStringLiteral(value) {
  15892. return this.parseLiteral(value, "StringLiteral");
  15893. }
  15894. parseNumericLiteral(value) {
  15895. return this.parseLiteral(value, "NumericLiteral");
  15896. }
  15897. parseBigIntLiteral(value) {
  15898. {
  15899. return this.parseLiteral(value, "BigIntLiteral");
  15900. }
  15901. }
  15902. parseDecimalLiteral(value) {
  15903. return this.parseLiteral(value, "DecimalLiteral");
  15904. }
  15905. parseRegExpLiteral(value) {
  15906. const node = this.startNode();
  15907. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  15908. node.pattern = value.pattern;
  15909. node.flags = value.flags;
  15910. this.next();
  15911. return this.finishNode(node, "RegExpLiteral");
  15912. }
  15913. parseBooleanLiteral(value) {
  15914. const node = this.startNode();
  15915. node.value = value;
  15916. this.next();
  15917. return this.finishNode(node, "BooleanLiteral");
  15918. }
  15919. parseNullLiteral() {
  15920. const node = this.startNode();
  15921. this.next();
  15922. return this.finishNode(node, "NullLiteral");
  15923. }
  15924. parseParenAndDistinguishExpression(canBeArrow) {
  15925. const startLoc = this.state.startLoc;
  15926. let val;
  15927. this.next();
  15928. this.expressionScope.enter(newArrowHeadScope());
  15929. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  15930. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  15931. this.state.maybeInArrowParameters = true;
  15932. this.state.inFSharpPipelineDirectBody = false;
  15933. const innerStartLoc = this.state.startLoc;
  15934. const exprList = [];
  15935. const refExpressionErrors = new ExpressionErrors();
  15936. let first = true;
  15937. let spreadStartLoc;
  15938. let optionalCommaStartLoc;
  15939. while (!this.match(11)) {
  15940. if (first) {
  15941. first = false;
  15942. } else {
  15943. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  15944. if (this.match(11)) {
  15945. optionalCommaStartLoc = this.state.startLoc;
  15946. break;
  15947. }
  15948. }
  15949. if (this.match(21)) {
  15950. const spreadNodeStartLoc = this.state.startLoc;
  15951. spreadStartLoc = this.state.startLoc;
  15952. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  15953. if (!this.checkCommaAfterRest(41)) {
  15954. break;
  15955. }
  15956. } else {
  15957. exprList.push(this.parseMaybeAssignAllowInOrVoidPattern(11, refExpressionErrors, this.parseParenItem));
  15958. }
  15959. }
  15960. const innerEndLoc = this.state.lastTokEndLoc;
  15961. this.expect(11);
  15962. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  15963. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  15964. let arrowNode = this.startNodeAt(startLoc);
  15965. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  15966. this.checkDestructuringPrivate(refExpressionErrors);
  15967. this.expressionScope.validateAsPattern();
  15968. this.expressionScope.exit();
  15969. this.parseArrowExpression(arrowNode, exprList, false);
  15970. return arrowNode;
  15971. }
  15972. this.expressionScope.exit();
  15973. if (!exprList.length) {
  15974. this.unexpected(this.state.lastTokStartLoc);
  15975. }
  15976. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  15977. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  15978. this.checkExpressionErrors(refExpressionErrors, true);
  15979. this.toReferencedListDeep(exprList, true);
  15980. if (exprList.length > 1) {
  15981. val = this.startNodeAt(innerStartLoc);
  15982. val.expressions = exprList;
  15983. this.finishNode(val, "SequenceExpression");
  15984. this.resetEndLocation(val, innerEndLoc);
  15985. } else {
  15986. val = exprList[0];
  15987. }
  15988. return this.wrapParenthesis(startLoc, val);
  15989. }
  15990. wrapParenthesis(startLoc, expression) {
  15991. if (!(this.optionFlags & 1024)) {
  15992. this.addExtra(expression, "parenthesized", true);
  15993. this.addExtra(expression, "parenStart", startLoc.index);
  15994. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  15995. return expression;
  15996. }
  15997. const parenExpression = this.startNodeAt(startLoc);
  15998. parenExpression.expression = expression;
  15999. return this.finishNode(parenExpression, "ParenthesizedExpression");
  16000. }
  16001. shouldParseArrow(params) {
  16002. return !this.canInsertSemicolon();
  16003. }
  16004. parseArrow(node) {
  16005. if (this.eat(19)) {
  16006. return node;
  16007. }
  16008. }
  16009. parseParenItem(node, startLoc) {
  16010. return node;
  16011. }
  16012. parseNewOrNewTarget() {
  16013. const node = this.startNode();
  16014. this.next();
  16015. if (this.match(16)) {
  16016. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  16017. this.next();
  16018. const metaProp = this.parseMetaProperty(node, meta, "target");
  16019. if (!this.scope.allowNewTarget) {
  16020. this.raise(Errors.UnexpectedNewTarget, metaProp);
  16021. }
  16022. return metaProp;
  16023. }
  16024. return this.parseNew(node);
  16025. }
  16026. parseNew(node) {
  16027. this.parseNewCallee(node);
  16028. if (this.eat(10)) {
  16029. const args = this.parseExprList(11);
  16030. this.toReferencedList(args);
  16031. node.arguments = args;
  16032. } else {
  16033. node.arguments = [];
  16034. }
  16035. return this.finishNode(node, "NewExpression");
  16036. }
  16037. parseNewCallee(node) {
  16038. const isImport = this.match(83);
  16039. const callee = this.parseNoCallExpr();
  16040. node.callee = callee;
  16041. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  16042. this.raise(Errors.ImportCallNotNewExpression, callee);
  16043. }
  16044. }
  16045. parseTemplateElement(isTagged) {
  16046. const {
  16047. start,
  16048. startLoc,
  16049. end,
  16050. value
  16051. } = this.state;
  16052. const elemStart = start + 1;
  16053. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  16054. if (value === null) {
  16055. if (!isTagged) {
  16056. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  16057. }
  16058. }
  16059. const isTail = this.match(24);
  16060. const endOffset = isTail ? -1 : -2;
  16061. const elemEnd = end + endOffset;
  16062. elem.value = {
  16063. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  16064. cooked: value === null ? null : value.slice(1, endOffset)
  16065. };
  16066. elem.tail = isTail;
  16067. this.next();
  16068. const finishedNode = this.finishNode(elem, "TemplateElement");
  16069. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  16070. return finishedNode;
  16071. }
  16072. parseTemplate(isTagged) {
  16073. const node = this.startNode();
  16074. let curElt = this.parseTemplateElement(isTagged);
  16075. const quasis = [curElt];
  16076. const substitutions = [];
  16077. while (!curElt.tail) {
  16078. substitutions.push(this.parseTemplateSubstitution());
  16079. this.readTemplateContinuation();
  16080. quasis.push(curElt = this.parseTemplateElement(isTagged));
  16081. }
  16082. node.expressions = substitutions;
  16083. node.quasis = quasis;
  16084. return this.finishNode(node, "TemplateLiteral");
  16085. }
  16086. parseTemplateSubstitution() {
  16087. return this.parseExpression();
  16088. }
  16089. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  16090. if (isRecord) {
  16091. this.expectPlugin("recordAndTuple");
  16092. }
  16093. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  16094. this.state.inFSharpPipelineDirectBody = false;
  16095. let sawProto = false;
  16096. let first = true;
  16097. const node = this.startNode();
  16098. node.properties = [];
  16099. this.next();
  16100. while (!this.match(close)) {
  16101. if (first) {
  16102. first = false;
  16103. } else {
  16104. this.expect(12);
  16105. if (this.match(close)) {
  16106. this.addTrailingCommaExtraToNode(node);
  16107. break;
  16108. }
  16109. }
  16110. let prop;
  16111. if (isPattern) {
  16112. prop = this.parseBindingProperty();
  16113. } else {
  16114. prop = this.parsePropertyDefinition(refExpressionErrors);
  16115. sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
  16116. }
  16117. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  16118. this.raise(Errors.InvalidRecordProperty, prop);
  16119. }
  16120. {
  16121. if (prop.shorthand) {
  16122. this.addExtra(prop, "shorthand", true);
  16123. }
  16124. }
  16125. node.properties.push(prop);
  16126. }
  16127. this.next();
  16128. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  16129. let type = "ObjectExpression";
  16130. if (isPattern) {
  16131. type = "ObjectPattern";
  16132. } else if (isRecord) {
  16133. type = "RecordExpression";
  16134. }
  16135. return this.finishNode(node, type);
  16136. }
  16137. addTrailingCommaExtraToNode(node) {
  16138. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  16139. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  16140. }
  16141. maybeAsyncOrAccessorProp(prop) {
  16142. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  16143. }
  16144. parsePropertyDefinition(refExpressionErrors) {
  16145. let decorators = [];
  16146. if (this.match(26)) {
  16147. if (this.hasPlugin("decorators")) {
  16148. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  16149. }
  16150. while (this.match(26)) {
  16151. decorators.push(this.parseDecorator());
  16152. }
  16153. }
  16154. const prop = this.startNode();
  16155. let isAsync = false;
  16156. let isAccessor = false;
  16157. let startLoc;
  16158. if (this.match(21)) {
  16159. if (decorators.length) this.unexpected();
  16160. return this.parseSpread();
  16161. }
  16162. if (decorators.length) {
  16163. prop.decorators = decorators;
  16164. decorators = [];
  16165. }
  16166. prop.method = false;
  16167. if (refExpressionErrors) {
  16168. startLoc = this.state.startLoc;
  16169. }
  16170. let isGenerator = this.eat(55);
  16171. this.parsePropertyNamePrefixOperator(prop);
  16172. const containsEsc = this.state.containsEsc;
  16173. this.parsePropertyName(prop, refExpressionErrors);
  16174. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  16175. const {
  16176. key
  16177. } = prop;
  16178. const keyName = key.name;
  16179. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  16180. isAsync = true;
  16181. this.resetPreviousNodeTrailingComments(key);
  16182. isGenerator = this.eat(55);
  16183. this.parsePropertyName(prop);
  16184. }
  16185. if (keyName === "get" || keyName === "set") {
  16186. isAccessor = true;
  16187. this.resetPreviousNodeTrailingComments(key);
  16188. prop.kind = keyName;
  16189. if (this.match(55)) {
  16190. isGenerator = true;
  16191. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  16192. kind: keyName
  16193. });
  16194. this.next();
  16195. }
  16196. this.parsePropertyName(prop);
  16197. }
  16198. }
  16199. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  16200. }
  16201. getGetterSetterExpectedParamCount(method) {
  16202. return method.kind === "get" ? 0 : 1;
  16203. }
  16204. getObjectOrClassMethodParams(method) {
  16205. return method.params;
  16206. }
  16207. checkGetterSetterParams(method) {
  16208. var _params;
  16209. const paramCount = this.getGetterSetterExpectedParamCount(method);
  16210. const params = this.getObjectOrClassMethodParams(method);
  16211. if (params.length !== paramCount) {
  16212. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  16213. }
  16214. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  16215. this.raise(Errors.BadSetterRestParameter, method);
  16216. }
  16217. }
  16218. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  16219. if (isAccessor) {
  16220. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  16221. this.checkGetterSetterParams(finishedProp);
  16222. return finishedProp;
  16223. }
  16224. if (isAsync || isGenerator || this.match(10)) {
  16225. if (isPattern) this.unexpected();
  16226. prop.kind = "method";
  16227. prop.method = true;
  16228. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  16229. }
  16230. }
  16231. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  16232. prop.shorthand = false;
  16233. if (this.eat(14)) {
  16234. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowInOrVoidPattern(8, refExpressionErrors);
  16235. return this.finishObjectProperty(prop);
  16236. }
  16237. if (!prop.computed && prop.key.type === "Identifier") {
  16238. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  16239. if (isPattern) {
  16240. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  16241. } else if (this.match(29)) {
  16242. const shorthandAssignLoc = this.state.startLoc;
  16243. if (refExpressionErrors != null) {
  16244. if (refExpressionErrors.shorthandAssignLoc === null) {
  16245. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  16246. }
  16247. } else {
  16248. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  16249. }
  16250. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  16251. } else {
  16252. prop.value = this.cloneIdentifier(prop.key);
  16253. }
  16254. prop.shorthand = true;
  16255. return this.finishObjectProperty(prop);
  16256. }
  16257. }
  16258. finishObjectProperty(node) {
  16259. return this.finishNode(node, "ObjectProperty");
  16260. }
  16261. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  16262. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  16263. if (!node) this.unexpected();
  16264. return node;
  16265. }
  16266. parsePropertyName(prop, refExpressionErrors) {
  16267. if (this.eat(0)) {
  16268. prop.computed = true;
  16269. prop.key = this.parseMaybeAssignAllowIn();
  16270. this.expect(3);
  16271. } else {
  16272. const {
  16273. type,
  16274. value
  16275. } = this.state;
  16276. let key;
  16277. if (tokenIsKeywordOrIdentifier(type)) {
  16278. key = this.parseIdentifier(true);
  16279. } else {
  16280. switch (type) {
  16281. case 135:
  16282. key = this.parseNumericLiteral(value);
  16283. break;
  16284. case 134:
  16285. key = this.parseStringLiteral(value);
  16286. break;
  16287. case 136:
  16288. key = this.parseBigIntLiteral(value);
  16289. break;
  16290. case 139:
  16291. {
  16292. const privateKeyLoc = this.state.startLoc;
  16293. if (refExpressionErrors != null) {
  16294. if (refExpressionErrors.privateKeyLoc === null) {
  16295. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  16296. }
  16297. } else {
  16298. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  16299. }
  16300. key = this.parsePrivateName();
  16301. break;
  16302. }
  16303. default:
  16304. if (type === 137) {
  16305. key = this.parseDecimalLiteral(value);
  16306. break;
  16307. }
  16308. this.unexpected();
  16309. }
  16310. }
  16311. prop.key = key;
  16312. if (type !== 139) {
  16313. prop.computed = false;
  16314. }
  16315. }
  16316. }
  16317. initFunction(node, isAsync) {
  16318. node.id = null;
  16319. node.generator = false;
  16320. node.async = isAsync;
  16321. }
  16322. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  16323. this.initFunction(node, isAsync);
  16324. node.generator = isGenerator;
  16325. this.scope.enter(514 | 16 | (inClassScope ? 576 : 0) | (allowDirectSuper ? 32 : 0));
  16326. this.prodParam.enter(functionFlags(isAsync, node.generator));
  16327. this.parseFunctionParams(node, isConstructor);
  16328. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  16329. this.prodParam.exit();
  16330. this.scope.exit();
  16331. return finishedNode;
  16332. }
  16333. parseArrayLike(close, isTuple, refExpressionErrors) {
  16334. if (isTuple) {
  16335. this.expectPlugin("recordAndTuple");
  16336. }
  16337. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  16338. this.state.inFSharpPipelineDirectBody = false;
  16339. const node = this.startNode();
  16340. this.next();
  16341. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  16342. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  16343. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  16344. }
  16345. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  16346. this.scope.enter(514 | 4);
  16347. let flags = functionFlags(isAsync, false);
  16348. if (!this.match(5) && this.prodParam.hasIn) {
  16349. flags |= 8;
  16350. }
  16351. this.prodParam.enter(flags);
  16352. this.initFunction(node, isAsync);
  16353. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  16354. if (params) {
  16355. this.state.maybeInArrowParameters = true;
  16356. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  16357. }
  16358. this.state.maybeInArrowParameters = false;
  16359. this.parseFunctionBody(node, true);
  16360. this.prodParam.exit();
  16361. this.scope.exit();
  16362. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  16363. return this.finishNode(node, "ArrowFunctionExpression");
  16364. }
  16365. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  16366. this.toAssignableList(params, trailingCommaLoc, false);
  16367. node.params = params;
  16368. }
  16369. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  16370. this.parseFunctionBody(node, false, isMethod);
  16371. return this.finishNode(node, type);
  16372. }
  16373. parseFunctionBody(node, allowExpression, isMethod = false) {
  16374. const isExpression = allowExpression && !this.match(5);
  16375. this.expressionScope.enter(newExpressionScope());
  16376. if (isExpression) {
  16377. node.body = this.parseMaybeAssign();
  16378. this.checkParams(node, false, allowExpression, false);
  16379. } else {
  16380. const oldStrict = this.state.strict;
  16381. const oldLabels = this.state.labels;
  16382. this.state.labels = [];
  16383. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  16384. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  16385. const nonSimple = !this.isSimpleParamList(node.params);
  16386. if (hasStrictModeDirective && nonSimple) {
  16387. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  16388. }
  16389. const strictModeChanged = !oldStrict && this.state.strict;
  16390. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  16391. if (this.state.strict && node.id) {
  16392. this.checkIdentifier(node.id, 65, strictModeChanged);
  16393. }
  16394. });
  16395. this.prodParam.exit();
  16396. this.state.labels = oldLabels;
  16397. }
  16398. this.expressionScope.exit();
  16399. }
  16400. isSimpleParameter(node) {
  16401. return node.type === "Identifier";
  16402. }
  16403. isSimpleParamList(params) {
  16404. for (let i = 0, len = params.length; i < len; i++) {
  16405. if (!this.isSimpleParameter(params[i])) return false;
  16406. }
  16407. return true;
  16408. }
  16409. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  16410. const checkClashes = !allowDuplicates && new Set();
  16411. const formalParameters = {
  16412. type: "FormalParameters"
  16413. };
  16414. for (const param of node.params) {
  16415. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  16416. }
  16417. }
  16418. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  16419. const elts = [];
  16420. let first = true;
  16421. while (!this.eat(close)) {
  16422. if (first) {
  16423. first = false;
  16424. } else {
  16425. this.expect(12);
  16426. if (this.match(close)) {
  16427. if (nodeForExtra) {
  16428. this.addTrailingCommaExtraToNode(nodeForExtra);
  16429. }
  16430. this.next();
  16431. break;
  16432. }
  16433. }
  16434. elts.push(this.parseExprListItem(close, allowEmpty, refExpressionErrors));
  16435. }
  16436. return elts;
  16437. }
  16438. parseExprListItem(close, allowEmpty, refExpressionErrors, allowPlaceholder) {
  16439. let elt;
  16440. if (this.match(12)) {
  16441. if (!allowEmpty) {
  16442. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  16443. unexpected: ","
  16444. });
  16445. }
  16446. elt = null;
  16447. } else if (this.match(21)) {
  16448. const spreadNodeStartLoc = this.state.startLoc;
  16449. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  16450. } else if (this.match(17)) {
  16451. this.expectPlugin("partialApplication");
  16452. if (!allowPlaceholder) {
  16453. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  16454. }
  16455. const node = this.startNode();
  16456. this.next();
  16457. elt = this.finishNode(node, "ArgumentPlaceholder");
  16458. } else {
  16459. elt = this.parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, this.parseParenItem);
  16460. }
  16461. return elt;
  16462. }
  16463. parseIdentifier(liberal) {
  16464. const node = this.startNode();
  16465. const name = this.parseIdentifierName(liberal);
  16466. return this.createIdentifier(node, name);
  16467. }
  16468. createIdentifier(node, name) {
  16469. node.name = name;
  16470. node.loc.identifierName = name;
  16471. return this.finishNode(node, "Identifier");
  16472. }
  16473. createIdentifierAt(node, name, endLoc) {
  16474. node.name = name;
  16475. node.loc.identifierName = name;
  16476. return this.finishNodeAt(node, "Identifier", endLoc);
  16477. }
  16478. parseIdentifierName(liberal) {
  16479. let name;
  16480. const {
  16481. startLoc,
  16482. type
  16483. } = this.state;
  16484. if (tokenIsKeywordOrIdentifier(type)) {
  16485. name = this.state.value;
  16486. } else {
  16487. this.unexpected();
  16488. }
  16489. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  16490. if (liberal) {
  16491. if (tokenIsKeyword) {
  16492. this.replaceToken(132);
  16493. }
  16494. } else {
  16495. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  16496. }
  16497. this.next();
  16498. return name;
  16499. }
  16500. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  16501. if (word.length > 10) {
  16502. return;
  16503. }
  16504. if (!canBeReservedWord(word)) {
  16505. return;
  16506. }
  16507. if (checkKeywords && isKeyword(word)) {
  16508. this.raise(Errors.UnexpectedKeyword, startLoc, {
  16509. keyword: word
  16510. });
  16511. return;
  16512. }
  16513. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  16514. if (reservedTest(word, this.inModule)) {
  16515. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  16516. reservedWord: word
  16517. });
  16518. return;
  16519. } else if (word === "yield") {
  16520. if (this.prodParam.hasYield) {
  16521. this.raise(Errors.YieldBindingIdentifier, startLoc);
  16522. return;
  16523. }
  16524. } else if (word === "await") {
  16525. if (this.prodParam.hasAwait) {
  16526. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  16527. return;
  16528. }
  16529. if (this.scope.inStaticBlock) {
  16530. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  16531. return;
  16532. }
  16533. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  16534. } else if (word === "arguments") {
  16535. if (this.scope.inClassAndNotInNonArrowFunction) {
  16536. this.raise(Errors.ArgumentsInClass, startLoc);
  16537. return;
  16538. }
  16539. }
  16540. }
  16541. recordAwaitIfAllowed() {
  16542. const isAwaitAllowed = this.prodParam.hasAwait;
  16543. if (isAwaitAllowed && !this.scope.inFunction) {
  16544. this.state.hasTopLevelAwait = true;
  16545. }
  16546. return isAwaitAllowed;
  16547. }
  16548. parseAwait(startLoc) {
  16549. const node = this.startNodeAt(startLoc);
  16550. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  16551. if (this.eat(55)) {
  16552. this.raise(Errors.ObsoleteAwaitStar, node);
  16553. }
  16554. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  16555. if (this.isAmbiguousPrefixOrIdentifier()) {
  16556. this.ambiguousScriptDifferentAst = true;
  16557. } else {
  16558. this.sawUnambiguousESM = true;
  16559. }
  16560. }
  16561. if (!this.state.soloAwait) {
  16562. node.argument = this.parseMaybeUnary(null, true);
  16563. }
  16564. return this.finishNode(node, "AwaitExpression");
  16565. }
  16566. isAmbiguousPrefixOrIdentifier() {
  16567. if (this.hasPrecedingLineBreak()) return true;
  16568. const {
  16569. type
  16570. } = this.state;
  16571. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  16572. }
  16573. parseYield(startLoc) {
  16574. const node = this.startNodeAt(startLoc);
  16575. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  16576. let delegating = false;
  16577. let argument = null;
  16578. if (!this.hasPrecedingLineBreak()) {
  16579. delegating = this.eat(55);
  16580. switch (this.state.type) {
  16581. case 13:
  16582. case 140:
  16583. case 8:
  16584. case 11:
  16585. case 3:
  16586. case 9:
  16587. case 14:
  16588. case 12:
  16589. if (!delegating) break;
  16590. default:
  16591. argument = this.parseMaybeAssign();
  16592. }
  16593. }
  16594. node.delegate = delegating;
  16595. node.argument = argument;
  16596. return this.finishNode(node, "YieldExpression");
  16597. }
  16598. parseImportCall(node) {
  16599. this.next();
  16600. node.source = this.parseMaybeAssignAllowIn();
  16601. node.options = null;
  16602. if (this.eat(12)) {
  16603. if (!this.match(11)) {
  16604. node.options = this.parseMaybeAssignAllowIn();
  16605. if (this.eat(12)) {
  16606. this.addTrailingCommaExtraToNode(node.options);
  16607. if (!this.match(11)) {
  16608. do {
  16609. this.parseMaybeAssignAllowIn();
  16610. } while (this.eat(12) && !this.match(11));
  16611. this.raise(Errors.ImportCallArity, node);
  16612. }
  16613. }
  16614. } else {
  16615. this.addTrailingCommaExtraToNode(node.source);
  16616. }
  16617. }
  16618. this.expect(11);
  16619. return this.finishNode(node, "ImportExpression");
  16620. }
  16621. checkPipelineAtInfixOperator(left, leftStartLoc) {
  16622. if (this.hasPlugin(["pipelineOperator", {
  16623. proposal: "smart"
  16624. }])) {
  16625. if (left.type === "SequenceExpression") {
  16626. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  16627. }
  16628. }
  16629. }
  16630. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  16631. if (this.isSimpleReference(childExpr)) {
  16632. const bodyNode = this.startNodeAt(startLoc);
  16633. bodyNode.callee = childExpr;
  16634. return this.finishNode(bodyNode, "PipelineBareFunction");
  16635. } else {
  16636. const bodyNode = this.startNodeAt(startLoc);
  16637. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  16638. bodyNode.expression = childExpr;
  16639. return this.finishNode(bodyNode, "PipelineTopicExpression");
  16640. }
  16641. }
  16642. isSimpleReference(expression) {
  16643. switch (expression.type) {
  16644. case "MemberExpression":
  16645. return !expression.computed && this.isSimpleReference(expression.object);
  16646. case "Identifier":
  16647. return true;
  16648. default:
  16649. return false;
  16650. }
  16651. }
  16652. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  16653. if (this.match(19)) {
  16654. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  16655. }
  16656. if (!this.topicReferenceWasUsedInCurrentContext()) {
  16657. this.raise(Errors.PipelineTopicUnused, startLoc);
  16658. }
  16659. }
  16660. withTopicBindingContext(callback) {
  16661. const outerContextTopicState = this.state.topicContext;
  16662. this.state.topicContext = {
  16663. maxNumOfResolvableTopics: 1,
  16664. maxTopicIndex: null
  16665. };
  16666. try {
  16667. return callback();
  16668. } finally {
  16669. this.state.topicContext = outerContextTopicState;
  16670. }
  16671. }
  16672. withSmartMixTopicForbiddingContext(callback) {
  16673. if (this.hasPlugin(["pipelineOperator", {
  16674. proposal: "smart"
  16675. }])) {
  16676. const outerContextTopicState = this.state.topicContext;
  16677. this.state.topicContext = {
  16678. maxNumOfResolvableTopics: 0,
  16679. maxTopicIndex: null
  16680. };
  16681. try {
  16682. return callback();
  16683. } finally {
  16684. this.state.topicContext = outerContextTopicState;
  16685. }
  16686. } else {
  16687. return callback();
  16688. }
  16689. }
  16690. withSoloAwaitPermittingContext(callback) {
  16691. const outerContextSoloAwaitState = this.state.soloAwait;
  16692. this.state.soloAwait = true;
  16693. try {
  16694. return callback();
  16695. } finally {
  16696. this.state.soloAwait = outerContextSoloAwaitState;
  16697. }
  16698. }
  16699. allowInAnd(callback) {
  16700. const flags = this.prodParam.currentFlags();
  16701. const prodParamToSet = 8 & ~flags;
  16702. if (prodParamToSet) {
  16703. this.prodParam.enter(flags | 8);
  16704. try {
  16705. return callback();
  16706. } finally {
  16707. this.prodParam.exit();
  16708. }
  16709. }
  16710. return callback();
  16711. }
  16712. disallowInAnd(callback) {
  16713. const flags = this.prodParam.currentFlags();
  16714. const prodParamToClear = 8 & flags;
  16715. if (prodParamToClear) {
  16716. this.prodParam.enter(flags & -9);
  16717. try {
  16718. return callback();
  16719. } finally {
  16720. this.prodParam.exit();
  16721. }
  16722. }
  16723. return callback();
  16724. }
  16725. registerTopicReference() {
  16726. this.state.topicContext.maxTopicIndex = 0;
  16727. }
  16728. topicReferenceIsAllowedInCurrentContext() {
  16729. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  16730. }
  16731. topicReferenceWasUsedInCurrentContext() {
  16732. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  16733. }
  16734. parseFSharpPipelineBody(prec) {
  16735. const startLoc = this.state.startLoc;
  16736. this.state.potentialArrowAt = this.state.start;
  16737. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  16738. this.state.inFSharpPipelineDirectBody = true;
  16739. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  16740. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  16741. return ret;
  16742. }
  16743. parseModuleExpression() {
  16744. this.expectPlugin("moduleBlocks");
  16745. const node = this.startNode();
  16746. this.next();
  16747. if (!this.match(5)) {
  16748. this.unexpected(null, 5);
  16749. }
  16750. const program = this.startNodeAt(this.state.endLoc);
  16751. this.next();
  16752. const revertScopes = this.initializeScopes(true);
  16753. this.enterInitialScopes();
  16754. try {
  16755. node.body = this.parseProgram(program, 8, "module");
  16756. } finally {
  16757. revertScopes();
  16758. }
  16759. return this.finishNode(node, "ModuleExpression");
  16760. }
  16761. parseVoidPattern(refExpressionErrors) {
  16762. this.expectPlugin("discardBinding");
  16763. const node = this.startNode();
  16764. if (refExpressionErrors != null) {
  16765. refExpressionErrors.voidPatternLoc = this.state.startLoc;
  16766. }
  16767. this.next();
  16768. return this.finishNode(node, "VoidPattern");
  16769. }
  16770. parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, afterLeftParse) {
  16771. if (refExpressionErrors != null && this.match(88)) {
  16772. const nextCode = this.lookaheadCharCode();
  16773. if (nextCode === 44 || nextCode === (close === 3 ? 93 : close === 8 ? 125 : 41) || nextCode === 61) {
  16774. return this.parseMaybeDefault(this.state.startLoc, this.parseVoidPattern(refExpressionErrors));
  16775. }
  16776. }
  16777. return this.parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse);
  16778. }
  16779. parsePropertyNamePrefixOperator(prop) {}
  16780. }
  16781. const loopLabel = {
  16782. kind: 1
  16783. },
  16784. switchLabel = {
  16785. kind: 2
  16786. };
  16787. const loneSurrogate = /[\uD800-\uDFFF]/u;
  16788. const keywordRelationalOperator = /in(?:stanceof)?/y;
  16789. function babel7CompatTokens(tokens, input, startIndex) {
  16790. for (let i = 0; i < tokens.length; i++) {
  16791. const token = tokens[i];
  16792. const {
  16793. type
  16794. } = token;
  16795. if (typeof type === "number") {
  16796. {
  16797. if (type === 139) {
  16798. const {
  16799. loc,
  16800. start,
  16801. value,
  16802. end
  16803. } = token;
  16804. const hashEndPos = start + 1;
  16805. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  16806. tokens.splice(i, 1, new Token({
  16807. type: getExportedToken(27),
  16808. value: "#",
  16809. start: start,
  16810. end: hashEndPos,
  16811. startLoc: loc.start,
  16812. endLoc: hashEndLoc
  16813. }), new Token({
  16814. type: getExportedToken(132),
  16815. value: value,
  16816. start: hashEndPos,
  16817. end: end,
  16818. startLoc: hashEndLoc,
  16819. endLoc: loc.end
  16820. }));
  16821. i++;
  16822. continue;
  16823. }
  16824. if (tokenIsTemplate(type)) {
  16825. const {
  16826. loc,
  16827. start,
  16828. value,
  16829. end
  16830. } = token;
  16831. const backquoteEnd = start + 1;
  16832. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  16833. let startToken;
  16834. if (input.charCodeAt(start - startIndex) === 96) {
  16835. startToken = new Token({
  16836. type: getExportedToken(22),
  16837. value: "`",
  16838. start: start,
  16839. end: backquoteEnd,
  16840. startLoc: loc.start,
  16841. endLoc: backquoteEndLoc
  16842. });
  16843. } else {
  16844. startToken = new Token({
  16845. type: getExportedToken(8),
  16846. value: "}",
  16847. start: start,
  16848. end: backquoteEnd,
  16849. startLoc: loc.start,
  16850. endLoc: backquoteEndLoc
  16851. });
  16852. }
  16853. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  16854. if (type === 24) {
  16855. templateElementEnd = end - 1;
  16856. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  16857. templateValue = value === null ? null : value.slice(1, -1);
  16858. endToken = new Token({
  16859. type: getExportedToken(22),
  16860. value: "`",
  16861. start: templateElementEnd,
  16862. end: end,
  16863. startLoc: templateElementEndLoc,
  16864. endLoc: loc.end
  16865. });
  16866. } else {
  16867. templateElementEnd = end - 2;
  16868. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  16869. templateValue = value === null ? null : value.slice(1, -2);
  16870. endToken = new Token({
  16871. type: getExportedToken(23),
  16872. value: "${",
  16873. start: templateElementEnd,
  16874. end: end,
  16875. startLoc: templateElementEndLoc,
  16876. endLoc: loc.end
  16877. });
  16878. }
  16879. tokens.splice(i, 1, startToken, new Token({
  16880. type: getExportedToken(20),
  16881. value: templateValue,
  16882. start: backquoteEnd,
  16883. end: templateElementEnd,
  16884. startLoc: backquoteEndLoc,
  16885. endLoc: templateElementEndLoc
  16886. }), endToken);
  16887. i += 2;
  16888. continue;
  16889. }
  16890. }
  16891. token.type = getExportedToken(type);
  16892. }
  16893. }
  16894. return tokens;
  16895. }
  16896. class StatementParser extends ExpressionParser {
  16897. parseTopLevel(file, program) {
  16898. file.program = this.parseProgram(program, 140, this.options.sourceType === "module" ? "module" : "script");
  16899. file.comments = this.comments;
  16900. if (this.optionFlags & 256) {
  16901. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  16902. }
  16903. return this.finishNode(file, "File");
  16904. }
  16905. parseProgram(program, end, sourceType) {
  16906. program.sourceType = sourceType;
  16907. program.interpreter = this.parseInterpreterDirective();
  16908. this.parseBlockBody(program, true, true, end);
  16909. if (this.inModule) {
  16910. if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
  16911. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  16912. this.raise(Errors.ModuleExportUndefined, at, {
  16913. localName
  16914. });
  16915. }
  16916. }
  16917. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  16918. }
  16919. let finishedProgram;
  16920. if (end === 140) {
  16921. finishedProgram = this.finishNode(program, "Program");
  16922. } else {
  16923. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  16924. }
  16925. return finishedProgram;
  16926. }
  16927. stmtToDirective(stmt) {
  16928. const directive = this.castNodeTo(stmt, "Directive");
  16929. const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
  16930. const expressionValue = directiveLiteral.value;
  16931. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  16932. const val = directiveLiteral.value = raw.slice(1, -1);
  16933. this.addExtra(directiveLiteral, "raw", raw);
  16934. this.addExtra(directiveLiteral, "rawValue", val);
  16935. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  16936. directive.value = directiveLiteral;
  16937. delete stmt.expression;
  16938. return directive;
  16939. }
  16940. parseInterpreterDirective() {
  16941. if (!this.match(28)) {
  16942. return null;
  16943. }
  16944. const node = this.startNode();
  16945. node.value = this.state.value;
  16946. this.next();
  16947. return this.finishNode(node, "InterpreterDirective");
  16948. }
  16949. isLet() {
  16950. if (!this.isContextual(100)) {
  16951. return false;
  16952. }
  16953. return this.hasFollowingBindingAtom();
  16954. }
  16955. isUsing() {
  16956. if (!this.isContextual(107)) {
  16957. return false;
  16958. }
  16959. return this.nextTokenIsIdentifierOnSameLine();
  16960. }
  16961. isForUsing() {
  16962. if (!this.isContextual(107)) {
  16963. return false;
  16964. }
  16965. const next = this.nextTokenInLineStart();
  16966. const nextCh = this.codePointAtPos(next);
  16967. if (this.isUnparsedContextual(next, "of")) {
  16968. const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
  16969. if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
  16970. return false;
  16971. }
  16972. }
  16973. if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
  16974. return true;
  16975. }
  16976. return false;
  16977. }
  16978. nextTokenIsIdentifierOnSameLine() {
  16979. const next = this.nextTokenInLineStart();
  16980. const nextCh = this.codePointAtPos(next);
  16981. return this.chStartsBindingIdentifier(nextCh, next);
  16982. }
  16983. isAwaitUsing() {
  16984. if (!this.isContextual(96)) {
  16985. return false;
  16986. }
  16987. let next = this.nextTokenInLineStart();
  16988. if (this.isUnparsedContextual(next, "using")) {
  16989. next = this.nextTokenInLineStartSince(next + 5);
  16990. const nextCh = this.codePointAtPos(next);
  16991. if (this.chStartsBindingIdentifier(nextCh, next)) {
  16992. return true;
  16993. }
  16994. }
  16995. return false;
  16996. }
  16997. chStartsBindingIdentifier(ch, pos) {
  16998. if (isIdentifierStart(ch)) {
  16999. keywordRelationalOperator.lastIndex = pos;
  17000. if (keywordRelationalOperator.test(this.input)) {
  17001. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  17002. if (!isIdentifierChar(endCh) && endCh !== 92) {
  17003. return false;
  17004. }
  17005. }
  17006. return true;
  17007. } else if (ch === 92) {
  17008. return true;
  17009. } else {
  17010. return false;
  17011. }
  17012. }
  17013. chStartsBindingPattern(ch) {
  17014. return ch === 91 || ch === 123;
  17015. }
  17016. hasFollowingBindingAtom() {
  17017. const next = this.nextTokenStart();
  17018. const nextCh = this.codePointAtPos(next);
  17019. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  17020. }
  17021. hasInLineFollowingBindingIdentifierOrBrace() {
  17022. const next = this.nextTokenInLineStart();
  17023. const nextCh = this.codePointAtPos(next);
  17024. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  17025. }
  17026. allowsUsing() {
  17027. return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
  17028. }
  17029. parseModuleItem() {
  17030. return this.parseStatementLike(1 | 2 | 4 | 8);
  17031. }
  17032. parseStatementListItem() {
  17033. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  17034. }
  17035. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  17036. let flags = 0;
  17037. if (this.options.annexB && !this.state.strict) {
  17038. flags |= 4;
  17039. if (allowLabeledFunction) {
  17040. flags |= 8;
  17041. }
  17042. }
  17043. return this.parseStatementLike(flags);
  17044. }
  17045. parseStatement() {
  17046. return this.parseStatementLike(0);
  17047. }
  17048. parseStatementLike(flags) {
  17049. let decorators = null;
  17050. if (this.match(26)) {
  17051. decorators = this.parseDecorators(true);
  17052. }
  17053. return this.parseStatementContent(flags, decorators);
  17054. }
  17055. parseStatementContent(flags, decorators) {
  17056. const startType = this.state.type;
  17057. const node = this.startNode();
  17058. const allowDeclaration = !!(flags & 2);
  17059. const allowFunctionDeclaration = !!(flags & 4);
  17060. const topLevel = flags & 1;
  17061. switch (startType) {
  17062. case 60:
  17063. return this.parseBreakContinueStatement(node, true);
  17064. case 63:
  17065. return this.parseBreakContinueStatement(node, false);
  17066. case 64:
  17067. return this.parseDebuggerStatement(node);
  17068. case 90:
  17069. return this.parseDoWhileStatement(node);
  17070. case 91:
  17071. return this.parseForStatement(node);
  17072. case 68:
  17073. if (this.lookaheadCharCode() === 46) break;
  17074. if (!allowFunctionDeclaration) {
  17075. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  17076. }
  17077. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  17078. case 80:
  17079. if (!allowDeclaration) this.unexpected();
  17080. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  17081. case 69:
  17082. return this.parseIfStatement(node);
  17083. case 70:
  17084. return this.parseReturnStatement(node);
  17085. case 71:
  17086. return this.parseSwitchStatement(node);
  17087. case 72:
  17088. return this.parseThrowStatement(node);
  17089. case 73:
  17090. return this.parseTryStatement(node);
  17091. case 96:
  17092. if (this.isAwaitUsing()) {
  17093. if (!this.allowsUsing()) {
  17094. this.raise(Errors.UnexpectedUsingDeclaration, node);
  17095. } else if (!allowDeclaration) {
  17096. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  17097. } else if (!this.recordAwaitIfAllowed()) {
  17098. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  17099. }
  17100. this.next();
  17101. return this.parseVarStatement(node, "await using");
  17102. }
  17103. break;
  17104. case 107:
  17105. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  17106. break;
  17107. }
  17108. if (!this.allowsUsing()) {
  17109. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  17110. } else if (!allowDeclaration) {
  17111. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  17112. }
  17113. return this.parseVarStatement(node, "using");
  17114. case 100:
  17115. {
  17116. if (this.state.containsEsc) {
  17117. break;
  17118. }
  17119. const next = this.nextTokenStart();
  17120. const nextCh = this.codePointAtPos(next);
  17121. if (nextCh !== 91) {
  17122. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  17123. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  17124. break;
  17125. }
  17126. }
  17127. }
  17128. case 75:
  17129. {
  17130. if (!allowDeclaration) {
  17131. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  17132. }
  17133. }
  17134. case 74:
  17135. {
  17136. const kind = this.state.value;
  17137. return this.parseVarStatement(node, kind);
  17138. }
  17139. case 92:
  17140. return this.parseWhileStatement(node);
  17141. case 76:
  17142. return this.parseWithStatement(node);
  17143. case 5:
  17144. return this.parseBlock();
  17145. case 13:
  17146. return this.parseEmptyStatement(node);
  17147. case 83:
  17148. {
  17149. const nextTokenCharCode = this.lookaheadCharCode();
  17150. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  17151. break;
  17152. }
  17153. }
  17154. case 82:
  17155. {
  17156. if (!(this.optionFlags & 8) && !topLevel) {
  17157. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  17158. }
  17159. this.next();
  17160. let result;
  17161. if (startType === 83) {
  17162. result = this.parseImport(node);
  17163. } else {
  17164. result = this.parseExport(node, decorators);
  17165. }
  17166. this.assertModuleNodeAllowed(result);
  17167. return result;
  17168. }
  17169. default:
  17170. {
  17171. if (this.isAsyncFunction()) {
  17172. if (!allowDeclaration) {
  17173. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  17174. }
  17175. this.next();
  17176. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  17177. }
  17178. }
  17179. }
  17180. const maybeName = this.state.value;
  17181. const expr = this.parseExpression();
  17182. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  17183. return this.parseLabeledStatement(node, maybeName, expr, flags);
  17184. } else {
  17185. return this.parseExpressionStatement(node, expr, decorators);
  17186. }
  17187. }
  17188. assertModuleNodeAllowed(node) {
  17189. if (!(this.optionFlags & 8) && !this.inModule) {
  17190. this.raise(Errors.ImportOutsideModule, node);
  17191. }
  17192. }
  17193. decoratorsEnabledBeforeExport() {
  17194. if (this.hasPlugin("decorators-legacy")) return true;
  17195. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  17196. }
  17197. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  17198. if (maybeDecorators) {
  17199. var _classNode$decorators;
  17200. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  17201. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  17202. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  17203. }
  17204. classNode.decorators.unshift(...maybeDecorators);
  17205. } else {
  17206. classNode.decorators = maybeDecorators;
  17207. }
  17208. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  17209. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  17210. }
  17211. return classNode;
  17212. }
  17213. canHaveLeadingDecorator() {
  17214. return this.match(80);
  17215. }
  17216. parseDecorators(allowExport) {
  17217. const decorators = [];
  17218. do {
  17219. decorators.push(this.parseDecorator());
  17220. } while (this.match(26));
  17221. if (this.match(82)) {
  17222. if (!allowExport) {
  17223. this.unexpected();
  17224. }
  17225. if (!this.decoratorsEnabledBeforeExport()) {
  17226. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  17227. }
  17228. } else if (!this.canHaveLeadingDecorator()) {
  17229. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  17230. }
  17231. return decorators;
  17232. }
  17233. parseDecorator() {
  17234. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  17235. const node = this.startNode();
  17236. this.next();
  17237. if (this.hasPlugin("decorators")) {
  17238. const startLoc = this.state.startLoc;
  17239. let expr;
  17240. if (this.match(10)) {
  17241. const startLoc = this.state.startLoc;
  17242. this.next();
  17243. expr = this.parseExpression();
  17244. this.expect(11);
  17245. expr = this.wrapParenthesis(startLoc, expr);
  17246. const paramsStartLoc = this.state.startLoc;
  17247. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  17248. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  17249. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  17250. }
  17251. } else {
  17252. expr = this.parseIdentifier(false);
  17253. while (this.eat(16)) {
  17254. const node = this.startNodeAt(startLoc);
  17255. node.object = expr;
  17256. if (this.match(139)) {
  17257. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  17258. node.property = this.parsePrivateName();
  17259. } else {
  17260. node.property = this.parseIdentifier(true);
  17261. }
  17262. node.computed = false;
  17263. expr = this.finishNode(node, "MemberExpression");
  17264. }
  17265. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  17266. }
  17267. } else {
  17268. node.expression = this.parseExprSubscripts();
  17269. }
  17270. return this.finishNode(node, "Decorator");
  17271. }
  17272. parseMaybeDecoratorArguments(expr, startLoc) {
  17273. if (this.eat(10)) {
  17274. const node = this.startNodeAt(startLoc);
  17275. node.callee = expr;
  17276. node.arguments = this.parseCallExpressionArguments();
  17277. this.toReferencedList(node.arguments);
  17278. return this.finishNode(node, "CallExpression");
  17279. }
  17280. return expr;
  17281. }
  17282. parseBreakContinueStatement(node, isBreak) {
  17283. this.next();
  17284. if (this.isLineTerminator()) {
  17285. node.label = null;
  17286. } else {
  17287. node.label = this.parseIdentifier();
  17288. this.semicolon();
  17289. }
  17290. this.verifyBreakContinue(node, isBreak);
  17291. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  17292. }
  17293. verifyBreakContinue(node, isBreak) {
  17294. let i;
  17295. for (i = 0; i < this.state.labels.length; ++i) {
  17296. const lab = this.state.labels[i];
  17297. if (node.label == null || lab.name === node.label.name) {
  17298. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  17299. break;
  17300. }
  17301. if (node.label && isBreak) break;
  17302. }
  17303. }
  17304. if (i === this.state.labels.length) {
  17305. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  17306. this.raise(Errors.IllegalBreakContinue, node, {
  17307. type
  17308. });
  17309. }
  17310. }
  17311. parseDebuggerStatement(node) {
  17312. this.next();
  17313. this.semicolon();
  17314. return this.finishNode(node, "DebuggerStatement");
  17315. }
  17316. parseHeaderExpression() {
  17317. this.expect(10);
  17318. const val = this.parseExpression();
  17319. this.expect(11);
  17320. return val;
  17321. }
  17322. parseDoWhileStatement(node) {
  17323. this.next();
  17324. this.state.labels.push(loopLabel);
  17325. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  17326. this.state.labels.pop();
  17327. this.expect(92);
  17328. node.test = this.parseHeaderExpression();
  17329. this.eat(13);
  17330. return this.finishNode(node, "DoWhileStatement");
  17331. }
  17332. parseForStatement(node) {
  17333. this.next();
  17334. this.state.labels.push(loopLabel);
  17335. let awaitAt = null;
  17336. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  17337. awaitAt = this.state.startLoc;
  17338. this.next();
  17339. }
  17340. this.scope.enter(0);
  17341. this.expect(10);
  17342. if (this.match(13)) {
  17343. if (awaitAt !== null) {
  17344. this.unexpected(awaitAt);
  17345. }
  17346. return this.parseFor(node, null);
  17347. }
  17348. const startsWithLet = this.isContextual(100);
  17349. {
  17350. const startsWithAwaitUsing = this.isAwaitUsing();
  17351. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
  17352. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  17353. if (this.match(74) || this.match(75) || isLetOrUsing) {
  17354. const initNode = this.startNode();
  17355. let kind;
  17356. if (startsWithAwaitUsing) {
  17357. kind = "await using";
  17358. if (!this.recordAwaitIfAllowed()) {
  17359. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  17360. }
  17361. this.next();
  17362. } else {
  17363. kind = this.state.value;
  17364. }
  17365. this.next();
  17366. this.parseVar(initNode, true, kind);
  17367. const init = this.finishNode(initNode, "VariableDeclaration");
  17368. const isForIn = this.match(58);
  17369. if (isForIn && starsWithUsingDeclaration) {
  17370. this.raise(Errors.ForInUsing, init);
  17371. }
  17372. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  17373. return this.parseForIn(node, init, awaitAt);
  17374. }
  17375. if (awaitAt !== null) {
  17376. this.unexpected(awaitAt);
  17377. }
  17378. return this.parseFor(node, init);
  17379. }
  17380. }
  17381. const startsWithAsync = this.isContextual(95);
  17382. const refExpressionErrors = new ExpressionErrors();
  17383. const init = this.parseExpression(true, refExpressionErrors);
  17384. const isForOf = this.isContextual(102);
  17385. if (isForOf) {
  17386. if (startsWithLet) {
  17387. this.raise(Errors.ForOfLet, init);
  17388. }
  17389. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  17390. this.raise(Errors.ForOfAsync, init);
  17391. }
  17392. }
  17393. if (isForOf || this.match(58)) {
  17394. this.checkDestructuringPrivate(refExpressionErrors);
  17395. this.toAssignable(init, true);
  17396. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  17397. this.checkLVal(init, {
  17398. type
  17399. });
  17400. return this.parseForIn(node, init, awaitAt);
  17401. } else {
  17402. this.checkExpressionErrors(refExpressionErrors, true);
  17403. }
  17404. if (awaitAt !== null) {
  17405. this.unexpected(awaitAt);
  17406. }
  17407. return this.parseFor(node, init);
  17408. }
  17409. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  17410. this.next();
  17411. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  17412. }
  17413. parseIfStatement(node) {
  17414. this.next();
  17415. node.test = this.parseHeaderExpression();
  17416. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  17417. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  17418. return this.finishNode(node, "IfStatement");
  17419. }
  17420. parseReturnStatement(node) {
  17421. if (!this.prodParam.hasReturn) {
  17422. this.raise(Errors.IllegalReturn, this.state.startLoc);
  17423. }
  17424. this.next();
  17425. if (this.isLineTerminator()) {
  17426. node.argument = null;
  17427. } else {
  17428. node.argument = this.parseExpression();
  17429. this.semicolon();
  17430. }
  17431. return this.finishNode(node, "ReturnStatement");
  17432. }
  17433. parseSwitchStatement(node) {
  17434. this.next();
  17435. node.discriminant = this.parseHeaderExpression();
  17436. const cases = node.cases = [];
  17437. this.expect(5);
  17438. this.state.labels.push(switchLabel);
  17439. this.scope.enter(256);
  17440. let cur;
  17441. for (let sawDefault; !this.match(8);) {
  17442. if (this.match(61) || this.match(65)) {
  17443. const isCase = this.match(61);
  17444. if (cur) this.finishNode(cur, "SwitchCase");
  17445. cases.push(cur = this.startNode());
  17446. cur.consequent = [];
  17447. this.next();
  17448. if (isCase) {
  17449. cur.test = this.parseExpression();
  17450. } else {
  17451. if (sawDefault) {
  17452. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  17453. }
  17454. sawDefault = true;
  17455. cur.test = null;
  17456. }
  17457. this.expect(14);
  17458. } else {
  17459. if (cur) {
  17460. cur.consequent.push(this.parseStatementListItem());
  17461. } else {
  17462. this.unexpected();
  17463. }
  17464. }
  17465. }
  17466. this.scope.exit();
  17467. if (cur) this.finishNode(cur, "SwitchCase");
  17468. this.next();
  17469. this.state.labels.pop();
  17470. return this.finishNode(node, "SwitchStatement");
  17471. }
  17472. parseThrowStatement(node) {
  17473. this.next();
  17474. if (this.hasPrecedingLineBreak()) {
  17475. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  17476. }
  17477. node.argument = this.parseExpression();
  17478. this.semicolon();
  17479. return this.finishNode(node, "ThrowStatement");
  17480. }
  17481. parseCatchClauseParam() {
  17482. const param = this.parseBindingAtom();
  17483. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  17484. this.checkLVal(param, {
  17485. type: "CatchClause"
  17486. }, 9);
  17487. return param;
  17488. }
  17489. parseTryStatement(node) {
  17490. this.next();
  17491. node.block = this.parseBlock();
  17492. node.handler = null;
  17493. if (this.match(62)) {
  17494. const clause = this.startNode();
  17495. this.next();
  17496. if (this.match(10)) {
  17497. this.expect(10);
  17498. clause.param = this.parseCatchClauseParam();
  17499. this.expect(11);
  17500. } else {
  17501. clause.param = null;
  17502. this.scope.enter(0);
  17503. }
  17504. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  17505. this.scope.exit();
  17506. node.handler = this.finishNode(clause, "CatchClause");
  17507. }
  17508. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  17509. if (!node.handler && !node.finalizer) {
  17510. this.raise(Errors.NoCatchOrFinally, node);
  17511. }
  17512. return this.finishNode(node, "TryStatement");
  17513. }
  17514. parseVarStatement(node, kind, allowMissingInitializer = false) {
  17515. this.next();
  17516. this.parseVar(node, false, kind, allowMissingInitializer);
  17517. this.semicolon();
  17518. return this.finishNode(node, "VariableDeclaration");
  17519. }
  17520. parseWhileStatement(node) {
  17521. this.next();
  17522. node.test = this.parseHeaderExpression();
  17523. this.state.labels.push(loopLabel);
  17524. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  17525. this.state.labels.pop();
  17526. return this.finishNode(node, "WhileStatement");
  17527. }
  17528. parseWithStatement(node) {
  17529. if (this.state.strict) {
  17530. this.raise(Errors.StrictWith, this.state.startLoc);
  17531. }
  17532. this.next();
  17533. node.object = this.parseHeaderExpression();
  17534. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  17535. return this.finishNode(node, "WithStatement");
  17536. }
  17537. parseEmptyStatement(node) {
  17538. this.next();
  17539. return this.finishNode(node, "EmptyStatement");
  17540. }
  17541. parseLabeledStatement(node, maybeName, expr, flags) {
  17542. for (const label of this.state.labels) {
  17543. if (label.name === maybeName) {
  17544. this.raise(Errors.LabelRedeclaration, expr, {
  17545. labelName: maybeName
  17546. });
  17547. }
  17548. }
  17549. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  17550. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  17551. const label = this.state.labels[i];
  17552. if (label.statementStart === node.start) {
  17553. label.statementStart = this.sourceToOffsetPos(this.state.start);
  17554. label.kind = kind;
  17555. } else {
  17556. break;
  17557. }
  17558. }
  17559. this.state.labels.push({
  17560. name: maybeName,
  17561. kind: kind,
  17562. statementStart: this.sourceToOffsetPos(this.state.start)
  17563. });
  17564. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  17565. this.state.labels.pop();
  17566. node.label = expr;
  17567. return this.finishNode(node, "LabeledStatement");
  17568. }
  17569. parseExpressionStatement(node, expr, decorators) {
  17570. node.expression = expr;
  17571. this.semicolon();
  17572. return this.finishNode(node, "ExpressionStatement");
  17573. }
  17574. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  17575. const node = this.startNode();
  17576. if (allowDirectives) {
  17577. this.state.strictErrors.clear();
  17578. }
  17579. this.expect(5);
  17580. if (createNewLexicalScope) {
  17581. this.scope.enter(0);
  17582. }
  17583. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  17584. if (createNewLexicalScope) {
  17585. this.scope.exit();
  17586. }
  17587. return this.finishNode(node, "BlockStatement");
  17588. }
  17589. isValidDirective(stmt) {
  17590. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  17591. }
  17592. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  17593. const body = node.body = [];
  17594. const directives = node.directives = [];
  17595. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  17596. }
  17597. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  17598. const oldStrict = this.state.strict;
  17599. let hasStrictModeDirective = false;
  17600. let parsedNonDirective = false;
  17601. while (!this.match(end)) {
  17602. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  17603. if (directives && !parsedNonDirective) {
  17604. if (this.isValidDirective(stmt)) {
  17605. const directive = this.stmtToDirective(stmt);
  17606. directives.push(directive);
  17607. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  17608. hasStrictModeDirective = true;
  17609. this.setStrict(true);
  17610. }
  17611. continue;
  17612. }
  17613. parsedNonDirective = true;
  17614. this.state.strictErrors.clear();
  17615. }
  17616. body.push(stmt);
  17617. }
  17618. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  17619. if (!oldStrict) {
  17620. this.setStrict(false);
  17621. }
  17622. this.next();
  17623. }
  17624. parseFor(node, init) {
  17625. node.init = init;
  17626. this.semicolon(false);
  17627. node.test = this.match(13) ? null : this.parseExpression();
  17628. this.semicolon(false);
  17629. node.update = this.match(11) ? null : this.parseExpression();
  17630. this.expect(11);
  17631. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  17632. this.scope.exit();
  17633. this.state.labels.pop();
  17634. return this.finishNode(node, "ForStatement");
  17635. }
  17636. parseForIn(node, init, awaitAt) {
  17637. const isForIn = this.match(58);
  17638. this.next();
  17639. if (isForIn) {
  17640. if (awaitAt !== null) this.unexpected(awaitAt);
  17641. } else {
  17642. node.await = awaitAt !== null;
  17643. }
  17644. 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")) {
  17645. this.raise(Errors.ForInOfLoopInitializer, init, {
  17646. type: isForIn ? "ForInStatement" : "ForOfStatement"
  17647. });
  17648. }
  17649. if (init.type === "AssignmentPattern") {
  17650. this.raise(Errors.InvalidLhs, init, {
  17651. ancestor: {
  17652. type: "ForStatement"
  17653. }
  17654. });
  17655. }
  17656. node.left = init;
  17657. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  17658. this.expect(11);
  17659. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  17660. this.scope.exit();
  17661. this.state.labels.pop();
  17662. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  17663. }
  17664. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  17665. const declarations = node.declarations = [];
  17666. node.kind = kind;
  17667. for (;;) {
  17668. const decl = this.startNode();
  17669. this.parseVarId(decl, kind);
  17670. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  17671. if (decl.init === null && !allowMissingInitializer) {
  17672. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  17673. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  17674. kind: "destructuring"
  17675. });
  17676. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  17677. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  17678. kind
  17679. });
  17680. }
  17681. }
  17682. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  17683. if (!this.eat(12)) break;
  17684. }
  17685. return node;
  17686. }
  17687. parseVarId(decl, kind) {
  17688. const id = this.parseBindingAtom();
  17689. if (kind === "using" || kind === "await using") {
  17690. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  17691. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  17692. }
  17693. } else {
  17694. if (id.type === "VoidPattern") {
  17695. this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
  17696. }
  17697. }
  17698. this.checkLVal(id, {
  17699. type: "VariableDeclarator"
  17700. }, kind === "var" ? 5 : 8201);
  17701. decl.id = id;
  17702. }
  17703. parseAsyncFunctionExpression(node) {
  17704. return this.parseFunction(node, 8);
  17705. }
  17706. parseFunction(node, flags = 0) {
  17707. const hangingDeclaration = flags & 2;
  17708. const isDeclaration = !!(flags & 1);
  17709. const requireId = isDeclaration && !(flags & 4);
  17710. const isAsync = !!(flags & 8);
  17711. this.initFunction(node, isAsync);
  17712. if (this.match(55)) {
  17713. if (hangingDeclaration) {
  17714. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  17715. }
  17716. this.next();
  17717. node.generator = true;
  17718. }
  17719. if (isDeclaration) {
  17720. node.id = this.parseFunctionId(requireId);
  17721. }
  17722. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  17723. this.state.maybeInArrowParameters = false;
  17724. this.scope.enter(514);
  17725. this.prodParam.enter(functionFlags(isAsync, node.generator));
  17726. if (!isDeclaration) {
  17727. node.id = this.parseFunctionId();
  17728. }
  17729. this.parseFunctionParams(node, false);
  17730. this.withSmartMixTopicForbiddingContext(() => {
  17731. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  17732. });
  17733. this.prodParam.exit();
  17734. this.scope.exit();
  17735. if (isDeclaration && !hangingDeclaration) {
  17736. this.registerFunctionStatementId(node);
  17737. }
  17738. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  17739. return node;
  17740. }
  17741. parseFunctionId(requireId) {
  17742. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  17743. }
  17744. parseFunctionParams(node, isConstructor) {
  17745. this.expect(10);
  17746. this.expressionScope.enter(newParameterDeclarationScope());
  17747. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  17748. this.expressionScope.exit();
  17749. }
  17750. registerFunctionStatementId(node) {
  17751. if (!node.id) return;
  17752. this.scope.declareName(node.id.name, !this.options.annexB || this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? 5 : 8201 : 17, node.id.loc.start);
  17753. }
  17754. parseClass(node, isStatement, optionalId) {
  17755. this.next();
  17756. const oldStrict = this.state.strict;
  17757. this.state.strict = true;
  17758. this.parseClassId(node, isStatement, optionalId);
  17759. this.parseClassSuper(node);
  17760. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  17761. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  17762. }
  17763. isClassProperty() {
  17764. return this.match(29) || this.match(13) || this.match(8);
  17765. }
  17766. isClassMethod() {
  17767. return this.match(10);
  17768. }
  17769. nameIsConstructor(key) {
  17770. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  17771. }
  17772. isNonstaticConstructor(method) {
  17773. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  17774. }
  17775. parseClassBody(hadSuperClass, oldStrict) {
  17776. this.classScope.enter();
  17777. const state = {
  17778. hadConstructor: false,
  17779. hadSuperClass
  17780. };
  17781. let decorators = [];
  17782. const classBody = this.startNode();
  17783. classBody.body = [];
  17784. this.expect(5);
  17785. this.withSmartMixTopicForbiddingContext(() => {
  17786. while (!this.match(8)) {
  17787. if (this.eat(13)) {
  17788. if (decorators.length > 0) {
  17789. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  17790. }
  17791. continue;
  17792. }
  17793. if (this.match(26)) {
  17794. decorators.push(this.parseDecorator());
  17795. continue;
  17796. }
  17797. const member = this.startNode();
  17798. if (decorators.length) {
  17799. member.decorators = decorators;
  17800. this.resetStartLocationFromNode(member, decorators[0]);
  17801. decorators = [];
  17802. }
  17803. this.parseClassMember(classBody, member, state);
  17804. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  17805. this.raise(Errors.DecoratorConstructor, member);
  17806. }
  17807. }
  17808. });
  17809. this.state.strict = oldStrict;
  17810. this.next();
  17811. if (decorators.length) {
  17812. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  17813. }
  17814. this.classScope.exit();
  17815. return this.finishNode(classBody, "ClassBody");
  17816. }
  17817. parseClassMemberFromModifier(classBody, member) {
  17818. const key = this.parseIdentifier(true);
  17819. if (this.isClassMethod()) {
  17820. const method = member;
  17821. method.kind = "method";
  17822. method.computed = false;
  17823. method.key = key;
  17824. method.static = false;
  17825. this.pushClassMethod(classBody, method, false, false, false, false);
  17826. return true;
  17827. } else if (this.isClassProperty()) {
  17828. const prop = member;
  17829. prop.computed = false;
  17830. prop.key = key;
  17831. prop.static = false;
  17832. classBody.body.push(this.parseClassProperty(prop));
  17833. return true;
  17834. }
  17835. this.resetPreviousNodeTrailingComments(key);
  17836. return false;
  17837. }
  17838. parseClassMember(classBody, member, state) {
  17839. const isStatic = this.isContextual(106);
  17840. if (isStatic) {
  17841. if (this.parseClassMemberFromModifier(classBody, member)) {
  17842. return;
  17843. }
  17844. if (this.eat(5)) {
  17845. this.parseClassStaticBlock(classBody, member);
  17846. return;
  17847. }
  17848. }
  17849. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  17850. }
  17851. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  17852. const publicMethod = member;
  17853. const privateMethod = member;
  17854. const publicProp = member;
  17855. const privateProp = member;
  17856. const accessorProp = member;
  17857. const method = publicMethod;
  17858. const publicMember = publicMethod;
  17859. member.static = isStatic;
  17860. this.parsePropertyNamePrefixOperator(member);
  17861. if (this.eat(55)) {
  17862. method.kind = "method";
  17863. const isPrivateName = this.match(139);
  17864. this.parseClassElementName(method);
  17865. this.parsePostMemberNameModifiers(method);
  17866. if (isPrivateName) {
  17867. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  17868. return;
  17869. }
  17870. if (this.isNonstaticConstructor(publicMethod)) {
  17871. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  17872. }
  17873. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  17874. return;
  17875. }
  17876. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  17877. const key = this.parseClassElementName(member);
  17878. const maybeContextualKw = isContextual ? key.name : null;
  17879. const isPrivate = this.isPrivateName(key);
  17880. const maybeQuestionTokenStartLoc = this.state.startLoc;
  17881. this.parsePostMemberNameModifiers(publicMember);
  17882. if (this.isClassMethod()) {
  17883. method.kind = "method";
  17884. if (isPrivate) {
  17885. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  17886. return;
  17887. }
  17888. const isConstructor = this.isNonstaticConstructor(publicMethod);
  17889. let allowsDirectSuper = false;
  17890. if (isConstructor) {
  17891. publicMethod.kind = "constructor";
  17892. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  17893. this.raise(Errors.DuplicateConstructor, key);
  17894. }
  17895. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  17896. this.raise(Errors.OverrideOnConstructor, key);
  17897. }
  17898. state.hadConstructor = true;
  17899. allowsDirectSuper = state.hadSuperClass;
  17900. }
  17901. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  17902. } else if (this.isClassProperty()) {
  17903. if (isPrivate) {
  17904. this.pushClassPrivateProperty(classBody, privateProp);
  17905. } else {
  17906. this.pushClassProperty(classBody, publicProp);
  17907. }
  17908. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  17909. this.resetPreviousNodeTrailingComments(key);
  17910. const isGenerator = this.eat(55);
  17911. if (publicMember.optional) {
  17912. this.unexpected(maybeQuestionTokenStartLoc);
  17913. }
  17914. method.kind = "method";
  17915. const isPrivate = this.match(139);
  17916. this.parseClassElementName(method);
  17917. this.parsePostMemberNameModifiers(publicMember);
  17918. if (isPrivate) {
  17919. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  17920. } else {
  17921. if (this.isNonstaticConstructor(publicMethod)) {
  17922. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  17923. }
  17924. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  17925. }
  17926. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  17927. this.resetPreviousNodeTrailingComments(key);
  17928. method.kind = maybeContextualKw;
  17929. const isPrivate = this.match(139);
  17930. this.parseClassElementName(publicMethod);
  17931. if (isPrivate) {
  17932. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  17933. } else {
  17934. if (this.isNonstaticConstructor(publicMethod)) {
  17935. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  17936. }
  17937. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  17938. }
  17939. this.checkGetterSetterParams(publicMethod);
  17940. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  17941. this.expectPlugin("decoratorAutoAccessors");
  17942. this.resetPreviousNodeTrailingComments(key);
  17943. const isPrivate = this.match(139);
  17944. this.parseClassElementName(publicProp);
  17945. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  17946. } else if (this.isLineTerminator()) {
  17947. if (isPrivate) {
  17948. this.pushClassPrivateProperty(classBody, privateProp);
  17949. } else {
  17950. this.pushClassProperty(classBody, publicProp);
  17951. }
  17952. } else {
  17953. this.unexpected();
  17954. }
  17955. }
  17956. parseClassElementName(member) {
  17957. const {
  17958. type,
  17959. value
  17960. } = this.state;
  17961. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  17962. this.raise(Errors.StaticPrototype, this.state.startLoc);
  17963. }
  17964. if (type === 139) {
  17965. if (value === "constructor") {
  17966. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  17967. }
  17968. const key = this.parsePrivateName();
  17969. member.key = key;
  17970. return key;
  17971. }
  17972. this.parsePropertyName(member);
  17973. return member.key;
  17974. }
  17975. parseClassStaticBlock(classBody, member) {
  17976. var _member$decorators;
  17977. this.scope.enter(576 | 128 | 16);
  17978. const oldLabels = this.state.labels;
  17979. this.state.labels = [];
  17980. this.prodParam.enter(0);
  17981. const body = member.body = [];
  17982. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  17983. this.prodParam.exit();
  17984. this.scope.exit();
  17985. this.state.labels = oldLabels;
  17986. classBody.body.push(this.finishNode(member, "StaticBlock"));
  17987. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  17988. this.raise(Errors.DecoratorStaticBlock, member);
  17989. }
  17990. }
  17991. pushClassProperty(classBody, prop) {
  17992. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  17993. this.raise(Errors.ConstructorClassField, prop.key);
  17994. }
  17995. classBody.body.push(this.parseClassProperty(prop));
  17996. }
  17997. pushClassPrivateProperty(classBody, prop) {
  17998. const node = this.parseClassPrivateProperty(prop);
  17999. classBody.body.push(node);
  18000. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  18001. }
  18002. pushClassAccessorProperty(classBody, prop, isPrivate) {
  18003. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  18004. this.raise(Errors.ConstructorClassField, prop.key);
  18005. }
  18006. const node = this.parseClassAccessorProperty(prop);
  18007. classBody.body.push(node);
  18008. if (isPrivate) {
  18009. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  18010. }
  18011. }
  18012. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  18013. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  18014. }
  18015. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  18016. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  18017. classBody.body.push(node);
  18018. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  18019. this.declareClassPrivateMethodInScope(node, kind);
  18020. }
  18021. declareClassPrivateMethodInScope(node, kind) {
  18022. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  18023. }
  18024. parsePostMemberNameModifiers(methodOrProp) {}
  18025. parseClassPrivateProperty(node) {
  18026. this.parseInitializer(node);
  18027. this.semicolon();
  18028. return this.finishNode(node, "ClassPrivateProperty");
  18029. }
  18030. parseClassProperty(node) {
  18031. this.parseInitializer(node);
  18032. this.semicolon();
  18033. return this.finishNode(node, "ClassProperty");
  18034. }
  18035. parseClassAccessorProperty(node) {
  18036. this.parseInitializer(node);
  18037. this.semicolon();
  18038. return this.finishNode(node, "ClassAccessorProperty");
  18039. }
  18040. parseInitializer(node) {
  18041. this.scope.enter(576 | 16);
  18042. this.expressionScope.enter(newExpressionScope());
  18043. this.prodParam.enter(0);
  18044. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  18045. this.expressionScope.exit();
  18046. this.prodParam.exit();
  18047. this.scope.exit();
  18048. }
  18049. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  18050. if (tokenIsIdentifier(this.state.type)) {
  18051. node.id = this.parseIdentifier();
  18052. if (isStatement) {
  18053. this.declareNameFromIdentifier(node.id, bindingType);
  18054. }
  18055. } else {
  18056. if (optionalId || !isStatement) {
  18057. node.id = null;
  18058. } else {
  18059. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  18060. }
  18061. }
  18062. }
  18063. parseClassSuper(node) {
  18064. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  18065. }
  18066. parseExport(node, decorators) {
  18067. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  18068. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  18069. const parseAfterDefault = !hasDefault || this.eat(12);
  18070. const hasStar = parseAfterDefault && this.eatExportStar(node);
  18071. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  18072. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  18073. const isFromRequired = hasDefault || hasStar;
  18074. if (hasStar && !hasNamespace) {
  18075. if (hasDefault) this.unexpected();
  18076. if (decorators) {
  18077. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  18078. }
  18079. this.parseExportFrom(node, true);
  18080. this.sawUnambiguousESM = true;
  18081. return this.finishNode(node, "ExportAllDeclaration");
  18082. }
  18083. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  18084. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  18085. this.unexpected(null, 5);
  18086. }
  18087. if (hasNamespace && parseAfterNamespace) {
  18088. this.unexpected(null, 98);
  18089. }
  18090. let hasDeclaration;
  18091. if (isFromRequired || hasSpecifiers) {
  18092. hasDeclaration = false;
  18093. if (decorators) {
  18094. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  18095. }
  18096. this.parseExportFrom(node, isFromRequired);
  18097. } else {
  18098. hasDeclaration = this.maybeParseExportDeclaration(node);
  18099. }
  18100. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  18101. var _node2$declaration;
  18102. const node2 = node;
  18103. this.checkExport(node2, true, false, !!node2.source);
  18104. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  18105. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  18106. } else if (decorators) {
  18107. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  18108. }
  18109. this.sawUnambiguousESM = true;
  18110. return this.finishNode(node2, "ExportNamedDeclaration");
  18111. }
  18112. if (this.eat(65)) {
  18113. const node2 = node;
  18114. const decl = this.parseExportDefaultExpression();
  18115. node2.declaration = decl;
  18116. if (decl.type === "ClassDeclaration") {
  18117. this.maybeTakeDecorators(decorators, decl, node2);
  18118. } else if (decorators) {
  18119. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  18120. }
  18121. this.checkExport(node2, true, true);
  18122. this.sawUnambiguousESM = true;
  18123. return this.finishNode(node2, "ExportDefaultDeclaration");
  18124. }
  18125. throw this.unexpected(null, 5);
  18126. }
  18127. eatExportStar(node) {
  18128. return this.eat(55);
  18129. }
  18130. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  18131. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  18132. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  18133. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  18134. const specifier = this.startNodeAtNode(id);
  18135. specifier.exported = id;
  18136. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  18137. return true;
  18138. }
  18139. return false;
  18140. }
  18141. maybeParseExportNamespaceSpecifier(node) {
  18142. if (this.isContextual(93)) {
  18143. var _ref, _ref$specifiers;
  18144. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  18145. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  18146. this.next();
  18147. specifier.exported = this.parseModuleExportName();
  18148. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  18149. return true;
  18150. }
  18151. return false;
  18152. }
  18153. maybeParseExportNamedSpecifiers(node) {
  18154. if (this.match(5)) {
  18155. const node2 = node;
  18156. if (!node2.specifiers) node2.specifiers = [];
  18157. const isTypeExport = node2.exportKind === "type";
  18158. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  18159. node2.source = null;
  18160. if (this.hasPlugin("importAssertions")) {
  18161. node2.assertions = [];
  18162. } else {
  18163. node2.attributes = [];
  18164. }
  18165. node2.declaration = null;
  18166. return true;
  18167. }
  18168. return false;
  18169. }
  18170. maybeParseExportDeclaration(node) {
  18171. if (this.shouldParseExportDeclaration()) {
  18172. node.specifiers = [];
  18173. node.source = null;
  18174. if (this.hasPlugin("importAssertions")) {
  18175. node.assertions = [];
  18176. } else {
  18177. node.attributes = [];
  18178. }
  18179. node.declaration = this.parseExportDeclaration(node);
  18180. return true;
  18181. }
  18182. return false;
  18183. }
  18184. isAsyncFunction() {
  18185. if (!this.isContextual(95)) return false;
  18186. const next = this.nextTokenInLineStart();
  18187. return this.isUnparsedContextual(next, "function");
  18188. }
  18189. parseExportDefaultExpression() {
  18190. const expr = this.startNode();
  18191. if (this.match(68)) {
  18192. this.next();
  18193. return this.parseFunction(expr, 1 | 4);
  18194. } else if (this.isAsyncFunction()) {
  18195. this.next();
  18196. this.next();
  18197. return this.parseFunction(expr, 1 | 4 | 8);
  18198. }
  18199. if (this.match(80)) {
  18200. return this.parseClass(expr, true, true);
  18201. }
  18202. if (this.match(26)) {
  18203. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  18204. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  18205. }
  18206. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  18207. }
  18208. if (this.match(75) || this.match(74) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
  18209. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  18210. }
  18211. const res = this.parseMaybeAssignAllowIn();
  18212. this.semicolon();
  18213. return res;
  18214. }
  18215. parseExportDeclaration(node) {
  18216. if (this.match(80)) {
  18217. const node = this.parseClass(this.startNode(), true, false);
  18218. return node;
  18219. }
  18220. return this.parseStatementListItem();
  18221. }
  18222. isExportDefaultSpecifier() {
  18223. const {
  18224. type
  18225. } = this.state;
  18226. if (tokenIsIdentifier(type)) {
  18227. if (type === 95 && !this.state.containsEsc || type === 100) {
  18228. return false;
  18229. }
  18230. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  18231. const next = this.nextTokenStart();
  18232. const nextChar = this.input.charCodeAt(next);
  18233. if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next) && !this.input.startsWith("from", next)) {
  18234. this.expectOnePlugin(["flow", "typescript"]);
  18235. return false;
  18236. }
  18237. }
  18238. } else if (!this.match(65)) {
  18239. return false;
  18240. }
  18241. const next = this.nextTokenStart();
  18242. const hasFrom = this.isUnparsedContextual(next, "from");
  18243. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  18244. return true;
  18245. }
  18246. if (this.match(65) && hasFrom) {
  18247. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  18248. return nextAfterFrom === 34 || nextAfterFrom === 39;
  18249. }
  18250. return false;
  18251. }
  18252. parseExportFrom(node, expect) {
  18253. if (this.eatContextual(98)) {
  18254. node.source = this.parseImportSource();
  18255. this.checkExport(node);
  18256. this.maybeParseImportAttributes(node);
  18257. this.checkJSONModuleImport(node);
  18258. } else if (expect) {
  18259. this.unexpected();
  18260. }
  18261. this.semicolon();
  18262. }
  18263. shouldParseExportDeclaration() {
  18264. const {
  18265. type
  18266. } = this.state;
  18267. if (type === 26) {
  18268. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  18269. if (this.hasPlugin("decorators")) {
  18270. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  18271. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  18272. }
  18273. return true;
  18274. }
  18275. }
  18276. if (this.isUsing()) {
  18277. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  18278. return true;
  18279. }
  18280. if (this.isAwaitUsing()) {
  18281. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  18282. return true;
  18283. }
  18284. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  18285. }
  18286. checkExport(node, checkNames, isDefault, isFrom) {
  18287. if (checkNames) {
  18288. var _node$specifiers;
  18289. if (isDefault) {
  18290. this.checkDuplicateExports(node, "default");
  18291. if (this.hasPlugin("exportDefaultFrom")) {
  18292. var _declaration$extra;
  18293. const declaration = node.declaration;
  18294. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  18295. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  18296. }
  18297. }
  18298. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  18299. for (const specifier of node.specifiers) {
  18300. const {
  18301. exported
  18302. } = specifier;
  18303. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  18304. this.checkDuplicateExports(specifier, exportName);
  18305. if (!isFrom && specifier.local) {
  18306. const {
  18307. local
  18308. } = specifier;
  18309. if (local.type !== "Identifier") {
  18310. this.raise(Errors.ExportBindingIsString, specifier, {
  18311. localName: local.value,
  18312. exportName
  18313. });
  18314. } else {
  18315. this.checkReservedWord(local.name, local.loc.start, true, false);
  18316. this.scope.checkLocalExport(local);
  18317. }
  18318. }
  18319. }
  18320. } else if (node.declaration) {
  18321. const decl = node.declaration;
  18322. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  18323. const {
  18324. id
  18325. } = decl;
  18326. if (!id) throw new Error("Assertion failure");
  18327. this.checkDuplicateExports(node, id.name);
  18328. } else if (decl.type === "VariableDeclaration") {
  18329. for (const declaration of decl.declarations) {
  18330. this.checkDeclaration(declaration.id);
  18331. }
  18332. }
  18333. }
  18334. }
  18335. }
  18336. checkDeclaration(node) {
  18337. if (node.type === "Identifier") {
  18338. this.checkDuplicateExports(node, node.name);
  18339. } else if (node.type === "ObjectPattern") {
  18340. for (const prop of node.properties) {
  18341. this.checkDeclaration(prop);
  18342. }
  18343. } else if (node.type === "ArrayPattern") {
  18344. for (const elem of node.elements) {
  18345. if (elem) {
  18346. this.checkDeclaration(elem);
  18347. }
  18348. }
  18349. } else if (node.type === "ObjectProperty") {
  18350. this.checkDeclaration(node.value);
  18351. } else if (node.type === "RestElement") {
  18352. this.checkDeclaration(node.argument);
  18353. } else if (node.type === "AssignmentPattern") {
  18354. this.checkDeclaration(node.left);
  18355. }
  18356. }
  18357. checkDuplicateExports(node, exportName) {
  18358. if (this.exportedIdentifiers.has(exportName)) {
  18359. if (exportName === "default") {
  18360. this.raise(Errors.DuplicateDefaultExport, node);
  18361. } else {
  18362. this.raise(Errors.DuplicateExport, node, {
  18363. exportName
  18364. });
  18365. }
  18366. }
  18367. this.exportedIdentifiers.add(exportName);
  18368. }
  18369. parseExportSpecifiers(isInTypeExport) {
  18370. const nodes = [];
  18371. let first = true;
  18372. this.expect(5);
  18373. while (!this.eat(8)) {
  18374. if (first) {
  18375. first = false;
  18376. } else {
  18377. this.expect(12);
  18378. if (this.eat(8)) break;
  18379. }
  18380. const isMaybeTypeOnly = this.isContextual(130);
  18381. const isString = this.match(134);
  18382. const node = this.startNode();
  18383. node.local = this.parseModuleExportName();
  18384. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  18385. }
  18386. return nodes;
  18387. }
  18388. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  18389. if (this.eatContextual(93)) {
  18390. node.exported = this.parseModuleExportName();
  18391. } else if (isString) {
  18392. node.exported = this.cloneStringLiteral(node.local);
  18393. } else if (!node.exported) {
  18394. node.exported = this.cloneIdentifier(node.local);
  18395. }
  18396. return this.finishNode(node, "ExportSpecifier");
  18397. }
  18398. parseModuleExportName() {
  18399. if (this.match(134)) {
  18400. const result = this.parseStringLiteral(this.state.value);
  18401. const surrogate = loneSurrogate.exec(result.value);
  18402. if (surrogate) {
  18403. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  18404. surrogateCharCode: surrogate[0].charCodeAt(0)
  18405. });
  18406. }
  18407. return result;
  18408. }
  18409. return this.parseIdentifier(true);
  18410. }
  18411. isJSONModuleImport(node) {
  18412. if (node.assertions != null) {
  18413. return node.assertions.some(({
  18414. key,
  18415. value
  18416. }) => {
  18417. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  18418. });
  18419. }
  18420. return false;
  18421. }
  18422. checkImportReflection(node) {
  18423. const {
  18424. specifiers
  18425. } = node;
  18426. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  18427. if (node.phase === "source") {
  18428. if (singleBindingType !== "ImportDefaultSpecifier") {
  18429. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  18430. }
  18431. } else if (node.phase === "defer") {
  18432. if (singleBindingType !== "ImportNamespaceSpecifier") {
  18433. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  18434. }
  18435. } else if (node.module) {
  18436. var _node$assertions;
  18437. if (singleBindingType !== "ImportDefaultSpecifier") {
  18438. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  18439. }
  18440. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  18441. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  18442. }
  18443. }
  18444. }
  18445. checkJSONModuleImport(node) {
  18446. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  18447. const {
  18448. specifiers
  18449. } = node;
  18450. if (specifiers != null) {
  18451. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  18452. let imported;
  18453. if (specifier.type === "ExportSpecifier") {
  18454. imported = specifier.local;
  18455. } else if (specifier.type === "ImportSpecifier") {
  18456. imported = specifier.imported;
  18457. }
  18458. if (imported !== undefined) {
  18459. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  18460. }
  18461. });
  18462. if (nonDefaultNamedSpecifier !== undefined) {
  18463. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  18464. }
  18465. }
  18466. }
  18467. }
  18468. isPotentialImportPhase(isExport) {
  18469. if (isExport) return false;
  18470. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  18471. }
  18472. applyImportPhase(node, isExport, phase, loc) {
  18473. if (isExport) {
  18474. return;
  18475. }
  18476. if (phase === "module") {
  18477. this.expectPlugin("importReflection", loc);
  18478. node.module = true;
  18479. } else if (this.hasPlugin("importReflection")) {
  18480. node.module = false;
  18481. }
  18482. if (phase === "source") {
  18483. this.expectPlugin("sourcePhaseImports", loc);
  18484. node.phase = "source";
  18485. } else if (phase === "defer") {
  18486. this.expectPlugin("deferredImportEvaluation", loc);
  18487. node.phase = "defer";
  18488. } else if (this.hasPlugin("sourcePhaseImports")) {
  18489. node.phase = null;
  18490. }
  18491. }
  18492. parseMaybeImportPhase(node, isExport) {
  18493. if (!this.isPotentialImportPhase(isExport)) {
  18494. this.applyImportPhase(node, isExport, null);
  18495. return null;
  18496. }
  18497. const phaseIdentifier = this.startNode();
  18498. const phaseIdentifierName = this.parseIdentifierName(true);
  18499. const {
  18500. type
  18501. } = this.state;
  18502. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  18503. if (isImportPhase) {
  18504. this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
  18505. return null;
  18506. } else {
  18507. this.applyImportPhase(node, isExport, null);
  18508. return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
  18509. }
  18510. }
  18511. isPrecedingIdImportPhase(phase) {
  18512. const {
  18513. type
  18514. } = this.state;
  18515. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  18516. }
  18517. parseImport(node) {
  18518. if (this.match(134)) {
  18519. return this.parseImportSourceAndAttributes(node);
  18520. }
  18521. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  18522. }
  18523. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  18524. node.specifiers = [];
  18525. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  18526. const parseNext = !hasDefault || this.eat(12);
  18527. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  18528. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  18529. this.expectContextual(98);
  18530. return this.parseImportSourceAndAttributes(node);
  18531. }
  18532. parseImportSourceAndAttributes(node) {
  18533. var _node$specifiers2;
  18534. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  18535. node.source = this.parseImportSource();
  18536. this.maybeParseImportAttributes(node);
  18537. this.checkImportReflection(node);
  18538. this.checkJSONModuleImport(node);
  18539. this.semicolon();
  18540. this.sawUnambiguousESM = true;
  18541. return this.finishNode(node, "ImportDeclaration");
  18542. }
  18543. parseImportSource() {
  18544. if (!this.match(134)) this.unexpected();
  18545. return this.parseExprAtom();
  18546. }
  18547. parseImportSpecifierLocal(node, specifier, type) {
  18548. specifier.local = this.parseIdentifier();
  18549. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  18550. }
  18551. finishImportSpecifier(specifier, type, bindingType = 8201) {
  18552. this.checkLVal(specifier.local, {
  18553. type
  18554. }, bindingType);
  18555. return this.finishNode(specifier, type);
  18556. }
  18557. parseImportAttributes() {
  18558. this.expect(5);
  18559. const attrs = [];
  18560. const attrNames = new Set();
  18561. do {
  18562. if (this.match(8)) {
  18563. break;
  18564. }
  18565. const node = this.startNode();
  18566. const keyName = this.state.value;
  18567. if (attrNames.has(keyName)) {
  18568. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  18569. key: keyName
  18570. });
  18571. }
  18572. attrNames.add(keyName);
  18573. if (this.match(134)) {
  18574. node.key = this.parseStringLiteral(keyName);
  18575. } else {
  18576. node.key = this.parseIdentifier(true);
  18577. }
  18578. this.expect(14);
  18579. if (!this.match(134)) {
  18580. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  18581. }
  18582. node.value = this.parseStringLiteral(this.state.value);
  18583. attrs.push(this.finishNode(node, "ImportAttribute"));
  18584. } while (this.eat(12));
  18585. this.expect(8);
  18586. return attrs;
  18587. }
  18588. parseModuleAttributes() {
  18589. const attrs = [];
  18590. const attributes = new Set();
  18591. do {
  18592. const node = this.startNode();
  18593. node.key = this.parseIdentifier(true);
  18594. if (node.key.name !== "type") {
  18595. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  18596. }
  18597. if (attributes.has(node.key.name)) {
  18598. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  18599. key: node.key.name
  18600. });
  18601. }
  18602. attributes.add(node.key.name);
  18603. this.expect(14);
  18604. if (!this.match(134)) {
  18605. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  18606. }
  18607. node.value = this.parseStringLiteral(this.state.value);
  18608. attrs.push(this.finishNode(node, "ImportAttribute"));
  18609. } while (this.eat(12));
  18610. return attrs;
  18611. }
  18612. maybeParseImportAttributes(node) {
  18613. let attributes;
  18614. {
  18615. var useWith = false;
  18616. }
  18617. if (this.match(76)) {
  18618. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  18619. return;
  18620. }
  18621. this.next();
  18622. if (this.hasPlugin("moduleAttributes")) {
  18623. attributes = this.parseModuleAttributes();
  18624. this.addExtra(node, "deprecatedWithLegacySyntax", true);
  18625. } else {
  18626. attributes = this.parseImportAttributes();
  18627. }
  18628. {
  18629. useWith = true;
  18630. }
  18631. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  18632. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  18633. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  18634. }
  18635. if (!this.hasPlugin("importAssertions")) {
  18636. this.addExtra(node, "deprecatedAssertSyntax", true);
  18637. }
  18638. this.next();
  18639. attributes = this.parseImportAttributes();
  18640. } else {
  18641. attributes = [];
  18642. }
  18643. if (!useWith && this.hasPlugin("importAssertions")) {
  18644. node.assertions = attributes;
  18645. } else {
  18646. node.attributes = attributes;
  18647. }
  18648. }
  18649. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  18650. if (maybeDefaultIdentifier) {
  18651. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  18652. specifier.local = maybeDefaultIdentifier;
  18653. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  18654. return true;
  18655. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  18656. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  18657. return true;
  18658. }
  18659. return false;
  18660. }
  18661. maybeParseStarImportSpecifier(node) {
  18662. if (this.match(55)) {
  18663. const specifier = this.startNode();
  18664. this.next();
  18665. this.expectContextual(93);
  18666. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  18667. return true;
  18668. }
  18669. return false;
  18670. }
  18671. parseNamedImportSpecifiers(node) {
  18672. let first = true;
  18673. this.expect(5);
  18674. while (!this.eat(8)) {
  18675. if (first) {
  18676. first = false;
  18677. } else {
  18678. if (this.eat(14)) {
  18679. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  18680. }
  18681. this.expect(12);
  18682. if (this.eat(8)) break;
  18683. }
  18684. const specifier = this.startNode();
  18685. const importedIsString = this.match(134);
  18686. const isMaybeTypeOnly = this.isContextual(130);
  18687. specifier.imported = this.parseModuleExportName();
  18688. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  18689. node.specifiers.push(importSpecifier);
  18690. }
  18691. }
  18692. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  18693. if (this.eatContextual(93)) {
  18694. specifier.local = this.parseIdentifier();
  18695. } else {
  18696. const {
  18697. imported
  18698. } = specifier;
  18699. if (importedIsString) {
  18700. throw this.raise(Errors.ImportBindingIsString, specifier, {
  18701. importName: imported.value
  18702. });
  18703. }
  18704. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  18705. if (!specifier.local) {
  18706. specifier.local = this.cloneIdentifier(imported);
  18707. }
  18708. }
  18709. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  18710. }
  18711. isThisParam(param) {
  18712. return param.type === "Identifier" && param.name === "this";
  18713. }
  18714. }
  18715. class Parser extends StatementParser {
  18716. constructor(options, input, pluginsMap) {
  18717. const normalizedOptions = getOptions(options);
  18718. super(normalizedOptions, input);
  18719. this.options = normalizedOptions;
  18720. this.initializeScopes();
  18721. this.plugins = pluginsMap;
  18722. this.filename = normalizedOptions.sourceFilename;
  18723. this.startIndex = normalizedOptions.startIndex;
  18724. let optionFlags = 0;
  18725. if (normalizedOptions.allowAwaitOutsideFunction) {
  18726. optionFlags |= 1;
  18727. }
  18728. if (normalizedOptions.allowReturnOutsideFunction) {
  18729. optionFlags |= 2;
  18730. }
  18731. if (normalizedOptions.allowImportExportEverywhere) {
  18732. optionFlags |= 8;
  18733. }
  18734. if (normalizedOptions.allowSuperOutsideMethod) {
  18735. optionFlags |= 16;
  18736. }
  18737. if (normalizedOptions.allowUndeclaredExports) {
  18738. optionFlags |= 64;
  18739. }
  18740. if (normalizedOptions.allowNewTargetOutsideFunction) {
  18741. optionFlags |= 4;
  18742. }
  18743. if (normalizedOptions.allowYieldOutsideFunction) {
  18744. optionFlags |= 32;
  18745. }
  18746. if (normalizedOptions.ranges) {
  18747. optionFlags |= 128;
  18748. }
  18749. if (normalizedOptions.tokens) {
  18750. optionFlags |= 256;
  18751. }
  18752. if (normalizedOptions.createImportExpressions) {
  18753. optionFlags |= 512;
  18754. }
  18755. if (normalizedOptions.createParenthesizedExpressions) {
  18756. optionFlags |= 1024;
  18757. }
  18758. if (normalizedOptions.errorRecovery) {
  18759. optionFlags |= 2048;
  18760. }
  18761. if (normalizedOptions.attachComment) {
  18762. optionFlags |= 4096;
  18763. }
  18764. if (normalizedOptions.annexB) {
  18765. optionFlags |= 8192;
  18766. }
  18767. this.optionFlags = optionFlags;
  18768. }
  18769. getScopeHandler() {
  18770. return ScopeHandler;
  18771. }
  18772. parse() {
  18773. this.enterInitialScopes();
  18774. const file = this.startNode();
  18775. const program = this.startNode();
  18776. this.nextToken();
  18777. file.errors = null;
  18778. const result = this.parseTopLevel(file, program);
  18779. result.errors = this.state.errors;
  18780. result.comments.length = this.state.commentsLen;
  18781. return result;
  18782. }
  18783. }
  18784. function parse(input, options) {
  18785. var _options;
  18786. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  18787. options = Object.assign({}, options);
  18788. try {
  18789. options.sourceType = "module";
  18790. const parser = getParser(options, input);
  18791. const ast = parser.parse();
  18792. if (parser.sawUnambiguousESM) {
  18793. return ast;
  18794. }
  18795. if (parser.ambiguousScriptDifferentAst) {
  18796. try {
  18797. options.sourceType = "script";
  18798. return getParser(options, input).parse();
  18799. } catch (_unused) {}
  18800. } else {
  18801. ast.program.sourceType = "script";
  18802. }
  18803. return ast;
  18804. } catch (moduleError) {
  18805. try {
  18806. options.sourceType = "script";
  18807. return getParser(options, input).parse();
  18808. } catch (_unused2) {}
  18809. throw moduleError;
  18810. }
  18811. } else {
  18812. return getParser(options, input).parse();
  18813. }
  18814. }
  18815. function parseExpression(input, options) {
  18816. const parser = getParser(options, input);
  18817. if (parser.options.strictMode) {
  18818. parser.state.strict = true;
  18819. }
  18820. return parser.getExpression();
  18821. }
  18822. function generateExportedTokenTypes(internalTokenTypes) {
  18823. const tokenTypes = {};
  18824. for (const typeName of Object.keys(internalTokenTypes)) {
  18825. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  18826. }
  18827. return tokenTypes;
  18828. }
  18829. const tokTypes = generateExportedTokenTypes(tt);
  18830. function getParser(options, input) {
  18831. let cls = Parser;
  18832. const pluginsMap = new Map();
  18833. if (options != null && options.plugins) {
  18834. for (const plugin of options.plugins) {
  18835. let name, opts;
  18836. if (typeof plugin === "string") {
  18837. name = plugin;
  18838. } else {
  18839. [name, opts] = plugin;
  18840. }
  18841. if (!pluginsMap.has(name)) {
  18842. pluginsMap.set(name, opts || {});
  18843. }
  18844. }
  18845. validatePlugins(pluginsMap);
  18846. cls = getParserClass(pluginsMap);
  18847. }
  18848. return new cls(options, input, pluginsMap);
  18849. }
  18850. const parserClassCache = new Map();
  18851. function getParserClass(pluginsMap) {
  18852. const pluginList = [];
  18853. for (const name of mixinPluginNames) {
  18854. if (pluginsMap.has(name)) {
  18855. pluginList.push(name);
  18856. }
  18857. }
  18858. const key = pluginList.join("|");
  18859. let cls = parserClassCache.get(key);
  18860. if (!cls) {
  18861. cls = Parser;
  18862. for (const plugin of pluginList) {
  18863. cls = mixinPlugins[plugin](cls);
  18864. }
  18865. parserClassCache.set(key, cls);
  18866. }
  18867. return cls;
  18868. }
  18869. lib.parse = parse;
  18870. lib.parseExpression = parseExpression;
  18871. lib.tokTypes = tokTypes;
  18872. return lib;
  18873. }
  18874. var libExports = /*@__PURE__*/ requireLib();
  18875. // @ts-check
  18876. /** @typedef { import('estree').BaseNode} BaseNode */
  18877. /** @typedef {{
  18878. skip: () => void;
  18879. remove: () => void;
  18880. replace: (node: BaseNode) => void;
  18881. }} WalkerContext */
  18882. class WalkerBase {
  18883. constructor() {
  18884. /** @type {boolean} */
  18885. this.should_skip = false;
  18886. /** @type {boolean} */
  18887. this.should_remove = false;
  18888. /** @type {BaseNode | null} */
  18889. this.replacement = null;
  18890. /** @type {WalkerContext} */
  18891. this.context = {
  18892. skip: () => (this.should_skip = true),
  18893. remove: () => (this.should_remove = true),
  18894. replace: (node) => (this.replacement = node)
  18895. };
  18896. }
  18897. /**
  18898. *
  18899. * @param {any} parent
  18900. * @param {string} prop
  18901. * @param {number} index
  18902. * @param {BaseNode} node
  18903. */
  18904. replace(parent, prop, index, node) {
  18905. if (parent) {
  18906. if (index !== null) {
  18907. parent[prop][index] = node;
  18908. } else {
  18909. parent[prop] = node;
  18910. }
  18911. }
  18912. }
  18913. /**
  18914. *
  18915. * @param {any} parent
  18916. * @param {string} prop
  18917. * @param {number} index
  18918. */
  18919. remove(parent, prop, index) {
  18920. if (parent) {
  18921. if (index !== null) {
  18922. parent[prop].splice(index, 1);
  18923. } else {
  18924. delete parent[prop];
  18925. }
  18926. }
  18927. }
  18928. }
  18929. // @ts-check
  18930. /** @typedef { import('estree').BaseNode} BaseNode */
  18931. /** @typedef { import('./walker.js').WalkerContext} WalkerContext */
  18932. /** @typedef {(
  18933. * this: WalkerContext,
  18934. * node: BaseNode,
  18935. * parent: BaseNode,
  18936. * key: string,
  18937. * index: number
  18938. * ) => void} SyncHandler */
  18939. class SyncWalker extends WalkerBase {
  18940. /**
  18941. *
  18942. * @param {SyncHandler} enter
  18943. * @param {SyncHandler} leave
  18944. */
  18945. constructor(enter, leave) {
  18946. super();
  18947. /** @type {SyncHandler} */
  18948. this.enter = enter;
  18949. /** @type {SyncHandler} */
  18950. this.leave = leave;
  18951. }
  18952. /**
  18953. *
  18954. * @param {BaseNode} node
  18955. * @param {BaseNode} parent
  18956. * @param {string} [prop]
  18957. * @param {number} [index]
  18958. * @returns {BaseNode}
  18959. */
  18960. visit(node, parent, prop, index) {
  18961. if (node) {
  18962. if (this.enter) {
  18963. const _should_skip = this.should_skip;
  18964. const _should_remove = this.should_remove;
  18965. const _replacement = this.replacement;
  18966. this.should_skip = false;
  18967. this.should_remove = false;
  18968. this.replacement = null;
  18969. this.enter.call(this.context, node, parent, prop, index);
  18970. if (this.replacement) {
  18971. node = this.replacement;
  18972. this.replace(parent, prop, index, node);
  18973. }
  18974. if (this.should_remove) {
  18975. this.remove(parent, prop, index);
  18976. }
  18977. const skipped = this.should_skip;
  18978. const removed = this.should_remove;
  18979. this.should_skip = _should_skip;
  18980. this.should_remove = _should_remove;
  18981. this.replacement = _replacement;
  18982. if (skipped) return node;
  18983. if (removed) return null;
  18984. }
  18985. for (const key in node) {
  18986. const value = node[key];
  18987. if (typeof value !== "object") {
  18988. continue;
  18989. } else if (Array.isArray(value)) {
  18990. for (let i = 0; i < value.length; i += 1) {
  18991. if (value[i] !== null && typeof value[i].type === 'string') {
  18992. if (!this.visit(value[i], node, key, i)) {
  18993. // removed
  18994. i--;
  18995. }
  18996. }
  18997. }
  18998. } else if (value !== null && typeof value.type === "string") {
  18999. this.visit(value, node, key, null);
  19000. }
  19001. }
  19002. if (this.leave) {
  19003. const _replacement = this.replacement;
  19004. const _should_remove = this.should_remove;
  19005. this.replacement = null;
  19006. this.should_remove = false;
  19007. this.leave.call(this.context, node, parent, prop, index);
  19008. if (this.replacement) {
  19009. node = this.replacement;
  19010. this.replace(parent, prop, index, node);
  19011. }
  19012. if (this.should_remove) {
  19013. this.remove(parent, prop, index);
  19014. }
  19015. const removed = this.should_remove;
  19016. this.replacement = _replacement;
  19017. this.should_remove = _should_remove;
  19018. if (removed) return null;
  19019. }
  19020. }
  19021. return node;
  19022. }
  19023. }
  19024. // @ts-check
  19025. /** @typedef { import('estree').BaseNode} BaseNode */
  19026. /** @typedef { import('./sync.js').SyncHandler} SyncHandler */
  19027. /** @typedef { import('./async.js').AsyncHandler} AsyncHandler */
  19028. /**
  19029. *
  19030. * @param {BaseNode} ast
  19031. * @param {{
  19032. * enter?: SyncHandler
  19033. * leave?: SyncHandler
  19034. * }} walker
  19035. * @returns {BaseNode}
  19036. */
  19037. function walk$2(ast, { enter, leave }) {
  19038. const instance = new SyncWalker(enter, leave);
  19039. return instance.visit(ast, null);
  19040. }
  19041. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
  19042. const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
  19043. walk$2(root, {
  19044. enter(node, parent) {
  19045. parent && parentStack.push(parent);
  19046. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  19047. return this.skip();
  19048. }
  19049. if (node.type === "Identifier") {
  19050. const isLocal = !!knownIds[node.name];
  19051. const isRefed = isReferencedIdentifier(node, parent, parentStack);
  19052. if (includeAll || isRefed && !isLocal) {
  19053. onIdentifier(node, parent, parentStack, isRefed, isLocal);
  19054. }
  19055. } else if (node.type === "ObjectProperty" && // eslint-disable-next-line no-restricted-syntax
  19056. (parent == null ? void 0 : parent.type) === "ObjectPattern") {
  19057. node.inPattern = true;
  19058. } else if (isFunctionType(node)) {
  19059. if (node.scopeIds) {
  19060. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  19061. } else {
  19062. walkFunctionParams(
  19063. node,
  19064. (id) => markScopeIdentifier(node, id, knownIds)
  19065. );
  19066. }
  19067. } else if (node.type === "BlockStatement") {
  19068. if (node.scopeIds) {
  19069. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  19070. } else {
  19071. walkBlockDeclarations(
  19072. node,
  19073. (id) => markScopeIdentifier(node, id, knownIds)
  19074. );
  19075. }
  19076. } else if (node.type === "SwitchStatement") {
  19077. if (node.scopeIds) {
  19078. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  19079. } else {
  19080. walkSwitchStatement(
  19081. node,
  19082. false,
  19083. (id) => markScopeIdentifier(node, id, knownIds)
  19084. );
  19085. }
  19086. } else if (node.type === "CatchClause" && node.param) {
  19087. if (node.scopeIds) {
  19088. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  19089. } else {
  19090. for (const id of extractIdentifiers$1(node.param)) {
  19091. markScopeIdentifier(node, id, knownIds);
  19092. }
  19093. }
  19094. } else if (isForStatement(node)) {
  19095. if (node.scopeIds) {
  19096. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  19097. } else {
  19098. walkForStatement(
  19099. node,
  19100. false,
  19101. (id) => markScopeIdentifier(node, id, knownIds)
  19102. );
  19103. }
  19104. }
  19105. },
  19106. leave(node, parent) {
  19107. parent && parentStack.pop();
  19108. if (node !== rootExp && node.scopeIds) {
  19109. for (const id of node.scopeIds) {
  19110. knownIds[id]--;
  19111. if (knownIds[id] === 0) {
  19112. delete knownIds[id];
  19113. }
  19114. }
  19115. }
  19116. }
  19117. });
  19118. }
  19119. function isReferencedIdentifier(id, parent, parentStack) {
  19120. if (!parent) {
  19121. return true;
  19122. }
  19123. if (id.name === "arguments") {
  19124. return false;
  19125. }
  19126. if (isReferenced(id, parent, parentStack[parentStack.length - 2])) {
  19127. return true;
  19128. }
  19129. switch (parent.type) {
  19130. case "AssignmentExpression":
  19131. case "AssignmentPattern":
  19132. return true;
  19133. case "ObjectProperty":
  19134. return parent.key !== id && isInDestructureAssignment(parent, parentStack);
  19135. case "ArrayPattern":
  19136. return isInDestructureAssignment(parent, parentStack);
  19137. }
  19138. return false;
  19139. }
  19140. function isInDestructureAssignment(parent, parentStack) {
  19141. if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
  19142. let i = parentStack.length;
  19143. while (i--) {
  19144. const p = parentStack[i];
  19145. if (p.type === "AssignmentExpression") {
  19146. return true;
  19147. } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
  19148. break;
  19149. }
  19150. }
  19151. }
  19152. return false;
  19153. }
  19154. function isInNewExpression(parentStack) {
  19155. let i = parentStack.length;
  19156. while (i--) {
  19157. const p = parentStack[i];
  19158. if (p.type === "NewExpression") {
  19159. return true;
  19160. } else if (p.type !== "MemberExpression") {
  19161. break;
  19162. }
  19163. }
  19164. return false;
  19165. }
  19166. function walkFunctionParams(node, onIdent) {
  19167. for (const p of node.params) {
  19168. for (const id of extractIdentifiers$1(p)) {
  19169. onIdent(id);
  19170. }
  19171. }
  19172. }
  19173. function walkBlockDeclarations(block, onIdent) {
  19174. const body = block.type === "SwitchCase" ? block.consequent : block.body;
  19175. for (const stmt of body) {
  19176. if (stmt.type === "VariableDeclaration") {
  19177. if (stmt.declare) continue;
  19178. for (const decl of stmt.declarations) {
  19179. for (const id of extractIdentifiers$1(decl.id)) {
  19180. onIdent(id);
  19181. }
  19182. }
  19183. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  19184. if (stmt.declare || !stmt.id) continue;
  19185. onIdent(stmt.id);
  19186. } else if (isForStatement(stmt)) {
  19187. walkForStatement(stmt, true, onIdent);
  19188. } else if (stmt.type === "SwitchStatement") {
  19189. walkSwitchStatement(stmt, true, onIdent);
  19190. }
  19191. }
  19192. }
  19193. function isForStatement(stmt) {
  19194. return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
  19195. }
  19196. function walkForStatement(stmt, isVar, onIdent) {
  19197. const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
  19198. if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) {
  19199. for (const decl of variable.declarations) {
  19200. for (const id of extractIdentifiers$1(decl.id)) {
  19201. onIdent(id);
  19202. }
  19203. }
  19204. }
  19205. }
  19206. function walkSwitchStatement(stmt, isVar, onIdent) {
  19207. for (const cs of stmt.cases) {
  19208. for (const stmt2 of cs.consequent) {
  19209. if (stmt2.type === "VariableDeclaration" && (stmt2.kind === "var" ? isVar : !isVar)) {
  19210. for (const decl of stmt2.declarations) {
  19211. for (const id of extractIdentifiers$1(decl.id)) {
  19212. onIdent(id);
  19213. }
  19214. }
  19215. }
  19216. }
  19217. walkBlockDeclarations(cs, onIdent);
  19218. }
  19219. }
  19220. function extractIdentifiers$1(param, nodes = []) {
  19221. switch (param.type) {
  19222. case "Identifier":
  19223. nodes.push(param);
  19224. break;
  19225. case "MemberExpression":
  19226. let object = param;
  19227. while (object.type === "MemberExpression") {
  19228. object = object.object;
  19229. }
  19230. nodes.push(object);
  19231. break;
  19232. case "ObjectPattern":
  19233. for (const prop of param.properties) {
  19234. if (prop.type === "RestElement") {
  19235. extractIdentifiers$1(prop.argument, nodes);
  19236. } else {
  19237. extractIdentifiers$1(prop.value, nodes);
  19238. }
  19239. }
  19240. break;
  19241. case "ArrayPattern":
  19242. param.elements.forEach((element) => {
  19243. if (element) extractIdentifiers$1(element, nodes);
  19244. });
  19245. break;
  19246. case "RestElement":
  19247. extractIdentifiers$1(param.argument, nodes);
  19248. break;
  19249. case "AssignmentPattern":
  19250. extractIdentifiers$1(param.left, nodes);
  19251. break;
  19252. }
  19253. return nodes;
  19254. }
  19255. function markKnownIds(name, knownIds) {
  19256. if (name in knownIds) {
  19257. knownIds[name]++;
  19258. } else {
  19259. knownIds[name] = 1;
  19260. }
  19261. }
  19262. function markScopeIdentifier(node, child, knownIds) {
  19263. const { name } = child;
  19264. if (node.scopeIds && node.scopeIds.has(name)) {
  19265. return;
  19266. }
  19267. markKnownIds(name, knownIds);
  19268. (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
  19269. }
  19270. const isFunctionType = (node) => {
  19271. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  19272. };
  19273. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  19274. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  19275. function isReferenced(node, parent, grandparent) {
  19276. switch (parent.type) {
  19277. // yes: PARENT[NODE]
  19278. // yes: NODE.child
  19279. // no: parent.NODE
  19280. case "MemberExpression":
  19281. case "OptionalMemberExpression":
  19282. if (parent.property === node) {
  19283. return !!parent.computed;
  19284. }
  19285. return parent.object === node;
  19286. case "JSXMemberExpression":
  19287. return parent.object === node;
  19288. // no: let NODE = init;
  19289. // yes: let id = NODE;
  19290. case "VariableDeclarator":
  19291. return parent.init === node;
  19292. // yes: () => NODE
  19293. // no: (NODE) => {}
  19294. case "ArrowFunctionExpression":
  19295. return parent.body === node;
  19296. // no: class { #NODE; }
  19297. // no: class { get #NODE() {} }
  19298. // no: class { #NODE() {} }
  19299. // no: class { fn() { return this.#NODE; } }
  19300. case "PrivateName":
  19301. return false;
  19302. // no: class { NODE() {} }
  19303. // yes: class { [NODE]() {} }
  19304. // no: class { foo(NODE) {} }
  19305. case "ClassMethod":
  19306. case "ClassPrivateMethod":
  19307. case "ObjectMethod":
  19308. if (parent.key === node) {
  19309. return !!parent.computed;
  19310. }
  19311. return false;
  19312. // yes: { [NODE]: "" }
  19313. // no: { NODE: "" }
  19314. // depends: { NODE }
  19315. // depends: { key: NODE }
  19316. case "ObjectProperty":
  19317. if (parent.key === node) {
  19318. return !!parent.computed;
  19319. }
  19320. return !grandparent || grandparent.type !== "ObjectPattern";
  19321. // no: class { NODE = value; }
  19322. // yes: class { [NODE] = value; }
  19323. // yes: class { key = NODE; }
  19324. case "ClassProperty":
  19325. if (parent.key === node) {
  19326. return !!parent.computed;
  19327. }
  19328. return true;
  19329. case "ClassPrivateProperty":
  19330. return parent.key !== node;
  19331. // no: class NODE {}
  19332. // yes: class Foo extends NODE {}
  19333. case "ClassDeclaration":
  19334. case "ClassExpression":
  19335. return parent.superClass === node;
  19336. // yes: left = NODE;
  19337. // no: NODE = right;
  19338. case "AssignmentExpression":
  19339. return parent.right === node;
  19340. // no: [NODE = foo] = [];
  19341. // yes: [foo = NODE] = [];
  19342. case "AssignmentPattern":
  19343. return parent.right === node;
  19344. // no: NODE: for (;;) {}
  19345. case "LabeledStatement":
  19346. return false;
  19347. // no: try {} catch (NODE) {}
  19348. case "CatchClause":
  19349. return false;
  19350. // no: function foo(...NODE) {}
  19351. case "RestElement":
  19352. return false;
  19353. case "BreakStatement":
  19354. case "ContinueStatement":
  19355. return false;
  19356. // no: function NODE() {}
  19357. // no: function foo(NODE) {}
  19358. case "FunctionDeclaration":
  19359. case "FunctionExpression":
  19360. return false;
  19361. // no: export NODE from "foo";
  19362. // no: export * as NODE from "foo";
  19363. case "ExportNamespaceSpecifier":
  19364. case "ExportDefaultSpecifier":
  19365. return false;
  19366. // no: export { foo as NODE };
  19367. // yes: export { NODE as foo };
  19368. // no: export { NODE as foo } from "foo";
  19369. case "ExportSpecifier":
  19370. if (grandparent == null ? void 0 : grandparent.source) {
  19371. return false;
  19372. }
  19373. return parent.local === node;
  19374. // no: import NODE from "foo";
  19375. // no: import * as NODE from "foo";
  19376. // no: import { NODE as foo } from "foo";
  19377. // no: import { foo as NODE } from "foo";
  19378. // no: import NODE from "bar";
  19379. case "ImportDefaultSpecifier":
  19380. case "ImportNamespaceSpecifier":
  19381. case "ImportSpecifier":
  19382. return false;
  19383. // no: import "foo" assert { NODE: "json" }
  19384. case "ImportAttribute":
  19385. return false;
  19386. // no: <div NODE="foo" />
  19387. case "JSXAttribute":
  19388. return false;
  19389. // no: [NODE] = [];
  19390. // no: ({ NODE }) = [];
  19391. case "ObjectPattern":
  19392. case "ArrayPattern":
  19393. return false;
  19394. // no: new.NODE
  19395. // no: NODE.target
  19396. case "MetaProperty":
  19397. return false;
  19398. // yes: type X = { someProperty: NODE }
  19399. // no: type X = { NODE: OtherType }
  19400. case "ObjectTypeProperty":
  19401. return parent.key !== node;
  19402. // yes: enum X { Foo = NODE }
  19403. // no: enum X { NODE }
  19404. case "TSEnumMember":
  19405. return parent.id !== node;
  19406. // yes: { [NODE]: value }
  19407. // no: { NODE: value }
  19408. case "TSPropertySignature":
  19409. if (parent.key === node) {
  19410. return !!parent.computed;
  19411. }
  19412. return true;
  19413. }
  19414. return true;
  19415. }
  19416. const TS_NODE_TYPES = [
  19417. "TSAsExpression",
  19418. // foo as number
  19419. "TSTypeAssertion",
  19420. // (<number>foo)
  19421. "TSNonNullExpression",
  19422. // foo!
  19423. "TSInstantiationExpression",
  19424. // foo<string>
  19425. "TSSatisfiesExpression"
  19426. // foo satisfies T
  19427. ];
  19428. function unwrapTSNode(node) {
  19429. if (TS_NODE_TYPES.includes(node.type)) {
  19430. return unwrapTSNode(node.expression);
  19431. } else {
  19432. return node;
  19433. }
  19434. }
  19435. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  19436. function isCoreComponent(tag) {
  19437. switch (tag) {
  19438. case "Teleport":
  19439. case "teleport":
  19440. return TELEPORT;
  19441. case "Suspense":
  19442. case "suspense":
  19443. return SUSPENSE;
  19444. case "KeepAlive":
  19445. case "keep-alive":
  19446. return KEEP_ALIVE;
  19447. case "BaseTransition":
  19448. case "base-transition":
  19449. return BASE_TRANSITION;
  19450. }
  19451. }
  19452. const nonIdentifierRE = /^$|^\d|[^\$\w\xA0-\uFFFF]/;
  19453. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  19454. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  19455. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  19456. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  19457. const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
  19458. const isMemberExpressionBrowser = (exp) => {
  19459. const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
  19460. let state = 0 /* inMemberExp */;
  19461. let stateStack = [];
  19462. let currentOpenBracketCount = 0;
  19463. let currentOpenParensCount = 0;
  19464. let currentStringType = null;
  19465. for (let i = 0; i < path.length; i++) {
  19466. const char = path.charAt(i);
  19467. switch (state) {
  19468. case 0 /* inMemberExp */:
  19469. if (char === "[") {
  19470. stateStack.push(state);
  19471. state = 1 /* inBrackets */;
  19472. currentOpenBracketCount++;
  19473. } else if (char === "(") {
  19474. stateStack.push(state);
  19475. state = 2 /* inParens */;
  19476. currentOpenParensCount++;
  19477. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  19478. return false;
  19479. }
  19480. break;
  19481. case 1 /* inBrackets */:
  19482. if (char === `'` || char === `"` || char === "`") {
  19483. stateStack.push(state);
  19484. state = 3 /* inString */;
  19485. currentStringType = char;
  19486. } else if (char === `[`) {
  19487. currentOpenBracketCount++;
  19488. } else if (char === `]`) {
  19489. if (!--currentOpenBracketCount) {
  19490. state = stateStack.pop();
  19491. }
  19492. }
  19493. break;
  19494. case 2 /* inParens */:
  19495. if (char === `'` || char === `"` || char === "`") {
  19496. stateStack.push(state);
  19497. state = 3 /* inString */;
  19498. currentStringType = char;
  19499. } else if (char === `(`) {
  19500. currentOpenParensCount++;
  19501. } else if (char === `)`) {
  19502. if (i === path.length - 1) {
  19503. return false;
  19504. }
  19505. if (!--currentOpenParensCount) {
  19506. state = stateStack.pop();
  19507. }
  19508. }
  19509. break;
  19510. case 3 /* inString */:
  19511. if (char === currentStringType) {
  19512. state = stateStack.pop();
  19513. currentStringType = null;
  19514. }
  19515. break;
  19516. }
  19517. }
  19518. return !currentOpenBracketCount && !currentOpenParensCount;
  19519. };
  19520. const isMemberExpressionNode = (exp, context) => {
  19521. try {
  19522. let ret = exp.ast || libExports.parseExpression(getExpSource(exp), {
  19523. plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
  19524. });
  19525. ret = unwrapTSNode(ret);
  19526. return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier" && ret.name !== "undefined";
  19527. } catch (e) {
  19528. return false;
  19529. }
  19530. };
  19531. const isMemberExpression = isMemberExpressionNode;
  19532. const fnExpRE = /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  19533. const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
  19534. const isFnExpressionNode = (exp, context) => {
  19535. try {
  19536. let ret = exp.ast || libExports.parseExpression(getExpSource(exp), {
  19537. plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
  19538. });
  19539. if (ret.type === "Program") {
  19540. ret = ret.body[0];
  19541. if (ret.type === "ExpressionStatement") {
  19542. ret = ret.expression;
  19543. }
  19544. }
  19545. ret = unwrapTSNode(ret);
  19546. return ret.type === "FunctionExpression" || ret.type === "ArrowFunctionExpression";
  19547. } catch (e) {
  19548. return false;
  19549. }
  19550. };
  19551. const isFnExpression = isFnExpressionNode;
  19552. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  19553. return advancePositionWithMutation(
  19554. {
  19555. offset: pos.offset,
  19556. line: pos.line,
  19557. column: pos.column
  19558. },
  19559. source,
  19560. numberOfCharacters
  19561. );
  19562. }
  19563. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  19564. let linesCount = 0;
  19565. let lastNewLinePos = -1;
  19566. for (let i = 0; i < numberOfCharacters; i++) {
  19567. if (source.charCodeAt(i) === 10) {
  19568. linesCount++;
  19569. lastNewLinePos = i;
  19570. }
  19571. }
  19572. pos.offset += numberOfCharacters;
  19573. pos.line += linesCount;
  19574. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  19575. return pos;
  19576. }
  19577. function assert(condition, msg) {
  19578. if (!condition) {
  19579. throw new Error(msg || `unexpected compiler condition`);
  19580. }
  19581. }
  19582. function findDir(node, name, allowEmpty = false) {
  19583. for (let i = 0; i < node.props.length; i++) {
  19584. const p = node.props[i];
  19585. if (p.type === 7 && (allowEmpty || p.exp) && (isString$1(name) ? p.name === name : name.test(p.name))) {
  19586. return p;
  19587. }
  19588. }
  19589. }
  19590. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  19591. for (let i = 0; i < node.props.length; i++) {
  19592. const p = node.props[i];
  19593. if (p.type === 6) {
  19594. if (dynamicOnly) continue;
  19595. if (p.name === name && (p.value || allowEmpty)) {
  19596. return p;
  19597. }
  19598. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  19599. return p;
  19600. }
  19601. }
  19602. }
  19603. function isStaticArgOf(arg, name) {
  19604. return !!(arg && isStaticExp(arg) && arg.content === name);
  19605. }
  19606. function hasDynamicKeyVBind(node) {
  19607. return node.props.some(
  19608. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  19609. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  19610. !p.arg.isStatic)
  19611. // v-bind:[foo]
  19612. );
  19613. }
  19614. function isText$1(node) {
  19615. return node.type === 5 || node.type === 2;
  19616. }
  19617. function isVPre(p) {
  19618. return p.type === 7 && p.name === "pre";
  19619. }
  19620. function isVSlot(p) {
  19621. return p.type === 7 && p.name === "slot";
  19622. }
  19623. function isTemplateNode(node) {
  19624. return node.type === 1 && node.tagType === 3;
  19625. }
  19626. function isSlotOutlet(node) {
  19627. return node.type === 1 && node.tagType === 2;
  19628. }
  19629. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  19630. function getUnnormalizedProps(props, callPath = []) {
  19631. if (props && !isString$1(props) && props.type === 14) {
  19632. const callee = props.callee;
  19633. if (!isString$1(callee) && propsHelperSet.has(callee)) {
  19634. return getUnnormalizedProps(
  19635. props.arguments[0],
  19636. callPath.concat(props)
  19637. );
  19638. }
  19639. }
  19640. return [props, callPath];
  19641. }
  19642. function injectProp(node, prop, context) {
  19643. let propsWithInjection;
  19644. let props = node.type === 13 ? node.props : node.arguments[2];
  19645. let callPath = [];
  19646. let parentCall;
  19647. if (props && !isString$1(props) && props.type === 14) {
  19648. const ret = getUnnormalizedProps(props);
  19649. props = ret[0];
  19650. callPath = ret[1];
  19651. parentCall = callPath[callPath.length - 1];
  19652. }
  19653. if (props == null || isString$1(props)) {
  19654. propsWithInjection = createObjectExpression([prop]);
  19655. } else if (props.type === 14) {
  19656. const first = props.arguments[0];
  19657. if (!isString$1(first) && first.type === 15) {
  19658. if (!hasProp(prop, first)) {
  19659. first.properties.unshift(prop);
  19660. }
  19661. } else {
  19662. if (props.callee === TO_HANDLERS) {
  19663. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  19664. createObjectExpression([prop]),
  19665. props
  19666. ]);
  19667. } else {
  19668. props.arguments.unshift(createObjectExpression([prop]));
  19669. }
  19670. }
  19671. !propsWithInjection && (propsWithInjection = props);
  19672. } else if (props.type === 15) {
  19673. if (!hasProp(prop, props)) {
  19674. props.properties.unshift(prop);
  19675. }
  19676. propsWithInjection = props;
  19677. } else {
  19678. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  19679. createObjectExpression([prop]),
  19680. props
  19681. ]);
  19682. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  19683. parentCall = callPath[callPath.length - 2];
  19684. }
  19685. }
  19686. if (node.type === 13) {
  19687. if (parentCall) {
  19688. parentCall.arguments[0] = propsWithInjection;
  19689. } else {
  19690. node.props = propsWithInjection;
  19691. }
  19692. } else {
  19693. if (parentCall) {
  19694. parentCall.arguments[0] = propsWithInjection;
  19695. } else {
  19696. node.arguments[2] = propsWithInjection;
  19697. }
  19698. }
  19699. }
  19700. function hasProp(prop, props) {
  19701. let result = false;
  19702. if (prop.key.type === 4) {
  19703. const propKeyName = prop.key.content;
  19704. result = props.properties.some(
  19705. (p) => p.key.type === 4 && p.key.content === propKeyName
  19706. );
  19707. }
  19708. return result;
  19709. }
  19710. function toValidAssetId(name, type) {
  19711. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  19712. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  19713. })}`;
  19714. }
  19715. function hasScopeRef(node, ids) {
  19716. if (!node || Object.keys(ids).length === 0) {
  19717. return false;
  19718. }
  19719. switch (node.type) {
  19720. case 1:
  19721. for (let i = 0; i < node.props.length; i++) {
  19722. const p = node.props[i];
  19723. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  19724. return true;
  19725. }
  19726. }
  19727. return node.children.some((c) => hasScopeRef(c, ids));
  19728. case 11:
  19729. if (hasScopeRef(node.source, ids)) {
  19730. return true;
  19731. }
  19732. return node.children.some((c) => hasScopeRef(c, ids));
  19733. case 9:
  19734. return node.branches.some((b) => hasScopeRef(b, ids));
  19735. case 10:
  19736. if (hasScopeRef(node.condition, ids)) {
  19737. return true;
  19738. }
  19739. return node.children.some((c) => hasScopeRef(c, ids));
  19740. case 4:
  19741. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  19742. case 8:
  19743. return node.children.some((c) => isObject$2(c) && hasScopeRef(c, ids));
  19744. case 5:
  19745. case 12:
  19746. return hasScopeRef(node.content, ids);
  19747. case 2:
  19748. case 3:
  19749. case 20:
  19750. return false;
  19751. default:
  19752. return false;
  19753. }
  19754. }
  19755. function getMemoedVNodeCall(node) {
  19756. if (node.type === 14 && node.callee === WITH_MEMO) {
  19757. return node.arguments[1].returns;
  19758. } else {
  19759. return node;
  19760. }
  19761. }
  19762. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
  19763. function isAllWhitespace(str) {
  19764. for (let i = 0; i < str.length; i++) {
  19765. if (!isWhitespace(str.charCodeAt(i))) {
  19766. return false;
  19767. }
  19768. }
  19769. return true;
  19770. }
  19771. function isWhitespaceText(node) {
  19772. return node.type === 2 && isAllWhitespace(node.content) || node.type === 12 && isWhitespaceText(node.content);
  19773. }
  19774. function isCommentOrWhitespace(node) {
  19775. return node.type === 3 || isWhitespaceText(node);
  19776. }
  19777. const defaultParserOptions = {
  19778. parseMode: "base",
  19779. ns: 0,
  19780. delimiters: [`{{`, `}}`],
  19781. getNamespace: () => 0,
  19782. isVoidTag: NO,
  19783. isPreTag: NO,
  19784. isIgnoreNewlineTag: NO,
  19785. isCustomElement: NO,
  19786. onError: defaultOnError,
  19787. onWarn: defaultOnWarn,
  19788. comments: true,
  19789. prefixIdentifiers: false
  19790. };
  19791. let currentOptions = defaultParserOptions;
  19792. let currentRoot = null;
  19793. let currentInput = "";
  19794. let currentOpenTag = null;
  19795. let currentProp = null;
  19796. let currentAttrValue = "";
  19797. let currentAttrStartIndex = -1;
  19798. let currentAttrEndIndex = -1;
  19799. let inPre = 0;
  19800. let inVPre = false;
  19801. let currentVPreBoundary = null;
  19802. const stack = [];
  19803. const tokenizer = new Tokenizer(stack, {
  19804. onerr: emitError,
  19805. ontext(start, end) {
  19806. onText(getSlice(start, end), start, end);
  19807. },
  19808. ontextentity(char, start, end) {
  19809. onText(char, start, end);
  19810. },
  19811. oninterpolation(start, end) {
  19812. if (inVPre) {
  19813. return onText(getSlice(start, end), start, end);
  19814. }
  19815. let innerStart = start + tokenizer.delimiterOpen.length;
  19816. let innerEnd = end - tokenizer.delimiterClose.length;
  19817. while (isWhitespace(currentInput.charCodeAt(innerStart))) {
  19818. innerStart++;
  19819. }
  19820. while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
  19821. innerEnd--;
  19822. }
  19823. let exp = getSlice(innerStart, innerEnd);
  19824. if (exp.includes("&")) {
  19825. {
  19826. exp = decodeHTML(exp);
  19827. }
  19828. }
  19829. addNode({
  19830. type: 5,
  19831. content: createExp(exp, false, getLoc(innerStart, innerEnd)),
  19832. loc: getLoc(start, end)
  19833. });
  19834. },
  19835. onopentagname(start, end) {
  19836. const name = getSlice(start, end);
  19837. currentOpenTag = {
  19838. type: 1,
  19839. tag: name,
  19840. ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
  19841. tagType: 0,
  19842. // will be refined on tag close
  19843. props: [],
  19844. children: [],
  19845. loc: getLoc(start - 1, end),
  19846. codegenNode: void 0
  19847. };
  19848. },
  19849. onopentagend(end) {
  19850. endOpenTag(end);
  19851. },
  19852. onclosetag(start, end) {
  19853. const name = getSlice(start, end);
  19854. if (!currentOptions.isVoidTag(name)) {
  19855. let found = false;
  19856. for (let i = 0; i < stack.length; i++) {
  19857. const e = stack[i];
  19858. if (e.tag.toLowerCase() === name.toLowerCase()) {
  19859. found = true;
  19860. if (i > 0) {
  19861. emitError(24, stack[0].loc.start.offset);
  19862. }
  19863. for (let j = 0; j <= i; j++) {
  19864. const el = stack.shift();
  19865. onCloseTag(el, end, j < i);
  19866. }
  19867. break;
  19868. }
  19869. }
  19870. if (!found) {
  19871. emitError(23, backTrack(start, 60));
  19872. }
  19873. }
  19874. },
  19875. onselfclosingtag(end) {
  19876. const name = currentOpenTag.tag;
  19877. currentOpenTag.isSelfClosing = true;
  19878. endOpenTag(end);
  19879. if (stack[0] && stack[0].tag === name) {
  19880. onCloseTag(stack.shift(), end);
  19881. }
  19882. },
  19883. onattribname(start, end) {
  19884. currentProp = {
  19885. type: 6,
  19886. name: getSlice(start, end),
  19887. nameLoc: getLoc(start, end),
  19888. value: void 0,
  19889. loc: getLoc(start)
  19890. };
  19891. },
  19892. ondirname(start, end) {
  19893. const raw = getSlice(start, end);
  19894. const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
  19895. if (!inVPre && name === "") {
  19896. emitError(26, start);
  19897. }
  19898. if (inVPre || name === "") {
  19899. currentProp = {
  19900. type: 6,
  19901. name: raw,
  19902. nameLoc: getLoc(start, end),
  19903. value: void 0,
  19904. loc: getLoc(start)
  19905. };
  19906. } else {
  19907. currentProp = {
  19908. type: 7,
  19909. name,
  19910. rawName: raw,
  19911. exp: void 0,
  19912. arg: void 0,
  19913. modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
  19914. loc: getLoc(start)
  19915. };
  19916. if (name === "pre") {
  19917. inVPre = tokenizer.inVPre = true;
  19918. currentVPreBoundary = currentOpenTag;
  19919. const props = currentOpenTag.props;
  19920. for (let i = 0; i < props.length; i++) {
  19921. if (props[i].type === 7) {
  19922. props[i] = dirToAttr(props[i]);
  19923. }
  19924. }
  19925. }
  19926. }
  19927. },
  19928. ondirarg(start, end) {
  19929. if (start === end) return;
  19930. const arg = getSlice(start, end);
  19931. if (inVPre && !isVPre(currentProp)) {
  19932. currentProp.name += arg;
  19933. setLocEnd(currentProp.nameLoc, end);
  19934. } else {
  19935. const isStatic = arg[0] !== `[`;
  19936. currentProp.arg = createExp(
  19937. isStatic ? arg : arg.slice(1, -1),
  19938. isStatic,
  19939. getLoc(start, end),
  19940. isStatic ? 3 : 0
  19941. );
  19942. }
  19943. },
  19944. ondirmodifier(start, end) {
  19945. const mod = getSlice(start, end);
  19946. if (inVPre && !isVPre(currentProp)) {
  19947. currentProp.name += "." + mod;
  19948. setLocEnd(currentProp.nameLoc, end);
  19949. } else if (currentProp.name === "slot") {
  19950. const arg = currentProp.arg;
  19951. if (arg) {
  19952. arg.content += "." + mod;
  19953. setLocEnd(arg.loc, end);
  19954. }
  19955. } else {
  19956. const exp = createSimpleExpression(mod, true, getLoc(start, end));
  19957. currentProp.modifiers.push(exp);
  19958. }
  19959. },
  19960. onattribdata(start, end) {
  19961. currentAttrValue += getSlice(start, end);
  19962. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  19963. currentAttrEndIndex = end;
  19964. },
  19965. onattribentity(char, start, end) {
  19966. currentAttrValue += char;
  19967. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  19968. currentAttrEndIndex = end;
  19969. },
  19970. onattribnameend(end) {
  19971. const start = currentProp.loc.start.offset;
  19972. const name = getSlice(start, end);
  19973. if (currentProp.type === 7) {
  19974. currentProp.rawName = name;
  19975. }
  19976. if (currentOpenTag.props.some(
  19977. (p) => (p.type === 7 ? p.rawName : p.name) === name
  19978. )) {
  19979. emitError(2, start);
  19980. }
  19981. },
  19982. onattribend(quote, end) {
  19983. if (currentOpenTag && currentProp) {
  19984. setLocEnd(currentProp.loc, end);
  19985. if (quote !== 0) {
  19986. if (currentProp.type === 6) {
  19987. if (currentProp.name === "class") {
  19988. currentAttrValue = condense(currentAttrValue).trim();
  19989. }
  19990. if (quote === 1 && !currentAttrValue) {
  19991. emitError(13, end);
  19992. }
  19993. currentProp.value = {
  19994. type: 2,
  19995. content: currentAttrValue,
  19996. loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
  19997. };
  19998. if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
  19999. tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
  20000. }
  20001. } else {
  20002. let expParseMode = 0 /* Normal */;
  20003. {
  20004. if (currentProp.name === "for") {
  20005. expParseMode = 3 /* Skip */;
  20006. } else if (currentProp.name === "slot") {
  20007. expParseMode = 1 /* Params */;
  20008. } else if (currentProp.name === "on" && currentAttrValue.includes(";")) {
  20009. expParseMode = 2 /* Statements */;
  20010. }
  20011. }
  20012. currentProp.exp = createExp(
  20013. currentAttrValue,
  20014. false,
  20015. getLoc(currentAttrStartIndex, currentAttrEndIndex),
  20016. 0,
  20017. expParseMode
  20018. );
  20019. if (currentProp.name === "for") {
  20020. currentProp.forParseResult = parseForExpression(currentProp.exp);
  20021. }
  20022. }
  20023. }
  20024. if (currentProp.type !== 7 || currentProp.name !== "pre") {
  20025. currentOpenTag.props.push(currentProp);
  20026. }
  20027. }
  20028. currentAttrValue = "";
  20029. currentAttrStartIndex = currentAttrEndIndex = -1;
  20030. },
  20031. oncomment(start, end) {
  20032. if (currentOptions.comments) {
  20033. addNode({
  20034. type: 3,
  20035. content: getSlice(start, end),
  20036. loc: getLoc(start - 4, end + 3)
  20037. });
  20038. }
  20039. },
  20040. onend() {
  20041. const end = currentInput.length;
  20042. if (tokenizer.state !== 1) {
  20043. switch (tokenizer.state) {
  20044. case 5:
  20045. case 8:
  20046. emitError(5, end);
  20047. break;
  20048. case 3:
  20049. case 4:
  20050. emitError(
  20051. 25,
  20052. tokenizer.sectionStart
  20053. );
  20054. break;
  20055. case 28:
  20056. if (tokenizer.currentSequence === Sequences.CdataEnd) {
  20057. emitError(6, end);
  20058. } else {
  20059. emitError(7, end);
  20060. }
  20061. break;
  20062. case 6:
  20063. case 7:
  20064. case 9:
  20065. case 11:
  20066. case 12:
  20067. case 13:
  20068. case 14:
  20069. case 15:
  20070. case 16:
  20071. case 17:
  20072. case 18:
  20073. case 19:
  20074. // "
  20075. case 20:
  20076. // '
  20077. case 21:
  20078. emitError(9, end);
  20079. break;
  20080. }
  20081. }
  20082. for (let index = 0; index < stack.length; index++) {
  20083. onCloseTag(stack[index], end - 1);
  20084. emitError(24, stack[index].loc.start.offset);
  20085. }
  20086. },
  20087. oncdata(start, end) {
  20088. if (stack[0].ns !== 0) {
  20089. onText(getSlice(start, end), start, end);
  20090. } else {
  20091. emitError(1, start - 9);
  20092. }
  20093. },
  20094. onprocessinginstruction(start) {
  20095. if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  20096. emitError(
  20097. 21,
  20098. start - 1
  20099. );
  20100. }
  20101. }
  20102. });
  20103. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  20104. const stripParensRE = /^\(|\)$/g;
  20105. function parseForExpression(input) {
  20106. const loc = input.loc;
  20107. const exp = input.content;
  20108. const inMatch = exp.match(forAliasRE);
  20109. if (!inMatch) return;
  20110. const [, LHS, RHS] = inMatch;
  20111. const createAliasExpression = (content, offset, asParam = false) => {
  20112. const start = loc.start.offset + offset;
  20113. const end = start + content.length;
  20114. return createExp(
  20115. content,
  20116. false,
  20117. getLoc(start, end),
  20118. 0,
  20119. asParam ? 1 /* Params */ : 0 /* Normal */
  20120. );
  20121. };
  20122. const result = {
  20123. source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
  20124. value: void 0,
  20125. key: void 0,
  20126. index: void 0,
  20127. finalized: false
  20128. };
  20129. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  20130. const trimmedOffset = LHS.indexOf(valueContent);
  20131. const iteratorMatch = valueContent.match(forIteratorRE);
  20132. if (iteratorMatch) {
  20133. valueContent = valueContent.replace(forIteratorRE, "").trim();
  20134. const keyContent = iteratorMatch[1].trim();
  20135. let keyOffset;
  20136. if (keyContent) {
  20137. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  20138. result.key = createAliasExpression(keyContent, keyOffset, true);
  20139. }
  20140. if (iteratorMatch[2]) {
  20141. const indexContent = iteratorMatch[2].trim();
  20142. if (indexContent) {
  20143. result.index = createAliasExpression(
  20144. indexContent,
  20145. exp.indexOf(
  20146. indexContent,
  20147. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  20148. ),
  20149. true
  20150. );
  20151. }
  20152. }
  20153. }
  20154. if (valueContent) {
  20155. result.value = createAliasExpression(valueContent, trimmedOffset, true);
  20156. }
  20157. return result;
  20158. }
  20159. function getSlice(start, end) {
  20160. return currentInput.slice(start, end);
  20161. }
  20162. function endOpenTag(end) {
  20163. if (tokenizer.inSFCRoot) {
  20164. currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
  20165. }
  20166. addNode(currentOpenTag);
  20167. const { tag, ns } = currentOpenTag;
  20168. if (ns === 0 && currentOptions.isPreTag(tag)) {
  20169. inPre++;
  20170. }
  20171. if (currentOptions.isVoidTag(tag)) {
  20172. onCloseTag(currentOpenTag, end);
  20173. } else {
  20174. stack.unshift(currentOpenTag);
  20175. if (ns === 1 || ns === 2) {
  20176. tokenizer.inXML = true;
  20177. }
  20178. }
  20179. currentOpenTag = null;
  20180. }
  20181. function onText(content, start, end) {
  20182. const parent = stack[0] || currentRoot;
  20183. const lastNode = parent.children[parent.children.length - 1];
  20184. if (lastNode && lastNode.type === 2) {
  20185. lastNode.content += content;
  20186. setLocEnd(lastNode.loc, end);
  20187. } else {
  20188. parent.children.push({
  20189. type: 2,
  20190. content,
  20191. loc: getLoc(start, end)
  20192. });
  20193. }
  20194. }
  20195. function onCloseTag(el, end, isImplied = false) {
  20196. if (isImplied) {
  20197. setLocEnd(el.loc, backTrack(end, 60));
  20198. } else {
  20199. setLocEnd(el.loc, lookAhead(end, 62) + 1);
  20200. }
  20201. if (tokenizer.inSFCRoot) {
  20202. if (el.children.length) {
  20203. el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
  20204. } else {
  20205. el.innerLoc.end = extend({}, el.innerLoc.start);
  20206. }
  20207. el.innerLoc.source = getSlice(
  20208. el.innerLoc.start.offset,
  20209. el.innerLoc.end.offset
  20210. );
  20211. }
  20212. const { tag, ns, children } = el;
  20213. if (!inVPre) {
  20214. if (tag === "slot") {
  20215. el.tagType = 2;
  20216. } else if (isFragmentTemplate(el)) {
  20217. el.tagType = 3;
  20218. } else if (isComponent(el)) {
  20219. el.tagType = 1;
  20220. }
  20221. }
  20222. if (!tokenizer.inRCDATA) {
  20223. el.children = condenseWhitespace(children);
  20224. }
  20225. if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
  20226. const first = children[0];
  20227. if (first && first.type === 2) {
  20228. first.content = first.content.replace(/^\r?\n/, "");
  20229. }
  20230. }
  20231. if (ns === 0 && currentOptions.isPreTag(tag)) {
  20232. inPre--;
  20233. }
  20234. if (currentVPreBoundary === el) {
  20235. inVPre = tokenizer.inVPre = false;
  20236. currentVPreBoundary = null;
  20237. }
  20238. if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  20239. tokenizer.inXML = false;
  20240. }
  20241. }
  20242. function lookAhead(index, c) {
  20243. let i = index;
  20244. while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
  20245. return i;
  20246. }
  20247. function backTrack(index, c) {
  20248. let i = index;
  20249. while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
  20250. return i;
  20251. }
  20252. const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
  20253. function isFragmentTemplate({ tag, props }) {
  20254. if (tag === "template") {
  20255. for (let i = 0; i < props.length; i++) {
  20256. if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
  20257. return true;
  20258. }
  20259. }
  20260. }
  20261. return false;
  20262. }
  20263. function isComponent({ tag, props }) {
  20264. if (currentOptions.isCustomElement(tag)) {
  20265. return false;
  20266. }
  20267. if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
  20268. return true;
  20269. }
  20270. for (let i = 0; i < props.length; i++) {
  20271. const p = props[i];
  20272. if (p.type === 6) {
  20273. if (p.name === "is" && p.value) {
  20274. if (p.value.content.startsWith("vue:")) {
  20275. return true;
  20276. }
  20277. }
  20278. }
  20279. }
  20280. return false;
  20281. }
  20282. function isUpperCase(c) {
  20283. return c > 64 && c < 91;
  20284. }
  20285. const windowsNewlineRE = /\r\n/g;
  20286. function condenseWhitespace(nodes) {
  20287. const shouldCondense = currentOptions.whitespace !== "preserve";
  20288. let removedWhitespace = false;
  20289. for (let i = 0; i < nodes.length; i++) {
  20290. const node = nodes[i];
  20291. if (node.type === 2) {
  20292. if (!inPre) {
  20293. if (isAllWhitespace(node.content)) {
  20294. const prev = nodes[i - 1] && nodes[i - 1].type;
  20295. const next = nodes[i + 1] && nodes[i + 1].type;
  20296. if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
  20297. removedWhitespace = true;
  20298. nodes[i] = null;
  20299. } else {
  20300. node.content = " ";
  20301. }
  20302. } else if (shouldCondense) {
  20303. node.content = condense(node.content);
  20304. }
  20305. } else {
  20306. node.content = node.content.replace(windowsNewlineRE, "\n");
  20307. }
  20308. }
  20309. }
  20310. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  20311. }
  20312. function hasNewlineChar(str) {
  20313. for (let i = 0; i < str.length; i++) {
  20314. const c = str.charCodeAt(i);
  20315. if (c === 10 || c === 13) {
  20316. return true;
  20317. }
  20318. }
  20319. return false;
  20320. }
  20321. function condense(str) {
  20322. let ret = "";
  20323. let prevCharIsWhitespace = false;
  20324. for (let i = 0; i < str.length; i++) {
  20325. if (isWhitespace(str.charCodeAt(i))) {
  20326. if (!prevCharIsWhitespace) {
  20327. ret += " ";
  20328. prevCharIsWhitespace = true;
  20329. }
  20330. } else {
  20331. ret += str[i];
  20332. prevCharIsWhitespace = false;
  20333. }
  20334. }
  20335. return ret;
  20336. }
  20337. function addNode(node) {
  20338. (stack[0] || currentRoot).children.push(node);
  20339. }
  20340. function getLoc(start, end) {
  20341. return {
  20342. start: tokenizer.getPos(start),
  20343. // @ts-expect-error allow late attachment
  20344. end: end == null ? end : tokenizer.getPos(end),
  20345. // @ts-expect-error allow late attachment
  20346. source: end == null ? end : getSlice(start, end)
  20347. };
  20348. }
  20349. function cloneLoc(loc) {
  20350. return getLoc(loc.start.offset, loc.end.offset);
  20351. }
  20352. function setLocEnd(loc, end) {
  20353. loc.end = tokenizer.getPos(end);
  20354. loc.source = getSlice(loc.start.offset, end);
  20355. }
  20356. function dirToAttr(dir) {
  20357. const attr = {
  20358. type: 6,
  20359. name: dir.rawName,
  20360. nameLoc: getLoc(
  20361. dir.loc.start.offset,
  20362. dir.loc.start.offset + dir.rawName.length
  20363. ),
  20364. value: void 0,
  20365. loc: dir.loc
  20366. };
  20367. if (dir.exp) {
  20368. const loc = dir.exp.loc;
  20369. if (loc.end.offset < dir.loc.end.offset) {
  20370. loc.start.offset--;
  20371. loc.start.column--;
  20372. loc.end.offset++;
  20373. loc.end.column++;
  20374. }
  20375. attr.value = {
  20376. type: 2,
  20377. content: dir.exp.content,
  20378. loc
  20379. };
  20380. }
  20381. return attr;
  20382. }
  20383. function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
  20384. const exp = createSimpleExpression(content, isStatic, loc, constType);
  20385. if (!isStatic && currentOptions.prefixIdentifiers && parseMode !== 3 /* Skip */ && content.trim()) {
  20386. if (isSimpleIdentifier(content)) {
  20387. exp.ast = null;
  20388. return exp;
  20389. }
  20390. try {
  20391. const plugins = currentOptions.expressionPlugins;
  20392. const options = {
  20393. plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
  20394. };
  20395. if (parseMode === 2 /* Statements */) {
  20396. exp.ast = libExports.parse(` ${content} `, options).program;
  20397. } else if (parseMode === 1 /* Params */) {
  20398. exp.ast = libExports.parseExpression(`(${content})=>{}`, options);
  20399. } else {
  20400. exp.ast = libExports.parseExpression(`(${content})`, options);
  20401. }
  20402. } catch (e) {
  20403. exp.ast = false;
  20404. emitError(46, loc.start.offset, e.message);
  20405. }
  20406. }
  20407. return exp;
  20408. }
  20409. function emitError(code, index, message) {
  20410. currentOptions.onError(
  20411. createCompilerError(code, getLoc(index, index), void 0, message)
  20412. );
  20413. }
  20414. function reset() {
  20415. tokenizer.reset();
  20416. currentOpenTag = null;
  20417. currentProp = null;
  20418. currentAttrValue = "";
  20419. currentAttrStartIndex = -1;
  20420. currentAttrEndIndex = -1;
  20421. stack.length = 0;
  20422. }
  20423. function baseParse(input, options) {
  20424. reset();
  20425. currentInput = input;
  20426. currentOptions = extend({}, defaultParserOptions);
  20427. if (options) {
  20428. let key;
  20429. for (key in options) {
  20430. if (options[key] != null) {
  20431. currentOptions[key] = options[key];
  20432. }
  20433. }
  20434. }
  20435. {
  20436. if (currentOptions.decodeEntities) {
  20437. console.warn(
  20438. `[@vue/compiler-core] decodeEntities option is passed but will be ignored in non-browser builds.`
  20439. );
  20440. }
  20441. }
  20442. tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
  20443. tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
  20444. const delimiters = options && options.delimiters;
  20445. if (delimiters) {
  20446. tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
  20447. tokenizer.delimiterClose = toCharCodes(delimiters[1]);
  20448. }
  20449. const root = currentRoot = createRoot([], input);
  20450. tokenizer.parse(currentInput);
  20451. root.loc = getLoc(0, input.length);
  20452. root.children = condenseWhitespace(root.children);
  20453. currentRoot = null;
  20454. return root;
  20455. }
  20456. function cacheStatic(root, context) {
  20457. walk$1(
  20458. root,
  20459. void 0,
  20460. context,
  20461. // Root node is unfortunately non-hoistable due to potential parent
  20462. // fallthrough attributes.
  20463. !!getSingleElementRoot(root)
  20464. );
  20465. }
  20466. function getSingleElementRoot(root) {
  20467. const children = root.children.filter((x) => x.type !== 3);
  20468. return children.length === 1 && children[0].type === 1 && !isSlotOutlet(children[0]) ? children[0] : null;
  20469. }
  20470. function walk$1(node, parent, context, doNotHoistNode = false, inFor = false) {
  20471. const { children } = node;
  20472. const toCache = [];
  20473. for (let i = 0; i < children.length; i++) {
  20474. const child = children[i];
  20475. if (child.type === 1 && child.tagType === 0) {
  20476. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  20477. if (constantType > 0) {
  20478. if (constantType >= 2) {
  20479. child.codegenNode.patchFlag = -1;
  20480. toCache.push(child);
  20481. continue;
  20482. }
  20483. } else {
  20484. const codegenNode = child.codegenNode;
  20485. if (codegenNode.type === 13) {
  20486. const flag = codegenNode.patchFlag;
  20487. if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  20488. const props = getNodeProps(child);
  20489. if (props) {
  20490. codegenNode.props = context.hoist(props);
  20491. }
  20492. }
  20493. if (codegenNode.dynamicProps) {
  20494. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  20495. }
  20496. }
  20497. }
  20498. } else if (child.type === 12) {
  20499. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  20500. if (constantType >= 2) {
  20501. if (child.codegenNode.type === 14 && child.codegenNode.arguments.length > 0) {
  20502. child.codegenNode.arguments.push(
  20503. -1 + (` /* ${PatchFlagNames[-1]} */` )
  20504. );
  20505. }
  20506. toCache.push(child);
  20507. continue;
  20508. }
  20509. }
  20510. if (child.type === 1) {
  20511. const isComponent = child.tagType === 1;
  20512. if (isComponent) {
  20513. context.scopes.vSlot++;
  20514. }
  20515. walk$1(child, node, context, false, inFor);
  20516. if (isComponent) {
  20517. context.scopes.vSlot--;
  20518. }
  20519. } else if (child.type === 11) {
  20520. walk$1(child, node, context, child.children.length === 1, true);
  20521. } else if (child.type === 9) {
  20522. for (let i2 = 0; i2 < child.branches.length; i2++) {
  20523. walk$1(
  20524. child.branches[i2],
  20525. node,
  20526. context,
  20527. child.branches[i2].children.length === 1,
  20528. inFor
  20529. );
  20530. }
  20531. }
  20532. }
  20533. let cachedAsArray = false;
  20534. if (toCache.length === children.length && node.type === 1) {
  20535. if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray$3(node.codegenNode.children)) {
  20536. node.codegenNode.children = getCacheExpression(
  20537. createArrayExpression(node.codegenNode.children)
  20538. );
  20539. cachedAsArray = true;
  20540. } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray$3(node.codegenNode.children) && node.codegenNode.children.type === 15) {
  20541. const slot = getSlotNode(node.codegenNode, "default");
  20542. if (slot) {
  20543. slot.returns = getCacheExpression(
  20544. createArrayExpression(slot.returns)
  20545. );
  20546. cachedAsArray = true;
  20547. }
  20548. } else if (node.tagType === 3 && parent && parent.type === 1 && parent.tagType === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray$3(parent.codegenNode.children) && parent.codegenNode.children.type === 15) {
  20549. const slotName = findDir(node, "slot", true);
  20550. const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
  20551. if (slot) {
  20552. slot.returns = getCacheExpression(
  20553. createArrayExpression(slot.returns)
  20554. );
  20555. cachedAsArray = true;
  20556. }
  20557. }
  20558. }
  20559. if (!cachedAsArray) {
  20560. for (const child of toCache) {
  20561. child.codegenNode = context.cache(child.codegenNode);
  20562. }
  20563. }
  20564. function getCacheExpression(value) {
  20565. const exp = context.cache(value);
  20566. exp.needArraySpread = true;
  20567. return exp;
  20568. }
  20569. function getSlotNode(node2, name) {
  20570. if (node2.children && !isArray$3(node2.children) && node2.children.type === 15) {
  20571. const slot = node2.children.properties.find(
  20572. (p) => p.key === name || p.key.content === name
  20573. );
  20574. return slot && slot.value;
  20575. }
  20576. }
  20577. if (toCache.length && context.transformHoist) {
  20578. context.transformHoist(children, context, node);
  20579. }
  20580. }
  20581. function getConstantType(node, context) {
  20582. const { constantCache } = context;
  20583. switch (node.type) {
  20584. case 1:
  20585. if (node.tagType !== 0) {
  20586. return 0;
  20587. }
  20588. const cached = constantCache.get(node);
  20589. if (cached !== void 0) {
  20590. return cached;
  20591. }
  20592. const codegenNode = node.codegenNode;
  20593. if (codegenNode.type !== 13) {
  20594. return 0;
  20595. }
  20596. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
  20597. return 0;
  20598. }
  20599. if (codegenNode.patchFlag === void 0) {
  20600. let returnType2 = 3;
  20601. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  20602. if (generatedPropsType === 0) {
  20603. constantCache.set(node, 0);
  20604. return 0;
  20605. }
  20606. if (generatedPropsType < returnType2) {
  20607. returnType2 = generatedPropsType;
  20608. }
  20609. for (let i = 0; i < node.children.length; i++) {
  20610. const childType = getConstantType(node.children[i], context);
  20611. if (childType === 0) {
  20612. constantCache.set(node, 0);
  20613. return 0;
  20614. }
  20615. if (childType < returnType2) {
  20616. returnType2 = childType;
  20617. }
  20618. }
  20619. if (returnType2 > 1) {
  20620. for (let i = 0; i < node.props.length; i++) {
  20621. const p = node.props[i];
  20622. if (p.type === 7 && p.name === "bind" && p.exp) {
  20623. const expType = getConstantType(p.exp, context);
  20624. if (expType === 0) {
  20625. constantCache.set(node, 0);
  20626. return 0;
  20627. }
  20628. if (expType < returnType2) {
  20629. returnType2 = expType;
  20630. }
  20631. }
  20632. }
  20633. }
  20634. if (codegenNode.isBlock) {
  20635. for (let i = 0; i < node.props.length; i++) {
  20636. const p = node.props[i];
  20637. if (p.type === 7) {
  20638. constantCache.set(node, 0);
  20639. return 0;
  20640. }
  20641. }
  20642. context.removeHelper(OPEN_BLOCK);
  20643. context.removeHelper(
  20644. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  20645. );
  20646. codegenNode.isBlock = false;
  20647. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  20648. }
  20649. constantCache.set(node, returnType2);
  20650. return returnType2;
  20651. } else {
  20652. constantCache.set(node, 0);
  20653. return 0;
  20654. }
  20655. case 2:
  20656. case 3:
  20657. return 3;
  20658. case 9:
  20659. case 11:
  20660. case 10:
  20661. return 0;
  20662. case 5:
  20663. case 12:
  20664. return getConstantType(node.content, context);
  20665. case 4:
  20666. return node.constType;
  20667. case 8:
  20668. let returnType = 3;
  20669. for (let i = 0; i < node.children.length; i++) {
  20670. const child = node.children[i];
  20671. if (isString$1(child) || isSymbol$1(child)) {
  20672. continue;
  20673. }
  20674. const childType = getConstantType(child, context);
  20675. if (childType === 0) {
  20676. return 0;
  20677. } else if (childType < returnType) {
  20678. returnType = childType;
  20679. }
  20680. }
  20681. return returnType;
  20682. case 20:
  20683. return 2;
  20684. default:
  20685. return 0;
  20686. }
  20687. }
  20688. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  20689. NORMALIZE_CLASS,
  20690. NORMALIZE_STYLE,
  20691. NORMALIZE_PROPS,
  20692. GUARD_REACTIVE_PROPS
  20693. ]);
  20694. function getConstantTypeOfHelperCall(value, context) {
  20695. if (value.type === 14 && !isString$1(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  20696. const arg = value.arguments[0];
  20697. if (arg.type === 4) {
  20698. return getConstantType(arg, context);
  20699. } else if (arg.type === 14) {
  20700. return getConstantTypeOfHelperCall(arg, context);
  20701. }
  20702. }
  20703. return 0;
  20704. }
  20705. function getGeneratedPropsConstantType(node, context) {
  20706. let returnType = 3;
  20707. const props = getNodeProps(node);
  20708. if (props && props.type === 15) {
  20709. const { properties } = props;
  20710. for (let i = 0; i < properties.length; i++) {
  20711. const { key, value } = properties[i];
  20712. const keyType = getConstantType(key, context);
  20713. if (keyType === 0) {
  20714. return keyType;
  20715. }
  20716. if (keyType < returnType) {
  20717. returnType = keyType;
  20718. }
  20719. let valueType;
  20720. if (value.type === 4) {
  20721. valueType = getConstantType(value, context);
  20722. } else if (value.type === 14) {
  20723. valueType = getConstantTypeOfHelperCall(value, context);
  20724. } else {
  20725. valueType = 0;
  20726. }
  20727. if (valueType === 0) {
  20728. return valueType;
  20729. }
  20730. if (valueType < returnType) {
  20731. returnType = valueType;
  20732. }
  20733. }
  20734. }
  20735. return returnType;
  20736. }
  20737. function getNodeProps(node) {
  20738. const codegenNode = node.codegenNode;
  20739. if (codegenNode.type === 13) {
  20740. return codegenNode.props;
  20741. }
  20742. }
  20743. function createTransformContext(root, {
  20744. filename = "",
  20745. prefixIdentifiers = false,
  20746. hoistStatic = false,
  20747. hmr = false,
  20748. cacheHandlers = false,
  20749. nodeTransforms = [],
  20750. directiveTransforms = {},
  20751. transformHoist = null,
  20752. isBuiltInComponent = NOOP,
  20753. isCustomElement = NOOP,
  20754. expressionPlugins = [],
  20755. scopeId = null,
  20756. slotted = true,
  20757. ssr = false,
  20758. inSSR = false,
  20759. ssrCssVars = ``,
  20760. bindingMetadata = EMPTY_OBJ,
  20761. inline = false,
  20762. isTS = false,
  20763. onError = defaultOnError,
  20764. onWarn = defaultOnWarn,
  20765. compatConfig
  20766. }) {
  20767. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  20768. const context = {
  20769. // options
  20770. filename,
  20771. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  20772. prefixIdentifiers,
  20773. hoistStatic,
  20774. hmr,
  20775. cacheHandlers,
  20776. nodeTransforms,
  20777. directiveTransforms,
  20778. transformHoist,
  20779. isBuiltInComponent,
  20780. isCustomElement,
  20781. expressionPlugins,
  20782. scopeId,
  20783. slotted,
  20784. ssr,
  20785. inSSR,
  20786. ssrCssVars,
  20787. bindingMetadata,
  20788. inline,
  20789. isTS,
  20790. onError,
  20791. onWarn,
  20792. compatConfig,
  20793. // state
  20794. root,
  20795. helpers: /* @__PURE__ */ new Map(),
  20796. components: /* @__PURE__ */ new Set(),
  20797. directives: /* @__PURE__ */ new Set(),
  20798. hoists: [],
  20799. imports: [],
  20800. cached: [],
  20801. constantCache: /* @__PURE__ */ new WeakMap(),
  20802. temps: 0,
  20803. identifiers: /* @__PURE__ */ Object.create(null),
  20804. scopes: {
  20805. vFor: 0,
  20806. vSlot: 0,
  20807. vPre: 0,
  20808. vOnce: 0
  20809. },
  20810. parent: null,
  20811. grandParent: null,
  20812. currentNode: root,
  20813. childIndex: 0,
  20814. inVOnce: false,
  20815. // methods
  20816. helper(name) {
  20817. const count = context.helpers.get(name) || 0;
  20818. context.helpers.set(name, count + 1);
  20819. return name;
  20820. },
  20821. removeHelper(name) {
  20822. const count = context.helpers.get(name);
  20823. if (count) {
  20824. const currentCount = count - 1;
  20825. if (!currentCount) {
  20826. context.helpers.delete(name);
  20827. } else {
  20828. context.helpers.set(name, currentCount);
  20829. }
  20830. }
  20831. },
  20832. helperString(name) {
  20833. return `_${helperNameMap[context.helper(name)]}`;
  20834. },
  20835. replaceNode(node) {
  20836. {
  20837. if (!context.currentNode) {
  20838. throw new Error(`Node being replaced is already removed.`);
  20839. }
  20840. if (!context.parent) {
  20841. throw new Error(`Cannot replace root node.`);
  20842. }
  20843. }
  20844. context.parent.children[context.childIndex] = context.currentNode = node;
  20845. },
  20846. removeNode(node) {
  20847. if (!context.parent) {
  20848. throw new Error(`Cannot remove root node.`);
  20849. }
  20850. const list = context.parent.children;
  20851. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  20852. if (removalIndex < 0) {
  20853. throw new Error(`node being removed is not a child of current parent`);
  20854. }
  20855. if (!node || node === context.currentNode) {
  20856. context.currentNode = null;
  20857. context.onNodeRemoved();
  20858. } else {
  20859. if (context.childIndex > removalIndex) {
  20860. context.childIndex--;
  20861. context.onNodeRemoved();
  20862. }
  20863. }
  20864. context.parent.children.splice(removalIndex, 1);
  20865. },
  20866. onNodeRemoved: NOOP,
  20867. addIdentifiers(exp) {
  20868. {
  20869. if (isString$1(exp)) {
  20870. addId(exp);
  20871. } else if (exp.identifiers) {
  20872. exp.identifiers.forEach(addId);
  20873. } else if (exp.type === 4) {
  20874. addId(exp.content);
  20875. }
  20876. }
  20877. },
  20878. removeIdentifiers(exp) {
  20879. {
  20880. if (isString$1(exp)) {
  20881. removeId(exp);
  20882. } else if (exp.identifiers) {
  20883. exp.identifiers.forEach(removeId);
  20884. } else if (exp.type === 4) {
  20885. removeId(exp.content);
  20886. }
  20887. }
  20888. },
  20889. hoist(exp) {
  20890. if (isString$1(exp)) exp = createSimpleExpression(exp);
  20891. context.hoists.push(exp);
  20892. const identifier = createSimpleExpression(
  20893. `_hoisted_${context.hoists.length}`,
  20894. false,
  20895. exp.loc,
  20896. 2
  20897. );
  20898. identifier.hoisted = exp;
  20899. return identifier;
  20900. },
  20901. cache(exp, isVNode = false, inVOnce = false) {
  20902. const cacheExp = createCacheExpression(
  20903. context.cached.length,
  20904. exp,
  20905. isVNode,
  20906. inVOnce
  20907. );
  20908. context.cached.push(cacheExp);
  20909. return cacheExp;
  20910. }
  20911. };
  20912. function addId(id) {
  20913. const { identifiers } = context;
  20914. if (identifiers[id] === void 0) {
  20915. identifiers[id] = 0;
  20916. }
  20917. identifiers[id]++;
  20918. }
  20919. function removeId(id) {
  20920. context.identifiers[id]--;
  20921. }
  20922. return context;
  20923. }
  20924. function transform(root, options) {
  20925. const context = createTransformContext(root, options);
  20926. traverseNode(root, context);
  20927. if (options.hoistStatic) {
  20928. cacheStatic(root, context);
  20929. }
  20930. if (!options.ssr) {
  20931. createRootCodegen(root, context);
  20932. }
  20933. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  20934. root.components = [...context.components];
  20935. root.directives = [...context.directives];
  20936. root.imports = context.imports;
  20937. root.hoists = context.hoists;
  20938. root.temps = context.temps;
  20939. root.cached = context.cached;
  20940. root.transformed = true;
  20941. }
  20942. function createRootCodegen(root, context) {
  20943. const { helper } = context;
  20944. const { children } = root;
  20945. if (children.length === 1) {
  20946. const singleElementRootChild = getSingleElementRoot(root);
  20947. if (singleElementRootChild && singleElementRootChild.codegenNode) {
  20948. const codegenNode = singleElementRootChild.codegenNode;
  20949. if (codegenNode.type === 13) {
  20950. convertToBlock(codegenNode, context);
  20951. }
  20952. root.codegenNode = codegenNode;
  20953. } else {
  20954. root.codegenNode = children[0];
  20955. }
  20956. } else if (children.length > 1) {
  20957. let patchFlag = 64;
  20958. if (children.filter((c) => c.type !== 3).length === 1) {
  20959. patchFlag |= 2048;
  20960. }
  20961. root.codegenNode = createVNodeCall(
  20962. context,
  20963. helper(FRAGMENT),
  20964. void 0,
  20965. root.children,
  20966. patchFlag,
  20967. void 0,
  20968. void 0,
  20969. true,
  20970. void 0,
  20971. false
  20972. );
  20973. } else ;
  20974. }
  20975. function traverseChildren(parent, context) {
  20976. let i = 0;
  20977. const nodeRemoved = () => {
  20978. i--;
  20979. };
  20980. for (; i < parent.children.length; i++) {
  20981. const child = parent.children[i];
  20982. if (isString$1(child)) continue;
  20983. context.grandParent = context.parent;
  20984. context.parent = parent;
  20985. context.childIndex = i;
  20986. context.onNodeRemoved = nodeRemoved;
  20987. traverseNode(child, context);
  20988. }
  20989. }
  20990. function traverseNode(node, context) {
  20991. context.currentNode = node;
  20992. const { nodeTransforms } = context;
  20993. const exitFns = [];
  20994. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  20995. const onExit = nodeTransforms[i2](node, context);
  20996. if (onExit) {
  20997. if (isArray$3(onExit)) {
  20998. exitFns.push(...onExit);
  20999. } else {
  21000. exitFns.push(onExit);
  21001. }
  21002. }
  21003. if (!context.currentNode) {
  21004. return;
  21005. } else {
  21006. node = context.currentNode;
  21007. }
  21008. }
  21009. switch (node.type) {
  21010. case 3:
  21011. if (!context.ssr) {
  21012. context.helper(CREATE_COMMENT);
  21013. }
  21014. break;
  21015. case 5:
  21016. if (!context.ssr) {
  21017. context.helper(TO_DISPLAY_STRING);
  21018. }
  21019. break;
  21020. // for container types, further traverse downwards
  21021. case 9:
  21022. for (let i2 = 0; i2 < node.branches.length; i2++) {
  21023. traverseNode(node.branches[i2], context);
  21024. }
  21025. break;
  21026. case 10:
  21027. case 11:
  21028. case 1:
  21029. case 0:
  21030. traverseChildren(node, context);
  21031. break;
  21032. }
  21033. context.currentNode = node;
  21034. let i = exitFns.length;
  21035. while (i--) {
  21036. exitFns[i]();
  21037. }
  21038. }
  21039. function createStructuralDirectiveTransform(name, fn) {
  21040. const matches = isString$1(name) ? (n) => n === name : (n) => name.test(n);
  21041. return (node, context) => {
  21042. if (node.type === 1) {
  21043. const { props } = node;
  21044. if (node.tagType === 3 && props.some(isVSlot)) {
  21045. return;
  21046. }
  21047. const exitFns = [];
  21048. for (let i = 0; i < props.length; i++) {
  21049. const prop = props[i];
  21050. if (prop.type === 7 && matches(prop.name)) {
  21051. props.splice(i, 1);
  21052. i--;
  21053. const onExit = fn(node, prop, context);
  21054. if (onExit) exitFns.push(onExit);
  21055. }
  21056. }
  21057. return exitFns;
  21058. }
  21059. };
  21060. }
  21061. var sourceMap$1 = {};
  21062. var sourceMapGenerator$1 = {};
  21063. var base64Vlq$1 = {};
  21064. var base64$1 = {};
  21065. /* -*- Mode: js; js-indent-level: 2; -*- */
  21066. var hasRequiredBase64$1;
  21067. function requireBase64$1 () {
  21068. if (hasRequiredBase64$1) return base64$1;
  21069. hasRequiredBase64$1 = 1;
  21070. /*
  21071. * Copyright 2011 Mozilla Foundation and contributors
  21072. * Licensed under the New BSD license. See LICENSE or:
  21073. * http://opensource.org/licenses/BSD-3-Clause
  21074. */
  21075. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  21076. /**
  21077. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  21078. */
  21079. base64$1.encode = function (number) {
  21080. if (0 <= number && number < intToCharMap.length) {
  21081. return intToCharMap[number];
  21082. }
  21083. throw new TypeError("Must be between 0 and 63: " + number);
  21084. };
  21085. /**
  21086. * Decode a single base 64 character code digit to an integer. Returns -1 on
  21087. * failure.
  21088. */
  21089. base64$1.decode = function (charCode) {
  21090. var bigA = 65; // 'A'
  21091. var bigZ = 90; // 'Z'
  21092. var littleA = 97; // 'a'
  21093. var littleZ = 122; // 'z'
  21094. var zero = 48; // '0'
  21095. var nine = 57; // '9'
  21096. var plus = 43; // '+'
  21097. var slash = 47; // '/'
  21098. var littleOffset = 26;
  21099. var numberOffset = 52;
  21100. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  21101. if (bigA <= charCode && charCode <= bigZ) {
  21102. return (charCode - bigA);
  21103. }
  21104. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  21105. if (littleA <= charCode && charCode <= littleZ) {
  21106. return (charCode - littleA + littleOffset);
  21107. }
  21108. // 52 - 61: 0123456789
  21109. if (zero <= charCode && charCode <= nine) {
  21110. return (charCode - zero + numberOffset);
  21111. }
  21112. // 62: +
  21113. if (charCode == plus) {
  21114. return 62;
  21115. }
  21116. // 63: /
  21117. if (charCode == slash) {
  21118. return 63;
  21119. }
  21120. // Invalid base64 digit.
  21121. return -1;
  21122. };
  21123. return base64$1;
  21124. }
  21125. /* -*- Mode: js; js-indent-level: 2; -*- */
  21126. var hasRequiredBase64Vlq$1;
  21127. function requireBase64Vlq$1 () {
  21128. if (hasRequiredBase64Vlq$1) return base64Vlq$1;
  21129. hasRequiredBase64Vlq$1 = 1;
  21130. /*
  21131. * Copyright 2011 Mozilla Foundation and contributors
  21132. * Licensed under the New BSD license. See LICENSE or:
  21133. * http://opensource.org/licenses/BSD-3-Clause
  21134. *
  21135. * Based on the Base 64 VLQ implementation in Closure Compiler:
  21136. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  21137. *
  21138. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  21139. * Redistribution and use in source and binary forms, with or without
  21140. * modification, are permitted provided that the following conditions are
  21141. * met:
  21142. *
  21143. * * Redistributions of source code must retain the above copyright
  21144. * notice, this list of conditions and the following disclaimer.
  21145. * * Redistributions in binary form must reproduce the above
  21146. * copyright notice, this list of conditions and the following
  21147. * disclaimer in the documentation and/or other materials provided
  21148. * with the distribution.
  21149. * * Neither the name of Google Inc. nor the names of its
  21150. * contributors may be used to endorse or promote products derived
  21151. * from this software without specific prior written permission.
  21152. *
  21153. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21154. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21155. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21156. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21157. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21158. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21159. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21160. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21161. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21162. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  21163. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21164. */
  21165. var base64 = /*@__PURE__*/ requireBase64$1();
  21166. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  21167. // length quantities we use in the source map spec, the first bit is the sign,
  21168. // the next four bits are the actual value, and the 6th bit is the
  21169. // continuation bit. The continuation bit tells us whether there are more
  21170. // digits in this value following this digit.
  21171. //
  21172. // Continuation
  21173. // | Sign
  21174. // | |
  21175. // V V
  21176. // 101011
  21177. var VLQ_BASE_SHIFT = 5;
  21178. // binary: 100000
  21179. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  21180. // binary: 011111
  21181. var VLQ_BASE_MASK = VLQ_BASE - 1;
  21182. // binary: 100000
  21183. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  21184. /**
  21185. * Converts from a two-complement value to a value where the sign bit is
  21186. * placed in the least significant bit. For example, as decimals:
  21187. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  21188. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  21189. */
  21190. function toVLQSigned(aValue) {
  21191. return aValue < 0
  21192. ? ((-aValue) << 1) + 1
  21193. : (aValue << 1) + 0;
  21194. }
  21195. /**
  21196. * Converts to a two-complement value from a value where the sign bit is
  21197. * placed in the least significant bit. For example, as decimals:
  21198. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  21199. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  21200. */
  21201. function fromVLQSigned(aValue) {
  21202. var isNegative = (aValue & 1) === 1;
  21203. var shifted = aValue >> 1;
  21204. return isNegative
  21205. ? -shifted
  21206. : shifted;
  21207. }
  21208. /**
  21209. * Returns the base 64 VLQ encoded value.
  21210. */
  21211. base64Vlq$1.encode = function base64VLQ_encode(aValue) {
  21212. var encoded = "";
  21213. var digit;
  21214. var vlq = toVLQSigned(aValue);
  21215. do {
  21216. digit = vlq & VLQ_BASE_MASK;
  21217. vlq >>>= VLQ_BASE_SHIFT;
  21218. if (vlq > 0) {
  21219. // There are still more digits in this value, so we must make sure the
  21220. // continuation bit is marked.
  21221. digit |= VLQ_CONTINUATION_BIT;
  21222. }
  21223. encoded += base64.encode(digit);
  21224. } while (vlq > 0);
  21225. return encoded;
  21226. };
  21227. /**
  21228. * Decodes the next base 64 VLQ value from the given string and returns the
  21229. * value and the rest of the string via the out parameter.
  21230. */
  21231. base64Vlq$1.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  21232. var strLen = aStr.length;
  21233. var result = 0;
  21234. var shift = 0;
  21235. var continuation, digit;
  21236. do {
  21237. if (aIndex >= strLen) {
  21238. throw new Error("Expected more digits in base 64 VLQ value.");
  21239. }
  21240. digit = base64.decode(aStr.charCodeAt(aIndex++));
  21241. if (digit === -1) {
  21242. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  21243. }
  21244. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  21245. digit &= VLQ_BASE_MASK;
  21246. result = result + (digit << shift);
  21247. shift += VLQ_BASE_SHIFT;
  21248. } while (continuation);
  21249. aOutParam.value = fromVLQSigned(result);
  21250. aOutParam.rest = aIndex;
  21251. };
  21252. return base64Vlq$1;
  21253. }
  21254. var util$2 = {};
  21255. /* -*- Mode: js; js-indent-level: 2; -*- */
  21256. var hasRequiredUtil$2;
  21257. function requireUtil$2 () {
  21258. if (hasRequiredUtil$2) return util$2;
  21259. hasRequiredUtil$2 = 1;
  21260. (function (exports$1) {
  21261. /*
  21262. * Copyright 2011 Mozilla Foundation and contributors
  21263. * Licensed under the New BSD license. See LICENSE or:
  21264. * http://opensource.org/licenses/BSD-3-Clause
  21265. */
  21266. /**
  21267. * This is a helper function for getting values from parameter/options
  21268. * objects.
  21269. *
  21270. * @param args The object we are extracting values from
  21271. * @param name The name of the property we are getting.
  21272. * @param defaultValue An optional value to return if the property is missing
  21273. * from the object. If this is not specified and the property is missing, an
  21274. * error will be thrown.
  21275. */
  21276. function getArg(aArgs, aName, aDefaultValue) {
  21277. if (aName in aArgs) {
  21278. return aArgs[aName];
  21279. } else if (arguments.length === 3) {
  21280. return aDefaultValue;
  21281. } else {
  21282. throw new Error('"' + aName + '" is a required argument.');
  21283. }
  21284. }
  21285. exports$1.getArg = getArg;
  21286. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  21287. var dataUrlRegexp = /^data:.+\,.+$/;
  21288. function urlParse(aUrl) {
  21289. var match = aUrl.match(urlRegexp);
  21290. if (!match) {
  21291. return null;
  21292. }
  21293. return {
  21294. scheme: match[1],
  21295. auth: match[2],
  21296. host: match[3],
  21297. port: match[4],
  21298. path: match[5]
  21299. };
  21300. }
  21301. exports$1.urlParse = urlParse;
  21302. function urlGenerate(aParsedUrl) {
  21303. var url = '';
  21304. if (aParsedUrl.scheme) {
  21305. url += aParsedUrl.scheme + ':';
  21306. }
  21307. url += '//';
  21308. if (aParsedUrl.auth) {
  21309. url += aParsedUrl.auth + '@';
  21310. }
  21311. if (aParsedUrl.host) {
  21312. url += aParsedUrl.host;
  21313. }
  21314. if (aParsedUrl.port) {
  21315. url += ":" + aParsedUrl.port;
  21316. }
  21317. if (aParsedUrl.path) {
  21318. url += aParsedUrl.path;
  21319. }
  21320. return url;
  21321. }
  21322. exports$1.urlGenerate = urlGenerate;
  21323. var MAX_CACHED_INPUTS = 32;
  21324. /**
  21325. * Takes some function `f(input) -> result` and returns a memoized version of
  21326. * `f`.
  21327. *
  21328. * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
  21329. * memoization is a dumb-simple, linear least-recently-used cache.
  21330. */
  21331. function lruMemoize(f) {
  21332. var cache = [];
  21333. return function(input) {
  21334. for (var i = 0; i < cache.length; i++) {
  21335. if (cache[i].input === input) {
  21336. var temp = cache[0];
  21337. cache[0] = cache[i];
  21338. cache[i] = temp;
  21339. return cache[0].result;
  21340. }
  21341. }
  21342. var result = f(input);
  21343. cache.unshift({
  21344. input,
  21345. result,
  21346. });
  21347. if (cache.length > MAX_CACHED_INPUTS) {
  21348. cache.pop();
  21349. }
  21350. return result;
  21351. };
  21352. }
  21353. /**
  21354. * Normalizes a path, or the path portion of a URL:
  21355. *
  21356. * - Replaces consecutive slashes with one slash.
  21357. * - Removes unnecessary '.' parts.
  21358. * - Removes unnecessary '<dir>/..' parts.
  21359. *
  21360. * Based on code in the Node.js 'path' core module.
  21361. *
  21362. * @param aPath The path or url to normalize.
  21363. */
  21364. var normalize = lruMemoize(function normalize(aPath) {
  21365. var path = aPath;
  21366. var url = urlParse(aPath);
  21367. if (url) {
  21368. if (!url.path) {
  21369. return aPath;
  21370. }
  21371. path = url.path;
  21372. }
  21373. var isAbsolute = exports$1.isAbsolute(path);
  21374. // Split the path into parts between `/` characters. This is much faster than
  21375. // using `.split(/\/+/g)`.
  21376. var parts = [];
  21377. var start = 0;
  21378. var i = 0;
  21379. while (true) {
  21380. start = i;
  21381. i = path.indexOf("/", start);
  21382. if (i === -1) {
  21383. parts.push(path.slice(start));
  21384. break;
  21385. } else {
  21386. parts.push(path.slice(start, i));
  21387. while (i < path.length && path[i] === "/") {
  21388. i++;
  21389. }
  21390. }
  21391. }
  21392. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  21393. part = parts[i];
  21394. if (part === '.') {
  21395. parts.splice(i, 1);
  21396. } else if (part === '..') {
  21397. up++;
  21398. } else if (up > 0) {
  21399. if (part === '') {
  21400. // The first part is blank if the path is absolute. Trying to go
  21401. // above the root is a no-op. Therefore we can remove all '..' parts
  21402. // directly after the root.
  21403. parts.splice(i + 1, up);
  21404. up = 0;
  21405. } else {
  21406. parts.splice(i, 2);
  21407. up--;
  21408. }
  21409. }
  21410. }
  21411. path = parts.join('/');
  21412. if (path === '') {
  21413. path = isAbsolute ? '/' : '.';
  21414. }
  21415. if (url) {
  21416. url.path = path;
  21417. return urlGenerate(url);
  21418. }
  21419. return path;
  21420. });
  21421. exports$1.normalize = normalize;
  21422. /**
  21423. * Joins two paths/URLs.
  21424. *
  21425. * @param aRoot The root path or URL.
  21426. * @param aPath The path or URL to be joined with the root.
  21427. *
  21428. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  21429. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  21430. * first.
  21431. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  21432. * is updated with the result and aRoot is returned. Otherwise the result
  21433. * is returned.
  21434. * - If aPath is absolute, the result is aPath.
  21435. * - Otherwise the two paths are joined with a slash.
  21436. * - Joining for example 'http://' and 'www.example.com' is also supported.
  21437. */
  21438. function join(aRoot, aPath) {
  21439. if (aRoot === "") {
  21440. aRoot = ".";
  21441. }
  21442. if (aPath === "") {
  21443. aPath = ".";
  21444. }
  21445. var aPathUrl = urlParse(aPath);
  21446. var aRootUrl = urlParse(aRoot);
  21447. if (aRootUrl) {
  21448. aRoot = aRootUrl.path || '/';
  21449. }
  21450. // `join(foo, '//www.example.org')`
  21451. if (aPathUrl && !aPathUrl.scheme) {
  21452. if (aRootUrl) {
  21453. aPathUrl.scheme = aRootUrl.scheme;
  21454. }
  21455. return urlGenerate(aPathUrl);
  21456. }
  21457. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  21458. return aPath;
  21459. }
  21460. // `join('http://', 'www.example.com')`
  21461. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  21462. aRootUrl.host = aPath;
  21463. return urlGenerate(aRootUrl);
  21464. }
  21465. var joined = aPath.charAt(0) === '/'
  21466. ? aPath
  21467. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  21468. if (aRootUrl) {
  21469. aRootUrl.path = joined;
  21470. return urlGenerate(aRootUrl);
  21471. }
  21472. return joined;
  21473. }
  21474. exports$1.join = join;
  21475. exports$1.isAbsolute = function (aPath) {
  21476. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  21477. };
  21478. /**
  21479. * Make a path relative to a URL or another path.
  21480. *
  21481. * @param aRoot The root path or URL.
  21482. * @param aPath The path or URL to be made relative to aRoot.
  21483. */
  21484. function relative(aRoot, aPath) {
  21485. if (aRoot === "") {
  21486. aRoot = ".";
  21487. }
  21488. aRoot = aRoot.replace(/\/$/, '');
  21489. // It is possible for the path to be above the root. In this case, simply
  21490. // checking whether the root is a prefix of the path won't work. Instead, we
  21491. // need to remove components from the root one by one, until either we find
  21492. // a prefix that fits, or we run out of components to remove.
  21493. var level = 0;
  21494. while (aPath.indexOf(aRoot + '/') !== 0) {
  21495. var index = aRoot.lastIndexOf("/");
  21496. if (index < 0) {
  21497. return aPath;
  21498. }
  21499. // If the only part of the root that is left is the scheme (i.e. http://,
  21500. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  21501. // have exhausted all components, so the path is not relative to the root.
  21502. aRoot = aRoot.slice(0, index);
  21503. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  21504. return aPath;
  21505. }
  21506. ++level;
  21507. }
  21508. // Make sure we add a "../" for each component we removed from the root.
  21509. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  21510. }
  21511. exports$1.relative = relative;
  21512. var supportsNullProto = (function () {
  21513. var obj = Object.create(null);
  21514. return !('__proto__' in obj);
  21515. }());
  21516. function identity (s) {
  21517. return s;
  21518. }
  21519. /**
  21520. * Because behavior goes wacky when you set `__proto__` on objects, we
  21521. * have to prefix all the strings in our set with an arbitrary character.
  21522. *
  21523. * See https://github.com/mozilla/source-map/pull/31 and
  21524. * https://github.com/mozilla/source-map/issues/30
  21525. *
  21526. * @param String aStr
  21527. */
  21528. function toSetString(aStr) {
  21529. if (isProtoString(aStr)) {
  21530. return '$' + aStr;
  21531. }
  21532. return aStr;
  21533. }
  21534. exports$1.toSetString = supportsNullProto ? identity : toSetString;
  21535. function fromSetString(aStr) {
  21536. if (isProtoString(aStr)) {
  21537. return aStr.slice(1);
  21538. }
  21539. return aStr;
  21540. }
  21541. exports$1.fromSetString = supportsNullProto ? identity : fromSetString;
  21542. function isProtoString(s) {
  21543. if (!s) {
  21544. return false;
  21545. }
  21546. var length = s.length;
  21547. if (length < 9 /* "__proto__".length */) {
  21548. return false;
  21549. }
  21550. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  21551. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  21552. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  21553. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  21554. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  21555. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  21556. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  21557. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  21558. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  21559. return false;
  21560. }
  21561. for (var i = length - 10; i >= 0; i--) {
  21562. if (s.charCodeAt(i) !== 36 /* '$' */) {
  21563. return false;
  21564. }
  21565. }
  21566. return true;
  21567. }
  21568. /**
  21569. * Comparator between two mappings where the original positions are compared.
  21570. *
  21571. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  21572. * mappings with the same original source/line/column, but different generated
  21573. * line and column the same. Useful when searching for a mapping with a
  21574. * stubbed out mapping.
  21575. */
  21576. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  21577. var cmp = strcmp(mappingA.source, mappingB.source);
  21578. if (cmp !== 0) {
  21579. return cmp;
  21580. }
  21581. cmp = mappingA.originalLine - mappingB.originalLine;
  21582. if (cmp !== 0) {
  21583. return cmp;
  21584. }
  21585. cmp = mappingA.originalColumn - mappingB.originalColumn;
  21586. if (cmp !== 0 || onlyCompareOriginal) {
  21587. return cmp;
  21588. }
  21589. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  21590. if (cmp !== 0) {
  21591. return cmp;
  21592. }
  21593. cmp = mappingA.generatedLine - mappingB.generatedLine;
  21594. if (cmp !== 0) {
  21595. return cmp;
  21596. }
  21597. return strcmp(mappingA.name, mappingB.name);
  21598. }
  21599. exports$1.compareByOriginalPositions = compareByOriginalPositions;
  21600. function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) {
  21601. var cmp;
  21602. cmp = mappingA.originalLine - mappingB.originalLine;
  21603. if (cmp !== 0) {
  21604. return cmp;
  21605. }
  21606. cmp = mappingA.originalColumn - mappingB.originalColumn;
  21607. if (cmp !== 0 || onlyCompareOriginal) {
  21608. return cmp;
  21609. }
  21610. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  21611. if (cmp !== 0) {
  21612. return cmp;
  21613. }
  21614. cmp = mappingA.generatedLine - mappingB.generatedLine;
  21615. if (cmp !== 0) {
  21616. return cmp;
  21617. }
  21618. return strcmp(mappingA.name, mappingB.name);
  21619. }
  21620. exports$1.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource;
  21621. /**
  21622. * Comparator between two mappings with deflated source and name indices where
  21623. * the generated positions are compared.
  21624. *
  21625. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  21626. * mappings with the same generated line and column, but different
  21627. * source/name/original line and column the same. Useful when searching for a
  21628. * mapping with a stubbed out mapping.
  21629. */
  21630. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  21631. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  21632. if (cmp !== 0) {
  21633. return cmp;
  21634. }
  21635. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  21636. if (cmp !== 0 || onlyCompareGenerated) {
  21637. return cmp;
  21638. }
  21639. cmp = strcmp(mappingA.source, mappingB.source);
  21640. if (cmp !== 0) {
  21641. return cmp;
  21642. }
  21643. cmp = mappingA.originalLine - mappingB.originalLine;
  21644. if (cmp !== 0) {
  21645. return cmp;
  21646. }
  21647. cmp = mappingA.originalColumn - mappingB.originalColumn;
  21648. if (cmp !== 0) {
  21649. return cmp;
  21650. }
  21651. return strcmp(mappingA.name, mappingB.name);
  21652. }
  21653. exports$1.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  21654. function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) {
  21655. var cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  21656. if (cmp !== 0 || onlyCompareGenerated) {
  21657. return cmp;
  21658. }
  21659. cmp = strcmp(mappingA.source, mappingB.source);
  21660. if (cmp !== 0) {
  21661. return cmp;
  21662. }
  21663. cmp = mappingA.originalLine - mappingB.originalLine;
  21664. if (cmp !== 0) {
  21665. return cmp;
  21666. }
  21667. cmp = mappingA.originalColumn - mappingB.originalColumn;
  21668. if (cmp !== 0) {
  21669. return cmp;
  21670. }
  21671. return strcmp(mappingA.name, mappingB.name);
  21672. }
  21673. exports$1.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine;
  21674. function strcmp(aStr1, aStr2) {
  21675. if (aStr1 === aStr2) {
  21676. return 0;
  21677. }
  21678. if (aStr1 === null) {
  21679. return 1; // aStr2 !== null
  21680. }
  21681. if (aStr2 === null) {
  21682. return -1; // aStr1 !== null
  21683. }
  21684. if (aStr1 > aStr2) {
  21685. return 1;
  21686. }
  21687. return -1;
  21688. }
  21689. /**
  21690. * Comparator between two mappings with inflated source and name strings where
  21691. * the generated positions are compared.
  21692. */
  21693. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  21694. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  21695. if (cmp !== 0) {
  21696. return cmp;
  21697. }
  21698. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  21699. if (cmp !== 0) {
  21700. return cmp;
  21701. }
  21702. cmp = strcmp(mappingA.source, mappingB.source);
  21703. if (cmp !== 0) {
  21704. return cmp;
  21705. }
  21706. cmp = mappingA.originalLine - mappingB.originalLine;
  21707. if (cmp !== 0) {
  21708. return cmp;
  21709. }
  21710. cmp = mappingA.originalColumn - mappingB.originalColumn;
  21711. if (cmp !== 0) {
  21712. return cmp;
  21713. }
  21714. return strcmp(mappingA.name, mappingB.name);
  21715. }
  21716. exports$1.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  21717. /**
  21718. * Strip any JSON XSSI avoidance prefix from the string (as documented
  21719. * in the source maps specification), and then parse the string as
  21720. * JSON.
  21721. */
  21722. function parseSourceMapInput(str) {
  21723. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  21724. }
  21725. exports$1.parseSourceMapInput = parseSourceMapInput;
  21726. /**
  21727. * Compute the URL of a source given the the source root, the source's
  21728. * URL, and the source map's URL.
  21729. */
  21730. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  21731. sourceURL = sourceURL || '';
  21732. if (sourceRoot) {
  21733. // This follows what Chrome does.
  21734. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  21735. sourceRoot += '/';
  21736. }
  21737. // The spec says:
  21738. // Line 4: An optional source root, useful for relocating source
  21739. // files on a server or removing repeated values in the
  21740. // “sources” entry. This value is prepended to the individual
  21741. // entries in the “source” field.
  21742. sourceURL = sourceRoot + sourceURL;
  21743. }
  21744. // Historically, SourceMapConsumer did not take the sourceMapURL as
  21745. // a parameter. This mode is still somewhat supported, which is why
  21746. // this code block is conditional. However, it's preferable to pass
  21747. // the source map URL to SourceMapConsumer, so that this function
  21748. // can implement the source URL resolution algorithm as outlined in
  21749. // the spec. This block is basically the equivalent of:
  21750. // new URL(sourceURL, sourceMapURL).toString()
  21751. // ... except it avoids using URL, which wasn't available in the
  21752. // older releases of node still supported by this library.
  21753. //
  21754. // The spec says:
  21755. // If the sources are not absolute URLs after prepending of the
  21756. // “sourceRoot”, the sources are resolved relative to the
  21757. // SourceMap (like resolving script src in a html document).
  21758. if (sourceMapURL) {
  21759. var parsed = urlParse(sourceMapURL);
  21760. if (!parsed) {
  21761. throw new Error("sourceMapURL could not be parsed");
  21762. }
  21763. if (parsed.path) {
  21764. // Strip the last path component, but keep the "/".
  21765. var index = parsed.path.lastIndexOf('/');
  21766. if (index >= 0) {
  21767. parsed.path = parsed.path.substring(0, index + 1);
  21768. }
  21769. }
  21770. sourceURL = join(urlGenerate(parsed), sourceURL);
  21771. }
  21772. return normalize(sourceURL);
  21773. }
  21774. exports$1.computeSourceURL = computeSourceURL;
  21775. } (util$2));
  21776. return util$2;
  21777. }
  21778. var arraySet$1 = {};
  21779. /* -*- Mode: js; js-indent-level: 2; -*- */
  21780. var hasRequiredArraySet$1;
  21781. function requireArraySet$1 () {
  21782. if (hasRequiredArraySet$1) return arraySet$1;
  21783. hasRequiredArraySet$1 = 1;
  21784. /*
  21785. * Copyright 2011 Mozilla Foundation and contributors
  21786. * Licensed under the New BSD license. See LICENSE or:
  21787. * http://opensource.org/licenses/BSD-3-Clause
  21788. */
  21789. var util = /*@__PURE__*/ requireUtil$2();
  21790. var has = Object.prototype.hasOwnProperty;
  21791. var hasNativeMap = typeof Map !== "undefined";
  21792. /**
  21793. * A data structure which is a combination of an array and a set. Adding a new
  21794. * member is O(1), testing for membership is O(1), and finding the index of an
  21795. * element is O(1). Removing elements from the set is not supported. Only
  21796. * strings are supported for membership.
  21797. */
  21798. function ArraySet() {
  21799. this._array = [];
  21800. this._set = hasNativeMap ? new Map() : Object.create(null);
  21801. }
  21802. /**
  21803. * Static method for creating ArraySet instances from an existing array.
  21804. */
  21805. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  21806. var set = new ArraySet();
  21807. for (var i = 0, len = aArray.length; i < len; i++) {
  21808. set.add(aArray[i], aAllowDuplicates);
  21809. }
  21810. return set;
  21811. };
  21812. /**
  21813. * Return how many unique items are in this ArraySet. If duplicates have been
  21814. * added, than those do not count towards the size.
  21815. *
  21816. * @returns Number
  21817. */
  21818. ArraySet.prototype.size = function ArraySet_size() {
  21819. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  21820. };
  21821. /**
  21822. * Add the given string to this set.
  21823. *
  21824. * @param String aStr
  21825. */
  21826. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  21827. var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
  21828. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  21829. var idx = this._array.length;
  21830. if (!isDuplicate || aAllowDuplicates) {
  21831. this._array.push(aStr);
  21832. }
  21833. if (!isDuplicate) {
  21834. if (hasNativeMap) {
  21835. this._set.set(aStr, idx);
  21836. } else {
  21837. this._set[sStr] = idx;
  21838. }
  21839. }
  21840. };
  21841. /**
  21842. * Is the given string a member of this set?
  21843. *
  21844. * @param String aStr
  21845. */
  21846. ArraySet.prototype.has = function ArraySet_has(aStr) {
  21847. if (hasNativeMap) {
  21848. return this._set.has(aStr);
  21849. } else {
  21850. var sStr = util.toSetString(aStr);
  21851. return has.call(this._set, sStr);
  21852. }
  21853. };
  21854. /**
  21855. * What is the index of the given string in the array?
  21856. *
  21857. * @param String aStr
  21858. */
  21859. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  21860. if (hasNativeMap) {
  21861. var idx = this._set.get(aStr);
  21862. if (idx >= 0) {
  21863. return idx;
  21864. }
  21865. } else {
  21866. var sStr = util.toSetString(aStr);
  21867. if (has.call(this._set, sStr)) {
  21868. return this._set[sStr];
  21869. }
  21870. }
  21871. throw new Error('"' + aStr + '" is not in the set.');
  21872. };
  21873. /**
  21874. * What is the element at the given index?
  21875. *
  21876. * @param Number aIdx
  21877. */
  21878. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  21879. if (aIdx >= 0 && aIdx < this._array.length) {
  21880. return this._array[aIdx];
  21881. }
  21882. throw new Error('No element indexed by ' + aIdx);
  21883. };
  21884. /**
  21885. * Returns the array representation of this set (which has the proper indices
  21886. * indicated by indexOf). Note that this is a copy of the internal array used
  21887. * for storing the members so that no one can mess with internal state.
  21888. */
  21889. ArraySet.prototype.toArray = function ArraySet_toArray() {
  21890. return this._array.slice();
  21891. };
  21892. arraySet$1.ArraySet = ArraySet;
  21893. return arraySet$1;
  21894. }
  21895. var mappingList$1 = {};
  21896. /* -*- Mode: js; js-indent-level: 2; -*- */
  21897. var hasRequiredMappingList$1;
  21898. function requireMappingList$1 () {
  21899. if (hasRequiredMappingList$1) return mappingList$1;
  21900. hasRequiredMappingList$1 = 1;
  21901. /*
  21902. * Copyright 2014 Mozilla Foundation and contributors
  21903. * Licensed under the New BSD license. See LICENSE or:
  21904. * http://opensource.org/licenses/BSD-3-Clause
  21905. */
  21906. var util = /*@__PURE__*/ requireUtil$2();
  21907. /**
  21908. * Determine whether mappingB is after mappingA with respect to generated
  21909. * position.
  21910. */
  21911. function generatedPositionAfter(mappingA, mappingB) {
  21912. // Optimized for most common case
  21913. var lineA = mappingA.generatedLine;
  21914. var lineB = mappingB.generatedLine;
  21915. var columnA = mappingA.generatedColumn;
  21916. var columnB = mappingB.generatedColumn;
  21917. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  21918. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  21919. }
  21920. /**
  21921. * A data structure to provide a sorted view of accumulated mappings in a
  21922. * performance conscious manner. It trades a neglibable overhead in general
  21923. * case for a large speedup in case of mappings being added in order.
  21924. */
  21925. function MappingList() {
  21926. this._array = [];
  21927. this._sorted = true;
  21928. // Serves as infimum
  21929. this._last = {generatedLine: -1, generatedColumn: 0};
  21930. }
  21931. /**
  21932. * Iterate through internal items. This method takes the same arguments that
  21933. * `Array.prototype.forEach` takes.
  21934. *
  21935. * NOTE: The order of the mappings is NOT guaranteed.
  21936. */
  21937. MappingList.prototype.unsortedForEach =
  21938. function MappingList_forEach(aCallback, aThisArg) {
  21939. this._array.forEach(aCallback, aThisArg);
  21940. };
  21941. /**
  21942. * Add the given source mapping.
  21943. *
  21944. * @param Object aMapping
  21945. */
  21946. MappingList.prototype.add = function MappingList_add(aMapping) {
  21947. if (generatedPositionAfter(this._last, aMapping)) {
  21948. this._last = aMapping;
  21949. this._array.push(aMapping);
  21950. } else {
  21951. this._sorted = false;
  21952. this._array.push(aMapping);
  21953. }
  21954. };
  21955. /**
  21956. * Returns the flat, sorted array of mappings. The mappings are sorted by
  21957. * generated position.
  21958. *
  21959. * WARNING: This method returns internal data without copying, for
  21960. * performance. The return value must NOT be mutated, and should be treated as
  21961. * an immutable borrow. If you want to take ownership, you must make your own
  21962. * copy.
  21963. */
  21964. MappingList.prototype.toArray = function MappingList_toArray() {
  21965. if (!this._sorted) {
  21966. this._array.sort(util.compareByGeneratedPositionsInflated);
  21967. this._sorted = true;
  21968. }
  21969. return this._array;
  21970. };
  21971. mappingList$1.MappingList = MappingList;
  21972. return mappingList$1;
  21973. }
  21974. /* -*- Mode: js; js-indent-level: 2; -*- */
  21975. var hasRequiredSourceMapGenerator$1;
  21976. function requireSourceMapGenerator$1 () {
  21977. if (hasRequiredSourceMapGenerator$1) return sourceMapGenerator$1;
  21978. hasRequiredSourceMapGenerator$1 = 1;
  21979. /*
  21980. * Copyright 2011 Mozilla Foundation and contributors
  21981. * Licensed under the New BSD license. See LICENSE or:
  21982. * http://opensource.org/licenses/BSD-3-Clause
  21983. */
  21984. var base64VLQ = /*@__PURE__*/ requireBase64Vlq$1();
  21985. var util = /*@__PURE__*/ requireUtil$2();
  21986. var ArraySet = /*@__PURE__*/ requireArraySet$1().ArraySet;
  21987. var MappingList = /*@__PURE__*/ requireMappingList$1().MappingList;
  21988. /**
  21989. * An instance of the SourceMapGenerator represents a source map which is
  21990. * being built incrementally. You may pass an object with the following
  21991. * properties:
  21992. *
  21993. * - file: The filename of the generated source.
  21994. * - sourceRoot: A root for all relative URLs in this source map.
  21995. */
  21996. function SourceMapGenerator(aArgs) {
  21997. if (!aArgs) {
  21998. aArgs = {};
  21999. }
  22000. this._file = util.getArg(aArgs, 'file', null);
  22001. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  22002. this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
  22003. this._ignoreInvalidMapping = util.getArg(aArgs, 'ignoreInvalidMapping', false);
  22004. this._sources = new ArraySet();
  22005. this._names = new ArraySet();
  22006. this._mappings = new MappingList();
  22007. this._sourcesContents = null;
  22008. }
  22009. SourceMapGenerator.prototype._version = 3;
  22010. /**
  22011. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  22012. *
  22013. * @param aSourceMapConsumer The SourceMap.
  22014. */
  22015. SourceMapGenerator.fromSourceMap =
  22016. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer, generatorOps) {
  22017. var sourceRoot = aSourceMapConsumer.sourceRoot;
  22018. var generator = new SourceMapGenerator(Object.assign(generatorOps || {}, {
  22019. file: aSourceMapConsumer.file,
  22020. sourceRoot: sourceRoot
  22021. }));
  22022. aSourceMapConsumer.eachMapping(function (mapping) {
  22023. var newMapping = {
  22024. generated: {
  22025. line: mapping.generatedLine,
  22026. column: mapping.generatedColumn
  22027. }
  22028. };
  22029. if (mapping.source != null) {
  22030. newMapping.source = mapping.source;
  22031. if (sourceRoot != null) {
  22032. newMapping.source = util.relative(sourceRoot, newMapping.source);
  22033. }
  22034. newMapping.original = {
  22035. line: mapping.originalLine,
  22036. column: mapping.originalColumn
  22037. };
  22038. if (mapping.name != null) {
  22039. newMapping.name = mapping.name;
  22040. }
  22041. }
  22042. generator.addMapping(newMapping);
  22043. });
  22044. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  22045. var sourceRelative = sourceFile;
  22046. if (sourceRoot !== null) {
  22047. sourceRelative = util.relative(sourceRoot, sourceFile);
  22048. }
  22049. if (!generator._sources.has(sourceRelative)) {
  22050. generator._sources.add(sourceRelative);
  22051. }
  22052. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  22053. if (content != null) {
  22054. generator.setSourceContent(sourceFile, content);
  22055. }
  22056. });
  22057. return generator;
  22058. };
  22059. /**
  22060. * Add a single mapping from original source line and column to the generated
  22061. * source's line and column for this source map being created. The mapping
  22062. * object should have the following properties:
  22063. *
  22064. * - generated: An object with the generated line and column positions.
  22065. * - original: An object with the original line and column positions.
  22066. * - source: The original source file (relative to the sourceRoot).
  22067. * - name: An optional original token name for this mapping.
  22068. */
  22069. SourceMapGenerator.prototype.addMapping =
  22070. function SourceMapGenerator_addMapping(aArgs) {
  22071. var generated = util.getArg(aArgs, 'generated');
  22072. var original = util.getArg(aArgs, 'original', null);
  22073. var source = util.getArg(aArgs, 'source', null);
  22074. var name = util.getArg(aArgs, 'name', null);
  22075. if (!this._skipValidation) {
  22076. if (this._validateMapping(generated, original, source, name) === false) {
  22077. return;
  22078. }
  22079. }
  22080. if (source != null) {
  22081. source = String(source);
  22082. if (!this._sources.has(source)) {
  22083. this._sources.add(source);
  22084. }
  22085. }
  22086. if (name != null) {
  22087. name = String(name);
  22088. if (!this._names.has(name)) {
  22089. this._names.add(name);
  22090. }
  22091. }
  22092. this._mappings.add({
  22093. generatedLine: generated.line,
  22094. generatedColumn: generated.column,
  22095. originalLine: original != null && original.line,
  22096. originalColumn: original != null && original.column,
  22097. source: source,
  22098. name: name
  22099. });
  22100. };
  22101. /**
  22102. * Set the source content for a source file.
  22103. */
  22104. SourceMapGenerator.prototype.setSourceContent =
  22105. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  22106. var source = aSourceFile;
  22107. if (this._sourceRoot != null) {
  22108. source = util.relative(this._sourceRoot, source);
  22109. }
  22110. if (aSourceContent != null) {
  22111. // Add the source content to the _sourcesContents map.
  22112. // Create a new _sourcesContents map if the property is null.
  22113. if (!this._sourcesContents) {
  22114. this._sourcesContents = Object.create(null);
  22115. }
  22116. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  22117. } else if (this._sourcesContents) {
  22118. // Remove the source file from the _sourcesContents map.
  22119. // If the _sourcesContents map is empty, set the property to null.
  22120. delete this._sourcesContents[util.toSetString(source)];
  22121. if (Object.keys(this._sourcesContents).length === 0) {
  22122. this._sourcesContents = null;
  22123. }
  22124. }
  22125. };
  22126. /**
  22127. * Applies the mappings of a sub-source-map for a specific source file to the
  22128. * source map being generated. Each mapping to the supplied source file is
  22129. * rewritten using the supplied source map. Note: The resolution for the
  22130. * resulting mappings is the minimium of this map and the supplied map.
  22131. *
  22132. * @param aSourceMapConsumer The source map to be applied.
  22133. * @param aSourceFile Optional. The filename of the source file.
  22134. * If omitted, SourceMapConsumer's file property will be used.
  22135. * @param aSourceMapPath Optional. The dirname of the path to the source map
  22136. * to be applied. If relative, it is relative to the SourceMapConsumer.
  22137. * This parameter is needed when the two source maps aren't in the same
  22138. * directory, and the source map to be applied contains relative source
  22139. * paths. If so, those relative source paths need to be rewritten
  22140. * relative to the SourceMapGenerator.
  22141. */
  22142. SourceMapGenerator.prototype.applySourceMap =
  22143. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  22144. var sourceFile = aSourceFile;
  22145. // If aSourceFile is omitted, we will use the file property of the SourceMap
  22146. if (aSourceFile == null) {
  22147. if (aSourceMapConsumer.file == null) {
  22148. throw new Error(
  22149. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  22150. 'or the source map\'s "file" property. Both were omitted.'
  22151. );
  22152. }
  22153. sourceFile = aSourceMapConsumer.file;
  22154. }
  22155. var sourceRoot = this._sourceRoot;
  22156. // Make "sourceFile" relative if an absolute Url is passed.
  22157. if (sourceRoot != null) {
  22158. sourceFile = util.relative(sourceRoot, sourceFile);
  22159. }
  22160. // Applying the SourceMap can add and remove items from the sources and
  22161. // the names array.
  22162. var newSources = new ArraySet();
  22163. var newNames = new ArraySet();
  22164. // Find mappings for the "sourceFile"
  22165. this._mappings.unsortedForEach(function (mapping) {
  22166. if (mapping.source === sourceFile && mapping.originalLine != null) {
  22167. // Check if it can be mapped by the source map, then update the mapping.
  22168. var original = aSourceMapConsumer.originalPositionFor({
  22169. line: mapping.originalLine,
  22170. column: mapping.originalColumn
  22171. });
  22172. if (original.source != null) {
  22173. // Copy mapping
  22174. mapping.source = original.source;
  22175. if (aSourceMapPath != null) {
  22176. mapping.source = util.join(aSourceMapPath, mapping.source);
  22177. }
  22178. if (sourceRoot != null) {
  22179. mapping.source = util.relative(sourceRoot, mapping.source);
  22180. }
  22181. mapping.originalLine = original.line;
  22182. mapping.originalColumn = original.column;
  22183. if (original.name != null) {
  22184. mapping.name = original.name;
  22185. }
  22186. }
  22187. }
  22188. var source = mapping.source;
  22189. if (source != null && !newSources.has(source)) {
  22190. newSources.add(source);
  22191. }
  22192. var name = mapping.name;
  22193. if (name != null && !newNames.has(name)) {
  22194. newNames.add(name);
  22195. }
  22196. }, this);
  22197. this._sources = newSources;
  22198. this._names = newNames;
  22199. // Copy sourcesContents of applied map.
  22200. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  22201. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  22202. if (content != null) {
  22203. if (aSourceMapPath != null) {
  22204. sourceFile = util.join(aSourceMapPath, sourceFile);
  22205. }
  22206. if (sourceRoot != null) {
  22207. sourceFile = util.relative(sourceRoot, sourceFile);
  22208. }
  22209. this.setSourceContent(sourceFile, content);
  22210. }
  22211. }, this);
  22212. };
  22213. /**
  22214. * A mapping can have one of the three levels of data:
  22215. *
  22216. * 1. Just the generated position.
  22217. * 2. The Generated position, original position, and original source.
  22218. * 3. Generated and original position, original source, as well as a name
  22219. * token.
  22220. *
  22221. * To maintain consistency, we validate that any new mapping being added falls
  22222. * in to one of these categories.
  22223. */
  22224. SourceMapGenerator.prototype._validateMapping =
  22225. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  22226. aName) {
  22227. // When aOriginal is truthy but has empty values for .line and .column,
  22228. // it is most likely a programmer error. In this case we throw a very
  22229. // specific error message to try to guide them the right way.
  22230. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  22231. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  22232. var message = 'original.line and original.column are not numbers -- you probably meant to omit ' +
  22233. 'the original mapping entirely and only map the generated position. If so, pass ' +
  22234. 'null for the original mapping instead of an object with empty or null values.';
  22235. if (this._ignoreInvalidMapping) {
  22236. if (typeof console !== 'undefined' && console.warn) {
  22237. console.warn(message);
  22238. }
  22239. return false;
  22240. } else {
  22241. throw new Error(message);
  22242. }
  22243. }
  22244. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  22245. && aGenerated.line > 0 && aGenerated.column >= 0
  22246. && !aOriginal && !aSource && !aName) {
  22247. // Case 1.
  22248. return;
  22249. }
  22250. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  22251. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  22252. && aGenerated.line > 0 && aGenerated.column >= 0
  22253. && aOriginal.line > 0 && aOriginal.column >= 0
  22254. && aSource) {
  22255. // Cases 2 and 3.
  22256. return;
  22257. }
  22258. else {
  22259. var message = 'Invalid mapping: ' + JSON.stringify({
  22260. generated: aGenerated,
  22261. source: aSource,
  22262. original: aOriginal,
  22263. name: aName
  22264. });
  22265. if (this._ignoreInvalidMapping) {
  22266. if (typeof console !== 'undefined' && console.warn) {
  22267. console.warn(message);
  22268. }
  22269. return false;
  22270. } else {
  22271. throw new Error(message)
  22272. }
  22273. }
  22274. };
  22275. /**
  22276. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  22277. * specified by the source map format.
  22278. */
  22279. SourceMapGenerator.prototype._serializeMappings =
  22280. function SourceMapGenerator_serializeMappings() {
  22281. var previousGeneratedColumn = 0;
  22282. var previousGeneratedLine = 1;
  22283. var previousOriginalColumn = 0;
  22284. var previousOriginalLine = 0;
  22285. var previousName = 0;
  22286. var previousSource = 0;
  22287. var result = '';
  22288. var next;
  22289. var mapping;
  22290. var nameIdx;
  22291. var sourceIdx;
  22292. var mappings = this._mappings.toArray();
  22293. for (var i = 0, len = mappings.length; i < len; i++) {
  22294. mapping = mappings[i];
  22295. next = '';
  22296. if (mapping.generatedLine !== previousGeneratedLine) {
  22297. previousGeneratedColumn = 0;
  22298. while (mapping.generatedLine !== previousGeneratedLine) {
  22299. next += ';';
  22300. previousGeneratedLine++;
  22301. }
  22302. }
  22303. else {
  22304. if (i > 0) {
  22305. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  22306. continue;
  22307. }
  22308. next += ',';
  22309. }
  22310. }
  22311. next += base64VLQ.encode(mapping.generatedColumn
  22312. - previousGeneratedColumn);
  22313. previousGeneratedColumn = mapping.generatedColumn;
  22314. if (mapping.source != null) {
  22315. sourceIdx = this._sources.indexOf(mapping.source);
  22316. next += base64VLQ.encode(sourceIdx - previousSource);
  22317. previousSource = sourceIdx;
  22318. // lines are stored 0-based in SourceMap spec version 3
  22319. next += base64VLQ.encode(mapping.originalLine - 1
  22320. - previousOriginalLine);
  22321. previousOriginalLine = mapping.originalLine - 1;
  22322. next += base64VLQ.encode(mapping.originalColumn
  22323. - previousOriginalColumn);
  22324. previousOriginalColumn = mapping.originalColumn;
  22325. if (mapping.name != null) {
  22326. nameIdx = this._names.indexOf(mapping.name);
  22327. next += base64VLQ.encode(nameIdx - previousName);
  22328. previousName = nameIdx;
  22329. }
  22330. }
  22331. result += next;
  22332. }
  22333. return result;
  22334. };
  22335. SourceMapGenerator.prototype._generateSourcesContent =
  22336. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  22337. return aSources.map(function (source) {
  22338. if (!this._sourcesContents) {
  22339. return null;
  22340. }
  22341. if (aSourceRoot != null) {
  22342. source = util.relative(aSourceRoot, source);
  22343. }
  22344. var key = util.toSetString(source);
  22345. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  22346. ? this._sourcesContents[key]
  22347. : null;
  22348. }, this);
  22349. };
  22350. /**
  22351. * Externalize the source map.
  22352. */
  22353. SourceMapGenerator.prototype.toJSON =
  22354. function SourceMapGenerator_toJSON() {
  22355. var map = {
  22356. version: this._version,
  22357. sources: this._sources.toArray(),
  22358. names: this._names.toArray(),
  22359. mappings: this._serializeMappings()
  22360. };
  22361. if (this._file != null) {
  22362. map.file = this._file;
  22363. }
  22364. if (this._sourceRoot != null) {
  22365. map.sourceRoot = this._sourceRoot;
  22366. }
  22367. if (this._sourcesContents) {
  22368. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  22369. }
  22370. return map;
  22371. };
  22372. /**
  22373. * Render the source map being generated to a string.
  22374. */
  22375. SourceMapGenerator.prototype.toString =
  22376. function SourceMapGenerator_toString() {
  22377. return JSON.stringify(this.toJSON());
  22378. };
  22379. sourceMapGenerator$1.SourceMapGenerator = SourceMapGenerator;
  22380. return sourceMapGenerator$1;
  22381. }
  22382. var sourceMapConsumer$1 = {};
  22383. var binarySearch$1 = {};
  22384. /* -*- Mode: js; js-indent-level: 2; -*- */
  22385. var hasRequiredBinarySearch$1;
  22386. function requireBinarySearch$1 () {
  22387. if (hasRequiredBinarySearch$1) return binarySearch$1;
  22388. hasRequiredBinarySearch$1 = 1;
  22389. (function (exports$1) {
  22390. /*
  22391. * Copyright 2011 Mozilla Foundation and contributors
  22392. * Licensed under the New BSD license. See LICENSE or:
  22393. * http://opensource.org/licenses/BSD-3-Clause
  22394. */
  22395. exports$1.GREATEST_LOWER_BOUND = 1;
  22396. exports$1.LEAST_UPPER_BOUND = 2;
  22397. /**
  22398. * Recursive implementation of binary search.
  22399. *
  22400. * @param aLow Indices here and lower do not contain the needle.
  22401. * @param aHigh Indices here and higher do not contain the needle.
  22402. * @param aNeedle The element being searched for.
  22403. * @param aHaystack The non-empty array being searched.
  22404. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  22405. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  22406. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  22407. * closest element that is smaller than or greater than the one we are
  22408. * searching for, respectively, if the exact element cannot be found.
  22409. */
  22410. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  22411. // This function terminates when one of the following is true:
  22412. //
  22413. // 1. We find the exact element we are looking for.
  22414. //
  22415. // 2. We did not find the exact element, but we can return the index of
  22416. // the next-closest element.
  22417. //
  22418. // 3. We did not find the exact element, and there is no next-closest
  22419. // element than the one we are searching for, so we return -1.
  22420. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  22421. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  22422. if (cmp === 0) {
  22423. // Found the element we are looking for.
  22424. return mid;
  22425. }
  22426. else if (cmp > 0) {
  22427. // Our needle is greater than aHaystack[mid].
  22428. if (aHigh - mid > 1) {
  22429. // The element is in the upper half.
  22430. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  22431. }
  22432. // The exact needle element was not found in this haystack. Determine if
  22433. // we are in termination case (3) or (2) and return the appropriate thing.
  22434. if (aBias == exports$1.LEAST_UPPER_BOUND) {
  22435. return aHigh < aHaystack.length ? aHigh : -1;
  22436. } else {
  22437. return mid;
  22438. }
  22439. }
  22440. else {
  22441. // Our needle is less than aHaystack[mid].
  22442. if (mid - aLow > 1) {
  22443. // The element is in the lower half.
  22444. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  22445. }
  22446. // we are in termination case (3) or (2) and return the appropriate thing.
  22447. if (aBias == exports$1.LEAST_UPPER_BOUND) {
  22448. return mid;
  22449. } else {
  22450. return aLow < 0 ? -1 : aLow;
  22451. }
  22452. }
  22453. }
  22454. /**
  22455. * This is an implementation of binary search which will always try and return
  22456. * the index of the closest element if there is no exact hit. This is because
  22457. * mappings between original and generated line/col pairs are single points,
  22458. * and there is an implicit region between each of them, so a miss just means
  22459. * that you aren't on the very start of a region.
  22460. *
  22461. * @param aNeedle The element you are looking for.
  22462. * @param aHaystack The array that is being searched.
  22463. * @param aCompare A function which takes the needle and an element in the
  22464. * array and returns -1, 0, or 1 depending on whether the needle is less
  22465. * than, equal to, or greater than the element, respectively.
  22466. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  22467. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  22468. * closest element that is smaller than or greater than the one we are
  22469. * searching for, respectively, if the exact element cannot be found.
  22470. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  22471. */
  22472. exports$1.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  22473. if (aHaystack.length === 0) {
  22474. return -1;
  22475. }
  22476. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  22477. aCompare, aBias || exports$1.GREATEST_LOWER_BOUND);
  22478. if (index < 0) {
  22479. return -1;
  22480. }
  22481. // We have found either the exact element, or the next-closest element than
  22482. // the one we are searching for. However, there may be more than one such
  22483. // element. Make sure we always return the smallest of these.
  22484. while (index - 1 >= 0) {
  22485. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  22486. break;
  22487. }
  22488. --index;
  22489. }
  22490. return index;
  22491. };
  22492. } (binarySearch$1));
  22493. return binarySearch$1;
  22494. }
  22495. var quickSort$1 = {};
  22496. /* -*- Mode: js; js-indent-level: 2; -*- */
  22497. var hasRequiredQuickSort$1;
  22498. function requireQuickSort$1 () {
  22499. if (hasRequiredQuickSort$1) return quickSort$1;
  22500. hasRequiredQuickSort$1 = 1;
  22501. /*
  22502. * Copyright 2011 Mozilla Foundation and contributors
  22503. * Licensed under the New BSD license. See LICENSE or:
  22504. * http://opensource.org/licenses/BSD-3-Clause
  22505. */
  22506. // It turns out that some (most?) JavaScript engines don't self-host
  22507. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  22508. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  22509. // custom comparator function, calling back and forth between the VM's C++ and
  22510. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  22511. // worse generated code for the comparator function than would be optimal. In
  22512. // fact, when sorting with a comparator, these costs outweigh the benefits of
  22513. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  22514. // a ~3500ms mean speed-up in `bench/bench.html`.
  22515. function SortTemplate(comparator) {
  22516. /**
  22517. * Swap the elements indexed by `x` and `y` in the array `ary`.
  22518. *
  22519. * @param {Array} ary
  22520. * The array.
  22521. * @param {Number} x
  22522. * The index of the first item.
  22523. * @param {Number} y
  22524. * The index of the second item.
  22525. */
  22526. function swap(ary, x, y) {
  22527. var temp = ary[x];
  22528. ary[x] = ary[y];
  22529. ary[y] = temp;
  22530. }
  22531. /**
  22532. * Returns a random integer within the range `low .. high` inclusive.
  22533. *
  22534. * @param {Number} low
  22535. * The lower bound on the range.
  22536. * @param {Number} high
  22537. * The upper bound on the range.
  22538. */
  22539. function randomIntInRange(low, high) {
  22540. return Math.round(low + (Math.random() * (high - low)));
  22541. }
  22542. /**
  22543. * The Quick Sort algorithm.
  22544. *
  22545. * @param {Array} ary
  22546. * An array to sort.
  22547. * @param {function} comparator
  22548. * Function to use to compare two items.
  22549. * @param {Number} p
  22550. * Start index of the array
  22551. * @param {Number} r
  22552. * End index of the array
  22553. */
  22554. function doQuickSort(ary, comparator, p, r) {
  22555. // If our lower bound is less than our upper bound, we (1) partition the
  22556. // array into two pieces and (2) recurse on each half. If it is not, this is
  22557. // the empty array and our base case.
  22558. if (p < r) {
  22559. // (1) Partitioning.
  22560. //
  22561. // The partitioning chooses a pivot between `p` and `r` and moves all
  22562. // elements that are less than or equal to the pivot to the before it, and
  22563. // all the elements that are greater than it after it. The effect is that
  22564. // once partition is done, the pivot is in the exact place it will be when
  22565. // the array is put in sorted order, and it will not need to be moved
  22566. // again. This runs in O(n) time.
  22567. // Always choose a random pivot so that an input array which is reverse
  22568. // sorted does not cause O(n^2) running time.
  22569. var pivotIndex = randomIntInRange(p, r);
  22570. var i = p - 1;
  22571. swap(ary, pivotIndex, r);
  22572. var pivot = ary[r];
  22573. // Immediately after `j` is incremented in this loop, the following hold
  22574. // true:
  22575. //
  22576. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  22577. //
  22578. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  22579. for (var j = p; j < r; j++) {
  22580. if (comparator(ary[j], pivot, false) <= 0) {
  22581. i += 1;
  22582. swap(ary, i, j);
  22583. }
  22584. }
  22585. swap(ary, i + 1, j);
  22586. var q = i + 1;
  22587. // (2) Recurse on each half.
  22588. doQuickSort(ary, comparator, p, q - 1);
  22589. doQuickSort(ary, comparator, q + 1, r);
  22590. }
  22591. }
  22592. return doQuickSort;
  22593. }
  22594. function cloneSort(comparator) {
  22595. let template = SortTemplate.toString();
  22596. let templateFn = new Function(`return ${template}`)();
  22597. return templateFn(comparator);
  22598. }
  22599. /**
  22600. * Sort the given array in-place with the given comparator function.
  22601. *
  22602. * @param {Array} ary
  22603. * An array to sort.
  22604. * @param {function} comparator
  22605. * Function to use to compare two items.
  22606. */
  22607. let sortCache = new WeakMap();
  22608. quickSort$1.quickSort = function (ary, comparator, start = 0) {
  22609. let doQuickSort = sortCache.get(comparator);
  22610. if (doQuickSort === void 0) {
  22611. doQuickSort = cloneSort(comparator);
  22612. sortCache.set(comparator, doQuickSort);
  22613. }
  22614. doQuickSort(ary, comparator, start, ary.length - 1);
  22615. };
  22616. return quickSort$1;
  22617. }
  22618. /* -*- Mode: js; js-indent-level: 2; -*- */
  22619. var hasRequiredSourceMapConsumer$1;
  22620. function requireSourceMapConsumer$1 () {
  22621. if (hasRequiredSourceMapConsumer$1) return sourceMapConsumer$1;
  22622. hasRequiredSourceMapConsumer$1 = 1;
  22623. /*
  22624. * Copyright 2011 Mozilla Foundation and contributors
  22625. * Licensed under the New BSD license. See LICENSE or:
  22626. * http://opensource.org/licenses/BSD-3-Clause
  22627. */
  22628. var util = /*@__PURE__*/ requireUtil$2();
  22629. var binarySearch = /*@__PURE__*/ requireBinarySearch$1();
  22630. var ArraySet = /*@__PURE__*/ requireArraySet$1().ArraySet;
  22631. var base64VLQ = /*@__PURE__*/ requireBase64Vlq$1();
  22632. var quickSort = /*@__PURE__*/ requireQuickSort$1().quickSort;
  22633. function SourceMapConsumer(aSourceMap, aSourceMapURL) {
  22634. var sourceMap = aSourceMap;
  22635. if (typeof aSourceMap === 'string') {
  22636. sourceMap = util.parseSourceMapInput(aSourceMap);
  22637. }
  22638. return sourceMap.sections != null
  22639. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  22640. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  22641. }
  22642. SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  22643. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  22644. };
  22645. /**
  22646. * The version of the source mapping spec that we are consuming.
  22647. */
  22648. SourceMapConsumer.prototype._version = 3;
  22649. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  22650. // parsed mapping coordinates from the source map's "mappings" attribute. They
  22651. // are lazily instantiated, accessed via the `_generatedMappings` and
  22652. // `_originalMappings` getters respectively, and we only parse the mappings
  22653. // and create these arrays once queried for a source location. We jump through
  22654. // these hoops because there can be many thousands of mappings, and parsing
  22655. // them is expensive, so we only want to do it if we must.
  22656. //
  22657. // Each object in the arrays is of the form:
  22658. //
  22659. // {
  22660. // generatedLine: The line number in the generated code,
  22661. // generatedColumn: The column number in the generated code,
  22662. // source: The path to the original source file that generated this
  22663. // chunk of code,
  22664. // originalLine: The line number in the original source that
  22665. // corresponds to this chunk of generated code,
  22666. // originalColumn: The column number in the original source that
  22667. // corresponds to this chunk of generated code,
  22668. // name: The name of the original symbol which generated this chunk of
  22669. // code.
  22670. // }
  22671. //
  22672. // All properties except for `generatedLine` and `generatedColumn` can be
  22673. // `null`.
  22674. //
  22675. // `_generatedMappings` is ordered by the generated positions.
  22676. //
  22677. // `_originalMappings` is ordered by the original positions.
  22678. SourceMapConsumer.prototype.__generatedMappings = null;
  22679. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  22680. configurable: true,
  22681. enumerable: true,
  22682. get: function () {
  22683. if (!this.__generatedMappings) {
  22684. this._parseMappings(this._mappings, this.sourceRoot);
  22685. }
  22686. return this.__generatedMappings;
  22687. }
  22688. });
  22689. SourceMapConsumer.prototype.__originalMappings = null;
  22690. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  22691. configurable: true,
  22692. enumerable: true,
  22693. get: function () {
  22694. if (!this.__originalMappings) {
  22695. this._parseMappings(this._mappings, this.sourceRoot);
  22696. }
  22697. return this.__originalMappings;
  22698. }
  22699. });
  22700. SourceMapConsumer.prototype._charIsMappingSeparator =
  22701. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  22702. var c = aStr.charAt(index);
  22703. return c === ";" || c === ",";
  22704. };
  22705. /**
  22706. * Parse the mappings in a string in to a data structure which we can easily
  22707. * query (the ordered arrays in the `this.__generatedMappings` and
  22708. * `this.__originalMappings` properties).
  22709. */
  22710. SourceMapConsumer.prototype._parseMappings =
  22711. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  22712. throw new Error("Subclasses must implement _parseMappings");
  22713. };
  22714. SourceMapConsumer.GENERATED_ORDER = 1;
  22715. SourceMapConsumer.ORIGINAL_ORDER = 2;
  22716. SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
  22717. SourceMapConsumer.LEAST_UPPER_BOUND = 2;
  22718. /**
  22719. * Iterate over each mapping between an original source/line/column and a
  22720. * generated line/column in this source map.
  22721. *
  22722. * @param Function aCallback
  22723. * The function that is called with each mapping.
  22724. * @param Object aContext
  22725. * Optional. If specified, this object will be the value of `this` every
  22726. * time that `aCallback` is called.
  22727. * @param aOrder
  22728. * Either `SourceMapConsumer.GENERATED_ORDER` or
  22729. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  22730. * iterate over the mappings sorted by the generated file's line/column
  22731. * order or the original's source/line/column order, respectively. Defaults to
  22732. * `SourceMapConsumer.GENERATED_ORDER`.
  22733. */
  22734. SourceMapConsumer.prototype.eachMapping =
  22735. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  22736. var context = aContext || null;
  22737. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  22738. var mappings;
  22739. switch (order) {
  22740. case SourceMapConsumer.GENERATED_ORDER:
  22741. mappings = this._generatedMappings;
  22742. break;
  22743. case SourceMapConsumer.ORIGINAL_ORDER:
  22744. mappings = this._originalMappings;
  22745. break;
  22746. default:
  22747. throw new Error("Unknown order of iteration.");
  22748. }
  22749. var sourceRoot = this.sourceRoot;
  22750. var boundCallback = aCallback.bind(context);
  22751. var names = this._names;
  22752. var sources = this._sources;
  22753. var sourceMapURL = this._sourceMapURL;
  22754. for (var i = 0, n = mappings.length; i < n; i++) {
  22755. var mapping = mappings[i];
  22756. var source = mapping.source === null ? null : sources.at(mapping.source);
  22757. if(source !== null) {
  22758. source = util.computeSourceURL(sourceRoot, source, sourceMapURL);
  22759. }
  22760. boundCallback({
  22761. source: source,
  22762. generatedLine: mapping.generatedLine,
  22763. generatedColumn: mapping.generatedColumn,
  22764. originalLine: mapping.originalLine,
  22765. originalColumn: mapping.originalColumn,
  22766. name: mapping.name === null ? null : names.at(mapping.name)
  22767. });
  22768. }
  22769. };
  22770. /**
  22771. * Returns all generated line and column information for the original source,
  22772. * line, and column provided. If no column is provided, returns all mappings
  22773. * corresponding to a either the line we are searching for or the next
  22774. * closest line that has any mappings. Otherwise, returns all mappings
  22775. * corresponding to the given line and either the column we are searching for
  22776. * or the next closest column that has any offsets.
  22777. *
  22778. * The only argument is an object with the following properties:
  22779. *
  22780. * - source: The filename of the original source.
  22781. * - line: The line number in the original source. The line number is 1-based.
  22782. * - column: Optional. the column number in the original source.
  22783. * The column number is 0-based.
  22784. *
  22785. * and an array of objects is returned, each with the following properties:
  22786. *
  22787. * - line: The line number in the generated source, or null. The
  22788. * line number is 1-based.
  22789. * - column: The column number in the generated source, or null.
  22790. * The column number is 0-based.
  22791. */
  22792. SourceMapConsumer.prototype.allGeneratedPositionsFor =
  22793. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  22794. var line = util.getArg(aArgs, 'line');
  22795. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  22796. // returns the index of the closest mapping less than the needle. By
  22797. // setting needle.originalColumn to 0, we thus find the last mapping for
  22798. // the given line, provided such a mapping exists.
  22799. var needle = {
  22800. source: util.getArg(aArgs, 'source'),
  22801. originalLine: line,
  22802. originalColumn: util.getArg(aArgs, 'column', 0)
  22803. };
  22804. needle.source = this._findSourceIndex(needle.source);
  22805. if (needle.source < 0) {
  22806. return [];
  22807. }
  22808. var mappings = [];
  22809. var index = this._findMapping(needle,
  22810. this._originalMappings,
  22811. "originalLine",
  22812. "originalColumn",
  22813. util.compareByOriginalPositions,
  22814. binarySearch.LEAST_UPPER_BOUND);
  22815. if (index >= 0) {
  22816. var mapping = this._originalMappings[index];
  22817. if (aArgs.column === undefined) {
  22818. var originalLine = mapping.originalLine;
  22819. // Iterate until either we run out of mappings, or we run into
  22820. // a mapping for a different line than the one we found. Since
  22821. // mappings are sorted, this is guaranteed to find all mappings for
  22822. // the line we found.
  22823. while (mapping && mapping.originalLine === originalLine) {
  22824. mappings.push({
  22825. line: util.getArg(mapping, 'generatedLine', null),
  22826. column: util.getArg(mapping, 'generatedColumn', null),
  22827. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  22828. });
  22829. mapping = this._originalMappings[++index];
  22830. }
  22831. } else {
  22832. var originalColumn = mapping.originalColumn;
  22833. // Iterate until either we run out of mappings, or we run into
  22834. // a mapping for a different line than the one we were searching for.
  22835. // Since mappings are sorted, this is guaranteed to find all mappings for
  22836. // the line we are searching for.
  22837. while (mapping &&
  22838. mapping.originalLine === line &&
  22839. mapping.originalColumn == originalColumn) {
  22840. mappings.push({
  22841. line: util.getArg(mapping, 'generatedLine', null),
  22842. column: util.getArg(mapping, 'generatedColumn', null),
  22843. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  22844. });
  22845. mapping = this._originalMappings[++index];
  22846. }
  22847. }
  22848. }
  22849. return mappings;
  22850. };
  22851. sourceMapConsumer$1.SourceMapConsumer = SourceMapConsumer;
  22852. /**
  22853. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  22854. * query for information about the original file positions by giving it a file
  22855. * position in the generated source.
  22856. *
  22857. * The first parameter is the raw source map (either as a JSON string, or
  22858. * already parsed to an object). According to the spec, source maps have the
  22859. * following attributes:
  22860. *
  22861. * - version: Which version of the source map spec this map is following.
  22862. * - sources: An array of URLs to the original source files.
  22863. * - names: An array of identifiers which can be referrenced by individual mappings.
  22864. * - sourceRoot: Optional. The URL root from which all sources are relative.
  22865. * - sourcesContent: Optional. An array of contents of the original source files.
  22866. * - mappings: A string of base64 VLQs which contain the actual mappings.
  22867. * - file: Optional. The generated file this source map is associated with.
  22868. *
  22869. * Here is an example source map, taken from the source map spec[0]:
  22870. *
  22871. * {
  22872. * version : 3,
  22873. * file: "out.js",
  22874. * sourceRoot : "",
  22875. * sources: ["foo.js", "bar.js"],
  22876. * names: ["src", "maps", "are", "fun"],
  22877. * mappings: "AA,AB;;ABCDE;"
  22878. * }
  22879. *
  22880. * The second parameter, if given, is a string whose value is the URL
  22881. * at which the source map was found. This URL is used to compute the
  22882. * sources array.
  22883. *
  22884. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  22885. */
  22886. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  22887. var sourceMap = aSourceMap;
  22888. if (typeof aSourceMap === 'string') {
  22889. sourceMap = util.parseSourceMapInput(aSourceMap);
  22890. }
  22891. var version = util.getArg(sourceMap, 'version');
  22892. var sources = util.getArg(sourceMap, 'sources');
  22893. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  22894. // requires the array) to play nice here.
  22895. var names = util.getArg(sourceMap, 'names', []);
  22896. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  22897. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  22898. var mappings = util.getArg(sourceMap, 'mappings');
  22899. var file = util.getArg(sourceMap, 'file', null);
  22900. // Once again, Sass deviates from the spec and supplies the version as a
  22901. // string rather than a number, so we use loose equality checking here.
  22902. if (version != this._version) {
  22903. throw new Error('Unsupported version: ' + version);
  22904. }
  22905. if (sourceRoot) {
  22906. sourceRoot = util.normalize(sourceRoot);
  22907. }
  22908. sources = sources
  22909. .map(String)
  22910. // Some source maps produce relative source paths like "./foo.js" instead of
  22911. // "foo.js". Normalize these first so that future comparisons will succeed.
  22912. // See bugzil.la/1090768.
  22913. .map(util.normalize)
  22914. // Always ensure that absolute sources are internally stored relative to
  22915. // the source root, if the source root is absolute. Not doing this would
  22916. // be particularly problematic when the source root is a prefix of the
  22917. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  22918. .map(function (source) {
  22919. return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
  22920. ? util.relative(sourceRoot, source)
  22921. : source;
  22922. });
  22923. // Pass `true` below to allow duplicate names and sources. While source maps
  22924. // are intended to be compressed and deduplicated, the TypeScript compiler
  22925. // sometimes generates source maps with duplicates in them. See Github issue
  22926. // #72 and bugzil.la/889492.
  22927. this._names = ArraySet.fromArray(names.map(String), true);
  22928. this._sources = ArraySet.fromArray(sources, true);
  22929. this._absoluteSources = this._sources.toArray().map(function (s) {
  22930. return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
  22931. });
  22932. this.sourceRoot = sourceRoot;
  22933. this.sourcesContent = sourcesContent;
  22934. this._mappings = mappings;
  22935. this._sourceMapURL = aSourceMapURL;
  22936. this.file = file;
  22937. }
  22938. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  22939. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
  22940. /**
  22941. * Utility function to find the index of a source. Returns -1 if not
  22942. * found.
  22943. */
  22944. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  22945. var relativeSource = aSource;
  22946. if (this.sourceRoot != null) {
  22947. relativeSource = util.relative(this.sourceRoot, relativeSource);
  22948. }
  22949. if (this._sources.has(relativeSource)) {
  22950. return this._sources.indexOf(relativeSource);
  22951. }
  22952. // Maybe aSource is an absolute URL as returned by |sources|. In
  22953. // this case we can't simply undo the transform.
  22954. var i;
  22955. for (i = 0; i < this._absoluteSources.length; ++i) {
  22956. if (this._absoluteSources[i] == aSource) {
  22957. return i;
  22958. }
  22959. }
  22960. return -1;
  22961. };
  22962. /**
  22963. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  22964. *
  22965. * @param SourceMapGenerator aSourceMap
  22966. * The source map that will be consumed.
  22967. * @param String aSourceMapURL
  22968. * The URL at which the source map can be found (optional)
  22969. * @returns BasicSourceMapConsumer
  22970. */
  22971. BasicSourceMapConsumer.fromSourceMap =
  22972. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  22973. var smc = Object.create(BasicSourceMapConsumer.prototype);
  22974. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  22975. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  22976. smc.sourceRoot = aSourceMap._sourceRoot;
  22977. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  22978. smc.sourceRoot);
  22979. smc.file = aSourceMap._file;
  22980. smc._sourceMapURL = aSourceMapURL;
  22981. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  22982. return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  22983. });
  22984. // Because we are modifying the entries (by converting string sources and
  22985. // names to indices into the sources and names ArraySets), we have to make
  22986. // a copy of the entry or else bad things happen. Shared mutable state
  22987. // strikes again! See github issue #191.
  22988. var generatedMappings = aSourceMap._mappings.toArray().slice();
  22989. var destGeneratedMappings = smc.__generatedMappings = [];
  22990. var destOriginalMappings = smc.__originalMappings = [];
  22991. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  22992. var srcMapping = generatedMappings[i];
  22993. var destMapping = new Mapping;
  22994. destMapping.generatedLine = srcMapping.generatedLine;
  22995. destMapping.generatedColumn = srcMapping.generatedColumn;
  22996. if (srcMapping.source) {
  22997. destMapping.source = sources.indexOf(srcMapping.source);
  22998. destMapping.originalLine = srcMapping.originalLine;
  22999. destMapping.originalColumn = srcMapping.originalColumn;
  23000. if (srcMapping.name) {
  23001. destMapping.name = names.indexOf(srcMapping.name);
  23002. }
  23003. destOriginalMappings.push(destMapping);
  23004. }
  23005. destGeneratedMappings.push(destMapping);
  23006. }
  23007. quickSort(smc.__originalMappings, util.compareByOriginalPositions);
  23008. return smc;
  23009. };
  23010. /**
  23011. * The version of the source mapping spec that we are consuming.
  23012. */
  23013. BasicSourceMapConsumer.prototype._version = 3;
  23014. /**
  23015. * The list of original sources.
  23016. */
  23017. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  23018. get: function () {
  23019. return this._absoluteSources.slice();
  23020. }
  23021. });
  23022. /**
  23023. * Provide the JIT with a nice shape / hidden class.
  23024. */
  23025. function Mapping() {
  23026. this.generatedLine = 0;
  23027. this.generatedColumn = 0;
  23028. this.source = null;
  23029. this.originalLine = null;
  23030. this.originalColumn = null;
  23031. this.name = null;
  23032. }
  23033. /**
  23034. * Parse the mappings in a string in to a data structure which we can easily
  23035. * query (the ordered arrays in the `this.__generatedMappings` and
  23036. * `this.__originalMappings` properties).
  23037. */
  23038. const compareGenerated = util.compareByGeneratedPositionsDeflatedNoLine;
  23039. function sortGenerated(array, start) {
  23040. let l = array.length;
  23041. let n = array.length - start;
  23042. if (n <= 1) {
  23043. return;
  23044. } else if (n == 2) {
  23045. let a = array[start];
  23046. let b = array[start + 1];
  23047. if (compareGenerated(a, b) > 0) {
  23048. array[start] = b;
  23049. array[start + 1] = a;
  23050. }
  23051. } else if (n < 20) {
  23052. for (let i = start; i < l; i++) {
  23053. for (let j = i; j > start; j--) {
  23054. let a = array[j - 1];
  23055. let b = array[j];
  23056. if (compareGenerated(a, b) <= 0) {
  23057. break;
  23058. }
  23059. array[j - 1] = b;
  23060. array[j] = a;
  23061. }
  23062. }
  23063. } else {
  23064. quickSort(array, compareGenerated, start);
  23065. }
  23066. }
  23067. BasicSourceMapConsumer.prototype._parseMappings =
  23068. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  23069. var generatedLine = 1;
  23070. var previousGeneratedColumn = 0;
  23071. var previousOriginalLine = 0;
  23072. var previousOriginalColumn = 0;
  23073. var previousSource = 0;
  23074. var previousName = 0;
  23075. var length = aStr.length;
  23076. var index = 0;
  23077. var temp = {};
  23078. var originalMappings = [];
  23079. var generatedMappings = [];
  23080. var mapping, segment, end, value;
  23081. let subarrayStart = 0;
  23082. while (index < length) {
  23083. if (aStr.charAt(index) === ';') {
  23084. generatedLine++;
  23085. index++;
  23086. previousGeneratedColumn = 0;
  23087. sortGenerated(generatedMappings, subarrayStart);
  23088. subarrayStart = generatedMappings.length;
  23089. }
  23090. else if (aStr.charAt(index) === ',') {
  23091. index++;
  23092. }
  23093. else {
  23094. mapping = new Mapping();
  23095. mapping.generatedLine = generatedLine;
  23096. for (end = index; end < length; end++) {
  23097. if (this._charIsMappingSeparator(aStr, end)) {
  23098. break;
  23099. }
  23100. }
  23101. aStr.slice(index, end);
  23102. segment = [];
  23103. while (index < end) {
  23104. base64VLQ.decode(aStr, index, temp);
  23105. value = temp.value;
  23106. index = temp.rest;
  23107. segment.push(value);
  23108. }
  23109. if (segment.length === 2) {
  23110. throw new Error('Found a source, but no line and column');
  23111. }
  23112. if (segment.length === 3) {
  23113. throw new Error('Found a source and line, but no column');
  23114. }
  23115. // Generated column.
  23116. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  23117. previousGeneratedColumn = mapping.generatedColumn;
  23118. if (segment.length > 1) {
  23119. // Original source.
  23120. mapping.source = previousSource + segment[1];
  23121. previousSource += segment[1];
  23122. // Original line.
  23123. mapping.originalLine = previousOriginalLine + segment[2];
  23124. previousOriginalLine = mapping.originalLine;
  23125. // Lines are stored 0-based
  23126. mapping.originalLine += 1;
  23127. // Original column.
  23128. mapping.originalColumn = previousOriginalColumn + segment[3];
  23129. previousOriginalColumn = mapping.originalColumn;
  23130. if (segment.length > 4) {
  23131. // Original name.
  23132. mapping.name = previousName + segment[4];
  23133. previousName += segment[4];
  23134. }
  23135. }
  23136. generatedMappings.push(mapping);
  23137. if (typeof mapping.originalLine === 'number') {
  23138. let currentSource = mapping.source;
  23139. while (originalMappings.length <= currentSource) {
  23140. originalMappings.push(null);
  23141. }
  23142. if (originalMappings[currentSource] === null) {
  23143. originalMappings[currentSource] = [];
  23144. }
  23145. originalMappings[currentSource].push(mapping);
  23146. }
  23147. }
  23148. }
  23149. sortGenerated(generatedMappings, subarrayStart);
  23150. this.__generatedMappings = generatedMappings;
  23151. for (var i = 0; i < originalMappings.length; i++) {
  23152. if (originalMappings[i] != null) {
  23153. quickSort(originalMappings[i], util.compareByOriginalPositionsNoSource);
  23154. }
  23155. }
  23156. this.__originalMappings = [].concat(...originalMappings);
  23157. };
  23158. /**
  23159. * Find the mapping that best matches the hypothetical "needle" mapping that
  23160. * we are searching for in the given "haystack" of mappings.
  23161. */
  23162. BasicSourceMapConsumer.prototype._findMapping =
  23163. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  23164. aColumnName, aComparator, aBias) {
  23165. // To return the position we are searching for, we must first find the
  23166. // mapping for the given position and then return the opposite position it
  23167. // points to. Because the mappings are sorted, we can use binary search to
  23168. // find the best mapping.
  23169. if (aNeedle[aLineName] <= 0) {
  23170. throw new TypeError('Line must be greater than or equal to 1, got '
  23171. + aNeedle[aLineName]);
  23172. }
  23173. if (aNeedle[aColumnName] < 0) {
  23174. throw new TypeError('Column must be greater than or equal to 0, got '
  23175. + aNeedle[aColumnName]);
  23176. }
  23177. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  23178. };
  23179. /**
  23180. * Compute the last column for each generated mapping. The last column is
  23181. * inclusive.
  23182. */
  23183. BasicSourceMapConsumer.prototype.computeColumnSpans =
  23184. function SourceMapConsumer_computeColumnSpans() {
  23185. for (var index = 0; index < this._generatedMappings.length; ++index) {
  23186. var mapping = this._generatedMappings[index];
  23187. // Mappings do not contain a field for the last generated columnt. We
  23188. // can come up with an optimistic estimate, however, by assuming that
  23189. // mappings are contiguous (i.e. given two consecutive mappings, the
  23190. // first mapping ends where the second one starts).
  23191. if (index + 1 < this._generatedMappings.length) {
  23192. var nextMapping = this._generatedMappings[index + 1];
  23193. if (mapping.generatedLine === nextMapping.generatedLine) {
  23194. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  23195. continue;
  23196. }
  23197. }
  23198. // The last mapping for each line spans the entire line.
  23199. mapping.lastGeneratedColumn = Infinity;
  23200. }
  23201. };
  23202. /**
  23203. * Returns the original source, line, and column information for the generated
  23204. * source's line and column positions provided. The only argument is an object
  23205. * with the following properties:
  23206. *
  23207. * - line: The line number in the generated source. The line number
  23208. * is 1-based.
  23209. * - column: The column number in the generated source. The column
  23210. * number is 0-based.
  23211. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  23212. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  23213. * closest element that is smaller than or greater than the one we are
  23214. * searching for, respectively, if the exact element cannot be found.
  23215. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  23216. *
  23217. * and an object is returned with the following properties:
  23218. *
  23219. * - source: The original source file, or null.
  23220. * - line: The line number in the original source, or null. The
  23221. * line number is 1-based.
  23222. * - column: The column number in the original source, or null. The
  23223. * column number is 0-based.
  23224. * - name: The original identifier, or null.
  23225. */
  23226. BasicSourceMapConsumer.prototype.originalPositionFor =
  23227. function SourceMapConsumer_originalPositionFor(aArgs) {
  23228. var needle = {
  23229. generatedLine: util.getArg(aArgs, 'line'),
  23230. generatedColumn: util.getArg(aArgs, 'column')
  23231. };
  23232. var index = this._findMapping(
  23233. needle,
  23234. this._generatedMappings,
  23235. "generatedLine",
  23236. "generatedColumn",
  23237. util.compareByGeneratedPositionsDeflated,
  23238. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  23239. );
  23240. if (index >= 0) {
  23241. var mapping = this._generatedMappings[index];
  23242. if (mapping.generatedLine === needle.generatedLine) {
  23243. var source = util.getArg(mapping, 'source', null);
  23244. if (source !== null) {
  23245. source = this._sources.at(source);
  23246. source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  23247. }
  23248. var name = util.getArg(mapping, 'name', null);
  23249. if (name !== null) {
  23250. name = this._names.at(name);
  23251. }
  23252. return {
  23253. source: source,
  23254. line: util.getArg(mapping, 'originalLine', null),
  23255. column: util.getArg(mapping, 'originalColumn', null),
  23256. name: name
  23257. };
  23258. }
  23259. }
  23260. return {
  23261. source: null,
  23262. line: null,
  23263. column: null,
  23264. name: null
  23265. };
  23266. };
  23267. /**
  23268. * Return true if we have the source content for every source in the source
  23269. * map, false otherwise.
  23270. */
  23271. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  23272. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  23273. if (!this.sourcesContent) {
  23274. return false;
  23275. }
  23276. return this.sourcesContent.length >= this._sources.size() &&
  23277. !this.sourcesContent.some(function (sc) { return sc == null; });
  23278. };
  23279. /**
  23280. * Returns the original source content. The only argument is the url of the
  23281. * original source file. Returns null if no original source content is
  23282. * available.
  23283. */
  23284. BasicSourceMapConsumer.prototype.sourceContentFor =
  23285. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  23286. if (!this.sourcesContent) {
  23287. return null;
  23288. }
  23289. var index = this._findSourceIndex(aSource);
  23290. if (index >= 0) {
  23291. return this.sourcesContent[index];
  23292. }
  23293. var relativeSource = aSource;
  23294. if (this.sourceRoot != null) {
  23295. relativeSource = util.relative(this.sourceRoot, relativeSource);
  23296. }
  23297. var url;
  23298. if (this.sourceRoot != null
  23299. && (url = util.urlParse(this.sourceRoot))) {
  23300. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  23301. // many users. We can help them out when they expect file:// URIs to
  23302. // behave like it would if they were running a local HTTP server. See
  23303. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  23304. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  23305. if (url.scheme == "file"
  23306. && this._sources.has(fileUriAbsPath)) {
  23307. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  23308. }
  23309. if ((!url.path || url.path == "/")
  23310. && this._sources.has("/" + relativeSource)) {
  23311. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  23312. }
  23313. }
  23314. // This function is used recursively from
  23315. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  23316. // don't want to throw if we can't find the source - we just want to
  23317. // return null, so we provide a flag to exit gracefully.
  23318. if (nullOnMissing) {
  23319. return null;
  23320. }
  23321. else {
  23322. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  23323. }
  23324. };
  23325. /**
  23326. * Returns the generated line and column information for the original source,
  23327. * line, and column positions provided. The only argument is an object with
  23328. * the following properties:
  23329. *
  23330. * - source: The filename of the original source.
  23331. * - line: The line number in the original source. The line number
  23332. * is 1-based.
  23333. * - column: The column number in the original source. The column
  23334. * number is 0-based.
  23335. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  23336. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  23337. * closest element that is smaller than or greater than the one we are
  23338. * searching for, respectively, if the exact element cannot be found.
  23339. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  23340. *
  23341. * and an object is returned with the following properties:
  23342. *
  23343. * - line: The line number in the generated source, or null. The
  23344. * line number is 1-based.
  23345. * - column: The column number in the generated source, or null.
  23346. * The column number is 0-based.
  23347. */
  23348. BasicSourceMapConsumer.prototype.generatedPositionFor =
  23349. function SourceMapConsumer_generatedPositionFor(aArgs) {
  23350. var source = util.getArg(aArgs, 'source');
  23351. source = this._findSourceIndex(source);
  23352. if (source < 0) {
  23353. return {
  23354. line: null,
  23355. column: null,
  23356. lastColumn: null
  23357. };
  23358. }
  23359. var needle = {
  23360. source: source,
  23361. originalLine: util.getArg(aArgs, 'line'),
  23362. originalColumn: util.getArg(aArgs, 'column')
  23363. };
  23364. var index = this._findMapping(
  23365. needle,
  23366. this._originalMappings,
  23367. "originalLine",
  23368. "originalColumn",
  23369. util.compareByOriginalPositions,
  23370. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  23371. );
  23372. if (index >= 0) {
  23373. var mapping = this._originalMappings[index];
  23374. if (mapping.source === needle.source) {
  23375. return {
  23376. line: util.getArg(mapping, 'generatedLine', null),
  23377. column: util.getArg(mapping, 'generatedColumn', null),
  23378. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  23379. };
  23380. }
  23381. }
  23382. return {
  23383. line: null,
  23384. column: null,
  23385. lastColumn: null
  23386. };
  23387. };
  23388. sourceMapConsumer$1.BasicSourceMapConsumer = BasicSourceMapConsumer;
  23389. /**
  23390. * An IndexedSourceMapConsumer instance represents a parsed source map which
  23391. * we can query for information. It differs from BasicSourceMapConsumer in
  23392. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  23393. * input.
  23394. *
  23395. * The first parameter is a raw source map (either as a JSON string, or already
  23396. * parsed to an object). According to the spec for indexed source maps, they
  23397. * have the following attributes:
  23398. *
  23399. * - version: Which version of the source map spec this map is following.
  23400. * - file: Optional. The generated file this source map is associated with.
  23401. * - sections: A list of section definitions.
  23402. *
  23403. * Each value under the "sections" field has two fields:
  23404. * - offset: The offset into the original specified at which this section
  23405. * begins to apply, defined as an object with a "line" and "column"
  23406. * field.
  23407. * - map: A source map definition. This source map could also be indexed,
  23408. * but doesn't have to be.
  23409. *
  23410. * Instead of the "map" field, it's also possible to have a "url" field
  23411. * specifying a URL to retrieve a source map from, but that's currently
  23412. * unsupported.
  23413. *
  23414. * Here's an example source map, taken from the source map spec[0], but
  23415. * modified to omit a section which uses the "url" field.
  23416. *
  23417. * {
  23418. * version : 3,
  23419. * file: "app.js",
  23420. * sections: [{
  23421. * offset: {line:100, column:10},
  23422. * map: {
  23423. * version : 3,
  23424. * file: "section.js",
  23425. * sources: ["foo.js", "bar.js"],
  23426. * names: ["src", "maps", "are", "fun"],
  23427. * mappings: "AAAA,E;;ABCDE;"
  23428. * }
  23429. * }],
  23430. * }
  23431. *
  23432. * The second parameter, if given, is a string whose value is the URL
  23433. * at which the source map was found. This URL is used to compute the
  23434. * sources array.
  23435. *
  23436. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  23437. */
  23438. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  23439. var sourceMap = aSourceMap;
  23440. if (typeof aSourceMap === 'string') {
  23441. sourceMap = util.parseSourceMapInput(aSourceMap);
  23442. }
  23443. var version = util.getArg(sourceMap, 'version');
  23444. var sections = util.getArg(sourceMap, 'sections');
  23445. if (version != this._version) {
  23446. throw new Error('Unsupported version: ' + version);
  23447. }
  23448. this._sources = new ArraySet();
  23449. this._names = new ArraySet();
  23450. var lastOffset = {
  23451. line: -1,
  23452. column: 0
  23453. };
  23454. this._sections = sections.map(function (s) {
  23455. if (s.url) {
  23456. // The url field will require support for asynchronicity.
  23457. // See https://github.com/mozilla/source-map/issues/16
  23458. throw new Error('Support for url field in sections not implemented.');
  23459. }
  23460. var offset = util.getArg(s, 'offset');
  23461. var offsetLine = util.getArg(offset, 'line');
  23462. var offsetColumn = util.getArg(offset, 'column');
  23463. if (offsetLine < lastOffset.line ||
  23464. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  23465. throw new Error('Section offsets must be ordered and non-overlapping.');
  23466. }
  23467. lastOffset = offset;
  23468. return {
  23469. generatedOffset: {
  23470. // The offset fields are 0-based, but we use 1-based indices when
  23471. // encoding/decoding from VLQ.
  23472. generatedLine: offsetLine + 1,
  23473. generatedColumn: offsetColumn + 1
  23474. },
  23475. consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
  23476. }
  23477. });
  23478. }
  23479. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  23480. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
  23481. /**
  23482. * The version of the source mapping spec that we are consuming.
  23483. */
  23484. IndexedSourceMapConsumer.prototype._version = 3;
  23485. /**
  23486. * The list of original sources.
  23487. */
  23488. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  23489. get: function () {
  23490. var sources = [];
  23491. for (var i = 0; i < this._sections.length; i++) {
  23492. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  23493. sources.push(this._sections[i].consumer.sources[j]);
  23494. }
  23495. }
  23496. return sources;
  23497. }
  23498. });
  23499. /**
  23500. * Returns the original source, line, and column information for the generated
  23501. * source's line and column positions provided. The only argument is an object
  23502. * with the following properties:
  23503. *
  23504. * - line: The line number in the generated source. The line number
  23505. * is 1-based.
  23506. * - column: The column number in the generated source. The column
  23507. * number is 0-based.
  23508. *
  23509. * and an object is returned with the following properties:
  23510. *
  23511. * - source: The original source file, or null.
  23512. * - line: The line number in the original source, or null. The
  23513. * line number is 1-based.
  23514. * - column: The column number in the original source, or null. The
  23515. * column number is 0-based.
  23516. * - name: The original identifier, or null.
  23517. */
  23518. IndexedSourceMapConsumer.prototype.originalPositionFor =
  23519. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  23520. var needle = {
  23521. generatedLine: util.getArg(aArgs, 'line'),
  23522. generatedColumn: util.getArg(aArgs, 'column')
  23523. };
  23524. // Find the section containing the generated position we're trying to map
  23525. // to an original position.
  23526. var sectionIndex = binarySearch.search(needle, this._sections,
  23527. function(needle, section) {
  23528. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  23529. if (cmp) {
  23530. return cmp;
  23531. }
  23532. return (needle.generatedColumn -
  23533. section.generatedOffset.generatedColumn);
  23534. });
  23535. var section = this._sections[sectionIndex];
  23536. if (!section) {
  23537. return {
  23538. source: null,
  23539. line: null,
  23540. column: null,
  23541. name: null
  23542. };
  23543. }
  23544. return section.consumer.originalPositionFor({
  23545. line: needle.generatedLine -
  23546. (section.generatedOffset.generatedLine - 1),
  23547. column: needle.generatedColumn -
  23548. (section.generatedOffset.generatedLine === needle.generatedLine
  23549. ? section.generatedOffset.generatedColumn - 1
  23550. : 0),
  23551. bias: aArgs.bias
  23552. });
  23553. };
  23554. /**
  23555. * Return true if we have the source content for every source in the source
  23556. * map, false otherwise.
  23557. */
  23558. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  23559. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  23560. return this._sections.every(function (s) {
  23561. return s.consumer.hasContentsOfAllSources();
  23562. });
  23563. };
  23564. /**
  23565. * Returns the original source content. The only argument is the url of the
  23566. * original source file. Returns null if no original source content is
  23567. * available.
  23568. */
  23569. IndexedSourceMapConsumer.prototype.sourceContentFor =
  23570. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  23571. for (var i = 0; i < this._sections.length; i++) {
  23572. var section = this._sections[i];
  23573. var content = section.consumer.sourceContentFor(aSource, true);
  23574. if (content || content === '') {
  23575. return content;
  23576. }
  23577. }
  23578. if (nullOnMissing) {
  23579. return null;
  23580. }
  23581. else {
  23582. throw new Error('"' + aSource + '" is not in the SourceMap.');
  23583. }
  23584. };
  23585. /**
  23586. * Returns the generated line and column information for the original source,
  23587. * line, and column positions provided. The only argument is an object with
  23588. * the following properties:
  23589. *
  23590. * - source: The filename of the original source.
  23591. * - line: The line number in the original source. The line number
  23592. * is 1-based.
  23593. * - column: The column number in the original source. The column
  23594. * number is 0-based.
  23595. *
  23596. * and an object is returned with the following properties:
  23597. *
  23598. * - line: The line number in the generated source, or null. The
  23599. * line number is 1-based.
  23600. * - column: The column number in the generated source, or null.
  23601. * The column number is 0-based.
  23602. */
  23603. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  23604. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  23605. for (var i = 0; i < this._sections.length; i++) {
  23606. var section = this._sections[i];
  23607. // Only consider this section if the requested source is in the list of
  23608. // sources of the consumer.
  23609. if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
  23610. continue;
  23611. }
  23612. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  23613. if (generatedPosition) {
  23614. var ret = {
  23615. line: generatedPosition.line +
  23616. (section.generatedOffset.generatedLine - 1),
  23617. column: generatedPosition.column +
  23618. (section.generatedOffset.generatedLine === generatedPosition.line
  23619. ? section.generatedOffset.generatedColumn - 1
  23620. : 0)
  23621. };
  23622. return ret;
  23623. }
  23624. }
  23625. return {
  23626. line: null,
  23627. column: null
  23628. };
  23629. };
  23630. /**
  23631. * Parse the mappings in a string in to a data structure which we can easily
  23632. * query (the ordered arrays in the `this.__generatedMappings` and
  23633. * `this.__originalMappings` properties).
  23634. */
  23635. IndexedSourceMapConsumer.prototype._parseMappings =
  23636. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  23637. this.__generatedMappings = [];
  23638. this.__originalMappings = [];
  23639. for (var i = 0; i < this._sections.length; i++) {
  23640. var section = this._sections[i];
  23641. var sectionMappings = section.consumer._generatedMappings;
  23642. for (var j = 0; j < sectionMappings.length; j++) {
  23643. var mapping = sectionMappings[j];
  23644. var source = section.consumer._sources.at(mapping.source);
  23645. if(source !== null) {
  23646. source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  23647. }
  23648. this._sources.add(source);
  23649. source = this._sources.indexOf(source);
  23650. var name = null;
  23651. if (mapping.name) {
  23652. name = section.consumer._names.at(mapping.name);
  23653. this._names.add(name);
  23654. name = this._names.indexOf(name);
  23655. }
  23656. // The mappings coming from the consumer for the section have
  23657. // generated positions relative to the start of the section, so we
  23658. // need to offset them to be relative to the start of the concatenated
  23659. // generated file.
  23660. var adjustedMapping = {
  23661. source: source,
  23662. generatedLine: mapping.generatedLine +
  23663. (section.generatedOffset.generatedLine - 1),
  23664. generatedColumn: mapping.generatedColumn +
  23665. (section.generatedOffset.generatedLine === mapping.generatedLine
  23666. ? section.generatedOffset.generatedColumn - 1
  23667. : 0),
  23668. originalLine: mapping.originalLine,
  23669. originalColumn: mapping.originalColumn,
  23670. name: name
  23671. };
  23672. this.__generatedMappings.push(adjustedMapping);
  23673. if (typeof adjustedMapping.originalLine === 'number') {
  23674. this.__originalMappings.push(adjustedMapping);
  23675. }
  23676. }
  23677. }
  23678. quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
  23679. quickSort(this.__originalMappings, util.compareByOriginalPositions);
  23680. };
  23681. sourceMapConsumer$1.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  23682. return sourceMapConsumer$1;
  23683. }
  23684. var sourceNode$1 = {};
  23685. /* -*- Mode: js; js-indent-level: 2; -*- */
  23686. var hasRequiredSourceNode$1;
  23687. function requireSourceNode$1 () {
  23688. if (hasRequiredSourceNode$1) return sourceNode$1;
  23689. hasRequiredSourceNode$1 = 1;
  23690. /*
  23691. * Copyright 2011 Mozilla Foundation and contributors
  23692. * Licensed under the New BSD license. See LICENSE or:
  23693. * http://opensource.org/licenses/BSD-3-Clause
  23694. */
  23695. var SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator$1().SourceMapGenerator;
  23696. var util = /*@__PURE__*/ requireUtil$2();
  23697. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  23698. // operating systems these days (capturing the result).
  23699. var REGEX_NEWLINE = /(\r?\n)/;
  23700. // Newline character code for charCodeAt() comparisons
  23701. var NEWLINE_CODE = 10;
  23702. // Private symbol for identifying `SourceNode`s when multiple versions of
  23703. // the source-map library are loaded. This MUST NOT CHANGE across
  23704. // versions!
  23705. var isSourceNode = "$$$isSourceNode$$$";
  23706. /**
  23707. * SourceNodes provide a way to abstract over interpolating/concatenating
  23708. * snippets of generated JavaScript source code while maintaining the line and
  23709. * column information associated with the original source code.
  23710. *
  23711. * @param aLine The original line number.
  23712. * @param aColumn The original column number.
  23713. * @param aSource The original source's filename.
  23714. * @param aChunks Optional. An array of strings which are snippets of
  23715. * generated JS, or other SourceNodes.
  23716. * @param aName The original identifier.
  23717. */
  23718. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  23719. this.children = [];
  23720. this.sourceContents = {};
  23721. this.line = aLine == null ? null : aLine;
  23722. this.column = aColumn == null ? null : aColumn;
  23723. this.source = aSource == null ? null : aSource;
  23724. this.name = aName == null ? null : aName;
  23725. this[isSourceNode] = true;
  23726. if (aChunks != null) this.add(aChunks);
  23727. }
  23728. /**
  23729. * Creates a SourceNode from generated code and a SourceMapConsumer.
  23730. *
  23731. * @param aGeneratedCode The generated code
  23732. * @param aSourceMapConsumer The SourceMap for the generated code
  23733. * @param aRelativePath Optional. The path that relative sources in the
  23734. * SourceMapConsumer should be relative to.
  23735. */
  23736. SourceNode.fromStringWithSourceMap =
  23737. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  23738. // The SourceNode we want to fill with the generated code
  23739. // and the SourceMap
  23740. var node = new SourceNode();
  23741. // All even indices of this array are one line of the generated code,
  23742. // while all odd indices are the newlines between two adjacent lines
  23743. // (since `REGEX_NEWLINE` captures its match).
  23744. // Processed fragments are accessed by calling `shiftNextLine`.
  23745. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  23746. var remainingLinesIndex = 0;
  23747. var shiftNextLine = function() {
  23748. var lineContents = getNextLine();
  23749. // The last line of a file might not have a newline.
  23750. var newLine = getNextLine() || "";
  23751. return lineContents + newLine;
  23752. function getNextLine() {
  23753. return remainingLinesIndex < remainingLines.length ?
  23754. remainingLines[remainingLinesIndex++] : undefined;
  23755. }
  23756. };
  23757. // We need to remember the position of "remainingLines"
  23758. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  23759. // The generate SourceNodes we need a code range.
  23760. // To extract it current and last mapping is used.
  23761. // Here we store the last mapping.
  23762. var lastMapping = null;
  23763. aSourceMapConsumer.eachMapping(function (mapping) {
  23764. if (lastMapping !== null) {
  23765. // We add the code from "lastMapping" to "mapping":
  23766. // First check if there is a new line in between.
  23767. if (lastGeneratedLine < mapping.generatedLine) {
  23768. // Associate first line with "lastMapping"
  23769. addMappingWithCode(lastMapping, shiftNextLine());
  23770. lastGeneratedLine++;
  23771. lastGeneratedColumn = 0;
  23772. // The remaining code is added without mapping
  23773. } else {
  23774. // There is no new line in between.
  23775. // Associate the code between "lastGeneratedColumn" and
  23776. // "mapping.generatedColumn" with "lastMapping"
  23777. var nextLine = remainingLines[remainingLinesIndex] || '';
  23778. var code = nextLine.substr(0, mapping.generatedColumn -
  23779. lastGeneratedColumn);
  23780. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  23781. lastGeneratedColumn);
  23782. lastGeneratedColumn = mapping.generatedColumn;
  23783. addMappingWithCode(lastMapping, code);
  23784. // No more remaining code, continue
  23785. lastMapping = mapping;
  23786. return;
  23787. }
  23788. }
  23789. // We add the generated code until the first mapping
  23790. // to the SourceNode without any mapping.
  23791. // Each line is added as separate string.
  23792. while (lastGeneratedLine < mapping.generatedLine) {
  23793. node.add(shiftNextLine());
  23794. lastGeneratedLine++;
  23795. }
  23796. if (lastGeneratedColumn < mapping.generatedColumn) {
  23797. var nextLine = remainingLines[remainingLinesIndex] || '';
  23798. node.add(nextLine.substr(0, mapping.generatedColumn));
  23799. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  23800. lastGeneratedColumn = mapping.generatedColumn;
  23801. }
  23802. lastMapping = mapping;
  23803. }, this);
  23804. // We have processed all mappings.
  23805. if (remainingLinesIndex < remainingLines.length) {
  23806. if (lastMapping) {
  23807. // Associate the remaining code in the current line with "lastMapping"
  23808. addMappingWithCode(lastMapping, shiftNextLine());
  23809. }
  23810. // and add the remaining lines without any mapping
  23811. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  23812. }
  23813. // Copy sourcesContent into SourceNode
  23814. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  23815. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  23816. if (content != null) {
  23817. if (aRelativePath != null) {
  23818. sourceFile = util.join(aRelativePath, sourceFile);
  23819. }
  23820. node.setSourceContent(sourceFile, content);
  23821. }
  23822. });
  23823. return node;
  23824. function addMappingWithCode(mapping, code) {
  23825. if (mapping === null || mapping.source === undefined) {
  23826. node.add(code);
  23827. } else {
  23828. var source = aRelativePath
  23829. ? util.join(aRelativePath, mapping.source)
  23830. : mapping.source;
  23831. node.add(new SourceNode(mapping.originalLine,
  23832. mapping.originalColumn,
  23833. source,
  23834. code,
  23835. mapping.name));
  23836. }
  23837. }
  23838. };
  23839. /**
  23840. * Add a chunk of generated JS to this source node.
  23841. *
  23842. * @param aChunk A string snippet of generated JS code, another instance of
  23843. * SourceNode, or an array where each member is one of those things.
  23844. */
  23845. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  23846. if (Array.isArray(aChunk)) {
  23847. aChunk.forEach(function (chunk) {
  23848. this.add(chunk);
  23849. }, this);
  23850. }
  23851. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  23852. if (aChunk) {
  23853. this.children.push(aChunk);
  23854. }
  23855. }
  23856. else {
  23857. throw new TypeError(
  23858. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  23859. );
  23860. }
  23861. return this;
  23862. };
  23863. /**
  23864. * Add a chunk of generated JS to the beginning of this source node.
  23865. *
  23866. * @param aChunk A string snippet of generated JS code, another instance of
  23867. * SourceNode, or an array where each member is one of those things.
  23868. */
  23869. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  23870. if (Array.isArray(aChunk)) {
  23871. for (var i = aChunk.length-1; i >= 0; i--) {
  23872. this.prepend(aChunk[i]);
  23873. }
  23874. }
  23875. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  23876. this.children.unshift(aChunk);
  23877. }
  23878. else {
  23879. throw new TypeError(
  23880. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  23881. );
  23882. }
  23883. return this;
  23884. };
  23885. /**
  23886. * Walk over the tree of JS snippets in this node and its children. The
  23887. * walking function is called once for each snippet of JS and is passed that
  23888. * snippet and the its original associated source's line/column location.
  23889. *
  23890. * @param aFn The traversal function.
  23891. */
  23892. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  23893. var chunk;
  23894. for (var i = 0, len = this.children.length; i < len; i++) {
  23895. chunk = this.children[i];
  23896. if (chunk[isSourceNode]) {
  23897. chunk.walk(aFn);
  23898. }
  23899. else {
  23900. if (chunk !== '') {
  23901. aFn(chunk, { source: this.source,
  23902. line: this.line,
  23903. column: this.column,
  23904. name: this.name });
  23905. }
  23906. }
  23907. }
  23908. };
  23909. /**
  23910. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  23911. * each of `this.children`.
  23912. *
  23913. * @param aSep The separator.
  23914. */
  23915. SourceNode.prototype.join = function SourceNode_join(aSep) {
  23916. var newChildren;
  23917. var i;
  23918. var len = this.children.length;
  23919. if (len > 0) {
  23920. newChildren = [];
  23921. for (i = 0; i < len-1; i++) {
  23922. newChildren.push(this.children[i]);
  23923. newChildren.push(aSep);
  23924. }
  23925. newChildren.push(this.children[i]);
  23926. this.children = newChildren;
  23927. }
  23928. return this;
  23929. };
  23930. /**
  23931. * Call String.prototype.replace on the very right-most source snippet. Useful
  23932. * for trimming whitespace from the end of a source node, etc.
  23933. *
  23934. * @param aPattern The pattern to replace.
  23935. * @param aReplacement The thing to replace the pattern with.
  23936. */
  23937. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  23938. var lastChild = this.children[this.children.length - 1];
  23939. if (lastChild[isSourceNode]) {
  23940. lastChild.replaceRight(aPattern, aReplacement);
  23941. }
  23942. else if (typeof lastChild === 'string') {
  23943. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  23944. }
  23945. else {
  23946. this.children.push(''.replace(aPattern, aReplacement));
  23947. }
  23948. return this;
  23949. };
  23950. /**
  23951. * Set the source content for a source file. This will be added to the SourceMapGenerator
  23952. * in the sourcesContent field.
  23953. *
  23954. * @param aSourceFile The filename of the source file
  23955. * @param aSourceContent The content of the source file
  23956. */
  23957. SourceNode.prototype.setSourceContent =
  23958. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  23959. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  23960. };
  23961. /**
  23962. * Walk over the tree of SourceNodes. The walking function is called for each
  23963. * source file content and is passed the filename and source content.
  23964. *
  23965. * @param aFn The traversal function.
  23966. */
  23967. SourceNode.prototype.walkSourceContents =
  23968. function SourceNode_walkSourceContents(aFn) {
  23969. for (var i = 0, len = this.children.length; i < len; i++) {
  23970. if (this.children[i][isSourceNode]) {
  23971. this.children[i].walkSourceContents(aFn);
  23972. }
  23973. }
  23974. var sources = Object.keys(this.sourceContents);
  23975. for (var i = 0, len = sources.length; i < len; i++) {
  23976. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  23977. }
  23978. };
  23979. /**
  23980. * Return the string representation of this source node. Walks over the tree
  23981. * and concatenates all the various snippets together to one string.
  23982. */
  23983. SourceNode.prototype.toString = function SourceNode_toString() {
  23984. var str = "";
  23985. this.walk(function (chunk) {
  23986. str += chunk;
  23987. });
  23988. return str;
  23989. };
  23990. /**
  23991. * Returns the string representation of this source node along with a source
  23992. * map.
  23993. */
  23994. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  23995. var generated = {
  23996. code: "",
  23997. line: 1,
  23998. column: 0
  23999. };
  24000. var map = new SourceMapGenerator(aArgs);
  24001. var sourceMappingActive = false;
  24002. var lastOriginalSource = null;
  24003. var lastOriginalLine = null;
  24004. var lastOriginalColumn = null;
  24005. var lastOriginalName = null;
  24006. this.walk(function (chunk, original) {
  24007. generated.code += chunk;
  24008. if (original.source !== null
  24009. && original.line !== null
  24010. && original.column !== null) {
  24011. if(lastOriginalSource !== original.source
  24012. || lastOriginalLine !== original.line
  24013. || lastOriginalColumn !== original.column
  24014. || lastOriginalName !== original.name) {
  24015. map.addMapping({
  24016. source: original.source,
  24017. original: {
  24018. line: original.line,
  24019. column: original.column
  24020. },
  24021. generated: {
  24022. line: generated.line,
  24023. column: generated.column
  24024. },
  24025. name: original.name
  24026. });
  24027. }
  24028. lastOriginalSource = original.source;
  24029. lastOriginalLine = original.line;
  24030. lastOriginalColumn = original.column;
  24031. lastOriginalName = original.name;
  24032. sourceMappingActive = true;
  24033. } else if (sourceMappingActive) {
  24034. map.addMapping({
  24035. generated: {
  24036. line: generated.line,
  24037. column: generated.column
  24038. }
  24039. });
  24040. lastOriginalSource = null;
  24041. sourceMappingActive = false;
  24042. }
  24043. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  24044. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  24045. generated.line++;
  24046. generated.column = 0;
  24047. // Mappings end at eol
  24048. if (idx + 1 === length) {
  24049. lastOriginalSource = null;
  24050. sourceMappingActive = false;
  24051. } else if (sourceMappingActive) {
  24052. map.addMapping({
  24053. source: original.source,
  24054. original: {
  24055. line: original.line,
  24056. column: original.column
  24057. },
  24058. generated: {
  24059. line: generated.line,
  24060. column: generated.column
  24061. },
  24062. name: original.name
  24063. });
  24064. }
  24065. } else {
  24066. generated.column++;
  24067. }
  24068. }
  24069. });
  24070. this.walkSourceContents(function (sourceFile, sourceContent) {
  24071. map.setSourceContent(sourceFile, sourceContent);
  24072. });
  24073. return { code: generated.code, map: map };
  24074. };
  24075. sourceNode$1.SourceNode = SourceNode;
  24076. return sourceNode$1;
  24077. }
  24078. /*
  24079. * Copyright 2009-2011 Mozilla Foundation and contributors
  24080. * Licensed under the New BSD license. See LICENSE.txt or:
  24081. * http://opensource.org/licenses/BSD-3-Clause
  24082. */
  24083. var hasRequiredSourceMap$1;
  24084. function requireSourceMap$1 () {
  24085. if (hasRequiredSourceMap$1) return sourceMap$1;
  24086. hasRequiredSourceMap$1 = 1;
  24087. sourceMap$1.SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator$1().SourceMapGenerator;
  24088. sourceMap$1.SourceMapConsumer = /*@__PURE__*/ requireSourceMapConsumer$1().SourceMapConsumer;
  24089. sourceMap$1.SourceNode = /*@__PURE__*/ requireSourceNode$1().SourceNode;
  24090. return sourceMap$1;
  24091. }
  24092. var sourceMapExports = /*@__PURE__*/ requireSourceMap$1();
  24093. const PURE_ANNOTATION = `/*@__PURE__*/`;
  24094. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  24095. function createCodegenContext(ast, {
  24096. mode = "function",
  24097. prefixIdentifiers = mode === "module",
  24098. sourceMap = false,
  24099. filename = `template.vue.html`,
  24100. scopeId = null,
  24101. optimizeImports = false,
  24102. runtimeGlobalName = `Vue`,
  24103. runtimeModuleName = `vue`,
  24104. ssrRuntimeModuleName = "vue/server-renderer",
  24105. ssr = false,
  24106. isTS = false,
  24107. inSSR = false
  24108. }) {
  24109. const context = {
  24110. mode,
  24111. prefixIdentifiers,
  24112. sourceMap,
  24113. filename,
  24114. scopeId,
  24115. optimizeImports,
  24116. runtimeGlobalName,
  24117. runtimeModuleName,
  24118. ssrRuntimeModuleName,
  24119. ssr,
  24120. isTS,
  24121. inSSR,
  24122. source: ast.source,
  24123. code: ``,
  24124. column: 1,
  24125. line: 1,
  24126. offset: 0,
  24127. indentLevel: 0,
  24128. pure: false,
  24129. map: void 0,
  24130. helper(key) {
  24131. return `_${helperNameMap[key]}`;
  24132. },
  24133. push(code, newlineIndex = -2 /* None */, node) {
  24134. context.code += code;
  24135. if (context.map) {
  24136. if (node) {
  24137. let name;
  24138. if (node.type === 4 && !node.isStatic) {
  24139. const content = node.content.replace(/^_ctx\./, "");
  24140. if (content !== node.content && isSimpleIdentifier(content)) {
  24141. name = content;
  24142. }
  24143. }
  24144. if (node.loc.source) {
  24145. addMapping(node.loc.start, name);
  24146. }
  24147. }
  24148. if (newlineIndex === -3 /* Unknown */) {
  24149. advancePositionWithMutation(context, code);
  24150. } else {
  24151. context.offset += code.length;
  24152. if (newlineIndex === -2 /* None */) {
  24153. context.column += code.length;
  24154. } else {
  24155. if (newlineIndex === -1 /* End */) {
  24156. newlineIndex = code.length - 1;
  24157. }
  24158. context.line++;
  24159. context.column = code.length - newlineIndex;
  24160. }
  24161. }
  24162. if (node && node.loc !== locStub && node.loc.source) {
  24163. addMapping(node.loc.end);
  24164. }
  24165. }
  24166. },
  24167. indent() {
  24168. newline(++context.indentLevel);
  24169. },
  24170. deindent(withoutNewLine = false) {
  24171. if (withoutNewLine) {
  24172. --context.indentLevel;
  24173. } else {
  24174. newline(--context.indentLevel);
  24175. }
  24176. },
  24177. newline() {
  24178. newline(context.indentLevel);
  24179. }
  24180. };
  24181. function newline(n) {
  24182. context.push("\n" + ` `.repeat(n), 0 /* Start */);
  24183. }
  24184. function addMapping(loc, name = null) {
  24185. const { _names, _mappings } = context.map;
  24186. if (name !== null && !_names.has(name)) _names.add(name);
  24187. _mappings.add({
  24188. originalLine: loc.line,
  24189. originalColumn: loc.column - 1,
  24190. // source-map column is 0 based
  24191. generatedLine: context.line,
  24192. generatedColumn: context.column - 1,
  24193. source: filename,
  24194. name
  24195. });
  24196. }
  24197. if (sourceMap) {
  24198. context.map = new sourceMapExports.SourceMapGenerator();
  24199. context.map.setSourceContent(filename, context.source);
  24200. context.map._sources.add(filename);
  24201. }
  24202. return context;
  24203. }
  24204. function generate(ast, options = {}) {
  24205. const context = createCodegenContext(ast, options);
  24206. if (options.onContextCreated) options.onContextCreated(context);
  24207. const {
  24208. mode,
  24209. push,
  24210. prefixIdentifiers,
  24211. indent,
  24212. deindent,
  24213. newline,
  24214. scopeId,
  24215. ssr
  24216. } = context;
  24217. const helpers = Array.from(ast.helpers);
  24218. const hasHelpers = helpers.length > 0;
  24219. const useWithBlock = !prefixIdentifiers && mode !== "module";
  24220. const genScopeId = scopeId != null && mode === "module";
  24221. const isSetupInlined = !!options.inline;
  24222. const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
  24223. if (mode === "module") {
  24224. genModulePreamble(ast, preambleContext, genScopeId, isSetupInlined);
  24225. } else {
  24226. genFunctionPreamble(ast, preambleContext);
  24227. }
  24228. const functionName = ssr ? `ssrRender` : `render`;
  24229. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  24230. if (options.bindingMetadata && !options.inline) {
  24231. args.push("$props", "$setup", "$data", "$options");
  24232. }
  24233. const signature = options.isTS ? args.map((arg) => `${arg}: any`).join(",") : args.join(", ");
  24234. if (isSetupInlined) {
  24235. push(`(${signature}) => {`);
  24236. } else {
  24237. push(`function ${functionName}(${signature}) {`);
  24238. }
  24239. indent();
  24240. if (useWithBlock) {
  24241. push(`with (_ctx) {`);
  24242. indent();
  24243. if (hasHelpers) {
  24244. push(
  24245. `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
  24246. `,
  24247. -1 /* End */
  24248. );
  24249. newline();
  24250. }
  24251. }
  24252. if (ast.components.length) {
  24253. genAssets(ast.components, "component", context);
  24254. if (ast.directives.length || ast.temps > 0) {
  24255. newline();
  24256. }
  24257. }
  24258. if (ast.directives.length) {
  24259. genAssets(ast.directives, "directive", context);
  24260. if (ast.temps > 0) {
  24261. newline();
  24262. }
  24263. }
  24264. if (ast.temps > 0) {
  24265. push(`let `);
  24266. for (let i = 0; i < ast.temps; i++) {
  24267. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  24268. }
  24269. }
  24270. if (ast.components.length || ast.directives.length || ast.temps) {
  24271. push(`
  24272. `, 0 /* Start */);
  24273. newline();
  24274. }
  24275. if (!ssr) {
  24276. push(`return `);
  24277. }
  24278. if (ast.codegenNode) {
  24279. genNode(ast.codegenNode, context);
  24280. } else {
  24281. push(`null`);
  24282. }
  24283. if (useWithBlock) {
  24284. deindent();
  24285. push(`}`);
  24286. }
  24287. deindent();
  24288. push(`}`);
  24289. return {
  24290. ast,
  24291. code: context.code,
  24292. preamble: isSetupInlined ? preambleContext.code : ``,
  24293. map: context.map ? context.map.toJSON() : void 0
  24294. };
  24295. }
  24296. function genFunctionPreamble(ast, context) {
  24297. const {
  24298. ssr,
  24299. prefixIdentifiers,
  24300. push,
  24301. newline,
  24302. runtimeModuleName,
  24303. runtimeGlobalName,
  24304. ssrRuntimeModuleName
  24305. } = context;
  24306. const VueBinding = ssr ? `require(${JSON.stringify(runtimeModuleName)})` : runtimeGlobalName;
  24307. const helpers = Array.from(ast.helpers);
  24308. if (helpers.length > 0) {
  24309. if (prefixIdentifiers) {
  24310. push(
  24311. `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
  24312. `,
  24313. -1 /* End */
  24314. );
  24315. } else {
  24316. push(`const _Vue = ${VueBinding}
  24317. `, -1 /* End */);
  24318. if (ast.hoists.length) {
  24319. const staticHelpers = [
  24320. CREATE_VNODE,
  24321. CREATE_ELEMENT_VNODE,
  24322. CREATE_COMMENT,
  24323. CREATE_TEXT,
  24324. CREATE_STATIC
  24325. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  24326. push(`const { ${staticHelpers} } = _Vue
  24327. `, -1 /* End */);
  24328. }
  24329. }
  24330. }
  24331. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  24332. push(
  24333. `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
  24334. `,
  24335. -1 /* End */
  24336. );
  24337. }
  24338. genHoists(ast.hoists, context);
  24339. newline();
  24340. push(`return `);
  24341. }
  24342. function genModulePreamble(ast, context, genScopeId, inline) {
  24343. const {
  24344. push,
  24345. newline,
  24346. optimizeImports,
  24347. runtimeModuleName,
  24348. ssrRuntimeModuleName
  24349. } = context;
  24350. if (ast.helpers.size) {
  24351. const helpers = Array.from(ast.helpers);
  24352. if (optimizeImports) {
  24353. push(
  24354. `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  24355. `,
  24356. -1 /* End */
  24357. );
  24358. push(
  24359. `
  24360. // Binding optimization for webpack code-split
  24361. const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
  24362. `,
  24363. -1 /* End */
  24364. );
  24365. } else {
  24366. push(
  24367. `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  24368. `,
  24369. -1 /* End */
  24370. );
  24371. }
  24372. }
  24373. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  24374. push(
  24375. `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
  24376. `,
  24377. -1 /* End */
  24378. );
  24379. }
  24380. if (ast.imports.length) {
  24381. genImports(ast.imports, context);
  24382. newline();
  24383. }
  24384. genHoists(ast.hoists, context);
  24385. newline();
  24386. if (!inline) {
  24387. push(`export `);
  24388. }
  24389. }
  24390. function genAssets(assets, type, { helper, push, newline, isTS }) {
  24391. const resolver = helper(
  24392. type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  24393. );
  24394. for (let i = 0; i < assets.length; i++) {
  24395. let id = assets[i];
  24396. const maybeSelfReference = id.endsWith("__self");
  24397. if (maybeSelfReference) {
  24398. id = id.slice(0, -6);
  24399. }
  24400. push(
  24401. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  24402. );
  24403. if (i < assets.length - 1) {
  24404. newline();
  24405. }
  24406. }
  24407. }
  24408. function genHoists(hoists, context) {
  24409. if (!hoists.length) {
  24410. return;
  24411. }
  24412. context.pure = true;
  24413. const { push, newline } = context;
  24414. newline();
  24415. for (let i = 0; i < hoists.length; i++) {
  24416. const exp = hoists[i];
  24417. if (exp) {
  24418. push(`const _hoisted_${i + 1} = `);
  24419. genNode(exp, context);
  24420. newline();
  24421. }
  24422. }
  24423. context.pure = false;
  24424. }
  24425. function genImports(importsOptions, context) {
  24426. if (!importsOptions.length) {
  24427. return;
  24428. }
  24429. importsOptions.forEach((imports) => {
  24430. context.push(`import `);
  24431. genNode(imports.exp, context);
  24432. context.push(` from '${imports.path}'`);
  24433. context.newline();
  24434. });
  24435. }
  24436. function isText(n) {
  24437. return isString$1(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  24438. }
  24439. function genNodeListAsArray(nodes, context) {
  24440. const multilines = nodes.length > 3 || nodes.some((n) => isArray$3(n) || !isText(n));
  24441. context.push(`[`);
  24442. multilines && context.indent();
  24443. genNodeList(nodes, context, multilines);
  24444. multilines && context.deindent();
  24445. context.push(`]`);
  24446. }
  24447. function genNodeList(nodes, context, multilines = false, comma = true) {
  24448. const { push, newline } = context;
  24449. for (let i = 0; i < nodes.length; i++) {
  24450. const node = nodes[i];
  24451. if (isString$1(node)) {
  24452. push(node, -3 /* Unknown */);
  24453. } else if (isArray$3(node)) {
  24454. genNodeListAsArray(node, context);
  24455. } else {
  24456. genNode(node, context);
  24457. }
  24458. if (i < nodes.length - 1) {
  24459. if (multilines) {
  24460. comma && push(",");
  24461. newline();
  24462. } else {
  24463. comma && push(", ");
  24464. }
  24465. }
  24466. }
  24467. }
  24468. function genNode(node, context) {
  24469. if (isString$1(node)) {
  24470. context.push(node, -3 /* Unknown */);
  24471. return;
  24472. }
  24473. if (isSymbol$1(node)) {
  24474. context.push(context.helper(node));
  24475. return;
  24476. }
  24477. switch (node.type) {
  24478. case 1:
  24479. case 9:
  24480. case 11:
  24481. assert(
  24482. node.codegenNode != null,
  24483. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  24484. );
  24485. genNode(node.codegenNode, context);
  24486. break;
  24487. case 2:
  24488. genText(node, context);
  24489. break;
  24490. case 4:
  24491. genExpression(node, context);
  24492. break;
  24493. case 5:
  24494. genInterpolation(node, context);
  24495. break;
  24496. case 12:
  24497. genNode(node.codegenNode, context);
  24498. break;
  24499. case 8:
  24500. genCompoundExpression(node, context);
  24501. break;
  24502. case 3:
  24503. genComment(node, context);
  24504. break;
  24505. case 13:
  24506. genVNodeCall(node, context);
  24507. break;
  24508. case 14:
  24509. genCallExpression(node, context);
  24510. break;
  24511. case 15:
  24512. genObjectExpression(node, context);
  24513. break;
  24514. case 17:
  24515. genArrayExpression(node, context);
  24516. break;
  24517. case 18:
  24518. genFunctionExpression(node, context);
  24519. break;
  24520. case 19:
  24521. genConditionalExpression(node, context);
  24522. break;
  24523. case 20:
  24524. genCacheExpression(node, context);
  24525. break;
  24526. case 21:
  24527. genNodeList(node.body, context, true, false);
  24528. break;
  24529. // SSR only types
  24530. case 22:
  24531. genTemplateLiteral(node, context);
  24532. break;
  24533. case 23:
  24534. genIfStatement(node, context);
  24535. break;
  24536. case 24:
  24537. genAssignmentExpression(node, context);
  24538. break;
  24539. case 25:
  24540. genSequenceExpression(node, context);
  24541. break;
  24542. case 26:
  24543. genReturnStatement(node, context);
  24544. break;
  24545. /* v8 ignore start */
  24546. case 10:
  24547. break;
  24548. default:
  24549. {
  24550. assert(false, `unhandled codegen node type: ${node.type}`);
  24551. const exhaustiveCheck = node;
  24552. return exhaustiveCheck;
  24553. }
  24554. }
  24555. }
  24556. function genText(node, context) {
  24557. context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
  24558. }
  24559. function genExpression(node, context) {
  24560. const { content, isStatic } = node;
  24561. context.push(
  24562. isStatic ? JSON.stringify(content) : content,
  24563. -3 /* Unknown */,
  24564. node
  24565. );
  24566. }
  24567. function genInterpolation(node, context) {
  24568. const { push, helper, pure } = context;
  24569. if (pure) push(PURE_ANNOTATION);
  24570. push(`${helper(TO_DISPLAY_STRING)}(`);
  24571. genNode(node.content, context);
  24572. push(`)`);
  24573. }
  24574. function genCompoundExpression(node, context) {
  24575. for (let i = 0; i < node.children.length; i++) {
  24576. const child = node.children[i];
  24577. if (isString$1(child)) {
  24578. context.push(child, -3 /* Unknown */);
  24579. } else {
  24580. genNode(child, context);
  24581. }
  24582. }
  24583. }
  24584. function genExpressionAsPropertyKey(node, context) {
  24585. const { push } = context;
  24586. if (node.type === 8) {
  24587. push(`[`);
  24588. genCompoundExpression(node, context);
  24589. push(`]`);
  24590. } else if (node.isStatic) {
  24591. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  24592. push(text, -2 /* None */, node);
  24593. } else {
  24594. push(`[${node.content}]`, -3 /* Unknown */, node);
  24595. }
  24596. }
  24597. function genComment(node, context) {
  24598. const { push, helper, pure } = context;
  24599. if (pure) {
  24600. push(PURE_ANNOTATION);
  24601. }
  24602. push(
  24603. `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
  24604. -3 /* Unknown */,
  24605. node
  24606. );
  24607. }
  24608. function genVNodeCall(node, context) {
  24609. const { push, helper, pure } = context;
  24610. const {
  24611. tag,
  24612. props,
  24613. children,
  24614. patchFlag,
  24615. dynamicProps,
  24616. directives,
  24617. isBlock,
  24618. disableTracking,
  24619. isComponent
  24620. } = node;
  24621. let patchFlagString;
  24622. if (patchFlag) {
  24623. {
  24624. if (patchFlag < 0) {
  24625. patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  24626. } else {
  24627. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  24628. patchFlagString = patchFlag + ` /* ${flagNames} */`;
  24629. }
  24630. }
  24631. }
  24632. if (directives) {
  24633. push(helper(WITH_DIRECTIVES) + `(`);
  24634. }
  24635. if (isBlock) {
  24636. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  24637. }
  24638. if (pure) {
  24639. push(PURE_ANNOTATION);
  24640. }
  24641. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  24642. push(helper(callHelper) + `(`, -2 /* None */, node);
  24643. genNodeList(
  24644. genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
  24645. context
  24646. );
  24647. push(`)`);
  24648. if (isBlock) {
  24649. push(`)`);
  24650. }
  24651. if (directives) {
  24652. push(`, `);
  24653. genNode(directives, context);
  24654. push(`)`);
  24655. }
  24656. }
  24657. function genNullableArgs(args) {
  24658. let i = args.length;
  24659. while (i--) {
  24660. if (args[i] != null) break;
  24661. }
  24662. return args.slice(0, i + 1).map((arg) => arg || `null`);
  24663. }
  24664. function genCallExpression(node, context) {
  24665. const { push, helper, pure } = context;
  24666. const callee = isString$1(node.callee) ? node.callee : helper(node.callee);
  24667. if (pure) {
  24668. push(PURE_ANNOTATION);
  24669. }
  24670. push(callee + `(`, -2 /* None */, node);
  24671. genNodeList(node.arguments, context);
  24672. push(`)`);
  24673. }
  24674. function genObjectExpression(node, context) {
  24675. const { push, indent, deindent, newline } = context;
  24676. const { properties } = node;
  24677. if (!properties.length) {
  24678. push(`{}`, -2 /* None */, node);
  24679. return;
  24680. }
  24681. const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
  24682. push(multilines ? `{` : `{ `);
  24683. multilines && indent();
  24684. for (let i = 0; i < properties.length; i++) {
  24685. const { key, value } = properties[i];
  24686. genExpressionAsPropertyKey(key, context);
  24687. push(`: `);
  24688. genNode(value, context);
  24689. if (i < properties.length - 1) {
  24690. push(`,`);
  24691. newline();
  24692. }
  24693. }
  24694. multilines && deindent();
  24695. push(multilines ? `}` : ` }`);
  24696. }
  24697. function genArrayExpression(node, context) {
  24698. genNodeListAsArray(node.elements, context);
  24699. }
  24700. function genFunctionExpression(node, context) {
  24701. const { push, indent, deindent } = context;
  24702. const { params, returns, body, newline, isSlot } = node;
  24703. if (isSlot) {
  24704. push(`_${helperNameMap[WITH_CTX]}(`);
  24705. }
  24706. push(`(`, -2 /* None */, node);
  24707. if (isArray$3(params)) {
  24708. genNodeList(params, context);
  24709. } else if (params) {
  24710. genNode(params, context);
  24711. }
  24712. push(`) => `);
  24713. if (newline || body) {
  24714. push(`{`);
  24715. indent();
  24716. }
  24717. if (returns) {
  24718. if (newline) {
  24719. push(`return `);
  24720. }
  24721. if (isArray$3(returns)) {
  24722. genNodeListAsArray(returns, context);
  24723. } else {
  24724. genNode(returns, context);
  24725. }
  24726. } else if (body) {
  24727. genNode(body, context);
  24728. }
  24729. if (newline || body) {
  24730. deindent();
  24731. push(`}`);
  24732. }
  24733. if (isSlot) {
  24734. push(`)`);
  24735. }
  24736. }
  24737. function genConditionalExpression(node, context) {
  24738. const { test, consequent, alternate, newline: needNewline } = node;
  24739. const { push, indent, deindent, newline } = context;
  24740. if (test.type === 4) {
  24741. const needsParens = !isSimpleIdentifier(test.content);
  24742. needsParens && push(`(`);
  24743. genExpression(test, context);
  24744. needsParens && push(`)`);
  24745. } else {
  24746. push(`(`);
  24747. genNode(test, context);
  24748. push(`)`);
  24749. }
  24750. needNewline && indent();
  24751. context.indentLevel++;
  24752. needNewline || push(` `);
  24753. push(`? `);
  24754. genNode(consequent, context);
  24755. context.indentLevel--;
  24756. needNewline && newline();
  24757. needNewline || push(` `);
  24758. push(`: `);
  24759. const isNested = alternate.type === 19;
  24760. if (!isNested) {
  24761. context.indentLevel++;
  24762. }
  24763. genNode(alternate, context);
  24764. if (!isNested) {
  24765. context.indentLevel--;
  24766. }
  24767. needNewline && deindent(
  24768. true
  24769. /* without newline */
  24770. );
  24771. }
  24772. function genCacheExpression(node, context) {
  24773. const { push, helper, indent, deindent, newline } = context;
  24774. const { needPauseTracking, needArraySpread } = node;
  24775. if (needArraySpread) {
  24776. push(`[...(`);
  24777. }
  24778. push(`_cache[${node.index}] || (`);
  24779. if (needPauseTracking) {
  24780. indent();
  24781. push(`${helper(SET_BLOCK_TRACKING)}(-1`);
  24782. if (node.inVOnce) push(`, true`);
  24783. push(`),`);
  24784. newline();
  24785. push(`(`);
  24786. }
  24787. push(`_cache[${node.index}] = `);
  24788. genNode(node.value, context);
  24789. if (needPauseTracking) {
  24790. push(`).cacheIndex = ${node.index},`);
  24791. newline();
  24792. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  24793. newline();
  24794. push(`_cache[${node.index}]`);
  24795. deindent();
  24796. }
  24797. push(`)`);
  24798. if (needArraySpread) {
  24799. push(`)]`);
  24800. }
  24801. }
  24802. function genTemplateLiteral(node, context) {
  24803. const { push, indent, deindent } = context;
  24804. push("`");
  24805. const l = node.elements.length;
  24806. const multilines = l > 3;
  24807. for (let i = 0; i < l; i++) {
  24808. const e = node.elements[i];
  24809. if (isString$1(e)) {
  24810. push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
  24811. } else {
  24812. push("${");
  24813. if (multilines) indent();
  24814. genNode(e, context);
  24815. if (multilines) deindent();
  24816. push("}");
  24817. }
  24818. }
  24819. push("`");
  24820. }
  24821. function genIfStatement(node, context) {
  24822. const { push, indent, deindent } = context;
  24823. const { test, consequent, alternate } = node;
  24824. push(`if (`);
  24825. genNode(test, context);
  24826. push(`) {`);
  24827. indent();
  24828. genNode(consequent, context);
  24829. deindent();
  24830. push(`}`);
  24831. if (alternate) {
  24832. push(` else `);
  24833. if (alternate.type === 23) {
  24834. genIfStatement(alternate, context);
  24835. } else {
  24836. push(`{`);
  24837. indent();
  24838. genNode(alternate, context);
  24839. deindent();
  24840. push(`}`);
  24841. }
  24842. }
  24843. }
  24844. function genAssignmentExpression(node, context) {
  24845. genNode(node.left, context);
  24846. context.push(` = `);
  24847. genNode(node.right, context);
  24848. }
  24849. function genSequenceExpression(node, context) {
  24850. context.push(`(`);
  24851. genNodeList(node.expressions, context);
  24852. context.push(`)`);
  24853. }
  24854. function genReturnStatement({ returns }, context) {
  24855. context.push(`return `);
  24856. if (isArray$3(returns)) {
  24857. genNodeListAsArray(returns, context);
  24858. } else {
  24859. genNode(returns, context);
  24860. }
  24861. }
  24862. const isLiteralWhitelisted = /* @__PURE__ */ makeMap("true,false,null,this");
  24863. const transformExpression = (node, context) => {
  24864. if (node.type === 5) {
  24865. node.content = processExpression(
  24866. node.content,
  24867. context
  24868. );
  24869. } else if (node.type === 1) {
  24870. const memo = findDir(node, "memo");
  24871. for (let i = 0; i < node.props.length; i++) {
  24872. const dir = node.props[i];
  24873. if (dir.type === 7 && dir.name !== "for") {
  24874. const exp = dir.exp;
  24875. const arg = dir.arg;
  24876. if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
  24877. !(memo && arg && arg.type === 4 && arg.content === "key")) {
  24878. dir.exp = processExpression(
  24879. exp,
  24880. context,
  24881. // slot args must be processed as function params
  24882. dir.name === "slot"
  24883. );
  24884. }
  24885. if (arg && arg.type === 4 && !arg.isStatic) {
  24886. dir.arg = processExpression(arg, context);
  24887. }
  24888. }
  24889. }
  24890. }
  24891. };
  24892. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  24893. if (!context.prefixIdentifiers || !node.content.trim()) {
  24894. return node;
  24895. }
  24896. const { inline, bindingMetadata } = context;
  24897. const rewriteIdentifier = (raw, parent, id) => {
  24898. const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw];
  24899. if (inline) {
  24900. const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
  24901. const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
  24902. const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
  24903. const isNewExpression = parent && isInNewExpression(parentStack);
  24904. const wrapWithUnref = (raw2) => {
  24905. const wrapped = `${context.helperString(UNREF)}(${raw2})`;
  24906. return isNewExpression ? `(${wrapped})` : wrapped;
  24907. };
  24908. if (isConst(type) || type === "setup-reactive-const" || localVars[raw]) {
  24909. return raw;
  24910. } else if (type === "setup-ref") {
  24911. return `${raw}.value`;
  24912. } else if (type === "setup-maybe-ref") {
  24913. return isAssignmentLVal || isUpdateArg || isDestructureAssignment ? `${raw}.value` : wrapWithUnref(raw);
  24914. } else if (type === "setup-let") {
  24915. if (isAssignmentLVal) {
  24916. const { right: rVal, operator } = parent;
  24917. const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
  24918. const rExpString = stringifyExpression(
  24919. processExpression(
  24920. createSimpleExpression(rExp, false),
  24921. context,
  24922. false,
  24923. false,
  24924. knownIds
  24925. )
  24926. );
  24927. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  24928. ` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
  24929. } else if (isUpdateArg) {
  24930. id.start = parent.start;
  24931. id.end = parent.end;
  24932. const { prefix: isPrefix, operator } = parent;
  24933. const prefix = isPrefix ? operator : ``;
  24934. const postfix = isPrefix ? `` : operator;
  24935. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  24936. ` : ``} ? ${prefix}${raw}.value${postfix} : ${prefix}${raw}${postfix}`;
  24937. } else if (isDestructureAssignment) {
  24938. return raw;
  24939. } else {
  24940. return wrapWithUnref(raw);
  24941. }
  24942. } else if (type === "props") {
  24943. return genPropsAccessExp(raw);
  24944. } else if (type === "props-aliased") {
  24945. return genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
  24946. }
  24947. } else {
  24948. if (type && type.startsWith("setup") || type === "literal-const") {
  24949. return `$setup.${raw}`;
  24950. } else if (type === "props-aliased") {
  24951. return `$props['${bindingMetadata.__propsAliases[raw]}']`;
  24952. } else if (type) {
  24953. return `$${type}.${raw}`;
  24954. }
  24955. }
  24956. return `_ctx.${raw}`;
  24957. };
  24958. const rawExp = node.content;
  24959. let ast = node.ast;
  24960. if (ast === false) {
  24961. return node;
  24962. }
  24963. if (ast === null || !ast && isSimpleIdentifier(rawExp)) {
  24964. const isScopeVarReference = context.identifiers[rawExp];
  24965. const isAllowedGlobal = isGloballyAllowed(rawExp);
  24966. const isLiteral = isLiteralWhitelisted(rawExp);
  24967. if (!asParams && !isScopeVarReference && !isLiteral && (!isAllowedGlobal || bindingMetadata[rawExp])) {
  24968. if (isConst(bindingMetadata[rawExp])) {
  24969. node.constType = 1;
  24970. }
  24971. node.content = rewriteIdentifier(rawExp);
  24972. } else if (!isScopeVarReference) {
  24973. if (isLiteral) {
  24974. node.constType = 3;
  24975. } else {
  24976. node.constType = 2;
  24977. }
  24978. }
  24979. return node;
  24980. }
  24981. if (!ast) {
  24982. const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
  24983. try {
  24984. ast = libExports.parseExpression(source, {
  24985. sourceType: "module",
  24986. plugins: context.expressionPlugins
  24987. });
  24988. } catch (e) {
  24989. context.onError(
  24990. createCompilerError(
  24991. 46,
  24992. node.loc,
  24993. void 0,
  24994. e.message
  24995. )
  24996. );
  24997. return node;
  24998. }
  24999. }
  25000. const ids = [];
  25001. const parentStack = [];
  25002. const knownIds = Object.create(context.identifiers);
  25003. walkIdentifiers(
  25004. ast,
  25005. (node2, parent, _, isReferenced, isLocal) => {
  25006. if (isStaticPropertyKey(node2, parent)) {
  25007. return;
  25008. }
  25009. const needPrefix = isReferenced && canPrefix(node2);
  25010. if (needPrefix && !isLocal) {
  25011. if (isStaticProperty(parent) && parent.shorthand) {
  25012. node2.prefix = `${node2.name}: `;
  25013. }
  25014. node2.name = rewriteIdentifier(node2.name, parent, node2);
  25015. ids.push(node2);
  25016. } else {
  25017. if (!(needPrefix && isLocal) && (!parent || parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression")) {
  25018. node2.isConstant = true;
  25019. }
  25020. ids.push(node2);
  25021. }
  25022. },
  25023. true,
  25024. // invoke on ALL identifiers
  25025. parentStack,
  25026. knownIds
  25027. );
  25028. const children = [];
  25029. ids.sort((a, b) => a.start - b.start);
  25030. ids.forEach((id, i) => {
  25031. const start = id.start - 1;
  25032. const end = id.end - 1;
  25033. const last = ids[i - 1];
  25034. const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
  25035. if (leadingText.length || id.prefix) {
  25036. children.push(leadingText + (id.prefix || ``));
  25037. }
  25038. const source = rawExp.slice(start, end);
  25039. children.push(
  25040. createSimpleExpression(
  25041. id.name,
  25042. false,
  25043. {
  25044. start: advancePositionWithClone(node.loc.start, source, start),
  25045. end: advancePositionWithClone(node.loc.start, source, end),
  25046. source
  25047. },
  25048. id.isConstant ? 3 : 0
  25049. )
  25050. );
  25051. if (i === ids.length - 1 && end < rawExp.length) {
  25052. children.push(rawExp.slice(end));
  25053. }
  25054. });
  25055. let ret;
  25056. if (children.length) {
  25057. ret = createCompoundExpression(children, node.loc);
  25058. ret.ast = ast;
  25059. } else {
  25060. ret = node;
  25061. ret.constType = 3;
  25062. }
  25063. ret.identifiers = Object.keys(knownIds);
  25064. return ret;
  25065. }
  25066. function canPrefix(id) {
  25067. if (isGloballyAllowed(id.name)) {
  25068. return false;
  25069. }
  25070. if (id.name === "require") {
  25071. return false;
  25072. }
  25073. return true;
  25074. }
  25075. function stringifyExpression(exp) {
  25076. if (isString$1(exp)) {
  25077. return exp;
  25078. } else if (exp.type === 4) {
  25079. return exp.content;
  25080. } else {
  25081. return exp.children.map(stringifyExpression).join("");
  25082. }
  25083. }
  25084. function isConst(type) {
  25085. return type === "setup-const" || type === "literal-const";
  25086. }
  25087. const transformIf = createStructuralDirectiveTransform(
  25088. /^(?:if|else|else-if)$/,
  25089. (node, dir, context) => {
  25090. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  25091. const siblings = context.parent.children;
  25092. let i = siblings.indexOf(ifNode);
  25093. let key = 0;
  25094. while (i-- >= 0) {
  25095. const sibling = siblings[i];
  25096. if (sibling && sibling.type === 9) {
  25097. key += sibling.branches.length;
  25098. }
  25099. }
  25100. return () => {
  25101. if (isRoot) {
  25102. ifNode.codegenNode = createCodegenNodeForBranch(
  25103. branch,
  25104. key,
  25105. context
  25106. );
  25107. } else {
  25108. const parentCondition = getParentCondition(ifNode.codegenNode);
  25109. parentCondition.alternate = createCodegenNodeForBranch(
  25110. branch,
  25111. key + ifNode.branches.length - 1,
  25112. context
  25113. );
  25114. }
  25115. };
  25116. });
  25117. }
  25118. );
  25119. function processIf(node, dir, context, processCodegen) {
  25120. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  25121. const loc = dir.exp ? dir.exp.loc : node.loc;
  25122. context.onError(
  25123. createCompilerError(28, dir.loc)
  25124. );
  25125. dir.exp = createSimpleExpression(`true`, false, loc);
  25126. }
  25127. if (context.prefixIdentifiers && dir.exp) {
  25128. dir.exp = processExpression(dir.exp, context);
  25129. }
  25130. if (dir.name === "if") {
  25131. const branch = createIfBranch(node, dir);
  25132. const ifNode = {
  25133. type: 9,
  25134. loc: cloneLoc(node.loc),
  25135. branches: [branch]
  25136. };
  25137. context.replaceNode(ifNode);
  25138. if (processCodegen) {
  25139. return processCodegen(ifNode, branch, true);
  25140. }
  25141. } else {
  25142. const siblings = context.parent.children;
  25143. const comments = [];
  25144. let i = siblings.indexOf(node);
  25145. while (i-- >= -1) {
  25146. const sibling = siblings[i];
  25147. if (sibling && isCommentOrWhitespace(sibling)) {
  25148. context.removeNode(sibling);
  25149. if (sibling.type === 3) {
  25150. comments.unshift(sibling);
  25151. }
  25152. continue;
  25153. }
  25154. if (sibling && sibling.type === 9) {
  25155. if ((dir.name === "else-if" || dir.name === "else") && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  25156. context.onError(
  25157. createCompilerError(30, node.loc)
  25158. );
  25159. }
  25160. context.removeNode();
  25161. const branch = createIfBranch(node, dir);
  25162. if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  25163. !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
  25164. branch.children = [...comments, ...branch.children];
  25165. }
  25166. {
  25167. const key = branch.userKey;
  25168. if (key) {
  25169. sibling.branches.forEach(({ userKey }) => {
  25170. if (isSameKey(userKey, key)) {
  25171. context.onError(
  25172. createCompilerError(
  25173. 29,
  25174. branch.userKey.loc
  25175. )
  25176. );
  25177. }
  25178. });
  25179. }
  25180. }
  25181. sibling.branches.push(branch);
  25182. const onExit = processCodegen && processCodegen(sibling, branch, false);
  25183. traverseNode(branch, context);
  25184. if (onExit) onExit();
  25185. context.currentNode = null;
  25186. } else {
  25187. context.onError(
  25188. createCompilerError(30, node.loc)
  25189. );
  25190. }
  25191. break;
  25192. }
  25193. }
  25194. }
  25195. function createIfBranch(node, dir) {
  25196. const isTemplateIf = node.tagType === 3;
  25197. return {
  25198. type: 10,
  25199. loc: node.loc,
  25200. condition: dir.name === "else" ? void 0 : dir.exp,
  25201. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  25202. userKey: findProp(node, `key`),
  25203. isTemplateIf
  25204. };
  25205. }
  25206. function createCodegenNodeForBranch(branch, keyIndex, context) {
  25207. if (branch.condition) {
  25208. return createConditionalExpression(
  25209. branch.condition,
  25210. createChildrenCodegenNode(branch, keyIndex, context),
  25211. // make sure to pass in asBlock: true so that the comment node call
  25212. // closes the current block.
  25213. createCallExpression(context.helper(CREATE_COMMENT), [
  25214. '"v-if"' ,
  25215. "true"
  25216. ])
  25217. );
  25218. } else {
  25219. return createChildrenCodegenNode(branch, keyIndex, context);
  25220. }
  25221. }
  25222. function createChildrenCodegenNode(branch, keyIndex, context) {
  25223. const { helper } = context;
  25224. const keyProperty = createObjectProperty(
  25225. `key`,
  25226. createSimpleExpression(
  25227. `${keyIndex}`,
  25228. false,
  25229. locStub,
  25230. 2
  25231. )
  25232. );
  25233. const { children } = branch;
  25234. const firstChild = children[0];
  25235. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  25236. if (needFragmentWrapper) {
  25237. if (children.length === 1 && firstChild.type === 11) {
  25238. const vnodeCall = firstChild.codegenNode;
  25239. injectProp(vnodeCall, keyProperty, context);
  25240. return vnodeCall;
  25241. } else {
  25242. let patchFlag = 64;
  25243. if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  25244. patchFlag |= 2048;
  25245. }
  25246. return createVNodeCall(
  25247. context,
  25248. helper(FRAGMENT),
  25249. createObjectExpression([keyProperty]),
  25250. children,
  25251. patchFlag,
  25252. void 0,
  25253. void 0,
  25254. true,
  25255. false,
  25256. false,
  25257. branch.loc
  25258. );
  25259. }
  25260. } else {
  25261. const ret = firstChild.codegenNode;
  25262. const vnodeCall = getMemoedVNodeCall(ret);
  25263. if (vnodeCall.type === 13) {
  25264. convertToBlock(vnodeCall, context);
  25265. }
  25266. injectProp(vnodeCall, keyProperty, context);
  25267. return ret;
  25268. }
  25269. }
  25270. function isSameKey(a, b) {
  25271. if (!a || a.type !== b.type) {
  25272. return false;
  25273. }
  25274. if (a.type === 6) {
  25275. if (a.value.content !== b.value.content) {
  25276. return false;
  25277. }
  25278. } else {
  25279. const exp = a.exp;
  25280. const branchExp = b.exp;
  25281. if (exp.type !== branchExp.type) {
  25282. return false;
  25283. }
  25284. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  25285. return false;
  25286. }
  25287. }
  25288. return true;
  25289. }
  25290. function getParentCondition(node) {
  25291. while (true) {
  25292. if (node.type === 19) {
  25293. if (node.alternate.type === 19) {
  25294. node = node.alternate;
  25295. } else {
  25296. return node;
  25297. }
  25298. } else if (node.type === 20) {
  25299. node = node.value;
  25300. }
  25301. }
  25302. }
  25303. const transformFor = createStructuralDirectiveTransform(
  25304. "for",
  25305. (node, dir, context) => {
  25306. const { helper, removeHelper } = context;
  25307. return processFor(node, dir, context, (forNode) => {
  25308. const renderExp = createCallExpression(helper(RENDER_LIST), [
  25309. forNode.source
  25310. ]);
  25311. const isTemplate = isTemplateNode(node);
  25312. const memo = findDir(node, "memo");
  25313. const keyProp = findProp(node, `key`, false, true);
  25314. const isDirKey = keyProp && keyProp.type === 7;
  25315. let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
  25316. if (memo && keyExp && isDirKey) {
  25317. {
  25318. keyProp.exp = keyExp = processExpression(
  25319. keyExp,
  25320. context
  25321. );
  25322. }
  25323. }
  25324. const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
  25325. if (isTemplate) {
  25326. if (memo) {
  25327. memo.exp = processExpression(
  25328. memo.exp,
  25329. context
  25330. );
  25331. }
  25332. if (keyProperty && keyProp.type !== 6) {
  25333. keyProperty.value = processExpression(
  25334. keyProperty.value,
  25335. context
  25336. );
  25337. }
  25338. }
  25339. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  25340. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  25341. forNode.codegenNode = createVNodeCall(
  25342. context,
  25343. helper(FRAGMENT),
  25344. void 0,
  25345. renderExp,
  25346. fragmentFlag,
  25347. void 0,
  25348. void 0,
  25349. true,
  25350. !isStableFragment,
  25351. false,
  25352. node.loc
  25353. );
  25354. return () => {
  25355. let childBlock;
  25356. const { children } = forNode;
  25357. if (isTemplate) {
  25358. node.children.some((c) => {
  25359. if (c.type === 1) {
  25360. const key = findProp(c, "key");
  25361. if (key) {
  25362. context.onError(
  25363. createCompilerError(
  25364. 33,
  25365. key.loc
  25366. )
  25367. );
  25368. return true;
  25369. }
  25370. }
  25371. });
  25372. }
  25373. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  25374. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  25375. if (slotOutlet) {
  25376. childBlock = slotOutlet.codegenNode;
  25377. if (isTemplate && keyProperty) {
  25378. injectProp(childBlock, keyProperty, context);
  25379. }
  25380. } else if (needFragmentWrapper) {
  25381. childBlock = createVNodeCall(
  25382. context,
  25383. helper(FRAGMENT),
  25384. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  25385. node.children,
  25386. 64,
  25387. void 0,
  25388. void 0,
  25389. true,
  25390. void 0,
  25391. false
  25392. );
  25393. } else {
  25394. childBlock = children[0].codegenNode;
  25395. if (isTemplate && keyProperty) {
  25396. injectProp(childBlock, keyProperty, context);
  25397. }
  25398. if (childBlock.isBlock !== !isStableFragment) {
  25399. if (childBlock.isBlock) {
  25400. removeHelper(OPEN_BLOCK);
  25401. removeHelper(
  25402. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  25403. );
  25404. } else {
  25405. removeHelper(
  25406. getVNodeHelper(context.inSSR, childBlock.isComponent)
  25407. );
  25408. }
  25409. }
  25410. childBlock.isBlock = !isStableFragment;
  25411. if (childBlock.isBlock) {
  25412. helper(OPEN_BLOCK);
  25413. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  25414. } else {
  25415. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  25416. }
  25417. }
  25418. if (memo) {
  25419. const loop = createFunctionExpression(
  25420. createForLoopParams(forNode.parseResult, [
  25421. createSimpleExpression(`_cached`)
  25422. ])
  25423. );
  25424. loop.body = createBlockStatement([
  25425. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  25426. createCompoundExpression([
  25427. `if (_cached`,
  25428. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  25429. ` && ${context.helperString(
  25430. IS_MEMO_SAME
  25431. )}(_cached, _memo)) return _cached`
  25432. ]),
  25433. createCompoundExpression([`const _item = `, childBlock]),
  25434. createSimpleExpression(`_item.memo = _memo`),
  25435. createSimpleExpression(`return _item`)
  25436. ]);
  25437. renderExp.arguments.push(
  25438. loop,
  25439. createSimpleExpression(`_cache`),
  25440. createSimpleExpression(String(context.cached.length))
  25441. );
  25442. context.cached.push(null);
  25443. } else {
  25444. renderExp.arguments.push(
  25445. createFunctionExpression(
  25446. createForLoopParams(forNode.parseResult),
  25447. childBlock,
  25448. true
  25449. )
  25450. );
  25451. }
  25452. };
  25453. });
  25454. }
  25455. );
  25456. function processFor(node, dir, context, processCodegen) {
  25457. if (!dir.exp) {
  25458. context.onError(
  25459. createCompilerError(31, dir.loc)
  25460. );
  25461. return;
  25462. }
  25463. const parseResult = dir.forParseResult;
  25464. if (!parseResult) {
  25465. context.onError(
  25466. createCompilerError(32, dir.loc)
  25467. );
  25468. return;
  25469. }
  25470. finalizeForParseResult(parseResult, context);
  25471. const { addIdentifiers, removeIdentifiers, scopes } = context;
  25472. const { source, value, key, index } = parseResult;
  25473. const forNode = {
  25474. type: 11,
  25475. loc: dir.loc,
  25476. source,
  25477. valueAlias: value,
  25478. keyAlias: key,
  25479. objectIndexAlias: index,
  25480. parseResult,
  25481. children: isTemplateNode(node) ? node.children : [node]
  25482. };
  25483. context.replaceNode(forNode);
  25484. scopes.vFor++;
  25485. if (context.prefixIdentifiers) {
  25486. value && addIdentifiers(value);
  25487. key && addIdentifiers(key);
  25488. index && addIdentifiers(index);
  25489. }
  25490. const onExit = processCodegen && processCodegen(forNode);
  25491. return () => {
  25492. scopes.vFor--;
  25493. if (context.prefixIdentifiers) {
  25494. value && removeIdentifiers(value);
  25495. key && removeIdentifiers(key);
  25496. index && removeIdentifiers(index);
  25497. }
  25498. if (onExit) onExit();
  25499. };
  25500. }
  25501. function finalizeForParseResult(result, context) {
  25502. if (result.finalized) return;
  25503. if (context.prefixIdentifiers) {
  25504. result.source = processExpression(
  25505. result.source,
  25506. context
  25507. );
  25508. if (result.key) {
  25509. result.key = processExpression(
  25510. result.key,
  25511. context,
  25512. true
  25513. );
  25514. }
  25515. if (result.index) {
  25516. result.index = processExpression(
  25517. result.index,
  25518. context,
  25519. true
  25520. );
  25521. }
  25522. if (result.value) {
  25523. result.value = processExpression(
  25524. result.value,
  25525. context,
  25526. true
  25527. );
  25528. }
  25529. }
  25530. result.finalized = true;
  25531. }
  25532. function createForLoopParams({ value, key, index }, memoArgs = []) {
  25533. return createParamsList([value, key, index, ...memoArgs]);
  25534. }
  25535. function createParamsList(args) {
  25536. let i = args.length;
  25537. while (i--) {
  25538. if (args[i]) break;
  25539. }
  25540. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  25541. }
  25542. const defaultFallback = createSimpleExpression(`undefined`, false);
  25543. const trackSlotScopes = (node, context) => {
  25544. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  25545. const vSlot = findDir(node, "slot");
  25546. if (vSlot) {
  25547. const slotProps = vSlot.exp;
  25548. if (context.prefixIdentifiers) {
  25549. slotProps && context.addIdentifiers(slotProps);
  25550. }
  25551. context.scopes.vSlot++;
  25552. return () => {
  25553. if (context.prefixIdentifiers) {
  25554. slotProps && context.removeIdentifiers(slotProps);
  25555. }
  25556. context.scopes.vSlot--;
  25557. };
  25558. }
  25559. }
  25560. };
  25561. const trackVForSlotScopes = (node, context) => {
  25562. let vFor;
  25563. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  25564. const result = vFor.forParseResult;
  25565. if (result) {
  25566. finalizeForParseResult(result, context);
  25567. const { value, key, index } = result;
  25568. const { addIdentifiers, removeIdentifiers } = context;
  25569. value && addIdentifiers(value);
  25570. key && addIdentifiers(key);
  25571. index && addIdentifiers(index);
  25572. return () => {
  25573. value && removeIdentifiers(value);
  25574. key && removeIdentifiers(key);
  25575. index && removeIdentifiers(index);
  25576. };
  25577. }
  25578. }
  25579. };
  25580. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  25581. props,
  25582. children,
  25583. false,
  25584. true,
  25585. children.length ? children[0].loc : loc
  25586. );
  25587. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  25588. context.helper(WITH_CTX);
  25589. const { children, loc } = node;
  25590. const slotsProperties = [];
  25591. const dynamicSlots = [];
  25592. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  25593. if (!context.ssr && context.prefixIdentifiers) {
  25594. hasDynamicSlots = node.props.some(
  25595. (prop) => isVSlot(prop) && (hasScopeRef(prop.arg, context.identifiers) || hasScopeRef(prop.exp, context.identifiers))
  25596. ) || children.some((child) => hasScopeRef(child, context.identifiers));
  25597. }
  25598. const onComponentSlot = findDir(node, "slot", true);
  25599. if (onComponentSlot) {
  25600. const { arg, exp } = onComponentSlot;
  25601. if (arg && !isStaticExp(arg)) {
  25602. hasDynamicSlots = true;
  25603. }
  25604. slotsProperties.push(
  25605. createObjectProperty(
  25606. arg || createSimpleExpression("default", true),
  25607. buildSlotFn(exp, void 0, children, loc)
  25608. )
  25609. );
  25610. }
  25611. let hasTemplateSlots = false;
  25612. let hasNamedDefaultSlot = false;
  25613. const implicitDefaultChildren = [];
  25614. const seenSlotNames = /* @__PURE__ */ new Set();
  25615. let conditionalBranchIndex = 0;
  25616. for (let i = 0; i < children.length; i++) {
  25617. const slotElement = children[i];
  25618. let slotDir;
  25619. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  25620. if (slotElement.type !== 3) {
  25621. implicitDefaultChildren.push(slotElement);
  25622. }
  25623. continue;
  25624. }
  25625. if (onComponentSlot) {
  25626. context.onError(
  25627. createCompilerError(37, slotDir.loc)
  25628. );
  25629. break;
  25630. }
  25631. hasTemplateSlots = true;
  25632. const { children: slotChildren, loc: slotLoc } = slotElement;
  25633. const {
  25634. arg: slotName = createSimpleExpression(`default`, true),
  25635. exp: slotProps,
  25636. loc: dirLoc
  25637. } = slotDir;
  25638. let staticSlotName;
  25639. if (isStaticExp(slotName)) {
  25640. staticSlotName = slotName ? slotName.content : `default`;
  25641. } else {
  25642. hasDynamicSlots = true;
  25643. }
  25644. const vFor = findDir(slotElement, "for");
  25645. const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
  25646. let vIf;
  25647. let vElse;
  25648. if (vIf = findDir(slotElement, "if")) {
  25649. hasDynamicSlots = true;
  25650. dynamicSlots.push(
  25651. createConditionalExpression(
  25652. vIf.exp,
  25653. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  25654. defaultFallback
  25655. )
  25656. );
  25657. } else if (vElse = findDir(
  25658. slotElement,
  25659. /^else(?:-if)?$/,
  25660. true
  25661. /* allowEmpty */
  25662. )) {
  25663. let j = i;
  25664. let prev;
  25665. while (j--) {
  25666. prev = children[j];
  25667. if (!isCommentOrWhitespace(prev)) {
  25668. break;
  25669. }
  25670. }
  25671. if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
  25672. let conditional = dynamicSlots[dynamicSlots.length - 1];
  25673. while (conditional.alternate.type === 19) {
  25674. conditional = conditional.alternate;
  25675. }
  25676. conditional.alternate = vElse.exp ? createConditionalExpression(
  25677. vElse.exp,
  25678. buildDynamicSlot(
  25679. slotName,
  25680. slotFunction,
  25681. conditionalBranchIndex++
  25682. ),
  25683. defaultFallback
  25684. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  25685. } else {
  25686. context.onError(
  25687. createCompilerError(30, vElse.loc)
  25688. );
  25689. }
  25690. } else if (vFor) {
  25691. hasDynamicSlots = true;
  25692. const parseResult = vFor.forParseResult;
  25693. if (parseResult) {
  25694. finalizeForParseResult(parseResult, context);
  25695. dynamicSlots.push(
  25696. createCallExpression(context.helper(RENDER_LIST), [
  25697. parseResult.source,
  25698. createFunctionExpression(
  25699. createForLoopParams(parseResult),
  25700. buildDynamicSlot(slotName, slotFunction),
  25701. true
  25702. )
  25703. ])
  25704. );
  25705. } else {
  25706. context.onError(
  25707. createCompilerError(
  25708. 32,
  25709. vFor.loc
  25710. )
  25711. );
  25712. }
  25713. } else {
  25714. if (staticSlotName) {
  25715. if (seenSlotNames.has(staticSlotName)) {
  25716. context.onError(
  25717. createCompilerError(
  25718. 38,
  25719. dirLoc
  25720. )
  25721. );
  25722. continue;
  25723. }
  25724. seenSlotNames.add(staticSlotName);
  25725. if (staticSlotName === "default") {
  25726. hasNamedDefaultSlot = true;
  25727. }
  25728. }
  25729. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  25730. }
  25731. }
  25732. if (!onComponentSlot) {
  25733. const buildDefaultSlotProperty = (props, children2) => {
  25734. const fn = buildSlotFn(props, void 0, children2, loc);
  25735. return createObjectProperty(`default`, fn);
  25736. };
  25737. if (!hasTemplateSlots) {
  25738. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  25739. } else if (implicitDefaultChildren.length && // #3766
  25740. // with whitespace: 'preserve', whitespaces between slots will end up in
  25741. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  25742. !implicitDefaultChildren.every(isWhitespaceText)) {
  25743. if (hasNamedDefaultSlot) {
  25744. context.onError(
  25745. createCompilerError(
  25746. 39,
  25747. implicitDefaultChildren[0].loc
  25748. )
  25749. );
  25750. } else {
  25751. slotsProperties.push(
  25752. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  25753. );
  25754. }
  25755. }
  25756. }
  25757. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  25758. let slots = createObjectExpression(
  25759. slotsProperties.concat(
  25760. createObjectProperty(
  25761. `_`,
  25762. // 2 = compiled but dynamic = can skip normalization, but must run diff
  25763. // 1 = compiled and static = can skip normalization AND diff as optimized
  25764. createSimpleExpression(
  25765. slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
  25766. false
  25767. )
  25768. )
  25769. ),
  25770. loc
  25771. );
  25772. if (dynamicSlots.length) {
  25773. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  25774. slots,
  25775. createArrayExpression(dynamicSlots)
  25776. ]);
  25777. }
  25778. return {
  25779. slots,
  25780. hasDynamicSlots
  25781. };
  25782. }
  25783. function buildDynamicSlot(name, fn, index) {
  25784. const props = [
  25785. createObjectProperty(`name`, name),
  25786. createObjectProperty(`fn`, fn)
  25787. ];
  25788. if (index != null) {
  25789. props.push(
  25790. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  25791. );
  25792. }
  25793. return createObjectExpression(props);
  25794. }
  25795. function hasForwardedSlots(children) {
  25796. for (let i = 0; i < children.length; i++) {
  25797. const child = children[i];
  25798. switch (child.type) {
  25799. case 1:
  25800. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  25801. return true;
  25802. }
  25803. break;
  25804. case 9:
  25805. if (hasForwardedSlots(child.branches)) return true;
  25806. break;
  25807. case 10:
  25808. case 11:
  25809. if (hasForwardedSlots(child.children)) return true;
  25810. break;
  25811. }
  25812. }
  25813. return false;
  25814. }
  25815. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  25816. const transformElement = (node, context) => {
  25817. return function postTransformElement() {
  25818. node = context.currentNode;
  25819. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  25820. return;
  25821. }
  25822. const { tag, props } = node;
  25823. const isComponent = node.tagType === 1;
  25824. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  25825. const isDynamicComponent = isObject$2(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  25826. let vnodeProps;
  25827. let vnodeChildren;
  25828. let patchFlag = 0;
  25829. let vnodeDynamicProps;
  25830. let dynamicPropNames;
  25831. let vnodeDirectives;
  25832. let shouldUseBlock = (
  25833. // dynamic component may resolve to plain elements
  25834. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  25835. // updates inside get proper isSVG flag at runtime. (#639, #643)
  25836. // This is technically web-specific, but splitting the logic out of core
  25837. // leads to too much unnecessary complexity.
  25838. (tag === "svg" || tag === "foreignObject" || tag === "math")
  25839. );
  25840. if (props.length > 0) {
  25841. const propsBuildResult = buildProps(
  25842. node,
  25843. context,
  25844. void 0,
  25845. isComponent,
  25846. isDynamicComponent
  25847. );
  25848. vnodeProps = propsBuildResult.props;
  25849. patchFlag = propsBuildResult.patchFlag;
  25850. dynamicPropNames = propsBuildResult.dynamicPropNames;
  25851. const directives = propsBuildResult.directives;
  25852. vnodeDirectives = directives && directives.length ? createArrayExpression(
  25853. directives.map((dir) => buildDirectiveArgs(dir, context))
  25854. ) : void 0;
  25855. if (propsBuildResult.shouldUseBlock) {
  25856. shouldUseBlock = true;
  25857. }
  25858. }
  25859. if (node.children.length > 0) {
  25860. if (vnodeTag === KEEP_ALIVE) {
  25861. shouldUseBlock = true;
  25862. patchFlag |= 1024;
  25863. if (node.children.length > 1) {
  25864. context.onError(
  25865. createCompilerError(47, {
  25866. start: node.children[0].loc.start,
  25867. end: node.children[node.children.length - 1].loc.end,
  25868. source: ""
  25869. })
  25870. );
  25871. }
  25872. }
  25873. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  25874. vnodeTag !== TELEPORT && // explained above.
  25875. vnodeTag !== KEEP_ALIVE;
  25876. if (shouldBuildAsSlots) {
  25877. const { slots, hasDynamicSlots } = buildSlots(node, context);
  25878. vnodeChildren = slots;
  25879. if (hasDynamicSlots) {
  25880. patchFlag |= 1024;
  25881. }
  25882. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  25883. const child = node.children[0];
  25884. const type = child.type;
  25885. const hasDynamicTextChild = type === 5 || type === 8;
  25886. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  25887. patchFlag |= 1;
  25888. }
  25889. if (hasDynamicTextChild || type === 2) {
  25890. vnodeChildren = child;
  25891. } else {
  25892. vnodeChildren = node.children;
  25893. }
  25894. } else {
  25895. vnodeChildren = node.children;
  25896. }
  25897. }
  25898. if (dynamicPropNames && dynamicPropNames.length) {
  25899. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  25900. }
  25901. node.codegenNode = createVNodeCall(
  25902. context,
  25903. vnodeTag,
  25904. vnodeProps,
  25905. vnodeChildren,
  25906. patchFlag === 0 ? void 0 : patchFlag,
  25907. vnodeDynamicProps,
  25908. vnodeDirectives,
  25909. !!shouldUseBlock,
  25910. false,
  25911. isComponent,
  25912. node.loc
  25913. );
  25914. };
  25915. };
  25916. function resolveComponentType(node, context, ssr = false) {
  25917. let { tag } = node;
  25918. const isExplicitDynamic = isComponentTag(tag);
  25919. const isProp = findProp(
  25920. node,
  25921. "is",
  25922. false,
  25923. true
  25924. /* allow empty */
  25925. );
  25926. if (isProp) {
  25927. if (isExplicitDynamic || false) {
  25928. let exp;
  25929. if (isProp.type === 6) {
  25930. exp = isProp.value && createSimpleExpression(isProp.value.content, true);
  25931. } else {
  25932. exp = isProp.exp;
  25933. if (!exp) {
  25934. exp = createSimpleExpression(`is`, false, isProp.arg.loc);
  25935. {
  25936. exp = isProp.exp = processExpression(exp, context);
  25937. }
  25938. }
  25939. }
  25940. if (exp) {
  25941. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  25942. exp
  25943. ]);
  25944. }
  25945. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  25946. tag = isProp.value.content.slice(4);
  25947. }
  25948. }
  25949. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  25950. if (builtIn) {
  25951. if (!ssr) context.helper(builtIn);
  25952. return builtIn;
  25953. }
  25954. {
  25955. const fromSetup = resolveSetupReference(tag, context);
  25956. if (fromSetup) {
  25957. return fromSetup;
  25958. }
  25959. const dotIndex = tag.indexOf(".");
  25960. if (dotIndex > 0) {
  25961. const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
  25962. if (ns) {
  25963. return ns + tag.slice(dotIndex);
  25964. }
  25965. }
  25966. }
  25967. if (context.selfName && capitalize(camelize(tag)) === context.selfName) {
  25968. context.helper(RESOLVE_COMPONENT);
  25969. context.components.add(tag + `__self`);
  25970. return toValidAssetId(tag, `component`);
  25971. }
  25972. context.helper(RESOLVE_COMPONENT);
  25973. context.components.add(tag);
  25974. return toValidAssetId(tag, `component`);
  25975. }
  25976. function resolveSetupReference(name, context) {
  25977. const bindings = context.bindingMetadata;
  25978. if (!bindings || bindings.__isScriptSetup === false) {
  25979. return;
  25980. }
  25981. const camelName = camelize(name);
  25982. const PascalName = capitalize(camelName);
  25983. const checkType = (type) => {
  25984. if (bindings[name] === type) {
  25985. return name;
  25986. }
  25987. if (bindings[camelName] === type) {
  25988. return camelName;
  25989. }
  25990. if (bindings[PascalName] === type) {
  25991. return PascalName;
  25992. }
  25993. };
  25994. const fromConst = checkType("setup-const") || checkType("setup-reactive-const") || checkType("literal-const");
  25995. if (fromConst) {
  25996. return context.inline ? (
  25997. // in inline mode, const setup bindings (e.g. imports) can be used as-is
  25998. fromConst
  25999. ) : `$setup[${JSON.stringify(fromConst)}]`;
  26000. }
  26001. const fromMaybeRef = checkType("setup-let") || checkType("setup-ref") || checkType("setup-maybe-ref");
  26002. if (fromMaybeRef) {
  26003. return context.inline ? (
  26004. // setup scope bindings that may be refs need to be unrefed
  26005. `${context.helperString(UNREF)}(${fromMaybeRef})`
  26006. ) : `$setup[${JSON.stringify(fromMaybeRef)}]`;
  26007. }
  26008. const fromProps = checkType("props");
  26009. if (fromProps) {
  26010. return `${context.helperString(UNREF)}(${context.inline ? "__props" : "$props"}[${JSON.stringify(fromProps)}])`;
  26011. }
  26012. }
  26013. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  26014. const { tag, loc: elementLoc, children } = node;
  26015. let properties = [];
  26016. const mergeArgs = [];
  26017. const runtimeDirectives = [];
  26018. const hasChildren = children.length > 0;
  26019. let shouldUseBlock = false;
  26020. let patchFlag = 0;
  26021. let hasRef = false;
  26022. let hasClassBinding = false;
  26023. let hasStyleBinding = false;
  26024. let hasHydrationEventBinding = false;
  26025. let hasDynamicKeys = false;
  26026. let hasVnodeHook = false;
  26027. const dynamicPropNames = [];
  26028. const pushMergeArg = (arg) => {
  26029. if (properties.length) {
  26030. mergeArgs.push(
  26031. createObjectExpression(dedupeProperties(properties), elementLoc)
  26032. );
  26033. properties = [];
  26034. }
  26035. if (arg) mergeArgs.push(arg);
  26036. };
  26037. const pushRefVForMarker = () => {
  26038. if (context.scopes.vFor > 0) {
  26039. properties.push(
  26040. createObjectProperty(
  26041. createSimpleExpression("ref_for", true),
  26042. createSimpleExpression("true")
  26043. )
  26044. );
  26045. }
  26046. };
  26047. const analyzePatchFlag = ({ key, value }) => {
  26048. if (isStaticExp(key)) {
  26049. const name = key.content;
  26050. const isEventHandler = isOn(name);
  26051. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  26052. // dedicated fast path.
  26053. name.toLowerCase() !== "onclick" && // omit v-model handlers
  26054. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  26055. !isReservedProp(name)) {
  26056. hasHydrationEventBinding = true;
  26057. }
  26058. if (isEventHandler && isReservedProp(name)) {
  26059. hasVnodeHook = true;
  26060. }
  26061. if (isEventHandler && value.type === 14) {
  26062. value = value.arguments[0];
  26063. }
  26064. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  26065. return;
  26066. }
  26067. if (name === "ref") {
  26068. hasRef = true;
  26069. } else if (name === "class") {
  26070. hasClassBinding = true;
  26071. } else if (name === "style") {
  26072. hasStyleBinding = true;
  26073. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  26074. dynamicPropNames.push(name);
  26075. }
  26076. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  26077. dynamicPropNames.push(name);
  26078. }
  26079. } else {
  26080. hasDynamicKeys = true;
  26081. }
  26082. };
  26083. for (let i = 0; i < props.length; i++) {
  26084. const prop = props[i];
  26085. if (prop.type === 6) {
  26086. const { loc, name, nameLoc, value } = prop;
  26087. let isStatic = true;
  26088. if (name === "ref") {
  26089. hasRef = true;
  26090. pushRefVForMarker();
  26091. if (value && context.inline) {
  26092. const binding = context.bindingMetadata[value.content];
  26093. if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") {
  26094. isStatic = false;
  26095. properties.push(
  26096. createObjectProperty(
  26097. createSimpleExpression("ref_key", true),
  26098. createSimpleExpression(value.content, true, value.loc)
  26099. )
  26100. );
  26101. }
  26102. }
  26103. }
  26104. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || false)) {
  26105. continue;
  26106. }
  26107. properties.push(
  26108. createObjectProperty(
  26109. createSimpleExpression(name, true, nameLoc),
  26110. createSimpleExpression(
  26111. value ? value.content : "",
  26112. isStatic,
  26113. value ? value.loc : loc
  26114. )
  26115. )
  26116. );
  26117. } else {
  26118. const { name, arg, exp, loc, modifiers } = prop;
  26119. const isVBind = name === "bind";
  26120. const isVOn = name === "on";
  26121. if (name === "slot") {
  26122. if (!isComponent) {
  26123. context.onError(
  26124. createCompilerError(40, loc)
  26125. );
  26126. }
  26127. continue;
  26128. }
  26129. if (name === "once" || name === "memo") {
  26130. continue;
  26131. }
  26132. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || false)) {
  26133. continue;
  26134. }
  26135. if (isVOn && ssr) {
  26136. continue;
  26137. }
  26138. if (
  26139. // #938: elements with dynamic keys should be forced into blocks
  26140. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  26141. // before children
  26142. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  26143. ) {
  26144. shouldUseBlock = true;
  26145. }
  26146. if (isVBind && isStaticArgOf(arg, "ref")) {
  26147. pushRefVForMarker();
  26148. }
  26149. if (!arg && (isVBind || isVOn)) {
  26150. hasDynamicKeys = true;
  26151. if (exp) {
  26152. if (isVBind) {
  26153. pushRefVForMarker();
  26154. pushMergeArg();
  26155. mergeArgs.push(exp);
  26156. } else {
  26157. pushMergeArg({
  26158. type: 14,
  26159. loc,
  26160. callee: context.helper(TO_HANDLERS),
  26161. arguments: isComponent ? [exp] : [exp, `true`]
  26162. });
  26163. }
  26164. } else {
  26165. context.onError(
  26166. createCompilerError(
  26167. isVBind ? 34 : 35,
  26168. loc
  26169. )
  26170. );
  26171. }
  26172. continue;
  26173. }
  26174. if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
  26175. patchFlag |= 32;
  26176. }
  26177. const directiveTransform = context.directiveTransforms[name];
  26178. if (directiveTransform) {
  26179. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  26180. !ssr && props2.forEach(analyzePatchFlag);
  26181. if (isVOn && arg && !isStaticExp(arg)) {
  26182. pushMergeArg(createObjectExpression(props2, elementLoc));
  26183. } else {
  26184. properties.push(...props2);
  26185. }
  26186. if (needRuntime) {
  26187. runtimeDirectives.push(prop);
  26188. if (isSymbol$1(needRuntime)) {
  26189. directiveImportMap.set(prop, needRuntime);
  26190. }
  26191. }
  26192. } else if (!isBuiltInDirective(name)) {
  26193. runtimeDirectives.push(prop);
  26194. if (hasChildren) {
  26195. shouldUseBlock = true;
  26196. }
  26197. }
  26198. }
  26199. }
  26200. let propsExpression = void 0;
  26201. if (mergeArgs.length) {
  26202. pushMergeArg();
  26203. if (mergeArgs.length > 1) {
  26204. propsExpression = createCallExpression(
  26205. context.helper(MERGE_PROPS),
  26206. mergeArgs,
  26207. elementLoc
  26208. );
  26209. } else {
  26210. propsExpression = mergeArgs[0];
  26211. }
  26212. } else if (properties.length) {
  26213. propsExpression = createObjectExpression(
  26214. dedupeProperties(properties),
  26215. elementLoc
  26216. );
  26217. }
  26218. if (hasDynamicKeys) {
  26219. patchFlag |= 16;
  26220. } else {
  26221. if (hasClassBinding && !isComponent) {
  26222. patchFlag |= 2;
  26223. }
  26224. if (hasStyleBinding && !isComponent) {
  26225. patchFlag |= 4;
  26226. }
  26227. if (dynamicPropNames.length) {
  26228. patchFlag |= 8;
  26229. }
  26230. if (hasHydrationEventBinding) {
  26231. patchFlag |= 32;
  26232. }
  26233. }
  26234. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  26235. patchFlag |= 512;
  26236. }
  26237. if (!context.inSSR && propsExpression) {
  26238. switch (propsExpression.type) {
  26239. case 15:
  26240. let classKeyIndex = -1;
  26241. let styleKeyIndex = -1;
  26242. let hasDynamicKey = false;
  26243. for (let i = 0; i < propsExpression.properties.length; i++) {
  26244. const key = propsExpression.properties[i].key;
  26245. if (isStaticExp(key)) {
  26246. if (key.content === "class") {
  26247. classKeyIndex = i;
  26248. } else if (key.content === "style") {
  26249. styleKeyIndex = i;
  26250. }
  26251. } else if (!key.isHandlerKey) {
  26252. hasDynamicKey = true;
  26253. }
  26254. }
  26255. const classProp = propsExpression.properties[classKeyIndex];
  26256. const styleProp = propsExpression.properties[styleKeyIndex];
  26257. if (!hasDynamicKey) {
  26258. if (classProp && !isStaticExp(classProp.value)) {
  26259. classProp.value = createCallExpression(
  26260. context.helper(NORMALIZE_CLASS),
  26261. [classProp.value]
  26262. );
  26263. }
  26264. if (styleProp && // the static style is compiled into an object,
  26265. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  26266. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  26267. // v-bind:style with static literal object
  26268. styleProp.value.type === 17)) {
  26269. styleProp.value = createCallExpression(
  26270. context.helper(NORMALIZE_STYLE),
  26271. [styleProp.value]
  26272. );
  26273. }
  26274. } else {
  26275. propsExpression = createCallExpression(
  26276. context.helper(NORMALIZE_PROPS),
  26277. [propsExpression]
  26278. );
  26279. }
  26280. break;
  26281. case 14:
  26282. break;
  26283. default:
  26284. propsExpression = createCallExpression(
  26285. context.helper(NORMALIZE_PROPS),
  26286. [
  26287. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  26288. propsExpression
  26289. ])
  26290. ]
  26291. );
  26292. break;
  26293. }
  26294. }
  26295. return {
  26296. props: propsExpression,
  26297. directives: runtimeDirectives,
  26298. patchFlag,
  26299. dynamicPropNames,
  26300. shouldUseBlock
  26301. };
  26302. }
  26303. function dedupeProperties(properties) {
  26304. const knownProps = /* @__PURE__ */ new Map();
  26305. const deduped = [];
  26306. for (let i = 0; i < properties.length; i++) {
  26307. const prop = properties[i];
  26308. if (prop.key.type === 8 || !prop.key.isStatic) {
  26309. deduped.push(prop);
  26310. continue;
  26311. }
  26312. const name = prop.key.content;
  26313. const existing = knownProps.get(name);
  26314. if (existing) {
  26315. if (name === "style" || name === "class" || isOn(name)) {
  26316. mergeAsArray(existing, prop);
  26317. }
  26318. } else {
  26319. knownProps.set(name, prop);
  26320. deduped.push(prop);
  26321. }
  26322. }
  26323. return deduped;
  26324. }
  26325. function mergeAsArray(existing, incoming) {
  26326. if (existing.value.type === 17) {
  26327. existing.value.elements.push(incoming.value);
  26328. } else {
  26329. existing.value = createArrayExpression(
  26330. [existing.value, incoming.value],
  26331. existing.loc
  26332. );
  26333. }
  26334. }
  26335. function buildDirectiveArgs(dir, context) {
  26336. const dirArgs = [];
  26337. const runtime = directiveImportMap.get(dir);
  26338. if (runtime) {
  26339. dirArgs.push(context.helperString(runtime));
  26340. } else {
  26341. const fromSetup = resolveSetupReference("v-" + dir.name, context);
  26342. if (fromSetup) {
  26343. dirArgs.push(fromSetup);
  26344. } else {
  26345. context.helper(RESOLVE_DIRECTIVE);
  26346. context.directives.add(dir.name);
  26347. dirArgs.push(toValidAssetId(dir.name, `directive`));
  26348. }
  26349. }
  26350. const { loc } = dir;
  26351. if (dir.exp) dirArgs.push(dir.exp);
  26352. if (dir.arg) {
  26353. if (!dir.exp) {
  26354. dirArgs.push(`void 0`);
  26355. }
  26356. dirArgs.push(dir.arg);
  26357. }
  26358. if (Object.keys(dir.modifiers).length) {
  26359. if (!dir.arg) {
  26360. if (!dir.exp) {
  26361. dirArgs.push(`void 0`);
  26362. }
  26363. dirArgs.push(`void 0`);
  26364. }
  26365. const trueExpression = createSimpleExpression(`true`, false, loc);
  26366. dirArgs.push(
  26367. createObjectExpression(
  26368. dir.modifiers.map(
  26369. (modifier) => createObjectProperty(modifier, trueExpression)
  26370. ),
  26371. loc
  26372. )
  26373. );
  26374. }
  26375. return createArrayExpression(dirArgs, dir.loc);
  26376. }
  26377. function stringifyDynamicPropNames(props) {
  26378. let propsNamesString = `[`;
  26379. for (let i = 0, l = props.length; i < l; i++) {
  26380. propsNamesString += JSON.stringify(props[i]);
  26381. if (i < l - 1) propsNamesString += ", ";
  26382. }
  26383. return propsNamesString + `]`;
  26384. }
  26385. function isComponentTag(tag) {
  26386. return tag === "component" || tag === "Component";
  26387. }
  26388. const transformSlotOutlet = (node, context) => {
  26389. if (isSlotOutlet(node)) {
  26390. const { children, loc } = node;
  26391. const { slotName, slotProps } = processSlotOutlet(node, context);
  26392. const slotArgs = [
  26393. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  26394. slotName,
  26395. "{}",
  26396. "undefined",
  26397. "true"
  26398. ];
  26399. let expectedLen = 2;
  26400. if (slotProps) {
  26401. slotArgs[2] = slotProps;
  26402. expectedLen = 3;
  26403. }
  26404. if (children.length) {
  26405. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  26406. expectedLen = 4;
  26407. }
  26408. if (context.scopeId && !context.slotted) {
  26409. expectedLen = 5;
  26410. }
  26411. slotArgs.splice(expectedLen);
  26412. node.codegenNode = createCallExpression(
  26413. context.helper(RENDER_SLOT),
  26414. slotArgs,
  26415. loc
  26416. );
  26417. }
  26418. };
  26419. function processSlotOutlet(node, context) {
  26420. let slotName = `"default"`;
  26421. let slotProps = void 0;
  26422. const nonNameProps = [];
  26423. for (let i = 0; i < node.props.length; i++) {
  26424. const p = node.props[i];
  26425. if (p.type === 6) {
  26426. if (p.value) {
  26427. if (p.name === "name") {
  26428. slotName = JSON.stringify(p.value.content);
  26429. } else {
  26430. p.name = camelize(p.name);
  26431. nonNameProps.push(p);
  26432. }
  26433. }
  26434. } else {
  26435. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  26436. if (p.exp) {
  26437. slotName = p.exp;
  26438. } else if (p.arg && p.arg.type === 4) {
  26439. const name = camelize(p.arg.content);
  26440. slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
  26441. {
  26442. slotName = p.exp = processExpression(p.exp, context);
  26443. }
  26444. }
  26445. } else {
  26446. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  26447. p.arg.content = camelize(p.arg.content);
  26448. }
  26449. nonNameProps.push(p);
  26450. }
  26451. }
  26452. }
  26453. if (nonNameProps.length > 0) {
  26454. const { props, directives } = buildProps(
  26455. node,
  26456. context,
  26457. nonNameProps,
  26458. false,
  26459. false
  26460. );
  26461. slotProps = props;
  26462. if (directives.length) {
  26463. context.onError(
  26464. createCompilerError(
  26465. 36,
  26466. directives[0].loc
  26467. )
  26468. );
  26469. }
  26470. }
  26471. return {
  26472. slotName,
  26473. slotProps
  26474. };
  26475. }
  26476. const transformOn$1 = (dir, node, context, augmentor) => {
  26477. const { loc, modifiers, arg } = dir;
  26478. if (!dir.exp && !modifiers.length) {
  26479. context.onError(createCompilerError(35, loc));
  26480. }
  26481. let eventName;
  26482. if (arg.type === 4) {
  26483. if (arg.isStatic) {
  26484. let rawName = arg.content;
  26485. if (rawName.startsWith("vnode")) {
  26486. context.onError(createCompilerError(52, arg.loc));
  26487. }
  26488. if (rawName.startsWith("vue:")) {
  26489. rawName = `vnode-${rawName.slice(4)}`;
  26490. }
  26491. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  26492. // for non-element and vnode lifecycle event listeners, auto convert
  26493. // it to camelCase. See issue #2249
  26494. toHandlerKey(camelize(rawName))
  26495. ) : (
  26496. // preserve case for plain element listeners that have uppercase
  26497. // letters, as these may be custom elements' custom events
  26498. `on:${rawName}`
  26499. );
  26500. eventName = createSimpleExpression(eventString, true, arg.loc);
  26501. } else {
  26502. eventName = createCompoundExpression([
  26503. `${context.helperString(TO_HANDLER_KEY)}(`,
  26504. arg,
  26505. `)`
  26506. ]);
  26507. }
  26508. } else {
  26509. eventName = arg;
  26510. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  26511. eventName.children.push(`)`);
  26512. }
  26513. let exp = dir.exp;
  26514. if (exp && !exp.content.trim()) {
  26515. exp = void 0;
  26516. }
  26517. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  26518. if (exp) {
  26519. const isMemberExp = isMemberExpression(exp, context);
  26520. const isInlineStatement = !(isMemberExp || isFnExpression(exp, context));
  26521. const hasMultipleStatements = exp.content.includes(`;`);
  26522. if (context.prefixIdentifiers) {
  26523. isInlineStatement && context.addIdentifiers(`$event`);
  26524. exp = dir.exp = processExpression(
  26525. exp,
  26526. context,
  26527. false,
  26528. hasMultipleStatements
  26529. );
  26530. isInlineStatement && context.removeIdentifiers(`$event`);
  26531. shouldCache = context.cacheHandlers && // unnecessary to cache inside v-once
  26532. !context.inVOnce && // runtime constants don't need to be cached
  26533. // (this is analyzed by compileScript in SFC <script setup>)
  26534. !(exp.type === 4 && exp.constType > 0) && // #1541 bail if this is a member exp handler passed to a component -
  26535. // we need to use the original function to preserve arity,
  26536. // e.g. <transition> relies on checking cb.length to determine
  26537. // transition end handling. Inline function is ok since its arity
  26538. // is preserved even when cached.
  26539. !(isMemberExp && node.tagType === 1) && // bail if the function references closure variables (v-for, v-slot)
  26540. // it must be passed fresh to avoid stale values.
  26541. !hasScopeRef(exp, context.identifiers);
  26542. if (shouldCache && isMemberExp) {
  26543. if (exp.type === 4) {
  26544. exp.content = `${exp.content} && ${exp.content}(...args)`;
  26545. } else {
  26546. exp.children = [...exp.children, ` && `, ...exp.children, `(...args)`];
  26547. }
  26548. }
  26549. }
  26550. if (isInlineStatement || shouldCache && isMemberExp) {
  26551. exp = createCompoundExpression([
  26552. `${isInlineStatement ? context.isTS ? `($event: any)` : `$event` : `${context.isTS ? `
  26553. //@ts-ignore
  26554. ` : ``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  26555. exp,
  26556. hasMultipleStatements ? `}` : `)`
  26557. ]);
  26558. }
  26559. }
  26560. let ret = {
  26561. props: [
  26562. createObjectProperty(
  26563. eventName,
  26564. exp || createSimpleExpression(`() => {}`, false, loc)
  26565. )
  26566. ]
  26567. };
  26568. if (augmentor) {
  26569. ret = augmentor(ret);
  26570. }
  26571. if (shouldCache) {
  26572. ret.props[0].value = context.cache(ret.props[0].value);
  26573. }
  26574. ret.props.forEach((p) => p.key.isHandlerKey = true);
  26575. return ret;
  26576. };
  26577. const transformBind = (dir, _node, context) => {
  26578. const { modifiers, loc } = dir;
  26579. const arg = dir.arg;
  26580. let { exp } = dir;
  26581. if (exp && exp.type === 4 && !exp.content.trim()) {
  26582. {
  26583. context.onError(
  26584. createCompilerError(34, loc)
  26585. );
  26586. return {
  26587. props: [
  26588. createObjectProperty(arg, createSimpleExpression("", true, loc))
  26589. ]
  26590. };
  26591. }
  26592. }
  26593. if (arg.type !== 4) {
  26594. arg.children.unshift(`(`);
  26595. arg.children.push(`) || ""`);
  26596. } else if (!arg.isStatic) {
  26597. arg.content = arg.content ? `${arg.content} || ""` : `""`;
  26598. }
  26599. if (modifiers.some((mod) => mod.content === "camel")) {
  26600. if (arg.type === 4) {
  26601. if (arg.isStatic) {
  26602. arg.content = camelize(arg.content);
  26603. } else {
  26604. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  26605. }
  26606. } else {
  26607. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  26608. arg.children.push(`)`);
  26609. }
  26610. }
  26611. if (!context.inSSR) {
  26612. if (modifiers.some((mod) => mod.content === "prop")) {
  26613. injectPrefix(arg, ".");
  26614. }
  26615. if (modifiers.some((mod) => mod.content === "attr")) {
  26616. injectPrefix(arg, "^");
  26617. }
  26618. }
  26619. return {
  26620. props: [createObjectProperty(arg, exp)]
  26621. };
  26622. };
  26623. const injectPrefix = (arg, prefix) => {
  26624. if (arg.type === 4) {
  26625. if (arg.isStatic) {
  26626. arg.content = prefix + arg.content;
  26627. } else {
  26628. arg.content = `\`${prefix}\${${arg.content}}\``;
  26629. }
  26630. } else {
  26631. arg.children.unshift(`'${prefix}' + (`);
  26632. arg.children.push(`)`);
  26633. }
  26634. };
  26635. const transformText = (node, context) => {
  26636. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  26637. return () => {
  26638. const children = node.children;
  26639. let currentContainer = void 0;
  26640. let hasText = false;
  26641. for (let i = 0; i < children.length; i++) {
  26642. const child = children[i];
  26643. if (isText$1(child)) {
  26644. hasText = true;
  26645. for (let j = i + 1; j < children.length; j++) {
  26646. const next = children[j];
  26647. if (isText$1(next)) {
  26648. if (!currentContainer) {
  26649. currentContainer = children[i] = createCompoundExpression(
  26650. [child],
  26651. child.loc
  26652. );
  26653. }
  26654. currentContainer.children.push(` + `, next);
  26655. children.splice(j, 1);
  26656. j--;
  26657. } else {
  26658. currentContainer = void 0;
  26659. break;
  26660. }
  26661. }
  26662. }
  26663. }
  26664. if (!hasText || // if this is a plain element with a single text child, leave it
  26665. // as-is since the runtime has dedicated fast path for this by directly
  26666. // setting textContent of the element.
  26667. // for component root it's always normalized anyway.
  26668. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  26669. // custom directives can potentially add DOM elements arbitrarily,
  26670. // we need to avoid setting textContent of the element at runtime
  26671. // to avoid accidentally overwriting the DOM elements added
  26672. // by the user through custom directives.
  26673. !node.props.find(
  26674. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  26675. ) && // in compat mode, <template> tags with no special directives
  26676. // will be rendered as a fragment so its children must be
  26677. // converted into vnodes.
  26678. true)) {
  26679. return;
  26680. }
  26681. for (let i = 0; i < children.length; i++) {
  26682. const child = children[i];
  26683. if (isText$1(child) || child.type === 8) {
  26684. const callArgs = [];
  26685. if (child.type !== 2 || child.content !== " ") {
  26686. callArgs.push(child);
  26687. }
  26688. if (!context.ssr && getConstantType(child, context) === 0) {
  26689. callArgs.push(
  26690. 1 + (` /* ${PatchFlagNames[1]} */` )
  26691. );
  26692. }
  26693. children[i] = {
  26694. type: 12,
  26695. content: child,
  26696. loc: child.loc,
  26697. codegenNode: createCallExpression(
  26698. context.helper(CREATE_TEXT),
  26699. callArgs
  26700. )
  26701. };
  26702. }
  26703. }
  26704. };
  26705. }
  26706. };
  26707. const seen$1 = /* @__PURE__ */ new WeakSet();
  26708. const transformOnce = (node, context) => {
  26709. if (node.type === 1 && findDir(node, "once", true)) {
  26710. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  26711. return;
  26712. }
  26713. seen$1.add(node);
  26714. context.inVOnce = true;
  26715. context.helper(SET_BLOCK_TRACKING);
  26716. return () => {
  26717. context.inVOnce = false;
  26718. const cur = context.currentNode;
  26719. if (cur.codegenNode) {
  26720. cur.codegenNode = context.cache(
  26721. cur.codegenNode,
  26722. true,
  26723. true
  26724. );
  26725. }
  26726. };
  26727. }
  26728. };
  26729. const transformModel$1 = (dir, node, context) => {
  26730. const { exp, arg } = dir;
  26731. if (!exp) {
  26732. context.onError(
  26733. createCompilerError(41, dir.loc)
  26734. );
  26735. return createTransformProps();
  26736. }
  26737. const rawExp = exp.loc.source.trim();
  26738. const expString = exp.type === 4 ? exp.content : rawExp;
  26739. const bindingType = context.bindingMetadata[rawExp];
  26740. if (bindingType === "props" || bindingType === "props-aliased") {
  26741. context.onError(createCompilerError(44, exp.loc));
  26742. return createTransformProps();
  26743. }
  26744. if (bindingType === "literal-const" || bindingType === "setup-const") {
  26745. context.onError(createCompilerError(45, exp.loc));
  26746. return createTransformProps();
  26747. }
  26748. const maybeRef = context.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
  26749. if (!expString.trim() || !isMemberExpression(exp, context) && !maybeRef) {
  26750. context.onError(
  26751. createCompilerError(42, exp.loc)
  26752. );
  26753. return createTransformProps();
  26754. }
  26755. if (context.prefixIdentifiers && isSimpleIdentifier(expString) && context.identifiers[expString]) {
  26756. context.onError(
  26757. createCompilerError(43, exp.loc)
  26758. );
  26759. return createTransformProps();
  26760. }
  26761. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  26762. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  26763. let assignmentExp;
  26764. const eventArg = context.isTS ? `($event: any)` : `$event`;
  26765. if (maybeRef) {
  26766. if (bindingType === "setup-ref") {
  26767. assignmentExp = createCompoundExpression([
  26768. `${eventArg} => ((`,
  26769. createSimpleExpression(rawExp, false, exp.loc),
  26770. `).value = $event)`
  26771. ]);
  26772. } else {
  26773. const altAssignment = bindingType === "setup-let" ? `${rawExp} = $event` : `null`;
  26774. assignmentExp = createCompoundExpression([
  26775. `${eventArg} => (${context.helperString(IS_REF)}(${rawExp}) ? (`,
  26776. createSimpleExpression(rawExp, false, exp.loc),
  26777. `).value = $event : ${altAssignment})`
  26778. ]);
  26779. }
  26780. } else {
  26781. assignmentExp = createCompoundExpression([
  26782. `${eventArg} => ((`,
  26783. exp,
  26784. `) = $event)`
  26785. ]);
  26786. }
  26787. const props = [
  26788. // modelValue: foo
  26789. createObjectProperty(propName, dir.exp),
  26790. // "onUpdate:modelValue": $event => (foo = $event)
  26791. createObjectProperty(eventName, assignmentExp)
  26792. ];
  26793. if (context.prefixIdentifiers && !context.inVOnce && context.cacheHandlers && !hasScopeRef(exp, context.identifiers)) {
  26794. props[1].value = context.cache(props[1].value);
  26795. }
  26796. if (dir.modifiers.length && node.tagType === 1) {
  26797. const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  26798. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  26799. props.push(
  26800. createObjectProperty(
  26801. modifiersKey,
  26802. createSimpleExpression(
  26803. `{ ${modifiers} }`,
  26804. false,
  26805. dir.loc,
  26806. 2
  26807. )
  26808. )
  26809. );
  26810. }
  26811. return createTransformProps(props);
  26812. };
  26813. function createTransformProps(props = []) {
  26814. return { props };
  26815. }
  26816. const seen = /* @__PURE__ */ new WeakSet();
  26817. const transformMemo = (node, context) => {
  26818. if (node.type === 1) {
  26819. const dir = findDir(node, "memo");
  26820. if (!dir || seen.has(node) || context.inSSR) {
  26821. return;
  26822. }
  26823. seen.add(node);
  26824. return () => {
  26825. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  26826. if (codegenNode && codegenNode.type === 13) {
  26827. if (node.tagType !== 1) {
  26828. convertToBlock(codegenNode, context);
  26829. }
  26830. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  26831. dir.exp,
  26832. createFunctionExpression(void 0, codegenNode),
  26833. `_cache`,
  26834. String(context.cached.length)
  26835. ]);
  26836. context.cached.push(null);
  26837. }
  26838. };
  26839. }
  26840. };
  26841. const transformVBindShorthand = (node, context) => {
  26842. if (node.type === 1) {
  26843. for (const prop of node.props) {
  26844. if (prop.type === 7 && prop.name === "bind" && (!prop.exp || // #13930 :foo in in-DOM templates will be parsed into :foo="" by browser
  26845. false) && prop.arg) {
  26846. const arg = prop.arg;
  26847. if (arg.type !== 4 || !arg.isStatic) {
  26848. context.onError(
  26849. createCompilerError(
  26850. 53,
  26851. arg.loc
  26852. )
  26853. );
  26854. prop.exp = createSimpleExpression("", true, arg.loc);
  26855. } else {
  26856. const propName = camelize(arg.content);
  26857. if (validFirstIdentCharRE.test(propName[0]) || // allow hyphen first char for https://github.com/vuejs/language-tools/pull/3424
  26858. propName[0] === "-") {
  26859. prop.exp = createSimpleExpression(propName, false, arg.loc);
  26860. }
  26861. }
  26862. }
  26863. }
  26864. }
  26865. };
  26866. function getBaseTransformPreset(prefixIdentifiers) {
  26867. return [
  26868. [
  26869. transformVBindShorthand,
  26870. transformOnce,
  26871. transformIf,
  26872. transformMemo,
  26873. transformFor,
  26874. ...[],
  26875. ...prefixIdentifiers ? [
  26876. // order is important
  26877. trackVForSlotScopes,
  26878. transformExpression
  26879. ] : [],
  26880. transformSlotOutlet,
  26881. transformElement,
  26882. trackSlotScopes,
  26883. transformText
  26884. ],
  26885. {
  26886. on: transformOn$1,
  26887. bind: transformBind,
  26888. model: transformModel$1
  26889. }
  26890. ];
  26891. }
  26892. function baseCompile(source, options = {}) {
  26893. const onError = options.onError || defaultOnError;
  26894. const isModuleMode = options.mode === "module";
  26895. const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
  26896. if (!prefixIdentifiers && options.cacheHandlers) {
  26897. onError(createCompilerError(50));
  26898. }
  26899. if (options.scopeId && !isModuleMode) {
  26900. onError(createCompilerError(51));
  26901. }
  26902. const resolvedOptions = extend({}, options, {
  26903. prefixIdentifiers
  26904. });
  26905. const ast = isString$1(source) ? baseParse(source, resolvedOptions) : source;
  26906. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
  26907. if (options.isTS) {
  26908. const { expressionPlugins } = options;
  26909. if (!expressionPlugins || !expressionPlugins.includes("typescript")) {
  26910. options.expressionPlugins = [...expressionPlugins || [], "typescript"];
  26911. }
  26912. }
  26913. transform(
  26914. ast,
  26915. extend({}, resolvedOptions, {
  26916. nodeTransforms: [
  26917. ...nodeTransforms,
  26918. ...options.nodeTransforms || []
  26919. // user transforms
  26920. ],
  26921. directiveTransforms: extend(
  26922. {},
  26923. directiveTransforms,
  26924. options.directiveTransforms || {}
  26925. // user transforms
  26926. )
  26927. })
  26928. );
  26929. return generate(ast, resolvedOptions);
  26930. }
  26931. const BindingTypes = {
  26932. "DATA": "data",
  26933. "PROPS": "props",
  26934. "PROPS_ALIASED": "props-aliased",
  26935. "SETUP_LET": "setup-let",
  26936. "SETUP_CONST": "setup-const",
  26937. "SETUP_REACTIVE_CONST": "setup-reactive-const",
  26938. "SETUP_MAYBE_REF": "setup-maybe-ref",
  26939. "SETUP_REF": "setup-ref",
  26940. "OPTIONS": "options",
  26941. "LITERAL_CONST": "literal-const"
  26942. };
  26943. const noopDirectiveTransform = () => ({ props: [] });
  26944. const V_MODEL_RADIO = /* @__PURE__ */ Symbol(`vModelRadio` );
  26945. const V_MODEL_CHECKBOX = /* @__PURE__ */ Symbol(
  26946. `vModelCheckbox`
  26947. );
  26948. const V_MODEL_TEXT = /* @__PURE__ */ Symbol(`vModelText` );
  26949. const V_MODEL_SELECT = /* @__PURE__ */ Symbol(
  26950. `vModelSelect`
  26951. );
  26952. const V_MODEL_DYNAMIC = /* @__PURE__ */ Symbol(
  26953. `vModelDynamic`
  26954. );
  26955. const V_ON_WITH_MODIFIERS = /* @__PURE__ */ Symbol(
  26956. `vOnModifiersGuard`
  26957. );
  26958. const V_ON_WITH_KEYS = /* @__PURE__ */ Symbol(
  26959. `vOnKeysGuard`
  26960. );
  26961. const V_SHOW = /* @__PURE__ */ Symbol(`vShow` );
  26962. const TRANSITION = /* @__PURE__ */ Symbol(`Transition` );
  26963. const TRANSITION_GROUP = /* @__PURE__ */ Symbol(
  26964. `TransitionGroup`
  26965. );
  26966. registerRuntimeHelpers({
  26967. [V_MODEL_RADIO]: `vModelRadio`,
  26968. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  26969. [V_MODEL_TEXT]: `vModelText`,
  26970. [V_MODEL_SELECT]: `vModelSelect`,
  26971. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  26972. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  26973. [V_ON_WITH_KEYS]: `withKeys`,
  26974. [V_SHOW]: `vShow`,
  26975. [TRANSITION]: `Transition`,
  26976. [TRANSITION_GROUP]: `TransitionGroup`
  26977. });
  26978. const parserOptions = {
  26979. parseMode: "html",
  26980. isVoidTag,
  26981. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
  26982. isPreTag: (tag) => tag === "pre",
  26983. isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
  26984. decodeEntities: void 0,
  26985. isBuiltInComponent: (tag) => {
  26986. if (tag === "Transition" || tag === "transition") {
  26987. return TRANSITION;
  26988. } else if (tag === "TransitionGroup" || tag === "transition-group") {
  26989. return TRANSITION_GROUP;
  26990. }
  26991. },
  26992. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  26993. getNamespace(tag, parent, rootNamespace) {
  26994. let ns = parent ? parent.ns : rootNamespace;
  26995. if (parent && ns === 2) {
  26996. if (parent.tag === "annotation-xml") {
  26997. if (tag === "svg") {
  26998. return 1;
  26999. }
  27000. if (parent.props.some(
  27001. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  27002. )) {
  27003. ns = 0;
  27004. }
  27005. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  27006. ns = 0;
  27007. }
  27008. } else if (parent && ns === 1) {
  27009. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  27010. ns = 0;
  27011. }
  27012. }
  27013. if (ns === 0) {
  27014. if (tag === "svg") {
  27015. return 1;
  27016. }
  27017. if (tag === "math") {
  27018. return 2;
  27019. }
  27020. }
  27021. return ns;
  27022. }
  27023. };
  27024. const transformStyle = (node) => {
  27025. if (node.type === 1) {
  27026. node.props.forEach((p, i) => {
  27027. if (p.type === 6 && p.name === "style" && p.value) {
  27028. node.props[i] = {
  27029. type: 7,
  27030. name: `bind`,
  27031. arg: createSimpleExpression(`style`, true, p.loc),
  27032. exp: parseInlineCSS(p.value.content, p.loc),
  27033. modifiers: [],
  27034. loc: p.loc
  27035. };
  27036. }
  27037. });
  27038. }
  27039. };
  27040. const parseInlineCSS = (cssText, loc) => {
  27041. const normalized = parseStringStyle(cssText);
  27042. return createSimpleExpression(
  27043. JSON.stringify(normalized),
  27044. false,
  27045. loc,
  27046. 3
  27047. );
  27048. };
  27049. function createDOMCompilerError(code, loc) {
  27050. return createCompilerError(
  27051. code,
  27052. loc,
  27053. DOMErrorMessages
  27054. );
  27055. }
  27056. const DOMErrorCodes = {
  27057. "X_V_HTML_NO_EXPRESSION": 54,
  27058. "54": "X_V_HTML_NO_EXPRESSION",
  27059. "X_V_HTML_WITH_CHILDREN": 55,
  27060. "55": "X_V_HTML_WITH_CHILDREN",
  27061. "X_V_TEXT_NO_EXPRESSION": 56,
  27062. "56": "X_V_TEXT_NO_EXPRESSION",
  27063. "X_V_TEXT_WITH_CHILDREN": 57,
  27064. "57": "X_V_TEXT_WITH_CHILDREN",
  27065. "X_V_MODEL_ON_INVALID_ELEMENT": 58,
  27066. "58": "X_V_MODEL_ON_INVALID_ELEMENT",
  27067. "X_V_MODEL_ARG_ON_ELEMENT": 59,
  27068. "59": "X_V_MODEL_ARG_ON_ELEMENT",
  27069. "X_V_MODEL_ON_FILE_INPUT_ELEMENT": 60,
  27070. "60": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
  27071. "X_V_MODEL_UNNECESSARY_VALUE": 61,
  27072. "61": "X_V_MODEL_UNNECESSARY_VALUE",
  27073. "X_V_SHOW_NO_EXPRESSION": 62,
  27074. "62": "X_V_SHOW_NO_EXPRESSION",
  27075. "X_TRANSITION_INVALID_CHILDREN": 63,
  27076. "63": "X_TRANSITION_INVALID_CHILDREN",
  27077. "X_IGNORED_SIDE_EFFECT_TAG": 64,
  27078. "64": "X_IGNORED_SIDE_EFFECT_TAG",
  27079. "__EXTEND_POINT__": 65,
  27080. "65": "__EXTEND_POINT__"
  27081. };
  27082. const DOMErrorMessages = {
  27083. [54]: `v-html is missing expression.`,
  27084. [55]: `v-html will override element children.`,
  27085. [56]: `v-text is missing expression.`,
  27086. [57]: `v-text will override element children.`,
  27087. [58]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  27088. [59]: `v-model argument is not supported on plain elements.`,
  27089. [60]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  27090. [61]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  27091. [62]: `v-show is missing expression.`,
  27092. [63]: `<Transition> expects exactly one child element or component.`,
  27093. [64]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  27094. };
  27095. const transformVHtml = (dir, node, context) => {
  27096. const { exp, loc } = dir;
  27097. if (!exp) {
  27098. context.onError(
  27099. createDOMCompilerError(54, loc)
  27100. );
  27101. }
  27102. if (node.children.length) {
  27103. context.onError(
  27104. createDOMCompilerError(55, loc)
  27105. );
  27106. node.children.length = 0;
  27107. }
  27108. return {
  27109. props: [
  27110. createObjectProperty(
  27111. createSimpleExpression(`innerHTML`, true, loc),
  27112. exp || createSimpleExpression("", true)
  27113. )
  27114. ]
  27115. };
  27116. };
  27117. const transformVText = (dir, node, context) => {
  27118. const { exp, loc } = dir;
  27119. if (!exp) {
  27120. context.onError(
  27121. createDOMCompilerError(56, loc)
  27122. );
  27123. }
  27124. if (node.children.length) {
  27125. context.onError(
  27126. createDOMCompilerError(57, loc)
  27127. );
  27128. node.children.length = 0;
  27129. }
  27130. return {
  27131. props: [
  27132. createObjectProperty(
  27133. createSimpleExpression(`textContent`, true),
  27134. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  27135. context.helperString(TO_DISPLAY_STRING),
  27136. [exp],
  27137. loc
  27138. ) : createSimpleExpression("", true)
  27139. )
  27140. ]
  27141. };
  27142. };
  27143. const transformModel = (dir, node, context) => {
  27144. const baseResult = transformModel$1(dir, node, context);
  27145. if (!baseResult.props.length || node.tagType === 1) {
  27146. return baseResult;
  27147. }
  27148. if (dir.arg) {
  27149. context.onError(
  27150. createDOMCompilerError(
  27151. 59,
  27152. dir.arg.loc
  27153. )
  27154. );
  27155. }
  27156. function checkDuplicatedValue() {
  27157. const value = findDir(node, "bind");
  27158. if (value && isStaticArgOf(value.arg, "value")) {
  27159. context.onError(
  27160. createDOMCompilerError(
  27161. 61,
  27162. value.loc
  27163. )
  27164. );
  27165. }
  27166. }
  27167. const { tag } = node;
  27168. const isCustomElement = context.isCustomElement(tag);
  27169. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  27170. let directiveToUse = V_MODEL_TEXT;
  27171. let isInvalidType = false;
  27172. if (tag === "input" || isCustomElement) {
  27173. const type = findProp(node, `type`);
  27174. if (type) {
  27175. if (type.type === 7) {
  27176. directiveToUse = V_MODEL_DYNAMIC;
  27177. } else if (type.value) {
  27178. switch (type.value.content) {
  27179. case "radio":
  27180. directiveToUse = V_MODEL_RADIO;
  27181. break;
  27182. case "checkbox":
  27183. directiveToUse = V_MODEL_CHECKBOX;
  27184. break;
  27185. case "file":
  27186. isInvalidType = true;
  27187. context.onError(
  27188. createDOMCompilerError(
  27189. 60,
  27190. dir.loc
  27191. )
  27192. );
  27193. break;
  27194. default:
  27195. checkDuplicatedValue();
  27196. break;
  27197. }
  27198. }
  27199. } else if (hasDynamicKeyVBind(node)) {
  27200. directiveToUse = V_MODEL_DYNAMIC;
  27201. } else {
  27202. checkDuplicatedValue();
  27203. }
  27204. } else if (tag === "select") {
  27205. directiveToUse = V_MODEL_SELECT;
  27206. } else {
  27207. checkDuplicatedValue();
  27208. }
  27209. if (!isInvalidType) {
  27210. baseResult.needRuntime = context.helper(directiveToUse);
  27211. }
  27212. } else {
  27213. context.onError(
  27214. createDOMCompilerError(
  27215. 58,
  27216. dir.loc
  27217. )
  27218. );
  27219. }
  27220. baseResult.props = baseResult.props.filter(
  27221. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  27222. );
  27223. return baseResult;
  27224. };
  27225. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  27226. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  27227. // event propagation management
  27228. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  27229. );
  27230. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  27231. const isKeyboardEvent = /* @__PURE__ */ makeMap(`onkeyup,onkeydown,onkeypress`);
  27232. const resolveModifiers = (key, modifiers, context, loc) => {
  27233. const keyModifiers = [];
  27234. const nonKeyModifiers = [];
  27235. const eventOptionModifiers = [];
  27236. for (let i = 0; i < modifiers.length; i++) {
  27237. const modifier = modifiers[i].content;
  27238. if (isEventOptionModifier(modifier)) {
  27239. eventOptionModifiers.push(modifier);
  27240. } else {
  27241. if (maybeKeyModifier(modifier)) {
  27242. if (isStaticExp(key)) {
  27243. if (isKeyboardEvent(key.content.toLowerCase())) {
  27244. keyModifiers.push(modifier);
  27245. } else {
  27246. nonKeyModifiers.push(modifier);
  27247. }
  27248. } else {
  27249. keyModifiers.push(modifier);
  27250. nonKeyModifiers.push(modifier);
  27251. }
  27252. } else {
  27253. if (isNonKeyModifier(modifier)) {
  27254. nonKeyModifiers.push(modifier);
  27255. } else {
  27256. keyModifiers.push(modifier);
  27257. }
  27258. }
  27259. }
  27260. }
  27261. return {
  27262. keyModifiers,
  27263. nonKeyModifiers,
  27264. eventOptionModifiers
  27265. };
  27266. };
  27267. const transformClick = (key, event) => {
  27268. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  27269. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  27270. `(`,
  27271. key,
  27272. `) === "onClick" ? "${event}" : (`,
  27273. key,
  27274. `)`
  27275. ]) : key;
  27276. };
  27277. const transformOn = (dir, node, context) => {
  27278. return transformOn$1(dir, node, context, (baseResult) => {
  27279. const { modifiers } = dir;
  27280. if (!modifiers.length) return baseResult;
  27281. let { key, value: handlerExp } = baseResult.props[0];
  27282. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  27283. if (nonKeyModifiers.includes("right")) {
  27284. key = transformClick(key, `onContextmenu`);
  27285. }
  27286. if (nonKeyModifiers.includes("middle")) {
  27287. key = transformClick(key, `onMouseup`);
  27288. }
  27289. if (nonKeyModifiers.length) {
  27290. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  27291. handlerExp,
  27292. JSON.stringify(nonKeyModifiers)
  27293. ]);
  27294. }
  27295. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  27296. (!isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
  27297. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  27298. handlerExp,
  27299. JSON.stringify(keyModifiers)
  27300. ]);
  27301. }
  27302. if (eventOptionModifiers.length) {
  27303. const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
  27304. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  27305. }
  27306. return {
  27307. props: [createObjectProperty(key, handlerExp)]
  27308. };
  27309. });
  27310. };
  27311. const transformShow = (dir, node, context) => {
  27312. const { exp, loc } = dir;
  27313. if (!exp) {
  27314. context.onError(
  27315. createDOMCompilerError(62, loc)
  27316. );
  27317. }
  27318. return {
  27319. props: [],
  27320. needRuntime: context.helper(V_SHOW)
  27321. };
  27322. };
  27323. const transformTransition = (node, context) => {
  27324. if (node.type === 1 && node.tagType === 1) {
  27325. const component = context.isBuiltInComponent(node.tag);
  27326. if (component === TRANSITION) {
  27327. return () => {
  27328. if (!node.children.length) {
  27329. return;
  27330. }
  27331. if (hasMultipleChildren(node)) {
  27332. context.onError(
  27333. createDOMCompilerError(
  27334. 63,
  27335. {
  27336. start: node.children[0].loc.start,
  27337. end: node.children[node.children.length - 1].loc.end,
  27338. source: ""
  27339. }
  27340. )
  27341. );
  27342. }
  27343. const child = node.children[0];
  27344. if (child.type === 1) {
  27345. for (const p of child.props) {
  27346. if (p.type === 7 && p.name === "show") {
  27347. node.props.push({
  27348. type: 6,
  27349. name: "persisted",
  27350. nameLoc: node.loc,
  27351. value: void 0,
  27352. loc: node.loc
  27353. });
  27354. }
  27355. }
  27356. }
  27357. };
  27358. }
  27359. }
  27360. };
  27361. function hasMultipleChildren(node) {
  27362. const children = node.children = node.children.filter(
  27363. (c) => !isCommentOrWhitespace(c)
  27364. );
  27365. const child = children[0];
  27366. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  27367. }
  27368. const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
  27369. const stringifyStatic = (children, context, parent) => {
  27370. if (context.scopes.vSlot > 0) {
  27371. return;
  27372. }
  27373. const isParentCached = parent.type === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray$3(parent.codegenNode.children) && parent.codegenNode.children.type === 20;
  27374. let nc = 0;
  27375. let ec = 0;
  27376. const currentChunk = [];
  27377. const stringifyCurrentChunk = (currentIndex) => {
  27378. if (nc >= 20 || ec >= 5) {
  27379. const staticCall = createCallExpression(context.helper(CREATE_STATIC), [
  27380. JSON.stringify(
  27381. currentChunk.map((node) => stringifyNode(node, context)).join("")
  27382. ).replace(expReplaceRE, `" + $1 + "`),
  27383. // the 2nd argument indicates the number of DOM nodes this static vnode
  27384. // will insert / hydrate
  27385. String(currentChunk.length)
  27386. ]);
  27387. const deleteCount = currentChunk.length - 1;
  27388. if (isParentCached) {
  27389. children.splice(
  27390. currentIndex - currentChunk.length,
  27391. currentChunk.length,
  27392. // @ts-expect-error
  27393. staticCall
  27394. );
  27395. } else {
  27396. currentChunk[0].codegenNode.value = staticCall;
  27397. if (currentChunk.length > 1) {
  27398. children.splice(currentIndex - currentChunk.length + 1, deleteCount);
  27399. const cacheIndex = context.cached.indexOf(
  27400. currentChunk[currentChunk.length - 1].codegenNode
  27401. );
  27402. if (cacheIndex > -1) {
  27403. for (let i2 = cacheIndex; i2 < context.cached.length; i2++) {
  27404. const c = context.cached[i2];
  27405. if (c) c.index -= deleteCount;
  27406. }
  27407. context.cached.splice(cacheIndex - deleteCount + 1, deleteCount);
  27408. }
  27409. }
  27410. }
  27411. return deleteCount;
  27412. }
  27413. return 0;
  27414. };
  27415. let i = 0;
  27416. for (; i < children.length; i++) {
  27417. const child = children[i];
  27418. const isCached = isParentCached || getCachedNode(child);
  27419. if (isCached) {
  27420. const result = analyzeNode(child);
  27421. if (result) {
  27422. nc += result[0];
  27423. ec += result[1];
  27424. currentChunk.push(child);
  27425. continue;
  27426. }
  27427. }
  27428. i -= stringifyCurrentChunk(i);
  27429. nc = 0;
  27430. ec = 0;
  27431. currentChunk.length = 0;
  27432. }
  27433. stringifyCurrentChunk(i);
  27434. };
  27435. const getCachedNode = (node) => {
  27436. if ((node.type === 1 && node.tagType === 0 || node.type === 12) && node.codegenNode && node.codegenNode.type === 20) {
  27437. return node.codegenNode;
  27438. }
  27439. };
  27440. const dataAriaRE = /^(?:data|aria)-/;
  27441. const isStringifiableAttr = (name, ns) => {
  27442. return (ns === 0 ? isKnownHtmlAttr(name) : ns === 1 ? isKnownSvgAttr(name) : ns === 2 ? isKnownMathMLAttr(name) : false) || dataAriaRE.test(name);
  27443. };
  27444. const isNonStringifiable = /* @__PURE__ */ makeMap(
  27445. `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
  27446. );
  27447. function analyzeNode(node) {
  27448. if (node.type === 1 && isNonStringifiable(node.tag)) {
  27449. return false;
  27450. }
  27451. if (node.type === 1 && findDir(node, "once", true)) {
  27452. return false;
  27453. }
  27454. if (node.type === 12) {
  27455. return [1, 0];
  27456. }
  27457. let nc = 1;
  27458. let ec = node.props.length > 0 ? 1 : 0;
  27459. let bailed = false;
  27460. const bail = () => {
  27461. bailed = true;
  27462. return false;
  27463. };
  27464. function walk(node2) {
  27465. const isOptionTag = node2.tag === "option" && node2.ns === 0;
  27466. for (let i = 0; i < node2.props.length; i++) {
  27467. const p = node2.props[i];
  27468. if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
  27469. return bail();
  27470. }
  27471. if (p.type === 7 && p.name === "bind") {
  27472. if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
  27473. return bail();
  27474. }
  27475. if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
  27476. return bail();
  27477. }
  27478. if (isOptionTag && isStaticArgOf(p.arg, "value") && p.exp && !p.exp.isStatic) {
  27479. return bail();
  27480. }
  27481. }
  27482. }
  27483. for (let i = 0; i < node2.children.length; i++) {
  27484. nc++;
  27485. const child = node2.children[i];
  27486. if (child.type === 1) {
  27487. if (child.props.length > 0) {
  27488. ec++;
  27489. }
  27490. walk(child);
  27491. if (bailed) {
  27492. return false;
  27493. }
  27494. }
  27495. }
  27496. return true;
  27497. }
  27498. return walk(node) ? [nc, ec] : false;
  27499. }
  27500. function stringifyNode(node, context) {
  27501. if (isString$1(node)) {
  27502. return node;
  27503. }
  27504. if (isSymbol$1(node)) {
  27505. return ``;
  27506. }
  27507. switch (node.type) {
  27508. case 1:
  27509. return stringifyElement(node, context);
  27510. case 2:
  27511. return escapeHtml(node.content);
  27512. case 3:
  27513. return `<!--${escapeHtml(node.content)}-->`;
  27514. case 5:
  27515. return escapeHtml(toDisplayString(evaluateConstant(node.content)));
  27516. case 8:
  27517. return escapeHtml(evaluateConstant(node));
  27518. case 12:
  27519. return stringifyNode(node.content, context);
  27520. default:
  27521. return "";
  27522. }
  27523. }
  27524. function stringifyElement(node, context) {
  27525. let res = `<${node.tag}`;
  27526. let innerHTML = "";
  27527. for (let i = 0; i < node.props.length; i++) {
  27528. const p = node.props[i];
  27529. if (p.type === 6) {
  27530. res += ` ${p.name}`;
  27531. if (p.value) {
  27532. res += `="${escapeHtml(p.value.content)}"`;
  27533. }
  27534. } else if (p.type === 7) {
  27535. if (p.name === "bind") {
  27536. const exp = p.exp;
  27537. if (exp.content[0] === "_") {
  27538. res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
  27539. continue;
  27540. }
  27541. if (isBooleanAttr(p.arg.content) && exp.content === "false") {
  27542. continue;
  27543. }
  27544. let evaluated = evaluateConstant(exp);
  27545. if (evaluated != null) {
  27546. const arg = p.arg && p.arg.content;
  27547. if (arg === "class") {
  27548. evaluated = normalizeClass(evaluated);
  27549. } else if (arg === "style") {
  27550. evaluated = stringifyStyle(normalizeStyle(evaluated));
  27551. }
  27552. res += ` ${p.arg.content}="${escapeHtml(
  27553. evaluated
  27554. )}"`;
  27555. }
  27556. } else if (p.name === "html") {
  27557. innerHTML = evaluateConstant(p.exp);
  27558. } else if (p.name === "text") {
  27559. innerHTML = escapeHtml(
  27560. toDisplayString(evaluateConstant(p.exp))
  27561. );
  27562. }
  27563. }
  27564. }
  27565. if (context.scopeId) {
  27566. res += ` ${context.scopeId}`;
  27567. }
  27568. res += `>`;
  27569. if (innerHTML) {
  27570. res += innerHTML;
  27571. } else {
  27572. for (let i = 0; i < node.children.length; i++) {
  27573. res += stringifyNode(node.children[i], context);
  27574. }
  27575. }
  27576. if (!isVoidTag(node.tag)) {
  27577. res += `</${node.tag}>`;
  27578. }
  27579. return res;
  27580. }
  27581. function evaluateConstant(exp) {
  27582. if (exp.type === 4) {
  27583. return new Function(`return (${exp.content})`)();
  27584. } else {
  27585. let res = ``;
  27586. exp.children.forEach((c) => {
  27587. if (isString$1(c) || isSymbol$1(c)) {
  27588. return;
  27589. }
  27590. if (c.type === 2) {
  27591. res += c.content;
  27592. } else if (c.type === 5) {
  27593. res += toDisplayString(evaluateConstant(c.content));
  27594. } else {
  27595. res += evaluateConstant(c);
  27596. }
  27597. });
  27598. return res;
  27599. }
  27600. }
  27601. const ignoreSideEffectTags = (node, context) => {
  27602. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  27603. context.onError(
  27604. createDOMCompilerError(
  27605. 64,
  27606. node.loc
  27607. )
  27608. );
  27609. context.removeNode();
  27610. }
  27611. };
  27612. function isValidHTMLNesting(parent, child) {
  27613. if (parent === "template") {
  27614. return true;
  27615. }
  27616. if (parent in onlyValidChildren) {
  27617. return onlyValidChildren[parent].has(child);
  27618. }
  27619. if (child in onlyValidParents) {
  27620. return onlyValidParents[child].has(parent);
  27621. }
  27622. if (parent in knownInvalidChildren) {
  27623. if (knownInvalidChildren[parent].has(child)) return false;
  27624. }
  27625. if (child in knownInvalidParents) {
  27626. if (knownInvalidParents[child].has(parent)) return false;
  27627. }
  27628. return true;
  27629. }
  27630. const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
  27631. const emptySet = /* @__PURE__ */ new Set([]);
  27632. const onlyValidChildren = {
  27633. head: /* @__PURE__ */ new Set([
  27634. "base",
  27635. "basefront",
  27636. "bgsound",
  27637. "link",
  27638. "meta",
  27639. "title",
  27640. "noscript",
  27641. "noframes",
  27642. "style",
  27643. "script",
  27644. "template"
  27645. ]),
  27646. optgroup: /* @__PURE__ */ new Set(["option"]),
  27647. select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
  27648. // table
  27649. table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
  27650. tr: /* @__PURE__ */ new Set(["td", "th"]),
  27651. colgroup: /* @__PURE__ */ new Set(["col"]),
  27652. tbody: /* @__PURE__ */ new Set(["tr"]),
  27653. thead: /* @__PURE__ */ new Set(["tr"]),
  27654. tfoot: /* @__PURE__ */ new Set(["tr"]),
  27655. // these elements can not have any children elements
  27656. script: emptySet,
  27657. iframe: emptySet,
  27658. option: emptySet,
  27659. textarea: emptySet,
  27660. style: emptySet,
  27661. title: emptySet
  27662. };
  27663. const onlyValidParents = {
  27664. // sections
  27665. html: emptySet,
  27666. body: /* @__PURE__ */ new Set(["html"]),
  27667. head: /* @__PURE__ */ new Set(["html"]),
  27668. // table
  27669. td: /* @__PURE__ */ new Set(["tr"]),
  27670. colgroup: /* @__PURE__ */ new Set(["table"]),
  27671. caption: /* @__PURE__ */ new Set(["table"]),
  27672. tbody: /* @__PURE__ */ new Set(["table"]),
  27673. tfoot: /* @__PURE__ */ new Set(["table"]),
  27674. col: /* @__PURE__ */ new Set(["colgroup"]),
  27675. th: /* @__PURE__ */ new Set(["tr"]),
  27676. thead: /* @__PURE__ */ new Set(["table"]),
  27677. tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
  27678. // data list
  27679. dd: /* @__PURE__ */ new Set(["dl", "div"]),
  27680. dt: /* @__PURE__ */ new Set(["dl", "div"]),
  27681. // other
  27682. figcaption: /* @__PURE__ */ new Set(["figure"]),
  27683. // li: new Set(["ul", "ol"]),
  27684. summary: /* @__PURE__ */ new Set(["details"]),
  27685. area: /* @__PURE__ */ new Set(["map"])
  27686. };
  27687. const knownInvalidChildren = {
  27688. p: /* @__PURE__ */ new Set([
  27689. "address",
  27690. "article",
  27691. "aside",
  27692. "blockquote",
  27693. "center",
  27694. "details",
  27695. "dialog",
  27696. "dir",
  27697. "div",
  27698. "dl",
  27699. "fieldset",
  27700. "figure",
  27701. "footer",
  27702. "form",
  27703. "h1",
  27704. "h2",
  27705. "h3",
  27706. "h4",
  27707. "h5",
  27708. "h6",
  27709. "header",
  27710. "hgroup",
  27711. "hr",
  27712. "li",
  27713. "main",
  27714. "nav",
  27715. "menu",
  27716. "ol",
  27717. "p",
  27718. "pre",
  27719. "section",
  27720. "table",
  27721. "ul"
  27722. ]),
  27723. svg: /* @__PURE__ */ new Set([
  27724. "b",
  27725. "blockquote",
  27726. "br",
  27727. "code",
  27728. "dd",
  27729. "div",
  27730. "dl",
  27731. "dt",
  27732. "em",
  27733. "embed",
  27734. "h1",
  27735. "h2",
  27736. "h3",
  27737. "h4",
  27738. "h5",
  27739. "h6",
  27740. "hr",
  27741. "i",
  27742. "img",
  27743. "li",
  27744. "menu",
  27745. "meta",
  27746. "ol",
  27747. "p",
  27748. "pre",
  27749. "ruby",
  27750. "s",
  27751. "small",
  27752. "span",
  27753. "strong",
  27754. "sub",
  27755. "sup",
  27756. "table",
  27757. "u",
  27758. "ul",
  27759. "var"
  27760. ])
  27761. };
  27762. const knownInvalidParents = {
  27763. a: /* @__PURE__ */ new Set(["a"]),
  27764. button: /* @__PURE__ */ new Set(["button"]),
  27765. dd: /* @__PURE__ */ new Set(["dd", "dt"]),
  27766. dt: /* @__PURE__ */ new Set(["dd", "dt"]),
  27767. form: /* @__PURE__ */ new Set(["form"]),
  27768. li: /* @__PURE__ */ new Set(["li"]),
  27769. h1: headings,
  27770. h2: headings,
  27771. h3: headings,
  27772. h4: headings,
  27773. h5: headings,
  27774. h6: headings
  27775. };
  27776. const validateHtmlNesting = (node, context) => {
  27777. if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
  27778. const error = new SyntaxError(
  27779. `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
  27780. );
  27781. error.loc = node.loc;
  27782. context.onWarn(error);
  27783. }
  27784. };
  27785. const DOMNodeTransforms = [
  27786. transformStyle,
  27787. ...[transformTransition, validateHtmlNesting]
  27788. ];
  27789. const DOMDirectiveTransforms = {
  27790. cloak: noopDirectiveTransform,
  27791. html: transformVHtml,
  27792. text: transformVText,
  27793. model: transformModel,
  27794. // override compiler-core
  27795. on: transformOn,
  27796. // override compiler-core
  27797. show: transformShow
  27798. };
  27799. function compile$1(src, options = {}) {
  27800. return baseCompile(
  27801. src,
  27802. extend({}, parserOptions, options, {
  27803. nodeTransforms: [
  27804. // ignore <script> and <tag>
  27805. // this is not put inside DOMNodeTransforms because that list is used
  27806. // by compiler-ssr to generate vnode fallback branches
  27807. ignoreSideEffectTags,
  27808. ...DOMNodeTransforms,
  27809. ...options.nodeTransforms || []
  27810. ],
  27811. directiveTransforms: extend(
  27812. {},
  27813. DOMDirectiveTransforms,
  27814. options.directiveTransforms || {}
  27815. ),
  27816. transformHoist: stringifyStatic
  27817. })
  27818. );
  27819. }
  27820. function parse$3(template, options = {}) {
  27821. return baseParse(template, extend({}, parserOptions, options));
  27822. }
  27823. var CompilerDOM = /*#__PURE__*/Object.freeze({
  27824. __proto__: null,
  27825. BASE_TRANSITION: BASE_TRANSITION,
  27826. BindingTypes: BindingTypes,
  27827. CAMELIZE: CAMELIZE,
  27828. CAPITALIZE: CAPITALIZE,
  27829. CREATE_BLOCK: CREATE_BLOCK,
  27830. CREATE_COMMENT: CREATE_COMMENT,
  27831. CREATE_ELEMENT_BLOCK: CREATE_ELEMENT_BLOCK,
  27832. CREATE_ELEMENT_VNODE: CREATE_ELEMENT_VNODE,
  27833. CREATE_SLOTS: CREATE_SLOTS,
  27834. CREATE_STATIC: CREATE_STATIC,
  27835. CREATE_TEXT: CREATE_TEXT,
  27836. CREATE_VNODE: CREATE_VNODE,
  27837. CompilerDeprecationTypes: CompilerDeprecationTypes,
  27838. ConstantTypes: ConstantTypes,
  27839. DOMDirectiveTransforms: DOMDirectiveTransforms,
  27840. DOMErrorCodes: DOMErrorCodes,
  27841. DOMErrorMessages: DOMErrorMessages,
  27842. DOMNodeTransforms: DOMNodeTransforms,
  27843. ElementTypes: ElementTypes,
  27844. ErrorCodes: ErrorCodes,
  27845. FRAGMENT: FRAGMENT,
  27846. GUARD_REACTIVE_PROPS: GUARD_REACTIVE_PROPS,
  27847. IS_MEMO_SAME: IS_MEMO_SAME,
  27848. IS_REF: IS_REF,
  27849. KEEP_ALIVE: KEEP_ALIVE,
  27850. MERGE_PROPS: MERGE_PROPS,
  27851. NORMALIZE_CLASS: NORMALIZE_CLASS,
  27852. NORMALIZE_PROPS: NORMALIZE_PROPS,
  27853. NORMALIZE_STYLE: NORMALIZE_STYLE,
  27854. Namespaces: Namespaces,
  27855. NodeTypes: NodeTypes,
  27856. OPEN_BLOCK: OPEN_BLOCK,
  27857. POP_SCOPE_ID: POP_SCOPE_ID,
  27858. PUSH_SCOPE_ID: PUSH_SCOPE_ID,
  27859. RENDER_LIST: RENDER_LIST,
  27860. RENDER_SLOT: RENDER_SLOT,
  27861. RESOLVE_COMPONENT: RESOLVE_COMPONENT,
  27862. RESOLVE_DIRECTIVE: RESOLVE_DIRECTIVE,
  27863. RESOLVE_DYNAMIC_COMPONENT: RESOLVE_DYNAMIC_COMPONENT,
  27864. RESOLVE_FILTER: RESOLVE_FILTER,
  27865. SET_BLOCK_TRACKING: SET_BLOCK_TRACKING,
  27866. SUSPENSE: SUSPENSE,
  27867. TELEPORT: TELEPORT,
  27868. TO_DISPLAY_STRING: TO_DISPLAY_STRING,
  27869. TO_HANDLERS: TO_HANDLERS,
  27870. TO_HANDLER_KEY: TO_HANDLER_KEY,
  27871. TRANSITION: TRANSITION,
  27872. TRANSITION_GROUP: TRANSITION_GROUP,
  27873. TS_NODE_TYPES: TS_NODE_TYPES,
  27874. UNREF: UNREF,
  27875. V_MODEL_CHECKBOX: V_MODEL_CHECKBOX,
  27876. V_MODEL_DYNAMIC: V_MODEL_DYNAMIC,
  27877. V_MODEL_RADIO: V_MODEL_RADIO,
  27878. V_MODEL_SELECT: V_MODEL_SELECT,
  27879. V_MODEL_TEXT: V_MODEL_TEXT,
  27880. V_ON_WITH_KEYS: V_ON_WITH_KEYS,
  27881. V_ON_WITH_MODIFIERS: V_ON_WITH_MODIFIERS,
  27882. V_SHOW: V_SHOW,
  27883. WITH_CTX: WITH_CTX,
  27884. WITH_DIRECTIVES: WITH_DIRECTIVES,
  27885. WITH_MEMO: WITH_MEMO,
  27886. advancePositionWithClone: advancePositionWithClone,
  27887. advancePositionWithMutation: advancePositionWithMutation,
  27888. assert: assert,
  27889. baseCompile: baseCompile,
  27890. baseParse: baseParse,
  27891. buildDirectiveArgs: buildDirectiveArgs,
  27892. buildProps: buildProps,
  27893. buildSlots: buildSlots,
  27894. checkCompatEnabled: checkCompatEnabled,
  27895. compile: compile$1,
  27896. convertToBlock: convertToBlock,
  27897. createArrayExpression: createArrayExpression,
  27898. createAssignmentExpression: createAssignmentExpression,
  27899. createBlockStatement: createBlockStatement,
  27900. createCacheExpression: createCacheExpression,
  27901. createCallExpression: createCallExpression,
  27902. createCompilerError: createCompilerError,
  27903. createCompoundExpression: createCompoundExpression,
  27904. createConditionalExpression: createConditionalExpression,
  27905. createDOMCompilerError: createDOMCompilerError,
  27906. createForLoopParams: createForLoopParams,
  27907. createFunctionExpression: createFunctionExpression,
  27908. createIfStatement: createIfStatement,
  27909. createInterpolation: createInterpolation,
  27910. createObjectExpression: createObjectExpression,
  27911. createObjectProperty: createObjectProperty,
  27912. createReturnStatement: createReturnStatement,
  27913. createRoot: createRoot,
  27914. createSequenceExpression: createSequenceExpression,
  27915. createSimpleExpression: createSimpleExpression,
  27916. createStructuralDirectiveTransform: createStructuralDirectiveTransform,
  27917. createTemplateLiteral: createTemplateLiteral,
  27918. createTransformContext: createTransformContext,
  27919. createVNodeCall: createVNodeCall,
  27920. errorMessages: errorMessages$1,
  27921. extractIdentifiers: extractIdentifiers$1,
  27922. findDir: findDir,
  27923. findProp: findProp,
  27924. forAliasRE: forAliasRE,
  27925. generate: generate,
  27926. generateCodeFrame: generateCodeFrame,
  27927. getBaseTransformPreset: getBaseTransformPreset,
  27928. getConstantType: getConstantType,
  27929. getMemoedVNodeCall: getMemoedVNodeCall,
  27930. getVNodeBlockHelper: getVNodeBlockHelper,
  27931. getVNodeHelper: getVNodeHelper,
  27932. hasDynamicKeyVBind: hasDynamicKeyVBind,
  27933. hasScopeRef: hasScopeRef,
  27934. helperNameMap: helperNameMap,
  27935. injectProp: injectProp,
  27936. isAllWhitespace: isAllWhitespace,
  27937. isCommentOrWhitespace: isCommentOrWhitespace,
  27938. isCoreComponent: isCoreComponent,
  27939. isFnExpression: isFnExpression,
  27940. isFnExpressionBrowser: isFnExpressionBrowser,
  27941. isFnExpressionNode: isFnExpressionNode,
  27942. isFunctionType: isFunctionType,
  27943. isInDestructureAssignment: isInDestructureAssignment,
  27944. isInNewExpression: isInNewExpression,
  27945. isMemberExpression: isMemberExpression,
  27946. isMemberExpressionBrowser: isMemberExpressionBrowser,
  27947. isMemberExpressionNode: isMemberExpressionNode,
  27948. isReferencedIdentifier: isReferencedIdentifier,
  27949. isSimpleIdentifier: isSimpleIdentifier,
  27950. isSlotOutlet: isSlotOutlet,
  27951. isStaticArgOf: isStaticArgOf,
  27952. isStaticExp: isStaticExp,
  27953. isStaticProperty: isStaticProperty,
  27954. isStaticPropertyKey: isStaticPropertyKey,
  27955. isTemplateNode: isTemplateNode,
  27956. isText: isText$1,
  27957. isVPre: isVPre,
  27958. isVSlot: isVSlot,
  27959. isWhitespaceText: isWhitespaceText,
  27960. locStub: locStub,
  27961. noopDirectiveTransform: noopDirectiveTransform,
  27962. parse: parse$3,
  27963. parserOptions: parserOptions,
  27964. processExpression: processExpression,
  27965. processFor: processFor,
  27966. processIf: processIf,
  27967. processSlotOutlet: processSlotOutlet,
  27968. registerRuntimeHelpers: registerRuntimeHelpers,
  27969. resolveComponentType: resolveComponentType,
  27970. stringifyExpression: stringifyExpression,
  27971. toValidAssetId: toValidAssetId,
  27972. trackSlotScopes: trackSlotScopes,
  27973. trackVForSlotScopes: trackVForSlotScopes,
  27974. transform: transform,
  27975. transformBind: transformBind,
  27976. transformElement: transformElement,
  27977. transformExpression: transformExpression,
  27978. transformModel: transformModel$1,
  27979. transformOn: transformOn$1,
  27980. transformStyle: transformStyle,
  27981. transformVBindShorthand: transformVBindShorthand,
  27982. traverseNode: traverseNode,
  27983. unwrapTSNode: unwrapTSNode,
  27984. validFirstIdentCharRE: validFirstIdentCharRE,
  27985. walkBlockDeclarations: walkBlockDeclarations,
  27986. walkFunctionParams: walkFunctionParams,
  27987. walkIdentifiers: walkIdentifiers,
  27988. warnDeprecation: warnDeprecation
  27989. });
  27990. var hashSum;
  27991. var hasRequiredHashSum;
  27992. function requireHashSum () {
  27993. if (hasRequiredHashSum) return hashSum;
  27994. hasRequiredHashSum = 1;
  27995. function pad (hash, len) {
  27996. while (hash.length < len) {
  27997. hash = '0' + hash;
  27998. }
  27999. return hash;
  28000. }
  28001. function fold (hash, text) {
  28002. var i;
  28003. var chr;
  28004. var len;
  28005. if (text.length === 0) {
  28006. return hash;
  28007. }
  28008. for (i = 0, len = text.length; i < len; i++) {
  28009. chr = text.charCodeAt(i);
  28010. hash = ((hash << 5) - hash) + chr;
  28011. hash |= 0;
  28012. }
  28013. return hash < 0 ? hash * -2 : hash;
  28014. }
  28015. function foldObject (hash, o, seen) {
  28016. return Object.keys(o).sort().reduce(foldKey, hash);
  28017. function foldKey (hash, key) {
  28018. return foldValue(hash, o[key], key, seen);
  28019. }
  28020. }
  28021. function foldValue (input, value, key, seen) {
  28022. var hash = fold(fold(fold(input, key), toString(value)), typeof value);
  28023. if (value === null) {
  28024. return fold(hash, 'null');
  28025. }
  28026. if (value === undefined) {
  28027. return fold(hash, 'undefined');
  28028. }
  28029. if (typeof value === 'object' || typeof value === 'function') {
  28030. if (seen.indexOf(value) !== -1) {
  28031. return fold(hash, '[Circular]' + key);
  28032. }
  28033. seen.push(value);
  28034. var objHash = foldObject(hash, value, seen);
  28035. if (!('valueOf' in value) || typeof value.valueOf !== 'function') {
  28036. return objHash;
  28037. }
  28038. try {
  28039. return fold(objHash, String(value.valueOf()))
  28040. } catch (err) {
  28041. return fold(objHash, '[valueOf exception]' + (err.stack || err.message))
  28042. }
  28043. }
  28044. return fold(hash, value.toString());
  28045. }
  28046. function toString (o) {
  28047. return Object.prototype.toString.call(o);
  28048. }
  28049. function sum (o) {
  28050. return pad(foldValue(0, o, '', []).toString(16), 8);
  28051. }
  28052. hashSum = sum;
  28053. return hashSum;
  28054. }
  28055. var hashSumExports = /*@__PURE__*/ requireHashSum();
  28056. var hash = /*@__PURE__*/getDefaultExportFromCjs(hashSumExports);
  28057. const CSS_VARS_HELPER = `useCssVars`;
  28058. function genCssVarsFromList(vars, id, isProd, isSSR = false) {
  28059. return `{
  28060. ${vars.map(
  28061. (key) => (
  28062. // The `:` prefix here is used in `ssrRenderStyle` to distinguish whether
  28063. // a custom property comes from `ssrCssVars`. If it does, we need to reset
  28064. // its value to `initial` on the component instance to avoid unintentionally
  28065. // inheriting the same property value from a different instance of the same
  28066. // component in the outer scope.
  28067. `"${isSSR ? `:--` : ``}${genVarName(id, key, isProd, isSSR)}": (${key})`
  28068. )
  28069. ).join(",\n ")}
  28070. }`;
  28071. }
  28072. function genVarName(id, raw, isProd, isSSR = false) {
  28073. if (isProd) {
  28074. return hash(id + raw).replace(/^\d/, (r) => `v${r}`);
  28075. } else {
  28076. return `${id}-${getEscapedCssVarName(raw, isSSR)}`;
  28077. }
  28078. }
  28079. function normalizeExpression(exp) {
  28080. exp = exp.trim();
  28081. if (exp[0] === `'` && exp[exp.length - 1] === `'` || exp[0] === `"` && exp[exp.length - 1] === `"`) {
  28082. return exp.slice(1, -1);
  28083. }
  28084. return exp;
  28085. }
  28086. const vBindRE = /v-bind\s*\(/g;
  28087. function parseCssVars(sfc) {
  28088. const vars = [];
  28089. sfc.styles.forEach((style) => {
  28090. let match;
  28091. const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
  28092. while (match = vBindRE.exec(content)) {
  28093. const start = match.index + match[0].length;
  28094. const end = lexBinding(content, start);
  28095. if (end !== null) {
  28096. const variable = normalizeExpression(content.slice(start, end));
  28097. if (!vars.includes(variable)) {
  28098. vars.push(variable);
  28099. }
  28100. }
  28101. }
  28102. });
  28103. return vars;
  28104. }
  28105. function lexBinding(content, start) {
  28106. let state = 0 /* inParens */;
  28107. let parenDepth = 0;
  28108. for (let i = start; i < content.length; i++) {
  28109. const char = content.charAt(i);
  28110. switch (state) {
  28111. case 0 /* inParens */:
  28112. if (char === `'`) {
  28113. state = 1 /* inSingleQuoteString */;
  28114. } else if (char === `"`) {
  28115. state = 2 /* inDoubleQuoteString */;
  28116. } else if (char === `(`) {
  28117. parenDepth++;
  28118. } else if (char === `)`) {
  28119. if (parenDepth > 0) {
  28120. parenDepth--;
  28121. } else {
  28122. return i;
  28123. }
  28124. }
  28125. break;
  28126. case 1 /* inSingleQuoteString */:
  28127. if (char === `'`) {
  28128. state = 0 /* inParens */;
  28129. }
  28130. break;
  28131. case 2 /* inDoubleQuoteString */:
  28132. if (char === `"`) {
  28133. state = 0 /* inParens */;
  28134. }
  28135. break;
  28136. }
  28137. }
  28138. return null;
  28139. }
  28140. const cssVarsPlugin = (opts) => {
  28141. const { id, isProd } = opts;
  28142. return {
  28143. postcssPlugin: "vue-sfc-vars",
  28144. Declaration(decl) {
  28145. const value = decl.value;
  28146. if (vBindRE.test(value)) {
  28147. vBindRE.lastIndex = 0;
  28148. let transformed = "";
  28149. let lastIndex = 0;
  28150. let match;
  28151. while (match = vBindRE.exec(value)) {
  28152. const start = match.index + match[0].length;
  28153. const end = lexBinding(value, start);
  28154. if (end !== null) {
  28155. const variable = normalizeExpression(value.slice(start, end));
  28156. transformed += value.slice(lastIndex, match.index) + `var(--${genVarName(id, variable, isProd)})`;
  28157. lastIndex = end + 1;
  28158. }
  28159. }
  28160. decl.value = transformed + value.slice(lastIndex);
  28161. }
  28162. }
  28163. };
  28164. };
  28165. cssVarsPlugin.postcss = true;
  28166. function genCssVarsCode(vars, bindings, id, isProd) {
  28167. const varsExp = genCssVarsFromList(vars, id, isProd);
  28168. const exp = createSimpleExpression(varsExp, false);
  28169. const context = createTransformContext(createRoot([]), {
  28170. prefixIdentifiers: true,
  28171. inline: true,
  28172. bindingMetadata: bindings.__isScriptSetup === false ? void 0 : bindings
  28173. });
  28174. const transformed = processExpression(exp, context);
  28175. const transformedString = transformed.type === 4 ? transformed.content : transformed.children.map((c) => {
  28176. return typeof c === "string" ? c : c.content;
  28177. }).join("");
  28178. return `_${CSS_VARS_HELPER}(_ctx => (${transformedString}))`;
  28179. }
  28180. function genNormalScriptCssVarsCode(cssVars, bindings, id, isProd, defaultVar) {
  28181. return `
  28182. import { ${CSS_VARS_HELPER} as _${CSS_VARS_HELPER} } from 'vue'
  28183. const __injectCSSVars__ = () => {
  28184. ${genCssVarsCode(
  28185. cssVars,
  28186. bindings,
  28187. id,
  28188. isProd
  28189. )}}
  28190. const __setup__ = ${defaultVar}.setup
  28191. ${defaultVar}.setup = __setup__
  28192. ? (props, ctx) => { __injectCSSVars__();return __setup__(props, ctx) }
  28193. : __injectCSSVars__
  28194. `;
  28195. }
  28196. // shim for using process in browser
  28197. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  28198. function defaultSetTimout() {
  28199. throw new Error('setTimeout has not been defined');
  28200. }
  28201. function defaultClearTimeout () {
  28202. throw new Error('clearTimeout has not been defined');
  28203. }
  28204. var cachedSetTimeout = defaultSetTimout;
  28205. var cachedClearTimeout = defaultClearTimeout;
  28206. if (typeof global$1.setTimeout === 'function') {
  28207. cachedSetTimeout = setTimeout;
  28208. }
  28209. if (typeof global$1.clearTimeout === 'function') {
  28210. cachedClearTimeout = clearTimeout;
  28211. }
  28212. function runTimeout(fun) {
  28213. if (cachedSetTimeout === setTimeout) {
  28214. //normal enviroments in sane situations
  28215. return setTimeout(fun, 0);
  28216. }
  28217. // if setTimeout wasn't available but was latter defined
  28218. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  28219. cachedSetTimeout = setTimeout;
  28220. return setTimeout(fun, 0);
  28221. }
  28222. try {
  28223. // when when somebody has screwed with setTimeout but no I.E. maddness
  28224. return cachedSetTimeout(fun, 0);
  28225. } catch(e){
  28226. try {
  28227. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  28228. return cachedSetTimeout.call(null, fun, 0);
  28229. } catch(e){
  28230. // 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
  28231. return cachedSetTimeout.call(this, fun, 0);
  28232. }
  28233. }
  28234. }
  28235. function runClearTimeout(marker) {
  28236. if (cachedClearTimeout === clearTimeout) {
  28237. //normal enviroments in sane situations
  28238. return clearTimeout(marker);
  28239. }
  28240. // if clearTimeout wasn't available but was latter defined
  28241. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  28242. cachedClearTimeout = clearTimeout;
  28243. return clearTimeout(marker);
  28244. }
  28245. try {
  28246. // when when somebody has screwed with setTimeout but no I.E. maddness
  28247. return cachedClearTimeout(marker);
  28248. } catch (e){
  28249. try {
  28250. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  28251. return cachedClearTimeout.call(null, marker);
  28252. } catch (e){
  28253. // 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.
  28254. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  28255. return cachedClearTimeout.call(this, marker);
  28256. }
  28257. }
  28258. }
  28259. var queue = [];
  28260. var draining = false;
  28261. var currentQueue;
  28262. var queueIndex = -1;
  28263. function cleanUpNextTick() {
  28264. if (!draining || !currentQueue) {
  28265. return;
  28266. }
  28267. draining = false;
  28268. if (currentQueue.length) {
  28269. queue = currentQueue.concat(queue);
  28270. } else {
  28271. queueIndex = -1;
  28272. }
  28273. if (queue.length) {
  28274. drainQueue();
  28275. }
  28276. }
  28277. function drainQueue() {
  28278. if (draining) {
  28279. return;
  28280. }
  28281. var timeout = runTimeout(cleanUpNextTick);
  28282. draining = true;
  28283. var len = queue.length;
  28284. while(len) {
  28285. currentQueue = queue;
  28286. queue = [];
  28287. while (++queueIndex < len) {
  28288. if (currentQueue) {
  28289. currentQueue[queueIndex].run();
  28290. }
  28291. }
  28292. queueIndex = -1;
  28293. len = queue.length;
  28294. }
  28295. currentQueue = null;
  28296. draining = false;
  28297. runClearTimeout(timeout);
  28298. }
  28299. function nextTick(fun) {
  28300. var args = new Array(arguments.length - 1);
  28301. if (arguments.length > 1) {
  28302. for (var i = 1; i < arguments.length; i++) {
  28303. args[i - 1] = arguments[i];
  28304. }
  28305. }
  28306. queue.push(new Item(fun, args));
  28307. if (queue.length === 1 && !draining) {
  28308. runTimeout(drainQueue);
  28309. }
  28310. }
  28311. // v8 likes predictible objects
  28312. function Item(fun, array) {
  28313. this.fun = fun;
  28314. this.array = array;
  28315. }
  28316. Item.prototype.run = function () {
  28317. this.fun.apply(null, this.array);
  28318. };
  28319. var title = 'browser';
  28320. var platform = 'browser';
  28321. var browser = true;
  28322. var env = {};
  28323. var argv = [];
  28324. var version$1 = ''; // empty string to avoid regexp issues
  28325. var versions = {};
  28326. var release = {};
  28327. var config = {};
  28328. function noop() {}
  28329. var on = noop;
  28330. var addListener = noop;
  28331. var once = noop;
  28332. var off = noop;
  28333. var removeListener = noop;
  28334. var removeAllListeners = noop;
  28335. var emit = noop;
  28336. function binding(name) {
  28337. throw new Error('process.binding is not supported');
  28338. }
  28339. function cwd () { return '/' }
  28340. function chdir (dir) {
  28341. throw new Error('process.chdir is not supported');
  28342. }function umask() { return 0; }
  28343. // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  28344. var performance = global$1.performance || {};
  28345. var performanceNow =
  28346. performance.now ||
  28347. performance.mozNow ||
  28348. performance.msNow ||
  28349. performance.oNow ||
  28350. performance.webkitNow ||
  28351. function(){ return (new Date()).getTime() };
  28352. // generate timestamp or delta
  28353. // see http://nodejs.org/api/process.html#process_process_hrtime
  28354. function hrtime(previousTimestamp){
  28355. var clocktime = performanceNow.call(performance)*1e-3;
  28356. var seconds = Math.floor(clocktime);
  28357. var nanoseconds = Math.floor((clocktime%1)*1e9);
  28358. if (previousTimestamp) {
  28359. seconds = seconds - previousTimestamp[0];
  28360. nanoseconds = nanoseconds - previousTimestamp[1];
  28361. if (nanoseconds<0) {
  28362. seconds--;
  28363. nanoseconds += 1e9;
  28364. }
  28365. }
  28366. return [seconds,nanoseconds]
  28367. }
  28368. var startTime = new Date();
  28369. function uptime() {
  28370. var currentTime = new Date();
  28371. var dif = currentTime - startTime;
  28372. return dif / 1000;
  28373. }
  28374. var browser$1 = {
  28375. nextTick: nextTick,
  28376. title: title,
  28377. browser: browser,
  28378. env: env,
  28379. argv: argv,
  28380. version: version$1,
  28381. versions: versions,
  28382. on: on,
  28383. addListener: addListener,
  28384. once: once,
  28385. off: off,
  28386. removeListener: removeListener,
  28387. removeAllListeners: removeAllListeners,
  28388. emit: emit,
  28389. binding: binding,
  28390. cwd: cwd,
  28391. chdir: chdir,
  28392. umask: umask,
  28393. hrtime: hrtime,
  28394. platform: platform,
  28395. release: release,
  28396. config: config,
  28397. uptime: uptime
  28398. };
  28399. function createCache(max = 500) {
  28400. {
  28401. return /* @__PURE__ */ new Map();
  28402. }
  28403. }
  28404. function isImportUsed(local, sfc) {
  28405. return resolveTemplateUsedIdentifiers(sfc).has(local);
  28406. }
  28407. const templateAnalysisCache = createCache();
  28408. function resolveTemplateVModelIdentifiers(sfc) {
  28409. return resolveTemplateAnalysisResult(sfc, false).vModelIds;
  28410. }
  28411. function resolveTemplateUsedIdentifiers(sfc) {
  28412. return resolveTemplateAnalysisResult(sfc).usedIds;
  28413. }
  28414. function resolveTemplateAnalysisResult(sfc, collectUsedIds = true) {
  28415. const { content, ast } = sfc.template;
  28416. const cached = templateAnalysisCache.get(content);
  28417. if (cached && (!collectUsedIds || cached.usedIds)) {
  28418. return cached;
  28419. }
  28420. const ids = collectUsedIds ? /* @__PURE__ */ new Set() : void 0;
  28421. const vModelIds = /* @__PURE__ */ new Set();
  28422. ast.children.forEach(walk);
  28423. function walk(node) {
  28424. var _a;
  28425. switch (node.type) {
  28426. case 1:
  28427. let tag = node.tag;
  28428. if (tag.includes(".")) tag = tag.split(".")[0].trim();
  28429. if (!parserOptions.isNativeTag(tag) && !parserOptions.isBuiltInComponent(tag)) {
  28430. if (ids) {
  28431. ids.add(camelize(tag));
  28432. ids.add(capitalize(camelize(tag)));
  28433. }
  28434. }
  28435. for (let i = 0; i < node.props.length; i++) {
  28436. const prop = node.props[i];
  28437. if (prop.type === 7) {
  28438. if (ids) {
  28439. if (!isBuiltInDirective(prop.name)) {
  28440. ids.add(`v${capitalize(camelize(prop.name))}`);
  28441. }
  28442. }
  28443. if (prop.name === "model") {
  28444. const exp = prop.exp;
  28445. if (exp && exp.type === 4) {
  28446. const expString = exp.content.trim();
  28447. if (isSimpleIdentifier(expString) && expString !== "undefined") {
  28448. vModelIds.add(expString);
  28449. }
  28450. }
  28451. }
  28452. if (ids && prop.arg && !prop.arg.isStatic) {
  28453. extractIdentifiers(ids, prop.arg);
  28454. }
  28455. if (ids) {
  28456. if (prop.name === "for") {
  28457. extractIdentifiers(ids, prop.forParseResult.source);
  28458. } else if (prop.exp) {
  28459. extractIdentifiers(ids, prop.exp);
  28460. } else if (prop.name === "bind" && !prop.exp) {
  28461. ids.add(camelize(prop.arg.content));
  28462. }
  28463. }
  28464. }
  28465. if (ids && prop.type === 6 && prop.name === "ref" && ((_a = prop.value) == null ? void 0 : _a.content)) {
  28466. ids.add(prop.value.content);
  28467. }
  28468. }
  28469. node.children.forEach(walk);
  28470. break;
  28471. case 5:
  28472. if (ids) extractIdentifiers(ids, node.content);
  28473. break;
  28474. }
  28475. }
  28476. const result = { usedIds: ids, vModelIds };
  28477. templateAnalysisCache.set(content, result);
  28478. return result;
  28479. }
  28480. function extractIdentifiers(ids, node) {
  28481. if (node.ast) {
  28482. walkIdentifiers(node.ast, (n) => ids.add(n.name));
  28483. } else if (node.ast === null) {
  28484. ids.add(node.content);
  28485. }
  28486. }
  28487. var __defProp$a = Object.defineProperty;
  28488. var __defProps$9 = Object.defineProperties;
  28489. var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
  28490. var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
  28491. var __hasOwnProp$a = Object.prototype.hasOwnProperty;
  28492. var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
  28493. var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  28494. var __spreadValues$a = (a, b) => {
  28495. for (var prop in b || (b = {}))
  28496. if (__hasOwnProp$a.call(b, prop))
  28497. __defNormalProp$a(a, prop, b[prop]);
  28498. if (__getOwnPropSymbols$a)
  28499. for (var prop of __getOwnPropSymbols$a(b)) {
  28500. if (__propIsEnum$a.call(b, prop))
  28501. __defNormalProp$a(a, prop, b[prop]);
  28502. }
  28503. return a;
  28504. };
  28505. var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
  28506. const DEFAULT_FILENAME = "anonymous.vue";
  28507. const parseCache$1 = createCache();
  28508. function parse$2(source, options = {}) {
  28509. var _a;
  28510. const sourceKey = genCacheKey(source, __spreadProps$9(__spreadValues$a({}, options), {
  28511. compiler: { parse: (_a = options.compiler) == null ? void 0 : _a.parse }
  28512. }));
  28513. const cache = parseCache$1.get(sourceKey);
  28514. if (cache) {
  28515. return cache;
  28516. }
  28517. const {
  28518. sourceMap = true,
  28519. filename = DEFAULT_FILENAME,
  28520. sourceRoot = "",
  28521. pad = false,
  28522. ignoreEmpty = true,
  28523. compiler = CompilerDOM,
  28524. templateParseOptions = {}
  28525. } = options;
  28526. const descriptor = {
  28527. filename,
  28528. source,
  28529. template: null,
  28530. script: null,
  28531. scriptSetup: null,
  28532. styles: [],
  28533. customBlocks: [],
  28534. cssVars: [],
  28535. slotted: false,
  28536. shouldForceReload: (prevImports) => hmrShouldReload(prevImports, descriptor)
  28537. };
  28538. const errors = [];
  28539. const ast = compiler.parse(source, __spreadProps$9(__spreadValues$a({
  28540. parseMode: "sfc",
  28541. prefixIdentifiers: true
  28542. }, templateParseOptions), {
  28543. onError: (e) => {
  28544. errors.push(e);
  28545. }
  28546. }));
  28547. ast.children.forEach((node) => {
  28548. if (node.type !== 1) {
  28549. return;
  28550. }
  28551. if (ignoreEmpty && node.tag !== "template" && isEmpty(node) && !hasSrc(node)) {
  28552. return;
  28553. }
  28554. switch (node.tag) {
  28555. case "template":
  28556. if (!descriptor.template) {
  28557. const templateBlock = descriptor.template = createBlock(
  28558. node,
  28559. source,
  28560. false
  28561. );
  28562. if (!templateBlock.attrs.src) {
  28563. templateBlock.ast = createRoot(node.children, source);
  28564. }
  28565. if (templateBlock.attrs.functional) {
  28566. const err = new SyntaxError(
  28567. `<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.`
  28568. );
  28569. err.loc = node.props.find(
  28570. (p) => p.type === 6 && p.name === "functional"
  28571. ).loc;
  28572. errors.push(err);
  28573. }
  28574. } else {
  28575. errors.push(createDuplicateBlockError(node));
  28576. }
  28577. break;
  28578. case "script":
  28579. const scriptBlock = createBlock(node, source, pad);
  28580. const isSetup = !!scriptBlock.attrs.setup;
  28581. if (isSetup && !descriptor.scriptSetup) {
  28582. descriptor.scriptSetup = scriptBlock;
  28583. break;
  28584. }
  28585. if (!isSetup && !descriptor.script) {
  28586. descriptor.script = scriptBlock;
  28587. break;
  28588. }
  28589. errors.push(createDuplicateBlockError(node, isSetup));
  28590. break;
  28591. case "style":
  28592. const styleBlock = createBlock(node, source, pad);
  28593. if (styleBlock.attrs.vars) {
  28594. errors.push(
  28595. new SyntaxError(
  28596. `<style vars> has been replaced by a new proposal: https://github.com/vuejs/rfcs/pull/231`
  28597. )
  28598. );
  28599. }
  28600. descriptor.styles.push(styleBlock);
  28601. break;
  28602. default:
  28603. descriptor.customBlocks.push(createBlock(node, source, pad));
  28604. break;
  28605. }
  28606. });
  28607. if (!descriptor.template && !descriptor.script && !descriptor.scriptSetup) {
  28608. errors.push(
  28609. new SyntaxError(
  28610. `At least one <template> or <script> is required in a single file component. ${descriptor.filename}`
  28611. )
  28612. );
  28613. }
  28614. if (descriptor.scriptSetup) {
  28615. if (descriptor.scriptSetup.src) {
  28616. errors.push(
  28617. new SyntaxError(
  28618. `<script setup> cannot use the "src" attribute because its syntax will be ambiguous outside of the component.`
  28619. )
  28620. );
  28621. descriptor.scriptSetup = null;
  28622. }
  28623. if (descriptor.script && descriptor.script.src) {
  28624. errors.push(
  28625. new SyntaxError(
  28626. `<script> cannot use the "src" attribute when <script setup> is also present because they must be processed together.`
  28627. )
  28628. );
  28629. descriptor.script = null;
  28630. }
  28631. }
  28632. let templateColumnOffset = 0;
  28633. if (descriptor.template && (descriptor.template.lang === "pug" || descriptor.template.lang === "jade")) {
  28634. [descriptor.template.content, templateColumnOffset] = dedent(
  28635. descriptor.template.content
  28636. );
  28637. }
  28638. if (sourceMap) {
  28639. const genMap = (block, columnOffset = 0) => {
  28640. if (block && !block.src) {
  28641. block.map = generateSourceMap(
  28642. filename,
  28643. source,
  28644. block.content,
  28645. sourceRoot,
  28646. !pad || block.type === "template" ? block.loc.start.line - 1 : 0,
  28647. columnOffset
  28648. );
  28649. }
  28650. };
  28651. genMap(descriptor.template, templateColumnOffset);
  28652. genMap(descriptor.script);
  28653. descriptor.styles.forEach((s) => genMap(s));
  28654. descriptor.customBlocks.forEach((s) => genMap(s));
  28655. }
  28656. descriptor.cssVars = parseCssVars(descriptor);
  28657. const slottedRE = /(?:::v-|:)slotted\(/;
  28658. descriptor.slotted = descriptor.styles.some(
  28659. (s) => s.scoped && slottedRE.test(s.content)
  28660. );
  28661. const result = {
  28662. descriptor,
  28663. errors
  28664. };
  28665. parseCache$1.set(sourceKey, result);
  28666. return result;
  28667. }
  28668. function createDuplicateBlockError(node, isScriptSetup = false) {
  28669. const err = new SyntaxError(
  28670. `Single file component can contain only one <${node.tag}${isScriptSetup ? ` setup` : ``}> element`
  28671. );
  28672. err.loc = node.loc;
  28673. return err;
  28674. }
  28675. function createBlock(node, source, pad) {
  28676. const type = node.tag;
  28677. const loc = node.innerLoc;
  28678. const attrs = {};
  28679. const block = {
  28680. type,
  28681. content: source.slice(loc.start.offset, loc.end.offset),
  28682. loc,
  28683. attrs
  28684. };
  28685. if (pad) {
  28686. block.content = padContent(source, block, pad) + block.content;
  28687. }
  28688. node.props.forEach((p) => {
  28689. if (p.type === 6) {
  28690. const name = p.name;
  28691. attrs[name] = p.value ? p.value.content || true : true;
  28692. if (name === "lang") {
  28693. block.lang = p.value && p.value.content;
  28694. } else if (name === "src") {
  28695. block.src = p.value && p.value.content;
  28696. } else if (type === "style") {
  28697. if (name === "scoped") {
  28698. block.scoped = true;
  28699. } else if (name === "module") {
  28700. block.module = attrs[name];
  28701. }
  28702. } else if (type === "script" && name === "setup") {
  28703. block.setup = attrs.setup;
  28704. }
  28705. }
  28706. });
  28707. return block;
  28708. }
  28709. const splitRE = /\r?\n/g;
  28710. const emptyRE = /^(?:\/\/)?\s*$/;
  28711. const replaceRE = /./g;
  28712. function generateSourceMap(filename, source, generated, sourceRoot, lineOffset, columnOffset) {
  28713. const map = new sourceMapExports.SourceMapGenerator({
  28714. file: filename.replace(/\\/g, "/"),
  28715. sourceRoot: sourceRoot.replace(/\\/g, "/")
  28716. });
  28717. map.setSourceContent(filename, source);
  28718. map._sources.add(filename);
  28719. generated.split(splitRE).forEach((line, index) => {
  28720. if (!emptyRE.test(line)) {
  28721. const originalLine = index + 1 + lineOffset;
  28722. const generatedLine = index + 1;
  28723. for (let i = 0; i < line.length; i++) {
  28724. if (!/\s/.test(line[i])) {
  28725. map._mappings.add({
  28726. originalLine,
  28727. originalColumn: i + columnOffset,
  28728. generatedLine,
  28729. generatedColumn: i,
  28730. source: filename,
  28731. name: null
  28732. });
  28733. }
  28734. }
  28735. }
  28736. });
  28737. return map.toJSON();
  28738. }
  28739. function padContent(content, block, pad) {
  28740. content = content.slice(0, block.loc.start.offset);
  28741. if (pad === "space") {
  28742. return content.replace(replaceRE, " ");
  28743. } else {
  28744. const offset = content.split(splitRE).length;
  28745. const padChar = block.type === "script" && !block.lang ? "//\n" : "\n";
  28746. return Array(offset).join(padChar);
  28747. }
  28748. }
  28749. function hasSrc(node) {
  28750. return node.props.some((p) => {
  28751. if (p.type !== 6) {
  28752. return false;
  28753. }
  28754. return p.name === "src";
  28755. });
  28756. }
  28757. function isEmpty(node) {
  28758. for (let i = 0; i < node.children.length; i++) {
  28759. const child = node.children[i];
  28760. if (child.type !== 2 || child.content.trim() !== "") {
  28761. return false;
  28762. }
  28763. }
  28764. return true;
  28765. }
  28766. function hmrShouldReload(prevImports, next) {
  28767. if (!next.scriptSetup || next.scriptSetup.lang !== "ts" && next.scriptSetup.lang !== "tsx") {
  28768. return false;
  28769. }
  28770. for (const key in prevImports) {
  28771. if (!prevImports[key].isUsedInTemplate && isImportUsed(key, next)) {
  28772. return true;
  28773. }
  28774. }
  28775. return false;
  28776. }
  28777. function dedent(s) {
  28778. const lines = s.split("\n");
  28779. const minIndent = lines.reduce(function(minIndent2, line) {
  28780. var _a, _b;
  28781. if (line.trim() === "") {
  28782. return minIndent2;
  28783. }
  28784. const indent = ((_b = (_a = line.match(/^\s*/)) == null ? void 0 : _a[0]) == null ? void 0 : _b.length) || 0;
  28785. return Math.min(indent, minIndent2);
  28786. }, Infinity);
  28787. if (minIndent === 0) {
  28788. return [s, minIndent];
  28789. }
  28790. return [
  28791. lines.map(function(line) {
  28792. return line.slice(minIndent);
  28793. }).join("\n"),
  28794. minIndent
  28795. ];
  28796. }
  28797. // Copyright Joyent, Inc. and other Node contributors.
  28798. //
  28799. // Permission is hereby granted, free of charge, to any person obtaining a
  28800. // copy of this software and associated documentation files (the
  28801. // "Software"), to deal in the Software without restriction, including
  28802. // without limitation the rights to use, copy, modify, merge, publish,
  28803. // distribute, sublicense, and/or sell copies of the Software, and to permit
  28804. // persons to whom the Software is furnished to do so, subject to the
  28805. // following conditions:
  28806. //
  28807. // The above copyright notice and this permission notice shall be included
  28808. // in all copies or substantial portions of the Software.
  28809. //
  28810. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  28811. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28812. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  28813. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  28814. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  28815. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  28816. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  28817. // resolves . and .. elements in a path array with directory names there
  28818. // must be no slashes, empty elements, or device names (c:\) in the array
  28819. // (so also no leading and trailing slashes - it does not distinguish
  28820. // relative and absolute paths)
  28821. function normalizeArray(parts, allowAboveRoot) {
  28822. // if the path tries to go above the root, `up` ends up > 0
  28823. var up = 0;
  28824. for (var i = parts.length - 1; i >= 0; i--) {
  28825. var last = parts[i];
  28826. if (last === '.') {
  28827. parts.splice(i, 1);
  28828. } else if (last === '..') {
  28829. parts.splice(i, 1);
  28830. up++;
  28831. } else if (up) {
  28832. parts.splice(i, 1);
  28833. up--;
  28834. }
  28835. }
  28836. // if the path is allowed to go above the root, restore leading ..s
  28837. if (allowAboveRoot) {
  28838. for (; up--; up) {
  28839. parts.unshift('..');
  28840. }
  28841. }
  28842. return parts;
  28843. }
  28844. // Split a filename into [root, dir, basename, ext], unix version
  28845. // 'root' is just a slash, or nothing.
  28846. var splitPathRe =
  28847. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  28848. var splitPath = function(filename) {
  28849. return splitPathRe.exec(filename).slice(1);
  28850. };
  28851. // path.resolve([from ...], to)
  28852. // posix version
  28853. function resolve() {
  28854. var resolvedPath = '',
  28855. resolvedAbsolute = false;
  28856. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  28857. var path = (i >= 0) ? arguments[i] : '/';
  28858. // Skip empty and invalid entries
  28859. if (typeof path !== 'string') {
  28860. throw new TypeError('Arguments to path.resolve must be strings');
  28861. } else if (!path) {
  28862. continue;
  28863. }
  28864. resolvedPath = path + '/' + resolvedPath;
  28865. resolvedAbsolute = path.charAt(0) === '/';
  28866. }
  28867. // At this point the path should be resolved to a full absolute path, but
  28868. // handle relative paths to be safe (might happen when process.cwd() fails)
  28869. // Normalize the path
  28870. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  28871. return !!p;
  28872. }), !resolvedAbsolute).join('/');
  28873. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  28874. }
  28875. // path.normalize(path)
  28876. // posix version
  28877. function normalize$1(path) {
  28878. var isPathAbsolute = isAbsolute(path),
  28879. trailingSlash = substr(path, -1) === '/';
  28880. // Normalize the path
  28881. path = normalizeArray(filter(path.split('/'), function(p) {
  28882. return !!p;
  28883. }), !isPathAbsolute).join('/');
  28884. if (!path && !isPathAbsolute) {
  28885. path = '.';
  28886. }
  28887. if (path && trailingSlash) {
  28888. path += '/';
  28889. }
  28890. return (isPathAbsolute ? '/' : '') + path;
  28891. }
  28892. // posix version
  28893. function isAbsolute(path) {
  28894. return path.charAt(0) === '/';
  28895. }
  28896. // posix version
  28897. function join() {
  28898. var paths = Array.prototype.slice.call(arguments, 0);
  28899. return normalize$1(filter(paths, function(p, index) {
  28900. if (typeof p !== 'string') {
  28901. throw new TypeError('Arguments to path.join must be strings');
  28902. }
  28903. return p;
  28904. }).join('/'));
  28905. }
  28906. // path.relative(from, to)
  28907. // posix version
  28908. function relative(from, to) {
  28909. from = resolve(from).substr(1);
  28910. to = resolve(to).substr(1);
  28911. function trim(arr) {
  28912. var start = 0;
  28913. for (; start < arr.length; start++) {
  28914. if (arr[start] !== '') break;
  28915. }
  28916. var end = arr.length - 1;
  28917. for (; end >= 0; end--) {
  28918. if (arr[end] !== '') break;
  28919. }
  28920. if (start > end) return [];
  28921. return arr.slice(start, end - start + 1);
  28922. }
  28923. var fromParts = trim(from.split('/'));
  28924. var toParts = trim(to.split('/'));
  28925. var length = Math.min(fromParts.length, toParts.length);
  28926. var samePartsLength = length;
  28927. for (var i = 0; i < length; i++) {
  28928. if (fromParts[i] !== toParts[i]) {
  28929. samePartsLength = i;
  28930. break;
  28931. }
  28932. }
  28933. var outputParts = [];
  28934. for (var i = samePartsLength; i < fromParts.length; i++) {
  28935. outputParts.push('..');
  28936. }
  28937. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  28938. return outputParts.join('/');
  28939. }
  28940. var sep = '/';
  28941. var delimiter$1 = ':';
  28942. function dirname(path) {
  28943. var result = splitPath(path),
  28944. root = result[0],
  28945. dir = result[1];
  28946. if (!root && !dir) {
  28947. // No dirname whatsoever
  28948. return '.';
  28949. }
  28950. if (dir) {
  28951. // It has a dirname, strip trailing slash
  28952. dir = dir.substr(0, dir.length - 1);
  28953. }
  28954. return root + dir;
  28955. }
  28956. function basename(path, ext) {
  28957. var f = splitPath(path)[2];
  28958. // TODO: make this comparison case-insensitive on windows?
  28959. if (ext && f.substr(-1 * ext.length) === ext) {
  28960. f = f.substr(0, f.length - ext.length);
  28961. }
  28962. return f;
  28963. }
  28964. function extname(path) {
  28965. return splitPath(path)[3];
  28966. }
  28967. var path = {
  28968. extname: extname,
  28969. basename: basename,
  28970. dirname: dirname,
  28971. sep: sep,
  28972. delimiter: delimiter$1,
  28973. relative: relative,
  28974. join: join,
  28975. isAbsolute: isAbsolute,
  28976. normalize: normalize$1,
  28977. resolve: resolve
  28978. };
  28979. function filter (xs, f) {
  28980. if (xs.filter) return xs.filter(f);
  28981. var res = [];
  28982. for (var i = 0; i < xs.length; i++) {
  28983. if (f(xs[i], i, xs)) res.push(xs[i]);
  28984. }
  28985. return res;
  28986. }
  28987. // String.prototype.substr - negative index don't work in IE8
  28988. var substr = 'ab'.substr(-1) === 'b' ?
  28989. function (str, start, len) { return str.substr(start, len) } :
  28990. function (str, start, len) {
  28991. if (start < 0) start = str.length + start;
  28992. return str.substr(start, len);
  28993. }
  28994. ;
  28995. var _polyfillNode_path = /*#__PURE__*/Object.freeze({
  28996. __proto__: null,
  28997. basename: basename,
  28998. default: path,
  28999. delimiter: delimiter$1,
  29000. dirname: dirname,
  29001. extname: extname,
  29002. isAbsolute: isAbsolute,
  29003. join: join,
  29004. normalize: normalize$1,
  29005. relative: relative,
  29006. resolve: resolve,
  29007. sep: sep
  29008. });
  29009. /*! https://mths.be/punycode v1.4.1 by @mathias */
  29010. /** Highest positive signed 32-bit float value */
  29011. var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
  29012. /** Bootstring parameters */
  29013. var base = 36;
  29014. var tMin = 1;
  29015. var tMax = 26;
  29016. var skew = 38;
  29017. var damp = 700;
  29018. var initialBias = 72;
  29019. var initialN = 128; // 0x80
  29020. var delimiter = '-'; // '\x2D'
  29021. var regexNonASCII = /[^\x20-\x7E]/; // unprintable ASCII chars + non-ASCII chars
  29022. var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
  29023. /** Error messages */
  29024. var errors = {
  29025. 'overflow': 'Overflow: input needs wider integers to process',
  29026. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  29027. 'invalid-input': 'Invalid input'
  29028. };
  29029. /** Convenience shortcuts */
  29030. var baseMinusTMin = base - tMin;
  29031. var floor = Math.floor;
  29032. var stringFromCharCode = String.fromCharCode;
  29033. /*--------------------------------------------------------------------------*/
  29034. /**
  29035. * A generic error utility function.
  29036. * @private
  29037. * @param {String} type The error type.
  29038. * @returns {Error} Throws a `RangeError` with the applicable error message.
  29039. */
  29040. function error(type) {
  29041. throw new RangeError(errors[type]);
  29042. }
  29043. /**
  29044. * A generic `Array#map` utility function.
  29045. * @private
  29046. * @param {Array} array The array to iterate over.
  29047. * @param {Function} callback The function that gets called for every array
  29048. * item.
  29049. * @returns {Array} A new array of values returned by the callback function.
  29050. */
  29051. function map$1(array, fn) {
  29052. var length = array.length;
  29053. var result = [];
  29054. while (length--) {
  29055. result[length] = fn(array[length]);
  29056. }
  29057. return result;
  29058. }
  29059. /**
  29060. * A simple `Array#map`-like wrapper to work with domain name strings or email
  29061. * addresses.
  29062. * @private
  29063. * @param {String} domain The domain name or email address.
  29064. * @param {Function} callback The function that gets called for every
  29065. * character.
  29066. * @returns {Array} A new string of characters returned by the callback
  29067. * function.
  29068. */
  29069. function mapDomain(string, fn) {
  29070. var parts = string.split('@');
  29071. var result = '';
  29072. if (parts.length > 1) {
  29073. // In email addresses, only the domain name should be punycoded. Leave
  29074. // the local part (i.e. everything up to `@`) intact.
  29075. result = parts[0] + '@';
  29076. string = parts[1];
  29077. }
  29078. // Avoid `split(regex)` for IE8 compatibility. See #17.
  29079. string = string.replace(regexSeparators, '\x2E');
  29080. var labels = string.split('.');
  29081. var encoded = map$1(labels, fn).join('.');
  29082. return result + encoded;
  29083. }
  29084. /**
  29085. * Creates an array containing the numeric code points of each Unicode
  29086. * character in the string. While JavaScript uses UCS-2 internally,
  29087. * this function will convert a pair of surrogate halves (each of which
  29088. * UCS-2 exposes as separate characters) into a single code point,
  29089. * matching UTF-16.
  29090. * @see `punycode.ucs2.encode`
  29091. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  29092. * @memberOf punycode.ucs2
  29093. * @name decode
  29094. * @param {String} string The Unicode input string (UCS-2).
  29095. * @returns {Array} The new array of code points.
  29096. */
  29097. function ucs2decode(string) {
  29098. var output = [],
  29099. counter = 0,
  29100. length = string.length,
  29101. value,
  29102. extra;
  29103. while (counter < length) {
  29104. value = string.charCodeAt(counter++);
  29105. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  29106. // high surrogate, and there is a next character
  29107. extra = string.charCodeAt(counter++);
  29108. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  29109. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  29110. } else {
  29111. // unmatched surrogate; only append this code unit, in case the next
  29112. // code unit is the high surrogate of a surrogate pair
  29113. output.push(value);
  29114. counter--;
  29115. }
  29116. } else {
  29117. output.push(value);
  29118. }
  29119. }
  29120. return output;
  29121. }
  29122. /**
  29123. * Converts a digit/integer into a basic code point.
  29124. * @see `basicToDigit()`
  29125. * @private
  29126. * @param {Number} digit The numeric value of a basic code point.
  29127. * @returns {Number} The basic code point whose value (when used for
  29128. * representing integers) is `digit`, which needs to be in the range
  29129. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  29130. * used; else, the lowercase form is used. The behavior is undefined
  29131. * if `flag` is non-zero and `digit` has no uppercase form.
  29132. */
  29133. function digitToBasic(digit, flag) {
  29134. // 0..25 map to ASCII a..z or A..Z
  29135. // 26..35 map to ASCII 0..9
  29136. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  29137. }
  29138. /**
  29139. * Bias adaptation function as per section 3.4 of RFC 3492.
  29140. * https://tools.ietf.org/html/rfc3492#section-3.4
  29141. * @private
  29142. */
  29143. function adapt(delta, numPoints, firstTime) {
  29144. var k = 0;
  29145. delta = firstTime ? floor(delta / damp) : delta >> 1;
  29146. delta += floor(delta / numPoints);
  29147. for ( /* no initialization */ ; delta > baseMinusTMin * tMax >> 1; k += base) {
  29148. delta = floor(delta / baseMinusTMin);
  29149. }
  29150. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  29151. }
  29152. /**
  29153. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  29154. * Punycode string of ASCII-only symbols.
  29155. * @memberOf punycode
  29156. * @param {String} input The string of Unicode symbols.
  29157. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  29158. */
  29159. function encode$1(input) {
  29160. var n,
  29161. delta,
  29162. handledCPCount,
  29163. basicLength,
  29164. bias,
  29165. j,
  29166. m,
  29167. q,
  29168. k,
  29169. t,
  29170. currentValue,
  29171. output = [],
  29172. /** `inputLength` will hold the number of code points in `input`. */
  29173. inputLength,
  29174. /** Cached calculation results */
  29175. handledCPCountPlusOne,
  29176. baseMinusT,
  29177. qMinusT;
  29178. // Convert the input in UCS-2 to Unicode
  29179. input = ucs2decode(input);
  29180. // Cache the length
  29181. inputLength = input.length;
  29182. // Initialize the state
  29183. n = initialN;
  29184. delta = 0;
  29185. bias = initialBias;
  29186. // Handle the basic code points
  29187. for (j = 0; j < inputLength; ++j) {
  29188. currentValue = input[j];
  29189. if (currentValue < 0x80) {
  29190. output.push(stringFromCharCode(currentValue));
  29191. }
  29192. }
  29193. handledCPCount = basicLength = output.length;
  29194. // `handledCPCount` is the number of code points that have been handled;
  29195. // `basicLength` is the number of basic code points.
  29196. // Finish the basic string - if it is not empty - with a delimiter
  29197. if (basicLength) {
  29198. output.push(delimiter);
  29199. }
  29200. // Main encoding loop:
  29201. while (handledCPCount < inputLength) {
  29202. // All non-basic code points < n have been handled already. Find the next
  29203. // larger one:
  29204. for (m = maxInt, j = 0; j < inputLength; ++j) {
  29205. currentValue = input[j];
  29206. if (currentValue >= n && currentValue < m) {
  29207. m = currentValue;
  29208. }
  29209. }
  29210. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  29211. // but guard against overflow
  29212. handledCPCountPlusOne = handledCPCount + 1;
  29213. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  29214. error('overflow');
  29215. }
  29216. delta += (m - n) * handledCPCountPlusOne;
  29217. n = m;
  29218. for (j = 0; j < inputLength; ++j) {
  29219. currentValue = input[j];
  29220. if (currentValue < n && ++delta > maxInt) {
  29221. error('overflow');
  29222. }
  29223. if (currentValue == n) {
  29224. // Represent delta as a generalized variable-length integer
  29225. for (q = delta, k = base; /* no condition */ ; k += base) {
  29226. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  29227. if (q < t) {
  29228. break;
  29229. }
  29230. qMinusT = q - t;
  29231. baseMinusT = base - t;
  29232. output.push(
  29233. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  29234. );
  29235. q = floor(qMinusT / baseMinusT);
  29236. }
  29237. output.push(stringFromCharCode(digitToBasic(q, 0)));
  29238. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  29239. delta = 0;
  29240. ++handledCPCount;
  29241. }
  29242. }
  29243. ++delta;
  29244. ++n;
  29245. }
  29246. return output.join('');
  29247. }
  29248. /**
  29249. * Converts a Unicode string representing a domain name or an email address to
  29250. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  29251. * i.e. it doesn't matter if you call it with a domain that's already in
  29252. * ASCII.
  29253. * @memberOf punycode
  29254. * @param {String} input The domain name or email address to convert, as a
  29255. * Unicode string.
  29256. * @returns {String} The Punycode representation of the given domain name or
  29257. * email address.
  29258. */
  29259. function toASCII(input) {
  29260. return mapDomain(input, function(string) {
  29261. return regexNonASCII.test(string) ?
  29262. 'xn--' + encode$1(string) :
  29263. string;
  29264. });
  29265. }
  29266. var inherits;
  29267. if (typeof Object.create === 'function'){
  29268. inherits = function inherits(ctor, superCtor) {
  29269. // implementation from standard node.js 'util' module
  29270. ctor.super_ = superCtor;
  29271. ctor.prototype = Object.create(superCtor.prototype, {
  29272. constructor: {
  29273. value: ctor,
  29274. enumerable: false,
  29275. writable: true,
  29276. configurable: true
  29277. }
  29278. });
  29279. };
  29280. } else {
  29281. inherits = function inherits(ctor, superCtor) {
  29282. ctor.super_ = superCtor;
  29283. var TempCtor = function () {};
  29284. TempCtor.prototype = superCtor.prototype;
  29285. ctor.prototype = new TempCtor();
  29286. ctor.prototype.constructor = ctor;
  29287. };
  29288. }
  29289. var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
  29290. function getOwnPropertyDescriptors(obj) {
  29291. var keys = Object.keys(obj);
  29292. var descriptors = {};
  29293. for (var i = 0; i < keys.length; i++) {
  29294. descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  29295. }
  29296. return descriptors;
  29297. };
  29298. var formatRegExp = /%[sdj%]/g;
  29299. function format$1(f) {
  29300. if (!isString(f)) {
  29301. var objects = [];
  29302. for (var i = 0; i < arguments.length; i++) {
  29303. objects.push(inspect(arguments[i]));
  29304. }
  29305. return objects.join(' ');
  29306. }
  29307. var i = 1;
  29308. var args = arguments;
  29309. var len = args.length;
  29310. var str = String(f).replace(formatRegExp, function(x) {
  29311. if (x === '%%') return '%';
  29312. if (i >= len) return x;
  29313. switch (x) {
  29314. case '%s': return String(args[i++]);
  29315. case '%d': return Number(args[i++]);
  29316. case '%j':
  29317. try {
  29318. return JSON.stringify(args[i++]);
  29319. } catch (_) {
  29320. return '[Circular]';
  29321. }
  29322. default:
  29323. return x;
  29324. }
  29325. });
  29326. for (var x = args[i]; i < len; x = args[++i]) {
  29327. if (isNull(x) || !isObject$1(x)) {
  29328. str += ' ' + x;
  29329. } else {
  29330. str += ' ' + inspect(x);
  29331. }
  29332. }
  29333. return str;
  29334. }
  29335. // Mark that a method should not be used.
  29336. // Returns a modified function which warns once by default.
  29337. // If --no-deprecation is set, then it is a no-op.
  29338. function deprecate(fn, msg) {
  29339. // Allow for deprecating things in the process of starting up.
  29340. if (isUndefined(global$1.process)) {
  29341. return function() {
  29342. return deprecate(fn, msg).apply(this, arguments);
  29343. };
  29344. }
  29345. if (browser$1.noDeprecation === true) {
  29346. return fn;
  29347. }
  29348. var warned = false;
  29349. function deprecated() {
  29350. if (!warned) {
  29351. if (browser$1.throwDeprecation) {
  29352. throw new Error(msg);
  29353. } else if (browser$1.traceDeprecation) {
  29354. console.trace(msg);
  29355. } else {
  29356. console.error(msg);
  29357. }
  29358. warned = true;
  29359. }
  29360. return fn.apply(this, arguments);
  29361. }
  29362. return deprecated;
  29363. }
  29364. var debugs = {};
  29365. var debugEnviron;
  29366. function debuglog(set) {
  29367. if (isUndefined(debugEnviron))
  29368. debugEnviron = browser$1.env.NODE_DEBUG || '';
  29369. set = set.toUpperCase();
  29370. if (!debugs[set]) {
  29371. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  29372. var pid = 0;
  29373. debugs[set] = function() {
  29374. var msg = format$1.apply(null, arguments);
  29375. console.error('%s %d: %s', set, pid, msg);
  29376. };
  29377. } else {
  29378. debugs[set] = function() {};
  29379. }
  29380. }
  29381. return debugs[set];
  29382. }
  29383. /**
  29384. * Echos the value of a value. Trys to print the value out
  29385. * in the best way possible given the different types.
  29386. *
  29387. * @param {Object} obj The object to print out.
  29388. * @param {Object} opts Optional options object that alters the output.
  29389. */
  29390. /* legacy: obj, showHidden, depth, colors*/
  29391. function inspect(obj, opts) {
  29392. // default options
  29393. var ctx = {
  29394. seen: [],
  29395. stylize: stylizeNoColor
  29396. };
  29397. // legacy...
  29398. if (arguments.length >= 3) ctx.depth = arguments[2];
  29399. if (arguments.length >= 4) ctx.colors = arguments[3];
  29400. if (isBoolean(opts)) {
  29401. // legacy...
  29402. ctx.showHidden = opts;
  29403. } else if (opts) {
  29404. // got an "options" object
  29405. _extend(ctx, opts);
  29406. }
  29407. // set default options
  29408. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  29409. if (isUndefined(ctx.depth)) ctx.depth = 2;
  29410. if (isUndefined(ctx.colors)) ctx.colors = false;
  29411. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  29412. if (ctx.colors) ctx.stylize = stylizeWithColor;
  29413. return formatValue(ctx, obj, ctx.depth);
  29414. }
  29415. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  29416. inspect.colors = {
  29417. 'bold' : [1, 22],
  29418. 'italic' : [3, 23],
  29419. 'underline' : [4, 24],
  29420. 'inverse' : [7, 27],
  29421. 'white' : [37, 39],
  29422. 'grey' : [90, 39],
  29423. 'black' : [30, 39],
  29424. 'blue' : [34, 39],
  29425. 'cyan' : [36, 39],
  29426. 'green' : [32, 39],
  29427. 'magenta' : [35, 39],
  29428. 'red' : [31, 39],
  29429. 'yellow' : [33, 39]
  29430. };
  29431. // Don't use 'blue' not visible on cmd.exe
  29432. inspect.styles = {
  29433. 'special': 'cyan',
  29434. 'number': 'yellow',
  29435. 'boolean': 'yellow',
  29436. 'undefined': 'grey',
  29437. 'null': 'bold',
  29438. 'string': 'green',
  29439. 'date': 'magenta',
  29440. // "name": intentionally not styling
  29441. 'regexp': 'red'
  29442. };
  29443. function stylizeWithColor(str, styleType) {
  29444. var style = inspect.styles[styleType];
  29445. if (style) {
  29446. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  29447. '\u001b[' + inspect.colors[style][1] + 'm';
  29448. } else {
  29449. return str;
  29450. }
  29451. }
  29452. function stylizeNoColor(str, styleType) {
  29453. return str;
  29454. }
  29455. function arrayToHash(array) {
  29456. var hash = {};
  29457. array.forEach(function(val, idx) {
  29458. hash[val] = true;
  29459. });
  29460. return hash;
  29461. }
  29462. function formatValue(ctx, value, recurseTimes) {
  29463. // Provide a hook for user-specified inspect functions.
  29464. // Check that value is an object with an inspect function on it
  29465. if (ctx.customInspect &&
  29466. value &&
  29467. isFunction(value.inspect) &&
  29468. // Filter out the util module, it's inspect function is special
  29469. value.inspect !== inspect &&
  29470. // Also filter out any prototype objects using the circular check.
  29471. !(value.constructor && value.constructor.prototype === value)) {
  29472. var ret = value.inspect(recurseTimes, ctx);
  29473. if (!isString(ret)) {
  29474. ret = formatValue(ctx, ret, recurseTimes);
  29475. }
  29476. return ret;
  29477. }
  29478. // Primitive types cannot have properties
  29479. var primitive = formatPrimitive(ctx, value);
  29480. if (primitive) {
  29481. return primitive;
  29482. }
  29483. // Look up the keys of the object.
  29484. var keys = Object.keys(value);
  29485. var visibleKeys = arrayToHash(keys);
  29486. if (ctx.showHidden) {
  29487. keys = Object.getOwnPropertyNames(value);
  29488. }
  29489. // IE doesn't make error fields non-enumerable
  29490. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  29491. if (isError(value)
  29492. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  29493. return formatError(value);
  29494. }
  29495. // Some type of object without properties can be shortcutted.
  29496. if (keys.length === 0) {
  29497. if (isFunction(value)) {
  29498. var name = value.name ? ': ' + value.name : '';
  29499. return ctx.stylize('[Function' + name + ']', 'special');
  29500. }
  29501. if (isRegExp(value)) {
  29502. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29503. }
  29504. if (isDate(value)) {
  29505. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  29506. }
  29507. if (isError(value)) {
  29508. return formatError(value);
  29509. }
  29510. }
  29511. var base = '', array = false, braces = ['{', '}'];
  29512. // Make Array say that they are Array
  29513. if (isArray$1(value)) {
  29514. array = true;
  29515. braces = ['[', ']'];
  29516. }
  29517. // Make functions say that they are functions
  29518. if (isFunction(value)) {
  29519. var n = value.name ? ': ' + value.name : '';
  29520. base = ' [Function' + n + ']';
  29521. }
  29522. // Make RegExps say that they are RegExps
  29523. if (isRegExp(value)) {
  29524. base = ' ' + RegExp.prototype.toString.call(value);
  29525. }
  29526. // Make dates with properties first say the date
  29527. if (isDate(value)) {
  29528. base = ' ' + Date.prototype.toUTCString.call(value);
  29529. }
  29530. // Make error with message first say the error
  29531. if (isError(value)) {
  29532. base = ' ' + formatError(value);
  29533. }
  29534. if (keys.length === 0 && (!array || value.length == 0)) {
  29535. return braces[0] + base + braces[1];
  29536. }
  29537. if (recurseTimes < 0) {
  29538. if (isRegExp(value)) {
  29539. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29540. } else {
  29541. return ctx.stylize('[Object]', 'special');
  29542. }
  29543. }
  29544. ctx.seen.push(value);
  29545. var output;
  29546. if (array) {
  29547. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  29548. } else {
  29549. output = keys.map(function(key) {
  29550. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  29551. });
  29552. }
  29553. ctx.seen.pop();
  29554. return reduceToSingleString(output, base, braces);
  29555. }
  29556. function formatPrimitive(ctx, value) {
  29557. if (isUndefined(value))
  29558. return ctx.stylize('undefined', 'undefined');
  29559. if (isString(value)) {
  29560. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  29561. .replace(/'/g, "\\'")
  29562. .replace(/\\"/g, '"') + '\'';
  29563. return ctx.stylize(simple, 'string');
  29564. }
  29565. if (isNumber(value))
  29566. return ctx.stylize('' + value, 'number');
  29567. if (isBoolean(value))
  29568. return ctx.stylize('' + value, 'boolean');
  29569. // For some reason typeof null is "object", so special case here.
  29570. if (isNull(value))
  29571. return ctx.stylize('null', 'null');
  29572. }
  29573. function formatError(value) {
  29574. return '[' + Error.prototype.toString.call(value) + ']';
  29575. }
  29576. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  29577. var output = [];
  29578. for (var i = 0, l = value.length; i < l; ++i) {
  29579. if (hasOwnProperty$2(value, String(i))) {
  29580. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29581. String(i), true));
  29582. } else {
  29583. output.push('');
  29584. }
  29585. }
  29586. keys.forEach(function(key) {
  29587. if (!key.match(/^\d+$/)) {
  29588. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29589. key, true));
  29590. }
  29591. });
  29592. return output;
  29593. }
  29594. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  29595. var name, str, desc;
  29596. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  29597. if (desc.get) {
  29598. if (desc.set) {
  29599. str = ctx.stylize('[Getter/Setter]', 'special');
  29600. } else {
  29601. str = ctx.stylize('[Getter]', 'special');
  29602. }
  29603. } else {
  29604. if (desc.set) {
  29605. str = ctx.stylize('[Setter]', 'special');
  29606. }
  29607. }
  29608. if (!hasOwnProperty$2(visibleKeys, key)) {
  29609. name = '[' + key + ']';
  29610. }
  29611. if (!str) {
  29612. if (ctx.seen.indexOf(desc.value) < 0) {
  29613. if (isNull(recurseTimes)) {
  29614. str = formatValue(ctx, desc.value, null);
  29615. } else {
  29616. str = formatValue(ctx, desc.value, recurseTimes - 1);
  29617. }
  29618. if (str.indexOf('\n') > -1) {
  29619. if (array) {
  29620. str = str.split('\n').map(function(line) {
  29621. return ' ' + line;
  29622. }).join('\n').substr(2);
  29623. } else {
  29624. str = '\n' + str.split('\n').map(function(line) {
  29625. return ' ' + line;
  29626. }).join('\n');
  29627. }
  29628. }
  29629. } else {
  29630. str = ctx.stylize('[Circular]', 'special');
  29631. }
  29632. }
  29633. if (isUndefined(name)) {
  29634. if (array && key.match(/^\d+$/)) {
  29635. return str;
  29636. }
  29637. name = JSON.stringify('' + key);
  29638. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  29639. name = name.substr(1, name.length - 2);
  29640. name = ctx.stylize(name, 'name');
  29641. } else {
  29642. name = name.replace(/'/g, "\\'")
  29643. .replace(/\\"/g, '"')
  29644. .replace(/(^"|"$)/g, "'");
  29645. name = ctx.stylize(name, 'string');
  29646. }
  29647. }
  29648. return name + ': ' + str;
  29649. }
  29650. function reduceToSingleString(output, base, braces) {
  29651. var length = output.reduce(function(prev, cur) {
  29652. if (cur.indexOf('\n') >= 0) ;
  29653. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  29654. }, 0);
  29655. if (length > 60) {
  29656. return braces[0] +
  29657. (base === '' ? '' : base + '\n ') +
  29658. ' ' +
  29659. output.join(',\n ') +
  29660. ' ' +
  29661. braces[1];
  29662. }
  29663. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  29664. }
  29665. // NOTE: These type checking functions intentionally don't use `instanceof`
  29666. // because it is fragile and can be easily faked with `Object.create()`.
  29667. function isArray$1(ar) {
  29668. return Array.isArray(ar);
  29669. }
  29670. function isBoolean(arg) {
  29671. return typeof arg === 'boolean';
  29672. }
  29673. function isNull(arg) {
  29674. return arg === null;
  29675. }
  29676. function isNullOrUndefined(arg) {
  29677. return arg == null;
  29678. }
  29679. function isNumber(arg) {
  29680. return typeof arg === 'number';
  29681. }
  29682. function isString(arg) {
  29683. return typeof arg === 'string';
  29684. }
  29685. function isSymbol(arg) {
  29686. return typeof arg === 'symbol';
  29687. }
  29688. function isUndefined(arg) {
  29689. return arg === void 0;
  29690. }
  29691. function isRegExp(re) {
  29692. return isObject$1(re) && objectToString(re) === '[object RegExp]';
  29693. }
  29694. function isObject$1(arg) {
  29695. return typeof arg === 'object' && arg !== null;
  29696. }
  29697. function isDate(d) {
  29698. return isObject$1(d) && objectToString(d) === '[object Date]';
  29699. }
  29700. function isError(e) {
  29701. return isObject$1(e) &&
  29702. (objectToString(e) === '[object Error]' || e instanceof Error);
  29703. }
  29704. function isFunction(arg) {
  29705. return typeof arg === 'function';
  29706. }
  29707. function isPrimitive(arg) {
  29708. return arg === null ||
  29709. typeof arg === 'boolean' ||
  29710. typeof arg === 'number' ||
  29711. typeof arg === 'string' ||
  29712. typeof arg === 'symbol' || // ES6 symbol
  29713. typeof arg === 'undefined';
  29714. }
  29715. function isBuffer(maybeBuf) {
  29716. return Buffer$1.isBuffer(maybeBuf);
  29717. }
  29718. function objectToString(o) {
  29719. return Object.prototype.toString.call(o);
  29720. }
  29721. function pad(n) {
  29722. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  29723. }
  29724. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  29725. 'Oct', 'Nov', 'Dec'];
  29726. // 26 Feb 16:19:34
  29727. function timestamp() {
  29728. var d = new Date();
  29729. var time = [pad(d.getHours()),
  29730. pad(d.getMinutes()),
  29731. pad(d.getSeconds())].join(':');
  29732. return [d.getDate(), months[d.getMonth()], time].join(' ');
  29733. }
  29734. // log is just a thin wrapper to console.log that prepends a timestamp
  29735. function log() {
  29736. console.log('%s - %s', timestamp(), format$1.apply(null, arguments));
  29737. }
  29738. function _extend(origin, add) {
  29739. // Don't do anything if add isn't an object
  29740. if (!add || !isObject$1(add)) return origin;
  29741. var keys = Object.keys(add);
  29742. var i = keys.length;
  29743. while (i--) {
  29744. origin[keys[i]] = add[keys[i]];
  29745. }
  29746. return origin;
  29747. }
  29748. function hasOwnProperty$2(obj, prop) {
  29749. return Object.prototype.hasOwnProperty.call(obj, prop);
  29750. }
  29751. var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
  29752. function promisify(original) {
  29753. if (typeof original !== 'function')
  29754. throw new TypeError('The "original" argument must be of type Function');
  29755. if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
  29756. var fn = original[kCustomPromisifiedSymbol];
  29757. if (typeof fn !== 'function') {
  29758. throw new TypeError('The "util.promisify.custom" argument must be of type Function');
  29759. }
  29760. Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29761. value: fn, enumerable: false, writable: false, configurable: true
  29762. });
  29763. return fn;
  29764. }
  29765. function fn() {
  29766. var promiseResolve, promiseReject;
  29767. var promise = new Promise(function (resolve, reject) {
  29768. promiseResolve = resolve;
  29769. promiseReject = reject;
  29770. });
  29771. var args = [];
  29772. for (var i = 0; i < arguments.length; i++) {
  29773. args.push(arguments[i]);
  29774. }
  29775. args.push(function (err, value) {
  29776. if (err) {
  29777. promiseReject(err);
  29778. } else {
  29779. promiseResolve(value);
  29780. }
  29781. });
  29782. try {
  29783. original.apply(this, args);
  29784. } catch (err) {
  29785. promiseReject(err);
  29786. }
  29787. return promise;
  29788. }
  29789. Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
  29790. if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29791. value: fn, enumerable: false, writable: false, configurable: true
  29792. });
  29793. return Object.defineProperties(
  29794. fn,
  29795. getOwnPropertyDescriptors(original)
  29796. );
  29797. }
  29798. promisify.custom = kCustomPromisifiedSymbol;
  29799. function callbackifyOnRejected(reason, cb) {
  29800. // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
  29801. // Because `null` is a special error value in callbacks which means "no error
  29802. // occurred", we error-wrap so the callback consumer can distinguish between
  29803. // "the promise rejected with null" or "the promise fulfilled with undefined".
  29804. if (!reason) {
  29805. var newReason = new Error('Promise was rejected with a falsy value');
  29806. newReason.reason = reason;
  29807. reason = newReason;
  29808. }
  29809. return cb(reason);
  29810. }
  29811. function callbackify(original) {
  29812. if (typeof original !== 'function') {
  29813. throw new TypeError('The "original" argument must be of type Function');
  29814. }
  29815. // We DO NOT return the promise as it gives the user a false sense that
  29816. // the promise is actually somehow related to the callback's execution
  29817. // and that the callback throwing will reject the promise.
  29818. function callbackified() {
  29819. var args = [];
  29820. for (var i = 0; i < arguments.length; i++) {
  29821. args.push(arguments[i]);
  29822. }
  29823. var maybeCb = args.pop();
  29824. if (typeof maybeCb !== 'function') {
  29825. throw new TypeError('The last argument must be of type Function');
  29826. }
  29827. var self = this;
  29828. var cb = function() {
  29829. return maybeCb.apply(self, arguments);
  29830. };
  29831. // In true node style we process the callback on `nextTick` with all the
  29832. // implications (stack, `uncaughtException`, `async_hooks`)
  29833. original.apply(this, args)
  29834. .then(function(ret) { browser$1.nextTick(cb.bind(null, null, ret)); },
  29835. function(rej) { browser$1.nextTick(callbackifyOnRejected.bind(null, rej, cb)); });
  29836. }
  29837. Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
  29838. Object.defineProperties(callbackified, getOwnPropertyDescriptors(original));
  29839. return callbackified;
  29840. }
  29841. var _polyfillNode_util = {
  29842. inherits: inherits,
  29843. _extend: _extend,
  29844. log: log,
  29845. isBuffer: isBuffer,
  29846. isPrimitive: isPrimitive,
  29847. isFunction: isFunction,
  29848. isError: isError,
  29849. isDate: isDate,
  29850. isObject: isObject$1,
  29851. isRegExp: isRegExp,
  29852. isUndefined: isUndefined,
  29853. isSymbol: isSymbol,
  29854. isString: isString,
  29855. isNumber: isNumber,
  29856. isNullOrUndefined: isNullOrUndefined,
  29857. isNull: isNull,
  29858. isBoolean: isBoolean,
  29859. isArray: isArray$1,
  29860. inspect: inspect,
  29861. deprecate: deprecate,
  29862. format: format$1,
  29863. debuglog: debuglog,
  29864. promisify: promisify,
  29865. callbackify: callbackify,
  29866. };
  29867. var _polyfillNode_util$1 = /*#__PURE__*/Object.freeze({
  29868. __proto__: null,
  29869. _extend: _extend,
  29870. callbackify: callbackify,
  29871. debuglog: debuglog,
  29872. default: _polyfillNode_util,
  29873. deprecate: deprecate,
  29874. format: format$1,
  29875. inherits: inherits,
  29876. inspect: inspect,
  29877. isArray: isArray$1,
  29878. isBoolean: isBoolean,
  29879. isBuffer: isBuffer,
  29880. isDate: isDate,
  29881. isError: isError,
  29882. isFunction: isFunction,
  29883. isNull: isNull,
  29884. isNullOrUndefined: isNullOrUndefined,
  29885. isNumber: isNumber,
  29886. isObject: isObject$1,
  29887. isPrimitive: isPrimitive,
  29888. isRegExp: isRegExp,
  29889. isString: isString,
  29890. isSymbol: isSymbol,
  29891. isUndefined: isUndefined,
  29892. log: log,
  29893. promisify: promisify
  29894. });
  29895. // Copyright Joyent, Inc. and other Node contributors.
  29896. //
  29897. // Permission is hereby granted, free of charge, to any person obtaining a
  29898. // copy of this software and associated documentation files (the
  29899. // "Software"), to deal in the Software without restriction, including
  29900. // without limitation the rights to use, copy, modify, merge, publish,
  29901. // distribute, sublicense, and/or sell copies of the Software, and to permit
  29902. // persons to whom the Software is furnished to do so, subject to the
  29903. // following conditions:
  29904. //
  29905. // The above copyright notice and this permission notice shall be included
  29906. // in all copies or substantial portions of the Software.
  29907. //
  29908. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  29909. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29910. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  29911. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  29912. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  29913. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  29914. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  29915. // If obj.hasOwnProperty has been overridden, then calling
  29916. // obj.hasOwnProperty(prop) will break.
  29917. // See: https://github.com/joyent/node/issues/1707
  29918. function hasOwnProperty$1(obj, prop) {
  29919. return Object.prototype.hasOwnProperty.call(obj, prop);
  29920. }
  29921. var isArray = Array.isArray || function (xs) {
  29922. return Object.prototype.toString.call(xs) === '[object Array]';
  29923. };
  29924. function stringifyPrimitive(v) {
  29925. switch (typeof v) {
  29926. case 'string':
  29927. return v;
  29928. case 'boolean':
  29929. return v ? 'true' : 'false';
  29930. case 'number':
  29931. return isFinite(v) ? v : '';
  29932. default:
  29933. return '';
  29934. }
  29935. }
  29936. function stringify (obj, sep, eq, name) {
  29937. sep = sep || '&';
  29938. eq = eq || '=';
  29939. if (obj === null) {
  29940. obj = undefined;
  29941. }
  29942. if (typeof obj === 'object') {
  29943. return map(objectKeys(obj), function(k) {
  29944. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  29945. if (isArray(obj[k])) {
  29946. return map(obj[k], function(v) {
  29947. return ks + encodeURIComponent(stringifyPrimitive(v));
  29948. }).join(sep);
  29949. } else {
  29950. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  29951. }
  29952. }).join(sep);
  29953. }
  29954. if (!name) return '';
  29955. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  29956. encodeURIComponent(stringifyPrimitive(obj));
  29957. }
  29958. function map (xs, f) {
  29959. if (xs.map) return xs.map(f);
  29960. var res = [];
  29961. for (var i = 0; i < xs.length; i++) {
  29962. res.push(f(xs[i], i));
  29963. }
  29964. return res;
  29965. }
  29966. var objectKeys = Object.keys || function (obj) {
  29967. var res = [];
  29968. for (var key in obj) {
  29969. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  29970. }
  29971. return res;
  29972. };
  29973. function parse$1(qs, sep, eq, options) {
  29974. sep = sep || '&';
  29975. eq = eq || '=';
  29976. var obj = {};
  29977. if (typeof qs !== 'string' || qs.length === 0) {
  29978. return obj;
  29979. }
  29980. var regexp = /\+/g;
  29981. qs = qs.split(sep);
  29982. var maxKeys = 1000;
  29983. if (options && typeof options.maxKeys === 'number') {
  29984. maxKeys = options.maxKeys;
  29985. }
  29986. var len = qs.length;
  29987. // maxKeys <= 0 means that we should not limit keys count
  29988. if (maxKeys > 0 && len > maxKeys) {
  29989. len = maxKeys;
  29990. }
  29991. for (var i = 0; i < len; ++i) {
  29992. var x = qs[i].replace(regexp, '%20'),
  29993. idx = x.indexOf(eq),
  29994. kstr, vstr, k, v;
  29995. if (idx >= 0) {
  29996. kstr = x.substr(0, idx);
  29997. vstr = x.substr(idx + 1);
  29998. } else {
  29999. kstr = x;
  30000. vstr = '';
  30001. }
  30002. k = decodeURIComponent(kstr);
  30003. v = decodeURIComponent(vstr);
  30004. if (!hasOwnProperty$1(obj, k)) {
  30005. obj[k] = v;
  30006. } else if (isArray(obj[k])) {
  30007. obj[k].push(v);
  30008. } else {
  30009. obj[k] = [obj[k], v];
  30010. }
  30011. }
  30012. return obj;
  30013. }
  30014. // WHATWG API
  30015. const URL$1 = global$1.URL;
  30016. const URLSearchParams = global$1.URLSearchParams;
  30017. var _polyfillNode_url = {
  30018. parse: urlParse,
  30019. resolve: urlResolve,
  30020. resolveObject: urlResolveObject,
  30021. fileURLToPath: urlFileURLToPath,
  30022. format: urlFormat,
  30023. Url: Url,
  30024. // WHATWG API
  30025. URL: URL$1,
  30026. URLSearchParams,
  30027. };
  30028. function Url() {
  30029. this.protocol = null;
  30030. this.slashes = null;
  30031. this.auth = null;
  30032. this.host = null;
  30033. this.port = null;
  30034. this.hostname = null;
  30035. this.hash = null;
  30036. this.search = null;
  30037. this.query = null;
  30038. this.pathname = null;
  30039. this.path = null;
  30040. this.href = null;
  30041. }
  30042. // Reference: RFC 3986, RFC 1808, RFC 2396
  30043. // define these here so at least they only have to be
  30044. // compiled once on the first module load.
  30045. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  30046. portPattern = /:[0-9]*$/,
  30047. // Special case for a simple path URL
  30048. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  30049. // RFC 2396: characters reserved for delimiting URLs.
  30050. // We actually just auto-escape these.
  30051. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  30052. // RFC 2396: characters not allowed for various reasons.
  30053. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  30054. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  30055. autoEscape = ['\''].concat(unwise),
  30056. // Characters that are never ever allowed in a hostname.
  30057. // Note that any invalid chars are also handled, but these
  30058. // are the ones that are *expected* to be seen, so we fast-path
  30059. // them.
  30060. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  30061. hostEndingChars = ['/', '?', '#'],
  30062. hostnameMaxLen = 255,
  30063. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  30064. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  30065. // protocols that can allow "unsafe" and "unwise" chars.
  30066. unsafeProtocol = {
  30067. 'javascript': true,
  30068. 'javascript:': true
  30069. },
  30070. // protocols that never have a hostname.
  30071. hostlessProtocol = {
  30072. 'javascript': true,
  30073. 'javascript:': true
  30074. },
  30075. // protocols that always contain a // bit.
  30076. slashedProtocol = {
  30077. 'http': true,
  30078. 'https': true,
  30079. 'ftp': true,
  30080. 'gopher': true,
  30081. 'file': true,
  30082. 'http:': true,
  30083. 'https:': true,
  30084. 'ftp:': true,
  30085. 'gopher:': true,
  30086. 'file:': true
  30087. };
  30088. function urlParse(url, parseQueryString, slashesDenoteHost) {
  30089. if (url && isObject$1(url) && url instanceof Url) return url;
  30090. var u = new Url;
  30091. u.parse(url, parseQueryString, slashesDenoteHost);
  30092. return u;
  30093. }
  30094. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  30095. return parse(this, url, parseQueryString, slashesDenoteHost);
  30096. };
  30097. function parse(self, url, parseQueryString, slashesDenoteHost) {
  30098. if (!isString(url)) {
  30099. throw new TypeError('Parameter \'url\' must be a string, not ' + typeof url);
  30100. }
  30101. // Copy chrome, IE, opera backslash-handling behavior.
  30102. // Back slashes before the query string get converted to forward slashes
  30103. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  30104. var queryIndex = url.indexOf('?'),
  30105. splitter =
  30106. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  30107. uSplit = url.split(splitter),
  30108. slashRegex = /\\/g;
  30109. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  30110. url = uSplit.join(splitter);
  30111. var rest = url;
  30112. // trim before proceeding.
  30113. // This is to support parse stuff like " http://foo.com \n"
  30114. rest = rest.trim();
  30115. if (!slashesDenoteHost && url.split('#').length === 1) {
  30116. // Try fast path regexp
  30117. var simplePath = simplePathPattern.exec(rest);
  30118. if (simplePath) {
  30119. self.path = rest;
  30120. self.href = rest;
  30121. self.pathname = simplePath[1];
  30122. if (simplePath[2]) {
  30123. self.search = simplePath[2];
  30124. if (parseQueryString) {
  30125. self.query = parse$1(self.search.substr(1));
  30126. } else {
  30127. self.query = self.search.substr(1);
  30128. }
  30129. } else if (parseQueryString) {
  30130. self.search = '';
  30131. self.query = {};
  30132. }
  30133. return self;
  30134. }
  30135. }
  30136. var proto = protocolPattern.exec(rest);
  30137. if (proto) {
  30138. proto = proto[0];
  30139. var lowerProto = proto.toLowerCase();
  30140. self.protocol = lowerProto;
  30141. rest = rest.substr(proto.length);
  30142. }
  30143. // figure out if it's got a host
  30144. // user@server is *always* interpreted as a hostname, and url
  30145. // resolution will treat //foo/bar as host=foo,path=bar because that's
  30146. // how the browser resolves relative URLs.
  30147. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  30148. var slashes = rest.substr(0, 2) === '//';
  30149. if (slashes && !(proto && hostlessProtocol[proto])) {
  30150. rest = rest.substr(2);
  30151. self.slashes = true;
  30152. }
  30153. }
  30154. var i, hec, l, p;
  30155. if (!hostlessProtocol[proto] &&
  30156. (slashes || (proto && !slashedProtocol[proto]))) {
  30157. // there's a hostname.
  30158. // the first instance of /, ?, ;, or # ends the host.
  30159. //
  30160. // If there is an @ in the hostname, then non-host chars *are* allowed
  30161. // to the left of the last @ sign, unless some host-ending character
  30162. // comes *before* the @-sign.
  30163. // URLs are obnoxious.
  30164. //
  30165. // ex:
  30166. // http://a@b@c/ => user:a@b host:c
  30167. // http://a@b?@c => user:a host:c path:/?@c
  30168. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  30169. // Review our test case against browsers more comprehensively.
  30170. // find the first instance of any hostEndingChars
  30171. var hostEnd = -1;
  30172. for (i = 0; i < hostEndingChars.length; i++) {
  30173. hec = rest.indexOf(hostEndingChars[i]);
  30174. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  30175. hostEnd = hec;
  30176. }
  30177. // at this point, either we have an explicit point where the
  30178. // auth portion cannot go past, or the last @ char is the decider.
  30179. var auth, atSign;
  30180. if (hostEnd === -1) {
  30181. // atSign can be anywhere.
  30182. atSign = rest.lastIndexOf('@');
  30183. } else {
  30184. // atSign must be in auth portion.
  30185. // http://a@b/c@d => host:b auth:a path:/c@d
  30186. atSign = rest.lastIndexOf('@', hostEnd);
  30187. }
  30188. // Now we have a portion which is definitely the auth.
  30189. // Pull that off.
  30190. if (atSign !== -1) {
  30191. auth = rest.slice(0, atSign);
  30192. rest = rest.slice(atSign + 1);
  30193. self.auth = decodeURIComponent(auth);
  30194. }
  30195. // the host is the remaining to the left of the first non-host char
  30196. hostEnd = -1;
  30197. for (i = 0; i < nonHostChars.length; i++) {
  30198. hec = rest.indexOf(nonHostChars[i]);
  30199. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  30200. hostEnd = hec;
  30201. }
  30202. // if we still have not hit it, then the entire thing is a host.
  30203. if (hostEnd === -1)
  30204. hostEnd = rest.length;
  30205. self.host = rest.slice(0, hostEnd);
  30206. rest = rest.slice(hostEnd);
  30207. // pull out port.
  30208. parseHost(self);
  30209. // we've indicated that there is a hostname,
  30210. // so even if it's empty, it has to be present.
  30211. self.hostname = self.hostname || '';
  30212. // if hostname begins with [ and ends with ]
  30213. // assume that it's an IPv6 address.
  30214. var ipv6Hostname = self.hostname[0] === '[' &&
  30215. self.hostname[self.hostname.length - 1] === ']';
  30216. // validate a little.
  30217. if (!ipv6Hostname) {
  30218. var hostparts = self.hostname.split(/\./);
  30219. for (i = 0, l = hostparts.length; i < l; i++) {
  30220. var part = hostparts[i];
  30221. if (!part) continue;
  30222. if (!part.match(hostnamePartPattern)) {
  30223. var newpart = '';
  30224. for (var j = 0, k = part.length; j < k; j++) {
  30225. if (part.charCodeAt(j) > 127) {
  30226. // we replace non-ASCII char with a temporary placeholder
  30227. // we need this to make sure size of hostname is not
  30228. // broken by replacing non-ASCII by nothing
  30229. newpart += 'x';
  30230. } else {
  30231. newpart += part[j];
  30232. }
  30233. }
  30234. // we test again with ASCII char only
  30235. if (!newpart.match(hostnamePartPattern)) {
  30236. var validParts = hostparts.slice(0, i);
  30237. var notHost = hostparts.slice(i + 1);
  30238. var bit = part.match(hostnamePartStart);
  30239. if (bit) {
  30240. validParts.push(bit[1]);
  30241. notHost.unshift(bit[2]);
  30242. }
  30243. if (notHost.length) {
  30244. rest = '/' + notHost.join('.') + rest;
  30245. }
  30246. self.hostname = validParts.join('.');
  30247. break;
  30248. }
  30249. }
  30250. }
  30251. }
  30252. if (self.hostname.length > hostnameMaxLen) {
  30253. self.hostname = '';
  30254. } else {
  30255. // hostnames are always lower case.
  30256. self.hostname = self.hostname.toLowerCase();
  30257. }
  30258. if (!ipv6Hostname) {
  30259. // IDNA Support: Returns a punycoded representation of "domain".
  30260. // It only converts parts of the domain name that
  30261. // have non-ASCII characters, i.e. it doesn't matter if
  30262. // you call it with a domain that already is ASCII-only.
  30263. self.hostname = toASCII(self.hostname);
  30264. }
  30265. p = self.port ? ':' + self.port : '';
  30266. var h = self.hostname || '';
  30267. self.host = h + p;
  30268. self.href += self.host;
  30269. // strip [ and ] from the hostname
  30270. // the host field still retains them, though
  30271. if (ipv6Hostname) {
  30272. self.hostname = self.hostname.substr(1, self.hostname.length - 2);
  30273. if (rest[0] !== '/') {
  30274. rest = '/' + rest;
  30275. }
  30276. }
  30277. }
  30278. // now rest is set to the post-host stuff.
  30279. // chop off any delim chars.
  30280. if (!unsafeProtocol[lowerProto]) {
  30281. // First, make 100% sure that any "autoEscape" chars get
  30282. // escaped, even if encodeURIComponent doesn't think they
  30283. // need to be.
  30284. for (i = 0, l = autoEscape.length; i < l; i++) {
  30285. var ae = autoEscape[i];
  30286. if (rest.indexOf(ae) === -1)
  30287. continue;
  30288. var esc = encodeURIComponent(ae);
  30289. if (esc === ae) {
  30290. esc = escape(ae);
  30291. }
  30292. rest = rest.split(ae).join(esc);
  30293. }
  30294. }
  30295. // chop off from the tail first.
  30296. var hash = rest.indexOf('#');
  30297. if (hash !== -1) {
  30298. // got a fragment string.
  30299. self.hash = rest.substr(hash);
  30300. rest = rest.slice(0, hash);
  30301. }
  30302. var qm = rest.indexOf('?');
  30303. if (qm !== -1) {
  30304. self.search = rest.substr(qm);
  30305. self.query = rest.substr(qm + 1);
  30306. if (parseQueryString) {
  30307. self.query = parse$1(self.query);
  30308. }
  30309. rest = rest.slice(0, qm);
  30310. } else if (parseQueryString) {
  30311. // no query string, but parseQueryString still requested
  30312. self.search = '';
  30313. self.query = {};
  30314. }
  30315. if (rest) self.pathname = rest;
  30316. if (slashedProtocol[lowerProto] &&
  30317. self.hostname && !self.pathname) {
  30318. self.pathname = '/';
  30319. }
  30320. //to support http.request
  30321. if (self.pathname || self.search) {
  30322. p = self.pathname || '';
  30323. var s = self.search || '';
  30324. self.path = p + s;
  30325. }
  30326. // finally, reconstruct the href based on what has been validated.
  30327. self.href = format(self);
  30328. return self;
  30329. }
  30330. function urlFileURLToPath(path) {
  30331. if (typeof path === 'string')
  30332. path = new Url().parse(path);
  30333. else if (!(path instanceof Url))
  30334. throw new TypeError('The "path" argument must be of type string or an instance of URL. Received type ' + (typeof path) + String(path));
  30335. if (path.protocol !== 'file:')
  30336. throw new TypeError('The URL must be of scheme file');
  30337. return getPathFromURLPosix(path);
  30338. }
  30339. function getPathFromURLPosix(url) {
  30340. const pathname = url.pathname;
  30341. for (let n = 0; n < pathname.length; n++) {
  30342. if (pathname[n] === '%') {
  30343. const third = pathname.codePointAt(n + 2) | 0x20;
  30344. if (pathname[n + 1] === '2' && third === 102) {
  30345. throw new TypeError(
  30346. 'must not include encoded / characters'
  30347. );
  30348. }
  30349. }
  30350. }
  30351. return decodeURIComponent(pathname);
  30352. }
  30353. // format a parsed object into a url string
  30354. function urlFormat(obj) {
  30355. // ensure it's an object, and not a string url.
  30356. // If it's an obj, this is a no-op.
  30357. // this way, you can call url_format() on strings
  30358. // to clean up potentially wonky urls.
  30359. if (isString(obj)) obj = parse({}, obj);
  30360. return format(obj);
  30361. }
  30362. function format(self) {
  30363. var auth = self.auth || '';
  30364. if (auth) {
  30365. auth = encodeURIComponent(auth);
  30366. auth = auth.replace(/%3A/i, ':');
  30367. auth += '@';
  30368. }
  30369. var protocol = self.protocol || '',
  30370. pathname = self.pathname || '',
  30371. hash = self.hash || '',
  30372. host = false,
  30373. query = '';
  30374. if (self.host) {
  30375. host = auth + self.host;
  30376. } else if (self.hostname) {
  30377. host = auth + (self.hostname.indexOf(':') === -1 ?
  30378. self.hostname :
  30379. '[' + this.hostname + ']');
  30380. if (self.port) {
  30381. host += ':' + self.port;
  30382. }
  30383. }
  30384. if (self.query &&
  30385. isObject$1(self.query) &&
  30386. Object.keys(self.query).length) {
  30387. query = stringify(self.query);
  30388. }
  30389. var search = self.search || (query && ('?' + query)) || '';
  30390. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  30391. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  30392. // unless they had them to begin with.
  30393. if (self.slashes ||
  30394. (!protocol || slashedProtocol[protocol]) && host !== false) {
  30395. host = '//' + (host || '');
  30396. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  30397. } else if (!host) {
  30398. host = '';
  30399. }
  30400. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  30401. if (search && search.charAt(0) !== '?') search = '?' + search;
  30402. pathname = pathname.replace(/[?#]/g, function(match) {
  30403. return encodeURIComponent(match);
  30404. });
  30405. search = search.replace('#', '%23');
  30406. return protocol + host + pathname + search + hash;
  30407. }
  30408. Url.prototype.format = function() {
  30409. return format(this);
  30410. };
  30411. function urlResolve(source, relative) {
  30412. return urlParse(source, false, true).resolve(relative);
  30413. }
  30414. Url.prototype.resolve = function(relative) {
  30415. return this.resolveObject(urlParse(relative, false, true)).format();
  30416. };
  30417. function urlResolveObject(source, relative) {
  30418. if (!source) return relative;
  30419. return urlParse(source, false, true).resolveObject(relative);
  30420. }
  30421. Url.prototype.resolveObject = function(relative) {
  30422. if (isString(relative)) {
  30423. var rel = new Url();
  30424. rel.parse(relative, false, true);
  30425. relative = rel;
  30426. }
  30427. var result = new Url();
  30428. var tkeys = Object.keys(this);
  30429. for (var tk = 0; tk < tkeys.length; tk++) {
  30430. var tkey = tkeys[tk];
  30431. result[tkey] = this[tkey];
  30432. }
  30433. // hash is always overridden, no matter what.
  30434. // even href="" will remove it.
  30435. result.hash = relative.hash;
  30436. // if the relative url is empty, then there's nothing left to do here.
  30437. if (relative.href === '') {
  30438. result.href = result.format();
  30439. return result;
  30440. }
  30441. // hrefs like //foo/bar always cut to the protocol.
  30442. if (relative.slashes && !relative.protocol) {
  30443. // take everything except the protocol from relative
  30444. var rkeys = Object.keys(relative);
  30445. for (var rk = 0; rk < rkeys.length; rk++) {
  30446. var rkey = rkeys[rk];
  30447. if (rkey !== 'protocol')
  30448. result[rkey] = relative[rkey];
  30449. }
  30450. //urlParse appends trailing / to urls like http://www.example.com
  30451. if (slashedProtocol[result.protocol] &&
  30452. result.hostname && !result.pathname) {
  30453. result.path = result.pathname = '/';
  30454. }
  30455. result.href = result.format();
  30456. return result;
  30457. }
  30458. var relPath;
  30459. if (relative.protocol && relative.protocol !== result.protocol) {
  30460. // if it's a known url protocol, then changing
  30461. // the protocol does weird things
  30462. // first, if it's not file:, then we MUST have a host,
  30463. // and if there was a path
  30464. // to begin with, then we MUST have a path.
  30465. // if it is file:, then the host is dropped,
  30466. // because that's known to be hostless.
  30467. // anything else is assumed to be absolute.
  30468. if (!slashedProtocol[relative.protocol]) {
  30469. var keys = Object.keys(relative);
  30470. for (var v = 0; v < keys.length; v++) {
  30471. var k = keys[v];
  30472. result[k] = relative[k];
  30473. }
  30474. result.href = result.format();
  30475. return result;
  30476. }
  30477. result.protocol = relative.protocol;
  30478. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  30479. relPath = (relative.pathname || '').split('/');
  30480. while (relPath.length && !(relative.host = relPath.shift()));
  30481. if (!relative.host) relative.host = '';
  30482. if (!relative.hostname) relative.hostname = '';
  30483. if (relPath[0] !== '') relPath.unshift('');
  30484. if (relPath.length < 2) relPath.unshift('');
  30485. result.pathname = relPath.join('/');
  30486. } else {
  30487. result.pathname = relative.pathname;
  30488. }
  30489. result.search = relative.search;
  30490. result.query = relative.query;
  30491. result.host = relative.host || '';
  30492. result.auth = relative.auth;
  30493. result.hostname = relative.hostname || relative.host;
  30494. result.port = relative.port;
  30495. // to support http.request
  30496. if (result.pathname || result.search) {
  30497. var p = result.pathname || '';
  30498. var s = result.search || '';
  30499. result.path = p + s;
  30500. }
  30501. result.slashes = result.slashes || relative.slashes;
  30502. result.href = result.format();
  30503. return result;
  30504. }
  30505. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  30506. isRelAbs = (
  30507. relative.host ||
  30508. relative.pathname && relative.pathname.charAt(0) === '/'
  30509. ),
  30510. mustEndAbs = (isRelAbs || isSourceAbs ||
  30511. (result.host && relative.pathname)),
  30512. removeAllDots = mustEndAbs,
  30513. srcPath = result.pathname && result.pathname.split('/') || [],
  30514. psychotic = result.protocol && !slashedProtocol[result.protocol];
  30515. relPath = relative.pathname && relative.pathname.split('/') || [];
  30516. // if the url is a non-slashed url, then relative
  30517. // links like ../.. should be able
  30518. // to crawl up to the hostname, as well. This is strange.
  30519. // result.protocol has already been set by now.
  30520. // Later on, put the first path part into the host field.
  30521. if (psychotic) {
  30522. result.hostname = '';
  30523. result.port = null;
  30524. if (result.host) {
  30525. if (srcPath[0] === '') srcPath[0] = result.host;
  30526. else srcPath.unshift(result.host);
  30527. }
  30528. result.host = '';
  30529. if (relative.protocol) {
  30530. relative.hostname = null;
  30531. relative.port = null;
  30532. if (relative.host) {
  30533. if (relPath[0] === '') relPath[0] = relative.host;
  30534. else relPath.unshift(relative.host);
  30535. }
  30536. relative.host = null;
  30537. }
  30538. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  30539. }
  30540. var authInHost;
  30541. if (isRelAbs) {
  30542. // it's absolute.
  30543. result.host = (relative.host || relative.host === '') ?
  30544. relative.host : result.host;
  30545. result.hostname = (relative.hostname || relative.hostname === '') ?
  30546. relative.hostname : result.hostname;
  30547. result.search = relative.search;
  30548. result.query = relative.query;
  30549. srcPath = relPath;
  30550. // fall through to the dot-handling below.
  30551. } else if (relPath.length) {
  30552. // it's relative
  30553. // throw away the existing file, and take the new path instead.
  30554. if (!srcPath) srcPath = [];
  30555. srcPath.pop();
  30556. srcPath = srcPath.concat(relPath);
  30557. result.search = relative.search;
  30558. result.query = relative.query;
  30559. } else if (!isNullOrUndefined(relative.search)) {
  30560. // just pull out the search.
  30561. // like href='?foo'.
  30562. // Put this after the other two cases because it simplifies the booleans
  30563. if (psychotic) {
  30564. result.hostname = result.host = srcPath.shift();
  30565. //occationaly the auth can get stuck only in host
  30566. //this especially happens in cases like
  30567. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30568. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30569. result.host.split('@') : false;
  30570. if (authInHost) {
  30571. result.auth = authInHost.shift();
  30572. result.host = result.hostname = authInHost.shift();
  30573. }
  30574. }
  30575. result.search = relative.search;
  30576. result.query = relative.query;
  30577. //to support http.request
  30578. if (!isNull(result.pathname) || !isNull(result.search)) {
  30579. result.path = (result.pathname ? result.pathname : '') +
  30580. (result.search ? result.search : '');
  30581. }
  30582. result.href = result.format();
  30583. return result;
  30584. }
  30585. if (!srcPath.length) {
  30586. // no path at all. easy.
  30587. // we've already handled the other stuff above.
  30588. result.pathname = null;
  30589. //to support http.request
  30590. if (result.search) {
  30591. result.path = '/' + result.search;
  30592. } else {
  30593. result.path = null;
  30594. }
  30595. result.href = result.format();
  30596. return result;
  30597. }
  30598. // if a url ENDs in . or .., then it must get a trailing slash.
  30599. // however, if it ends in anything else non-slashy,
  30600. // then it must NOT get a trailing slash.
  30601. var last = srcPath.slice(-1)[0];
  30602. var hasTrailingSlash = (
  30603. (result.host || relative.host || srcPath.length > 1) &&
  30604. (last === '.' || last === '..') || last === '');
  30605. // strip single dots, resolve double dots to parent dir
  30606. // if the path tries to go above the root, `up` ends up > 0
  30607. var up = 0;
  30608. for (var i = srcPath.length; i >= 0; i--) {
  30609. last = srcPath[i];
  30610. if (last === '.') {
  30611. srcPath.splice(i, 1);
  30612. } else if (last === '..') {
  30613. srcPath.splice(i, 1);
  30614. up++;
  30615. } else if (up) {
  30616. srcPath.splice(i, 1);
  30617. up--;
  30618. }
  30619. }
  30620. // if the path is allowed to go above the root, restore leading ..s
  30621. if (!mustEndAbs && !removeAllDots) {
  30622. for (; up--; up) {
  30623. srcPath.unshift('..');
  30624. }
  30625. }
  30626. if (mustEndAbs && srcPath[0] !== '' &&
  30627. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  30628. srcPath.unshift('');
  30629. }
  30630. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  30631. srcPath.push('');
  30632. }
  30633. var isAbsolute = srcPath[0] === '' ||
  30634. (srcPath[0] && srcPath[0].charAt(0) === '/');
  30635. // put the host back
  30636. if (psychotic) {
  30637. result.hostname = result.host = isAbsolute ? '' :
  30638. srcPath.length ? srcPath.shift() : '';
  30639. //occationaly the auth can get stuck only in host
  30640. //this especially happens in cases like
  30641. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30642. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30643. result.host.split('@') : false;
  30644. if (authInHost) {
  30645. result.auth = authInHost.shift();
  30646. result.host = result.hostname = authInHost.shift();
  30647. }
  30648. }
  30649. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  30650. if (mustEndAbs && !isAbsolute) {
  30651. srcPath.unshift('');
  30652. }
  30653. if (!srcPath.length) {
  30654. result.pathname = null;
  30655. result.path = null;
  30656. } else {
  30657. result.pathname = srcPath.join('/');
  30658. }
  30659. //to support request.http
  30660. if (!isNull(result.pathname) || !isNull(result.search)) {
  30661. result.path = (result.pathname ? result.pathname : '') +
  30662. (result.search ? result.search : '');
  30663. }
  30664. result.auth = relative.auth || result.auth;
  30665. result.slashes = result.slashes || relative.slashes;
  30666. result.href = result.format();
  30667. return result;
  30668. };
  30669. Url.prototype.parseHost = function() {
  30670. return parseHost(this);
  30671. };
  30672. function parseHost(self) {
  30673. var host = self.host;
  30674. var port = portPattern.exec(host);
  30675. if (port) {
  30676. port = port[0];
  30677. if (port !== ':') {
  30678. self.port = port.substr(1);
  30679. }
  30680. host = host.substr(0, host.length - port.length);
  30681. }
  30682. if (host) self.hostname = host;
  30683. }
  30684. var _polyfillNode_url$1 = /*#__PURE__*/Object.freeze({
  30685. __proto__: null,
  30686. URL: URL$1,
  30687. URLSearchParams: URLSearchParams,
  30688. Url: Url,
  30689. default: _polyfillNode_url,
  30690. fileURLToPath: urlFileURLToPath,
  30691. format: urlFormat,
  30692. parse: urlParse,
  30693. resolve: urlResolve,
  30694. resolveObject: urlResolveObject
  30695. });
  30696. function isRelativeUrl(url) {
  30697. const firstChar = url.charAt(0);
  30698. return firstChar === "." || firstChar === "~" || firstChar === "@";
  30699. }
  30700. const externalRE = /^(?:https?:)?\/\//;
  30701. function isExternalUrl(url) {
  30702. return externalRE.test(url);
  30703. }
  30704. const dataUrlRE = /^\s*data:/i;
  30705. function isDataUrl(url) {
  30706. return dataUrlRE.test(url);
  30707. }
  30708. function parseUrl(url) {
  30709. const firstChar = url.charAt(0);
  30710. if (firstChar === "~") {
  30711. const secondChar = url.charAt(1);
  30712. url = url.slice(secondChar === "/" ? 2 : 1);
  30713. }
  30714. return parseUriParts(url);
  30715. }
  30716. function parseUriParts(urlString) {
  30717. return urlParse(isString$1(urlString) ? urlString : "", false, true);
  30718. }
  30719. var __defProp$9 = Object.defineProperty;
  30720. var __defProps$8 = Object.defineProperties;
  30721. var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
  30722. var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
  30723. var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
  30724. var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
  30725. var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  30726. var __spreadValues$9 = (a, b) => {
  30727. for (var prop in b || (b = {}))
  30728. if (__hasOwnProp$9.call(b, prop))
  30729. __defNormalProp$9(a, prop, b[prop]);
  30730. if (__getOwnPropSymbols$9)
  30731. for (var prop of __getOwnPropSymbols$9(b)) {
  30732. if (__propIsEnum$9.call(b, prop))
  30733. __defNormalProp$9(a, prop, b[prop]);
  30734. }
  30735. return a;
  30736. };
  30737. var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
  30738. const defaultAssetUrlOptions = {
  30739. base: null,
  30740. includeAbsolute: false,
  30741. tags: {
  30742. video: ["src", "poster"],
  30743. source: ["src"],
  30744. img: ["src"],
  30745. image: ["xlink:href", "href"],
  30746. use: ["xlink:href", "href"]
  30747. }
  30748. };
  30749. const normalizeOptions = (options) => {
  30750. if (Object.keys(options).some((key) => isArray$3(options[key]))) {
  30751. return __spreadProps$8(__spreadValues$9({}, defaultAssetUrlOptions), {
  30752. tags: options
  30753. });
  30754. }
  30755. return __spreadValues$9(__spreadValues$9({}, defaultAssetUrlOptions), options);
  30756. };
  30757. const createAssetUrlTransformWithOptions = (options) => {
  30758. return (node, context) => transformAssetUrl(node, context, options);
  30759. };
  30760. const transformAssetUrl = (node, context, options = defaultAssetUrlOptions) => {
  30761. if (node.type === 1) {
  30762. if (!node.props.length) {
  30763. return;
  30764. }
  30765. const tags = options.tags || defaultAssetUrlOptions.tags;
  30766. const attrs = tags[node.tag];
  30767. const wildCardAttrs = tags["*"];
  30768. if (!attrs && !wildCardAttrs) {
  30769. return;
  30770. }
  30771. const assetAttrs = (attrs || []).concat(wildCardAttrs || []);
  30772. node.props.forEach((attr, index) => {
  30773. 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)) {
  30774. return;
  30775. }
  30776. const url = parseUrl(attr.value.content);
  30777. if (options.base && attr.value.content[0] === ".") {
  30778. const base = parseUrl(options.base);
  30779. const protocol = base.protocol || "";
  30780. const host = base.host ? protocol + "//" + base.host : "";
  30781. const basePath = base.path || "/";
  30782. attr.value.content = host + (path.posix || path).join(basePath, url.path + (url.hash || ""));
  30783. return;
  30784. }
  30785. const exp = getImportsExpressionExp(url.path, url.hash, attr.loc, context);
  30786. node.props[index] = {
  30787. type: 7,
  30788. name: "bind",
  30789. arg: createSimpleExpression(attr.name, true, attr.loc),
  30790. exp,
  30791. modifiers: [],
  30792. loc: attr.loc
  30793. };
  30794. });
  30795. }
  30796. };
  30797. function getImportsExpressionExp(path2, hash, loc, context) {
  30798. if (path2) {
  30799. let name;
  30800. let exp;
  30801. const existingIndex = context.imports.findIndex((i) => i.path === path2);
  30802. if (existingIndex > -1) {
  30803. name = `_imports_${existingIndex}`;
  30804. exp = context.imports[existingIndex].exp;
  30805. } else {
  30806. name = `_imports_${context.imports.length}`;
  30807. exp = createSimpleExpression(
  30808. name,
  30809. false,
  30810. loc,
  30811. 3
  30812. );
  30813. context.imports.push({
  30814. exp,
  30815. path: decodeURIComponent(path2)
  30816. });
  30817. }
  30818. if (!hash) {
  30819. return exp;
  30820. }
  30821. const hashExp = `${name} + '${hash}'`;
  30822. const finalExp = createSimpleExpression(
  30823. hashExp,
  30824. false,
  30825. loc,
  30826. 3
  30827. );
  30828. if (!context.hoistStatic) {
  30829. return finalExp;
  30830. }
  30831. const existingHoistIndex = context.hoists.findIndex((h) => {
  30832. return h && h.type === 4 && !h.isStatic && h.content === hashExp;
  30833. });
  30834. if (existingHoistIndex > -1) {
  30835. return createSimpleExpression(
  30836. `_hoisted_${existingHoistIndex + 1}`,
  30837. false,
  30838. loc,
  30839. 3
  30840. );
  30841. }
  30842. return context.hoist(finalExp);
  30843. } else {
  30844. return createSimpleExpression(`''`, false, loc, 3);
  30845. }
  30846. }
  30847. const srcsetTags = ["img", "source"];
  30848. const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g;
  30849. const createSrcsetTransformWithOptions = (options) => {
  30850. return (node, context) => transformSrcset(node, context, options);
  30851. };
  30852. const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
  30853. if (node.type === 1) {
  30854. if (srcsetTags.includes(node.tag) && node.props.length) {
  30855. node.props.forEach((attr, index) => {
  30856. if (attr.name === "srcset" && attr.type === 6) {
  30857. if (!attr.value) return;
  30858. const value = attr.value.content;
  30859. if (!value) return;
  30860. const imageCandidates = value.split(",").map((s) => {
  30861. const [url, descriptor] = s.replace(escapedSpaceCharacters, " ").trim().split(" ", 2);
  30862. return { url, descriptor };
  30863. });
  30864. for (let i = 0; i < imageCandidates.length; i++) {
  30865. const { url } = imageCandidates[i];
  30866. if (isDataUrl(url)) {
  30867. imageCandidates[i + 1].url = url + "," + imageCandidates[i + 1].url;
  30868. imageCandidates.splice(i, 1);
  30869. }
  30870. }
  30871. const shouldProcessUrl = (url) => {
  30872. return url && !isExternalUrl(url) && !isDataUrl(url) && (options.includeAbsolute || isRelativeUrl(url));
  30873. };
  30874. if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
  30875. return;
  30876. }
  30877. if (options.base) {
  30878. const base = options.base;
  30879. const set = [];
  30880. let needImportTransform = false;
  30881. imageCandidates.forEach((candidate) => {
  30882. let { url, descriptor } = candidate;
  30883. descriptor = descriptor ? ` ${descriptor}` : ``;
  30884. if (url[0] === ".") {
  30885. candidate.url = (path.posix || path).join(base, url);
  30886. set.push(candidate.url + descriptor);
  30887. } else if (shouldProcessUrl(url)) {
  30888. needImportTransform = true;
  30889. } else {
  30890. set.push(url + descriptor);
  30891. }
  30892. });
  30893. if (!needImportTransform) {
  30894. attr.value.content = set.join(", ");
  30895. return;
  30896. }
  30897. }
  30898. const compoundExpression = createCompoundExpression([], attr.loc);
  30899. imageCandidates.forEach(({ url, descriptor }, index2) => {
  30900. if (shouldProcessUrl(url)) {
  30901. const { path: path2 } = parseUrl(url);
  30902. let exp2;
  30903. if (path2) {
  30904. const existingImportsIndex = context.imports.findIndex(
  30905. (i) => i.path === path2
  30906. );
  30907. if (existingImportsIndex > -1) {
  30908. exp2 = createSimpleExpression(
  30909. `_imports_${existingImportsIndex}`,
  30910. false,
  30911. attr.loc,
  30912. 3
  30913. );
  30914. } else {
  30915. exp2 = createSimpleExpression(
  30916. `_imports_${context.imports.length}`,
  30917. false,
  30918. attr.loc,
  30919. 3
  30920. );
  30921. context.imports.push({ exp: exp2, path: path2 });
  30922. }
  30923. compoundExpression.children.push(exp2);
  30924. }
  30925. } else {
  30926. const exp2 = createSimpleExpression(
  30927. `"${url}"`,
  30928. false,
  30929. attr.loc,
  30930. 3
  30931. );
  30932. compoundExpression.children.push(exp2);
  30933. }
  30934. const isNotLast = imageCandidates.length - 1 > index2;
  30935. if (descriptor && isNotLast) {
  30936. compoundExpression.children.push(` + ' ${descriptor}, ' + `);
  30937. } else if (descriptor) {
  30938. compoundExpression.children.push(` + ' ${descriptor}'`);
  30939. } else if (isNotLast) {
  30940. compoundExpression.children.push(` + ', ' + `);
  30941. }
  30942. });
  30943. let exp = compoundExpression;
  30944. if (context.hoistStatic) {
  30945. exp = context.hoist(compoundExpression);
  30946. exp.constType = 3;
  30947. }
  30948. node.props[index] = {
  30949. type: 7,
  30950. name: "bind",
  30951. arg: createSimpleExpression("srcset", true, attr.loc),
  30952. exp,
  30953. modifiers: [],
  30954. loc: attr.loc
  30955. };
  30956. }
  30957. });
  30958. }
  30959. }
  30960. };
  30961. const SSR_INTERPOLATE = /* @__PURE__ */ Symbol(`ssrInterpolate`);
  30962. const SSR_RENDER_VNODE = /* @__PURE__ */ Symbol(`ssrRenderVNode`);
  30963. const SSR_RENDER_COMPONENT = /* @__PURE__ */ Symbol(`ssrRenderComponent`);
  30964. const SSR_RENDER_SLOT = /* @__PURE__ */ Symbol(`ssrRenderSlot`);
  30965. const SSR_RENDER_SLOT_INNER = /* @__PURE__ */ Symbol(`ssrRenderSlotInner`);
  30966. const SSR_RENDER_CLASS = /* @__PURE__ */ Symbol(`ssrRenderClass`);
  30967. const SSR_RENDER_STYLE = /* @__PURE__ */ Symbol(`ssrRenderStyle`);
  30968. const SSR_RENDER_ATTRS = /* @__PURE__ */ Symbol(`ssrRenderAttrs`);
  30969. const SSR_RENDER_ATTR = /* @__PURE__ */ Symbol(`ssrRenderAttr`);
  30970. const SSR_RENDER_DYNAMIC_ATTR = /* @__PURE__ */ Symbol(`ssrRenderDynamicAttr`);
  30971. const SSR_RENDER_LIST = /* @__PURE__ */ Symbol(`ssrRenderList`);
  30972. const SSR_INCLUDE_BOOLEAN_ATTR = /* @__PURE__ */ Symbol(
  30973. `ssrIncludeBooleanAttr`
  30974. );
  30975. const SSR_LOOSE_EQUAL = /* @__PURE__ */ Symbol(`ssrLooseEqual`);
  30976. const SSR_LOOSE_CONTAIN = /* @__PURE__ */ Symbol(`ssrLooseContain`);
  30977. const SSR_RENDER_DYNAMIC_MODEL = /* @__PURE__ */ Symbol(
  30978. `ssrRenderDynamicModel`
  30979. );
  30980. const SSR_GET_DYNAMIC_MODEL_PROPS = /* @__PURE__ */ Symbol(
  30981. `ssrGetDynamicModelProps`
  30982. );
  30983. const SSR_RENDER_TELEPORT = /* @__PURE__ */ Symbol(`ssrRenderTeleport`);
  30984. const SSR_RENDER_SUSPENSE = /* @__PURE__ */ Symbol(`ssrRenderSuspense`);
  30985. const SSR_GET_DIRECTIVE_PROPS = /* @__PURE__ */ Symbol(`ssrGetDirectiveProps`);
  30986. const ssrHelpers = {
  30987. [SSR_INTERPOLATE]: `ssrInterpolate`,
  30988. [SSR_RENDER_VNODE]: `ssrRenderVNode`,
  30989. [SSR_RENDER_COMPONENT]: `ssrRenderComponent`,
  30990. [SSR_RENDER_SLOT]: `ssrRenderSlot`,
  30991. [SSR_RENDER_SLOT_INNER]: `ssrRenderSlotInner`,
  30992. [SSR_RENDER_CLASS]: `ssrRenderClass`,
  30993. [SSR_RENDER_STYLE]: `ssrRenderStyle`,
  30994. [SSR_RENDER_ATTRS]: `ssrRenderAttrs`,
  30995. [SSR_RENDER_ATTR]: `ssrRenderAttr`,
  30996. [SSR_RENDER_DYNAMIC_ATTR]: `ssrRenderDynamicAttr`,
  30997. [SSR_RENDER_LIST]: `ssrRenderList`,
  30998. [SSR_INCLUDE_BOOLEAN_ATTR]: `ssrIncludeBooleanAttr`,
  30999. [SSR_LOOSE_EQUAL]: `ssrLooseEqual`,
  31000. [SSR_LOOSE_CONTAIN]: `ssrLooseContain`,
  31001. [SSR_RENDER_DYNAMIC_MODEL]: `ssrRenderDynamicModel`,
  31002. [SSR_GET_DYNAMIC_MODEL_PROPS]: `ssrGetDynamicModelProps`,
  31003. [SSR_RENDER_TELEPORT]: `ssrRenderTeleport`,
  31004. [SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`,
  31005. [SSR_GET_DIRECTIVE_PROPS]: `ssrGetDirectiveProps`
  31006. };
  31007. registerRuntimeHelpers(ssrHelpers);
  31008. const ssrTransformIf = createStructuralDirectiveTransform(
  31009. /^(?:if|else|else-if)$/,
  31010. processIf
  31011. );
  31012. function ssrProcessIf(node, context, disableNestedFragments = false, disableComment = false) {
  31013. const [rootBranch] = node.branches;
  31014. const ifStatement = createIfStatement(
  31015. rootBranch.condition,
  31016. processIfBranch(rootBranch, context, disableNestedFragments)
  31017. );
  31018. context.pushStatement(ifStatement);
  31019. let currentIf = ifStatement;
  31020. for (let i = 1; i < node.branches.length; i++) {
  31021. const branch = node.branches[i];
  31022. const branchBlockStatement = processIfBranch(
  31023. branch,
  31024. context,
  31025. disableNestedFragments
  31026. );
  31027. if (branch.condition) {
  31028. currentIf = currentIf.alternate = createIfStatement(
  31029. branch.condition,
  31030. branchBlockStatement
  31031. );
  31032. } else {
  31033. currentIf.alternate = branchBlockStatement;
  31034. }
  31035. }
  31036. if (!currentIf.alternate && !disableComment) {
  31037. currentIf.alternate = createBlockStatement([
  31038. createCallExpression(`_push`, ["`<!---->`"])
  31039. ]);
  31040. }
  31041. }
  31042. function processIfBranch(branch, context, disableNestedFragments = false) {
  31043. const { children } = branch;
  31044. const needFragmentWrapper = !disableNestedFragments && (children.length !== 1 || children[0].type !== 1) && // optimize away nested fragments when the only child is a ForNode
  31045. !(children.length === 1 && children[0].type === 11);
  31046. return processChildrenAsStatement(branch, context, needFragmentWrapper);
  31047. }
  31048. const ssrTransformFor = createStructuralDirectiveTransform("for", processFor);
  31049. function ssrProcessFor(node, context, disableNestedFragments = false) {
  31050. const needFragmentWrapper = !disableNestedFragments && (node.children.length !== 1 || node.children[0].type !== 1);
  31051. const renderLoop = createFunctionExpression(
  31052. createForLoopParams(node.parseResult)
  31053. );
  31054. renderLoop.body = processChildrenAsStatement(
  31055. node,
  31056. context,
  31057. needFragmentWrapper
  31058. );
  31059. if (!disableNestedFragments) {
  31060. context.pushStringPart(`<!--[-->`);
  31061. }
  31062. context.pushStatement(
  31063. createCallExpression(context.helper(SSR_RENDER_LIST), [
  31064. node.source,
  31065. renderLoop
  31066. ])
  31067. );
  31068. if (!disableNestedFragments) {
  31069. context.pushStringPart(`<!--]-->`);
  31070. }
  31071. }
  31072. const ssrTransformSlotOutlet = (node, context) => {
  31073. if (isSlotOutlet(node)) {
  31074. const { slotName, slotProps } = processSlotOutlet(node, context);
  31075. const args = [
  31076. `_ctx.$slots`,
  31077. slotName,
  31078. slotProps || `{}`,
  31079. // fallback content placeholder. will be replaced in the process phase
  31080. `null`,
  31081. `_push`,
  31082. `_parent`
  31083. ];
  31084. if (context.scopeId && context.slotted !== false) {
  31085. args.push(`"${context.scopeId}-s"`);
  31086. }
  31087. let method = SSR_RENDER_SLOT;
  31088. let parent = context.parent;
  31089. if (parent) {
  31090. const children = parent.children;
  31091. if (parent.type === 10) {
  31092. parent = context.grandParent;
  31093. }
  31094. let componentType;
  31095. if (parent.type === 1 && parent.tagType === 1 && ((componentType = resolveComponentType(parent, context, true)) === TRANSITION || componentType === TRANSITION_GROUP) && children.filter((c) => c.type === 1).length === 1) {
  31096. method = SSR_RENDER_SLOT_INNER;
  31097. if (!(context.scopeId && context.slotted !== false)) {
  31098. args.push("null");
  31099. }
  31100. args.push("true");
  31101. }
  31102. }
  31103. node.ssrCodegenNode = createCallExpression(context.helper(method), args);
  31104. }
  31105. };
  31106. function ssrProcessSlotOutlet(node, context) {
  31107. const renderCall = node.ssrCodegenNode;
  31108. if (node.children.length) {
  31109. const fallbackRenderFn = createFunctionExpression([]);
  31110. fallbackRenderFn.body = processChildrenAsStatement(node, context);
  31111. renderCall.arguments[3] = fallbackRenderFn;
  31112. }
  31113. if (context.withSlotScopeId) {
  31114. const slotScopeId = renderCall.arguments[6];
  31115. renderCall.arguments[6] = slotScopeId ? `${slotScopeId} + _scopeId` : `_scopeId`;
  31116. }
  31117. context.pushStatement(node.ssrCodegenNode);
  31118. }
  31119. function createSSRCompilerError(code, loc) {
  31120. return createCompilerError(code, loc, SSRErrorMessages);
  31121. }
  31122. const SSRErrorMessages = {
  31123. [65]: `Unsafe attribute name for SSR.`,
  31124. [66]: `Missing the 'to' prop on teleport element.`,
  31125. [67]: `Invalid AST node during SSR transform.`
  31126. };
  31127. function ssrProcessTeleport(node, context) {
  31128. const targetProp = findProp(node, "to");
  31129. if (!targetProp) {
  31130. context.onError(
  31131. createSSRCompilerError(66, node.loc)
  31132. );
  31133. return;
  31134. }
  31135. let target;
  31136. if (targetProp.type === 6) {
  31137. target = targetProp.value && createSimpleExpression(targetProp.value.content, true);
  31138. } else {
  31139. target = targetProp.exp;
  31140. }
  31141. if (!target) {
  31142. context.onError(
  31143. createSSRCompilerError(
  31144. 66,
  31145. targetProp.loc
  31146. )
  31147. );
  31148. return;
  31149. }
  31150. const disabledProp = findProp(
  31151. node,
  31152. "disabled",
  31153. false,
  31154. true
  31155. /* allow empty */
  31156. );
  31157. const disabled = disabledProp ? disabledProp.type === 6 ? `true` : disabledProp.exp || `false` : `false`;
  31158. const contentRenderFn = createFunctionExpression(
  31159. [`_push`],
  31160. void 0,
  31161. // Body is added later
  31162. true,
  31163. // newline
  31164. false,
  31165. // isSlot
  31166. node.loc
  31167. );
  31168. contentRenderFn.body = processChildrenAsStatement(node, context);
  31169. context.pushStatement(
  31170. createCallExpression(context.helper(SSR_RENDER_TELEPORT), [
  31171. `_push`,
  31172. contentRenderFn,
  31173. target,
  31174. disabled,
  31175. `_parent`
  31176. ])
  31177. );
  31178. }
  31179. const wipMap$3 = /* @__PURE__ */ new WeakMap();
  31180. function ssrTransformSuspense(node, context) {
  31181. return () => {
  31182. if (node.children.length) {
  31183. const wipEntry = {
  31184. slotsExp: null,
  31185. // to be immediately set
  31186. wipSlots: []
  31187. };
  31188. wipMap$3.set(node, wipEntry);
  31189. wipEntry.slotsExp = buildSlots(
  31190. node,
  31191. context,
  31192. (_props, _vForExp, children, loc) => {
  31193. const fn = createFunctionExpression(
  31194. [],
  31195. void 0,
  31196. // no return, assign body later
  31197. true,
  31198. // newline
  31199. false,
  31200. // suspense slots are not treated as normal slots
  31201. loc
  31202. );
  31203. wipEntry.wipSlots.push({
  31204. fn,
  31205. children
  31206. });
  31207. return fn;
  31208. }
  31209. ).slots;
  31210. }
  31211. };
  31212. }
  31213. function ssrProcessSuspense(node, context) {
  31214. const wipEntry = wipMap$3.get(node);
  31215. if (!wipEntry) {
  31216. return;
  31217. }
  31218. const { slotsExp, wipSlots } = wipEntry;
  31219. for (let i = 0; i < wipSlots.length; i++) {
  31220. const slot = wipSlots[i];
  31221. slot.fn.body = processChildrenAsStatement(slot, context);
  31222. }
  31223. context.pushStatement(
  31224. createCallExpression(context.helper(SSR_RENDER_SUSPENSE), [
  31225. `_push`,
  31226. slotsExp
  31227. ])
  31228. );
  31229. }
  31230. const rawChildrenMap = /* @__PURE__ */ new WeakMap();
  31231. const ssrTransformElement = (node, context) => {
  31232. if (node.type !== 1 || node.tagType !== 0) {
  31233. return;
  31234. }
  31235. return function ssrPostTransformElement() {
  31236. const openTag = [`<${node.tag}`];
  31237. const needTagForRuntime = node.tag === "textarea" || node.tag.indexOf("-") > 0;
  31238. const hasDynamicVBind = hasDynamicKeyVBind(node);
  31239. const hasCustomDir = node.props.some(
  31240. (p) => p.type === 7 && !isBuiltInDirective(p.name)
  31241. );
  31242. const vShowPropIndex = node.props.findIndex(
  31243. (i) => i.type === 7 && i.name === "show"
  31244. );
  31245. if (vShowPropIndex !== -1) {
  31246. const vShowProp = node.props[vShowPropIndex];
  31247. node.props.splice(vShowPropIndex, 1);
  31248. node.props.push(vShowProp);
  31249. }
  31250. const needMergeProps = hasDynamicVBind || hasCustomDir;
  31251. if (needMergeProps) {
  31252. const { props, directives } = buildProps(
  31253. node,
  31254. context,
  31255. node.props,
  31256. false,
  31257. false,
  31258. true
  31259. );
  31260. if (props || directives.length) {
  31261. const mergedProps = buildSSRProps(props, directives, context);
  31262. const propsExp = createCallExpression(
  31263. context.helper(SSR_RENDER_ATTRS),
  31264. [mergedProps]
  31265. );
  31266. if (node.tag === "textarea") {
  31267. const existingText = node.children[0];
  31268. if (!hasContentOverrideDirective(node) && (!existingText || existingText.type !== 5)) {
  31269. const tempId = `_temp${context.temps++}`;
  31270. propsExp.arguments = [
  31271. createAssignmentExpression(
  31272. createSimpleExpression(tempId, false),
  31273. mergedProps
  31274. )
  31275. ];
  31276. rawChildrenMap.set(
  31277. node,
  31278. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31279. createConditionalExpression(
  31280. createSimpleExpression(`"value" in ${tempId}`, false),
  31281. createSimpleExpression(`${tempId}.value`, false),
  31282. createSimpleExpression(
  31283. existingText ? existingText.content : ``,
  31284. true
  31285. ),
  31286. false
  31287. )
  31288. ])
  31289. );
  31290. }
  31291. } else if (node.tag === "input") {
  31292. const vModel = findVModel(node);
  31293. if (vModel) {
  31294. const tempId = `_temp${context.temps++}`;
  31295. const tempExp = createSimpleExpression(tempId, false);
  31296. propsExp.arguments = [
  31297. createSequenceExpression([
  31298. createAssignmentExpression(tempExp, mergedProps),
  31299. createCallExpression(context.helper(MERGE_PROPS), [
  31300. tempExp,
  31301. createCallExpression(
  31302. context.helper(SSR_GET_DYNAMIC_MODEL_PROPS),
  31303. [
  31304. tempExp,
  31305. // existing props
  31306. vModel.exp
  31307. // model
  31308. ]
  31309. )
  31310. ])
  31311. ])
  31312. ];
  31313. }
  31314. } else if (directives.length && !node.children.length) {
  31315. if (!hasContentOverrideDirective(node)) {
  31316. const tempId = `_temp${context.temps++}`;
  31317. propsExp.arguments = [
  31318. createAssignmentExpression(
  31319. createSimpleExpression(tempId, false),
  31320. mergedProps
  31321. )
  31322. ];
  31323. rawChildrenMap.set(
  31324. node,
  31325. createConditionalExpression(
  31326. createSimpleExpression(`"textContent" in ${tempId}`, false),
  31327. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31328. createSimpleExpression(`${tempId}.textContent`, false)
  31329. ]),
  31330. createSimpleExpression(`${tempId}.innerHTML ?? ''`, false),
  31331. false
  31332. )
  31333. );
  31334. }
  31335. }
  31336. if (needTagForRuntime) {
  31337. propsExp.arguments.push(`"${node.tag}"`);
  31338. }
  31339. openTag.push(propsExp);
  31340. }
  31341. }
  31342. let dynamicClassBinding = void 0;
  31343. let staticClassBinding = void 0;
  31344. let dynamicStyleBinding = void 0;
  31345. for (let i = 0; i < node.props.length; i++) {
  31346. const prop = node.props[i];
  31347. if (node.tag === "input" && isTrueFalseValue(prop)) {
  31348. continue;
  31349. }
  31350. if (prop.type === 7) {
  31351. if (prop.name === "html" && prop.exp) {
  31352. rawChildrenMap.set(
  31353. node,
  31354. createCompoundExpression([`(`, prop.exp, `) ?? ''`])
  31355. );
  31356. } else if (prop.name === "text" && prop.exp) {
  31357. node.children = [createInterpolation(prop.exp, prop.loc)];
  31358. } else if (prop.name === "slot") {
  31359. context.onError(
  31360. createCompilerError(40, prop.loc)
  31361. );
  31362. } else if (isTextareaWithValue(node, prop) && prop.exp) {
  31363. if (!needMergeProps) {
  31364. node.children = [createInterpolation(prop.exp, prop.loc)];
  31365. }
  31366. } else if (!needMergeProps && prop.name !== "on") {
  31367. const directiveTransform = context.directiveTransforms[prop.name];
  31368. if (directiveTransform) {
  31369. const { props, ssrTagParts } = directiveTransform(
  31370. prop,
  31371. node,
  31372. context
  31373. );
  31374. if (ssrTagParts) {
  31375. openTag.push(...ssrTagParts);
  31376. }
  31377. for (let j = 0; j < props.length; j++) {
  31378. const { key, value } = props[j];
  31379. if (isStaticExp(key)) {
  31380. let attrName = key.content;
  31381. if (attrName === "key" || attrName === "ref") {
  31382. continue;
  31383. }
  31384. if (attrName === "class") {
  31385. openTag.push(
  31386. ` class="`,
  31387. dynamicClassBinding = createCallExpression(
  31388. context.helper(SSR_RENDER_CLASS),
  31389. [value]
  31390. ),
  31391. `"`
  31392. );
  31393. } else if (attrName === "style") {
  31394. if (dynamicStyleBinding) {
  31395. mergeCall(dynamicStyleBinding, value);
  31396. } else {
  31397. openTag.push(
  31398. ` style="`,
  31399. dynamicStyleBinding = createCallExpression(
  31400. context.helper(SSR_RENDER_STYLE),
  31401. [value]
  31402. ),
  31403. `"`
  31404. );
  31405. }
  31406. } else {
  31407. attrName = node.tag.indexOf("-") > 0 ? attrName : propsToAttrMap[attrName] || attrName.toLowerCase();
  31408. if (isBooleanAttr(attrName)) {
  31409. openTag.push(
  31410. createConditionalExpression(
  31411. createCallExpression(
  31412. context.helper(SSR_INCLUDE_BOOLEAN_ATTR),
  31413. [value]
  31414. ),
  31415. createSimpleExpression(" " + attrName, true),
  31416. createSimpleExpression("", true),
  31417. false
  31418. )
  31419. );
  31420. } else if (isSSRSafeAttrName(attrName)) {
  31421. openTag.push(
  31422. createCallExpression(context.helper(SSR_RENDER_ATTR), [
  31423. key,
  31424. value
  31425. ])
  31426. );
  31427. } else {
  31428. context.onError(
  31429. createSSRCompilerError(
  31430. 65,
  31431. key.loc
  31432. )
  31433. );
  31434. }
  31435. }
  31436. } else {
  31437. const args = [key, value];
  31438. if (needTagForRuntime) {
  31439. args.push(`"${node.tag}"`);
  31440. }
  31441. openTag.push(
  31442. createCallExpression(
  31443. context.helper(SSR_RENDER_DYNAMIC_ATTR),
  31444. args
  31445. )
  31446. );
  31447. }
  31448. }
  31449. }
  31450. }
  31451. } else {
  31452. const name = prop.name;
  31453. if (node.tag === "textarea" && name === "value" && prop.value) {
  31454. rawChildrenMap.set(node, escapeHtml(prop.value.content));
  31455. } else if (!needMergeProps) {
  31456. if (name === "key" || name === "ref") {
  31457. continue;
  31458. }
  31459. if (name === "class" && prop.value) {
  31460. staticClassBinding = JSON.stringify(prop.value.content);
  31461. }
  31462. openTag.push(
  31463. ` ${prop.name}` + (prop.value ? `="${escapeHtml(prop.value.content)}"` : ``)
  31464. );
  31465. }
  31466. }
  31467. }
  31468. if (dynamicClassBinding && staticClassBinding) {
  31469. mergeCall(dynamicClassBinding, staticClassBinding);
  31470. removeStaticBinding(openTag, "class");
  31471. }
  31472. if (context.scopeId) {
  31473. openTag.push(` ${context.scopeId}`);
  31474. }
  31475. node.ssrCodegenNode = createTemplateLiteral(openTag);
  31476. };
  31477. };
  31478. function buildSSRProps(props, directives, context) {
  31479. let mergePropsArgs = [];
  31480. if (props) {
  31481. if (props.type === 14) {
  31482. mergePropsArgs = props.arguments;
  31483. } else {
  31484. mergePropsArgs.push(props);
  31485. }
  31486. }
  31487. if (directives.length) {
  31488. for (const dir of directives) {
  31489. mergePropsArgs.push(
  31490. createCallExpression(context.helper(SSR_GET_DIRECTIVE_PROPS), [
  31491. `_ctx`,
  31492. ...buildDirectiveArgs(dir, context).elements
  31493. ])
  31494. );
  31495. }
  31496. }
  31497. return mergePropsArgs.length > 1 ? createCallExpression(context.helper(MERGE_PROPS), mergePropsArgs) : mergePropsArgs[0];
  31498. }
  31499. function isTrueFalseValue(prop) {
  31500. if (prop.type === 7) {
  31501. return prop.name === "bind" && prop.arg && isStaticExp(prop.arg) && (prop.arg.content === "true-value" || prop.arg.content === "false-value");
  31502. } else {
  31503. return prop.name === "true-value" || prop.name === "false-value";
  31504. }
  31505. }
  31506. function isTextareaWithValue(node, prop) {
  31507. return !!(node.tag === "textarea" && prop.name === "bind" && isStaticArgOf(prop.arg, "value"));
  31508. }
  31509. function mergeCall(call, arg) {
  31510. const existing = call.arguments[0];
  31511. if (existing.type === 17) {
  31512. existing.elements.push(arg);
  31513. } else {
  31514. call.arguments[0] = createArrayExpression([existing, arg]);
  31515. }
  31516. }
  31517. function removeStaticBinding(tag, binding) {
  31518. const regExp = new RegExp(`^ ${binding}=".+"$`);
  31519. const i = tag.findIndex((e) => typeof e === "string" && regExp.test(e));
  31520. if (i > -1) {
  31521. tag.splice(i, 1);
  31522. }
  31523. }
  31524. function findVModel(node) {
  31525. return node.props.find(
  31526. (p) => p.type === 7 && p.name === "model" && p.exp
  31527. );
  31528. }
  31529. function hasContentOverrideDirective(node) {
  31530. return !!findDir(node, "text") || !!findDir(node, "html");
  31531. }
  31532. function ssrProcessElement(node, context) {
  31533. const isVoidTag = context.options.isVoidTag || NO;
  31534. const elementsToAdd = node.ssrCodegenNode.elements;
  31535. for (let j = 0; j < elementsToAdd.length; j++) {
  31536. context.pushStringPart(elementsToAdd[j]);
  31537. }
  31538. if (context.withSlotScopeId) {
  31539. context.pushStringPart(createSimpleExpression(`_scopeId`, false));
  31540. }
  31541. context.pushStringPart(`>`);
  31542. const rawChildren = rawChildrenMap.get(node);
  31543. if (rawChildren) {
  31544. context.pushStringPart(rawChildren);
  31545. } else if (node.children.length) {
  31546. processChildren(node, context);
  31547. }
  31548. if (!isVoidTag(node.tag)) {
  31549. context.pushStringPart(`</${node.tag}>`);
  31550. }
  31551. }
  31552. const wipMap$2 = /* @__PURE__ */ new WeakMap();
  31553. function ssrTransformTransitionGroup(node, context) {
  31554. return () => {
  31555. const tag = findProp(node, "tag");
  31556. if (tag) {
  31557. const otherProps = node.props.filter((p) => p !== tag);
  31558. const { props, directives } = buildProps(
  31559. node,
  31560. context,
  31561. otherProps,
  31562. true,
  31563. false,
  31564. true
  31565. );
  31566. let propsExp = null;
  31567. if (props || directives.length) {
  31568. propsExp = createCallExpression(context.helper(SSR_RENDER_ATTRS), [
  31569. buildSSRProps(props, directives, context)
  31570. ]);
  31571. }
  31572. wipMap$2.set(node, {
  31573. tag,
  31574. propsExp,
  31575. scopeId: context.scopeId || null
  31576. });
  31577. }
  31578. };
  31579. }
  31580. function ssrProcessTransitionGroup(node, context) {
  31581. const entry = wipMap$2.get(node);
  31582. if (entry) {
  31583. const { tag, propsExp, scopeId } = entry;
  31584. if (tag.type === 7) {
  31585. context.pushStringPart(`<`);
  31586. context.pushStringPart(tag.exp);
  31587. if (propsExp) {
  31588. context.pushStringPart(propsExp);
  31589. }
  31590. if (scopeId) {
  31591. context.pushStringPart(` ${scopeId}`);
  31592. }
  31593. context.pushStringPart(`>`);
  31594. processChildren(
  31595. node,
  31596. context,
  31597. false,
  31598. /**
  31599. * TransitionGroup has the special runtime behavior of flattening and
  31600. * concatenating all children into a single fragment (in order for them to
  31601. * be patched using the same key map) so we need to account for that here
  31602. * by disabling nested fragment wrappers from being generated.
  31603. */
  31604. true,
  31605. /**
  31606. * TransitionGroup filters out comment children at runtime and thus
  31607. * doesn't expect comments to be present during hydration. We need to
  31608. * account for that by disabling the empty comment that is otherwise
  31609. * rendered for a falsy v-if that has no v-else specified. (#6715)
  31610. */
  31611. true
  31612. );
  31613. context.pushStringPart(`</`);
  31614. context.pushStringPart(tag.exp);
  31615. context.pushStringPart(`>`);
  31616. } else {
  31617. context.pushStringPart(`<${tag.value.content}`);
  31618. if (propsExp) {
  31619. context.pushStringPart(propsExp);
  31620. }
  31621. if (scopeId) {
  31622. context.pushStringPart(` ${scopeId}`);
  31623. }
  31624. context.pushStringPart(`>`);
  31625. processChildren(node, context, false, true, true);
  31626. context.pushStringPart(`</${tag.value.content}>`);
  31627. }
  31628. } else {
  31629. processChildren(node, context, true, true, true);
  31630. }
  31631. }
  31632. const wipMap$1 = /* @__PURE__ */ new WeakMap();
  31633. function ssrTransformTransition(node, context) {
  31634. return () => {
  31635. const appear = findProp(node, "appear", false, true);
  31636. wipMap$1.set(node, !!appear);
  31637. };
  31638. }
  31639. function ssrProcessTransition(node, context) {
  31640. node.children = node.children.filter((c) => c.type !== 3);
  31641. const appear = wipMap$1.get(node);
  31642. if (appear) {
  31643. context.pushStringPart(`<template>`);
  31644. processChildren(node, context, false, true);
  31645. context.pushStringPart(`</template>`);
  31646. } else {
  31647. processChildren(node, context, false, true);
  31648. }
  31649. }
  31650. var __defProp$8 = Object.defineProperty;
  31651. var __defProps$7 = Object.defineProperties;
  31652. var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
  31653. var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
  31654. var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
  31655. var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
  31656. var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  31657. var __spreadValues$8 = (a, b) => {
  31658. for (var prop in b || (b = {}))
  31659. if (__hasOwnProp$8.call(b, prop))
  31660. __defNormalProp$8(a, prop, b[prop]);
  31661. if (__getOwnPropSymbols$8)
  31662. for (var prop of __getOwnPropSymbols$8(b)) {
  31663. if (__propIsEnum$8.call(b, prop))
  31664. __defNormalProp$8(a, prop, b[prop]);
  31665. }
  31666. return a;
  31667. };
  31668. var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
  31669. const wipMap = /* @__PURE__ */ new WeakMap();
  31670. const WIP_SLOT = /* @__PURE__ */ Symbol();
  31671. const componentTypeMap = /* @__PURE__ */ new WeakMap();
  31672. const ssrTransformComponent = (node, context) => {
  31673. if (node.type !== 1 || node.tagType !== 1) {
  31674. return;
  31675. }
  31676. const component = resolveComponentType(
  31677. node,
  31678. context,
  31679. true
  31680. /* ssr */
  31681. );
  31682. const isDynamicComponent = isObject$2(component) && component.callee === RESOLVE_DYNAMIC_COMPONENT;
  31683. componentTypeMap.set(node, component);
  31684. if (isSymbol$1(component)) {
  31685. if (component === SUSPENSE) {
  31686. return ssrTransformSuspense(node, context);
  31687. } else if (component === TRANSITION_GROUP) {
  31688. return ssrTransformTransitionGroup(node, context);
  31689. } else if (component === TRANSITION) {
  31690. return ssrTransformTransition(node);
  31691. }
  31692. return;
  31693. }
  31694. const vnodeBranches = [];
  31695. const clonedNode = clone(node);
  31696. return function ssrPostTransformComponent() {
  31697. if (clonedNode.children.length) {
  31698. buildSlots(clonedNode, context, (props, vFor, children) => {
  31699. vnodeBranches.push(
  31700. createVNodeSlotBranch(props, vFor, children, context)
  31701. );
  31702. return createFunctionExpression(void 0);
  31703. });
  31704. }
  31705. let propsExp = `null`;
  31706. if (node.props.length) {
  31707. const { props, directives } = buildProps(
  31708. node,
  31709. context,
  31710. void 0,
  31711. true,
  31712. isDynamicComponent
  31713. );
  31714. if (props || directives.length) {
  31715. propsExp = buildSSRProps(props, directives, context);
  31716. }
  31717. }
  31718. const wipEntries = [];
  31719. wipMap.set(node, wipEntries);
  31720. const buildSSRSlotFn = (props, _vForExp, children, loc) => {
  31721. const param0 = props && stringifyExpression(props) || `_`;
  31722. const fn = createFunctionExpression(
  31723. [param0, `_push`, `_parent`, `_scopeId`],
  31724. void 0,
  31725. // no return, assign body later
  31726. true,
  31727. // newline
  31728. true,
  31729. // isSlot
  31730. loc
  31731. );
  31732. wipEntries.push({
  31733. type: WIP_SLOT,
  31734. fn,
  31735. children,
  31736. // also collect the corresponding vnode branch built earlier
  31737. vnodeBranch: vnodeBranches[wipEntries.length]
  31738. });
  31739. return fn;
  31740. };
  31741. const slots = node.children.length ? buildSlots(node, context, buildSSRSlotFn).slots : `null`;
  31742. if (typeof component !== "string") {
  31743. node.ssrCodegenNode = createCallExpression(
  31744. context.helper(SSR_RENDER_VNODE),
  31745. [
  31746. `_push`,
  31747. createCallExpression(context.helper(CREATE_VNODE), [
  31748. component,
  31749. propsExp,
  31750. slots
  31751. ]),
  31752. `_parent`
  31753. ]
  31754. );
  31755. } else {
  31756. node.ssrCodegenNode = createCallExpression(
  31757. context.helper(SSR_RENDER_COMPONENT),
  31758. [component, propsExp, slots, `_parent`]
  31759. );
  31760. }
  31761. };
  31762. };
  31763. function ssrProcessComponent(node, context, parent) {
  31764. const component = componentTypeMap.get(node);
  31765. if (!node.ssrCodegenNode) {
  31766. if (component === TELEPORT) {
  31767. return ssrProcessTeleport(node, context);
  31768. } else if (component === SUSPENSE) {
  31769. return ssrProcessSuspense(node, context);
  31770. } else if (component === TRANSITION_GROUP) {
  31771. return ssrProcessTransitionGroup(node, context);
  31772. } else {
  31773. if (parent.type === WIP_SLOT) {
  31774. context.pushStringPart(``);
  31775. }
  31776. if (component === TRANSITION) {
  31777. return ssrProcessTransition(node, context);
  31778. }
  31779. processChildren(node, context);
  31780. }
  31781. } else {
  31782. const wipEntries = wipMap.get(node) || [];
  31783. for (let i = 0; i < wipEntries.length; i++) {
  31784. const { fn, vnodeBranch } = wipEntries[i];
  31785. fn.body = createIfStatement(
  31786. createSimpleExpression(`_push`, false),
  31787. processChildrenAsStatement(
  31788. wipEntries[i],
  31789. context,
  31790. false,
  31791. true
  31792. ),
  31793. vnodeBranch
  31794. );
  31795. }
  31796. if (context.withSlotScopeId) {
  31797. node.ssrCodegenNode.arguments.push(`_scopeId`);
  31798. }
  31799. if (typeof component === "string") {
  31800. context.pushStatement(
  31801. createCallExpression(`_push`, [node.ssrCodegenNode])
  31802. );
  31803. } else {
  31804. context.pushStatement(node.ssrCodegenNode);
  31805. }
  31806. }
  31807. }
  31808. const rawOptionsMap = /* @__PURE__ */ new WeakMap();
  31809. const [baseNodeTransforms, baseDirectiveTransforms] = getBaseTransformPreset(true);
  31810. const vnodeNodeTransforms = [...baseNodeTransforms, ...DOMNodeTransforms];
  31811. const vnodeDirectiveTransforms = __spreadValues$8(__spreadValues$8({}, baseDirectiveTransforms), DOMDirectiveTransforms);
  31812. function createVNodeSlotBranch(slotProps, vFor, children, parentContext) {
  31813. const rawOptions = rawOptionsMap.get(parentContext.root);
  31814. const subOptions = __spreadProps$7(__spreadValues$8({}, rawOptions), {
  31815. // overwrite with vnode-based transforms
  31816. nodeTransforms: [
  31817. ...vnodeNodeTransforms,
  31818. ...rawOptions.nodeTransforms || []
  31819. ],
  31820. directiveTransforms: __spreadValues$8(__spreadValues$8({}, vnodeDirectiveTransforms), rawOptions.directiveTransforms || {})
  31821. });
  31822. const wrapperProps = [];
  31823. if (slotProps) {
  31824. wrapperProps.push({
  31825. type: 7,
  31826. name: "slot",
  31827. exp: slotProps,
  31828. arg: void 0,
  31829. modifiers: [],
  31830. loc: locStub
  31831. });
  31832. }
  31833. if (vFor) {
  31834. wrapperProps.push(extend({}, vFor));
  31835. }
  31836. const wrapperNode = {
  31837. type: 1,
  31838. ns: 0,
  31839. tag: "template",
  31840. tagType: 3,
  31841. props: wrapperProps,
  31842. children,
  31843. loc: locStub,
  31844. codegenNode: void 0
  31845. };
  31846. subTransform(wrapperNode, subOptions, parentContext);
  31847. return createReturnStatement(children);
  31848. }
  31849. function subTransform(node, options, parentContext) {
  31850. const childRoot = createRoot([node]);
  31851. const childContext = createTransformContext(childRoot, options);
  31852. childContext.ssr = false;
  31853. childContext.scopes = __spreadValues$8({}, parentContext.scopes);
  31854. childContext.identifiers = __spreadValues$8({}, parentContext.identifiers);
  31855. childContext.imports = parentContext.imports;
  31856. traverseNode(childRoot, childContext);
  31857. ["helpers", "components", "directives"].forEach((key) => {
  31858. childContext[key].forEach((value, helperKey) => {
  31859. if (key === "helpers") {
  31860. const parentCount = parentContext.helpers.get(helperKey);
  31861. if (parentCount === void 0) {
  31862. parentContext.helpers.set(helperKey, value);
  31863. } else {
  31864. parentContext.helpers.set(helperKey, value + parentCount);
  31865. }
  31866. } else {
  31867. parentContext[key].add(value);
  31868. }
  31869. });
  31870. });
  31871. }
  31872. function clone(v) {
  31873. if (isArray$3(v)) {
  31874. return v.map(clone);
  31875. } else if (isPlainObject(v)) {
  31876. const res = {};
  31877. for (const key in v) {
  31878. res[key] = clone(v[key]);
  31879. }
  31880. return res;
  31881. } else {
  31882. return v;
  31883. }
  31884. }
  31885. function ssrCodegenTransform(ast, options) {
  31886. const context = createSSRTransformContext(ast, options);
  31887. if (options.ssrCssVars) {
  31888. const cssContext = createTransformContext(createRoot([]), options);
  31889. const varsExp = processExpression(
  31890. createSimpleExpression(options.ssrCssVars, false),
  31891. cssContext
  31892. );
  31893. context.body.push(
  31894. createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`])
  31895. );
  31896. Array.from(cssContext.helpers.keys()).forEach((helper) => {
  31897. ast.helpers.add(helper);
  31898. });
  31899. }
  31900. const isFragment = ast.children.length > 1 && ast.children.some((c) => !isText$1(c));
  31901. processChildren(ast, context, isFragment);
  31902. ast.codegenNode = createBlockStatement(context.body);
  31903. ast.ssrHelpers = Array.from(
  31904. /* @__PURE__ */ new Set([
  31905. ...Array.from(ast.helpers).filter((h) => h in ssrHelpers),
  31906. ...context.helpers
  31907. ])
  31908. );
  31909. ast.helpers = new Set(Array.from(ast.helpers).filter((h) => !(h in ssrHelpers)));
  31910. }
  31911. function createSSRTransformContext(root, options, helpers = /* @__PURE__ */ new Set(), withSlotScopeId = false) {
  31912. const body = [];
  31913. let currentString = null;
  31914. return {
  31915. root,
  31916. options,
  31917. body,
  31918. helpers,
  31919. withSlotScopeId,
  31920. onError: options.onError || ((e) => {
  31921. throw e;
  31922. }),
  31923. helper(name) {
  31924. helpers.add(name);
  31925. return name;
  31926. },
  31927. pushStringPart(part) {
  31928. if (!currentString) {
  31929. const currentCall = createCallExpression(`_push`);
  31930. body.push(currentCall);
  31931. currentString = createTemplateLiteral([]);
  31932. currentCall.arguments.push(currentString);
  31933. }
  31934. const bufferedElements = currentString.elements;
  31935. const lastItem = bufferedElements[bufferedElements.length - 1];
  31936. if (isString$1(part) && isString$1(lastItem)) {
  31937. bufferedElements[bufferedElements.length - 1] += part;
  31938. } else {
  31939. bufferedElements.push(part);
  31940. }
  31941. },
  31942. pushStatement(statement) {
  31943. currentString = null;
  31944. body.push(statement);
  31945. }
  31946. };
  31947. }
  31948. function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
  31949. return createSSRTransformContext(
  31950. parent.root,
  31951. parent.options,
  31952. parent.helpers,
  31953. withSlotScopeId
  31954. );
  31955. }
  31956. function processChildren(parent, context, asFragment = false, disableNestedFragments = false, disableComment = false) {
  31957. if (asFragment) {
  31958. context.pushStringPart(`<!--[-->`);
  31959. }
  31960. const { children } = parent;
  31961. for (let i = 0; i < children.length; i++) {
  31962. const child = children[i];
  31963. switch (child.type) {
  31964. case 1:
  31965. switch (child.tagType) {
  31966. case 0:
  31967. ssrProcessElement(child, context);
  31968. break;
  31969. case 1:
  31970. ssrProcessComponent(child, context, parent);
  31971. break;
  31972. case 2:
  31973. ssrProcessSlotOutlet(child, context);
  31974. break;
  31975. case 3:
  31976. break;
  31977. default:
  31978. context.onError(
  31979. createSSRCompilerError(
  31980. 67,
  31981. child.loc
  31982. )
  31983. );
  31984. const exhaustiveCheck2 = child;
  31985. return exhaustiveCheck2;
  31986. }
  31987. break;
  31988. case 2:
  31989. context.pushStringPart(escapeHtml(child.content));
  31990. break;
  31991. case 3:
  31992. if (!disableComment) {
  31993. context.pushStringPart(`<!--${child.content}-->`);
  31994. }
  31995. break;
  31996. case 5:
  31997. context.pushStringPart(
  31998. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31999. child.content
  32000. ])
  32001. );
  32002. break;
  32003. case 9:
  32004. ssrProcessIf(child, context, disableNestedFragments, disableComment);
  32005. break;
  32006. case 11:
  32007. ssrProcessFor(child, context, disableNestedFragments);
  32008. break;
  32009. case 10:
  32010. break;
  32011. case 12:
  32012. case 8:
  32013. break;
  32014. default:
  32015. context.onError(
  32016. createSSRCompilerError(
  32017. 67,
  32018. child.loc
  32019. )
  32020. );
  32021. const exhaustiveCheck = child;
  32022. return exhaustiveCheck;
  32023. }
  32024. }
  32025. if (asFragment) {
  32026. context.pushStringPart(`<!--]-->`);
  32027. }
  32028. }
  32029. function processChildrenAsStatement(parent, parentContext, asFragment = false, withSlotScopeId = parentContext.withSlotScopeId) {
  32030. const childContext = createChildContext(parentContext, withSlotScopeId);
  32031. processChildren(parent, childContext, asFragment);
  32032. return createBlockStatement(childContext.body);
  32033. }
  32034. const ssrTransformModel = (dir, node, context) => {
  32035. const model = dir.exp;
  32036. function checkDuplicatedValue() {
  32037. const value = findProp(node, "value");
  32038. if (value) {
  32039. context.onError(
  32040. createDOMCompilerError(
  32041. 61,
  32042. value.loc
  32043. )
  32044. );
  32045. }
  32046. }
  32047. const processSelectChildren = (children) => {
  32048. children.forEach((child) => {
  32049. if (child.type === 1) {
  32050. processOption(child);
  32051. } else if (child.type === 11) {
  32052. processSelectChildren(child.children);
  32053. } else if (child.type === 9) {
  32054. child.branches.forEach((b) => processSelectChildren(b.children));
  32055. }
  32056. });
  32057. };
  32058. function processOption(plainNode) {
  32059. if (plainNode.tag === "option") {
  32060. if (plainNode.props.findIndex((p) => p.name === "selected") === -1) {
  32061. const value = findValueBinding(plainNode);
  32062. plainNode.ssrCodegenNode.elements.push(
  32063. createConditionalExpression(
  32064. createCallExpression(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [
  32065. createConditionalExpression(
  32066. createCallExpression(`Array.isArray`, [model]),
  32067. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  32068. model,
  32069. value
  32070. ]),
  32071. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  32072. model,
  32073. value
  32074. ])
  32075. )
  32076. ]),
  32077. createSimpleExpression(" selected", true),
  32078. createSimpleExpression("", true),
  32079. false
  32080. )
  32081. );
  32082. }
  32083. } else if (plainNode.tag === "optgroup") {
  32084. processSelectChildren(plainNode.children);
  32085. }
  32086. }
  32087. if (node.tagType === 0) {
  32088. const res = { props: [] };
  32089. if (node.tag === "input") {
  32090. const defaultProps = [
  32091. // default value binding for text type inputs
  32092. createObjectProperty(`value`, model)
  32093. ];
  32094. const type = findProp(node, "type");
  32095. if (type) {
  32096. const value = findValueBinding(node);
  32097. if (type.type === 7) {
  32098. res.ssrTagParts = [
  32099. createCallExpression(context.helper(SSR_RENDER_DYNAMIC_MODEL), [
  32100. type.exp,
  32101. model,
  32102. value
  32103. ])
  32104. ];
  32105. } else if (type.value) {
  32106. switch (type.value.content) {
  32107. case "radio":
  32108. res.props = [
  32109. createObjectProperty(
  32110. `checked`,
  32111. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  32112. model,
  32113. value
  32114. ])
  32115. )
  32116. ];
  32117. break;
  32118. case "checkbox":
  32119. const trueValueBinding = findProp(node, "true-value");
  32120. if (trueValueBinding) {
  32121. const trueValue = trueValueBinding.type === 6 ? JSON.stringify(trueValueBinding.value.content) : trueValueBinding.exp;
  32122. res.props = [
  32123. createObjectProperty(
  32124. `checked`,
  32125. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  32126. model,
  32127. trueValue
  32128. ])
  32129. )
  32130. ];
  32131. } else {
  32132. res.props = [
  32133. createObjectProperty(
  32134. `checked`,
  32135. createConditionalExpression(
  32136. createCallExpression(`Array.isArray`, [model]),
  32137. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  32138. model,
  32139. value
  32140. ]),
  32141. model
  32142. )
  32143. )
  32144. ];
  32145. }
  32146. break;
  32147. case "file":
  32148. context.onError(
  32149. createDOMCompilerError(
  32150. 60,
  32151. dir.loc
  32152. )
  32153. );
  32154. break;
  32155. default:
  32156. checkDuplicatedValue();
  32157. res.props = defaultProps;
  32158. break;
  32159. }
  32160. }
  32161. } else if (hasDynamicKeyVBind(node)) ; else {
  32162. checkDuplicatedValue();
  32163. res.props = defaultProps;
  32164. }
  32165. } else if (node.tag === "textarea") {
  32166. checkDuplicatedValue();
  32167. node.children = [createInterpolation(model, model.loc)];
  32168. } else if (node.tag === "select") {
  32169. processSelectChildren(node.children);
  32170. } else {
  32171. context.onError(
  32172. createDOMCompilerError(
  32173. 58,
  32174. dir.loc
  32175. )
  32176. );
  32177. }
  32178. return res;
  32179. } else {
  32180. return transformModel$1(dir, node, context);
  32181. }
  32182. };
  32183. function findValueBinding(node) {
  32184. const valueBinding = findProp(node, "value");
  32185. return valueBinding ? valueBinding.type === 7 ? valueBinding.exp : createSimpleExpression(valueBinding.value.content, true) : createSimpleExpression(`null`, false);
  32186. }
  32187. const ssrTransformShow = (dir, node, context) => {
  32188. if (!dir.exp) {
  32189. context.onError(
  32190. createDOMCompilerError(62)
  32191. );
  32192. }
  32193. return {
  32194. props: [
  32195. createObjectProperty(
  32196. `style`,
  32197. createConditionalExpression(
  32198. dir.exp,
  32199. createSimpleExpression(`null`, false),
  32200. createObjectExpression([
  32201. createObjectProperty(
  32202. `display`,
  32203. createSimpleExpression(`none`, true)
  32204. )
  32205. ]),
  32206. false
  32207. )
  32208. )
  32209. ]
  32210. };
  32211. };
  32212. const filterChild = (node) => node.children.filter((n) => !isCommentOrWhitespace(n));
  32213. const hasSingleChild = (node) => filterChild(node).length === 1;
  32214. const ssrInjectFallthroughAttrs = (node, context) => {
  32215. if (node.type === 0) {
  32216. context.identifiers._attrs = 1;
  32217. }
  32218. if (node.type === 1 && node.tagType === 1 && (node.tag === "transition" || node.tag === "Transition" || node.tag === "KeepAlive" || node.tag === "keep-alive")) {
  32219. const rootChildren = filterChild(context.root);
  32220. if (rootChildren.length === 1 && rootChildren[0] === node) {
  32221. if (hasSingleChild(node)) {
  32222. injectFallthroughAttrs(node.children[0]);
  32223. }
  32224. return;
  32225. }
  32226. }
  32227. const parent = context.parent;
  32228. if (!parent || parent.type !== 0) {
  32229. return;
  32230. }
  32231. if (node.type === 10 && hasSingleChild(node)) {
  32232. let hasEncounteredIf = false;
  32233. for (const c of filterChild(parent)) {
  32234. if (c.type === 9 || c.type === 1 && findDir(c, "if")) {
  32235. if (hasEncounteredIf) return;
  32236. hasEncounteredIf = true;
  32237. } else if (
  32238. // node before v-if
  32239. !hasEncounteredIf || // non else nodes
  32240. !(c.type === 1 && findDir(c, /else/, true))
  32241. ) {
  32242. return;
  32243. }
  32244. }
  32245. injectFallthroughAttrs(node.children[0]);
  32246. } else if (hasSingleChild(parent)) {
  32247. injectFallthroughAttrs(node);
  32248. }
  32249. };
  32250. function injectFallthroughAttrs(node) {
  32251. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  32252. node.props.push({
  32253. type: 7,
  32254. name: "bind",
  32255. arg: void 0,
  32256. exp: createSimpleExpression(`_attrs`, false),
  32257. modifiers: [],
  32258. loc: locStub
  32259. });
  32260. }
  32261. }
  32262. const ssrInjectCssVars = (node, context) => {
  32263. if (!context.ssrCssVars) {
  32264. return;
  32265. }
  32266. if (node.type === 0) {
  32267. context.identifiers._cssVars = 1;
  32268. }
  32269. const parent = context.parent;
  32270. if (!parent || parent.type !== 0) {
  32271. return;
  32272. }
  32273. if (node.type === 10) {
  32274. for (const child of node.children) {
  32275. injectCssVars(child);
  32276. }
  32277. } else {
  32278. injectCssVars(node);
  32279. }
  32280. };
  32281. function injectCssVars(node) {
  32282. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  32283. if (node.tag === "suspense" || node.tag === "Suspense") {
  32284. for (const child of node.children) {
  32285. if (child.type === 1 && child.tagType === 3) {
  32286. child.children.forEach(injectCssVars);
  32287. } else {
  32288. injectCssVars(child);
  32289. }
  32290. }
  32291. } else {
  32292. node.props.push({
  32293. type: 7,
  32294. name: "bind",
  32295. arg: void 0,
  32296. exp: createSimpleExpression(`_cssVars`, false),
  32297. modifiers: [],
  32298. loc: locStub
  32299. });
  32300. }
  32301. }
  32302. }
  32303. var __defProp$7 = Object.defineProperty;
  32304. var __defProps$6 = Object.defineProperties;
  32305. var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
  32306. var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
  32307. var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
  32308. var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
  32309. var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  32310. var __spreadValues$7 = (a, b) => {
  32311. for (var prop in b || (b = {}))
  32312. if (__hasOwnProp$7.call(b, prop))
  32313. __defNormalProp$7(a, prop, b[prop]);
  32314. if (__getOwnPropSymbols$7)
  32315. for (var prop of __getOwnPropSymbols$7(b)) {
  32316. if (__propIsEnum$7.call(b, prop))
  32317. __defNormalProp$7(a, prop, b[prop]);
  32318. }
  32319. return a;
  32320. };
  32321. var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
  32322. function compile(source, options = {}) {
  32323. options = __spreadProps$6(__spreadValues$7(__spreadValues$7({}, options), parserOptions), {
  32324. ssr: true,
  32325. inSSR: true,
  32326. scopeId: options.mode === "function" ? null : options.scopeId,
  32327. // always prefix since compiler-ssr doesn't have size concern
  32328. prefixIdentifiers: true,
  32329. // disable optimizations that are unnecessary for ssr
  32330. cacheHandlers: false,
  32331. hoistStatic: false
  32332. });
  32333. const ast = typeof source === "string" ? baseParse(source, options) : source;
  32334. rawOptionsMap.set(ast, options);
  32335. transform(ast, __spreadProps$6(__spreadValues$7({}, options), {
  32336. hoistStatic: false,
  32337. nodeTransforms: [
  32338. transformVBindShorthand,
  32339. ssrTransformIf,
  32340. ssrTransformFor,
  32341. trackVForSlotScopes,
  32342. transformExpression,
  32343. ssrTransformSlotOutlet,
  32344. ssrInjectFallthroughAttrs,
  32345. ssrInjectCssVars,
  32346. ssrTransformElement,
  32347. ssrTransformComponent,
  32348. trackSlotScopes,
  32349. transformStyle,
  32350. ...options.nodeTransforms || []
  32351. // user transforms
  32352. ],
  32353. directiveTransforms: __spreadValues$7({
  32354. // reusing core v-bind
  32355. bind: transformBind,
  32356. on: transformOn$1,
  32357. // model and show have dedicated SSR handling
  32358. model: ssrTransformModel,
  32359. show: ssrTransformShow,
  32360. // the following are ignored during SSR
  32361. // on: noopDirectiveTransform,
  32362. cloak: noopDirectiveTransform,
  32363. once: noopDirectiveTransform,
  32364. memo: noopDirectiveTransform
  32365. }, options.directiveTransforms || {})
  32366. }));
  32367. ssrCodegenTransform(ast, options);
  32368. return generate(ast, options);
  32369. }
  32370. var CompilerSSR = /*#__PURE__*/Object.freeze({
  32371. __proto__: null,
  32372. compile: compile
  32373. });
  32374. var _polyfillNode_fs = {};
  32375. var _polyfillNode_fs$1 = /*#__PURE__*/Object.freeze({
  32376. __proto__: null,
  32377. default: _polyfillNode_fs
  32378. });
  32379. var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_fs$1);
  32380. var require$$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_path);
  32381. var require$$0 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_util$1);
  32382. const hasWarned = {};
  32383. function warnOnce$1(msg) {
  32384. const isNodeProd = typeof process !== "undefined" && process.env.NODE_ENV === "production";
  32385. if (!isNodeProd && true && !hasWarned[msg]) {
  32386. hasWarned[msg] = true;
  32387. warn(msg);
  32388. }
  32389. }
  32390. function warn(msg) {
  32391. console.warn(
  32392. `\x1B[1m\x1B[33m[@vue/compiler-sfc]\x1B[0m\x1B[33m ${msg}\x1B[0m
  32393. `
  32394. );
  32395. }
  32396. var __defProp$6 = Object.defineProperty;
  32397. var __defProps$5 = Object.defineProperties;
  32398. var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
  32399. var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
  32400. var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
  32401. var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
  32402. var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  32403. var __spreadValues$6 = (a, b) => {
  32404. for (var prop in b || (b = {}))
  32405. if (__hasOwnProp$6.call(b, prop))
  32406. __defNormalProp$6(a, prop, b[prop]);
  32407. if (__getOwnPropSymbols$6)
  32408. for (var prop of __getOwnPropSymbols$6(b)) {
  32409. if (__propIsEnum$6.call(b, prop))
  32410. __defNormalProp$6(a, prop, b[prop]);
  32411. }
  32412. return a;
  32413. };
  32414. var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
  32415. function preprocess$1({ source, filename, preprocessOptions }, preprocessor) {
  32416. let res = "";
  32417. let err = null;
  32418. preprocessor.render(
  32419. source,
  32420. __spreadValues$6({ filename }, preprocessOptions),
  32421. (_err, _res) => {
  32422. if (_err) err = _err;
  32423. res = _res;
  32424. }
  32425. );
  32426. if (err) throw err;
  32427. return res;
  32428. }
  32429. function compileTemplate(options) {
  32430. const { preprocessLang, preprocessCustomRequire } = options;
  32431. if (preprocessLang && !preprocessCustomRequire) {
  32432. throw new Error(
  32433. `[@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 }.`
  32434. );
  32435. }
  32436. const preprocessor = preprocessLang ? preprocessCustomRequire ? preprocessCustomRequire(preprocessLang) : void 0 : false;
  32437. if (preprocessor) {
  32438. try {
  32439. return doCompileTemplate(__spreadProps$5(__spreadValues$6({}, options), {
  32440. source: preprocess$1(options, preprocessor),
  32441. ast: void 0
  32442. // invalidate AST if template goes through preprocessor
  32443. }));
  32444. } catch (e) {
  32445. return {
  32446. code: `export default function render() {}`,
  32447. source: options.source,
  32448. tips: [],
  32449. errors: [e]
  32450. };
  32451. }
  32452. } else if (preprocessLang) {
  32453. return {
  32454. code: `export default function render() {}`,
  32455. source: options.source,
  32456. tips: [
  32457. `Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`
  32458. ],
  32459. errors: [
  32460. `Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`
  32461. ]
  32462. };
  32463. } else {
  32464. return doCompileTemplate(options);
  32465. }
  32466. }
  32467. function doCompileTemplate({
  32468. filename,
  32469. id,
  32470. scoped,
  32471. slotted,
  32472. inMap,
  32473. source,
  32474. ast: inAST,
  32475. ssr = false,
  32476. ssrCssVars,
  32477. isProd = false,
  32478. compiler,
  32479. compilerOptions = {},
  32480. transformAssetUrls
  32481. }) {
  32482. const errors = [];
  32483. const warnings = [];
  32484. let nodeTransforms = [];
  32485. if (isObject$2(transformAssetUrls)) {
  32486. const assetOptions = normalizeOptions(transformAssetUrls);
  32487. nodeTransforms = [
  32488. createAssetUrlTransformWithOptions(assetOptions),
  32489. createSrcsetTransformWithOptions(assetOptions)
  32490. ];
  32491. } else if (transformAssetUrls !== false) {
  32492. nodeTransforms = [transformAssetUrl, transformSrcset];
  32493. }
  32494. if (ssr && !ssrCssVars) {
  32495. warnOnce$1(
  32496. `compileTemplate is called with \`ssr: true\` but no corresponding \`cssVars\` option.`
  32497. );
  32498. }
  32499. if (!id) {
  32500. warnOnce$1(`compileTemplate now requires the \`id\` option.`);
  32501. id = "";
  32502. }
  32503. const shortId = id.replace(/^data-v-/, "");
  32504. const longId = `data-v-${shortId}`;
  32505. const defaultCompiler = ssr ? CompilerSSR : CompilerDOM;
  32506. compiler = compiler || defaultCompiler;
  32507. if (compiler !== defaultCompiler) {
  32508. inAST = void 0;
  32509. }
  32510. if (inAST == null ? void 0 : inAST.transformed) {
  32511. const newAST = (ssr ? CompilerDOM : compiler).parse(inAST.source, __spreadProps$5(__spreadValues$6({
  32512. prefixIdentifiers: true
  32513. }, compilerOptions), {
  32514. parseMode: "sfc",
  32515. onError: (e) => errors.push(e)
  32516. }));
  32517. const template = newAST.children.find(
  32518. (node) => node.type === 1 && node.tag === "template"
  32519. );
  32520. inAST = createRoot(template.children, inAST.source);
  32521. }
  32522. let { code, ast, preamble, map } = compiler.compile(inAST || source, __spreadProps$5(__spreadValues$6({
  32523. mode: "module",
  32524. prefixIdentifiers: true,
  32525. hoistStatic: true,
  32526. cacheHandlers: true,
  32527. ssrCssVars: ssr && ssrCssVars && ssrCssVars.length ? genCssVarsFromList(ssrCssVars, shortId, isProd, true) : "",
  32528. scopeId: scoped ? longId : void 0,
  32529. slotted,
  32530. sourceMap: true
  32531. }, compilerOptions), {
  32532. hmr: !isProd,
  32533. nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
  32534. filename,
  32535. onError: (e) => errors.push(e),
  32536. onWarn: (w) => warnings.push(w)
  32537. }));
  32538. if (inMap && !inAST) {
  32539. if (map) {
  32540. map = mapLines(inMap, map);
  32541. }
  32542. if (errors.length) {
  32543. patchErrors(errors, source, inMap);
  32544. }
  32545. }
  32546. const tips = warnings.map((w) => {
  32547. let msg = w.message;
  32548. if (w.loc) {
  32549. msg += `
  32550. ${generateCodeFrame(
  32551. (inAST == null ? void 0 : inAST.source) || source,
  32552. w.loc.start.offset,
  32553. w.loc.end.offset
  32554. )}`;
  32555. }
  32556. return msg;
  32557. });
  32558. return { code, ast, preamble, source, errors, tips, map };
  32559. }
  32560. function mapLines(oldMap, newMap) {
  32561. if (!oldMap) return newMap;
  32562. if (!newMap) return oldMap;
  32563. const oldMapConsumer = new sourceMapExports.SourceMapConsumer(oldMap);
  32564. const newMapConsumer = new sourceMapExports.SourceMapConsumer(newMap);
  32565. const mergedMapGenerator = new sourceMapExports.SourceMapGenerator();
  32566. newMapConsumer.eachMapping((m) => {
  32567. if (m.originalLine == null) {
  32568. return;
  32569. }
  32570. const origPosInOldMap = oldMapConsumer.originalPositionFor({
  32571. line: m.originalLine,
  32572. column: m.originalColumn
  32573. });
  32574. if (origPosInOldMap.source == null) {
  32575. return;
  32576. }
  32577. mergedMapGenerator.addMapping({
  32578. generated: {
  32579. line: m.generatedLine,
  32580. column: m.generatedColumn
  32581. },
  32582. original: {
  32583. line: origPosInOldMap.line,
  32584. // map line
  32585. // use current column, since the oldMap produced by @vue/compiler-sfc
  32586. // does not
  32587. column: m.originalColumn
  32588. },
  32589. source: origPosInOldMap.source,
  32590. name: origPosInOldMap.name
  32591. });
  32592. });
  32593. const generator = mergedMapGenerator;
  32594. oldMapConsumer.sources.forEach((sourceFile) => {
  32595. generator._sources.add(sourceFile);
  32596. const sourceContent = oldMapConsumer.sourceContentFor(sourceFile);
  32597. if (sourceContent != null) {
  32598. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  32599. }
  32600. });
  32601. generator._sourceRoot = oldMap.sourceRoot;
  32602. generator._file = oldMap.file;
  32603. return generator.toJSON();
  32604. }
  32605. function patchErrors(errors, source, inMap) {
  32606. const originalSource = inMap.sourcesContent[0];
  32607. const offset = originalSource.indexOf(source);
  32608. const lineOffset = originalSource.slice(0, offset).split(/\r?\n/).length - 1;
  32609. errors.forEach((err) => {
  32610. if (err.loc) {
  32611. err.loc.start.line += lineOffset;
  32612. err.loc.start.offset += offset;
  32613. if (err.loc.end !== err.loc.start) {
  32614. err.loc.end.line += lineOffset;
  32615. err.loc.end.offset += offset;
  32616. }
  32617. }
  32618. });
  32619. }
  32620. var picocolors = {exports: {}};
  32621. var hasRequiredPicocolors;
  32622. function requirePicocolors () {
  32623. if (hasRequiredPicocolors) return picocolors.exports;
  32624. hasRequiredPicocolors = 1;
  32625. let p = browser$1 || {}, argv = p.argv || [], env = p.env || {};
  32626. let isColorSupported =
  32627. !(!!env.NO_COLOR || argv.includes("--no-color")) &&
  32628. (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || ((p.stdout || {}).isTTY && env.TERM !== "dumb") || !!env.CI);
  32629. let formatter = (open, close, replace = open) =>
  32630. input => {
  32631. let string = "" + input, index = string.indexOf(close, open.length);
  32632. return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close
  32633. };
  32634. let replaceClose = (string, close, replace, index) => {
  32635. let result = "", cursor = 0;
  32636. do {
  32637. result += string.substring(cursor, index) + replace;
  32638. cursor = index + close.length;
  32639. index = string.indexOf(close, cursor);
  32640. } while (~index)
  32641. return result + string.substring(cursor)
  32642. };
  32643. let createColors = (enabled = isColorSupported) => {
  32644. let f = enabled ? formatter : () => String;
  32645. return {
  32646. isColorSupported: enabled,
  32647. reset: f("\x1b[0m", "\x1b[0m"),
  32648. bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
  32649. dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
  32650. italic: f("\x1b[3m", "\x1b[23m"),
  32651. underline: f("\x1b[4m", "\x1b[24m"),
  32652. inverse: f("\x1b[7m", "\x1b[27m"),
  32653. hidden: f("\x1b[8m", "\x1b[28m"),
  32654. strikethrough: f("\x1b[9m", "\x1b[29m"),
  32655. black: f("\x1b[30m", "\x1b[39m"),
  32656. red: f("\x1b[31m", "\x1b[39m"),
  32657. green: f("\x1b[32m", "\x1b[39m"),
  32658. yellow: f("\x1b[33m", "\x1b[39m"),
  32659. blue: f("\x1b[34m", "\x1b[39m"),
  32660. magenta: f("\x1b[35m", "\x1b[39m"),
  32661. cyan: f("\x1b[36m", "\x1b[39m"),
  32662. white: f("\x1b[37m", "\x1b[39m"),
  32663. gray: f("\x1b[90m", "\x1b[39m"),
  32664. bgBlack: f("\x1b[40m", "\x1b[49m"),
  32665. bgRed: f("\x1b[41m", "\x1b[49m"),
  32666. bgGreen: f("\x1b[42m", "\x1b[49m"),
  32667. bgYellow: f("\x1b[43m", "\x1b[49m"),
  32668. bgBlue: f("\x1b[44m", "\x1b[49m"),
  32669. bgMagenta: f("\x1b[45m", "\x1b[49m"),
  32670. bgCyan: f("\x1b[46m", "\x1b[49m"),
  32671. bgWhite: f("\x1b[47m", "\x1b[49m"),
  32672. blackBright: f("\x1b[90m", "\x1b[39m"),
  32673. redBright: f("\x1b[91m", "\x1b[39m"),
  32674. greenBright: f("\x1b[92m", "\x1b[39m"),
  32675. yellowBright: f("\x1b[93m", "\x1b[39m"),
  32676. blueBright: f("\x1b[94m", "\x1b[39m"),
  32677. magentaBright: f("\x1b[95m", "\x1b[39m"),
  32678. cyanBright: f("\x1b[96m", "\x1b[39m"),
  32679. whiteBright: f("\x1b[97m", "\x1b[39m"),
  32680. bgBlackBright: f("\x1b[100m", "\x1b[49m"),
  32681. bgRedBright: f("\x1b[101m", "\x1b[49m"),
  32682. bgGreenBright: f("\x1b[102m", "\x1b[49m"),
  32683. bgYellowBright: f("\x1b[103m", "\x1b[49m"),
  32684. bgBlueBright: f("\x1b[104m", "\x1b[49m"),
  32685. bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
  32686. bgCyanBright: f("\x1b[106m", "\x1b[49m"),
  32687. bgWhiteBright: f("\x1b[107m", "\x1b[49m"),
  32688. }
  32689. };
  32690. picocolors.exports = createColors();
  32691. picocolors.exports.createColors = createColors;
  32692. return picocolors.exports;
  32693. }
  32694. var tokenize$1;
  32695. var hasRequiredTokenize$1;
  32696. function requireTokenize$1 () {
  32697. if (hasRequiredTokenize$1) return tokenize$1;
  32698. hasRequiredTokenize$1 = 1;
  32699. const SINGLE_QUOTE = "'".charCodeAt(0);
  32700. const DOUBLE_QUOTE = '"'.charCodeAt(0);
  32701. const BACKSLASH = '\\'.charCodeAt(0);
  32702. const SLASH = '/'.charCodeAt(0);
  32703. const NEWLINE = '\n'.charCodeAt(0);
  32704. const SPACE = ' '.charCodeAt(0);
  32705. const FEED = '\f'.charCodeAt(0);
  32706. const TAB = '\t'.charCodeAt(0);
  32707. const CR = '\r'.charCodeAt(0);
  32708. const OPEN_SQUARE = '['.charCodeAt(0);
  32709. const CLOSE_SQUARE = ']'.charCodeAt(0);
  32710. const OPEN_PARENTHESES = '('.charCodeAt(0);
  32711. const CLOSE_PARENTHESES = ')'.charCodeAt(0);
  32712. const OPEN_CURLY = '{'.charCodeAt(0);
  32713. const CLOSE_CURLY = '}'.charCodeAt(0);
  32714. const SEMICOLON = ';'.charCodeAt(0);
  32715. const ASTERISK = '*'.charCodeAt(0);
  32716. const COLON = ':'.charCodeAt(0);
  32717. const AT = '@'.charCodeAt(0);
  32718. const RE_AT_END = /[\t\n\f\r "#'()/;[\\\]{}]/g;
  32719. const RE_WORD_END = /[\t\n\f\r !"#'():;@[\\\]{}]|\/(?=\*)/g;
  32720. const RE_BAD_BRACKET = /.[\r\n"'(/\\]/;
  32721. const RE_HEX_ESCAPE = /[\da-f]/i;
  32722. tokenize$1 = function tokenizer(input, options = {}) {
  32723. let css = input.css.valueOf();
  32724. let ignore = options.ignoreErrors;
  32725. let code, content, escape, next, quote;
  32726. let currentToken, escaped, escapePos, n, prev;
  32727. let length = css.length;
  32728. let pos = 0;
  32729. let buffer = [];
  32730. let returned = [];
  32731. function position() {
  32732. return pos
  32733. }
  32734. function unclosed(what) {
  32735. throw input.error('Unclosed ' + what, pos)
  32736. }
  32737. function endOfFile() {
  32738. return returned.length === 0 && pos >= length
  32739. }
  32740. function nextToken(opts) {
  32741. if (returned.length) return returned.pop()
  32742. if (pos >= length) return
  32743. let ignoreUnclosed = opts ? opts.ignoreUnclosed : false;
  32744. code = css.charCodeAt(pos);
  32745. switch (code) {
  32746. case NEWLINE:
  32747. case SPACE:
  32748. case TAB:
  32749. case CR:
  32750. case FEED: {
  32751. next = pos;
  32752. do {
  32753. next += 1;
  32754. code = css.charCodeAt(next);
  32755. } while (
  32756. code === SPACE ||
  32757. code === NEWLINE ||
  32758. code === TAB ||
  32759. code === CR ||
  32760. code === FEED
  32761. )
  32762. currentToken = ['space', css.slice(pos, next)];
  32763. pos = next - 1;
  32764. break
  32765. }
  32766. case OPEN_SQUARE:
  32767. case CLOSE_SQUARE:
  32768. case OPEN_CURLY:
  32769. case CLOSE_CURLY:
  32770. case COLON:
  32771. case SEMICOLON:
  32772. case CLOSE_PARENTHESES: {
  32773. let controlChar = String.fromCharCode(code);
  32774. currentToken = [controlChar, controlChar, pos];
  32775. break
  32776. }
  32777. case OPEN_PARENTHESES: {
  32778. prev = buffer.length ? buffer.pop()[1] : '';
  32779. n = css.charCodeAt(pos + 1);
  32780. if (
  32781. prev === 'url' &&
  32782. n !== SINGLE_QUOTE &&
  32783. n !== DOUBLE_QUOTE &&
  32784. n !== SPACE &&
  32785. n !== NEWLINE &&
  32786. n !== TAB &&
  32787. n !== FEED &&
  32788. n !== CR
  32789. ) {
  32790. next = pos;
  32791. do {
  32792. escaped = false;
  32793. next = css.indexOf(')', next + 1);
  32794. if (next === -1) {
  32795. if (ignore || ignoreUnclosed) {
  32796. next = pos;
  32797. break
  32798. } else {
  32799. unclosed('bracket');
  32800. }
  32801. }
  32802. escapePos = next;
  32803. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32804. escapePos -= 1;
  32805. escaped = !escaped;
  32806. }
  32807. } while (escaped)
  32808. currentToken = ['brackets', css.slice(pos, next + 1), pos, next];
  32809. pos = next;
  32810. } else {
  32811. next = css.indexOf(')', pos + 1);
  32812. content = css.slice(pos, next + 1);
  32813. if (next === -1 || RE_BAD_BRACKET.test(content)) {
  32814. currentToken = ['(', '(', pos];
  32815. } else {
  32816. currentToken = ['brackets', content, pos, next];
  32817. pos = next;
  32818. }
  32819. }
  32820. break
  32821. }
  32822. case SINGLE_QUOTE:
  32823. case DOUBLE_QUOTE: {
  32824. quote = code === SINGLE_QUOTE ? "'" : '"';
  32825. next = pos;
  32826. do {
  32827. escaped = false;
  32828. next = css.indexOf(quote, next + 1);
  32829. if (next === -1) {
  32830. if (ignore || ignoreUnclosed) {
  32831. next = pos + 1;
  32832. break
  32833. } else {
  32834. unclosed('string');
  32835. }
  32836. }
  32837. escapePos = next;
  32838. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32839. escapePos -= 1;
  32840. escaped = !escaped;
  32841. }
  32842. } while (escaped)
  32843. currentToken = ['string', css.slice(pos, next + 1), pos, next];
  32844. pos = next;
  32845. break
  32846. }
  32847. case AT: {
  32848. RE_AT_END.lastIndex = pos + 1;
  32849. RE_AT_END.test(css);
  32850. if (RE_AT_END.lastIndex === 0) {
  32851. next = css.length - 1;
  32852. } else {
  32853. next = RE_AT_END.lastIndex - 2;
  32854. }
  32855. currentToken = ['at-word', css.slice(pos, next + 1), pos, next];
  32856. pos = next;
  32857. break
  32858. }
  32859. case BACKSLASH: {
  32860. next = pos;
  32861. escape = true;
  32862. while (css.charCodeAt(next + 1) === BACKSLASH) {
  32863. next += 1;
  32864. escape = !escape;
  32865. }
  32866. code = css.charCodeAt(next + 1);
  32867. if (
  32868. escape &&
  32869. code !== SLASH &&
  32870. code !== SPACE &&
  32871. code !== NEWLINE &&
  32872. code !== TAB &&
  32873. code !== CR &&
  32874. code !== FEED
  32875. ) {
  32876. next += 1;
  32877. if (RE_HEX_ESCAPE.test(css.charAt(next))) {
  32878. while (RE_HEX_ESCAPE.test(css.charAt(next + 1))) {
  32879. next += 1;
  32880. }
  32881. if (css.charCodeAt(next + 1) === SPACE) {
  32882. next += 1;
  32883. }
  32884. }
  32885. }
  32886. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32887. pos = next;
  32888. break
  32889. }
  32890. default: {
  32891. if (code === SLASH && css.charCodeAt(pos + 1) === ASTERISK) {
  32892. next = css.indexOf('*/', pos + 2) + 1;
  32893. if (next === 0) {
  32894. if (ignore || ignoreUnclosed) {
  32895. next = css.length;
  32896. } else {
  32897. unclosed('comment');
  32898. }
  32899. }
  32900. currentToken = ['comment', css.slice(pos, next + 1), pos, next];
  32901. pos = next;
  32902. } else {
  32903. RE_WORD_END.lastIndex = pos + 1;
  32904. RE_WORD_END.test(css);
  32905. if (RE_WORD_END.lastIndex === 0) {
  32906. next = css.length - 1;
  32907. } else {
  32908. next = RE_WORD_END.lastIndex - 2;
  32909. }
  32910. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32911. buffer.push(currentToken);
  32912. pos = next;
  32913. }
  32914. break
  32915. }
  32916. }
  32917. pos++;
  32918. return currentToken
  32919. }
  32920. function back(token) {
  32921. returned.push(token);
  32922. }
  32923. return {
  32924. back,
  32925. endOfFile,
  32926. nextToken,
  32927. position
  32928. }
  32929. };
  32930. return tokenize$1;
  32931. }
  32932. var terminalHighlight_1;
  32933. var hasRequiredTerminalHighlight;
  32934. function requireTerminalHighlight () {
  32935. if (hasRequiredTerminalHighlight) return terminalHighlight_1;
  32936. hasRequiredTerminalHighlight = 1;
  32937. let pico = /*@__PURE__*/ requirePicocolors();
  32938. let tokenizer = /*@__PURE__*/ requireTokenize$1();
  32939. let Input;
  32940. function registerInput(dependant) {
  32941. Input = dependant;
  32942. }
  32943. const HIGHLIGHT_THEME = {
  32944. ';': pico.yellow,
  32945. ':': pico.yellow,
  32946. '(': pico.cyan,
  32947. ')': pico.cyan,
  32948. '[': pico.yellow,
  32949. ']': pico.yellow,
  32950. '{': pico.yellow,
  32951. '}': pico.yellow,
  32952. 'at-word': pico.cyan,
  32953. 'brackets': pico.cyan,
  32954. 'call': pico.cyan,
  32955. 'class': pico.yellow,
  32956. 'comment': pico.gray,
  32957. 'hash': pico.magenta,
  32958. 'string': pico.green
  32959. };
  32960. function getTokenType([type, value], processor) {
  32961. if (type === 'word') {
  32962. if (value[0] === '.') {
  32963. return 'class'
  32964. }
  32965. if (value[0] === '#') {
  32966. return 'hash'
  32967. }
  32968. }
  32969. if (!processor.endOfFile()) {
  32970. let next = processor.nextToken();
  32971. processor.back(next);
  32972. if (next[0] === 'brackets' || next[0] === '(') return 'call'
  32973. }
  32974. return type
  32975. }
  32976. function terminalHighlight(css) {
  32977. let processor = tokenizer(new Input(css), { ignoreErrors: true });
  32978. let result = '';
  32979. while (!processor.endOfFile()) {
  32980. let token = processor.nextToken();
  32981. let color = HIGHLIGHT_THEME[getTokenType(token, processor)];
  32982. if (color) {
  32983. result += token[1]
  32984. .split(/\r?\n/)
  32985. .map(i => color(i))
  32986. .join('\n');
  32987. } else {
  32988. result += token[1];
  32989. }
  32990. }
  32991. return result
  32992. }
  32993. terminalHighlight.registerInput = registerInput;
  32994. terminalHighlight_1 = terminalHighlight;
  32995. return terminalHighlight_1;
  32996. }
  32997. var cssSyntaxError;
  32998. var hasRequiredCssSyntaxError;
  32999. function requireCssSyntaxError () {
  33000. if (hasRequiredCssSyntaxError) return cssSyntaxError;
  33001. hasRequiredCssSyntaxError = 1;
  33002. let pico = /*@__PURE__*/ requirePicocolors();
  33003. let terminalHighlight = /*@__PURE__*/ requireTerminalHighlight();
  33004. class CssSyntaxError extends Error {
  33005. constructor(message, line, column, source, file, plugin) {
  33006. super(message);
  33007. this.name = 'CssSyntaxError';
  33008. this.reason = message;
  33009. if (file) {
  33010. this.file = file;
  33011. }
  33012. if (source) {
  33013. this.source = source;
  33014. }
  33015. if (plugin) {
  33016. this.plugin = plugin;
  33017. }
  33018. if (typeof line !== 'undefined' && typeof column !== 'undefined') {
  33019. if (typeof line === 'number') {
  33020. this.line = line;
  33021. this.column = column;
  33022. } else {
  33023. this.line = line.line;
  33024. this.column = line.column;
  33025. this.endLine = column.line;
  33026. this.endColumn = column.column;
  33027. }
  33028. }
  33029. this.setMessage();
  33030. if (Error.captureStackTrace) {
  33031. Error.captureStackTrace(this, CssSyntaxError);
  33032. }
  33033. }
  33034. setMessage() {
  33035. this.message = this.plugin ? this.plugin + ': ' : '';
  33036. this.message += this.file ? this.file : '<css input>';
  33037. if (typeof this.line !== 'undefined') {
  33038. this.message += ':' + this.line + ':' + this.column;
  33039. }
  33040. this.message += ': ' + this.reason;
  33041. }
  33042. showSourceCode(color) {
  33043. if (!this.source) return ''
  33044. let css = this.source;
  33045. if (color == null) color = pico.isColorSupported;
  33046. let aside = text => text;
  33047. let mark = text => text;
  33048. let highlight = text => text;
  33049. if (color) {
  33050. let { bold, gray, red } = pico.createColors(true);
  33051. mark = text => bold(red(text));
  33052. aside = text => gray(text);
  33053. if (terminalHighlight) {
  33054. highlight = text => terminalHighlight(text);
  33055. }
  33056. }
  33057. let lines = css.split(/\r?\n/);
  33058. let start = Math.max(this.line - 3, 0);
  33059. let end = Math.min(this.line + 2, lines.length);
  33060. let maxWidth = String(end).length;
  33061. return lines
  33062. .slice(start, end)
  33063. .map((line, index) => {
  33064. let number = start + 1 + index;
  33065. let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ';
  33066. if (number === this.line) {
  33067. if (line.length > 160) {
  33068. let padding = 20;
  33069. let subLineStart = Math.max(0, this.column - padding);
  33070. let subLineEnd = Math.max(
  33071. this.column + padding,
  33072. this.endColumn + padding
  33073. );
  33074. let subLine = line.slice(subLineStart, subLineEnd);
  33075. let spacing =
  33076. aside(gutter.replace(/\d/g, ' ')) +
  33077. line
  33078. .slice(0, Math.min(this.column - 1, padding - 1))
  33079. .replace(/[^\t]/g, ' ');
  33080. return (
  33081. mark('>') +
  33082. aside(gutter) +
  33083. highlight(subLine) +
  33084. '\n ' +
  33085. spacing +
  33086. mark('^')
  33087. )
  33088. }
  33089. let spacing =
  33090. aside(gutter.replace(/\d/g, ' ')) +
  33091. line.slice(0, this.column - 1).replace(/[^\t]/g, ' ');
  33092. return (
  33093. mark('>') +
  33094. aside(gutter) +
  33095. highlight(line) +
  33096. '\n ' +
  33097. spacing +
  33098. mark('^')
  33099. )
  33100. }
  33101. return ' ' + aside(gutter) + highlight(line)
  33102. })
  33103. .join('\n')
  33104. }
  33105. toString() {
  33106. let code = this.showSourceCode();
  33107. if (code) {
  33108. code = '\n\n' + code + '\n';
  33109. }
  33110. return this.name + ': ' + this.message + code
  33111. }
  33112. }
  33113. cssSyntaxError = CssSyntaxError;
  33114. CssSyntaxError.default = CssSyntaxError;
  33115. return cssSyntaxError;
  33116. }
  33117. var stringifier;
  33118. var hasRequiredStringifier;
  33119. function requireStringifier () {
  33120. if (hasRequiredStringifier) return stringifier;
  33121. hasRequiredStringifier = 1;
  33122. const DEFAULT_RAW = {
  33123. after: '\n',
  33124. beforeClose: '\n',
  33125. beforeComment: '\n',
  33126. beforeDecl: '\n',
  33127. beforeOpen: ' ',
  33128. beforeRule: '\n',
  33129. colon: ': ',
  33130. commentLeft: ' ',
  33131. commentRight: ' ',
  33132. emptyBody: '',
  33133. indent: ' ',
  33134. semicolon: false
  33135. };
  33136. function capitalize(str) {
  33137. return str[0].toUpperCase() + str.slice(1)
  33138. }
  33139. class Stringifier {
  33140. constructor(builder) {
  33141. this.builder = builder;
  33142. }
  33143. atrule(node, semicolon) {
  33144. let name = '@' + node.name;
  33145. let params = node.params ? this.rawValue(node, 'params') : '';
  33146. if (typeof node.raws.afterName !== 'undefined') {
  33147. name += node.raws.afterName;
  33148. } else if (params) {
  33149. name += ' ';
  33150. }
  33151. if (node.nodes) {
  33152. this.block(node, name + params);
  33153. } else {
  33154. let end = (node.raws.between || '') + (semicolon ? ';' : '');
  33155. this.builder(name + params + end, node);
  33156. }
  33157. }
  33158. beforeAfter(node, detect) {
  33159. let value;
  33160. if (node.type === 'decl') {
  33161. value = this.raw(node, null, 'beforeDecl');
  33162. } else if (node.type === 'comment') {
  33163. value = this.raw(node, null, 'beforeComment');
  33164. } else if (detect === 'before') {
  33165. value = this.raw(node, null, 'beforeRule');
  33166. } else {
  33167. value = this.raw(node, null, 'beforeClose');
  33168. }
  33169. let buf = node.parent;
  33170. let depth = 0;
  33171. while (buf && buf.type !== 'root') {
  33172. depth += 1;
  33173. buf = buf.parent;
  33174. }
  33175. if (value.includes('\n')) {
  33176. let indent = this.raw(node, null, 'indent');
  33177. if (indent.length) {
  33178. for (let step = 0; step < depth; step++) value += indent;
  33179. }
  33180. }
  33181. return value
  33182. }
  33183. block(node, start) {
  33184. let between = this.raw(node, 'between', 'beforeOpen');
  33185. this.builder(start + between + '{', node, 'start');
  33186. let after;
  33187. if (node.nodes && node.nodes.length) {
  33188. this.body(node);
  33189. after = this.raw(node, 'after');
  33190. } else {
  33191. after = this.raw(node, 'after', 'emptyBody');
  33192. }
  33193. if (after) this.builder(after);
  33194. this.builder('}', node, 'end');
  33195. }
  33196. body(node) {
  33197. let last = node.nodes.length - 1;
  33198. while (last > 0) {
  33199. if (node.nodes[last].type !== 'comment') break
  33200. last -= 1;
  33201. }
  33202. let semicolon = this.raw(node, 'semicolon');
  33203. for (let i = 0; i < node.nodes.length; i++) {
  33204. let child = node.nodes[i];
  33205. let before = this.raw(child, 'before');
  33206. if (before) this.builder(before);
  33207. this.stringify(child, last !== i || semicolon);
  33208. }
  33209. }
  33210. comment(node) {
  33211. let left = this.raw(node, 'left', 'commentLeft');
  33212. let right = this.raw(node, 'right', 'commentRight');
  33213. this.builder('/*' + left + node.text + right + '*/', node);
  33214. }
  33215. decl(node, semicolon) {
  33216. let between = this.raw(node, 'between', 'colon');
  33217. let string = node.prop + between + this.rawValue(node, 'value');
  33218. if (node.important) {
  33219. string += node.raws.important || ' !important';
  33220. }
  33221. if (semicolon) string += ';';
  33222. this.builder(string, node);
  33223. }
  33224. document(node) {
  33225. this.body(node);
  33226. }
  33227. raw(node, own, detect) {
  33228. let value;
  33229. if (!detect) detect = own;
  33230. // Already had
  33231. if (own) {
  33232. value = node.raws[own];
  33233. if (typeof value !== 'undefined') return value
  33234. }
  33235. let parent = node.parent;
  33236. if (detect === 'before') {
  33237. // Hack for first rule in CSS
  33238. if (!parent || (parent.type === 'root' && parent.first === node)) {
  33239. return ''
  33240. }
  33241. // `root` nodes in `document` should use only their own raws
  33242. if (parent && parent.type === 'document') {
  33243. return ''
  33244. }
  33245. }
  33246. // Floating child without parent
  33247. if (!parent) return DEFAULT_RAW[detect]
  33248. // Detect style by other nodes
  33249. let root = node.root();
  33250. if (!root.rawCache) root.rawCache = {};
  33251. if (typeof root.rawCache[detect] !== 'undefined') {
  33252. return root.rawCache[detect]
  33253. }
  33254. if (detect === 'before' || detect === 'after') {
  33255. return this.beforeAfter(node, detect)
  33256. } else {
  33257. let method = 'raw' + capitalize(detect);
  33258. if (this[method]) {
  33259. value = this[method](root, node);
  33260. } else {
  33261. root.walk(i => {
  33262. value = i.raws[own];
  33263. if (typeof value !== 'undefined') return false
  33264. });
  33265. }
  33266. }
  33267. if (typeof value === 'undefined') value = DEFAULT_RAW[detect];
  33268. root.rawCache[detect] = value;
  33269. return value
  33270. }
  33271. rawBeforeClose(root) {
  33272. let value;
  33273. root.walk(i => {
  33274. if (i.nodes && i.nodes.length > 0) {
  33275. if (typeof i.raws.after !== 'undefined') {
  33276. value = i.raws.after;
  33277. if (value.includes('\n')) {
  33278. value = value.replace(/[^\n]+$/, '');
  33279. }
  33280. return false
  33281. }
  33282. }
  33283. });
  33284. if (value) value = value.replace(/\S/g, '');
  33285. return value
  33286. }
  33287. rawBeforeComment(root, node) {
  33288. let value;
  33289. root.walkComments(i => {
  33290. if (typeof i.raws.before !== 'undefined') {
  33291. value = i.raws.before;
  33292. if (value.includes('\n')) {
  33293. value = value.replace(/[^\n]+$/, '');
  33294. }
  33295. return false
  33296. }
  33297. });
  33298. if (typeof value === 'undefined') {
  33299. value = this.raw(node, null, 'beforeDecl');
  33300. } else if (value) {
  33301. value = value.replace(/\S/g, '');
  33302. }
  33303. return value
  33304. }
  33305. rawBeforeDecl(root, node) {
  33306. let value;
  33307. root.walkDecls(i => {
  33308. if (typeof i.raws.before !== 'undefined') {
  33309. value = i.raws.before;
  33310. if (value.includes('\n')) {
  33311. value = value.replace(/[^\n]+$/, '');
  33312. }
  33313. return false
  33314. }
  33315. });
  33316. if (typeof value === 'undefined') {
  33317. value = this.raw(node, null, 'beforeRule');
  33318. } else if (value) {
  33319. value = value.replace(/\S/g, '');
  33320. }
  33321. return value
  33322. }
  33323. rawBeforeOpen(root) {
  33324. let value;
  33325. root.walk(i => {
  33326. if (i.type !== 'decl') {
  33327. value = i.raws.between;
  33328. if (typeof value !== 'undefined') return false
  33329. }
  33330. });
  33331. return value
  33332. }
  33333. rawBeforeRule(root) {
  33334. let value;
  33335. root.walk(i => {
  33336. if (i.nodes && (i.parent !== root || root.first !== i)) {
  33337. if (typeof i.raws.before !== 'undefined') {
  33338. value = i.raws.before;
  33339. if (value.includes('\n')) {
  33340. value = value.replace(/[^\n]+$/, '');
  33341. }
  33342. return false
  33343. }
  33344. }
  33345. });
  33346. if (value) value = value.replace(/\S/g, '');
  33347. return value
  33348. }
  33349. rawColon(root) {
  33350. let value;
  33351. root.walkDecls(i => {
  33352. if (typeof i.raws.between !== 'undefined') {
  33353. value = i.raws.between.replace(/[^\s:]/g, '');
  33354. return false
  33355. }
  33356. });
  33357. return value
  33358. }
  33359. rawEmptyBody(root) {
  33360. let value;
  33361. root.walk(i => {
  33362. if (i.nodes && i.nodes.length === 0) {
  33363. value = i.raws.after;
  33364. if (typeof value !== 'undefined') return false
  33365. }
  33366. });
  33367. return value
  33368. }
  33369. rawIndent(root) {
  33370. if (root.raws.indent) return root.raws.indent
  33371. let value;
  33372. root.walk(i => {
  33373. let p = i.parent;
  33374. if (p && p !== root && p.parent && p.parent === root) {
  33375. if (typeof i.raws.before !== 'undefined') {
  33376. let parts = i.raws.before.split('\n');
  33377. value = parts[parts.length - 1];
  33378. value = value.replace(/\S/g, '');
  33379. return false
  33380. }
  33381. }
  33382. });
  33383. return value
  33384. }
  33385. rawSemicolon(root) {
  33386. let value;
  33387. root.walk(i => {
  33388. if (i.nodes && i.nodes.length && i.last.type === 'decl') {
  33389. value = i.raws.semicolon;
  33390. if (typeof value !== 'undefined') return false
  33391. }
  33392. });
  33393. return value
  33394. }
  33395. rawValue(node, prop) {
  33396. let value = node[prop];
  33397. let raw = node.raws[prop];
  33398. if (raw && raw.value === value) {
  33399. return raw.raw
  33400. }
  33401. return value
  33402. }
  33403. root(node) {
  33404. this.body(node);
  33405. if (node.raws.after) this.builder(node.raws.after);
  33406. }
  33407. rule(node) {
  33408. this.block(node, this.rawValue(node, 'selector'));
  33409. if (node.raws.ownSemicolon) {
  33410. this.builder(node.raws.ownSemicolon, node, 'end');
  33411. }
  33412. }
  33413. stringify(node, semicolon) {
  33414. /* c8 ignore start */
  33415. if (!this[node.type]) {
  33416. throw new Error(
  33417. 'Unknown AST node type ' +
  33418. node.type +
  33419. '. ' +
  33420. 'Maybe you need to change PostCSS stringifier.'
  33421. )
  33422. }
  33423. /* c8 ignore stop */
  33424. this[node.type](node, semicolon);
  33425. }
  33426. }
  33427. stringifier = Stringifier;
  33428. Stringifier.default = Stringifier;
  33429. return stringifier;
  33430. }
  33431. var stringify_1;
  33432. var hasRequiredStringify;
  33433. function requireStringify () {
  33434. if (hasRequiredStringify) return stringify_1;
  33435. hasRequiredStringify = 1;
  33436. let Stringifier = /*@__PURE__*/ requireStringifier();
  33437. function stringify(node, builder) {
  33438. let str = new Stringifier(builder);
  33439. str.stringify(node);
  33440. }
  33441. stringify_1 = stringify;
  33442. stringify.default = stringify;
  33443. return stringify_1;
  33444. }
  33445. var symbols = {};
  33446. var hasRequiredSymbols;
  33447. function requireSymbols () {
  33448. if (hasRequiredSymbols) return symbols;
  33449. hasRequiredSymbols = 1;
  33450. symbols.isClean = Symbol('isClean');
  33451. symbols.my = Symbol('my');
  33452. return symbols;
  33453. }
  33454. var node$2;
  33455. var hasRequiredNode$2;
  33456. function requireNode$2 () {
  33457. if (hasRequiredNode$2) return node$2;
  33458. hasRequiredNode$2 = 1;
  33459. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  33460. let Stringifier = /*@__PURE__*/ requireStringifier();
  33461. let stringify = /*@__PURE__*/ requireStringify();
  33462. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  33463. function cloneNode(obj, parent) {
  33464. let cloned = new obj.constructor();
  33465. for (let i in obj) {
  33466. if (!Object.prototype.hasOwnProperty.call(obj, i)) {
  33467. /* c8 ignore next 2 */
  33468. continue
  33469. }
  33470. if (i === 'proxyCache') continue
  33471. let value = obj[i];
  33472. let type = typeof value;
  33473. if (i === 'parent' && type === 'object') {
  33474. if (parent) cloned[i] = parent;
  33475. } else if (i === 'source') {
  33476. cloned[i] = value;
  33477. } else if (Array.isArray(value)) {
  33478. cloned[i] = value.map(j => cloneNode(j, cloned));
  33479. } else {
  33480. if (type === 'object' && value !== null) value = cloneNode(value);
  33481. cloned[i] = value;
  33482. }
  33483. }
  33484. return cloned
  33485. }
  33486. function sourceOffset(inputCSS, position) {
  33487. // Not all custom syntaxes support `offset` in `source.start` and `source.end`
  33488. if (position && typeof position.offset !== 'undefined') {
  33489. return position.offset
  33490. }
  33491. let column = 1;
  33492. let line = 1;
  33493. let offset = 0;
  33494. for (let i = 0; i < inputCSS.length; i++) {
  33495. if (line === position.line && column === position.column) {
  33496. offset = i;
  33497. break
  33498. }
  33499. if (inputCSS[i] === '\n') {
  33500. column = 1;
  33501. line += 1;
  33502. } else {
  33503. column += 1;
  33504. }
  33505. }
  33506. return offset
  33507. }
  33508. class Node {
  33509. get proxyOf() {
  33510. return this
  33511. }
  33512. constructor(defaults = {}) {
  33513. this.raws = {};
  33514. this[isClean] = false;
  33515. this[my] = true;
  33516. for (let name in defaults) {
  33517. if (name === 'nodes') {
  33518. this.nodes = [];
  33519. for (let node of defaults[name]) {
  33520. if (typeof node.clone === 'function') {
  33521. this.append(node.clone());
  33522. } else {
  33523. this.append(node);
  33524. }
  33525. }
  33526. } else {
  33527. this[name] = defaults[name];
  33528. }
  33529. }
  33530. }
  33531. addToError(error) {
  33532. error.postcssNode = this;
  33533. if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
  33534. let s = this.source;
  33535. error.stack = error.stack.replace(
  33536. /\n\s{4}at /,
  33537. `$&${s.input.from}:${s.start.line}:${s.start.column}$&`
  33538. );
  33539. }
  33540. return error
  33541. }
  33542. after(add) {
  33543. this.parent.insertAfter(this, add);
  33544. return this
  33545. }
  33546. assign(overrides = {}) {
  33547. for (let name in overrides) {
  33548. this[name] = overrides[name];
  33549. }
  33550. return this
  33551. }
  33552. before(add) {
  33553. this.parent.insertBefore(this, add);
  33554. return this
  33555. }
  33556. cleanRaws(keepBetween) {
  33557. delete this.raws.before;
  33558. delete this.raws.after;
  33559. if (!keepBetween) delete this.raws.between;
  33560. }
  33561. clone(overrides = {}) {
  33562. let cloned = cloneNode(this);
  33563. for (let name in overrides) {
  33564. cloned[name] = overrides[name];
  33565. }
  33566. return cloned
  33567. }
  33568. cloneAfter(overrides = {}) {
  33569. let cloned = this.clone(overrides);
  33570. this.parent.insertAfter(this, cloned);
  33571. return cloned
  33572. }
  33573. cloneBefore(overrides = {}) {
  33574. let cloned = this.clone(overrides);
  33575. this.parent.insertBefore(this, cloned);
  33576. return cloned
  33577. }
  33578. error(message, opts = {}) {
  33579. if (this.source) {
  33580. let { end, start } = this.rangeBy(opts);
  33581. return this.source.input.error(
  33582. message,
  33583. { column: start.column, line: start.line },
  33584. { column: end.column, line: end.line },
  33585. opts
  33586. )
  33587. }
  33588. return new CssSyntaxError(message)
  33589. }
  33590. getProxyProcessor() {
  33591. return {
  33592. get(node, prop) {
  33593. if (prop === 'proxyOf') {
  33594. return node
  33595. } else if (prop === 'root') {
  33596. return () => node.root().toProxy()
  33597. } else {
  33598. return node[prop]
  33599. }
  33600. },
  33601. set(node, prop, value) {
  33602. if (node[prop] === value) return true
  33603. node[prop] = value;
  33604. if (
  33605. prop === 'prop' ||
  33606. prop === 'value' ||
  33607. prop === 'name' ||
  33608. prop === 'params' ||
  33609. prop === 'important' ||
  33610. /* c8 ignore next */
  33611. prop === 'text'
  33612. ) {
  33613. node.markDirty();
  33614. }
  33615. return true
  33616. }
  33617. }
  33618. }
  33619. /* c8 ignore next 3 */
  33620. markClean() {
  33621. this[isClean] = true;
  33622. }
  33623. markDirty() {
  33624. if (this[isClean]) {
  33625. this[isClean] = false;
  33626. let next = this;
  33627. while ((next = next.parent)) {
  33628. next[isClean] = false;
  33629. }
  33630. }
  33631. }
  33632. next() {
  33633. if (!this.parent) return undefined
  33634. let index = this.parent.index(this);
  33635. return this.parent.nodes[index + 1]
  33636. }
  33637. positionBy(opts = {}) {
  33638. let pos = this.source.start;
  33639. if (opts.index) {
  33640. pos = this.positionInside(opts.index);
  33641. } else if (opts.word) {
  33642. let inputString =
  33643. 'document' in this.source.input
  33644. ? this.source.input.document
  33645. : this.source.input.css;
  33646. let stringRepresentation = inputString.slice(
  33647. sourceOffset(inputString, this.source.start),
  33648. sourceOffset(inputString, this.source.end)
  33649. );
  33650. let index = stringRepresentation.indexOf(opts.word);
  33651. if (index !== -1) pos = this.positionInside(index);
  33652. }
  33653. return pos
  33654. }
  33655. positionInside(index) {
  33656. let column = this.source.start.column;
  33657. let line = this.source.start.line;
  33658. let inputString =
  33659. 'document' in this.source.input
  33660. ? this.source.input.document
  33661. : this.source.input.css;
  33662. let offset = sourceOffset(inputString, this.source.start);
  33663. let end = offset + index;
  33664. for (let i = offset; i < end; i++) {
  33665. if (inputString[i] === '\n') {
  33666. column = 1;
  33667. line += 1;
  33668. } else {
  33669. column += 1;
  33670. }
  33671. }
  33672. return { column, line, offset: end }
  33673. }
  33674. prev() {
  33675. if (!this.parent) return undefined
  33676. let index = this.parent.index(this);
  33677. return this.parent.nodes[index - 1]
  33678. }
  33679. rangeBy(opts = {}) {
  33680. let inputString =
  33681. 'document' in this.source.input
  33682. ? this.source.input.document
  33683. : this.source.input.css;
  33684. let start = {
  33685. column: this.source.start.column,
  33686. line: this.source.start.line,
  33687. offset: sourceOffset(inputString, this.source.start)
  33688. };
  33689. let end = this.source.end
  33690. ? {
  33691. column: this.source.end.column + 1,
  33692. line: this.source.end.line,
  33693. offset:
  33694. typeof this.source.end.offset === 'number'
  33695. ? // `source.end.offset` is exclusive, so we don't need to add 1
  33696. this.source.end.offset
  33697. : // Since line/column in this.source.end is inclusive,
  33698. // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
  33699. // So, we add 1 to convert it to exclusive.
  33700. sourceOffset(inputString, this.source.end) + 1
  33701. }
  33702. : {
  33703. column: start.column + 1,
  33704. line: start.line,
  33705. offset: start.offset + 1
  33706. };
  33707. if (opts.word) {
  33708. let stringRepresentation = inputString.slice(
  33709. sourceOffset(inputString, this.source.start),
  33710. sourceOffset(inputString, this.source.end)
  33711. );
  33712. let index = stringRepresentation.indexOf(opts.word);
  33713. if (index !== -1) {
  33714. start = this.positionInside(index);
  33715. end = this.positionInside(index + opts.word.length);
  33716. }
  33717. } else {
  33718. if (opts.start) {
  33719. start = {
  33720. column: opts.start.column,
  33721. line: opts.start.line,
  33722. offset: sourceOffset(inputString, opts.start)
  33723. };
  33724. } else if (opts.index) {
  33725. start = this.positionInside(opts.index);
  33726. }
  33727. if (opts.end) {
  33728. end = {
  33729. column: opts.end.column,
  33730. line: opts.end.line,
  33731. offset: sourceOffset(inputString, opts.end)
  33732. };
  33733. } else if (typeof opts.endIndex === 'number') {
  33734. end = this.positionInside(opts.endIndex);
  33735. } else if (opts.index) {
  33736. end = this.positionInside(opts.index + 1);
  33737. }
  33738. }
  33739. if (
  33740. end.line < start.line ||
  33741. (end.line === start.line && end.column <= start.column)
  33742. ) {
  33743. end = {
  33744. column: start.column + 1,
  33745. line: start.line,
  33746. offset: start.offset + 1
  33747. };
  33748. }
  33749. return { end, start }
  33750. }
  33751. raw(prop, defaultType) {
  33752. let str = new Stringifier();
  33753. return str.raw(this, prop, defaultType)
  33754. }
  33755. remove() {
  33756. if (this.parent) {
  33757. this.parent.removeChild(this);
  33758. }
  33759. this.parent = undefined;
  33760. return this
  33761. }
  33762. replaceWith(...nodes) {
  33763. if (this.parent) {
  33764. let bookmark = this;
  33765. let foundSelf = false;
  33766. for (let node of nodes) {
  33767. if (node === this) {
  33768. foundSelf = true;
  33769. } else if (foundSelf) {
  33770. this.parent.insertAfter(bookmark, node);
  33771. bookmark = node;
  33772. } else {
  33773. this.parent.insertBefore(bookmark, node);
  33774. }
  33775. }
  33776. if (!foundSelf) {
  33777. this.remove();
  33778. }
  33779. }
  33780. return this
  33781. }
  33782. root() {
  33783. let result = this;
  33784. while (result.parent && result.parent.type !== 'document') {
  33785. result = result.parent;
  33786. }
  33787. return result
  33788. }
  33789. toJSON(_, inputs) {
  33790. let fixed = {};
  33791. let emitInputs = inputs == null;
  33792. inputs = inputs || new Map();
  33793. let inputsNextIndex = 0;
  33794. for (let name in this) {
  33795. if (!Object.prototype.hasOwnProperty.call(this, name)) {
  33796. /* c8 ignore next 2 */
  33797. continue
  33798. }
  33799. if (name === 'parent' || name === 'proxyCache') continue
  33800. let value = this[name];
  33801. if (Array.isArray(value)) {
  33802. fixed[name] = value.map(i => {
  33803. if (typeof i === 'object' && i.toJSON) {
  33804. return i.toJSON(null, inputs)
  33805. } else {
  33806. return i
  33807. }
  33808. });
  33809. } else if (typeof value === 'object' && value.toJSON) {
  33810. fixed[name] = value.toJSON(null, inputs);
  33811. } else if (name === 'source') {
  33812. if (value == null) continue
  33813. let inputId = inputs.get(value.input);
  33814. if (inputId == null) {
  33815. inputId = inputsNextIndex;
  33816. inputs.set(value.input, inputsNextIndex);
  33817. inputsNextIndex++;
  33818. }
  33819. fixed[name] = {
  33820. end: value.end,
  33821. inputId,
  33822. start: value.start
  33823. };
  33824. } else {
  33825. fixed[name] = value;
  33826. }
  33827. }
  33828. if (emitInputs) {
  33829. fixed.inputs = [...inputs.keys()].map(input => input.toJSON());
  33830. }
  33831. return fixed
  33832. }
  33833. toProxy() {
  33834. if (!this.proxyCache) {
  33835. this.proxyCache = new Proxy(this, this.getProxyProcessor());
  33836. }
  33837. return this.proxyCache
  33838. }
  33839. toString(stringifier = stringify) {
  33840. if (stringifier.stringify) stringifier = stringifier.stringify;
  33841. let result = '';
  33842. stringifier(this, i => {
  33843. result += i;
  33844. });
  33845. return result
  33846. }
  33847. warn(result, text, opts = {}) {
  33848. let data = { node: this };
  33849. for (let i in opts) data[i] = opts[i];
  33850. return result.warn(text, data)
  33851. }
  33852. }
  33853. node$2 = Node;
  33854. Node.default = Node;
  33855. return node$2;
  33856. }
  33857. var comment$1;
  33858. var hasRequiredComment$1;
  33859. function requireComment$1 () {
  33860. if (hasRequiredComment$1) return comment$1;
  33861. hasRequiredComment$1 = 1;
  33862. let Node = /*@__PURE__*/ requireNode$2();
  33863. class Comment extends Node {
  33864. constructor(defaults) {
  33865. super(defaults);
  33866. this.type = 'comment';
  33867. }
  33868. }
  33869. comment$1 = Comment;
  33870. Comment.default = Comment;
  33871. return comment$1;
  33872. }
  33873. var declaration;
  33874. var hasRequiredDeclaration;
  33875. function requireDeclaration () {
  33876. if (hasRequiredDeclaration) return declaration;
  33877. hasRequiredDeclaration = 1;
  33878. let Node = /*@__PURE__*/ requireNode$2();
  33879. class Declaration extends Node {
  33880. get variable() {
  33881. return this.prop.startsWith('--') || this.prop[0] === '$'
  33882. }
  33883. constructor(defaults) {
  33884. if (
  33885. defaults &&
  33886. typeof defaults.value !== 'undefined' &&
  33887. typeof defaults.value !== 'string'
  33888. ) {
  33889. defaults = { ...defaults, value: String(defaults.value) };
  33890. }
  33891. super(defaults);
  33892. this.type = 'decl';
  33893. }
  33894. }
  33895. declaration = Declaration;
  33896. Declaration.default = Declaration;
  33897. return declaration;
  33898. }
  33899. var container$1;
  33900. var hasRequiredContainer$1;
  33901. function requireContainer$1 () {
  33902. if (hasRequiredContainer$1) return container$1;
  33903. hasRequiredContainer$1 = 1;
  33904. let Comment = /*@__PURE__*/ requireComment$1();
  33905. let Declaration = /*@__PURE__*/ requireDeclaration();
  33906. let Node = /*@__PURE__*/ requireNode$2();
  33907. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  33908. let AtRule, parse, Root, Rule;
  33909. function cleanSource(nodes) {
  33910. return nodes.map(i => {
  33911. if (i.nodes) i.nodes = cleanSource(i.nodes);
  33912. delete i.source;
  33913. return i
  33914. })
  33915. }
  33916. function markTreeDirty(node) {
  33917. node[isClean] = false;
  33918. if (node.proxyOf.nodes) {
  33919. for (let i of node.proxyOf.nodes) {
  33920. markTreeDirty(i);
  33921. }
  33922. }
  33923. }
  33924. class Container extends Node {
  33925. get first() {
  33926. if (!this.proxyOf.nodes) return undefined
  33927. return this.proxyOf.nodes[0]
  33928. }
  33929. get last() {
  33930. if (!this.proxyOf.nodes) return undefined
  33931. return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
  33932. }
  33933. append(...children) {
  33934. for (let child of children) {
  33935. let nodes = this.normalize(child, this.last);
  33936. for (let node of nodes) this.proxyOf.nodes.push(node);
  33937. }
  33938. this.markDirty();
  33939. return this
  33940. }
  33941. cleanRaws(keepBetween) {
  33942. super.cleanRaws(keepBetween);
  33943. if (this.nodes) {
  33944. for (let node of this.nodes) node.cleanRaws(keepBetween);
  33945. }
  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. every(condition) {
  33961. return this.nodes.every(condition)
  33962. }
  33963. getIterator() {
  33964. if (!this.lastEach) this.lastEach = 0;
  33965. if (!this.indexes) this.indexes = {};
  33966. this.lastEach += 1;
  33967. let iterator = this.lastEach;
  33968. this.indexes[iterator] = 0;
  33969. return iterator
  33970. }
  33971. getProxyProcessor() {
  33972. return {
  33973. get(node, prop) {
  33974. if (prop === 'proxyOf') {
  33975. return node
  33976. } else if (!node[prop]) {
  33977. return node[prop]
  33978. } else if (
  33979. prop === 'each' ||
  33980. (typeof prop === 'string' && prop.startsWith('walk'))
  33981. ) {
  33982. return (...args) => {
  33983. return node[prop](
  33984. ...args.map(i => {
  33985. if (typeof i === 'function') {
  33986. return (child, index) => i(child.toProxy(), index)
  33987. } else {
  33988. return i
  33989. }
  33990. })
  33991. )
  33992. }
  33993. } else if (prop === 'every' || prop === 'some') {
  33994. return cb => {
  33995. return node[prop]((child, ...other) =>
  33996. cb(child.toProxy(), ...other)
  33997. )
  33998. }
  33999. } else if (prop === 'root') {
  34000. return () => node.root().toProxy()
  34001. } else if (prop === 'nodes') {
  34002. return node.nodes.map(i => i.toProxy())
  34003. } else if (prop === 'first' || prop === 'last') {
  34004. return node[prop].toProxy()
  34005. } else {
  34006. return node[prop]
  34007. }
  34008. },
  34009. set(node, prop, value) {
  34010. if (node[prop] === value) return true
  34011. node[prop] = value;
  34012. if (prop === 'name' || prop === 'params' || prop === 'selector') {
  34013. node.markDirty();
  34014. }
  34015. return true
  34016. }
  34017. }
  34018. }
  34019. index(child) {
  34020. if (typeof child === 'number') return child
  34021. if (child.proxyOf) child = child.proxyOf;
  34022. return this.proxyOf.nodes.indexOf(child)
  34023. }
  34024. insertAfter(exist, add) {
  34025. let existIndex = this.index(exist);
  34026. let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
  34027. existIndex = this.index(exist);
  34028. for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node);
  34029. let index;
  34030. for (let id in this.indexes) {
  34031. index = this.indexes[id];
  34032. if (existIndex < index) {
  34033. this.indexes[id] = index + nodes.length;
  34034. }
  34035. }
  34036. this.markDirty();
  34037. return this
  34038. }
  34039. insertBefore(exist, add) {
  34040. let existIndex = this.index(exist);
  34041. let type = existIndex === 0 ? 'prepend' : false;
  34042. let nodes = this.normalize(
  34043. add,
  34044. this.proxyOf.nodes[existIndex],
  34045. type
  34046. ).reverse();
  34047. existIndex = this.index(exist);
  34048. for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node);
  34049. let index;
  34050. for (let id in this.indexes) {
  34051. index = this.indexes[id];
  34052. if (existIndex <= index) {
  34053. this.indexes[id] = index + nodes.length;
  34054. }
  34055. }
  34056. this.markDirty();
  34057. return this
  34058. }
  34059. normalize(nodes, sample) {
  34060. if (typeof nodes === 'string') {
  34061. nodes = cleanSource(parse(nodes).nodes);
  34062. } else if (typeof nodes === 'undefined') {
  34063. nodes = [];
  34064. } else if (Array.isArray(nodes)) {
  34065. nodes = nodes.slice(0);
  34066. for (let i of nodes) {
  34067. if (i.parent) i.parent.removeChild(i, 'ignore');
  34068. }
  34069. } else if (nodes.type === 'root' && this.type !== 'document') {
  34070. nodes = nodes.nodes.slice(0);
  34071. for (let i of nodes) {
  34072. if (i.parent) i.parent.removeChild(i, 'ignore');
  34073. }
  34074. } else if (nodes.type) {
  34075. nodes = [nodes];
  34076. } else if (nodes.prop) {
  34077. if (typeof nodes.value === 'undefined') {
  34078. throw new Error('Value field is missed in node creation')
  34079. } else if (typeof nodes.value !== 'string') {
  34080. nodes.value = String(nodes.value);
  34081. }
  34082. nodes = [new Declaration(nodes)];
  34083. } else if (nodes.selector || nodes.selectors) {
  34084. nodes = [new Rule(nodes)];
  34085. } else if (nodes.name) {
  34086. nodes = [new AtRule(nodes)];
  34087. } else if (nodes.text) {
  34088. nodes = [new Comment(nodes)];
  34089. } else {
  34090. throw new Error('Unknown node type in node creation')
  34091. }
  34092. let processed = nodes.map(i => {
  34093. /* c8 ignore next */
  34094. if (!i[my]) Container.rebuild(i);
  34095. i = i.proxyOf;
  34096. if (i.parent) i.parent.removeChild(i);
  34097. if (i[isClean]) markTreeDirty(i);
  34098. if (!i.raws) i.raws = {};
  34099. if (typeof i.raws.before === 'undefined') {
  34100. if (sample && typeof sample.raws.before !== 'undefined') {
  34101. i.raws.before = sample.raws.before.replace(/\S/g, '');
  34102. }
  34103. }
  34104. i.parent = this.proxyOf;
  34105. return i
  34106. });
  34107. return processed
  34108. }
  34109. prepend(...children) {
  34110. children = children.reverse();
  34111. for (let child of children) {
  34112. let nodes = this.normalize(child, this.first, 'prepend').reverse();
  34113. for (let node of nodes) this.proxyOf.nodes.unshift(node);
  34114. for (let id in this.indexes) {
  34115. this.indexes[id] = this.indexes[id] + nodes.length;
  34116. }
  34117. }
  34118. this.markDirty();
  34119. return this
  34120. }
  34121. push(child) {
  34122. child.parent = this;
  34123. this.proxyOf.nodes.push(child);
  34124. return this
  34125. }
  34126. removeAll() {
  34127. for (let node of this.proxyOf.nodes) node.parent = undefined;
  34128. this.proxyOf.nodes = [];
  34129. this.markDirty();
  34130. return this
  34131. }
  34132. removeChild(child) {
  34133. child = this.index(child);
  34134. this.proxyOf.nodes[child].parent = undefined;
  34135. this.proxyOf.nodes.splice(child, 1);
  34136. let index;
  34137. for (let id in this.indexes) {
  34138. index = this.indexes[id];
  34139. if (index >= child) {
  34140. this.indexes[id] = index - 1;
  34141. }
  34142. }
  34143. this.markDirty();
  34144. return this
  34145. }
  34146. replaceValues(pattern, opts, callback) {
  34147. if (!callback) {
  34148. callback = opts;
  34149. opts = {};
  34150. }
  34151. this.walkDecls(decl => {
  34152. if (opts.props && !opts.props.includes(decl.prop)) return
  34153. if (opts.fast && !decl.value.includes(opts.fast)) return
  34154. decl.value = decl.value.replace(pattern, callback);
  34155. });
  34156. this.markDirty();
  34157. return this
  34158. }
  34159. some(condition) {
  34160. return this.nodes.some(condition)
  34161. }
  34162. walk(callback) {
  34163. return this.each((child, i) => {
  34164. let result;
  34165. try {
  34166. result = callback(child, i);
  34167. } catch (e) {
  34168. throw child.addToError(e)
  34169. }
  34170. if (result !== false && child.walk) {
  34171. result = child.walk(callback);
  34172. }
  34173. return result
  34174. })
  34175. }
  34176. walkAtRules(name, callback) {
  34177. if (!callback) {
  34178. callback = name;
  34179. return this.walk((child, i) => {
  34180. if (child.type === 'atrule') {
  34181. return callback(child, i)
  34182. }
  34183. })
  34184. }
  34185. if (name instanceof RegExp) {
  34186. return this.walk((child, i) => {
  34187. if (child.type === 'atrule' && name.test(child.name)) {
  34188. return callback(child, i)
  34189. }
  34190. })
  34191. }
  34192. return this.walk((child, i) => {
  34193. if (child.type === 'atrule' && child.name === name) {
  34194. return callback(child, i)
  34195. }
  34196. })
  34197. }
  34198. walkComments(callback) {
  34199. return this.walk((child, i) => {
  34200. if (child.type === 'comment') {
  34201. return callback(child, i)
  34202. }
  34203. })
  34204. }
  34205. walkDecls(prop, callback) {
  34206. if (!callback) {
  34207. callback = prop;
  34208. return this.walk((child, i) => {
  34209. if (child.type === 'decl') {
  34210. return callback(child, i)
  34211. }
  34212. })
  34213. }
  34214. if (prop instanceof RegExp) {
  34215. return this.walk((child, i) => {
  34216. if (child.type === 'decl' && prop.test(child.prop)) {
  34217. return callback(child, i)
  34218. }
  34219. })
  34220. }
  34221. return this.walk((child, i) => {
  34222. if (child.type === 'decl' && child.prop === prop) {
  34223. return callback(child, i)
  34224. }
  34225. })
  34226. }
  34227. walkRules(selector, callback) {
  34228. if (!callback) {
  34229. callback = selector;
  34230. return this.walk((child, i) => {
  34231. if (child.type === 'rule') {
  34232. return callback(child, i)
  34233. }
  34234. })
  34235. }
  34236. if (selector instanceof RegExp) {
  34237. return this.walk((child, i) => {
  34238. if (child.type === 'rule' && selector.test(child.selector)) {
  34239. return callback(child, i)
  34240. }
  34241. })
  34242. }
  34243. return this.walk((child, i) => {
  34244. if (child.type === 'rule' && child.selector === selector) {
  34245. return callback(child, i)
  34246. }
  34247. })
  34248. }
  34249. }
  34250. Container.registerParse = dependant => {
  34251. parse = dependant;
  34252. };
  34253. Container.registerRule = dependant => {
  34254. Rule = dependant;
  34255. };
  34256. Container.registerAtRule = dependant => {
  34257. AtRule = dependant;
  34258. };
  34259. Container.registerRoot = dependant => {
  34260. Root = dependant;
  34261. };
  34262. container$1 = Container;
  34263. Container.default = Container;
  34264. /* c8 ignore start */
  34265. Container.rebuild = node => {
  34266. if (node.type === 'atrule') {
  34267. Object.setPrototypeOf(node, AtRule.prototype);
  34268. } else if (node.type === 'rule') {
  34269. Object.setPrototypeOf(node, Rule.prototype);
  34270. } else if (node.type === 'decl') {
  34271. Object.setPrototypeOf(node, Declaration.prototype);
  34272. } else if (node.type === 'comment') {
  34273. Object.setPrototypeOf(node, Comment.prototype);
  34274. } else if (node.type === 'root') {
  34275. Object.setPrototypeOf(node, Root.prototype);
  34276. }
  34277. node[my] = true;
  34278. if (node.nodes) {
  34279. node.nodes.forEach(child => {
  34280. Container.rebuild(child);
  34281. });
  34282. }
  34283. };
  34284. /* c8 ignore stop */
  34285. return container$1;
  34286. }
  34287. var atRule;
  34288. var hasRequiredAtRule;
  34289. function requireAtRule () {
  34290. if (hasRequiredAtRule) return atRule;
  34291. hasRequiredAtRule = 1;
  34292. let Container = /*@__PURE__*/ requireContainer$1();
  34293. class AtRule extends Container {
  34294. constructor(defaults) {
  34295. super(defaults);
  34296. this.type = 'atrule';
  34297. }
  34298. append(...children) {
  34299. if (!this.proxyOf.nodes) this.nodes = [];
  34300. return super.append(...children)
  34301. }
  34302. prepend(...children) {
  34303. if (!this.proxyOf.nodes) this.nodes = [];
  34304. return super.prepend(...children)
  34305. }
  34306. }
  34307. atRule = AtRule;
  34308. AtRule.default = AtRule;
  34309. Container.registerAtRule(AtRule);
  34310. return atRule;
  34311. }
  34312. var document;
  34313. var hasRequiredDocument;
  34314. function requireDocument () {
  34315. if (hasRequiredDocument) return document;
  34316. hasRequiredDocument = 1;
  34317. let Container = /*@__PURE__*/ requireContainer$1();
  34318. let LazyResult, Processor;
  34319. class Document extends Container {
  34320. constructor(defaults) {
  34321. // type needs to be passed to super, otherwise child roots won't be normalized correctly
  34322. super({ type: 'document', ...defaults });
  34323. if (!this.nodes) {
  34324. this.nodes = [];
  34325. }
  34326. }
  34327. toResult(opts = {}) {
  34328. let lazy = new LazyResult(new Processor(), this, opts);
  34329. return lazy.stringify()
  34330. }
  34331. }
  34332. Document.registerLazyResult = dependant => {
  34333. LazyResult = dependant;
  34334. };
  34335. Document.registerProcessor = dependant => {
  34336. Processor = dependant;
  34337. };
  34338. document = Document;
  34339. Document.default = Document;
  34340. return document;
  34341. }
  34342. var nonSecure;
  34343. var hasRequiredNonSecure;
  34344. function requireNonSecure () {
  34345. if (hasRequiredNonSecure) return nonSecure;
  34346. hasRequiredNonSecure = 1;
  34347. // This alphabet uses `A-Za-z0-9_-` symbols.
  34348. // The order of characters is optimized for better gzip and brotli compression.
  34349. // References to the same file (works both for gzip and brotli):
  34350. // `'use`, `andom`, and `rict'`
  34351. // References to the brotli default dictionary:
  34352. // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
  34353. let urlAlphabet =
  34354. 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
  34355. let customAlphabet = (alphabet, defaultSize = 21) => {
  34356. return (size = defaultSize) => {
  34357. let id = '';
  34358. // A compact alternative for `for (var i = 0; i < step; i++)`.
  34359. let i = size | 0;
  34360. while (i--) {
  34361. // `| 0` is more compact and faster than `Math.floor()`.
  34362. id += alphabet[(Math.random() * alphabet.length) | 0];
  34363. }
  34364. return id
  34365. }
  34366. };
  34367. let nanoid = (size = 21) => {
  34368. let id = '';
  34369. // A compact alternative for `for (var i = 0; i < step; i++)`.
  34370. let i = size | 0;
  34371. while (i--) {
  34372. // `| 0` is more compact and faster than `Math.floor()`.
  34373. id += urlAlphabet[(Math.random() * 64) | 0];
  34374. }
  34375. return id
  34376. };
  34377. nonSecure = { nanoid, customAlphabet };
  34378. return nonSecure;
  34379. }
  34380. var require$$2 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_url$1);
  34381. var previousMap;
  34382. var hasRequiredPreviousMap;
  34383. function requirePreviousMap () {
  34384. if (hasRequiredPreviousMap) return previousMap;
  34385. hasRequiredPreviousMap = 1;
  34386. let { existsSync, readFileSync } = require$$0$1;
  34387. let { dirname, join } = require$$1;
  34388. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34389. function fromBase64(str) {
  34390. if (Buffer$1) {
  34391. return Buffer$1.from(str, 'base64').toString()
  34392. } else {
  34393. /* c8 ignore next 2 */
  34394. return window.atob(str)
  34395. }
  34396. }
  34397. class PreviousMap {
  34398. constructor(css, opts) {
  34399. if (opts.map === false) return
  34400. this.loadAnnotation(css);
  34401. this.inline = this.startWith(this.annotation, 'data:');
  34402. let prev = opts.map ? opts.map.prev : undefined;
  34403. let text = this.loadMap(opts.from, prev);
  34404. if (!this.mapFile && opts.from) {
  34405. this.mapFile = opts.from;
  34406. }
  34407. if (this.mapFile) this.root = dirname(this.mapFile);
  34408. if (text) this.text = text;
  34409. }
  34410. consumer() {
  34411. if (!this.consumerCache) {
  34412. this.consumerCache = new SourceMapConsumer(this.text);
  34413. }
  34414. return this.consumerCache
  34415. }
  34416. decodeInline(text) {
  34417. let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
  34418. let baseUri = /^data:application\/json;base64,/;
  34419. let charsetUri = /^data:application\/json;charset=utf-?8,/;
  34420. let uri = /^data:application\/json,/;
  34421. let uriMatch = text.match(charsetUri) || text.match(uri);
  34422. if (uriMatch) {
  34423. return decodeURIComponent(text.substr(uriMatch[0].length))
  34424. }
  34425. let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri);
  34426. if (baseUriMatch) {
  34427. return fromBase64(text.substr(baseUriMatch[0].length))
  34428. }
  34429. let encoding = text.match(/data:application\/json;([^,]+),/)[1];
  34430. throw new Error('Unsupported source map encoding ' + encoding)
  34431. }
  34432. getAnnotationURL(sourceMapString) {
  34433. return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
  34434. }
  34435. isMap(map) {
  34436. if (typeof map !== 'object') return false
  34437. return (
  34438. typeof map.mappings === 'string' ||
  34439. typeof map._mappings === 'string' ||
  34440. Array.isArray(map.sections)
  34441. )
  34442. }
  34443. loadAnnotation(css) {
  34444. let comments = css.match(/\/\*\s*# sourceMappingURL=/g);
  34445. if (!comments) return
  34446. // sourceMappingURLs from comments, strings, etc.
  34447. let start = css.lastIndexOf(comments.pop());
  34448. let end = css.indexOf('*/', start);
  34449. if (start > -1 && end > -1) {
  34450. // Locate the last sourceMappingURL to avoid pickin
  34451. this.annotation = this.getAnnotationURL(css.substring(start, end));
  34452. }
  34453. }
  34454. loadFile(path) {
  34455. this.root = dirname(path);
  34456. if (existsSync(path)) {
  34457. this.mapFile = path;
  34458. return readFileSync(path, 'utf-8').toString().trim()
  34459. }
  34460. }
  34461. loadMap(file, prev) {
  34462. if (prev === false) return false
  34463. if (prev) {
  34464. if (typeof prev === 'string') {
  34465. return prev
  34466. } else if (typeof prev === 'function') {
  34467. let prevPath = prev(file);
  34468. if (prevPath) {
  34469. let map = this.loadFile(prevPath);
  34470. if (!map) {
  34471. throw new Error(
  34472. 'Unable to load previous source map: ' + prevPath.toString()
  34473. )
  34474. }
  34475. return map
  34476. }
  34477. } else if (prev instanceof SourceMapConsumer) {
  34478. return SourceMapGenerator.fromSourceMap(prev).toString()
  34479. } else if (prev instanceof SourceMapGenerator) {
  34480. return prev.toString()
  34481. } else if (this.isMap(prev)) {
  34482. return JSON.stringify(prev)
  34483. } else {
  34484. throw new Error(
  34485. 'Unsupported previous source map format: ' + prev.toString()
  34486. )
  34487. }
  34488. } else if (this.inline) {
  34489. return this.decodeInline(this.annotation)
  34490. } else if (this.annotation) {
  34491. let map = this.annotation;
  34492. if (file) map = join(dirname(file), map);
  34493. return this.loadFile(map)
  34494. }
  34495. }
  34496. startWith(string, start) {
  34497. if (!string) return false
  34498. return string.substr(0, start.length) === start
  34499. }
  34500. withContent() {
  34501. return !!(
  34502. this.consumer().sourcesContent &&
  34503. this.consumer().sourcesContent.length > 0
  34504. )
  34505. }
  34506. }
  34507. previousMap = PreviousMap;
  34508. PreviousMap.default = PreviousMap;
  34509. return previousMap;
  34510. }
  34511. var input;
  34512. var hasRequiredInput;
  34513. function requireInput () {
  34514. if (hasRequiredInput) return input;
  34515. hasRequiredInput = 1;
  34516. let { nanoid } = /*@__PURE__*/ requireNonSecure();
  34517. let { isAbsolute, resolve } = require$$1;
  34518. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34519. let { fileURLToPath, pathToFileURL } = require$$2;
  34520. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  34521. let PreviousMap = /*@__PURE__*/ requirePreviousMap();
  34522. let terminalHighlight = /*@__PURE__*/ requireTerminalHighlight();
  34523. let lineToIndexCache = Symbol('lineToIndexCache');
  34524. let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
  34525. let pathAvailable = Boolean(resolve && isAbsolute);
  34526. function getLineToIndex(input) {
  34527. if (input[lineToIndexCache]) return input[lineToIndexCache]
  34528. let lines = input.css.split('\n');
  34529. let lineToIndex = new Array(lines.length);
  34530. let prevIndex = 0;
  34531. for (let i = 0, l = lines.length; i < l; i++) {
  34532. lineToIndex[i] = prevIndex;
  34533. prevIndex += lines[i].length + 1;
  34534. }
  34535. input[lineToIndexCache] = lineToIndex;
  34536. return lineToIndex
  34537. }
  34538. class Input {
  34539. get from() {
  34540. return this.file || this.id
  34541. }
  34542. constructor(css, opts = {}) {
  34543. if (
  34544. css === null ||
  34545. typeof css === 'undefined' ||
  34546. (typeof css === 'object' && !css.toString)
  34547. ) {
  34548. throw new Error(`PostCSS received ${css} instead of CSS string`)
  34549. }
  34550. this.css = css.toString();
  34551. if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
  34552. this.hasBOM = true;
  34553. this.css = this.css.slice(1);
  34554. } else {
  34555. this.hasBOM = false;
  34556. }
  34557. this.document = this.css;
  34558. if (opts.document) this.document = opts.document.toString();
  34559. if (opts.from) {
  34560. if (
  34561. !pathAvailable ||
  34562. /^\w+:\/\//.test(opts.from) ||
  34563. isAbsolute(opts.from)
  34564. ) {
  34565. this.file = opts.from;
  34566. } else {
  34567. this.file = resolve(opts.from);
  34568. }
  34569. }
  34570. if (pathAvailable && sourceMapAvailable) {
  34571. let map = new PreviousMap(this.css, opts);
  34572. if (map.text) {
  34573. this.map = map;
  34574. let file = map.consumer().file;
  34575. if (!this.file && file) this.file = this.mapResolve(file);
  34576. }
  34577. }
  34578. if (!this.file) {
  34579. this.id = '<input css ' + nanoid(6) + '>';
  34580. }
  34581. if (this.map) this.map.file = this.from;
  34582. }
  34583. error(message, line, column, opts = {}) {
  34584. let endColumn, endLine, endOffset, offset, result;
  34585. if (line && typeof line === 'object') {
  34586. let start = line;
  34587. let end = column;
  34588. if (typeof start.offset === 'number') {
  34589. offset = start.offset;
  34590. let pos = this.fromOffset(offset);
  34591. line = pos.line;
  34592. column = pos.col;
  34593. } else {
  34594. line = start.line;
  34595. column = start.column;
  34596. offset = this.fromLineAndColumn(line, column);
  34597. }
  34598. if (typeof end.offset === 'number') {
  34599. endOffset = end.offset;
  34600. let pos = this.fromOffset(endOffset);
  34601. endLine = pos.line;
  34602. endColumn = pos.col;
  34603. } else {
  34604. endLine = end.line;
  34605. endColumn = end.column;
  34606. endOffset = this.fromLineAndColumn(end.line, end.column);
  34607. }
  34608. } else if (!column) {
  34609. offset = line;
  34610. let pos = this.fromOffset(offset);
  34611. line = pos.line;
  34612. column = pos.col;
  34613. } else {
  34614. offset = this.fromLineAndColumn(line, column);
  34615. }
  34616. let origin = this.origin(line, column, endLine, endColumn);
  34617. if (origin) {
  34618. result = new CssSyntaxError(
  34619. message,
  34620. origin.endLine === undefined
  34621. ? origin.line
  34622. : { column: origin.column, line: origin.line },
  34623. origin.endLine === undefined
  34624. ? origin.column
  34625. : { column: origin.endColumn, line: origin.endLine },
  34626. origin.source,
  34627. origin.file,
  34628. opts.plugin
  34629. );
  34630. } else {
  34631. result = new CssSyntaxError(
  34632. message,
  34633. endLine === undefined ? line : { column, line },
  34634. endLine === undefined ? column : { column: endColumn, line: endLine },
  34635. this.css,
  34636. this.file,
  34637. opts.plugin
  34638. );
  34639. }
  34640. result.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
  34641. if (this.file) {
  34642. if (pathToFileURL) {
  34643. result.input.url = pathToFileURL(this.file).toString();
  34644. }
  34645. result.input.file = this.file;
  34646. }
  34647. return result
  34648. }
  34649. fromLineAndColumn(line, column) {
  34650. let lineToIndex = getLineToIndex(this);
  34651. let index = lineToIndex[line - 1];
  34652. return index + column - 1
  34653. }
  34654. fromOffset(offset) {
  34655. let lineToIndex = getLineToIndex(this);
  34656. let lastLine = lineToIndex[lineToIndex.length - 1];
  34657. let min = 0;
  34658. if (offset >= lastLine) {
  34659. min = lineToIndex.length - 1;
  34660. } else {
  34661. let max = lineToIndex.length - 2;
  34662. let mid;
  34663. while (min < max) {
  34664. mid = min + ((max - min) >> 1);
  34665. if (offset < lineToIndex[mid]) {
  34666. max = mid - 1;
  34667. } else if (offset >= lineToIndex[mid + 1]) {
  34668. min = mid + 1;
  34669. } else {
  34670. min = mid;
  34671. break
  34672. }
  34673. }
  34674. }
  34675. return {
  34676. col: offset - lineToIndex[min] + 1,
  34677. line: min + 1
  34678. }
  34679. }
  34680. mapResolve(file) {
  34681. if (/^\w+:\/\//.test(file)) {
  34682. return file
  34683. }
  34684. return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
  34685. }
  34686. origin(line, column, endLine, endColumn) {
  34687. if (!this.map) return false
  34688. let consumer = this.map.consumer();
  34689. let from = consumer.originalPositionFor({ column, line });
  34690. if (!from.source) return false
  34691. let to;
  34692. if (typeof endLine === 'number') {
  34693. to = consumer.originalPositionFor({ column: endColumn, line: endLine });
  34694. }
  34695. let fromUrl;
  34696. if (isAbsolute(from.source)) {
  34697. fromUrl = pathToFileURL(from.source);
  34698. } else {
  34699. fromUrl = new URL(
  34700. from.source,
  34701. this.map.consumer().sourceRoot || pathToFileURL(this.map.mapFile)
  34702. );
  34703. }
  34704. let result = {
  34705. column: from.column,
  34706. endColumn: to && to.column,
  34707. endLine: to && to.line,
  34708. line: from.line,
  34709. url: fromUrl.toString()
  34710. };
  34711. if (fromUrl.protocol === 'file:') {
  34712. if (fileURLToPath) {
  34713. result.file = fileURLToPath(fromUrl);
  34714. } else {
  34715. /* c8 ignore next 2 */
  34716. throw new Error(`file: protocol is not available in this PostCSS build`)
  34717. }
  34718. }
  34719. let source = consumer.sourceContentFor(from.source);
  34720. if (source) result.source = source;
  34721. return result
  34722. }
  34723. toJSON() {
  34724. let json = {};
  34725. for (let name of ['hasBOM', 'css', 'file', 'id']) {
  34726. if (this[name] != null) {
  34727. json[name] = this[name];
  34728. }
  34729. }
  34730. if (this.map) {
  34731. json.map = { ...this.map };
  34732. if (json.map.consumerCache) {
  34733. json.map.consumerCache = undefined;
  34734. }
  34735. }
  34736. return json
  34737. }
  34738. }
  34739. input = Input;
  34740. Input.default = Input;
  34741. if (terminalHighlight && terminalHighlight.registerInput) {
  34742. terminalHighlight.registerInput(Input);
  34743. }
  34744. return input;
  34745. }
  34746. var root$1;
  34747. var hasRequiredRoot$1;
  34748. function requireRoot$1 () {
  34749. if (hasRequiredRoot$1) return root$1;
  34750. hasRequiredRoot$1 = 1;
  34751. let Container = /*@__PURE__*/ requireContainer$1();
  34752. let LazyResult, Processor;
  34753. class Root extends Container {
  34754. constructor(defaults) {
  34755. super(defaults);
  34756. this.type = 'root';
  34757. if (!this.nodes) this.nodes = [];
  34758. }
  34759. normalize(child, sample, type) {
  34760. let nodes = super.normalize(child);
  34761. if (sample) {
  34762. if (type === 'prepend') {
  34763. if (this.nodes.length > 1) {
  34764. sample.raws.before = this.nodes[1].raws.before;
  34765. } else {
  34766. delete sample.raws.before;
  34767. }
  34768. } else if (this.first !== sample) {
  34769. for (let node of nodes) {
  34770. node.raws.before = sample.raws.before;
  34771. }
  34772. }
  34773. }
  34774. return nodes
  34775. }
  34776. removeChild(child, ignore) {
  34777. let index = this.index(child);
  34778. if (!ignore && index === 0 && this.nodes.length > 1) {
  34779. this.nodes[1].raws.before = this.nodes[index].raws.before;
  34780. }
  34781. return super.removeChild(child)
  34782. }
  34783. toResult(opts = {}) {
  34784. let lazy = new LazyResult(new Processor(), this, opts);
  34785. return lazy.stringify()
  34786. }
  34787. }
  34788. Root.registerLazyResult = dependant => {
  34789. LazyResult = dependant;
  34790. };
  34791. Root.registerProcessor = dependant => {
  34792. Processor = dependant;
  34793. };
  34794. root$1 = Root;
  34795. Root.default = Root;
  34796. Container.registerRoot(Root);
  34797. return root$1;
  34798. }
  34799. var list_1;
  34800. var hasRequiredList;
  34801. function requireList () {
  34802. if (hasRequiredList) return list_1;
  34803. hasRequiredList = 1;
  34804. let list = {
  34805. comma(string) {
  34806. return list.split(string, [','], true)
  34807. },
  34808. space(string) {
  34809. let spaces = [' ', '\n', '\t'];
  34810. return list.split(string, spaces)
  34811. },
  34812. split(string, separators, last) {
  34813. let array = [];
  34814. let current = '';
  34815. let split = false;
  34816. let func = 0;
  34817. let inQuote = false;
  34818. let prevQuote = '';
  34819. let escape = false;
  34820. for (let letter of string) {
  34821. if (escape) {
  34822. escape = false;
  34823. } else if (letter === '\\') {
  34824. escape = true;
  34825. } else if (inQuote) {
  34826. if (letter === prevQuote) {
  34827. inQuote = false;
  34828. }
  34829. } else if (letter === '"' || letter === "'") {
  34830. inQuote = true;
  34831. prevQuote = letter;
  34832. } else if (letter === '(') {
  34833. func += 1;
  34834. } else if (letter === ')') {
  34835. if (func > 0) func -= 1;
  34836. } else if (func === 0) {
  34837. if (separators.includes(letter)) split = true;
  34838. }
  34839. if (split) {
  34840. if (current !== '') array.push(current.trim());
  34841. current = '';
  34842. split = false;
  34843. } else {
  34844. current += letter;
  34845. }
  34846. }
  34847. if (last || current !== '') array.push(current.trim());
  34848. return array
  34849. }
  34850. };
  34851. list_1 = list;
  34852. list.default = list;
  34853. return list_1;
  34854. }
  34855. var rule;
  34856. var hasRequiredRule;
  34857. function requireRule () {
  34858. if (hasRequiredRule) return rule;
  34859. hasRequiredRule = 1;
  34860. let Container = /*@__PURE__*/ requireContainer$1();
  34861. let list = /*@__PURE__*/ requireList();
  34862. class Rule extends Container {
  34863. get selectors() {
  34864. return list.comma(this.selector)
  34865. }
  34866. set selectors(values) {
  34867. let match = this.selector ? this.selector.match(/,\s*/) : null;
  34868. let sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
  34869. this.selector = values.join(sep);
  34870. }
  34871. constructor(defaults) {
  34872. super(defaults);
  34873. this.type = 'rule';
  34874. if (!this.nodes) this.nodes = [];
  34875. }
  34876. }
  34877. rule = Rule;
  34878. Rule.default = Rule;
  34879. Container.registerRule(Rule);
  34880. return rule;
  34881. }
  34882. var fromJSON_1;
  34883. var hasRequiredFromJSON;
  34884. function requireFromJSON () {
  34885. if (hasRequiredFromJSON) return fromJSON_1;
  34886. hasRequiredFromJSON = 1;
  34887. let AtRule = /*@__PURE__*/ requireAtRule();
  34888. let Comment = /*@__PURE__*/ requireComment$1();
  34889. let Declaration = /*@__PURE__*/ requireDeclaration();
  34890. let Input = /*@__PURE__*/ requireInput();
  34891. let PreviousMap = /*@__PURE__*/ requirePreviousMap();
  34892. let Root = /*@__PURE__*/ requireRoot$1();
  34893. let Rule = /*@__PURE__*/ requireRule();
  34894. function fromJSON(json, inputs) {
  34895. if (Array.isArray(json)) return json.map(n => fromJSON(n))
  34896. let { inputs: ownInputs, ...defaults } = json;
  34897. if (ownInputs) {
  34898. inputs = [];
  34899. for (let input of ownInputs) {
  34900. let inputHydrated = { ...input, __proto__: Input.prototype };
  34901. if (inputHydrated.map) {
  34902. inputHydrated.map = {
  34903. ...inputHydrated.map,
  34904. __proto__: PreviousMap.prototype
  34905. };
  34906. }
  34907. inputs.push(inputHydrated);
  34908. }
  34909. }
  34910. if (defaults.nodes) {
  34911. defaults.nodes = json.nodes.map(n => fromJSON(n, inputs));
  34912. }
  34913. if (defaults.source) {
  34914. let { inputId, ...source } = defaults.source;
  34915. defaults.source = source;
  34916. if (inputId != null) {
  34917. defaults.source.input = inputs[inputId];
  34918. }
  34919. }
  34920. if (defaults.type === 'root') {
  34921. return new Root(defaults)
  34922. } else if (defaults.type === 'decl') {
  34923. return new Declaration(defaults)
  34924. } else if (defaults.type === 'rule') {
  34925. return new Rule(defaults)
  34926. } else if (defaults.type === 'comment') {
  34927. return new Comment(defaults)
  34928. } else if (defaults.type === 'atrule') {
  34929. return new AtRule(defaults)
  34930. } else {
  34931. throw new Error('Unknown node type: ' + json.type)
  34932. }
  34933. }
  34934. fromJSON_1 = fromJSON;
  34935. fromJSON.default = fromJSON;
  34936. return fromJSON_1;
  34937. }
  34938. var mapGenerator;
  34939. var hasRequiredMapGenerator;
  34940. function requireMapGenerator () {
  34941. if (hasRequiredMapGenerator) return mapGenerator;
  34942. hasRequiredMapGenerator = 1;
  34943. let { dirname, relative, resolve, sep } = require$$1;
  34944. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34945. let { pathToFileURL } = require$$2;
  34946. let Input = /*@__PURE__*/ requireInput();
  34947. let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
  34948. let pathAvailable = Boolean(dirname && resolve && relative && sep);
  34949. class MapGenerator {
  34950. constructor(stringify, root, opts, cssString) {
  34951. this.stringify = stringify;
  34952. this.mapOpts = opts.map || {};
  34953. this.root = root;
  34954. this.opts = opts;
  34955. this.css = cssString;
  34956. this.originalCSS = cssString;
  34957. this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
  34958. this.memoizedFileURLs = new Map();
  34959. this.memoizedPaths = new Map();
  34960. this.memoizedURLs = new Map();
  34961. }
  34962. addAnnotation() {
  34963. let content;
  34964. if (this.isInline()) {
  34965. content =
  34966. 'data:application/json;base64,' + this.toBase64(this.map.toString());
  34967. } else if (typeof this.mapOpts.annotation === 'string') {
  34968. content = this.mapOpts.annotation;
  34969. } else if (typeof this.mapOpts.annotation === 'function') {
  34970. content = this.mapOpts.annotation(this.opts.to, this.root);
  34971. } else {
  34972. content = this.outputFile() + '.map';
  34973. }
  34974. let eol = '\n';
  34975. if (this.css.includes('\r\n')) eol = '\r\n';
  34976. this.css += eol + '/*# sourceMappingURL=' + content + ' */';
  34977. }
  34978. applyPrevMaps() {
  34979. for (let prev of this.previous()) {
  34980. let from = this.toUrl(this.path(prev.file));
  34981. let root = prev.root || dirname(prev.file);
  34982. let map;
  34983. if (this.mapOpts.sourcesContent === false) {
  34984. map = new SourceMapConsumer(prev.text);
  34985. if (map.sourcesContent) {
  34986. map.sourcesContent = null;
  34987. }
  34988. } else {
  34989. map = prev.consumer();
  34990. }
  34991. this.map.applySourceMap(map, from, this.toUrl(this.path(root)));
  34992. }
  34993. }
  34994. clearAnnotation() {
  34995. if (this.mapOpts.annotation === false) return
  34996. if (this.root) {
  34997. let node;
  34998. for (let i = this.root.nodes.length - 1; i >= 0; i--) {
  34999. node = this.root.nodes[i];
  35000. if (node.type !== 'comment') continue
  35001. if (node.text.startsWith('# sourceMappingURL=')) {
  35002. this.root.removeChild(i);
  35003. }
  35004. }
  35005. } else if (this.css) {
  35006. this.css = this.css.replace(/\n*\/\*#[\S\s]*?\*\/$/gm, '');
  35007. }
  35008. }
  35009. generate() {
  35010. this.clearAnnotation();
  35011. if (pathAvailable && sourceMapAvailable && this.isMap()) {
  35012. return this.generateMap()
  35013. } else {
  35014. let result = '';
  35015. this.stringify(this.root, i => {
  35016. result += i;
  35017. });
  35018. return [result]
  35019. }
  35020. }
  35021. generateMap() {
  35022. if (this.root) {
  35023. this.generateString();
  35024. } else if (this.previous().length === 1) {
  35025. let prev = this.previous()[0].consumer();
  35026. prev.file = this.outputFile();
  35027. this.map = SourceMapGenerator.fromSourceMap(prev, {
  35028. ignoreInvalidMapping: true
  35029. });
  35030. } else {
  35031. this.map = new SourceMapGenerator({
  35032. file: this.outputFile(),
  35033. ignoreInvalidMapping: true
  35034. });
  35035. this.map.addMapping({
  35036. generated: { column: 0, line: 1 },
  35037. original: { column: 0, line: 1 },
  35038. source: this.opts.from
  35039. ? this.toUrl(this.path(this.opts.from))
  35040. : '<no source>'
  35041. });
  35042. }
  35043. if (this.isSourcesContent()) this.setSourcesContent();
  35044. if (this.root && this.previous().length > 0) this.applyPrevMaps();
  35045. if (this.isAnnotation()) this.addAnnotation();
  35046. if (this.isInline()) {
  35047. return [this.css]
  35048. } else {
  35049. return [this.css, this.map]
  35050. }
  35051. }
  35052. generateString() {
  35053. this.css = '';
  35054. this.map = new SourceMapGenerator({
  35055. file: this.outputFile(),
  35056. ignoreInvalidMapping: true
  35057. });
  35058. let line = 1;
  35059. let column = 1;
  35060. let noSource = '<no source>';
  35061. let mapping = {
  35062. generated: { column: 0, line: 0 },
  35063. original: { column: 0, line: 0 },
  35064. source: ''
  35065. };
  35066. let last, lines;
  35067. this.stringify(this.root, (str, node, type) => {
  35068. this.css += str;
  35069. if (node && type !== 'end') {
  35070. mapping.generated.line = line;
  35071. mapping.generated.column = column - 1;
  35072. if (node.source && node.source.start) {
  35073. mapping.source = this.sourcePath(node);
  35074. mapping.original.line = node.source.start.line;
  35075. mapping.original.column = node.source.start.column - 1;
  35076. this.map.addMapping(mapping);
  35077. } else {
  35078. mapping.source = noSource;
  35079. mapping.original.line = 1;
  35080. mapping.original.column = 0;
  35081. this.map.addMapping(mapping);
  35082. }
  35083. }
  35084. lines = str.match(/\n/g);
  35085. if (lines) {
  35086. line += lines.length;
  35087. last = str.lastIndexOf('\n');
  35088. column = str.length - last;
  35089. } else {
  35090. column += str.length;
  35091. }
  35092. if (node && type !== 'start') {
  35093. let p = node.parent || { raws: {} };
  35094. let childless =
  35095. node.type === 'decl' || (node.type === 'atrule' && !node.nodes);
  35096. if (!childless || node !== p.last || p.raws.semicolon) {
  35097. if (node.source && node.source.end) {
  35098. mapping.source = this.sourcePath(node);
  35099. mapping.original.line = node.source.end.line;
  35100. mapping.original.column = node.source.end.column - 1;
  35101. mapping.generated.line = line;
  35102. mapping.generated.column = column - 2;
  35103. this.map.addMapping(mapping);
  35104. } else {
  35105. mapping.source = noSource;
  35106. mapping.original.line = 1;
  35107. mapping.original.column = 0;
  35108. mapping.generated.line = line;
  35109. mapping.generated.column = column - 1;
  35110. this.map.addMapping(mapping);
  35111. }
  35112. }
  35113. }
  35114. });
  35115. }
  35116. isAnnotation() {
  35117. if (this.isInline()) {
  35118. return true
  35119. }
  35120. if (typeof this.mapOpts.annotation !== 'undefined') {
  35121. return this.mapOpts.annotation
  35122. }
  35123. if (this.previous().length) {
  35124. return this.previous().some(i => i.annotation)
  35125. }
  35126. return true
  35127. }
  35128. isInline() {
  35129. if (typeof this.mapOpts.inline !== 'undefined') {
  35130. return this.mapOpts.inline
  35131. }
  35132. let annotation = this.mapOpts.annotation;
  35133. if (typeof annotation !== 'undefined' && annotation !== true) {
  35134. return false
  35135. }
  35136. if (this.previous().length) {
  35137. return this.previous().some(i => i.inline)
  35138. }
  35139. return true
  35140. }
  35141. isMap() {
  35142. if (typeof this.opts.map !== 'undefined') {
  35143. return !!this.opts.map
  35144. }
  35145. return this.previous().length > 0
  35146. }
  35147. isSourcesContent() {
  35148. if (typeof this.mapOpts.sourcesContent !== 'undefined') {
  35149. return this.mapOpts.sourcesContent
  35150. }
  35151. if (this.previous().length) {
  35152. return this.previous().some(i => i.withContent())
  35153. }
  35154. return true
  35155. }
  35156. outputFile() {
  35157. if (this.opts.to) {
  35158. return this.path(this.opts.to)
  35159. } else if (this.opts.from) {
  35160. return this.path(this.opts.from)
  35161. } else {
  35162. return 'to.css'
  35163. }
  35164. }
  35165. path(file) {
  35166. if (this.mapOpts.absolute) return file
  35167. if (file.charCodeAt(0) === 60 /* `<` */) return file
  35168. if (/^\w+:\/\//.test(file)) return file
  35169. let cached = this.memoizedPaths.get(file);
  35170. if (cached) return cached
  35171. let from = this.opts.to ? dirname(this.opts.to) : '.';
  35172. if (typeof this.mapOpts.annotation === 'string') {
  35173. from = dirname(resolve(from, this.mapOpts.annotation));
  35174. }
  35175. let path = relative(from, file);
  35176. this.memoizedPaths.set(file, path);
  35177. return path
  35178. }
  35179. previous() {
  35180. if (!this.previousMaps) {
  35181. this.previousMaps = [];
  35182. if (this.root) {
  35183. this.root.walk(node => {
  35184. if (node.source && node.source.input.map) {
  35185. let map = node.source.input.map;
  35186. if (!this.previousMaps.includes(map)) {
  35187. this.previousMaps.push(map);
  35188. }
  35189. }
  35190. });
  35191. } else {
  35192. let input = new Input(this.originalCSS, this.opts);
  35193. if (input.map) this.previousMaps.push(input.map);
  35194. }
  35195. }
  35196. return this.previousMaps
  35197. }
  35198. setSourcesContent() {
  35199. let already = {};
  35200. if (this.root) {
  35201. this.root.walk(node => {
  35202. if (node.source) {
  35203. let from = node.source.input.from;
  35204. if (from && !already[from]) {
  35205. already[from] = true;
  35206. let fromUrl = this.usesFileUrls
  35207. ? this.toFileUrl(from)
  35208. : this.toUrl(this.path(from));
  35209. this.map.setSourceContent(fromUrl, node.source.input.css);
  35210. }
  35211. }
  35212. });
  35213. } else if (this.css) {
  35214. let from = this.opts.from
  35215. ? this.toUrl(this.path(this.opts.from))
  35216. : '<no source>';
  35217. this.map.setSourceContent(from, this.css);
  35218. }
  35219. }
  35220. sourcePath(node) {
  35221. if (this.mapOpts.from) {
  35222. return this.toUrl(this.mapOpts.from)
  35223. } else if (this.usesFileUrls) {
  35224. return this.toFileUrl(node.source.input.from)
  35225. } else {
  35226. return this.toUrl(this.path(node.source.input.from))
  35227. }
  35228. }
  35229. toBase64(str) {
  35230. if (Buffer$1) {
  35231. return Buffer$1.from(str).toString('base64')
  35232. } else {
  35233. return window.btoa(unescape(encodeURIComponent(str)))
  35234. }
  35235. }
  35236. toFileUrl(path) {
  35237. let cached = this.memoizedFileURLs.get(path);
  35238. if (cached) return cached
  35239. if (pathToFileURL) {
  35240. let fileURL = pathToFileURL(path).toString();
  35241. this.memoizedFileURLs.set(path, fileURL);
  35242. return fileURL
  35243. } else {
  35244. throw new Error(
  35245. '`map.absolute` option is not available in this PostCSS build'
  35246. )
  35247. }
  35248. }
  35249. toUrl(path) {
  35250. let cached = this.memoizedURLs.get(path);
  35251. if (cached) return cached
  35252. if (sep === '\\') {
  35253. path = path.replace(/\\/g, '/');
  35254. }
  35255. let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
  35256. this.memoizedURLs.set(path, url);
  35257. return url
  35258. }
  35259. }
  35260. mapGenerator = MapGenerator;
  35261. return mapGenerator;
  35262. }
  35263. var parser$1;
  35264. var hasRequiredParser$1;
  35265. function requireParser$1 () {
  35266. if (hasRequiredParser$1) return parser$1;
  35267. hasRequiredParser$1 = 1;
  35268. let AtRule = /*@__PURE__*/ requireAtRule();
  35269. let Comment = /*@__PURE__*/ requireComment$1();
  35270. let Declaration = /*@__PURE__*/ requireDeclaration();
  35271. let Root = /*@__PURE__*/ requireRoot$1();
  35272. let Rule = /*@__PURE__*/ requireRule();
  35273. let tokenizer = /*@__PURE__*/ requireTokenize$1();
  35274. const SAFE_COMMENT_NEIGHBOR = {
  35275. empty: true,
  35276. space: true
  35277. };
  35278. function findLastWithPosition(tokens) {
  35279. for (let i = tokens.length - 1; i >= 0; i--) {
  35280. let token = tokens[i];
  35281. let pos = token[3] || token[2];
  35282. if (pos) return pos
  35283. }
  35284. }
  35285. class Parser {
  35286. constructor(input) {
  35287. this.input = input;
  35288. this.root = new Root();
  35289. this.current = this.root;
  35290. this.spaces = '';
  35291. this.semicolon = false;
  35292. this.createTokenizer();
  35293. this.root.source = { input, start: { column: 1, line: 1, offset: 0 } };
  35294. }
  35295. atrule(token) {
  35296. let node = new AtRule();
  35297. node.name = token[1].slice(1);
  35298. if (node.name === '') {
  35299. this.unnamedAtrule(node, token);
  35300. }
  35301. this.init(node, token[2]);
  35302. let type;
  35303. let prev;
  35304. let shift;
  35305. let last = false;
  35306. let open = false;
  35307. let params = [];
  35308. let brackets = [];
  35309. while (!this.tokenizer.endOfFile()) {
  35310. token = this.tokenizer.nextToken();
  35311. type = token[0];
  35312. if (type === '(' || type === '[') {
  35313. brackets.push(type === '(' ? ')' : ']');
  35314. } else if (type === '{' && brackets.length > 0) {
  35315. brackets.push('}');
  35316. } else if (type === brackets[brackets.length - 1]) {
  35317. brackets.pop();
  35318. }
  35319. if (brackets.length === 0) {
  35320. if (type === ';') {
  35321. node.source.end = this.getPosition(token[2]);
  35322. node.source.end.offset++;
  35323. this.semicolon = true;
  35324. break
  35325. } else if (type === '{') {
  35326. open = true;
  35327. break
  35328. } else if (type === '}') {
  35329. if (params.length > 0) {
  35330. shift = params.length - 1;
  35331. prev = params[shift];
  35332. while (prev && prev[0] === 'space') {
  35333. prev = params[--shift];
  35334. }
  35335. if (prev) {
  35336. node.source.end = this.getPosition(prev[3] || prev[2]);
  35337. node.source.end.offset++;
  35338. }
  35339. }
  35340. this.end(token);
  35341. break
  35342. } else {
  35343. params.push(token);
  35344. }
  35345. } else {
  35346. params.push(token);
  35347. }
  35348. if (this.tokenizer.endOfFile()) {
  35349. last = true;
  35350. break
  35351. }
  35352. }
  35353. node.raws.between = this.spacesAndCommentsFromEnd(params);
  35354. if (params.length) {
  35355. node.raws.afterName = this.spacesAndCommentsFromStart(params);
  35356. this.raw(node, 'params', params);
  35357. if (last) {
  35358. token = params[params.length - 1];
  35359. node.source.end = this.getPosition(token[3] || token[2]);
  35360. node.source.end.offset++;
  35361. this.spaces = node.raws.between;
  35362. node.raws.between = '';
  35363. }
  35364. } else {
  35365. node.raws.afterName = '';
  35366. node.params = '';
  35367. }
  35368. if (open) {
  35369. node.nodes = [];
  35370. this.current = node;
  35371. }
  35372. }
  35373. checkMissedSemicolon(tokens) {
  35374. let colon = this.colon(tokens);
  35375. if (colon === false) return
  35376. let founded = 0;
  35377. let token;
  35378. for (let j = colon - 1; j >= 0; j--) {
  35379. token = tokens[j];
  35380. if (token[0] !== 'space') {
  35381. founded += 1;
  35382. if (founded === 2) break
  35383. }
  35384. }
  35385. // If the token is a word, e.g. `!important`, `red` or any other valid property's value.
  35386. // Then we need to return the colon after that word token. [3] is the "end" colon of that word.
  35387. // And because we need it after that one we do +1 to get the next one.
  35388. throw this.input.error(
  35389. 'Missed semicolon',
  35390. token[0] === 'word' ? token[3] + 1 : token[2]
  35391. )
  35392. }
  35393. colon(tokens) {
  35394. let brackets = 0;
  35395. let prev, token, type;
  35396. for (let [i, element] of tokens.entries()) {
  35397. token = element;
  35398. type = token[0];
  35399. if (type === '(') {
  35400. brackets += 1;
  35401. }
  35402. if (type === ')') {
  35403. brackets -= 1;
  35404. }
  35405. if (brackets === 0 && type === ':') {
  35406. if (!prev) {
  35407. this.doubleColon(token);
  35408. } else if (prev[0] === 'word' && prev[1] === 'progid') {
  35409. continue
  35410. } else {
  35411. return i
  35412. }
  35413. }
  35414. prev = token;
  35415. }
  35416. return false
  35417. }
  35418. comment(token) {
  35419. let node = new Comment();
  35420. this.init(node, token[2]);
  35421. node.source.end = this.getPosition(token[3] || token[2]);
  35422. node.source.end.offset++;
  35423. let text = token[1].slice(2, -2);
  35424. if (/^\s*$/.test(text)) {
  35425. node.text = '';
  35426. node.raws.left = text;
  35427. node.raws.right = '';
  35428. } else {
  35429. let match = text.match(/^(\s*)([^]*\S)(\s*)$/);
  35430. node.text = match[2];
  35431. node.raws.left = match[1];
  35432. node.raws.right = match[3];
  35433. }
  35434. }
  35435. createTokenizer() {
  35436. this.tokenizer = tokenizer(this.input);
  35437. }
  35438. decl(tokens, customProperty) {
  35439. let node = new Declaration();
  35440. this.init(node, tokens[0][2]);
  35441. let last = tokens[tokens.length - 1];
  35442. if (last[0] === ';') {
  35443. this.semicolon = true;
  35444. tokens.pop();
  35445. }
  35446. node.source.end = this.getPosition(
  35447. last[3] || last[2] || findLastWithPosition(tokens)
  35448. );
  35449. node.source.end.offset++;
  35450. while (tokens[0][0] !== 'word') {
  35451. if (tokens.length === 1) this.unknownWord(tokens);
  35452. node.raws.before += tokens.shift()[1];
  35453. }
  35454. node.source.start = this.getPosition(tokens[0][2]);
  35455. node.prop = '';
  35456. while (tokens.length) {
  35457. let type = tokens[0][0];
  35458. if (type === ':' || type === 'space' || type === 'comment') {
  35459. break
  35460. }
  35461. node.prop += tokens.shift()[1];
  35462. }
  35463. node.raws.between = '';
  35464. let token;
  35465. while (tokens.length) {
  35466. token = tokens.shift();
  35467. if (token[0] === ':') {
  35468. node.raws.between += token[1];
  35469. break
  35470. } else {
  35471. if (token[0] === 'word' && /\w/.test(token[1])) {
  35472. this.unknownWord([token]);
  35473. }
  35474. node.raws.between += token[1];
  35475. }
  35476. }
  35477. if (node.prop[0] === '_' || node.prop[0] === '*') {
  35478. node.raws.before += node.prop[0];
  35479. node.prop = node.prop.slice(1);
  35480. }
  35481. let firstSpaces = [];
  35482. let next;
  35483. while (tokens.length) {
  35484. next = tokens[0][0];
  35485. if (next !== 'space' && next !== 'comment') break
  35486. firstSpaces.push(tokens.shift());
  35487. }
  35488. this.precheckMissedSemicolon(tokens);
  35489. for (let i = tokens.length - 1; i >= 0; i--) {
  35490. token = tokens[i];
  35491. if (token[1].toLowerCase() === '!important') {
  35492. node.important = true;
  35493. let string = this.stringFrom(tokens, i);
  35494. string = this.spacesFromEnd(tokens) + string;
  35495. if (string !== ' !important') node.raws.important = string;
  35496. break
  35497. } else if (token[1].toLowerCase() === 'important') {
  35498. let cache = tokens.slice(0);
  35499. let str = '';
  35500. for (let j = i; j > 0; j--) {
  35501. let type = cache[j][0];
  35502. if (str.trim().startsWith('!') && type !== 'space') {
  35503. break
  35504. }
  35505. str = cache.pop()[1] + str;
  35506. }
  35507. if (str.trim().startsWith('!')) {
  35508. node.important = true;
  35509. node.raws.important = str;
  35510. tokens = cache;
  35511. }
  35512. }
  35513. if (token[0] !== 'space' && token[0] !== 'comment') {
  35514. break
  35515. }
  35516. }
  35517. let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment');
  35518. if (hasWord) {
  35519. node.raws.between += firstSpaces.map(i => i[1]).join('');
  35520. firstSpaces = [];
  35521. }
  35522. this.raw(node, 'value', firstSpaces.concat(tokens), customProperty);
  35523. if (node.value.includes(':') && !customProperty) {
  35524. this.checkMissedSemicolon(tokens);
  35525. }
  35526. }
  35527. doubleColon(token) {
  35528. throw this.input.error(
  35529. 'Double colon',
  35530. { offset: token[2] },
  35531. { offset: token[2] + token[1].length }
  35532. )
  35533. }
  35534. emptyRule(token) {
  35535. let node = new Rule();
  35536. this.init(node, token[2]);
  35537. node.selector = '';
  35538. node.raws.between = '';
  35539. this.current = node;
  35540. }
  35541. end(token) {
  35542. if (this.current.nodes && this.current.nodes.length) {
  35543. this.current.raws.semicolon = this.semicolon;
  35544. }
  35545. this.semicolon = false;
  35546. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35547. this.spaces = '';
  35548. if (this.current.parent) {
  35549. this.current.source.end = this.getPosition(token[2]);
  35550. this.current.source.end.offset++;
  35551. this.current = this.current.parent;
  35552. } else {
  35553. this.unexpectedClose(token);
  35554. }
  35555. }
  35556. endFile() {
  35557. if (this.current.parent) this.unclosedBlock();
  35558. if (this.current.nodes && this.current.nodes.length) {
  35559. this.current.raws.semicolon = this.semicolon;
  35560. }
  35561. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35562. this.root.source.end = this.getPosition(this.tokenizer.position());
  35563. }
  35564. freeSemicolon(token) {
  35565. this.spaces += token[1];
  35566. if (this.current.nodes) {
  35567. let prev = this.current.nodes[this.current.nodes.length - 1];
  35568. if (prev && prev.type === 'rule' && !prev.raws.ownSemicolon) {
  35569. prev.raws.ownSemicolon = this.spaces;
  35570. this.spaces = '';
  35571. prev.source.end = this.getPosition(token[2]);
  35572. prev.source.end.offset += prev.raws.ownSemicolon.length;
  35573. }
  35574. }
  35575. }
  35576. // Helpers
  35577. getPosition(offset) {
  35578. let pos = this.input.fromOffset(offset);
  35579. return {
  35580. column: pos.col,
  35581. line: pos.line,
  35582. offset
  35583. }
  35584. }
  35585. init(node, offset) {
  35586. this.current.push(node);
  35587. node.source = {
  35588. input: this.input,
  35589. start: this.getPosition(offset)
  35590. };
  35591. node.raws.before = this.spaces;
  35592. this.spaces = '';
  35593. if (node.type !== 'comment') this.semicolon = false;
  35594. }
  35595. other(start) {
  35596. let end = false;
  35597. let type = null;
  35598. let colon = false;
  35599. let bracket = null;
  35600. let brackets = [];
  35601. let customProperty = start[1].startsWith('--');
  35602. let tokens = [];
  35603. let token = start;
  35604. while (token) {
  35605. type = token[0];
  35606. tokens.push(token);
  35607. if (type === '(' || type === '[') {
  35608. if (!bracket) bracket = token;
  35609. brackets.push(type === '(' ? ')' : ']');
  35610. } else if (customProperty && colon && type === '{') {
  35611. if (!bracket) bracket = token;
  35612. brackets.push('}');
  35613. } else if (brackets.length === 0) {
  35614. if (type === ';') {
  35615. if (colon) {
  35616. this.decl(tokens, customProperty);
  35617. return
  35618. } else {
  35619. break
  35620. }
  35621. } else if (type === '{') {
  35622. this.rule(tokens);
  35623. return
  35624. } else if (type === '}') {
  35625. this.tokenizer.back(tokens.pop());
  35626. end = true;
  35627. break
  35628. } else if (type === ':') {
  35629. colon = true;
  35630. }
  35631. } else if (type === brackets[brackets.length - 1]) {
  35632. brackets.pop();
  35633. if (brackets.length === 0) bracket = null;
  35634. }
  35635. token = this.tokenizer.nextToken();
  35636. }
  35637. if (this.tokenizer.endOfFile()) end = true;
  35638. if (brackets.length > 0) this.unclosedBracket(bracket);
  35639. if (end && colon) {
  35640. if (!customProperty) {
  35641. while (tokens.length) {
  35642. token = tokens[tokens.length - 1][0];
  35643. if (token !== 'space' && token !== 'comment') break
  35644. this.tokenizer.back(tokens.pop());
  35645. }
  35646. }
  35647. this.decl(tokens, customProperty);
  35648. } else {
  35649. this.unknownWord(tokens);
  35650. }
  35651. }
  35652. parse() {
  35653. let token;
  35654. while (!this.tokenizer.endOfFile()) {
  35655. token = this.tokenizer.nextToken();
  35656. switch (token[0]) {
  35657. case 'space':
  35658. this.spaces += token[1];
  35659. break
  35660. case ';':
  35661. this.freeSemicolon(token);
  35662. break
  35663. case '}':
  35664. this.end(token);
  35665. break
  35666. case 'comment':
  35667. this.comment(token);
  35668. break
  35669. case 'at-word':
  35670. this.atrule(token);
  35671. break
  35672. case '{':
  35673. this.emptyRule(token);
  35674. break
  35675. default:
  35676. this.other(token);
  35677. break
  35678. }
  35679. }
  35680. this.endFile();
  35681. }
  35682. precheckMissedSemicolon(/* tokens */) {
  35683. // Hook for Safe Parser
  35684. }
  35685. raw(node, prop, tokens, customProperty) {
  35686. let token, type;
  35687. let length = tokens.length;
  35688. let value = '';
  35689. let clean = true;
  35690. let next, prev;
  35691. for (let i = 0; i < length; i += 1) {
  35692. token = tokens[i];
  35693. type = token[0];
  35694. if (type === 'space' && i === length - 1 && !customProperty) {
  35695. clean = false;
  35696. } else if (type === 'comment') {
  35697. prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty';
  35698. next = tokens[i + 1] ? tokens[i + 1][0] : 'empty';
  35699. if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) {
  35700. if (value.slice(-1) === ',') {
  35701. clean = false;
  35702. } else {
  35703. value += token[1];
  35704. }
  35705. } else {
  35706. clean = false;
  35707. }
  35708. } else {
  35709. value += token[1];
  35710. }
  35711. }
  35712. if (!clean) {
  35713. let raw = tokens.reduce((all, i) => all + i[1], '');
  35714. node.raws[prop] = { raw, value };
  35715. }
  35716. node[prop] = value;
  35717. }
  35718. rule(tokens) {
  35719. tokens.pop();
  35720. let node = new Rule();
  35721. this.init(node, tokens[0][2]);
  35722. node.raws.between = this.spacesAndCommentsFromEnd(tokens);
  35723. this.raw(node, 'selector', tokens);
  35724. this.current = node;
  35725. }
  35726. spacesAndCommentsFromEnd(tokens) {
  35727. let lastTokenType;
  35728. let spaces = '';
  35729. while (tokens.length) {
  35730. lastTokenType = tokens[tokens.length - 1][0];
  35731. if (lastTokenType !== 'space' && lastTokenType !== 'comment') break
  35732. spaces = tokens.pop()[1] + spaces;
  35733. }
  35734. return spaces
  35735. }
  35736. // Errors
  35737. spacesAndCommentsFromStart(tokens) {
  35738. let next;
  35739. let spaces = '';
  35740. while (tokens.length) {
  35741. next = tokens[0][0];
  35742. if (next !== 'space' && next !== 'comment') break
  35743. spaces += tokens.shift()[1];
  35744. }
  35745. return spaces
  35746. }
  35747. spacesFromEnd(tokens) {
  35748. let lastTokenType;
  35749. let spaces = '';
  35750. while (tokens.length) {
  35751. lastTokenType = tokens[tokens.length - 1][0];
  35752. if (lastTokenType !== 'space') break
  35753. spaces = tokens.pop()[1] + spaces;
  35754. }
  35755. return spaces
  35756. }
  35757. stringFrom(tokens, from) {
  35758. let result = '';
  35759. for (let i = from; i < tokens.length; i++) {
  35760. result += tokens[i][1];
  35761. }
  35762. tokens.splice(from, tokens.length - from);
  35763. return result
  35764. }
  35765. unclosedBlock() {
  35766. let pos = this.current.source.start;
  35767. throw this.input.error('Unclosed block', pos.line, pos.column)
  35768. }
  35769. unclosedBracket(bracket) {
  35770. throw this.input.error(
  35771. 'Unclosed bracket',
  35772. { offset: bracket[2] },
  35773. { offset: bracket[2] + 1 }
  35774. )
  35775. }
  35776. unexpectedClose(token) {
  35777. throw this.input.error(
  35778. 'Unexpected }',
  35779. { offset: token[2] },
  35780. { offset: token[2] + 1 }
  35781. )
  35782. }
  35783. unknownWord(tokens) {
  35784. throw this.input.error(
  35785. 'Unknown word ' + tokens[0][1],
  35786. { offset: tokens[0][2] },
  35787. { offset: tokens[0][2] + tokens[0][1].length }
  35788. )
  35789. }
  35790. unnamedAtrule(node, token) {
  35791. throw this.input.error(
  35792. 'At-rule without name',
  35793. { offset: token[2] },
  35794. { offset: token[2] + token[1].length }
  35795. )
  35796. }
  35797. }
  35798. parser$1 = Parser;
  35799. return parser$1;
  35800. }
  35801. var parse_1;
  35802. var hasRequiredParse;
  35803. function requireParse () {
  35804. if (hasRequiredParse) return parse_1;
  35805. hasRequiredParse = 1;
  35806. let Container = /*@__PURE__*/ requireContainer$1();
  35807. let Input = /*@__PURE__*/ requireInput();
  35808. let Parser = /*@__PURE__*/ requireParser$1();
  35809. function parse(css, opts) {
  35810. let input = new Input(css, opts);
  35811. let parser = new Parser(input);
  35812. try {
  35813. parser.parse();
  35814. } catch (e) {
  35815. if (browser$1.env.NODE_ENV !== 'production') {
  35816. if (e.name === 'CssSyntaxError' && opts && opts.from) {
  35817. if (/\.scss$/i.test(opts.from)) {
  35818. e.message +=
  35819. '\nYou tried to parse SCSS with ' +
  35820. 'the standard CSS parser; ' +
  35821. 'try again with the postcss-scss parser';
  35822. } else if (/\.sass/i.test(opts.from)) {
  35823. e.message +=
  35824. '\nYou tried to parse Sass with ' +
  35825. 'the standard CSS parser; ' +
  35826. 'try again with the postcss-sass parser';
  35827. } else if (/\.less$/i.test(opts.from)) {
  35828. e.message +=
  35829. '\nYou tried to parse Less with ' +
  35830. 'the standard CSS parser; ' +
  35831. 'try again with the postcss-less parser';
  35832. }
  35833. }
  35834. }
  35835. throw e
  35836. }
  35837. return parser.root
  35838. }
  35839. parse_1 = parse;
  35840. parse.default = parse;
  35841. Container.registerParse(parse);
  35842. return parse_1;
  35843. }
  35844. var warning;
  35845. var hasRequiredWarning;
  35846. function requireWarning () {
  35847. if (hasRequiredWarning) return warning;
  35848. hasRequiredWarning = 1;
  35849. class Warning {
  35850. constructor(text, opts = {}) {
  35851. this.type = 'warning';
  35852. this.text = text;
  35853. if (opts.node && opts.node.source) {
  35854. let range = opts.node.rangeBy(opts);
  35855. this.line = range.start.line;
  35856. this.column = range.start.column;
  35857. this.endLine = range.end.line;
  35858. this.endColumn = range.end.column;
  35859. }
  35860. for (let opt in opts) this[opt] = opts[opt];
  35861. }
  35862. toString() {
  35863. if (this.node) {
  35864. return this.node.error(this.text, {
  35865. index: this.index,
  35866. plugin: this.plugin,
  35867. word: this.word
  35868. }).message
  35869. }
  35870. if (this.plugin) {
  35871. return this.plugin + ': ' + this.text
  35872. }
  35873. return this.text
  35874. }
  35875. }
  35876. warning = Warning;
  35877. Warning.default = Warning;
  35878. return warning;
  35879. }
  35880. var result;
  35881. var hasRequiredResult;
  35882. function requireResult () {
  35883. if (hasRequiredResult) return result;
  35884. hasRequiredResult = 1;
  35885. let Warning = /*@__PURE__*/ requireWarning();
  35886. class Result {
  35887. get content() {
  35888. return this.css
  35889. }
  35890. constructor(processor, root, opts) {
  35891. this.processor = processor;
  35892. this.messages = [];
  35893. this.root = root;
  35894. this.opts = opts;
  35895. this.css = '';
  35896. this.map = undefined;
  35897. }
  35898. toString() {
  35899. return this.css
  35900. }
  35901. warn(text, opts = {}) {
  35902. if (!opts.plugin) {
  35903. if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
  35904. opts.plugin = this.lastPlugin.postcssPlugin;
  35905. }
  35906. }
  35907. let warning = new Warning(text, opts);
  35908. this.messages.push(warning);
  35909. return warning
  35910. }
  35911. warnings() {
  35912. return this.messages.filter(i => i.type === 'warning')
  35913. }
  35914. }
  35915. result = Result;
  35916. Result.default = Result;
  35917. return result;
  35918. }
  35919. /* eslint-disable no-console */
  35920. var warnOnce;
  35921. var hasRequiredWarnOnce;
  35922. function requireWarnOnce () {
  35923. if (hasRequiredWarnOnce) return warnOnce;
  35924. hasRequiredWarnOnce = 1;
  35925. let printed = {};
  35926. warnOnce = function warnOnce(message) {
  35927. if (printed[message]) return
  35928. printed[message] = true;
  35929. if (typeof console !== 'undefined' && console.warn) {
  35930. console.warn(message);
  35931. }
  35932. };
  35933. return warnOnce;
  35934. }
  35935. var lazyResult;
  35936. var hasRequiredLazyResult;
  35937. function requireLazyResult () {
  35938. if (hasRequiredLazyResult) return lazyResult;
  35939. hasRequiredLazyResult = 1;
  35940. let Container = /*@__PURE__*/ requireContainer$1();
  35941. let Document = /*@__PURE__*/ requireDocument();
  35942. let MapGenerator = /*@__PURE__*/ requireMapGenerator();
  35943. let parse = /*@__PURE__*/ requireParse();
  35944. let Result = /*@__PURE__*/ requireResult();
  35945. let Root = /*@__PURE__*/ requireRoot$1();
  35946. let stringify = /*@__PURE__*/ requireStringify();
  35947. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  35948. let warnOnce = /*@__PURE__*/ requireWarnOnce();
  35949. const TYPE_TO_CLASS_NAME = {
  35950. atrule: 'AtRule',
  35951. comment: 'Comment',
  35952. decl: 'Declaration',
  35953. document: 'Document',
  35954. root: 'Root',
  35955. rule: 'Rule'
  35956. };
  35957. const PLUGIN_PROPS = {
  35958. AtRule: true,
  35959. AtRuleExit: true,
  35960. Comment: true,
  35961. CommentExit: true,
  35962. Declaration: true,
  35963. DeclarationExit: true,
  35964. Document: true,
  35965. DocumentExit: true,
  35966. Once: true,
  35967. OnceExit: true,
  35968. postcssPlugin: true,
  35969. prepare: true,
  35970. Root: true,
  35971. RootExit: true,
  35972. Rule: true,
  35973. RuleExit: true
  35974. };
  35975. const NOT_VISITORS = {
  35976. Once: true,
  35977. postcssPlugin: true,
  35978. prepare: true
  35979. };
  35980. const CHILDREN = 0;
  35981. function isPromise(obj) {
  35982. return typeof obj === 'object' && typeof obj.then === 'function'
  35983. }
  35984. function getEvents(node) {
  35985. let key = false;
  35986. let type = TYPE_TO_CLASS_NAME[node.type];
  35987. if (node.type === 'decl') {
  35988. key = node.prop.toLowerCase();
  35989. } else if (node.type === 'atrule') {
  35990. key = node.name.toLowerCase();
  35991. }
  35992. if (key && node.append) {
  35993. return [
  35994. type,
  35995. type + '-' + key,
  35996. CHILDREN,
  35997. type + 'Exit',
  35998. type + 'Exit-' + key
  35999. ]
  36000. } else if (key) {
  36001. return [type, type + '-' + key, type + 'Exit', type + 'Exit-' + key]
  36002. } else if (node.append) {
  36003. return [type, CHILDREN, type + 'Exit']
  36004. } else {
  36005. return [type, type + 'Exit']
  36006. }
  36007. }
  36008. function toStack(node) {
  36009. let events;
  36010. if (node.type === 'document') {
  36011. events = ['Document', CHILDREN, 'DocumentExit'];
  36012. } else if (node.type === 'root') {
  36013. events = ['Root', CHILDREN, 'RootExit'];
  36014. } else {
  36015. events = getEvents(node);
  36016. }
  36017. return {
  36018. eventIndex: 0,
  36019. events,
  36020. iterator: 0,
  36021. node,
  36022. visitorIndex: 0,
  36023. visitors: []
  36024. }
  36025. }
  36026. function cleanMarks(node) {
  36027. node[isClean] = false;
  36028. if (node.nodes) node.nodes.forEach(i => cleanMarks(i));
  36029. return node
  36030. }
  36031. let postcss = {};
  36032. class LazyResult {
  36033. get content() {
  36034. return this.stringify().content
  36035. }
  36036. get css() {
  36037. return this.stringify().css
  36038. }
  36039. get map() {
  36040. return this.stringify().map
  36041. }
  36042. get messages() {
  36043. return this.sync().messages
  36044. }
  36045. get opts() {
  36046. return this.result.opts
  36047. }
  36048. get processor() {
  36049. return this.result.processor
  36050. }
  36051. get root() {
  36052. return this.sync().root
  36053. }
  36054. get [Symbol.toStringTag]() {
  36055. return 'LazyResult'
  36056. }
  36057. constructor(processor, css, opts) {
  36058. this.stringified = false;
  36059. this.processed = false;
  36060. let root;
  36061. if (
  36062. typeof css === 'object' &&
  36063. css !== null &&
  36064. (css.type === 'root' || css.type === 'document')
  36065. ) {
  36066. root = cleanMarks(css);
  36067. } else if (css instanceof LazyResult || css instanceof Result) {
  36068. root = cleanMarks(css.root);
  36069. if (css.map) {
  36070. if (typeof opts.map === 'undefined') opts.map = {};
  36071. if (!opts.map.inline) opts.map.inline = false;
  36072. opts.map.prev = css.map;
  36073. }
  36074. } else {
  36075. let parser = parse;
  36076. if (opts.syntax) parser = opts.syntax.parse;
  36077. if (opts.parser) parser = opts.parser;
  36078. if (parser.parse) parser = parser.parse;
  36079. try {
  36080. root = parser(css, opts);
  36081. } catch (error) {
  36082. this.processed = true;
  36083. this.error = error;
  36084. }
  36085. if (root && !root[my]) {
  36086. /* c8 ignore next 2 */
  36087. Container.rebuild(root);
  36088. }
  36089. }
  36090. this.result = new Result(processor, root, opts);
  36091. this.helpers = { ...postcss, postcss, result: this.result };
  36092. this.plugins = this.processor.plugins.map(plugin => {
  36093. if (typeof plugin === 'object' && plugin.prepare) {
  36094. return { ...plugin, ...plugin.prepare(this.result) }
  36095. } else {
  36096. return plugin
  36097. }
  36098. });
  36099. }
  36100. async() {
  36101. if (this.error) return Promise.reject(this.error)
  36102. if (this.processed) return Promise.resolve(this.result)
  36103. if (!this.processing) {
  36104. this.processing = this.runAsync();
  36105. }
  36106. return this.processing
  36107. }
  36108. catch(onRejected) {
  36109. return this.async().catch(onRejected)
  36110. }
  36111. finally(onFinally) {
  36112. return this.async().then(onFinally, onFinally)
  36113. }
  36114. getAsyncError() {
  36115. throw new Error('Use process(css).then(cb) to work with async plugins')
  36116. }
  36117. handleError(error, node) {
  36118. let plugin = this.result.lastPlugin;
  36119. try {
  36120. if (node) node.addToError(error);
  36121. this.error = error;
  36122. if (error.name === 'CssSyntaxError' && !error.plugin) {
  36123. error.plugin = plugin.postcssPlugin;
  36124. error.setMessage();
  36125. } else if (plugin.postcssVersion) {
  36126. if (browser$1.env.NODE_ENV !== 'production') {
  36127. let pluginName = plugin.postcssPlugin;
  36128. let pluginVer = plugin.postcssVersion;
  36129. let runtimeVer = this.result.processor.version;
  36130. let a = pluginVer.split('.');
  36131. let b = runtimeVer.split('.');
  36132. if (a[0] !== b[0] || parseInt(a[1]) > parseInt(b[1])) {
  36133. // eslint-disable-next-line no-console
  36134. console.error(
  36135. 'Unknown error from PostCSS plugin. Your current PostCSS ' +
  36136. 'version is ' +
  36137. runtimeVer +
  36138. ', but ' +
  36139. pluginName +
  36140. ' uses ' +
  36141. pluginVer +
  36142. '. Perhaps this is the source of the error below.'
  36143. );
  36144. }
  36145. }
  36146. }
  36147. } catch (err) {
  36148. /* c8 ignore next 3 */
  36149. // eslint-disable-next-line no-console
  36150. if (console && console.error) console.error(err);
  36151. }
  36152. return error
  36153. }
  36154. prepareVisitors() {
  36155. this.listeners = {};
  36156. let add = (plugin, type, cb) => {
  36157. if (!this.listeners[type]) this.listeners[type] = [];
  36158. this.listeners[type].push([plugin, cb]);
  36159. };
  36160. for (let plugin of this.plugins) {
  36161. if (typeof plugin === 'object') {
  36162. for (let event in plugin) {
  36163. if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
  36164. throw new Error(
  36165. `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
  36166. `Try to update PostCSS (${this.processor.version} now).`
  36167. )
  36168. }
  36169. if (!NOT_VISITORS[event]) {
  36170. if (typeof plugin[event] === 'object') {
  36171. for (let filter in plugin[event]) {
  36172. if (filter === '*') {
  36173. add(plugin, event, plugin[event][filter]);
  36174. } else {
  36175. add(
  36176. plugin,
  36177. event + '-' + filter.toLowerCase(),
  36178. plugin[event][filter]
  36179. );
  36180. }
  36181. }
  36182. } else if (typeof plugin[event] === 'function') {
  36183. add(plugin, event, plugin[event]);
  36184. }
  36185. }
  36186. }
  36187. }
  36188. }
  36189. this.hasListener = Object.keys(this.listeners).length > 0;
  36190. }
  36191. async runAsync() {
  36192. this.plugin = 0;
  36193. for (let i = 0; i < this.plugins.length; i++) {
  36194. let plugin = this.plugins[i];
  36195. let promise = this.runOnRoot(plugin);
  36196. if (isPromise(promise)) {
  36197. try {
  36198. await promise;
  36199. } catch (error) {
  36200. throw this.handleError(error)
  36201. }
  36202. }
  36203. }
  36204. this.prepareVisitors();
  36205. if (this.hasListener) {
  36206. let root = this.result.root;
  36207. while (!root[isClean]) {
  36208. root[isClean] = true;
  36209. let stack = [toStack(root)];
  36210. while (stack.length > 0) {
  36211. let promise = this.visitTick(stack);
  36212. if (isPromise(promise)) {
  36213. try {
  36214. await promise;
  36215. } catch (e) {
  36216. let node = stack[stack.length - 1].node;
  36217. throw this.handleError(e, node)
  36218. }
  36219. }
  36220. }
  36221. }
  36222. if (this.listeners.OnceExit) {
  36223. for (let [plugin, visitor] of this.listeners.OnceExit) {
  36224. this.result.lastPlugin = plugin;
  36225. try {
  36226. if (root.type === 'document') {
  36227. let roots = root.nodes.map(subRoot =>
  36228. visitor(subRoot, this.helpers)
  36229. );
  36230. await Promise.all(roots);
  36231. } else {
  36232. await visitor(root, this.helpers);
  36233. }
  36234. } catch (e) {
  36235. throw this.handleError(e)
  36236. }
  36237. }
  36238. }
  36239. }
  36240. this.processed = true;
  36241. return this.stringify()
  36242. }
  36243. runOnRoot(plugin) {
  36244. this.result.lastPlugin = plugin;
  36245. try {
  36246. if (typeof plugin === 'object' && plugin.Once) {
  36247. if (this.result.root.type === 'document') {
  36248. let roots = this.result.root.nodes.map(root =>
  36249. plugin.Once(root, this.helpers)
  36250. );
  36251. if (isPromise(roots[0])) {
  36252. return Promise.all(roots)
  36253. }
  36254. return roots
  36255. }
  36256. return plugin.Once(this.result.root, this.helpers)
  36257. } else if (typeof plugin === 'function') {
  36258. return plugin(this.result.root, this.result)
  36259. }
  36260. } catch (error) {
  36261. throw this.handleError(error)
  36262. }
  36263. }
  36264. stringify() {
  36265. if (this.error) throw this.error
  36266. if (this.stringified) return this.result
  36267. this.stringified = true;
  36268. this.sync();
  36269. let opts = this.result.opts;
  36270. let str = stringify;
  36271. if (opts.syntax) str = opts.syntax.stringify;
  36272. if (opts.stringifier) str = opts.stringifier;
  36273. if (str.stringify) str = str.stringify;
  36274. let map = new MapGenerator(str, this.result.root, this.result.opts);
  36275. let data = map.generate();
  36276. this.result.css = data[0];
  36277. this.result.map = data[1];
  36278. return this.result
  36279. }
  36280. sync() {
  36281. if (this.error) throw this.error
  36282. if (this.processed) return this.result
  36283. this.processed = true;
  36284. if (this.processing) {
  36285. throw this.getAsyncError()
  36286. }
  36287. for (let plugin of this.plugins) {
  36288. let promise = this.runOnRoot(plugin);
  36289. if (isPromise(promise)) {
  36290. throw this.getAsyncError()
  36291. }
  36292. }
  36293. this.prepareVisitors();
  36294. if (this.hasListener) {
  36295. let root = this.result.root;
  36296. while (!root[isClean]) {
  36297. root[isClean] = true;
  36298. this.walkSync(root);
  36299. }
  36300. if (this.listeners.OnceExit) {
  36301. if (root.type === 'document') {
  36302. for (let subRoot of root.nodes) {
  36303. this.visitSync(this.listeners.OnceExit, subRoot);
  36304. }
  36305. } else {
  36306. this.visitSync(this.listeners.OnceExit, root);
  36307. }
  36308. }
  36309. }
  36310. return this.result
  36311. }
  36312. then(onFulfilled, onRejected) {
  36313. if (browser$1.env.NODE_ENV !== 'production') {
  36314. if (!('from' in this.opts)) {
  36315. warnOnce(
  36316. 'Without `from` option PostCSS could generate wrong source map ' +
  36317. 'and will not find Browserslist config. Set it to CSS file path ' +
  36318. 'or to `undefined` to prevent this warning.'
  36319. );
  36320. }
  36321. }
  36322. return this.async().then(onFulfilled, onRejected)
  36323. }
  36324. toString() {
  36325. return this.css
  36326. }
  36327. visitSync(visitors, node) {
  36328. for (let [plugin, visitor] of visitors) {
  36329. this.result.lastPlugin = plugin;
  36330. let promise;
  36331. try {
  36332. promise = visitor(node, this.helpers);
  36333. } catch (e) {
  36334. throw this.handleError(e, node.proxyOf)
  36335. }
  36336. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  36337. return true
  36338. }
  36339. if (isPromise(promise)) {
  36340. throw this.getAsyncError()
  36341. }
  36342. }
  36343. }
  36344. visitTick(stack) {
  36345. let visit = stack[stack.length - 1];
  36346. let { node, visitors } = visit;
  36347. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  36348. stack.pop();
  36349. return
  36350. }
  36351. if (visitors.length > 0 && visit.visitorIndex < visitors.length) {
  36352. let [plugin, visitor] = visitors[visit.visitorIndex];
  36353. visit.visitorIndex += 1;
  36354. if (visit.visitorIndex === visitors.length) {
  36355. visit.visitors = [];
  36356. visit.visitorIndex = 0;
  36357. }
  36358. this.result.lastPlugin = plugin;
  36359. try {
  36360. return visitor(node.toProxy(), this.helpers)
  36361. } catch (e) {
  36362. throw this.handleError(e, node)
  36363. }
  36364. }
  36365. if (visit.iterator !== 0) {
  36366. let iterator = visit.iterator;
  36367. let child;
  36368. while ((child = node.nodes[node.indexes[iterator]])) {
  36369. node.indexes[iterator] += 1;
  36370. if (!child[isClean]) {
  36371. child[isClean] = true;
  36372. stack.push(toStack(child));
  36373. return
  36374. }
  36375. }
  36376. visit.iterator = 0;
  36377. delete node.indexes[iterator];
  36378. }
  36379. let events = visit.events;
  36380. while (visit.eventIndex < events.length) {
  36381. let event = events[visit.eventIndex];
  36382. visit.eventIndex += 1;
  36383. if (event === CHILDREN) {
  36384. if (node.nodes && node.nodes.length) {
  36385. node[isClean] = true;
  36386. visit.iterator = node.getIterator();
  36387. }
  36388. return
  36389. } else if (this.listeners[event]) {
  36390. visit.visitors = this.listeners[event];
  36391. return
  36392. }
  36393. }
  36394. stack.pop();
  36395. }
  36396. walkSync(node) {
  36397. node[isClean] = true;
  36398. let events = getEvents(node);
  36399. for (let event of events) {
  36400. if (event === CHILDREN) {
  36401. if (node.nodes) {
  36402. node.each(child => {
  36403. if (!child[isClean]) this.walkSync(child);
  36404. });
  36405. }
  36406. } else {
  36407. let visitors = this.listeners[event];
  36408. if (visitors) {
  36409. if (this.visitSync(visitors, node.toProxy())) return
  36410. }
  36411. }
  36412. }
  36413. }
  36414. warnings() {
  36415. return this.sync().warnings()
  36416. }
  36417. }
  36418. LazyResult.registerPostcss = dependant => {
  36419. postcss = dependant;
  36420. };
  36421. lazyResult = LazyResult;
  36422. LazyResult.default = LazyResult;
  36423. Root.registerLazyResult(LazyResult);
  36424. Document.registerLazyResult(LazyResult);
  36425. return lazyResult;
  36426. }
  36427. var noWorkResult;
  36428. var hasRequiredNoWorkResult;
  36429. function requireNoWorkResult () {
  36430. if (hasRequiredNoWorkResult) return noWorkResult;
  36431. hasRequiredNoWorkResult = 1;
  36432. let MapGenerator = /*@__PURE__*/ requireMapGenerator();
  36433. let parse = /*@__PURE__*/ requireParse();
  36434. const Result = /*@__PURE__*/ requireResult();
  36435. let stringify = /*@__PURE__*/ requireStringify();
  36436. let warnOnce = /*@__PURE__*/ requireWarnOnce();
  36437. class NoWorkResult {
  36438. get content() {
  36439. return this.result.css
  36440. }
  36441. get css() {
  36442. return this.result.css
  36443. }
  36444. get map() {
  36445. return this.result.map
  36446. }
  36447. get messages() {
  36448. return []
  36449. }
  36450. get opts() {
  36451. return this.result.opts
  36452. }
  36453. get processor() {
  36454. return this.result.processor
  36455. }
  36456. get root() {
  36457. if (this._root) {
  36458. return this._root
  36459. }
  36460. let root;
  36461. let parser = parse;
  36462. try {
  36463. root = parser(this._css, this._opts);
  36464. } catch (error) {
  36465. this.error = error;
  36466. }
  36467. if (this.error) {
  36468. throw this.error
  36469. } else {
  36470. this._root = root;
  36471. return root
  36472. }
  36473. }
  36474. get [Symbol.toStringTag]() {
  36475. return 'NoWorkResult'
  36476. }
  36477. constructor(processor, css, opts) {
  36478. css = css.toString();
  36479. this.stringified = false;
  36480. this._processor = processor;
  36481. this._css = css;
  36482. this._opts = opts;
  36483. this._map = undefined;
  36484. let root;
  36485. let str = stringify;
  36486. this.result = new Result(this._processor, root, this._opts);
  36487. this.result.css = css;
  36488. let self = this;
  36489. Object.defineProperty(this.result, 'root', {
  36490. get() {
  36491. return self.root
  36492. }
  36493. });
  36494. let map = new MapGenerator(str, root, this._opts, css);
  36495. if (map.isMap()) {
  36496. let [generatedCSS, generatedMap] = map.generate();
  36497. if (generatedCSS) {
  36498. this.result.css = generatedCSS;
  36499. }
  36500. if (generatedMap) {
  36501. this.result.map = generatedMap;
  36502. }
  36503. } else {
  36504. map.clearAnnotation();
  36505. this.result.css = map.css;
  36506. }
  36507. }
  36508. async() {
  36509. if (this.error) return Promise.reject(this.error)
  36510. return Promise.resolve(this.result)
  36511. }
  36512. catch(onRejected) {
  36513. return this.async().catch(onRejected)
  36514. }
  36515. finally(onFinally) {
  36516. return this.async().then(onFinally, onFinally)
  36517. }
  36518. sync() {
  36519. if (this.error) throw this.error
  36520. return this.result
  36521. }
  36522. then(onFulfilled, onRejected) {
  36523. if (browser$1.env.NODE_ENV !== 'production') {
  36524. if (!('from' in this._opts)) {
  36525. warnOnce(
  36526. 'Without `from` option PostCSS could generate wrong source map ' +
  36527. 'and will not find Browserslist config. Set it to CSS file path ' +
  36528. 'or to `undefined` to prevent this warning.'
  36529. );
  36530. }
  36531. }
  36532. return this.async().then(onFulfilled, onRejected)
  36533. }
  36534. toString() {
  36535. return this._css
  36536. }
  36537. warnings() {
  36538. return []
  36539. }
  36540. }
  36541. noWorkResult = NoWorkResult;
  36542. NoWorkResult.default = NoWorkResult;
  36543. return noWorkResult;
  36544. }
  36545. var processor$1;
  36546. var hasRequiredProcessor$1;
  36547. function requireProcessor$1 () {
  36548. if (hasRequiredProcessor$1) return processor$1;
  36549. hasRequiredProcessor$1 = 1;
  36550. let Document = /*@__PURE__*/ requireDocument();
  36551. let LazyResult = /*@__PURE__*/ requireLazyResult();
  36552. let NoWorkResult = /*@__PURE__*/ requireNoWorkResult();
  36553. let Root = /*@__PURE__*/ requireRoot$1();
  36554. class Processor {
  36555. constructor(plugins = []) {
  36556. this.version = '8.5.6';
  36557. this.plugins = this.normalize(plugins);
  36558. }
  36559. normalize(plugins) {
  36560. let normalized = [];
  36561. for (let i of plugins) {
  36562. if (i.postcss === true) {
  36563. i = i();
  36564. } else if (i.postcss) {
  36565. i = i.postcss;
  36566. }
  36567. if (typeof i === 'object' && Array.isArray(i.plugins)) {
  36568. normalized = normalized.concat(i.plugins);
  36569. } else if (typeof i === 'object' && i.postcssPlugin) {
  36570. normalized.push(i);
  36571. } else if (typeof i === 'function') {
  36572. normalized.push(i);
  36573. } else if (typeof i === 'object' && (i.parse || i.stringify)) {
  36574. if (browser$1.env.NODE_ENV !== 'production') {
  36575. throw new Error(
  36576. 'PostCSS syntaxes cannot be used as plugins. Instead, please use ' +
  36577. 'one of the syntax/parser/stringifier options as outlined ' +
  36578. 'in your PostCSS runner documentation.'
  36579. )
  36580. }
  36581. } else {
  36582. throw new Error(i + ' is not a PostCSS plugin')
  36583. }
  36584. }
  36585. return normalized
  36586. }
  36587. process(css, opts = {}) {
  36588. if (
  36589. !this.plugins.length &&
  36590. !opts.parser &&
  36591. !opts.stringifier &&
  36592. !opts.syntax
  36593. ) {
  36594. return new NoWorkResult(this, css, opts)
  36595. } else {
  36596. return new LazyResult(this, css, opts)
  36597. }
  36598. }
  36599. use(plugin) {
  36600. this.plugins = this.plugins.concat(this.normalize([plugin]));
  36601. return this
  36602. }
  36603. }
  36604. processor$1 = Processor;
  36605. Processor.default = Processor;
  36606. Root.registerProcessor(Processor);
  36607. Document.registerProcessor(Processor);
  36608. return processor$1;
  36609. }
  36610. var postcss_1;
  36611. var hasRequiredPostcss;
  36612. function requirePostcss () {
  36613. if (hasRequiredPostcss) return postcss_1;
  36614. hasRequiredPostcss = 1;
  36615. let AtRule = /*@__PURE__*/ requireAtRule();
  36616. let Comment = /*@__PURE__*/ requireComment$1();
  36617. let Container = /*@__PURE__*/ requireContainer$1();
  36618. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  36619. let Declaration = /*@__PURE__*/ requireDeclaration();
  36620. let Document = /*@__PURE__*/ requireDocument();
  36621. let fromJSON = /*@__PURE__*/ requireFromJSON();
  36622. let Input = /*@__PURE__*/ requireInput();
  36623. let LazyResult = /*@__PURE__*/ requireLazyResult();
  36624. let list = /*@__PURE__*/ requireList();
  36625. let Node = /*@__PURE__*/ requireNode$2();
  36626. let parse = /*@__PURE__*/ requireParse();
  36627. let Processor = /*@__PURE__*/ requireProcessor$1();
  36628. let Result = /*@__PURE__*/ requireResult();
  36629. let Root = /*@__PURE__*/ requireRoot$1();
  36630. let Rule = /*@__PURE__*/ requireRule();
  36631. let stringify = /*@__PURE__*/ requireStringify();
  36632. let Warning = /*@__PURE__*/ requireWarning();
  36633. function postcss(...plugins) {
  36634. if (plugins.length === 1 && Array.isArray(plugins[0])) {
  36635. plugins = plugins[0];
  36636. }
  36637. return new Processor(plugins)
  36638. }
  36639. postcss.plugin = function plugin(name, initializer) {
  36640. let warningPrinted = false;
  36641. function creator(...args) {
  36642. // eslint-disable-next-line no-console
  36643. if (console && console.warn && !warningPrinted) {
  36644. warningPrinted = true;
  36645. // eslint-disable-next-line no-console
  36646. console.warn(
  36647. name +
  36648. ': postcss.plugin was deprecated. Migration guide:\n' +
  36649. 'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
  36650. );
  36651. if (browser$1.env.LANG && browser$1.env.LANG.startsWith('cn')) {
  36652. /* c8 ignore next 7 */
  36653. // eslint-disable-next-line no-console
  36654. console.warn(
  36655. name +
  36656. ': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
  36657. 'https://www.w3ctech.com/topic/2226'
  36658. );
  36659. }
  36660. }
  36661. let transformer = initializer(...args);
  36662. transformer.postcssPlugin = name;
  36663. transformer.postcssVersion = new Processor().version;
  36664. return transformer
  36665. }
  36666. let cache;
  36667. Object.defineProperty(creator, 'postcss', {
  36668. get() {
  36669. if (!cache) cache = creator();
  36670. return cache
  36671. }
  36672. });
  36673. creator.process = function (css, processOpts, pluginOpts) {
  36674. return postcss([creator(pluginOpts)]).process(css, processOpts)
  36675. };
  36676. return creator
  36677. };
  36678. postcss.stringify = stringify;
  36679. postcss.parse = parse;
  36680. postcss.fromJSON = fromJSON;
  36681. postcss.list = list;
  36682. postcss.comment = defaults => new Comment(defaults);
  36683. postcss.atRule = defaults => new AtRule(defaults);
  36684. postcss.decl = defaults => new Declaration(defaults);
  36685. postcss.rule = defaults => new Rule(defaults);
  36686. postcss.root = defaults => new Root(defaults);
  36687. postcss.document = defaults => new Document(defaults);
  36688. postcss.CssSyntaxError = CssSyntaxError;
  36689. postcss.Declaration = Declaration;
  36690. postcss.Container = Container;
  36691. postcss.Processor = Processor;
  36692. postcss.Document = Document;
  36693. postcss.Comment = Comment;
  36694. postcss.Warning = Warning;
  36695. postcss.AtRule = AtRule;
  36696. postcss.Result = Result;
  36697. postcss.Input = Input;
  36698. postcss.Rule = Rule;
  36699. postcss.Root = Root;
  36700. postcss.Node = Node;
  36701. LazyResult.registerPostcss(postcss);
  36702. postcss_1 = postcss;
  36703. postcss.default = postcss;
  36704. return postcss_1;
  36705. }
  36706. var postcssExports = /*@__PURE__*/ requirePostcss();
  36707. var postcss = /*@__PURE__*/getDefaultExportFromCjs(postcssExports);
  36708. postcss.stringify;
  36709. postcss.fromJSON;
  36710. postcss.plugin;
  36711. postcss.parse;
  36712. postcss.list;
  36713. postcss.document;
  36714. postcss.comment;
  36715. postcss.atRule;
  36716. postcss.rule;
  36717. postcss.decl;
  36718. postcss.root;
  36719. postcss.CssSyntaxError;
  36720. postcss.Declaration;
  36721. postcss.Container;
  36722. postcss.Processor;
  36723. postcss.Document;
  36724. postcss.Comment;
  36725. postcss.Warning;
  36726. postcss.AtRule;
  36727. postcss.Result;
  36728. postcss.Input;
  36729. const Rule = postcss.Rule;
  36730. postcss.Root;
  36731. postcss.Node;
  36732. const trimPlugin = () => {
  36733. return {
  36734. postcssPlugin: "vue-sfc-trim",
  36735. Once(root) {
  36736. root.walk(({ type, raws }) => {
  36737. if (type === "rule" || type === "atrule") {
  36738. if (raws.before) raws.before = "\n";
  36739. if ("after" in raws && raws.after) raws.after = "\n";
  36740. }
  36741. });
  36742. }
  36743. };
  36744. };
  36745. trimPlugin.postcss = true;
  36746. var dist = {exports: {}};
  36747. var processor = {exports: {}};
  36748. var parser = {exports: {}};
  36749. var root = {exports: {}};
  36750. var container = {exports: {}};
  36751. var node$1 = {exports: {}};
  36752. var util$1 = {};
  36753. var unesc = {exports: {}};
  36754. var hasRequiredUnesc;
  36755. function requireUnesc () {
  36756. if (hasRequiredUnesc) return unesc.exports;
  36757. hasRequiredUnesc = 1;
  36758. (function (module, exports$1) {
  36759. exports$1.__esModule = true;
  36760. exports$1["default"] = unesc;
  36761. // Many thanks for this post which made this migration much easier.
  36762. // https://mathiasbynens.be/notes/css-escapes
  36763. /**
  36764. *
  36765. * @param {string} str
  36766. * @returns {[string, number]|undefined}
  36767. */
  36768. function gobbleHex(str) {
  36769. var lower = str.toLowerCase();
  36770. var hex = '';
  36771. var spaceTerminated = false;
  36772. for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
  36773. var code = lower.charCodeAt(i);
  36774. // check to see if we are dealing with a valid hex char [a-f|0-9]
  36775. var valid = code >= 97 && code <= 102 || code >= 48 && code <= 57;
  36776. // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
  36777. spaceTerminated = code === 32;
  36778. if (!valid) {
  36779. break;
  36780. }
  36781. hex += lower[i];
  36782. }
  36783. if (hex.length === 0) {
  36784. return undefined;
  36785. }
  36786. var codePoint = parseInt(hex, 16);
  36787. var isSurrogate = codePoint >= 0xD800 && codePoint <= 0xDFFF;
  36788. // Add special case for
  36789. // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
  36790. // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
  36791. if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10FFFF) {
  36792. return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
  36793. }
  36794. return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
  36795. }
  36796. var CONTAINS_ESCAPE = /\\/;
  36797. function unesc(str) {
  36798. var needToProcess = CONTAINS_ESCAPE.test(str);
  36799. if (!needToProcess) {
  36800. return str;
  36801. }
  36802. var ret = "";
  36803. for (var i = 0; i < str.length; i++) {
  36804. if (str[i] === "\\") {
  36805. var gobbled = gobbleHex(str.slice(i + 1, i + 7));
  36806. if (gobbled !== undefined) {
  36807. ret += gobbled[0];
  36808. i += gobbled[1];
  36809. continue;
  36810. }
  36811. // Retain a pair of \\ if double escaped `\\\\`
  36812. // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
  36813. if (str[i + 1] === "\\") {
  36814. ret += "\\";
  36815. i++;
  36816. continue;
  36817. }
  36818. // if \\ is at the end of the string retain it
  36819. // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
  36820. if (str.length === i + 1) {
  36821. ret += str[i];
  36822. }
  36823. continue;
  36824. }
  36825. ret += str[i];
  36826. }
  36827. return ret;
  36828. }
  36829. module.exports = exports$1.default;
  36830. } (unesc, unesc.exports));
  36831. return unesc.exports;
  36832. }
  36833. var getProp = {exports: {}};
  36834. var hasRequiredGetProp;
  36835. function requireGetProp () {
  36836. if (hasRequiredGetProp) return getProp.exports;
  36837. hasRequiredGetProp = 1;
  36838. (function (module, exports$1) {
  36839. exports$1.__esModule = true;
  36840. exports$1["default"] = getProp;
  36841. function getProp(obj) {
  36842. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36843. props[_key - 1] = arguments[_key];
  36844. }
  36845. while (props.length > 0) {
  36846. var prop = props.shift();
  36847. if (!obj[prop]) {
  36848. return undefined;
  36849. }
  36850. obj = obj[prop];
  36851. }
  36852. return obj;
  36853. }
  36854. module.exports = exports$1.default;
  36855. } (getProp, getProp.exports));
  36856. return getProp.exports;
  36857. }
  36858. var ensureObject = {exports: {}};
  36859. var hasRequiredEnsureObject;
  36860. function requireEnsureObject () {
  36861. if (hasRequiredEnsureObject) return ensureObject.exports;
  36862. hasRequiredEnsureObject = 1;
  36863. (function (module, exports$1) {
  36864. exports$1.__esModule = true;
  36865. exports$1["default"] = ensureObject;
  36866. function ensureObject(obj) {
  36867. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36868. props[_key - 1] = arguments[_key];
  36869. }
  36870. while (props.length > 0) {
  36871. var prop = props.shift();
  36872. if (!obj[prop]) {
  36873. obj[prop] = {};
  36874. }
  36875. obj = obj[prop];
  36876. }
  36877. }
  36878. module.exports = exports$1.default;
  36879. } (ensureObject, ensureObject.exports));
  36880. return ensureObject.exports;
  36881. }
  36882. var stripComments = {exports: {}};
  36883. var hasRequiredStripComments;
  36884. function requireStripComments () {
  36885. if (hasRequiredStripComments) return stripComments.exports;
  36886. hasRequiredStripComments = 1;
  36887. (function (module, exports$1) {
  36888. exports$1.__esModule = true;
  36889. exports$1["default"] = stripComments;
  36890. function stripComments(str) {
  36891. var s = "";
  36892. var commentStart = str.indexOf("/*");
  36893. var lastEnd = 0;
  36894. while (commentStart >= 0) {
  36895. s = s + str.slice(lastEnd, commentStart);
  36896. var commentEnd = str.indexOf("*/", commentStart + 2);
  36897. if (commentEnd < 0) {
  36898. return s;
  36899. }
  36900. lastEnd = commentEnd + 2;
  36901. commentStart = str.indexOf("/*", lastEnd);
  36902. }
  36903. s = s + str.slice(lastEnd);
  36904. return s;
  36905. }
  36906. module.exports = exports$1.default;
  36907. } (stripComments, stripComments.exports));
  36908. return stripComments.exports;
  36909. }
  36910. var hasRequiredUtil$1;
  36911. function requireUtil$1 () {
  36912. if (hasRequiredUtil$1) return util$1;
  36913. hasRequiredUtil$1 = 1;
  36914. util$1.__esModule = true;
  36915. util$1.unesc = util$1.stripComments = util$1.getProp = util$1.ensureObject = void 0;
  36916. var _unesc = _interopRequireDefault(/*@__PURE__*/ requireUnesc());
  36917. util$1.unesc = _unesc["default"];
  36918. var _getProp = _interopRequireDefault(/*@__PURE__*/ requireGetProp());
  36919. util$1.getProp = _getProp["default"];
  36920. var _ensureObject = _interopRequireDefault(/*@__PURE__*/ requireEnsureObject());
  36921. util$1.ensureObject = _ensureObject["default"];
  36922. var _stripComments = _interopRequireDefault(/*@__PURE__*/ requireStripComments());
  36923. util$1.stripComments = _stripComments["default"];
  36924. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36925. return util$1;
  36926. }
  36927. var hasRequiredNode$1;
  36928. function requireNode$1 () {
  36929. if (hasRequiredNode$1) return node$1.exports;
  36930. hasRequiredNode$1 = 1;
  36931. (function (module, exports$1) {
  36932. exports$1.__esModule = true;
  36933. exports$1["default"] = void 0;
  36934. var _util = /*@__PURE__*/ requireUtil$1();
  36935. 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); } }
  36936. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  36937. var cloneNode = function cloneNode(obj, parent) {
  36938. if (typeof obj !== 'object' || obj === null) {
  36939. return obj;
  36940. }
  36941. var cloned = new obj.constructor();
  36942. for (var i in obj) {
  36943. if (!obj.hasOwnProperty(i)) {
  36944. continue;
  36945. }
  36946. var value = obj[i];
  36947. var type = typeof value;
  36948. if (i === 'parent' && type === 'object') {
  36949. if (parent) {
  36950. cloned[i] = parent;
  36951. }
  36952. } else if (value instanceof Array) {
  36953. cloned[i] = value.map(function (j) {
  36954. return cloneNode(j, cloned);
  36955. });
  36956. } else {
  36957. cloned[i] = cloneNode(value, cloned);
  36958. }
  36959. }
  36960. return cloned;
  36961. };
  36962. var Node = /*#__PURE__*/function () {
  36963. function Node(opts) {
  36964. if (opts === void 0) {
  36965. opts = {};
  36966. }
  36967. Object.assign(this, opts);
  36968. this.spaces = this.spaces || {};
  36969. this.spaces.before = this.spaces.before || '';
  36970. this.spaces.after = this.spaces.after || '';
  36971. }
  36972. var _proto = Node.prototype;
  36973. _proto.remove = function remove() {
  36974. if (this.parent) {
  36975. this.parent.removeChild(this);
  36976. }
  36977. this.parent = undefined;
  36978. return this;
  36979. };
  36980. _proto.replaceWith = function replaceWith() {
  36981. if (this.parent) {
  36982. for (var index in arguments) {
  36983. this.parent.insertBefore(this, arguments[index]);
  36984. }
  36985. this.remove();
  36986. }
  36987. return this;
  36988. };
  36989. _proto.next = function next() {
  36990. return this.parent.at(this.parent.index(this) + 1);
  36991. };
  36992. _proto.prev = function prev() {
  36993. return this.parent.at(this.parent.index(this) - 1);
  36994. };
  36995. _proto.clone = function clone(overrides) {
  36996. if (overrides === void 0) {
  36997. overrides = {};
  36998. }
  36999. var cloned = cloneNode(this);
  37000. for (var name in overrides) {
  37001. cloned[name] = overrides[name];
  37002. }
  37003. return cloned;
  37004. }
  37005. /**
  37006. * Some non-standard syntax doesn't follow normal escaping rules for css.
  37007. * This allows non standard syntax to be appended to an existing property
  37008. * by specifying the escaped value. By specifying the escaped value,
  37009. * illegal characters are allowed to be directly inserted into css output.
  37010. * @param {string} name the property to set
  37011. * @param {any} value the unescaped value of the property
  37012. * @param {string} valueEscaped optional. the escaped value of the property.
  37013. */;
  37014. _proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
  37015. if (!this.raws) {
  37016. this.raws = {};
  37017. }
  37018. var originalValue = this[name];
  37019. var originalEscaped = this.raws[name];
  37020. this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
  37021. if (originalEscaped || valueEscaped !== value) {
  37022. this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
  37023. } else {
  37024. delete this.raws[name]; // delete any escaped value that was created by the setter.
  37025. }
  37026. }
  37027. /**
  37028. * Some non-standard syntax doesn't follow normal escaping rules for css.
  37029. * This allows the escaped value to be specified directly, allowing illegal
  37030. * characters to be directly inserted into css output.
  37031. * @param {string} name the property to set
  37032. * @param {any} value the unescaped value of the property
  37033. * @param {string} valueEscaped the escaped value of the property.
  37034. */;
  37035. _proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
  37036. if (!this.raws) {
  37037. this.raws = {};
  37038. }
  37039. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  37040. this.raws[name] = valueEscaped;
  37041. }
  37042. /**
  37043. * When you want a value to passed through to CSS directly. This method
  37044. * deletes the corresponding raw value causing the stringifier to fallback
  37045. * to the unescaped value.
  37046. * @param {string} name the property to set.
  37047. * @param {any} value The value that is both escaped and unescaped.
  37048. */;
  37049. _proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
  37050. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  37051. if (this.raws) {
  37052. delete this.raws[name];
  37053. }
  37054. }
  37055. /**
  37056. *
  37057. * @param {number} line The number (starting with 1)
  37058. * @param {number} column The column number (starting with 1)
  37059. */;
  37060. _proto.isAtPosition = function isAtPosition(line, column) {
  37061. if (this.source && this.source.start && this.source.end) {
  37062. if (this.source.start.line > line) {
  37063. return false;
  37064. }
  37065. if (this.source.end.line < line) {
  37066. return false;
  37067. }
  37068. if (this.source.start.line === line && this.source.start.column > column) {
  37069. return false;
  37070. }
  37071. if (this.source.end.line === line && this.source.end.column < column) {
  37072. return false;
  37073. }
  37074. return true;
  37075. }
  37076. return undefined;
  37077. };
  37078. _proto.stringifyProperty = function stringifyProperty(name) {
  37079. return this.raws && this.raws[name] || this[name];
  37080. };
  37081. _proto.valueToString = function valueToString() {
  37082. return String(this.stringifyProperty("value"));
  37083. };
  37084. _proto.toString = function toString() {
  37085. return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
  37086. };
  37087. _createClass(Node, [{
  37088. key: "rawSpaceBefore",
  37089. get: function get() {
  37090. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
  37091. if (rawSpace === undefined) {
  37092. rawSpace = this.spaces && this.spaces.before;
  37093. }
  37094. return rawSpace || "";
  37095. },
  37096. set: function set(raw) {
  37097. (0, _util.ensureObject)(this, "raws", "spaces");
  37098. this.raws.spaces.before = raw;
  37099. }
  37100. }, {
  37101. key: "rawSpaceAfter",
  37102. get: function get() {
  37103. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
  37104. if (rawSpace === undefined) {
  37105. rawSpace = this.spaces.after;
  37106. }
  37107. return rawSpace || "";
  37108. },
  37109. set: function set(raw) {
  37110. (0, _util.ensureObject)(this, "raws", "spaces");
  37111. this.raws.spaces.after = raw;
  37112. }
  37113. }]);
  37114. return Node;
  37115. }();
  37116. exports$1["default"] = Node;
  37117. module.exports = exports$1.default;
  37118. } (node$1, node$1.exports));
  37119. return node$1.exports;
  37120. }
  37121. var types = {};
  37122. var hasRequiredTypes;
  37123. function requireTypes () {
  37124. if (hasRequiredTypes) return types;
  37125. hasRequiredTypes = 1;
  37126. types.__esModule = true;
  37127. types.UNIVERSAL = types.TAG = types.STRING = types.SELECTOR = types.ROOT = types.PSEUDO = types.NESTING = types.ID = types.COMMENT = types.COMBINATOR = types.CLASS = types.ATTRIBUTE = void 0;
  37128. var TAG = 'tag';
  37129. types.TAG = TAG;
  37130. var STRING = 'string';
  37131. types.STRING = STRING;
  37132. var SELECTOR = 'selector';
  37133. types.SELECTOR = SELECTOR;
  37134. var ROOT = 'root';
  37135. types.ROOT = ROOT;
  37136. var PSEUDO = 'pseudo';
  37137. types.PSEUDO = PSEUDO;
  37138. var NESTING = 'nesting';
  37139. types.NESTING = NESTING;
  37140. var ID = 'id';
  37141. types.ID = ID;
  37142. var COMMENT = 'comment';
  37143. types.COMMENT = COMMENT;
  37144. var COMBINATOR = 'combinator';
  37145. types.COMBINATOR = COMBINATOR;
  37146. var CLASS = 'class';
  37147. types.CLASS = CLASS;
  37148. var ATTRIBUTE = 'attribute';
  37149. types.ATTRIBUTE = ATTRIBUTE;
  37150. var UNIVERSAL = 'universal';
  37151. types.UNIVERSAL = UNIVERSAL;
  37152. return types;
  37153. }
  37154. var hasRequiredContainer;
  37155. function requireContainer () {
  37156. if (hasRequiredContainer) return container.exports;
  37157. hasRequiredContainer = 1;
  37158. (function (module, exports$1) {
  37159. exports$1.__esModule = true;
  37160. exports$1["default"] = void 0;
  37161. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37162. var types = _interopRequireWildcard(/*@__PURE__*/ requireTypes());
  37163. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  37164. function _interopRequireWildcard(obj, nodeInterop) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
  37165. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37166. function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike) { 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."); }
  37167. 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); }
  37168. 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; }
  37169. 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); } }
  37170. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37171. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37172. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37173. var Container = /*#__PURE__*/function (_Node) {
  37174. _inheritsLoose(Container, _Node);
  37175. function Container(opts) {
  37176. var _this;
  37177. _this = _Node.call(this, opts) || this;
  37178. if (!_this.nodes) {
  37179. _this.nodes = [];
  37180. }
  37181. return _this;
  37182. }
  37183. var _proto = Container.prototype;
  37184. _proto.append = function append(selector) {
  37185. selector.parent = this;
  37186. this.nodes.push(selector);
  37187. return this;
  37188. };
  37189. _proto.prepend = function prepend(selector) {
  37190. selector.parent = this;
  37191. this.nodes.unshift(selector);
  37192. for (var id in this.indexes) {
  37193. this.indexes[id]++;
  37194. }
  37195. return this;
  37196. };
  37197. _proto.at = function at(index) {
  37198. return this.nodes[index];
  37199. };
  37200. _proto.index = function index(child) {
  37201. if (typeof child === 'number') {
  37202. return child;
  37203. }
  37204. return this.nodes.indexOf(child);
  37205. };
  37206. _proto.removeChild = function removeChild(child) {
  37207. child = this.index(child);
  37208. this.at(child).parent = undefined;
  37209. this.nodes.splice(child, 1);
  37210. var index;
  37211. for (var id in this.indexes) {
  37212. index = this.indexes[id];
  37213. if (index >= child) {
  37214. this.indexes[id] = index - 1;
  37215. }
  37216. }
  37217. return this;
  37218. };
  37219. _proto.removeAll = function removeAll() {
  37220. for (var _iterator = _createForOfIteratorHelperLoose(this.nodes), _step; !(_step = _iterator()).done;) {
  37221. var node = _step.value;
  37222. node.parent = undefined;
  37223. }
  37224. this.nodes = [];
  37225. return this;
  37226. };
  37227. _proto.empty = function empty() {
  37228. return this.removeAll();
  37229. };
  37230. _proto.insertAfter = function insertAfter(oldNode, newNode) {
  37231. var _this$nodes;
  37232. newNode.parent = this;
  37233. var oldIndex = this.index(oldNode);
  37234. var resetNode = [];
  37235. for (var i = 2; i < arguments.length; i++) {
  37236. resetNode.push(arguments[i]);
  37237. }
  37238. (_this$nodes = this.nodes).splice.apply(_this$nodes, [oldIndex + 1, 0, newNode].concat(resetNode));
  37239. newNode.parent = this;
  37240. var index;
  37241. for (var id in this.indexes) {
  37242. index = this.indexes[id];
  37243. if (oldIndex < index) {
  37244. this.indexes[id] = index + arguments.length - 1;
  37245. }
  37246. }
  37247. return this;
  37248. };
  37249. _proto.insertBefore = function insertBefore(oldNode, newNode) {
  37250. var _this$nodes2;
  37251. newNode.parent = this;
  37252. var oldIndex = this.index(oldNode);
  37253. var resetNode = [];
  37254. for (var i = 2; i < arguments.length; i++) {
  37255. resetNode.push(arguments[i]);
  37256. }
  37257. (_this$nodes2 = this.nodes).splice.apply(_this$nodes2, [oldIndex, 0, newNode].concat(resetNode));
  37258. newNode.parent = this;
  37259. var index;
  37260. for (var id in this.indexes) {
  37261. index = this.indexes[id];
  37262. if (index >= oldIndex) {
  37263. this.indexes[id] = index + arguments.length - 1;
  37264. }
  37265. }
  37266. return this;
  37267. };
  37268. _proto._findChildAtPosition = function _findChildAtPosition(line, col) {
  37269. var found = undefined;
  37270. this.each(function (node) {
  37271. if (node.atPosition) {
  37272. var foundChild = node.atPosition(line, col);
  37273. if (foundChild) {
  37274. found = foundChild;
  37275. return false;
  37276. }
  37277. } else if (node.isAtPosition(line, col)) {
  37278. found = node;
  37279. return false;
  37280. }
  37281. });
  37282. return found;
  37283. }
  37284. /**
  37285. * Return the most specific node at the line and column number given.
  37286. * The source location is based on the original parsed location, locations aren't
  37287. * updated as selector nodes are mutated.
  37288. *
  37289. * Note that this location is relative to the location of the first character
  37290. * of the selector, and not the location of the selector in the overall document
  37291. * when used in conjunction with postcss.
  37292. *
  37293. * If not found, returns undefined.
  37294. * @param {number} line The line number of the node to find. (1-based index)
  37295. * @param {number} col The column number of the node to find. (1-based index)
  37296. */;
  37297. _proto.atPosition = function atPosition(line, col) {
  37298. if (this.isAtPosition(line, col)) {
  37299. return this._findChildAtPosition(line, col) || this;
  37300. } else {
  37301. return undefined;
  37302. }
  37303. };
  37304. _proto._inferEndPosition = function _inferEndPosition() {
  37305. if (this.last && this.last.source && this.last.source.end) {
  37306. this.source = this.source || {};
  37307. this.source.end = this.source.end || {};
  37308. Object.assign(this.source.end, this.last.source.end);
  37309. }
  37310. };
  37311. _proto.each = function each(callback) {
  37312. if (!this.lastEach) {
  37313. this.lastEach = 0;
  37314. }
  37315. if (!this.indexes) {
  37316. this.indexes = {};
  37317. }
  37318. this.lastEach++;
  37319. var id = this.lastEach;
  37320. this.indexes[id] = 0;
  37321. if (!this.length) {
  37322. return undefined;
  37323. }
  37324. var index, result;
  37325. while (this.indexes[id] < this.length) {
  37326. index = this.indexes[id];
  37327. result = callback(this.at(index), index);
  37328. if (result === false) {
  37329. break;
  37330. }
  37331. this.indexes[id] += 1;
  37332. }
  37333. delete this.indexes[id];
  37334. if (result === false) {
  37335. return false;
  37336. }
  37337. };
  37338. _proto.walk = function walk(callback) {
  37339. return this.each(function (node, i) {
  37340. var result = callback(node, i);
  37341. if (result !== false && node.length) {
  37342. result = node.walk(callback);
  37343. }
  37344. if (result === false) {
  37345. return false;
  37346. }
  37347. });
  37348. };
  37349. _proto.walkAttributes = function walkAttributes(callback) {
  37350. var _this2 = this;
  37351. return this.walk(function (selector) {
  37352. if (selector.type === types.ATTRIBUTE) {
  37353. return callback.call(_this2, selector);
  37354. }
  37355. });
  37356. };
  37357. _proto.walkClasses = function walkClasses(callback) {
  37358. var _this3 = this;
  37359. return this.walk(function (selector) {
  37360. if (selector.type === types.CLASS) {
  37361. return callback.call(_this3, selector);
  37362. }
  37363. });
  37364. };
  37365. _proto.walkCombinators = function walkCombinators(callback) {
  37366. var _this4 = this;
  37367. return this.walk(function (selector) {
  37368. if (selector.type === types.COMBINATOR) {
  37369. return callback.call(_this4, selector);
  37370. }
  37371. });
  37372. };
  37373. _proto.walkComments = function walkComments(callback) {
  37374. var _this5 = this;
  37375. return this.walk(function (selector) {
  37376. if (selector.type === types.COMMENT) {
  37377. return callback.call(_this5, selector);
  37378. }
  37379. });
  37380. };
  37381. _proto.walkIds = function walkIds(callback) {
  37382. var _this6 = this;
  37383. return this.walk(function (selector) {
  37384. if (selector.type === types.ID) {
  37385. return callback.call(_this6, selector);
  37386. }
  37387. });
  37388. };
  37389. _proto.walkNesting = function walkNesting(callback) {
  37390. var _this7 = this;
  37391. return this.walk(function (selector) {
  37392. if (selector.type === types.NESTING) {
  37393. return callback.call(_this7, selector);
  37394. }
  37395. });
  37396. };
  37397. _proto.walkPseudos = function walkPseudos(callback) {
  37398. var _this8 = this;
  37399. return this.walk(function (selector) {
  37400. if (selector.type === types.PSEUDO) {
  37401. return callback.call(_this8, selector);
  37402. }
  37403. });
  37404. };
  37405. _proto.walkTags = function walkTags(callback) {
  37406. var _this9 = this;
  37407. return this.walk(function (selector) {
  37408. if (selector.type === types.TAG) {
  37409. return callback.call(_this9, selector);
  37410. }
  37411. });
  37412. };
  37413. _proto.walkUniversals = function walkUniversals(callback) {
  37414. var _this10 = this;
  37415. return this.walk(function (selector) {
  37416. if (selector.type === types.UNIVERSAL) {
  37417. return callback.call(_this10, selector);
  37418. }
  37419. });
  37420. };
  37421. _proto.split = function split(callback) {
  37422. var _this11 = this;
  37423. var current = [];
  37424. return this.reduce(function (memo, node, index) {
  37425. var split = callback.call(_this11, node);
  37426. current.push(node);
  37427. if (split) {
  37428. memo.push(current);
  37429. current = [];
  37430. } else if (index === _this11.length - 1) {
  37431. memo.push(current);
  37432. }
  37433. return memo;
  37434. }, []);
  37435. };
  37436. _proto.map = function map(callback) {
  37437. return this.nodes.map(callback);
  37438. };
  37439. _proto.reduce = function reduce(callback, memo) {
  37440. return this.nodes.reduce(callback, memo);
  37441. };
  37442. _proto.every = function every(callback) {
  37443. return this.nodes.every(callback);
  37444. };
  37445. _proto.some = function some(callback) {
  37446. return this.nodes.some(callback);
  37447. };
  37448. _proto.filter = function filter(callback) {
  37449. return this.nodes.filter(callback);
  37450. };
  37451. _proto.sort = function sort(callback) {
  37452. return this.nodes.sort(callback);
  37453. };
  37454. _proto.toString = function toString() {
  37455. return this.map(String).join('');
  37456. };
  37457. _createClass(Container, [{
  37458. key: "first",
  37459. get: function get() {
  37460. return this.at(0);
  37461. }
  37462. }, {
  37463. key: "last",
  37464. get: function get() {
  37465. return this.at(this.length - 1);
  37466. }
  37467. }, {
  37468. key: "length",
  37469. get: function get() {
  37470. return this.nodes.length;
  37471. }
  37472. }]);
  37473. return Container;
  37474. }(_node["default"]);
  37475. exports$1["default"] = Container;
  37476. module.exports = exports$1.default;
  37477. } (container, container.exports));
  37478. return container.exports;
  37479. }
  37480. var hasRequiredRoot;
  37481. function requireRoot () {
  37482. if (hasRequiredRoot) return root.exports;
  37483. hasRequiredRoot = 1;
  37484. (function (module, exports$1) {
  37485. exports$1.__esModule = true;
  37486. exports$1["default"] = void 0;
  37487. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37488. var _types = /*@__PURE__*/ requireTypes();
  37489. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37490. 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); } }
  37491. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37492. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37493. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37494. var Root = /*#__PURE__*/function (_Container) {
  37495. _inheritsLoose(Root, _Container);
  37496. function Root(opts) {
  37497. var _this;
  37498. _this = _Container.call(this, opts) || this;
  37499. _this.type = _types.ROOT;
  37500. return _this;
  37501. }
  37502. var _proto = Root.prototype;
  37503. _proto.toString = function toString() {
  37504. var str = this.reduce(function (memo, selector) {
  37505. memo.push(String(selector));
  37506. return memo;
  37507. }, []).join(',');
  37508. return this.trailingComma ? str + ',' : str;
  37509. };
  37510. _proto.error = function error(message, options) {
  37511. if (this._error) {
  37512. return this._error(message, options);
  37513. } else {
  37514. return new Error(message);
  37515. }
  37516. };
  37517. _createClass(Root, [{
  37518. key: "errorGenerator",
  37519. set: function set(handler) {
  37520. this._error = handler;
  37521. }
  37522. }]);
  37523. return Root;
  37524. }(_container["default"]);
  37525. exports$1["default"] = Root;
  37526. module.exports = exports$1.default;
  37527. } (root, root.exports));
  37528. return root.exports;
  37529. }
  37530. var selector = {exports: {}};
  37531. var hasRequiredSelector;
  37532. function requireSelector () {
  37533. if (hasRequiredSelector) return selector.exports;
  37534. hasRequiredSelector = 1;
  37535. (function (module, exports$1) {
  37536. exports$1.__esModule = true;
  37537. exports$1["default"] = void 0;
  37538. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37539. var _types = /*@__PURE__*/ requireTypes();
  37540. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37541. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37542. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37543. var Selector = /*#__PURE__*/function (_Container) {
  37544. _inheritsLoose(Selector, _Container);
  37545. function Selector(opts) {
  37546. var _this;
  37547. _this = _Container.call(this, opts) || this;
  37548. _this.type = _types.SELECTOR;
  37549. return _this;
  37550. }
  37551. return Selector;
  37552. }(_container["default"]);
  37553. exports$1["default"] = Selector;
  37554. module.exports = exports$1.default;
  37555. } (selector, selector.exports));
  37556. return selector.exports;
  37557. }
  37558. var className = {exports: {}};
  37559. /*! https://mths.be/cssesc v3.0.0 by @mathias */
  37560. var cssesc_1;
  37561. var hasRequiredCssesc;
  37562. function requireCssesc () {
  37563. if (hasRequiredCssesc) return cssesc_1;
  37564. hasRequiredCssesc = 1;
  37565. var object = {};
  37566. var hasOwnProperty = object.hasOwnProperty;
  37567. var merge = function merge(options, defaults) {
  37568. if (!options) {
  37569. return defaults;
  37570. }
  37571. var result = {};
  37572. for (var key in defaults) {
  37573. // `if (defaults.hasOwnProperty(key) { … }` is not needed here, since
  37574. // only recognized option names are used.
  37575. result[key] = hasOwnProperty.call(options, key) ? options[key] : defaults[key];
  37576. }
  37577. return result;
  37578. };
  37579. var regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
  37580. var regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
  37581. var regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
  37582. // https://mathiasbynens.be/notes/css-escapes#css
  37583. var cssesc = function cssesc(string, options) {
  37584. options = merge(options, cssesc.options);
  37585. if (options.quotes != 'single' && options.quotes != 'double') {
  37586. options.quotes = 'single';
  37587. }
  37588. var quote = options.quotes == 'double' ? '"' : '\'';
  37589. var isIdentifier = options.isIdentifier;
  37590. var firstChar = string.charAt(0);
  37591. var output = '';
  37592. var counter = 0;
  37593. var length = string.length;
  37594. while (counter < length) {
  37595. var character = string.charAt(counter++);
  37596. var codePoint = character.charCodeAt();
  37597. var value = void 0;
  37598. // If it’s not a printable ASCII character…
  37599. if (codePoint < 0x20 || codePoint > 0x7E) {
  37600. if (codePoint >= 0xD800 && codePoint <= 0xDBFF && counter < length) {
  37601. // It’s a high surrogate, and there is a next character.
  37602. var extra = string.charCodeAt(counter++);
  37603. if ((extra & 0xFC00) == 0xDC00) {
  37604. // next character is low surrogate
  37605. codePoint = ((codePoint & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
  37606. } else {
  37607. // It’s an unmatched surrogate; only append this code unit, in case
  37608. // the next code unit is the high surrogate of a surrogate pair.
  37609. counter--;
  37610. }
  37611. }
  37612. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37613. } else {
  37614. if (options.escapeEverything) {
  37615. if (regexAnySingleEscape.test(character)) {
  37616. value = '\\' + character;
  37617. } else {
  37618. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37619. }
  37620. } else if (/[\t\n\f\r\x0B]/.test(character)) {
  37621. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37622. } else if (character == '\\' || !isIdentifier && (character == '"' && quote == character || character == '\'' && quote == character) || isIdentifier && regexSingleEscape.test(character)) {
  37623. value = '\\' + character;
  37624. } else {
  37625. value = character;
  37626. }
  37627. }
  37628. output += value;
  37629. }
  37630. if (isIdentifier) {
  37631. if (/^-[-\d]/.test(output)) {
  37632. output = '\\-' + output.slice(1);
  37633. } else if (/\d/.test(firstChar)) {
  37634. output = '\\3' + firstChar + ' ' + output.slice(1);
  37635. }
  37636. }
  37637. // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
  37638. // since they’re redundant. Note that this is only possible if the escape
  37639. // sequence isn’t preceded by an odd number of backslashes.
  37640. output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
  37641. if ($1 && $1.length % 2) {
  37642. // It’s not safe to remove the space, so don’t.
  37643. return $0;
  37644. }
  37645. // Strip the space.
  37646. return ($1 || '') + $2;
  37647. });
  37648. if (!isIdentifier && options.wrap) {
  37649. return quote + output + quote;
  37650. }
  37651. return output;
  37652. };
  37653. // Expose default options (so they can be overridden globally).
  37654. cssesc.options = {
  37655. 'escapeEverything': false,
  37656. 'isIdentifier': false,
  37657. 'quotes': 'single',
  37658. 'wrap': false
  37659. };
  37660. cssesc.version = '3.0.0';
  37661. cssesc_1 = cssesc;
  37662. return cssesc_1;
  37663. }
  37664. var hasRequiredClassName;
  37665. function requireClassName () {
  37666. if (hasRequiredClassName) return className.exports;
  37667. hasRequiredClassName = 1;
  37668. (function (module, exports$1) {
  37669. exports$1.__esModule = true;
  37670. exports$1["default"] = void 0;
  37671. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37672. var _util = /*@__PURE__*/ requireUtil$1();
  37673. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37674. var _types = /*@__PURE__*/ requireTypes();
  37675. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37676. 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); } }
  37677. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37678. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37679. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37680. var ClassName = /*#__PURE__*/function (_Node) {
  37681. _inheritsLoose(ClassName, _Node);
  37682. function ClassName(opts) {
  37683. var _this;
  37684. _this = _Node.call(this, opts) || this;
  37685. _this.type = _types.CLASS;
  37686. _this._constructed = true;
  37687. return _this;
  37688. }
  37689. var _proto = ClassName.prototype;
  37690. _proto.valueToString = function valueToString() {
  37691. return '.' + _Node.prototype.valueToString.call(this);
  37692. };
  37693. _createClass(ClassName, [{
  37694. key: "value",
  37695. get: function get() {
  37696. return this._value;
  37697. },
  37698. set: function set(v) {
  37699. if (this._constructed) {
  37700. var escaped = (0, _cssesc["default"])(v, {
  37701. isIdentifier: true
  37702. });
  37703. if (escaped !== v) {
  37704. (0, _util.ensureObject)(this, "raws");
  37705. this.raws.value = escaped;
  37706. } else if (this.raws) {
  37707. delete this.raws.value;
  37708. }
  37709. }
  37710. this._value = v;
  37711. }
  37712. }]);
  37713. return ClassName;
  37714. }(_node["default"]);
  37715. exports$1["default"] = ClassName;
  37716. module.exports = exports$1.default;
  37717. } (className, className.exports));
  37718. return className.exports;
  37719. }
  37720. var comment = {exports: {}};
  37721. var hasRequiredComment;
  37722. function requireComment () {
  37723. if (hasRequiredComment) return comment.exports;
  37724. hasRequiredComment = 1;
  37725. (function (module, exports$1) {
  37726. exports$1.__esModule = true;
  37727. exports$1["default"] = void 0;
  37728. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37729. var _types = /*@__PURE__*/ requireTypes();
  37730. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37731. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37732. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37733. var Comment = /*#__PURE__*/function (_Node) {
  37734. _inheritsLoose(Comment, _Node);
  37735. function Comment(opts) {
  37736. var _this;
  37737. _this = _Node.call(this, opts) || this;
  37738. _this.type = _types.COMMENT;
  37739. return _this;
  37740. }
  37741. return Comment;
  37742. }(_node["default"]);
  37743. exports$1["default"] = Comment;
  37744. module.exports = exports$1.default;
  37745. } (comment, comment.exports));
  37746. return comment.exports;
  37747. }
  37748. var id = {exports: {}};
  37749. var hasRequiredId;
  37750. function requireId () {
  37751. if (hasRequiredId) return id.exports;
  37752. hasRequiredId = 1;
  37753. (function (module, exports$1) {
  37754. exports$1.__esModule = true;
  37755. exports$1["default"] = void 0;
  37756. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37757. var _types = /*@__PURE__*/ requireTypes();
  37758. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37759. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37760. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37761. var ID = /*#__PURE__*/function (_Node) {
  37762. _inheritsLoose(ID, _Node);
  37763. function ID(opts) {
  37764. var _this;
  37765. _this = _Node.call(this, opts) || this;
  37766. _this.type = _types.ID;
  37767. return _this;
  37768. }
  37769. var _proto = ID.prototype;
  37770. _proto.valueToString = function valueToString() {
  37771. return '#' + _Node.prototype.valueToString.call(this);
  37772. };
  37773. return ID;
  37774. }(_node["default"]);
  37775. exports$1["default"] = ID;
  37776. module.exports = exports$1.default;
  37777. } (id, id.exports));
  37778. return id.exports;
  37779. }
  37780. var tag = {exports: {}};
  37781. var namespace = {exports: {}};
  37782. var hasRequiredNamespace;
  37783. function requireNamespace () {
  37784. if (hasRequiredNamespace) return namespace.exports;
  37785. hasRequiredNamespace = 1;
  37786. (function (module, exports$1) {
  37787. exports$1.__esModule = true;
  37788. exports$1["default"] = void 0;
  37789. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37790. var _util = /*@__PURE__*/ requireUtil$1();
  37791. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37792. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37793. 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); } }
  37794. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37795. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37796. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37797. var Namespace = /*#__PURE__*/function (_Node) {
  37798. _inheritsLoose(Namespace, _Node);
  37799. function Namespace() {
  37800. return _Node.apply(this, arguments) || this;
  37801. }
  37802. var _proto = Namespace.prototype;
  37803. _proto.qualifiedName = function qualifiedName(value) {
  37804. if (this.namespace) {
  37805. return this.namespaceString + "|" + value;
  37806. } else {
  37807. return value;
  37808. }
  37809. };
  37810. _proto.valueToString = function valueToString() {
  37811. return this.qualifiedName(_Node.prototype.valueToString.call(this));
  37812. };
  37813. _createClass(Namespace, [{
  37814. key: "namespace",
  37815. get: function get() {
  37816. return this._namespace;
  37817. },
  37818. set: function set(namespace) {
  37819. if (namespace === true || namespace === "*" || namespace === "&") {
  37820. this._namespace = namespace;
  37821. if (this.raws) {
  37822. delete this.raws.namespace;
  37823. }
  37824. return;
  37825. }
  37826. var escaped = (0, _cssesc["default"])(namespace, {
  37827. isIdentifier: true
  37828. });
  37829. this._namespace = namespace;
  37830. if (escaped !== namespace) {
  37831. (0, _util.ensureObject)(this, "raws");
  37832. this.raws.namespace = escaped;
  37833. } else if (this.raws) {
  37834. delete this.raws.namespace;
  37835. }
  37836. }
  37837. }, {
  37838. key: "ns",
  37839. get: function get() {
  37840. return this._namespace;
  37841. },
  37842. set: function set(namespace) {
  37843. this.namespace = namespace;
  37844. }
  37845. }, {
  37846. key: "namespaceString",
  37847. get: function get() {
  37848. if (this.namespace) {
  37849. var ns = this.stringifyProperty("namespace");
  37850. if (ns === true) {
  37851. return '';
  37852. } else {
  37853. return ns;
  37854. }
  37855. } else {
  37856. return '';
  37857. }
  37858. }
  37859. }]);
  37860. return Namespace;
  37861. }(_node["default"]);
  37862. exports$1["default"] = Namespace;
  37863. module.exports = exports$1.default;
  37864. } (namespace, namespace.exports));
  37865. return namespace.exports;
  37866. }
  37867. var hasRequiredTag;
  37868. function requireTag () {
  37869. if (hasRequiredTag) return tag.exports;
  37870. hasRequiredTag = 1;
  37871. (function (module, exports$1) {
  37872. exports$1.__esModule = true;
  37873. exports$1["default"] = void 0;
  37874. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  37875. var _types = /*@__PURE__*/ requireTypes();
  37876. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37877. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37878. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37879. var Tag = /*#__PURE__*/function (_Namespace) {
  37880. _inheritsLoose(Tag, _Namespace);
  37881. function Tag(opts) {
  37882. var _this;
  37883. _this = _Namespace.call(this, opts) || this;
  37884. _this.type = _types.TAG;
  37885. return _this;
  37886. }
  37887. return Tag;
  37888. }(_namespace["default"]);
  37889. exports$1["default"] = Tag;
  37890. module.exports = exports$1.default;
  37891. } (tag, tag.exports));
  37892. return tag.exports;
  37893. }
  37894. var string = {exports: {}};
  37895. var hasRequiredString;
  37896. function requireString () {
  37897. if (hasRequiredString) return string.exports;
  37898. hasRequiredString = 1;
  37899. (function (module, exports$1) {
  37900. exports$1.__esModule = true;
  37901. exports$1["default"] = void 0;
  37902. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37903. var _types = /*@__PURE__*/ requireTypes();
  37904. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37905. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37906. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37907. var String = /*#__PURE__*/function (_Node) {
  37908. _inheritsLoose(String, _Node);
  37909. function String(opts) {
  37910. var _this;
  37911. _this = _Node.call(this, opts) || this;
  37912. _this.type = _types.STRING;
  37913. return _this;
  37914. }
  37915. return String;
  37916. }(_node["default"]);
  37917. exports$1["default"] = String;
  37918. module.exports = exports$1.default;
  37919. } (string, string.exports));
  37920. return string.exports;
  37921. }
  37922. var pseudo = {exports: {}};
  37923. var hasRequiredPseudo;
  37924. function requirePseudo () {
  37925. if (hasRequiredPseudo) return pseudo.exports;
  37926. hasRequiredPseudo = 1;
  37927. (function (module, exports$1) {
  37928. exports$1.__esModule = true;
  37929. exports$1["default"] = void 0;
  37930. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37931. var _types = /*@__PURE__*/ requireTypes();
  37932. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37933. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37934. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37935. var Pseudo = /*#__PURE__*/function (_Container) {
  37936. _inheritsLoose(Pseudo, _Container);
  37937. function Pseudo(opts) {
  37938. var _this;
  37939. _this = _Container.call(this, opts) || this;
  37940. _this.type = _types.PSEUDO;
  37941. return _this;
  37942. }
  37943. var _proto = Pseudo.prototype;
  37944. _proto.toString = function toString() {
  37945. var params = this.length ? '(' + this.map(String).join(',') + ')' : '';
  37946. return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
  37947. };
  37948. return Pseudo;
  37949. }(_container["default"]);
  37950. exports$1["default"] = Pseudo;
  37951. module.exports = exports$1.default;
  37952. } (pseudo, pseudo.exports));
  37953. return pseudo.exports;
  37954. }
  37955. var attribute = {};
  37956. var node;
  37957. var hasRequiredNode;
  37958. function requireNode () {
  37959. if (hasRequiredNode) return node;
  37960. hasRequiredNode = 1;
  37961. /**
  37962. * For Node.js, simply re-export the core `util.deprecate` function.
  37963. */
  37964. node = require$$0.deprecate;
  37965. return node;
  37966. }
  37967. var hasRequiredAttribute;
  37968. function requireAttribute () {
  37969. if (hasRequiredAttribute) return attribute;
  37970. hasRequiredAttribute = 1;
  37971. (function (exports$1) {
  37972. exports$1.__esModule = true;
  37973. exports$1["default"] = void 0;
  37974. exports$1.unescapeValue = unescapeValue;
  37975. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37976. var _unesc = _interopRequireDefault(/*@__PURE__*/ requireUnesc());
  37977. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  37978. var _types = /*@__PURE__*/ requireTypes();
  37979. var _CSSESC_QUOTE_OPTIONS;
  37980. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37981. 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); } }
  37982. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37983. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37984. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37985. var deprecate = /*@__PURE__*/ requireNode();
  37986. var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
  37987. var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
  37988. var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
  37989. var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
  37990. function unescapeValue(value) {
  37991. var deprecatedUsage = false;
  37992. var quoteMark = null;
  37993. var unescaped = value;
  37994. var m = unescaped.match(WRAPPED_IN_QUOTES);
  37995. if (m) {
  37996. quoteMark = m[1];
  37997. unescaped = m[2];
  37998. }
  37999. unescaped = (0, _unesc["default"])(unescaped);
  38000. if (unescaped !== value) {
  38001. deprecatedUsage = true;
  38002. }
  38003. return {
  38004. deprecatedUsage: deprecatedUsage,
  38005. unescaped: unescaped,
  38006. quoteMark: quoteMark
  38007. };
  38008. }
  38009. function handleDeprecatedContructorOpts(opts) {
  38010. if (opts.quoteMark !== undefined) {
  38011. return opts;
  38012. }
  38013. if (opts.value === undefined) {
  38014. return opts;
  38015. }
  38016. warnOfDeprecatedConstructor();
  38017. var _unescapeValue = unescapeValue(opts.value),
  38018. quoteMark = _unescapeValue.quoteMark,
  38019. unescaped = _unescapeValue.unescaped;
  38020. if (!opts.raws) {
  38021. opts.raws = {};
  38022. }
  38023. if (opts.raws.value === undefined) {
  38024. opts.raws.value = opts.value;
  38025. }
  38026. opts.value = unescaped;
  38027. opts.quoteMark = quoteMark;
  38028. return opts;
  38029. }
  38030. var Attribute = /*#__PURE__*/function (_Namespace) {
  38031. _inheritsLoose(Attribute, _Namespace);
  38032. function Attribute(opts) {
  38033. var _this;
  38034. if (opts === void 0) {
  38035. opts = {};
  38036. }
  38037. _this = _Namespace.call(this, handleDeprecatedContructorOpts(opts)) || this;
  38038. _this.type = _types.ATTRIBUTE;
  38039. _this.raws = _this.raws || {};
  38040. Object.defineProperty(_this.raws, 'unquoted', {
  38041. get: deprecate(function () {
  38042. return _this.value;
  38043. }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
  38044. set: deprecate(function () {
  38045. return _this.value;
  38046. }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
  38047. });
  38048. _this._constructed = true;
  38049. return _this;
  38050. }
  38051. /**
  38052. * Returns the Attribute's value quoted such that it would be legal to use
  38053. * in the value of a css file. The original value's quotation setting
  38054. * used for stringification is left unchanged. See `setValue(value, options)`
  38055. * if you want to control the quote settings of a new value for the attribute.
  38056. *
  38057. * You can also change the quotation used for the current value by setting quoteMark.
  38058. *
  38059. * Options:
  38060. * * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
  38061. * option is not set, the original value for quoteMark will be used. If
  38062. * indeterminate, a double quote is used. The legal values are:
  38063. * * `null` - the value will be unquoted and characters will be escaped as necessary.
  38064. * * `'` - the value will be quoted with a single quote and single quotes are escaped.
  38065. * * `"` - the value will be quoted with a double quote and double quotes are escaped.
  38066. * * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
  38067. * over the quoteMark option value.
  38068. * * smart {boolean} - if true, will select a quote mark based on the value
  38069. * and the other options specified here. See the `smartQuoteMark()`
  38070. * method.
  38071. **/
  38072. var _proto = Attribute.prototype;
  38073. _proto.getQuotedValue = function getQuotedValue(options) {
  38074. if (options === void 0) {
  38075. options = {};
  38076. }
  38077. var quoteMark = this._determineQuoteMark(options);
  38078. var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
  38079. var escaped = (0, _cssesc["default"])(this._value, cssescopts);
  38080. return escaped;
  38081. };
  38082. _proto._determineQuoteMark = function _determineQuoteMark(options) {
  38083. return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
  38084. }
  38085. /**
  38086. * Set the unescaped value with the specified quotation options. The value
  38087. * provided must not include any wrapping quote marks -- those quotes will
  38088. * be interpreted as part of the value and escaped accordingly.
  38089. */;
  38090. _proto.setValue = function setValue(value, options) {
  38091. if (options === void 0) {
  38092. options = {};
  38093. }
  38094. this._value = value;
  38095. this._quoteMark = this._determineQuoteMark(options);
  38096. this._syncRawValue();
  38097. }
  38098. /**
  38099. * Intelligently select a quoteMark value based on the value's contents. If
  38100. * the value is a legal CSS ident, it will not be quoted. Otherwise a quote
  38101. * mark will be picked that minimizes the number of escapes.
  38102. *
  38103. * If there's no clear winner, the quote mark from these options is used,
  38104. * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
  38105. * true). If the quoteMark is unspecified, a double quote is used.
  38106. *
  38107. * @param options This takes the quoteMark and preferCurrentQuoteMark options
  38108. * from the quoteValue method.
  38109. */;
  38110. _proto.smartQuoteMark = function smartQuoteMark(options) {
  38111. var v = this.value;
  38112. var numSingleQuotes = v.replace(/[^']/g, '').length;
  38113. var numDoubleQuotes = v.replace(/[^"]/g, '').length;
  38114. if (numSingleQuotes + numDoubleQuotes === 0) {
  38115. var escaped = (0, _cssesc["default"])(v, {
  38116. isIdentifier: true
  38117. });
  38118. if (escaped === v) {
  38119. return Attribute.NO_QUOTE;
  38120. } else {
  38121. var pref = this.preferredQuoteMark(options);
  38122. if (pref === Attribute.NO_QUOTE) {
  38123. // pick a quote mark that isn't none and see if it's smaller
  38124. var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
  38125. var opts = CSSESC_QUOTE_OPTIONS[quote];
  38126. var quoteValue = (0, _cssesc["default"])(v, opts);
  38127. if (quoteValue.length < escaped.length) {
  38128. return quote;
  38129. }
  38130. }
  38131. return pref;
  38132. }
  38133. } else if (numDoubleQuotes === numSingleQuotes) {
  38134. return this.preferredQuoteMark(options);
  38135. } else if (numDoubleQuotes < numSingleQuotes) {
  38136. return Attribute.DOUBLE_QUOTE;
  38137. } else {
  38138. return Attribute.SINGLE_QUOTE;
  38139. }
  38140. }
  38141. /**
  38142. * Selects the preferred quote mark based on the options and the current quote mark value.
  38143. * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
  38144. * instead.
  38145. */;
  38146. _proto.preferredQuoteMark = function preferredQuoteMark(options) {
  38147. var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
  38148. if (quoteMark === undefined) {
  38149. quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
  38150. }
  38151. if (quoteMark === undefined) {
  38152. quoteMark = Attribute.DOUBLE_QUOTE;
  38153. }
  38154. return quoteMark;
  38155. };
  38156. _proto._syncRawValue = function _syncRawValue() {
  38157. var rawValue = (0, _cssesc["default"])(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
  38158. if (rawValue === this._value) {
  38159. if (this.raws) {
  38160. delete this.raws.value;
  38161. }
  38162. } else {
  38163. this.raws.value = rawValue;
  38164. }
  38165. };
  38166. _proto._handleEscapes = function _handleEscapes(prop, value) {
  38167. if (this._constructed) {
  38168. var escaped = (0, _cssesc["default"])(value, {
  38169. isIdentifier: true
  38170. });
  38171. if (escaped !== value) {
  38172. this.raws[prop] = escaped;
  38173. } else {
  38174. delete this.raws[prop];
  38175. }
  38176. }
  38177. };
  38178. _proto._spacesFor = function _spacesFor(name) {
  38179. var attrSpaces = {
  38180. before: '',
  38181. after: ''
  38182. };
  38183. var spaces = this.spaces[name] || {};
  38184. var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
  38185. return Object.assign(attrSpaces, spaces, rawSpaces);
  38186. };
  38187. _proto._stringFor = function _stringFor(name, spaceName, concat) {
  38188. if (spaceName === void 0) {
  38189. spaceName = name;
  38190. }
  38191. if (concat === void 0) {
  38192. concat = defaultAttrConcat;
  38193. }
  38194. var attrSpaces = this._spacesFor(spaceName);
  38195. return concat(this.stringifyProperty(name), attrSpaces);
  38196. }
  38197. /**
  38198. * returns the offset of the attribute part specified relative to the
  38199. * start of the node of the output string.
  38200. *
  38201. * * "ns" - alias for "namespace"
  38202. * * "namespace" - the namespace if it exists.
  38203. * * "attribute" - the attribute name
  38204. * * "attributeNS" - the start of the attribute or its namespace
  38205. * * "operator" - the match operator of the attribute
  38206. * * "value" - The value (string or identifier)
  38207. * * "insensitive" - the case insensitivity flag;
  38208. * @param part One of the possible values inside an attribute.
  38209. * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
  38210. */;
  38211. _proto.offsetOf = function offsetOf(name) {
  38212. var count = 1;
  38213. var attributeSpaces = this._spacesFor("attribute");
  38214. count += attributeSpaces.before.length;
  38215. if (name === "namespace" || name === "ns") {
  38216. return this.namespace ? count : -1;
  38217. }
  38218. if (name === "attributeNS") {
  38219. return count;
  38220. }
  38221. count += this.namespaceString.length;
  38222. if (this.namespace) {
  38223. count += 1;
  38224. }
  38225. if (name === "attribute") {
  38226. return count;
  38227. }
  38228. count += this.stringifyProperty("attribute").length;
  38229. count += attributeSpaces.after.length;
  38230. var operatorSpaces = this._spacesFor("operator");
  38231. count += operatorSpaces.before.length;
  38232. var operator = this.stringifyProperty("operator");
  38233. if (name === "operator") {
  38234. return operator ? count : -1;
  38235. }
  38236. count += operator.length;
  38237. count += operatorSpaces.after.length;
  38238. var valueSpaces = this._spacesFor("value");
  38239. count += valueSpaces.before.length;
  38240. var value = this.stringifyProperty("value");
  38241. if (name === "value") {
  38242. return value ? count : -1;
  38243. }
  38244. count += value.length;
  38245. count += valueSpaces.after.length;
  38246. var insensitiveSpaces = this._spacesFor("insensitive");
  38247. count += insensitiveSpaces.before.length;
  38248. if (name === "insensitive") {
  38249. return this.insensitive ? count : -1;
  38250. }
  38251. return -1;
  38252. };
  38253. _proto.toString = function toString() {
  38254. var _this2 = this;
  38255. var selector = [this.rawSpaceBefore, '['];
  38256. selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
  38257. if (this.operator && (this.value || this.value === '')) {
  38258. selector.push(this._stringFor('operator'));
  38259. selector.push(this._stringFor('value'));
  38260. selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
  38261. if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
  38262. attrSpaces.before = " ";
  38263. }
  38264. return defaultAttrConcat(attrValue, attrSpaces);
  38265. }));
  38266. }
  38267. selector.push(']');
  38268. selector.push(this.rawSpaceAfter);
  38269. return selector.join('');
  38270. };
  38271. _createClass(Attribute, [{
  38272. key: "quoted",
  38273. get: function get() {
  38274. var qm = this.quoteMark;
  38275. return qm === "'" || qm === '"';
  38276. },
  38277. set: function set(value) {
  38278. warnOfDeprecatedQuotedAssignment();
  38279. }
  38280. /**
  38281. * returns a single (`'`) or double (`"`) quote character if the value is quoted.
  38282. * returns `null` if the value is not quoted.
  38283. * returns `undefined` if the quotation state is unknown (this can happen when
  38284. * the attribute is constructed without specifying a quote mark.)
  38285. */
  38286. }, {
  38287. key: "quoteMark",
  38288. get: function get() {
  38289. return this._quoteMark;
  38290. }
  38291. /**
  38292. * Set the quote mark to be used by this attribute's value.
  38293. * If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
  38294. * value is updated accordingly.
  38295. *
  38296. * @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
  38297. */,
  38298. set: function set(quoteMark) {
  38299. if (!this._constructed) {
  38300. this._quoteMark = quoteMark;
  38301. return;
  38302. }
  38303. if (this._quoteMark !== quoteMark) {
  38304. this._quoteMark = quoteMark;
  38305. this._syncRawValue();
  38306. }
  38307. }
  38308. }, {
  38309. key: "qualifiedAttribute",
  38310. get: function get() {
  38311. return this.qualifiedName(this.raws.attribute || this.attribute);
  38312. }
  38313. }, {
  38314. key: "insensitiveFlag",
  38315. get: function get() {
  38316. return this.insensitive ? 'i' : '';
  38317. }
  38318. }, {
  38319. key: "value",
  38320. get: function get() {
  38321. return this._value;
  38322. },
  38323. set:
  38324. /**
  38325. * Before 3.0, the value had to be set to an escaped value including any wrapped
  38326. * quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
  38327. * is unescaped during parsing and any quote marks are removed.
  38328. *
  38329. * Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
  38330. * a deprecation warning is raised when the new value contains any characters that would
  38331. * require escaping (including if it contains wrapped quotes).
  38332. *
  38333. * Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
  38334. * how the new value is quoted.
  38335. */
  38336. function set(v) {
  38337. if (this._constructed) {
  38338. var _unescapeValue2 = unescapeValue(v),
  38339. deprecatedUsage = _unescapeValue2.deprecatedUsage,
  38340. unescaped = _unescapeValue2.unescaped,
  38341. quoteMark = _unescapeValue2.quoteMark;
  38342. if (deprecatedUsage) {
  38343. warnOfDeprecatedValueAssignment();
  38344. }
  38345. if (unescaped === this._value && quoteMark === this._quoteMark) {
  38346. return;
  38347. }
  38348. this._value = unescaped;
  38349. this._quoteMark = quoteMark;
  38350. this._syncRawValue();
  38351. } else {
  38352. this._value = v;
  38353. }
  38354. }
  38355. }, {
  38356. key: "insensitive",
  38357. get: function get() {
  38358. return this._insensitive;
  38359. }
  38360. /**
  38361. * Set the case insensitive flag.
  38362. * If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
  38363. * of the attribute is updated accordingly.
  38364. *
  38365. * @param {true | false} insensitive true if the attribute should match case-insensitively.
  38366. */,
  38367. set: function set(insensitive) {
  38368. if (!insensitive) {
  38369. this._insensitive = false;
  38370. // "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
  38371. // When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
  38372. if (this.raws && (this.raws.insensitiveFlag === 'I' || this.raws.insensitiveFlag === 'i')) {
  38373. this.raws.insensitiveFlag = undefined;
  38374. }
  38375. }
  38376. this._insensitive = insensitive;
  38377. }
  38378. }, {
  38379. key: "attribute",
  38380. get: function get() {
  38381. return this._attribute;
  38382. },
  38383. set: function set(name) {
  38384. this._handleEscapes("attribute", name);
  38385. this._attribute = name;
  38386. }
  38387. }]);
  38388. return Attribute;
  38389. }(_namespace["default"]);
  38390. exports$1["default"] = Attribute;
  38391. Attribute.NO_QUOTE = null;
  38392. Attribute.SINGLE_QUOTE = "'";
  38393. Attribute.DOUBLE_QUOTE = '"';
  38394. var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
  38395. "'": {
  38396. quotes: 'single',
  38397. wrap: true
  38398. },
  38399. '"': {
  38400. quotes: 'double',
  38401. wrap: true
  38402. }
  38403. }, _CSSESC_QUOTE_OPTIONS[null] = {
  38404. isIdentifier: true
  38405. }, _CSSESC_QUOTE_OPTIONS);
  38406. function defaultAttrConcat(attrValue, attrSpaces) {
  38407. return "" + attrSpaces.before + attrValue + attrSpaces.after;
  38408. }
  38409. } (attribute));
  38410. return attribute;
  38411. }
  38412. var universal = {exports: {}};
  38413. var hasRequiredUniversal;
  38414. function requireUniversal () {
  38415. if (hasRequiredUniversal) return universal.exports;
  38416. hasRequiredUniversal = 1;
  38417. (function (module, exports$1) {
  38418. exports$1.__esModule = true;
  38419. exports$1["default"] = void 0;
  38420. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  38421. var _types = /*@__PURE__*/ requireTypes();
  38422. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38423. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38424. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38425. var Universal = /*#__PURE__*/function (_Namespace) {
  38426. _inheritsLoose(Universal, _Namespace);
  38427. function Universal(opts) {
  38428. var _this;
  38429. _this = _Namespace.call(this, opts) || this;
  38430. _this.type = _types.UNIVERSAL;
  38431. _this.value = '*';
  38432. return _this;
  38433. }
  38434. return Universal;
  38435. }(_namespace["default"]);
  38436. exports$1["default"] = Universal;
  38437. module.exports = exports$1.default;
  38438. } (universal, universal.exports));
  38439. return universal.exports;
  38440. }
  38441. var combinator = {exports: {}};
  38442. var hasRequiredCombinator;
  38443. function requireCombinator () {
  38444. if (hasRequiredCombinator) return combinator.exports;
  38445. hasRequiredCombinator = 1;
  38446. (function (module, exports$1) {
  38447. exports$1.__esModule = true;
  38448. exports$1["default"] = void 0;
  38449. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  38450. var _types = /*@__PURE__*/ requireTypes();
  38451. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38452. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38453. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38454. var Combinator = /*#__PURE__*/function (_Node) {
  38455. _inheritsLoose(Combinator, _Node);
  38456. function Combinator(opts) {
  38457. var _this;
  38458. _this = _Node.call(this, opts) || this;
  38459. _this.type = _types.COMBINATOR;
  38460. return _this;
  38461. }
  38462. return Combinator;
  38463. }(_node["default"]);
  38464. exports$1["default"] = Combinator;
  38465. module.exports = exports$1.default;
  38466. } (combinator, combinator.exports));
  38467. return combinator.exports;
  38468. }
  38469. var nesting = {exports: {}};
  38470. var hasRequiredNesting;
  38471. function requireNesting () {
  38472. if (hasRequiredNesting) return nesting.exports;
  38473. hasRequiredNesting = 1;
  38474. (function (module, exports$1) {
  38475. exports$1.__esModule = true;
  38476. exports$1["default"] = void 0;
  38477. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  38478. var _types = /*@__PURE__*/ requireTypes();
  38479. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38480. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38481. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38482. var Nesting = /*#__PURE__*/function (_Node) {
  38483. _inheritsLoose(Nesting, _Node);
  38484. function Nesting(opts) {
  38485. var _this;
  38486. _this = _Node.call(this, opts) || this;
  38487. _this.type = _types.NESTING;
  38488. _this.value = '&';
  38489. return _this;
  38490. }
  38491. return Nesting;
  38492. }(_node["default"]);
  38493. exports$1["default"] = Nesting;
  38494. module.exports = exports$1.default;
  38495. } (nesting, nesting.exports));
  38496. return nesting.exports;
  38497. }
  38498. var sortAscending = {exports: {}};
  38499. var hasRequiredSortAscending;
  38500. function requireSortAscending () {
  38501. if (hasRequiredSortAscending) return sortAscending.exports;
  38502. hasRequiredSortAscending = 1;
  38503. (function (module, exports$1) {
  38504. exports$1.__esModule = true;
  38505. exports$1["default"] = sortAscending;
  38506. function sortAscending(list) {
  38507. return list.sort(function (a, b) {
  38508. return a - b;
  38509. });
  38510. }
  38511. module.exports = exports$1.default;
  38512. } (sortAscending, sortAscending.exports));
  38513. return sortAscending.exports;
  38514. }
  38515. var tokenize = {};
  38516. var tokenTypes = {};
  38517. var hasRequiredTokenTypes;
  38518. function requireTokenTypes () {
  38519. if (hasRequiredTokenTypes) return tokenTypes;
  38520. hasRequiredTokenTypes = 1;
  38521. tokenTypes.__esModule = true;
  38522. tokenTypes.word = tokenTypes.tilde = tokenTypes.tab = tokenTypes.str = tokenTypes.space = tokenTypes.slash = tokenTypes.singleQuote = tokenTypes.semicolon = tokenTypes.plus = tokenTypes.pipe = tokenTypes.openSquare = tokenTypes.openParenthesis = tokenTypes.newline = tokenTypes.greaterThan = tokenTypes.feed = tokenTypes.equals = tokenTypes.doubleQuote = tokenTypes.dollar = tokenTypes.cr = tokenTypes.comment = tokenTypes.comma = tokenTypes.combinator = tokenTypes.colon = tokenTypes.closeSquare = tokenTypes.closeParenthesis = tokenTypes.caret = tokenTypes.bang = tokenTypes.backslash = tokenTypes.at = tokenTypes.asterisk = tokenTypes.ampersand = void 0;
  38523. var ampersand = 38; // `&`.charCodeAt(0);
  38524. tokenTypes.ampersand = ampersand;
  38525. var asterisk = 42; // `*`.charCodeAt(0);
  38526. tokenTypes.asterisk = asterisk;
  38527. var at = 64; // `@`.charCodeAt(0);
  38528. tokenTypes.at = at;
  38529. var comma = 44; // `,`.charCodeAt(0);
  38530. tokenTypes.comma = comma;
  38531. var colon = 58; // `:`.charCodeAt(0);
  38532. tokenTypes.colon = colon;
  38533. var semicolon = 59; // `;`.charCodeAt(0);
  38534. tokenTypes.semicolon = semicolon;
  38535. var openParenthesis = 40; // `(`.charCodeAt(0);
  38536. tokenTypes.openParenthesis = openParenthesis;
  38537. var closeParenthesis = 41; // `)`.charCodeAt(0);
  38538. tokenTypes.closeParenthesis = closeParenthesis;
  38539. var openSquare = 91; // `[`.charCodeAt(0);
  38540. tokenTypes.openSquare = openSquare;
  38541. var closeSquare = 93; // `]`.charCodeAt(0);
  38542. tokenTypes.closeSquare = closeSquare;
  38543. var dollar = 36; // `$`.charCodeAt(0);
  38544. tokenTypes.dollar = dollar;
  38545. var tilde = 126; // `~`.charCodeAt(0);
  38546. tokenTypes.tilde = tilde;
  38547. var caret = 94; // `^`.charCodeAt(0);
  38548. tokenTypes.caret = caret;
  38549. var plus = 43; // `+`.charCodeAt(0);
  38550. tokenTypes.plus = plus;
  38551. var equals = 61; // `=`.charCodeAt(0);
  38552. tokenTypes.equals = equals;
  38553. var pipe = 124; // `|`.charCodeAt(0);
  38554. tokenTypes.pipe = pipe;
  38555. var greaterThan = 62; // `>`.charCodeAt(0);
  38556. tokenTypes.greaterThan = greaterThan;
  38557. var space = 32; // ` `.charCodeAt(0);
  38558. tokenTypes.space = space;
  38559. var singleQuote = 39; // `'`.charCodeAt(0);
  38560. tokenTypes.singleQuote = singleQuote;
  38561. var doubleQuote = 34; // `"`.charCodeAt(0);
  38562. tokenTypes.doubleQuote = doubleQuote;
  38563. var slash = 47; // `/`.charCodeAt(0);
  38564. tokenTypes.slash = slash;
  38565. var bang = 33; // `!`.charCodeAt(0);
  38566. tokenTypes.bang = bang;
  38567. var backslash = 92; // '\\'.charCodeAt(0);
  38568. tokenTypes.backslash = backslash;
  38569. var cr = 13; // '\r'.charCodeAt(0);
  38570. tokenTypes.cr = cr;
  38571. var feed = 12; // '\f'.charCodeAt(0);
  38572. tokenTypes.feed = feed;
  38573. var newline = 10; // '\n'.charCodeAt(0);
  38574. tokenTypes.newline = newline;
  38575. var tab = 9; // '\t'.charCodeAt(0);
  38576. // Expose aliases primarily for readability.
  38577. tokenTypes.tab = tab;
  38578. var str = singleQuote;
  38579. // No good single character representation!
  38580. tokenTypes.str = str;
  38581. var comment = -1;
  38582. tokenTypes.comment = comment;
  38583. var word = -2;
  38584. tokenTypes.word = word;
  38585. var combinator = -3;
  38586. tokenTypes.combinator = combinator;
  38587. return tokenTypes;
  38588. }
  38589. var hasRequiredTokenize;
  38590. function requireTokenize () {
  38591. if (hasRequiredTokenize) return tokenize;
  38592. hasRequiredTokenize = 1;
  38593. (function (exports$1) {
  38594. exports$1.__esModule = true;
  38595. exports$1.FIELDS = void 0;
  38596. exports$1["default"] = tokenize;
  38597. var t = _interopRequireWildcard(/*@__PURE__*/ requireTokenTypes());
  38598. var _unescapable, _wordDelimiters;
  38599. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  38600. function _interopRequireWildcard(obj, nodeInterop) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
  38601. var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
  38602. 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);
  38603. var hex = {};
  38604. var hexChars = "0123456789abcdefABCDEF";
  38605. for (var i = 0; i < hexChars.length; i++) {
  38606. hex[hexChars.charCodeAt(i)] = true;
  38607. }
  38608. /**
  38609. * Returns the last index of the bar css word
  38610. * @param {string} css The string in which the word begins
  38611. * @param {number} start The index into the string where word's first letter occurs
  38612. */
  38613. function consumeWord(css, start) {
  38614. var next = start;
  38615. var code;
  38616. do {
  38617. code = css.charCodeAt(next);
  38618. if (wordDelimiters[code]) {
  38619. return next - 1;
  38620. } else if (code === t.backslash) {
  38621. next = consumeEscape(css, next) + 1;
  38622. } else {
  38623. // All other characters are part of the word
  38624. next++;
  38625. }
  38626. } while (next < css.length);
  38627. return next - 1;
  38628. }
  38629. /**
  38630. * Returns the last index of the escape sequence
  38631. * @param {string} css The string in which the sequence begins
  38632. * @param {number} start The index into the string where escape character (`\`) occurs.
  38633. */
  38634. function consumeEscape(css, start) {
  38635. var next = start;
  38636. var code = css.charCodeAt(next + 1);
  38637. if (unescapable[code]) ; else if (hex[code]) {
  38638. var hexDigits = 0;
  38639. // consume up to 6 hex chars
  38640. do {
  38641. next++;
  38642. hexDigits++;
  38643. code = css.charCodeAt(next + 1);
  38644. } while (hex[code] && hexDigits < 6);
  38645. // if fewer than 6 hex chars, a trailing space ends the escape
  38646. if (hexDigits < 6 && code === t.space) {
  38647. next++;
  38648. }
  38649. } else {
  38650. // the next char is part of the current word
  38651. next++;
  38652. }
  38653. return next;
  38654. }
  38655. var FIELDS = {
  38656. TYPE: 0,
  38657. START_LINE: 1,
  38658. START_COL: 2,
  38659. END_LINE: 3,
  38660. END_COL: 4,
  38661. START_POS: 5,
  38662. END_POS: 6
  38663. };
  38664. exports$1.FIELDS = FIELDS;
  38665. function tokenize(input) {
  38666. var tokens = [];
  38667. var css = input.css.valueOf();
  38668. var _css = css,
  38669. length = _css.length;
  38670. var offset = -1;
  38671. var line = 1;
  38672. var start = 0;
  38673. var end = 0;
  38674. var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
  38675. function unclosed(what, fix) {
  38676. if (input.safe) {
  38677. // fyi: this is never set to true.
  38678. css += fix;
  38679. next = css.length - 1;
  38680. } else {
  38681. throw input.error('Unclosed ' + what, line, start - offset, start);
  38682. }
  38683. }
  38684. while (start < length) {
  38685. code = css.charCodeAt(start);
  38686. if (code === t.newline) {
  38687. offset = start;
  38688. line += 1;
  38689. }
  38690. switch (code) {
  38691. case t.space:
  38692. case t.tab:
  38693. case t.newline:
  38694. case t.cr:
  38695. case t.feed:
  38696. next = start;
  38697. do {
  38698. next += 1;
  38699. code = css.charCodeAt(next);
  38700. if (code === t.newline) {
  38701. offset = next;
  38702. line += 1;
  38703. }
  38704. } while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
  38705. tokenType = t.space;
  38706. endLine = line;
  38707. endColumn = next - offset - 1;
  38708. end = next;
  38709. break;
  38710. case t.plus:
  38711. case t.greaterThan:
  38712. case t.tilde:
  38713. case t.pipe:
  38714. next = start;
  38715. do {
  38716. next += 1;
  38717. code = css.charCodeAt(next);
  38718. } while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
  38719. tokenType = t.combinator;
  38720. endLine = line;
  38721. endColumn = start - offset;
  38722. end = next;
  38723. break;
  38724. // Consume these characters as single tokens.
  38725. case t.asterisk:
  38726. case t.ampersand:
  38727. case t.bang:
  38728. case t.comma:
  38729. case t.equals:
  38730. case t.dollar:
  38731. case t.caret:
  38732. case t.openSquare:
  38733. case t.closeSquare:
  38734. case t.colon:
  38735. case t.semicolon:
  38736. case t.openParenthesis:
  38737. case t.closeParenthesis:
  38738. next = start;
  38739. tokenType = code;
  38740. endLine = line;
  38741. endColumn = start - offset;
  38742. end = next + 1;
  38743. break;
  38744. case t.singleQuote:
  38745. case t.doubleQuote:
  38746. quote = code === t.singleQuote ? "'" : '"';
  38747. next = start;
  38748. do {
  38749. escaped = false;
  38750. next = css.indexOf(quote, next + 1);
  38751. if (next === -1) {
  38752. unclosed('quote', quote);
  38753. }
  38754. escapePos = next;
  38755. while (css.charCodeAt(escapePos - 1) === t.backslash) {
  38756. escapePos -= 1;
  38757. escaped = !escaped;
  38758. }
  38759. } while (escaped);
  38760. tokenType = t.str;
  38761. endLine = line;
  38762. endColumn = start - offset;
  38763. end = next + 1;
  38764. break;
  38765. default:
  38766. if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
  38767. next = css.indexOf('*/', start + 2) + 1;
  38768. if (next === 0) {
  38769. unclosed('comment', '*/');
  38770. }
  38771. content = css.slice(start, next + 1);
  38772. lines = content.split('\n');
  38773. last = lines.length - 1;
  38774. if (last > 0) {
  38775. nextLine = line + last;
  38776. nextOffset = next - lines[last].length;
  38777. } else {
  38778. nextLine = line;
  38779. nextOffset = offset;
  38780. }
  38781. tokenType = t.comment;
  38782. line = nextLine;
  38783. endLine = nextLine;
  38784. endColumn = next - nextOffset;
  38785. } else if (code === t.slash) {
  38786. next = start;
  38787. tokenType = code;
  38788. endLine = line;
  38789. endColumn = start - offset;
  38790. end = next + 1;
  38791. } else {
  38792. next = consumeWord(css, start);
  38793. tokenType = t.word;
  38794. endLine = line;
  38795. endColumn = next - offset;
  38796. }
  38797. end = next + 1;
  38798. break;
  38799. }
  38800. // Ensure that the token structure remains consistent
  38801. tokens.push([tokenType,
  38802. // [0] Token type
  38803. line,
  38804. // [1] Starting line
  38805. start - offset,
  38806. // [2] Starting column
  38807. endLine,
  38808. // [3] Ending line
  38809. endColumn,
  38810. // [4] Ending column
  38811. start,
  38812. // [5] Start position / Source index
  38813. end // [6] End position
  38814. ]);
  38815. // Reset offset for the next token
  38816. if (nextOffset) {
  38817. offset = nextOffset;
  38818. nextOffset = null;
  38819. }
  38820. start = end;
  38821. }
  38822. return tokens;
  38823. }
  38824. } (tokenize));
  38825. return tokenize;
  38826. }
  38827. var hasRequiredParser;
  38828. function requireParser () {
  38829. if (hasRequiredParser) return parser.exports;
  38830. hasRequiredParser = 1;
  38831. (function (module, exports$1) {
  38832. exports$1.__esModule = true;
  38833. exports$1["default"] = void 0;
  38834. var _root = _interopRequireDefault(/*@__PURE__*/ requireRoot());
  38835. var _selector = _interopRequireDefault(/*@__PURE__*/ requireSelector());
  38836. var _className = _interopRequireDefault(/*@__PURE__*/ requireClassName());
  38837. var _comment = _interopRequireDefault(/*@__PURE__*/ requireComment());
  38838. var _id = _interopRequireDefault(/*@__PURE__*/ requireId());
  38839. var _tag = _interopRequireDefault(/*@__PURE__*/ requireTag());
  38840. var _string = _interopRequireDefault(/*@__PURE__*/ requireString());
  38841. var _pseudo = _interopRequireDefault(/*@__PURE__*/ requirePseudo());
  38842. var _attribute = _interopRequireWildcard(/*@__PURE__*/ requireAttribute());
  38843. var _universal = _interopRequireDefault(/*@__PURE__*/ requireUniversal());
  38844. var _combinator = _interopRequireDefault(/*@__PURE__*/ requireCombinator());
  38845. var _nesting = _interopRequireDefault(/*@__PURE__*/ requireNesting());
  38846. var _sortAscending = _interopRequireDefault(/*@__PURE__*/ requireSortAscending());
  38847. var _tokenize = _interopRequireWildcard(/*@__PURE__*/ requireTokenize());
  38848. var tokens = _interopRequireWildcard(/*@__PURE__*/ requireTokenTypes());
  38849. var types = _interopRequireWildcard(/*@__PURE__*/ requireTypes());
  38850. var _util = /*@__PURE__*/ requireUtil$1();
  38851. var _WHITESPACE_TOKENS, _Object$assign;
  38852. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  38853. function _interopRequireWildcard(obj, nodeInterop) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
  38854. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38855. 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); } }
  38856. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  38857. 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);
  38858. var WHITESPACE_EQUIV_TOKENS = Object.assign({}, WHITESPACE_TOKENS, (_Object$assign = {}, _Object$assign[tokens.comment] = true, _Object$assign));
  38859. function tokenStart(token) {
  38860. return {
  38861. line: token[_tokenize.FIELDS.START_LINE],
  38862. column: token[_tokenize.FIELDS.START_COL]
  38863. };
  38864. }
  38865. function tokenEnd(token) {
  38866. return {
  38867. line: token[_tokenize.FIELDS.END_LINE],
  38868. column: token[_tokenize.FIELDS.END_COL]
  38869. };
  38870. }
  38871. function getSource(startLine, startColumn, endLine, endColumn) {
  38872. return {
  38873. start: {
  38874. line: startLine,
  38875. column: startColumn
  38876. },
  38877. end: {
  38878. line: endLine,
  38879. column: endColumn
  38880. }
  38881. };
  38882. }
  38883. function getTokenSource(token) {
  38884. return getSource(token[_tokenize.FIELDS.START_LINE], token[_tokenize.FIELDS.START_COL], token[_tokenize.FIELDS.END_LINE], token[_tokenize.FIELDS.END_COL]);
  38885. }
  38886. function getTokenSourceSpan(startToken, endToken) {
  38887. if (!startToken) {
  38888. return undefined;
  38889. }
  38890. return getSource(startToken[_tokenize.FIELDS.START_LINE], startToken[_tokenize.FIELDS.START_COL], endToken[_tokenize.FIELDS.END_LINE], endToken[_tokenize.FIELDS.END_COL]);
  38891. }
  38892. function unescapeProp(node, prop) {
  38893. var value = node[prop];
  38894. if (typeof value !== "string") {
  38895. return;
  38896. }
  38897. if (value.indexOf("\\") !== -1) {
  38898. (0, _util.ensureObject)(node, 'raws');
  38899. node[prop] = (0, _util.unesc)(value);
  38900. if (node.raws[prop] === undefined) {
  38901. node.raws[prop] = value;
  38902. }
  38903. }
  38904. return node;
  38905. }
  38906. function indexesOf(array, item) {
  38907. var i = -1;
  38908. var indexes = [];
  38909. while ((i = array.indexOf(item, i + 1)) !== -1) {
  38910. indexes.push(i);
  38911. }
  38912. return indexes;
  38913. }
  38914. function uniqs() {
  38915. var list = Array.prototype.concat.apply([], arguments);
  38916. return list.filter(function (item, i) {
  38917. return i === list.indexOf(item);
  38918. });
  38919. }
  38920. var Parser = /*#__PURE__*/function () {
  38921. function Parser(rule, options) {
  38922. if (options === void 0) {
  38923. options = {};
  38924. }
  38925. this.rule = rule;
  38926. this.options = Object.assign({
  38927. lossy: false,
  38928. safe: false
  38929. }, options);
  38930. this.position = 0;
  38931. this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
  38932. this.tokens = (0, _tokenize["default"])({
  38933. css: this.css,
  38934. error: this._errorGenerator(),
  38935. safe: this.options.safe
  38936. });
  38937. var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
  38938. this.root = new _root["default"]({
  38939. source: rootSource
  38940. });
  38941. this.root.errorGenerator = this._errorGenerator();
  38942. var selector = new _selector["default"]({
  38943. source: {
  38944. start: {
  38945. line: 1,
  38946. column: 1
  38947. }
  38948. },
  38949. sourceIndex: 0
  38950. });
  38951. this.root.append(selector);
  38952. this.current = selector;
  38953. this.loop();
  38954. }
  38955. var _proto = Parser.prototype;
  38956. _proto._errorGenerator = function _errorGenerator() {
  38957. var _this = this;
  38958. return function (message, errorOptions) {
  38959. if (typeof _this.rule === 'string') {
  38960. return new Error(message);
  38961. }
  38962. return _this.rule.error(message, errorOptions);
  38963. };
  38964. };
  38965. _proto.attribute = function attribute() {
  38966. var attr = [];
  38967. var startingToken = this.currToken;
  38968. this.position++;
  38969. while (this.position < this.tokens.length && this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38970. attr.push(this.currToken);
  38971. this.position++;
  38972. }
  38973. if (this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38974. return this.expected('closing square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  38975. }
  38976. var len = attr.length;
  38977. var node = {
  38978. source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
  38979. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  38980. };
  38981. if (len === 1 && !~[tokens.word].indexOf(attr[0][_tokenize.FIELDS.TYPE])) {
  38982. return this.expected('attribute', attr[0][_tokenize.FIELDS.START_POS]);
  38983. }
  38984. var pos = 0;
  38985. var spaceBefore = '';
  38986. var commentBefore = '';
  38987. var lastAdded = null;
  38988. var spaceAfterMeaningfulToken = false;
  38989. while (pos < len) {
  38990. var token = attr[pos];
  38991. var content = this.content(token);
  38992. var next = attr[pos + 1];
  38993. switch (token[_tokenize.FIELDS.TYPE]) {
  38994. case tokens.space:
  38995. // if (
  38996. // len === 1 ||
  38997. // pos === 0 && this.content(next) === '|'
  38998. // ) {
  38999. // return this.expected('attribute', token[TOKEN.START_POS], content);
  39000. // }
  39001. spaceAfterMeaningfulToken = true;
  39002. if (this.options.lossy) {
  39003. break;
  39004. }
  39005. if (lastAdded) {
  39006. (0, _util.ensureObject)(node, 'spaces', lastAdded);
  39007. var prevContent = node.spaces[lastAdded].after || '';
  39008. node.spaces[lastAdded].after = prevContent + content;
  39009. var existingComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || null;
  39010. if (existingComment) {
  39011. node.raws.spaces[lastAdded].after = existingComment + content;
  39012. }
  39013. } else {
  39014. spaceBefore = spaceBefore + content;
  39015. commentBefore = commentBefore + content;
  39016. }
  39017. break;
  39018. case tokens.asterisk:
  39019. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39020. node.operator = content;
  39021. lastAdded = 'operator';
  39022. } else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
  39023. if (spaceBefore) {
  39024. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  39025. node.spaces.attribute.before = spaceBefore;
  39026. spaceBefore = '';
  39027. }
  39028. if (commentBefore) {
  39029. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  39030. node.raws.spaces.attribute.before = spaceBefore;
  39031. commentBefore = '';
  39032. }
  39033. node.namespace = (node.namespace || "") + content;
  39034. var rawValue = (0, _util.getProp)(node, 'raws', 'namespace') || null;
  39035. if (rawValue) {
  39036. node.raws.namespace += content;
  39037. }
  39038. lastAdded = 'namespace';
  39039. }
  39040. spaceAfterMeaningfulToken = false;
  39041. break;
  39042. case tokens.dollar:
  39043. if (lastAdded === "value") {
  39044. var oldRawValue = (0, _util.getProp)(node, 'raws', 'value');
  39045. node.value += "$";
  39046. if (oldRawValue) {
  39047. node.raws.value = oldRawValue + "$";
  39048. }
  39049. break;
  39050. }
  39051. // Falls through
  39052. case tokens.caret:
  39053. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39054. node.operator = content;
  39055. lastAdded = 'operator';
  39056. }
  39057. spaceAfterMeaningfulToken = false;
  39058. break;
  39059. case tokens.combinator:
  39060. if (content === '~' && next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39061. node.operator = content;
  39062. lastAdded = 'operator';
  39063. }
  39064. if (content !== '|') {
  39065. spaceAfterMeaningfulToken = false;
  39066. break;
  39067. }
  39068. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39069. node.operator = content;
  39070. lastAdded = 'operator';
  39071. } else if (!node.namespace && !node.attribute) {
  39072. node.namespace = true;
  39073. }
  39074. spaceAfterMeaningfulToken = false;
  39075. break;
  39076. case tokens.word:
  39077. if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][_tokenize.FIELDS.TYPE] !== tokens.equals &&
  39078. // this look-ahead probably fails with comment nodes involved.
  39079. !node.operator && !node.namespace) {
  39080. node.namespace = content;
  39081. lastAdded = 'namespace';
  39082. } else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
  39083. if (spaceBefore) {
  39084. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  39085. node.spaces.attribute.before = spaceBefore;
  39086. spaceBefore = '';
  39087. }
  39088. if (commentBefore) {
  39089. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  39090. node.raws.spaces.attribute.before = commentBefore;
  39091. commentBefore = '';
  39092. }
  39093. node.attribute = (node.attribute || "") + content;
  39094. var _rawValue = (0, _util.getProp)(node, 'raws', 'attribute') || null;
  39095. if (_rawValue) {
  39096. node.raws.attribute += content;
  39097. }
  39098. lastAdded = 'attribute';
  39099. } else if (!node.value && node.value !== "" || lastAdded === "value" && !(spaceAfterMeaningfulToken || node.quoteMark)) {
  39100. var _unescaped = (0, _util.unesc)(content);
  39101. var _oldRawValue = (0, _util.getProp)(node, 'raws', 'value') || '';
  39102. var oldValue = node.value || '';
  39103. node.value = oldValue + _unescaped;
  39104. node.quoteMark = null;
  39105. if (_unescaped !== content || _oldRawValue) {
  39106. (0, _util.ensureObject)(node, 'raws');
  39107. node.raws.value = (_oldRawValue || oldValue) + content;
  39108. }
  39109. lastAdded = 'value';
  39110. } else {
  39111. var insensitive = content === 'i' || content === "I";
  39112. if ((node.value || node.value === '') && (node.quoteMark || spaceAfterMeaningfulToken)) {
  39113. node.insensitive = insensitive;
  39114. if (!insensitive || content === "I") {
  39115. (0, _util.ensureObject)(node, 'raws');
  39116. node.raws.insensitiveFlag = content;
  39117. }
  39118. lastAdded = 'insensitive';
  39119. if (spaceBefore) {
  39120. (0, _util.ensureObject)(node, 'spaces', 'insensitive');
  39121. node.spaces.insensitive.before = spaceBefore;
  39122. spaceBefore = '';
  39123. }
  39124. if (commentBefore) {
  39125. (0, _util.ensureObject)(node, 'raws', 'spaces', 'insensitive');
  39126. node.raws.spaces.insensitive.before = commentBefore;
  39127. commentBefore = '';
  39128. }
  39129. } else if (node.value || node.value === '') {
  39130. lastAdded = 'value';
  39131. node.value += content;
  39132. if (node.raws.value) {
  39133. node.raws.value += content;
  39134. }
  39135. }
  39136. }
  39137. spaceAfterMeaningfulToken = false;
  39138. break;
  39139. case tokens.str:
  39140. if (!node.attribute || !node.operator) {
  39141. return this.error("Expected an attribute followed by an operator preceding the string.", {
  39142. index: token[_tokenize.FIELDS.START_POS]
  39143. });
  39144. }
  39145. var _unescapeValue = (0, _attribute.unescapeValue)(content),
  39146. unescaped = _unescapeValue.unescaped,
  39147. quoteMark = _unescapeValue.quoteMark;
  39148. node.value = unescaped;
  39149. node.quoteMark = quoteMark;
  39150. lastAdded = 'value';
  39151. (0, _util.ensureObject)(node, 'raws');
  39152. node.raws.value = content;
  39153. spaceAfterMeaningfulToken = false;
  39154. break;
  39155. case tokens.equals:
  39156. if (!node.attribute) {
  39157. return this.expected('attribute', token[_tokenize.FIELDS.START_POS], content);
  39158. }
  39159. if (node.value) {
  39160. return this.error('Unexpected "=" found; an operator was already defined.', {
  39161. index: token[_tokenize.FIELDS.START_POS]
  39162. });
  39163. }
  39164. node.operator = node.operator ? node.operator + content : content;
  39165. lastAdded = 'operator';
  39166. spaceAfterMeaningfulToken = false;
  39167. break;
  39168. case tokens.comment:
  39169. if (lastAdded) {
  39170. if (spaceAfterMeaningfulToken || next && next[_tokenize.FIELDS.TYPE] === tokens.space || lastAdded === 'insensitive') {
  39171. var lastComment = (0, _util.getProp)(node, 'spaces', lastAdded, 'after') || '';
  39172. var rawLastComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;
  39173. (0, _util.ensureObject)(node, 'raws', 'spaces', lastAdded);
  39174. node.raws.spaces[lastAdded].after = rawLastComment + content;
  39175. } else {
  39176. var lastValue = node[lastAdded] || '';
  39177. var rawLastValue = (0, _util.getProp)(node, 'raws', lastAdded) || lastValue;
  39178. (0, _util.ensureObject)(node, 'raws');
  39179. node.raws[lastAdded] = rawLastValue + content;
  39180. }
  39181. } else {
  39182. commentBefore = commentBefore + content;
  39183. }
  39184. break;
  39185. default:
  39186. return this.error("Unexpected \"" + content + "\" found.", {
  39187. index: token[_tokenize.FIELDS.START_POS]
  39188. });
  39189. }
  39190. pos++;
  39191. }
  39192. unescapeProp(node, "attribute");
  39193. unescapeProp(node, "namespace");
  39194. this.newNode(new _attribute["default"](node));
  39195. this.position++;
  39196. }
  39197. /**
  39198. * return a node containing meaningless garbage up to (but not including) the specified token position.
  39199. * if the token position is negative, all remaining tokens are consumed.
  39200. *
  39201. * This returns an array containing a single string node if all whitespace,
  39202. * otherwise an array of comment nodes with space before and after.
  39203. *
  39204. * These tokens are not added to the current selector, the caller can add them or use them to amend
  39205. * a previous node's space metadata.
  39206. *
  39207. * In lossy mode, this returns only comments.
  39208. */;
  39209. _proto.parseWhitespaceEquivalentTokens = function parseWhitespaceEquivalentTokens(stopPosition) {
  39210. if (stopPosition < 0) {
  39211. stopPosition = this.tokens.length;
  39212. }
  39213. var startPosition = this.position;
  39214. var nodes = [];
  39215. var space = "";
  39216. var lastComment = undefined;
  39217. do {
  39218. if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
  39219. if (!this.options.lossy) {
  39220. space += this.content();
  39221. }
  39222. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.comment) {
  39223. var spaces = {};
  39224. if (space) {
  39225. spaces.before = space;
  39226. space = "";
  39227. }
  39228. lastComment = new _comment["default"]({
  39229. value: this.content(),
  39230. source: getTokenSource(this.currToken),
  39231. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  39232. spaces: spaces
  39233. });
  39234. nodes.push(lastComment);
  39235. }
  39236. } while (++this.position < stopPosition);
  39237. if (space) {
  39238. if (lastComment) {
  39239. lastComment.spaces.after = space;
  39240. } else if (!this.options.lossy) {
  39241. var firstToken = this.tokens[startPosition];
  39242. var lastToken = this.tokens[this.position - 1];
  39243. nodes.push(new _string["default"]({
  39244. value: '',
  39245. source: getSource(firstToken[_tokenize.FIELDS.START_LINE], firstToken[_tokenize.FIELDS.START_COL], lastToken[_tokenize.FIELDS.END_LINE], lastToken[_tokenize.FIELDS.END_COL]),
  39246. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  39247. spaces: {
  39248. before: space,
  39249. after: ''
  39250. }
  39251. }));
  39252. }
  39253. }
  39254. return nodes;
  39255. }
  39256. /**
  39257. *
  39258. * @param {*} nodes
  39259. */;
  39260. _proto.convertWhitespaceNodesToSpace = function convertWhitespaceNodesToSpace(nodes, requiredSpace) {
  39261. var _this2 = this;
  39262. if (requiredSpace === void 0) {
  39263. requiredSpace = false;
  39264. }
  39265. var space = "";
  39266. var rawSpace = "";
  39267. nodes.forEach(function (n) {
  39268. var spaceBefore = _this2.lossySpace(n.spaces.before, requiredSpace);
  39269. var rawSpaceBefore = _this2.lossySpace(n.rawSpaceBefore, requiredSpace);
  39270. space += spaceBefore + _this2.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
  39271. rawSpace += spaceBefore + n.value + _this2.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
  39272. });
  39273. if (rawSpace === space) {
  39274. rawSpace = undefined;
  39275. }
  39276. var result = {
  39277. space: space,
  39278. rawSpace: rawSpace
  39279. };
  39280. return result;
  39281. };
  39282. _proto.isNamedCombinator = function isNamedCombinator(position) {
  39283. if (position === void 0) {
  39284. position = this.position;
  39285. }
  39286. 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;
  39287. };
  39288. _proto.namedCombinator = function namedCombinator() {
  39289. if (this.isNamedCombinator()) {
  39290. var nameRaw = this.content(this.tokens[this.position + 1]);
  39291. var name = (0, _util.unesc)(nameRaw).toLowerCase();
  39292. var raws = {};
  39293. if (name !== nameRaw) {
  39294. raws.value = "/" + nameRaw + "/";
  39295. }
  39296. var node = new _combinator["default"]({
  39297. value: "/" + name + "/",
  39298. 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]),
  39299. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  39300. raws: raws
  39301. });
  39302. this.position = this.position + 3;
  39303. return node;
  39304. } else {
  39305. this.unexpected();
  39306. }
  39307. };
  39308. _proto.combinator = function combinator() {
  39309. var _this3 = this;
  39310. if (this.content() === '|') {
  39311. return this.namespace();
  39312. }
  39313. // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
  39314. var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
  39315. if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39316. var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  39317. if (nodes.length > 0) {
  39318. var last = this.current.last;
  39319. if (last) {
  39320. var _this$convertWhitespa = this.convertWhitespaceNodesToSpace(nodes),
  39321. space = _this$convertWhitespa.space,
  39322. rawSpace = _this$convertWhitespa.rawSpace;
  39323. if (rawSpace !== undefined) {
  39324. last.rawSpaceAfter += rawSpace;
  39325. }
  39326. last.spaces.after += space;
  39327. } else {
  39328. nodes.forEach(function (n) {
  39329. return _this3.newNode(n);
  39330. });
  39331. }
  39332. }
  39333. return;
  39334. }
  39335. var firstToken = this.currToken;
  39336. var spaceOrDescendantSelectorNodes = undefined;
  39337. if (nextSigTokenPos > this.position) {
  39338. spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  39339. }
  39340. var node;
  39341. if (this.isNamedCombinator()) {
  39342. node = this.namedCombinator();
  39343. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.combinator) {
  39344. node = new _combinator["default"]({
  39345. value: this.content(),
  39346. source: getTokenSource(this.currToken),
  39347. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS]
  39348. });
  39349. this.position++;
  39350. } else if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) ; else if (!spaceOrDescendantSelectorNodes) {
  39351. this.unexpected();
  39352. }
  39353. if (node) {
  39354. if (spaceOrDescendantSelectorNodes) {
  39355. var _this$convertWhitespa2 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes),
  39356. _space = _this$convertWhitespa2.space,
  39357. _rawSpace = _this$convertWhitespa2.rawSpace;
  39358. node.spaces.before = _space;
  39359. node.rawSpaceBefore = _rawSpace;
  39360. }
  39361. } else {
  39362. // descendant combinator
  39363. var _this$convertWhitespa3 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true),
  39364. _space2 = _this$convertWhitespa3.space,
  39365. _rawSpace2 = _this$convertWhitespa3.rawSpace;
  39366. if (!_rawSpace2) {
  39367. _rawSpace2 = _space2;
  39368. }
  39369. var spaces = {};
  39370. var raws = {
  39371. spaces: {}
  39372. };
  39373. if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
  39374. spaces.before = _space2.slice(0, _space2.length - 1);
  39375. raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
  39376. } else if (_space2.startsWith(' ') && _rawSpace2.startsWith(' ')) {
  39377. spaces.after = _space2.slice(1);
  39378. raws.spaces.after = _rawSpace2.slice(1);
  39379. } else {
  39380. raws.value = _rawSpace2;
  39381. }
  39382. node = new _combinator["default"]({
  39383. value: ' ',
  39384. source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
  39385. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  39386. spaces: spaces,
  39387. raws: raws
  39388. });
  39389. }
  39390. if (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.space) {
  39391. node.spaces.after = this.optionalSpace(this.content());
  39392. this.position++;
  39393. }
  39394. return this.newNode(node);
  39395. };
  39396. _proto.comma = function comma() {
  39397. if (this.position === this.tokens.length - 1) {
  39398. this.root.trailingComma = true;
  39399. this.position++;
  39400. return;
  39401. }
  39402. this.current._inferEndPosition();
  39403. var selector = new _selector["default"]({
  39404. source: {
  39405. start: tokenStart(this.tokens[this.position + 1])
  39406. },
  39407. sourceIndex: this.tokens[this.position + 1][_tokenize.FIELDS.START_POS]
  39408. });
  39409. this.current.parent.append(selector);
  39410. this.current = selector;
  39411. this.position++;
  39412. };
  39413. _proto.comment = function comment() {
  39414. var current = this.currToken;
  39415. this.newNode(new _comment["default"]({
  39416. value: this.content(),
  39417. source: getTokenSource(current),
  39418. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39419. }));
  39420. this.position++;
  39421. };
  39422. _proto.error = function error(message, opts) {
  39423. throw this.root.error(message, opts);
  39424. };
  39425. _proto.missingBackslash = function missingBackslash() {
  39426. return this.error('Expected a backslash preceding the semicolon.', {
  39427. index: this.currToken[_tokenize.FIELDS.START_POS]
  39428. });
  39429. };
  39430. _proto.missingParenthesis = function missingParenthesis() {
  39431. return this.expected('opening parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  39432. };
  39433. _proto.missingSquareBracket = function missingSquareBracket() {
  39434. return this.expected('opening square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  39435. };
  39436. _proto.unexpected = function unexpected() {
  39437. return this.error("Unexpected '" + this.content() + "'. Escaping special characters with \\ may help.", this.currToken[_tokenize.FIELDS.START_POS]);
  39438. };
  39439. _proto.unexpectedPipe = function unexpectedPipe() {
  39440. return this.error("Unexpected '|'.", this.currToken[_tokenize.FIELDS.START_POS]);
  39441. };
  39442. _proto.namespace = function namespace() {
  39443. var before = this.prevToken && this.content(this.prevToken) || true;
  39444. if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  39445. this.position++;
  39446. return this.word(before);
  39447. } else if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.asterisk) {
  39448. this.position++;
  39449. return this.universal(before);
  39450. }
  39451. this.unexpectedPipe();
  39452. };
  39453. _proto.nesting = function nesting() {
  39454. if (this.nextToken) {
  39455. var nextContent = this.content(this.nextToken);
  39456. if (nextContent === "|") {
  39457. this.position++;
  39458. return;
  39459. }
  39460. }
  39461. var current = this.currToken;
  39462. this.newNode(new _nesting["default"]({
  39463. value: this.content(),
  39464. source: getTokenSource(current),
  39465. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39466. }));
  39467. this.position++;
  39468. };
  39469. _proto.parentheses = function parentheses() {
  39470. var last = this.current.last;
  39471. var unbalanced = 1;
  39472. this.position++;
  39473. if (last && last.type === types.PSEUDO) {
  39474. var selector = new _selector["default"]({
  39475. source: {
  39476. start: tokenStart(this.tokens[this.position])
  39477. },
  39478. sourceIndex: this.tokens[this.position][_tokenize.FIELDS.START_POS]
  39479. });
  39480. var cache = this.current;
  39481. last.append(selector);
  39482. this.current = selector;
  39483. while (this.position < this.tokens.length && unbalanced) {
  39484. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39485. unbalanced++;
  39486. }
  39487. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39488. unbalanced--;
  39489. }
  39490. if (unbalanced) {
  39491. this.parse();
  39492. } else {
  39493. this.current.source.end = tokenEnd(this.currToken);
  39494. this.current.parent.source.end = tokenEnd(this.currToken);
  39495. this.position++;
  39496. }
  39497. }
  39498. this.current = cache;
  39499. } else {
  39500. // I think this case should be an error. It's used to implement a basic parse of media queries
  39501. // but I don't think it's a good idea.
  39502. var parenStart = this.currToken;
  39503. var parenValue = "(";
  39504. var parenEnd;
  39505. while (this.position < this.tokens.length && unbalanced) {
  39506. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39507. unbalanced++;
  39508. }
  39509. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39510. unbalanced--;
  39511. }
  39512. parenEnd = this.currToken;
  39513. parenValue += this.parseParenthesisToken(this.currToken);
  39514. this.position++;
  39515. }
  39516. if (last) {
  39517. last.appendToPropertyAndEscape("value", parenValue, parenValue);
  39518. } else {
  39519. this.newNode(new _string["default"]({
  39520. value: parenValue,
  39521. source: getSource(parenStart[_tokenize.FIELDS.START_LINE], parenStart[_tokenize.FIELDS.START_COL], parenEnd[_tokenize.FIELDS.END_LINE], parenEnd[_tokenize.FIELDS.END_COL]),
  39522. sourceIndex: parenStart[_tokenize.FIELDS.START_POS]
  39523. }));
  39524. }
  39525. }
  39526. if (unbalanced) {
  39527. return this.expected('closing parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  39528. }
  39529. };
  39530. _proto.pseudo = function pseudo() {
  39531. var _this4 = this;
  39532. var pseudoStr = '';
  39533. var startingToken = this.currToken;
  39534. while (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.colon) {
  39535. pseudoStr += this.content();
  39536. this.position++;
  39537. }
  39538. if (!this.currToken) {
  39539. return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
  39540. }
  39541. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  39542. this.splitWord(false, function (first, length) {
  39543. pseudoStr += first;
  39544. _this4.newNode(new _pseudo["default"]({
  39545. value: pseudoStr,
  39546. source: getTokenSourceSpan(startingToken, _this4.currToken),
  39547. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  39548. }));
  39549. if (length > 1 && _this4.nextToken && _this4.nextToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39550. _this4.error('Misplaced parenthesis.', {
  39551. index: _this4.nextToken[_tokenize.FIELDS.START_POS]
  39552. });
  39553. }
  39554. });
  39555. } else {
  39556. return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[_tokenize.FIELDS.START_POS]);
  39557. }
  39558. };
  39559. _proto.space = function space() {
  39560. var content = this.content();
  39561. // Handle space before and after the selector
  39562. if (this.position === 0 || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis || this.current.nodes.every(function (node) {
  39563. return node.type === 'comment';
  39564. })) {
  39565. this.spaces = this.optionalSpace(content);
  39566. this.position++;
  39567. } else if (this.position === this.tokens.length - 1 || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39568. this.current.last.spaces.after = this.optionalSpace(content);
  39569. this.position++;
  39570. } else {
  39571. this.combinator();
  39572. }
  39573. };
  39574. _proto.string = function string() {
  39575. var current = this.currToken;
  39576. this.newNode(new _string["default"]({
  39577. value: this.content(),
  39578. source: getTokenSource(current),
  39579. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39580. }));
  39581. this.position++;
  39582. };
  39583. _proto.universal = function universal(namespace) {
  39584. var nextToken = this.nextToken;
  39585. if (nextToken && this.content(nextToken) === '|') {
  39586. this.position++;
  39587. return this.namespace();
  39588. }
  39589. var current = this.currToken;
  39590. this.newNode(new _universal["default"]({
  39591. value: this.content(),
  39592. source: getTokenSource(current),
  39593. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39594. }), namespace);
  39595. this.position++;
  39596. };
  39597. _proto.splitWord = function splitWord(namespace, firstCallback) {
  39598. var _this5 = this;
  39599. var nextToken = this.nextToken;
  39600. var word = this.content();
  39601. while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[_tokenize.FIELDS.TYPE])) {
  39602. this.position++;
  39603. var current = this.content();
  39604. word += current;
  39605. if (current.lastIndexOf('\\') === current.length - 1) {
  39606. var next = this.nextToken;
  39607. if (next && next[_tokenize.FIELDS.TYPE] === tokens.space) {
  39608. word += this.requiredSpace(this.content(next));
  39609. this.position++;
  39610. }
  39611. }
  39612. nextToken = this.nextToken;
  39613. }
  39614. var hasClass = indexesOf(word, '.').filter(function (i) {
  39615. // Allow escaped dot within class name
  39616. var escapedDot = word[i - 1] === '\\';
  39617. // Allow decimal numbers percent in @keyframes
  39618. var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
  39619. return !escapedDot && !isKeyframesPercent;
  39620. });
  39621. var hasId = indexesOf(word, '#').filter(function (i) {
  39622. return word[i - 1] !== '\\';
  39623. });
  39624. // Eliminate Sass interpolations from the list of id indexes
  39625. var interpolations = indexesOf(word, '#{');
  39626. if (interpolations.length) {
  39627. hasId = hasId.filter(function (hashIndex) {
  39628. return !~interpolations.indexOf(hashIndex);
  39629. });
  39630. }
  39631. var indices = (0, _sortAscending["default"])(uniqs([0].concat(hasClass, hasId)));
  39632. indices.forEach(function (ind, i) {
  39633. var index = indices[i + 1] || word.length;
  39634. var value = word.slice(ind, index);
  39635. if (i === 0 && firstCallback) {
  39636. return firstCallback.call(_this5, value, indices.length);
  39637. }
  39638. var node;
  39639. var current = _this5.currToken;
  39640. var sourceIndex = current[_tokenize.FIELDS.START_POS] + indices[i];
  39641. var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
  39642. if (~hasClass.indexOf(ind)) {
  39643. var classNameOpts = {
  39644. value: value.slice(1),
  39645. source: source,
  39646. sourceIndex: sourceIndex
  39647. };
  39648. node = new _className["default"](unescapeProp(classNameOpts, "value"));
  39649. } else if (~hasId.indexOf(ind)) {
  39650. var idOpts = {
  39651. value: value.slice(1),
  39652. source: source,
  39653. sourceIndex: sourceIndex
  39654. };
  39655. node = new _id["default"](unescapeProp(idOpts, "value"));
  39656. } else {
  39657. var tagOpts = {
  39658. value: value,
  39659. source: source,
  39660. sourceIndex: sourceIndex
  39661. };
  39662. unescapeProp(tagOpts, "value");
  39663. node = new _tag["default"](tagOpts);
  39664. }
  39665. _this5.newNode(node, namespace);
  39666. // Ensure that the namespace is used only once
  39667. namespace = null;
  39668. });
  39669. this.position++;
  39670. };
  39671. _proto.word = function word(namespace) {
  39672. var nextToken = this.nextToken;
  39673. if (nextToken && this.content(nextToken) === '|') {
  39674. this.position++;
  39675. return this.namespace();
  39676. }
  39677. return this.splitWord(namespace);
  39678. };
  39679. _proto.loop = function loop() {
  39680. while (this.position < this.tokens.length) {
  39681. this.parse(true);
  39682. }
  39683. this.current._inferEndPosition();
  39684. return this.root;
  39685. };
  39686. _proto.parse = function parse(throwOnParenthesis) {
  39687. switch (this.currToken[_tokenize.FIELDS.TYPE]) {
  39688. case tokens.space:
  39689. this.space();
  39690. break;
  39691. case tokens.comment:
  39692. this.comment();
  39693. break;
  39694. case tokens.openParenthesis:
  39695. this.parentheses();
  39696. break;
  39697. case tokens.closeParenthesis:
  39698. if (throwOnParenthesis) {
  39699. this.missingParenthesis();
  39700. }
  39701. break;
  39702. case tokens.openSquare:
  39703. this.attribute();
  39704. break;
  39705. case tokens.dollar:
  39706. case tokens.caret:
  39707. case tokens.equals:
  39708. case tokens.word:
  39709. this.word();
  39710. break;
  39711. case tokens.colon:
  39712. this.pseudo();
  39713. break;
  39714. case tokens.comma:
  39715. this.comma();
  39716. break;
  39717. case tokens.asterisk:
  39718. this.universal();
  39719. break;
  39720. case tokens.ampersand:
  39721. this.nesting();
  39722. break;
  39723. case tokens.slash:
  39724. case tokens.combinator:
  39725. this.combinator();
  39726. break;
  39727. case tokens.str:
  39728. this.string();
  39729. break;
  39730. // These cases throw; no break needed.
  39731. case tokens.closeSquare:
  39732. this.missingSquareBracket();
  39733. case tokens.semicolon:
  39734. this.missingBackslash();
  39735. default:
  39736. this.unexpected();
  39737. }
  39738. }
  39739. /**
  39740. * Helpers
  39741. */;
  39742. _proto.expected = function expected(description, index, found) {
  39743. if (Array.isArray(description)) {
  39744. var last = description.pop();
  39745. description = description.join(', ') + " or " + last;
  39746. }
  39747. var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
  39748. if (!found) {
  39749. return this.error("Expected " + an + " " + description + ".", {
  39750. index: index
  39751. });
  39752. }
  39753. return this.error("Expected " + an + " " + description + ", found \"" + found + "\" instead.", {
  39754. index: index
  39755. });
  39756. };
  39757. _proto.requiredSpace = function requiredSpace(space) {
  39758. return this.options.lossy ? ' ' : space;
  39759. };
  39760. _proto.optionalSpace = function optionalSpace(space) {
  39761. return this.options.lossy ? '' : space;
  39762. };
  39763. _proto.lossySpace = function lossySpace(space, required) {
  39764. if (this.options.lossy) {
  39765. return required ? ' ' : '';
  39766. } else {
  39767. return space;
  39768. }
  39769. };
  39770. _proto.parseParenthesisToken = function parseParenthesisToken(token) {
  39771. var content = this.content(token);
  39772. if (token[_tokenize.FIELDS.TYPE] === tokens.space) {
  39773. return this.requiredSpace(content);
  39774. } else {
  39775. return content;
  39776. }
  39777. };
  39778. _proto.newNode = function newNode(node, namespace) {
  39779. if (namespace) {
  39780. if (/^ +$/.test(namespace)) {
  39781. if (!this.options.lossy) {
  39782. this.spaces = (this.spaces || '') + namespace;
  39783. }
  39784. namespace = true;
  39785. }
  39786. node.namespace = namespace;
  39787. unescapeProp(node, "namespace");
  39788. }
  39789. if (this.spaces) {
  39790. node.spaces.before = this.spaces;
  39791. this.spaces = '';
  39792. }
  39793. return this.current.append(node);
  39794. };
  39795. _proto.content = function content(token) {
  39796. if (token === void 0) {
  39797. token = this.currToken;
  39798. }
  39799. return this.css.slice(token[_tokenize.FIELDS.START_POS], token[_tokenize.FIELDS.END_POS]);
  39800. };
  39801. /**
  39802. * returns the index of the next non-whitespace, non-comment token.
  39803. * returns -1 if no meaningful token is found.
  39804. */
  39805. _proto.locateNextMeaningfulToken = function locateNextMeaningfulToken(startPosition) {
  39806. if (startPosition === void 0) {
  39807. startPosition = this.position + 1;
  39808. }
  39809. var searchPosition = startPosition;
  39810. while (searchPosition < this.tokens.length) {
  39811. if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][_tokenize.FIELDS.TYPE]]) {
  39812. searchPosition++;
  39813. continue;
  39814. } else {
  39815. return searchPosition;
  39816. }
  39817. }
  39818. return -1;
  39819. };
  39820. _createClass(Parser, [{
  39821. key: "currToken",
  39822. get: function get() {
  39823. return this.tokens[this.position];
  39824. }
  39825. }, {
  39826. key: "nextToken",
  39827. get: function get() {
  39828. return this.tokens[this.position + 1];
  39829. }
  39830. }, {
  39831. key: "prevToken",
  39832. get: function get() {
  39833. return this.tokens[this.position - 1];
  39834. }
  39835. }]);
  39836. return Parser;
  39837. }();
  39838. exports$1["default"] = Parser;
  39839. module.exports = exports$1.default;
  39840. } (parser, parser.exports));
  39841. return parser.exports;
  39842. }
  39843. var hasRequiredProcessor;
  39844. function requireProcessor () {
  39845. if (hasRequiredProcessor) return processor.exports;
  39846. hasRequiredProcessor = 1;
  39847. (function (module, exports$1) {
  39848. exports$1.__esModule = true;
  39849. exports$1["default"] = void 0;
  39850. var _parser = _interopRequireDefault(/*@__PURE__*/ requireParser());
  39851. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39852. var Processor = /*#__PURE__*/function () {
  39853. function Processor(func, options) {
  39854. this.func = func || function noop() {};
  39855. this.funcRes = null;
  39856. this.options = options;
  39857. }
  39858. var _proto = Processor.prototype;
  39859. _proto._shouldUpdateSelector = function _shouldUpdateSelector(rule, options) {
  39860. if (options === void 0) {
  39861. options = {};
  39862. }
  39863. var merged = Object.assign({}, this.options, options);
  39864. if (merged.updateSelector === false) {
  39865. return false;
  39866. } else {
  39867. return typeof rule !== "string";
  39868. }
  39869. };
  39870. _proto._isLossy = function _isLossy(options) {
  39871. if (options === void 0) {
  39872. options = {};
  39873. }
  39874. var merged = Object.assign({}, this.options, options);
  39875. if (merged.lossless === false) {
  39876. return true;
  39877. } else {
  39878. return false;
  39879. }
  39880. };
  39881. _proto._root = function _root(rule, options) {
  39882. if (options === void 0) {
  39883. options = {};
  39884. }
  39885. var parser = new _parser["default"](rule, this._parseOptions(options));
  39886. return parser.root;
  39887. };
  39888. _proto._parseOptions = function _parseOptions(options) {
  39889. return {
  39890. lossy: this._isLossy(options)
  39891. };
  39892. };
  39893. _proto._run = function _run(rule, options) {
  39894. var _this = this;
  39895. if (options === void 0) {
  39896. options = {};
  39897. }
  39898. return new Promise(function (resolve, reject) {
  39899. try {
  39900. var root = _this._root(rule, options);
  39901. Promise.resolve(_this.func(root)).then(function (transform) {
  39902. var string = undefined;
  39903. if (_this._shouldUpdateSelector(rule, options)) {
  39904. string = root.toString();
  39905. rule.selector = string;
  39906. }
  39907. return {
  39908. transform: transform,
  39909. root: root,
  39910. string: string
  39911. };
  39912. }).then(resolve, reject);
  39913. } catch (e) {
  39914. reject(e);
  39915. return;
  39916. }
  39917. });
  39918. };
  39919. _proto._runSync = function _runSync(rule, options) {
  39920. if (options === void 0) {
  39921. options = {};
  39922. }
  39923. var root = this._root(rule, options);
  39924. var transform = this.func(root);
  39925. if (transform && typeof transform.then === "function") {
  39926. throw new Error("Selector processor returned a promise to a synchronous call.");
  39927. }
  39928. var string = undefined;
  39929. if (options.updateSelector && typeof rule !== "string") {
  39930. string = root.toString();
  39931. rule.selector = string;
  39932. }
  39933. return {
  39934. transform: transform,
  39935. root: root,
  39936. string: string
  39937. };
  39938. }
  39939. /**
  39940. * Process rule into a selector AST.
  39941. *
  39942. * @param rule {postcss.Rule | string} The css selector to be processed
  39943. * @param options The options for processing
  39944. * @returns {Promise<parser.Root>} The AST of the selector after processing it.
  39945. */;
  39946. _proto.ast = function ast(rule, options) {
  39947. return this._run(rule, options).then(function (result) {
  39948. return result.root;
  39949. });
  39950. }
  39951. /**
  39952. * Process rule into a selector AST synchronously.
  39953. *
  39954. * @param rule {postcss.Rule | string} The css selector to be processed
  39955. * @param options The options for processing
  39956. * @returns {parser.Root} The AST of the selector after processing it.
  39957. */;
  39958. _proto.astSync = function astSync(rule, options) {
  39959. return this._runSync(rule, options).root;
  39960. }
  39961. /**
  39962. * Process a selector into a transformed value asynchronously
  39963. *
  39964. * @param rule {postcss.Rule | string} The css selector to be processed
  39965. * @param options The options for processing
  39966. * @returns {Promise<any>} The value returned by the processor.
  39967. */;
  39968. _proto.transform = function transform(rule, options) {
  39969. return this._run(rule, options).then(function (result) {
  39970. return result.transform;
  39971. });
  39972. }
  39973. /**
  39974. * Process a selector into a transformed value synchronously.
  39975. *
  39976. * @param rule {postcss.Rule | string} The css selector to be processed
  39977. * @param options The options for processing
  39978. * @returns {any} The value returned by the processor.
  39979. */;
  39980. _proto.transformSync = function transformSync(rule, options) {
  39981. return this._runSync(rule, options).transform;
  39982. }
  39983. /**
  39984. * Process a selector into a new selector string asynchronously.
  39985. *
  39986. * @param rule {postcss.Rule | string} The css selector to be processed
  39987. * @param options The options for processing
  39988. * @returns {string} the selector after processing.
  39989. */;
  39990. _proto.process = function process(rule, options) {
  39991. return this._run(rule, options).then(function (result) {
  39992. return result.string || result.root.toString();
  39993. });
  39994. }
  39995. /**
  39996. * Process a selector into a new selector string synchronously.
  39997. *
  39998. * @param rule {postcss.Rule | string} The css selector to be processed
  39999. * @param options The options for processing
  40000. * @returns {string} the selector after processing.
  40001. */;
  40002. _proto.processSync = function processSync(rule, options) {
  40003. var result = this._runSync(rule, options);
  40004. return result.string || result.root.toString();
  40005. };
  40006. return Processor;
  40007. }();
  40008. exports$1["default"] = Processor;
  40009. module.exports = exports$1.default;
  40010. } (processor, processor.exports));
  40011. return processor.exports;
  40012. }
  40013. var selectors = {};
  40014. var constructors = {};
  40015. var hasRequiredConstructors;
  40016. function requireConstructors () {
  40017. if (hasRequiredConstructors) return constructors;
  40018. hasRequiredConstructors = 1;
  40019. constructors.__esModule = true;
  40020. 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;
  40021. var _attribute = _interopRequireDefault(/*@__PURE__*/ requireAttribute());
  40022. var _className = _interopRequireDefault(/*@__PURE__*/ requireClassName());
  40023. var _combinator = _interopRequireDefault(/*@__PURE__*/ requireCombinator());
  40024. var _comment = _interopRequireDefault(/*@__PURE__*/ requireComment());
  40025. var _id = _interopRequireDefault(/*@__PURE__*/ requireId());
  40026. var _nesting = _interopRequireDefault(/*@__PURE__*/ requireNesting());
  40027. var _pseudo = _interopRequireDefault(/*@__PURE__*/ requirePseudo());
  40028. var _root = _interopRequireDefault(/*@__PURE__*/ requireRoot());
  40029. var _selector = _interopRequireDefault(/*@__PURE__*/ requireSelector());
  40030. var _string = _interopRequireDefault(/*@__PURE__*/ requireString());
  40031. var _tag = _interopRequireDefault(/*@__PURE__*/ requireTag());
  40032. var _universal = _interopRequireDefault(/*@__PURE__*/ requireUniversal());
  40033. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  40034. var attribute = function attribute(opts) {
  40035. return new _attribute["default"](opts);
  40036. };
  40037. constructors.attribute = attribute;
  40038. var className = function className(opts) {
  40039. return new _className["default"](opts);
  40040. };
  40041. constructors.className = className;
  40042. var combinator = function combinator(opts) {
  40043. return new _combinator["default"](opts);
  40044. };
  40045. constructors.combinator = combinator;
  40046. var comment = function comment(opts) {
  40047. return new _comment["default"](opts);
  40048. };
  40049. constructors.comment = comment;
  40050. var id = function id(opts) {
  40051. return new _id["default"](opts);
  40052. };
  40053. constructors.id = id;
  40054. var nesting = function nesting(opts) {
  40055. return new _nesting["default"](opts);
  40056. };
  40057. constructors.nesting = nesting;
  40058. var pseudo = function pseudo(opts) {
  40059. return new _pseudo["default"](opts);
  40060. };
  40061. constructors.pseudo = pseudo;
  40062. var root = function root(opts) {
  40063. return new _root["default"](opts);
  40064. };
  40065. constructors.root = root;
  40066. var selector = function selector(opts) {
  40067. return new _selector["default"](opts);
  40068. };
  40069. constructors.selector = selector;
  40070. var string = function string(opts) {
  40071. return new _string["default"](opts);
  40072. };
  40073. constructors.string = string;
  40074. var tag = function tag(opts) {
  40075. return new _tag["default"](opts);
  40076. };
  40077. constructors.tag = tag;
  40078. var universal = function universal(opts) {
  40079. return new _universal["default"](opts);
  40080. };
  40081. constructors.universal = universal;
  40082. return constructors;
  40083. }
  40084. var guards = {};
  40085. var hasRequiredGuards;
  40086. function requireGuards () {
  40087. if (hasRequiredGuards) return guards;
  40088. hasRequiredGuards = 1;
  40089. guards.__esModule = true;
  40090. guards.isComment = guards.isCombinator = guards.isClassName = guards.isAttribute = void 0;
  40091. guards.isContainer = isContainer;
  40092. guards.isIdentifier = void 0;
  40093. guards.isNamespace = isNamespace;
  40094. guards.isNesting = void 0;
  40095. guards.isNode = isNode;
  40096. guards.isPseudo = void 0;
  40097. guards.isPseudoClass = isPseudoClass;
  40098. guards.isPseudoElement = isPseudoElement;
  40099. guards.isUniversal = guards.isTag = guards.isString = guards.isSelector = guards.isRoot = void 0;
  40100. var _types = /*@__PURE__*/ requireTypes();
  40101. var _IS_TYPE;
  40102. 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);
  40103. function isNode(node) {
  40104. return typeof node === "object" && IS_TYPE[node.type];
  40105. }
  40106. function isNodeType(type, node) {
  40107. return isNode(node) && node.type === type;
  40108. }
  40109. var isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
  40110. guards.isAttribute = isAttribute;
  40111. var isClassName = isNodeType.bind(null, _types.CLASS);
  40112. guards.isClassName = isClassName;
  40113. var isCombinator = isNodeType.bind(null, _types.COMBINATOR);
  40114. guards.isCombinator = isCombinator;
  40115. var isComment = isNodeType.bind(null, _types.COMMENT);
  40116. guards.isComment = isComment;
  40117. var isIdentifier = isNodeType.bind(null, _types.ID);
  40118. guards.isIdentifier = isIdentifier;
  40119. var isNesting = isNodeType.bind(null, _types.NESTING);
  40120. guards.isNesting = isNesting;
  40121. var isPseudo = isNodeType.bind(null, _types.PSEUDO);
  40122. guards.isPseudo = isPseudo;
  40123. var isRoot = isNodeType.bind(null, _types.ROOT);
  40124. guards.isRoot = isRoot;
  40125. var isSelector = isNodeType.bind(null, _types.SELECTOR);
  40126. guards.isSelector = isSelector;
  40127. var isString = isNodeType.bind(null, _types.STRING);
  40128. guards.isString = isString;
  40129. var isTag = isNodeType.bind(null, _types.TAG);
  40130. guards.isTag = isTag;
  40131. var isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
  40132. guards.isUniversal = isUniversal;
  40133. function isPseudoElement(node) {
  40134. 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");
  40135. }
  40136. function isPseudoClass(node) {
  40137. return isPseudo(node) && !isPseudoElement(node);
  40138. }
  40139. function isContainer(node) {
  40140. return !!(isNode(node) && node.walk);
  40141. }
  40142. function isNamespace(node) {
  40143. return isAttribute(node) || isTag(node);
  40144. }
  40145. return guards;
  40146. }
  40147. var hasRequiredSelectors;
  40148. function requireSelectors () {
  40149. if (hasRequiredSelectors) return selectors;
  40150. hasRequiredSelectors = 1;
  40151. (function (exports$1) {
  40152. exports$1.__esModule = true;
  40153. var _types = /*@__PURE__*/ requireTypes();
  40154. Object.keys(_types).forEach(function (key) {
  40155. if (key === "default" || key === "__esModule") return;
  40156. if (key in exports$1 && exports$1[key] === _types[key]) return;
  40157. exports$1[key] = _types[key];
  40158. });
  40159. var _constructors = /*@__PURE__*/ requireConstructors();
  40160. Object.keys(_constructors).forEach(function (key) {
  40161. if (key === "default" || key === "__esModule") return;
  40162. if (key in exports$1 && exports$1[key] === _constructors[key]) return;
  40163. exports$1[key] = _constructors[key];
  40164. });
  40165. var _guards = /*@__PURE__*/ requireGuards();
  40166. Object.keys(_guards).forEach(function (key) {
  40167. if (key === "default" || key === "__esModule") return;
  40168. if (key in exports$1 && exports$1[key] === _guards[key]) return;
  40169. exports$1[key] = _guards[key];
  40170. });
  40171. } (selectors));
  40172. return selectors;
  40173. }
  40174. var hasRequiredDist;
  40175. function requireDist () {
  40176. if (hasRequiredDist) return dist.exports;
  40177. hasRequiredDist = 1;
  40178. (function (module, exports$1) {
  40179. exports$1.__esModule = true;
  40180. exports$1["default"] = void 0;
  40181. var _processor = _interopRequireDefault(/*@__PURE__*/ requireProcessor());
  40182. var selectors = _interopRequireWildcard(/*@__PURE__*/ requireSelectors());
  40183. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  40184. function _interopRequireWildcard(obj, nodeInterop) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
  40185. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  40186. var parser = function parser(processor) {
  40187. return new _processor["default"](processor);
  40188. };
  40189. Object.assign(parser, selectors);
  40190. delete parser.__esModule;
  40191. var _default = parser;
  40192. exports$1["default"] = _default;
  40193. module.exports = exports$1.default;
  40194. } (dist, dist.exports));
  40195. return dist.exports;
  40196. }
  40197. var distExports = /*@__PURE__*/ requireDist();
  40198. var selectorParser = /*@__PURE__*/getDefaultExportFromCjs(distExports);
  40199. const animationNameRE = /^(?:-\w+-)?animation-name$/;
  40200. const animationRE = /^(?:-\w+-)?animation$/;
  40201. const keyframesRE = /^(?:-\w+-)?keyframes$/;
  40202. const scopedPlugin = (id = "") => {
  40203. const keyframes = /* @__PURE__ */ Object.create(null);
  40204. const shortId = id.replace(/^data-v-/, "");
  40205. return {
  40206. postcssPlugin: "vue-sfc-scoped",
  40207. Rule(rule) {
  40208. processRule(id, rule);
  40209. },
  40210. AtRule(node) {
  40211. if (keyframesRE.test(node.name) && !node.params.endsWith(`-${shortId}`)) {
  40212. keyframes[node.params] = node.params = node.params + "-" + shortId;
  40213. }
  40214. },
  40215. OnceExit(root) {
  40216. if (Object.keys(keyframes).length) {
  40217. root.walkDecls((decl) => {
  40218. if (animationNameRE.test(decl.prop)) {
  40219. decl.value = decl.value.split(",").map((v) => keyframes[v.trim()] || v.trim()).join(",");
  40220. }
  40221. if (animationRE.test(decl.prop)) {
  40222. decl.value = decl.value.split(",").map((v) => {
  40223. const vals = v.trim().split(/\s+/);
  40224. const i = vals.findIndex((val) => keyframes[val]);
  40225. if (i !== -1) {
  40226. vals.splice(i, 1, keyframes[vals[i]]);
  40227. return vals.join(" ");
  40228. } else {
  40229. return v;
  40230. }
  40231. }).join(",");
  40232. }
  40233. });
  40234. }
  40235. }
  40236. };
  40237. };
  40238. const processedRules = /* @__PURE__ */ new WeakSet();
  40239. function processRule(id, rule) {
  40240. if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" && keyframesRE.test(rule.parent.name)) {
  40241. return;
  40242. }
  40243. processedRules.add(rule);
  40244. let deep = false;
  40245. let parent = rule.parent;
  40246. while (parent && parent.type !== "root") {
  40247. if (parent.__deep) {
  40248. deep = true;
  40249. break;
  40250. }
  40251. parent = parent.parent;
  40252. }
  40253. rule.selector = selectorParser((selectorRoot) => {
  40254. selectorRoot.each((selector) => {
  40255. rewriteSelector(id, rule, selector, selectorRoot, deep);
  40256. });
  40257. }).processSync(rule.selector);
  40258. }
  40259. function rewriteSelector(id, rule, selector, selectorRoot, deep, slotted = false) {
  40260. let node = null;
  40261. let shouldInject = !deep;
  40262. selector.each((n) => {
  40263. if (n.type === "combinator" && (n.value === ">>>" || n.value === "/deep/")) {
  40264. n.value = " ";
  40265. n.spaces.before = n.spaces.after = "";
  40266. warn(
  40267. `the >>> and /deep/ combinators have been deprecated. Use :deep() instead.`
  40268. );
  40269. return false;
  40270. }
  40271. if (n.type === "pseudo") {
  40272. const { value } = n;
  40273. if (value === ":deep" || value === "::v-deep") {
  40274. rule.__deep = true;
  40275. if (n.nodes.length) {
  40276. let last = n;
  40277. n.nodes[0].each((ss) => {
  40278. selector.insertAfter(last, ss);
  40279. last = ss;
  40280. });
  40281. const prev = selector.at(selector.index(n) - 1);
  40282. if (!prev || !isSpaceCombinator(prev)) {
  40283. selector.insertAfter(
  40284. n,
  40285. selectorParser.combinator({
  40286. value: " "
  40287. })
  40288. );
  40289. }
  40290. selector.removeChild(n);
  40291. } else {
  40292. warn(
  40293. `${value} usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead of ${value} <inner-selector>.`
  40294. );
  40295. const prev = selector.at(selector.index(n) - 1);
  40296. if (prev && isSpaceCombinator(prev)) {
  40297. selector.removeChild(prev);
  40298. }
  40299. selector.removeChild(n);
  40300. }
  40301. return false;
  40302. }
  40303. if (value === ":slotted" || value === "::v-slotted") {
  40304. rewriteSelector(
  40305. id,
  40306. rule,
  40307. n.nodes[0],
  40308. selectorRoot,
  40309. deep,
  40310. true
  40311. );
  40312. let last = n;
  40313. n.nodes[0].each((ss) => {
  40314. selector.insertAfter(last, ss);
  40315. last = ss;
  40316. });
  40317. selector.removeChild(n);
  40318. shouldInject = false;
  40319. return false;
  40320. }
  40321. if (value === ":global" || value === "::v-global") {
  40322. selector.replaceWith(n.nodes[0]);
  40323. return false;
  40324. }
  40325. }
  40326. if (n.type === "universal") {
  40327. const prev = selector.at(selector.index(n) - 1);
  40328. const next = selector.at(selector.index(n) + 1);
  40329. if (!prev) {
  40330. if (next) {
  40331. if (next.type === "combinator" && next.value === " ") {
  40332. selector.removeChild(next);
  40333. }
  40334. selector.removeChild(n);
  40335. return;
  40336. } else {
  40337. node = selectorParser.combinator({
  40338. value: ""
  40339. });
  40340. selector.insertBefore(n, node);
  40341. selector.removeChild(n);
  40342. return false;
  40343. }
  40344. }
  40345. if (node) return;
  40346. }
  40347. if (n.type !== "pseudo" && n.type !== "combinator" || n.type === "pseudo" && (n.value === ":is" || n.value === ":where") && !node) {
  40348. node = n;
  40349. }
  40350. });
  40351. if (rule.nodes.some((node2) => node2.type === "rule")) {
  40352. const deep2 = rule.__deep;
  40353. if (!deep2) {
  40354. extractAndWrapNodes(rule);
  40355. const atruleNodes = rule.nodes.filter((node2) => node2.type === "atrule");
  40356. for (const atnode of atruleNodes) {
  40357. extractAndWrapNodes(atnode);
  40358. }
  40359. }
  40360. shouldInject = deep2;
  40361. }
  40362. if (node) {
  40363. const { type, value } = node;
  40364. if (type === "pseudo" && (value === ":is" || value === ":where")) {
  40365. node.nodes.forEach(
  40366. (value2) => rewriteSelector(id, rule, value2, selectorRoot, deep, slotted)
  40367. );
  40368. shouldInject = false;
  40369. }
  40370. }
  40371. if (node) {
  40372. node.spaces.after = "";
  40373. } else {
  40374. selector.first.spaces.before = "";
  40375. }
  40376. if (shouldInject) {
  40377. const idToAdd = slotted ? id + "-s" : id;
  40378. selector.insertAfter(
  40379. // If node is null it means we need to inject [id] at the start
  40380. // insertAfter can handle `null` here
  40381. node,
  40382. selectorParser.attribute({
  40383. attribute: idToAdd,
  40384. value: idToAdd,
  40385. raws: {},
  40386. quoteMark: `"`
  40387. })
  40388. );
  40389. }
  40390. }
  40391. function isSpaceCombinator(node) {
  40392. return node.type === "combinator" && /^\s+$/.test(node.value);
  40393. }
  40394. function extractAndWrapNodes(parentNode) {
  40395. if (!parentNode.nodes) return;
  40396. const nodes = parentNode.nodes.filter(
  40397. (node) => node.type === "decl" || node.type === "comment"
  40398. );
  40399. if (nodes.length) {
  40400. for (const node of nodes) {
  40401. parentNode.removeChild(node);
  40402. }
  40403. const wrappedRule = new Rule({
  40404. nodes,
  40405. selector: "&"
  40406. });
  40407. parentNode.prepend(wrappedRule);
  40408. }
  40409. }
  40410. scopedPlugin.postcss = true;
  40411. var sourceMap = {};
  40412. var sourceMapGenerator = {};
  40413. var base64Vlq = {};
  40414. var base64 = {};
  40415. /* -*- Mode: js; js-indent-level: 2; -*- */
  40416. var hasRequiredBase64;
  40417. function requireBase64 () {
  40418. if (hasRequiredBase64) return base64;
  40419. hasRequiredBase64 = 1;
  40420. /*
  40421. * Copyright 2011 Mozilla Foundation and contributors
  40422. * Licensed under the New BSD license. See LICENSE or:
  40423. * http://opensource.org/licenses/BSD-3-Clause
  40424. */
  40425. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  40426. /**
  40427. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  40428. */
  40429. base64.encode = function (number) {
  40430. if (0 <= number && number < intToCharMap.length) {
  40431. return intToCharMap[number];
  40432. }
  40433. throw new TypeError("Must be between 0 and 63: " + number);
  40434. };
  40435. /**
  40436. * Decode a single base 64 character code digit to an integer. Returns -1 on
  40437. * failure.
  40438. */
  40439. base64.decode = function (charCode) {
  40440. var bigA = 65; // 'A'
  40441. var bigZ = 90; // 'Z'
  40442. var littleA = 97; // 'a'
  40443. var littleZ = 122; // 'z'
  40444. var zero = 48; // '0'
  40445. var nine = 57; // '9'
  40446. var plus = 43; // '+'
  40447. var slash = 47; // '/'
  40448. var littleOffset = 26;
  40449. var numberOffset = 52;
  40450. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  40451. if (bigA <= charCode && charCode <= bigZ) {
  40452. return (charCode - bigA);
  40453. }
  40454. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  40455. if (littleA <= charCode && charCode <= littleZ) {
  40456. return (charCode - littleA + littleOffset);
  40457. }
  40458. // 52 - 61: 0123456789
  40459. if (zero <= charCode && charCode <= nine) {
  40460. return (charCode - zero + numberOffset);
  40461. }
  40462. // 62: +
  40463. if (charCode == plus) {
  40464. return 62;
  40465. }
  40466. // 63: /
  40467. if (charCode == slash) {
  40468. return 63;
  40469. }
  40470. // Invalid base64 digit.
  40471. return -1;
  40472. };
  40473. return base64;
  40474. }
  40475. /* -*- Mode: js; js-indent-level: 2; -*- */
  40476. var hasRequiredBase64Vlq;
  40477. function requireBase64Vlq () {
  40478. if (hasRequiredBase64Vlq) return base64Vlq;
  40479. hasRequiredBase64Vlq = 1;
  40480. /*
  40481. * Copyright 2011 Mozilla Foundation and contributors
  40482. * Licensed under the New BSD license. See LICENSE or:
  40483. * http://opensource.org/licenses/BSD-3-Clause
  40484. *
  40485. * Based on the Base 64 VLQ implementation in Closure Compiler:
  40486. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  40487. *
  40488. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  40489. * Redistribution and use in source and binary forms, with or without
  40490. * modification, are permitted provided that the following conditions are
  40491. * met:
  40492. *
  40493. * * Redistributions of source code must retain the above copyright
  40494. * notice, this list of conditions and the following disclaimer.
  40495. * * Redistributions in binary form must reproduce the above
  40496. * copyright notice, this list of conditions and the following
  40497. * disclaimer in the documentation and/or other materials provided
  40498. * with the distribution.
  40499. * * Neither the name of Google Inc. nor the names of its
  40500. * contributors may be used to endorse or promote products derived
  40501. * from this software without specific prior written permission.
  40502. *
  40503. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  40504. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40505. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  40506. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40507. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40508. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40509. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  40510. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  40511. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40512. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  40513. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40514. */
  40515. var base64 = /*@__PURE__*/ requireBase64();
  40516. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  40517. // length quantities we use in the source map spec, the first bit is the sign,
  40518. // the next four bits are the actual value, and the 6th bit is the
  40519. // continuation bit. The continuation bit tells us whether there are more
  40520. // digits in this value following this digit.
  40521. //
  40522. // Continuation
  40523. // | Sign
  40524. // | |
  40525. // V V
  40526. // 101011
  40527. var VLQ_BASE_SHIFT = 5;
  40528. // binary: 100000
  40529. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  40530. // binary: 011111
  40531. var VLQ_BASE_MASK = VLQ_BASE - 1;
  40532. // binary: 100000
  40533. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  40534. /**
  40535. * Converts from a two-complement value to a value where the sign bit is
  40536. * placed in the least significant bit. For example, as decimals:
  40537. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  40538. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  40539. */
  40540. function toVLQSigned(aValue) {
  40541. return aValue < 0
  40542. ? ((-aValue) << 1) + 1
  40543. : (aValue << 1) + 0;
  40544. }
  40545. /**
  40546. * Converts to a two-complement value from a value where the sign bit is
  40547. * placed in the least significant bit. For example, as decimals:
  40548. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  40549. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  40550. */
  40551. function fromVLQSigned(aValue) {
  40552. var isNegative = (aValue & 1) === 1;
  40553. var shifted = aValue >> 1;
  40554. return isNegative
  40555. ? -shifted
  40556. : shifted;
  40557. }
  40558. /**
  40559. * Returns the base 64 VLQ encoded value.
  40560. */
  40561. base64Vlq.encode = function base64VLQ_encode(aValue) {
  40562. var encoded = "";
  40563. var digit;
  40564. var vlq = toVLQSigned(aValue);
  40565. do {
  40566. digit = vlq & VLQ_BASE_MASK;
  40567. vlq >>>= VLQ_BASE_SHIFT;
  40568. if (vlq > 0) {
  40569. // There are still more digits in this value, so we must make sure the
  40570. // continuation bit is marked.
  40571. digit |= VLQ_CONTINUATION_BIT;
  40572. }
  40573. encoded += base64.encode(digit);
  40574. } while (vlq > 0);
  40575. return encoded;
  40576. };
  40577. /**
  40578. * Decodes the next base 64 VLQ value from the given string and returns the
  40579. * value and the rest of the string via the out parameter.
  40580. */
  40581. base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  40582. var strLen = aStr.length;
  40583. var result = 0;
  40584. var shift = 0;
  40585. var continuation, digit;
  40586. do {
  40587. if (aIndex >= strLen) {
  40588. throw new Error("Expected more digits in base 64 VLQ value.");
  40589. }
  40590. digit = base64.decode(aStr.charCodeAt(aIndex++));
  40591. if (digit === -1) {
  40592. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  40593. }
  40594. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  40595. digit &= VLQ_BASE_MASK;
  40596. result = result + (digit << shift);
  40597. shift += VLQ_BASE_SHIFT;
  40598. } while (continuation);
  40599. aOutParam.value = fromVLQSigned(result);
  40600. aOutParam.rest = aIndex;
  40601. };
  40602. return base64Vlq;
  40603. }
  40604. var util = {};
  40605. /* -*- Mode: js; js-indent-level: 2; -*- */
  40606. var hasRequiredUtil;
  40607. function requireUtil () {
  40608. if (hasRequiredUtil) return util;
  40609. hasRequiredUtil = 1;
  40610. (function (exports$1) {
  40611. /*
  40612. * Copyright 2011 Mozilla Foundation and contributors
  40613. * Licensed under the New BSD license. See LICENSE or:
  40614. * http://opensource.org/licenses/BSD-3-Clause
  40615. */
  40616. /**
  40617. * This is a helper function for getting values from parameter/options
  40618. * objects.
  40619. *
  40620. * @param args The object we are extracting values from
  40621. * @param name The name of the property we are getting.
  40622. * @param defaultValue An optional value to return if the property is missing
  40623. * from the object. If this is not specified and the property is missing, an
  40624. * error will be thrown.
  40625. */
  40626. function getArg(aArgs, aName, aDefaultValue) {
  40627. if (aName in aArgs) {
  40628. return aArgs[aName];
  40629. } else if (arguments.length === 3) {
  40630. return aDefaultValue;
  40631. } else {
  40632. throw new Error('"' + aName + '" is a required argument.');
  40633. }
  40634. }
  40635. exports$1.getArg = getArg;
  40636. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  40637. var dataUrlRegexp = /^data:.+\,.+$/;
  40638. function urlParse(aUrl) {
  40639. var match = aUrl.match(urlRegexp);
  40640. if (!match) {
  40641. return null;
  40642. }
  40643. return {
  40644. scheme: match[1],
  40645. auth: match[2],
  40646. host: match[3],
  40647. port: match[4],
  40648. path: match[5]
  40649. };
  40650. }
  40651. exports$1.urlParse = urlParse;
  40652. function urlGenerate(aParsedUrl) {
  40653. var url = '';
  40654. if (aParsedUrl.scheme) {
  40655. url += aParsedUrl.scheme + ':';
  40656. }
  40657. url += '//';
  40658. if (aParsedUrl.auth) {
  40659. url += aParsedUrl.auth + '@';
  40660. }
  40661. if (aParsedUrl.host) {
  40662. url += aParsedUrl.host;
  40663. }
  40664. if (aParsedUrl.port) {
  40665. url += ":" + aParsedUrl.port;
  40666. }
  40667. if (aParsedUrl.path) {
  40668. url += aParsedUrl.path;
  40669. }
  40670. return url;
  40671. }
  40672. exports$1.urlGenerate = urlGenerate;
  40673. /**
  40674. * Normalizes a path, or the path portion of a URL:
  40675. *
  40676. * - Replaces consecutive slashes with one slash.
  40677. * - Removes unnecessary '.' parts.
  40678. * - Removes unnecessary '<dir>/..' parts.
  40679. *
  40680. * Based on code in the Node.js 'path' core module.
  40681. *
  40682. * @param aPath The path or url to normalize.
  40683. */
  40684. function normalize(aPath) {
  40685. var path = aPath;
  40686. var url = urlParse(aPath);
  40687. if (url) {
  40688. if (!url.path) {
  40689. return aPath;
  40690. }
  40691. path = url.path;
  40692. }
  40693. var isAbsolute = exports$1.isAbsolute(path);
  40694. var parts = path.split(/\/+/);
  40695. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  40696. part = parts[i];
  40697. if (part === '.') {
  40698. parts.splice(i, 1);
  40699. } else if (part === '..') {
  40700. up++;
  40701. } else if (up > 0) {
  40702. if (part === '') {
  40703. // The first part is blank if the path is absolute. Trying to go
  40704. // above the root is a no-op. Therefore we can remove all '..' parts
  40705. // directly after the root.
  40706. parts.splice(i + 1, up);
  40707. up = 0;
  40708. } else {
  40709. parts.splice(i, 2);
  40710. up--;
  40711. }
  40712. }
  40713. }
  40714. path = parts.join('/');
  40715. if (path === '') {
  40716. path = isAbsolute ? '/' : '.';
  40717. }
  40718. if (url) {
  40719. url.path = path;
  40720. return urlGenerate(url);
  40721. }
  40722. return path;
  40723. }
  40724. exports$1.normalize = normalize;
  40725. /**
  40726. * Joins two paths/URLs.
  40727. *
  40728. * @param aRoot The root path or URL.
  40729. * @param aPath The path or URL to be joined with the root.
  40730. *
  40731. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  40732. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  40733. * first.
  40734. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  40735. * is updated with the result and aRoot is returned. Otherwise the result
  40736. * is returned.
  40737. * - If aPath is absolute, the result is aPath.
  40738. * - Otherwise the two paths are joined with a slash.
  40739. * - Joining for example 'http://' and 'www.example.com' is also supported.
  40740. */
  40741. function join(aRoot, aPath) {
  40742. if (aRoot === "") {
  40743. aRoot = ".";
  40744. }
  40745. if (aPath === "") {
  40746. aPath = ".";
  40747. }
  40748. var aPathUrl = urlParse(aPath);
  40749. var aRootUrl = urlParse(aRoot);
  40750. if (aRootUrl) {
  40751. aRoot = aRootUrl.path || '/';
  40752. }
  40753. // `join(foo, '//www.example.org')`
  40754. if (aPathUrl && !aPathUrl.scheme) {
  40755. if (aRootUrl) {
  40756. aPathUrl.scheme = aRootUrl.scheme;
  40757. }
  40758. return urlGenerate(aPathUrl);
  40759. }
  40760. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  40761. return aPath;
  40762. }
  40763. // `join('http://', 'www.example.com')`
  40764. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  40765. aRootUrl.host = aPath;
  40766. return urlGenerate(aRootUrl);
  40767. }
  40768. var joined = aPath.charAt(0) === '/'
  40769. ? aPath
  40770. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  40771. if (aRootUrl) {
  40772. aRootUrl.path = joined;
  40773. return urlGenerate(aRootUrl);
  40774. }
  40775. return joined;
  40776. }
  40777. exports$1.join = join;
  40778. exports$1.isAbsolute = function (aPath) {
  40779. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  40780. };
  40781. /**
  40782. * Make a path relative to a URL or another path.
  40783. *
  40784. * @param aRoot The root path or URL.
  40785. * @param aPath The path or URL to be made relative to aRoot.
  40786. */
  40787. function relative(aRoot, aPath) {
  40788. if (aRoot === "") {
  40789. aRoot = ".";
  40790. }
  40791. aRoot = aRoot.replace(/\/$/, '');
  40792. // It is possible for the path to be above the root. In this case, simply
  40793. // checking whether the root is a prefix of the path won't work. Instead, we
  40794. // need to remove components from the root one by one, until either we find
  40795. // a prefix that fits, or we run out of components to remove.
  40796. var level = 0;
  40797. while (aPath.indexOf(aRoot + '/') !== 0) {
  40798. var index = aRoot.lastIndexOf("/");
  40799. if (index < 0) {
  40800. return aPath;
  40801. }
  40802. // If the only part of the root that is left is the scheme (i.e. http://,
  40803. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  40804. // have exhausted all components, so the path is not relative to the root.
  40805. aRoot = aRoot.slice(0, index);
  40806. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  40807. return aPath;
  40808. }
  40809. ++level;
  40810. }
  40811. // Make sure we add a "../" for each component we removed from the root.
  40812. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  40813. }
  40814. exports$1.relative = relative;
  40815. var supportsNullProto = (function () {
  40816. var obj = Object.create(null);
  40817. return !('__proto__' in obj);
  40818. }());
  40819. function identity (s) {
  40820. return s;
  40821. }
  40822. /**
  40823. * Because behavior goes wacky when you set `__proto__` on objects, we
  40824. * have to prefix all the strings in our set with an arbitrary character.
  40825. *
  40826. * See https://github.com/mozilla/source-map/pull/31 and
  40827. * https://github.com/mozilla/source-map/issues/30
  40828. *
  40829. * @param String aStr
  40830. */
  40831. function toSetString(aStr) {
  40832. if (isProtoString(aStr)) {
  40833. return '$' + aStr;
  40834. }
  40835. return aStr;
  40836. }
  40837. exports$1.toSetString = supportsNullProto ? identity : toSetString;
  40838. function fromSetString(aStr) {
  40839. if (isProtoString(aStr)) {
  40840. return aStr.slice(1);
  40841. }
  40842. return aStr;
  40843. }
  40844. exports$1.fromSetString = supportsNullProto ? identity : fromSetString;
  40845. function isProtoString(s) {
  40846. if (!s) {
  40847. return false;
  40848. }
  40849. var length = s.length;
  40850. if (length < 9 /* "__proto__".length */) {
  40851. return false;
  40852. }
  40853. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  40854. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  40855. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  40856. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  40857. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  40858. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  40859. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  40860. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  40861. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  40862. return false;
  40863. }
  40864. for (var i = length - 10; i >= 0; i--) {
  40865. if (s.charCodeAt(i) !== 36 /* '$' */) {
  40866. return false;
  40867. }
  40868. }
  40869. return true;
  40870. }
  40871. /**
  40872. * Comparator between two mappings where the original positions are compared.
  40873. *
  40874. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40875. * mappings with the same original source/line/column, but different generated
  40876. * line and column the same. Useful when searching for a mapping with a
  40877. * stubbed out mapping.
  40878. */
  40879. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  40880. var cmp = strcmp(mappingA.source, mappingB.source);
  40881. if (cmp !== 0) {
  40882. return cmp;
  40883. }
  40884. cmp = mappingA.originalLine - mappingB.originalLine;
  40885. if (cmp !== 0) {
  40886. return cmp;
  40887. }
  40888. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40889. if (cmp !== 0 || onlyCompareOriginal) {
  40890. return cmp;
  40891. }
  40892. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40893. if (cmp !== 0) {
  40894. return cmp;
  40895. }
  40896. cmp = mappingA.generatedLine - mappingB.generatedLine;
  40897. if (cmp !== 0) {
  40898. return cmp;
  40899. }
  40900. return strcmp(mappingA.name, mappingB.name);
  40901. }
  40902. exports$1.compareByOriginalPositions = compareByOriginalPositions;
  40903. /**
  40904. * Comparator between two mappings with deflated source and name indices where
  40905. * the generated positions are compared.
  40906. *
  40907. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40908. * mappings with the same generated line and column, but different
  40909. * source/name/original line and column the same. Useful when searching for a
  40910. * mapping with a stubbed out mapping.
  40911. */
  40912. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  40913. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40914. if (cmp !== 0) {
  40915. return cmp;
  40916. }
  40917. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40918. if (cmp !== 0 || onlyCompareGenerated) {
  40919. return cmp;
  40920. }
  40921. cmp = strcmp(mappingA.source, mappingB.source);
  40922. if (cmp !== 0) {
  40923. return cmp;
  40924. }
  40925. cmp = mappingA.originalLine - mappingB.originalLine;
  40926. if (cmp !== 0) {
  40927. return cmp;
  40928. }
  40929. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40930. if (cmp !== 0) {
  40931. return cmp;
  40932. }
  40933. return strcmp(mappingA.name, mappingB.name);
  40934. }
  40935. exports$1.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  40936. function strcmp(aStr1, aStr2) {
  40937. if (aStr1 === aStr2) {
  40938. return 0;
  40939. }
  40940. if (aStr1 === null) {
  40941. return 1; // aStr2 !== null
  40942. }
  40943. if (aStr2 === null) {
  40944. return -1; // aStr1 !== null
  40945. }
  40946. if (aStr1 > aStr2) {
  40947. return 1;
  40948. }
  40949. return -1;
  40950. }
  40951. /**
  40952. * Comparator between two mappings with inflated source and name strings where
  40953. * the generated positions are compared.
  40954. */
  40955. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  40956. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40957. if (cmp !== 0) {
  40958. return cmp;
  40959. }
  40960. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40961. if (cmp !== 0) {
  40962. return cmp;
  40963. }
  40964. cmp = strcmp(mappingA.source, mappingB.source);
  40965. if (cmp !== 0) {
  40966. return cmp;
  40967. }
  40968. cmp = mappingA.originalLine - mappingB.originalLine;
  40969. if (cmp !== 0) {
  40970. return cmp;
  40971. }
  40972. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40973. if (cmp !== 0) {
  40974. return cmp;
  40975. }
  40976. return strcmp(mappingA.name, mappingB.name);
  40977. }
  40978. exports$1.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  40979. /**
  40980. * Strip any JSON XSSI avoidance prefix from the string (as documented
  40981. * in the source maps specification), and then parse the string as
  40982. * JSON.
  40983. */
  40984. function parseSourceMapInput(str) {
  40985. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  40986. }
  40987. exports$1.parseSourceMapInput = parseSourceMapInput;
  40988. /**
  40989. * Compute the URL of a source given the the source root, the source's
  40990. * URL, and the source map's URL.
  40991. */
  40992. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  40993. sourceURL = sourceURL || '';
  40994. if (sourceRoot) {
  40995. // This follows what Chrome does.
  40996. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  40997. sourceRoot += '/';
  40998. }
  40999. // The spec says:
  41000. // Line 4: An optional source root, useful for relocating source
  41001. // files on a server or removing repeated values in the
  41002. // “sources” entry. This value is prepended to the individual
  41003. // entries in the “source” field.
  41004. sourceURL = sourceRoot + sourceURL;
  41005. }
  41006. // Historically, SourceMapConsumer did not take the sourceMapURL as
  41007. // a parameter. This mode is still somewhat supported, which is why
  41008. // this code block is conditional. However, it's preferable to pass
  41009. // the source map URL to SourceMapConsumer, so that this function
  41010. // can implement the source URL resolution algorithm as outlined in
  41011. // the spec. This block is basically the equivalent of:
  41012. // new URL(sourceURL, sourceMapURL).toString()
  41013. // ... except it avoids using URL, which wasn't available in the
  41014. // older releases of node still supported by this library.
  41015. //
  41016. // The spec says:
  41017. // If the sources are not absolute URLs after prepending of the
  41018. // “sourceRoot”, the sources are resolved relative to the
  41019. // SourceMap (like resolving script src in a html document).
  41020. if (sourceMapURL) {
  41021. var parsed = urlParse(sourceMapURL);
  41022. if (!parsed) {
  41023. throw new Error("sourceMapURL could not be parsed");
  41024. }
  41025. if (parsed.path) {
  41026. // Strip the last path component, but keep the "/".
  41027. var index = parsed.path.lastIndexOf('/');
  41028. if (index >= 0) {
  41029. parsed.path = parsed.path.substring(0, index + 1);
  41030. }
  41031. }
  41032. sourceURL = join(urlGenerate(parsed), sourceURL);
  41033. }
  41034. return normalize(sourceURL);
  41035. }
  41036. exports$1.computeSourceURL = computeSourceURL;
  41037. } (util));
  41038. return util;
  41039. }
  41040. var arraySet = {};
  41041. /* -*- Mode: js; js-indent-level: 2; -*- */
  41042. var hasRequiredArraySet;
  41043. function requireArraySet () {
  41044. if (hasRequiredArraySet) return arraySet;
  41045. hasRequiredArraySet = 1;
  41046. /*
  41047. * Copyright 2011 Mozilla Foundation and contributors
  41048. * Licensed under the New BSD license. See LICENSE or:
  41049. * http://opensource.org/licenses/BSD-3-Clause
  41050. */
  41051. var util = /*@__PURE__*/ requireUtil();
  41052. var has = Object.prototype.hasOwnProperty;
  41053. var hasNativeMap = typeof Map !== "undefined";
  41054. /**
  41055. * A data structure which is a combination of an array and a set. Adding a new
  41056. * member is O(1), testing for membership is O(1), and finding the index of an
  41057. * element is O(1). Removing elements from the set is not supported. Only
  41058. * strings are supported for membership.
  41059. */
  41060. function ArraySet() {
  41061. this._array = [];
  41062. this._set = hasNativeMap ? new Map() : Object.create(null);
  41063. }
  41064. /**
  41065. * Static method for creating ArraySet instances from an existing array.
  41066. */
  41067. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  41068. var set = new ArraySet();
  41069. for (var i = 0, len = aArray.length; i < len; i++) {
  41070. set.add(aArray[i], aAllowDuplicates);
  41071. }
  41072. return set;
  41073. };
  41074. /**
  41075. * Return how many unique items are in this ArraySet. If duplicates have been
  41076. * added, than those do not count towards the size.
  41077. *
  41078. * @returns Number
  41079. */
  41080. ArraySet.prototype.size = function ArraySet_size() {
  41081. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  41082. };
  41083. /**
  41084. * Add the given string to this set.
  41085. *
  41086. * @param String aStr
  41087. */
  41088. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  41089. var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
  41090. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  41091. var idx = this._array.length;
  41092. if (!isDuplicate || aAllowDuplicates) {
  41093. this._array.push(aStr);
  41094. }
  41095. if (!isDuplicate) {
  41096. if (hasNativeMap) {
  41097. this._set.set(aStr, idx);
  41098. } else {
  41099. this._set[sStr] = idx;
  41100. }
  41101. }
  41102. };
  41103. /**
  41104. * Is the given string a member of this set?
  41105. *
  41106. * @param String aStr
  41107. */
  41108. ArraySet.prototype.has = function ArraySet_has(aStr) {
  41109. if (hasNativeMap) {
  41110. return this._set.has(aStr);
  41111. } else {
  41112. var sStr = util.toSetString(aStr);
  41113. return has.call(this._set, sStr);
  41114. }
  41115. };
  41116. /**
  41117. * What is the index of the given string in the array?
  41118. *
  41119. * @param String aStr
  41120. */
  41121. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  41122. if (hasNativeMap) {
  41123. var idx = this._set.get(aStr);
  41124. if (idx >= 0) {
  41125. return idx;
  41126. }
  41127. } else {
  41128. var sStr = util.toSetString(aStr);
  41129. if (has.call(this._set, sStr)) {
  41130. return this._set[sStr];
  41131. }
  41132. }
  41133. throw new Error('"' + aStr + '" is not in the set.');
  41134. };
  41135. /**
  41136. * What is the element at the given index?
  41137. *
  41138. * @param Number aIdx
  41139. */
  41140. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  41141. if (aIdx >= 0 && aIdx < this._array.length) {
  41142. return this._array[aIdx];
  41143. }
  41144. throw new Error('No element indexed by ' + aIdx);
  41145. };
  41146. /**
  41147. * Returns the array representation of this set (which has the proper indices
  41148. * indicated by indexOf). Note that this is a copy of the internal array used
  41149. * for storing the members so that no one can mess with internal state.
  41150. */
  41151. ArraySet.prototype.toArray = function ArraySet_toArray() {
  41152. return this._array.slice();
  41153. };
  41154. arraySet.ArraySet = ArraySet;
  41155. return arraySet;
  41156. }
  41157. var mappingList = {};
  41158. /* -*- Mode: js; js-indent-level: 2; -*- */
  41159. var hasRequiredMappingList;
  41160. function requireMappingList () {
  41161. if (hasRequiredMappingList) return mappingList;
  41162. hasRequiredMappingList = 1;
  41163. /*
  41164. * Copyright 2014 Mozilla Foundation and contributors
  41165. * Licensed under the New BSD license. See LICENSE or:
  41166. * http://opensource.org/licenses/BSD-3-Clause
  41167. */
  41168. var util = /*@__PURE__*/ requireUtil();
  41169. /**
  41170. * Determine whether mappingB is after mappingA with respect to generated
  41171. * position.
  41172. */
  41173. function generatedPositionAfter(mappingA, mappingB) {
  41174. // Optimized for most common case
  41175. var lineA = mappingA.generatedLine;
  41176. var lineB = mappingB.generatedLine;
  41177. var columnA = mappingA.generatedColumn;
  41178. var columnB = mappingB.generatedColumn;
  41179. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  41180. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  41181. }
  41182. /**
  41183. * A data structure to provide a sorted view of accumulated mappings in a
  41184. * performance conscious manner. It trades a neglibable overhead in general
  41185. * case for a large speedup in case of mappings being added in order.
  41186. */
  41187. function MappingList() {
  41188. this._array = [];
  41189. this._sorted = true;
  41190. // Serves as infimum
  41191. this._last = {generatedLine: -1, generatedColumn: 0};
  41192. }
  41193. /**
  41194. * Iterate through internal items. This method takes the same arguments that
  41195. * `Array.prototype.forEach` takes.
  41196. *
  41197. * NOTE: The order of the mappings is NOT guaranteed.
  41198. */
  41199. MappingList.prototype.unsortedForEach =
  41200. function MappingList_forEach(aCallback, aThisArg) {
  41201. this._array.forEach(aCallback, aThisArg);
  41202. };
  41203. /**
  41204. * Add the given source mapping.
  41205. *
  41206. * @param Object aMapping
  41207. */
  41208. MappingList.prototype.add = function MappingList_add(aMapping) {
  41209. if (generatedPositionAfter(this._last, aMapping)) {
  41210. this._last = aMapping;
  41211. this._array.push(aMapping);
  41212. } else {
  41213. this._sorted = false;
  41214. this._array.push(aMapping);
  41215. }
  41216. };
  41217. /**
  41218. * Returns the flat, sorted array of mappings. The mappings are sorted by
  41219. * generated position.
  41220. *
  41221. * WARNING: This method returns internal data without copying, for
  41222. * performance. The return value must NOT be mutated, and should be treated as
  41223. * an immutable borrow. If you want to take ownership, you must make your own
  41224. * copy.
  41225. */
  41226. MappingList.prototype.toArray = function MappingList_toArray() {
  41227. if (!this._sorted) {
  41228. this._array.sort(util.compareByGeneratedPositionsInflated);
  41229. this._sorted = true;
  41230. }
  41231. return this._array;
  41232. };
  41233. mappingList.MappingList = MappingList;
  41234. return mappingList;
  41235. }
  41236. /* -*- Mode: js; js-indent-level: 2; -*- */
  41237. var hasRequiredSourceMapGenerator;
  41238. function requireSourceMapGenerator () {
  41239. if (hasRequiredSourceMapGenerator) return sourceMapGenerator;
  41240. hasRequiredSourceMapGenerator = 1;
  41241. /*
  41242. * Copyright 2011 Mozilla Foundation and contributors
  41243. * Licensed under the New BSD license. See LICENSE or:
  41244. * http://opensource.org/licenses/BSD-3-Clause
  41245. */
  41246. var base64VLQ = /*@__PURE__*/ requireBase64Vlq();
  41247. var util = /*@__PURE__*/ requireUtil();
  41248. var ArraySet = /*@__PURE__*/ requireArraySet().ArraySet;
  41249. var MappingList = /*@__PURE__*/ requireMappingList().MappingList;
  41250. /**
  41251. * An instance of the SourceMapGenerator represents a source map which is
  41252. * being built incrementally. You may pass an object with the following
  41253. * properties:
  41254. *
  41255. * - file: The filename of the generated source.
  41256. * - sourceRoot: A root for all relative URLs in this source map.
  41257. */
  41258. function SourceMapGenerator(aArgs) {
  41259. if (!aArgs) {
  41260. aArgs = {};
  41261. }
  41262. this._file = util.getArg(aArgs, 'file', null);
  41263. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  41264. this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
  41265. this._sources = new ArraySet();
  41266. this._names = new ArraySet();
  41267. this._mappings = new MappingList();
  41268. this._sourcesContents = null;
  41269. }
  41270. SourceMapGenerator.prototype._version = 3;
  41271. /**
  41272. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  41273. *
  41274. * @param aSourceMapConsumer The SourceMap.
  41275. */
  41276. SourceMapGenerator.fromSourceMap =
  41277. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  41278. var sourceRoot = aSourceMapConsumer.sourceRoot;
  41279. var generator = new SourceMapGenerator({
  41280. file: aSourceMapConsumer.file,
  41281. sourceRoot: sourceRoot
  41282. });
  41283. aSourceMapConsumer.eachMapping(function (mapping) {
  41284. var newMapping = {
  41285. generated: {
  41286. line: mapping.generatedLine,
  41287. column: mapping.generatedColumn
  41288. }
  41289. };
  41290. if (mapping.source != null) {
  41291. newMapping.source = mapping.source;
  41292. if (sourceRoot != null) {
  41293. newMapping.source = util.relative(sourceRoot, newMapping.source);
  41294. }
  41295. newMapping.original = {
  41296. line: mapping.originalLine,
  41297. column: mapping.originalColumn
  41298. };
  41299. if (mapping.name != null) {
  41300. newMapping.name = mapping.name;
  41301. }
  41302. }
  41303. generator.addMapping(newMapping);
  41304. });
  41305. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41306. var sourceRelative = sourceFile;
  41307. if (sourceRoot !== null) {
  41308. sourceRelative = util.relative(sourceRoot, sourceFile);
  41309. }
  41310. if (!generator._sources.has(sourceRelative)) {
  41311. generator._sources.add(sourceRelative);
  41312. }
  41313. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41314. if (content != null) {
  41315. generator.setSourceContent(sourceFile, content);
  41316. }
  41317. });
  41318. return generator;
  41319. };
  41320. /**
  41321. * Add a single mapping from original source line and column to the generated
  41322. * source's line and column for this source map being created. The mapping
  41323. * object should have the following properties:
  41324. *
  41325. * - generated: An object with the generated line and column positions.
  41326. * - original: An object with the original line and column positions.
  41327. * - source: The original source file (relative to the sourceRoot).
  41328. * - name: An optional original token name for this mapping.
  41329. */
  41330. SourceMapGenerator.prototype.addMapping =
  41331. function SourceMapGenerator_addMapping(aArgs) {
  41332. var generated = util.getArg(aArgs, 'generated');
  41333. var original = util.getArg(aArgs, 'original', null);
  41334. var source = util.getArg(aArgs, 'source', null);
  41335. var name = util.getArg(aArgs, 'name', null);
  41336. if (!this._skipValidation) {
  41337. this._validateMapping(generated, original, source, name);
  41338. }
  41339. if (source != null) {
  41340. source = String(source);
  41341. if (!this._sources.has(source)) {
  41342. this._sources.add(source);
  41343. }
  41344. }
  41345. if (name != null) {
  41346. name = String(name);
  41347. if (!this._names.has(name)) {
  41348. this._names.add(name);
  41349. }
  41350. }
  41351. this._mappings.add({
  41352. generatedLine: generated.line,
  41353. generatedColumn: generated.column,
  41354. originalLine: original != null && original.line,
  41355. originalColumn: original != null && original.column,
  41356. source: source,
  41357. name: name
  41358. });
  41359. };
  41360. /**
  41361. * Set the source content for a source file.
  41362. */
  41363. SourceMapGenerator.prototype.setSourceContent =
  41364. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  41365. var source = aSourceFile;
  41366. if (this._sourceRoot != null) {
  41367. source = util.relative(this._sourceRoot, source);
  41368. }
  41369. if (aSourceContent != null) {
  41370. // Add the source content to the _sourcesContents map.
  41371. // Create a new _sourcesContents map if the property is null.
  41372. if (!this._sourcesContents) {
  41373. this._sourcesContents = Object.create(null);
  41374. }
  41375. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  41376. } else if (this._sourcesContents) {
  41377. // Remove the source file from the _sourcesContents map.
  41378. // If the _sourcesContents map is empty, set the property to null.
  41379. delete this._sourcesContents[util.toSetString(source)];
  41380. if (Object.keys(this._sourcesContents).length === 0) {
  41381. this._sourcesContents = null;
  41382. }
  41383. }
  41384. };
  41385. /**
  41386. * Applies the mappings of a sub-source-map for a specific source file to the
  41387. * source map being generated. Each mapping to the supplied source file is
  41388. * rewritten using the supplied source map. Note: The resolution for the
  41389. * resulting mappings is the minimium of this map and the supplied map.
  41390. *
  41391. * @param aSourceMapConsumer The source map to be applied.
  41392. * @param aSourceFile Optional. The filename of the source file.
  41393. * If omitted, SourceMapConsumer's file property will be used.
  41394. * @param aSourceMapPath Optional. The dirname of the path to the source map
  41395. * to be applied. If relative, it is relative to the SourceMapConsumer.
  41396. * This parameter is needed when the two source maps aren't in the same
  41397. * directory, and the source map to be applied contains relative source
  41398. * paths. If so, those relative source paths need to be rewritten
  41399. * relative to the SourceMapGenerator.
  41400. */
  41401. SourceMapGenerator.prototype.applySourceMap =
  41402. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  41403. var sourceFile = aSourceFile;
  41404. // If aSourceFile is omitted, we will use the file property of the SourceMap
  41405. if (aSourceFile == null) {
  41406. if (aSourceMapConsumer.file == null) {
  41407. throw new Error(
  41408. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  41409. 'or the source map\'s "file" property. Both were omitted.'
  41410. );
  41411. }
  41412. sourceFile = aSourceMapConsumer.file;
  41413. }
  41414. var sourceRoot = this._sourceRoot;
  41415. // Make "sourceFile" relative if an absolute Url is passed.
  41416. if (sourceRoot != null) {
  41417. sourceFile = util.relative(sourceRoot, sourceFile);
  41418. }
  41419. // Applying the SourceMap can add and remove items from the sources and
  41420. // the names array.
  41421. var newSources = new ArraySet();
  41422. var newNames = new ArraySet();
  41423. // Find mappings for the "sourceFile"
  41424. this._mappings.unsortedForEach(function (mapping) {
  41425. if (mapping.source === sourceFile && mapping.originalLine != null) {
  41426. // Check if it can be mapped by the source map, then update the mapping.
  41427. var original = aSourceMapConsumer.originalPositionFor({
  41428. line: mapping.originalLine,
  41429. column: mapping.originalColumn
  41430. });
  41431. if (original.source != null) {
  41432. // Copy mapping
  41433. mapping.source = original.source;
  41434. if (aSourceMapPath != null) {
  41435. mapping.source = util.join(aSourceMapPath, mapping.source);
  41436. }
  41437. if (sourceRoot != null) {
  41438. mapping.source = util.relative(sourceRoot, mapping.source);
  41439. }
  41440. mapping.originalLine = original.line;
  41441. mapping.originalColumn = original.column;
  41442. if (original.name != null) {
  41443. mapping.name = original.name;
  41444. }
  41445. }
  41446. }
  41447. var source = mapping.source;
  41448. if (source != null && !newSources.has(source)) {
  41449. newSources.add(source);
  41450. }
  41451. var name = mapping.name;
  41452. if (name != null && !newNames.has(name)) {
  41453. newNames.add(name);
  41454. }
  41455. }, this);
  41456. this._sources = newSources;
  41457. this._names = newNames;
  41458. // Copy sourcesContents of applied map.
  41459. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41460. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41461. if (content != null) {
  41462. if (aSourceMapPath != null) {
  41463. sourceFile = util.join(aSourceMapPath, sourceFile);
  41464. }
  41465. if (sourceRoot != null) {
  41466. sourceFile = util.relative(sourceRoot, sourceFile);
  41467. }
  41468. this.setSourceContent(sourceFile, content);
  41469. }
  41470. }, this);
  41471. };
  41472. /**
  41473. * A mapping can have one of the three levels of data:
  41474. *
  41475. * 1. Just the generated position.
  41476. * 2. The Generated position, original position, and original source.
  41477. * 3. Generated and original position, original source, as well as a name
  41478. * token.
  41479. *
  41480. * To maintain consistency, we validate that any new mapping being added falls
  41481. * in to one of these categories.
  41482. */
  41483. SourceMapGenerator.prototype._validateMapping =
  41484. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  41485. aName) {
  41486. // When aOriginal is truthy but has empty values for .line and .column,
  41487. // it is most likely a programmer error. In this case we throw a very
  41488. // specific error message to try to guide them the right way.
  41489. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  41490. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  41491. throw new Error(
  41492. 'original.line and original.column are not numbers -- you probably meant to omit ' +
  41493. 'the original mapping entirely and only map the generated position. If so, pass ' +
  41494. 'null for the original mapping instead of an object with empty or null values.'
  41495. );
  41496. }
  41497. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  41498. && aGenerated.line > 0 && aGenerated.column >= 0
  41499. && !aOriginal && !aSource && !aName) {
  41500. // Case 1.
  41501. return;
  41502. }
  41503. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  41504. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  41505. && aGenerated.line > 0 && aGenerated.column >= 0
  41506. && aOriginal.line > 0 && aOriginal.column >= 0
  41507. && aSource) {
  41508. // Cases 2 and 3.
  41509. return;
  41510. }
  41511. else {
  41512. throw new Error('Invalid mapping: ' + JSON.stringify({
  41513. generated: aGenerated,
  41514. source: aSource,
  41515. original: aOriginal,
  41516. name: aName
  41517. }));
  41518. }
  41519. };
  41520. /**
  41521. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  41522. * specified by the source map format.
  41523. */
  41524. SourceMapGenerator.prototype._serializeMappings =
  41525. function SourceMapGenerator_serializeMappings() {
  41526. var previousGeneratedColumn = 0;
  41527. var previousGeneratedLine = 1;
  41528. var previousOriginalColumn = 0;
  41529. var previousOriginalLine = 0;
  41530. var previousName = 0;
  41531. var previousSource = 0;
  41532. var result = '';
  41533. var next;
  41534. var mapping;
  41535. var nameIdx;
  41536. var sourceIdx;
  41537. var mappings = this._mappings.toArray();
  41538. for (var i = 0, len = mappings.length; i < len; i++) {
  41539. mapping = mappings[i];
  41540. next = '';
  41541. if (mapping.generatedLine !== previousGeneratedLine) {
  41542. previousGeneratedColumn = 0;
  41543. while (mapping.generatedLine !== previousGeneratedLine) {
  41544. next += ';';
  41545. previousGeneratedLine++;
  41546. }
  41547. }
  41548. else {
  41549. if (i > 0) {
  41550. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  41551. continue;
  41552. }
  41553. next += ',';
  41554. }
  41555. }
  41556. next += base64VLQ.encode(mapping.generatedColumn
  41557. - previousGeneratedColumn);
  41558. previousGeneratedColumn = mapping.generatedColumn;
  41559. if (mapping.source != null) {
  41560. sourceIdx = this._sources.indexOf(mapping.source);
  41561. next += base64VLQ.encode(sourceIdx - previousSource);
  41562. previousSource = sourceIdx;
  41563. // lines are stored 0-based in SourceMap spec version 3
  41564. next += base64VLQ.encode(mapping.originalLine - 1
  41565. - previousOriginalLine);
  41566. previousOriginalLine = mapping.originalLine - 1;
  41567. next += base64VLQ.encode(mapping.originalColumn
  41568. - previousOriginalColumn);
  41569. previousOriginalColumn = mapping.originalColumn;
  41570. if (mapping.name != null) {
  41571. nameIdx = this._names.indexOf(mapping.name);
  41572. next += base64VLQ.encode(nameIdx - previousName);
  41573. previousName = nameIdx;
  41574. }
  41575. }
  41576. result += next;
  41577. }
  41578. return result;
  41579. };
  41580. SourceMapGenerator.prototype._generateSourcesContent =
  41581. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  41582. return aSources.map(function (source) {
  41583. if (!this._sourcesContents) {
  41584. return null;
  41585. }
  41586. if (aSourceRoot != null) {
  41587. source = util.relative(aSourceRoot, source);
  41588. }
  41589. var key = util.toSetString(source);
  41590. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  41591. ? this._sourcesContents[key]
  41592. : null;
  41593. }, this);
  41594. };
  41595. /**
  41596. * Externalize the source map.
  41597. */
  41598. SourceMapGenerator.prototype.toJSON =
  41599. function SourceMapGenerator_toJSON() {
  41600. var map = {
  41601. version: this._version,
  41602. sources: this._sources.toArray(),
  41603. names: this._names.toArray(),
  41604. mappings: this._serializeMappings()
  41605. };
  41606. if (this._file != null) {
  41607. map.file = this._file;
  41608. }
  41609. if (this._sourceRoot != null) {
  41610. map.sourceRoot = this._sourceRoot;
  41611. }
  41612. if (this._sourcesContents) {
  41613. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  41614. }
  41615. return map;
  41616. };
  41617. /**
  41618. * Render the source map being generated to a string.
  41619. */
  41620. SourceMapGenerator.prototype.toString =
  41621. function SourceMapGenerator_toString() {
  41622. return JSON.stringify(this.toJSON());
  41623. };
  41624. sourceMapGenerator.SourceMapGenerator = SourceMapGenerator;
  41625. return sourceMapGenerator;
  41626. }
  41627. var sourceMapConsumer = {};
  41628. var binarySearch = {};
  41629. /* -*- Mode: js; js-indent-level: 2; -*- */
  41630. var hasRequiredBinarySearch;
  41631. function requireBinarySearch () {
  41632. if (hasRequiredBinarySearch) return binarySearch;
  41633. hasRequiredBinarySearch = 1;
  41634. (function (exports$1) {
  41635. /*
  41636. * Copyright 2011 Mozilla Foundation and contributors
  41637. * Licensed under the New BSD license. See LICENSE or:
  41638. * http://opensource.org/licenses/BSD-3-Clause
  41639. */
  41640. exports$1.GREATEST_LOWER_BOUND = 1;
  41641. exports$1.LEAST_UPPER_BOUND = 2;
  41642. /**
  41643. * Recursive implementation of binary search.
  41644. *
  41645. * @param aLow Indices here and lower do not contain the needle.
  41646. * @param aHigh Indices here and higher do not contain the needle.
  41647. * @param aNeedle The element being searched for.
  41648. * @param aHaystack The non-empty array being searched.
  41649. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  41650. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  41651. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  41652. * closest element that is smaller than or greater than the one we are
  41653. * searching for, respectively, if the exact element cannot be found.
  41654. */
  41655. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  41656. // This function terminates when one of the following is true:
  41657. //
  41658. // 1. We find the exact element we are looking for.
  41659. //
  41660. // 2. We did not find the exact element, but we can return the index of
  41661. // the next-closest element.
  41662. //
  41663. // 3. We did not find the exact element, and there is no next-closest
  41664. // element than the one we are searching for, so we return -1.
  41665. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  41666. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  41667. if (cmp === 0) {
  41668. // Found the element we are looking for.
  41669. return mid;
  41670. }
  41671. else if (cmp > 0) {
  41672. // Our needle is greater than aHaystack[mid].
  41673. if (aHigh - mid > 1) {
  41674. // The element is in the upper half.
  41675. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  41676. }
  41677. // The exact needle element was not found in this haystack. Determine if
  41678. // we are in termination case (3) or (2) and return the appropriate thing.
  41679. if (aBias == exports$1.LEAST_UPPER_BOUND) {
  41680. return aHigh < aHaystack.length ? aHigh : -1;
  41681. } else {
  41682. return mid;
  41683. }
  41684. }
  41685. else {
  41686. // Our needle is less than aHaystack[mid].
  41687. if (mid - aLow > 1) {
  41688. // The element is in the lower half.
  41689. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  41690. }
  41691. // we are in termination case (3) or (2) and return the appropriate thing.
  41692. if (aBias == exports$1.LEAST_UPPER_BOUND) {
  41693. return mid;
  41694. } else {
  41695. return aLow < 0 ? -1 : aLow;
  41696. }
  41697. }
  41698. }
  41699. /**
  41700. * This is an implementation of binary search which will always try and return
  41701. * the index of the closest element if there is no exact hit. This is because
  41702. * mappings between original and generated line/col pairs are single points,
  41703. * and there is an implicit region between each of them, so a miss just means
  41704. * that you aren't on the very start of a region.
  41705. *
  41706. * @param aNeedle The element you are looking for.
  41707. * @param aHaystack The array that is being searched.
  41708. * @param aCompare A function which takes the needle and an element in the
  41709. * array and returns -1, 0, or 1 depending on whether the needle is less
  41710. * than, equal to, or greater than the element, respectively.
  41711. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  41712. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  41713. * closest element that is smaller than or greater than the one we are
  41714. * searching for, respectively, if the exact element cannot be found.
  41715. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  41716. */
  41717. exports$1.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  41718. if (aHaystack.length === 0) {
  41719. return -1;
  41720. }
  41721. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  41722. aCompare, aBias || exports$1.GREATEST_LOWER_BOUND);
  41723. if (index < 0) {
  41724. return -1;
  41725. }
  41726. // We have found either the exact element, or the next-closest element than
  41727. // the one we are searching for. However, there may be more than one such
  41728. // element. Make sure we always return the smallest of these.
  41729. while (index - 1 >= 0) {
  41730. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  41731. break;
  41732. }
  41733. --index;
  41734. }
  41735. return index;
  41736. };
  41737. } (binarySearch));
  41738. return binarySearch;
  41739. }
  41740. var quickSort = {};
  41741. /* -*- Mode: js; js-indent-level: 2; -*- */
  41742. var hasRequiredQuickSort;
  41743. function requireQuickSort () {
  41744. if (hasRequiredQuickSort) return quickSort;
  41745. hasRequiredQuickSort = 1;
  41746. /*
  41747. * Copyright 2011 Mozilla Foundation and contributors
  41748. * Licensed under the New BSD license. See LICENSE or:
  41749. * http://opensource.org/licenses/BSD-3-Clause
  41750. */
  41751. // It turns out that some (most?) JavaScript engines don't self-host
  41752. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  41753. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  41754. // custom comparator function, calling back and forth between the VM's C++ and
  41755. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  41756. // worse generated code for the comparator function than would be optimal. In
  41757. // fact, when sorting with a comparator, these costs outweigh the benefits of
  41758. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  41759. // a ~3500ms mean speed-up in `bench/bench.html`.
  41760. /**
  41761. * Swap the elements indexed by `x` and `y` in the array `ary`.
  41762. *
  41763. * @param {Array} ary
  41764. * The array.
  41765. * @param {Number} x
  41766. * The index of the first item.
  41767. * @param {Number} y
  41768. * The index of the second item.
  41769. */
  41770. function swap(ary, x, y) {
  41771. var temp = ary[x];
  41772. ary[x] = ary[y];
  41773. ary[y] = temp;
  41774. }
  41775. /**
  41776. * Returns a random integer within the range `low .. high` inclusive.
  41777. *
  41778. * @param {Number} low
  41779. * The lower bound on the range.
  41780. * @param {Number} high
  41781. * The upper bound on the range.
  41782. */
  41783. function randomIntInRange(low, high) {
  41784. return Math.round(low + (Math.random() * (high - low)));
  41785. }
  41786. /**
  41787. * The Quick Sort algorithm.
  41788. *
  41789. * @param {Array} ary
  41790. * An array to sort.
  41791. * @param {function} comparator
  41792. * Function to use to compare two items.
  41793. * @param {Number} p
  41794. * Start index of the array
  41795. * @param {Number} r
  41796. * End index of the array
  41797. */
  41798. function doQuickSort(ary, comparator, p, r) {
  41799. // If our lower bound is less than our upper bound, we (1) partition the
  41800. // array into two pieces and (2) recurse on each half. If it is not, this is
  41801. // the empty array and our base case.
  41802. if (p < r) {
  41803. // (1) Partitioning.
  41804. //
  41805. // The partitioning chooses a pivot between `p` and `r` and moves all
  41806. // elements that are less than or equal to the pivot to the before it, and
  41807. // all the elements that are greater than it after it. The effect is that
  41808. // once partition is done, the pivot is in the exact place it will be when
  41809. // the array is put in sorted order, and it will not need to be moved
  41810. // again. This runs in O(n) time.
  41811. // Always choose a random pivot so that an input array which is reverse
  41812. // sorted does not cause O(n^2) running time.
  41813. var pivotIndex = randomIntInRange(p, r);
  41814. var i = p - 1;
  41815. swap(ary, pivotIndex, r);
  41816. var pivot = ary[r];
  41817. // Immediately after `j` is incremented in this loop, the following hold
  41818. // true:
  41819. //
  41820. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  41821. //
  41822. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  41823. for (var j = p; j < r; j++) {
  41824. if (comparator(ary[j], pivot) <= 0) {
  41825. i += 1;
  41826. swap(ary, i, j);
  41827. }
  41828. }
  41829. swap(ary, i + 1, j);
  41830. var q = i + 1;
  41831. // (2) Recurse on each half.
  41832. doQuickSort(ary, comparator, p, q - 1);
  41833. doQuickSort(ary, comparator, q + 1, r);
  41834. }
  41835. }
  41836. /**
  41837. * Sort the given array in-place with the given comparator function.
  41838. *
  41839. * @param {Array} ary
  41840. * An array to sort.
  41841. * @param {function} comparator
  41842. * Function to use to compare two items.
  41843. */
  41844. quickSort.quickSort = function (ary, comparator) {
  41845. doQuickSort(ary, comparator, 0, ary.length - 1);
  41846. };
  41847. return quickSort;
  41848. }
  41849. /* -*- Mode: js; js-indent-level: 2; -*- */
  41850. var hasRequiredSourceMapConsumer;
  41851. function requireSourceMapConsumer () {
  41852. if (hasRequiredSourceMapConsumer) return sourceMapConsumer;
  41853. hasRequiredSourceMapConsumer = 1;
  41854. /*
  41855. * Copyright 2011 Mozilla Foundation and contributors
  41856. * Licensed under the New BSD license. See LICENSE or:
  41857. * http://opensource.org/licenses/BSD-3-Clause
  41858. */
  41859. var util = /*@__PURE__*/ requireUtil();
  41860. var binarySearch = /*@__PURE__*/ requireBinarySearch();
  41861. var ArraySet = /*@__PURE__*/ requireArraySet().ArraySet;
  41862. var base64VLQ = /*@__PURE__*/ requireBase64Vlq();
  41863. var quickSort = /*@__PURE__*/ requireQuickSort().quickSort;
  41864. function SourceMapConsumer(aSourceMap, aSourceMapURL) {
  41865. var sourceMap = aSourceMap;
  41866. if (typeof aSourceMap === 'string') {
  41867. sourceMap = util.parseSourceMapInput(aSourceMap);
  41868. }
  41869. return sourceMap.sections != null
  41870. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  41871. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  41872. }
  41873. SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  41874. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  41875. };
  41876. /**
  41877. * The version of the source mapping spec that we are consuming.
  41878. */
  41879. SourceMapConsumer.prototype._version = 3;
  41880. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  41881. // parsed mapping coordinates from the source map's "mappings" attribute. They
  41882. // are lazily instantiated, accessed via the `_generatedMappings` and
  41883. // `_originalMappings` getters respectively, and we only parse the mappings
  41884. // and create these arrays once queried for a source location. We jump through
  41885. // these hoops because there can be many thousands of mappings, and parsing
  41886. // them is expensive, so we only want to do it if we must.
  41887. //
  41888. // Each object in the arrays is of the form:
  41889. //
  41890. // {
  41891. // generatedLine: The line number in the generated code,
  41892. // generatedColumn: The column number in the generated code,
  41893. // source: The path to the original source file that generated this
  41894. // chunk of code,
  41895. // originalLine: The line number in the original source that
  41896. // corresponds to this chunk of generated code,
  41897. // originalColumn: The column number in the original source that
  41898. // corresponds to this chunk of generated code,
  41899. // name: The name of the original symbol which generated this chunk of
  41900. // code.
  41901. // }
  41902. //
  41903. // All properties except for `generatedLine` and `generatedColumn` can be
  41904. // `null`.
  41905. //
  41906. // `_generatedMappings` is ordered by the generated positions.
  41907. //
  41908. // `_originalMappings` is ordered by the original positions.
  41909. SourceMapConsumer.prototype.__generatedMappings = null;
  41910. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  41911. configurable: true,
  41912. enumerable: true,
  41913. get: function () {
  41914. if (!this.__generatedMappings) {
  41915. this._parseMappings(this._mappings, this.sourceRoot);
  41916. }
  41917. return this.__generatedMappings;
  41918. }
  41919. });
  41920. SourceMapConsumer.prototype.__originalMappings = null;
  41921. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  41922. configurable: true,
  41923. enumerable: true,
  41924. get: function () {
  41925. if (!this.__originalMappings) {
  41926. this._parseMappings(this._mappings, this.sourceRoot);
  41927. }
  41928. return this.__originalMappings;
  41929. }
  41930. });
  41931. SourceMapConsumer.prototype._charIsMappingSeparator =
  41932. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  41933. var c = aStr.charAt(index);
  41934. return c === ";" || c === ",";
  41935. };
  41936. /**
  41937. * Parse the mappings in a string in to a data structure which we can easily
  41938. * query (the ordered arrays in the `this.__generatedMappings` and
  41939. * `this.__originalMappings` properties).
  41940. */
  41941. SourceMapConsumer.prototype._parseMappings =
  41942. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  41943. throw new Error("Subclasses must implement _parseMappings");
  41944. };
  41945. SourceMapConsumer.GENERATED_ORDER = 1;
  41946. SourceMapConsumer.ORIGINAL_ORDER = 2;
  41947. SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
  41948. SourceMapConsumer.LEAST_UPPER_BOUND = 2;
  41949. /**
  41950. * Iterate over each mapping between an original source/line/column and a
  41951. * generated line/column in this source map.
  41952. *
  41953. * @param Function aCallback
  41954. * The function that is called with each mapping.
  41955. * @param Object aContext
  41956. * Optional. If specified, this object will be the value of `this` every
  41957. * time that `aCallback` is called.
  41958. * @param aOrder
  41959. * Either `SourceMapConsumer.GENERATED_ORDER` or
  41960. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  41961. * iterate over the mappings sorted by the generated file's line/column
  41962. * order or the original's source/line/column order, respectively. Defaults to
  41963. * `SourceMapConsumer.GENERATED_ORDER`.
  41964. */
  41965. SourceMapConsumer.prototype.eachMapping =
  41966. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  41967. var context = aContext || null;
  41968. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  41969. var mappings;
  41970. switch (order) {
  41971. case SourceMapConsumer.GENERATED_ORDER:
  41972. mappings = this._generatedMappings;
  41973. break;
  41974. case SourceMapConsumer.ORIGINAL_ORDER:
  41975. mappings = this._originalMappings;
  41976. break;
  41977. default:
  41978. throw new Error("Unknown order of iteration.");
  41979. }
  41980. var sourceRoot = this.sourceRoot;
  41981. mappings.map(function (mapping) {
  41982. var source = mapping.source === null ? null : this._sources.at(mapping.source);
  41983. source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
  41984. return {
  41985. source: source,
  41986. generatedLine: mapping.generatedLine,
  41987. generatedColumn: mapping.generatedColumn,
  41988. originalLine: mapping.originalLine,
  41989. originalColumn: mapping.originalColumn,
  41990. name: mapping.name === null ? null : this._names.at(mapping.name)
  41991. };
  41992. }, this).forEach(aCallback, context);
  41993. };
  41994. /**
  41995. * Returns all generated line and column information for the original source,
  41996. * line, and column provided. If no column is provided, returns all mappings
  41997. * corresponding to a either the line we are searching for or the next
  41998. * closest line that has any mappings. Otherwise, returns all mappings
  41999. * corresponding to the given line and either the column we are searching for
  42000. * or the next closest column that has any offsets.
  42001. *
  42002. * The only argument is an object with the following properties:
  42003. *
  42004. * - source: The filename of the original source.
  42005. * - line: The line number in the original source. The line number is 1-based.
  42006. * - column: Optional. the column number in the original source.
  42007. * The column number is 0-based.
  42008. *
  42009. * and an array of objects is returned, each with the following properties:
  42010. *
  42011. * - line: The line number in the generated source, or null. The
  42012. * line number is 1-based.
  42013. * - column: The column number in the generated source, or null.
  42014. * The column number is 0-based.
  42015. */
  42016. SourceMapConsumer.prototype.allGeneratedPositionsFor =
  42017. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  42018. var line = util.getArg(aArgs, 'line');
  42019. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  42020. // returns the index of the closest mapping less than the needle. By
  42021. // setting needle.originalColumn to 0, we thus find the last mapping for
  42022. // the given line, provided such a mapping exists.
  42023. var needle = {
  42024. source: util.getArg(aArgs, 'source'),
  42025. originalLine: line,
  42026. originalColumn: util.getArg(aArgs, 'column', 0)
  42027. };
  42028. needle.source = this._findSourceIndex(needle.source);
  42029. if (needle.source < 0) {
  42030. return [];
  42031. }
  42032. var mappings = [];
  42033. var index = this._findMapping(needle,
  42034. this._originalMappings,
  42035. "originalLine",
  42036. "originalColumn",
  42037. util.compareByOriginalPositions,
  42038. binarySearch.LEAST_UPPER_BOUND);
  42039. if (index >= 0) {
  42040. var mapping = this._originalMappings[index];
  42041. if (aArgs.column === undefined) {
  42042. var originalLine = mapping.originalLine;
  42043. // Iterate until either we run out of mappings, or we run into
  42044. // a mapping for a different line than the one we found. Since
  42045. // mappings are sorted, this is guaranteed to find all mappings for
  42046. // the line we found.
  42047. while (mapping && mapping.originalLine === originalLine) {
  42048. mappings.push({
  42049. line: util.getArg(mapping, 'generatedLine', null),
  42050. column: util.getArg(mapping, 'generatedColumn', null),
  42051. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42052. });
  42053. mapping = this._originalMappings[++index];
  42054. }
  42055. } else {
  42056. var originalColumn = mapping.originalColumn;
  42057. // Iterate until either we run out of mappings, or we run into
  42058. // a mapping for a different line than the one we were searching for.
  42059. // Since mappings are sorted, this is guaranteed to find all mappings for
  42060. // the line we are searching for.
  42061. while (mapping &&
  42062. mapping.originalLine === line &&
  42063. mapping.originalColumn == originalColumn) {
  42064. mappings.push({
  42065. line: util.getArg(mapping, 'generatedLine', null),
  42066. column: util.getArg(mapping, 'generatedColumn', null),
  42067. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42068. });
  42069. mapping = this._originalMappings[++index];
  42070. }
  42071. }
  42072. }
  42073. return mappings;
  42074. };
  42075. sourceMapConsumer.SourceMapConsumer = SourceMapConsumer;
  42076. /**
  42077. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  42078. * query for information about the original file positions by giving it a file
  42079. * position in the generated source.
  42080. *
  42081. * The first parameter is the raw source map (either as a JSON string, or
  42082. * already parsed to an object). According to the spec, source maps have the
  42083. * following attributes:
  42084. *
  42085. * - version: Which version of the source map spec this map is following.
  42086. * - sources: An array of URLs to the original source files.
  42087. * - names: An array of identifiers which can be referrenced by individual mappings.
  42088. * - sourceRoot: Optional. The URL root from which all sources are relative.
  42089. * - sourcesContent: Optional. An array of contents of the original source files.
  42090. * - mappings: A string of base64 VLQs which contain the actual mappings.
  42091. * - file: Optional. The generated file this source map is associated with.
  42092. *
  42093. * Here is an example source map, taken from the source map spec[0]:
  42094. *
  42095. * {
  42096. * version : 3,
  42097. * file: "out.js",
  42098. * sourceRoot : "",
  42099. * sources: ["foo.js", "bar.js"],
  42100. * names: ["src", "maps", "are", "fun"],
  42101. * mappings: "AA,AB;;ABCDE;"
  42102. * }
  42103. *
  42104. * The second parameter, if given, is a string whose value is the URL
  42105. * at which the source map was found. This URL is used to compute the
  42106. * sources array.
  42107. *
  42108. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  42109. */
  42110. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  42111. var sourceMap = aSourceMap;
  42112. if (typeof aSourceMap === 'string') {
  42113. sourceMap = util.parseSourceMapInput(aSourceMap);
  42114. }
  42115. var version = util.getArg(sourceMap, 'version');
  42116. var sources = util.getArg(sourceMap, 'sources');
  42117. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  42118. // requires the array) to play nice here.
  42119. var names = util.getArg(sourceMap, 'names', []);
  42120. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  42121. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  42122. var mappings = util.getArg(sourceMap, 'mappings');
  42123. var file = util.getArg(sourceMap, 'file', null);
  42124. // Once again, Sass deviates from the spec and supplies the version as a
  42125. // string rather than a number, so we use loose equality checking here.
  42126. if (version != this._version) {
  42127. throw new Error('Unsupported version: ' + version);
  42128. }
  42129. if (sourceRoot) {
  42130. sourceRoot = util.normalize(sourceRoot);
  42131. }
  42132. sources = sources
  42133. .map(String)
  42134. // Some source maps produce relative source paths like "./foo.js" instead of
  42135. // "foo.js". Normalize these first so that future comparisons will succeed.
  42136. // See bugzil.la/1090768.
  42137. .map(util.normalize)
  42138. // Always ensure that absolute sources are internally stored relative to
  42139. // the source root, if the source root is absolute. Not doing this would
  42140. // be particularly problematic when the source root is a prefix of the
  42141. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  42142. .map(function (source) {
  42143. return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
  42144. ? util.relative(sourceRoot, source)
  42145. : source;
  42146. });
  42147. // Pass `true` below to allow duplicate names and sources. While source maps
  42148. // are intended to be compressed and deduplicated, the TypeScript compiler
  42149. // sometimes generates source maps with duplicates in them. See Github issue
  42150. // #72 and bugzil.la/889492.
  42151. this._names = ArraySet.fromArray(names.map(String), true);
  42152. this._sources = ArraySet.fromArray(sources, true);
  42153. this._absoluteSources = this._sources.toArray().map(function (s) {
  42154. return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
  42155. });
  42156. this.sourceRoot = sourceRoot;
  42157. this.sourcesContent = sourcesContent;
  42158. this._mappings = mappings;
  42159. this._sourceMapURL = aSourceMapURL;
  42160. this.file = file;
  42161. }
  42162. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  42163. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
  42164. /**
  42165. * Utility function to find the index of a source. Returns -1 if not
  42166. * found.
  42167. */
  42168. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  42169. var relativeSource = aSource;
  42170. if (this.sourceRoot != null) {
  42171. relativeSource = util.relative(this.sourceRoot, relativeSource);
  42172. }
  42173. if (this._sources.has(relativeSource)) {
  42174. return this._sources.indexOf(relativeSource);
  42175. }
  42176. // Maybe aSource is an absolute URL as returned by |sources|. In
  42177. // this case we can't simply undo the transform.
  42178. var i;
  42179. for (i = 0; i < this._absoluteSources.length; ++i) {
  42180. if (this._absoluteSources[i] == aSource) {
  42181. return i;
  42182. }
  42183. }
  42184. return -1;
  42185. };
  42186. /**
  42187. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  42188. *
  42189. * @param SourceMapGenerator aSourceMap
  42190. * The source map that will be consumed.
  42191. * @param String aSourceMapURL
  42192. * The URL at which the source map can be found (optional)
  42193. * @returns BasicSourceMapConsumer
  42194. */
  42195. BasicSourceMapConsumer.fromSourceMap =
  42196. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  42197. var smc = Object.create(BasicSourceMapConsumer.prototype);
  42198. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  42199. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  42200. smc.sourceRoot = aSourceMap._sourceRoot;
  42201. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  42202. smc.sourceRoot);
  42203. smc.file = aSourceMap._file;
  42204. smc._sourceMapURL = aSourceMapURL;
  42205. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  42206. return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  42207. });
  42208. // Because we are modifying the entries (by converting string sources and
  42209. // names to indices into the sources and names ArraySets), we have to make
  42210. // a copy of the entry or else bad things happen. Shared mutable state
  42211. // strikes again! See github issue #191.
  42212. var generatedMappings = aSourceMap._mappings.toArray().slice();
  42213. var destGeneratedMappings = smc.__generatedMappings = [];
  42214. var destOriginalMappings = smc.__originalMappings = [];
  42215. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  42216. var srcMapping = generatedMappings[i];
  42217. var destMapping = new Mapping;
  42218. destMapping.generatedLine = srcMapping.generatedLine;
  42219. destMapping.generatedColumn = srcMapping.generatedColumn;
  42220. if (srcMapping.source) {
  42221. destMapping.source = sources.indexOf(srcMapping.source);
  42222. destMapping.originalLine = srcMapping.originalLine;
  42223. destMapping.originalColumn = srcMapping.originalColumn;
  42224. if (srcMapping.name) {
  42225. destMapping.name = names.indexOf(srcMapping.name);
  42226. }
  42227. destOriginalMappings.push(destMapping);
  42228. }
  42229. destGeneratedMappings.push(destMapping);
  42230. }
  42231. quickSort(smc.__originalMappings, util.compareByOriginalPositions);
  42232. return smc;
  42233. };
  42234. /**
  42235. * The version of the source mapping spec that we are consuming.
  42236. */
  42237. BasicSourceMapConsumer.prototype._version = 3;
  42238. /**
  42239. * The list of original sources.
  42240. */
  42241. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  42242. get: function () {
  42243. return this._absoluteSources.slice();
  42244. }
  42245. });
  42246. /**
  42247. * Provide the JIT with a nice shape / hidden class.
  42248. */
  42249. function Mapping() {
  42250. this.generatedLine = 0;
  42251. this.generatedColumn = 0;
  42252. this.source = null;
  42253. this.originalLine = null;
  42254. this.originalColumn = null;
  42255. this.name = null;
  42256. }
  42257. /**
  42258. * Parse the mappings in a string in to a data structure which we can easily
  42259. * query (the ordered arrays in the `this.__generatedMappings` and
  42260. * `this.__originalMappings` properties).
  42261. */
  42262. BasicSourceMapConsumer.prototype._parseMappings =
  42263. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42264. var generatedLine = 1;
  42265. var previousGeneratedColumn = 0;
  42266. var previousOriginalLine = 0;
  42267. var previousOriginalColumn = 0;
  42268. var previousSource = 0;
  42269. var previousName = 0;
  42270. var length = aStr.length;
  42271. var index = 0;
  42272. var cachedSegments = {};
  42273. var temp = {};
  42274. var originalMappings = [];
  42275. var generatedMappings = [];
  42276. var mapping, str, segment, end, value;
  42277. while (index < length) {
  42278. if (aStr.charAt(index) === ';') {
  42279. generatedLine++;
  42280. index++;
  42281. previousGeneratedColumn = 0;
  42282. }
  42283. else if (aStr.charAt(index) === ',') {
  42284. index++;
  42285. }
  42286. else {
  42287. mapping = new Mapping();
  42288. mapping.generatedLine = generatedLine;
  42289. // Because each offset is encoded relative to the previous one,
  42290. // many segments often have the same encoding. We can exploit this
  42291. // fact by caching the parsed variable length fields of each segment,
  42292. // allowing us to avoid a second parse if we encounter the same
  42293. // segment again.
  42294. for (end = index; end < length; end++) {
  42295. if (this._charIsMappingSeparator(aStr, end)) {
  42296. break;
  42297. }
  42298. }
  42299. str = aStr.slice(index, end);
  42300. segment = cachedSegments[str];
  42301. if (segment) {
  42302. index += str.length;
  42303. } else {
  42304. segment = [];
  42305. while (index < end) {
  42306. base64VLQ.decode(aStr, index, temp);
  42307. value = temp.value;
  42308. index = temp.rest;
  42309. segment.push(value);
  42310. }
  42311. if (segment.length === 2) {
  42312. throw new Error('Found a source, but no line and column');
  42313. }
  42314. if (segment.length === 3) {
  42315. throw new Error('Found a source and line, but no column');
  42316. }
  42317. cachedSegments[str] = segment;
  42318. }
  42319. // Generated column.
  42320. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  42321. previousGeneratedColumn = mapping.generatedColumn;
  42322. if (segment.length > 1) {
  42323. // Original source.
  42324. mapping.source = previousSource + segment[1];
  42325. previousSource += segment[1];
  42326. // Original line.
  42327. mapping.originalLine = previousOriginalLine + segment[2];
  42328. previousOriginalLine = mapping.originalLine;
  42329. // Lines are stored 0-based
  42330. mapping.originalLine += 1;
  42331. // Original column.
  42332. mapping.originalColumn = previousOriginalColumn + segment[3];
  42333. previousOriginalColumn = mapping.originalColumn;
  42334. if (segment.length > 4) {
  42335. // Original name.
  42336. mapping.name = previousName + segment[4];
  42337. previousName += segment[4];
  42338. }
  42339. }
  42340. generatedMappings.push(mapping);
  42341. if (typeof mapping.originalLine === 'number') {
  42342. originalMappings.push(mapping);
  42343. }
  42344. }
  42345. }
  42346. quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated);
  42347. this.__generatedMappings = generatedMappings;
  42348. quickSort(originalMappings, util.compareByOriginalPositions);
  42349. this.__originalMappings = originalMappings;
  42350. };
  42351. /**
  42352. * Find the mapping that best matches the hypothetical "needle" mapping that
  42353. * we are searching for in the given "haystack" of mappings.
  42354. */
  42355. BasicSourceMapConsumer.prototype._findMapping =
  42356. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  42357. aColumnName, aComparator, aBias) {
  42358. // To return the position we are searching for, we must first find the
  42359. // mapping for the given position and then return the opposite position it
  42360. // points to. Because the mappings are sorted, we can use binary search to
  42361. // find the best mapping.
  42362. if (aNeedle[aLineName] <= 0) {
  42363. throw new TypeError('Line must be greater than or equal to 1, got '
  42364. + aNeedle[aLineName]);
  42365. }
  42366. if (aNeedle[aColumnName] < 0) {
  42367. throw new TypeError('Column must be greater than or equal to 0, got '
  42368. + aNeedle[aColumnName]);
  42369. }
  42370. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  42371. };
  42372. /**
  42373. * Compute the last column for each generated mapping. The last column is
  42374. * inclusive.
  42375. */
  42376. BasicSourceMapConsumer.prototype.computeColumnSpans =
  42377. function SourceMapConsumer_computeColumnSpans() {
  42378. for (var index = 0; index < this._generatedMappings.length; ++index) {
  42379. var mapping = this._generatedMappings[index];
  42380. // Mappings do not contain a field for the last generated columnt. We
  42381. // can come up with an optimistic estimate, however, by assuming that
  42382. // mappings are contiguous (i.e. given two consecutive mappings, the
  42383. // first mapping ends where the second one starts).
  42384. if (index + 1 < this._generatedMappings.length) {
  42385. var nextMapping = this._generatedMappings[index + 1];
  42386. if (mapping.generatedLine === nextMapping.generatedLine) {
  42387. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  42388. continue;
  42389. }
  42390. }
  42391. // The last mapping for each line spans the entire line.
  42392. mapping.lastGeneratedColumn = Infinity;
  42393. }
  42394. };
  42395. /**
  42396. * Returns the original source, line, and column information for the generated
  42397. * source's line and column positions provided. The only argument is an object
  42398. * with the following properties:
  42399. *
  42400. * - line: The line number in the generated source. The line number
  42401. * is 1-based.
  42402. * - column: The column number in the generated source. The column
  42403. * number is 0-based.
  42404. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  42405. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  42406. * closest element that is smaller than or greater than the one we are
  42407. * searching for, respectively, if the exact element cannot be found.
  42408. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  42409. *
  42410. * and an object is returned with the following properties:
  42411. *
  42412. * - source: The original source file, or null.
  42413. * - line: The line number in the original source, or null. The
  42414. * line number is 1-based.
  42415. * - column: The column number in the original source, or null. The
  42416. * column number is 0-based.
  42417. * - name: The original identifier, or null.
  42418. */
  42419. BasicSourceMapConsumer.prototype.originalPositionFor =
  42420. function SourceMapConsumer_originalPositionFor(aArgs) {
  42421. var needle = {
  42422. generatedLine: util.getArg(aArgs, 'line'),
  42423. generatedColumn: util.getArg(aArgs, 'column')
  42424. };
  42425. var index = this._findMapping(
  42426. needle,
  42427. this._generatedMappings,
  42428. "generatedLine",
  42429. "generatedColumn",
  42430. util.compareByGeneratedPositionsDeflated,
  42431. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  42432. );
  42433. if (index >= 0) {
  42434. var mapping = this._generatedMappings[index];
  42435. if (mapping.generatedLine === needle.generatedLine) {
  42436. var source = util.getArg(mapping, 'source', null);
  42437. if (source !== null) {
  42438. source = this._sources.at(source);
  42439. source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  42440. }
  42441. var name = util.getArg(mapping, 'name', null);
  42442. if (name !== null) {
  42443. name = this._names.at(name);
  42444. }
  42445. return {
  42446. source: source,
  42447. line: util.getArg(mapping, 'originalLine', null),
  42448. column: util.getArg(mapping, 'originalColumn', null),
  42449. name: name
  42450. };
  42451. }
  42452. }
  42453. return {
  42454. source: null,
  42455. line: null,
  42456. column: null,
  42457. name: null
  42458. };
  42459. };
  42460. /**
  42461. * Return true if we have the source content for every source in the source
  42462. * map, false otherwise.
  42463. */
  42464. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  42465. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  42466. if (!this.sourcesContent) {
  42467. return false;
  42468. }
  42469. return this.sourcesContent.length >= this._sources.size() &&
  42470. !this.sourcesContent.some(function (sc) { return sc == null; });
  42471. };
  42472. /**
  42473. * Returns the original source content. The only argument is the url of the
  42474. * original source file. Returns null if no original source content is
  42475. * available.
  42476. */
  42477. BasicSourceMapConsumer.prototype.sourceContentFor =
  42478. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  42479. if (!this.sourcesContent) {
  42480. return null;
  42481. }
  42482. var index = this._findSourceIndex(aSource);
  42483. if (index >= 0) {
  42484. return this.sourcesContent[index];
  42485. }
  42486. var relativeSource = aSource;
  42487. if (this.sourceRoot != null) {
  42488. relativeSource = util.relative(this.sourceRoot, relativeSource);
  42489. }
  42490. var url;
  42491. if (this.sourceRoot != null
  42492. && (url = util.urlParse(this.sourceRoot))) {
  42493. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  42494. // many users. We can help them out when they expect file:// URIs to
  42495. // behave like it would if they were running a local HTTP server. See
  42496. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  42497. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  42498. if (url.scheme == "file"
  42499. && this._sources.has(fileUriAbsPath)) {
  42500. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  42501. }
  42502. if ((!url.path || url.path == "/")
  42503. && this._sources.has("/" + relativeSource)) {
  42504. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  42505. }
  42506. }
  42507. // This function is used recursively from
  42508. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  42509. // don't want to throw if we can't find the source - we just want to
  42510. // return null, so we provide a flag to exit gracefully.
  42511. if (nullOnMissing) {
  42512. return null;
  42513. }
  42514. else {
  42515. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  42516. }
  42517. };
  42518. /**
  42519. * Returns the generated line and column information for the original source,
  42520. * line, and column positions provided. The only argument is an object with
  42521. * the following properties:
  42522. *
  42523. * - source: The filename of the original source.
  42524. * - line: The line number in the original source. The line number
  42525. * is 1-based.
  42526. * - column: The column number in the original source. The column
  42527. * number is 0-based.
  42528. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  42529. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  42530. * closest element that is smaller than or greater than the one we are
  42531. * searching for, respectively, if the exact element cannot be found.
  42532. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  42533. *
  42534. * and an object is returned with the following properties:
  42535. *
  42536. * - line: The line number in the generated source, or null. The
  42537. * line number is 1-based.
  42538. * - column: The column number in the generated source, or null.
  42539. * The column number is 0-based.
  42540. */
  42541. BasicSourceMapConsumer.prototype.generatedPositionFor =
  42542. function SourceMapConsumer_generatedPositionFor(aArgs) {
  42543. var source = util.getArg(aArgs, 'source');
  42544. source = this._findSourceIndex(source);
  42545. if (source < 0) {
  42546. return {
  42547. line: null,
  42548. column: null,
  42549. lastColumn: null
  42550. };
  42551. }
  42552. var needle = {
  42553. source: source,
  42554. originalLine: util.getArg(aArgs, 'line'),
  42555. originalColumn: util.getArg(aArgs, 'column')
  42556. };
  42557. var index = this._findMapping(
  42558. needle,
  42559. this._originalMappings,
  42560. "originalLine",
  42561. "originalColumn",
  42562. util.compareByOriginalPositions,
  42563. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  42564. );
  42565. if (index >= 0) {
  42566. var mapping = this._originalMappings[index];
  42567. if (mapping.source === needle.source) {
  42568. return {
  42569. line: util.getArg(mapping, 'generatedLine', null),
  42570. column: util.getArg(mapping, 'generatedColumn', null),
  42571. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42572. };
  42573. }
  42574. }
  42575. return {
  42576. line: null,
  42577. column: null,
  42578. lastColumn: null
  42579. };
  42580. };
  42581. sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
  42582. /**
  42583. * An IndexedSourceMapConsumer instance represents a parsed source map which
  42584. * we can query for information. It differs from BasicSourceMapConsumer in
  42585. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  42586. * input.
  42587. *
  42588. * The first parameter is a raw source map (either as a JSON string, or already
  42589. * parsed to an object). According to the spec for indexed source maps, they
  42590. * have the following attributes:
  42591. *
  42592. * - version: Which version of the source map spec this map is following.
  42593. * - file: Optional. The generated file this source map is associated with.
  42594. * - sections: A list of section definitions.
  42595. *
  42596. * Each value under the "sections" field has two fields:
  42597. * - offset: The offset into the original specified at which this section
  42598. * begins to apply, defined as an object with a "line" and "column"
  42599. * field.
  42600. * - map: A source map definition. This source map could also be indexed,
  42601. * but doesn't have to be.
  42602. *
  42603. * Instead of the "map" field, it's also possible to have a "url" field
  42604. * specifying a URL to retrieve a source map from, but that's currently
  42605. * unsupported.
  42606. *
  42607. * Here's an example source map, taken from the source map spec[0], but
  42608. * modified to omit a section which uses the "url" field.
  42609. *
  42610. * {
  42611. * version : 3,
  42612. * file: "app.js",
  42613. * sections: [{
  42614. * offset: {line:100, column:10},
  42615. * map: {
  42616. * version : 3,
  42617. * file: "section.js",
  42618. * sources: ["foo.js", "bar.js"],
  42619. * names: ["src", "maps", "are", "fun"],
  42620. * mappings: "AAAA,E;;ABCDE;"
  42621. * }
  42622. * }],
  42623. * }
  42624. *
  42625. * The second parameter, if given, is a string whose value is the URL
  42626. * at which the source map was found. This URL is used to compute the
  42627. * sources array.
  42628. *
  42629. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  42630. */
  42631. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  42632. var sourceMap = aSourceMap;
  42633. if (typeof aSourceMap === 'string') {
  42634. sourceMap = util.parseSourceMapInput(aSourceMap);
  42635. }
  42636. var version = util.getArg(sourceMap, 'version');
  42637. var sections = util.getArg(sourceMap, 'sections');
  42638. if (version != this._version) {
  42639. throw new Error('Unsupported version: ' + version);
  42640. }
  42641. this._sources = new ArraySet();
  42642. this._names = new ArraySet();
  42643. var lastOffset = {
  42644. line: -1,
  42645. column: 0
  42646. };
  42647. this._sections = sections.map(function (s) {
  42648. if (s.url) {
  42649. // The url field will require support for asynchronicity.
  42650. // See https://github.com/mozilla/source-map/issues/16
  42651. throw new Error('Support for url field in sections not implemented.');
  42652. }
  42653. var offset = util.getArg(s, 'offset');
  42654. var offsetLine = util.getArg(offset, 'line');
  42655. var offsetColumn = util.getArg(offset, 'column');
  42656. if (offsetLine < lastOffset.line ||
  42657. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  42658. throw new Error('Section offsets must be ordered and non-overlapping.');
  42659. }
  42660. lastOffset = offset;
  42661. return {
  42662. generatedOffset: {
  42663. // The offset fields are 0-based, but we use 1-based indices when
  42664. // encoding/decoding from VLQ.
  42665. generatedLine: offsetLine + 1,
  42666. generatedColumn: offsetColumn + 1
  42667. },
  42668. consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
  42669. }
  42670. });
  42671. }
  42672. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  42673. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
  42674. /**
  42675. * The version of the source mapping spec that we are consuming.
  42676. */
  42677. IndexedSourceMapConsumer.prototype._version = 3;
  42678. /**
  42679. * The list of original sources.
  42680. */
  42681. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  42682. get: function () {
  42683. var sources = [];
  42684. for (var i = 0; i < this._sections.length; i++) {
  42685. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  42686. sources.push(this._sections[i].consumer.sources[j]);
  42687. }
  42688. }
  42689. return sources;
  42690. }
  42691. });
  42692. /**
  42693. * Returns the original source, line, and column information for the generated
  42694. * source's line and column positions provided. The only argument is an object
  42695. * with the following properties:
  42696. *
  42697. * - line: The line number in the generated source. The line number
  42698. * is 1-based.
  42699. * - column: The column number in the generated source. The column
  42700. * number is 0-based.
  42701. *
  42702. * and an object is returned with the following properties:
  42703. *
  42704. * - source: The original source file, or null.
  42705. * - line: The line number in the original source, or null. The
  42706. * line number is 1-based.
  42707. * - column: The column number in the original source, or null. The
  42708. * column number is 0-based.
  42709. * - name: The original identifier, or null.
  42710. */
  42711. IndexedSourceMapConsumer.prototype.originalPositionFor =
  42712. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  42713. var needle = {
  42714. generatedLine: util.getArg(aArgs, 'line'),
  42715. generatedColumn: util.getArg(aArgs, 'column')
  42716. };
  42717. // Find the section containing the generated position we're trying to map
  42718. // to an original position.
  42719. var sectionIndex = binarySearch.search(needle, this._sections,
  42720. function(needle, section) {
  42721. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  42722. if (cmp) {
  42723. return cmp;
  42724. }
  42725. return (needle.generatedColumn -
  42726. section.generatedOffset.generatedColumn);
  42727. });
  42728. var section = this._sections[sectionIndex];
  42729. if (!section) {
  42730. return {
  42731. source: null,
  42732. line: null,
  42733. column: null,
  42734. name: null
  42735. };
  42736. }
  42737. return section.consumer.originalPositionFor({
  42738. line: needle.generatedLine -
  42739. (section.generatedOffset.generatedLine - 1),
  42740. column: needle.generatedColumn -
  42741. (section.generatedOffset.generatedLine === needle.generatedLine
  42742. ? section.generatedOffset.generatedColumn - 1
  42743. : 0),
  42744. bias: aArgs.bias
  42745. });
  42746. };
  42747. /**
  42748. * Return true if we have the source content for every source in the source
  42749. * map, false otherwise.
  42750. */
  42751. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  42752. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  42753. return this._sections.every(function (s) {
  42754. return s.consumer.hasContentsOfAllSources();
  42755. });
  42756. };
  42757. /**
  42758. * Returns the original source content. The only argument is the url of the
  42759. * original source file. Returns null if no original source content is
  42760. * available.
  42761. */
  42762. IndexedSourceMapConsumer.prototype.sourceContentFor =
  42763. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  42764. for (var i = 0; i < this._sections.length; i++) {
  42765. var section = this._sections[i];
  42766. var content = section.consumer.sourceContentFor(aSource, true);
  42767. if (content) {
  42768. return content;
  42769. }
  42770. }
  42771. if (nullOnMissing) {
  42772. return null;
  42773. }
  42774. else {
  42775. throw new Error('"' + aSource + '" is not in the SourceMap.');
  42776. }
  42777. };
  42778. /**
  42779. * Returns the generated line and column information for the original source,
  42780. * line, and column positions provided. The only argument is an object with
  42781. * the following properties:
  42782. *
  42783. * - source: The filename of the original source.
  42784. * - line: The line number in the original source. The line number
  42785. * is 1-based.
  42786. * - column: The column number in the original source. The column
  42787. * number is 0-based.
  42788. *
  42789. * and an object is returned with the following properties:
  42790. *
  42791. * - line: The line number in the generated source, or null. The
  42792. * line number is 1-based.
  42793. * - column: The column number in the generated source, or null.
  42794. * The column number is 0-based.
  42795. */
  42796. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  42797. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  42798. for (var i = 0; i < this._sections.length; i++) {
  42799. var section = this._sections[i];
  42800. // Only consider this section if the requested source is in the list of
  42801. // sources of the consumer.
  42802. if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
  42803. continue;
  42804. }
  42805. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  42806. if (generatedPosition) {
  42807. var ret = {
  42808. line: generatedPosition.line +
  42809. (section.generatedOffset.generatedLine - 1),
  42810. column: generatedPosition.column +
  42811. (section.generatedOffset.generatedLine === generatedPosition.line
  42812. ? section.generatedOffset.generatedColumn - 1
  42813. : 0)
  42814. };
  42815. return ret;
  42816. }
  42817. }
  42818. return {
  42819. line: null,
  42820. column: null
  42821. };
  42822. };
  42823. /**
  42824. * Parse the mappings in a string in to a data structure which we can easily
  42825. * query (the ordered arrays in the `this.__generatedMappings` and
  42826. * `this.__originalMappings` properties).
  42827. */
  42828. IndexedSourceMapConsumer.prototype._parseMappings =
  42829. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42830. this.__generatedMappings = [];
  42831. this.__originalMappings = [];
  42832. for (var i = 0; i < this._sections.length; i++) {
  42833. var section = this._sections[i];
  42834. var sectionMappings = section.consumer._generatedMappings;
  42835. for (var j = 0; j < sectionMappings.length; j++) {
  42836. var mapping = sectionMappings[j];
  42837. var source = section.consumer._sources.at(mapping.source);
  42838. source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  42839. this._sources.add(source);
  42840. source = this._sources.indexOf(source);
  42841. var name = null;
  42842. if (mapping.name) {
  42843. name = section.consumer._names.at(mapping.name);
  42844. this._names.add(name);
  42845. name = this._names.indexOf(name);
  42846. }
  42847. // The mappings coming from the consumer for the section have
  42848. // generated positions relative to the start of the section, so we
  42849. // need to offset them to be relative to the start of the concatenated
  42850. // generated file.
  42851. var adjustedMapping = {
  42852. source: source,
  42853. generatedLine: mapping.generatedLine +
  42854. (section.generatedOffset.generatedLine - 1),
  42855. generatedColumn: mapping.generatedColumn +
  42856. (section.generatedOffset.generatedLine === mapping.generatedLine
  42857. ? section.generatedOffset.generatedColumn - 1
  42858. : 0),
  42859. originalLine: mapping.originalLine,
  42860. originalColumn: mapping.originalColumn,
  42861. name: name
  42862. };
  42863. this.__generatedMappings.push(adjustedMapping);
  42864. if (typeof adjustedMapping.originalLine === 'number') {
  42865. this.__originalMappings.push(adjustedMapping);
  42866. }
  42867. }
  42868. }
  42869. quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
  42870. quickSort(this.__originalMappings, util.compareByOriginalPositions);
  42871. };
  42872. sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  42873. return sourceMapConsumer;
  42874. }
  42875. var sourceNode = {};
  42876. /* -*- Mode: js; js-indent-level: 2; -*- */
  42877. var hasRequiredSourceNode;
  42878. function requireSourceNode () {
  42879. if (hasRequiredSourceNode) return sourceNode;
  42880. hasRequiredSourceNode = 1;
  42881. /*
  42882. * Copyright 2011 Mozilla Foundation and contributors
  42883. * Licensed under the New BSD license. See LICENSE or:
  42884. * http://opensource.org/licenses/BSD-3-Clause
  42885. */
  42886. var SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator().SourceMapGenerator;
  42887. var util = /*@__PURE__*/ requireUtil();
  42888. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  42889. // operating systems these days (capturing the result).
  42890. var REGEX_NEWLINE = /(\r?\n)/;
  42891. // Newline character code for charCodeAt() comparisons
  42892. var NEWLINE_CODE = 10;
  42893. // Private symbol for identifying `SourceNode`s when multiple versions of
  42894. // the source-map library are loaded. This MUST NOT CHANGE across
  42895. // versions!
  42896. var isSourceNode = "$$$isSourceNode$$$";
  42897. /**
  42898. * SourceNodes provide a way to abstract over interpolating/concatenating
  42899. * snippets of generated JavaScript source code while maintaining the line and
  42900. * column information associated with the original source code.
  42901. *
  42902. * @param aLine The original line number.
  42903. * @param aColumn The original column number.
  42904. * @param aSource The original source's filename.
  42905. * @param aChunks Optional. An array of strings which are snippets of
  42906. * generated JS, or other SourceNodes.
  42907. * @param aName The original identifier.
  42908. */
  42909. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  42910. this.children = [];
  42911. this.sourceContents = {};
  42912. this.line = aLine == null ? null : aLine;
  42913. this.column = aColumn == null ? null : aColumn;
  42914. this.source = aSource == null ? null : aSource;
  42915. this.name = aName == null ? null : aName;
  42916. this[isSourceNode] = true;
  42917. if (aChunks != null) this.add(aChunks);
  42918. }
  42919. /**
  42920. * Creates a SourceNode from generated code and a SourceMapConsumer.
  42921. *
  42922. * @param aGeneratedCode The generated code
  42923. * @param aSourceMapConsumer The SourceMap for the generated code
  42924. * @param aRelativePath Optional. The path that relative sources in the
  42925. * SourceMapConsumer should be relative to.
  42926. */
  42927. SourceNode.fromStringWithSourceMap =
  42928. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  42929. // The SourceNode we want to fill with the generated code
  42930. // and the SourceMap
  42931. var node = new SourceNode();
  42932. // All even indices of this array are one line of the generated code,
  42933. // while all odd indices are the newlines between two adjacent lines
  42934. // (since `REGEX_NEWLINE` captures its match).
  42935. // Processed fragments are accessed by calling `shiftNextLine`.
  42936. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  42937. var remainingLinesIndex = 0;
  42938. var shiftNextLine = function() {
  42939. var lineContents = getNextLine();
  42940. // The last line of a file might not have a newline.
  42941. var newLine = getNextLine() || "";
  42942. return lineContents + newLine;
  42943. function getNextLine() {
  42944. return remainingLinesIndex < remainingLines.length ?
  42945. remainingLines[remainingLinesIndex++] : undefined;
  42946. }
  42947. };
  42948. // We need to remember the position of "remainingLines"
  42949. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  42950. // The generate SourceNodes we need a code range.
  42951. // To extract it current and last mapping is used.
  42952. // Here we store the last mapping.
  42953. var lastMapping = null;
  42954. aSourceMapConsumer.eachMapping(function (mapping) {
  42955. if (lastMapping !== null) {
  42956. // We add the code from "lastMapping" to "mapping":
  42957. // First check if there is a new line in between.
  42958. if (lastGeneratedLine < mapping.generatedLine) {
  42959. // Associate first line with "lastMapping"
  42960. addMappingWithCode(lastMapping, shiftNextLine());
  42961. lastGeneratedLine++;
  42962. lastGeneratedColumn = 0;
  42963. // The remaining code is added without mapping
  42964. } else {
  42965. // There is no new line in between.
  42966. // Associate the code between "lastGeneratedColumn" and
  42967. // "mapping.generatedColumn" with "lastMapping"
  42968. var nextLine = remainingLines[remainingLinesIndex] || '';
  42969. var code = nextLine.substr(0, mapping.generatedColumn -
  42970. lastGeneratedColumn);
  42971. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  42972. lastGeneratedColumn);
  42973. lastGeneratedColumn = mapping.generatedColumn;
  42974. addMappingWithCode(lastMapping, code);
  42975. // No more remaining code, continue
  42976. lastMapping = mapping;
  42977. return;
  42978. }
  42979. }
  42980. // We add the generated code until the first mapping
  42981. // to the SourceNode without any mapping.
  42982. // Each line is added as separate string.
  42983. while (lastGeneratedLine < mapping.generatedLine) {
  42984. node.add(shiftNextLine());
  42985. lastGeneratedLine++;
  42986. }
  42987. if (lastGeneratedColumn < mapping.generatedColumn) {
  42988. var nextLine = remainingLines[remainingLinesIndex] || '';
  42989. node.add(nextLine.substr(0, mapping.generatedColumn));
  42990. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  42991. lastGeneratedColumn = mapping.generatedColumn;
  42992. }
  42993. lastMapping = mapping;
  42994. }, this);
  42995. // We have processed all mappings.
  42996. if (remainingLinesIndex < remainingLines.length) {
  42997. if (lastMapping) {
  42998. // Associate the remaining code in the current line with "lastMapping"
  42999. addMappingWithCode(lastMapping, shiftNextLine());
  43000. }
  43001. // and add the remaining lines without any mapping
  43002. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  43003. }
  43004. // Copy sourcesContent into SourceNode
  43005. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  43006. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  43007. if (content != null) {
  43008. if (aRelativePath != null) {
  43009. sourceFile = util.join(aRelativePath, sourceFile);
  43010. }
  43011. node.setSourceContent(sourceFile, content);
  43012. }
  43013. });
  43014. return node;
  43015. function addMappingWithCode(mapping, code) {
  43016. if (mapping === null || mapping.source === undefined) {
  43017. node.add(code);
  43018. } else {
  43019. var source = aRelativePath
  43020. ? util.join(aRelativePath, mapping.source)
  43021. : mapping.source;
  43022. node.add(new SourceNode(mapping.originalLine,
  43023. mapping.originalColumn,
  43024. source,
  43025. code,
  43026. mapping.name));
  43027. }
  43028. }
  43029. };
  43030. /**
  43031. * Add a chunk of generated JS to this source node.
  43032. *
  43033. * @param aChunk A string snippet of generated JS code, another instance of
  43034. * SourceNode, or an array where each member is one of those things.
  43035. */
  43036. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  43037. if (Array.isArray(aChunk)) {
  43038. aChunk.forEach(function (chunk) {
  43039. this.add(chunk);
  43040. }, this);
  43041. }
  43042. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  43043. if (aChunk) {
  43044. this.children.push(aChunk);
  43045. }
  43046. }
  43047. else {
  43048. throw new TypeError(
  43049. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  43050. );
  43051. }
  43052. return this;
  43053. };
  43054. /**
  43055. * Add a chunk of generated JS to the beginning of this source node.
  43056. *
  43057. * @param aChunk A string snippet of generated JS code, another instance of
  43058. * SourceNode, or an array where each member is one of those things.
  43059. */
  43060. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  43061. if (Array.isArray(aChunk)) {
  43062. for (var i = aChunk.length-1; i >= 0; i--) {
  43063. this.prepend(aChunk[i]);
  43064. }
  43065. }
  43066. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  43067. this.children.unshift(aChunk);
  43068. }
  43069. else {
  43070. throw new TypeError(
  43071. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  43072. );
  43073. }
  43074. return this;
  43075. };
  43076. /**
  43077. * Walk over the tree of JS snippets in this node and its children. The
  43078. * walking function is called once for each snippet of JS and is passed that
  43079. * snippet and the its original associated source's line/column location.
  43080. *
  43081. * @param aFn The traversal function.
  43082. */
  43083. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  43084. var chunk;
  43085. for (var i = 0, len = this.children.length; i < len; i++) {
  43086. chunk = this.children[i];
  43087. if (chunk[isSourceNode]) {
  43088. chunk.walk(aFn);
  43089. }
  43090. else {
  43091. if (chunk !== '') {
  43092. aFn(chunk, { source: this.source,
  43093. line: this.line,
  43094. column: this.column,
  43095. name: this.name });
  43096. }
  43097. }
  43098. }
  43099. };
  43100. /**
  43101. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  43102. * each of `this.children`.
  43103. *
  43104. * @param aSep The separator.
  43105. */
  43106. SourceNode.prototype.join = function SourceNode_join(aSep) {
  43107. var newChildren;
  43108. var i;
  43109. var len = this.children.length;
  43110. if (len > 0) {
  43111. newChildren = [];
  43112. for (i = 0; i < len-1; i++) {
  43113. newChildren.push(this.children[i]);
  43114. newChildren.push(aSep);
  43115. }
  43116. newChildren.push(this.children[i]);
  43117. this.children = newChildren;
  43118. }
  43119. return this;
  43120. };
  43121. /**
  43122. * Call String.prototype.replace on the very right-most source snippet. Useful
  43123. * for trimming whitespace from the end of a source node, etc.
  43124. *
  43125. * @param aPattern The pattern to replace.
  43126. * @param aReplacement The thing to replace the pattern with.
  43127. */
  43128. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  43129. var lastChild = this.children[this.children.length - 1];
  43130. if (lastChild[isSourceNode]) {
  43131. lastChild.replaceRight(aPattern, aReplacement);
  43132. }
  43133. else if (typeof lastChild === 'string') {
  43134. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  43135. }
  43136. else {
  43137. this.children.push(''.replace(aPattern, aReplacement));
  43138. }
  43139. return this;
  43140. };
  43141. /**
  43142. * Set the source content for a source file. This will be added to the SourceMapGenerator
  43143. * in the sourcesContent field.
  43144. *
  43145. * @param aSourceFile The filename of the source file
  43146. * @param aSourceContent The content of the source file
  43147. */
  43148. SourceNode.prototype.setSourceContent =
  43149. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  43150. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  43151. };
  43152. /**
  43153. * Walk over the tree of SourceNodes. The walking function is called for each
  43154. * source file content and is passed the filename and source content.
  43155. *
  43156. * @param aFn The traversal function.
  43157. */
  43158. SourceNode.prototype.walkSourceContents =
  43159. function SourceNode_walkSourceContents(aFn) {
  43160. for (var i = 0, len = this.children.length; i < len; i++) {
  43161. if (this.children[i][isSourceNode]) {
  43162. this.children[i].walkSourceContents(aFn);
  43163. }
  43164. }
  43165. var sources = Object.keys(this.sourceContents);
  43166. for (var i = 0, len = sources.length; i < len; i++) {
  43167. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  43168. }
  43169. };
  43170. /**
  43171. * Return the string representation of this source node. Walks over the tree
  43172. * and concatenates all the various snippets together to one string.
  43173. */
  43174. SourceNode.prototype.toString = function SourceNode_toString() {
  43175. var str = "";
  43176. this.walk(function (chunk) {
  43177. str += chunk;
  43178. });
  43179. return str;
  43180. };
  43181. /**
  43182. * Returns the string representation of this source node along with a source
  43183. * map.
  43184. */
  43185. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  43186. var generated = {
  43187. code: "",
  43188. line: 1,
  43189. column: 0
  43190. };
  43191. var map = new SourceMapGenerator(aArgs);
  43192. var sourceMappingActive = false;
  43193. var lastOriginalSource = null;
  43194. var lastOriginalLine = null;
  43195. var lastOriginalColumn = null;
  43196. var lastOriginalName = null;
  43197. this.walk(function (chunk, original) {
  43198. generated.code += chunk;
  43199. if (original.source !== null
  43200. && original.line !== null
  43201. && original.column !== null) {
  43202. if(lastOriginalSource !== original.source
  43203. || lastOriginalLine !== original.line
  43204. || lastOriginalColumn !== original.column
  43205. || lastOriginalName !== original.name) {
  43206. map.addMapping({
  43207. source: original.source,
  43208. original: {
  43209. line: original.line,
  43210. column: original.column
  43211. },
  43212. generated: {
  43213. line: generated.line,
  43214. column: generated.column
  43215. },
  43216. name: original.name
  43217. });
  43218. }
  43219. lastOriginalSource = original.source;
  43220. lastOriginalLine = original.line;
  43221. lastOriginalColumn = original.column;
  43222. lastOriginalName = original.name;
  43223. sourceMappingActive = true;
  43224. } else if (sourceMappingActive) {
  43225. map.addMapping({
  43226. generated: {
  43227. line: generated.line,
  43228. column: generated.column
  43229. }
  43230. });
  43231. lastOriginalSource = null;
  43232. sourceMappingActive = false;
  43233. }
  43234. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  43235. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  43236. generated.line++;
  43237. generated.column = 0;
  43238. // Mappings end at eol
  43239. if (idx + 1 === length) {
  43240. lastOriginalSource = null;
  43241. sourceMappingActive = false;
  43242. } else if (sourceMappingActive) {
  43243. map.addMapping({
  43244. source: original.source,
  43245. original: {
  43246. line: original.line,
  43247. column: original.column
  43248. },
  43249. generated: {
  43250. line: generated.line,
  43251. column: generated.column
  43252. },
  43253. name: original.name
  43254. });
  43255. }
  43256. } else {
  43257. generated.column++;
  43258. }
  43259. }
  43260. });
  43261. this.walkSourceContents(function (sourceFile, sourceContent) {
  43262. map.setSourceContent(sourceFile, sourceContent);
  43263. });
  43264. return { code: generated.code, map: map };
  43265. };
  43266. sourceNode.SourceNode = SourceNode;
  43267. return sourceNode;
  43268. }
  43269. /*
  43270. * Copyright 2009-2011 Mozilla Foundation and contributors
  43271. * Licensed under the New BSD license. See LICENSE.txt or:
  43272. * http://opensource.org/licenses/BSD-3-Clause
  43273. */
  43274. var hasRequiredSourceMap;
  43275. function requireSourceMap () {
  43276. if (hasRequiredSourceMap) return sourceMap;
  43277. hasRequiredSourceMap = 1;
  43278. sourceMap.SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator().SourceMapGenerator;
  43279. sourceMap.SourceMapConsumer = /*@__PURE__*/ requireSourceMapConsumer().SourceMapConsumer;
  43280. sourceMap.SourceNode = /*@__PURE__*/ requireSourceNode().SourceNode;
  43281. return sourceMap;
  43282. }
  43283. var mergeSourceMap;
  43284. var hasRequiredMergeSourceMap;
  43285. function requireMergeSourceMap () {
  43286. if (hasRequiredMergeSourceMap) return mergeSourceMap;
  43287. hasRequiredMergeSourceMap = 1;
  43288. var sourceMap = /*@__PURE__*/ requireSourceMap();
  43289. var SourceMapConsumer = sourceMap.SourceMapConsumer;
  43290. var SourceMapGenerator = sourceMap.SourceMapGenerator;
  43291. mergeSourceMap = merge;
  43292. /**
  43293. * Merge old source map and new source map and return merged.
  43294. * If old or new source map value is falsy, return another one as it is.
  43295. *
  43296. * @param {object|string} [oldMap] old source map object
  43297. * @param {object|string} [newmap] new source map object
  43298. * @return {object|undefined} merged source map object, or undefined when both old and new source map are undefined
  43299. */
  43300. function merge(oldMap, newMap) {
  43301. if (!oldMap) return newMap
  43302. if (!newMap) return oldMap
  43303. var oldMapConsumer = new SourceMapConsumer(oldMap);
  43304. var newMapConsumer = new SourceMapConsumer(newMap);
  43305. var mergedMapGenerator = new SourceMapGenerator();
  43306. // iterate on new map and overwrite original position of new map with one of old map
  43307. newMapConsumer.eachMapping(function(m) {
  43308. // pass when `originalLine` is null.
  43309. // It occurs in case that the node does not have origin in original code.
  43310. if (m.originalLine == null) return
  43311. var origPosInOldMap = oldMapConsumer.originalPositionFor({
  43312. line: m.originalLine,
  43313. column: m.originalColumn
  43314. });
  43315. if (origPosInOldMap.source == null) return
  43316. mergedMapGenerator.addMapping({
  43317. original: {
  43318. line: origPosInOldMap.line,
  43319. column: origPosInOldMap.column
  43320. },
  43321. generated: {
  43322. line: m.generatedLine,
  43323. column: m.generatedColumn
  43324. },
  43325. source: origPosInOldMap.source,
  43326. name: origPosInOldMap.name
  43327. });
  43328. });
  43329. var consumers = [oldMapConsumer, newMapConsumer];
  43330. consumers.forEach(function(consumer) {
  43331. consumer.sources.forEach(function(sourceFile) {
  43332. mergedMapGenerator._sources.add(sourceFile);
  43333. var sourceContent = consumer.sourceContentFor(sourceFile);
  43334. if (sourceContent != null) {
  43335. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  43336. }
  43337. });
  43338. });
  43339. mergedMapGenerator._sourceRoot = oldMap.sourceRoot;
  43340. mergedMapGenerator._file = oldMap.file;
  43341. return JSON.parse(mergedMapGenerator.toString())
  43342. }
  43343. return mergeSourceMap;
  43344. }
  43345. var mergeSourceMapExports = /*@__PURE__*/ requireMergeSourceMap();
  43346. var merge = /*@__PURE__*/getDefaultExportFromCjs(mergeSourceMapExports);
  43347. var __defProp$5 = Object.defineProperty;
  43348. var __defProps$4 = Object.defineProperties;
  43349. var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
  43350. var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
  43351. var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
  43352. var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
  43353. var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43354. var __spreadValues$5 = (a, b) => {
  43355. for (var prop in b || (b = {}))
  43356. if (__hasOwnProp$5.call(b, prop))
  43357. __defNormalProp$5(a, prop, b[prop]);
  43358. if (__getOwnPropSymbols$5)
  43359. for (var prop of __getOwnPropSymbols$5(b)) {
  43360. if (__propIsEnum$5.call(b, prop))
  43361. __defNormalProp$5(a, prop, b[prop]);
  43362. }
  43363. return a;
  43364. };
  43365. var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
  43366. const scss = (source, map, options, load = require) => {
  43367. const nodeSass = load("sass");
  43368. const { compileString, renderSync } = nodeSass;
  43369. const data = getSource(source, options.filename, options.additionalData);
  43370. let css;
  43371. let dependencies;
  43372. let sourceMap;
  43373. try {
  43374. if (compileString) {
  43375. const { pathToFileURL, fileURLToPath } = load("url");
  43376. const result = compileString(data, __spreadProps$4(__spreadValues$5({}, options), {
  43377. url: pathToFileURL(options.filename),
  43378. sourceMap: !!map
  43379. }));
  43380. css = result.css;
  43381. dependencies = result.loadedUrls.map((url) => fileURLToPath(url));
  43382. sourceMap = map ? result.sourceMap : void 0;
  43383. } else {
  43384. const result = renderSync(__spreadProps$4(__spreadValues$5({}, options), {
  43385. data,
  43386. file: options.filename,
  43387. outFile: options.filename,
  43388. sourceMap: !!map
  43389. }));
  43390. css = result.css.toString();
  43391. dependencies = result.stats.includedFiles;
  43392. sourceMap = map ? JSON.parse(result.map.toString()) : void 0;
  43393. }
  43394. if (map) {
  43395. return {
  43396. code: css,
  43397. errors: [],
  43398. dependencies,
  43399. map: merge(map, sourceMap)
  43400. };
  43401. }
  43402. return { code: css, errors: [], dependencies };
  43403. } catch (e) {
  43404. return { code: "", errors: [e], dependencies: [] };
  43405. }
  43406. };
  43407. const sass = (source, map, options, load) => scss(
  43408. source,
  43409. map,
  43410. __spreadProps$4(__spreadValues$5({}, options), {
  43411. indentedSyntax: true
  43412. }),
  43413. load
  43414. );
  43415. const less = (source, map, options, load = require) => {
  43416. const nodeLess = load("less");
  43417. let result;
  43418. let error = null;
  43419. nodeLess.render(
  43420. getSource(source, options.filename, options.additionalData),
  43421. __spreadProps$4(__spreadValues$5({}, options), { syncImport: true }),
  43422. (err, output) => {
  43423. error = err;
  43424. result = output;
  43425. }
  43426. );
  43427. if (error) return { code: "", errors: [error], dependencies: [] };
  43428. const dependencies = result.imports;
  43429. if (map) {
  43430. return {
  43431. code: result.css.toString(),
  43432. map: merge(map, result.map),
  43433. errors: [],
  43434. dependencies
  43435. };
  43436. }
  43437. return {
  43438. code: result.css.toString(),
  43439. errors: [],
  43440. dependencies
  43441. };
  43442. };
  43443. const styl = (source, map, options, load = require) => {
  43444. const nodeStylus = load("stylus");
  43445. try {
  43446. const ref = nodeStylus(source, options);
  43447. if (map) ref.set("sourcemap", { inline: false, comment: false });
  43448. const result = ref.render();
  43449. const dependencies = ref.deps();
  43450. if (map) {
  43451. return {
  43452. code: result,
  43453. map: merge(map, ref.sourcemap),
  43454. errors: [],
  43455. dependencies
  43456. };
  43457. }
  43458. return { code: result, errors: [], dependencies };
  43459. } catch (e) {
  43460. return { code: "", errors: [e], dependencies: [] };
  43461. }
  43462. };
  43463. function getSource(source, filename, additionalData) {
  43464. if (!additionalData) return source;
  43465. if (isFunction$1(additionalData)) {
  43466. return additionalData(source, filename);
  43467. }
  43468. return additionalData + source;
  43469. }
  43470. const processors = {
  43471. less,
  43472. sass,
  43473. scss,
  43474. styl,
  43475. stylus: styl
  43476. };
  43477. var __defProp$4 = Object.defineProperty;
  43478. var __defProps$3 = Object.defineProperties;
  43479. var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
  43480. var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
  43481. var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
  43482. var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
  43483. var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43484. var __spreadValues$4 = (a, b) => {
  43485. for (var prop in b || (b = {}))
  43486. if (__hasOwnProp$4.call(b, prop))
  43487. __defNormalProp$4(a, prop, b[prop]);
  43488. if (__getOwnPropSymbols$4)
  43489. for (var prop of __getOwnPropSymbols$4(b)) {
  43490. if (__propIsEnum$4.call(b, prop))
  43491. __defNormalProp$4(a, prop, b[prop]);
  43492. }
  43493. return a;
  43494. };
  43495. var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
  43496. function compileStyle(options) {
  43497. return doCompileStyle(__spreadProps$3(__spreadValues$4({}, options), {
  43498. isAsync: false
  43499. }));
  43500. }
  43501. function compileStyleAsync(options) {
  43502. return doCompileStyle(__spreadProps$3(__spreadValues$4({}, options), {
  43503. isAsync: true
  43504. }));
  43505. }
  43506. function doCompileStyle(options) {
  43507. const {
  43508. filename,
  43509. id,
  43510. scoped = false,
  43511. trim = true,
  43512. isProd = false,
  43513. modules = false,
  43514. modulesOptions = {},
  43515. preprocessLang,
  43516. postcssOptions,
  43517. postcssPlugins
  43518. } = options;
  43519. const preprocessor = preprocessLang && processors[preprocessLang];
  43520. const preProcessedSource = preprocessor && preprocess(options, preprocessor);
  43521. const map = preProcessedSource ? preProcessedSource.map : options.inMap || options.map;
  43522. const source = preProcessedSource ? preProcessedSource.code : options.source;
  43523. const shortId = id.replace(/^data-v-/, "");
  43524. const longId = `data-v-${shortId}`;
  43525. const plugins = (postcssPlugins || []).slice();
  43526. plugins.unshift(cssVarsPlugin({ id: shortId, isProd }));
  43527. if (trim) {
  43528. plugins.push(trimPlugin());
  43529. }
  43530. if (scoped) {
  43531. plugins.push(scopedPlugin(longId));
  43532. }
  43533. let cssModules;
  43534. if (modules) {
  43535. {
  43536. throw new Error(
  43537. "[@vue/compiler-sfc] `modules` option is not supported in the browser build."
  43538. );
  43539. }
  43540. }
  43541. const postCSSOptions = __spreadProps$3(__spreadValues$4({}, postcssOptions), {
  43542. to: filename,
  43543. from: filename
  43544. });
  43545. if (map) {
  43546. postCSSOptions.map = {
  43547. inline: false,
  43548. annotation: false,
  43549. prev: map
  43550. };
  43551. }
  43552. let result;
  43553. let code;
  43554. let outMap;
  43555. const dependencies = new Set(
  43556. preProcessedSource ? preProcessedSource.dependencies : []
  43557. );
  43558. dependencies.delete(filename);
  43559. const errors = [];
  43560. if (preProcessedSource && preProcessedSource.errors.length) {
  43561. errors.push(...preProcessedSource.errors);
  43562. }
  43563. const recordPlainCssDependencies = (messages) => {
  43564. messages.forEach((msg) => {
  43565. if (msg.type === "dependency") {
  43566. dependencies.add(msg.file);
  43567. }
  43568. });
  43569. return dependencies;
  43570. };
  43571. try {
  43572. result = postcss(plugins).process(source, postCSSOptions);
  43573. if (options.isAsync) {
  43574. return result.then((result2) => ({
  43575. code: result2.css || "",
  43576. map: result2.map && result2.map.toJSON(),
  43577. errors,
  43578. modules: cssModules,
  43579. rawResult: result2,
  43580. dependencies: recordPlainCssDependencies(result2.messages)
  43581. })).catch((error) => ({
  43582. code: "",
  43583. map: void 0,
  43584. errors: [...errors, error],
  43585. rawResult: void 0,
  43586. dependencies
  43587. }));
  43588. }
  43589. recordPlainCssDependencies(result.messages);
  43590. code = result.css;
  43591. outMap = result.map;
  43592. } catch (e) {
  43593. errors.push(e);
  43594. }
  43595. return {
  43596. code: code || ``,
  43597. map: outMap && outMap.toJSON(),
  43598. errors,
  43599. rawResult: result,
  43600. dependencies
  43601. };
  43602. }
  43603. function preprocess(options, preprocessor) {
  43604. if (!options.preprocessCustomRequire) {
  43605. throw new Error(
  43606. `[@vue/compiler-sfc] Style preprocessing in the browser build must provide the \`preprocessCustomRequire\` option to return the in-browser version of the preprocessor.`
  43607. );
  43608. }
  43609. return preprocessor(
  43610. options.source,
  43611. options.inMap || options.map,
  43612. __spreadValues$4({
  43613. filename: options.filename
  43614. }, options.preprocessOptions),
  43615. options.preprocessCustomRequire
  43616. );
  43617. }
  43618. const UNKNOWN_TYPE = "Unknown";
  43619. function resolveObjectKey(node, computed) {
  43620. switch (node.type) {
  43621. case "StringLiteral":
  43622. case "NumericLiteral":
  43623. return String(node.value);
  43624. case "Identifier":
  43625. if (!computed) return node.name;
  43626. }
  43627. return void 0;
  43628. }
  43629. function concatStrings(strs) {
  43630. return strs.filter((s) => !!s).join(", ");
  43631. }
  43632. function isLiteralNode(node) {
  43633. return node.type.endsWith("Literal");
  43634. }
  43635. function isCallOf(node, test) {
  43636. return !!(node && test && node.type === "CallExpression" && node.callee.type === "Identifier" && (typeof test === "string" ? node.callee.name === test : test(node.callee.name)));
  43637. }
  43638. function toRuntimeTypeString(types) {
  43639. return types.length > 1 ? `[${types.join(", ")}]` : types[0];
  43640. }
  43641. function getImportedName(specifier) {
  43642. if (specifier.type === "ImportSpecifier")
  43643. return specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
  43644. else if (specifier.type === "ImportNamespaceSpecifier") return "*";
  43645. return "default";
  43646. }
  43647. function getId(node) {
  43648. return node.type === "Identifier" ? node.name : node.type === "StringLiteral" ? node.value : null;
  43649. }
  43650. function getStringLiteralKey(node) {
  43651. return node.computed ? node.key.type === "TemplateLiteral" && !node.key.expressions.length ? node.key.quasis.map((q) => q.value.cooked).join("") : null : node.key.type === "Identifier" ? node.key.name : node.key.type === "StringLiteral" ? node.key.value : node.key.type === "NumericLiteral" ? String(node.key.value) : null;
  43652. }
  43653. const normalize = (path.posix || path).normalize;
  43654. const windowsSlashRE = /\\/g;
  43655. function normalizePath(p) {
  43656. return normalize(p.replace(windowsSlashRE, "/"));
  43657. }
  43658. const joinPaths = (path.posix || path).join;
  43659. const propNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~\-]/;
  43660. function getEscapedPropName(key) {
  43661. return propNameEscapeSymbolsRE.test(key) ? JSON.stringify(key) : key;
  43662. }
  43663. const isJS = (...langs) => langs.some((lang) => lang === "js" || lang === "jsx");
  43664. const isTS = (...langs) => langs.some((lang) => lang === "ts" || lang === "tsx");
  43665. function analyzeScriptBindings(ast) {
  43666. for (const node of ast) {
  43667. if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "ObjectExpression") {
  43668. return analyzeBindingsFromOptions(node.declaration);
  43669. }
  43670. }
  43671. return {};
  43672. }
  43673. function analyzeBindingsFromOptions(node) {
  43674. const bindings = {};
  43675. Object.defineProperty(bindings, "__isScriptSetup", {
  43676. enumerable: false,
  43677. value: false
  43678. });
  43679. for (const property of node.properties) {
  43680. if (property.type === "ObjectProperty" && !property.computed && property.key.type === "Identifier") {
  43681. if (property.key.name === "props") {
  43682. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  43683. bindings[key] = "props";
  43684. }
  43685. } else if (property.key.name === "inject") {
  43686. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  43687. bindings[key] = "options";
  43688. }
  43689. } else if (property.value.type === "ObjectExpression" && (property.key.name === "computed" || property.key.name === "methods")) {
  43690. for (const key of getObjectExpressionKeys(property.value)) {
  43691. bindings[key] = "options";
  43692. }
  43693. }
  43694. } else if (property.type === "ObjectMethod" && property.key.type === "Identifier" && (property.key.name === "setup" || property.key.name === "data")) {
  43695. for (const bodyItem of property.body.body) {
  43696. if (bodyItem.type === "ReturnStatement" && bodyItem.argument && bodyItem.argument.type === "ObjectExpression") {
  43697. for (const key of getObjectExpressionKeys(bodyItem.argument)) {
  43698. bindings[key] = property.key.name === "setup" ? "setup-maybe-ref" : "data";
  43699. }
  43700. }
  43701. }
  43702. }
  43703. }
  43704. return bindings;
  43705. }
  43706. function getObjectExpressionKeys(node) {
  43707. const keys = [];
  43708. for (const prop of node.properties) {
  43709. if (prop.type === "SpreadElement") continue;
  43710. const key = resolveObjectKey(prop.key, prop.computed);
  43711. if (key) keys.push(String(key));
  43712. }
  43713. return keys;
  43714. }
  43715. function getArrayExpressionKeys(node) {
  43716. const keys = [];
  43717. for (const element of node.elements) {
  43718. if (element && element.type === "StringLiteral") {
  43719. keys.push(element.value);
  43720. }
  43721. }
  43722. return keys;
  43723. }
  43724. function getObjectOrArrayExpressionKeys(value) {
  43725. if (value.type === "ArrayExpression") {
  43726. return getArrayExpressionKeys(value);
  43727. }
  43728. if (value.type === "ObjectExpression") {
  43729. return getObjectExpressionKeys(value);
  43730. }
  43731. return [];
  43732. }
  43733. // src/vlq.ts
  43734. var comma = ",".charCodeAt(0);
  43735. var semicolon = ";".charCodeAt(0);
  43736. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  43737. var intToChar = new Uint8Array(64);
  43738. var charToInt = new Uint8Array(128);
  43739. for (let i = 0; i < chars.length; i++) {
  43740. const c = chars.charCodeAt(i);
  43741. intToChar[i] = c;
  43742. charToInt[c] = i;
  43743. }
  43744. function encodeInteger(builder, num, relative) {
  43745. let delta = num - relative;
  43746. delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
  43747. do {
  43748. let clamped = delta & 31;
  43749. delta >>>= 5;
  43750. if (delta > 0) clamped |= 32;
  43751. builder.write(intToChar[clamped]);
  43752. } while (delta > 0);
  43753. return num;
  43754. }
  43755. // src/strings.ts
  43756. var bufLength = 1024 * 16;
  43757. var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
  43758. decode(buf) {
  43759. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  43760. return out.toString();
  43761. }
  43762. } : {
  43763. decode(buf) {
  43764. let out = "";
  43765. for (let i = 0; i < buf.length; i++) {
  43766. out += String.fromCharCode(buf[i]);
  43767. }
  43768. return out;
  43769. }
  43770. };
  43771. var StringWriter = class {
  43772. constructor() {
  43773. this.pos = 0;
  43774. this.out = "";
  43775. this.buffer = new Uint8Array(bufLength);
  43776. }
  43777. write(v) {
  43778. const { buffer } = this;
  43779. buffer[this.pos++] = v;
  43780. if (this.pos === bufLength) {
  43781. this.out += td.decode(buffer);
  43782. this.pos = 0;
  43783. }
  43784. }
  43785. flush() {
  43786. const { buffer, out, pos } = this;
  43787. return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
  43788. }
  43789. };
  43790. function encode(decoded) {
  43791. const writer = new StringWriter();
  43792. let sourcesIndex = 0;
  43793. let sourceLine = 0;
  43794. let sourceColumn = 0;
  43795. let namesIndex = 0;
  43796. for (let i = 0; i < decoded.length; i++) {
  43797. const line = decoded[i];
  43798. if (i > 0) writer.write(semicolon);
  43799. if (line.length === 0) continue;
  43800. let genColumn = 0;
  43801. for (let j = 0; j < line.length; j++) {
  43802. const segment = line[j];
  43803. if (j > 0) writer.write(comma);
  43804. genColumn = encodeInteger(writer, segment[0], genColumn);
  43805. if (segment.length === 1) continue;
  43806. sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
  43807. sourceLine = encodeInteger(writer, segment[2], sourceLine);
  43808. sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
  43809. if (segment.length === 4) continue;
  43810. namesIndex = encodeInteger(writer, segment[4], namesIndex);
  43811. }
  43812. }
  43813. return writer.flush();
  43814. }
  43815. class BitSet {
  43816. constructor(arg) {
  43817. this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
  43818. }
  43819. add(n) {
  43820. this.bits[n >> 5] |= 1 << (n & 31);
  43821. }
  43822. has(n) {
  43823. return !!(this.bits[n >> 5] & (1 << (n & 31)));
  43824. }
  43825. }
  43826. class Chunk {
  43827. constructor(start, end, content) {
  43828. this.start = start;
  43829. this.end = end;
  43830. this.original = content;
  43831. this.intro = '';
  43832. this.outro = '';
  43833. this.content = content;
  43834. this.storeName = false;
  43835. this.edited = false;
  43836. {
  43837. this.previous = null;
  43838. this.next = null;
  43839. }
  43840. }
  43841. appendLeft(content) {
  43842. this.outro += content;
  43843. }
  43844. appendRight(content) {
  43845. this.intro = this.intro + content;
  43846. }
  43847. clone() {
  43848. const chunk = new Chunk(this.start, this.end, this.original);
  43849. chunk.intro = this.intro;
  43850. chunk.outro = this.outro;
  43851. chunk.content = this.content;
  43852. chunk.storeName = this.storeName;
  43853. chunk.edited = this.edited;
  43854. return chunk;
  43855. }
  43856. contains(index) {
  43857. return this.start < index && index < this.end;
  43858. }
  43859. eachNext(fn) {
  43860. let chunk = this;
  43861. while (chunk) {
  43862. fn(chunk);
  43863. chunk = chunk.next;
  43864. }
  43865. }
  43866. eachPrevious(fn) {
  43867. let chunk = this;
  43868. while (chunk) {
  43869. fn(chunk);
  43870. chunk = chunk.previous;
  43871. }
  43872. }
  43873. edit(content, storeName, contentOnly) {
  43874. this.content = content;
  43875. if (!contentOnly) {
  43876. this.intro = '';
  43877. this.outro = '';
  43878. }
  43879. this.storeName = storeName;
  43880. this.edited = true;
  43881. return this;
  43882. }
  43883. prependLeft(content) {
  43884. this.outro = content + this.outro;
  43885. }
  43886. prependRight(content) {
  43887. this.intro = content + this.intro;
  43888. }
  43889. reset() {
  43890. this.intro = '';
  43891. this.outro = '';
  43892. if (this.edited) {
  43893. this.content = this.original;
  43894. this.storeName = false;
  43895. this.edited = false;
  43896. }
  43897. }
  43898. split(index) {
  43899. const sliceIndex = index - this.start;
  43900. const originalBefore = this.original.slice(0, sliceIndex);
  43901. const originalAfter = this.original.slice(sliceIndex);
  43902. this.original = originalBefore;
  43903. const newChunk = new Chunk(index, this.end, originalAfter);
  43904. newChunk.outro = this.outro;
  43905. this.outro = '';
  43906. this.end = index;
  43907. if (this.edited) {
  43908. // after split we should save the edit content record into the correct chunk
  43909. // to make sure sourcemap correct
  43910. // For example:
  43911. // ' test'.trim()
  43912. // split -> ' ' + 'test'
  43913. // ✔️ edit -> '' + 'test'
  43914. // ✖️ edit -> 'test' + ''
  43915. // TODO is this block necessary?...
  43916. newChunk.edit('', false);
  43917. this.content = '';
  43918. } else {
  43919. this.content = originalBefore;
  43920. }
  43921. newChunk.next = this.next;
  43922. if (newChunk.next) newChunk.next.previous = newChunk;
  43923. newChunk.previous = this;
  43924. this.next = newChunk;
  43925. return newChunk;
  43926. }
  43927. toString() {
  43928. return this.intro + this.content + this.outro;
  43929. }
  43930. trimEnd(rx) {
  43931. this.outro = this.outro.replace(rx, '');
  43932. if (this.outro.length) return true;
  43933. const trimmed = this.content.replace(rx, '');
  43934. if (trimmed.length) {
  43935. if (trimmed !== this.content) {
  43936. this.split(this.start + trimmed.length).edit('', undefined, true);
  43937. if (this.edited) {
  43938. // save the change, if it has been edited
  43939. this.edit(trimmed, this.storeName, true);
  43940. }
  43941. }
  43942. return true;
  43943. } else {
  43944. this.edit('', undefined, true);
  43945. this.intro = this.intro.replace(rx, '');
  43946. if (this.intro.length) return true;
  43947. }
  43948. }
  43949. trimStart(rx) {
  43950. this.intro = this.intro.replace(rx, '');
  43951. if (this.intro.length) return true;
  43952. const trimmed = this.content.replace(rx, '');
  43953. if (trimmed.length) {
  43954. if (trimmed !== this.content) {
  43955. const newChunk = this.split(this.end - trimmed.length);
  43956. if (this.edited) {
  43957. // save the change, if it has been edited
  43958. newChunk.edit(trimmed, this.storeName, true);
  43959. }
  43960. this.edit('', undefined, true);
  43961. }
  43962. return true;
  43963. } else {
  43964. this.edit('', undefined, true);
  43965. this.outro = this.outro.replace(rx, '');
  43966. if (this.outro.length) return true;
  43967. }
  43968. }
  43969. }
  43970. function getBtoa() {
  43971. if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
  43972. return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
  43973. } else if (typeof Buffer === 'function') {
  43974. return (str) => Buffer.from(str, 'utf-8').toString('base64');
  43975. } else {
  43976. return () => {
  43977. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  43978. };
  43979. }
  43980. }
  43981. const btoa = /*#__PURE__*/ getBtoa();
  43982. class SourceMap {
  43983. constructor(properties) {
  43984. this.version = 3;
  43985. this.file = properties.file;
  43986. this.sources = properties.sources;
  43987. this.sourcesContent = properties.sourcesContent;
  43988. this.names = properties.names;
  43989. this.mappings = encode(properties.mappings);
  43990. if (typeof properties.x_google_ignoreList !== 'undefined') {
  43991. this.x_google_ignoreList = properties.x_google_ignoreList;
  43992. }
  43993. if (typeof properties.debugId !== 'undefined') {
  43994. this.debugId = properties.debugId;
  43995. }
  43996. }
  43997. toString() {
  43998. return JSON.stringify(this);
  43999. }
  44000. toUrl() {
  44001. return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
  44002. }
  44003. }
  44004. function guessIndent(code) {
  44005. const lines = code.split('\n');
  44006. const tabbed = lines.filter((line) => /^\t+/.test(line));
  44007. const spaced = lines.filter((line) => /^ {2,}/.test(line));
  44008. if (tabbed.length === 0 && spaced.length === 0) {
  44009. return null;
  44010. }
  44011. // More lines tabbed than spaced? Assume tabs, and
  44012. // default to tabs in the case of a tie (or nothing
  44013. // to go on)
  44014. if (tabbed.length >= spaced.length) {
  44015. return '\t';
  44016. }
  44017. // Otherwise, we need to guess the multiple
  44018. const min = spaced.reduce((previous, current) => {
  44019. const numSpaces = /^ +/.exec(current)[0].length;
  44020. return Math.min(numSpaces, previous);
  44021. }, Infinity);
  44022. return new Array(min + 1).join(' ');
  44023. }
  44024. function getRelativePath(from, to) {
  44025. const fromParts = from.split(/[/\\]/);
  44026. const toParts = to.split(/[/\\]/);
  44027. fromParts.pop(); // get dirname
  44028. while (fromParts[0] === toParts[0]) {
  44029. fromParts.shift();
  44030. toParts.shift();
  44031. }
  44032. if (fromParts.length) {
  44033. let i = fromParts.length;
  44034. while (i--) fromParts[i] = '..';
  44035. }
  44036. return fromParts.concat(toParts).join('/');
  44037. }
  44038. const toString = Object.prototype.toString;
  44039. function isObject(thing) {
  44040. return toString.call(thing) === '[object Object]';
  44041. }
  44042. function getLocator(source) {
  44043. const originalLines = source.split('\n');
  44044. const lineOffsets = [];
  44045. for (let i = 0, pos = 0; i < originalLines.length; i++) {
  44046. lineOffsets.push(pos);
  44047. pos += originalLines[i].length + 1;
  44048. }
  44049. return function locate(index) {
  44050. let i = 0;
  44051. let j = lineOffsets.length;
  44052. while (i < j) {
  44053. const m = (i + j) >> 1;
  44054. if (index < lineOffsets[m]) {
  44055. j = m;
  44056. } else {
  44057. i = m + 1;
  44058. }
  44059. }
  44060. const line = i - 1;
  44061. const column = index - lineOffsets[line];
  44062. return { line, column };
  44063. };
  44064. }
  44065. const wordRegex = /\w/;
  44066. class Mappings {
  44067. constructor(hires) {
  44068. this.hires = hires;
  44069. this.generatedCodeLine = 0;
  44070. this.generatedCodeColumn = 0;
  44071. this.raw = [];
  44072. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  44073. this.pending = null;
  44074. }
  44075. addEdit(sourceIndex, content, loc, nameIndex) {
  44076. if (content.length) {
  44077. const contentLengthMinusOne = content.length - 1;
  44078. let contentLineEnd = content.indexOf('\n', 0);
  44079. let previousContentLineEnd = -1;
  44080. // Loop through each line in the content and add a segment, but stop if the last line is empty,
  44081. // else code afterwards would fill one line too many
  44082. while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
  44083. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  44084. if (nameIndex >= 0) {
  44085. segment.push(nameIndex);
  44086. }
  44087. this.rawSegments.push(segment);
  44088. this.generatedCodeLine += 1;
  44089. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  44090. this.generatedCodeColumn = 0;
  44091. previousContentLineEnd = contentLineEnd;
  44092. contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
  44093. }
  44094. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  44095. if (nameIndex >= 0) {
  44096. segment.push(nameIndex);
  44097. }
  44098. this.rawSegments.push(segment);
  44099. this.advance(content.slice(previousContentLineEnd + 1));
  44100. } else if (this.pending) {
  44101. this.rawSegments.push(this.pending);
  44102. this.advance(content);
  44103. }
  44104. this.pending = null;
  44105. }
  44106. addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
  44107. let originalCharIndex = chunk.start;
  44108. let first = true;
  44109. // when iterating each char, check if it's in a word boundary
  44110. let charInHiresBoundary = false;
  44111. while (originalCharIndex < chunk.end) {
  44112. if (original[originalCharIndex] === '\n') {
  44113. loc.line += 1;
  44114. loc.column = 0;
  44115. this.generatedCodeLine += 1;
  44116. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  44117. this.generatedCodeColumn = 0;
  44118. first = true;
  44119. charInHiresBoundary = false;
  44120. } else {
  44121. if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
  44122. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  44123. if (this.hires === 'boundary') {
  44124. // in hires "boundary", group segments per word boundary than per char
  44125. if (wordRegex.test(original[originalCharIndex])) {
  44126. // for first char in the boundary found, start the boundary by pushing a segment
  44127. if (!charInHiresBoundary) {
  44128. this.rawSegments.push(segment);
  44129. charInHiresBoundary = true;
  44130. }
  44131. } else {
  44132. // for non-word char, end the boundary by pushing a segment
  44133. this.rawSegments.push(segment);
  44134. charInHiresBoundary = false;
  44135. }
  44136. } else {
  44137. this.rawSegments.push(segment);
  44138. }
  44139. }
  44140. loc.column += 1;
  44141. this.generatedCodeColumn += 1;
  44142. first = false;
  44143. }
  44144. originalCharIndex += 1;
  44145. }
  44146. this.pending = null;
  44147. }
  44148. advance(str) {
  44149. if (!str) return;
  44150. const lines = str.split('\n');
  44151. if (lines.length > 1) {
  44152. for (let i = 0; i < lines.length - 1; i++) {
  44153. this.generatedCodeLine++;
  44154. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  44155. }
  44156. this.generatedCodeColumn = 0;
  44157. }
  44158. this.generatedCodeColumn += lines[lines.length - 1].length;
  44159. }
  44160. }
  44161. const n = '\n';
  44162. const warned = {
  44163. insertLeft: false,
  44164. insertRight: false,
  44165. storeName: false,
  44166. };
  44167. class MagicString {
  44168. constructor(string, options = {}) {
  44169. const chunk = new Chunk(0, string.length, string);
  44170. Object.defineProperties(this, {
  44171. original: { writable: true, value: string },
  44172. outro: { writable: true, value: '' },
  44173. intro: { writable: true, value: '' },
  44174. firstChunk: { writable: true, value: chunk },
  44175. lastChunk: { writable: true, value: chunk },
  44176. lastSearchedChunk: { writable: true, value: chunk },
  44177. byStart: { writable: true, value: {} },
  44178. byEnd: { writable: true, value: {} },
  44179. filename: { writable: true, value: options.filename },
  44180. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  44181. sourcemapLocations: { writable: true, value: new BitSet() },
  44182. storedNames: { writable: true, value: {} },
  44183. indentStr: { writable: true, value: undefined },
  44184. ignoreList: { writable: true, value: options.ignoreList },
  44185. offset: { writable: true, value: options.offset || 0 },
  44186. });
  44187. this.byStart[0] = chunk;
  44188. this.byEnd[string.length] = chunk;
  44189. }
  44190. addSourcemapLocation(char) {
  44191. this.sourcemapLocations.add(char);
  44192. }
  44193. append(content) {
  44194. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  44195. this.outro += content;
  44196. return this;
  44197. }
  44198. appendLeft(index, content) {
  44199. index = index + this.offset;
  44200. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44201. this._split(index);
  44202. const chunk = this.byEnd[index];
  44203. if (chunk) {
  44204. chunk.appendLeft(content);
  44205. } else {
  44206. this.intro += content;
  44207. }
  44208. return this;
  44209. }
  44210. appendRight(index, content) {
  44211. index = index + this.offset;
  44212. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44213. this._split(index);
  44214. const chunk = this.byStart[index];
  44215. if (chunk) {
  44216. chunk.appendRight(content);
  44217. } else {
  44218. this.outro += content;
  44219. }
  44220. return this;
  44221. }
  44222. clone() {
  44223. const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
  44224. let originalChunk = this.firstChunk;
  44225. let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  44226. while (originalChunk) {
  44227. cloned.byStart[clonedChunk.start] = clonedChunk;
  44228. cloned.byEnd[clonedChunk.end] = clonedChunk;
  44229. const nextOriginalChunk = originalChunk.next;
  44230. const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  44231. if (nextClonedChunk) {
  44232. clonedChunk.next = nextClonedChunk;
  44233. nextClonedChunk.previous = clonedChunk;
  44234. clonedChunk = nextClonedChunk;
  44235. }
  44236. originalChunk = nextOriginalChunk;
  44237. }
  44238. cloned.lastChunk = clonedChunk;
  44239. if (this.indentExclusionRanges) {
  44240. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  44241. }
  44242. cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
  44243. cloned.intro = this.intro;
  44244. cloned.outro = this.outro;
  44245. return cloned;
  44246. }
  44247. generateDecodedMap(options) {
  44248. options = options || {};
  44249. const sourceIndex = 0;
  44250. const names = Object.keys(this.storedNames);
  44251. const mappings = new Mappings(options.hires);
  44252. const locate = getLocator(this.original);
  44253. if (this.intro) {
  44254. mappings.advance(this.intro);
  44255. }
  44256. this.firstChunk.eachNext((chunk) => {
  44257. const loc = locate(chunk.start);
  44258. if (chunk.intro.length) mappings.advance(chunk.intro);
  44259. if (chunk.edited) {
  44260. mappings.addEdit(
  44261. sourceIndex,
  44262. chunk.content,
  44263. loc,
  44264. chunk.storeName ? names.indexOf(chunk.original) : -1,
  44265. );
  44266. } else {
  44267. mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
  44268. }
  44269. if (chunk.outro.length) mappings.advance(chunk.outro);
  44270. });
  44271. if (this.outro) {
  44272. mappings.advance(this.outro);
  44273. }
  44274. return {
  44275. file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
  44276. sources: [
  44277. options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
  44278. ],
  44279. sourcesContent: options.includeContent ? [this.original] : undefined,
  44280. names,
  44281. mappings: mappings.raw,
  44282. x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
  44283. };
  44284. }
  44285. generateMap(options) {
  44286. return new SourceMap(this.generateDecodedMap(options));
  44287. }
  44288. _ensureindentStr() {
  44289. if (this.indentStr === undefined) {
  44290. this.indentStr = guessIndent(this.original);
  44291. }
  44292. }
  44293. _getRawIndentString() {
  44294. this._ensureindentStr();
  44295. return this.indentStr;
  44296. }
  44297. getIndentString() {
  44298. this._ensureindentStr();
  44299. return this.indentStr === null ? '\t' : this.indentStr;
  44300. }
  44301. indent(indentStr, options) {
  44302. const pattern = /^[^\r\n]/gm;
  44303. if (isObject(indentStr)) {
  44304. options = indentStr;
  44305. indentStr = undefined;
  44306. }
  44307. if (indentStr === undefined) {
  44308. this._ensureindentStr();
  44309. indentStr = this.indentStr || '\t';
  44310. }
  44311. if (indentStr === '') return this; // noop
  44312. options = options || {};
  44313. // Process exclusion ranges
  44314. const isExcluded = {};
  44315. if (options.exclude) {
  44316. const exclusions =
  44317. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  44318. exclusions.forEach((exclusion) => {
  44319. for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
  44320. isExcluded[i] = true;
  44321. }
  44322. });
  44323. }
  44324. let shouldIndentNextCharacter = options.indentStart !== false;
  44325. const replacer = (match) => {
  44326. if (shouldIndentNextCharacter) return `${indentStr}${match}`;
  44327. shouldIndentNextCharacter = true;
  44328. return match;
  44329. };
  44330. this.intro = this.intro.replace(pattern, replacer);
  44331. let charIndex = 0;
  44332. let chunk = this.firstChunk;
  44333. while (chunk) {
  44334. const end = chunk.end;
  44335. if (chunk.edited) {
  44336. if (!isExcluded[charIndex]) {
  44337. chunk.content = chunk.content.replace(pattern, replacer);
  44338. if (chunk.content.length) {
  44339. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  44340. }
  44341. }
  44342. } else {
  44343. charIndex = chunk.start;
  44344. while (charIndex < end) {
  44345. if (!isExcluded[charIndex]) {
  44346. const char = this.original[charIndex];
  44347. if (char === '\n') {
  44348. shouldIndentNextCharacter = true;
  44349. } else if (char !== '\r' && shouldIndentNextCharacter) {
  44350. shouldIndentNextCharacter = false;
  44351. if (charIndex === chunk.start) {
  44352. chunk.prependRight(indentStr);
  44353. } else {
  44354. this._splitChunk(chunk, charIndex);
  44355. chunk = chunk.next;
  44356. chunk.prependRight(indentStr);
  44357. }
  44358. }
  44359. }
  44360. charIndex += 1;
  44361. }
  44362. }
  44363. charIndex = chunk.end;
  44364. chunk = chunk.next;
  44365. }
  44366. this.outro = this.outro.replace(pattern, replacer);
  44367. return this;
  44368. }
  44369. insert() {
  44370. throw new Error(
  44371. 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
  44372. );
  44373. }
  44374. insertLeft(index, content) {
  44375. if (!warned.insertLeft) {
  44376. console.warn(
  44377. 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
  44378. );
  44379. warned.insertLeft = true;
  44380. }
  44381. return this.appendLeft(index, content);
  44382. }
  44383. insertRight(index, content) {
  44384. if (!warned.insertRight) {
  44385. console.warn(
  44386. 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
  44387. );
  44388. warned.insertRight = true;
  44389. }
  44390. return this.prependRight(index, content);
  44391. }
  44392. move(start, end, index) {
  44393. start = start + this.offset;
  44394. end = end + this.offset;
  44395. index = index + this.offset;
  44396. if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
  44397. this._split(start);
  44398. this._split(end);
  44399. this._split(index);
  44400. const first = this.byStart[start];
  44401. const last = this.byEnd[end];
  44402. const oldLeft = first.previous;
  44403. const oldRight = last.next;
  44404. const newRight = this.byStart[index];
  44405. if (!newRight && last === this.lastChunk) return this;
  44406. const newLeft = newRight ? newRight.previous : this.lastChunk;
  44407. if (oldLeft) oldLeft.next = oldRight;
  44408. if (oldRight) oldRight.previous = oldLeft;
  44409. if (newLeft) newLeft.next = first;
  44410. if (newRight) newRight.previous = last;
  44411. if (!first.previous) this.firstChunk = last.next;
  44412. if (!last.next) {
  44413. this.lastChunk = first.previous;
  44414. this.lastChunk.next = null;
  44415. }
  44416. first.previous = newLeft;
  44417. last.next = newRight || null;
  44418. if (!newLeft) this.firstChunk = first;
  44419. if (!newRight) this.lastChunk = last;
  44420. return this;
  44421. }
  44422. overwrite(start, end, content, options) {
  44423. options = options || {};
  44424. return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
  44425. }
  44426. update(start, end, content, options) {
  44427. start = start + this.offset;
  44428. end = end + this.offset;
  44429. if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
  44430. if (this.original.length !== 0) {
  44431. while (start < 0) start += this.original.length;
  44432. while (end < 0) end += this.original.length;
  44433. }
  44434. if (end > this.original.length) throw new Error('end is out of bounds');
  44435. if (start === end)
  44436. throw new Error(
  44437. 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
  44438. );
  44439. this._split(start);
  44440. this._split(end);
  44441. if (options === true) {
  44442. if (!warned.storeName) {
  44443. console.warn(
  44444. 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
  44445. );
  44446. warned.storeName = true;
  44447. }
  44448. options = { storeName: true };
  44449. }
  44450. const storeName = options !== undefined ? options.storeName : false;
  44451. const overwrite = options !== undefined ? options.overwrite : false;
  44452. if (storeName) {
  44453. const original = this.original.slice(start, end);
  44454. Object.defineProperty(this.storedNames, original, {
  44455. writable: true,
  44456. value: true,
  44457. enumerable: true,
  44458. });
  44459. }
  44460. const first = this.byStart[start];
  44461. const last = this.byEnd[end];
  44462. if (first) {
  44463. let chunk = first;
  44464. while (chunk !== last) {
  44465. if (chunk.next !== this.byStart[chunk.end]) {
  44466. throw new Error('Cannot overwrite across a split point');
  44467. }
  44468. chunk = chunk.next;
  44469. chunk.edit('', false);
  44470. }
  44471. first.edit(content, storeName, !overwrite);
  44472. } else {
  44473. // must be inserting at the end
  44474. const newChunk = new Chunk(start, end, '').edit(content, storeName);
  44475. // TODO last chunk in the array may not be the last chunk, if it's moved...
  44476. last.next = newChunk;
  44477. newChunk.previous = last;
  44478. }
  44479. return this;
  44480. }
  44481. prepend(content) {
  44482. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  44483. this.intro = content + this.intro;
  44484. return this;
  44485. }
  44486. prependLeft(index, content) {
  44487. index = index + this.offset;
  44488. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44489. this._split(index);
  44490. const chunk = this.byEnd[index];
  44491. if (chunk) {
  44492. chunk.prependLeft(content);
  44493. } else {
  44494. this.intro = content + this.intro;
  44495. }
  44496. return this;
  44497. }
  44498. prependRight(index, content) {
  44499. index = index + this.offset;
  44500. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44501. this._split(index);
  44502. const chunk = this.byStart[index];
  44503. if (chunk) {
  44504. chunk.prependRight(content);
  44505. } else {
  44506. this.outro = content + this.outro;
  44507. }
  44508. return this;
  44509. }
  44510. remove(start, end) {
  44511. start = start + this.offset;
  44512. end = end + this.offset;
  44513. if (this.original.length !== 0) {
  44514. while (start < 0) start += this.original.length;
  44515. while (end < 0) end += this.original.length;
  44516. }
  44517. if (start === end) return this;
  44518. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  44519. if (start > end) throw new Error('end must be greater than start');
  44520. this._split(start);
  44521. this._split(end);
  44522. let chunk = this.byStart[start];
  44523. while (chunk) {
  44524. chunk.intro = '';
  44525. chunk.outro = '';
  44526. chunk.edit('');
  44527. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  44528. }
  44529. return this;
  44530. }
  44531. reset(start, end) {
  44532. start = start + this.offset;
  44533. end = end + this.offset;
  44534. if (this.original.length !== 0) {
  44535. while (start < 0) start += this.original.length;
  44536. while (end < 0) end += this.original.length;
  44537. }
  44538. if (start === end) return this;
  44539. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  44540. if (start > end) throw new Error('end must be greater than start');
  44541. this._split(start);
  44542. this._split(end);
  44543. let chunk = this.byStart[start];
  44544. while (chunk) {
  44545. chunk.reset();
  44546. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  44547. }
  44548. return this;
  44549. }
  44550. lastChar() {
  44551. if (this.outro.length) return this.outro[this.outro.length - 1];
  44552. let chunk = this.lastChunk;
  44553. do {
  44554. if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
  44555. if (chunk.content.length) return chunk.content[chunk.content.length - 1];
  44556. if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
  44557. } while ((chunk = chunk.previous));
  44558. if (this.intro.length) return this.intro[this.intro.length - 1];
  44559. return '';
  44560. }
  44561. lastLine() {
  44562. let lineIndex = this.outro.lastIndexOf(n);
  44563. if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
  44564. let lineStr = this.outro;
  44565. let chunk = this.lastChunk;
  44566. do {
  44567. if (chunk.outro.length > 0) {
  44568. lineIndex = chunk.outro.lastIndexOf(n);
  44569. if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
  44570. lineStr = chunk.outro + lineStr;
  44571. }
  44572. if (chunk.content.length > 0) {
  44573. lineIndex = chunk.content.lastIndexOf(n);
  44574. if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
  44575. lineStr = chunk.content + lineStr;
  44576. }
  44577. if (chunk.intro.length > 0) {
  44578. lineIndex = chunk.intro.lastIndexOf(n);
  44579. if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
  44580. lineStr = chunk.intro + lineStr;
  44581. }
  44582. } while ((chunk = chunk.previous));
  44583. lineIndex = this.intro.lastIndexOf(n);
  44584. if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
  44585. return this.intro + lineStr;
  44586. }
  44587. slice(start = 0, end = this.original.length - this.offset) {
  44588. start = start + this.offset;
  44589. end = end + this.offset;
  44590. if (this.original.length !== 0) {
  44591. while (start < 0) start += this.original.length;
  44592. while (end < 0) end += this.original.length;
  44593. }
  44594. let result = '';
  44595. // find start chunk
  44596. let chunk = this.firstChunk;
  44597. while (chunk && (chunk.start > start || chunk.end <= start)) {
  44598. // found end chunk before start
  44599. if (chunk.start < end && chunk.end >= end) {
  44600. return result;
  44601. }
  44602. chunk = chunk.next;
  44603. }
  44604. if (chunk && chunk.edited && chunk.start !== start)
  44605. throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
  44606. const startChunk = chunk;
  44607. while (chunk) {
  44608. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  44609. result += chunk.intro;
  44610. }
  44611. const containsEnd = chunk.start < end && chunk.end >= end;
  44612. if (containsEnd && chunk.edited && chunk.end !== end)
  44613. throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
  44614. const sliceStart = startChunk === chunk ? start - chunk.start : 0;
  44615. const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  44616. result += chunk.content.slice(sliceStart, sliceEnd);
  44617. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  44618. result += chunk.outro;
  44619. }
  44620. if (containsEnd) {
  44621. break;
  44622. }
  44623. chunk = chunk.next;
  44624. }
  44625. return result;
  44626. }
  44627. // TODO deprecate this? not really very useful
  44628. snip(start, end) {
  44629. const clone = this.clone();
  44630. clone.remove(0, start);
  44631. clone.remove(end, clone.original.length);
  44632. return clone;
  44633. }
  44634. _split(index) {
  44635. if (this.byStart[index] || this.byEnd[index]) return;
  44636. let chunk = this.lastSearchedChunk;
  44637. let previousChunk = chunk;
  44638. const searchForward = index > chunk.end;
  44639. while (chunk) {
  44640. if (chunk.contains(index)) return this._splitChunk(chunk, index);
  44641. chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
  44642. // Prevent infinite loop (e.g. via empty chunks, where start === end)
  44643. if (chunk === previousChunk) return;
  44644. previousChunk = chunk;
  44645. }
  44646. }
  44647. _splitChunk(chunk, index) {
  44648. if (chunk.edited && chunk.content.length) {
  44649. // zero-length edited chunks are a special case (overlapping replacements)
  44650. const loc = getLocator(this.original)(index);
  44651. throw new Error(
  44652. `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
  44653. );
  44654. }
  44655. const newChunk = chunk.split(index);
  44656. this.byEnd[index] = chunk;
  44657. this.byStart[index] = newChunk;
  44658. this.byEnd[newChunk.end] = newChunk;
  44659. if (chunk === this.lastChunk) this.lastChunk = newChunk;
  44660. this.lastSearchedChunk = chunk;
  44661. return true;
  44662. }
  44663. toString() {
  44664. let str = this.intro;
  44665. let chunk = this.firstChunk;
  44666. while (chunk) {
  44667. str += chunk.toString();
  44668. chunk = chunk.next;
  44669. }
  44670. return str + this.outro;
  44671. }
  44672. isEmpty() {
  44673. let chunk = this.firstChunk;
  44674. do {
  44675. if (
  44676. (chunk.intro.length && chunk.intro.trim()) ||
  44677. (chunk.content.length && chunk.content.trim()) ||
  44678. (chunk.outro.length && chunk.outro.trim())
  44679. )
  44680. return false;
  44681. } while ((chunk = chunk.next));
  44682. return true;
  44683. }
  44684. length() {
  44685. let chunk = this.firstChunk;
  44686. let length = 0;
  44687. do {
  44688. length += chunk.intro.length + chunk.content.length + chunk.outro.length;
  44689. } while ((chunk = chunk.next));
  44690. return length;
  44691. }
  44692. trimLines() {
  44693. return this.trim('[\\r\\n]');
  44694. }
  44695. trim(charType) {
  44696. return this.trimStart(charType).trimEnd(charType);
  44697. }
  44698. trimEndAborted(charType) {
  44699. const rx = new RegExp((charType || '\\s') + '+$');
  44700. this.outro = this.outro.replace(rx, '');
  44701. if (this.outro.length) return true;
  44702. let chunk = this.lastChunk;
  44703. do {
  44704. const end = chunk.end;
  44705. const aborted = chunk.trimEnd(rx);
  44706. // if chunk was trimmed, we have a new lastChunk
  44707. if (chunk.end !== end) {
  44708. if (this.lastChunk === chunk) {
  44709. this.lastChunk = chunk.next;
  44710. }
  44711. this.byEnd[chunk.end] = chunk;
  44712. this.byStart[chunk.next.start] = chunk.next;
  44713. this.byEnd[chunk.next.end] = chunk.next;
  44714. }
  44715. if (aborted) return true;
  44716. chunk = chunk.previous;
  44717. } while (chunk);
  44718. return false;
  44719. }
  44720. trimEnd(charType) {
  44721. this.trimEndAborted(charType);
  44722. return this;
  44723. }
  44724. trimStartAborted(charType) {
  44725. const rx = new RegExp('^' + (charType || '\\s') + '+');
  44726. this.intro = this.intro.replace(rx, '');
  44727. if (this.intro.length) return true;
  44728. let chunk = this.firstChunk;
  44729. do {
  44730. const end = chunk.end;
  44731. const aborted = chunk.trimStart(rx);
  44732. if (chunk.end !== end) {
  44733. // special case...
  44734. if (chunk === this.lastChunk) this.lastChunk = chunk.next;
  44735. this.byEnd[chunk.end] = chunk;
  44736. this.byStart[chunk.next.start] = chunk.next;
  44737. this.byEnd[chunk.next.end] = chunk.next;
  44738. }
  44739. if (aborted) return true;
  44740. chunk = chunk.next;
  44741. } while (chunk);
  44742. return false;
  44743. }
  44744. trimStart(charType) {
  44745. this.trimStartAborted(charType);
  44746. return this;
  44747. }
  44748. hasChanged() {
  44749. return this.original !== this.toString();
  44750. }
  44751. _replaceRegexp(searchValue, replacement) {
  44752. function getReplacement(match, str) {
  44753. if (typeof replacement === 'string') {
  44754. return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
  44755. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
  44756. if (i === '$') return '$';
  44757. if (i === '&') return match[0];
  44758. const num = +i;
  44759. if (num < match.length) return match[+i];
  44760. return `$${i}`;
  44761. });
  44762. } else {
  44763. return replacement(...match, match.index, str, match.groups);
  44764. }
  44765. }
  44766. function matchAll(re, str) {
  44767. let match;
  44768. const matches = [];
  44769. while ((match = re.exec(str))) {
  44770. matches.push(match);
  44771. }
  44772. return matches;
  44773. }
  44774. if (searchValue.global) {
  44775. const matches = matchAll(searchValue, this.original);
  44776. matches.forEach((match) => {
  44777. if (match.index != null) {
  44778. const replacement = getReplacement(match, this.original);
  44779. if (replacement !== match[0]) {
  44780. this.overwrite(match.index, match.index + match[0].length, replacement);
  44781. }
  44782. }
  44783. });
  44784. } else {
  44785. const match = this.original.match(searchValue);
  44786. if (match && match.index != null) {
  44787. const replacement = getReplacement(match, this.original);
  44788. if (replacement !== match[0]) {
  44789. this.overwrite(match.index, match.index + match[0].length, replacement);
  44790. }
  44791. }
  44792. }
  44793. return this;
  44794. }
  44795. _replaceString(string, replacement) {
  44796. const { original } = this;
  44797. const index = original.indexOf(string);
  44798. if (index !== -1) {
  44799. if (typeof replacement === 'function') {
  44800. replacement = replacement(string, index, original);
  44801. }
  44802. if (string !== replacement) {
  44803. this.overwrite(index, index + string.length, replacement);
  44804. }
  44805. }
  44806. return this;
  44807. }
  44808. replace(searchValue, replacement) {
  44809. if (typeof searchValue === 'string') {
  44810. return this._replaceString(searchValue, replacement);
  44811. }
  44812. return this._replaceRegexp(searchValue, replacement);
  44813. }
  44814. _replaceAllString(string, replacement) {
  44815. const { original } = this;
  44816. const stringLength = string.length;
  44817. for (
  44818. let index = original.indexOf(string);
  44819. index !== -1;
  44820. index = original.indexOf(string, index + stringLength)
  44821. ) {
  44822. const previous = original.slice(index, index + stringLength);
  44823. let _replacement = replacement;
  44824. if (typeof replacement === 'function') {
  44825. _replacement = replacement(previous, index, original);
  44826. }
  44827. if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
  44828. }
  44829. return this;
  44830. }
  44831. replaceAll(searchValue, replacement) {
  44832. if (typeof searchValue === 'string') {
  44833. return this._replaceAllString(searchValue, replacement);
  44834. }
  44835. if (!searchValue.global) {
  44836. throw new TypeError(
  44837. 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
  44838. );
  44839. }
  44840. return this._replaceRegexp(searchValue, replacement);
  44841. }
  44842. }
  44843. var _a, _b;
  44844. class ScriptCompileContext {
  44845. constructor(descriptor, options) {
  44846. this.descriptor = descriptor;
  44847. this.options = options;
  44848. this.isCE = false;
  44849. this.source = this.descriptor.source;
  44850. this.filename = this.descriptor.filename;
  44851. this.s = new MagicString(this.source);
  44852. this.startOffset = (_a = this.descriptor.scriptSetup) == null ? void 0 : _a.loc.start.offset;
  44853. this.endOffset = (_b = this.descriptor.scriptSetup) == null ? void 0 : _b.loc.end.offset;
  44854. this.userImports = /* @__PURE__ */ Object.create(null);
  44855. // macros presence check
  44856. this.hasDefinePropsCall = false;
  44857. this.hasDefineEmitCall = false;
  44858. this.hasDefineExposeCall = false;
  44859. this.hasDefaultExportName = false;
  44860. this.hasDefaultExportRender = false;
  44861. this.hasDefineOptionsCall = false;
  44862. this.hasDefineSlotsCall = false;
  44863. this.hasDefineModelCall = false;
  44864. this.propsDestructuredBindings = /* @__PURE__ */ Object.create(null);
  44865. // defineModel
  44866. this.modelDecls = /* @__PURE__ */ Object.create(null);
  44867. // codegen
  44868. this.bindingMetadata = {};
  44869. this.helperImports = /* @__PURE__ */ new Set();
  44870. const { script, scriptSetup } = descriptor;
  44871. const scriptLang = script && script.lang;
  44872. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  44873. this.isJS = isJS(scriptLang, scriptSetupLang);
  44874. this.isTS = isTS(scriptLang, scriptSetupLang);
  44875. const customElement = options.customElement;
  44876. const filename = this.descriptor.filename;
  44877. if (customElement) {
  44878. this.isCE = typeof customElement === "boolean" ? customElement : customElement(filename);
  44879. }
  44880. const plugins = resolveParserPlugins(
  44881. scriptLang || scriptSetupLang,
  44882. options.babelParserPlugins
  44883. );
  44884. function parse(input, offset) {
  44885. try {
  44886. return libExports.parse(input, {
  44887. plugins,
  44888. sourceType: "module"
  44889. }).program;
  44890. } catch (e) {
  44891. e.message = `[vue/compiler-sfc] ${e.message}
  44892. ${descriptor.filename}
  44893. ${generateCodeFrame(
  44894. descriptor.source,
  44895. e.pos + offset,
  44896. e.pos + offset + 1
  44897. )}`;
  44898. throw e;
  44899. }
  44900. }
  44901. this.scriptAst = descriptor.script && parse(descriptor.script.content, descriptor.script.loc.start.offset);
  44902. this.scriptSetupAst = descriptor.scriptSetup && parse(descriptor.scriptSetup.content, this.startOffset);
  44903. }
  44904. helper(key) {
  44905. this.helperImports.add(key);
  44906. return `_${key}`;
  44907. }
  44908. getString(node, scriptSetup = true) {
  44909. const block = scriptSetup ? this.descriptor.scriptSetup : this.descriptor.script;
  44910. return block.content.slice(node.start, node.end);
  44911. }
  44912. warn(msg, node, scope) {
  44913. warn(generateError(msg, node, this, scope));
  44914. }
  44915. error(msg, node, scope) {
  44916. throw new Error(
  44917. `[@vue/compiler-sfc] ${generateError(msg, node, this, scope)}`
  44918. );
  44919. }
  44920. }
  44921. function generateError(msg, node, ctx, scope) {
  44922. const offset = scope ? scope.offset : ctx.startOffset;
  44923. return `${msg}
  44924. ${(scope || ctx.descriptor).filename}
  44925. ${generateCodeFrame(
  44926. (scope || ctx.descriptor).source,
  44927. node.start + offset,
  44928. node.end + offset
  44929. )}`;
  44930. }
  44931. function resolveParserPlugins(lang, userPlugins, dts = false) {
  44932. const plugins = [];
  44933. if (!userPlugins || !userPlugins.some(
  44934. (p) => p === "importAssertions" || p === "importAttributes" || isArray$3(p) && p[0] === "importAttributes"
  44935. )) {
  44936. plugins.push("importAttributes");
  44937. }
  44938. if (lang === "jsx" || lang === "tsx" || lang === "mtsx") {
  44939. plugins.push("jsx");
  44940. } else if (userPlugins) {
  44941. userPlugins = userPlugins.filter((p) => p !== "jsx");
  44942. }
  44943. if (lang === "ts" || lang === "mts" || lang === "tsx" || lang === "mtsx") {
  44944. plugins.push(["typescript", { dts }], "explicitResourceManagement");
  44945. if (!userPlugins || !userPlugins.includes("decorators")) {
  44946. plugins.push("decorators-legacy");
  44947. }
  44948. }
  44949. if (userPlugins) {
  44950. plugins.push(...userPlugins);
  44951. }
  44952. return plugins;
  44953. }
  44954. function rewriteDefault(input, as, parserPlugins) {
  44955. const ast = libExports.parse(input, {
  44956. sourceType: "module",
  44957. plugins: resolveParserPlugins("js", parserPlugins)
  44958. }).program.body;
  44959. const s = new MagicString(input);
  44960. rewriteDefaultAST(ast, s, as);
  44961. return s.toString();
  44962. }
  44963. function rewriteDefaultAST(ast, s, as) {
  44964. if (!hasDefaultExport(ast)) {
  44965. s.append(`
  44966. const ${as} = {}`);
  44967. return;
  44968. }
  44969. ast.forEach((node) => {
  44970. if (node.type === "ExportDefaultDeclaration") {
  44971. if (node.declaration.type === "ClassDeclaration" && node.declaration.id) {
  44972. const start = node.declaration.decorators && node.declaration.decorators.length > 0 ? node.declaration.decorators[node.declaration.decorators.length - 1].end : node.start;
  44973. s.overwrite(start, node.declaration.id.start, ` class `);
  44974. s.append(`
  44975. const ${as} = ${node.declaration.id.name}`);
  44976. } else {
  44977. s.overwrite(node.start, node.declaration.start, `const ${as} = `);
  44978. }
  44979. } else if (node.type === "ExportNamedDeclaration") {
  44980. for (const specifier of node.specifiers) {
  44981. if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier" && specifier.exported.name === "default") {
  44982. if (node.source) {
  44983. if (specifier.local.name === "default") {
  44984. s.prepend(
  44985. `import { default as __VUE_DEFAULT__ } from '${node.source.value}'
  44986. `
  44987. );
  44988. const end2 = specifierEnd(s, specifier.local.end, node.end);
  44989. s.remove(specifier.start, end2);
  44990. s.append(`
  44991. const ${as} = __VUE_DEFAULT__`);
  44992. continue;
  44993. } else {
  44994. s.prepend(
  44995. `import { ${s.slice(
  44996. specifier.local.start,
  44997. specifier.local.end
  44998. )} as __VUE_DEFAULT__ } from '${node.source.value}'
  44999. `
  45000. );
  45001. const end2 = specifierEnd(s, specifier.exported.end, node.end);
  45002. s.remove(specifier.start, end2);
  45003. s.append(`
  45004. const ${as} = __VUE_DEFAULT__`);
  45005. continue;
  45006. }
  45007. }
  45008. const end = specifierEnd(s, specifier.end, node.end);
  45009. s.remove(specifier.start, end);
  45010. s.append(`
  45011. const ${as} = ${specifier.local.name}`);
  45012. }
  45013. }
  45014. }
  45015. });
  45016. }
  45017. function hasDefaultExport(ast) {
  45018. for (const stmt of ast) {
  45019. if (stmt.type === "ExportDefaultDeclaration") {
  45020. return true;
  45021. } else if (stmt.type === "ExportNamedDeclaration" && stmt.specifiers.some(
  45022. (spec) => spec.exported.name === "default"
  45023. )) {
  45024. return true;
  45025. }
  45026. }
  45027. return false;
  45028. }
  45029. function specifierEnd(s, end, nodeEnd) {
  45030. let hasCommas = false;
  45031. let oldEnd = end;
  45032. while (end < nodeEnd) {
  45033. if (/\s/.test(s.slice(end, end + 1))) {
  45034. end++;
  45035. } else if (s.slice(end, end + 1) === ",") {
  45036. end++;
  45037. hasCommas = true;
  45038. break;
  45039. } else if (s.slice(end, end + 1) === "}") {
  45040. break;
  45041. }
  45042. }
  45043. return hasCommas ? end : oldEnd;
  45044. }
  45045. var __defProp$3 = Object.defineProperty;
  45046. var __defProps$2 = Object.defineProperties;
  45047. var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
  45048. var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
  45049. var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
  45050. var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
  45051. var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  45052. var __spreadValues$3 = (a, b) => {
  45053. for (var prop in b || (b = {}))
  45054. if (__hasOwnProp$3.call(b, prop))
  45055. __defNormalProp$3(a, prop, b[prop]);
  45056. if (__getOwnPropSymbols$3)
  45057. for (var prop of __getOwnPropSymbols$3(b)) {
  45058. if (__propIsEnum$3.call(b, prop))
  45059. __defNormalProp$3(a, prop, b[prop]);
  45060. }
  45061. return a;
  45062. };
  45063. var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
  45064. const normalScriptDefaultVar = `__default__`;
  45065. function processNormalScript(ctx, scopeId) {
  45066. var _a;
  45067. const script = ctx.descriptor.script;
  45068. try {
  45069. let content = script.content;
  45070. let map = script.map;
  45071. const scriptAst = ctx.scriptAst;
  45072. const bindings = analyzeScriptBindings(scriptAst.body);
  45073. const { cssVars } = ctx.descriptor;
  45074. const { genDefaultAs, isProd } = ctx.options;
  45075. if (cssVars.length || genDefaultAs) {
  45076. const defaultVar = genDefaultAs || normalScriptDefaultVar;
  45077. const s = new MagicString(content);
  45078. rewriteDefaultAST(scriptAst.body, s, defaultVar);
  45079. content = s.toString();
  45080. if (cssVars.length && !((_a = ctx.options.templateOptions) == null ? void 0 : _a.ssr)) {
  45081. content += genNormalScriptCssVarsCode(
  45082. cssVars,
  45083. bindings,
  45084. scopeId,
  45085. !!isProd,
  45086. defaultVar
  45087. );
  45088. }
  45089. if (!genDefaultAs) {
  45090. content += `
  45091. export default ${defaultVar}`;
  45092. }
  45093. }
  45094. return __spreadProps$2(__spreadValues$3({}, script), {
  45095. content,
  45096. map,
  45097. bindings,
  45098. scriptAst: scriptAst.body
  45099. });
  45100. } catch (e) {
  45101. return script;
  45102. }
  45103. }
  45104. var __defProp$2 = Object.defineProperty;
  45105. var __defProps$1 = Object.defineProperties;
  45106. var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
  45107. var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
  45108. var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
  45109. var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
  45110. var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  45111. var __spreadValues$2 = (a, b) => {
  45112. for (var prop in b || (b = {}))
  45113. if (__hasOwnProp$2.call(b, prop))
  45114. __defNormalProp$2(a, prop, b[prop]);
  45115. if (__getOwnPropSymbols$2)
  45116. for (var prop of __getOwnPropSymbols$2(b)) {
  45117. if (__propIsEnum$2.call(b, prop))
  45118. __defNormalProp$2(a, prop, b[prop]);
  45119. }
  45120. return a;
  45121. };
  45122. var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
  45123. class TypeScope {
  45124. constructor(filename, source, offset = 0, imports = /* @__PURE__ */ Object.create(null), types = /* @__PURE__ */ Object.create(null), declares = /* @__PURE__ */ Object.create(null)) {
  45125. this.filename = filename;
  45126. this.source = source;
  45127. this.offset = offset;
  45128. this.imports = imports;
  45129. this.types = types;
  45130. this.declares = declares;
  45131. this.isGenericScope = false;
  45132. this.resolvedImportSources = /* @__PURE__ */ Object.create(null);
  45133. this.exportedTypes = /* @__PURE__ */ Object.create(null);
  45134. this.exportedDeclares = /* @__PURE__ */ Object.create(null);
  45135. }
  45136. }
  45137. function resolveTypeElements(ctx, node, scope, typeParameters) {
  45138. const canCache = !typeParameters;
  45139. if (canCache && node._resolvedElements) {
  45140. return node._resolvedElements;
  45141. }
  45142. const resolved = innerResolveTypeElements(
  45143. ctx,
  45144. node,
  45145. node._ownerScope || scope || ctxToScope(ctx),
  45146. typeParameters
  45147. );
  45148. return canCache ? node._resolvedElements = resolved : resolved;
  45149. }
  45150. function innerResolveTypeElements(ctx, node, scope, typeParameters) {
  45151. var _a, _b;
  45152. if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
  45153. return { props: {} };
  45154. }
  45155. switch (node.type) {
  45156. case "TSTypeLiteral":
  45157. return typeElementsToMap(ctx, node.members, scope, typeParameters);
  45158. case "TSInterfaceDeclaration":
  45159. return resolveInterfaceMembers(ctx, node, scope, typeParameters);
  45160. case "TSTypeAliasDeclaration":
  45161. case "TSTypeAnnotation":
  45162. case "TSParenthesizedType":
  45163. return resolveTypeElements(
  45164. ctx,
  45165. node.typeAnnotation,
  45166. scope,
  45167. typeParameters
  45168. );
  45169. case "TSFunctionType": {
  45170. return { props: {}, calls: [node] };
  45171. }
  45172. case "TSUnionType":
  45173. case "TSIntersectionType":
  45174. return mergeElements(
  45175. node.types.map((t) => resolveTypeElements(ctx, t, scope, typeParameters)),
  45176. node.type
  45177. );
  45178. case "TSMappedType":
  45179. return resolveMappedType(ctx, node, scope, typeParameters);
  45180. case "TSIndexedAccessType": {
  45181. const types = resolveIndexType(ctx, node, scope);
  45182. return mergeElements(
  45183. types.map((t) => resolveTypeElements(ctx, t, t._ownerScope)),
  45184. "TSUnionType"
  45185. );
  45186. }
  45187. case "TSExpressionWithTypeArguments":
  45188. // referenced by interface extends
  45189. case "TSTypeReference": {
  45190. const typeName = getReferenceName(node);
  45191. if ((typeName === "ExtractPropTypes" || typeName === "ExtractPublicPropTypes") && node.typeParameters && ((_a = scope.imports[typeName]) == null ? void 0 : _a.source) === "vue") {
  45192. return resolveExtractPropTypes(
  45193. resolveTypeElements(
  45194. ctx,
  45195. node.typeParameters.params[0],
  45196. scope,
  45197. typeParameters
  45198. ),
  45199. scope
  45200. );
  45201. }
  45202. const resolved = resolveTypeReference(ctx, node, scope);
  45203. if (resolved) {
  45204. let typeParams;
  45205. if ((resolved.type === "TSTypeAliasDeclaration" || resolved.type === "TSInterfaceDeclaration") && resolved.typeParameters && node.typeParameters) {
  45206. typeParams = /* @__PURE__ */ Object.create(null);
  45207. resolved.typeParameters.params.forEach((p, i) => {
  45208. let param = typeParameters && typeParameters[p.name];
  45209. if (!param) param = node.typeParameters.params[i];
  45210. typeParams[p.name] = param;
  45211. });
  45212. }
  45213. return resolveTypeElements(
  45214. ctx,
  45215. resolved,
  45216. resolved._ownerScope,
  45217. typeParams
  45218. );
  45219. } else {
  45220. if (typeof typeName === "string") {
  45221. if (typeParameters && typeParameters[typeName]) {
  45222. return resolveTypeElements(
  45223. ctx,
  45224. typeParameters[typeName],
  45225. scope,
  45226. typeParameters
  45227. );
  45228. }
  45229. if (
  45230. // @ts-expect-error
  45231. SupportedBuiltinsSet.has(typeName)
  45232. ) {
  45233. return resolveBuiltin(
  45234. ctx,
  45235. node,
  45236. typeName,
  45237. scope,
  45238. typeParameters
  45239. );
  45240. } else if (typeName === "ReturnType" && node.typeParameters) {
  45241. const ret = resolveReturnType(
  45242. ctx,
  45243. node.typeParameters.params[0],
  45244. scope
  45245. );
  45246. if (ret) {
  45247. return resolveTypeElements(ctx, ret, scope);
  45248. }
  45249. }
  45250. }
  45251. return ctx.error(
  45252. `Unresolvable type reference or unsupported built-in utility type`,
  45253. node,
  45254. scope
  45255. );
  45256. }
  45257. }
  45258. case "TSImportType": {
  45259. if (getId(node.argument) === "vue" && ((_b = node.qualifier) == null ? void 0 : _b.type) === "Identifier" && node.qualifier.name === "ExtractPropTypes" && node.typeParameters) {
  45260. return resolveExtractPropTypes(
  45261. resolveTypeElements(ctx, node.typeParameters.params[0], scope),
  45262. scope
  45263. );
  45264. }
  45265. const sourceScope = importSourceToScope(
  45266. ctx,
  45267. node.argument,
  45268. scope,
  45269. node.argument.value
  45270. );
  45271. const resolved = resolveTypeReference(ctx, node, sourceScope);
  45272. if (resolved) {
  45273. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  45274. }
  45275. break;
  45276. }
  45277. case "TSTypeQuery":
  45278. {
  45279. const resolved = resolveTypeReference(ctx, node, scope);
  45280. if (resolved) {
  45281. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  45282. }
  45283. }
  45284. break;
  45285. }
  45286. return ctx.error(`Unresolvable type: ${node.type}`, node, scope);
  45287. }
  45288. function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameters) {
  45289. const res = { props: {} };
  45290. for (const e of elements) {
  45291. if (e.type === "TSPropertySignature" || e.type === "TSMethodSignature") {
  45292. if (typeParameters) {
  45293. scope = createChildScope(scope);
  45294. scope.isGenericScope = true;
  45295. Object.assign(scope.types, typeParameters);
  45296. }
  45297. e._ownerScope = scope;
  45298. const name = getStringLiteralKey(e);
  45299. if (name !== null) {
  45300. res.props[name] = e;
  45301. } else {
  45302. ctx.error(
  45303. `Unsupported computed key in type referenced by a macro`,
  45304. e.key,
  45305. scope
  45306. );
  45307. }
  45308. } else if (e.type === "TSCallSignatureDeclaration") {
  45309. (res.calls || (res.calls = [])).push(e);
  45310. }
  45311. }
  45312. return res;
  45313. }
  45314. function mergeElements(maps, type) {
  45315. if (maps.length === 1) return maps[0];
  45316. const res = { props: {} };
  45317. const { props: baseProps } = res;
  45318. for (const { props, calls } of maps) {
  45319. for (const key in props) {
  45320. if (!hasOwn(baseProps, key)) {
  45321. baseProps[key] = props[key];
  45322. } else {
  45323. baseProps[key] = createProperty(
  45324. baseProps[key].key,
  45325. {
  45326. type,
  45327. // @ts-expect-error
  45328. types: [baseProps[key], props[key]]
  45329. },
  45330. baseProps[key]._ownerScope,
  45331. baseProps[key].optional || props[key].optional
  45332. );
  45333. }
  45334. }
  45335. if (calls) {
  45336. (res.calls || (res.calls = [])).push(...calls);
  45337. }
  45338. }
  45339. return res;
  45340. }
  45341. function createProperty(key, typeAnnotation, scope, optional) {
  45342. return {
  45343. type: "TSPropertySignature",
  45344. key,
  45345. kind: "get",
  45346. optional,
  45347. typeAnnotation: {
  45348. type: "TSTypeAnnotation",
  45349. typeAnnotation
  45350. },
  45351. _ownerScope: scope
  45352. };
  45353. }
  45354. function resolveInterfaceMembers(ctx, node, scope, typeParameters) {
  45355. const base = typeElementsToMap(
  45356. ctx,
  45357. node.body.body,
  45358. node._ownerScope,
  45359. typeParameters
  45360. );
  45361. if (node.extends) {
  45362. for (const ext of node.extends) {
  45363. try {
  45364. const { props, calls } = resolveTypeElements(ctx, ext, scope);
  45365. for (const key in props) {
  45366. if (!hasOwn(base.props, key)) {
  45367. base.props[key] = props[key];
  45368. }
  45369. }
  45370. if (calls) {
  45371. ;
  45372. (base.calls || (base.calls = [])).push(...calls);
  45373. }
  45374. } catch (e) {
  45375. if (!ctx.silentOnExtendsFailure) {
  45376. ctx.error(
  45377. `Failed to resolve extends base type.
  45378. If this previously worked in 3.2, you can instruct the compiler to ignore this extend by adding /* @vue-ignore */ before it, for example:
  45379. interface Props extends /* @vue-ignore */ Base {}
  45380. Note: both in 3.2 or with the ignore, the properties in the base type are treated as fallthrough attrs at runtime.`,
  45381. ext,
  45382. scope
  45383. );
  45384. }
  45385. }
  45386. }
  45387. }
  45388. return base;
  45389. }
  45390. function resolveMappedType(ctx, node, scope, typeParameters) {
  45391. const res = { props: {} };
  45392. let keys;
  45393. if (node.nameType) {
  45394. const { name, constraint } = node.typeParameter;
  45395. scope = createChildScope(scope);
  45396. Object.assign(scope.types, __spreadProps$1(__spreadValues$2({}, typeParameters), { [name]: constraint }));
  45397. keys = resolveStringType(ctx, node.nameType, scope);
  45398. } else {
  45399. keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
  45400. }
  45401. for (const key of keys) {
  45402. res.props[key] = createProperty(
  45403. {
  45404. type: "Identifier",
  45405. name: key
  45406. },
  45407. node.typeAnnotation,
  45408. scope,
  45409. !!node.optional
  45410. );
  45411. }
  45412. return res;
  45413. }
  45414. function resolveIndexType(ctx, node, scope) {
  45415. var _a, _b;
  45416. if (node.indexType.type === "TSNumberKeyword") {
  45417. return resolveArrayElementType(ctx, node.objectType, scope);
  45418. }
  45419. const { indexType, objectType } = node;
  45420. const types = [];
  45421. let keys;
  45422. let resolved;
  45423. if (indexType.type === "TSStringKeyword") {
  45424. resolved = resolveTypeElements(ctx, objectType, scope);
  45425. keys = Object.keys(resolved.props);
  45426. } else {
  45427. keys = resolveStringType(ctx, indexType, scope);
  45428. resolved = resolveTypeElements(ctx, objectType, scope);
  45429. }
  45430. for (const key of keys) {
  45431. const targetType = (_b = (_a = resolved.props[key]) == null ? void 0 : _a.typeAnnotation) == null ? void 0 : _b.typeAnnotation;
  45432. if (targetType) {
  45433. targetType._ownerScope = resolved.props[key]._ownerScope;
  45434. types.push(targetType);
  45435. }
  45436. }
  45437. return types;
  45438. }
  45439. function resolveArrayElementType(ctx, node, scope) {
  45440. if (node.type === "TSArrayType") {
  45441. return [node.elementType];
  45442. }
  45443. if (node.type === "TSTupleType") {
  45444. return node.elementTypes.map(
  45445. (t) => t.type === "TSNamedTupleMember" ? t.elementType : t
  45446. );
  45447. }
  45448. if (node.type === "TSTypeReference") {
  45449. if (getReferenceName(node) === "Array" && node.typeParameters) {
  45450. return node.typeParameters.params;
  45451. } else {
  45452. const resolved = resolveTypeReference(ctx, node, scope);
  45453. if (resolved) {
  45454. return resolveArrayElementType(ctx, resolved, scope);
  45455. }
  45456. }
  45457. }
  45458. return ctx.error(
  45459. "Failed to resolve element type from target type",
  45460. node,
  45461. scope
  45462. );
  45463. }
  45464. function resolveStringType(ctx, node, scope, typeParameters) {
  45465. switch (node.type) {
  45466. case "StringLiteral":
  45467. return [node.value];
  45468. case "TSLiteralType":
  45469. return resolveStringType(ctx, node.literal, scope, typeParameters);
  45470. case "TSUnionType":
  45471. return node.types.map((t) => resolveStringType(ctx, t, scope, typeParameters)).flat();
  45472. case "TemplateLiteral": {
  45473. return resolveTemplateKeys(ctx, node, scope);
  45474. }
  45475. case "TSTypeReference": {
  45476. const resolved = resolveTypeReference(ctx, node, scope);
  45477. if (resolved) {
  45478. return resolveStringType(ctx, resolved, scope, typeParameters);
  45479. }
  45480. if (node.typeName.type === "Identifier") {
  45481. const name = node.typeName.name;
  45482. if (typeParameters && typeParameters[name]) {
  45483. return resolveStringType(
  45484. ctx,
  45485. typeParameters[name],
  45486. scope,
  45487. typeParameters
  45488. );
  45489. }
  45490. const getParam = (index = 0) => resolveStringType(
  45491. ctx,
  45492. node.typeParameters.params[index],
  45493. scope,
  45494. typeParameters
  45495. );
  45496. switch (name) {
  45497. case "Extract":
  45498. return getParam(1);
  45499. case "Exclude": {
  45500. const excluded = getParam(1);
  45501. return getParam().filter((s) => !excluded.includes(s));
  45502. }
  45503. case "Uppercase":
  45504. return getParam().map((s) => s.toUpperCase());
  45505. case "Lowercase":
  45506. return getParam().map((s) => s.toLowerCase());
  45507. case "Capitalize":
  45508. return getParam().map(capitalize);
  45509. case "Uncapitalize":
  45510. return getParam().map((s) => s[0].toLowerCase() + s.slice(1));
  45511. default:
  45512. ctx.error(
  45513. "Unsupported type when resolving index type",
  45514. node.typeName,
  45515. scope
  45516. );
  45517. }
  45518. }
  45519. }
  45520. }
  45521. return ctx.error("Failed to resolve index type into finite keys", node, scope);
  45522. }
  45523. function resolveTemplateKeys(ctx, node, scope) {
  45524. if (!node.expressions.length) {
  45525. return [node.quasis[0].value.raw];
  45526. }
  45527. const res = [];
  45528. const e = node.expressions[0];
  45529. const q = node.quasis[0];
  45530. const leading = q ? q.value.raw : ``;
  45531. const resolved = resolveStringType(ctx, e, scope);
  45532. const restResolved = resolveTemplateKeys(
  45533. ctx,
  45534. __spreadProps$1(__spreadValues$2({}, node), {
  45535. expressions: node.expressions.slice(1),
  45536. quasis: q ? node.quasis.slice(1) : node.quasis
  45537. }),
  45538. scope
  45539. );
  45540. for (const r of resolved) {
  45541. for (const rr of restResolved) {
  45542. res.push(leading + r + rr);
  45543. }
  45544. }
  45545. return res;
  45546. }
  45547. const SupportedBuiltinsSet = /* @__PURE__ */ new Set([
  45548. "Partial",
  45549. "Required",
  45550. "Readonly",
  45551. "Pick",
  45552. "Omit"
  45553. ]);
  45554. function resolveBuiltin(ctx, node, name, scope, typeParameters) {
  45555. const t = resolveTypeElements(
  45556. ctx,
  45557. node.typeParameters.params[0],
  45558. scope,
  45559. typeParameters
  45560. );
  45561. switch (name) {
  45562. case "Partial": {
  45563. const res2 = { props: {}, calls: t.calls };
  45564. Object.keys(t.props).forEach((key) => {
  45565. res2.props[key] = __spreadProps$1(__spreadValues$2({}, t.props[key]), { optional: true });
  45566. });
  45567. return res2;
  45568. }
  45569. case "Required": {
  45570. const res2 = { props: {}, calls: t.calls };
  45571. Object.keys(t.props).forEach((key) => {
  45572. res2.props[key] = __spreadProps$1(__spreadValues$2({}, t.props[key]), { optional: false });
  45573. });
  45574. return res2;
  45575. }
  45576. case "Readonly":
  45577. return t;
  45578. case "Pick": {
  45579. const picked = resolveStringType(
  45580. ctx,
  45581. node.typeParameters.params[1],
  45582. scope,
  45583. typeParameters
  45584. );
  45585. const res2 = { props: {}, calls: t.calls };
  45586. for (const key of picked) {
  45587. res2.props[key] = t.props[key];
  45588. }
  45589. return res2;
  45590. }
  45591. case "Omit":
  45592. const omitted = resolveStringType(
  45593. ctx,
  45594. node.typeParameters.params[1],
  45595. scope,
  45596. typeParameters
  45597. );
  45598. const res = { props: {}, calls: t.calls };
  45599. for (const key in t.props) {
  45600. if (!omitted.includes(key)) {
  45601. res.props[key] = t.props[key];
  45602. }
  45603. }
  45604. return res;
  45605. }
  45606. }
  45607. function resolveTypeReference(ctx, node, scope, name, onlyExported = false) {
  45608. const canCache = !(scope == null ? void 0 : scope.isGenericScope);
  45609. if (canCache && node._resolvedReference) {
  45610. return node._resolvedReference;
  45611. }
  45612. const resolved = innerResolveTypeReference(
  45613. ctx,
  45614. scope || ctxToScope(ctx),
  45615. name || getReferenceName(node),
  45616. node,
  45617. onlyExported
  45618. );
  45619. return canCache ? node._resolvedReference = resolved : resolved;
  45620. }
  45621. function innerResolveTypeReference(ctx, scope, name, node, onlyExported) {
  45622. if (typeof name === "string") {
  45623. if (scope.imports[name]) {
  45624. return resolveTypeFromImport(ctx, node, name, scope);
  45625. } else {
  45626. const lookupSource = node.type === "TSTypeQuery" ? onlyExported ? scope.exportedDeclares : scope.declares : onlyExported ? scope.exportedTypes : scope.types;
  45627. if (lookupSource[name]) {
  45628. return lookupSource[name];
  45629. } else {
  45630. const globalScopes = resolveGlobalScope(ctx);
  45631. if (globalScopes) {
  45632. for (const s of globalScopes) {
  45633. const src = node.type === "TSTypeQuery" ? s.declares : s.types;
  45634. if (src[name]) {
  45635. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(s.filename);
  45636. return src[name];
  45637. }
  45638. }
  45639. }
  45640. }
  45641. }
  45642. } else {
  45643. let ns = innerResolveTypeReference(ctx, scope, name[0], node, onlyExported);
  45644. if (ns) {
  45645. if (ns.type !== "TSModuleDeclaration") {
  45646. ns = ns._ns;
  45647. }
  45648. if (ns) {
  45649. const childScope = moduleDeclToScope(ctx, ns, ns._ownerScope || scope);
  45650. return innerResolveTypeReference(
  45651. ctx,
  45652. childScope,
  45653. name.length > 2 ? name.slice(1) : name[name.length - 1],
  45654. node,
  45655. !ns.declare
  45656. );
  45657. }
  45658. }
  45659. }
  45660. }
  45661. function getReferenceName(node) {
  45662. const ref = node.type === "TSTypeReference" ? node.typeName : node.type === "TSExpressionWithTypeArguments" ? node.expression : node.type === "TSImportType" ? node.qualifier : node.exprName;
  45663. if ((ref == null ? void 0 : ref.type) === "Identifier") {
  45664. return ref.name;
  45665. } else if ((ref == null ? void 0 : ref.type) === "TSQualifiedName") {
  45666. return qualifiedNameToPath(ref);
  45667. } else {
  45668. return "default";
  45669. }
  45670. }
  45671. function qualifiedNameToPath(node) {
  45672. if (node.type === "Identifier") {
  45673. return [node.name];
  45674. } else {
  45675. return [...qualifiedNameToPath(node.left), node.right.name];
  45676. }
  45677. }
  45678. function resolveGlobalScope(ctx) {
  45679. if (ctx.options.globalTypeFiles) {
  45680. const fs = resolveFS(ctx);
  45681. if (!fs) {
  45682. throw new Error("[vue/compiler-sfc] globalTypeFiles requires fs access.");
  45683. }
  45684. return ctx.options.globalTypeFiles.map(
  45685. (file) => fileToScope(ctx, normalizePath(file), true)
  45686. );
  45687. }
  45688. }
  45689. let ts;
  45690. let loadTS;
  45691. function registerTS(_loadTS) {
  45692. loadTS = () => {
  45693. try {
  45694. return _loadTS();
  45695. } catch (err) {
  45696. if (typeof err.message === "string" && err.message.includes("Cannot find module")) {
  45697. throw new Error(
  45698. 'Failed to load TypeScript, which is required for resolving imported types. Please make sure "TypeScript" is installed as a project dependency.'
  45699. );
  45700. } else {
  45701. throw new Error(
  45702. "Failed to load TypeScript for resolving imported types."
  45703. );
  45704. }
  45705. }
  45706. };
  45707. }
  45708. function resolveFS(ctx) {
  45709. if (ctx.fs) {
  45710. return ctx.fs;
  45711. }
  45712. if (!ts && loadTS) {
  45713. ts = loadTS();
  45714. }
  45715. const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
  45716. if (!fs) {
  45717. return;
  45718. }
  45719. return ctx.fs = {
  45720. fileExists(file) {
  45721. if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
  45722. file = file.replace(/\.ts$/, "");
  45723. }
  45724. return fs.fileExists(file);
  45725. },
  45726. readFile(file) {
  45727. if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
  45728. file = file.replace(/\.ts$/, "");
  45729. }
  45730. return fs.readFile(file);
  45731. },
  45732. realpath: fs.realpath
  45733. };
  45734. }
  45735. function resolveTypeFromImport(ctx, node, name, scope) {
  45736. const { source, imported } = scope.imports[name];
  45737. const sourceScope = importSourceToScope(ctx, node, scope, source);
  45738. return resolveTypeReference(ctx, node, sourceScope, imported, true);
  45739. }
  45740. function importSourceToScope(ctx, node, scope, source) {
  45741. let fs;
  45742. try {
  45743. fs = resolveFS(ctx);
  45744. } catch (err) {
  45745. return ctx.error(err.message, node, scope);
  45746. }
  45747. if (!fs) {
  45748. return ctx.error(
  45749. `No fs option provided to \`compileScript\` in non-Node environment. File system access is required for resolving imported types.`,
  45750. node,
  45751. scope
  45752. );
  45753. }
  45754. let resolved = scope.resolvedImportSources[source];
  45755. if (!resolved) {
  45756. if (source.startsWith("..")) {
  45757. const osSpecificJoinFn = joinPaths;
  45758. const filename = osSpecificJoinFn(dirname(scope.filename), source);
  45759. resolved = resolveExt(filename, fs);
  45760. } else if (source[0] === ".") {
  45761. const filename = joinPaths(dirname(scope.filename), source);
  45762. resolved = resolveExt(filename, fs);
  45763. } else {
  45764. {
  45765. return ctx.error(
  45766. `Type import from non-relative sources is not supported in the browser build.`,
  45767. node,
  45768. scope
  45769. );
  45770. }
  45771. }
  45772. if (resolved) {
  45773. resolved = scope.resolvedImportSources[source] = normalizePath(resolved);
  45774. }
  45775. }
  45776. if (resolved) {
  45777. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(resolved);
  45778. return fileToScope(ctx, resolved);
  45779. } else {
  45780. return ctx.error(
  45781. `Failed to resolve import source ${JSON.stringify(source)}.`,
  45782. node,
  45783. scope
  45784. );
  45785. }
  45786. }
  45787. function resolveExt(filename, fs) {
  45788. filename = filename.replace(/\.js$/, "");
  45789. const tryResolve = (filename2) => {
  45790. if (fs.fileExists(filename2)) return filename2;
  45791. };
  45792. return tryResolve(filename) || tryResolve(filename + `.ts`) || tryResolve(filename + `.tsx`) || tryResolve(filename + `.d.ts`) || tryResolve(joinPaths(filename, `index.ts`)) || tryResolve(joinPaths(filename, `index.tsx`)) || tryResolve(joinPaths(filename, `index.d.ts`));
  45793. }
  45794. const tsConfigCache = createCache();
  45795. const tsConfigRefMap = /* @__PURE__ */ new Map();
  45796. const fileToScopeCache = createCache();
  45797. function invalidateTypeCache(filename) {
  45798. filename = normalizePath(filename);
  45799. fileToScopeCache.delete(filename);
  45800. tsConfigCache.delete(filename);
  45801. const affectedConfig = tsConfigRefMap.get(filename);
  45802. if (affectedConfig) tsConfigCache.delete(affectedConfig);
  45803. }
  45804. function fileToScope(ctx, filename, asGlobal = false) {
  45805. const cached = fileToScopeCache.get(filename);
  45806. if (cached) {
  45807. return cached;
  45808. }
  45809. const fs = resolveFS(ctx);
  45810. const source = fs.readFile(filename) || "";
  45811. const body = parseFile(filename, source, fs, ctx.options.babelParserPlugins);
  45812. const scope = new TypeScope(filename, source, 0, recordImports(body));
  45813. recordTypes(ctx, body, scope, asGlobal);
  45814. fileToScopeCache.set(filename, scope);
  45815. return scope;
  45816. }
  45817. function parseFile(filename, content, fs, parserPlugins) {
  45818. const ext = extname(filename);
  45819. if (ext === ".ts" || ext === ".mts" || ext === ".tsx" || ext === ".mtsx") {
  45820. return libExports.parse(content, {
  45821. plugins: resolveParserPlugins(
  45822. ext.slice(1),
  45823. parserPlugins,
  45824. /\.d\.m?ts$/.test(filename)
  45825. ),
  45826. sourceType: "module"
  45827. }).program.body;
  45828. }
  45829. const isUnknownTypeSource = !/\.[cm]?[tj]sx?$/.test(filename);
  45830. const arbitraryTypeSource = `${filename.slice(0, -ext.length)}.d${ext}.ts`;
  45831. const hasArbitraryTypeDeclaration = isUnknownTypeSource && fs.fileExists(arbitraryTypeSource);
  45832. if (hasArbitraryTypeDeclaration) {
  45833. return libExports.parse(fs.readFile(arbitraryTypeSource), {
  45834. plugins: resolveParserPlugins("ts", parserPlugins, true),
  45835. sourceType: "module"
  45836. }).program.body;
  45837. }
  45838. if (ext === ".vue") {
  45839. const {
  45840. descriptor: { script, scriptSetup }
  45841. } = parse$2(content);
  45842. if (!script && !scriptSetup) {
  45843. return [];
  45844. }
  45845. const scriptOffset = script ? script.loc.start.offset : Infinity;
  45846. const scriptSetupOffset = scriptSetup ? scriptSetup.loc.start.offset : Infinity;
  45847. const firstBlock = scriptOffset < scriptSetupOffset ? script : scriptSetup;
  45848. const secondBlock = scriptOffset < scriptSetupOffset ? scriptSetup : script;
  45849. let scriptContent = " ".repeat(Math.min(scriptOffset, scriptSetupOffset)) + firstBlock.content;
  45850. if (secondBlock) {
  45851. scriptContent += " ".repeat(secondBlock.loc.start.offset - script.loc.end.offset) + secondBlock.content;
  45852. }
  45853. const lang = (script == null ? void 0 : script.lang) || (scriptSetup == null ? void 0 : scriptSetup.lang);
  45854. return libExports.parse(scriptContent, {
  45855. plugins: resolveParserPlugins(lang, parserPlugins),
  45856. sourceType: "module"
  45857. }).program.body;
  45858. }
  45859. return [];
  45860. }
  45861. function ctxToScope(ctx) {
  45862. if (ctx.scope) {
  45863. return ctx.scope;
  45864. }
  45865. const body = "ast" in ctx ? ctx.ast : ctx.scriptAst ? [...ctx.scriptAst.body, ...ctx.scriptSetupAst.body] : ctx.scriptSetupAst.body;
  45866. const scope = new TypeScope(
  45867. ctx.filename,
  45868. ctx.source,
  45869. "startOffset" in ctx ? ctx.startOffset : 0,
  45870. "userImports" in ctx ? Object.create(ctx.userImports) : recordImports(body)
  45871. );
  45872. recordTypes(ctx, body, scope);
  45873. return ctx.scope = scope;
  45874. }
  45875. function moduleDeclToScope(ctx, node, parentScope) {
  45876. if (node._resolvedChildScope) {
  45877. return node._resolvedChildScope;
  45878. }
  45879. const scope = createChildScope(parentScope);
  45880. if (node.body.type === "TSModuleDeclaration") {
  45881. const decl = node.body;
  45882. decl._ownerScope = scope;
  45883. const id = getId(decl.id);
  45884. scope.types[id] = scope.exportedTypes[id] = decl;
  45885. } else {
  45886. recordTypes(ctx, node.body.body, scope);
  45887. }
  45888. return node._resolvedChildScope = scope;
  45889. }
  45890. function createChildScope(parentScope) {
  45891. return new TypeScope(
  45892. parentScope.filename,
  45893. parentScope.source,
  45894. parentScope.offset,
  45895. Object.create(parentScope.imports),
  45896. Object.create(parentScope.types),
  45897. Object.create(parentScope.declares)
  45898. );
  45899. }
  45900. const importExportRE = /^Import|^Export/;
  45901. function recordTypes(ctx, body, scope, asGlobal = false) {
  45902. const { types, declares, exportedTypes, exportedDeclares, imports } = scope;
  45903. const isAmbient = asGlobal ? !body.some((s) => importExportRE.test(s.type)) : false;
  45904. for (const stmt of body) {
  45905. if (asGlobal) {
  45906. if (isAmbient) {
  45907. if (stmt.declare) {
  45908. recordType(stmt, types, declares);
  45909. }
  45910. } else if (stmt.type === "TSModuleDeclaration" && stmt.global) {
  45911. for (const s of stmt.body.body) {
  45912. if (s.type === "ExportNamedDeclaration" && s.declaration) {
  45913. recordType(s.declaration, types, declares);
  45914. } else {
  45915. recordType(s, types, declares);
  45916. }
  45917. }
  45918. }
  45919. } else {
  45920. recordType(stmt, types, declares);
  45921. }
  45922. }
  45923. if (!asGlobal) {
  45924. for (const stmt of body) {
  45925. if (stmt.type === "ExportNamedDeclaration") {
  45926. if (stmt.declaration) {
  45927. recordType(stmt.declaration, types, declares);
  45928. recordType(stmt.declaration, exportedTypes, exportedDeclares);
  45929. } else {
  45930. for (const spec of stmt.specifiers) {
  45931. if (spec.type === "ExportSpecifier") {
  45932. const local = spec.local.name;
  45933. const exported = getId(spec.exported);
  45934. if (stmt.source) {
  45935. imports[exported] = {
  45936. source: stmt.source.value,
  45937. imported: local
  45938. };
  45939. exportedTypes[exported] = {
  45940. type: "TSTypeReference",
  45941. typeName: {
  45942. type: "Identifier",
  45943. name: local
  45944. },
  45945. _ownerScope: scope
  45946. };
  45947. } else if (types[local]) {
  45948. exportedTypes[exported] = types[local];
  45949. }
  45950. }
  45951. }
  45952. }
  45953. } else if (stmt.type === "ExportAllDeclaration") {
  45954. const sourceScope = importSourceToScope(
  45955. ctx,
  45956. stmt.source,
  45957. scope,
  45958. stmt.source.value
  45959. );
  45960. Object.assign(scope.exportedTypes, sourceScope.exportedTypes);
  45961. } else if (stmt.type === "ExportDefaultDeclaration" && stmt.declaration) {
  45962. if (stmt.declaration.type !== "Identifier") {
  45963. recordType(stmt.declaration, types, declares, "default");
  45964. recordType(
  45965. stmt.declaration,
  45966. exportedTypes,
  45967. exportedDeclares,
  45968. "default"
  45969. );
  45970. } else if (types[stmt.declaration.name]) {
  45971. exportedTypes["default"] = types[stmt.declaration.name];
  45972. }
  45973. }
  45974. }
  45975. }
  45976. for (const key of Object.keys(types)) {
  45977. const node = types[key];
  45978. node._ownerScope = scope;
  45979. if (node._ns) node._ns._ownerScope = scope;
  45980. }
  45981. for (const key of Object.keys(declares)) {
  45982. declares[key]._ownerScope = scope;
  45983. }
  45984. }
  45985. function recordType(node, types, declares, overwriteId) {
  45986. switch (node.type) {
  45987. case "TSInterfaceDeclaration":
  45988. case "TSEnumDeclaration":
  45989. case "TSModuleDeclaration": {
  45990. if (node.type === "TSModuleDeclaration" && node.global) {
  45991. const body = node.body;
  45992. for (const s of body.body) {
  45993. if (s.type === "ExportNamedDeclaration" && s.declaration) {
  45994. recordType(s.declaration, types, declares);
  45995. } else {
  45996. recordType(s, types, declares);
  45997. }
  45998. }
  45999. break;
  46000. }
  46001. const id = overwriteId || getId(node.id);
  46002. let existing = types[id];
  46003. if (existing) {
  46004. if (node.type === "TSModuleDeclaration") {
  46005. if (existing.type === "TSModuleDeclaration") {
  46006. mergeNamespaces(existing, node);
  46007. } else {
  46008. attachNamespace(existing, node);
  46009. }
  46010. break;
  46011. }
  46012. if (existing.type === "TSModuleDeclaration") {
  46013. types[id] = node;
  46014. attachNamespace(node, existing);
  46015. break;
  46016. }
  46017. if (existing.type !== node.type) {
  46018. break;
  46019. }
  46020. if (node.type === "TSInterfaceDeclaration") {
  46021. existing.body.body.push(...node.body.body);
  46022. } else {
  46023. existing.members.push(...node.members);
  46024. }
  46025. } else {
  46026. types[id] = node;
  46027. }
  46028. break;
  46029. }
  46030. case "ClassDeclaration":
  46031. if (overwriteId || node.id) types[overwriteId || getId(node.id)] = node;
  46032. break;
  46033. case "TSTypeAliasDeclaration":
  46034. types[node.id.name] = node.typeParameters ? node : node.typeAnnotation;
  46035. break;
  46036. case "TSDeclareFunction":
  46037. if (node.id) declares[node.id.name] = node;
  46038. break;
  46039. case "VariableDeclaration": {
  46040. if (node.declare) {
  46041. for (const decl of node.declarations) {
  46042. if (decl.id.type === "Identifier" && decl.id.typeAnnotation) {
  46043. declares[decl.id.name] = decl.id.typeAnnotation.typeAnnotation;
  46044. }
  46045. }
  46046. }
  46047. break;
  46048. }
  46049. }
  46050. }
  46051. function mergeNamespaces(to, from) {
  46052. const toBody = to.body;
  46053. const fromBody = from.body;
  46054. if (toBody.type === "TSModuleDeclaration") {
  46055. if (fromBody.type === "TSModuleDeclaration") {
  46056. mergeNamespaces(toBody, fromBody);
  46057. } else {
  46058. fromBody.body.push({
  46059. type: "ExportNamedDeclaration",
  46060. declaration: toBody,
  46061. exportKind: "type",
  46062. specifiers: []
  46063. });
  46064. }
  46065. } else if (fromBody.type === "TSModuleDeclaration") {
  46066. toBody.body.push({
  46067. type: "ExportNamedDeclaration",
  46068. declaration: fromBody,
  46069. exportKind: "type",
  46070. specifiers: []
  46071. });
  46072. } else {
  46073. toBody.body.push(...fromBody.body);
  46074. }
  46075. }
  46076. function attachNamespace(to, ns) {
  46077. if (!to._ns) {
  46078. to._ns = ns;
  46079. } else {
  46080. mergeNamespaces(to._ns, ns);
  46081. }
  46082. }
  46083. function recordImports(body) {
  46084. const imports = /* @__PURE__ */ Object.create(null);
  46085. for (const s of body) {
  46086. recordImport(s, imports);
  46087. }
  46088. return imports;
  46089. }
  46090. function recordImport(node, imports) {
  46091. if (node.type !== "ImportDeclaration") {
  46092. return;
  46093. }
  46094. for (const s of node.specifiers) {
  46095. imports[s.local.name] = {
  46096. imported: getImportedName(s),
  46097. source: node.source.value
  46098. };
  46099. }
  46100. }
  46101. function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false, typeParameters) {
  46102. if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
  46103. return [UNKNOWN_TYPE];
  46104. }
  46105. const prevSilent = ctx.silentOnExtendsFailure;
  46106. ctx.silentOnExtendsFailure = true;
  46107. try {
  46108. switch (node.type) {
  46109. case "TSStringKeyword":
  46110. return ["String"];
  46111. case "TSNumberKeyword":
  46112. return ["Number"];
  46113. case "TSBooleanKeyword":
  46114. return ["Boolean"];
  46115. case "TSObjectKeyword":
  46116. return ["Object"];
  46117. case "TSNullKeyword":
  46118. return ["null"];
  46119. case "TSTypeLiteral":
  46120. case "TSInterfaceDeclaration": {
  46121. const types = /* @__PURE__ */ new Set();
  46122. const members = node.type === "TSTypeLiteral" ? node.members : node.body.body;
  46123. for (const m of members) {
  46124. if (isKeyOf) {
  46125. if (m.type === "TSPropertySignature" && m.key.type === "NumericLiteral") {
  46126. types.add("Number");
  46127. } else if (m.type === "TSIndexSignature") {
  46128. const annotation = m.parameters[0].typeAnnotation;
  46129. if (annotation && annotation.type !== "Noop") {
  46130. const type = inferRuntimeType(
  46131. ctx,
  46132. annotation.typeAnnotation,
  46133. scope
  46134. )[0];
  46135. if (type === UNKNOWN_TYPE) return [UNKNOWN_TYPE];
  46136. types.add(type);
  46137. }
  46138. } else {
  46139. types.add("String");
  46140. }
  46141. } else if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
  46142. types.add("Function");
  46143. } else {
  46144. types.add("Object");
  46145. }
  46146. }
  46147. return types.size ? Array.from(types) : [isKeyOf ? UNKNOWN_TYPE : "Object"];
  46148. }
  46149. case "TSPropertySignature":
  46150. if (node.typeAnnotation) {
  46151. return inferRuntimeType(
  46152. ctx,
  46153. node.typeAnnotation.typeAnnotation,
  46154. scope
  46155. );
  46156. }
  46157. break;
  46158. case "TSMethodSignature":
  46159. case "TSFunctionType":
  46160. return ["Function"];
  46161. case "TSArrayType":
  46162. case "TSTupleType":
  46163. return ["Array"];
  46164. case "TSLiteralType":
  46165. switch (node.literal.type) {
  46166. case "StringLiteral":
  46167. return ["String"];
  46168. case "BooleanLiteral":
  46169. return ["Boolean"];
  46170. case "NumericLiteral":
  46171. case "BigIntLiteral":
  46172. return ["Number"];
  46173. default:
  46174. return [UNKNOWN_TYPE];
  46175. }
  46176. case "TSTypeReference": {
  46177. const resolved = resolveTypeReference(ctx, node, scope);
  46178. if (resolved) {
  46179. if (resolved.type === "TSTypeAliasDeclaration") {
  46180. if (resolved.typeAnnotation.type === "TSFunctionType") {
  46181. return ["Function"];
  46182. }
  46183. if (node.typeParameters) {
  46184. const typeParams = /* @__PURE__ */ Object.create(null);
  46185. if (resolved.typeParameters) {
  46186. resolved.typeParameters.params.forEach((p, i) => {
  46187. typeParams[p.name] = node.typeParameters.params[i];
  46188. });
  46189. }
  46190. return inferRuntimeType(
  46191. ctx,
  46192. resolved.typeAnnotation,
  46193. resolved._ownerScope,
  46194. isKeyOf,
  46195. typeParams
  46196. );
  46197. }
  46198. }
  46199. return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf);
  46200. }
  46201. if (node.typeName.type === "Identifier") {
  46202. if (typeParameters && typeParameters[node.typeName.name]) {
  46203. return inferRuntimeType(
  46204. ctx,
  46205. typeParameters[node.typeName.name],
  46206. scope,
  46207. isKeyOf,
  46208. typeParameters
  46209. );
  46210. }
  46211. if (isKeyOf) {
  46212. switch (node.typeName.name) {
  46213. case "String":
  46214. case "Array":
  46215. case "ArrayLike":
  46216. case "Parameters":
  46217. case "ConstructorParameters":
  46218. case "ReadonlyArray":
  46219. return ["String", "Number"];
  46220. // TS built-in utility types
  46221. case "Record":
  46222. case "Partial":
  46223. case "Required":
  46224. case "Readonly":
  46225. if (node.typeParameters && node.typeParameters.params[0]) {
  46226. return inferRuntimeType(
  46227. ctx,
  46228. node.typeParameters.params[0],
  46229. scope,
  46230. true
  46231. );
  46232. }
  46233. break;
  46234. case "Pick":
  46235. case "Extract":
  46236. if (node.typeParameters && node.typeParameters.params[1]) {
  46237. return inferRuntimeType(
  46238. ctx,
  46239. node.typeParameters.params[1],
  46240. scope
  46241. );
  46242. }
  46243. break;
  46244. case "Function":
  46245. case "Object":
  46246. case "Set":
  46247. case "Map":
  46248. case "WeakSet":
  46249. case "WeakMap":
  46250. case "Date":
  46251. case "Promise":
  46252. case "Error":
  46253. case "Uppercase":
  46254. case "Lowercase":
  46255. case "Capitalize":
  46256. case "Uncapitalize":
  46257. case "ReadonlyMap":
  46258. case "ReadonlySet":
  46259. return ["String"];
  46260. }
  46261. } else {
  46262. switch (node.typeName.name) {
  46263. case "Array":
  46264. case "Function":
  46265. case "Object":
  46266. case "Set":
  46267. case "Map":
  46268. case "WeakSet":
  46269. case "WeakMap":
  46270. case "Date":
  46271. case "Promise":
  46272. case "Error":
  46273. return [node.typeName.name];
  46274. // TS built-in utility types
  46275. // https://www.typescriptlang.org/docs/handbook/utility-types.html
  46276. case "Partial":
  46277. case "Required":
  46278. case "Readonly":
  46279. case "Record":
  46280. case "Pick":
  46281. case "Omit":
  46282. case "InstanceType":
  46283. return ["Object"];
  46284. case "Uppercase":
  46285. case "Lowercase":
  46286. case "Capitalize":
  46287. case "Uncapitalize":
  46288. return ["String"];
  46289. case "Parameters":
  46290. case "ConstructorParameters":
  46291. case "ReadonlyArray":
  46292. return ["Array"];
  46293. case "ReadonlyMap":
  46294. return ["Map"];
  46295. case "ReadonlySet":
  46296. return ["Set"];
  46297. case "NonNullable":
  46298. if (node.typeParameters && node.typeParameters.params[0]) {
  46299. return inferRuntimeType(
  46300. ctx,
  46301. node.typeParameters.params[0],
  46302. scope
  46303. ).filter((t) => t !== "null");
  46304. }
  46305. break;
  46306. case "Extract":
  46307. if (node.typeParameters && node.typeParameters.params[1]) {
  46308. return inferRuntimeType(
  46309. ctx,
  46310. node.typeParameters.params[1],
  46311. scope
  46312. );
  46313. }
  46314. break;
  46315. case "Exclude":
  46316. case "OmitThisParameter":
  46317. if (node.typeParameters && node.typeParameters.params[0]) {
  46318. return inferRuntimeType(
  46319. ctx,
  46320. node.typeParameters.params[0],
  46321. scope
  46322. );
  46323. }
  46324. break;
  46325. }
  46326. }
  46327. }
  46328. break;
  46329. }
  46330. case "TSParenthesizedType":
  46331. return inferRuntimeType(ctx, node.typeAnnotation, scope);
  46332. case "TSUnionType":
  46333. return flattenTypes(ctx, node.types, scope, isKeyOf, typeParameters);
  46334. case "TSIntersectionType": {
  46335. return flattenTypes(
  46336. ctx,
  46337. node.types,
  46338. scope,
  46339. isKeyOf,
  46340. typeParameters
  46341. ).filter((t) => t !== UNKNOWN_TYPE);
  46342. }
  46343. case "TSMappedType": {
  46344. const { typeAnnotation, typeParameter } = node;
  46345. if (typeAnnotation && typeAnnotation.type === "TSIndexedAccessType" && typeParameter && typeParameter.constraint && typeParameters) {
  46346. const constraint = typeParameter.constraint;
  46347. if (constraint.type === "TSTypeOperator" && constraint.operator === "keyof" && constraint.typeAnnotation && constraint.typeAnnotation.type === "TSTypeReference" && constraint.typeAnnotation.typeName.type === "Identifier") {
  46348. const typeName = constraint.typeAnnotation.typeName.name;
  46349. const index = typeAnnotation.indexType;
  46350. const obj = typeAnnotation.objectType;
  46351. if (obj && obj.type === "TSTypeReference" && obj.typeName.type === "Identifier" && obj.typeName.name === typeName && index && index.type === "TSTypeReference" && index.typeName.type === "Identifier" && index.typeName.name === typeParameter.name) {
  46352. const targetType = typeParameters[typeName];
  46353. if (targetType) {
  46354. return inferRuntimeType(ctx, targetType, scope);
  46355. }
  46356. }
  46357. }
  46358. }
  46359. return [UNKNOWN_TYPE];
  46360. }
  46361. case "TSEnumDeclaration":
  46362. return inferEnumType(node);
  46363. case "TSSymbolKeyword":
  46364. return ["Symbol"];
  46365. case "TSIndexedAccessType": {
  46366. const types = resolveIndexType(ctx, node, scope);
  46367. return flattenTypes(ctx, types, scope, isKeyOf);
  46368. }
  46369. case "ClassDeclaration":
  46370. return ["Object"];
  46371. case "TSImportType": {
  46372. const sourceScope = importSourceToScope(
  46373. ctx,
  46374. node.argument,
  46375. scope,
  46376. node.argument.value
  46377. );
  46378. const resolved = resolveTypeReference(ctx, node, sourceScope);
  46379. if (resolved) {
  46380. return inferRuntimeType(ctx, resolved, resolved._ownerScope);
  46381. }
  46382. break;
  46383. }
  46384. case "TSTypeQuery": {
  46385. const id = node.exprName;
  46386. if (id.type === "Identifier") {
  46387. const matched = scope.declares[id.name];
  46388. if (matched) {
  46389. return inferRuntimeType(ctx, matched, matched._ownerScope, isKeyOf);
  46390. }
  46391. }
  46392. break;
  46393. }
  46394. // e.g. readonly
  46395. case "TSTypeOperator": {
  46396. return inferRuntimeType(
  46397. ctx,
  46398. node.typeAnnotation,
  46399. scope,
  46400. node.operator === "keyof"
  46401. );
  46402. }
  46403. case "TSAnyKeyword": {
  46404. if (isKeyOf) {
  46405. return ["String", "Number", "Symbol"];
  46406. }
  46407. break;
  46408. }
  46409. }
  46410. } catch (e) {
  46411. } finally {
  46412. ctx.silentOnExtendsFailure = prevSilent;
  46413. }
  46414. return [UNKNOWN_TYPE];
  46415. }
  46416. function flattenTypes(ctx, types, scope, isKeyOf = false, typeParameters = void 0) {
  46417. if (types.length === 1) {
  46418. return inferRuntimeType(
  46419. ctx,
  46420. types[0],
  46421. types[0]._ownerScope || scope,
  46422. isKeyOf,
  46423. typeParameters
  46424. );
  46425. }
  46426. return [
  46427. ...new Set(
  46428. [].concat(
  46429. ...types.map(
  46430. (t) => inferRuntimeType(
  46431. ctx,
  46432. t,
  46433. t._ownerScope || scope,
  46434. isKeyOf,
  46435. typeParameters
  46436. )
  46437. )
  46438. )
  46439. )
  46440. ];
  46441. }
  46442. function inferEnumType(node) {
  46443. const types = /* @__PURE__ */ new Set();
  46444. for (const m of node.members) {
  46445. if (m.initializer) {
  46446. switch (m.initializer.type) {
  46447. case "StringLiteral":
  46448. types.add("String");
  46449. break;
  46450. case "NumericLiteral":
  46451. types.add("Number");
  46452. break;
  46453. }
  46454. }
  46455. }
  46456. return types.size ? [...types] : ["Number"];
  46457. }
  46458. function resolveExtractPropTypes({ props }, scope) {
  46459. const res = { props: {} };
  46460. for (const key in props) {
  46461. const raw = props[key];
  46462. res.props[key] = reverseInferType(
  46463. raw.key,
  46464. raw.typeAnnotation.typeAnnotation,
  46465. scope
  46466. );
  46467. }
  46468. return res;
  46469. }
  46470. function reverseInferType(key, node, scope, optional = true, checkObjectSyntax = true) {
  46471. if (checkObjectSyntax && node.type === "TSTypeLiteral") {
  46472. const typeType = findStaticPropertyType(node, "type");
  46473. if (typeType) {
  46474. const requiredType = findStaticPropertyType(node, "required");
  46475. const optional2 = requiredType && requiredType.type === "TSLiteralType" && requiredType.literal.type === "BooleanLiteral" ? !requiredType.literal.value : true;
  46476. return reverseInferType(key, typeType, scope, optional2, false);
  46477. }
  46478. } else if (node.type === "TSTypeReference" && node.typeName.type === "Identifier") {
  46479. if (node.typeName.name.endsWith("Constructor")) {
  46480. return createProperty(
  46481. key,
  46482. ctorToType(node.typeName.name),
  46483. scope,
  46484. optional
  46485. );
  46486. } else if (node.typeName.name === "PropType" && node.typeParameters) {
  46487. return createProperty(key, node.typeParameters.params[0], scope, optional);
  46488. }
  46489. }
  46490. if ((node.type === "TSTypeReference" || node.type === "TSImportType") && node.typeParameters) {
  46491. for (const t of node.typeParameters.params) {
  46492. const inferred = reverseInferType(key, t, scope, optional);
  46493. if (inferred) return inferred;
  46494. }
  46495. }
  46496. return createProperty(key, { type: `TSNullKeyword` }, scope, optional);
  46497. }
  46498. function ctorToType(ctorType) {
  46499. const ctor = ctorType.slice(0, -11);
  46500. switch (ctor) {
  46501. case "String":
  46502. case "Number":
  46503. case "Boolean":
  46504. return { type: `TS${ctor}Keyword` };
  46505. case "Array":
  46506. case "Function":
  46507. case "Object":
  46508. case "Set":
  46509. case "Map":
  46510. case "WeakSet":
  46511. case "WeakMap":
  46512. case "Date":
  46513. case "Promise":
  46514. return {
  46515. type: "TSTypeReference",
  46516. typeName: { type: "Identifier", name: ctor }
  46517. };
  46518. }
  46519. return { type: `TSNullKeyword` };
  46520. }
  46521. function findStaticPropertyType(node, key) {
  46522. const prop = node.members.find(
  46523. (m) => m.type === "TSPropertySignature" && getStringLiteralKey(m) === key && m.typeAnnotation
  46524. );
  46525. return prop && prop.typeAnnotation.typeAnnotation;
  46526. }
  46527. function resolveReturnType(ctx, arg, scope) {
  46528. var _a;
  46529. let resolved = arg;
  46530. if (arg.type === "TSTypeReference" || arg.type === "TSTypeQuery" || arg.type === "TSImportType") {
  46531. resolved = resolveTypeReference(ctx, arg, scope);
  46532. }
  46533. if (!resolved) return;
  46534. if (resolved.type === "TSFunctionType") {
  46535. return (_a = resolved.typeAnnotation) == null ? void 0 : _a.typeAnnotation;
  46536. }
  46537. if (resolved.type === "TSDeclareFunction") {
  46538. return resolved.returnType;
  46539. }
  46540. }
  46541. function resolveUnionType(ctx, node, scope) {
  46542. if (node.type === "TSTypeReference") {
  46543. const resolved = resolveTypeReference(ctx, node, scope);
  46544. if (resolved) node = resolved;
  46545. }
  46546. let types;
  46547. if (node.type === "TSUnionType") {
  46548. types = node.types.flatMap((node2) => resolveUnionType(ctx, node2, scope));
  46549. } else {
  46550. types = [node];
  46551. }
  46552. return types;
  46553. }
  46554. const DEFINE_MODEL = "defineModel";
  46555. function processDefineModel(ctx, node, declId) {
  46556. if (!isCallOf(node, DEFINE_MODEL)) {
  46557. return false;
  46558. }
  46559. ctx.hasDefineModelCall = true;
  46560. const type = node.typeParameters && node.typeParameters.params[0] || void 0;
  46561. let modelName;
  46562. let options;
  46563. const arg0 = node.arguments[0] && unwrapTSNode(node.arguments[0]);
  46564. const hasName = arg0 && arg0.type === "StringLiteral";
  46565. if (hasName) {
  46566. modelName = arg0.value;
  46567. options = node.arguments[1];
  46568. } else {
  46569. modelName = "modelValue";
  46570. options = arg0;
  46571. }
  46572. if (ctx.modelDecls[modelName]) {
  46573. ctx.error(`duplicate model name ${JSON.stringify(modelName)}`, node);
  46574. }
  46575. let optionsString = options && ctx.getString(options);
  46576. let optionsRemoved = !options;
  46577. const runtimeOptionNodes = [];
  46578. if (options && options.type === "ObjectExpression" && !options.properties.some((p) => p.type === "SpreadElement" || p.computed)) {
  46579. let removed = 0;
  46580. for (let i = options.properties.length - 1; i >= 0; i--) {
  46581. const p = options.properties[i];
  46582. const next = options.properties[i + 1];
  46583. const start = p.start;
  46584. const end = next ? next.start : options.end - 1;
  46585. if ((p.type === "ObjectProperty" || p.type === "ObjectMethod") && (p.key.type === "Identifier" && (p.key.name === "get" || p.key.name === "set") || p.key.type === "StringLiteral" && (p.key.value === "get" || p.key.value === "set"))) {
  46586. optionsString = optionsString.slice(0, start - options.start) + optionsString.slice(end - options.start);
  46587. } else {
  46588. removed++;
  46589. ctx.s.remove(ctx.startOffset + start, ctx.startOffset + end);
  46590. runtimeOptionNodes.push(p);
  46591. }
  46592. }
  46593. if (removed === options.properties.length) {
  46594. optionsRemoved = true;
  46595. ctx.s.remove(
  46596. ctx.startOffset + (hasName ? arg0.end : options.start),
  46597. ctx.startOffset + options.end
  46598. );
  46599. }
  46600. }
  46601. ctx.modelDecls[modelName] = {
  46602. type,
  46603. options: optionsString,
  46604. runtimeOptionNodes,
  46605. identifier: declId && declId.type === "Identifier" ? declId.name : void 0
  46606. };
  46607. ctx.bindingMetadata[modelName] = "props";
  46608. ctx.s.overwrite(
  46609. ctx.startOffset + node.callee.start,
  46610. ctx.startOffset + node.callee.end,
  46611. ctx.helper("useModel")
  46612. );
  46613. ctx.s.appendLeft(
  46614. ctx.startOffset + (node.arguments.length ? node.arguments[0].start : node.end - 1),
  46615. `__props, ` + (hasName ? `` : `${JSON.stringify(modelName)}${optionsRemoved ? `` : `, `}`)
  46616. );
  46617. return true;
  46618. }
  46619. function genModelProps(ctx) {
  46620. if (!ctx.hasDefineModelCall) return;
  46621. const isProd = !!ctx.options.isProd;
  46622. let modelPropsDecl = "";
  46623. for (const [name, { type, options: runtimeOptions }] of Object.entries(
  46624. ctx.modelDecls
  46625. )) {
  46626. let skipCheck = false;
  46627. let codegenOptions = ``;
  46628. let runtimeTypes = type && inferRuntimeType(ctx, type);
  46629. if (runtimeTypes) {
  46630. const hasBoolean = runtimeTypes.includes("Boolean");
  46631. const hasFunction = runtimeTypes.includes("Function");
  46632. const hasUnknownType = runtimeTypes.includes(UNKNOWN_TYPE);
  46633. if (hasUnknownType) {
  46634. if (hasBoolean || hasFunction) {
  46635. runtimeTypes = runtimeTypes.filter((t) => t !== UNKNOWN_TYPE);
  46636. skipCheck = true;
  46637. } else {
  46638. runtimeTypes = ["null"];
  46639. }
  46640. }
  46641. if (!isProd) {
  46642. codegenOptions = `type: ${toRuntimeTypeString(runtimeTypes)}` + (skipCheck ? ", skipCheck: true" : "");
  46643. } else if (hasBoolean || runtimeOptions && hasFunction) {
  46644. codegenOptions = `type: ${toRuntimeTypeString(runtimeTypes)}`;
  46645. } else ;
  46646. }
  46647. let decl;
  46648. if (codegenOptions && runtimeOptions) {
  46649. decl = ctx.isTS ? `{ ${codegenOptions}, ...${runtimeOptions} }` : `Object.assign({ ${codegenOptions} }, ${runtimeOptions})`;
  46650. } else if (codegenOptions) {
  46651. decl = `{ ${codegenOptions} }`;
  46652. } else if (runtimeOptions) {
  46653. decl = runtimeOptions;
  46654. } else {
  46655. decl = `{}`;
  46656. }
  46657. modelPropsDecl += `
  46658. ${JSON.stringify(name)}: ${decl},`;
  46659. const modifierPropName = JSON.stringify(
  46660. name === "modelValue" ? `modelModifiers` : `${name}Modifiers`
  46661. );
  46662. modelPropsDecl += `
  46663. ${modifierPropName}: {},`;
  46664. }
  46665. return `{${modelPropsDecl}
  46666. }`;
  46667. }
  46668. const DEFINE_PROPS = "defineProps";
  46669. const WITH_DEFAULTS = "withDefaults";
  46670. function processDefineProps(ctx, node, declId, isWithDefaults = false) {
  46671. if (!isCallOf(node, DEFINE_PROPS)) {
  46672. return processWithDefaults(ctx, node, declId);
  46673. }
  46674. if (ctx.hasDefinePropsCall) {
  46675. ctx.error(`duplicate ${DEFINE_PROPS}() call`, node);
  46676. }
  46677. ctx.hasDefinePropsCall = true;
  46678. ctx.propsRuntimeDecl = node.arguments[0];
  46679. if (ctx.propsRuntimeDecl) {
  46680. for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) {
  46681. if (!(key in ctx.bindingMetadata)) {
  46682. ctx.bindingMetadata[key] = "props";
  46683. }
  46684. }
  46685. }
  46686. if (node.typeParameters) {
  46687. if (ctx.propsRuntimeDecl) {
  46688. ctx.error(
  46689. `${DEFINE_PROPS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  46690. node
  46691. );
  46692. }
  46693. ctx.propsTypeDecl = node.typeParameters.params[0];
  46694. }
  46695. if (!isWithDefaults && declId && declId.type === "ObjectPattern") {
  46696. processPropsDestructure(ctx, declId);
  46697. }
  46698. ctx.propsCall = node;
  46699. ctx.propsDecl = declId;
  46700. return true;
  46701. }
  46702. function processWithDefaults(ctx, node, declId) {
  46703. if (!isCallOf(node, WITH_DEFAULTS)) {
  46704. return false;
  46705. }
  46706. if (!processDefineProps(
  46707. ctx,
  46708. node.arguments[0],
  46709. declId,
  46710. true
  46711. )) {
  46712. ctx.error(
  46713. `${WITH_DEFAULTS}' first argument must be a ${DEFINE_PROPS} call.`,
  46714. node.arguments[0] || node
  46715. );
  46716. }
  46717. if (ctx.propsRuntimeDecl) {
  46718. ctx.error(
  46719. `${WITH_DEFAULTS} can only be used with type-based ${DEFINE_PROPS} declaration.`,
  46720. node
  46721. );
  46722. }
  46723. if (declId && declId.type === "ObjectPattern") {
  46724. ctx.warn(
  46725. `${WITH_DEFAULTS}() is unnecessary when using destructure with ${DEFINE_PROPS}().
  46726. Reactive destructure will be disabled when using withDefaults().
  46727. Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(...). `,
  46728. node.callee
  46729. );
  46730. }
  46731. ctx.propsRuntimeDefaults = node.arguments[1];
  46732. if (!ctx.propsRuntimeDefaults) {
  46733. ctx.error(`The 2nd argument of ${WITH_DEFAULTS} is required.`, node);
  46734. }
  46735. ctx.propsCall = node;
  46736. return true;
  46737. }
  46738. function genRuntimeProps(ctx) {
  46739. let propsDecls;
  46740. if (ctx.propsRuntimeDecl) {
  46741. propsDecls = ctx.getString(ctx.propsRuntimeDecl).trim();
  46742. if (ctx.propsDestructureDecl) {
  46743. const defaults = [];
  46744. for (const key in ctx.propsDestructuredBindings) {
  46745. const d = genDestructuredDefaultValue(ctx, key);
  46746. const finalKey = getEscapedPropName(key);
  46747. if (d)
  46748. defaults.push(
  46749. `${finalKey}: ${d.valueString}${d.needSkipFactory ? `, __skip_${finalKey}: true` : ``}`
  46750. );
  46751. }
  46752. if (defaults.length) {
  46753. propsDecls = `/*@__PURE__*/${ctx.helper(
  46754. `mergeDefaults`
  46755. )}(${propsDecls}, {
  46756. ${defaults.join(",\n ")}
  46757. })`;
  46758. }
  46759. }
  46760. } else if (ctx.propsTypeDecl) {
  46761. propsDecls = extractRuntimeProps(ctx);
  46762. }
  46763. const modelsDecls = genModelProps(ctx);
  46764. if (propsDecls && modelsDecls) {
  46765. return `/*@__PURE__*/${ctx.helper(
  46766. "mergeModels"
  46767. )}(${propsDecls}, ${modelsDecls})`;
  46768. } else {
  46769. return modelsDecls || propsDecls;
  46770. }
  46771. }
  46772. function extractRuntimeProps(ctx) {
  46773. const props = resolveRuntimePropsFromType(ctx, ctx.propsTypeDecl);
  46774. if (!props.length) {
  46775. return;
  46776. }
  46777. const propStrings = [];
  46778. const hasStaticDefaults = hasStaticWithDefaults(ctx);
  46779. for (const prop of props) {
  46780. propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults));
  46781. if ("bindingMetadata" in ctx && !(prop.key in ctx.bindingMetadata)) {
  46782. ctx.bindingMetadata[prop.key] = "props";
  46783. }
  46784. }
  46785. let propsDecls = `{
  46786. ${propStrings.join(",\n ")}
  46787. }`;
  46788. if (ctx.propsRuntimeDefaults && !hasStaticDefaults) {
  46789. propsDecls = `/*@__PURE__*/${ctx.helper(
  46790. "mergeDefaults"
  46791. )}(${propsDecls}, ${ctx.getString(ctx.propsRuntimeDefaults)})`;
  46792. }
  46793. return propsDecls;
  46794. }
  46795. function resolveRuntimePropsFromType(ctx, node) {
  46796. const props = [];
  46797. const elements = resolveTypeElements(ctx, node);
  46798. for (const key in elements.props) {
  46799. const e = elements.props[key];
  46800. let type = inferRuntimeType(ctx, e);
  46801. let skipCheck = false;
  46802. if (type.includes(UNKNOWN_TYPE)) {
  46803. if (type.includes("Boolean") || type.includes("Function")) {
  46804. type = type.filter((t) => t !== UNKNOWN_TYPE);
  46805. skipCheck = true;
  46806. } else {
  46807. type = ["null"];
  46808. }
  46809. }
  46810. props.push({
  46811. key,
  46812. required: !e.optional,
  46813. type: type || [`null`],
  46814. skipCheck
  46815. });
  46816. }
  46817. return props;
  46818. }
  46819. function genRuntimePropFromType(ctx, { key, required, type, skipCheck }, hasStaticDefaults) {
  46820. let defaultString;
  46821. const destructured = genDestructuredDefaultValue(ctx, key, type);
  46822. if (destructured) {
  46823. defaultString = `default: ${destructured.valueString}${destructured.needSkipFactory ? `, skipFactory: true` : ``}`;
  46824. } else if (hasStaticDefaults) {
  46825. const prop = ctx.propsRuntimeDefaults.properties.find(
  46826. (node) => {
  46827. if (node.type === "SpreadElement") return false;
  46828. return resolveObjectKey(node.key, node.computed) === key;
  46829. }
  46830. );
  46831. if (prop) {
  46832. if (prop.type === "ObjectProperty") {
  46833. defaultString = `default: ${ctx.getString(prop.value)}`;
  46834. } else {
  46835. defaultString = `${prop.async ? "async " : ""}${prop.kind !== "method" ? `${prop.kind} ` : ""}default() ${ctx.getString(prop.body)}`;
  46836. }
  46837. }
  46838. }
  46839. const finalKey = getEscapedPropName(key);
  46840. if (!ctx.options.isProd) {
  46841. return `${finalKey}: { ${concatStrings([
  46842. `type: ${toRuntimeTypeString(type)}`,
  46843. `required: ${required}`,
  46844. skipCheck && "skipCheck: true",
  46845. defaultString
  46846. ])} }`;
  46847. } else if (type.some(
  46848. (el) => el === "Boolean" || (!hasStaticDefaults || defaultString) && el === "Function"
  46849. )) {
  46850. return `${finalKey}: { ${concatStrings([
  46851. `type: ${toRuntimeTypeString(type)}`,
  46852. defaultString
  46853. ])} }`;
  46854. } else {
  46855. if (ctx.isCE) {
  46856. if (defaultString) {
  46857. return `${finalKey}: ${`{ ${defaultString}, type: ${toRuntimeTypeString(
  46858. type
  46859. )} }`}`;
  46860. } else {
  46861. return `${finalKey}: {type: ${toRuntimeTypeString(type)}}`;
  46862. }
  46863. }
  46864. return `${finalKey}: ${defaultString ? `{ ${defaultString} }` : `{}`}`;
  46865. }
  46866. }
  46867. function hasStaticWithDefaults(ctx) {
  46868. return !!(ctx.propsRuntimeDefaults && ctx.propsRuntimeDefaults.type === "ObjectExpression" && ctx.propsRuntimeDefaults.properties.every(
  46869. (node) => node.type !== "SpreadElement" && (!node.computed || node.key.type.endsWith("Literal"))
  46870. ));
  46871. }
  46872. function genDestructuredDefaultValue(ctx, key, inferredType) {
  46873. const destructured = ctx.propsDestructuredBindings[key];
  46874. const defaultVal = destructured && destructured.default;
  46875. if (defaultVal) {
  46876. const value = ctx.getString(defaultVal);
  46877. const unwrapped = unwrapTSNode(defaultVal);
  46878. if (inferredType && inferredType.length && !inferredType.includes("null")) {
  46879. const valueType = inferValueType(unwrapped);
  46880. if (valueType && !inferredType.includes(valueType)) {
  46881. ctx.error(
  46882. `Default value of prop "${key}" does not match declared type.`,
  46883. unwrapped
  46884. );
  46885. }
  46886. }
  46887. const needSkipFactory = !inferredType && (isFunctionType(unwrapped) || unwrapped.type === "Identifier");
  46888. const needFactoryWrap = !needSkipFactory && !isLiteralNode(unwrapped) && !(inferredType == null ? void 0 : inferredType.includes("Function"));
  46889. return {
  46890. valueString: needFactoryWrap ? `() => (${value})` : value,
  46891. needSkipFactory
  46892. };
  46893. }
  46894. }
  46895. function inferValueType(node) {
  46896. switch (node.type) {
  46897. case "StringLiteral":
  46898. return "String";
  46899. case "NumericLiteral":
  46900. return "Number";
  46901. case "BooleanLiteral":
  46902. return "Boolean";
  46903. case "ObjectExpression":
  46904. return "Object";
  46905. case "ArrayExpression":
  46906. return "Array";
  46907. case "FunctionExpression":
  46908. case "ArrowFunctionExpression":
  46909. return "Function";
  46910. }
  46911. }
  46912. function processPropsDestructure(ctx, declId) {
  46913. if (ctx.options.propsDestructure === "error") {
  46914. ctx.error(`Props destructure is explicitly prohibited via config.`, declId);
  46915. } else if (ctx.options.propsDestructure === false) {
  46916. return;
  46917. }
  46918. ctx.propsDestructureDecl = declId;
  46919. const registerBinding = (key, local, defaultValue) => {
  46920. ctx.propsDestructuredBindings[key] = { local, default: defaultValue };
  46921. if (local !== key) {
  46922. ctx.bindingMetadata[local] = "props-aliased";
  46923. (ctx.bindingMetadata.__propsAliases || (ctx.bindingMetadata.__propsAliases = {}))[local] = key;
  46924. }
  46925. };
  46926. for (const prop of declId.properties) {
  46927. if (prop.type === "ObjectProperty") {
  46928. const propKey = resolveObjectKey(prop.key, prop.computed);
  46929. if (!propKey) {
  46930. ctx.error(
  46931. `${DEFINE_PROPS}() destructure cannot use computed key.`,
  46932. prop.key
  46933. );
  46934. }
  46935. if (prop.value.type === "AssignmentPattern") {
  46936. const { left, right } = prop.value;
  46937. if (left.type !== "Identifier") {
  46938. ctx.error(
  46939. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  46940. left
  46941. );
  46942. }
  46943. registerBinding(propKey, left.name, right);
  46944. } else if (prop.value.type === "Identifier") {
  46945. registerBinding(propKey, prop.value.name);
  46946. } else {
  46947. ctx.error(
  46948. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  46949. prop.value
  46950. );
  46951. }
  46952. } else {
  46953. ctx.propsDestructureRestId = prop.argument.name;
  46954. ctx.bindingMetadata[ctx.propsDestructureRestId] = "setup-reactive-const";
  46955. }
  46956. }
  46957. }
  46958. function transformDestructuredProps(ctx, vueImportAliases) {
  46959. if (ctx.options.propsDestructure === false) {
  46960. return;
  46961. }
  46962. const rootScope = /* @__PURE__ */ Object.create(null);
  46963. const scopeStack = [rootScope];
  46964. let currentScope = rootScope;
  46965. const excludedIds = /* @__PURE__ */ new WeakSet();
  46966. const parentStack = [];
  46967. const propsLocalToPublicMap = /* @__PURE__ */ Object.create(null);
  46968. for (const key in ctx.propsDestructuredBindings) {
  46969. const { local } = ctx.propsDestructuredBindings[key];
  46970. rootScope[local] = true;
  46971. propsLocalToPublicMap[local] = key;
  46972. }
  46973. function pushScope() {
  46974. scopeStack.push(currentScope = Object.create(currentScope));
  46975. }
  46976. function popScope() {
  46977. scopeStack.pop();
  46978. currentScope = scopeStack[scopeStack.length - 1] || null;
  46979. }
  46980. function registerLocalBinding(id) {
  46981. excludedIds.add(id);
  46982. if (currentScope) {
  46983. currentScope[id.name] = false;
  46984. } else {
  46985. ctx.error(
  46986. "registerBinding called without active scope, something is wrong.",
  46987. id
  46988. );
  46989. }
  46990. }
  46991. function walkScope(node, isRoot = false) {
  46992. for (const stmt of node.body) {
  46993. if (stmt.type === "VariableDeclaration") {
  46994. walkVariableDeclaration(stmt, isRoot);
  46995. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  46996. if (stmt.declare || !stmt.id) continue;
  46997. registerLocalBinding(stmt.id);
  46998. } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration && stmt.declaration.type === "VariableDeclaration") {
  46999. walkVariableDeclaration(stmt.declaration, isRoot);
  47000. } else if (stmt.type === "LabeledStatement" && stmt.body.type === "VariableDeclaration") {
  47001. walkVariableDeclaration(stmt.body, isRoot);
  47002. }
  47003. }
  47004. }
  47005. function walkVariableDeclaration(stmt, isRoot = false) {
  47006. if (stmt.declare) {
  47007. return;
  47008. }
  47009. for (const decl of stmt.declarations) {
  47010. const isDefineProps = isRoot && decl.init && isCallOf(unwrapTSNode(decl.init), "defineProps");
  47011. for (const id of extractIdentifiers$1(decl.id)) {
  47012. if (isDefineProps) {
  47013. excludedIds.add(id);
  47014. } else {
  47015. registerLocalBinding(id);
  47016. }
  47017. }
  47018. }
  47019. }
  47020. function rewriteId(id, parent, parentStack2) {
  47021. if (parent.type === "AssignmentExpression" && id === parent.left || parent.type === "UpdateExpression") {
  47022. ctx.error(`Cannot assign to destructured props as they are readonly.`, id);
  47023. }
  47024. if (isStaticProperty(parent) && parent.shorthand) {
  47025. if (!parent.inPattern || isInDestructureAssignment(parent, parentStack2)) {
  47026. ctx.s.appendLeft(
  47027. id.end + ctx.startOffset,
  47028. `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`
  47029. );
  47030. }
  47031. } else {
  47032. ctx.s.overwrite(
  47033. id.start + ctx.startOffset,
  47034. id.end + ctx.startOffset,
  47035. genPropsAccessExp(propsLocalToPublicMap[id.name])
  47036. );
  47037. }
  47038. }
  47039. function checkUsage(node, method, alias = method) {
  47040. if (isCallOf(node, alias)) {
  47041. const arg = unwrapTSNode(node.arguments[0]);
  47042. if (arg.type === "Identifier" && currentScope[arg.name]) {
  47043. ctx.error(
  47044. `"${arg.name}" is a destructured prop and should not be passed directly to ${method}(). Pass a getter () => ${arg.name} instead.`,
  47045. arg
  47046. );
  47047. }
  47048. }
  47049. }
  47050. const ast = ctx.scriptSetupAst;
  47051. walkScope(ast, true);
  47052. walk$2(ast, {
  47053. enter(node, parent) {
  47054. parent && parentStack.push(parent);
  47055. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  47056. return this.skip();
  47057. }
  47058. checkUsage(node, "watch", vueImportAliases.watch);
  47059. checkUsage(node, "toRef", vueImportAliases.toRef);
  47060. if (isFunctionType(node)) {
  47061. pushScope();
  47062. walkFunctionParams(node, registerLocalBinding);
  47063. if (node.body.type === "BlockStatement") {
  47064. walkScope(node.body);
  47065. }
  47066. return;
  47067. }
  47068. if (node.type === "CatchClause") {
  47069. pushScope();
  47070. if (node.param && node.param.type === "Identifier") {
  47071. registerLocalBinding(node.param);
  47072. }
  47073. walkScope(node.body);
  47074. return;
  47075. }
  47076. if (node.type === "ForOfStatement" || node.type === "ForInStatement" || node.type === "ForStatement") {
  47077. pushScope();
  47078. const varDecl = node.type === "ForStatement" ? node.init : node.left;
  47079. if (varDecl && varDecl.type === "VariableDeclaration") {
  47080. walkVariableDeclaration(varDecl);
  47081. }
  47082. if (node.body.type === "BlockStatement") {
  47083. walkScope(node.body);
  47084. }
  47085. return;
  47086. }
  47087. if (node.type === "BlockStatement" && !isFunctionType(parent)) {
  47088. pushScope();
  47089. walkScope(node);
  47090. return;
  47091. }
  47092. if (node.type === "Identifier") {
  47093. if (isReferencedIdentifier(node, parent, parentStack) && !excludedIds.has(node)) {
  47094. if (currentScope[node.name]) {
  47095. rewriteId(node, parent, parentStack);
  47096. }
  47097. }
  47098. }
  47099. },
  47100. leave(node, parent) {
  47101. parent && parentStack.pop();
  47102. if (node.type === "BlockStatement" && !isFunctionType(parent) || isFunctionType(node) || node.type === "CatchClause" || node.type === "ForOfStatement" || node.type === "ForInStatement" || node.type === "ForStatement") {
  47103. popScope();
  47104. }
  47105. }
  47106. });
  47107. }
  47108. const DEFINE_EMITS = "defineEmits";
  47109. function processDefineEmits(ctx, node, declId) {
  47110. if (!isCallOf(node, DEFINE_EMITS)) {
  47111. return false;
  47112. }
  47113. if (ctx.hasDefineEmitCall) {
  47114. ctx.error(`duplicate ${DEFINE_EMITS}() call`, node);
  47115. }
  47116. ctx.hasDefineEmitCall = true;
  47117. ctx.emitsRuntimeDecl = node.arguments[0];
  47118. if (node.typeParameters) {
  47119. if (ctx.emitsRuntimeDecl) {
  47120. ctx.error(
  47121. `${DEFINE_EMITS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  47122. node
  47123. );
  47124. }
  47125. ctx.emitsTypeDecl = node.typeParameters.params[0];
  47126. }
  47127. ctx.emitDecl = declId;
  47128. return true;
  47129. }
  47130. function genRuntimeEmits(ctx) {
  47131. let emitsDecl = "";
  47132. if (ctx.emitsRuntimeDecl) {
  47133. emitsDecl = ctx.getString(ctx.emitsRuntimeDecl).trim();
  47134. } else if (ctx.emitsTypeDecl) {
  47135. const typeDeclaredEmits = extractRuntimeEmits(ctx);
  47136. emitsDecl = typeDeclaredEmits.size ? `[${Array.from(typeDeclaredEmits).map((k) => JSON.stringify(k)).join(", ")}]` : ``;
  47137. }
  47138. if (ctx.hasDefineModelCall) {
  47139. let modelEmitsDecl = `[${Object.keys(ctx.modelDecls).map((n) => JSON.stringify(`update:${n}`)).join(", ")}]`;
  47140. emitsDecl = emitsDecl ? `/*@__PURE__*/${ctx.helper(
  47141. "mergeModels"
  47142. )}(${emitsDecl}, ${modelEmitsDecl})` : modelEmitsDecl;
  47143. }
  47144. return emitsDecl;
  47145. }
  47146. function extractRuntimeEmits(ctx) {
  47147. const emits = /* @__PURE__ */ new Set();
  47148. const node = ctx.emitsTypeDecl;
  47149. if (node.type === "TSFunctionType") {
  47150. extractEventNames(ctx, node.parameters[0], emits);
  47151. return emits;
  47152. }
  47153. const { props, calls } = resolveTypeElements(ctx, node);
  47154. let hasProperty = false;
  47155. for (const key in props) {
  47156. emits.add(key);
  47157. hasProperty = true;
  47158. }
  47159. if (calls) {
  47160. if (hasProperty) {
  47161. ctx.error(
  47162. `defineEmits() type cannot mixed call signature and property syntax.`,
  47163. node
  47164. );
  47165. }
  47166. for (const call of calls) {
  47167. extractEventNames(ctx, call.parameters[0], emits);
  47168. }
  47169. }
  47170. return emits;
  47171. }
  47172. function extractEventNames(ctx, eventName, emits) {
  47173. if (eventName.type === "Identifier" && eventName.typeAnnotation && eventName.typeAnnotation.type === "TSTypeAnnotation") {
  47174. const types = resolveUnionType(ctx, eventName.typeAnnotation.typeAnnotation);
  47175. for (const type of types) {
  47176. if (type.type === "TSLiteralType") {
  47177. if (type.literal.type !== "UnaryExpression" && type.literal.type !== "TemplateLiteral") {
  47178. emits.add(String(type.literal.value));
  47179. }
  47180. }
  47181. }
  47182. }
  47183. }
  47184. const DEFINE_EXPOSE = "defineExpose";
  47185. function processDefineExpose(ctx, node) {
  47186. if (isCallOf(node, DEFINE_EXPOSE)) {
  47187. if (ctx.hasDefineExposeCall) {
  47188. ctx.error(`duplicate ${DEFINE_EXPOSE}() call`, node);
  47189. }
  47190. ctx.hasDefineExposeCall = true;
  47191. return true;
  47192. }
  47193. return false;
  47194. }
  47195. const DEFINE_SLOTS = "defineSlots";
  47196. function processDefineSlots(ctx, node, declId) {
  47197. if (!isCallOf(node, DEFINE_SLOTS)) {
  47198. return false;
  47199. }
  47200. if (ctx.hasDefineSlotsCall) {
  47201. ctx.error(`duplicate ${DEFINE_SLOTS}() call`, node);
  47202. }
  47203. ctx.hasDefineSlotsCall = true;
  47204. if (node.arguments.length > 0) {
  47205. ctx.error(`${DEFINE_SLOTS}() cannot accept arguments`, node);
  47206. }
  47207. if (declId) {
  47208. ctx.s.overwrite(
  47209. ctx.startOffset + node.start,
  47210. ctx.startOffset + node.end,
  47211. `${ctx.helper("useSlots")}()`
  47212. );
  47213. }
  47214. return true;
  47215. }
  47216. const DEFINE_OPTIONS = "defineOptions";
  47217. function processDefineOptions(ctx, node) {
  47218. if (!isCallOf(node, DEFINE_OPTIONS)) {
  47219. return false;
  47220. }
  47221. if (ctx.hasDefineOptionsCall) {
  47222. ctx.error(`duplicate ${DEFINE_OPTIONS}() call`, node);
  47223. }
  47224. if (node.typeParameters) {
  47225. ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node);
  47226. }
  47227. if (!node.arguments[0]) return true;
  47228. ctx.hasDefineOptionsCall = true;
  47229. ctx.optionsRuntimeDecl = unwrapTSNode(node.arguments[0]);
  47230. let propsOption = void 0;
  47231. let emitsOption = void 0;
  47232. let exposeOption = void 0;
  47233. let slotsOption = void 0;
  47234. if (ctx.optionsRuntimeDecl.type === "ObjectExpression") {
  47235. for (const prop of ctx.optionsRuntimeDecl.properties) {
  47236. if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
  47237. switch (prop.key.name) {
  47238. case "props":
  47239. propsOption = prop;
  47240. break;
  47241. case "emits":
  47242. emitsOption = prop;
  47243. break;
  47244. case "expose":
  47245. exposeOption = prop;
  47246. break;
  47247. case "slots":
  47248. slotsOption = prop;
  47249. break;
  47250. }
  47251. }
  47252. }
  47253. }
  47254. if (propsOption) {
  47255. ctx.error(
  47256. `${DEFINE_OPTIONS}() cannot be used to declare props. Use ${DEFINE_PROPS}() instead.`,
  47257. propsOption
  47258. );
  47259. }
  47260. if (emitsOption) {
  47261. ctx.error(
  47262. `${DEFINE_OPTIONS}() cannot be used to declare emits. Use ${DEFINE_EMITS}() instead.`,
  47263. emitsOption
  47264. );
  47265. }
  47266. if (exposeOption) {
  47267. ctx.error(
  47268. `${DEFINE_OPTIONS}() cannot be used to declare expose. Use ${DEFINE_EXPOSE}() instead.`,
  47269. exposeOption
  47270. );
  47271. }
  47272. if (slotsOption) {
  47273. ctx.error(
  47274. `${DEFINE_OPTIONS}() cannot be used to declare slots. Use ${DEFINE_SLOTS}() instead.`,
  47275. slotsOption
  47276. );
  47277. }
  47278. return true;
  47279. }
  47280. function processAwait(ctx, node, needSemi, isStatement) {
  47281. const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? node.argument.extra.parenStart : node.argument.start;
  47282. const startOffset = ctx.startOffset;
  47283. const argumentStr = ctx.descriptor.source.slice(
  47284. argumentStart + startOffset,
  47285. node.argument.end + startOffset
  47286. );
  47287. const containsNestedAwait = /\bawait\b/.test(argumentStr);
  47288. ctx.s.overwrite(
  47289. node.start + startOffset,
  47290. argumentStart + startOffset,
  47291. `${needSemi ? `;` : ``}(
  47292. ([__temp,__restore] = ${ctx.helper(
  47293. `withAsyncContext`
  47294. )}(${containsNestedAwait ? `async ` : ``}() => `
  47295. );
  47296. ctx.s.appendLeft(
  47297. node.end + startOffset,
  47298. `)),
  47299. ${isStatement ? `` : `__temp = `}await __temp,
  47300. __restore()${isStatement ? `` : `,
  47301. __temp`}
  47302. )`
  47303. );
  47304. }
  47305. var __defProp$1 = Object.defineProperty;
  47306. var __defProps = Object.defineProperties;
  47307. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  47308. var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
  47309. var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
  47310. var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
  47311. var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  47312. var __spreadValues$1 = (a, b) => {
  47313. for (var prop in b || (b = {}))
  47314. if (__hasOwnProp$1.call(b, prop))
  47315. __defNormalProp$1(a, prop, b[prop]);
  47316. if (__getOwnPropSymbols$1)
  47317. for (var prop of __getOwnPropSymbols$1(b)) {
  47318. if (__propIsEnum$1.call(b, prop))
  47319. __defNormalProp$1(a, prop, b[prop]);
  47320. }
  47321. return a;
  47322. };
  47323. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  47324. const MACROS = [
  47325. DEFINE_PROPS,
  47326. DEFINE_EMITS,
  47327. DEFINE_EXPOSE,
  47328. DEFINE_OPTIONS,
  47329. DEFINE_SLOTS,
  47330. DEFINE_MODEL,
  47331. WITH_DEFAULTS
  47332. ];
  47333. function compileScript(sfc, options) {
  47334. var _a, _b, _c;
  47335. if (!options.id) {
  47336. warnOnce$1(
  47337. `compileScript now requires passing the \`id\` option.
  47338. Upgrade your vite or vue-loader version for compatibility with the latest experimental proposals.`
  47339. );
  47340. }
  47341. const { script, scriptSetup, source, filename } = sfc;
  47342. const hoistStatic = options.hoistStatic !== false && !script;
  47343. const scopeId = options.id ? options.id.replace(/^data-v-/, "") : "";
  47344. const scriptLang = script && script.lang;
  47345. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  47346. const isJSOrTS = isJS(scriptLang, scriptSetupLang) || isTS(scriptLang, scriptSetupLang);
  47347. if (script && scriptSetup && scriptLang !== scriptSetupLang) {
  47348. throw new Error(
  47349. `[@vue/compiler-sfc] <script> and <script setup> must have the same language type.`
  47350. );
  47351. }
  47352. if (!scriptSetup) {
  47353. if (!script) {
  47354. throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`);
  47355. }
  47356. if (script.lang && !isJSOrTS) {
  47357. return script;
  47358. }
  47359. const ctx2 = new ScriptCompileContext(sfc, options);
  47360. return processNormalScript(ctx2, scopeId);
  47361. }
  47362. if (scriptSetupLang && !isJSOrTS) {
  47363. return scriptSetup;
  47364. }
  47365. const ctx = new ScriptCompileContext(sfc, options);
  47366. const scriptBindings = /* @__PURE__ */ Object.create(null);
  47367. const setupBindings = /* @__PURE__ */ Object.create(null);
  47368. let defaultExport;
  47369. let hasAwait = false;
  47370. let hasInlinedSsrRenderFn = false;
  47371. const startOffset = ctx.startOffset;
  47372. const endOffset = ctx.endOffset;
  47373. const scriptStartOffset = script && script.loc.start.offset;
  47374. const scriptEndOffset = script && script.loc.end.offset;
  47375. function hoistNode(node) {
  47376. const start = node.start + startOffset;
  47377. let end = node.end + startOffset;
  47378. if (node.trailingComments && node.trailingComments.length > 0) {
  47379. const lastCommentNode = node.trailingComments[node.trailingComments.length - 1];
  47380. end = lastCommentNode.end + startOffset;
  47381. }
  47382. while (end <= source.length) {
  47383. if (!/\s/.test(source.charAt(end))) {
  47384. break;
  47385. }
  47386. end++;
  47387. }
  47388. ctx.s.move(start, end, 0);
  47389. }
  47390. function registerUserImport(source2, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
  47391. let isUsedInTemplate = needTemplateUsageCheck;
  47392. if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
  47393. isUsedInTemplate = isImportUsed(local, sfc);
  47394. }
  47395. ctx.userImports[local] = {
  47396. isType,
  47397. imported,
  47398. local,
  47399. source: source2,
  47400. isFromSetup,
  47401. isUsedInTemplate
  47402. };
  47403. }
  47404. function checkInvalidScopeReference(node, method) {
  47405. if (!node) return;
  47406. walkIdentifiers(node, (id) => {
  47407. const binding = setupBindings[id.name];
  47408. if (binding && binding !== "literal-const") {
  47409. ctx.error(
  47410. `\`${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.`,
  47411. id
  47412. );
  47413. }
  47414. });
  47415. }
  47416. const scriptAst = ctx.scriptAst;
  47417. const scriptSetupAst = ctx.scriptSetupAst;
  47418. if (scriptAst) {
  47419. for (const node of scriptAst.body) {
  47420. if (node.type === "ImportDeclaration") {
  47421. for (const specifier of node.specifiers) {
  47422. const imported = getImportedName(specifier);
  47423. registerUserImport(
  47424. node.source.value,
  47425. specifier.local.name,
  47426. imported,
  47427. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  47428. false,
  47429. !options.inlineTemplate
  47430. );
  47431. }
  47432. }
  47433. }
  47434. }
  47435. for (const node of scriptSetupAst.body) {
  47436. if (node.type === "ImportDeclaration") {
  47437. hoistNode(node);
  47438. let removed = 0;
  47439. const removeSpecifier = (i) => {
  47440. const removeLeft = i > removed;
  47441. removed++;
  47442. const current = node.specifiers[i];
  47443. const next = node.specifiers[i + 1];
  47444. ctx.s.remove(
  47445. removeLeft ? node.specifiers[i - 1].end + startOffset : current.start + startOffset,
  47446. next && !removeLeft ? next.start + startOffset : current.end + startOffset
  47447. );
  47448. };
  47449. for (let i = 0; i < node.specifiers.length; i++) {
  47450. const specifier = node.specifiers[i];
  47451. const local = specifier.local.name;
  47452. const imported = getImportedName(specifier);
  47453. const source2 = node.source.value;
  47454. const existing = ctx.userImports[local];
  47455. if (source2 === "vue" && MACROS.includes(imported)) {
  47456. if (local === imported) {
  47457. warnOnce$1(
  47458. `\`${imported}\` is a compiler macro and no longer needs to be imported.`
  47459. );
  47460. } else {
  47461. ctx.error(
  47462. `\`${imported}\` is a compiler macro and cannot be aliased to a different name.`,
  47463. specifier
  47464. );
  47465. }
  47466. removeSpecifier(i);
  47467. } else if (existing) {
  47468. if (existing.source === source2 && existing.imported === imported) {
  47469. removeSpecifier(i);
  47470. } else {
  47471. ctx.error(
  47472. `different imports aliased to same local name.`,
  47473. specifier
  47474. );
  47475. }
  47476. } else {
  47477. registerUserImport(
  47478. source2,
  47479. local,
  47480. imported,
  47481. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  47482. true,
  47483. !options.inlineTemplate
  47484. );
  47485. }
  47486. }
  47487. if (node.specifiers.length && removed === node.specifiers.length) {
  47488. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47489. }
  47490. }
  47491. }
  47492. const vueImportAliases = {};
  47493. for (const key in ctx.userImports) {
  47494. const { source: source2, imported, local } = ctx.userImports[key];
  47495. if (source2 === "vue") vueImportAliases[imported] = local;
  47496. }
  47497. if (script && scriptAst) {
  47498. for (const node of scriptAst.body) {
  47499. if (node.type === "ExportDefaultDeclaration") {
  47500. defaultExport = node;
  47501. let optionProperties;
  47502. if (defaultExport.declaration.type === "ObjectExpression") {
  47503. optionProperties = defaultExport.declaration.properties;
  47504. } else if (defaultExport.declaration.type === "CallExpression" && defaultExport.declaration.arguments[0] && defaultExport.declaration.arguments[0].type === "ObjectExpression") {
  47505. optionProperties = defaultExport.declaration.arguments[0].properties;
  47506. }
  47507. if (optionProperties) {
  47508. for (const p of optionProperties) {
  47509. if (p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name") {
  47510. ctx.hasDefaultExportName = true;
  47511. }
  47512. if ((p.type === "ObjectMethod" || p.type === "ObjectProperty") && p.key.type === "Identifier" && p.key.name === "render") {
  47513. ctx.hasDefaultExportRender = true;
  47514. }
  47515. }
  47516. }
  47517. const start = node.start + scriptStartOffset;
  47518. const end = node.declaration.start + scriptStartOffset;
  47519. ctx.s.overwrite(start, end, `const ${normalScriptDefaultVar} = `);
  47520. } else if (node.type === "ExportNamedDeclaration") {
  47521. const defaultSpecifier = node.specifiers.find(
  47522. (s) => s.exported.type === "Identifier" && s.exported.name === "default"
  47523. );
  47524. if (defaultSpecifier) {
  47525. defaultExport = node;
  47526. if (node.specifiers.length > 1) {
  47527. ctx.s.remove(
  47528. defaultSpecifier.start + scriptStartOffset,
  47529. defaultSpecifier.end + scriptStartOffset
  47530. );
  47531. } else {
  47532. ctx.s.remove(
  47533. node.start + scriptStartOffset,
  47534. node.end + scriptStartOffset
  47535. );
  47536. }
  47537. if (node.source) {
  47538. ctx.s.prepend(
  47539. `import { ${defaultSpecifier.local.name} as ${normalScriptDefaultVar} } from '${node.source.value}'
  47540. `
  47541. );
  47542. } else {
  47543. ctx.s.appendLeft(
  47544. scriptEndOffset,
  47545. `
  47546. const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
  47547. `
  47548. );
  47549. }
  47550. }
  47551. if (node.declaration) {
  47552. walkDeclaration(
  47553. "script",
  47554. node.declaration,
  47555. scriptBindings,
  47556. vueImportAliases,
  47557. hoistStatic
  47558. );
  47559. }
  47560. } else if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  47561. walkDeclaration(
  47562. "script",
  47563. node,
  47564. scriptBindings,
  47565. vueImportAliases,
  47566. hoistStatic
  47567. );
  47568. }
  47569. }
  47570. if (scriptStartOffset > startOffset) {
  47571. if (!/\n$/.test(script.content.trim())) {
  47572. ctx.s.appendLeft(scriptEndOffset, `
  47573. `);
  47574. }
  47575. ctx.s.move(scriptStartOffset, scriptEndOffset, 0);
  47576. }
  47577. }
  47578. for (const node of scriptSetupAst.body) {
  47579. if (node.type === "ExpressionStatement") {
  47580. const expr = unwrapTSNode(node.expression);
  47581. if (processDefineProps(ctx, expr) || processDefineEmits(ctx, expr) || processDefineOptions(ctx, expr) || processDefineSlots(ctx, expr)) {
  47582. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47583. } else if (processDefineExpose(ctx, expr)) {
  47584. const callee = expr.callee;
  47585. ctx.s.overwrite(
  47586. callee.start + startOffset,
  47587. callee.end + startOffset,
  47588. "__expose"
  47589. );
  47590. } else {
  47591. processDefineModel(ctx, expr);
  47592. }
  47593. }
  47594. if (node.type === "VariableDeclaration" && !node.declare) {
  47595. const total = node.declarations.length;
  47596. let left = total;
  47597. let lastNonRemoved;
  47598. for (let i = 0; i < total; i++) {
  47599. const decl = node.declarations[i];
  47600. const init = decl.init && unwrapTSNode(decl.init);
  47601. if (init) {
  47602. if (processDefineOptions(ctx, init)) {
  47603. ctx.error(
  47604. `${DEFINE_OPTIONS}() has no returning value, it cannot be assigned.`,
  47605. node
  47606. );
  47607. }
  47608. const isDefineProps = processDefineProps(ctx, init, decl.id);
  47609. if (ctx.propsDestructureRestId) {
  47610. setupBindings[ctx.propsDestructureRestId] = "setup-reactive-const";
  47611. }
  47612. const isDefineEmits = !isDefineProps && processDefineEmits(ctx, init, decl.id);
  47613. !isDefineEmits && (processDefineSlots(ctx, init, decl.id) || processDefineModel(ctx, init, decl.id));
  47614. if (isDefineProps && !ctx.propsDestructureRestId && ctx.propsDestructureDecl) {
  47615. if (left === 1) {
  47616. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47617. } else {
  47618. let start = decl.start + startOffset;
  47619. let end = decl.end + startOffset;
  47620. if (i === total - 1) {
  47621. start = node.declarations[lastNonRemoved].end + startOffset;
  47622. } else {
  47623. end = node.declarations[i + 1].start + startOffset;
  47624. }
  47625. ctx.s.remove(start, end);
  47626. left--;
  47627. }
  47628. } else if (isDefineEmits) {
  47629. ctx.s.overwrite(
  47630. startOffset + init.start,
  47631. startOffset + init.end,
  47632. "__emit"
  47633. );
  47634. } else {
  47635. lastNonRemoved = i;
  47636. }
  47637. }
  47638. }
  47639. }
  47640. let isAllLiteral = false;
  47641. if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  47642. isAllLiteral = walkDeclaration(
  47643. "scriptSetup",
  47644. node,
  47645. setupBindings,
  47646. vueImportAliases,
  47647. hoistStatic,
  47648. !!ctx.propsDestructureDecl
  47649. );
  47650. }
  47651. if (hoistStatic && isAllLiteral) {
  47652. hoistNode(node);
  47653. }
  47654. if (node.type === "VariableDeclaration" && !node.declare || node.type.endsWith("Statement")) {
  47655. const scope = [scriptSetupAst.body];
  47656. walk$2(node, {
  47657. enter(child, parent) {
  47658. if (isFunctionType(child)) {
  47659. this.skip();
  47660. }
  47661. if (child.type === "BlockStatement") {
  47662. scope.push(child.body);
  47663. }
  47664. if (child.type === "AwaitExpression") {
  47665. hasAwait = true;
  47666. const currentScope = scope[scope.length - 1];
  47667. const needsSemi = currentScope.some((n, i) => {
  47668. return (scope.length === 1 || i > 0) && n.type === "ExpressionStatement" && n.start === child.start;
  47669. });
  47670. processAwait(
  47671. ctx,
  47672. child,
  47673. needsSemi,
  47674. parent.type === "ExpressionStatement"
  47675. );
  47676. }
  47677. },
  47678. exit(node2) {
  47679. if (node2.type === "BlockStatement") scope.pop();
  47680. }
  47681. });
  47682. }
  47683. if (node.type === "ExportNamedDeclaration" && node.exportKind !== "type" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration") {
  47684. ctx.error(
  47685. `<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.`,
  47686. node
  47687. );
  47688. }
  47689. if (ctx.isTS) {
  47690. if (node.type.startsWith("TS") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "VariableDeclaration" && node.declare) {
  47691. if (node.type !== "TSEnumDeclaration") {
  47692. hoistNode(node);
  47693. }
  47694. }
  47695. }
  47696. }
  47697. if (ctx.propsDestructureDecl) {
  47698. transformDestructuredProps(ctx, vueImportAliases);
  47699. }
  47700. checkInvalidScopeReference(ctx.propsRuntimeDecl, DEFINE_PROPS);
  47701. checkInvalidScopeReference(ctx.propsRuntimeDefaults, DEFINE_PROPS);
  47702. checkInvalidScopeReference(ctx.propsDestructureDecl, DEFINE_PROPS);
  47703. checkInvalidScopeReference(ctx.emitsRuntimeDecl, DEFINE_EMITS);
  47704. checkInvalidScopeReference(ctx.optionsRuntimeDecl, DEFINE_OPTIONS);
  47705. for (const { runtimeOptionNodes } of Object.values(ctx.modelDecls)) {
  47706. for (const node of runtimeOptionNodes) {
  47707. checkInvalidScopeReference(node, DEFINE_MODEL);
  47708. }
  47709. }
  47710. if (script) {
  47711. if (startOffset < scriptStartOffset) {
  47712. ctx.s.remove(0, startOffset);
  47713. ctx.s.remove(endOffset, scriptStartOffset);
  47714. ctx.s.remove(scriptEndOffset, source.length);
  47715. } else {
  47716. ctx.s.remove(0, scriptStartOffset);
  47717. ctx.s.remove(scriptEndOffset, startOffset);
  47718. ctx.s.remove(endOffset, source.length);
  47719. }
  47720. } else {
  47721. ctx.s.remove(0, startOffset);
  47722. ctx.s.remove(endOffset, source.length);
  47723. }
  47724. if (scriptAst) {
  47725. Object.assign(ctx.bindingMetadata, analyzeScriptBindings(scriptAst.body));
  47726. }
  47727. for (const [key, { isType, imported, source: source2 }] of Object.entries(
  47728. ctx.userImports
  47729. )) {
  47730. if (isType) continue;
  47731. ctx.bindingMetadata[key] = imported === "*" || imported === "default" && source2.endsWith(".vue") || source2 === "vue" ? "setup-const" : "setup-maybe-ref";
  47732. }
  47733. for (const key in scriptBindings) {
  47734. ctx.bindingMetadata[key] = scriptBindings[key];
  47735. }
  47736. for (const key in setupBindings) {
  47737. ctx.bindingMetadata[key] = setupBindings[key];
  47738. }
  47739. if (sfc.template && !sfc.template.src && sfc.template.ast) {
  47740. const vModelIds = resolveTemplateVModelIdentifiers(sfc);
  47741. if (vModelIds.size) {
  47742. const toDemote = /* @__PURE__ */ new Set();
  47743. for (const id of vModelIds) {
  47744. if (setupBindings[id] === "setup-reactive-const") {
  47745. toDemote.add(id);
  47746. }
  47747. }
  47748. if (toDemote.size) {
  47749. for (const node of scriptSetupAst.body) {
  47750. if (node.type === "VariableDeclaration" && node.kind === "const" && !node.declare) {
  47751. const demotedInDecl = [];
  47752. for (const decl of node.declarations) {
  47753. if (decl.id.type === "Identifier" && toDemote.has(decl.id.name)) {
  47754. demotedInDecl.push(decl.id.name);
  47755. }
  47756. }
  47757. if (demotedInDecl.length) {
  47758. ctx.s.overwrite(
  47759. node.start + startOffset,
  47760. node.start + startOffset + "const".length,
  47761. "let"
  47762. );
  47763. for (const id of demotedInDecl) {
  47764. setupBindings[id] = "setup-let";
  47765. ctx.bindingMetadata[id] = "setup-let";
  47766. warnOnce$1(
  47767. `\`v-model\` cannot update a \`const\` reactive binding \`${id}\`. The compiler has transformed it to \`let\` to make the update work.`
  47768. );
  47769. }
  47770. }
  47771. }
  47772. }
  47773. }
  47774. }
  47775. }
  47776. if (sfc.cssVars.length && // no need to do this when targeting SSR
  47777. !((_a = options.templateOptions) == null ? void 0 : _a.ssr)) {
  47778. ctx.helperImports.add(CSS_VARS_HELPER);
  47779. ctx.helperImports.add("unref");
  47780. ctx.s.prependLeft(
  47781. startOffset,
  47782. `
  47783. ${genCssVarsCode(
  47784. sfc.cssVars,
  47785. ctx.bindingMetadata,
  47786. scopeId,
  47787. !!options.isProd
  47788. )}
  47789. `
  47790. );
  47791. }
  47792. let args = `__props`;
  47793. if (ctx.propsTypeDecl) {
  47794. args += `: any`;
  47795. }
  47796. if (ctx.propsDecl) {
  47797. if (ctx.propsDestructureRestId) {
  47798. ctx.s.overwrite(
  47799. startOffset + ctx.propsCall.start,
  47800. startOffset + ctx.propsCall.end,
  47801. `${ctx.helper(`createPropsRestProxy`)}(__props, ${JSON.stringify(
  47802. Object.keys(ctx.propsDestructuredBindings)
  47803. )})`
  47804. );
  47805. ctx.s.overwrite(
  47806. startOffset + ctx.propsDestructureDecl.start,
  47807. startOffset + ctx.propsDestructureDecl.end,
  47808. ctx.propsDestructureRestId
  47809. );
  47810. } else if (!ctx.propsDestructureDecl) {
  47811. ctx.s.overwrite(
  47812. startOffset + ctx.propsCall.start,
  47813. startOffset + ctx.propsCall.end,
  47814. "__props"
  47815. );
  47816. }
  47817. }
  47818. if (hasAwait) {
  47819. const any = ctx.isTS ? `: any` : ``;
  47820. ctx.s.prependLeft(startOffset, `
  47821. let __temp${any}, __restore${any}
  47822. `);
  47823. }
  47824. const destructureElements = ctx.hasDefineExposeCall || !options.inlineTemplate ? [`expose: __expose`] : [];
  47825. if (ctx.emitDecl) {
  47826. destructureElements.push(`emit: __emit`);
  47827. }
  47828. if (destructureElements.length) {
  47829. args += `, { ${destructureElements.join(", ")} }`;
  47830. }
  47831. let templateMap;
  47832. let returned;
  47833. const propsDecl = genRuntimeProps(ctx);
  47834. if (!options.inlineTemplate || !sfc.template && ctx.hasDefaultExportRender) {
  47835. const allBindings = __spreadValues$1(__spreadValues$1({}, scriptBindings), setupBindings);
  47836. for (const key in ctx.userImports) {
  47837. if (!ctx.userImports[key].isType && ctx.userImports[key].isUsedInTemplate) {
  47838. allBindings[key] = true;
  47839. }
  47840. }
  47841. returned = `{ `;
  47842. for (const key in allBindings) {
  47843. if (allBindings[key] === true && ctx.userImports[key].source !== "vue" && !ctx.userImports[key].source.endsWith(".vue")) {
  47844. returned += `get ${key}() { return ${key} }, `;
  47845. } else if (ctx.bindingMetadata[key] === "setup-let") {
  47846. const setArg = key === "v" ? `_v` : `v`;
  47847. returned += `get ${key}() { return ${key} }, set ${key}(${setArg}) { ${key} = ${setArg} }, `;
  47848. } else {
  47849. returned += `${key}, `;
  47850. }
  47851. }
  47852. returned = returned.replace(/, $/, "") + ` }`;
  47853. } else {
  47854. if (sfc.template && !sfc.template.src) {
  47855. if (options.templateOptions && options.templateOptions.ssr) {
  47856. hasInlinedSsrRenderFn = true;
  47857. }
  47858. const { code, ast, preamble, tips, errors, map: map2 } = compileTemplate(__spreadProps(__spreadValues$1({
  47859. filename,
  47860. ast: sfc.template.ast,
  47861. source: sfc.template.content,
  47862. inMap: sfc.template.map
  47863. }, options.templateOptions), {
  47864. id: scopeId,
  47865. scoped: sfc.styles.some((s) => s.scoped),
  47866. isProd: options.isProd,
  47867. ssrCssVars: sfc.cssVars,
  47868. compilerOptions: __spreadProps(__spreadValues$1({}, options.templateOptions && options.templateOptions.compilerOptions), {
  47869. inline: true,
  47870. isTS: ctx.isTS,
  47871. bindingMetadata: ctx.bindingMetadata
  47872. })
  47873. }));
  47874. templateMap = map2;
  47875. if (tips.length) {
  47876. tips.forEach(warnOnce$1);
  47877. }
  47878. const err = errors[0];
  47879. if (typeof err === "string") {
  47880. throw new Error(err);
  47881. } else if (err) {
  47882. if (err.loc) {
  47883. err.message += `
  47884. ` + sfc.filename + "\n" + generateCodeFrame(
  47885. source,
  47886. err.loc.start.offset,
  47887. err.loc.end.offset
  47888. ) + `
  47889. `;
  47890. }
  47891. throw err;
  47892. }
  47893. if (preamble) {
  47894. ctx.s.prepend(preamble);
  47895. }
  47896. if (ast && ast.helpers.has(UNREF)) {
  47897. ctx.helperImports.delete("unref");
  47898. }
  47899. returned = code;
  47900. } else {
  47901. returned = `() => {}`;
  47902. }
  47903. }
  47904. if (!options.inlineTemplate && true) {
  47905. ctx.s.appendRight(
  47906. endOffset,
  47907. `
  47908. const __returned__ = ${returned}
  47909. Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true })
  47910. return __returned__
  47911. }
  47912. `
  47913. );
  47914. } else {
  47915. ctx.s.appendRight(endOffset, `
  47916. return ${returned}
  47917. }
  47918. `);
  47919. }
  47920. const genDefaultAs = options.genDefaultAs ? `const ${options.genDefaultAs} =` : `export default`;
  47921. let runtimeOptions = ``;
  47922. if (!ctx.hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
  47923. const match = filename.match(/([^/\\]+)\.\w+$/);
  47924. if (match) {
  47925. runtimeOptions += `
  47926. __name: '${match[1]}',`;
  47927. }
  47928. }
  47929. if (hasInlinedSsrRenderFn) {
  47930. runtimeOptions += `
  47931. __ssrInlineRender: true,`;
  47932. }
  47933. if (propsDecl) runtimeOptions += `
  47934. props: ${propsDecl},`;
  47935. const emitsDecl = genRuntimeEmits(ctx);
  47936. if (emitsDecl) runtimeOptions += `
  47937. emits: ${emitsDecl},`;
  47938. let definedOptions = "";
  47939. if (ctx.optionsRuntimeDecl) {
  47940. definedOptions = scriptSetup.content.slice(ctx.optionsRuntimeDecl.start, ctx.optionsRuntimeDecl.end).trim();
  47941. }
  47942. const exposeCall = ctx.hasDefineExposeCall || options.inlineTemplate ? `` : ` __expose();
  47943. `;
  47944. if (ctx.isTS) {
  47945. const def = (defaultExport ? `
  47946. ...${normalScriptDefaultVar},` : ``) + (definedOptions ? `
  47947. ...${definedOptions},` : "");
  47948. ctx.s.prependLeft(
  47949. startOffset,
  47950. `
  47951. ${genDefaultAs} /*@__PURE__*/${ctx.helper(
  47952. `defineComponent`
  47953. )}({${def}${runtimeOptions}
  47954. ${hasAwait ? `async ` : ``}setup(${args}) {
  47955. ${exposeCall}`
  47956. );
  47957. ctx.s.appendRight(endOffset, `})`);
  47958. } else {
  47959. if (defaultExport || definedOptions) {
  47960. ctx.s.prependLeft(
  47961. startOffset,
  47962. `
  47963. ${genDefaultAs} /*@__PURE__*/Object.assign(${defaultExport ? `${normalScriptDefaultVar}, ` : ""}${definedOptions ? `${definedOptions}, ` : ""}{${runtimeOptions}
  47964. ${hasAwait ? `async ` : ``}setup(${args}) {
  47965. ${exposeCall}`
  47966. );
  47967. ctx.s.appendRight(endOffset, `})`);
  47968. } else {
  47969. ctx.s.prependLeft(
  47970. startOffset,
  47971. `
  47972. ${genDefaultAs} {${runtimeOptions}
  47973. ${hasAwait ? `async ` : ``}setup(${args}) {
  47974. ${exposeCall}`
  47975. );
  47976. ctx.s.appendRight(endOffset, `}`);
  47977. }
  47978. }
  47979. if (ctx.helperImports.size > 0) {
  47980. const runtimeModuleName = (_c = (_b = options.templateOptions) == null ? void 0 : _b.compilerOptions) == null ? void 0 : _c.runtimeModuleName;
  47981. const importSrc = runtimeModuleName ? JSON.stringify(runtimeModuleName) : `'vue'`;
  47982. ctx.s.prepend(
  47983. `import { ${[...ctx.helperImports].map((h) => `${h} as _${h}`).join(", ")} } from ${importSrc}
  47984. `
  47985. );
  47986. }
  47987. const content = ctx.s.toString();
  47988. let map = options.sourceMap !== false ? ctx.s.generateMap({
  47989. source: filename,
  47990. hires: true,
  47991. includeContent: true
  47992. }) : void 0;
  47993. if (templateMap && map) {
  47994. const offset = content.indexOf(returned);
  47995. const templateLineOffset = content.slice(0, offset).split(/\r?\n/).length - 1;
  47996. map = mergeSourceMaps(map, templateMap, templateLineOffset);
  47997. }
  47998. return __spreadProps(__spreadValues$1({}, scriptSetup), {
  47999. bindings: ctx.bindingMetadata,
  48000. imports: ctx.userImports,
  48001. content,
  48002. map,
  48003. scriptAst: scriptAst == null ? void 0 : scriptAst.body,
  48004. scriptSetupAst: scriptSetupAst == null ? void 0 : scriptSetupAst.body,
  48005. deps: ctx.deps ? [...ctx.deps] : void 0
  48006. });
  48007. }
  48008. function registerBinding(bindings, node, type) {
  48009. bindings[node.name] = type;
  48010. }
  48011. function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic, isPropsDestructureEnabled = false) {
  48012. let isAllLiteral = false;
  48013. if (node.type === "VariableDeclaration") {
  48014. const isConst = node.kind === "const";
  48015. isAllLiteral = isConst && node.declarations.every(
  48016. (decl) => decl.id.type === "Identifier" && isStaticNode(decl.init)
  48017. );
  48018. for (const { id, init: _init } of node.declarations) {
  48019. const init = _init && unwrapTSNode(_init);
  48020. const isConstMacroCall = isConst && isCallOf(
  48021. init,
  48022. (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS || c === DEFINE_SLOTS
  48023. );
  48024. if (id.type === "Identifier") {
  48025. let bindingType;
  48026. const userReactiveBinding = userImportAliases["reactive"];
  48027. if ((hoistStatic || from === "script") && (isAllLiteral || isConst && isStaticNode(init))) {
  48028. bindingType = "literal-const";
  48029. } else if (isCallOf(init, userReactiveBinding)) {
  48030. bindingType = isConst ? "setup-reactive-const" : "setup-let";
  48031. } else if (
  48032. // if a declaration is a const literal, we can mark it so that
  48033. // the generated render fn code doesn't need to unref() it
  48034. isConstMacroCall || isConst && canNeverBeRef(init, userReactiveBinding)
  48035. ) {
  48036. bindingType = isCallOf(init, DEFINE_PROPS) ? "setup-reactive-const" : "setup-const";
  48037. } else if (isConst) {
  48038. if (isCallOf(
  48039. init,
  48040. (m) => m === userImportAliases["ref"] || m === userImportAliases["computed"] || m === userImportAliases["shallowRef"] || m === userImportAliases["customRef"] || m === userImportAliases["toRef"] || m === userImportAliases["useTemplateRef"] || m === DEFINE_MODEL
  48041. )) {
  48042. bindingType = "setup-ref";
  48043. } else {
  48044. bindingType = "setup-maybe-ref";
  48045. }
  48046. } else {
  48047. bindingType = "setup-let";
  48048. }
  48049. registerBinding(bindings, id, bindingType);
  48050. } else {
  48051. if (isCallOf(init, DEFINE_PROPS) && isPropsDestructureEnabled) {
  48052. continue;
  48053. }
  48054. if (id.type === "ObjectPattern") {
  48055. walkObjectPattern(id, bindings, isConst, isConstMacroCall);
  48056. } else if (id.type === "ArrayPattern") {
  48057. walkArrayPattern(id, bindings, isConst, isConstMacroCall);
  48058. }
  48059. }
  48060. }
  48061. } else if (node.type === "TSEnumDeclaration") {
  48062. isAllLiteral = node.members.every(
  48063. (member) => !member.initializer || isStaticNode(member.initializer)
  48064. );
  48065. bindings[node.id.name] = isAllLiteral ? "literal-const" : "setup-const";
  48066. } else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
  48067. bindings[node.id.name] = "setup-const";
  48068. }
  48069. return isAllLiteral;
  48070. }
  48071. function walkObjectPattern(node, bindings, isConst, isDefineCall = false) {
  48072. for (const p of node.properties) {
  48073. if (p.type === "ObjectProperty") {
  48074. if (p.key.type === "Identifier" && p.key === p.value) {
  48075. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  48076. registerBinding(bindings, p.key, type);
  48077. } else {
  48078. walkPattern(p.value, bindings, isConst, isDefineCall);
  48079. }
  48080. } else {
  48081. const type = isConst ? "setup-const" : "setup-let";
  48082. registerBinding(bindings, p.argument, type);
  48083. }
  48084. }
  48085. }
  48086. function walkArrayPattern(node, bindings, isConst, isDefineCall = false) {
  48087. for (const e of node.elements) {
  48088. e && walkPattern(e, bindings, isConst, isDefineCall);
  48089. }
  48090. }
  48091. function walkPattern(node, bindings, isConst, isDefineCall = false) {
  48092. if (node.type === "Identifier") {
  48093. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  48094. registerBinding(bindings, node, type);
  48095. } else if (node.type === "RestElement") {
  48096. const type = isConst ? "setup-const" : "setup-let";
  48097. registerBinding(bindings, node.argument, type);
  48098. } else if (node.type === "ObjectPattern") {
  48099. walkObjectPattern(node, bindings, isConst);
  48100. } else if (node.type === "ArrayPattern") {
  48101. walkArrayPattern(node, bindings, isConst);
  48102. } else if (node.type === "AssignmentPattern") {
  48103. if (node.left.type === "Identifier") {
  48104. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  48105. registerBinding(bindings, node.left, type);
  48106. } else {
  48107. walkPattern(node.left, bindings, isConst);
  48108. }
  48109. }
  48110. }
  48111. function canNeverBeRef(node, userReactiveImport) {
  48112. if (isCallOf(node, userReactiveImport)) {
  48113. return true;
  48114. }
  48115. switch (node.type) {
  48116. case "UnaryExpression":
  48117. case "BinaryExpression":
  48118. case "ArrayExpression":
  48119. case "ObjectExpression":
  48120. case "FunctionExpression":
  48121. case "ArrowFunctionExpression":
  48122. case "UpdateExpression":
  48123. case "ClassExpression":
  48124. case "TaggedTemplateExpression":
  48125. return true;
  48126. case "SequenceExpression":
  48127. return canNeverBeRef(
  48128. node.expressions[node.expressions.length - 1],
  48129. userReactiveImport
  48130. );
  48131. default:
  48132. if (isLiteralNode(node)) {
  48133. return true;
  48134. }
  48135. return false;
  48136. }
  48137. }
  48138. function isStaticNode(node) {
  48139. node = unwrapTSNode(node);
  48140. switch (node.type) {
  48141. case "UnaryExpression":
  48142. return isStaticNode(node.argument);
  48143. case "LogicalExpression":
  48144. // 1 > 2
  48145. case "BinaryExpression":
  48146. return isStaticNode(node.left) && isStaticNode(node.right);
  48147. case "ConditionalExpression": {
  48148. return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
  48149. }
  48150. case "SequenceExpression":
  48151. // (1, 2)
  48152. case "TemplateLiteral":
  48153. return node.expressions.every((expr) => isStaticNode(expr));
  48154. case "ParenthesizedExpression":
  48155. return isStaticNode(node.expression);
  48156. case "StringLiteral":
  48157. case "NumericLiteral":
  48158. case "BooleanLiteral":
  48159. case "NullLiteral":
  48160. case "BigIntLiteral":
  48161. return true;
  48162. }
  48163. return false;
  48164. }
  48165. function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
  48166. const generator = new sourceMapExports.SourceMapGenerator();
  48167. const addMapping = (map, lineOffset = 0) => {
  48168. const consumer = new sourceMapExports.SourceMapConsumer(map);
  48169. consumer.sources.forEach((sourceFile) => {
  48170. generator._sources.add(sourceFile);
  48171. const sourceContent = consumer.sourceContentFor(sourceFile);
  48172. if (sourceContent != null) {
  48173. generator.setSourceContent(sourceFile, sourceContent);
  48174. }
  48175. });
  48176. consumer.eachMapping((m) => {
  48177. if (m.originalLine == null) return;
  48178. generator.addMapping({
  48179. generated: {
  48180. line: m.generatedLine + lineOffset,
  48181. column: m.generatedColumn
  48182. },
  48183. original: {
  48184. line: m.originalLine,
  48185. column: m.originalColumn
  48186. },
  48187. source: m.source,
  48188. name: m.name
  48189. });
  48190. });
  48191. };
  48192. addMapping(scriptMap);
  48193. addMapping(templateMap, templateLineOffset);
  48194. generator._sourceRoot = scriptMap.sourceRoot;
  48195. generator._file = scriptMap.file;
  48196. return generator.toJSON();
  48197. }
  48198. var __defProp = Object.defineProperty;
  48199. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  48200. var __hasOwnProp = Object.prototype.hasOwnProperty;
  48201. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  48202. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  48203. var __spreadValues = (a, b) => {
  48204. for (var prop in b || (b = {}))
  48205. if (__hasOwnProp.call(b, prop))
  48206. __defNormalProp(a, prop, b[prop]);
  48207. if (__getOwnPropSymbols)
  48208. for (var prop of __getOwnPropSymbols(b)) {
  48209. if (__propIsEnum.call(b, prop))
  48210. __defNormalProp(a, prop, b[prop]);
  48211. }
  48212. return a;
  48213. };
  48214. const version = "3.5.27";
  48215. const parseCache = parseCache$1;
  48216. const errorMessages = __spreadValues(__spreadValues({}, errorMessages$1), DOMErrorMessages);
  48217. const walk = walk$2;
  48218. const shouldTransformRef = () => false;
  48219. var parse$4 = libExports.parse;
  48220. export { MagicString, parse$4 as babelParse, compileScript, compileStyle, compileStyleAsync, compileTemplate, errorMessages, extractIdentifiers$1 as extractIdentifiers, extractRuntimeEmits, extractRuntimeProps, generateCodeFrame, inferRuntimeType, invalidateTypeCache, isInDestructureAssignment, isStaticProperty, parse$2 as parse, parseCache, registerTS, resolveTypeElements, rewriteDefault, rewriteDefaultAST, shouldTransformRef, version, walk, walkIdentifiers };